mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Changed hs_* hook script to be searched only once on game start
* in the same fashion as global scripts, affected by AlwaysFindScripts.
This commit is contained in:
+1
-1
@@ -832,7 +832,7 @@ DontDeleteProtos=0
|
||||
;Set to 1 to force sfall to inject all hooks code into the game, even if corresponding hook scripts don't exist
|
||||
InjectAllGameHooks=0
|
||||
|
||||
;Set to 1 to force sfall to search for global scripts every time the game loads rather than only once on the first game start
|
||||
;Set to 1 to force sfall to search for global/hook scripts every time the game loads rather than only the first time
|
||||
AlwaysFindScripts=0
|
||||
|
||||
;Set to 1 to force critters to display combat float messages
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
std::vector<HookFile> HookScripts::hookScriptFilesList;
|
||||
|
||||
typedef void(*HookInjectFunc)();
|
||||
struct HooksInjectInfo {
|
||||
int id;
|
||||
@@ -225,17 +227,27 @@ void RegisterHook(fo::Program* script, int id, int procNum, bool specReg) {
|
||||
static void HookScriptInit() {
|
||||
dlogr("Loading hook scripts:", DL_HOOK|DL_INIT);
|
||||
|
||||
InitCombatHookScripts();
|
||||
InitDeathHookScripts();
|
||||
InitHexBlockingHookScripts();
|
||||
InitInventoryHookScripts();
|
||||
InitObjectHookScripts();
|
||||
InitMiscHookScripts();
|
||||
static bool hooksFilesLoaded = false;
|
||||
if (!hooksFilesLoaded) { // hook files are already put in the list
|
||||
HookScripts::hookScriptFilesList.clear();
|
||||
|
||||
LoadHookScript("hs_keypress", HOOK_KEYPRESS);
|
||||
LoadHookScript("hs_mouseclick", HOOK_MOUSECLICK);
|
||||
LoadHookScript("hs_gamemodechange", HOOK_GAMEMODECHANGE);
|
||||
InitCombatHookScripts();
|
||||
InitDeathHookScripts();
|
||||
InitHexBlockingHookScripts();
|
||||
InitInventoryHookScripts();
|
||||
InitObjectHookScripts();
|
||||
InitMiscHookScripts();
|
||||
|
||||
LoadHookScript("hs_keypress", HOOK_KEYPRESS);
|
||||
LoadHookScript("hs_mouseclick", HOOK_MOUSECLICK);
|
||||
LoadHookScript("hs_gamemodechange", HOOK_GAMEMODECHANGE);
|
||||
|
||||
hooksFilesLoaded = !alwaysFindScripts;
|
||||
} else {
|
||||
for (auto& hook : HookScripts::hookScriptFilesList) {
|
||||
LoadHookScriptFile(hook.name, hook.id);
|
||||
}
|
||||
}
|
||||
dlogr("Finished loading hook scripts.", DL_HOOK|DL_INIT);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,12 +73,20 @@ enum HookType
|
||||
HOOK_COUNT
|
||||
};
|
||||
|
||||
struct HookFile {
|
||||
int id;
|
||||
// std::string filePath;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
class HookScripts : public Module {
|
||||
|
||||
public:
|
||||
const char* name() { return "HookScripts"; }
|
||||
void init();
|
||||
|
||||
static std::vector<HookFile> hookScriptFilesList;
|
||||
|
||||
static bool HookHasScript(int hookId);
|
||||
|
||||
static bool injectAllHooks;
|
||||
|
||||
@@ -31,11 +31,23 @@ DWORD cRetTmp; // how many return values were set by specific hook script (when
|
||||
|
||||
std::vector<HookScript> hooks[numHooks];
|
||||
|
||||
bool LoadHookScript(const char* name, int id) {
|
||||
if (id >= numHooks || IsGameScript(name)) return false;
|
||||
void LoadHookScript(const char* name, int id) {
|
||||
//if (id >= numHooks || IsGameScript(name)) return;
|
||||
|
||||
bool hookIsLoaded = LoadHookScriptFile(name, id);
|
||||
if (hookIsLoaded || (HookScripts::injectAllHooks && id != HOOK_SUBCOMBATDAMAGE)) {
|
||||
HookScripts::InjectingHook(id); // inject hook to engine code
|
||||
|
||||
if (!hookIsLoaded) return;
|
||||
HookFile hookFile = { id, name };
|
||||
HookScripts::hookScriptFilesList.push_back(hookFile);
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadHookScriptFile(const char* name, int id) {
|
||||
char filename[MAX_PATH];
|
||||
sprintf(filename, "scripts\\%s.int", name);
|
||||
|
||||
ScriptProgram prog;
|
||||
if (fo::func::db_access(filename)) {
|
||||
dlog("> ", DL_HOOK);
|
||||
@@ -53,11 +65,7 @@ bool LoadHookScript(const char* name, int id) {
|
||||
dlogr(" Error!", DL_HOOK);
|
||||
}
|
||||
}
|
||||
bool hookIsLoaded = (prog.ptr != nullptr);
|
||||
if (hookIsLoaded || (id != HOOK_SUBCOMBATDAMAGE && HookScripts::injectAllHooks)) {
|
||||
HookScripts::InjectingHook(id); // inject hook to engine code
|
||||
}
|
||||
return hookIsLoaded;
|
||||
return (prog.ptr != nullptr);
|
||||
}
|
||||
|
||||
// List of hooks that are not allowed to be called recursively
|
||||
|
||||
@@ -34,7 +34,9 @@ extern DWORD cArg; // how many arguments were taken by current hook script
|
||||
extern DWORD cRet; // how many return values were set by current hook script
|
||||
extern DWORD cRetTmp; // how many return values were set by specific hook script (when using register_hook)
|
||||
|
||||
bool LoadHookScript(const char* name, int id);
|
||||
void LoadHookScript(const char* name, int id);
|
||||
bool LoadHookScriptFile(const char* name, int id);
|
||||
|
||||
void __stdcall BeginHook();
|
||||
void __stdcall RunHookScript(DWORD hook);
|
||||
void __stdcall EndHook();
|
||||
|
||||
@@ -886,7 +886,7 @@ void ScriptExtender::init() {
|
||||
}
|
||||
|
||||
alwaysFindScripts = isDebug && (iniGetInt("Debugging", "AlwaysFindScripts", 0, ::sfall::ddrawIni) != 0);
|
||||
if (alwaysFindScripts) dlogr("Always searching for global scripts behavior enabled.", DL_SCRIPT);
|
||||
if (alwaysFindScripts) dlogr("Always searching for global/hook scripts behavior enabled.", DL_SCRIPT);
|
||||
|
||||
MakeJump(0x4A390C, FindSidHack); // scr_find_sid_from_program_
|
||||
MakeJump(0x4A5E34, ScrPtrHack);
|
||||
|
||||
Reference in New Issue
Block a user