From 7baa6de0143c2f046b7aa22b7886abd4670d6687 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 15 Jun 2023 13:24:02 +0800 Subject: [PATCH] Reduced buffer flush in Logging.cpp Edited some description in ddraw.ini. --- artifacts/ddraw.ini | 12 ++++++------ sfall/Logging.cpp | 34 ++++++++++++++++------------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 47d184f8..36580f99 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -523,7 +523,7 @@ ScienceOnCritters=0 ;Default is 166 (lower - faster; valid range: 0..1000) SpeedInventoryPCRotation=166 -;Modify the number of the extra interface boxes available to modders. (Default is 5, and the maximum is 95) +;Modify the number of the extra interface boxes available to modders (Default is 5, and the maximum is 95) BoxBarCount=5 ;Uncomment to set the text colour of the extra interface boxes @@ -536,7 +536,7 @@ BonusHtHDamageFix=1 ;Set to 1 to display additional points of damage from Bonus HtH/Ranged Damage perks in the inventory DisplayBonusDamage=0 -;Modify the maximum number of animations allowed to run on a map. (Default is 32, and the maximum is 127) +;Modify the maximum number of animations allowed to run on a map (Default is 32, and the maximum is 127) AnimationsAtOnceLimit=64 ;Set to 1 to remove the limits that stop the game from rolling critical successes/failures in the first few days of game time @@ -846,7 +846,7 @@ AllowUnsafeScripting=0 SkipCompatModeCheck=0 ;Fallout 2 Debug Patch -;Set to 1 to send debug output to the screen, 2 to a debug.log file, or 3 to both the screen and debug.log +;Set to 1 to send debug output to the screen, 2 to a debug.log file, or 3 to both ;Does not require sfall debugging mode ;While you don't need to create an environment variable, you do still need to set the appropriate lines in fallout2.cfg ;------- @@ -895,9 +895,9 @@ Criticals=1 ;Prints messages relating to engine fixes Fixes=1 -;Duplicate log to dedicated console window, shown alongside the main game window -;Set to 1 to display debug.log output (requires DebugMode > 0), 2 to display sfall log, 3 for both. +;Duplicates logs to a dedicated console window alongside the game window +;Set to 1 to display debug output (requires DebugMode to be enabled), 2 to display sfall log, or 3 for both ConsoleWindow=0 -;Updated automatically, don't change +;Console window position and size data. Do not modify ConsoleWindowData= diff --git a/sfall/Logging.cpp b/sfall/Logging.cpp index 0cef0ef8..8ee69fd2 100644 --- a/sfall/Logging.cpp +++ b/sfall/Logging.cpp @@ -93,7 +93,7 @@ void ConsoleWindow::loadPosition() { windowData[i] = atoi(windowDataSplit.at(i).c_str()); } if (!SetWindowPos(wnd, HWND_TOP, windowData[0], windowData[1], windowData[2], windowData[3], 0)) { - dlog_f("Error Repositioning console window: %x \n", DL_MAIN, GetLastError()); + dlog_f("Error repositioning console window: 0x%x\n", DL_MAIN, GetLastError()); } } @@ -101,17 +101,17 @@ void ConsoleWindow::savePosition() { HWND wnd; if (!tryGetWindow(&wnd)) return; - tagRECT wndRect; + RECT wndRect; if (!GetWindowRect(wnd, &wndRect)) { - dlog_f("Error getting console window position: %x \n", DL_MAIN, GetLastError()); + dlog_f("Error getting console window position: 0x%x\n", DL_MAIN, GetLastError()); } int width = wndRect.right - wndRect.left; int height = wndRect.bottom - wndRect.top; std::ostringstream ss; ss << wndRect.left << "," << wndRect.top << "," << width << "," << height; auto wndDataStr = ss.str(); - dlog_f("Saving console window position & size: %s", DL_MAIN, wndDataStr.c_str()); - + dlog_f("Saving console window position & size: %s\n", DL_MAIN, wndDataStr.c_str()); + IniReader::SetDefaultConfigString(IniSection, IniPositionKey, wndDataStr.c_str()); } @@ -119,16 +119,14 @@ static void __fastcall PrintToConsole(const char* a) { ConsoleWindow::instance().falloutLog(a); } -static void __declspec(naked) debug_printf_hack() { - static const DWORD backRet = 0x4C6F7C; +static void __declspec(naked) debug_printf_hook() { __asm { call fo::funcoffs::vsprintf_; pushadc; - mov ecx, esp; - add ecx, 12; + lea ecx, [esp + 16]; call PrintToConsole; popadc; - jmp backRet; + retn; } } @@ -136,17 +134,17 @@ void ConsoleWindow::init() { _mode = IniReader::GetIntDefaultConfig(IniSection, IniModeKey, 0); if (_mode == 0) return; if (!AllocConsole()) { - dlog_f("Failed to alloc console: %x", DL_MAIN, GetLastError()); + dlog_f("Failed to allocate console: 0x%x\n", DL_MAIN, GetLastError()); return; } freopen("CONOUT$", "w", stdout); // this allows to print to console via std::cout if (_mode & ConsoleSource::GAME) { - std::cout << "Displaying debug_printf output." << std::endl; - MakeJump(0x4C6F77, debug_printf_hack); + std::cout << "Displaying debug_printf output.\n"; + HookCall(0x4C6F77, debug_printf_hook); } if (_mode & ConsoleSource::SFALL) { - std::cout << "Displaying sfall debug output." << std::endl; + std::cout << "Displaying sfall debug output.\n"; } std::cout << std::endl; @@ -168,7 +166,7 @@ void ConsoleWindow::sfallLog(const std::string& a, int type) { if (!(_mode & ConsoleSource::SFALL)) return; if (_lastSource == ConsoleSource::GAME) { - std::cout << std::endl; // To make logs prettier, because debug_msg places newline before the message. + std::cout << "\n"; // To make logs prettier, because debug_msg places newline before the message. } std::cout << a; _lastSource = ConsoleSource::SFALL; @@ -182,11 +180,11 @@ static void OutLog(T a, int type, bool newLine = false) { ss << "[" << DebugTypeToStr(type) << "] "; } ss << a; - if (newLine) ss << std::endl; + if (newLine) ss << "\n"; std::string str = ss.str(); ConsoleWindow::instance().sfallLog(str, type); - + Log << str; Log.flush(); @@ -278,7 +276,7 @@ void LoggingInit() { if (IniReader::GetIntDefaultConfig("Debugging", "Fixes", 0)) { DebugTypes |= DL_FIX; } - + ConsoleWindow::instance().init(); }