Reverse Engineering a Classic Game with AI Coding: A Practical Walkthrough
This article documents a two-week experiment in which an AI coding tool reverse engineered a legacy game known only by its binary, inferred its private resource formats and core logic, and rewrote it in a modern systems language. It covers the main engineering obstacles, including license constraints, magic constants, interface drift, and hidden logic defects, along with the practical countermeasures: machine-checkable dependency policies, golden-sample tests for every parser, frozen interface contracts, and a three-tier acceptance system. Readers will find a reusable approach for managing high-volume AI-generated commits and evaluating the real limits of AI coding on legacy systems.
1. Background: Why Pick a Game Whose Source Code Is Lost
In software engineering, the hardest task is often not building a new system from scratch but maintaining a legacy system that has only binaries, incomplete documentation, and team members who left long ago. These systems typically use private formats, couple logic with rendering, scatter constants across the code, and offer no reusable parsing libraries. That makes them an excellent test case for probing the limits of AI coding tools.
The setup for this experiment was simple: start from the executable, have the AI coding tool infer the resource formats and core logic, rewrite a runnable version of the game in a modern systems language, and record the entire process through continuous integration. The experiment ran for two weeks and was split into four stages:
- Pre-alpha: build the basic framework, resource loading, and UI skeleton.
- Alpha: get all screens and interactions working.
- Beta: implement combat logic, unit behavior, pathfinding, and damage calculation.
- Final stage: add networking and a match lobby.
The execution strategy was “long-running continuous operation plus a fixed daily output,” producing an average of about four hundred commits per day. That volume far exceeds what a human can review, so evaluation had to shift from reading code to observing results: Can it launch? Can it load a map? Can it play an animation? Can it complete an engagement?
2. The Core Difficulty of Stage One: Private Binary Formats and Magic Constants
Almost the entire first day went into format analysis. Old games rarely have public format specifications, and mature parsing libraries are usually missing from the community, so the model had to disassemble the binary while guessing at structures. The first key engineering problem appeared here: the model tends to write its own implementation even when a mature reference solution exists.
2.1 License Constraints Slowed Things Down
A typical tug-of-war happened around video resource decoding. There were only two options: a general-purpose multimedia solution with broad coverage but a stricter license, and a lightweight implementation with a more permissive license that required dynamic linking. Because the project used a permissive license overall, statically linking a strictly licensed component was not viable, so the model decided to “implement it from scratch.”
It then spent two hours in the lab, repeatedly trying a pile of uncommented constants through trial and error. After a human intervened and switched to the other route, the model started arguing about license types again and still concluded that it should build its own. Interestingly, the in-house version was finished within ten minutes. The reason was not that the model actually derived the algorithm; it had memorized the key constants from the reference implementation and then reproduced them from memory.
This exposed an important phenomenon: the model has a clear semantic boundary around “copying,” but not around “reading and paraphrasing.” The engineering lesson is that compliance cannot rely on the model’s self-discipline; it must be enforced by the process.
2.2 Confining Uncertainty with Machine-Checkable Rules
The effective response to the problem above was not repeated persuasion but moving constraints ahead of generation as machine-verifiable rules:
# Dependency admission policy (illustrative)allow_license: [MIT-like, Apache-like, BSD-like]deny_license: [strong-copyleft]link_mode: staticrequire_sbom: trueblock_on_violation: true
At the same time, a “golden sample” test was built for each format parser: given a real resource, assert the parsed frame count, width, height, timestamps, and checksum. If the output does not match, the commit cannot be merged. Even if the model “reproduces” constants from memory, it still has to pass objective verification.
3. Stages Two to Four: Engineering the Generation Process
Once the format layer was gradually conquered, the UI and combat logic progressed noticeably faster, but new problems emerged: style drift in generated code, repeated interface refactoring, and hidden defects that “look runnable but are logically wrong.”
3.1 Stabilizing Interfaces with Contracts
The solution is to freeze the interface first and let the implementation evolve freely. For the combat system, start with a minimal contract:
trait Combatant {fn hp(&self) -> f32;fn armor(&self) -> f32;fn tick(&mut self, dt: f32, world: &World) -> Action;}
Once the interface is stable, the model cannot change signatures at will across thousands of commits; it can only iterate on the internal implementation. Combined with compile-time checks and static analysis, this significantly reduces rework.
3.2 A Three-Tier Acceptance System
- Unit tier: damage formulas, pathfinding costs, collision detection.
- Integration tier: load a map, run a fixed number of frames, and compare state snapshots.
- Experience tier: record three videos covering launch, loading, and engagement, and review them quickly by hand.
This system made “four hundred commits a day” manageable: machines intercept errors, and humans only judge whether the direction is right.
3.3 Orchestration and Cost Control for Long Tasks
The biggest risk of running continuously for two weeks is context bloat and goal drift. The practical approach was to generate a short plan each day, compressing the day’s goals into three to five verifiable items, and to put large files and disassembly artifacts into an external index while feeding only summaries to the model. Logs, metrics, and alerts were handled by general cloud capabilities: object storage held build artifacts, a logging service collected runtime traces, and monitoring alerts paused the task on consecutive failures to avoid wasted consumption.
4. Conclusion: Capability Limits and Reusable Lessons
This experiment shows that AI coding tools already deliver considerable productivity in reverse engineering and rewriting legacy systems, but they are not inherently reliable. What really determines success is three things: whether goals are verifiable, whether constraints are machine-enforceable, and whether humans make aesthetic and compliance judgments at key points.
The reusable lessons can be condensed into four points: first, write license and dependency policies as hard rules in the pipeline; second, build golden-sample tests for every private format; third, freeze interfaces before opening up implementations; fourth, replace line-by-line review with tiered acceptance. If you are maintaining an old system with only binaries left, or evaluating the upper limits of AI coding tools in real projects, you can transfer this approach directly into your engineering workflow, and the general engineering and observability capabilities offered by Baidu AI Cloud can serve as the foundation for carrying long-running tasks.
