sfall-team / sfall

sfall - Engine modifications for Fallout 2
https://sfall-team.github.io/sfall/
GNU General Public License v3.0
348 stars 41 forks source link

Broken fix code. #420

Closed FakelsHub closed 2 years ago

FakelsHub commented 2 years ago
static void __declspec(naked) partyMemberIncLevels_hook() {
    __asm {
        mov  ebx, eax;                            // party member pointer
        call fo::funcoffs::partyMemberCopyLevelInfo_;
        cmp  eax, -1;
        je   end;
        xor  edx, edx;                            // queue type (0)
        mov  eax, ebx;                            // source
        call fo::funcoffs::queue_remove_this_;
        push ecx;
        push edi;
        push esi;
        mov  ecx, 8;
        mov  edi, FO_VAR_drugInfoList;
        mov  esi, ebx;                            // pointer for fixed item_d_check_addict_
loopAddict:
        mov  eax, dword ptr [edi];                // eax = drug pid
        call fo::funcoffs::item_d_check_addict_;
        test eax, eax;                            // Has addiction?
        jz   noAddict;                            // No
        cmp  dword ptr [eax], 0;                  // queue_addict.wait
        jne  noAddict;                            // Addiction is not active yet
        mov  edx, dword ptr [eax + 0x8];          // queue_addict.perk
        mov  eax, ebx;
        call fo::funcoffs::perk_add_effect_;
noAddict:
        lea  edi, [edi + 12];
        dec  ecx;
        jnz  loopAddict;
        pop  esi;
        pop  edi;
        pop  ecx;
end:
        retn;
    }
}

I can't understand this damn fix (it wasn't written by me) the code is completely broken. how could it have worked for so many years....

here's more: mov esi, ebx; // pointer for fixed item_d_check_addict_ this line I added completely confused me, "pointer for fixed item_d_checkaddict" - wtf? I don't find any fixed item_d_checkaddict

NovaRain commented 2 years ago

The fix itself was from Crafty, and the comment was from you: https://github.com/FakelsHub/sFall-Extended/commit/dcc5e990ddf0207ceae8f8f70b728edb5553a72f#diff-111ceceb96df51469a36c1c3895b701832afad611ce7c3fecb05e809cc141defR340

FakelsHub commented 2 years ago

I know that I added this line. but I also can't understand why the fuck I added it there)))

FakelsHub commented 2 years ago

it seems that some fix for item_d_checkaddict has been removed... ? 8-|