From 606299fe765f091f3eb001adf36d69438aa49d1d Mon Sep 17 00:00:00 2001 From: Disquse Date: Fri, 26 Jan 2024 18:26:33 +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 | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/code/components/gta-core-five/src/DisableCameraShake.cpp b/code/components/gta-core-five/src/DisableCameraShake.cpp index b435800370..17caa73b72 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 -static std::shared_ptr> g_cameraShakeConvar; +#include "Hooking.Stubs.h" -static void CameraShakeOverride() +static bool g_disableCameraShake; + +static void (*g_origUpdateCameraVehicleHighSpeedShake)(void*); +static void UpdateCameraVehicleHighSpeedShake(void* a1) { - if (g_cameraShakeConvar->GetValue()) + if (!g_disableCameraShake) { - //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_disableCameraShake) + { + g_origUpdateCameraPedRunningShake(a1, a2, a3); } } static InitFunction initFunction([]() { - g_cameraShakeConvar = std::make_shared>("cam_disableCameraShake", ConVar_Archive, false); + static ConVar disableCameraShakeVar("cam_disableCameraShake", ConVar_Archive, false, &g_disableCameraShake); +}); + +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); + } });