[Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC
Verfasst: 10.10.2020, 22:04
(For the 20th anniversary of Driver 2.)
As some of you know, I’ve been extracting the worlds of the PlayStation game Driver 2. In the Driver modding scene, I met Soapy – a great reverse engineer and programmer, who then created his own game The Driver Syndicate. I can now finally announce his latest project: He ported Driver 2 from the PlayStation to the PC.
For starters: This is no trivial task. PSX and PC are vastly different. The PSX’s CPU uses an entirely different instruction set (MIPS RISC in opposite to x86 CISC) and a rather unique graphics coprocessor instead of a GPU. Porting the assembly may be possible in theory, but too difficult in practice.
So you could play the game with a PlayStation emulator, but only with the same shortcomings as on the original PlayStation: Low frame rate, wobbly polygons, little to no modding.
A foot in the door
This changed when a file with debug symbols was found that the Spanish version disc of Driver 2. The developers probably forgot to delete it after compiling.
It contained functions names, line numbers, structure layouts. We could figure out things like “address 0x12345 belongs to a function time_step(), and it changes the variable car[k].mass”.
While good to know, the value of these things was exclusive to hard-core reverse engineers.
Challenge accepted
Soapy set out to do the impossible: He decompiled the Spanish executable using NSA’s Ghidra (compared with IDA, the MIPS assembly support was better and data structures were easier to analyze) back into a set of C files, just like the original game.
The result was a bunch of C files with cryptic, decompiled functions. You could compile it to x86 code, but you couldn’t do anything useful with it, as the PlayStation’s graphics and sound APIs are not available on the PC.
Yet.
Filling in the gaps
Soapy checked out the PsyQ SDK (the official PlayStation SDK by Psygnosis), which can be found easily on the web. He looked at the data types and functions in the APIs and runtime libraries. Finally, he re-implemented all of them using SDL and TOMB5, an attempt at emulating Tomb Raider Chronicle’s graphics.
So when the game was rendering graphics, it was calling the PSX rendering functions. But these would actually redirect to new code which, in turn, would draw to a window using OpenGL. Input and sound were hooked in a similar way.
A few weeks into the project, Soapy had the main menu working. Not in an emulator running the PSX executable, but with all code compiled from source.
Crunch
What followed were several months of debugging and refactoring thousands of decompiled functions. Decompilers do make errors, after all – and finding them in optimized MIPS assembly is not trivial. Watching Soapy burst through them (and fix bugs by the way) was one of my main entertainments during the Covid lockdown!
Things gradually came together. Loading a city would work. A little later, cars would render. Physics would come to life (though there were so many weird glitches that you could fill an entire thread with them). Sound would be added.
Here it is
Soapy (and his helpers, first and foremost Fireboyd78) now have the conversion playable, although there is still much left to do on the code.
You can download the code from https://github.com/SoapyMan/REDRIVER2, compile it, place it in an extracted Driver 2 ISO, and play the game. In high resolution, with any aspect ratio, natively on the PC, with countless other small improvements!
If you want to have a look at the game and learn about the code, the cheats, the improvements, I recommend:
Starting at 2:48:00, Soapy explains the challenges and weirdnesses of the code; displays new cheats and extensions and glitches, and generally talks about internals.
We have collected a lot of weird screenshots and clips from the development, and there’s so much to talk about – old Driver 1 code, weird problems with the new architecture, confusing functions in the original game.
But that’s for a future post.
As some of you know, I’ve been extracting the worlds of the PlayStation game Driver 2. In the Driver modding scene, I met Soapy – a great reverse engineer and programmer, who then created his own game The Driver Syndicate. I can now finally announce his latest project: He ported Driver 2 from the PlayStation to the PC.
For starters: This is no trivial task. PSX and PC are vastly different. The PSX’s CPU uses an entirely different instruction set (MIPS RISC in opposite to x86 CISC) and a rather unique graphics coprocessor instead of a GPU. Porting the assembly may be possible in theory, but too difficult in practice.
So you could play the game with a PlayStation emulator, but only with the same shortcomings as on the original PlayStation: Low frame rate, wobbly polygons, little to no modding.
A foot in the door
This changed when a file with debug symbols was found that the Spanish version disc of Driver 2. The developers probably forgot to delete it after compiling.
It contained functions names, line numbers, structure layouts. We could figure out things like “address 0x12345 belongs to a function time_step(), and it changes the variable car[k].mass”.
While good to know, the value of these things was exclusive to hard-core reverse engineers.
Challenge accepted
Soapy set out to do the impossible: He decompiled the Spanish executable using NSA’s Ghidra (compared with IDA, the MIPS assembly support was better and data structures were easier to analyze) back into a set of C files, just like the original game.
The result was a bunch of C files with cryptic, decompiled functions. You could compile it to x86 code, but you couldn’t do anything useful with it, as the PlayStation’s graphics and sound APIs are not available on the PC.
Yet.
Filling in the gaps
Soapy checked out the PsyQ SDK (the official PlayStation SDK by Psygnosis), which can be found easily on the web. He looked at the data types and functions in the APIs and runtime libraries. Finally, he re-implemented all of them using SDL and TOMB5, an attempt at emulating Tomb Raider Chronicle’s graphics.
So when the game was rendering graphics, it was calling the PSX rendering functions. But these would actually redirect to new code which, in turn, would draw to a window using OpenGL. Input and sound were hooked in a similar way.
A few weeks into the project, Soapy had the main menu working. Not in an emulator running the PSX executable, but with all code compiled from source.
Crunch
What followed were several months of debugging and refactoring thousands of decompiled functions. Decompilers do make errors, after all – and finding them in optimized MIPS assembly is not trivial. Watching Soapy burst through them (and fix bugs by the way) was one of my main entertainments during the Covid lockdown!
Things gradually came together. Loading a city would work. A little later, cars would render. Physics would come to life (though there were so many weird glitches that you could fill an entire thread with them). Sound would be added.
Here it is
Soapy (and his helpers, first and foremost Fireboyd78) now have the conversion playable, although there is still much left to do on the code.
You can download the code from https://github.com/SoapyMan/REDRIVER2, compile it, place it in an extracted Driver 2 ISO, and play the game. In high resolution, with any aspect ratio, natively on the PC, with countless other small improvements!
If you want to have a look at the game and learn about the code, the cheats, the improvements, I recommend:
Starting at 2:48:00, Soapy explains the challenges and weirdnesses of the code; displays new cheats and extensions and glitches, and generally talks about internals.
We have collected a lot of weird screenshots and clips from the development, and there’s so much to talk about – old Driver 1 code, weird problems with the new architecture, confusing functions in the original game.
But that’s for a future post.