Reverse Engineering and Rewriting a Classic Game with LLMs: An Engineering Practice
This article walks through a practical pipeline for rebuilding a classic real-time strategy game from binaries and proprietary assets alone, using AI coding tools without access to the original source. It covers a four-stage milestone model (pre-Alpha, Alpha UI, Beta combat, multiplayer), a sample-matrix approach to reverse engineering undocumented formats with golden-sample equivalence checks, declarative UI layout with replayable action logs, deterministic simulation via fixed-point math and seeded randomness, lockstep networking, observability, and the compliance and evidence-based review practices needed to keep high-volume automated output maintainable.
1. The Starting Point: An “Impossible” Engineering Problem
A classic real-time strategy game whose official source code was lost long ago leaves behind only executables, asset packs, and a large set of private formats. That makes the engineering goal both clear and difficult: rebuild a runnable, extensible, multiplayer-capable modern implementation using only the binaries and assets, without touching the original project.
Tasks like this are not unusual in the industry. They usually fall under “legacy system reverse engineering and rebuilding.” The difficulty is not any single algorithm but the combination of three constraints: unknown formats, required behavioral equivalence, and the need for a sustainable codebase. Handing those three constraints to an AI coding tool is the starting point of this article.
One point needs emphasis up front: the target of reverse engineering should be something the user is authorized to work with, and the rebuilt product should use independently written code and self-owned assets. Directly transplanting a protected implementation is off the table. This is the premise behind every technical choice that follows.
2. Overall Approach: Turning “Rewrite” into a Verifiable Engineering Pipeline
To keep high-intensity automated output from getting out of control, the goal must first be split into layers where correctness can be decided mechanically. A four-stage milestone model works well in practice:
- Pre-Alpha: project skeleton, asset pipeline, closed loop for format parsing;
- Alpha (UI layer): menus, loading, HUD, input, and camera control;
- Beta (combat layer): unit pathfinding, attack resolution, damage, and state machines;
- Multiplayer layer: deterministic sync, rooms, and reconnection.
Every layer needs a runnable acceptance artifact, not a document. For example, the pre-Alpha acceptance artifact is “decode and render the opening video frame by frame,” and the Beta acceptance artifact is “two identical armies fight for 10 minutes under a fixed random seed with no drift.”
3. Stage One: Reverse Engineering Private Formats the Right Way
Resource formats in old games often have no public specification and no mature parsing library. Typical traits are magic-number headers, compact bitfields, magic constants, and self-implemented compression. The recommended path for handling them is below.
Step one: build a sample matrix. Sample assets by type in layers: video, audio, maps, sprite atlases, palettes, and script text. Take several extreme samples for each type (smallest, largest, corrupted, truncated) for regression use.
Step two: form structural hypotheses and verify them. Start with a hex view to confirm the header layout, then write a minimal probe script that prints and asserts field by field:
// Illustrative: skeleton of a format probe; field names and values must be confirmed against real samplesfn probe(header: &[u8]) -> Result<Meta, Error> {assert_eq!(&header[0..4], b"MAGI"); // magic numberlet version = u16::from_le_bytes([header[4], header[5]]);let frames = u32::from_le_bytes(header[6..10].try_into()?);let width = u16::from_le_bytes([header[10], header[11]]);let height = u16::from_le_bytes([header[12], header[13]]);Ok(Meta { version, frames, width, height })}
Step three: verify “behavioral equivalence” of the decoder. “It produces an image” is not the bar; “identical pixel by pixel or sample by sample” is. Freeze the reference implementation’s output as golden samples, add them to continuous integration, and let any regression fail immediately.
Step four: put license compliance first. If a reference algorithm exists only in a restrictively licensed implementation, the right move is not copy and paste. Instead, read public algorithm descriptions and format documentation, implement independently, and record the reference source, the license conclusion, and an independent-implementation note in code comments and the repository compliance checklist. This respects others’ work and keeps the product’s license consistently permissive.
A common mistake is “copy first, modify later.” A more reliable engineering habit is “define the interface first, write the tests second, implement independently last,” focusing attention on verifiable behavior rather than code similarity.
4. Stage Two: Rebuilding the UI and Interaction for Modern Platforms
The UI layer looks simple, but it determines debugging efficiency for everything that follows. A three-part progression is recommended: asset pipeline, layout system, event loop.
The asset pipeline converts original atlases, palettes, and fonts into modern textures and glyph caches. The layout system replaces hardcoded coordinates with declarative descriptions. The event loop unifies keyboard, mouse, and gamepad input and emits replayable action logs.
A declarative UI description can look like this:
screen: main_menuwidgets:- id: startrect: [320, 200, 240, 48]on_click: "matchmaking.open"- id: replayrect: [320, 260, 240, 48]on_click: "replay.load_last"
With action logs in place, UI problems can be covered by a record-replay-assert loop instead of repeated manual clicking.
5. Stage Three: Combat Logic and Determinism
The core of a real-time strategy game is not graphics but determinism. Unit pathfinding, collision, damage resolution, and random events must all produce fixed output from fixed input, otherwise multiplayer is out of the question.
Three engineering constraints are recommended:
- Fixed-point or controlled floating point: consistent across platforms, avoiding drift caused by compiler differences;
- Decouple logic from rendering: logic advances in fixed steps, rendering interpolates;
- Command-style randomness: all random numbers come from seeded sequences, and those sequences can be snapshotted.
// Illustrative: fixed-step logic looploop {let cmds = input.drain_frame();world.apply(cmds); // depends only on current state and inputworld.step(FIXED_DT); // fixed time stepif world.tick % 60 == 0 { world.snapshot()?; } // rollback verification}
Acceptance is straightforward: run the same initial state and input sequence twice, compare the state hash tick by tick, and require an exact match.
6. Stage Four: Multiplayer and Operability
Multiplayer does not need to arrive all at once. The recommended order is: two local instances pulling against each other, then direct LAN connection, then a room service with reconnection. For the sync model, prefer “lockstep plus input delay,” because it is bandwidth-friendly and naturally reuses the deterministic logic; if latency sensitivity is high, evaluate a state-sync approach instead.
On the operations side, observability must be filled in: structured logs, key metrics, crash dumps, and replay packages. On the cloud, general-purpose categories can carry the load, for example object storage for replays and dumps, a message queue to decouple room events, a container platform for stateless match services, and logging plus monitoring and alerting services to track error rates and latency.
7. Human-AI Collaboration: Real Experience and Risk Control
High-intensity automated output creates a new problem: output speed far exceeds human review speed. The answer is not “read the code” but “read the evidence.”
- Evidence one: runnable acceptance artifacts (video decodes, a match starts, a battle runs);
- Evidence two: automated tests and golden samples;
- Evidence three: the compliance checklist and source notes;
- Evidence four: daily rollback-able commits with change summaries.
Boundaries must also be set for automation: no dependencies of unknown origin, no embedding of reference implementations without confirmed licensing, and no commits that skip tests. Writing “what is not allowed” into project constraints is more effective than reviewing after the fact.
8. Transferable Engineering Lessons
This method is not limited to games. Any legacy system with lost source, private formats, and a behavioral-equivalence requirement can reuse the same skeleton: a sample matrix drives format reverse engineering, golden samples guarantee equivalence, fixed steps and seeds guarantee determinism, milestones guarantee deliverability, and a compliance checklist guarantees sustainability.
When AI coding tools make “typing speed” no longer scarce, what becomes truly scarce is verifiable engineering constraints. Whoever designs those constraints clearly enough can reliably turn automated output into maintainable assets.
