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:
authorTyrannys <80750971+Tyrannys@users.noreply.github.com>2026-11-25 07:19:48 -0600
committerTyrannys <80750971+Tyrannys@users.noreply.github.com>2026-11-25 07:19:48 -0600
commit03096929f42f6f1fdc687868fd9f9589e48a4b97 (patch)
tree326cad646471e19496b1de5c207c5fa34d02dee0 /runtime/src/main.cpp
parent7f08453da77d282924c09b6dc2ac51d69a369547 (diff)
parent384abe5b06d08e349f4b4e4394c68f036da47dc7 (diff)
Merge main into first-run-pad-focus
Keep main's first-run profile without GPU completion labels and this branch's focused keyboard pad (LEONIDA_KEYBOARD_PAD=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp58
1 files changed, 52 insertions, 6 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index a108a20fd..298f087e5 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.
78void start_title_peek(std::uint8_t* base) { 79void 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"
@@ -172,7 +195,7 @@ bool configure_first_run_ui(const std::filesystem::path& package, std::filesyste
172 const struct { const wchar_t* name; const wchar_t* value; } settings[] = { 195 const struct { const wchar_t* name; const wchar_t* value; } settings[] = {
173 {L"LEONIDA_D3D12", L"vulkan"}, {L"LEONIDA_ARENA_MB", L"2048"}, 196 {L"LEONIDA_D3D12", L"vulkan"}, {L"LEONIDA_ARENA_MB", L"2048"},
174 {L"LEONIDA_GRAPHICS_STAGE_LAYOUT", L"1"}, {L"LEONIDA_PIPELINE_COMPILE", L"on-demand"}, 197 {L"LEONIDA_GRAPHICS_STAGE_LAYOUT", L"1"}, {L"LEONIDA_PIPELINE_COMPILE", L"on-demand"},
175 {L"LEONIDA_GPU_LABELS", L"1"}, {L"LEONIDA_FRAME_PACING", L"1"}, 198 {L"LEONIDA_FRAME_PACING", L"1"},
176 // Focused, not always: keys typed into another window must not press anything on a consent page. 199 // Focused, not always: keys typed into another window must not press anything on a consent page.
177 // Scripted presses (LEONIDA_INPUT_SCRIPT) still run while the window is unfocused. 200 // Scripted presses (LEONIDA_INPUT_SCRIPT) still run while the window is unfocused.
178 {L"LEONIDA_KEYBOARD_PAD", L"1"}, 201 {L"LEONIDA_KEYBOARD_PAD", L"1"},
@@ -207,6 +230,18 @@ int usage() {
207} // namespace 230} // namespace
208 231
209#ifdef LEONIDA_VULKAN_DEVICE 232#ifdef LEONIDA_VULKAN_DEVICE
233// The run ends with the title's Vulkan device alive, so no ~Device stops the background pipeline compiler: stop it
234// here, before ExitProcess ends its thread, maybe inside the driver's compiler (rt::d3d12::stop_pipeline_compiles).
235constexpr unsigned kExitCompileWaitMs = 2000; // a console close gives the whole process 5 s
236
237static BOOL WINAPI stop_compiles_on_console_exit(DWORD event) {
238 if (event == CTRL_C_EVENT || event == CTRL_BREAK_EVENT || event == CTRL_CLOSE_EVENT) {
239 rt::d3d12_xs::stop_list_values(500); // as at the run's end: no list-value thread cut off inside the layer
240 rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs);
241 }
242 return FALSE; // the next handler (the default one: ExitProcess) ends the process, as before
243}
244
210static BOOL WINAPI show_package_window(HWND window, int command) { 245static BOOL WINAPI show_package_window(HWND window, int command) {
211 const BOOL previous = ShowWindow(window, command); 246 const BOOL previous = ShowWindow(window, command);
212 const DWORD error = GetLastError(); 247 const DWORD error = GetLastError();
@@ -359,6 +394,7 @@ int wmain(int argc, wchar_t** argv) {
359 leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); 394 leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases);
360 leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); 395 leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range);
361 rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); 396 rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data);
397 leonida::kernel_writes::set_unguarder(&rt::xmem::reopen_unowned);
362 if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { 398 if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) {
363 std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" 399 std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n"
364 : "error: cannot create the trace file\n"); 400 : "error: cannot create the trace file\n");
@@ -479,6 +515,10 @@ int wmain(int argc, wchar_t** argv) {
479 std::fflush(stdout); 515 std::fflush(stdout);
480 keep_title_watchdog_kicked(main_module.base); 516 keep_title_watchdog_kicked(main_module.base);
481 start_title_peek(main_module.base); 517 start_title_peek(main_module.base);
518 leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic)
519#ifdef LEONIDA_VULKAN_DEVICE
520 SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE);
521#endif
482 int code; 522 int code;
483 { 523 {
484 auto stacks = rt::start_thread_stacks(); 524 auto stacks = rt::start_thread_stacks();
@@ -493,6 +533,12 @@ int wmain(int argc, wchar_t** argv) {
493 // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its 533 // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its
494 // handlers would run against a game that has stopped) and whose last word decides the exit status. 534 // handlers would run against a game that has stopped) and whose last word decides the exit status.
495 // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead. 535 // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead.
536 // The list-value threads end first: ExitProcess must not cut one off inside the layer (in a held submission,
537 // holding its queues' lock).
538 rt::d3d12_xs::stop_list_values(500);
539#ifdef LEONIDA_VULKAN_DEVICE
540 rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs);
541#endif
496 rt::cleanup_tls_clones(); 542 rt::cleanup_tls_clones();
497 ExitProcess(static_cast<UINT>(code)); 543 ExitProcess(static_cast<UINT>(code));
498 } catch (const std::exception& e) { 544 } catch (const std::exception& e) {