Reverse Engineering and Rewriting a Classic Game with an LLM: A 14-Day Experiment Recap

    This article recaps a 14-day experiment using an AI coding tool to reverse engineer and rewrite a classic real-time strategy game whose original source code was lost. It covers the phased milestone plan, parsing legacy proprietary asset formats, license compliance rules, context and prompt engineering for long-running tasks, and automated quality guardrails, ending with reusable lessons for legacy system modernization.

    1. Why Start With a Game Whose Source Code Is Lost

    The original engineering projects of classic real-time strategy games often leave behind only executables and massive amounts of assets. Source code, build scripts, and design documents are mostly gone. These projects are a perfect test of an AI coding tool’s ability to “understand through reverse engineering and rewrite in a modern language.” They demand binary analysis, file format archaeology, rebuilding graphics and audio pipelines, network synchronization design, and sustained engineering effort over a long period.

    It is worth stressing that the goal of this experiment was not to clone a commercial title, but to validate a methodology: how to use AI coding tools to restore the behavior of a legacy system and modernize it when original materials are missing. All output was kept in an isolated directory and used only for technical research.

    2. Overall Approach: Breaking “Rewrite a Game” Into Deliverable Stages

    Asking a model to directly “rewrite a game” is bound to fail, because the goal is too broad and lacks verifiable intermediate states. A workable approach is to define milestones first and then advance stage by stage:

    • Pre-Alpha: runnable skeleton, asset pipeline, logging, and a debug panel;
    • Alpha: all interfaces and menu flows working;
    • Beta: a closed loop for units, combat, pathfinding, and damage resolution;
    • Multiplayer stage: deterministic synchronization and state validation.

    In the experiment, the model first produced a detailed two-week plan, then advanced at a pace of hundreds of commits per day. No human could review every line, so quality assurance had to shift left to “runnable acceptance criteria”: by the end of each day, the program had to start, load assets, and pass a fixed set of smoke tests.

    3. The Real Challenge: Parsing Ancient Asset Formats

    Old games commonly use proprietary containers and encodings: custom image atlases, compressed audio, scripts, and map data, with almost no ready-made parsing libraries available. The model’s typical path was representative:

    1. First try to find an existing implementation;
    2. Abandon direct reuse due to incompatible licenses;
    3. Rewrite the decoder “from memory”;
    4. Produce a runnable version within minutes.

    Here appeared the most interesting phenomenon of the experiment: when asked to “copy” code, it refused; when you merely mentioned that “a certain class of algorithm already exists in the industry,” it would proactively work out the idea and then reproduce key constants and state machines in a “recitation” style. The engineering lesson is that instead of fighting this tendency, it is better to channel it into “study the public specification first, then implement independently.”

    A schematic decoding skeleton follows; the focus is on structure rather than specific values:

    1. // Pseudocode: frame-based container decoding skeleton
    2. struct FrameDecoder { state: State, palette: Vec<u8> }
    3. impl FrameDecoder {
    4. fn decode(&mut self, buf: &[u8], out: &mut Vec<u8>) -> Result<()> {
    5. while self.state.need_more() {
    6. let (tag, payload) = self.read_chunk(buf)?;
    7. match tag {
    8. PALETTE => self.load_palette(payload)?,
    9. BLOCKS => self.expand_blocks(payload, out)?,
    10. _ => self.skip(payload),
    11. }
    12. }
    13. Ok(())
    14. }
    15. }

    There are three practical points: first, confirm the block structure with hex comparison and differential sampling; second, consolidate magic numbers into named constants with notes on their origin; third, write “golden sample” tests for each format, locking behavior with known input and output pairs to avoid silent regressions during later refactoring.

    4. Licensing and Compliance: “Can It Run” Is Not Enough

    In the experiment, the model showed an almost stubborn sensitivity to licensing: whenever it found a candidate implementation incompatible with the project license, it insisted on implementing it itself. This caution is correct in engineering, but humans need to back it up with clear rules:

    • Maintain a dependency whitelist that allows only permissively licensed components into the main repository;
    • For implementations that borrow ideas, keep an “independent implementation note” that records the public specification referenced rather than code snippets;
    • Separate assets from code to avoid mixing copyrighted material into an open-source directory;
    • Add compliance check items to the commit template so that review becomes part of the workflow.

    5. Context and Prompt Engineering: Keeping Long Tasks on Track

    With two continuous weeks and hundreds of commits per day, the biggest risk is goal drift. An effective practice is to maintain a “project constitution” file containing architecture constraints, naming conventions, prohibited items, and the current milestone, and force it to be read at the start of every session. At the same time, break large tasks into small ones with acceptance commands, such as “all tests pass” or “the main menu renders within three seconds after launch.”

    Another practical technique is “log every failure”: write each compilation error, crash stack, and reproduction step into a log, and have the model read the log before acting in the next round, which significantly reduces repeated mistakes.

    6. Quality Assurance: Verifying Behavior Instead of Reviewing Every Line

    When it is impossible to manually review all the code, automated guardrails should be established: continuous integration runs builds and smoke tests after every commit; screenshot comparison verifies interface layout; match scripts with a fixed random seed verify that combat results are reproducible; memory and frame rate sampling reveals obvious regressions. These measures turn “looks like it runs” into “measurably runs.”

    7. Capability Boundaries and Reusable Conclusions

    This kind of experiment shows that AI coding tools are good at pattern recognition, boilerplate generation, and probing and reproducing format reverse engineering, but still need human oversight for system-level architecture tradeoffs, performance limit optimization, and long-term consistency. The experience transferable to enterprise scenarios is that legacy system modernization can equally use the combination of “phased milestones + golden sample tests + compliance whitelist + automated guardrails.” If the build and observability pipeline is hosted on general capabilities such as the container platform, logging service, and monitoring and alerting on Baidu AI Cloud, the team can focus more energy on architecture decisions and acceptance criteria design. This is the most valuable output of this 14-day experiment.