-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrote GetManaAmount to result in the same decompiled code as Diablo #135
Conversation
…iginal function. Fixed the type of `PlayerStruct->pClass`. Thank you @galaxyhaxz for all the help getting into it :)
Hi @seritools! Looks great. Lovely to see that you added the original names also for the local variables 😈 I can confirm that the decompiled code (as output by IDA Hex-Rays) is indeed identical. The assembly is not exactly identical (e.g. different registers used, see below), but that's fine for now. I do believe that the original source code did not use shift operations for multiplication and division (e.g. So, we can merge this PR as is now, and then once we figure out the right compiler flags, we can update the code to use division and multiplication instead. +1 to merge from me. @galaxyhaxz, feel free to merge if you second. - if (spelldata[sn].sMinMana > ma >> 6 )
- ma = spelldata[sn].sMinMana << 6;
+ if (spelldata[sn].sMinMana > ma / 64 )
+ ma = spelldata[sn].sMinMana * 64; Original .text:0045744E mov eax, ecx
.text:00457450 push esi
.text:00457451 imul eax, 54D8h
.text:00457457 push edi
.text:0045B36A mov eax, ecx
.text:0045B36C push ebx
.text:0045B36D imul eax, 54D8h
.text:0045B373 push ebp
.text:0045B374 push esi |
Yeah, the optimizer does some interesting things. I've tried changing if ( plr[id]._pClass == 1 )
ma -= ma >> 2; for example, but that resulted in slightly different code. I just realized that _pClass probably is 32bit and not an
Basically, these two seem to be equal for such enums: BOOL foo(player_class pClass) { return pClass = PCLASS_SORC; }
BOOL foo(int pClass) { return (_BYTE)pClass = PCLASS_SORC; } I found the same to be true for I'm gonna recheck that in this case. :) |
Alright, i just checked the case of Things that speak for it being originally something like
Things that speak for it being originally something like
So I guess everything is fine leaving it |
LGTM. Great first PR @seritools! |
Sorry about the wait, I've been really busy dealing with typical real-world stuff and haven't been around for a few days. The commit looks good, the only thing that needs to be changed is:
|
Don't worry. If anything, you've earned some time off! And, being a hobby project you should invest time when you feel like and balance it with other things in life. I think anyone in the community would understand. To better distribute the work, I'd recommend inviting @seritools as a collaborator on the project too :) |
Fixed the type of
PlayerStruct->pClass
while being at it. Thank you @galaxyhaxz for all the help getting into it :)