Fixed an issue where reafing PDA would change game FOV

This commit is contained in:
2025-08-14 22:58:37 +02:00
parent 3f13534d1c
commit 0b34a20ee2

View File

@@ -25,7 +25,7 @@ static float aspectRatio = (float)screenWidth / screenHeight;
// Plugin states
static bool AOBScanDone = false;
static bool g_fix_enabled = false;
static bool g_FOV_fix_enabled = false;
static bool g_fov_fix_enabled = false;
static bool g_aspect_fix_enabled = false;
static bool g_DOF_fix_enabled = false;
static bool g_CA_fix_enabled = false;
@@ -35,6 +35,7 @@ static int g_AdditionalFOVValue = 0;
// Shared values
static float g_FOV_In = 0;
static float g_Compensated_FOV = 0;
static float g_FOV_Out = 0;
// AOB Scan pointers
@@ -48,7 +49,6 @@ static uint8_t* Fogaddress = nullptr;
// Hooking
static SafetyHookMid FOVHook{};
static SafetyHookMid FOVOtherHook{};
static SafetyHookMid AspectHook{};
static SafetyHookMid FogHook{};
@@ -82,22 +82,20 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
}
}
if (FOVOtheraddress == nullptr) {
constexpr auto AspectStringObfuscated = make_obfuscated<0x4A>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83 ?? ?? ?? ?? 89");
FOVOtheraddress = Memory::aob_scan(gameExecutable, AspectStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
//"HellIsUs-Win64-Shipping.exe" + 3632EC5 - EB 08 - jmp "HellIsUs-Win64-Shipping.exe" + 3632ECF
//"HellIsUs-Win64-Shipping.exe" + 3632EC7 - F3 0F 10 83 30 02 00 00 - movss xmm0, [rbx + 00000230]
//"HellIsUs-Win64-Shipping.exe" + 3632ECF - F3 0 F11 47 30 - movss[rdi + 30], xmm0
//"HellIsUs-Win64-Shipping.exe" + 3632ED4 - 8B 83 54 02 00 00 - mov eax, [rbx + 00000254]
//"HellIsUs-Win64-Shipping.exe" + 3632EDA - 89 47 5C - mov[rdi + 5C], eax
//"HellIsUs-Win64-Shipping.exe" + 3632EDD - 0F B6 8B 59 02 00 00 - movzx ecx, byte ptr[rbx + 00000259]
if (Aspectaddress == nullptr) {
constexpr auto AspectStringObfuscated = make_obfuscated<0x4A>("E9 ?? ?? ?? ?? CC CC CC CC CC CC 48 89 ?? ?? ?? 57 48 83 ?? ?? 0F ?? ?? 48 ?? ?? 48");
Aspectaddress = Memory::aob_scan(gameExecutable, AspectStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
//"HellIsUs-Win64-Shipping.exe" + 3453EBA - 89 41 58 - mov[rcx + 58], eax
//"HellIsUs-Win64-Shipping.exe" + 3453EBD - 8B 42 5C - mov eax, [rdx + 5C]
//"HellIsUs-Win64-Shipping.exe" + 3453EC0 - 89 41 5C - mov[rcx + 5C], eax <<= Aspect ratio
//"HellIsUs-Win64-Shipping.exe" + 3453EC3 - 48 8D 42 60 - lea rax, [rdx + 60]
//"HellIsUs-Win64-Shipping.exe" + 3453EC7 - 48 83 C1 60 - add rcx, 60
if (!FOVOtheraddress)
logger->warn("FOV others ratio signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
if (!Aspectaddress)
logger->warn("Aspect ratio ratio signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
logger->info("FOV others signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(FOVOtheraddress));
FOVOtheraddress += 0x0a;
Aspectaddress = FOVOtheraddress + 0x0b;
logger->info("Aspect ratio signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Aspectaddress));
Aspectaddress = Aspectaddress + 0x8b;
}
}
@@ -178,7 +176,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
logger->info("--------------- AOB scan finished ---------------");
}
if (g_fix_enabled) {
if (FOVaddress) FOVFixEnabled(g_FOV_fix_enabled);
if (FOVaddress) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled);
if (Aspectaddress) AspectFixEnabled(g_aspect_fix_enabled);
if (DOFaddress) DOFFixEnabled(g_DOF_fix_enabled);
if (CAaddress) CAFixEnabled(g_CA_fix_enabled);
@@ -199,8 +197,8 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
// Setters for Reshade addon call
extern "C" __declspec(dllexport) void SetFOVFixEnabled(bool enabled, bool init)
{
g_FOV_fix_enabled = enabled;
if (!init) FOVFixEnabled(g_FOV_fix_enabled);
g_fov_fix_enabled = enabled;
if (!init) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled);
}
extern "C" __declspec(dllexport) void SetAspectRatioFixEnabled(bool enabled, bool init)
@@ -254,7 +252,11 @@ static void FOVFixEnabled(bool fix_enabled) {
FOVHook = safetyhook::create_mid(FOVaddress,
[](SafetyHookContext& ctx) {
g_FOV_In = ctx.xmm0.f32[0];
g_FOV_Out = ctx.xmm0.f32[0] += (g_FOV_fix_enabled ? g_AdditionalFOVValue : 0);
if (g_aspect_fix_enabled)
g_Compensated_FOV = ctx.xmm0.f32[0] = Maths::CompensateHorizontalFOV(g_FOV_In, baseAspect, aspectRatio);
else
g_Compensated_FOV = ctx.xmm0.f32[0];
g_FOV_Out = ctx.xmm0.f32[0] += (g_fov_fix_enabled ? g_AdditionalFOVValue : 0);
});
}
else FOVHook.enable();
@@ -267,17 +269,7 @@ static void FOVFixEnabled(bool fix_enabled) {
}
static void AspectFixEnabled(bool fix_enabled) {
if (g_fix_enabled && fix_enabled && FOVOtheraddress && Aspectaddress) {
if (!FOVOtherHook) {
FOVOtherHook = safetyhook::create_mid(FOVOtheraddress,
[](SafetyHookContext& ctx) {
g_FOV_In = ctx.xmm0.f32[0];
ctx.xmm0.f32[0] = Maths::CompensateHorizontalFOV(g_FOV_In, baseAspect, aspectRatio)
- (g_FOV_fix_enabled ? g_AdditionalFOVValue : 0); // Compensated Menu and cutscenes FOV must not get additional World FOV
});
}
else FOVOtherHook.enable();
if (g_fix_enabled && fix_enabled && Aspectaddress) {
if (!AspectHook) {
AspectHook = safetyhook::create_mid(Aspectaddress,
[](SafetyHookContext& ctx) {
@@ -288,7 +280,6 @@ static void AspectFixEnabled(bool fix_enabled) {
logger->info("Aspect fix enabled");
}
if (!fix_enabled) {
if (FOVOtherHook) FOVOtherHook.disable();
if (AspectHook) AspectHook.disable();
logger->info("Aspect ratio fix disabled");
}