Commit Graph

20 Commits

Author SHA1 Message Date
ccd36246f7 runtime: acphal.dll shim with APU heap management and SHAPE context allocation (RT-5, ASSET-587)
- Resolve Stop 28 boot blocker preventing GTA 6 from launching: acphal.dll!ApuCreateHeap and AcpHalAllocateShapeContexts.
- Implement genuine APU physical memory management (ApuCreateHeap, ApuAlloc, ApuFree, ApuIsVirtualAddressValid, ApuMapApuAddress, ApuMapVirtualAddress):
  - Support cached and non-cached heap allocations with flags routing (flags=2 to non-cached, flags=1/0 to cached).
  - Genuine block tracking allowing proper memory reclamation and reuse upon ApuFree.
  - Disjoint APU 32-bit physical address space mapping with round-trip address conversions.
- Implement IAcpHal interface in AcpHalCreate:
  - Slot 0 (connect): S_OK.
  - Slot 1 (disconnect): S_OK.
  - Slot 2 (submit_command): S_OK (unblocks fatal int3 at +0x43ad94e at boot).
  - Slots 3 and 4 (pop_message, get_num_messages): return 0.
  - Slot 5 (release): releases object.
- Implement GDK SHAPE_CONTEXTS and exact layout:
  - Six context counts and arrays: SRC, EQCOMP, FILTVOL, DMA, XMA, PCM.
  - Structure alignment with xmaContextArray at offset +0x38, matching retail executable measurement (350 contexts x 64 bytes).
  - AcpHalReleaseShapeContexts releases allocated context arrays.
- Classify acphal.dll HRESULT imports in registry.cpp and update unimplemented_policy_test.cpp.
- Add acphal_test in runtime/CMakeLists.txt and python verification test tests/test_acphal_abi.py.
- Update fallback file list in scripts/build_runtime.ps1.

No game data. AI-assisted.
2026-11-23 22:19:47 +01:00
0656b0b200 Loader: W lookups find a mapped image by its non-ASCII name; ANSI lookups ignore case outside ASCII (#6754)
Squash-merged after diff review of PR #6754
2026-11-23 10:47:01 -06:00
57c175391d Revert #2490: its console-ABI list proxy breaks run_tiny_frame (please rebase and split)
With it, d3d12_xs reads list slot 48 as the console's IASetVertexBuffers, so the PC-shaped fixture list's
ClearRenderTargetView never runs and Close fails. The branch also changes runtime/src/pe_loader.cpp and carried
committed conflict markers in docs/fssm_crosscheck.md. Its docs rows go with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 04:42:53 -05:00
f95bea1d88 shims/loader: GetModuleFileName answers for the mapped images
GetModuleFileName was host-bound, so a mapped image asking for its own
path got gta6rt.exe's. The bundled-module ops now expose the main image
and each module's load path: GetModuleFileNameA/W return the mapped
module's path (the exe for a null handle, any bundled module for its
base) and GetModuleFileName falls through to the host otherwise.
GetModuleHandle(nullptr) answers the mapped exe's base the same way.
A unix-absolute stored path is spelled Z:\... under Wine.

First use measured: the package's game_scarlett_master.exe (a payload
verification probe, not the engine) took its own module path as the
scan root and verified the full 1.0.2.1 payload through the file
layer — 104/104 files, 223,534,748,018 bytes, rpf 22/22, ttpf 57/57,
png 5/5, dll 16/16, bad magic 0 — verdict PASS, exit 0.

Tested: clang-cl 20 + xwin cross-build clean; loader_test 87 checks,
xs_proxy_mock_test PASS under Wine. AI-assisted.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 17:53:08 -07:00
7cd6aa7c93 loader/tools: review fixes for import routing and the inventory
pe_loader: resolve() and resolve_forwarder() key the DLL name with
dll_key() — lower-case, trailing '.' dropped, ".dll" added when there
is no extension — the file-name rule LoadLibrary applies. Without it an
import naming "GameInput" or "gameinput.dll." missed the shim and
owns_dll lookups while LoadLibraryExA still bound a host namesake.

registry: xaudio2_9.dll ordinals 8-10 classify as hresult (host table
measured: XAudio2CreateV2_9 / WithVersionInfo / WithSharedContexts);
the redist's ordinal table is unconfirmed and stays other.

import_inventory: classify parity for the #1 ordinals; the delay-import
directory (entry 13) is read with the loader's checks; the descriptor
table stops at Name == 0 and unreadable names fail like read_string;
host-bound imports report as host instead of unimplemented thunk
(owns_dll ported); thunk tables deduplicate by RVA under a global cap.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 16:41:17 -07:00
2c6424bbc3 shims: classify the measured console ordinal imports (xaudio2_9 #1, gameinput #1) 2026-11-22 16:40:33 -07:00
68733d6606 Merge pull request #2021 from jaybeebabageyus 2026-11-22 11:41:02 -05:00
f4a3fe8d4a runtime: propagate LoadLibraryEx flags and reject DONT_RESOLVE_DLL_REFERENCES for bundled DLLs 2026-11-22 17:14:23 +01:00
81c6cfe4fd Merge pull request #2021 from jaybeebabageyus 2026-11-22 10:40:29 -05:00
4c2800bd27 Merge pull request #1912 from Nolan Cotter
# Conflicts:
#	docs/README.md
#	docs/d3d12_vulkan.md
#	docs/i18n/README.md
2026-11-22 10:39:23 -05:00
47f4cdc643 runtime: route LoadLibrary/GetProcAddress of bundled package DLLs through rt::Loader 2026-11-22 16:21:16 +01:00
d6443b1524 Startup trace: never replace an existing file; write UTF-8 only
Review on #1756 (Vonsek):
- The trace is opened before the loader reads the image, so `wb` could
  truncate an input named by mistake (the image itself). open() now
  uses "x" mode and fails with EEXIST on an existing path; gta6rt says
  so and exits with 2.
- OutputDebugStringA text is in the ANSI code page. It is converted
  to UTF-8 before quoting, so a byte such as 0xE9 no longer breaks the
  JSON lines. Host module names now come from GetModuleFileNameW,
  converted to UTF-8, for the same reason.

startup_trace_test: an existing file is refused with EEXIST and its
bytes survive, the trace stays off; an ANSI debug string with 0xE9
appears as its UTF-8 form and the whole file is valid UTF-8.
2026-11-22 12:06:49 -03:00
2dca597bd9 Runtime: opt-in startup trace (gta6rt --trace FILE)
Writes one JSON object per line, flushed per event: module maps, TLS
callbacks, DllMain results, the first call of each unimplemented import
with its caller as module+RVA, OutputDebugString text, exceptions with
module+RVA and a short unwind, and the exit code. A vectored handler
records and returns EXCEPTION_CONTINUE_SEARCH, so behaviour is unchanged.
Off by default.

startup_trace_test builds a synthetic DLL image (no game data) and
checks each event kind.
2026-11-22 12:03:22 -03:00
8fc8147bf3 docs+shims: fold in the measured Xbox ABI surface from sibling layers
Other Xbox Series compatibility-layer efforts have run the same package's
console DLLs, shader pack and retail titles. This folds their published
measurements into docs/d3d12_vulkan.md §7 — the CS root-argument packing, the
inline record opcodes, the mesh inputs, the OpenExistingHeapFromAddress UMA
recipe, 64 KiB physical pages, more command-list slot numbers and the console
export surface — each row paraphrased with its measurement basis noted.

The unimplemented-import classifier learns the console DLL names from that
surface (d3d12_xs!D3D12XboxCreateSyntheticDevice, xaudio2_9!XAudio2Create,
gameinput!GameInputCreate, dstorage_xs!DStorageGetFactory) so fail/stop
policies report E_NOTIMPL honestly instead of faking success; functions with
no measured return (xg_xs, AcpHal, D3D12XboxSetProcessDebugFlags) stay `other`.
Classification checks added to unimplemented_policy_test.

AI-assisted. Tested: test_i18n_index, test_docs_links, compileall. The
registry/test change is Windows-only C++ and was not compiled here.
2026-11-22 07:57:55 -07:00
5b9782f68d shims: mapped_image_base, the base of the mapped module holding an address
Answers from the same per-Loader lookups the unimplemented-import report uses,
under the same lock. Used by the next commit.
2026-11-22 12:29:52 +01:00
6f5b59ea81 runtime: serve LoadLibrary/GetProcAddress of shim-owned modules; xgameruntime.lib's run-time entry points
The package's GDK modules don't import xgameruntime.dll. libHttpClient.GDK.dll and XCurl.dll have no import
entry for it, but both carry the wide string "xgameruntime.dll" and the names InitializeApiImpl[Ex|Ex2],
QueryApiImpl and UninitializeApiImpl next to a statically linked XGameRuntimeInitialize: xgameruntime.lib's
thunks LoadLibraryW the runtime and GetProcAddress those names. Bound to the host, that bypasses the offline
shim. The executable is very likely built the same way.

- library_loader.cpp: LoadLibrary*/GetModuleHandle*/GetProcAddress/FreeLibrary for kernel32, kernelbase and the
  api-ms-win-core-libraryloader sets. A module the registry owns (rt::shims::owns_dll) gets a pseudo-handle and
  GetProcAddress resolves through the registry; an unserved name is NULL with ERROR_PROC_NOT_FOUND. Every other
  module goes to the host.
- xgameruntime.cpp: the five entry points, with the signatures and the unknown-class error documented by
  xodus-gaming/xgameruntime-docs (GPL-3.0, facts only). QueryApiImpl logs the class and interface ids and refuses
  them, so the first boot with the executable names the COM interfaces to implement.
- xgameruntime_test drives the path through XCurl.dll's api-set binding; docs/runtime_imports.md records the
  measurement and the new dry-run counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:58:12 +00:00
16e7591419 runtime: thunk deduplication, XGameRuntime shims, PE loader long paths, and drive-root packaging 2026-11-22 12:19:06 +05:30
7cfa4354fe runtime: unimplemented-import stub review fixes and ABI tests
- make_common_stub checks RtlAddFunctionTable and reports a failure once;
  the stub keeps working, only stack walks through it stop.
- rt_unimplemented keys per-import state by the thunk's `what` pointer, so a
  repeat call does one map lookup and builds no strings.
- A test hook (set_unimplemented_test_hook) lets unimplemented_policy_test
  check, from inside the call, that rsp is aligned and that
  RtlLookupFunctionEntry/RtlVirtualUnwind walk through rt_unimplemented and
  the stub back to the caller.
- abi_probe.asm (MASM) calls a thunk with rbx/rbp/rdi/rsi/r12-r15 and
  xmm6-xmm15 set to patterns and compares them afterwards, with a control
  callee that clobbers rbx and xmm6.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 01:58:29 +01:00
bcb9f6d5f2 runtime: LEONIDA_UNIMPLEMENTED=log|fail|stop policy for imports with no binding
An unimplemented import used to return 0 silently, which is S_OK for an
HRESULT function with its out parameters never written. The thunk now passes
the caller's return address and rcx/rdx/r8/r9 to a shared stub, and
LEONIDA_UNIMPLEMENTED picks the behaviour:

- log (default): exactly as before.
- fail: E_NOTIMPL for imports known to return HRESULT (D3D12Create*/Serialize*,
  CreateDXGIFactory*, XGameRuntimeInitialize, and the GDK XAsync/XTaskQueue/
  XUser/XStore/XGameSave/XPackage/XGameUi families minus their documented
  void/bool/int functions), 0 otherwise.
- stop: print the import, the caller as module+RVA and the four argument
  registers, then break under a debugger or exit with code 3.

--dry-run now counts unimplemented imports by return class. The stub zeroes
xmm0 and has unwind info, so float callers and debuggers are unaffected.
unimplemented_policy_test builds a synthetic image and checks all three modes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 01:46:33 +01:00
db0dc8bd5e Initial commit: Leonida, build-it-yourself PC port groundwork
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V),
asset export via rpf9-explorer's Core (submodule), PE loader and shim
skeleton, and make_game.py, which builds from the user's own copy of the game.
No game data, keys or executables are included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:22:16 -05:00