From a10196e2ca30028868e93270ca91c940b3029829 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 29 Oct 2018 11:04:51 +0800 Subject: [PATCH] Corrected the key overriding mechanism and removed unused vKey argument from KeyPressedDelegate (from Mr.Stalin) Changed the debug editor to require sfall debugging mode. Some minor code edits. --- artifacts/ddraw.ini | 7 ++++--- sfall/InputFuncs.cpp | 9 +++++---- sfall/InputFuncs.h | 2 +- sfall/Modules/BugFixes.cpp | 3 +-- sfall/Modules/DebugEditor.cpp | 5 +++-- sfall/Modules/HeroAppearance.cpp | 16 +--------------- sfall/Modules/HookScripts.cpp | 3 +-- sfall/Modules/HookScripts.h | 1 + sfall/Modules/HookScripts/Common.cpp | 9 ++++----- sfall/Modules/Inventory.cpp | 9 +++------ 10 files changed, 24 insertions(+), 40 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 83f84975..c0c96053 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -148,8 +148,9 @@ ItemFastMoveKey=29 ;Requires ItemFastMoveKey to be enabled FastMoveFromContainer=0 -;A key to press to open a debug game editor (requires FalloutClient.exe from the modders pack) +;A key to press to open a debug game editor ;Set to 0 to disable, or a DX scancode otherwise +;Requires FalloutClient.exe from the modders pack and sfall debugging mode DebugEditorKey=0 ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX @@ -685,12 +686,12 @@ DebugMode=0 SkipCompatModeCheck=0 ;Set to 1 to skip the executable file size check -;Does not require enabling sfall debugging mode +;Does not require sfall debugging mode SkipSizeCheck=0 ;If you're testing changes to the Fallout exe, you can override the CRC that sfall looks for here ;You can use several hex values, separated by commas -;Does not require enabling sfall debugging mode +;Does not require sfall debugging mode ;ExtraCRC=0x00000000,0x00000000 ;Set to 1 to stop Fallout from deleting non readonly protos at startup diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index 50fd842e..40acfa83 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -25,10 +25,11 @@ #include "Logging.h" #include "FalloutEngine\Fallout2.h" #include "Modules\Graphics.h" +#include "Modules\HookScripts.h" #include "InputFuncs.h" -namespace sfall +namespace sfall { bool useScrollWheel = true; @@ -111,7 +112,7 @@ DWORD _stdcall KeyDown(DWORD key) { return 0; } else { DWORD keyVK = 0; - if (keysDown[key]) { // confirm pressed state + if (keysDown[key]) { // confirm pressed state keyVK = MapVirtualKeyEx(key, MAPVK_VSC_TO_VK, keyboardLayout); if (keyVK) keysDown[key] = (GetAsyncKeyState(keyVK) & 0x8000); } @@ -276,10 +277,10 @@ public: for (DWORD i = 0; i < *c; i++) { DWORD dxKey = b[i].dwOfs; DWORD state = b[i].dwData & 0x80; - - onKeyPressed.invoke(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); + HookScripts::KeyPressHook(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); if (dxKey != b[i].dwOfs && dxKey > 0) b[i].dwOfs = dxKey; // Override key keysDown[b[i].dwOfs] = state; + onKeyPressed.invoke(b[i].dwOfs, (state > 0)); } return hr; } diff --git a/sfall/InputFuncs.h b/sfall/InputFuncs.h index 9470ca50..893e0b0c 100644 --- a/sfall/InputFuncs.h +++ b/sfall/InputFuncs.h @@ -34,7 +34,7 @@ void SetMPos(int x, int y); DWORD _stdcall KeyDown(DWORD key); void _stdcall TapKey(DWORD key); -typedef Delegate KeyPressedDelegate; +typedef Delegate KeyPressedDelegate; typedef Delegate MouseClickedDelegate; KeyPressedDelegate& OnKeyPressed(); diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 009f4638..521478cb 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -1824,8 +1824,7 @@ void BugFixes::init() //if (GetConfigInt("Misc", "MultiHexPathingFix", 1)) { dlog("Applying MultiHex Pathing Fix.", DL_INIT); - MakeCall(0x42901F, MultiHexFix); - MakeCall(0x429170, MultiHexFix); + MakeCalls(MultiHexFix, {0x42901F, 0x429170}); // Fix for multihex critters moving too close and overlapping their targets in combat MakeCall(0x42A14F, MultiHexCombatRunFix); SafeWrite8(0x42A154, 0x90); diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index b988657f..a1556df5 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -241,10 +241,11 @@ void RunDebugEditor() { static DWORD debugEditorKey = 0; void DebugEditor::init() { + if (!isDebug) return; debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0); if (debugEditorKey != 0) { - OnKeyPressed() += [](DWORD* scanCode, bool pressed, DWORD vkCode) { - if (*scanCode == debugEditorKey && pressed && IsMapLoaded()) { + OnKeyPressed() += [](DWORD scanCode, bool pressed) { + if (scanCode == debugEditorKey && pressed && IsMapLoaded()) { RunDebugEditor(); } }; diff --git a/sfall/Modules/HeroAppearance.cpp b/sfall/Modules/HeroAppearance.cpp index d2c35300..87cd9f94 100644 --- a/sfall/Modules/HeroAppearance.cpp +++ b/sfall/Modules/HeroAppearance.cpp @@ -264,21 +264,7 @@ int CheckFile(char*FileName, DWORD *size_out) { //----------------------------------------- char _stdcall GetSex(void) { - using fo::STAT_gender; - char sex; - __asm { - mov edx, STAT_gender //sex stat ref - mov eax, dword ptr ds:[FO_VAR_obj_dude] //hero state structure - call fo::funcoffs::stat_level_ //get Player stat val - test eax, eax //male=0, female=1 - jne Female - mov sex, 'M' - jmp EndFunc -Female: - mov sex, 'F' -EndFunc: - } - return sex; + return (fo::HeroIsFemale()) ? 'F' : 'M'; } // functions to load and save appearance globals diff --git a/sfall/Modules/HookScripts.cpp b/sfall/Modules/HookScripts.cpp index 9c2fcdfe..bb722465 100644 --- a/sfall/Modules/HookScripts.cpp +++ b/sfall/Modules/HookScripts.cpp @@ -87,7 +87,7 @@ DWORD initingHookScripts; // BEGIN HOOKS -void _stdcall KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey) { +void HookScripts::KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey) { if (!IsMapLoaded()) { return; } @@ -226,7 +226,6 @@ void _stdcall RunHookScriptsAtProc(DWORD procId) { } void HookScripts::init() { - OnKeyPressed() += KeyPressHook; OnMouseClick() += MouseClickHook; LoadGameHook::OnGameModeChange() += GameModeChangeHook; LoadGameHook::OnAfterGameStarted() += SourceUseSkillOnInit; diff --git a/sfall/Modules/HookScripts.h b/sfall/Modules/HookScripts.h index dd841a9e..4ecf1a07 100644 --- a/sfall/Modules/HookScripts.h +++ b/sfall/Modules/HookScripts.h @@ -76,6 +76,7 @@ public: static bool injectAllHooks; static void GameModeChangeHook(DWORD exit); + static void KeyPressHook(DWORD* dxKey, bool pressed, DWORD vKey); }; DWORD _stdcall GetHSArgCount(); diff --git a/sfall/Modules/HookScripts/Common.cpp b/sfall/Modules/HookScripts/Common.cpp index d86ea686..6ad984cf 100644 --- a/sfall/Modules/HookScripts/Common.cpp +++ b/sfall/Modules/HookScripts/Common.cpp @@ -25,12 +25,12 @@ DWORD cRetTmp; // how many return values were set by specific hook script (when std::vector hooks[numHooks]; void LoadHookScript(const char* name, int id) { - if (id >= numHooks) return; + if (id >= numHooks || IsGameScript(name)) return; char filename[MAX_PATH]; sprintf(filename, "scripts\\%s.int", name); - if (fo::func::db_access(filename) && !IsGameScript(name)) { - ScriptProgram prog; + ScriptProgram prog; + if (fo::func::db_access(filename)) { dlog(">", DL_HOOK); dlog(name, DL_HOOK); LoadScriptProgram(prog, name); @@ -42,12 +42,11 @@ void LoadHookScript(const char* name, int id) { hook.isGlobalScript = false; hooks[id].push_back(hook); AddProgramToMap(prog); - if (!HookScripts::injectAllHooks) HookScripts::InjectingHook(id); // inject hook to engine code } else { dlogr(" Error!", DL_HOOK); } } - if (HookScripts::injectAllHooks) HookScripts::InjectingHook(id); + if (HookScripts::injectAllHooks || prog.ptr != nullptr) HookScripts::InjectingHook(id); // inject hook to engine code } void _stdcall BeginHook() { diff --git a/sfall/Modules/Inventory.cpp b/sfall/Modules/Inventory.cpp index 219aea21..ea6f61ee 100644 --- a/sfall/Modules/Inventory.cpp +++ b/sfall/Modules/Inventory.cpp @@ -38,9 +38,9 @@ static DWORD reloadWeaponKey = 0; static DWORD itemFastMoveKey = 0; static DWORD skipFromContainer = 0; -void InventoryKeyPressedHook(DWORD* dxKey, bool pressed, DWORD vKey) { +void InventoryKeyPressedHook(DWORD dxKey, bool pressed) { // TODO: move this out into a script - if (pressed && reloadWeaponKey && *dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) { + if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) { DWORD maxAmmo, curAmmo; fo::GameObject* item = fo::GetActiveItem(); maxAmmo = fo::func::item_w_max_ammo(item); @@ -87,7 +87,6 @@ DWORD __stdcall sf_item_total_size(fo::GameObject* critter) { /*static const DWORD ObjPickupFail=0x49B70D; static const DWORD ObjPickupEnd=0x49B6F8; -static const DWORD size_limit; static __declspec(naked) void ObjPickupHook() { __asm { cmp edi, ds:[FO_VAR_obj_dude]; @@ -836,7 +835,7 @@ void Inventory::init() { // Move items out of bag/backpack and back into the main inventory list by dragging them to character's image // (similar to Fallout 1 behavior) - HookCall(0x471457, &inven_pickup_hook); + HookCall(0x471457, inven_pickup_hook); // Move items to player's main inventory instead of the opened bag/backpack when confirming a trade SafeWrite32(0x475CF2, FO_VAR_stack); @@ -853,6 +852,4 @@ Delegate& Inventory::OnAdjustFid() { return onAdjustFid; } - - }