Page 2 of 2

Re: HOW TO: Fix issues with crashing and freezing

Posted: Mon Jul 06, 2020 2:47 am
by Tggtt
That's really great, many thanks MildewMan1!

I have already updated the MP patch thread with your news. I hope that's also good news for you.

Re: HOW TO: Fix issues with crashing and freezing

Posted: Mon Jul 06, 2020 11:42 pm
by MildewMan1
Cool! I think it might be worth stickying this thread though since it can help people that are trying to get the CD version of the game working. Someone who is looking for a crash fix for that may not know to look in the multiplayer patch thread for the GOG version. Just a thought.

Re: HOW TO: Fix issues with crashing and freezing

Posted: Tue Apr 20, 2021 4:19 pm
by MildewMan1
Apologies in advance for the long post, but I wanted to give an update. I have almost completely reverse engineered version 1.20 of Deadlock 1. I would estimate that it is about 95% working with a few hiccups that still need to be fixed.

Since I basically have the source code, I wanted to try and understand what was causing the game to crash when I zoomed into a territory. I originally thought it was due to WinG not playing nicely with 64 bit Windows, but from debugging the code, I've discovered what the true problem is. The true problem is that the developers dimmed a global int[1280] array that they called "highestY", which is located at memory location 0x0056190C (English version 1.20).

Normally this wouldn't be a problem, but they sized this array based on the assumption that the screen width of the user would be <= 1280. When you try to run the game normally (in full screen mode) with a resolution width > 1280, the code overflows into another int[1280] array right next to it in memory because they use a pointer to access the array values without checking bounds. It ends up overwriting the 2nd array values, which were set previously in another function.

This 2nd int[1280] array is used as the "Y Table" for the back buffer (memory allocated to draw the background in the settlements). Basically their Y-table stores scan line offsets that the code uses to draw the background, but since it was overwritten, it causes a pointer in the "SmearLight" function (located at 0x00447649) to read outside of the allocated back buffer memory, and thus causes the crash to occur.

Neither the WinG code nor the WAIL32 code that I originally included would fix this problem. The reason why I thought it was fixing it for me is because I was also changing the resolution of the game to 1280x1024 in my version of the dll (which included other things besides the WinG/WAIL32 stuff).

To remedy this, I am going to update the WinG32 code to force the game to run in 1280x1024 mode like the GOG guys did. (Note: this code could also be compiled with the WAIL32 code, and the WING32.dll replacement wouldn't be needed anymore.)

In the source code, I just increased the size of the first array, and it fixed the problem. Once I start to rewrite the code to include newer c++ features, I'm going to size it dynamically.