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:
authorEmma <47298336+zzEmmazz@users.noreply.github.com>2026-11-23 00:40:34 +0200
committerEmma <47298336+zzEmmazz@users.noreply.github.com>2026-11-23 00:40:34 +0200
commitd2e6b31db24e7ca93a34f0b53b063d32ff944070 (patch)
tree85b3b6de8fd34420002210fc541f7daccef5267c /runtime/src/main.cpp
parent9d36ec83ce3b72c77e72753903cea9e73f5c0d91 (diff)
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
Merge commit 'aa2988cc' into d3d-417-msaa-depth-array-slices
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index 7bc2d78ab..49917bf18 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -19,8 +19,10 @@
19#include <windows.h> 19#include <windows.h>
20 20
21#include <cstdio> 21#include <cstdio>
22#include <filesystem>
22#include <map> 23#include <map>
23#include <string> 24#include <string>
25#include <system_error>
24#include <vector> 26#include <vector>
25 27
26#include "base_reservation.h" 28#include "base_reservation.h"
@@ -76,7 +78,16 @@ int wmain(int argc, wchar_t** argv) {
76 if (image.empty()) return usage(); 78 if (image.empty()) return usage();
77 // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. 79 // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point.
78 if (dry_run + init + run != 1) return usage(); 80 if (dry_run + init + run != 1) return usage();
79 if (game_dir.empty()) game_dir = image.parent_path(); 81 // The console folders are fixed once, as absolute paths. A bare image name (`gta6rt --run game.exe` from the
82 // game folder) has an empty parent path, which left GAME: with no root; and a relative --game-dir or --overlay
83 // would follow the title's later SetCurrentDirectory. If absolute() fails the path stays as given.
84 const auto absolute_or_same = [](const std::filesystem::path& p) {
85 std::error_code ec;
86 std::filesystem::path a = std::filesystem::absolute(p, ec);
87 return ec ? p : a;
88 };
89 game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir);
90 if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir);
80 // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new 91 // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new
81 // process that has the range reserved from the start (base_reservation.h); that process does not do this again. 92 // process that has the range reserved from the start (base_reservation.h); that process does not do this again.
82 if (!rt::base_reservation::inherited()) 93 if (!rt::base_reservation::inherited())
@@ -129,7 +140,22 @@ int wmain(int argc, wchar_t** argv) {
129 std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); 140 std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str());
130 return 1; 141 return 1;
131 } 142 }
132 std::printf("console paths: GAME: -> %ls, writes -> %ls\n", game_dir.c_str(), overlay_dir.c_str()); 143 const std::wstring paths = L"console paths: GAME: -> " + game_dir.native() + L", writes -> " + overlay_dir.native();
144 const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
145 DWORD mode;
146 bool printed = false;
147 if (GetConsoleMode(out, &mode)) {
148 std::fflush(stdout);
149 const std::wstring line = paths + L"\r\n";
150 DWORD written;
151 printed = WriteConsoleW(out, line.data(), static_cast<DWORD>(line.size()), &written, nullptr) != FALSE;
152 }
153 if (!printed) {
154 const auto game = game_dir.u8string();
155 const auto overlay = overlay_dir.u8string();
156 std::printf("console paths: GAME: -> %s, writes -> %s\n",
157 reinterpret_cast<const char*>(game.c_str()), reinterpret_cast<const char*>(overlay.c_str()));
158 }
133 std::printf("running %s\n", main_module.name.c_str()); 159 std::printf("running %s\n", main_module.name.c_str());
134 std::fflush(stdout); 160 std::fflush(stdout);
135 const int code = rt::process::run_entry(main_module.base + main_module.entry_rva); 161 const int code = rt::process::run_entry(main_module.base + main_module.entry_rva);
@@ -141,6 +167,8 @@ int wmain(int argc, wchar_t** argv) {
141 std::fflush(stderr); 167 std::fflush(stderr);
142 // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its 168 // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its
143 // handlers would run against a game that has stopped) and whose last word decides the exit status. 169 // handlers would run against a game that has stopped) and whose last word decides the exit status.
170 // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead.
171 rt::cleanup_tls_clones();
144 ExitProcess(static_cast<UINT>(code)); 172 ExitProcess(static_cast<UINT>(code));
145 } catch (const std::exception& e) { 173 } catch (const std::exception& e) {
146 std::fprintf(stderr, "error: %s\n", e.what()); 174 std::fprintf(stderr, "error: %s\n", e.what());