From 9c6cbbcf12757aa012da8064a6750d482826668a Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 24 Nov 2026 19:22:58 +0100 Subject: [PATCH 1/2] runtime: xapu.dll as a command queue with the console's layouts, audio silent xapu.dll moves out of xapu_chad.cpp into xapu.cpp; chad.dll is unchanged. The signatures, structure layouts, command kinds, option bits and error codes come from Marvisak/VIctory (GPL-3.0-or-later, crates/victory-hle/src/modules/apu.rs at ffe310e), which runs the retail executable through these calls. Only facts are used, no code (docs/related_projects.md). They settle what the old header left open: XApuConnect's first argument is an input (processing kind, streams, commands per stream, memory bytes, frames per output, options), and the dword the title reads at +0x34 of a result is its output byte count. - XApuConnect validates the input, allocates the memory the title asks for (zeroed) and, with option 0x8, an auto-reset result event; any processing kind but Opus decoding is E_NOTIMPL. - Each accepted command gives one result in command order, with the console's error codes; an unknown kind, a stream out of range or a full stream is refused with no result. - A process result carries the frame count of the Opus packet's TOC byte (RFC 6716, section 3.1), clipped from first_frame, to frame_count and to the output, and zeros in the output. Nothing is decoded. - xapu_chad_test covers result order, the full queue, the error codes, frame counts, silence and the event. Co-Authored-By: Claude Opus 5.5 --- docs/audio_hal_exe_calls.md | 17 ++ runtime/CMakeLists.txt | 5 +- runtime/shims/xapu.cpp | 361 ++++++++++++++++++++++++++++++++ runtime/shims/xapu_chad.cpp | 123 +---------- runtime/test/xapu_chad_test.cpp | 261 +++++++++++++++++++---- 5 files changed, 608 insertions(+), 159 deletions(-) create mode 100644 runtime/shims/xapu.cpp diff --git a/docs/audio_hal_exe_calls.md b/docs/audio_hal_exe_calls.md index c04943c7d5..1d7334fbdc 100644 --- a/docs/audio_hal_exe_calls.md +++ b/docs/audio_hal_exe_calls.md @@ -52,6 +52,23 @@ turns such an address back into a pointer. That is an inference from the shapes; `XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. +`runtime/shims/xapu.cpp` serves the five `xapu.dll` imports and `runtime/shims/xapu_chad.cpp` the five `chad.dll` ones. +The `xapu.dll` signatures, structure layouts, command kinds, option bits and error codes come from Marvisak/VIctory +(, GPL-3.0-or-later, `crates/victory-hle/src/modules/apu.rs` at commit `ffe310e`), +which runs the retail executable through these calls. Only the facts are used (see +[related_projects.md](related_projects.md)); the top of `xapu.cpp` lists them. They agree with the shapes above: + +| Shape measured here | What the layout says | +|---|---| +| `XApuConnect`: a 24-byte title global first, a 16-byte output second | the global is an input of six dwords (processing kind, streams, commands per stream, memory bytes, frames per output, options); the output is the zeroed memory and a result event | +| `XApuEnqueueCommand`: a stack-built command whose first dword is 1, 2 or 3 and second a stream slot, then 0 | a 24-byte command id (kind, stream, sequence, options, context): 1 activates, 2 deactivates, 3 processes an Opus packet; the third argument is an optional count of the commands accepted | +| `XApuDequeueResult`: a 0x50-byte result, read at +0, +4 and +0x34 | the command id at +0, the output byte count at +0x34; `0x8AC81001` while none is ready | +| `XApuDisconnect`: the handle, then `0x20` | the second argument is not read | + +What the results carry is the shim's own: each accepted command gets one result in command order, with the error codes +of the layout, and a process result carries the frame count of the Opus packet's table-of-contents byte (RFC 6716, +section 3.1) with zeros in its output. Nothing is decoded, so the audio stays silent. `xapu_chad_test` covers both DLLs. + ## `xg_xs.dll` and `XCRDAPI.dll` | Import | Sites | What the sites show | diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 3b334c7133..3616ab7413 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -168,6 +168,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) shims/process.cpp shims/com_shim.cpp shims/bcrypt_rng.cpp + shims/xapu.cpp shims/xapu_chad.cpp shims/dstorage.cpp ) @@ -316,9 +317,11 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) target_compile_options(dstorage_test PRIVATE /W4 /permissive- /utf-8) target_link_options(dstorage_test PRIVATE /OPT:NOREF) - # xapu.dll and chad.dll, the APU and audio DSP command queues, resolved through the registry like xmem_test. + # xapu.dll and chad.dll, the APU and audio DSP command queues, resolved through the registry like xmem_test; Opus + # frame counts from hand-made packets. add_executable(xapu_chad_test test/xapu_chad_test.cpp + shims/xapu.cpp shims/xapu_chad.cpp shims/registry.cpp ) diff --git a/runtime/shims/xapu.cpp b/runtime/shims/xapu.cpp new file mode 100644 index 0000000000..3e69ce43cd --- /dev/null +++ b/runtime/shims/xapu.cpp @@ -0,0 +1,361 @@ +// xapu.dll: the console's audio processing unit (APU) command queue. No PC has one, so this keeps the queue the title +// talks to - one result per accepted command, in command order, with the console's error codes - and decodes nothing: +// an Opus packet's result carries the frame count its table-of-contents byte gives and silence in its output. +// +// Read from the executable's call sites (counts in docs/runtime_imports.md, shapes in docs/audio_hal_exe_calls.md), +// statically, never run: +// XApuConnect(input24*, out16*, handle*) 1 site; success is SUCCEEDED(hr). The first qword of the 16-byte +// output is read later as the base of a CPU-visible buffer: per-stream +// input at base + slot * 0x280 and output at base + 0x14000 + +// slot * 0x1E00. The first argument is a 24-byte global of the title +// that other title code also addresses. +// XApuEnqueueCommand(handle, cmd*, 0) 4 sites; the return value is never read. cmd's first dword is a type +// (1, 2 and 3 seen), the second a stream slot. +// XApuGetResultCount(handle, 0) 1 site; 0 skips the loop that dequeues. +// XApuDequeueResult(handle, out*) 1 site, called count times into a zeroed 0x50-byte local; a negative +// HRESULT skips that result. The loop reads a type at +0, a stream slot +// at +4 and a dword at +0x34. Its per-slot state machine takes a type 1 +// result as "opened" and returns the slot to the title's free list only +// on a type 2 result, after the title enqueued a type 2 command. +// XApuDisconnect(handle, 0x20) 1 site; the return value is never read. +// +// Where the layouts come from. The signatures, structure layouts, command kinds, option bits and error codes below +// are facts recorded by Marvisak/VIctory (GPL-3.0-or-later, crates/victory-hle/src/modules/apu.rs at commit ffe310e), +// whose runtime runs the retail executable through these calls; see docs/related_projects.md. Nothing of its code is +// copied; this file is written from those facts. They agree with every shape above: the first argument of +// XApuConnect is an input, the dword the title reads at +0x34 of a result is its output byte count, and a type 1 +// (activate) or type 2 (deactivate) command gives a result of the same kind for the same stream. +// HRESULT XApuConnect(const ConnectInput*, ConnectOutput*, Connection** out) +// HRESULT XApuDisconnect(Connection*, uint32_t) the second argument is not read +// HRESULT XApuEnqueueCommand(Connection*, const void* command, uint32_t* accepted_so_far) may be null +// HRESULT XApuDequeueResult(Connection*, Result* out) 0x8AC81001 while no result is ready +// uint32_t XApuGetResultCount(Connection*, uint32_t* dequeued_so_far) may be null; returns the results ready +// A connection is for one kind of processing; kind 1 is Opus decoding to 32-bit float PCM at 48 kHz, and any other +// kind is E_NOTIMPL. Every command starts with the 24-byte CommandId. A command refused at once (unknown kind, +// stream out of range, or the stream already holding `commands_per_stream` results not dequeued) gives no result; +// every other command gives one, with its error, if any, in the result. +// +// What this does not do: decode. A process command's frame count comes from the Opus packet's table-of-contents byte +// (RFC 6716, section 3.1), clipped from first_frame, to frame_count and to what output_bytes holds, and that output +// range is written with zeros. So the title sees streams advance at the right rate and its error checks pass, and the +// audio stays silent until a decoder is wired in at fill_silence(). +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "shims.h" +#include "startup_trace.h" + +namespace { + +constexpr HRESULT kNotImpl = static_cast(rt::shims::kENotImpl); +constexpr HRESULT kQueueFull = static_cast(0x8AC81000u); +constexpr HRESULT kNoResult = static_cast(0x8AC81001u); +constexpr HRESULT kInvalidCommand = static_cast(0x8AC81002u); +constexpr HRESULT kInvalidStream = static_cast(0x8AC81003u); +constexpr HRESULT kAlreadyActive = static_cast(0x8AC81005u); +constexpr HRESULT kBadPacket = static_cast(0x8AC81008u); + +constexpr uint32_t kDecodeOpus = 1; // ConnectInput::processing + +constexpr uint32_t kActivate = 1; // CommandId::kind +constexpr uint32_t kDeactivate = 2; +constexpr uint32_t kProcess = 3; +constexpr uint32_t kReset = 5; // 4 is notify; neither carries anything to do while nothing is decoded + +constexpr uint32_t kSignalWhenDone = 0x1; // CommandId::options: set the result event when the result is ready +constexpr uint32_t kResultEvent = 0x8; // ConnectInput::options: create an auto-reset event and hand it out +// ConnectInput::options 0x4 asks for deinterleaved output; silence is the same zeros either way. + +constexpr uint32_t kMaxStreams = 500; +constexpr uint32_t kMaxCommandsPerStream = 16; +constexpr uint32_t kMaxFrames = 5760; // 120 ms at 48 kHz, the longest Opus packet (RFC 6716, section 3.2.5) + +#pragma pack(push, 1) +struct ConnectInput { + uint32_t processing; + uint32_t streams; + uint32_t commands_per_stream; + uint32_t memory_bytes; + uint32_t frames_per_output; // 0 for decoding + uint32_t options; +}; +struct ConnectOutput { + void* memory; // zeroed, for the title's packets and output + HANDLE result_event; +}; +struct CommandId { + uint32_t kind; + uint32_t stream; + uint32_t sequence; + uint32_t options; + uint64_t context; +}; +struct ActivateCommand { + CommandId id; + uint32_t channels; // 1 or 2 + uint32_t init_bytes; + const void* init; + float start_pitch; + uint32_t processing_bytes; + void* processing; +}; +struct ProcessCommand { + CommandId id; + float pitch_ramp; + float target_pitch; + uint32_t first_frame; + uint32_t frame_count; + uint32_t input_bytes; + const uint8_t* input; + uint32_t output_bytes; + uint8_t* output; +}; +struct Result { + CommandId id; + uint32_t state; + uint64_t state_data; + uint64_t usec; + HRESULT error; + uint32_t frames; + uint32_t output_bytes; + uint8_t* output; + float pitch; + uint32_t input_bytes; + const uint8_t* input; +}; +#pragma pack(pop) +static_assert(sizeof(ConnectInput) == 24, "six dwords"); +static_assert(sizeof(ConnectOutput) == 16, "memory and event"); +static_assert(sizeof(CommandId) == 24, "kind, stream, sequence, options, context"); +static_assert(sizeof(ActivateCommand) == 56, "CommandId and the activate fields"); +static_assert(sizeof(ProcessCommand) == 64, "CommandId and the process fields"); +static_assert(sizeof(Result) == 0x50, "the result the title dequeues"); +static_assert(offsetof(Result, state) == 0x18 && offsetof(Result, error) == 0x2C && + offsetof(Result, output_bytes) == 0x34 && offsetof(Result, pitch) == 0x40 && + offsetof(Result, input) == 0x48, + "the offsets the title and the layout agree on"); + +struct Stream { + bool active = false; + uint32_t channels = 0; + uint32_t pending = 0; // results queued and not dequeued +}; + +struct Connection { + void* memory = nullptr; + HANDLE event = nullptr; + uint32_t commands_per_stream = 0; + std::mutex mutex; + std::vector streams; + std::deque results; + uint32_t accepted = 0; + uint32_t dequeued = 0; +}; + +// gta6rt --trace FILE: the first call of each function and the first XApuEnqueueCommand of each command kind, with +// the caller, so the first boot shows what the title sends without a line per call. +void note(const char* api, uint64_t value, const void* caller) { + if (!rt::startup_trace::enabled()) return; + static std::mutex mutex; + static std::set> seen; + { + const std::lock_guard lock(mutex); + if (!seen.insert({api, value}).second) return; + } + rt::startup_trace::event( + "audio_queue", std::string("\"api\":") + rt::startup_trace::quote(api) + + ",\"value\":" + rt::startup_trace::quote(rt::startup_trace::hex(value)) + ",\"caller\":" + + rt::startup_trace::quote(rt::startup_trace::where(reinterpret_cast(caller)))); +} + +// Samples per channel at 48 kHz in one Opus packet, from its table-of-contents byte and frame count code (RFC 6716, +// section 3.1); 0 for a packet that is not valid. +uint32_t opus_packet_frames(const uint8_t* packet, uint32_t bytes) { + if (!packet || bytes == 0) return 0; + static constexpr uint32_t kSilk[4] = {480, 960, 1920, 2880}; // 10, 20, 40, 60 ms + static constexpr uint32_t kHybrid[2] = {480, 960}; // 10, 20 ms + static constexpr uint32_t kCelt[4] = {120, 240, 480, 960}; // 2.5, 5, 10, 20 ms + const uint32_t config = packet[0] >> 3; + const uint32_t per_frame = config < 12 ? kSilk[config & 3] : config < 16 ? kHybrid[config & 1] : kCelt[config & 3]; + uint32_t count = 0; + switch (packet[0] & 3) { + case 0: count = 1; break; + case 1: + case 2: count = 2; break; + default: + if (bytes < 2) return 0; + count = packet[1] & 0x3F; + break; + } + if (count == 0 || count * per_frame > kMaxFrames) return 0; + return count * per_frame; +} + +// Fills a process command's result. The decoder belongs here: today the frames are counted, not decoded. +void fill_silence(const Stream& stream, const ProcessCommand& c, Result& r) { + r.input = c.input; + r.input_bytes = c.input_bytes; + r.output = c.output; + if (!c.input || !c.output || c.input_bytes == 0) { + r.error = E_INVALIDARG; + return; + } + const uint32_t decoded = opus_packet_frames(c.input, c.input_bytes); + if (decoded == 0) { + r.error = kBadPacket; + return; + } + const uint32_t first = c.first_frame < decoded ? c.first_frame : decoded; + uint32_t frames = decoded - first; + if (frames > c.frame_count) frames = c.frame_count; + const uint32_t room = c.output_bytes / (4 * stream.channels); + if (frames > room) frames = room; + const uint32_t bytes = frames * stream.channels * 4; + std::memset(c.output, 0, bytes); // interleaved or not, silence is zeros + r.frames = frames; + r.output_bytes = bytes; +} + +HRESULT __stdcall XApuConnect(const ConnectInput* input, ConnectOutput* output, Connection** out) { + note("XApuConnect", input ? input->processing : ~0ull, _ReturnAddress()); + if (!input || !output || !out) return E_INVALIDARG; + *out = nullptr; + ConnectInput in; + std::memcpy(&in, input, sizeof(in)); + if (in.streams == 0 || in.streams > kMaxStreams || in.commands_per_stream == 0 || + in.commands_per_stream > kMaxCommandsPerStream || in.memory_bytes == 0) + return E_INVALIDARG; + if (in.processing != kDecodeOpus) { + std::fprintf(stderr, "[rt] xapu: XApuConnect for processing kind %u: only Opus decoding (1); E_NOTIMPL\n", + in.processing); + return kNotImpl; + } + if (in.frames_per_output != 0) return E_INVALIDARG; + + auto* c = new (std::nothrow) Connection; // a throwing new would unwind into the title + if (!c) return E_OUTOFMEMORY; + try { + c->streams.resize(in.streams); + } catch (...) { + delete c; + return E_OUTOFMEMORY; + } + c->memory = VirtualAlloc(nullptr, in.memory_bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); // zeroed + if (!c->memory) { + delete c; + return E_OUTOFMEMORY; + } + if (in.options & kResultEvent) { + c->event = CreateEventW(nullptr, FALSE, FALSE, nullptr); // auto-reset + if (!c->event) { + const HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); + VirtualFree(c->memory, 0, MEM_RELEASE); + delete c; + return hr; + } + } + c->commands_per_stream = in.commands_per_stream; + const ConnectOutput o{c->memory, c->event}; + std::memcpy(output, &o, sizeof(o)); + *out = c; + std::fprintf(stderr, "[rt] xapu: connected for Opus decoding, %u streams; packets are counted, not decoded\n", + in.streams); + return S_OK; +} + +HRESULT __stdcall XApuDisconnect(Connection* c, uint32_t /*0x20 at the measured site*/) { + note("XApuDisconnect", 0, _ReturnAddress()); + if (!c) return E_INVALIDARG; + if (c->event) CloseHandle(c->event); + VirtualFree(c->memory, 0, MEM_RELEASE); + delete c; + return S_OK; +} + +HRESULT __stdcall XApuEnqueueCommand(Connection* c, const void* command, uint32_t* accepted_so_far) { + if (!c || !command) return E_INVALIDARG; + CommandId id; + std::memcpy(&id, command, sizeof(id)); + note("XApuEnqueueCommand", id.kind, _ReturnAddress()); + if (id.kind < kActivate || id.kind > kReset) return kInvalidCommand; + + const std::lock_guard lock(c->mutex); + if (id.stream >= c->streams.size()) return kInvalidStream; + Stream& stream = c->streams[id.stream]; + if (stream.pending >= c->commands_per_stream) return kQueueFull; + + Result r{}; + r.id = id; + r.pitch = 1.0f; + if (id.kind == kActivate) { + ActivateCommand a; + std::memcpy(&a, command, sizeof(a)); + if (stream.active) { + r.error = kAlreadyActive; + } else if (a.channels < 1 || a.channels > 2) { + r.error = E_INVALIDARG; + } else { + stream.active = true; + stream.channels = a.channels; + } + } else if (id.kind == kDeactivate) { + stream.active = false; + } else if (id.kind == kProcess) { + ProcessCommand p; + std::memcpy(&p, command, sizeof(p)); + if (!stream.active) r.error = kInvalidStream; + else fill_silence(stream, p, r); + } + try { + c->results.push_back(r); + } catch (...) { // out of memory: refuse the command, nothing may unwind into the title + return E_OUTOFMEMORY; + } + ++stream.pending; + ++c->accepted; + if (accepted_so_far) *accepted_so_far = c->accepted; + if ((id.options & kSignalWhenDone) && c->event) SetEvent(c->event); + return S_OK; +} + +HRESULT __stdcall XApuDequeueResult(Connection* c, Result* out) { + note("XApuDequeueResult", 0, _ReturnAddress()); + if (!c || !out) return E_INVALIDARG; + const std::lock_guard lock(c->mutex); + if (c->results.empty()) return kNoResult; + const Result r = c->results.front(); + c->results.pop_front(); + --c->streams[r.id.stream].pending; + ++c->dequeued; + std::memcpy(out, &r, sizeof(r)); + return S_OK; +} + +uint32_t __stdcall XApuGetResultCount(Connection* c, uint32_t* dequeued_so_far) { + note("XApuGetResultCount", 0, _ReturnAddress()); + if (!c) return 0; + const std::lock_guard lock(c->mutex); + if (dequeued_so_far) *dequeued_so_far = c->dequeued; + return static_cast(c->results.size()); +} + +} // namespace + +SHIM_TABLE(xapu, + {"xapu.dll", "XApuConnect", reinterpret_cast(&XApuConnect)}, + {"xapu.dll", "XApuDequeueResult", reinterpret_cast(&XApuDequeueResult)}, + {"xapu.dll", "XApuDisconnect", reinterpret_cast(&XApuDisconnect)}, + {"xapu.dll", "XApuEnqueueCommand", reinterpret_cast(&XApuEnqueueCommand)}, + {"xapu.dll", "XApuGetResultCount", reinterpret_cast(&XApuGetResultCount)}, +); diff --git a/runtime/shims/xapu_chad.cpp b/runtime/shims/xapu_chad.cpp index 35bda2b72f..ee58311f0a 100644 --- a/runtime/shims/xapu_chad.cpp +++ b/runtime/shims/xapu_chad.cpp @@ -1,24 +1,8 @@ -// xapu.dll and chad.dll: the console's audio processing unit (APU) and audio DSP command queues. No PC has either, -// so these give the title connections whose calls succeed, a zeroed shared buffer, a result for each stream open and -// close, and zeroed DSP status: the audio the APU would render stays silent, and nothing the title submits is processed. +// chad.dll: the console's audio DSP command queue. No PC has one, so this gives the title a connection whose calls +// succeed and zeroed DSP status: nothing the title submits is processed. xapu.dll, the APU command queue, is in +// xapu.cpp. // // Read from the executable's call sites (counts in docs/runtime_imports.md), statically, never run: -// XApuConnect(block24*, out16*, handle*) 1 site; success is SUCCEEDED(hr). The first qword of the 16-byte -// output is read later as the base of a CPU-visible buffer: per-stream -// input at base + slot * 0x280 and output at base + 0x14000 + -// slot * 0x1E00. The first argument is a 24-byte global of the title -// that other title code also addresses; whether it is an input or an -// output is not known, so it is left untouched. -// XApuEnqueueCommand(handle, cmd*, 0) 4 sites; the return value is never read. cmd's first dword is a type -// (1, 2 and 3 seen), the second a stream slot. -// XApuGetResultCount(handle, 0) 1 site; 0 skips the loop that dequeues. -// XApuDequeueResult(handle, out*) 1 site, called count times into a zeroed 0x50-byte local; a negative -// HRESULT skips that result. The loop reads a type at +0, a stream slot -// at +4 and a dword at +0x34. Its per-slot state machine takes a type 1 -// result as "opened" and returns the slot to the title's free list only -// on a type 2 result, after the title enqueued a type 2 command. -// XApuDisconnect(handle, 0x20) 1 site; the return value is never read. The constant second -// argument is not declared here: nothing reads it. // XDspConnectWithMaximumStreamLimit(buffer, u32, u32, 0x80, 1, handle*) 1 site; success is a return of 0. The // buffer comes from the title's XMemAlloc and stays the title's. // XDspActivate(handle, desc*, out*, out*) 1 site; success is a return of 0, else the caller returns -1. The two @@ -30,12 +14,6 @@ // at +4 equals *id. // XDspDeactivate, XDspDisconnect 1 site each, tail calls: the caller returns what they return. // -// HYPOTHESIS: the shared buffer is 0x14000 + 128 * 0x1E00 bytes. 128 slots is what fits 0x14000 at the 0x280 input -// stride, and the DSP connect passes 0x80 as its stream limit; no call site shows a bound. The 16-byte output is -// written as {base, size}; only the base is measured. -// HYPOTHESIS: a type 1 (open) or type 2 (close) command produces one result of the same type for the same slot; the -// title's state machine fits that, the console is not measured. Without the close result the title's 256 stream ids -// run out. Only the two dwords are written; other command types are accepted with S_OK and produce no result. // HYPOTHESIS: XDspActivate's outputs point at zeroed memory owned by the connection. XDspSubmitCommand leaves *id at // the title's 0, so the zeroed status reads as "command 0 done, no error" and the title does not wait. #include @@ -43,7 +21,6 @@ #include #include -#include #include #include #include @@ -54,30 +31,13 @@ namespace { -constexpr size_t kApuBufferSize = 0x14000 + 128 * 0x1E00; - -// shortcut: results past this cap are dropped (each leaks one stream id); raise it if a title that never dequeues -// must still work. -constexpr size_t kMaxResults = 4096; - -struct ApuResult { - uint32_t type; - uint32_t slot; -}; - -struct ApuConnection { - void* buffer; - std::mutex mutex; - std::deque results; -}; - struct DspConnection { uint8_t status[256]; uint8_t stream[256]; }; -// gta6rt --trace FILE: the first call of each function and the first XApuEnqueueCommand of each command type, with -// the caller, so the first boot shows what the title sends without a line per call. +// gta6rt --trace FILE: the first call of each function, with the caller, so the first boot shows what the title sends +// without a line per call. void note(const char* api, uint64_t value, const void* caller) { if (!rt::startup_trace::enabled()) return; static std::mutex mutex; @@ -92,71 +52,6 @@ void note(const char* api, uint64_t value, const void* caller) { rt::startup_trace::quote(rt::startup_trace::where(reinterpret_cast(caller)))); } -HRESULT __stdcall XApuConnect(void* block24, void* out16, void** handle) { - note("XApuConnect", 0, _ReturnAddress()); - if (!handle) return E_INVALIDARG; - *handle = nullptr; - void* buffer = VirtualAlloc(nullptr, kApuBufferSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); // zeroed - if (!buffer) return E_OUTOFMEMORY; - auto* c = new (std::nothrow) ApuConnection; // a throwing new would unwind into the title - if (!c) { - VirtualFree(buffer, 0, MEM_RELEASE); - return E_OUTOFMEMORY; - } - c->buffer = buffer; - *handle = c; - (void)block24; - if (out16) { - const uint64_t info[2] = {reinterpret_cast(buffer), kApuBufferSize}; - std::memcpy(out16, info, sizeof info); - } - return S_OK; -} - -HRESULT __stdcall XApuDisconnect(void* handle) { - note("XApuDisconnect", 0, _ReturnAddress()); - auto* c = static_cast(handle); - if (!c) return E_INVALIDARG; - VirtualFree(c->buffer, 0, MEM_RELEASE); - delete c; - return S_OK; -} - -HRESULT __stdcall XApuEnqueueCommand(void* handle, const uint32_t* command, uint64_t flags) { - note("XApuEnqueueCommand", command ? command[0] : ~0ull, _ReturnAddress()); - (void)flags; - auto* c = static_cast(handle); - if (!c || !command) return E_INVALIDARG; - if (command[0] == 1 || command[0] == 2) { - try { - const std::lock_guard lock(c->mutex); - if (c->results.size() < kMaxResults) c->results.push_back({command[0], command[1]}); - } catch (...) { // out of memory: the result is lost, nothing may unwind into the title - } - } - return S_OK; -} - -uint32_t __stdcall XApuGetResultCount(void* handle, uint64_t flags) { - note("XApuGetResultCount", 0, _ReturnAddress()); - (void)flags; - auto* c = static_cast(handle); - if (!c) return 0; - const std::lock_guard lock(c->mutex); - return static_cast(c->results.size()); -} - -HRESULT __stdcall XApuDequeueResult(void* handle, void* result) { - note("XApuDequeueResult", 0, _ReturnAddress()); - auto* c = static_cast(handle); - if (!c || !result) return E_INVALIDARG; - const std::lock_guard lock(c->mutex); - if (c->results.empty()) return E_FAIL; - std::memcpy(result, &c->results.front(), sizeof(ApuResult)); // the rest stays as the caller zeroed it - c->results.pop_front(); - return S_OK; -} - HRESULT __stdcall XDspConnectWithMaximumStreamLimit(void* buffer, uint32_t a, uint32_t b, uint32_t max_streams, uint32_t flags, void** handle) { note("XDspConnectWithMaximumStreamLimit", max_streams, _ReturnAddress()); @@ -199,14 +94,6 @@ HRESULT __stdcall XDspSubmitCommand(void*, void*, uint32_t*) { } // namespace -SHIM_TABLE(xapu, - {"xapu.dll", "XApuConnect", reinterpret_cast(&XApuConnect)}, - {"xapu.dll", "XApuDequeueResult", reinterpret_cast(&XApuDequeueResult)}, - {"xapu.dll", "XApuDisconnect", reinterpret_cast(&XApuDisconnect)}, - {"xapu.dll", "XApuEnqueueCommand", reinterpret_cast(&XApuEnqueueCommand)}, - {"xapu.dll", "XApuGetResultCount", reinterpret_cast(&XApuGetResultCount)}, -); - SHIM_TABLE(chad, {"chad.dll", "XDspActivate", reinterpret_cast(&XDspActivate)}, {"chad.dll", "XDspConnectWithMaximumStreamLimit", reinterpret_cast(&XDspConnectWithMaximumStreamLimit)}, diff --git a/runtime/test/xapu_chad_test.cpp b/runtime/test/xapu_chad_test.cpp index dffa74404a..95a950356e 100644 --- a/runtime/test/xapu_chad_test.cpp +++ b/runtime/test/xapu_chad_test.cpp @@ -1,7 +1,11 @@ -// Checks the registered xapu.dll and chad.dll shims in the call shapes the executable uses (runtime/shims/xapu_chad.cpp): -// the connections succeed, the APU's shared buffer is zeroed and writable at the offsets the title reaches, commands -// are accepted, an open and a close each give one result and nothing else does, XDspActivate hands out zeroed status -// and stream memory, and both disconnect. +// Checks the registered xapu.dll and chad.dll shims (runtime/shims/xapu.cpp and runtime/shims/xapu_chad.cpp) in the +// call shapes the executable uses and against the layouts xapu.cpp documents. +// +// xapu.dll: the connection's limits and its zeroed memory, writable at the offsets the title reaches; one result per +// accepted command, in command order, with its id echoed; the per-stream queue limit; the error codes, returned or in +// the result; a process command's frame count taken from the Opus packet's table-of-contents byte (RFC 6716, section +// 3.1) and clipped, with silence written; and the result event. The packets are hand-made TOC bytes, not audio. +// chad.dll: XDspActivate hands out zeroed status and stream memory, and both disconnect. #include #include @@ -12,10 +16,10 @@ namespace { -using XApuConnectFn = HRESULT(__stdcall*)(void*, void*, void**); -using XApuDisconnectFn = HRESULT(__stdcall*)(void*); -using XApuEnqueueCommandFn = HRESULT(__stdcall*)(void*, const uint32_t*, uint64_t); -using XApuGetResultCountFn = uint32_t(__stdcall*)(void*, uint64_t); +using XApuConnectFn = HRESULT(__stdcall*)(const void*, void*, void**); +using XApuDisconnectFn = HRESULT(__stdcall*)(void*, uint32_t); +using XApuEnqueueCommandFn = HRESULT(__stdcall*)(void*, const void*, uint32_t*); +using XApuGetResultCountFn = uint32_t(__stdcall*)(void*, uint32_t*); using XApuDequeueResultFn = HRESULT(__stdcall*)(void*, void*); using XDspConnectFn = HRESULT(__stdcall*)(void*, uint32_t, uint32_t, uint32_t, uint32_t, void**); using XDspActivateFn = HRESULT(__stdcall*)(void*, const void*, void**, void**); @@ -23,6 +27,55 @@ using XDspDeactivateFn = HRESULT(__stdcall*)(void*, uint64_t, uint64_t, uint64_t using XDspDisconnectFn = HRESULT(__stdcall*)(void*); using XDspSubmitCommandFn = HRESULT(__stdcall*)(void*, void*, uint32_t*); +constexpr HRESULT kQueueFull = static_cast(0x8AC81000u); +constexpr HRESULT kNoResult = static_cast(0x8AC81001u); +constexpr HRESULT kInvalidCommand = static_cast(0x8AC81002u); +constexpr HRESULT kInvalidStream = static_cast(0x8AC81003u); +constexpr HRESULT kAlreadyActive = static_cast(0x8AC81005u); +constexpr HRESULT kBadPacket = static_cast(0x8AC81008u); + +#pragma pack(push, 1) +struct ConnectInput { + uint32_t processing, streams, commands_per_stream, memory_bytes, frames_per_output, options; +}; +struct ConnectOutput { + void* memory; + HANDLE result_event; +}; +struct CommandId { + uint32_t kind, stream, sequence, options; + uint64_t context; +}; +struct ActivateCommand { + CommandId id; + uint32_t channels, init_bytes; + const void* init; + float start_pitch; + uint32_t processing_bytes; + void* processing; +}; +struct ProcessCommand { + CommandId id; + float pitch_ramp, target_pitch; + uint32_t first_frame, frame_count, input_bytes; + const uint8_t* input; + uint32_t output_bytes; + uint8_t* output; +}; +struct Result { + CommandId id; + uint32_t state; + uint64_t state_data, usec; + HRESULT error; + uint32_t frames, output_bytes; + uint8_t* output; + float pitch; + uint32_t input_bytes; + const uint8_t* input; +}; +#pragma pack(pop) +static_assert(sizeof(ActivateCommand) == 56 && sizeof(ProcessCommand) == 64 && sizeof(Result) == 0x50, "layouts"); + int g_checks = 0; int g_failures = 0; @@ -39,6 +92,8 @@ T get(const char* dll, const char* name) { return reinterpret_cast(fn); } +CommandId id(uint32_t kind, uint32_t stream, uint32_t options = 0) { return {kind, stream, 7, options, 0x1234}; } + } // namespace int main() { @@ -56,39 +111,165 @@ int main() { check(rt::shims::owns_dll("xapu.dll") && rt::shims::owns_dll("chad.dll"), "the shims own xapu.dll and chad.dll"); if (g_failures) return 1; - // XApuConnect(block24*, out16*, handle*), success read as SUCCEEDED. - uint8_t out24[24]; - uint64_t out16[2] = {}; - std::memset(out24, 0xcc, sizeof out24); + // XApuConnect(const ConnectInput*, ConnectOutput*, handle*): the first argument is read, never written. + ConnectOutput out{}; void* apu = nullptr; - check(SUCCEEDED(connect(out24, out16, &apu)) && apu, "XApuConnect succeeds with a handle"); - check(out24[0] == 0xcc && out24[23] == 0xcc, "XApuConnect leaves the title's 24-byte block alone"); - auto* base = reinterpret_cast(out16[0]); - check(base != nullptr && out16[1] >= 0x14000 + 128 * 0x1E00, "XApuConnect returns the shared buffer and its size"); - if (base) { - const size_t last_output = 0x14000 + 127 * 0x1E00 + 0x1E00 - 1; // the end of slot 127's output - check(base[0] == 0 && base[last_output] == 0, "the shared buffer is zeroed"); - base[127 * 0x280] = 1; - base[last_output] = 1; - check(base[127 * 0x280] == 1 && base[last_output] == 1, "the shared buffer is writable at slot 127"); - } - check(connect(out24, out16, nullptr) == E_INVALIDARG, "XApuConnect without a handle pointer fails"); + ConnectInput bad{1, 0, 2, 0x10000, 0, 0}; + check(connect(&bad, &out, &apu) == E_INVALIDARG, "zero streams is E_INVALIDARG"); + bad = {1, 501, 2, 0x10000, 0, 0}; + check(connect(&bad, &out, &apu) == E_INVALIDARG, "more than 500 streams is E_INVALIDARG"); + bad = {1, 4, 17, 0x10000, 0, 0}; + check(connect(&bad, &out, &apu) == E_INVALIDARG, "more than 16 commands per stream is E_INVALIDARG"); + bad = {1, 4, 2, 0, 0, 0}; + check(connect(&bad, &out, &apu) == E_INVALIDARG, "no memory is E_INVALIDARG"); + bad = {1, 4, 2, 0x10000, 256, 0}; + check(connect(&bad, &out, &apu) == E_INVALIDARG, "frames per output for decoding is E_INVALIDARG"); + bad = {2, 4, 2, 0x10000, 0, 0}; + check(connect(&bad, &out, &apu) == static_cast(rt::shims::kENotImpl), + "a processing kind other than Opus decoding is E_NOTIMPL"); + check(apu == nullptr, "a failed XApuConnect hands out no handle"); + + // The memory the title addresses: input at base + slot * 0x280, output at base + 0x14000 + slot * 0x1E00. + constexpr uint32_t kMemory = 0x14000 + 128 * 0x1E00; + const ConnectInput in{1, 128, 2, kMemory, 0, 8}; + const ConnectInput in_copy = in; + check(SUCCEEDED(connect(&in, &out, &apu)) && apu, "XApuConnect for Opus decoding, 128 streams, 2 commands each"); + check(std::memcmp(&in, &in_copy, sizeof in) == 0, "XApuConnect leaves its input alone"); + check(out.memory != nullptr && out.result_event != nullptr, "it hands out memory and a result event"); + if (!apu || !out.memory) return 1; + auto* base = static_cast(out.memory); + const size_t last_output = 0x14000 + 127 * 0x1E00 + 0x1E00 - 1; // the end of slot 127's output + check(base[0] == 0 && base[last_output] == 0, "the memory is zeroed"); + base[127 * 0x280] = 1; + base[last_output] = 1; + check(base[127 * 0x280] == 1 && base[last_output] == 1, "the memory is writable at slot 127"); + base[127 * 0x280] = 0; + base[last_output] = 0; + + Result r{}; + check(dequeue(apu, &r) == kNoResult, "XApuDequeueResult with nothing queued is 0x8AC81001"); + uint32_t dequeued = 99; + check(count(apu, &dequeued) == 0 && dequeued == 0, "XApuGetResultCount: nothing ready, none dequeued"); - // Command types 1, 2 and 3 as the title builds them; the third argument is 0 at every site. - for (uint32_t type = 1; type <= 3; ++type) { - uint32_t command[16] = {type, 5}; - check(enqueue(apu, command, 0) == S_OK, "XApuEnqueueCommand accepts a command"); + // Activate stream 3 (stereo) and process one packet; the title's sites pass a null third argument. + const ActivateCommand activate{id(1, 3), 2, 0, nullptr, 1.0f, 0, nullptr}; + check(enqueue(apu, &activate, nullptr) == S_OK, "activate stream 3 with a null count pointer"); + check(WaitForSingleObject(out.result_event, 0) == WAIT_TIMEOUT, "a command not asking for it leaves the event"); + uint8_t* const packet = base + 3 * 0x280; + uint8_t* const pcm = base + 0x14000 + 3 * 0x1E00; + packet[0] = (31 << 3) | 0; // one 20 ms CELT frame (config 31, code 0): 960 frames per channel + std::memset(pcm, 0x55, 0x1E00 + 16); // the slot and the start of the next, to see nothing past it is written + ProcessCommand process{id(3, 3, 1), 0.0f, 1.0f, 0, 960, 40, packet, 960 * 8, pcm}; + uint32_t total = 0; + check(enqueue(apu, &process, &total) == S_OK && total == 2, "process on stream 3; two commands accepted"); + check(WaitForSingleObject(out.result_event, 0) == WAIT_OBJECT_0, "a command asking for it signals the event"); + check(WaitForSingleObject(out.result_event, 0) == WAIT_TIMEOUT, "the event resets itself"); + check(enqueue(apu, &process, &total) == kQueueFull && total == 2, + "a third command on a stream of two is 0x8AC81000 and not counted"); + check(count(apu, nullptr) == 2, "two results ready, with a null dequeued pointer"); + + check(dequeue(apu, &r) == S_OK && r.id.kind == 1 && r.id.stream == 3 && r.id.sequence == 7 && + r.id.context == 0x1234 && r.error == S_OK && r.pitch == 1.0f, + "results come in command order: the activate first, its id echoed"); + check(dequeue(apu, &r) == S_OK && r.id.kind == 3 && r.error == S_OK, "the process result follows"); + uint32_t dword34 = 0; + std::memcpy(&dword34, reinterpret_cast(&r) + 0x34, 4); + check(r.frames == 960 && dword34 == 960 * 8 && r.output == pcm && r.input == packet && r.input_bytes == 40, + "960 stereo float frames, the byte count at +0x34, the buffers echoed"); + bool silent = true; + for (int i = 0; i < 960 * 8; ++i) silent = silent && pcm[i] == 0; + check(silent && pcm[960 * 8] == 0x55, "the output range is silence, and nothing past it is written"); + check(count(apu, &dequeued) == 0 && dequeued == 2, "nothing ready, two dequeued"); + + // The TOC byte's frame size and count (RFC 6716, section 3.1), one stereo packet each. + struct Toc { + uint8_t toc, count; + uint32_t frames; + const char* what; + } const tocs[] = { + {(0 << 3) | 0, 0, 480, "SILK 10 ms, code 0: 480 frames"}, + {(3 << 3) | 1, 0, 5760, "SILK 60 ms, code 1 (two frames): 5760 frames"}, + {(13 << 3) | 2, 0, 1920, "hybrid 20 ms, code 2 (two frames): 1920 frames"}, + {(16 << 3) | 3, 5, 600, "CELT 2.5 ms, code 3 with five frames: 600 frames"}, + }; + for (const Toc& t : tocs) { + packet[0] = t.toc; + packet[1] = t.count; + process = {id(3, 3), 0.0f, 1.0f, 0, 6000, 40, packet, 0x1E00 * 4, pcm}; + r = {}; + check(enqueue(apu, &process, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == S_OK && + r.frames == (t.frames < 0x1E00 * 4 / 8 ? t.frames : 0x1E00 * 4 / 8), + t.what); } - check(count(apu, 0) == 2, "the open and the close each queued a result, the type 3 command none"); - for (uint32_t type = 1; type <= 2; ++type) { - uint32_t queued[0x50 / 4] = {}; - check(dequeue(apu, queued) == S_OK && queued[0] == type && queued[1] == 5 && queued[2] == 0 && queued[13] == 0, - "XApuDequeueResult returns the type and slot and leaves the rest zeroed"); + + // first_frame and frame_count clip like a decode: three 20 ms frames (code 3, count 3) = 2880, from frame 2000. + packet[0] = (31 << 3) | 3; + packet[1] = 3; + process = {id(3, 3), 0.0f, 1.0f, 2000, 4000, 40, packet, 0x1E00, pcm}; + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.error == S_OK && r.frames == 880 && r.output_bytes == 880 * 8, "frames from first_frame to the packet's end"); + process.frame_count = 300; + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.frames == 300, "no more than frame_count"); + process.frame_count = 4000; + process.output_bytes = 100 * 8 + 7; + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.frames == 100 && r.output_bytes == 800, "and no more than the output holds"); + + // Errors carried in the result: the command is accepted and its result says what went wrong. + packet[1] = 7; // seven 20 ms frames: 140 ms, longer than an Opus packet may be + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.error == kBadPacket && r.frames == 0, "an impossible packet: 0x8AC81008 in the result"); + packet[0] = (31 << 3) | 3; + packet[1] = 0; + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.error == kBadPacket, "a code 3 packet of zero frames: 0x8AC81008"); + ProcessCommand empty = process; + empty.input_bytes = 0; + check(enqueue(apu, &empty, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == E_INVALIDARG, + "an empty input: E_INVALIDARG in the result"); + empty = process; + empty.output = nullptr; + check(enqueue(apu, &empty, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == E_INVALIDARG, + "a null output: E_INVALIDARG in the result"); + ProcessCommand stray = process; + stray.id.stream = 4; + check(enqueue(apu, &stray, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == kInvalidStream, + "a process on a stream never activated: 0x8AC81003 in the result"); + check(enqueue(apu, &activate, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == kAlreadyActive, + "activating an active stream: 0x8AC81005 in the result"); + ActivateCommand surround = activate; + surround.id.stream = 5; + surround.channels = 6; + check(enqueue(apu, &surround, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.error == E_INVALIDARG, + "six channels: E_INVALIDARG in the result"); + + // Errors returned at once, with no result. + stray.id.stream = 128; + check(enqueue(apu, &stray, nullptr) == kInvalidStream, "a stream past the connection's is 0x8AC81003"); + const CommandId unknown = id(9, 3); + check(enqueue(apu, &unknown, nullptr) == kInvalidCommand, "an unknown kind is 0x8AC81002"); + check(count(apu, nullptr) == 0, "neither left a result"); + + // Notify and reset give a result; deactivate gives one and closes the stream. + for (uint32_t kind : {4u, 5u, 2u}) { + const CommandId command = id(kind, 3); + check(enqueue(apu, &command, nullptr) == S_OK && dequeue(apu, &r) == S_OK && r.id.kind == kind && + r.id.stream == 3 && r.error == S_OK, + "notify, reset and deactivate each give a result of their kind for their stream"); } - check(count(apu, 0) == 0, "XApuGetResultCount is 0 again"); - uint8_t result[0x50] = {}; - check(FAILED(dequeue(apu, result)), "XApuDequeueResult on the empty queue fails"); - check(disconnect(apu) == S_OK, "XApuDisconnect succeeds"); + process.id.stream = 3; + enqueue(apu, &process, nullptr); + dequeue(apu, &r); + check(r.error == kInvalidStream, "after deactivate the stream takes no process command"); + check(enqueue(apu, &activate, &total) == S_OK && dequeue(apu, &r) == S_OK && r.error == S_OK, + "and it can be activated again"); + check(disconnect(apu, 0x20) == S_OK, "XApuDisconnect(handle, 0x20)"); // XDspConnectWithMaximumStreamLimit(buffer, u32, u32, 0x80, 1, handle*), success read as a return of 0. alignas(64) static uint8_t dsp_buffer[4096]; @@ -99,10 +280,10 @@ int main() { void* stream = nullptr; check(dsp_activate(dsp, description, reinterpret_cast(&status), &stream) == 0, "XDspActivate returns 0"); check(status && stream && static_cast(status) != stream, "XDspActivate writes both outputs"); - uint32_t id = 0; - check(dsp_submit(stream, dsp_buffer, &id) == 0, "XDspSubmitCommand returns 0"); + uint32_t dsp_id = 0; + check(dsp_submit(stream, dsp_buffer, &dsp_id) == 0, "XDspSubmitCommand returns 0"); // What the title's wait reads: no error at +0xc and the submitted id at +4. - check(status && status[3] == 0 && status[1] == id, "the status block reports the submitted command as done"); + check(status && status[3] == 0 && status[1] == dsp_id, "the status block reports the submitted command as done"); check(dsp_deactivate(dsp, 0, 0, 0) == 0, "XDspDeactivate returns 0"); check(dsp_disconnect(dsp) == 0, "XDspDisconnect returns 0"); From 19559fec600f6e2899a5e96d6a44976ab07f3d65 Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 24 Nov 2026 22:27:07 +0100 Subject: [PATCH 2/2] scripts: build xapu.cpp in the cl.exe fallback (review of #1144) The fallback file list in build_runtime.ps1 must match the gta6rt sources CMake has; xapu.cpp was missing, so test_build_runtime_fallback failed and a build without CMake would have had no xapu.dll shim. Co-Authored-By: Claude Opus 5.5 --- scripts/build_runtime.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1 index f24cc073fb..98a5470ffb 100644 --- a/scripts/build_runtime.ps1 +++ b/scripts/build_runtime.ps1 @@ -86,7 +86,7 @@ $build || exit /b 1 Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3) and without the Rust XMA2 decoder (XMA voices are silent). Install CMake + Ninja or VS's CMake tools component to get it." $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } - $files = "src\main.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\com_shim.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } + $files = "src\main.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\com_shim.cpp", "shims\bcrypt_rng.cpp", "shims\xapu.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } $body = @"