Remove 25 FPS limit in Single Player

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Remove 25 FPS limit in Single Player

Post by devurandom » Fri Mar 23, 2018 5:13 am

I think this question has been asked a few times. The code that handles Frame Rates is quite a mess,
and you'd almost have to rewrite the function to find where the limit is.
Thanks to Necrolis for finding this!



Code: Select all

Remove 25 FPS Limit in Single Player

Credit to Necrolis for finding this


(In v1.14 Glide3x may peak at 200 FPS)
Note: Negative impact on your CPU 
without other edits
=====================================



[1.14d] - Game.0x4F27E


0004F278   391D 04077A00  CMP DWORD PTR DS:[7A0704],EBX
0004F27E   75 24          JNE SHORT 0004F2A4

Change to:

0004F278   90             NOP
0004F279   90             NOP
0004F27A   90             NOP
0004F27B   90             NOP
0004F27C   90             NOP
0004F27D   90             NOP
0004F27E   90             NOP
0004F27F   90             NOP


--------------------------

[1.13d] - D2Client.0x45EA7


00045EA1   391D F046BD6F  CMP DWORD PTR DS:[6FBD46F0],EBX
00045EA7   75 35          JNE SHORT 00045EDE

Change to:


00045EA1   90             NOP
00045EA2   90             NOP
00045EA3   90             NOP
00045EA4   90             NOP
00045EA5   90             NOP
00045EA6   90             NOP
00045EA7   90             NOP
00045EA8   90             NOP


--------------------------

[1.13c] - D2Client.0x44E57


00044E51   391D 9034BD6F  CMP DWORD PTR DS:[6FBD3490],EBX
00044E57   75 35          JNE SHORT 00044E8E

Change to:

00044E51   90             NOP
00044E52   90             NOP
00044E53   90             NOP
00044E54   90             NOP
00044E55   90             NOP
00044E56   90             NOP
00044E57   90             NOP
00044E58   90             NOP


--------------------------

[1.12a] - D2Client.0x7D1E7


0007D1E1   391D 2834BD6F  CMP DWORD PTR DS:[6FBD3428],EBX
0007D1E7   75 35          JNE SHORT 0007D21E

Change to:

0007D1E1   90             NOP
0007D1E2   90             NOP
0007D1E3   90             NOP
0007D1E4   90             NOP
0007D1E5   90             NOP
0007D1E6   90             NOP
0007D1E7   90             NOP
0007D1E8   90             NOP


--------------------------

[1.11b] - D2Client.0x33597


00033591   391D 8036BD6F  CMP DWORD PTR DS:[6FBD3680],EBX
00033597   75 35          JNE SHORT 000335CE

Change to:

00033591   90             NOP
00033592   90             NOP
00033593   90             NOP
00033594   90             NOP
00033595   90             NOP
00033596   90             NOP
00033597   90             NOP
00033598   90             NOP


--------------------------

[1.10f] - D2Client.0xA2CB


0000A2C4   A1 E079BA6F    MOV EAX,DWORD PTR DS:[6FBA79E0]
0000A2C9   85C0           TEST EAX,EAX
0000A2CB   75 2B          JNE SHORT 0000A2F8

Change to:

0000A2C4   A1 E079BA6F    MOV EAX,DWORD PTR DS:[6FBA79E0]
0000A2C9   90             NOP
0000A2CA   90             NOP
0000A2CB   90             NOP
0000A2CC   90             NOP


--------------------------

[1.09d] - D2Client.0x9B5F


00009B5F   392D 400CBB6F  CMP DWORD PTR DS:[6FBB0C40],EBP
00009B65   75 2B          JNE SHORT 00009B92

Change to:

00009B5F   90             NOP
00009B60   90             NOP
00009B61   90             NOP
00009B62   90             NOP
00009B63   90             NOP
00009B64   90             NOP
00009B65   90             NOP
00009B66   90             NOP


--------------------------

[1.09b] - D2Client.0x9B5F


00009B6F   392D E01DBB6F  CMP DWORD PTR DS:[6FBB1DE0],EBP
00009B75   75 2B          JNE SHORT 00009BA2

Change to:

00009B6F   90             NOP
00009B70   90             NOP
00009B71   90             NOP
00009B72   90             NOP
00009B73   90             NOP
00009B74   90             NOP
00009B75   90             NOP
00009B76   90             NOP


Last edited by devurandom on Sun Mar 25, 2018 1:47 pm, edited 1 time in total.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

User avatar
kidpaddle94
Forum Legend
Principality
Posts: 2057
Joined: Thu Aug 13, 2009 2:54 pm
Location: localhost
Canada

Re: Remove 25 FPS limit in Single Player

Post by kidpaddle94 » Sun Mar 25, 2018 5:23 am

The CMP instruction should be NOP'd out as well, on version where it applies. For example on 1.13c it should be

Code: Select all

00044E51   391D 9034BD6F  CMP DWORD PTR DS:[6FBD3490],EBX
00044E57   75 35          JNE SHORT 00044E8E

Change to:

00044E51   90             NOP
00044E52   90             NOP
00044E53   90             NOP
00044E54   90             NOP
00044E55   90             NOP
00044E56   90             NOP
00044E57   90             NOP
00044E58   90             NOP
Thanks to you & Necrolis for this.

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Remove 25 FPS limit in Single Player

Post by devurandom » Sun Mar 25, 2018 1:57 pm

It is best practice to nop out the cmp, but in this case it doesn't matter, cause the flag isn't evaluated before it's set again. I went ahead and changed it anyway. Thanks for noticing that. ;)

Code: Select all

00044E51   391D 9034BD6F CMP DWORD PTR DS:[6FBD3490],EBX
00044E57   75 35         JNE SHORT 00044E8E
00044E59   A1 FCBBBC6F   MOV EAX,DWORD PTR DS:[6FBCBBFC]
00044E5E   3BC3          CMP EAX,EBX
00044E60   74 38         JE SHORT 00044E9A
.......
00044E8E   395C24 10      CMP DWORD PTR SS:[ESP+10],EBX
00044E92   74 06          JE SHORT 00044E9A
Last edited by devurandom on Wed Mar 28, 2018 5:21 am, edited 1 time in total.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

leekun
Dark Alliance Beta Test
Warrior
Posts: 24
Joined: Wed Jul 19, 2017 9:41 pm

Re: Remove 25 FPS limit in Single Player

Post by leekun » Sun Mar 25, 2018 4:49 pm

Will kidpaddle94's edit fix the "Negative impact on your CPU without other edits" problem? and is there still more side effect, I'm not aware of?

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Remove 25 FPS limit in Single Player

Post by devurandom » Wed Mar 28, 2018 9:00 am

You may need CPU Fix, otherwise it just runs the full render rate i.e. the same as TCP/IP Multiplayer. That's the negative impact.

There can be other side effects that take some balancing to fix if adding CPU Fix. one is a possible increase in packet latency, depending on how much sleep time you give to CPU fix.

Would be better overall just to set an absolute frame rate cap, but as mentioned the code is a mess.

EDIT:

What I do is patch @6FAF4E51 [1.13c] to a custom call. It does the CPU fix, and sets a limit on rendering in one small function. Testing gives 10% CPU in Glide3x and 2% CPU for other Render Modes.

Code: Select all

// skip 2 then render  = 100 FPS for Glide3x and 64 FPS all other modes
BOOL __fastcall D2RenderSkip()
{
	Sleep (1);     // replacement for CPU Fix

	if(*gdwRenderMode == VIDEO_MODE_GLIDE)
	{
		if(gdwRenderSkip >= 2)
		{
			gdwRenderSkip = 0;
			return FALSE;
		}
		
		gdwRenderSkip++;
		return TRUE;
	}

	return FALSE;
}
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

FearedBliss
Posts: 82
Joined: Sat Oct 16, 2010 4:29 pm
United States of America

Re: Remove 25 FPS limit in Single Player

Post by FearedBliss » Tue Mar 02, 2021 12:52 am

Thanks for this devurandom and Necrolis. I'm implementing this atm in my Singling patch set for versions 1.00, 1.05b, 1.07, 1.08, 1.09b, 1.13d, and 1.14d. Just wanted to let you know that this patch is not safe atm since it contains a modification on a relocatable section (The CMP has a relocation). If ASLR kicks in, people's games will most likely crash. You'll either need to re-implement this without relocations, or make sure to kill the appropriate relocation in the relocation table. I'll be implementing this fix internally in another way when I'm done analyzing it.

EDIT: After looking at it a bit, I would say the simplest solution (that also wouldn't crash - from my best guest so far) is what devurandom originally mentioned which is to just NOP the JNE because the CMP's ZF won't be re-used before a subsequent CMP. Every version has this a bit differently so if people are doing this for multiple versions like me, you'll need to be careful and just look around. But nopping the JNE in this instance (for 1.13d specifically) would be the safest and most minimal change to the code base. You can try and implement a different strategy as I mentioned originally if you "really want to" kill that CMP.

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: Remove 25 FPS limit in Single Player

Post by devurandom » Tue Mar 09, 2021 10:02 am

Credit for the fix goes to Necrolis. He might be the only one so far to rewrite the top level function? IDK.

I could see your issue patching the 25 FPS fix into OLD mods with REBASED D2Client dll's. Rebased dlls
remove the reloc section. With modern operating systems you don't always get the preferred address space
that rebased dll's expect. Rebased worked fine in Windows 98 but not now.

This issue has been coined Diablo II ALSR issues, but it's not. ASLR randomizes the stack. None of the
Diablo II Modules up to 1.14d are capable of executing ASLR according to the file header section, and
windows wont attempt ASLR on these modules. ASLR is not the same as address relocation.

Forcing ASLR is something that could change with D2 1.15, aka D2 Resurrected. Blizzard I'm guessing
is more likely to use an encrypted Game.exe to prevent dll injection. How else are they going to
prevent dll injection?

If Blizzard forces people to run windows 10, I'm not sending them my dollars for D2 resurrected.
Windows 10 is a data collection OS. It would be 100% illegal under the 1974 privacy act.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

FearedBliss
Posts: 82
Joined: Sat Oct 16, 2010 4:29 pm
United States of America

Re: Remove 25 FPS limit in Single Player

Post by FearedBliss » Tue Mar 09, 2021 2:01 pm

Hey devurandom!

In that case I meant to say address relocation which I believe is still possible. All of my modifications are always done to the original dlls (unrebased original from the original patch files). So far from my observations address relocation is still possible for those addresses and that’s my primary concern. Just wanted to leave that note here ;).

BURAOT
Posts: 1
Joined: Sat Nov 28, 2020 2:10 pm

Re: Remove 25 FPS limit in Single Player

Post by BURAOT » Sat Apr 24, 2021 2:34 pm

for [1.14d] - Game.0x4F27E it should be 0x4F278 maybe mistypo, ive test this fps up to 80, power usage quite high ill stick to 25fps :), 0004F27E 75 24 <- Set to NOP only this also works

Post Reply

Return to “Code Editing”