upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index a6f41e8d1..b75baf15f 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -49,9 +49,9 @@ const char* binding_name(rt::Binding b) {
49 49
50int usage() { 50int usage() {
51 std::fprintf(stderr, 51 std::fprintf(stderr,
52 "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--trace FILE]\n" 52 "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n"
53 " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--trace-d3d12] [--trace FILE]\n" 53 " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n"
54 " gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n"); 54 " gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n");
55 return 2; 55 return 2;
56} 56}
57 57
@@ -61,6 +61,7 @@ int wmain(int argc, wchar_t** argv) {
61 std::filesystem::path image, game_dir, overlay_dir, mods_dir; 61 std::filesystem::path image, game_dir, overlay_dir, mods_dir;
62 uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash 62 uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash
63 int archetype_lookup_arg = 0; 63 int archetype_lookup_arg = 0;
64 uint32_t view_mode_getter_rva = 0; // --view-mode-getter RVA: the game's view mode of a camera context
64 bool dry_run = false, init = false, run = false, trace_d3d12 = false; 65 bool dry_run = false, init = false, run = false, trace_d3d12 = false;
65 std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84) 66 std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84)
66 std::wstring trace_file; 67 std::wstring trace_file;
@@ -78,6 +79,12 @@ int wmain(int argc, wchar_t** argv) {
78 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i]; 79 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i];
79 else if (a == L"--overlay" && i + 1 < argc) overlay_dir = argv[++i]; 80 else if (a == L"--overlay" && i + 1 < argc) overlay_dir = argv[++i];
80 else if (a == L"--mods" && i + 1 < argc) mods_dir = argv[++i]; 81 else if (a == L"--mods" && i + 1 < argc) mods_dir = argv[++i];
82 else if (a == L"--view-mode-getter" && i + 1 < argc) {
83 wchar_t* end = nullptr;
84 const unsigned long rva = std::wcstoul(argv[++i], &end, 16);
85 if (!end || *end || rva == 0) return usage();
86 view_mode_getter_rva = static_cast<uint32_t>(rva);
87 }
81 else if (a == L"--archetype-lookup" && i + 1 < argc) { 88 else if (a == L"--archetype-lookup" && i + 1 < argc) {
82 const std::wstring v = argv[++i]; 89 const std::wstring v = argv[++i];
83 const auto comma = v.find(L','); 90 const auto comma = v.find(L',');
@@ -127,6 +134,12 @@ int wmain(int argc, wchar_t** argv) {
127 sw.from, sw.to_name.c_str(), sw.to); 134 sw.from, sw.to_name.c_str(), sw.to);
128 } 135 }
129 leonida::mods::set_active(leonida::mods::ArchetypeSwaps(mods.mods)); 136 leonida::mods::set_active(leonida::mods::ArchetypeSwaps(mods.mods));
137 const leonida::mods::CameraView camera = leonida::mods::camera_of(mods.mods);
138 leonida::mods::set_active_camera(camera);
139 if (camera.first_person)
140 std::fprintf(stderr, "[rt] mods: first-person view (value %u) for %s%s\n", camera.first_person_value,
141 camera.contexts.empty() ? "every context" : "the listed contexts",
142 view_mode_getter_rva ? "" : "; not applied: no --view-mode-getter RVA for this executable");
130 if (leonida::mods::active().size()) 143 if (leonida::mods::active().size())
131 std::fprintf(stderr, archetype_lookup_rva ? "[rt] mods: %zu archetype swap(s) loaded\n" 144 std::fprintf(stderr, archetype_lookup_rva ? "[rt] mods: %zu archetype swap(s) loaded\n"
132 : "[rt] mods: %zu archetype swap(s) loaded; not applied: no --archetype-lookup RVA for " 145 : "[rt] mods: %zu archetype swap(s) loaded; not applied: no --archetype-lookup RVA for "
@@ -144,6 +157,16 @@ int wmain(int argc, wchar_t** argv) {
144 rt::Module& main_module = loader.load(image); // maps, binds and installs TLS; runs no image code 157 rt::Module& main_module = loader.load(image); // maps, binds and installs TLS; runs no image code
145 // The mods' archetype swaps (docs/modding.md): hooked here, before any image code runs, when the lookup's RVA 158 // The mods' archetype swaps (docs/modding.md): hooked here, before any image code runs, when the lookup's RVA
146 // for this executable is given. The count of redirected calls shows whether the RVA is the real lookup. 159 // for this executable is given. The count of redirected calls shows whether the RVA is the real lookup.
160 if (view_mode_getter_rva) {
161 const auto r = leonida::hooks::hook_image_results(main_module.base, view_mode_getter_rva,
162 &leonida::mods::override_view_mode);
163 if (r.ok)
164 std::fprintf(stderr, "[rt] mods: view-mode getter at RVA 0x%X hooked: %zu direct call(s) redirected\n",
165 view_mode_getter_rva, r.redirected);
166 else
167 std::fprintf(stderr, "[rt] mods: view-mode getter at RVA 0x%X not hooked: %s\n", view_mode_getter_rva,
168 r.error);
169 }
147 if (archetype_lookup_rva) { 170 if (archetype_lookup_rva) {
148 const auto r = leonida::hooks::hook_image_calls( 171 const auto r = leonida::hooks::hook_image_calls(
149 main_module.base, archetype_lookup_rva, 172 main_module.base, archetype_lookup_rva,