Skip to content

Commit

Permalink
Fixed object_fix_weapon_ammo_ engine function
Browse files Browse the repository at this point in the history
(was incorrectly checking Misc "object" type instead of item subtype.)
  • Loading branch information
NovaRain committed Aug 14, 2024
1 parent 02a25a0 commit c62aa26
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sfall/Modules/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4273,6 +4273,10 @@ void BugFixes::init() {

// Fix for using_skill function returning garbage values when the arguments are not the player and SKILL_SNEAK
MakeCall(0x4546A5, op_using_skill_hack, 1);

// Fix for object_fix_weapon_ammo_ engine function not checking "misc" type items
SafeWrite8(0x48916B, 0x41); // jnz 0x4891AD
SafeWrite8(0x4891C8, CodeType::JumpShort); // jmp 0x4891E9 (skip proto data correction)
}

}

4 comments on commit c62aa26

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit basically changes the code:
https://github.com/alexbatalov/fallout2-re/blob/main/src/game/object.c#L626
to:

if (item_get_type(obj) == ITEM_TYPE_MISC) {
    charges = obj->data.item.misc.charges;
    if (charges == 0xCCCCCCCC || charges != proto->item.data.misc.charges) {
        obj->data.item.misc.charges = proto->item.data.misc.charges;
    }
}

@phobos2077
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice in theory, but have you tested this fix?

See the condition of the only branch where it gets called:

 if (obj->pid < 0x5000010 || obj->pid > 0x5000017) {
        if (PID_TYPE(obj->pid) == 0 && !(map_data.flags & 0x01)) {
            object_fix_weapon_ammo(obj);
        }
    }

@phobos2077
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming map_data.flags & 0x01 is only true for save game maps? So this correction only happens on initial map load?

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have tested the fix for misc items. It's only called on first map enter.

Please sign in to comment.