From 1521290c06e139295147a05c6eee553e40e3f63b Mon Sep 17 00:00:00 2001 From: Disquse Date: Wed, 24 Jan 2024 13:29:45 +0300 Subject: [PATCH] tweak(core/five): rework camera shake toggle convar The way how this functionality was implemented before is very fragile and got broken in b3095. The one-way nopping was also breaking the ability to disable this option after disconnecting from a server. So it was decided to rework it a bit. --- .../gta-core-five/src/DisableCameraShake.cpp | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/code/components/gta-core-five/src/DisableCameraShake.cpp b/code/components/gta-core-five/src/DisableCameraShake.cpp index b435800370..9db1ef1e45 100644 --- a/code/components/gta-core-five/src/DisableCameraShake.cpp +++ b/code/components/gta-core-five/src/DisableCameraShake.cpp @@ -6,40 +6,45 @@ */ #include -#include #include #include -#include + +#include "Hooking.Stubs.h" static std::shared_ptr> g_cameraShakeConvar; -static void CameraShakeOverride() +static void (*g_origUpdateCameraVehicleHighSpeedShake)(void*); +static void UpdateCameraVehicleHighSpeedShake(void* a1) { - if (g_cameraShakeConvar->GetValue()) + if (!g_cameraShakeConvar->GetValue()) { - //Vehicle high speed camera shake - //48 8B D9 mov rbx, rcx - //48 81 C7 88 04 00 00 add rdi, 488h <-------------- - //8B 6F 08 mov ebp, [rdi+8] - - hook::nop(hook::get_pattern("48 8B D9 48 81 C7 ? ? ? ? 8B ? ? 85 ?", 3), 7); - - //Ped running camera shake - //0F 29 70 E8 movaps xmmword ptr[rax - 18h], xmm6 - //0F 29 78 D8 movaps xmmword ptr [rax-28h], xmm7 - //48 81 C7 08 08 00 00 add rdi, 808h <-------------- - //48 8B F1 mov rsi, rcx + g_origUpdateCameraVehicleHighSpeedShake(a1); + } +} - hook::nop(hook::get_pattern("57 48 81 EC ? ? ? ? 48 8B B9 ? ? ? ? 0F 29 70 E8 0F 29 78 D8 48 81 C7 ? ? ? ?", 23), 7); +static void (*g_origUpdateCameraPedRunningShake)(void*, void*, void*); +static void UpdateCameraPedRunningShake(void* a1, void* a2, void* a3) +{ + if (!g_cameraShakeConvar->GetValue()) + { + g_origUpdateCameraPedRunningShake(a1, a2, a3); } } static InitFunction initFunction([]() { g_cameraShakeConvar = std::make_shared>("cam_disableCameraShake", ConVar_Archive, false); +}); + +static HookFunction hookFunction([] +{ + { + auto location = hook::get_pattern("48 8B D9 48 81 C7 ? ? ? ? 8B ? ? 85", -31); + g_origUpdateCameraVehicleHighSpeedShake = hook::trampoline(location, UpdateCameraVehicleHighSpeedShake); + } - OnFirstLoadCompleted.Connect([]() { - CameraShakeOverride(); - }); + auto location = hook::get_pattern("57 48 81 EC ? ? ? ? 48 8B B9 ? ? ? ? 0F 29 70 E8 0F 29 78 D8 48 81 C7", -11); + g_origUpdateCameraPedRunningShake = hook::trampoline(location, UpdateCameraPedRunningShake); + } });