Reverse Engineering Legacy Games With AI: A Practical Rewrite Workflow

    This article documents a hands-on effort to reconstruct a lost classic RTS codebase using AI coding tools, starting from binaries, asset packs, and document fragments. It covers the four delivery phases, the observable feedback loop needed to reverse undocumented binary formats, license and compliance constraints that must be enforced in the pipeline, and the metrics-based gating required for long autonomous runs. It closes with the practical limits of AI collaboration and a reusable approach to legacy system rebuilding, protocol reverse engineering, and data format reconstruction.

    1. Where It Started: The Maintainers Moved On, the Source Did Not Survive

    The original source code of a classic real-time strategy game was lost years ago through office moves and staff turnover. All that remained was the executable, the asset packs, and a few torn pages of documentation. The community had floated an idea that sounded impossible: if AI coding tools are now reasonably good at understanding and generating code, could they “read” the old program and rewrite it in a modern language?

    The practical value of this experiment is not the recreation of one old game. It is the engineering problem underneath: when the only surviving assets are binaries and data files, how do you rebuild a maintainable implementation? Finance, industrial control, and embedded devices all run into the same wall.

    To make the work executable, I split the goal into four phases, each with a verifiable deliverable:

    • Pre-Alpha: asset format parsing and static UI restoration
    • Alpha: units, buildings, pathfinding, and a closed combat loop
    • Beta: multiplayer balance, random maps, and save games
    • Networking: state synchronization, reconnection, and spectating

    2. Phase One: Wrestling With Ancient Formats

    Old game data formats rarely have public specifications. They survive as hand-written read/write logic from the original developers plus a pile of magic constants. Video, maps, sound effects, and palettes each follow their own rules, and the community has almost no reusable parsing code to draw on.

    The first lesson in practice: do not expect the model to guess a binary layout out of thin air. What works is building an “observable loop” first — a hex viewer, hypotheses about field offsets, and a validation script working together, so the model converges through a cycle of propose, run, verify, correct.

    A typical field-probing sketch:

    1. # Guess field widths from the file header, then verify with statistical traits
    2. def probe_header(data: bytes):
    3. magic = data[:4]
    4. # Common pattern: magic + version + frame count + width + height
    5. version, frames, w, h = struct.unpack("<IIII", data[4:20])
    6. assert 0 < w <= 4096 and 0 < h <= 4096, "resolution assumption failed"
    7. return magic, version, frames, w, h

    When an assertion overturns an assumption, the model adjusts offsets and widths on its own, and the structure is usually pinned down within a dozen or so rounds. What this process consumes most is context and reasoning budget, not lines of code.

    3. The Underrated Obstacle: Licensing and Compliance

    The place where a rewrite most often goes wrong is not technical. It is code provenance and license compatibility. If the original project uses a permissive license while a reference implementation uses a stronger copyleft license, static linking creates compliance risk. Models tend to be unusually sensitive here and will repeatedly refuse the “just copy it” path.

    The pragmatic fix is to turn this into a process constraint instead of an on-the-spot judgment call:

    1. Maintain a dependency allowlist so only permissively licensed components enter the build;
    2. For modules that must be written from scratch, document the algorithm and data structures first, then generate the implementation;
    3. Attach provenance and a derivation for every constant and table structure;
    4. Scan the dependency manifest with a script and block non-compliant additions.

    One thing worth noting: model behavior differs sharply between being told to copy and being told that an algorithm already has a public implementation. The former tends to trigger refusals; the latter may lead the model to reproduce implementation details almost casually. The implication is that prompt design is itself part of the engineering constraints. Compliance requirements belong in the system prompt and in pipeline gates, not in the model’s own discretion.

    4. Long-Running Automation: Let the Work Run Itself

    Fourteen days of continuous operation, hundreds of commits per day on average. No human can review that line by line. The workable strategy is to change “humans read code” into “humans read metrics”:

    • Every commit must trigger a build and unit tests, with automatic rollback on failure;
    • Critical paths get performance baselines, with alerts when frame time crosses the threshold;
    • UI regressions are checked by screenshot comparison, flagged when pixel differences exceed the threshold;
    • A daily change summary and risk list is generated, and humans handle only the exceptions.

    A sketch of the pipeline constraints:

    1. gates:
    2. - build: must_pass
    3. - unit_test: coverage >= 60%
    4. - license_scan: allowlist_only
    5. - perf: frame_time_p95 <= 16ms

    The core idea is to replace human code reading with automatically decidable acceptance criteria, so human attention stays on architecture decisions and exception handling.

    5. Capability Boundaries and Collaboration Notes

    A few patterns held steady in practice. First, models are good at local refactoring and boilerplate, but not at long-term architectural consistency across modules, so humans have to set the boundaries. Second, long context introduces drift, which is why documentation and tests must serve as anchors. Third, compliance judgments have to be moved forward into hard constraints. Fourth, in reverse engineering work the largest cost is the verification environment, not code generation.

    To host this kind of long-running work in the cloud, the general pattern is to combine a code repository, build caches, asset packs in object storage, task events in a message queue, and logging plus monitoring and alerting into an observable, replayable automation environment. This part is vendor-neutral and belongs to general engineering practice.

    6. Closing Thoughts

    The real payoff of “let AI rewrite an old game” is not whether the recreation succeeded. It is a repeatable method for rebuilding legacy systems: build the observable loop before generation; write compliance into the pipeline before chasing speed; verify with metrics before scaling up. For developers on Baidu AI Cloud, the same method applies to legacy system migration, protocol reverse engineering, and data format reconstruction.