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:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 14:40:15 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 14:40:15 -0500
commit8bf99edc7a437f13e01fa4bc8b22b49b473e569c (patch)
tree4da9c23f1b292b04922fd7a28023720a40fd7074 /runtime/src/main.cpp
parentd279b288684060cdfd486a841fbd185ac37d865b (diff)
parent126062ae4a8831a564b9e3042684657c58781bef (diff)
Merge pull request #95 from Ayinaki
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index e69906c14..4477c4a69 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -3,6 +3,9 @@
3// gta6rt --dry-run <image> [--game-dir DIR] 3// gta6rt --dry-run <image> [--game-dir DIR]
4// Maps the image and its bundled modules, applies relocations, binds every import and prints a report. 4// Maps the image and its bundled modules, applies relocations, binds every import and prints a report.
5// No code from the image runs. 5// No code from the image runs.
6//
7// gta6rt --init <image> [--game-dir DIR]
8// The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run.
6#include <windows.h> 9#include <windows.h>
7 10
8#include <cstdio> 11#include <cstdio>
@@ -23,7 +26,9 @@ const char* binding_name(rt::Binding b) {
23} 26}
24 27
25int usage() { 28int usage() {
26 std::fprintf(stderr, "usage: gta6rt --dry-run <image> [--game-dir DIR]\n"); 29 std::fprintf(stderr,
30 "usage: gta6rt --dry-run <image> [--game-dir DIR]\n"
31 " gta6rt --init <image> [--game-dir DIR]\n");
27 return 2; 32 return 2;
28} 33}
29 34
@@ -31,17 +36,20 @@ int usage() {
31 36
32int wmain(int argc, wchar_t** argv) { 37int wmain(int argc, wchar_t** argv) {
33 std::filesystem::path image, game_dir; 38 std::filesystem::path image, game_dir;
34 bool dry_run = false; 39 bool dry_run = false, init = false;
35 for (int i = 1; i < argc; ++i) { 40 for (int i = 1; i < argc; ++i) {
36 std::wstring a = argv[i]; 41 std::wstring a = argv[i];
37 if (a == L"--dry-run") dry_run = true; 42 if (a == L"--dry-run") dry_run = true;
43 else if (a == L"--init") init = true;
38 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i]; 44 else if (a == L"--game-dir" && i + 1 < argc) game_dir = argv[++i];
39 else if (image.empty()) image = a; 45 else if (image.empty()) image = a;
40 else return usage(); 46 else return usage();
41 } 47 }
42 if (image.empty()) return usage(); 48 if (image.empty()) return usage();
43 if (!dry_run) { 49 if (!dry_run && !init) {
44 std::fprintf(stderr, "Only --dry-run exists so far: running game code needs the shims listed by it first.\n"); 50 std::fprintf(stderr,
51 "Only --dry-run and --init exist so far: running game code needs the shims listed by "
52 "--dry-run first.\n");
45 return 2; 53 return 2;
46 } 54 }
47 if (game_dir.empty()) game_dir = image.parent_path(); 55 if (game_dir.empty()) game_dir = image.parent_path();
@@ -49,6 +57,10 @@ int wmain(int argc, wchar_t** argv) {
49 try { 57 try {
50 rt::Loader loader(game_dir); 58 rt::Loader loader(game_dir);
51 loader.load(image); 59 loader.load(image);
60 if (init) {
61 loader.initialise();
62 std::printf("%zu module(s) initialised\n", loader.modules().size());
63 }
52 int unimplemented = 0; 64 int unimplemented = 0;
53 for (auto* m : loader.modules()) { 65 for (auto* m : loader.modules()) {
54 std::map<rt::Binding, int> counts; 66 std::map<rt::Binding, int> counts;