Backported HOOK_GAMEMODECHANGE from 4.2

Backported SPECIAL game mode flag from 4.2
This commit is contained in:
NovaRain
2021-01-10 21:45:50 +08:00
parent e075c05a3f
commit cf90437b71
8 changed files with 209 additions and 85 deletions
+2
View File
@@ -22,6 +22,7 @@
#define HEROWIN (0x40000)
#define DIALOGVIEW (0x80000)
#define COUNTERWIN (0x100000) // counter window for moving multiple items or setting a timer
#define SPECIAL (0x80000000)
//Valid arguments to register_hook
#define HOOK_TOHIT (0)
@@ -50,6 +51,7 @@
#define HOOK_WITHINPERCEPTION (23)
#define HOOK_INVENTORYMOVE (24)
#define HOOK_INVENWIELD (25)
#define HOOK_GAMEMODECHANGE (31)
//Valid arguments to list_begin
#define LIST_CRITTERS (0)
+9
View File
@@ -462,3 +462,12 @@ int arg3 - 1 when wielding, 0 when unwielding
int arg4 - 1 when removing an equipped item from inventory, 0 otherwise
int ret0 - overrides hard-coded handler (-1 - use engine handler, any other value - override) - NOT RECOMMENDED
-------------------------------------------
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 arg0 - event type: 1 - when the player exits the game, 0 - otherwise
int arg1 - the previous game mode
+3
View File
@@ -434,6 +434,8 @@ const DWORD game_time_date_ = 0x4A3338;
const DWORD gdDestroyHeadWindow_ = 0x447294;
const DWORD gdialog_barter_cleanup_tables_ = 0x448660;
const DWORD gdialog_barter_pressed_ = 0x44A52C;
const DWORD gdialog_window_create_ = 0x44A62C;
const DWORD gdialog_window_destroy_ = 0x44A9D8;
const DWORD gdialogActive_ = 0x444D2C;
const DWORD gdialogDisplayMsg_ = 0x445448;
const DWORD gdialogFreeSpeech_ = 0x4450C4;
@@ -573,6 +575,7 @@ const DWORD make_straight_path_ = 0x4163AC;
const DWORD make_straight_path_func_ = 0x4163C8;
const DWORD map_disable_bk_processes_ = 0x482104;
const DWORD map_enable_bk_processes_ = 0x4820C0;
const DWORD map_exit_ = 0x482084;
const DWORD map_get_short_name_ = 0x48261C;
const DWORD map_load_idx_ = 0x482B34;
const DWORD MapDirErase_ = 0x480040;
+3
View File
@@ -722,6 +722,8 @@ extern const DWORD game_time_date_;
extern const DWORD gdDestroyHeadWindow_;
extern const DWORD gdialog_barter_cleanup_tables_;
extern const DWORD gdialog_barter_pressed_;
extern const DWORD gdialog_window_create_;
extern const DWORD gdialog_window_destroy_;
extern const DWORD gdialogActive_;
extern const DWORD gdialogDisplayMsg_;
extern const DWORD gdialogFreeSpeech_;
@@ -867,6 +869,7 @@ extern const DWORD make_straight_path_;
extern const DWORD make_straight_path_func_; // (TGameObj *aObj<eax>, int aTileFrom<edx>, int a3<ecx>, signed int aTileTo<ebx>, TGameObj **aObjResult, int a5, int (*a6)(void))
extern const DWORD map_disable_bk_processes_;
extern const DWORD map_enable_bk_processes_;
extern const DWORD map_exit_;
extern const DWORD map_get_short_name_;
extern const DWORD map_load_idx_;
extern const DWORD MapDirErase_;
+22 -2
View File
@@ -1585,8 +1585,26 @@ long __stdcall CorrectFidForRemovedItem_wHook(TGameObj* critter, TGameObj* item,
if (result) CorrectFidForRemovedItem(critter, item, flags);
return result;
}
// 4.x backport
static unsigned long previousGameMode = 0;
void __stdcall GameModeChangeHook(DWORD exit) {
BeginHook();
argCount = 2;
args[0] = exit;
args[1] = previousGameMode;
RunHookScript(HOOK_GAMEMODECHANGE);
EndHook();
previousGameMode = GetLoopFlags();
}
// END HOOKS
static void HookCommon_Reset() {
previousGameMode = 0;
}
DWORD __stdcall GetHSArgCount() {
return argCount;
}
@@ -1617,7 +1635,7 @@ void __stdcall SetHSReturn(DWORD value) {
}
void __stdcall RegisterHook(TProgram* script, int id, int procNum, bool specReg) {
if (id >= numHooks) return;
if (id >= numHooks || (id > HOOK_INVENWIELD && id < HOOK_GAMEMODECHANGE)) return;
for (std::vector<sHookScript>::iterator it = hooks[id].begin(); it != hooks[id].end(); ++it) {
if (it->prog.ptr == script) {
if (procNum == 0) hooks[id].erase(it); // unregister
@@ -1855,6 +1873,8 @@ static void HookScriptInit() {
HookCall(0x45C4F6, op_move_obj_inven_to_obj_hook);
MakeCall(0x4778AF, item_drop_all_hack, 3);
LoadHookScript("hs_gamemodechange", HOOK_GAMEMODECHANGE);
DbFreeFileList(&filenames, 0);
dlogr("Finished loading hook scripts.", DL_HOOK|DL_INIT);
@@ -1865,6 +1885,7 @@ void HookScriptClear() {
hooks[i].clear();
}
std::memset(hooksInfo, 0, numHooks * sizeof(HooksPositionInfo));
HookCommon_Reset();
}
void LoadHookScripts() {
@@ -1889,4 +1910,3 @@ void __stdcall RunHookScriptsAtProc(DWORD procId) {
}
}
}
+2
View File
@@ -46,6 +46,7 @@ enum HookType
HOOK_WITHINPERCEPTION = 23,
HOOK_INVENTORYMOVE = 24,
HOOK_INVENWIELD = 25,
HOOK_GAMEMODECHANGE = 31, // 4.x backport
HOOK_COUNT
};
@@ -67,6 +68,7 @@ extern DWORD initingHookScripts;
int __fastcall AmmoCostHook_Script(DWORD hookType, TGameObj* weapon, DWORD &rounds);
void __stdcall RunHookScriptsAtProc(DWORD procId);
void __stdcall GameModeChangeHook(DWORD exit);
void __stdcall KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey);
void __stdcall MouseClickHook(DWORD button, bool pressed);
+167 -82
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -54,7 +54,7 @@ enum LoopFlag : unsigned long {
DIALOGVIEW = 1 << 19, // 0x80000
COUNTERWIN = 1 << 20, // 0x100000 Counter window for moving multiple items or setting a timer
// SPECIAL = 1UL << 31 // 0x80000000 Additional special flag for all modes
SPECIAL = 1UL << 31 // 0x80000000 Additional special flag for all modes
};
DWORD GetLoopFlags();