From 560eead6947f9d089900b0a445658cb05a98e415 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 24 Apr 2019 10:03:43 +0800 Subject: [PATCH] Rewrote Force Encounter script function code. Changed set_global_script_repeat/type & set_self to use fastcall. Minor edits to BugFixes.cpp and ddraw.ini. --- artifacts/ddraw.ini | 5 +-- sfall/Bugs.cpp | 15 ++++---- sfall/FalloutEngine.cpp | 1 + sfall/FalloutEngine.h | 1 + sfall/ScriptExtender.cpp | 62 +++++++++++++++------------------ sfall/ScriptOps/WorldmapOps.hpp | 52 +++++++++++++-------------- sfall/dinput.cpp | 2 +- 7 files changed, 67 insertions(+), 71 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a32b4ac79..194f0f60c 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -70,9 +70,10 @@ GraphicsHeight=0 ;GPU is faster, but requires v2.0 pixel shader support GPUBlt=0 -;Set to 1 to allow using 32-bit .png textures for talking heads +;Set to 1 to allow using 32-bit textures for talking heads ;The texture files should be placed in art/heads// (w/o extension) -;The files in the folder should be numbered according to the number of frames in the talking head FRM file (e.g. 0.png - 10.png) +;The files in the folder should be numbered according to the number of frames in the talking head FRM file (0.png, 1.png, etc.) +;See the text file in the modders pack for a detailed description ;Requires DX9 graphics mode and v2.0 pixel shader support (see GPUBlt option) Use32BitHeadGraphics=0 diff --git a/sfall/Bugs.cpp b/sfall/Bugs.cpp index 88c19f6b0..fd8f23097 100644 --- a/sfall/Bugs.cpp +++ b/sfall/Bugs.cpp @@ -679,13 +679,12 @@ static void __declspec(naked) item_c_curr_size_hack() { static void __declspec(naked) inven_pickup_hack() { __asm { - mov edx, ds:[_pud] - mov edx, [edx] // itemsCount - dec edx - sub edx, eax - lea edx, ds:0[edx*8] - push 0x470EC9 - retn + mov edx, ds:[_pud]; + mov edx, [edx]; // itemsCount + dec edx; + sub edx, eax; + lea edx, ds:0[edx * 8]; + retn; } } @@ -2166,7 +2165,7 @@ void BugsInit() dlog("Applying inventory reverse order issues fix.", DL_INIT); // Fix for minor visual glitch when picking up solo item from the top of inventory // and there is multiple item stack at the bottom of inventory - MakeJump(0x470EC2, inven_pickup_hack); + MakeCall(0x470EC2, inven_pickup_hack, 2); // Fix for error in player's inventory, related to IFACE_BAR_MODE=1 in f2_res.ini, and // also for reverse order error MakeJump(0x47114A, inven_pickup_hack2); diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index e06146eb6..594047e3d 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -472,6 +472,7 @@ const DWORD make_path_func_ = 0x415EFC; const DWORD make_straight_path_func_ = 0x4163C8; const DWORD map_disable_bk_processes_ = 0x482104; const DWORD map_enable_bk_processes_ = 0x4820C0; +const DWORD map_load_idx_ = 0x482B34; const DWORD mem_free_ = 0x4C5C24; const DWORD mem_malloc_ = 0x4C5AD0; const DWORD mem_realloc_ = 0x4C5B50; diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index ec819ec4c..734f10194 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -699,6 +699,7 @@ extern const DWORD make_path_func_; extern const DWORD make_straight_path_func_; // (TGameObj *aObj, int aTileFrom, int a3, signed int aTileTo, 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_load_idx_; extern const DWORD mem_free_; extern const DWORD mem_malloc_; extern const DWORD mem_realloc_; diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 9f0026062..d635ae9ac 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -495,11 +495,14 @@ TScript OverrideScriptStruct = {0}; -static void _stdcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) { +static void __fastcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) { for (DWORD d = 0; d < globalScripts.size(); d++) { if (globalScripts[d].prog.ptr == script) { - if (frames == 0xFFFFFFFF) globalScripts[d].mode = !globalScripts[d].mode; - else globalScripts[d].repeat = frames; + if (frames == 0xFFFFFFFF) { + globalScripts[d].mode = !globalScripts[d].mode; + } else { + globalScripts[d].repeat = frames; + } break; } } @@ -507,7 +510,6 @@ static void _stdcall SetGlobalScriptRepeat2(DWORD script, DWORD frames) { static void __declspec(naked) SetGlobalScriptRepeat() { __asm { - push ebx; push ecx; push edx; mov ecx, eax; @@ -517,30 +519,28 @@ static void __declspec(naked) SetGlobalScriptRepeat() { call interpretPopLong_; cmp dx, VAR_TYPE_INT; jnz end; - push eax; - push ecx; - call SetGlobalScriptRepeat2; + mov edx, eax; // frames + call SetGlobalScriptRepeat2; // ecx - script end: pop edx; pop ecx; - pop ebx; retn; } } -static void _stdcall SetGlobalScriptType2(DWORD script, DWORD type) { - if (type > 3) return; - for (DWORD d = 0; d < globalScripts.size(); d++) { - if (globalScripts[d].prog.ptr == script) { - globalScripts[d].mode = type; - break; +static void __fastcall SetGlobalScriptType2(DWORD script, DWORD type) { + if (type <= 3) { + for (size_t d = 0; d < globalScripts.size(); d++) { + if (globalScripts[d].prog.ptr == script) { + globalScripts[d].mode = type; + break; + } } } } static void __declspec(naked) SetGlobalScriptType() { __asm { - push ebx; push ecx; push edx; mov ecx, eax; @@ -550,20 +550,17 @@ static void __declspec(naked) SetGlobalScriptType() { call interpretPopLong_; cmp dx, VAR_TYPE_INT; jnz end; - push eax; - push ecx; - call SetGlobalScriptType2; + mov edx, eax; // type + call SetGlobalScriptType2; // ecx - script end: pop edx; pop ecx; - pop ebx; retn; } } static void __declspec(naked) GetGlobalScriptTypes() { __asm { - push ebx; push ecx; push edx; mov edx, AvailableGlobalScriptTypes; @@ -574,7 +571,6 @@ static void __declspec(naked) GetGlobalScriptTypes() { call interpretPushShort_; pop edx; pop ecx; - pop ebx; retn; } } @@ -770,7 +766,6 @@ static void __declspec(naked) SetSfallArg() { static void __declspec(naked) SetSfallReturn() { __asm { - push ebx; push ecx; push edx; mov ecx, eax; @@ -785,7 +780,6 @@ static void __declspec(naked) SetSfallReturn() { end: pop edx; pop ecx; - pop ebx; retn; } } @@ -806,7 +800,7 @@ static void __declspec(naked) InitHook() { } } -static void _stdcall set_self2(DWORD script, TGameObj* obj) { +static void __fastcall SetSelfObject(DWORD script, TGameObj* obj) { stdext::hash_map::iterator it = selfOverrideMap.find(script); bool isFind = (it != selfOverrideMap.end()); if (obj) { @@ -830,22 +824,24 @@ static void _stdcall set_self2(DWORD script, TGameObj* obj) { static void __declspec(naked) set_self() { __asm { - pushad; - mov ebp, eax; + push ecx; + push edx; + mov ecx, eax; call interpretPopShort_; - mov edi, eax; - mov eax, ebp; + mov edx, eax; + mov eax, ecx; call interpretPopLong_; - cmp di, VAR_TYPE_INT; + cmp dx, VAR_TYPE_INT; jnz end; - push eax; - push ebp; - call set_self2; + mov edx, eax; // object + call SetSelfObject; // ecx - script end: - popad; + pop edx; + pop ecx; retn; } } + static void __declspec(naked) register_hook() { __asm { pushad; diff --git a/sfall/ScriptOps/WorldmapOps.hpp b/sfall/ScriptOps/WorldmapOps.hpp index 6c86b8d68..9d41a092b 100644 --- a/sfall/ScriptOps/WorldmapOps.hpp +++ b/sfall/ScriptOps/WorldmapOps.hpp @@ -24,40 +24,38 @@ static DWORD EncounteredHorrigan; -static void _stdcall ForceEncounter4() { +static DWORD ForceEnconterMapID; + +static void _stdcall ForceEncounterRestore() { *(DWORD*)0x672E04 = EncounteredHorrigan; - SafeWrite32(0x4C070E, 0x95); - SafeWrite32(0x4C0718, 0x95); - SafeWrite32(0x4C06D1, 0x2E043D83); + SafeWrite32(0x4C070E, *(DWORD*)0x4C0718); // map id + SafeWrite16(0x4C06D8, 0x5175); SafeWrite32(0x4C071D, 0xFFFC2413); SafeWrite8(0x4C0706, 0x75); } -static void __declspec(naked) ForceEncounter3() { + +static void __declspec(naked) wmRndEncounterOccurred_hook() { __asm { - push eax; push ecx; - push edx; - mov eax, [esp + 0xC]; - sub eax, 5; - mov [esp + 0xC], eax; - call ForceEncounter4; - pop edx; - pop ecx; - pop eax; - retn; + call ForceEncounterRestore; + pop ecx; + mov eax, ForceEnconterMapID; + jmp map_load_idx_; } } -static void _stdcall ForceEncounter2(DWORD mapID, DWORD flags) { + +static void __fastcall ForceEncounter2(DWORD mapID, DWORD flags) { EncounteredHorrigan = *(DWORD*)0x672E04; + ForceEnconterMapID = mapID; SafeWrite32(0x4C070E, mapID); - SafeWrite32(0x4C0718, mapID); - SafeWrite32(0x4C06D1, 0x18EBD231); //xor edx, edx / jmp 0x18 - HookCall(0x4C071C, &ForceEncounter3); + SafeWrite16(0x4C06D8, 0x13EB); // jmp 0x4C06ED + HookCall(0x4C071C, wmRndEncounterOccurred_hook); + if (flags & 1) SafeWrite8(0x4C0706, 0xEB); } + static void __declspec(naked) ForceEncounter() { __asm { - push ebx; push ecx; push edx; mov ecx, eax; @@ -67,19 +65,19 @@ static void __declspec(naked) ForceEncounter() { call interpretPopLong_; cmp dx, VAR_TYPE_INT; jnz end; - push 0; - push eax; + xor edx, edx; // flags + mov ecx, eax; // mapID call ForceEncounter2; end: pop edx; pop ecx; - pop ebx; retn; } } + static void __declspec(naked) ForceEncounterWithFlags() { __asm { - pushad + pushad; mov ecx, eax; call interpretPopShort_; mov edx, eax; @@ -95,11 +93,11 @@ static void __declspec(naked) ForceEncounterWithFlags() { jnz end; cmp di, VAR_TYPE_INT; jnz end; - push ebx; - push eax; + mov edx, ebx; // flags + mov ecx, eax; // mapID call ForceEncounter2; end: - popad + popad; retn; } } diff --git a/sfall/dinput.cpp b/sfall/dinput.cpp index 366224df8..c92d37c96 100644 --- a/sfall/dinput.cpp +++ b/sfall/dinput.cpp @@ -229,7 +229,7 @@ class FakeDirectInputDevice : public IDirectInputDeviceA { } } } - if (MiddleMouseKey&&MouseState.rgbButtons[2]) { + if (MiddleMouseKey && MouseState.rgbButtons[2]) { if (!MiddleMouseDown) { TapKey(MiddleMouseKey); MiddleMouseDown = true;