From 9f689863d7d8ad9a70ea5f806782a8d35ac592a0 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 27 Oct 2018 09:46:35 +0800 Subject: [PATCH] Added a new setting to DebugMode to send debug output to both the screen and the debug log (from Crafty) Simplified the code for ObjCanSeeObj_ShootThru_Fix a bit (from Mr.Stalin) Changed sfall to not to create sfallfs.sav when UseFileSystemOverride is disabled. --- artifacts/ddraw.ini | 4 ++-- sfall/FalloutEngine.cpp | 1 + sfall/FalloutEngine.h | 2 ++ sfall/FileSystem.cpp | 7 ++----- sfall/FileSystem.h | 4 +++- sfall/LoadGameHook.cpp | 4 +++- sfall/ScriptExtender.cpp | 2 ++ sfall/main.cpp | 41 +++++++++++++++++++++++++++------------- 8 files changed, 43 insertions(+), 22 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 62c86ce3..7d5e9043 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -649,8 +649,8 @@ CreditsAtBottom=0 Enable=0 ;Fallout 2 Debug Patch -;Set to 1 to enable debugging output to screen or 2 to create a debug.log file -;While you don't need to create an environment variable, you do still need to set the appropriate lines in fallout2.cfg +;Set to 1 to send debug output to the screen, 2 to a debug.log file, or 3 to both the screen and a debug.log file +;While you don't need to create an environment variable, you do still need to set the appropriate lines in fallout2.cfg: ;------- ;[debug] ;mode=environment diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index 2554e107..3076e4bc 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -310,6 +310,7 @@ const DWORD db_get_file_list_ = 0x4C6628; const DWORD db_read_to_buf_ = 0x4C5DD4; const DWORD dbase_close_ = 0x4E5270; const DWORD dbase_open_ = 0x4E4F58; +const DWORD debug_log_ = 0x4C7028; const DWORD debug_printf_ = 0x4C6F48; const DWORD debug_register_env_ = 0x4C6D90; const DWORD determine_to_hit_func_ = 0x4243A8; diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index 66813708..56ece31e 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -88,6 +88,7 @@ #define _glblmode 0x5709D0 #define _gmouse_current_cursor 0x518C0C #define _gmovie_played_list 0x596C78 +#define _GNW_win_init_flag 0x51E3E0 #define _GreenColor 0x6A3CB0 #define _gsound_initialized 0x518E30 #define _hit_location_penalty 0x510954 @@ -506,6 +507,7 @@ extern const DWORD db_get_file_list_; extern const DWORD db_read_to_buf_; extern const DWORD dbase_close_; extern const DWORD dbase_open_; +extern const DWORD debug_log_; extern const DWORD debug_printf_; extern const DWORD debug_register_env_; extern const DWORD determine_to_hit_func_; diff --git a/sfall/FileSystem.cpp b/sfall/FileSystem.cpp index 95a2ac9d..ac3aa2e8 100644 --- a/sfall/FileSystem.cpp +++ b/sfall/FileSystem.cpp @@ -36,7 +36,7 @@ std::vector files; static DWORD loadedtiles = 0; static DWORD retval; -static bool UsingFileSystem = false; +bool UsingFileSystem = false; struct openFile { DWORD pos; @@ -446,12 +446,9 @@ void FileSystemReset() { for (DWORD i = files.size() - 1; i >= loadedtiles; i--) files.erase(files.begin() + i); } } + void FileSystemSave(HANDLE h) { DWORD count = 0, unused; - if (!UsingFileSystem) { - WriteFile(h, &count, 4, &unused, 0); - return; - } for (DWORD i = 0; i < files.size(); i++) { if (files[i].data) count++; } diff --git a/sfall/FileSystem.h b/sfall/FileSystem.h index 47f8ae1c..baf8a73c 100644 --- a/sfall/FileSystem.h +++ b/sfall/FileSystem.h @@ -18,6 +18,8 @@ #pragma once +extern bool UsingFileSystem; + void FileSystemInit(); void FileSystemReset(); void FileSystemSave(HANDLE h); @@ -35,7 +37,7 @@ void _stdcall FSwrite_bstring(DWORD id, const char* data); int _stdcall FSread_byte(DWORD id); int _stdcall FSread_short(DWORD id); int _stdcall FSread_int(DWORD id); - void _stdcall FSdelete(DWORD id); +void _stdcall FSdelete(DWORD id); DWORD _stdcall FSsize(DWORD id); DWORD _stdcall FSpos(DWORD id); void _stdcall FSseek(DWORD id, DWORD pos); diff --git a/sfall/LoadGameHook.cpp b/sfall/LoadGameHook.cpp index 1f909a5a..81ddac7d 100644 --- a/sfall/LoadGameHook.cpp +++ b/sfall/LoadGameHook.cpp @@ -110,12 +110,14 @@ static void _stdcall SaveGame2() { DisplayConsoleMessage(SaveSfallDataFailMsg); PlaySfx("IISXXXX1"); } + + if (!UsingFileSystem) return; GetSavePath(buf, "fs"); h = CreateFileA(buf, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); if (h != INVALID_HANDLE_VALUE) { FileSystemSave(h); + CloseHandle(h); } - CloseHandle(h); } static char SaveFailMsg[128]; diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 98ada738..80cffe97 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -1722,11 +1722,13 @@ void LoadGlobalScripts() { isGlobalScriptLoading = 0; } } + __asm { xor edx, edx lea eax, filenames call db_free_file_list_ } + dlogr("Finished loading global scripts.", DL_SCRIPT|DL_INIT); } diff --git a/sfall/main.cpp b/sfall/main.cpp index 2be81ed7..a08ad3cc 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -658,18 +658,14 @@ fail: } } -static void __declspec(naked) op_obj_can_see_obj_hook() { // (EAX *objStruct, EDX hexNum1, EBX hexNum2, ECX ?, stack1 **ret_objStruct, stack2 flags) +static void __declspec(naked) op_obj_can_see_obj_hook() { __asm { - push esi; - push edi; - push obj_shoot_blocking_at_; // arg3 check hex objects func pointer - mov esi, 0x20; // arg2 flags, 0x20 = check shootthru - push esi; - mov edi, dword ptr ss:[esp + 0x14]; // arg1 **ret_objStruct - push edi; - call make_straight_path_func_; // (EAX *objStruct, EDX hexNum1, EBX hexNum2, ECX ?, stack1 **ret_objStruct, stack2 flags, stack3 *check_hex_objs_func) - pop edi; - pop esi; + push obj_shoot_blocking_at_; // check hex objects func pointer + push 0x20; // flags, 0x20 = check shootthru + mov ecx, dword ptr [esp + 0x0C]; // buf **ret_objStruct + push ecx; + xor ecx, ecx; + call make_straight_path_func_; // (EAX *objStruct, EDX hexNum1, EBX hexNum2, ECX 0, stack1 **ret_objStruct, stack2 flags, stack3 *check_hex_objs_func) retn 8; } } @@ -766,6 +762,16 @@ static void __declspec(naked) wmInterfaceInit_text_font_hook() { } } +static void __declspec(naked) win_debug_hook() { + __asm { + call debug_log_; + xor eax, eax; + cmp ds:[_GNW_win_init_flag], eax; + push 0x4DC320; + retn; + } +} + static void DllMain2() { //SafeWrite8(0x4B15E8, 0xc3); //SafeWrite8(0x4B30C4, 0xc3); //this is the one I need to override for bigger tiles @@ -1102,8 +1108,17 @@ static void DllMain2() { SafeWrite32(0x444A6E, 0x90909090); } SafeWrite8(0x4C6D9B, 0xB8); // mov eax, GNW/LOG - if (tmp == 2) SafeWrite32(0x4C6D9C, (DWORD)debugLog); - else SafeWrite32(0x4C6D9C, (DWORD)debugGnw); + if (tmp & 2) { + SafeWrite32(0x4C6D9C, (DWORD)debugLog); + if (tmp & 1) { + SafeWrite16(0x4C6E75, 0x66EB); // jmps 0x4C6EDD + SafeWrite8(0x4C6EF2, 0xEB); + SafeWrite8(0x4C7034, 0x0); + MakeJump(0x4DC319, win_debug_hook); + } + } else { + SafeWrite32(0x4C6D9C, (DWORD)debugGnw); + } dlogr(" Done", DL_INIT); } }