From ffe9d4c8cf43c0e2cdb753a818638300a872d0c9 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 14 Sep 2019 08:50:54 +0800 Subject: [PATCH] Removed duplicate code from intface_redraw_ engine function Minor edits to code/documents. --- .../example_mods/UIHotkeys/gl_uihotkeys.int | Bin 602 -> 594 bytes .../example_mods/UIHotkeys/gl_uihotkeys.ssl | 2 +- artifacts/scripting/hookscripts.txt | 2 +- sfall/InputFuncs.cpp | 32 +++++++++--------- sfall/Modules/BugFixes.cpp | 3 ++ sfall/Modules/ExtraSaveSlots.cpp | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/artifacts/example_mods/UIHotkeys/gl_uihotkeys.int b/artifacts/example_mods/UIHotkeys/gl_uihotkeys.int index f00771f4a86447db8fc47ff45cadcd5482e1f19e..492d08a23057c4aad666e6c78105d7f9d8b3dd9b 100644 GIT binary patch delta 95 zcmcb`a*1WaL0PK?mc}Os7#SEC7#a+rEXD>ykO-62#CxTTR+B>*Eg7vQ_c2;>S~ajh fBqm>AbeDwlKw=C`4MqnT8JHLt8XP8DFew25F{T)e delta 103 zcmcb_a*JicL0P8;mc}Os7#SEC7#a+rEXD>ykO-60#CxTTPLo3zEg79A_c2;>IyJCB jBqm>AbXSD)Kw=C`4MqnT8JHLtz&w@)%Le1g224r-2aFm% diff --git a/artifacts/example_mods/UIHotkeys/gl_uihotkeys.ssl b/artifacts/example_mods/UIHotkeys/gl_uihotkeys.ssl index 60336c17..8600570f 100644 --- a/artifacts/example_mods/UIHotkeys/gl_uihotkeys.ssl +++ b/artifacts/example_mods/UIHotkeys/gl_uihotkeys.ssl @@ -44,7 +44,7 @@ procedure start begin tap_key(DIK_CAPITAL); tap_key(DIK_A); tap_key(DIK_CAPITAL); - end else if (mode == (BARTER + DIALOG)) then begin + end else if (mode bwand BARTER) then begin tap_key(DIK_M); end end diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index 551a816e..c932355b 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -47,7 +47,7 @@ Used from a normal global script if you want to run it at the same point a full The same as register_hook, except that you specifically define which procedure in the current script should be called as a hook (instead of "start" by default). Pass procedure the same as how you use dialog option functions. This IS the recommended way to use hook scripts, as it gives both modularity (each mod logic in a separate global script, no conflicts if you don't use "hs_*.int" scripts) and flexibility (you can place all related hook scripts for specific mod in a single script!). > void register_hook_proc_spec(int hook, procedure proc) -Works very similar to register_hook_proc, except that it registers the current script at the end of the hook script execution chain (i.e. the script will be executed after all previously registered scripts for the same hook, including the hs_*.int script.) All scripts hooked to a single hook point with this function are executed in exact order of how they were registered, as opposed to the description below, which refers to using register_hook/register_hook_proc functions. +Works very similar to register_hook_proc, except that it registers the current script at the end of the hook script execution chain (i.e. the script will be executed after all previously registered scripts for the same hook, including the hs_*.int script). All scripts hooked to a single hook point with this function are executed in exact order of how they were registered, as opposed to the description below, which refers to using register_hook/register_hook_proc functions. NOTE: you can hook several scripts to a single hook point, for example if it's different mods from different authors or just some different aspects of one larger mod. In this case scripts are executed in reverse order of how they were registered. When one of the scripts in a chain returns value with "set_sfall_return", the next script may override this value if calls "set_sfall_return" again. Sometimes you need to multiply certain value in a chain of hook scripts. Example: let's say we have a Mod A which reduces all "to hit" chances by 50%. The code might look like this: diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index f2087fd8..1774ef23 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -268,29 +268,29 @@ public: return 0; } - // Only called for the keyboard - HRESULT _stdcall GetDeviceData(DWORD a, DIDEVICEOBJECTDATA* b, DWORD* c, DWORD d) { + // Only called for the keyboard (dxinput_read_keyboard_buffer_ called at 0x4E06AB) + HRESULT _stdcall GetDeviceData(DWORD a, DIDEVICEOBJECTDATA* buf, DWORD* count, DWORD d) { // buf - DirectInputKeyboardBuffer (0x6B2560) if (DeviceType != kDeviceType_KEYBOARD) { - return RealDevice->GetDeviceData(a, b, c, d); + return RealDevice->GetDeviceData(a, buf, count, d); } onInputLoop.invoke(); - if (!b || bufferedPresses.empty() || (d & DIGDD_PEEK)) { - HRESULT hr = RealDevice->GetDeviceData(a, b, c, d); - if (FAILED(hr) || !b || !(*c)) return hr; - for (DWORD i = 0; i < *c; i++) { - DWORD dxKey = b[i].dwOfs; - DWORD state = b[i].dwData & 0x80; + if (!buf || bufferedPresses.empty() || (d & DIGDD_PEEK)) { + HRESULT hr = RealDevice->GetDeviceData(a, buf, count, d); + if (FAILED(hr) || !buf || !(*count)) return hr; + for (DWORD i = 0; i < *count; i++) { + DWORD dxKey = buf[i].dwOfs; + DWORD state = buf[i].dwData & 0x80; DWORD oldState = keysDown[dxKey]; keysDown[dxKey] = state; HookScripts::KeyPressHook(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); - if (dxKey > 0 && dxKey != b[i].dwOfs) { - keysDown[b[i].dwOfs] = oldState; - b[i].dwOfs = dxKey; // Override key - keysDown[b[i].dwOfs] = state; + if (dxKey > 0 && dxKey != buf[i].dwOfs) { + keysDown[buf[i].dwOfs] = oldState; + buf[i].dwOfs = dxKey; // Override key + keysDown[buf[i].dwOfs] = state; } - onKeyPressed.invoke(b[i].dwOfs, (state > 0)); + onKeyPressed.invoke(buf[i].dwOfs, (state > 0)); } return hr; } @@ -298,9 +298,9 @@ public: //TODO: Fallouts behaviour when passing multiple keypresses makes it appear like it's expecting the DIDEVICEOBJECTDATA struct to be // something other than 16 bytes. afaik, fallout uses DX3 for input, which is before the appData field was added, but it could // be worth checking anyway. - *b = bufferedPresses.front(); + *buf = bufferedPresses.front(); bufferedPresses.pop(); - *c = 1; + *count = 1; return DI_OK; } diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 0f4bf061..70d5c3b0 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2892,6 +2892,9 @@ void BugFixes::init() // Place the player on a nearby empty tile if the entrance tile is blocked by another object when entering a map HookCall(0x4836F8, map_check_state_hook); + + // Remove duplicate code from intface_redraw_ engine function + BlockCall(0x45EBBF); } } diff --git a/sfall/Modules/ExtraSaveSlots.cpp b/sfall/Modules/ExtraSaveSlots.cpp index 3a648842..068738fa 100644 --- a/sfall/Modules/ExtraSaveSlots.cpp +++ b/sfall/Modules/ExtraSaveSlots.cpp @@ -423,7 +423,7 @@ static long quickSavePage = 0; static FILETIME ftPrevSlot; static DWORD __stdcall QuickSaveGame(fo::DbFile* file, char* filename) { - int currSlot = fo::var::slot_cursor; + long currSlot = fo::var::slot_cursor; if (file) { // This slot is not empty fo::func::db_fclose(file);