diff options
| author | Moriz82 <72836413+Moriz82@users.noreply.github.com> | 2026-11-25 03:44:31 -0600 |
|---|---|---|
| committer | Moriz82 <72836413+Moriz82@users.noreply.github.com> | 2026-11-25 03:44:43 -0600 |
| commit | ba626820ec54776fb0faffa2413727285befe85b (patch) | |
| tree | 95a99f8029785bec5f3b07b7efc4277e5bc7510b /runtime/src/main.cpp | |
| parent | 3de22a19047b168d28a7a11152bf05d18ed0062e (diff) | |
Integrate post-story-load memory, queue and Vulkan runtime changes
Preserve physical window aliases across remaps, order console list values,
and replay bounded indirect graphics with captured draw state. Coordinate
pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU
and GPU coverage for the integrated paths.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 8e3767740..aec511414 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -72,7 +72,8 @@ void keep_title_watchdog_kicked(std::uint8_t* base) { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | // LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the | 74 | // LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the |
| 75 | // title's image (":n" = n consecutive values) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this | 75 | // title's image (":n" = n consecutive values, at most 32; "RVA>OFF" reads through the pointer stored at the RVA, at |
| 76 | // pointer + OFF, both hex) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this | ||
| 76 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly | 77 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly |
| 77 | // that. Reads are checked; nothing is written. | 78 | // that. Reads are checked; nothing is written. |
| 78 | void start_title_peek(std::uint8_t* base) { | 79 | void start_title_peek(std::uint8_t* base) { |
| @@ -93,15 +94,35 @@ void start_title_peek(std::uint8_t* base) { | |||
| 93 | char* end = nullptr; | 94 | char* end = nullptr; |
| 94 | const std::uint64_t rva = std::strtoull(at, &end, 16); | 95 | const std::uint64_t rva = std::strtoull(at, &end, 16); |
| 95 | if (end == at) break; | 96 | if (end == at) break; |
| 97 | // "RVA>OFF": the 8-byte pointer at the RVA, then the values at pointer + OFF (both hex). | ||
| 98 | bool deref = false; | ||
| 99 | std::uint64_t offset = 0; | ||
| 100 | if (*end == '>') { | ||
| 101 | deref = true; | ||
| 102 | offset = std::strtoull(end + 1, &end, 16); | ||
| 103 | } | ||
| 96 | unsigned count = 1; | 104 | unsigned count = 1; |
| 97 | if (*end == ':') count = static_cast<unsigned>(std::strtoul(end + 1, &end, 10)); | 105 | if (*end == ':') count = static_cast<unsigned>(std::strtoul(end + 1, &end, 10)); |
| 98 | char text[40]; | 106 | char text[48]; |
| 99 | std::snprintf(text, sizeof(text), " 0x%llx=", static_cast<unsigned long long>(rva)); | 107 | if (deref) |
| 108 | std::snprintf(text, sizeof(text), " 0x%llx>%llx=", static_cast<unsigned long long>(rva), | ||
| 109 | static_cast<unsigned long long>(offset)); | ||
| 110 | else | ||
| 111 | std::snprintf(text, sizeof(text), " 0x%llx=", static_cast<unsigned long long>(rva)); | ||
| 100 | line += text; | 112 | line += text; |
| 101 | for (unsigned i = 0; i < count && i < 16; ++i) { | 113 | const std::uint8_t* from = image + rva; |
| 114 | if (deref) { | ||
| 115 | std::uint64_t pointer = 0; | ||
| 116 | SIZE_T got = 0; | ||
| 117 | if (!ReadProcessMemory(GetCurrentProcess(), from, &pointer, sizeof(pointer), &got) || | ||
| 118 | got != sizeof(pointer) || !pointer) | ||
| 119 | count = 0, line += "?"; | ||
| 120 | from = reinterpret_cast<const std::uint8_t*>(pointer + offset); | ||
| 121 | } | ||
| 122 | for (unsigned i = 0; i < count && i < 32; ++i) { | ||
| 102 | std::uint64_t value = 0; | 123 | std::uint64_t value = 0; |
| 103 | SIZE_T got = 0; | 124 | SIZE_T got = 0; |
| 104 | const bool ok = ReadProcessMemory(GetCurrentProcess(), image + rva + 8ull * i, &value, | 125 | const bool ok = ReadProcessMemory(GetCurrentProcess(), from + 8ull * i, &value, |
| 105 | sizeof(value), &got) && got == sizeof(value); | 126 | sizeof(value), &got) && got == sizeof(value); |
| 106 | std::snprintf(text, sizeof(text), ok ? "%s%llx" : "%s?", i ? "," : "", | 127 | std::snprintf(text, sizeof(text), ok ? "%s%llx" : "%s?", i ? "," : "", |
| 107 | static_cast<unsigned long long>(value)); | 128 | static_cast<unsigned long long>(value)); |
| @@ -127,12 +148,14 @@ void start_title_peek(std::uint8_t* base) { | |||
| 127 | #include "mods.h" | 148 | #include "mods.h" |
| 128 | #include "pe_loader.h" | 149 | #include "pe_loader.h" |
| 129 | #include "thread_stacks.h" | 150 | #include "thread_stacks.h" |
| 151 | #include "thread_sampler.h" | ||
| 130 | #include "title_page_watch.h" | 152 | #include "title_page_watch.h" |
| 131 | #include "title_geometry_watch.h" | 153 | #include "title_geometry_watch.h" |
| 132 | #include "../shims/d3d12_trace.h" | 154 | #include "../shims/d3d12_trace.h" |
| 133 | #include "../shims/d3d12_xs_device.h" | 155 | #include "../shims/d3d12_xs_device.h" |
| 134 | #include "../shims/file_system.h" | 156 | #include "../shims/file_system.h" |
| 135 | #ifdef LEONIDA_VULKAN_DEVICE | 157 | #ifdef LEONIDA_VULKAN_DEVICE |
| 158 | #include "../shims/d3d12_compile_exit.h" | ||
| 136 | #include "../shims/package_splash.h" | 159 | #include "../shims/package_splash.h" |
| 137 | #endif | 160 | #endif |
| 138 | #include "../shims/process_shim.h" | 161 | #include "../shims/process_shim.h" |
| @@ -205,6 +228,18 @@ int usage() { | |||
| 205 | } // namespace | 228 | } // namespace |
| 206 | 229 | ||
| 207 | #ifdef LEONIDA_VULKAN_DEVICE | 230 | #ifdef LEONIDA_VULKAN_DEVICE |
| 231 | // The run ends with the title's Vulkan device alive, so no ~Device stops the background pipeline compiler: stop it | ||
| 232 | // here, before ExitProcess ends its thread, maybe inside the driver's compiler (rt::d3d12::stop_pipeline_compiles). | ||
| 233 | constexpr unsigned kExitCompileWaitMs = 2000; // a console close gives the whole process 5 s | ||
| 234 | |||
| 235 | static BOOL WINAPI stop_compiles_on_console_exit(DWORD event) { | ||
| 236 | if (event == CTRL_C_EVENT || event == CTRL_BREAK_EVENT || event == CTRL_CLOSE_EVENT) { | ||
| 237 | rt::d3d12_xs::stop_list_values(500); // as at the run's end: no list-value thread cut off inside the layer | ||
| 238 | rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); | ||
| 239 | } | ||
| 240 | return FALSE; // the next handler (the default one: ExitProcess) ends the process, as before | ||
| 241 | } | ||
| 242 | |||
| 208 | static BOOL WINAPI show_package_window(HWND window, int command) { | 243 | static BOOL WINAPI show_package_window(HWND window, int command) { |
| 209 | const BOOL previous = ShowWindow(window, command); | 244 | const BOOL previous = ShowWindow(window, command); |
| 210 | const DWORD error = GetLastError(); | 245 | const DWORD error = GetLastError(); |
| @@ -357,6 +392,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 357 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 392 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 358 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 393 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| 359 | rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); | 394 | rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); |
| 395 | leonida::kernel_writes::set_unguarder(&rt::xmem::reopen_unowned); | ||
| 360 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { | 396 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { |
| 361 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" | 397 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" |
| 362 | : "error: cannot create the trace file\n"); | 398 | : "error: cannot create the trace file\n"); |
| @@ -477,6 +513,10 @@ int wmain(int argc, wchar_t** argv) { | |||
| 477 | std::fflush(stdout); | 513 | std::fflush(stdout); |
| 478 | keep_title_watchdog_kicked(main_module.base); | 514 | keep_title_watchdog_kicked(main_module.base); |
| 479 | start_title_peek(main_module.base); | 515 | start_title_peek(main_module.base); |
| 516 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) | ||
| 517 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 518 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); | ||
| 519 | #endif | ||
| 480 | int code; | 520 | int code; |
| 481 | { | 521 | { |
| 482 | auto stacks = rt::start_thread_stacks(); | 522 | auto stacks = rt::start_thread_stacks(); |
| @@ -491,6 +531,12 @@ int wmain(int argc, wchar_t** argv) { | |||
| 491 | // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its | 531 | // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its |
| 492 | // handlers would run against a game that has stopped) and whose last word decides the exit status. | 532 | // handlers would run against a game that has stopped) and whose last word decides the exit status. |
| 493 | // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead. | 533 | // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead. |
| 534 | // The list-value threads end first: ExitProcess must not cut one off inside the layer (in a held submission, | ||
| 535 | // holding its queues' lock). | ||
| 536 | rt::d3d12_xs::stop_list_values(500); | ||
| 537 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 538 | rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); | ||
| 539 | #endif | ||
| 494 | rt::cleanup_tls_clones(); | 540 | rt::cleanup_tls_clones(); |
| 495 | ExitProcess(static_cast<UINT>(code)); | 541 | ExitProcess(static_cast<UINT>(code)); |
| 496 | } catch (const std::exception& e) { | 542 | } catch (const std::exception& e) { |