Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework camera shake toggle convar in FiveM #2360

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 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>

static std::shared_ptr<ConVar<bool>> 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<ConVar<bool>>("cam_disableCameraShake", ConVar_Archive, false);
static ConVar<bool> 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);
}
});
Loading