diff --git a/SilentHillF/dllmain.cpp b/SilentHillF/dllmain.cpp index 2738323..a9f17db 100644 --- a/SilentHillF/dllmain.cpp +++ b/SilentHillF/dllmain.cpp @@ -9,8 +9,6 @@ #include "UEngine.hpp"; #include "SDK/Basic.hpp" #include "SDK/Engine_classes.hpp" -//#include "SDK/BP_Pl_Base_NocePlayerCharacter_classes.hpp" -//#include "SDK/AdvancedThirdPersonCamera_classes.hpp" using namespace SDK; @@ -38,6 +36,7 @@ static bool g_Vignetting_fix_enabled = false; static bool g_Fog_fix_enabled = false; static bool g_Camera_fix_enabled = false; static int g_AdditionalFOVValue = 0; +static float g_CameraDistance = 1.f; // Shared values static float g_reference_FOV = 65.f; @@ -53,7 +52,6 @@ static uint8_t* ProcessEventaddress = nullptr; // AOB Scan pointers static uint8_t* FOVaddress = nullptr; -static uint8_t* referenceFOVaddress = nullptr; static uint8_t* DOFaddress = nullptr; static uint8_t* CAaddress = nullptr; static uint8_t* Vignettingaddress = nullptr; @@ -62,7 +60,6 @@ static uint8_t* Cameraaddress = nullptr; // Hooking static SafetyHookMid FOVHook{}; -static SafetyHookMid referenceFOVHook{}; static SafetyHookMid VolumetricFogHook{}; static SafetyHookMid HUDHook{}; static SafetyHookMid CameraHook{}; @@ -82,37 +79,18 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled) if (g_fix_enabled && !AOBScanDone) { logger->info("--------------- AOB scan started ---------------"); if (FOVaddress == nullptr) { - constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("77 ?? 48 ?? ?? FF ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 48"); + constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("F3 0F ?? ?? 0F 28 ?? ?? ?? F3 0F ?? ?? ?? F3 0F 11 ?? ?? ?? ?? ?? ?? 45"); FOVaddress = Memory::AOBScan(gameExecutable, FOVStringObfuscated.decrypt(), PAGE_EXECUTE_READ); - //"SHf-Win64-Shipping.exe" + 3AE6514 - 48 8B 01 - mov rax, [rcx] - //"SHf-Win64-Shipping.exe" + 3AE6517 - FF 90 50 07 00 00 - call qword ptr[rax + 00000750] - //"SHf-Win64-Shipping.exe" + 3AE651D - F3 0F 10 40 30 - movss xmm0, [rax + 30] - //"SHf-Win64-Shipping.exe" + 3AE6522 - 48 83 C4 28 - add rsp, 28 - //"SHf-Win64-Shipping.exe" + 3AE6526 - C3 - ret + //"SHf-Win64-Shipping.exe" + 48917E2 - 48 8B AC 24 A8 00 00 00 - mov rbp, [rsp + 000000A8] + //"SHf-Win64-Shipping.exe" + 48917EA - F3 0F 58 B7 98 02 00 00 - addss xmm6, [rdi + 00000298] + //"SHf-Win64-Shipping.exe" + 48917F2 - F3 0F 58 F7 - addss xmm6, xmm7 + //"SHf-Win64-Shipping.exe" + 48917F6 - 0F 28 7C 24 60 - movaps xmm7, [rsp + 60] + //"SHf-Win64-Shipping.exe" + 48917FB - F3 0F 58 76 30 - addss xmm6, [rsi + 30] if (!FOVaddress) logger->warn("FOV signature not found. Maybe your game has been updated and is no more compatible with this plugin."); else { logger->info("FOV signature found at address: 0x{:X}.", reinterpret_cast(FOVaddress)); - FOVaddress += 0x10; - } - } - - if (referenceFOVaddress == nullptr) { - //constexpr auto referenceFOVStringObfuscated = make_obfuscated<0x4A>("F3 0F ?? ?? 49 83 ?? ?? ?? 0F 84 ?? ?? ?? ?? 48 8D"); - constexpr auto referenceFOVStringObfuscated = make_obfuscated<0x4A>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83 ?? ?? ?? ?? 89"); - referenceFOVaddress = Memory::AOBScan(gameExecutable, referenceFOVStringObfuscated.decrypt(), PAGE_EXECUTE_READ); - //"SHf-Win64-Shipping.exe" + 3493A5E - EB 08 - jmp "SHf-Win64-Shipping.exe" + 3493A68 - //"SHf-Win64-Shipping.exe" + 3493A60 - F3 0F 10 83 30 02 00 00 - movss xmm0, [rbx + 00000230] - //"SHf-Win64-Shipping.exe" + 3493A68 - F3 0F 11 47 30 - movss[rdi + 30], xmm0 - //"SHf-Win64-Shipping.exe" + 3493A6D - 8B 83 4C 02 00 00 - mov eax, [rbx + 0000024C] - //"SHf-Win64-Shipping.exe" + 3493A73 - 89 47 54 - mov[rdi + 54], eax - - if (!referenceFOVaddress) - logger->warn("Reference FOV signature not found. Maybe your game has been updated and is no more compatible with this plugin."); - else { - logger->info("Reference FOV signature found at address: 0x{:X}.", reinterpret_cast(referenceFOVaddress)); - referenceFOVaddress += 0xa; } } @@ -167,7 +145,6 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled) if (VolumetricFogaddress == nullptr) { constexpr auto FogStringObfuscated = make_obfuscated<0x4A>("0F 84 ?? ?? ?? ?? F6 ?? ?? ?? 0F 84 ?? ?? ?? ?? 83 BF"); - //constexpr auto FogStringObfuscated = make_obfuscated<0x4A>("F7 44 ?? ?? ?? ?? ?? ?? 74 ?? 48 8B ?? ?? ?? ?? ?? 83 78 ?? ?? 75 ?? B3 ?? EB ?? 32 ?? 48 8B"); VolumetricFogaddress = Memory::AOBScan(gameExecutable, FogStringObfuscated.decrypt(), PAGE_EXECUTE_READ); //"SHf-Win64-Shipping.exe" + 2174B8A - E8 51 73 F0 FE - call "SHf-Win64-Shipping.exe" + 107BEE0 //"SHf-Win64-Shipping.exe" + 2174B8F - 0F B6 C3 - movzx eax, bl @@ -182,21 +159,23 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled) } } - //if (Cameraaddress == nullptr) { // Low level function involved in displaying Widgets in real time - // constexpr auto CameraStringObfuscated = make_obfuscated<0x4A>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 41 ?? 41 ?? 48 83 ?? ?? 4C 8B ?? ?? 49 ?? ?? 48 ?? ?? 48"); - // //constexpr auto CameraStringObfuscated = make_obfuscated<0x4A>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 41 ?? 41 ?? 48 83 ?? ?? 4C 8B ?? ?? 49 ?? ?? 48 ?? ?? 48 ?? ?? 45"); // UseCustomCamera - // //constexpr auto CameraStringObfuscated = make_obfuscated<0x4A>("FF 95 ?? ?? ?? ?? 48 8B ?? ?? ?? 48 8B ?? ?? ?? 48 89"); // After all camera - // //constexpr auto CameraStringObfuscated = make_obfuscated<0x4A>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 41 ?? 41 ?? 48 83 ?? ?? 4C 8B ?? ?? 49 ?? ?? 48"); // K2_OnEnterCameraMode - // Cameraaddress = Memory::AOBScan(gameExecutable, CameraStringObfuscated.decrypt(), PAGE_EXECUTE_READ); + if (Cameraaddress == nullptr) { // Low level function involved in displaying Widgets in real time + constexpr auto CameraStringObfuscated = make_obfuscated<0x4A>("41 0F ?? ?? 48 8D ?? ?? ?? 48 8D ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? F3 0F"); + Cameraaddress = Memory::AOBScan(gameExecutable, CameraStringObfuscated.decrypt(), PAGE_EXECUTE_READ); + //"SHf-Win64-Shipping.exe" + 488F5F5 - F3 0F 11 86 CC 01 00 00 - movss[rsi + 000001CC], xmm0 + //"SHf-Win64-Shipping.exe" + 488F5FD - 4D 8D 8E B4 00 00 00 - lea r9, [r14 + 000000B4] + //"SHf-Win64-Shipping.exe" + 488F604 - F3 0F 58 86 C0 01 00 00 - addss xmm0, [rsi + 000001C0] + //"SHf-Win64-Shipping.exe" + 488F60C - 41 0F 28 D0 - movaps xmm2, xmm8 + //"SHf-Win64-Shipping.exe" + 488F610 - 48 8D 54 24 60 - lea rdx, [rsp + 60] - // if (!Cameraaddress) - // logger->warn("Camera signature not found. Maybe your game has been updated and is no more compatible with this plugin."); - // else { - // logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast(Cameraaddress)); - // } - //} + if (!Cameraaddress) + logger->warn("Camera signature not found. Maybe your game has been updated and is no more compatible with this plugin."); + else { + logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast(Cameraaddress)); + } + } - if (FOVaddress && referenceFOVaddress && DOFaddress && CAaddress && Vignettingaddress && VolumetricFogaddress) { + if (FOVaddress && DOFaddress && CAaddress && Vignettingaddress && VolumetricFogaddress) { logger->info("All AOB signatures found. Ready to patch..."); AOBScanDone = true; } @@ -253,7 +232,8 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled) logger->info("-------------- Fixes initialisation -------------"); } - if (FOVaddress && referenceFOVaddress) FOVFixEnabled(); + if (FOVaddress) FOVFixEnabled(); + if (Cameraaddress) CameraFixEnabled(); if (DOFaddress) DOFFixEnabled(); if (CAaddress) CAFixEnabled(); if (Vignettingaddress) VignettingFixEnabled(); @@ -266,9 +246,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled) extern "C" __declspec(dllexport) void SetFOVFixEnabled(bool enabled, bool init) { g_fov_fix_enabled = enabled; - if (!init) { - FOVFixEnabled(); - } + if (!init) FOVFixEnabled(); } extern "C" __declspec(dllexport) void SetDOFFixEnabled(bool enabled, bool init) @@ -297,6 +275,7 @@ extern "C" __declspec(dllexport) void SetFogFixEnabled(bool enabled, bool init) extern "C" __declspec(dllexport) void SetCameraFixEnabled(bool enabled, bool init) { + g_Camera_fix_enabled = enabled; if (!init) CameraFixEnabled(); } @@ -306,6 +285,10 @@ extern "C" __declspec(dllexport) void SetFOV(int fov) g_AdditionalFOVValue = fov; } +extern "C" __declspec(dllexport) void SetCameraDistance(float multiplier) { + g_CameraDistance = multiplier; +} + // Getters for Reshade addon call extern "C" __declspec(dllexport) float GetFOVIn() { return g_FOV_In; @@ -320,63 +303,40 @@ extern "C" __declspec(dllexport) bool GetConsoleEnabled() { } // Code injection functions -// FOV compensation only static void FOVFixEnabled() { - if (g_fix_enabled && g_fov_fix_enabled && FOVaddress && referenceFOVaddress) { + if (g_fix_enabled && g_fov_fix_enabled && FOVaddress) { if (!FOVHook) { // Hook only once FOVHook = safetyhook::create_mid(FOVaddress, [](SafetyHookContext& ctx) { - g_FOV_In = g_reference_FOV; - ctx.xmm0.f32[0] = (g_fix_enabled && g_fov_fix_enabled ? g_reference_FOV + g_AdditionalFOVValue : g_reference_FOV); - g_FOV_Out = ctx.xmm0.f32[0]; + g_FOV_In = ctx.xmm6.f32[0]; + ctx.xmm6.f32[0] += (g_fix_enabled && g_fov_fix_enabled ? g_AdditionalFOVValue : g_FOV_In); + g_FOV_Out = ctx.xmm6.f32[0]; }); } else FOVHook.enable(); - if (!referenceFOVHook) { - referenceFOVHook = safetyhook::create_mid(referenceFOVaddress, - [](SafetyHookContext& ctx) { - g_reference_FOV = ctx.xmm0.f32[0]; - }); - } - else referenceFOVHook.enable(); - logger->info("FOV fix enabled"); } - if (!(g_fix_enabled && g_fov_fix_enabled) && FOVaddress && referenceFOVaddress) { + if (!(g_fix_enabled && g_fov_fix_enabled) && FOVaddress) { if (FOVHook) FOVHook.disable(); - if (referenceFOVHook) referenceFOVHook.disable(); logger->info("FOV fix disabled"); } } -UObject* widgetObject = nullptr; -std::string widgetName; - static void CameraFixEnabled() { - if (Cameraaddress) { + if (g_fix_enabled && g_Camera_fix_enabled && Cameraaddress) { if (!CameraHook) { CameraHook = safetyhook::create_mid(Cameraaddress, [](SafetyHookContext& ctx) { - //ABP_Pl_Base_NocePlayerCharacter_C* MyChar = (ABP_Pl_Base_NocePlayerCharacter_C*)ctx.rcx; - //UATPCCameraBaseObject* camObj = reinterpret_cast(ctx.rcx); - - //if (!camObj) return; - //if (!camObj->OwningCamera) return; - //if (!camObj->OwningCamera->LocationObject) return; - - //camObj->OwningCamera->LocationObject->SetCameraDistance(500.f, true); - //camObj->OwningCamera->SetCameraDistance(500.f, true); - //logger->debug("camera set"); - //if (MyChar && MyChar->IsA(ABP_Pl_Base_NocePlayerCharacter_C::StaticClass()) && MyChar->SweetLightSpringArm) { - // logger->debug("Arm length: {}", MyChar->SweetLightSpringArm->TargetArmLength); - // MyChar->SweetLightSpringArm->TargetArmLength = 600.f; - // //float* TargetArmPtr = &MyChar->SweetLightSpringArm->TargetArmLength; - // //logger->debug("TargetArmLength pointer address: {:X}", (uintptr_t)TargetArmPtr); - - //} + ctx.xmm0.f32[0] *= g_CameraDistance; }); } + else CameraHook.enable(); + logger->info("Camera fix enabled"); + } + if (!(g_fix_enabled && g_Camera_fix_enabled) && Cameraaddress) { + if (CameraHook) CameraHook.disable(); + logger->info("Camera fix disabled"); } }