[Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Hier könnt ihr euch selbst, eure Homepage, euren Entwicklerstammtisch, Termine oder eure Projekte vorstellen.
Forumsregeln
Bitte Präfixe benutzen. Das Präfix "[Projekt]" bewirkt die Aufnahme von Bildern aus den Beiträgen des Themenerstellers in den Showroom. Alle Bilder aus dem Thema Showroom erscheinen ebenfalls im Showroom auf der Frontpage. Es werden nur Bilder berücksichtigt, die entweder mit dem attachement- oder dem img-BBCode im Beitrag angezeigt werden.

Die Bildersammelfunktion muss manuell ausgeführt werden, die URL dazu und weitere Details zum Showroom sind hier zu finden.

This forum is primarily intended for German-language video game developers. Please don't post promotional information targeted at end users.
Antworten
Benutzeravatar
Krishty
Establishment
Beiträge: 8229
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

[Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Krishty »

(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.
Trying to render a car.
Trying to render a car.

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.
That’s the decompiled code we’re talking about
That’s the decompiled code we’re talking about

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.
The skybox lives!
The skybox lives!

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.
Physics is hard, but debug visualizations help
Physics is hard, but debug visualizations help

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.
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
D-eath
Beiträge: 51
Registriert: 28.08.2009, 19:37
Alter Benutzername: TrunkZ
Echter Name: Thomas

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von D-eath »

This is pretty amazing. Great work.
Benutzeravatar
Krishty
Establishment
Beiträge: 8229
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Krishty »

Thanks! The last weeks have been crunch time. (It’s not like Soapy would ever sleep anyway.)

Publicity

We now have articles in PC Gamer, Kotaku, and many more. The teaser has been watched over 10k times just today:



Vortex was so nice to provide an introduction, installation tutorial, and a general overview:



Let’s talk about the important milestones in programming.

Refactoring almost done; Joystick/Controller Support

As I mentioned, Soapy never sleeps. There are only a few functions left which have not yet been refactored to be human-readable.

REDRIVER2 now comes with proper handling of cutscenes (including subtitles) and credits – watch out for easter eggs!

The repository moved to its final location.

On the PSX, you would play the game with a DualShock Analog stick, but REDRIVER2 was limited to the keyboard for a long time. This has finally been fixed (although I haven’t checked it out myself).

Fixed Nvidia bug

REDRIVER2 has always had problems on Nvidia GPUs. Soapy doesn’t have an Nvidia card; my RenderDoc snapshots were of very limited use due to problems with the OpenGL support. But just a day before the big announcement, Fireboyd78 tracked it down to a rounding problem when the shaders access color lookup tables.
It was pretty much unplayable, but now that’s fixed.
It was pretty much unplayable, but now that’s fixed.
Fireboyd debugging in RenderDoc.
Fireboyd debugging in RenderDoc.
Weather decoded

Soapy and Fireboyd improved the time of day and weather handling. In the debug menu, you can now choose your preferred time of day – dawn, day dusk, night – and your preferred weather. Cars will automatically toggle lights.

This mostly involved decoding the way various environment maps and lighting modes were addressed.
Trying out dusk and rain.
Trying out dusk and rain.
Re-recording NPCs

There are lots of car chases in Driver 2. Whenever you chase an NPC, that’s not a real AI driving – it’s a member of the original development team. They would record their driving and the engine would play it back during a mission, much like the replay/movie director system.

Here’s the catch: This relies heavily on the game reproducing the *exact* gameplay each time you play a mission. NPC traffic must spawn in the exact same locations, or the pre-recorded NPC will crash into another car. Car handling has to be exactly the same, or the NPC will lose track.

For some reasons (I’ve forgotten them), we didn’t quite get there. So, for a few days … the team played every single chase mission again and again, playing the role of the NPC, and recording the driving. Apart from the basics – follow the route, don’t crash, don’t flip the car – you have to drive demanding, but not so much that the mission becomes too difficult. Make it interesting by hitting bumps or coming close to other cars, but keep it realistic. It’s explained (and shown) very well in Vortex’s video.

When a chase mission starts, the game will now display the name of the team member who recorded the getaway.

More Cars to come?

I already mentioned the increased range of sight. It does look empty without more traffic, though. Soapy and Fireboyd finally identified all areas in the source code related to the number of AI cars, so we may see improvements in the future! This stuff was hard-coded like hell and it hid in pointer offsets, array sizes, loop counter initializations, …
A crazy amount of cars not only crashed the engine. The AI is totally unable to cope with so many co-drivers and makes every intersection a crash site.
A crazy amount of cars not only crashed the engine. The AI is totally unable to cope with so many co-drivers and makes every intersection a crash site.
There’s so much more to show and write about, but for now we’re buzy with community management :)
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
Benutzeravatar
Jonathan
Establishment
Beiträge: 2353
Registriert: 04.08.2004, 20:06
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Jonathan »

Ah yes, very nice. I am not really a fan of driver, however I do absolutely love the idea of having code available for old games. There are just so many great memories in these old games which could become very playable again if only the community was allowed access to the code... (My personal wishlist: Earth Siege 2 & Crimson Skies)
Lieber dumm fragen, als dumm bleiben!
https://jonathank.de/games/
Benutzeravatar
Schrompf
Moderator
Beiträge: 4838
Registriert: 25.02.2009, 23:44
Benutzertext: Lernt nur selten dazu
Echter Name: Thomas Ziegenhagen
Wohnort: Dresden
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Schrompf »

Very cool. I love having the old gamedev tricks explained. Thanks for all your work!
Früher mal Dreamworlds. Früher mal Open Asset Import Library. Heutzutage nur noch so rumwursteln.
Benutzeravatar
Jonathan
Establishment
Beiträge: 2353
Registriert: 04.08.2004, 20:06
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Jonathan »

Gerade auch bei GameStar gesehen:

https://youtu.be/_CDA1XVaa0Q?t=218
Lieber dumm fragen, als dumm bleiben!
https://jonathank.de/games/
Benutzeravatar
Krishty
Establishment
Beiträge: 8229
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Krishty »

Cool! They’re repeating some misconceptions, so let me clear that up:

REDRIVER 2 doesn’t run at 60 fps. The physics engine is currently locked to 30 fps. We don’t know where that came from, but that rumor is out of control :) It may have stemmed from HD resolution/widescreen support.

As explained above, Driver 2 relies heavily on the replay mechanism to play back pre-recorded scenes during missions. This, in term, requires a fixed timestep. The original game was pretty slow on the PSX (often running at less than 25 fps), so the developers never had a reason to support high physics framerates and locked it to 30 fps.

We had a test build running at 60 fps, and apart from all mission replays breaking and a few animation issues, the cars were driving a little bit faster. We may implement higher fps at some point.

Fun fact: Driver 1 for PC is also locked, but at 50 fps. This makes it pretty hard to emulate Driver 1 and Driver 2 at the same time, but that’ll be a later article ;)

One real improvement is support of 16:9 and widescreen in general. This was pretty hard to achieve with all kinds of sprites used for pedestrians, debris, and so on. But Soapy fixed it eventually. It should even be playable in portrait mode, i.e. on a smartphone screen.

You don’t need both CDs to play all four cities. All cities are on each of the two game CDs. You do need the 2nd disc to play the later *missions*, though. That’s due to the large movie sequences. When they ran out of space halfway through the missions, they put the other half of the movie sequences on disc 2 and just duplicated the city data, driving games, etc.

P.S.: If anyone needs help with the game, visit the the Driver Madness Discord server (300 online).
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
Benutzeravatar
Krishty
Establishment
Beiträge: 8229
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

Re: [Project] REDRIVER 2 – Porting DRIVER 2 from PSX to PC

Beitrag von Krishty »

Soapy has written up a list of trivia and Easter Eggs about Driver 2 and its code … and I love it

https://github.com/OpenDriver2/REDRIVER ... t-Driver-2
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
Antworten