Max Payne 1 & 2 Startup Hang Patch

Getting old Windows games working.

Max Payne 1 & 2 Startup Hang Patch

Postby UCyborg » 2017-1-02 @ 11:51

I've recently assembled a brand new patch for classic Max Payne games, solving one of the biggest technical issues with those games, in some cases preventing them from starting-up on modern systems without hacky workarounds like starting the game with affinity set to single core or worse, running them in compatibility modes. I'll probably upload the patch to PC Gaming Wiki as well. Straight from the ReadMe:

This patch is intended to solve issues related to game engine initializing Direct3D inside DllMain, which most notably causes the game to hang during startup with certain combinations of graphics hardware and drivers. Additionally, it is impossible to run the game through dgVoodoo Direct3D 8 to 11 wrapper, because Direct3D 11 runtime refuses to initialize from DllMain to prevent lockups.

The patch will solve above mentioned issues and possibly other problems that might be related to Direct3D initialization inside DllMain by delaying actual initialization to the point when execution flow returns from LoadLibrary API, therefore preventing any sort of lockup that would occur otherwise.

No compatibility modes should be applied to game executables, as they usually create more problems than they solve. Starting the game with affinity set to single core also isn't required anymore and will only serve to slow the game down a little.

Files in this archive are intended to use with latest version of games, which are:

Max Payne v1.05
Max Payne 2 v1.01

If you have Steam version of games, you should already have latest versions, otherwise, they must be updated with appropriate official patches before applying this patch.

To install, simply extract contents of each game's folder into your own, overwriting original files.
Attachments
MaxPayneStartupHangPatchv1.01.zip
(1.1 MiB) Downloaded 123 times
Last edited by UCyborg on 2017-1-23 @ 09:48, edited 1 time in total.
UCyborg
Member
 
Posts: 112
Joined: 2015-9-04 @ 11:10

Re: Max Payne 1 & 2 Startup Hang Patch

Postby keropi » 2017-1-02 @ 13:42

nice, thanks for the heads up!
User avatar
keropi
l33t++
 
Posts: 5520
Joined: 2003-9-08 @ 06:45
Location: Greece

Re: Max Payne 1 & 2 Startup Hang Patch

Postby lowenz » 2017-1-02 @ 13:46

Can you make the same patch for 3DMark 2001 SE? (3DMark 2000 can already run with dgVoodoo 2).
lowenz
Oldbie
 
Posts: 775
Joined: 2014-12-20 @ 01:30

Re: Max Payne 1 & 2 Startup Hang Patch

Postby UCyborg » 2017-1-02 @ 17:22

lowenz wrote:Can you make the same patch for 3DMark 2001 SE? (3DMark 2000 can already run with dgVoodoo 2).

Will get to it. You just reminded me that I've read some time ago that older 3D Mark programs are based on MAX-FX engine. Just downloaded it and I see that it uses same DLLs as games, though checksums don't match with either fully patched games, so I suppose I gotta do it all over again, since due to the nature of working with disassembled code, you can't just do a copy-paste, even though the patches are identical for both games with exception of minor low-level differences.
UCyborg
Member
 
Posts: 112
Joined: 2015-9-04 @ 11:10

Re: Max Payne 1 & 2 Startup Hang Patch

Postby lowenz » 2017-1-02 @ 17:29

Obviously if you got the time! Thanks! (So we can test it with the pure D3D8.dll with the affinity trick, the Crosire D3D9 wrapper and dgVoodoo2 for D3D11).

These are the results with an OC'ed 1050 Ti

Pure D3D8:
Image

Crosire D3D8to9:
Image


It is really interesting, 'cause the wrapper overhead is largely exceeded by the D3D9 advantage givern by today GPUs drivers.
lowenz
Oldbie
 
Posts: 775
Joined: 2014-12-20 @ 01:30

Re: Max Payne 1 & 2 Startup Hang Patch

Postby UCyborg » 2017-1-02 @ 22:29

3D Mark 2001 SE patch done: viewtopic.php?f=8&t=51587

You actually don't need to change affinity with stock d3d8.dll thanks to this patch. On my weak laptop with AMD Radeon R2, I've noticed, without any FPS counters, that the game is a little smoother when run on all cores. It kinda makes sense since game's main thread isn't the only one that is part of the game's process so it helps if OS can schedule threads on any CPU it desires instead of everything being constricted to 1 core. And even before this patch, one could set affinity back to all cores when the game started up, but I don't think anyone ever thought of that.
UCyborg
Member
 
Posts: 112
Joined: 2015-9-04 @ 11:10

Re: Max Payne 1 & 2 Startup Hang Patch

Postby DCX6723 » 2017-2-28 @ 22:10

Good job and thank you!

The 2 was huge payne on my computer, making the game randomly working when upgrading Windows.
DCX6723
Newbie
 
Posts: 10
Joined: 2017-2-28 @ 21:53

Re: Max Payne 1 & 2 Startup Hang Patch

Postby Lelasin » 2017-3-07 @ 12:31

Good job!!!
Is it difficult to make such patches on their own? Can you advise any tutorials?
User avatar
Lelasin
Newbie
 
Posts: 4
Joined: 2017-2-07 @ 12:18
Location: New York

Re: Max Payne 1 & 2 Startup Hang Patch

Postby UCyborg » 2017-3-11 @ 16:36

You're all very welcome! There aren't any specific tutorials. You just somehow put the pieces together. Patching games that don't come with source code is a very specific kind of programming, or more like re-programming and needs the one to get familiar with x86 assembly language and studying disassembled code using tools like OllyDbg. You do find miscellaneous tutorials about certain tasks, but you're mostly on your own I think. I remember watching long time ago the tutorial that demonstrated how to make Notepad show a message box before it starts. The ones for demonstrating how to bypass copy protection in certain programs seem common, but I never found anything that demonstrated how some bugs were found and fixed in certain application/game. And the fact that every problem is unique complicates matters, plus the source code for most games is not available. When it's available, many improvements are possible, look at modern source ports of classic Doom and Quake games.

Generally, what little I've learned about programming, it all seems like some sort of complex puzzle. For example, you have a library with functionality that manipulate images, another for playing sound files and one that contains drawing routines and by combining functionality in all of them, you can make a game. It's really hard to explain and I'm not really good at these things, haven't really put anything particularly useful together from scratch. Improving other people's work is easier. I don't really understand how some people can just sit behind the computer screen and just write and write code, I usually struggle with simple things and like I said, every problem you're trying to solve programmatically is unique. Programming is essentially manipulating data that make the hardware produce the desired result. It probably takes a lot of practice, trial and error before you become proficient at it.

With this particular patch, it came down to understanding basic x86 assembly language, how Portable Executable format works (it's a container for Windows executable files and DLLs) and a couple of details from documentation on MSDN. So I thought, since I knew Max Payne did something in one of the DLLs' DllMain function, which is not supposed to be used for anything or just for really simple initialization, what if I could delay its execution by the time it would be safe to execute its functionality. So I put a variable in its DllMain where I store if the function was already called. If not, it means Windows called it as part of the game request to load its rendering library. When this happens, I bail out, since I know nothing complex (in this case, calls to Direct3D initialization routines) is supposed to be executed until the game's request to load said library is completed (otherwise you can get a deadlock), at which point, its initialization routine in DllMain can be executed without bad consequences. So by this point, I call it again on my own and this time, the check whether the routine was already called once passes and initialization completes instead of not doing anything like the first time. And no bizarre workarounds required.

This is really very special kind of problem and the only reason it came to it is the fact that developers chose to ignore documentation here: https://msdn.microsoft.com/en-us/librar ... 83(v=vs.85).aspx When you choose to ignore the guidelines, unexpected things can happen and since it works on one computer but not other, some people put the blame on the operating system or graphics drivers. Soulbringer had the same problem before I patched it and I've read that someone discovered the "fix" which includes putting older version of one of graphics driver DLLs in its game folder. Then another person tries it and wonders why the game randomly crashes with strange error. And for the third person, the game doesn't work at all.
UCyborg
Member
 
Posts: 112
Joined: 2015-9-04 @ 11:10


Return to Windows

Who is online

Users browsing this forum: No registered users and 1 guest