Skip to content

Commit

Permalink
Fixed screen effects bug at <1920 horizontal resolution. #42 Added op…
Browse files Browse the repository at this point in the history
…tion to span all backgrounds and all HUD elements.
  • Loading branch information
Lyall committed Mar 21, 2024
1 parent 10868e7 commit e874e79
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HMODULE baseModule = GetModuleHandle(NULL);
inipp::Ini<char> ini;
std::shared_ptr<spdlog::logger> logger;
std::string sFixName = "GBFRelinkFix";
std::string sFixVer = "1.0.9";
std::string sFixVer = "1.1.0";
std::string sLogFile = "GBFRelinkFix.log";
std::string sConfigFile = "GBFRelinkFix.ini";
std::string sExeName;
Expand All @@ -28,6 +28,8 @@ float fCamDistMulti;
bool bHUDFix;
bool bSpanHUD;
float fHUDAspectRatio;
bool bSpanAllHUD;
bool bSpanAllBackgrounds;
bool bAspectFix;
bool bFOVFix;
bool bShadowQuality;
Expand Down Expand Up @@ -123,6 +125,8 @@ void ReadConfig()
inipp::get_value(ini.sections["Fix HUD"], "Enabled", bHUDFix);
inipp::get_value(ini.sections["Span HUD"], "Enabled", bSpanHUD);
inipp::get_value(ini.sections["Span HUD"], "AspectRatio", fHUDAspectRatio);
inipp::get_value(ini.sections["Span HUD"], "SpanAllHUD", bSpanAllHUD);
inipp::get_value(ini.sections["Span HUD"], "SpanAllBackgrounds", bSpanAllBackgrounds);
inipp::get_value(ini.sections["Fix Aspect Ratio"], "Enabled", bAspectFix);
inipp::get_value(ini.sections["Fix FOV"], "Enabled", bFOVFix);
inipp::get_value(ini.sections["Shadow Quality"], "Enabled", bShadowQuality);
Expand Down Expand Up @@ -151,6 +155,8 @@ void ReadConfig()
spdlog::info("Config Parse: bHUDFix: {}", bHUDFix);
spdlog::info("Config Parse: bSpanHUD: {}", bSpanHUD);
spdlog::info("Config Parse: fHUDAspectRatio: {}", fHUDAspectRatio);
spdlog::info("Config Parse: bSpanAllHUD: {}", bSpanAllHUD);
spdlog::info("Config Parse: bSpanAllBackgrounds: {}", bSpanAllBackgrounds);
spdlog::info("Config Parse: bAspectFix: {}", bAspectFix);
spdlog::info("Config Parse: bFOVFix: {}", bFOVFix);
spdlog::info("Config Parse: bShadowQuality: {}", bShadowQuality);
Expand Down Expand Up @@ -297,7 +303,7 @@ void GraphicalFixes()
// Not necessary
}
});

/*
static SafetyHookMid ScreenEffects2MidHook{};
ScreenEffects2MidHook = safetyhook::create_mid(ScreenEffectsScanResult - 0x9B, // TODO: This is a long gap, maybe do a third pattern?
[](SafetyHookContext& ctx)
Expand All @@ -308,10 +314,10 @@ void GraphicalFixes()
}
else if (fAspectRatio < fNativeAspect)
{
ctx.xmm1.f32[0] = (float)iCustomResX / fNativeAspect;
// Not necessary
}
});

*/
spdlog::info("Screen Effects: Address 2 is {:s}+{:x}", sExeName.c_str(), (uintptr_t)ScreenEffects2ScanResult - (uintptr_t)baseModule);

static SafetyHookMid ScreenEffects3MidHook{};
Expand All @@ -324,7 +330,7 @@ void GraphicalFixes()
}
else if (fAspectRatio < fNativeAspect)
{
ctx.xmm0.f32[0] *= fAspectMultiplier;
// Not necessary
}
});

Expand Down Expand Up @@ -499,6 +505,14 @@ void HUDFix()
ctx.xmm0.f32[0] = (float)2160 * fAspectRatio;
}
}

if (bSpanAllBackgrounds)
{
if (fObjectWidth == (float)3840 && fObjectHeight == (float)2160)
{
ctx.xmm0.f32[0] = (float)2160 * fHUDAspectRatio;
}
}
});
}
else if (fAspectRatio < fNativeAspect)
Expand All @@ -520,6 +534,14 @@ void HUDFix()
ctx.xmm4.f32[0] = (float)3840 / fAspectRatio;
}
}

if (bSpanAllBackgrounds)
{
if (fObjectWidth == (float)3840 && fObjectHeight == (float)2160)
{
ctx.xmm4.f32[0] = (float)3840 / fAspectRatio;
}
}
});
}
}
Expand Down Expand Up @@ -580,6 +602,24 @@ void HUDFix()
*reinterpret_cast<float*>(ctx.rax + 0x1D0) = (float)-(((3840 / fHUDAspectRatio) - 2160) / 2);
}
}

if (bSpanAllHUD)
{
if (*reinterpret_cast<float*>(ctx.rax + 0x1F4) == (float)3840 && *reinterpret_cast<float*>(ctx.rax + 0x1F8) == (float)2160 && *reinterpret_cast<int*>(ctx.rax + 0x200) != (int)1234)
{
// Span
if (fAspectRatio > fNativeAspect)
{
*reinterpret_cast<float*>(ctx.rax + 0x1F4) = (float)2160 * fHUDAspectRatio;
}
else if (fAspectRatio < fNativeAspect)
{
*reinterpret_cast<float*>(ctx.rax + 0x1F8) = (float)3840 / fHUDAspectRatio;
}
// Write marker
*reinterpret_cast<int*>(ctx.rax + 0x200) = (int)1234;
}
}
});
}
else if (!HUDConstraintsScanResult)
Expand Down

0 comments on commit e874e79

Please sign in to comment.