Skip to content

Commit

Permalink
get rid of compiler warning, improve moduleBase and rename project
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-FADED committed Dec 10, 2022
1 parent 9c2720f commit 7a93f86
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions RDR2 FSR2 Loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ProjectGuid>{08c6ad03-c61e-4033-ac24-a5ed8f1ecf39}</ProjectGuid>
<RootNamespace>RDR2FSR2Loader</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>RDR2 NVGX Loader</ProjectName>
<ProjectName>RDR2 NVNGX Loader</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -83,7 +83,7 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>.\_Release</OutDir>
<TargetName>NVGX_Loader</TargetName>
<TargetName>NVNGX_Loader</TargetName>
<TargetExt>.asi</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
File renamed without changes.
Binary file not shown.
2 changes: 1 addition & 1 deletion _Release/nvngx_loader.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[nvngx_loader_options]
# values are bool so they must be true or false
Disable_NVNGX_Checks = true # patches GPU and Signature check allowing the Game to load nvngx.dll on any GPU
Disable_DLSS_Sharpening_and_AutoExposure = true # self explanatory
Disable_DLSS_Sharpening_and_AutoExposure = false # self explanatory
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RDR2 NVNGX Loader
NVGX.dll loader for RDR2 used for modding FSR2 into the game. R* will probably never update FSR2 to the newest version or they won't keep updating it and currently latest version of the FSR2 binaries crashes the game but we can mod the newest version into the game using [this](https://github.com/PotatoOfDoom/CyberFSR2)
NVGNX.dll loader for RDR2 used for modding FSR2 into the game. R* will probably never update FSR2 to the newest version or they won't keep updating it and currently latest version of the FSR2 binaries crashes the game but we can mod the newest version into the game using [this](https://github.com/PotatoOfDoom/CyberFSR2)

# Compatibility
the version when R* added DLSS to the game or higher(I don't remember the version number)
Expand All @@ -8,4 +8,4 @@ the version when R* added DLSS to the game or higher(I don't remember the versio
ASI loader **dinput8.dll** which comes with [Script Hook RDR2](http://www.dev-c.com/rdr2/scripthookrdr2/) or **version.dll** which you can download from [rdr2mods website](https://www.rdr2mods.com/downloads/rdr2/tools/9-rdr-2-asi-loader/)

# Installation
download any of the mentioned asi loaders put them where **RDR2.exe** is located downoad **NVGX_Loader.asi** and **nvngx_loader_options.toml** from[here](https://github.com/0x-FADED/RDR2-NVGX-Loader/releases) and extract it on the same place. download DLSS2FSR from [here](https://github.com/PotatoOfDoom/CyberFSR2) then extract it on the same place and enjoy.
download any of the mentioned asi loaders put them where **RDR2.exe** is located downoad **NVGX_Loader.asi** and **nvngx_loader_options.toml** from[here](https://github.com/0x-FADED/RDR2-NVNGX-Loader/releases) and extract it on the same place. download DLSS2FSR from [here](https://github.com/PotatoOfDoom/CyberFSR2) then extract it on the same place and enjoy.
44 changes: 23 additions & 21 deletions src/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

std::pair<uintptr_t, uintptr_t> GetModule(const std::wstring_view moduleName)
{
const static uintptr_t moduleBase = reinterpret_cast<uintptr_t>(GetModuleHandleW(moduleName.data()));
const static uintptr_t moduleEnd = [&]()
{
auto ntHeaders = reinterpret_cast<PIMAGE_NT_HEADERS64>(moduleBase + reinterpret_cast<PIMAGE_DOS_HEADER>(moduleBase)->e_lfanew);
return static_cast<uintptr_t>(moduleBase + ntHeaders->OptionalHeader.SizeOfImage);
}();
const auto dosHeader = reinterpret_cast<PIMAGE_DOS_HEADER>(GetModuleHandleW(moduleName.data()));
const auto ntHeaders = reinterpret_cast<PIMAGE_NT_HEADERS64>(reinterpret_cast<uintptr_t>(dosHeader) + dosHeader->e_lfanew);

static const uintptr_t moduleBase = static_cast<uintptr_t>(ntHeaders->OptionalHeader.ImageBase);
static const uintptr_t moduleEnd = moduleBase + static_cast<uintptr_t>(ntHeaders->OptionalHeader.SizeOfImage);

return { moduleBase , moduleEnd };

return { moduleBase, moduleEnd };
}


Expand Down Expand Up @@ -43,32 +43,34 @@
if (sig == dataEnd)
return NULL;

return std::distance(dataStart, sig) + startAddress;
return std::distance<const uint8_t*>(dataStart, sig) + startAddress;
}

uintptr_t scanner::GetAddress(const std::wstring_view moduleName, const std::string_view pattern, ptrdiff_t offset)
{
if (GetModuleHandleW(moduleName.data()) != nullptr)
{
uintptr_t address = FindPattern(GetModule(moduleName.data()).first, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());

if (address == NULL)
throw std::runtime_error("Failed to find pattern");
uintptr_t address = FindPattern(GetModule(moduleName.data()).first, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());

if ((GetModuleHandleW(moduleName.data()) == nullptr) || (address == NULL))
{
throw std::runtime_error("Pattern not found!");
}
else
{
return (address + offset);
}
}

uintptr_t scanner::GetOffsetFromInstruction(const std::wstring_view moduleName, const std::string_view pattern, ptrdiff_t offset)
{
if (GetModuleHandleW(moduleName.data()) != nullptr)
{
uintptr_t address = FindPattern(GetModule(moduleName.data()).first, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());

if (address == NULL)
throw std::runtime_error("Failed to find pattern");
uintptr_t address = FindPattern(GetModule(moduleName.data()).first, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());

if ((GetModuleHandleW(moduleName.data()) != nullptr) && (address != NULL))
{
auto reloffset = *reinterpret_cast<int32_t*>(address + offset) + sizeof(int32_t);
return (address + offset + reloffset);
}
}
else
{
throw std::runtime_error("Pattern not found!");
}
}

0 comments on commit 7a93f86

Please sign in to comment.