[1.13d] CPU sleep fix - less CPU time - big performance gain

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: 894
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

[1.13d] CPU sleep fix - less CPU time - big performance gain

Post by devurandom » Sat Mar 14, 2015 9:00 pm

[1.13d] CPU infinite loop bug fix

This is an update for the infinite loop found by Killer gorilla.
reference post viewtopic.php?f=8&t=53118

D2 never sleeps... Even if you had a 50,000 MHZ processor, it would still consume 100% of the clock cycles for a single core, 50% of clock cycles for dual cores... so on.

If I could only have 1 fix for D2 this would be it. D2 was consuming 25% of my 3.8 GHZ quad core processor... after this fix it dropped to ~1%. It amazes me that Blizzard never fixed this. 8-O

Code: Select all

Infinite Loop Bug in Function PeekmessageA  (Begins at 6FAD76A3) D2client.dll

change

6FAD7713  |.  75 17         |JNZ SHORT 6FAD772C   	        ; single player
6FAD7715  |.  A1 DCD1BC6F   |MOV EAX,DWORD PTR DS:[6FBCD1DC]
6FAD771A  |.  83F8 06       |CMP EAX,6
6FAD771D  |.  74 0D         |JE SHORT 6FAD772C
6FAD7715  |.  A1 DCD1BC6F   MOV EAX,DWORD PTR DS:[6FBCD1DC]
6FAD771A  |.  83F8 06       CMP EAX,6
6FAD771D      74 0D         JE SHORT 6FAD772C
6FAD771F  |.  83F8 08       CMP EAX,8
6FAD7722      74 08         JE SHORT 6FAD772C			;multi player
6FAD7724  |.  6A 0A         PUSH 0A                             ; Time = 10. ms

To

6FAD7713      90            NOP
6FAD7714      90            NOP
6FAD771A  |.  83F8 06       |CMP EAX,6
6FAD771D  |.  74 0D         |JE SHORT 6FAD772C
6FAD7715  |.  A1 DCD1BC6F   MOV EAX,DWORD PTR DS:[6FBCD1DC]
6FAD771A  |.  83F8 06       CMP EAX,6
6FAD771D      74 0D         JE SHORT 6FAD772C
6FAD771F  |.  83F8 08       CMP EAX,8
6FAD7722      90            NOP
6FAD7723      90            NOP
6FAD7724  |.  6A 0A         PUSH 0A                                  ; Time = 10. ms


Edit; update to Multiplayer
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: 77
Joined: Sat Oct 16, 2010 4:29 pm

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by FearedBliss » Thu Nov 24, 2016 6:27 pm

Thanks for this :). It was a bit confusing reading your paste since it seems there are multiple pastes of the same sequence in your example. After also finding your 1.13c cpu fix post on battle.net, I was able to cleanly extract your message haha:

Code: Select all

NOP the three lines marked as "Single Player", and "Multi-Player".
There is still another infinite loop happening in the main menu/character creation screen.
That hasn't been fixed.

Original (1.13d):

6FAD770A  |. 75 34          |JNZ SHORT D2Client.6FAD7740
6FAD770C  |> A1 007BBA6F    |MOV EAX,DWORD PTR DS:[6FBA7B00]
6FAD7711  |. 85C0           |TEST EAX,EAX
6FAD7713  |. 75 17          |JNZ SHORT D2Client.6FAD772C             ;  Single Player
6FAD7715  |. A1 DCD1BC6F    |MOV EAX,DWORD PTR DS:[6FBCD1DC]
6FAD771A  |. 83F8 06        |CMP EAX,6
6FAD771D  |. 74 0D          |JE SHORT D2Client.6FAD772C              ;  Closed Multi-Player (Battle.Net)
6FAD771F  |. 83F8 08        |CMP EAX,8
6FAD7722  |. 74 08          |JE SHORT D2Client.6FAD772C              ;  TCP/IP Multi-Player
6FAD7724  |. 6A 0A          |PUSH 0A                                 ; /Timeout = 10. ms
6FAD7726  |. FF15 6CFFB76F  |CALL DWORD PTR DS:[<&KERNEL32.Sleep>]   ; \Sleep
6FAD772C  |> 85F6           |TEST ESI,ESI
6FAD772E  |.^0F85 6FFFFFFF  \JNZ D2Client.6FAD76A3

New:

6FAD770A  |. 75 34          |JNZ SHORT D2Client.6FAD7740
6FAD770C  |> A1 007BBA6F    |MOV EAX,DWORD PTR DS:[6FBA7B00]
6FAD7711  |. 85C0           |TEST EAX,EAX
6FAD7713     90             NOP                                      ;  Single Player
6FAD7714     90             NOP
6FAD7715  |. A1 DCD1BC6F    |MOV EAX,DWORD PTR DS:[6FBCD1DC]
6FAD771A  |. 83F8 06        |CMP EAX,6
6FAD771D     90             NOP                                      ;  Closed Multi-Player (Battle.Net)
6FAD771E     90             NOP
6FAD771F  |. 83F8 08        |CMP EAX,8
6FAD7722     90             NOP                                      ;  TCP/IP Multi-Player
6FAD7723     90             NOP
6FAD7724  |. 6A 0A          |PUSH 0A                                 ; /Timeout = 10. ms
6FAD7726  |. FF15 6CFFB76F  |CALL DWORD PTR DS:[<&KERNEL32.Sleep>]   ; \Sleep
6FAD772C  |> 85F6           |TEST ESI,ESI
6FAD772E  |.^0F85 6FFFFFFF  \JNZ D2Client.6FAD76A3

1.13d Offset: 27713

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

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by devurandom » Thu Nov 24, 2016 7:48 pm

Hello,

This may not be the best way to fix the CPU bug. A better way would be to find where the frame rate is regulated for client and set the max frame rate to 200 FPS, for all modes.

The internal frame rate on the client is 1400+ FPS even in single player mode, while the server is doing 25 FPS. I've seen client go as high as 1700 FPS.. I think its only limited by your hardware & could go higher than that.

Blizzard fixed this for some 1.14 versions in MultiPlayer, but they never bothered to fix the single player frame rate, it still cranks out 1400+ FPS.

This is why I got into code editing because it {filtered} me off that a 14 year old game was flat-lining one of my I5 CPU cores.

;)
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
karlock
Posts: 35
Joined: Mon Mar 16, 2015 1:16 pm

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by karlock » Fri Nov 25, 2016 5:37 pm

Does your mod "UVLoD" have this fix or next version? And I want to use UVLoD with plugY 11.0 for 1.13d, But UVLoD shows invalid version.
PlugY for 1.13d viewtopic.php?f=133&t=62849

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

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by devurandom » Fri Nov 25, 2016 6:31 pm

karlock" wrote:Does your mod "UVLoD" have this fix or next version? And I want to use UVLoD with plugY 11.0 for 1.13d, But UVLoD shows invalid version.
PlugY for 1.13d viewtopic.php?f=133&t=62849
Hi,

1.39 is using and edit similar to the above. It's modified to limit frame rate to approx 200, by setting sleep to 5ms, but its still not the right method to do that. Setting the frame rate is something I 've partially tracked down, but havn't got around to fixing.

As far as I know, one person was able to get PlugY to work with UVLoD, but they had to disable certain things in PlugY so the 2 could work together.
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
karlock
Posts: 35
Joined: Mon Mar 16, 2015 1:16 pm

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by karlock » Tue Nov 29, 2016 2:22 am

devurandom" wrote:
karlock" wrote:Does your mod "UVLoD" have this fix or next version? And I want to use UVLoD with plugY 11.0 for 1.13d, But UVLoD shows invalid version.
PlugY for 1.13d viewtopic.php?f=133&t=62849
Hi,

1.39 is using and edit similar to the above. It's modified to limit frame rate to approx 200, by setting sleep to 5ms, but its still not the right method to do that. Setting the frame rate is something I 've partially tracked down, but havn't got around to fixing.

As far as I know, one person was able to get PlugY to work with UVLoD, but they had to disable certain things in PlugY so the 2 could work together.
I think maybe I used "plugy.exe" not the "Game.exe", So the DLL can't attach the program.

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

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by devurandom » Tue Nov 29, 2016 2:47 am

FearedBliss" wrote:Thanks for this :). It was a bit confusing reading your paste since it seems there are multiple pastes of the same sequence in your example. After also finding your 1.13c cpu fix post on battle.net, I was able to cleanly extract your message haha:
I suspect the code edit above may be related to a rare random NPC "Malah" crash described here:
viewtopic.php?t=62882

:-|

For now this is what I'm using:

Code: Select all

Credits Enceladus

[1.13d] D2Client.0x44928

6FAF491D    EB 09         |JMP SHORT 6FAF4928
6FAF491F    8D4424 0C     |LEA EAX,[LOCAL.127]  
6FAF4923    E8 68E70300   |CALL 6FB33090
6FAF4928    6A 00         |PUSH 0                        

change

6FAF4928    6A 00         PUSH 0                          

to:

6FAF4928    6A 01         PUSH 1
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: 77
Joined: Sat Oct 16, 2010 4:29 pm

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by FearedBliss » Sat Jun 10, 2017 2:37 pm

I've been updating my mod to 1.14d and when I was going to start working on this fix, I noticed that in 1.14d this doesn't occur anymore. It probably has to do with the 1.14b update:
Capped the frame rate to 200 to save batteries, spare system load, and prevent hot lap syndrome
https://us.battle.net/forums/en/bnet/topic/20742964214

User avatar
GalaXyHaXz
Hosted Forum Moderator
Crusader
Posts: 54
Joined: Mon Apr 04, 2011 3:44 am

Re: [1.13d] CPU sleep fix - less CPU time - big performance

Post by GalaXyHaXz » Sun Jul 23, 2017 5:55 pm

This bug still occurs for me even in 1.14d. Game always shows 25% CPU on a quad core. Here is the fix for 1.14d for both the Title Screen and In Game:

Code: Select all

; Title screen
004FA66F  |.  74 02         JE SHORT 004FA673 ; NOP
004FA671  |.  33C0          XOR EAX,EAX ; NOP
004FA673  |>  50            PUSH EAX                                ; /Time
004FA674  |.  FF15 58C26C00 CALL DWORD PTR DS:[<&KERNEL32.Sleep>]   ; \KERNEL32.Sleep

; In-game
; Single player
00451C31  |.  75 17         JNE SHORT 00451C4A ; NOP
00451C33  |.  A1 10067A00   MOV EAX,DWORD PTR DS:[7A0610]
00451C38  |.  83F8 06       CMP EAX,6
; Closed battle.net
00451C3B  |.  74 0D         JE SHORT 00451C4A ; NOP
00451C3D  |.  83F8 08       CMP EAX,8
; Open battle.net & TCP/IP
00451C40  |.  74 08         JE SHORT 00451C4A ; NOP
00451C42  |.  6A 0A         PUSH 0A                                 ; /Time = 10. ms
00451C44  |.  FF15 58C26C00 CALL DWORD PTR DS:[<&KERNEL32.Sleep>]   ; \KERNEL32.Sleep
1.09b Fixup: Download
UnSecurom'd .exe for patches 1.00-1.11b: Download
My very first mod, SLASH: Download

EnPhreg
Posts: 5
Joined: Thu Jan 21, 2021 3:50 pm

Re: [1.13d] CPU sleep fix - less CPU time - big performance gain

Post by EnPhreg » Fri Jan 22, 2021 1:34 am

GalaXyHaXz wrote:
Sun Jul 23, 2017 5:55 pm
This bug still occurs for me even in 1.14d. Game always shows 25% CPU on a quad core. Here is the fix for 1.14d for both the Title Screen and In Game:
how to use / where to copy this code for 1.14d? do i have to create a new dll for that stuff to work or do i have to alter the game.exe file?
have really no idea and my search has shed no light on this.

Post Reply

Return to “Code Editing”