Skip to content

Commit

Permalink
Added screen percentage override.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyall committed Feb 9, 2024
1 parent 89ab3d1 commit b2a2d2c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion P3RFix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ Enabled = true

[Fix FOV]
; Fixes FOV.
Enabled = true
Enabled = true

;;;;;;;;;; Graphical Tweaks ;;;;;;;;;;

[Screen Percentage]
; Overrides screen percentage (a.k.a render scale).
; Set to >100 for downsampling and <100 to upsample.
Enabled = false
Value = 100
36 changes: 36 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int iCustomResY;
bool bHUDFix;
bool bAspectFix;
bool bFOVFix;
bool bScreenPercentage;
int iScreenPercentage;

// Aspect ratio + HUD stuff
float fPi = (float)3.141592653;
Expand Down Expand Up @@ -131,6 +133,8 @@ void ReadConfig()
inipp::get_value(ini.sections["Fix HUD"], "Enabled", bHUDFix);
inipp::get_value(ini.sections["Fix Aspect Ratio"], "Enabled", bAspectFix);
inipp::get_value(ini.sections["Fix FOV"], "Enabled", bFOVFix);
inipp::get_value(ini.sections["Screen Percentage"], "Enabled", bScreenPercentage);
inipp::get_value(ini.sections["Screen Percentage"], "Value", iScreenPercentage);

// Log config parse
spdlog::info("Config Parse: iInjectionDelay: {}ms", iInjectionDelay);
Expand All @@ -140,6 +144,13 @@ void ReadConfig()
spdlog::info("Config Parse: bHUDFix: {}", bHUDFix);
spdlog::info("Config Parse: bAspectFix: {}", bAspectFix);
spdlog::info("Config Parse: bFOVFix: {}", bFOVFix);
spdlog::info("Config Parse: bScreenPercentage: {}", bScreenPercentage);
spdlog::info("Config Parse: iScreenPercentage: {}", iScreenPercentage);
if (iScreenPercentage < 10 || iScreenPercentage > 400)
{
iScreenPercentage = std::clamp(iScreenPercentage, 10, 400);
spdlog::info("Config Parse: iScreenPercentage value invalid, clamped to {}", iScreenPercentage);
}
spdlog::info("----------");

// Calculate aspect ratio / use desktop res instead
Expand Down Expand Up @@ -555,6 +566,30 @@ void Fades()
}
}

void GraphicalTweaks()
{
if (bScreenPercentage)
{
// Screen Percentage
uint8_t* ScreenPercentageScanResult = Memory::PatternScan(baseModule, "0F ?? ?? F3 0F ?? ?? ?? 0F ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 0F ?? ?? 77 ?? F3 0F ?? ?? ?? ?? ?? ?? 48 ?? ?? ?? ?? 48 ?? ?? 20 5F C3");
if (ScreenPercentageScanResult)
{
spdlog::info("Aspect Ratio: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)ScreenPercentageScanResult - (uintptr_t)baseModule);
static SafetyHookMid ScreenPercentageMidHook{};
ScreenPercentageMidHook = safetyhook::create_mid(ScreenPercentageScanResult + 0x3,
[](SafetyHookContext& ctx)
{
*reinterpret_cast<float*>(ctx.rdi + (ctx.rbx*4)) = (float)iScreenPercentage;
});

}
else if (!ScreenPercentageScanResult)
{
spdlog::error("Aspect Ratio: Pattern scan failed.");
}
}
}

DWORD __stdcall Main(void*)
{
Logging();
Expand All @@ -564,6 +599,7 @@ DWORD __stdcall Main(void*)
AspectFOVFix();
HUDFix();
Fades();
GraphicalTweaks();
return true;
}

Expand Down

0 comments on commit b2a2d2c

Please sign in to comment.