
Porting a 20-year-old commercial game to the browser with Claude Code with almost no modifications
Key Points
- 1A developer successfully ported the 2003 Windows-exclusive online TPS game "GunZ: The Duel" to run directly in a browser using WebAssembly and WebGL, requiring no downloads or installations.
- 2The primary technical challenge of adapting the game's Direct3D rendering was overcome by implementing a real-time D3D9 to WebGL translation layer, allowing the original game code to remain almost entirely untouched.
- 3This project's success, including the creation of the complex translation layer and other browser integrations, was largely attributed to the significant assistance provided by AI coding tools like Google Antigravity and Claude Code.
This paper details the successful endeavor of porting "GunZ: The Duel," a Windows-exclusive PC online TPS game released in 2003, to run directly within a web browser using WebAssembly (WASM) and WebGL. The core achievement is making the full, original game playable without requiring any downloads or installations beyond opening a Google Chrome page, with minimal modifications to the game's original C++ source code. The project significantly leveraged AI tools for code generation.
The author notes past failures in similar attempts, such as recreating the game using JavaScript and Three.js (three-gunz), which proved infeasible due to the immense complexity of re-implementing an entire game engine. The primary technical hurdle identified was the game's deep reliance on Windows-specific APIs, particularly Direct3D 9 for rendering, which is incompatible with browser environments.
The core methodology for overcoming Direct3D dependency involved an innovative "translation layer" or "wrapper" named d3d9-webgl. Instead of directly modifying the game's extensive C++ rendering codebase (tens of thousands of lines), this layer intercepts Direct3D 9 API calls made by the game and translates them in real-time into equivalent WebGL commands. This effectively creates a compatibility layer between the game's rendering logic and the browser's graphics capabilities. This approach is superior to direct code modification or mechanical transpilation due to the semantic differences between APIs. The game's C++ source, including this newly developed d3d9-webgl wrapper, was compiled into WebAssembly using Emscripten, enabling it to execute efficiently in the browser.
Beyond rendering, several other significant porting challenges were addressed:
- Network: The original game server, also written in C++, was compiled to WebAssembly and runs as a Web Worker within the same browser tab. Communication between the client and server within the tab is handled via
postMessageinstead of traditional network sockets. Player data and statistics are persisted using SQLite and IDBFS (an IndexedDB-based filesystem), effectively creating a serverless, local game experience that retains data across sessions. Online multiplayer with other users is still supported via WebSockets to external game servers. - Sound: The proprietary FMOD sound middleware used in the original game was entirely replaced with the Web Audio API. This involved re-implementing core sound functionalities such as 3D spatial audio (using
PannerNode), background music streaming, and sound effect distance culling, requiring approximately 1,260 lines of new code. - Input: Browser keyboard and mouse events were captured and translated into their corresponding Win32 messages (e.g.,
WM_KEYDOWN,WM_MOUSEMOVE,WM_CHAR) and fed into the game engine's message pump. The Pointer Lock API was utilized for accurate mouse capture, and HTML elements were overlaid for text input fields (e.g., login screens). - File System: Game assets, distributed in a custom
.mrsarchive format, were loaded into Emscripten's MEMFS. A two-stage loading mechanism was implemented: essential game files are loaded first, allowing for a quick start, while other assets (e.g., equipment parts) are downloaded in the background. The Cache API was used to store assets, enabling network-less startup on subsequent plays. - Game Data Optimization: To mitigate network download times, significant effort was placed on optimizing asset sizes. Notably, sound effects were converted from WAV to Opus format, resulting in an 88% reduction in size (from 44.3MB to 5.30MB). This optimization contributes to the game being playable within 10 seconds of opening the page. Content delivery is further optimized using S3 and CloudFront CDN.
The project heavily relied on AI tools, specifically Google Antigravity (early stages) and Claude Code (later, more effective stages). The author states that 99% of the new code, particularly the complex d3d9-webgl translation layer, was generated by AI. The author, having limited prior knowledge in 3D game development or graphics APIs, emphasizes that the project's success was largely attributable to the capabilities of these AI code generation tools. This initiative demonstrates the transformative potential of AI in porting complex legacy software to modern platforms with minimal manual intervention.