diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:14:27 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:14:27 -0500 |
| commit | 98fa503f8a19c3ed65df1f4f2f0e4571aa42c4f7 (patch) | |
| tree | 9f17c922e8deebaa4d0cd0a8eb59125349f5bda0 /runtime/test | |
| parent | 0db7fed551c4d48d7b97a9c4d609fc11d17ae19c (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test')
| -rw-r--r-- | runtime/test/code_hooks_test.cpp | 23 | ||||
| -rw-r--r-- | runtime/test/mods_test.cpp | 28 |
2 files changed, 51 insertions, 0 deletions
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() { | |||
| 100 | check(!hook_image_calls(self, 0, &remap_lucia, 0).ok, "an RVA in the headers (not code) is refused"); | 100 | check(!hook_image_calls(self, 0, &remap_lucia, 0).ok, "an RVA in the headers (not code) is refused"); |
| 101 | check(!make_remap_thunk(target0, 2, &remap_lucia, target0), "only argument 0 or 1 can be remapped"); | 101 | check(!make_remap_thunk(target0, 2, &remap_lucia, target0), "only argument 0 or 1 can be remapped"); |
| 102 | 102 | ||
| 103 | // The result-override thunk (a view-mode getter): the original returns 2 ("third person, far") for every | ||
| 104 | // context; the override answers 4 ("first person") for context 0 only and leaves the others as they were. | ||
| 105 | uint8_t* getter = mem + 512; | ||
| 106 | put(getter, {0xB8, 0x02, 0x00, 0x00, 0x00, 0xC3}); // mov eax, 2 ; ret | ||
| 107 | uint8_t* call_getter = mem + 544; | ||
| 108 | caller(call_getter, getter); | ||
| 109 | static int original_calls = 0; | ||
| 110 | auto first_person_on_foot = [](uint32_t result, uint32_t context) -> uint32_t { | ||
| 111 | ++original_calls; | ||
| 112 | return context == 0 ? 4u : result; | ||
| 113 | }; | ||
| 114 | uint8_t* rthunk = make_result_thunk(getter, first_person_on_foot, getter); | ||
| 115 | check(rthunk != nullptr, "a result thunk is allocated"); | ||
| 116 | if (rthunk) { | ||
| 117 | check(redirect_direct_branches(call_getter, 16, getter, rthunk) == 1, "the getter's caller is redirected"); | ||
| 118 | FlushInstructionCache(GetCurrentProcess(), mem, 4096); | ||
| 119 | using Ctx = uint32_t (*)(uint32_t); | ||
| 120 | check(reinterpret_cast<Ctx>(call_getter)(0) == 4, "context 0 gets the overridden result"); | ||
| 121 | check(reinterpret_cast<Ctx>(call_getter)(3) == 2, "another context keeps the original's result"); | ||
| 122 | check(original_calls == 2, "the override sees every call, after the original ran"); | ||
| 123 | } | ||
| 124 | check(!hook_image_results(mem, 0, first_person_on_foot).ok, "hook_image_results refuses memory without a PE"); | ||
| 125 | |||
| 103 | std::printf("code_hooks_test: %d checks, %d failures\n", g_checks, g_failures); | 126 | std::printf("code_hooks_test: %d checks, %d failures\n", g_checks, g_failures); |
| 104 | return g_failures == 0 ? 0 : 1; | 127 | return g_failures == 0 ? 0 : 1; |
| 105 | } | 128 | } |
diff --git a/runtime/test/mods_test.cpp b/runtime/test/mods_test.cpp index d6d369426..c61182c3c 100644 --- a/runtime/test/mods_test.cpp +++ b/runtime/test/mods_test.cpp | |||
| @@ -56,6 +56,34 @@ int main() { | |||
| 56 | check(!parse_mod("[1,2]", "m", mod, error), "a manifest that is not an object is refused"); | 56 | check(!parse_mod("[1,2]", "m", mod, error), "a manifest that is not an object is refused"); |
| 57 | check(parse_mod("{}", "folder_name", mod, error) && mod.name == "folder_name", "the name defaults to the folder"); | 57 | check(parse_mod("{}", "folder_name", mod, error) && mod.name == "folder_name", "the name defaults to the folder"); |
| 58 | 58 | ||
| 59 | // "camera": first-person view (docs/modding.md, "First-person view") | ||
| 60 | check(parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":4,"contexts":[0]}})", "fp", mod, | ||
| 61 | error) && mod.camera.set && mod.camera.first_person && mod.camera.first_person_value == 4 && | ||
| 62 | mod.camera.contexts.size() == 1 && mod.camera.contexts[0] == 0, | ||
| 63 | "a first-person camera section parses"); | ||
| 64 | check(parse_mod(R"({"camera":{"view_mode":"default"}})", "d", mod, error) && mod.camera.set && | ||
| 65 | !mod.camera.first_person, | ||
| 66 | "\"default\" leaves the game's view mode"); | ||
| 67 | check(!parse_mod(R"({"camera":{"view_mode":"top_down"}})", "x", mod, error), "an unknown view mode is refused"); | ||
| 68 | check(!parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":4.5}})", "x", mod, error), | ||
| 69 | "a fractional enum value is refused"); | ||
| 70 | check(!parse_mod(R"({"camera":{"view_mode":"first_person","contexts":"all"}})", "x", mod, error), | ||
| 71 | "contexts must be a list"); | ||
| 72 | |||
| 73 | Mod fp_on_foot, fp_everywhere, off; | ||
| 74 | check(parse_mod(R"({"camera":{"view_mode":"first_person","contexts":[0]}})", "a", fp_on_foot, error) && | ||
| 75 | parse_mod(R"({"camera":{"view_mode":"first_person","first_person_value":7}})", "b", fp_everywhere, | ||
| 76 | error) && | ||
| 77 | parse_mod(R"({"enabled":false,"camera":{"view_mode":"default"}})", "c", off, error), | ||
| 78 | "three camera mods parse"); | ||
| 79 | set_active_camera(camera_of({fp_on_foot})); | ||
| 80 | check(override_view_mode(2, 0) == 4, "on foot (context 0) the view becomes first person"); | ||
| 81 | check(override_view_mode(2, 1) == 2, "a context the mod does not list keeps the game's view"); | ||
| 82 | set_active_camera(camera_of({fp_on_foot, fp_everywhere, off})); | ||
| 83 | check(override_view_mode(1, 5) == 7, "the last enabled camera mod decides (a disabled one is skipped)"); | ||
| 84 | set_active_camera(camera_of({})); | ||
| 85 | check(override_view_mode(3, 0) == 3, "with no camera mod the game's view mode passes through"); | ||
| 86 | |||
| 59 | const auto dir = std::filesystem::temp_directory_path() / "leonida_mods_test"; | 87 | const auto dir = std::filesystem::temp_directory_path() / "leonida_mods_test"; |
| 60 | std::filesystem::remove_all(dir); | 88 | std::filesystem::remove_all(dir); |
| 61 | write(dir / "a_mandy" / "mod.json", | 89 | write(dir / "a_mandy" / "mod.json", |