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.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index 475ae6ec7..560f68349 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -1,18 +1,21 @@
1// gta6rt: native runtime for the Xbox Series build. 1// gta6rt: native runtime for the Xbox Series build.
2// 2//
3// gta6rt --dry-run <image> [--game-dir DIR] 3// gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR]
4// Maps the image and its bundled modules, applies relocations, binds every import, installs static TLS for 4// Maps the image and its bundled modules, applies relocations, binds every import, installs static TLS for
5// this thread and prints a report. No code from the mapped images 5// this thread and prints a report. No code from the mapped images
6// runs. TLS needs the runtime's own gta6rt_tls_host.dll, which reserves the module TLS index; system DLLs are 6// runs. TLS needs the runtime's own gta6rt_tls_host.dll, which reserves the module TLS index; system DLLs are
7// loaded to resolve host imports, as before. 7// loaded to resolve host imports, as before.
8// 8//
9// gta6rt --init <image> [--game-dir DIR] 9// gta6rt --init <image> [--game-dir DIR] [--overlay DIR]
10// The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run. 10// The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run.
11// 11//
12// gta6rt --run <exe> [--game-dir DIR] [--trace-d3d12] [-- game arguments...] 12// gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [-- game arguments...]
13// The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and 13// The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and
14// command line are <exe name> plus the arguments after "--"; exit/ExitProcess from the game end the run 14// command line are <exe name> plus the arguments after "--"; exit/ExitProcess from the game end the run
15// (shims/process.cpp). gta6rt prints the binding report first and returns the game's exit code. 15// (shims/process.cpp). gta6rt prints the binding report first and returns the game's exit code.
16//
17// --game-dir is also where a title's GAME: paths read from; anything it writes or deletes goes to the overlay
18// (--overlay, default <game-dir>/overlay) so the package is never modified (shims/file_system.cpp).
16#include <windows.h> 19#include <windows.h>
17 20
18#include <cstdio> 21#include <cstdio>
@@ -23,6 +26,7 @@
23#include "base_reservation.h" 26#include "base_reservation.h"
24#include "pe_loader.h" 27#include "pe_loader.h"
25#include "../shims/d3d12_trace.h" 28#include "../shims/d3d12_trace.h"
29#include "../shims/file_system.h"
26#include "../shims/process_shim.h" 30#include "../shims/process_shim.h"
27#include "../shims/shims.h" 31#include "../shims/shims.h"
28 32
@@ -39,16 +43,16 @@ const char* binding_name(rt::Binding b) {
39 43
40int usage() { 44int usage() {
41 std::fprintf(stderr, 45 std::fprintf(stderr,
42 "usage: gta6rt --dry-run <image> [--game-dir DIR]\n" 46 "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR]\n"
43 " gta6rt --init <image> [--game-dir DIR] [--trace-d3d12]\n" 47 " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--trace-d3d12]\n"
44 " gta6rt --run <exe> [--game-dir DIR] [--trace-d3d12] [-- game arguments...]\n"); 48 " gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [-- game arguments...]\n");
45 return 2; 49 return 2;
46} 50}
47 51
48} // namespace 52} // namespace
49 53
50int wmain(int argc, wchar_t** argv) { 54int wmain(int argc, wchar_t** argv) {
51 std::filesystem::path image, game_dir; 55 std::filesystem::path image, game_dir, overlay_dir;
52 bool dry_run = false, init = false, run = false, trace_d3d12 = false; 56 bool dry_run = false, init = false, run = false, trace_d3d12 = false;
53 std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84) 57 std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84)
54 for (int i = 1; i < argc; ++i) { 58 for (int i = 1; i < argc; ++i) {
@@ -62,6 +66,7 @@ int wmain(int argc, wchar_t** argv) {
62 else if (a == L"--run") run = true; 66 else if (a == L"--run") run = true;
63 else if (a == L"--trace-d3d12") trace_d3d12 = true; 67 else if (a == L"--trace-d3d12") trace_d3d12 = true;
64 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i]; 68 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i];
69 else if (a == L"--overlay" && i + 1 < argc) overlay_dir = argv[++i];
65 else if (image.empty()) image = a; 70 else if (image.empty()) image = a;
66 else return usage(); 71 else return usage();
67 } 72 }
@@ -73,6 +78,9 @@ int wmain(int argc, wchar_t** argv) {
73 // process that has the range reserved from the start (base_reservation.h); that process does not do this again. 78 // process that has the range reserved from the start (base_reservation.h); that process does not do this again.
74 if (!rt::base_reservation::inherited()) 79 if (!rt::base_reservation::inherited())
75 if (const auto range = rt::base_reservation::needed(image)) return rt::base_reservation::relaunch(*range); 80 if (const auto range = rt::base_reservation::needed(image)) return rt::base_reservation::relaunch(*range);
81 // GAME: paths read under --game-dir; whatever a title writes lands in the overlay, never in the package.
82 if (overlay_dir.empty()) overlay_dir = game_dir / "overlay";
83 rt::fs::configure(game_dir, overlay_dir);
76 rt::d3d12_trace::set_enabled(trace_d3d12); 84 rt::d3d12_trace::set_enabled(trace_d3d12);
77 85
78 try { 86 try {
@@ -110,6 +118,7 @@ int wmain(int argc, wchar_t** argv) {
110 return 1; 118 return 1;
111 } 119 }
112 rt::process::set_command_line(image.filename().wstring(), game_args); 120 rt::process::set_command_line(image.filename().wstring(), game_args);
121 std::printf("console paths: GAME: -> %ls, writes -> %ls\n", game_dir.c_str(), overlay_dir.c_str());
113 std::printf("running %s\n", main_module.name.c_str()); 122 std::printf("running %s\n", main_module.name.c_str());
114 std::fflush(stdout); 123 std::fflush(stdout);
115 const int code = rt::process::run_entry(main_module.base + main_module.entry_rva); 124 const int code = rt::process::run_entry(main_module.base + main_module.entry_rva);