Sonic 4: Episode II Research
Rebuilding a 2012 Sonic game in modern C++, checked against the original.
Rebuilding an engine's behaviour and checking it against the original code
Engineering research · Jul 2026 – present
At a glance
- Challenge
- Rebuild a 2012 game engine whose file formats are undocumented, and show the rebuilt code behaves like the original, not just that it looks right.
- Solution
- A C++17 engine and Direct3D 9 renderer; selected routines from the original code run in a CPU emulator and are compared with the rebuilt versions.
- Result
- Zero recorded differences in the compared routines, 52 native, 423 managed and 51 Python tests passing, and a native Direct3D 9 preview of the first act. Prototype.
The problem
The game runs on the AliceNN engine, whose assets use undocumented formats, and reconstructed game code can look right on screen while its results drift from the original's. The work is only worth having if its behaviour can be checked against the original code.
Approach
- Reconstruct the engine in C++17: format readers, skeletal animation, materials and lighting, and a Direct3D 9 renderer that drives the game's own compiled shaders from a user-supplied copy.
- Run selected routines from the original executable in a CPU emulator and compare their results with the C++ versions on 32- and 64-bit builds.
- Model the original's x87 floating-point precision explicitly, so both builds reproduce its results in the checked cases.
Outcome
A native Direct3D 9 preview (15 Sep 2026) renders the first act from a user-supplied copy, using the game's own compiled shaders, with Sonic's movement, rings, sounds and particles connected. An earlier C#/MonoGame prototype (July, phase 1) ran Zone 1 Act 1 from start to goal.
Evidence
Zero recorded differences in the emulator comparisons of the selected routines. 52 native, 423 managed and 51 Python tests pass on synthetic inputs (24 Sep 2026); the repository contains no executables, game archives, audio or disassembly.
Limitations
A prototype. Springs, a complete act, Tails, the HUD and bosses are not done, the comparisons cover individual routines rather than whole scenes, and complete engine and game compatibility are not claimed.
Built with
- C++17
- Direct3D 9
- CMake
- Python
- x86