diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index 44d6033e..f3e6083a 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -497,7 +497,7 @@ int arg2 - event type: 1 - when the resting ends normally, -1 - when pressin int arg3 - the hour part of the length of resting time int arg4 - the minute part of the length of resting time -int ret1 - pass 1 to interrupt the resting +int ret1 - pass 1 to interrupt the resting, or pass 0 to continue the rest if it was interrupted by the player using the Esc key. ------------------------------------------- @@ -506,3 +506,16 @@ HOOK_GAMEMODECHANGE (hs_gamemodechange.int) Runs once every time when the game mode was changed, like opening/closing the inventory, character screen, pipboy, etc. int arg1 - event type: 1 - when the player exits the game, 0 - otherwise + +------------------------------------------- + +HOOK_USEOBJECTMAP (hs_useobjectmap.int) + +Runs before the uses animation the map object (or walking/running animation if the player is at a distance from the object). +Hook allows to override the usage animation. + +Critter arg1 - critter that uses an object (usually dude_obj) +Obj arg2 - the map object that is used +int arg3 - animation code (see define.h) + +int ret1 - pass the animation code to override the animation, or pass -1 to skip the usage animation diff --git a/sfall/Modules/HookScripts.cpp b/sfall/Modules/HookScripts.cpp index 3f2846dd..39caa918 100644 --- a/sfall/Modules/HookScripts.cpp +++ b/sfall/Modules/HookScripts.cpp @@ -27,6 +27,7 @@ #include "HookScripts\DeathHs.h" #include "HookScripts\HexBlockingHs.h" #include "HookScripts\InventoryHs.h" +#include "HookScripts\ObjectHs.h" #include "HookScripts\MiscHs.h" #include "LoadGameHook.h" @@ -75,9 +76,10 @@ static HooksInjectInfo injectHooks[] = { {HOOK_SETGLOBALVAR, Inject_SetGlobalVarHook, false}, {HOOK_RESTTIMER, Inject_RestTimerHook, false}, {HOOK_GAMEMODECHANGE, nullptr, true}, // always embedded to the engine + {HOOK_USEOBJECTMAP, Inject_UseObjectMapHook, false}, }; -bool injectAllHooks; +bool HookScripts::injectAllHooks; DWORD initingHookScripts; // BEGIN HOOKS @@ -177,6 +179,7 @@ static void HookScriptInit() { InitDeathHookScripts(); InitHexBlockingHookScripts(); InitInventoryHookScripts(); + InitObjectHookScripts(); InitMiscHookScripts(); LoadHookScript("hs_keypress", HOOK_KEYPRESS); @@ -219,7 +222,7 @@ void HookScripts::init() { OnMouseClick() += MouseClickHook; LoadGameHook::OnGameModeChange() += GameModeChangeHook; - injectAllHooks = (isDebug && (GetConfigInt("Debugging", "InjectingAllGameHooks", 0) != 0)); + HookScripts::injectAllHooks = (isDebug && (GetConfigInt("Debugging", "InjectingAllGameHooks", 0) != 0)); } } diff --git a/sfall/Modules/HookScripts.h b/sfall/Modules/HookScripts.h index 23ba85b4..cf7c903a 100644 --- a/sfall/Modules/HookScripts.h +++ b/sfall/Modules/HookScripts.h @@ -58,15 +58,18 @@ enum HookType HOOK_SETGLOBALVAR = 29, HOOK_RESTTIMER = 30, HOOK_GAMEMODECHANGE = 31, + HOOK_USEOBJECTMAP = 32, HOOK_COUNT }; class HookScripts : public Module { + public: const char* name() { return "HookScripts"; } void init(); static void InjectingHook(int hookId); + static bool injectAllHooks; }; DWORD _stdcall GetHSArgCount(); @@ -81,7 +84,6 @@ void _stdcall RegisterHook(fo::Program* script, int id, int procNum); void HookScriptClear(); void LoadHookScripts(); -extern bool injectAllHooks; extern DWORD initingHookScripts; extern void __declspec() AmmoCostHookWrapper(); void _stdcall RunHookScriptsAtProc(DWORD procId); diff --git a/sfall/Modules/HookScripts/Common.cpp b/sfall/Modules/HookScripts/Common.cpp index 74382e78..d86ea686 100644 --- a/sfall/Modules/HookScripts/Common.cpp +++ b/sfall/Modules/HookScripts/Common.cpp @@ -42,12 +42,12 @@ void LoadHookScript(const char* name, int id) { hook.isGlobalScript = false; hooks[id].push_back(hook); AddProgramToMap(prog); - if (!injectAllHooks) HookScripts::InjectingHook(id); // inject hook to engine code + if (!HookScripts::injectAllHooks) HookScripts::InjectingHook(id); // inject hook to engine code } else { dlogr(" Error!", DL_HOOK); } } - if (injectAllHooks) HookScripts::InjectingHook(id); + if (HookScripts::injectAllHooks) HookScripts::InjectingHook(id); } void _stdcall BeginHook() { diff --git a/sfall/Modules/HookScripts/ObjectHs.cpp b/sfall/Modules/HookScripts/ObjectHs.cpp new file mode 100644 index 00000000..8624f34a --- /dev/null +++ b/sfall/Modules/HookScripts/ObjectHs.cpp @@ -0,0 +1,58 @@ +#include "..\..\FalloutEngine\Fallout2.h" +#include "..\..\SafeWrite.h" +#include "..\HookScripts.h" +#include "Common.h" + +#include "ObjectHs.h" + +// Object hook scripts +namespace sfall +{ + +// Before animation of using map object +static void __declspec(naked) UseObjectMapHook() { + __asm { + mov args[0], eax; // source critter + mov args[8], edx; // anim code + // + cmp dword ptr [esp], 0x412292 + 5; + jne contr; + mov args[4], ebp; // map object + jmp next; +contr: + mov args[4], edi; +next: + pushad; + } + + BeginHook(); + argCount = 3; + RunHookScript(HOOK_USEOBJECTMAP); + EndHook(); + + if (cRet > 0 && static_cast(rets[0]) > 64) cRet = 0; + + __asm { + popad; + cmp cRet, 0; + jle skip; + cmp rets[0], -1; + jle end; + mov edx, rets[0]; +skip: + call fo::funcoffs::register_object_animate_; +end: + retn; + } +} + +void Inject_UseObjectMapHook() { + HookCalls(UseObjectMapHook, { 0x4120C1, 0x412292 }); +} + +void InitObjectHookScripts() { + + LoadHookScript("hs_useobjectmap", HOOK_USEOBJECTMAP); +} + +} diff --git a/sfall/Modules/HookScripts/ObjectHs.h b/sfall/Modules/HookScripts/ObjectHs.h new file mode 100644 index 00000000..d908cc5a --- /dev/null +++ b/sfall/Modules/HookScripts/ObjectHs.h @@ -0,0 +1,8 @@ +#pragma once + +namespace sfall +{ + void InitObjectHookScripts(); + + void Inject_UseObjectMapHook(); +} diff --git a/sfall/ddraw.vcxproj b/sfall/ddraw.vcxproj index bc8641c4..2eaed0f3 100644 --- a/sfall/ddraw.vcxproj +++ b/sfall/ddraw.vcxproj @@ -228,6 +228,7 @@ + @@ -314,6 +315,7 @@ + diff --git a/sfall/ddraw.vcxproj.filters b/sfall/ddraw.vcxproj.filters index c3f1fdda..2d92ffaa 100644 --- a/sfall/ddraw.vcxproj.filters +++ b/sfall/ddraw.vcxproj.filters @@ -269,6 +269,9 @@ Modules\HookScripts + + Modules\HookScripts + @@ -498,6 +501,9 @@ Modules\HookScripts + + Modules\HookScripts +