From b187c8359be77e375a4e0952958412b0a0c16fe2 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 18 Dec 2021 21:37:48 +0800 Subject: [PATCH] Changed the load order of sfall.dat to after patchXXX.dat Code edits to Interface.cpp due to the previous commit. --- sfall/FalloutEngine/FunctionOffsets_def.h | 2 ++ sfall/Modules/Graphics.cpp | 10 ------- sfall/Modules/Graphics.h | 1 - sfall/Modules/Interface.cpp | 7 ++--- sfall/Modules/Interface.h | 1 - sfall/Modules/LoadGameHook.cpp | 1 - sfall/Modules/LoadOrder.cpp | 36 +++++++++++++++++------ sfall/Modules/MiscPatches.cpp | 2 +- 8 files changed, 32 insertions(+), 28 deletions(-) diff --git a/sfall/FalloutEngine/FunctionOffsets_def.h b/sfall/FalloutEngine/FunctionOffsets_def.h index 93a4dd2c..b2e6e23e 100644 --- a/sfall/FalloutEngine/FunctionOffsets_def.h +++ b/sfall/FalloutEngine/FunctionOffsets_def.h @@ -417,6 +417,8 @@ FUNC(movieStop_, 0x487150) FUNC(movieUpdate_, 0x487BEC) FUNC(my_free_, 0x4C5C2C) FUNC(new_obj_id_, 0x4A386C) +FUNC(nfree_, 0x4EF2B4) +FUNC(nmalloc_, 0x4EF1C5) FUNC(nrealloc_, 0x4F1669) FUNC(objPMAttemptPlacement_, 0x49D628) FUNC(obj_ai_blocking_at_, 0x48BA20) diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index 57c49c95..3a170637 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -135,16 +135,6 @@ static VertexFormat ShaderVertices[] = { {639.5, 479.5, 0, 1, 1, 1} // 3 - bottom right }; -HWND Graphics::GetFalloutWindowInfo(RECT* rect) { - if (rect) { - rect->left = windowLeft; - rect->top = windowTop; - rect->right = gWidth; - rect->bottom = gHeight; - } - return window; -} - long Graphics::GetGameWidthRes() { return (fo::ptr::scr_size->offx - fo::ptr::scr_size->x) + 1; } diff --git a/sfall/Modules/Graphics.h b/sfall/Modules/Graphics.h index b710954e..63296bac 100644 --- a/sfall/Modules/Graphics.h +++ b/sfall/Modules/Graphics.h @@ -38,7 +38,6 @@ public: static DWORD mode; static DWORD GPUBlt; - static HWND GetFalloutWindowInfo(RECT* rect); static long GetGameWidthRes(); static long GetGameHeightRes(); diff --git a/sfall/Modules/Interface.cpp b/sfall/Modules/Interface.cpp index aa58d26e..db67a71b 100644 --- a/sfall/Modules/Interface.cpp +++ b/sfall/Modules/Interface.cpp @@ -672,11 +672,6 @@ static void UIAnimationSpeedPatch() { SimplePatch(&addrs[4], 2, "Misc", "PipboyTimeAnimDelay", 50, 0, 127); } -void Interface::OnBeforeGameInit() { - if (hrpVersionValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); - HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP -} - void Interface::OnGameLoad() { dots.clear(); } @@ -699,6 +694,8 @@ void Interface::init() { // Transparent/Hidden - will not toggle the mouse cursor when the cursor hovers over a transparent/hidden window // ScriptWindow - prevents the player from moving when clicking on the window if the 'Transparent' flag is not set HookCall(0x44B737, gmouse_bk_process_hook); + HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP + if (hrpVersionValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0); } void Interface::exit() { diff --git a/sfall/Modules/Interface.h b/sfall/Modules/Interface.h index f5d08bbb..88723da0 100644 --- a/sfall/Modules/Interface.h +++ b/sfall/Modules/Interface.h @@ -10,7 +10,6 @@ public: static void exit(); static void OnGameLoad(); - static void OnBeforeGameInit(); static long ActiveInterfaceWID(); static fo::Window* GetWindow(long winType); diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index b7ac32d1..c8d15d6a 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -366,7 +366,6 @@ static void __declspec(naked) main_load_new_hook() { static void __stdcall GameInitialization() { // OnBeforeGameInit BugFixes::OnBeforeGameInit(); - Interface::OnBeforeGameInit(); } static void __stdcall game_init_hook() { // OnGameInit diff --git a/sfall/Modules/LoadOrder.cpp b/sfall/Modules/LoadOrder.cpp index a54ec1c5..a25321b3 100644 --- a/sfall/Modules/LoadOrder.cpp +++ b/sfall/Modules/LoadOrder.cpp @@ -138,7 +138,7 @@ static void __declspec(naked) game_init_databases_hack1() { mov ecx, [esp + 0x104 + 4]; // path_patches call RemoveDatabase; skip: - mov ds:[FO_VAR_master_db_handle], eax; // the pointer of master_patches node will be saved here + mov ds:[FO_VAR_master_db_handle], eax; // the pointer of master_patches node will be saved here retn; } } @@ -151,21 +151,21 @@ static void __declspec(naked) game_init_databases_hack2() { mov eax, ds:[FO_VAR_master_db_handle]; // pointer to master_patches node mov eax, [eax]; // eax = master_patches.path call fo::funcoffs::xremovepath_; - dec eax; // remove path (critter_patches == master_patches)? - jz end; // Yes (jump if 0) + dec eax; // 1 = remove path (critter_patches == master_patches)? + jz end; // yes (jump if removed) mov ecx, [esp + 0x104 + 4]; // path_patches call RemoveDatabase; end: mov ds:[FO_VAR_critter_db_handle], eax; // the pointer of critter_patches node will be saved here + xor ebx, ebx; + lea eax, [sfallRes]; + call fo::funcoffs::db_init_; // init sfall resource file retn; } } static void __fastcall game_init_databases_hook() { // eax = _master_db_handle fo::PathNode* master_patches = *fo::ptr::master_db_handle; - - fo::func::db_init(sfallRes, 0); - fo::PathNode* critter_patches = *fo::ptr::critter_db_handle; fo::PathNode* paths = *fo::ptr::paths; // beginning of the chain of paths // insert master_patches/critter_patches at the beginning of the chain of paths @@ -175,6 +175,26 @@ static void __fastcall game_init_databases_hook() { // eax = _master_db_handle } master_patches->next = paths; // master_patches.next -> paths *fo::ptr::paths = master_patches; // set master_patches node at the beginning of the chain of paths + + // remove paths that are identical to master_patches (usually the DATA folder) + fo::PathNode* parentPath = *fo::ptr::paths; + paths = parentPath->next; + while (paths) { + if (!paths->isDat && _stricmp(paths->path, (*fo::ptr::paths)->path) == 0) { + fo::PathNode* nextPaths = paths->next; + __asm { + mov eax, [paths]; + call fo::funcoffs::nfree_; // free path string + mov eax, paths; + call fo::funcoffs::nfree_; // free self + } + parentPath->next = nextPaths; + paths = nextPaths; + } else { + parentPath = paths; + paths = paths->next; + } + } } /* static void __fastcall game_init_databases_hook1() { @@ -187,8 +207,6 @@ static void __fastcall game_init_databases_hook1() { node = node->next; } *fo::ptr::master_db_handle = node; // set pointer to master_patches node - - fo::func::db_init(sfallRes, 0); } */ static void MultiPatchesPatch() { @@ -432,7 +450,7 @@ void LoadOrder::OnGameLoad() { } void LoadOrder::init() { - SfallResourceFile(); // Add external sfall resource file (load order is before patchXXX.dat) + SfallResourceFile(); // Add external sfall resource file (load order: > patchXXX.dat > sfall.dat > ... [last]) MultiPatchesPatch(); //if (IniReader::GetConfigInt("Misc", "DataLoadOrderPatch", 1)) { diff --git a/sfall/Modules/MiscPatches.cpp b/sfall/Modules/MiscPatches.cpp index 7a784b19..02c82d35 100644 --- a/sfall/Modules/MiscPatches.cpp +++ b/sfall/Modules/MiscPatches.cpp @@ -859,7 +859,7 @@ static void __declspec(naked) sf_inven_display_msg() { static void __declspec(naked) sf_display_print_alt() { __asm { push ecx; - push fo::funcoffs::display_print_; + push fo::funcoffs::display_print_; // func replaced by HRP push eax; // message call SplitPrintMessage; pop ecx;