Skip to content

Commit

Permalink
added fsr3 pattern matching for rdr1
Browse files Browse the repository at this point in the history
  • Loading branch information
cdozdil committed Jan 29, 2025
1 parent 697fa95 commit 9a30fe7
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 12 deletions.
2 changes: 2 additions & 0 deletions OptiScaler/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ bool Config::Reload(std::filesystem::path iniPath)
Fsr2Inputs.set_from_config(readBool("Inputs", "Fsr2"));
Fsr2Pattern.set_from_config(readBool("Inputs", "Fsr2Pattern"));
Fsr3Inputs.set_from_config(readBool("Inputs", "Fsr3"));
Fsr3Pattern.set_from_config(readBool("Inputs", "Fsr3Pattern"));
FfxInputs.set_from_config(readBool("Inputs", "Ffx"));
}

Expand Down Expand Up @@ -726,6 +727,7 @@ bool Config::SaveIni()
ini.SetValue("Inputs", "Fsr2", GetBoolValue(Instance()->Fsr2Inputs.value_for_config()).c_str());
ini.SetValue("Inputs", "Fsr2Pattern", GetBoolValue(Instance()->Fsr2Pattern.value_for_config()).c_str());
ini.SetValue("Inputs", "Fsr3", GetBoolValue(Instance()->Fsr3Inputs.value_for_config()).c_str());
ini.SetValue("Inputs", "Fsr3Pattern", GetBoolValue(Instance()->Fsr3Pattern.value_for_config()).c_str());
ini.SetValue("Inputs", "Ffx", GetBoolValue(Instance()->FfxInputs.value_for_config()).c_str());
}

Expand Down
1 change: 1 addition & 0 deletions OptiScaler/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class Config
CustomOptional<bool> Fsr2Inputs{ true };
CustomOptional<bool> Fsr2Pattern{ false };
CustomOptional<bool> Fsr3Inputs{ true };
CustomOptional<bool> Fsr3Pattern{ false };
CustomOptional<bool> FfxInputs{ true };

// Framerate
Expand Down
2 changes: 1 addition & 1 deletion OptiScaler/inputs/FSR2_Dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,10 +977,10 @@ void HookFSR2ExeInputs()
// Pattern matching
if (Config::Instance()->Fsr2Pattern.value_or_default())
{
LOG_DEBUG("Checking createPattern");
std::wstring_view exeNameV(exeNameW.c_str());

// Create
LOG_DEBUG("Checking createPattern");
std::string_view createPattern("40 55 57 41 54 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B F2 41 B8 ? ? ? ? 33 D2 48 8B F9 E8");
o_ffxFsr2ContextCreate_Pattern_Dx12 = (PFN_ffxFsr2ContextCreate)scanner::GetAddress(exeNameV, createPattern, 0);

Expand Down
271 changes: 264 additions & 7 deletions OptiScaler/inputs/FSR3_Dx12.cpp

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion OptiScaler/menu/menu_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2593,19 +2593,23 @@ bool MenuCommon::RenderMenu()
bool fsr2Inputs = Config::Instance()->Fsr2Inputs.value_or_default();
bool fsr2Pattern = Config::Instance()->Fsr2Pattern.value_or_default();
bool fsr3Inputs = Config::Instance()->Fsr3Inputs.value_or_default();
bool fsr3Pattern = Config::Instance()->Fsr3Pattern.value_or_default();
bool ffxInputs = Config::Instance()->FfxInputs.value_or_default();

if (ImGui::Checkbox("Use Fsr2 Inputs", &fsr2Inputs))
Config::Instance()->Fsr2Inputs = fsr2Inputs;

if (ImGui::Checkbox("Use Fsr2 Pattern Matching", &fsr2Pattern))
Config::Instance()->Fsr2Pattern = fsr2Pattern;

ShowTooltip("This setting will become active on next boot!");

if (ImGui::Checkbox("Use Fsr3 Inputs", &fsr3Inputs))
Config::Instance()->Fsr3Inputs = fsr3Inputs;

if (ImGui::Checkbox("Use Fsr3 Pattern Matching", &fsr3Pattern))
Config::Instance()->Fsr3Pattern = fsr2Pattern;
ShowTooltip("This setting will become active on next boot!");

if (ImGui::Checkbox("Use Ffx Inputs", &ffxInputs))
Config::Instance()->FfxInputs = ffxInputs;
}
Expand Down
9 changes: 7 additions & 2 deletions OptiScaler/scanner/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ uintptr_t FindPattern(uintptr_t startAddress, uintptr_t maxSize, const char* mas
return std::distance(dataStart, sig) + startAddress;
}

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

if (startAddress != 0)
address = FindPattern(startAddress, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());
else
address = FindPattern(GetModule(moduleName.data()).first, GetModule(moduleName.data()).second - GetModule(moduleName.data()).first, pattern.data());

if ((GetModuleHandleW(moduleName.data()) != nullptr) && (address != NULL))
{
Expand Down
2 changes: 1 addition & 1 deletion OptiScaler/scanner/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

namespace scanner
{
uintptr_t GetAddress(const std::wstring_view moduleName, const std::string_view pattern, ptrdiff_t offset = 0);
uintptr_t GetAddress(const std::wstring_view moduleName, const std::string_view pattern, ptrdiff_t offset = 0, uintptr_t startAddress = 0);
uintptr_t GetOffsetFromInstruction(const std::wstring_view moduleName, const std::string_view pattern, ptrdiff_t offset = 0);
}
5 changes: 5 additions & 0 deletions nvngx.ini
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ Fsr2Pattern=auto
; true or false - Default (auto) is true
Fsr3=auto

; Try to find FSR3 methods with pattern matching
; Will slow down the loading of game
; true or false - Default (auto) is false
Fsr3Pattern=auto

; Optiscaler will hook (amd_fidelityfx_dx12.dll) and use FidelityFX Api Inputs
; true or false - Default (auto) is true
Ffx=auto
Expand Down

0 comments on commit 9a30fe7

Please sign in to comment.