mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Backported ConsoleWindow option from 4.x
This commit is contained in:
+10
-3
@@ -525,7 +525,7 @@ ScienceOnCritters=0
|
|||||||
;Default is 166 (lower - faster; valid range: 0..1000)
|
;Default is 166 (lower - faster; valid range: 0..1000)
|
||||||
SpeedInventoryPCRotation=166
|
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
|
BoxBarCount=5
|
||||||
|
|
||||||
;Uncomment to set the text colour of the extra interface boxes
|
;Uncomment to set the text colour of the extra interface boxes
|
||||||
@@ -538,7 +538,7 @@ BonusHtHDamageFix=1
|
|||||||
;Set to 1 to display additional points of damage from Bonus HtH/Ranged Damage perks in the inventory
|
;Set to 1 to display additional points of damage from Bonus HtH/Ranged Damage perks in the inventory
|
||||||
DisplayBonusDamage=0
|
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
|
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
|
;Set to 1 to remove the limits that stop the game from rolling critical successes/failures in the first few days of game time
|
||||||
@@ -837,7 +837,7 @@ AllowUnsafeScripting=0
|
|||||||
SkipCompatModeCheck=0
|
SkipCompatModeCheck=0
|
||||||
|
|
||||||
;Fallout 2 Debug Patch
|
;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
|
;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
|
;While you don't need to create an environment variable, you do still need to set the appropriate lines in fallout2.cfg
|
||||||
;-------
|
;-------
|
||||||
@@ -885,3 +885,10 @@ Script=0
|
|||||||
Criticals=1
|
Criticals=1
|
||||||
;Prints messages relating to engine fixes
|
;Prints messages relating to engine fixes
|
||||||
Fixes=1
|
Fixes=1
|
||||||
|
|
||||||
|
;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
|
||||||
|
|
||||||
|
;Console window position and size data. Do not modify
|
||||||
|
ConsoleWindowData=
|
||||||
|
|||||||
@@ -718,6 +718,7 @@ FUNC(trait_set_, 0x4B3B48)
|
|||||||
FUNC(trans_buf_to_buf_, 0x4D3704)
|
FUNC(trans_buf_to_buf_, 0x4D3704)
|
||||||
FUNC(trans_cscale_, 0x4D3560)
|
FUNC(trans_cscale_, 0x4D3560)
|
||||||
FUNC(use_inventory_on_, 0x4717E4)
|
FUNC(use_inventory_on_, 0x4717E4)
|
||||||
|
FUNC(vsprintf_, 0x4F143B)
|
||||||
FUNC(win_add_, 0x4D6238)
|
FUNC(win_add_, 0x4D6238)
|
||||||
FUNC(win_clip_, 0x4D75B0)
|
FUNC(win_clip_, 0x4D75B0)
|
||||||
FUNC(win_delete_, 0x4D6468)
|
FUNC(win_delete_, 0x4D6468)
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ int IniReader::SetConfigInt(const char* section, const char* setting, int value)
|
|||||||
return setInt(section, setting, value, ini);
|
return setInt(section, setting, value, ini);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IniReader::SetConfigString(const char* section, const char* setting, const char* value) {
|
||||||
|
return WritePrivateProfileStringA(section, setting, value, ini);
|
||||||
|
}
|
||||||
|
|
||||||
int IniReader::SetDefaultConfigInt(const char* section, const char* setting, int value) {
|
int IniReader::SetDefaultConfigInt(const char* section, const char* setting, int value) {
|
||||||
return setInt(section, setting, value, ddrawIni);
|
return setInt(section, setting, value, ddrawIni);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -34,7 +34,7 @@ public:
|
|||||||
// Gets the integer value from the default config (i.e. ddraw.ini)
|
// Gets the integer value from the default config (i.e. ddraw.ini)
|
||||||
static int GetIntDefaultConfig(const char* section, const char* setting, int defaultValue);
|
static int GetIntDefaultConfig(const char* section, const char* setting, int defaultValue);
|
||||||
|
|
||||||
static std::string GetStringDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize);
|
static std::string GetStringDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize = 128);
|
||||||
|
|
||||||
// Gets a list of values separated by the delimiter from the default config (i.e. ddraw.ini)
|
// Gets a list of values separated by the delimiter from the default config (i.e. ddraw.ini)
|
||||||
static std::vector<std::string> GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter);
|
static std::vector<std::string> GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter);
|
||||||
@@ -65,6 +65,8 @@ public:
|
|||||||
|
|
||||||
static int SetConfigInt(const char* section, const char* setting, int value);
|
static int SetConfigInt(const char* section, const char* setting, int value);
|
||||||
|
|
||||||
|
static int SetConfigString(const char* section, const char* setting, const char* value);
|
||||||
|
|
||||||
static int SetDefaultConfigInt(const char* section, const char* setting, int value);
|
static int SetDefaultConfigInt(const char* section, const char* setting, int value);
|
||||||
|
|
||||||
static int SetDefaultConfigString(const char* section, const char* setting, const char* value);
|
static int SetDefaultConfigString(const char* section, const char* setting, const char* value);
|
||||||
|
|||||||
+178
-14
@@ -18,50 +18,208 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
|
#include "FalloutEngine\Fallout2.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#ifndef NO_SFALL_DEBUG
|
#ifndef NO_SFALL_DEBUG
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace sfall
|
namespace sfall
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum ConsoleSource : int {
|
||||||
|
GAME = 1,
|
||||||
|
SFALL = 2
|
||||||
|
};
|
||||||
|
|
||||||
static int DebugTypes = 0;
|
static int DebugTypes = 0;
|
||||||
static std::ofstream Log;
|
static std::ofstream Log;
|
||||||
|
|
||||||
template <class T>
|
static int LastType = -1;
|
||||||
static void OutLog(T a) {
|
static int LastNewLine;
|
||||||
Log << a;
|
|
||||||
Log.flush();
|
class ConsoleWindow {
|
||||||
|
public:
|
||||||
|
static ConsoleWindow& instance() { return _instance; }
|
||||||
|
|
||||||
|
ConsoleWindow() : _mode(0) {}
|
||||||
|
~ConsoleWindow();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void loadPosition();
|
||||||
|
void savePosition();
|
||||||
|
|
||||||
|
void sfallLog(const std::string& a, int type);
|
||||||
|
void falloutLog(const char* a);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ConsoleWindow _instance;
|
||||||
|
|
||||||
|
int _mode;
|
||||||
|
ConsoleSource _lastSource;
|
||||||
|
|
||||||
|
bool tryGetWindow(HWND* wnd);
|
||||||
|
};
|
||||||
|
|
||||||
|
ConsoleWindow ConsoleWindow::_instance;
|
||||||
|
|
||||||
|
bool ConsoleWindow::tryGetWindow(HWND* wnd) {
|
||||||
|
*wnd = GetConsoleWindow();
|
||||||
|
if (!*wnd) {
|
||||||
|
dlogr("Error getting console window.", DL_MAIN);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::loadPosition() {
|
||||||
|
std::string windowDataStr = IniReader::GetStringDefaultConfig("Debugging", "ConsoleWindowData", "");
|
||||||
|
std::vector<std::string> windowDataSplit = split(windowDataStr, ',');
|
||||||
|
if (windowDataSplit.size() < 4) return;
|
||||||
|
|
||||||
|
HWND wnd;
|
||||||
|
if (!tryGetWindow(&wnd)) return;
|
||||||
|
|
||||||
|
int windowData[4];
|
||||||
|
for (size_t i = 0; i < 4; i++) {
|
||||||
|
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: 0x%x\n", DL_MAIN, GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::savePosition() {
|
||||||
|
HWND wnd;
|
||||||
|
if (!tryGetWindow(&wnd)) return;
|
||||||
|
|
||||||
|
RECT wndRect;
|
||||||
|
if (!GetWindowRect(wnd, &wndRect)) {
|
||||||
|
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\n", DL_MAIN, wndDataStr.c_str());
|
||||||
|
|
||||||
|
IniReader::SetDefaultConfigString("Debugging", "ConsoleWindowData", wndDataStr.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __fastcall PrintToConsole(const char* a) {
|
||||||
|
ConsoleWindow::instance().falloutLog(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __declspec(naked) debug_printf_hook() {
|
||||||
|
__asm {
|
||||||
|
call fo::funcoffs::vsprintf_;
|
||||||
|
pushadc;
|
||||||
|
lea ecx, [esp + 16];
|
||||||
|
call PrintToConsole;
|
||||||
|
popadc;
|
||||||
|
retn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::init() {
|
||||||
|
_mode = IniReader::GetIntDefaultConfig("Debugging", "ConsoleWindow", 0);
|
||||||
|
if (_mode == 0) return;
|
||||||
|
if (!AllocConsole()) {
|
||||||
|
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.\n";
|
||||||
|
HookCall(0x4C6F77, debug_printf_hook);
|
||||||
|
}
|
||||||
|
if (_mode & ConsoleSource::SFALL) {
|
||||||
|
std::cout << "Displaying sfall debug output.\n";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
loadPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleWindow::~ConsoleWindow() {
|
||||||
|
if (_mode == 0) return;
|
||||||
|
|
||||||
|
savePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::falloutLog(const char* a) {
|
||||||
|
std::cout << a;
|
||||||
|
_lastSource = ConsoleSource::GAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWindow::sfallLog(const std::string& a, int type) {
|
||||||
|
if (!(_mode & ConsoleSource::SFALL)) return;
|
||||||
|
|
||||||
|
if (_lastSource == ConsoleSource::GAME) {
|
||||||
|
std::cout << "\n"; // To make logs prettier, because debug_msg places newline before the message.
|
||||||
|
}
|
||||||
|
std::cout << a;
|
||||||
|
_lastSource = ConsoleSource::SFALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static void OutLogN(T a) {
|
static void OutLog(T a, int type, bool newLine = false) {
|
||||||
Log << a << "\n";
|
std::ostringstream ss;
|
||||||
|
if (LastNewLine || type != LastType) {
|
||||||
|
ss << "[" << DebugTypeToStr(type) << "] ";
|
||||||
|
}
|
||||||
|
ss << a;
|
||||||
|
if (newLine) ss << "\n";
|
||||||
|
std::string str = ss.str();
|
||||||
|
|
||||||
|
ConsoleWindow::instance().sfallLog(str, type);
|
||||||
|
|
||||||
|
Log << str;
|
||||||
Log.flush();
|
Log.flush();
|
||||||
|
|
||||||
|
LastType = type;
|
||||||
|
LastNewLine = str.back() == '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* DebugTypeToStr(int type) {
|
||||||
|
switch (type) {
|
||||||
|
case DL_INIT: return "Init";
|
||||||
|
case DL_HOOK: return "Hook";
|
||||||
|
case DL_SCRIPT: return "Script";
|
||||||
|
case DL_CRITICALS: return "Crits";
|
||||||
|
case DL_FIX: return "Fix";
|
||||||
|
default: return "Main";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlog(const char* a, int type) {
|
void dlog(const char* a, int type) {
|
||||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||||
OutLog(a);
|
OutLog(a, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlog(const std::string& a, int type) {
|
void dlog(const std::string& a, int type) {
|
||||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||||
OutLog(a);
|
OutLog(a, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlogr(const char* a, int type) {
|
void dlogr(const char* a, int type) {
|
||||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||||
OutLogN(a);
|
OutLog(a, type, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlogr(const std::string& a, int type) {
|
void dlogr(const std::string& a, int type) {
|
||||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||||
OutLogN(a);
|
OutLog(a, type, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +228,10 @@ void dlog_f(const char* fmt, int type, ...) {
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, type);
|
va_start(args, type);
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
int written = vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
||||||
OutLog(buf);
|
if (written > 0) {
|
||||||
|
OutLog(buf, type);
|
||||||
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,8 +243,10 @@ void devlog_f(const char* fmt, int type, ...) {
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, type);
|
va_start(args, type);
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
int written = vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
||||||
OutLog(buf);
|
if (written > 0) {
|
||||||
|
OutLog(buf, type);
|
||||||
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,6 +272,8 @@ void LoggingInit() {
|
|||||||
if (IniReader::GetIntDefaultConfig("Debugging", "Fixes", 0)) {
|
if (IniReader::GetIntDefaultConfig("Debugging", "Fixes", 0)) {
|
||||||
DebugTypes |= DL_FIX;
|
DebugTypes |= DL_FIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConsoleWindow::instance().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -445,9 +445,6 @@ static void DebugModePatch() {
|
|||||||
MakeCall(0x4C703F, debug_log_hack);
|
MakeCall(0x4C703F, debug_log_hack);
|
||||||
BlockCall(0x4C7044); // just nop code
|
BlockCall(0x4C7044); // just nop code
|
||||||
}
|
}
|
||||||
// replace calling debug_printf_ with _debug_func
|
|
||||||
__int64 data = 0x51DF0415FFF08990; // mov eax, esi; call ds:_debug_func
|
|
||||||
SafeWriteBytes(0x455419, (BYTE*)&data, 8); // op_display_msg_
|
|
||||||
|
|
||||||
// set the position of the debug window
|
// set the position of the debug window
|
||||||
SafeWrite8(0x4DC34D, 15);
|
SafeWrite8(0x4DC34D, 15);
|
||||||
|
|||||||
@@ -35,6 +35,10 @@
|
|||||||
|
|
||||||
#include "Metarule.h"
|
#include "Metarule.h"
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#include <sstream>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace sfall
|
namespace sfall
|
||||||
{
|
{
|
||||||
namespace script
|
namespace script
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "..\..\..\main.h"
|
#include "..\..\..\main.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user