[1.13c] Fixing LCS bugs in Vanilla LoD

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

User avatar
mmpx222
Junior Member
Paladin
Posts: 154
Joined: Sat Apr 26, 2014 9:19 am
Korea South

[1.13c] Fixing LCS bugs in Vanilla LoD

Post by mmpx222 » Thu Jan 22, 2015 4:54 am

Edit: I'm going to post any other bug fixes I find here.
Edit2: Whoops, bug fix #2 had a critical bug that caused the game to crash. Fixed :(

I've been able to fix two unrelated, display-only bugs in vanilla D2 v1.13c:

Bug 1.
Every class has a ToHitFactor, specified in CharStats.txt, that is added to their attack rating. This bug(See Amazon Basin's wiki page for more info) causes the ToHitFactor to be added twice for calculating the percent hit chance in the LCS. This is a display bug only, and is pretty simple to fix.

Code: Select all

(D2Client.0x000BCCA7 - NOP 5 bytes)
text:6FB6CCA7                 call    GetClassToHitFactor
Bug 2.
The LCS applies the +Damage% bonus from Throwing Mastery and Double Throw's synergy *after* calculating other sources of +Damage%, even though they are actually added to the other sources before being multiplied. This results in 2-3x inflated Throw damage/Double Throw damage for throwbarbs. I had to replace some assembly code to fix it....

Code: Select all

;Insert @ D2Client.0x0003313B (replace 166 bytes of code)
;Add skill damage bonus to EDI
	ADD EDI,DWORD PTR SS:[ESP+24]             ;  EDI = damagepercent + skill_damage_bonus (if any)
;Retrieve Throwing Mastery bonus and store it in EDI
;Note: The functions may use EDI themselves, so let's push EDI onto the stack and retrieve it later
	PUSH EDI                                  ;  Temporary storage
	PUSH 4E                                   ;  UNIT_STATE_ThrowingMastery
	PUSH ESI
	CALL 6FABC1FC                             ;  CALL <JMP.&D2Common.#10494>
        POP EDI                                   ;  Retrieve from temporary storage
	TEST EAX, EAX                             ;  If the player has Throwing Mastery...
	JE SHORT 6FAE3163                         ;  ...then jump to <Continue Calculations>
	MOV EDX,DWORD PTR SS:[ESP+2C]             ;
	MOV EAX,DWORD PTR SS:[ESP+34]             ;
        PUSH EDI                                  ;  Temporary storage (again)
	PUSH 1
	PUSH EDX
	PUSH EAX
	PUSH ESI
	CALL 6FABC922                             ;  CALL <JMP.&D2Common.#10804>
	POP EDI                                   ;  Retrieve from temporary storage
	ADD EDI,EAX                               ;  EDI = damagepercent + skill_damage_bonus (if any) + throw_mastery_bonus (if any)                            ;  End of temporary storage
:Continue Calculations
;Calculate final mindamage
	MOV EAX,[ESP+10]                          ;  EAX = item_mindamage_percent
	ADD EAX,EDI                               ;  EAX = item_mindamage_percent + damagepercent + skill_damage_bonus (if any) + throw_mastery_bonus (if any)
	IMUL EAX,[EBP]                            ;  EAX = (mindamage_total_pct * mindamage)
	XOR EDX,EDX
	MOV ECX, 64
	IDIV ECX                                  ;  EAX = (mindamage_total_pct * mindamage) / 100
	ADD [EBP], EAX
;Calculate final maxdamage
	MOV EBX,[ESP+1C]                          ;  EBX => item_throw_mindamage
	MOV EAX,[ESP+14]                          ;  EAX = item_maxdamage_percent
	ADD EAX,EDI                               ;  EAX = item_maxdamage_percent + damagepercent + skill_damage_bonus (if any) + throw_mastery_bonus (if any)
	IMUL EAX,[EBX]                            ;  EAX = (maxdamage_total_pct * maxdamage)
	XOR EDX,EDX
	MOV ECX, 64
	IDIV ECX                                  ;  EAX = (maxdamage_total_pct * maxdamage) / 100
	ADD [EBX], EAX
;Compare mindamage and maxdamage
	MOV ECX, [EBP]                            ;  ECX = mindamage_final
	CMP EAX, ECX
	JGE SHORT 6FAE319A                        ;  Jump to <End of Code>
	MOV [EBX], ECX
:End of Code
;NOP up to D2Client.0x000331E1
Or, in binary string form:

Code: Select all

(Copy-paste this to D2Client.0x0003313B)
03 7C 24 24 57 6A 4E 56 E8 B4 90 FD FF 5F 85 C0 74 16 8B 54 24 2C 8B 44 24 34 57 6A 01 52 50 56
E8 C2 97 FD FF 5F 03 F8 8B 44 24 10 03 C7 0F AF 45 00 33 D2 B9 64 00 00 00 F7 F9 01 45 00 8B 5C
24 1C 8B 44 24 14 03 C7 0F AF 03 33 D2 B9 64 00 00 00 F7 F9 01 03 8B 4D 00 3B C1 7D 02 89 0B 90
90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
90 90 90 90 90 90
Last edited by mmpx222 on Wed Feb 11, 2015 10:32 pm, edited 2 times in total.
D2TXT / D2INI - Python scripts for editing TXT files, or converting between TXT ↔ INI files

User avatar
mmpx222
Junior Member
Paladin
Posts: 154
Joined: Sat Apr 26, 2014 9:19 am
Korea South

Re: [1.13c] Fixing LCS bugs in Vanilla LoD

Post by mmpx222 » Thu Jan 22, 2015 4:58 am

Another bug with Throwing Mastery adds the +Damage% bonus twice when using Throw or Left Throw. This can be fixed by NOPing a function call in D2Game.dll:

Code: Select all

(D2Game.0x0009E530, NOP 11 bytes)
.text:6FCBE530                 push    0               ; nLayer
.text:6FCBE532                 push    eax             ; nValue
.text:6FCBE533                 push    19h             ; nStat
.text:6FCBE535                 push    esi             ; unit
.text:6FCBE536                 call    D2Common_10551_AddUnitStat
D2TXT / D2INI - Python scripts for editing TXT files, or converting between TXT ↔ INI files

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
South Africa

Hand-picked

Re: [1.13c] Fixing LCS bugs in Vanilla LoD

Post by Necrolis » Thu Jan 22, 2015 2:27 pm

mmpx222" wrote:Another bug with Throwing Mastery adds the +Damage% bonus twice when using Throw or Left Throw. This can be fixed by NOPing a function call in D2Game.dll:

Code: Select all

(D2Game.0x0009E530, NOP 11 bytes)
.text:6FCBE530                 push    0               ; nLayer
.text:6FCBE532                 push    eax             ; nValue
.text:6FCBE533                 push    19h             ; nStat
.text:6FCBE535                 push    esi             ; unit
.text:6FCBE536                 call    D2Common_10551_AddUnitStat
I suggest you veryify that there is indeed a bug rather than going on empirical testing because this is the only place that shifts the mastery boni (both attack rating and damage%) to the missile (it is in fact the only place that calculates the mastery boni when you use throw, the missile itself doesn't have duplicated damage%). I did a quick run through of the missile creation (sksrvst -> sksrvdo -> missileinit -> sksrvdo -> missilesrvdo -> damageapplicator) and I didn't find anything that seemed fishy.
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

User avatar
mmpx222
Junior Member
Paladin
Posts: 154
Joined: Sat Apr 26, 2014 9:19 am
Korea South

Re: [1.13c] Fixing LCS bugs in Vanilla LoD

Post by mmpx222 » Fri Jan 30, 2015 6:28 am

Necrolis" wrote:I suggest you veryify that there is indeed a bug rather than going on empirical testing because this is the only place that shifts the mastery boni (both attack rating and damage%) to the missile (it is in fact the only place that calculates the mastery boni when you use throw, the missile itself doesn't have duplicated damage%). I did a quick run through of the missile creation (sksrvst -> sksrvdo -> missileinit -> sksrvdo -> missilesrvdo -> damageapplicator) and I didn't find anything that seemed fishy.
I wish I could, but I don't even know where most of the functions are, what relevant structures actually look like, etc. Empirical evidence says +ED% from items is unaffected by this, so perhaps Throwing Mastery +ED% is getting added with item +ED%, wherever that piece of code is located.
D2TXT / D2INI - Python scripts for editing TXT files, or converting between TXT ↔ INI files

Return to “Code Editing”