diff options
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 71a5b44e1..fbb4b3043 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -29,13 +29,16 @@ | |||
| 29 | 29 | ||
| 30 | #include "base_reservation.h" | 30 | #include "base_reservation.h" |
| 31 | #include "code_hooks.h" | 31 | #include "code_hooks.h" |
| 32 | #include "host_cpu.h" | ||
| 32 | #include "mods.h" | 33 | #include "mods.h" |
| 33 | #include "pe_loader.h" | 34 | #include "pe_loader.h" |
| 34 | #include "../shims/d3d12_trace.h" | 35 | #include "../shims/d3d12_trace.h" |
| 36 | #include "../shims/d3d12_xs_device.h" | ||
| 35 | #include "../shims/file_system.h" | 37 | #include "../shims/file_system.h" |
| 36 | #include "../shims/process_shim.h" | 38 | #include "../shims/process_shim.h" |
| 37 | #include "../shims/shims.h" | 39 | #include "../shims/shims.h" |
| 38 | #include "../shims/startup_trace.h" | 40 | #include "../shims/startup_trace.h" |
| 41 | #include "../shims/xmem.h" | ||
| 39 | 42 | ||
| 40 | namespace { | 43 | namespace { |
| 41 | 44 | ||
| @@ -101,6 +104,12 @@ int wmain(int argc, wchar_t** argv) { | |||
| 101 | if (image.empty()) return usage(); | 104 | if (image.empty()) return usage(); |
| 102 | // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. | 105 | // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. |
| 103 | if (dry_run + init + run != 1) return usage(); | 106 | if (dry_run + init + run != 1) return usage(); |
| 107 | // The game runs AVX code from its TLS callbacks on; without AVX that is a bare 0xC000001D (src/host_cpu.h). | ||
| 108 | if ((init || run) && !rt::host_cpu::check_skipped()) | ||
| 109 | if (const auto missing = rt::host_cpu::missing_host_features(); !missing.empty()) { | ||
| 110 | std::fprintf(stderr, "%s\n", rt::host_cpu::message(missing).c_str()); | ||
| 111 | return rt::host_cpu::kExitCode; | ||
| 112 | } | ||
| 104 | // The console folders are fixed once, as absolute paths. A bare image name (`gta6rt --run game.exe` from the | 113 | // The console folders are fixed once, as absolute paths. A bare image name (`gta6rt --run game.exe` from the |
| 105 | // game folder) has an empty parent path, which left GAME: with no root; and a relative --game-dir or --overlay | 114 | // game folder) has an empty parent path, which left GAME: with no root; and a relative --game-dir or --overlay |
| 106 | // would follow the title's later SetCurrentDirectory. If absolute() fails the path stays as given. | 115 | // would follow the title's later SetCurrentDirectory. If absolute() fails the path stays as given. |
| @@ -111,6 +120,15 @@ int wmain(int argc, wchar_t** argv) { | |||
| 111 | }; | 120 | }; |
| 112 | game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir); | 121 | game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir); |
| 113 | if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir); | 122 | if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir); |
| 123 | // LEONIDA_SHADERS too: the D3D12 device reads it at the title's first pipeline state, after it may have moved. | ||
| 124 | if (const DWORD size = GetEnvironmentVariableW(L"LEONIDA_SHADERS", nullptr, 0)) { | ||
| 125 | std::wstring shaders(size, L'\0'); | ||
| 126 | const DWORD n = GetEnvironmentVariableW(L"LEONIDA_SHADERS", shaders.data(), size); | ||
| 127 | if (n && n < size) { | ||
| 128 | shaders.resize(n); | ||
| 129 | SetEnvironmentVariableW(L"LEONIDA_SHADERS", absolute_or_same(shaders).c_str()); | ||
| 130 | } | ||
| 131 | } | ||
| 114 | // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new | 132 | // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new |
| 115 | // process that has the range reserved from the start (base_reservation.h); that process does not do this again. | 133 | // process that has the range reserved from the start (base_reservation.h); that process does not do this again. |
| 116 | if (!rt::base_reservation::inherited()) | 134 | if (!rt::base_reservation::inherited()) |
| @@ -147,6 +165,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 147 | "this executable (docs/modding.md)\n", leonida::mods::active().size()); | 165 | "this executable (docs/modding.md)\n", leonida::mods::active().size()); |
| 148 | } | 166 | } |
| 149 | rt::d3d12_trace::set_enabled(trace_d3d12); | 167 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 168 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. | ||
| 169 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); | ||
| 150 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { | 170 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { |
| 151 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" | 171 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" |
| 152 | : "error: cannot create the trace file\n"); | 172 | : "error: cannot create the trace file\n"); |