Planet Descent

Community => Mess Hall => Topic started by: SaladBadger on March 23, 2021, 05:18:47 PM

Title: Playing around with a Descent 3 patcher [Build 1 released!]
Post by: SaladBadger on March 23, 2021, 05:18:47 PM
https://github.com/InsanityBringer/InjectD3/releases/tag/v0.1-alpha (https://github.com/InsanityBringer/InjectD3/releases/tag/v0.1-alpha)

Assuming nothing's gone wrong, here's my first build!

It's absolutely vital you read the readme to tell what's going on. You'll need to use OpenGL for most patches to take effect, you'll probably need to rename your movies folder since I haven't patched the movie player yet, and there's still bugs in this release I'm trying to track down, but for normal playing it should be fine.

Old post:

Descent 3 always bugged me. It messes up your desktop windows if you play it in OpenGL, can't be run in windowed mode, doesn't support widescreen well, constantly changes video resolution. It sucks, but without a source release on the horizon, what can one do about it? Well, I've gotten curious, and with some motivation and help from Arne, I've been working on a program that patches it.

I have a dll injection system that loads a dll into the program's address space, and makes several patches, which should be user configurable. So far the current patches are:

Things I want to include for later include:

It's all pretty rough so far, but I'm planning on having a frontend that will allow choosing what modifications are active and setting parameters for them, such as the desired FOV and so on.

For now, have a pic of the game running natively in windowed mode (with no glide emulators in sight) with a ridiculously high FOV. There's still plenty of bugs I'm trying to chase down with this right now, but it kinda works:
(https://i.imgur.com/Jt98xpF.png)
Title: Re: Playing around with a Descent 3 patcher
Post by: Scyphi on March 24, 2021, 06:12:44 AM
Well, that all looks very promising! As I, too, have been getting frustrated with D3's various...quirks...and the increasing difficulty to get it to run smoothly on modern systems, I'd be very interested in something like this.  ;D
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on March 24, 2021, 07:41:59 AM
Ah, I hope I can deliver on this front, I've played the first couple of levels of Descent 3 with it and it's a lot more stable than I expected (only major bug I'm trying to track down now is that the mouse doesn't work in Telcom screens for reasons I can't comprehend), so I think I may be able to release something soon, though it currently only patches 1.4 (the exe that old fan packaged version of the game uses). I need to write code to detect your version and select the right offsets for 1.4 and 1.5.

For now, I just got command line arguments working in the injector program, so here's some 1920x1080 windowed with expanded FOV:
(https://i.imgur.com/bXyrxwE.png)

The cockpit is absolutely unusable, and it's probably fixable, but that will be very tricky to do, so just use the fullscreen HUD for now.
Title: Re: Playing around with a Descent 3 patcher
Post by: Hunter on March 25, 2021, 04:11:57 AM
The fact you managed to increase the FOV is an achievement! It's one of the MAIN gripes from Overload players that D3's FOV is too small.

A modified frontend could be sweet, a bit like PureFaction's frontend on top of Red Factions menus.

You also might wanna contact Matt about this - he and luke (I think) were working on a modified D3 build around the time Overload was in development. We never heard anything more about it, but I do remember seeing it briefly on a livestream so it definitely exists.
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on March 25, 2021, 07:41:58 AM
Honestly, I didn't realize quite how bad the FOV was until I started working on this. The default is a whopping 72 degrees. Ouch. As I discovered from writing Chocolate, Descent 1 and 2 were probably lower in fullscreen mode (cockpit mode expands it a bit), so I'm not entirely surprised, but it still hurts. In any case, being able to fix that was a breath of fresh air. That widescreen pic has it at 105, and I've played the first couple of levels like that and it's all fine.

I can look into menu integration for a frontend, but it'll be a bit hellish, the D3 menu code isn't exactly intuitive to hack.

I'm also trying to hack in an alternate sound implementation right now, using OpenAL. I have the entirety of the "LLS system" patched atm, but no sound yet. I tried to correct the crackles and pops the original sound code gives me, but honestly, I don't know DirectX well enough as it is, and I certainly have no idea why 22 year old DirectSound 6 code could be full of crackles and pops, so replacing it is basically my only option. I thought the sound quality wasn't getting set right, but I whacked a debugger up against the relevant functions and they're all passing high quality down the pipeline, so it's not that like I had thought.
Title: Re: Playing around with a Descent 3 patcher
Post by: Hunter on March 27, 2021, 03:04:20 AM
Oddly enough, when I play D3 on Wine there are no sound issues - even on high quality (a toggle which ONLY works in the main menu btw). Linux has its own set of issues though, but wine is the best way to play D3 despite the existence of the new 64-bit D3 port for native Linux. When it comes to Windows, there is that 'IndirectSound' dll that is supposed to fix sound issues. Have you tried it?

Another big gripe is the hardcoded menu/map resolution. That can REALLY mess up peoples desktops on Windows..

Also look into D3's bump mapping (-bumped) for Direct3D. I could only ever get it working on my old Radeon, but it looks pretty sweet when combined with reflective surfaces. It even puts Unreal's original 98 engine to shame (same production year).
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on March 27, 2021, 08:39:11 AM
I think bumpmapping is one of those things where it used some sort of GPU extension to do its thing, and I wouldn't be surprised if modern cards don't carry that feature anymore, since any game using bumpmapping from the past two decades would use shaders. One of my dream features ATM is to be able to outright replace the GL renderer with a shader based one, but that's going to take some time.

I am currently investigating making the game not mess with your resolution. My initial solution for this was my windowed mode, but this is a bit lacklustre if you wish to play in fullscreen. Interestingly, the game actually uses borderless windowed mode normally in GL mode, but it also changes your screen resolution... The idea I'm drafting up ATM is to use a render target. Descent 3, so far as I can tell, doesn't use render targets normally, even for things like the HUD camera views, so I can trick the game into thinking a render target is actually the main framebuffer, and then when the game goes to flip buffers, I quickly draw that render target to the main framebuffer and then flip. I'll give that a try today.

Also, regrettably, the sound code is on hold for the moment. While I got 3D sound playing just fine, no crackles and pops, I cannot get streams working for the life of me, I need to reverse engineer a lot more of the LLS system and other parts of the sound system before I can do it. If people aren't interested in music, I can toss in an optional prototype version of the new sound code that will just have the 3D sound but no music.
edit: the music not working properly may have been a 1 line typo. Oops.

I want to get something released by next weekend. With my usual reliability and the frustrations of things like the sound system, it may drift some, but there's not too much work. I currently worry that there's too many "downsides" to this patch (ie, movies will still change your resolution if you don't disable them), but a lot of it is stuff that isn't too important so far so I think the benefits will outweigh the negatives for this first release (we've all seen those crappy late-90s FMVs a hundred times at this point...)
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on March 27, 2021, 09:54:58 PM
Alright, I got borderless window fullscreen in... well, kinda. It was my intention, but Windows is weird and automatically handles the case of creating a window the size of the desktop as a sign you actually want exclusive fullscreen mode, so it's actually exclusive fullscreen mode but the resolution is your desktop resolution... good enough for now, I need to figure out what borderless window games do differently to avoid this. The framebuffer system caused some bugs at first, but I think I squashed them. All of these hacks currently only work with the OpenGL renderer, since it's the only one I know how to service, but it works out nicely.

I've basically completed all the big hacks I want to get into an initial release, so the rest of it is probably going to be things like automatically setting certain command line switches and things like the 32-bit color hack (I keep on neglecting it because my executable came pre-patched with the ancient fan 32-bit hack)
Title: Re: Playing around with a Descent 3 patcher
Post by: Hunter on March 29, 2021, 02:33:28 AM
Very nice! And no rush. Things move really slowly these days... it can be about 3 months before people even check a new level!

I believe Ryan converted the movies to ogg, they're included in the new Linux release. (https://www.gamingonlinux.com/articles/descent-3-returns-to-linux-and-macos-with-an-official-modern-port.15900 (https://www.gamingonlinux.com/articles/descent-3-returns-to-linux-and-macos-with-an-official-modern-port.15900))
Title: Re: Playing around with a Descent 3 patcher
Post by: Matthew on March 31, 2021, 07:58:20 AM
This sounds excellent! I might even be able to stomach a playthrough of D3 again! Thanks for your work!
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on April 01, 2021, 08:59:55 AM
Just a small update, but I'm finally working on the configuration parser, and then the configuration tool. While finishing up the fullscreen code I also took a moment to squeeze in optional MSAA support for the new windowed and fullscreen modes, and it looks quite nice.
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on April 02, 2021, 11:26:06 AM
(https://i.imgur.com/xq4dptw.png)
The configuration parser is functional now, and the configuration tool is working. Some testing and cleanup is still needed, and I need to load in the offsets for some other versions, but I hope I can get this mess released this weekend.

These are all the patches that will be in the initial release, but I want to add more later down the line
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on May 23, 2021, 06:37:03 AM
Well, I was hoping to have a build released by now, but I've been trying to track down a mysterious crashing issue in the OpenAL sound code I wrote. At first, it never crashed, I could launch the game reliably and I never had any issues. Later, it would crash like once in 10 launches, but now it's crashing nearly every launch. This is really hard to track down since the game installs an exception handler, which does at least create error.log which shows you the full state of the stack and register dumps, but it's harder than actually using a debugger on this...

Hopefully soon, but the source is available now. (https://github.com/InsanityBringer/InjectD3)
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on July 11, 2021, 06:21:00 PM
It's been a while, but I have two new patches in the pipeline ATM.

The first is reverbs. Descent 3 supported EAX-enabled sound cards to provide reverbs with DirectSound3D, but this wouldn't work on any modern system with simple integrated sound hardware. The right emulator should provide it, but rather than deal with that I've added support for reverbs in the OpenAL Soft sound code I've provided. This can be turned on and off in the configuration.

The second is that I added a patch to change the game to use the HKEY_CURRENT_USER registry hive instead of HKEY_LOCAL_MACHINE. The upshot of this is that you will never need to run the game as adminstrator to change settings (unless you stick it in Program Files, so don't), and settings are per-user if that's your thing. Downside is that settings are now per-user if that's not your thing, but for most people it's absolutely worth it.

This does warrant a new configuration program, since the stock launcher won't work here, so I added one to the configuration program:
(https://i.imgur.com/TDLTcUE.png)
Title: Re: Playing around with a Descent 3 patcher
Post by: Kaiaatzl on July 12, 2021, 10:28:58 AM
Neat!
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on July 17, 2021, 04:11:04 PM
I squeezed in two more patches. At this rate I'm going to finish the entirety of my "future goals" list before I get a single release out.... (but at least the source is up on GitHub for anyone to play with).

The first of my new patches fixes a bug with Descent 3 where if you're using the mouse at a decently high framerate, holding it down becomes unreliable. I traced this down to an oddity in the mouse code. The keyboard and joystick code, when timing how long a button's been held for, uses the normal timer code, which by default uses a much higher accuracy means of measuring time. The mouse code, on the other hand, uses a simple MS timer with a resolution of somewhere around 10-16 MS according to MS's docs. This means the game would frequently get deltas of 0 and think you released the mouse. I patched it to use the same high-precision timer as the other input methods.

The second is pretty mundane, but since I was having trouble getting mouse controls right, and the mouse sensitivity controls in the game have limited resolution, I threw on a configurable mouse prescalar which will scale the inputs before the game code gets it. Works well for the moment, but mouse control is still a little rough I feel.
Title: Re: Playing around with a Descent 3 patcher
Post by: SaladBadger on August 28, 2021, 11:11:21 AM
https://github.com/InsanityBringer/InjectD3/releases/tag/v0.1-alpha (https://github.com/InsanityBringer/InjectD3/releases/tag/v0.1-alpha)

Assuming nothing's gone wrong, here's my first build!

It's absolutely vital you read the readme to tell what's going on. You'll need to use OpenGL for most patches to take effect, you'll probably need to rename your movies folder since I haven't patched the movie player yet, and there's still bugs in this release I'm trying to track down, but for normal playing it should be fine.
Title: Re: Playing around with a Descent 3 patcher [Build 1 released!]
Post by: SaladBadger on August 29, 2021, 08:45:38 AM
If anyone downloaded this build before this post, I recommend redownloading, I forgot to include the OpenAL soft binaries in the distribution. Oops.
Title: Re: Playing around with a Descent 3 patcher [Build 1 released!]
Post by: Matthew on August 31, 2021, 08:17:47 AM
I'll try to give it a try in the next few days and let you know how it went! It sounds promising.
Title: Re: Playing around with a Descent 3 patcher [Build 1 released!]
Post by: SaladBadger on October 10, 2021, 12:52:28 PM
I have pushed an update at https://github.com/InsanityBringer/InjectD3/releases/tag/v0.2-beta (https://github.com/InsanityBringer/InjectD3/releases/tag/v0.2-beta). This includes many bugfixes for the new sound system and mouse code, and some user convenience features for the configuration program. See the linked page for full details.