From 98fa503f8a19c3ed65df1f4f2f0e4571aa42c4f7 Mon Sep 17 00:00:00 2001 From: ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:14:27 -0500 Subject: Mods: first-person view, the base (camera section, view-mode getter hook) mod.json gains "camera": {"view_mode": "first_person"|"default", "first_person_value", "contexts"}. gta6rt --view-mode-getter RVA hooks the game's view-mode getter with a result-override thunk (code_hooks.h: the original runs, then its result and first argument go through leonida::mods::override_view_mode), so the listed contexts answer first person and the others keep the game's mode. mods/first_person asks for it on foot. docs/modding.md records why switching a mode is enough: the game's tuning data refers to a first-person view (FirstPersonDirectionDot, UseFirstPersonCameraMatrix on cloth capsules, FIRST_PERSON_VIEW hit-reaction recovery, a firstpersonshooter HUD texture; RDR2's engine branch), while GTA V's camera class names are not present by joaat. The context numbering and the first-person enum value (4, GTA V's) are manifest settings to confirm in the executable. ctest mods and code_hooks cover the parser, the override and the thunk on x64 code in memory. Co-Authored-By: Claude Opus 5.5 --- runtime/test/code_hooks_test.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'runtime/test/code_hooks_test.cpp') diff --git a/runtime/test/code_hooks_test.cpp b/runtime/test/code_hooks_test.cpp index 6c1fb4fb1..cb5e266da 100644 --- a/runtime/test/code_hooks_test.cpp +++ b/runtime/test/code_hooks_test.cpp @@ -100,6 +100,29 @@ int main() { check(!hook_image_calls(self, 0, &remap_lucia, 0).ok, "an RVA in the headers (not code) is refused"); check(!make_remap_thunk(target0, 2, &remap_lucia, target0), "only argument 0 or 1 can be remapped"); + // The result-override thunk (a view-mode getter): the original returns 2 ("third person, far") for every + // context; the override answers 4 ("first person") for context 0 only and leaves the others as they were. + uint8_t* getter = mem + 512; + put(getter, {0xB8, 0x02, 0x00, 0x00, 0x00, 0xC3}); // mov eax, 2 ; ret + uint8_t* call_getter = mem + 544; + caller(call_getter, getter); + static int original_calls = 0; + auto first_person_on_foot = [](uint32_t result, uint32_t context) -> uint32_t { + ++original_calls; + return context == 0 ? 4u : result; + }; + uint8_t* rthunk = make_result_thunk(getter, first_person_on_foot, getter); + check(rthunk != nullptr, "a result thunk is allocated"); + if (rthunk) { + check(redirect_direct_branches(call_getter, 16, getter, rthunk) == 1, "the getter's caller is redirected"); + FlushInstructionCache(GetCurrentProcess(), mem, 4096); + using Ctx = uint32_t (*)(uint32_t); + check(reinterpret_cast(call_getter)(0) == 4, "context 0 gets the overridden result"); + check(reinterpret_cast(call_getter)(3) == 2, "another context keeps the original's result"); + check(original_calls == 2, "the override sees every call, after the original ran"); + } + check(!hook_image_results(mem, 0, first_person_on_foot).ok, "hook_image_results refuses memory without a PE"); + std::printf("code_hooks_test: %d checks, %d failures\n", g_checks, g_failures); return g_failures == 0 ? 0 : 1; } -- cgit v1.2.3