MercEquip Strange Code

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
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

MercEquip Strange Code

Post by devurandom » Sun Sep 03, 2017 9:33 am

Hi,

I rewrote the function D2MercEquip

[1.13c] - D2Game.6FCF05B0
[1.10] - D2Game.6FC88B20

I noticed what looks like goto labels inside the switch statement.
The switch uses a lot of code like:

case XYZ:
{
if(ConditionTrue)
break;
else
goto case default;
}

Its not spaghetti code, since each case is linear, but goto is considered bad coding practice.
Anyone know another way to replicate this switch compiled code in assembly without goto labels?

Maybe I missed something, I don't know any other way to replicate the code.

:-|
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
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: MercEquip Strange Code

Post by Necrolis » Sun Sep 03, 2017 11:17 am

use an inline function, but if its the default case, it might not be a default label, just code after the switch.
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
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: MercEquip Strange Code

Post by devurandom » Sun Sep 03, 2017 12:21 pm

Its labeled as default case, but I'll try using inline function to jump to default code.
Excellent suggestion!

Thanks!

Code: Select all

6FC88BCE    3D 67010000   CMP EAX,167                              ; Switch (cases 10F..231, 6 exits)
6FC88BD3    77 58         JA SHORT 6FC88C2D
6FC88BD5    74 32         JE SHORT 6FC88C09
6FC88BD7    2D 0F010000   SUB EAX,10F
6FC88BDC    74 27         JZ SHORT 6FC88C05
6FC88BDE    83E8 43       SUB EAX,43
6FC88BE1    0F85 88000000 JNZ 6FC88C6F
6FC88BE7    6A 21         PUSH 21                                  ; /Arg2 = 21, case 152 of switch D2Game.6FC88BCE
6FC88BE9    56            PUSH ESI                                 ; |Arg1
6FC88BEA    E8 DD2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88BEF    85C0          TEST EAX,EAX
6FC88BF1    0F85 80000000 JNZ 6FC88C77
6FC88BF7    6A 22         PUSH 22                                  ; /Arg2 = 22
6FC88BF9    56            PUSH ESI                                 ; |Arg1
6FC88BFA    E8 CD2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88BFF    85C0          TEST EAX,EAX
6FC88C01    74 6C         JZ SHORT 6FC88C6F
6FC88C03    EB 72         JMP SHORT 6FC88C77
6FC88C05    6A 1B         PUSH 1B                                  ; Case 10F of switch D2Game.6FC88BCE
6FC88C07    EB 5C         JMP SHORT 6FC88C65
6FC88C09    6A 02         PUSH 2                                   ; /Arg2 = 2, case 167 of switch D2Game.6FC88BCE
6FC88C0B    56            PUSH ESI                                 ; |Arg1
6FC88C0C    E8 BB2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88C11    85C0          TEST EAX,EAX
6FC88C13    75 62         JNZ SHORT 6FC88C77
6FC88C15    6A 1E         PUSH 1E                                  ; /Arg2 = 1E
6FC88C17    56            PUSH ESI                                 ; |Arg1
6FC88C18    E8 AF2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88C1D    85C0          TEST EAX,EAX
6FC88C1F    74 4E         JZ SHORT 6FC88C6F
6FC88C21    56            PUSH ESI                                 ; /Arg1
6FC88C22    E8 5F2D0900   CALL <JMP.&D2Common.#10765>              ; \D2Common.#10765
6FC88C27    85C0          TEST EAX,EAX
6FC88C29    74 4C         JZ SHORT 6FC88C77
6FC88C2B    EB 42         JMP SHORT 6FC88C6F
6FC88C2D    2D 30020000   SUB EAX,230
6FC88C32    74 11         JZ SHORT 6FC88C45
6FC88C34    48            DEC EAX
6FC88C35    75 38         JNZ SHORT 6FC88C6F
6FC88C37    6A 1E         PUSH 1E                                  ; /Arg2 = 1E, case 231 of switch D2Game.6FC88BCE
6FC88C39    56            PUSH ESI                                 ; |Arg1
6FC88C3A    E8 8D2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88C3F    85C0          TEST EAX,EAX
6FC88C41    74 20         JZ SHORT 6FC88C63
6FC88C43    EB 16         JMP SHORT 6FC88C5B
6FC88C45    6A 1C         PUSH 1C                                  ; /Arg2 = 1C, case 230 of switch D2Game.6FC88BCE
6FC88C47    56            PUSH ESI                                 ; |Arg1
6FC88C48    E8 7F2C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88C4D    85C0          TEST EAX,EAX
6FC88C4F    74 12         JZ SHORT 6FC88C63
6FC88C51    56            PUSH ESI                                 ; /Arg1
6FC88C52    E8 2F2D0900   CALL <JMP.&D2Common.#10765>              ; \D2Common.#10765
6FC88C57    85C0          TEST EAX,EAX
6FC88C59    75 08         JNZ SHORT 6FC88C63
6FC88C5B    C74424 18 010 MOV DWORD PTR SS:[ARG.2],1
6FC88C63    6A 47         PUSH 47
6FC88C65    56            PUSH ESI                                 ; |Arg1
6FC88C66    E8 612C0900   CALL <JMP.&D2Common.#10731>              ; \D2Common.#10731
6FC88C6B    85C0          TEST EAX,EAX
6FC88C6D    75 08         JNZ SHORT 6FC88C77
6FC88C6F    8B4424 18     MOV EAX,DWORD PTR SS:[ARG.2]             ; Default case of switch D2Game.6FC88BCE
6FC88C73    85C0          TEST EAX,EAX
6FC88C75    74 4B         JZ SHORT 6FC88CC2
6FC88C77    6A 00         PUSH 0                                   ; /Arg6 = 0
6FC88C79    6A 00         PUSH 0                                   ; |Arg5 = 0
6FC88C7B    6A 00         PUSH 0                                   ; |Arg4 = 0
6FC88C7D    6A 00         PUSH 0                                   ; |Arg3 = 0
6FC88C7F    57            PUSH EDI                                 ; |Arg2
6FC88C80    56            PUSH ESI                                 ; |Arg1
6FC88C81    E8 E22C0900   CALL <JMP.&D2Common.#10756>              ; \D2Common.#10756
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..

Return to “Code Editing”