Skip to content

Commit

Permalink
tweak(core/five): rework camera shake toggle convar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Disquse committed Jan 24, 2024
1 parent eac42c1 commit 1521290
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions code/components/gta-core-five/src/DisableCameraShake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,45 @@
*/

#include <StdInc.h>
#include <GameInit.h>
#include <Hooking.h>
#include <CoreConsole.h>
#include <nutsnbolts.h>

#include "Hooking.Stubs.h"

static std::shared_ptr<ConVar<bool>> 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<ConVar<bool>>("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);
}
});

0 comments on commit 1521290

Please sign in to comment.