Skip to content

Commit

Permalink
Fixed the return value of using_skill script function
Browse files Browse the repository at this point in the history
* if the arguments are not the player and SKILL_SNEAK, it returned
garbage values due to the uninitialized variable.
  • Loading branch information
NovaRain committed Jul 31, 2024
1 parent 130eb7d commit cfdb441
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sfall/Modules/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,19 @@ static __declspec(naked) void gmouse_handle_event_hook_use_inv() {
}
}

static __declspec(naked) void op_using_skill_hack() {
static const DWORD op_using_skill_Ret = 0x4546C4;
__asm {
mov dword ptr [esp + 0x28 - 0x1C + 4], 0; // initialize the value
cmp dword ptr [esp + 0x28 - 0x28 + 4], SKILL_SNEAK; // overwritten engine code
jne skip;
retn;
skip:
add esp, 4;
jmp op_using_skill_Ret;
}
}

void BugFixes::init() {
#ifndef NDEBUG
LoadGameHook::OnBeforeGameClose() += PrintAddrList;
Expand Down Expand Up @@ -4257,6 +4270,9 @@ void BugFixes::init() {
// Fix for clickability issue of the "Use Inventory Item On" action when the selected item overlaps an object
MakeCall(0x44BFB9, gmouse_handle_event_hack_use_inv, 2);
HookCall(0x44C6FB, gmouse_handle_event_hook_use_inv);

// 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);
}

}

0 comments on commit cfdb441

Please sign in to comment.