DEV Community

master48
master48

Posted on AI-assisted

gta4-reversed: Starting a C++20 Runtime Reimplementation of GTA IV (1.0.7.0) — Crossing 1%

Most recent Grand Theft Auto IV reverse-engineering projects focus on Xbox 360 static recompilation or Rust rewrites. I wanted to share gta4-reversed, an early-stage open-source C++20 project that tackles the PC GTAIV.exe 1.0.7.0 (x86) binary directly through runtime ASI injection.

Today, the project just crossed its first milestone: 1% (462 / 43,740 functions implemented, ~1.06%).

  • GitHub Repository: https://github.com/master4824/gta4-reversed
  • License: MIT (Source code only — no copyrighted game files, dumps, or compiled binaries are included. Requires a legitimate copy of GTA IV 1.0.7.0.)

Why Runtime ASI Injection Instead of a Standalone .exe?

Inspired by how gta-reversed approaches GTA: San Andreas, gta4-reversed compiles into a single plugin (gta4_reversed.asi, zero external dependencies, CMake + Ninja + MSVC x86) that injects into a real running copy of GTAIV.exe:

  1. Incremental Verification: Every single hooked function can be tested immediately inside the live game without breaking the rest of the 43,740 functions.
  2. Eliminating Hook::Call Over Time: Initially, unreversed callees bridge back to original game addresses via Core::Hook::Call(...). As lower-level systems are rewritten, those hex calls are replaced by direct C++20 calls until a module hits 0 fallbacks (100% Pure C++).
  3. Clean Scope: Original game files on disk are never modified, and DRM/anti-tamper/launcher code is completely out of scope.

Interesting Technical Challenges So Far

Reimplementing a 2008 32-bit MSVC Link-Time Code Generation (LTCG) binary comes with plenty of surprises:

  • Non-Standard Register Calling (__usercall & Hidden ECX/EDX Assumptions): LTCG routinely omits frame rules and passes arguments in ESI or EAX, or assumes small leaf functions preserve ECX/EDX across calls. Even decompilers sometimes hide mov ecx, ... before a __thiscall (which recently caused a real crash at spawn until checked directly in x86 disassembly). Where needed, small __declspec(naked) register-preserving bridges keep callers safe.
  • Sharing RAGE's Allocator via TLS: Calling standard malloc/new for engine objects corrupts RAGE's internal memory pools. For classes like CPool, CDummyObject, and CIplStore, allocations go directly through the game's sysMemAllocator fetched from Windows x86 TLS (__readfsdword(0x2C)).
  • Strict Struct Layout Verification: Classes like CPed (0xF00 bytes) and CPad (0x3A84 bytes) are locked down with VALIDATE_SIZE and VALIDATE_OFFSET (static_assert) checks against 1.0.7.0 disassembly.
  • Built-in VEH Crash Diagnostics: A Vectored Exception Handler (gta4_reversed.log) catches runtime crashes and subtracts the ASLR delta to log the exact GTAIV.exe IDA virtual address and stack trace.

Current Status (462 / 43,740 Functions — ~1.06%)

  • 11 Modules at 100% Pure C++ (0 original game fallbacks):
    • Core: Matrix, Pool, Vector
    • Game: LoadingScreens, Pad
    • Rage (Physics): phBound, phBoundComposite, phInst, phArticulatedCollider, phConstraint, phLevelNew
  • Core Subsystems Implemented & Hooked: CPlayerInfo, CWanted, CBuilding, CDummyObject, CModelInfo, CTxdStore, CStreaming, CCamera, CCam, rage::fiStream, CFileMgr, CIplStore, CFont, CEntity, CDynamicEntity, CPhysical, CPed, CVehicle, CWeaponInfo, CTimer, CClock, CWeather, CStats, CCheat, CWorld, phArchetype, phBoundBVH, phCollider, phSimulator.
  • CI: Automated MSVC x86 CMake + Ninja build check via GitHub Actions.

Looking for Contributors

43,740 functions is a massive undertaking, and even small contributions help—whether it's converting remaining Core::Hook::Call wrappers to pure C++, verifying struct fields/sizes, or helping debug physics/entity subsystems.

If you're interested in C++20, RAGE engine internals, or GTA IV modding, check out the repo, open issues, or CONTRIBUTING.md!

Top comments (0)