cd /news/ai-tools/resurrect-a-2003-borland-c-windows-n… · home › topics › ai-tools › article
[ARTICLE · art-178695] src=github.com ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

Resurrect a 2003 Borland C++ Windows native game to Rust and WebAssembly

A developer used Anthropic's Claude Code to port the 2003-era Borland C++ Windows MMORPG 仙侣奇缘2 (Xianlv Qiyuan 2) to Rust and WebAssembly, succeeding after an earlier attempt with Cursor failed because the models were not capable enough at the time. The source spans files up to 20,411 lines with six __asm blocks, no tests, and a custom in-house scripting language; 25 of the 3,588 scripts contain lines the original engine's parser does not recognize. The developer abandoned transpiling the scripts to Lua in favor of a custom intermediate representation, and traced an in-game bug to misuse of Windows rand(), whose 32,767 maximum caused monsters to bunch along map edges and corners.

recommendation

When porting legacy code with coding agents, scope work by layer (rendering first, then gameplay) and prefer a custom IR over transpiling when the source language has irregular control flow.

more in playbook: Working with AI coding agents
read12 min views5 publishedNov 30, 2026
Resurrect a 2003 Borland C++ Windows native game to Rust and WebAssembly
Image: Michielbdejong (auto-discovered)

Disclaimer: this article's ideas and structure are our own; AI only rephrased them.

I finally rebuilt a Borland C++ game using Claude Code.

The game is 仙侣奇缘2 (Xianlv Qiyuan 2, a 2D Chinese fantasy MMORPG). It launched around 2004 and was shut down because it was badly run. After that, some private servers kept it running, and I kept playing on them. Two years ago, I got the source code from a friend who runs a private server. But the source code had a lot of problems. The engine and everything else were written in-house. Off-the-shelf game engines weren't really an option back then. Even the network protocol was their own.

Making a game back then took an absurdly broad generalist. The lead engineer had to touch everything, from the server to database optimization to the engine's rendering, and had to handle all of the Windows APIs too. Most of this code seems to have been led by that one engineer.

I had downloaded the Borland C++ IDE before to compile this game. It's hard to imagine how painful it is to use: change any file and it recompiles everything. You can't find any docs for Borland's C++ UI library anymore. And the code is tied to a lot of Windows APIs. I had thought about remaking the game before, but when I estimated it, the amount of work was too big to be realistic. I also tried using Cursor to rewrite the server first, as a modern Linux-based C++ server, but that failed too. The models weren't capable enough for it then. The game code doesn't have a single test, some game files are tens of thousands of lines long, and some of it is assembly.

For this post we installed C++Builder 6 again on a Windows 11 machine and opened the original project.

The whole file is 20,411 lines.

This one file has six __asm blocks.

When we opened our copy of the source this time, it no longer built. The project's output path points at an F: drive on the old developer's machine, it includes headers that aren't in our copy, such as FileView.h, and our copy was converted to UTF-8, so the old compiler reads its Chinese strings as "Illegal character" errors.

We also found a lot of bugs in the game code. One example is how it called Windows rand(), whose maximum value is only 32,767. When I played the game as a kid, I noticed that the monsters the game spawned on a map were spread very unevenly. A lot of monsters were bunched up along the edges and corners of the map, because rand() was used wrong.

Then this year, as the models got better, I kept trying to rewrite it, and it only worked recently. Early in the year, I used Claude to pull out the game's rendering layer. It could reproduce the rendering of all the game maps and of the characters' equipment, but bringing back the gameplay was still miles away. The game's developers invented their own script language, with their own parser and runtime, a line-by-line interpreter that supports very little syntax. And every quest in the game is written in that script. Pretty wild.

Proc Main
	Random($monk,3)
	If ($monk == 1)
	Talk("\head\town\special\002.Img","Temple Monk","The abbot's uncle is a monk of great virtue, ...");
	EndIf
	...
	Return
EndProc

A town NPC's dialogue script, translated from the Chinese original.

After that I tried migrating the scripts to Lua, in two ways. At first I wanted to transpile them to Lua, but the transpiler was hard to write, because the syntax has some odd control flow. Later I used the Gemini API to generate a Lua version one script at a time. In the end we used our own IR instead, because we hadn't wired up a Lua runtime in the Rust server yet. There are Lua runtimes written in Rust, but we didn't use one.

The hard part of the migration is that the original scripts themselves have syntax problems, and some of them are just broken. 25 of the 3,588 scripts contain a line the original engine doesn't recognize, often a client-side Talk() dialogue pasted into a server script. The original parser stops at that line, so the rest of the script never ran in the original game. Thousands of conditions write less-than as <<, and a few dozen have operands a strict grammar can't parse. So our compiler doesn't skip or fix these lines. It records the first bad line, and the VM cuts the script off there, the same way the original did. The odd conditions go to a separate module that replays the original engine's scan instead of being patched into the main grammar. Everything compiles into 177,616 IR instructions.

The game's art too. All the original art is in the client, and it can be unpacked with the decompression code from the C++. But the sprites are very low-res. I tried using Gemini Nano Banana to regenerate it in HD, especially the monsters.

When we started writing it, we first wrote a pure JavaScript web client, but for some reason its performance was very bad. I don't know why; maybe JS was slow at the math when rendering. In the end we used egui and Bevy in WASM: egui for the HUD, Bevy to render the game. It was very interesting. The server is pure Rust with SQLite. The original game used some MySQL 5.x version, I think, and I couldn't even find a binary for that version anymore.

For the protocol we use FlatBuffers, with a FlatBuffers compiler I wrote myself. I'd wanted to write one myself anyway, and the upside of your own compiler is that you can change it however you want. At first we wanted to use gRPC's streaming over the web, but we ran into a lot of problems, and in the end we used WebSocket. Our gRPC service ran the whole game over one two-way stream, and a browser can't open one of those; gRPC-Web only streams from the server to the client. It also used protobuf, while everything else used FlatBuffers.

For storage, why SQLite? Compare it with the original, which used MySQL and had to keep tweaking it to handle all the writes. And it didn't store character data as JSON either. They wrote their own structure for storing it, which is also pretty wild. The columns are named in Chinese (name, level, cash and so on). A character's bag, equipment and warehouse each go into one text column in the same INI-file format as the game's config files, one numbered section per item, cut off at a fixed length: 4,000 bytes for the bag, 8,000 for the warehouse. When a bag ran over, the server logged it and saved what fit. Ours keeps each character as one versioned record in a single SQLite file, so there's no database server to run.

Getting the rendering right was another long battle with Claude Code. At the very beginning, Claude Code couldn't tell where the rendering code had bugs. Later we built a verification step: we changed the render output so it could snapshot the frame and return a matching JSON state. That way I could tell Claude directly which frame had a problem. Once we had that, we started running verification in batches. Even where a skill's animation had a problem, I could just tell Claude.

One frame captured by the main-story test, next to part of the state recorded with it: whether the map and its textures loaded, the player's predicted and server-confirmed position, the dialogue line on screen, and the quest objective.

The core of what makes this work is test coverage. The repo has about 6,500 Rust tests, plus about 500 JavaScript and 950 Python ones. They run in layers: unit tests; scripted test worlds on a virtual clock; protocol tests against a real server over the binary WebSocket; browser tests that drive the real WASM client in Chrome, from the main story chapter by chapter down to each monster's walk, attack and death animation; and install, update and rollback tests for the launcher on macOS and Windows. Test files alone are about a third of the Rust code.

This is also when I gradually started losing my understanding of the code. More and more code got written, and I had no way to read it line by line. By now there's so much code that I don't even know what each component and module does. It's a real headache. Only recently, once the game was playable, did I find that some modules weren't used anymore.

Now the game has basically finished its migration. Most of the game's features are in, and you can play it. Right now about ten players are playing at the same time.

To make this game production-ready, it also has to be deployed. The private servers I used to play on were all deployed on Windows machines on Alibaba Cloud in China. The advantage of ours is that it can be deployed directly on Linux or Windows, whichever. The only real trouble is the asset server.

Cloudflare Tunnel latency was also a problem. At first the game server was reached through a Cloudflare tunnel, and the first response took about four times as long as connecting directly (about 956 ms vs about 230 ms to first byte). So now the game server is reached directly.

All the clients share one Rust core. It holds the game state, applies the server's messages, and turns them into what each screen shows. The main client is that core plus Bevy for the game and egui for the HUD, compiled to WASM. It runs in the browser, and the desktop app is the same client inside Electron, with the server bundled for single-player. There's also a lighter web version, a React page on the same core compiled to WASM, and a phone client we're starting on works the same way. The server is one Rust binary.

Even now that the rewrite is mostly done, I still don't understand what all this code is doing, whether some of it is problematic, or whether some of it is completely useless. It isn't that I can't understand it. There's too much of it, and there's no way to read it all. The FlatBuffers compiler this game uses is also something I wrote myself, and I don't know what problems that compiler has now either. I think in the future we need more abstraction.

Another takeaway: I found the game's missing features only because I played it myself. When I let the agent look for them on its own, it didn't find them. It only caught them once I pointed them out. And it isn't only problems in the game's GUI. A lot of things that should have been rendered were missing. I don't have a good way to solve this yet. This is a bottleneck: even with a lot of verification, you can't find every gap. That's exactly the problem. If the verification loop really worked, it would discover these gaps automatically instead of waiting for me to run into them.

The game still has a lot of problems, including the mobile client we're starting to write now. There are still a lot of bugs compared with the original, and we have to find them bit by bit, with players helping us too. One bug a player found: the shop didn't show how much an item costs. Earlier we had asked the LLM to read and understand the source code and generate a spec, but it didn't really follow what we asked for. It never extracted a clear, accurate spec of the original game. We've been trying to solve this lately, but there's still no particularly good way. A lot of things still have to be done by hand, bit by bit.

So development is still going. We keep finding bugs, and we still need players to play the game with us and test it for bugs. Even though we have a lot of end-to-end tests, there are still a lot of corner cases they don't cover. And the problem now is that we don't even know how many corner cases there are, because we didn't write this code by hand.

Some players have sent us bug reports. There are hardcore fans who still play this game, and once we built this, they got interested in playing it too. We're very grateful to them for helping us find bugs. It also shows that reading the source code and pulling a spec out of it can't fully find all of the game's mechanics and features.

Also, with this project, someone without a software engineering background would still have a lot of trouble rebuilding this game directly: understanding the whole technical architecture, choosing it, and deploying it. I don't really know Bevy and egui that well either, but the underlying patterns are familiar: picking Electron, deploying a web app, putting assets on Cloudflare.

And deploying this game still involves a lot of DIY work. I had to write the launcher myself, the updater myself, the CDN deployment myself, and the web version myself. What we're missing now is infrastructure for games like this. Not infrastructure like Steam. Something that will let AI agents develop and deploy games better, and reach users.

Even though LLMs make it easy to rewrite a game, we're still missing a lot of basic infrastructure: deployment, updates, a CDN, bug reports, something like Sentry.

Independent developers now have enough tools to build a whole game. What used to take a company now takes one person.

In the future, we might use math and WebGL shaders to render skill effects instead of sprite assets. We've already prototyped 7 of the game's 246 skills this way.

The game is online: play it in the browser at https://play.koevol.com, or get the desktop app from https://xlqy.koevol.com.

── more in #ai-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/resurrect-a-2003-bor…] indexed:0 read:12min 2026-11-30 · —