mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Debugging.ConsoleWindow option
This commit is contained in:
@@ -894,3 +894,7 @@ Script=0
|
||||
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.
|
||||
ConsoleWindow=0
|
||||
|
||||
+65
-11
@@ -18,50 +18,69 @@
|
||||
|
||||
#include "main.h"
|
||||
#include "Logging.h"
|
||||
#include "FalloutEngine\Fallout2.h"
|
||||
|
||||
#ifndef NO_SFALL_DEBUG
|
||||
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
static int DebugTypes = 0;
|
||||
static std::ofstream Log;
|
||||
static int ConsoleWindowMode = 0;
|
||||
static bool NewLine = true;
|
||||
|
||||
template <class T>
|
||||
static void OutLog(T a) {
|
||||
Log << a;
|
||||
Log.flush();
|
||||
static inline void WriteLog(std::ostream& str, T a, int type, const char* prefix, bool newLine) {
|
||||
str << prefix << DebugTypeToStr(type) << "] " << a;
|
||||
if (newLine) str << "\n";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void OutLogN(T a) {
|
||||
Log << a << "\n";
|
||||
static void OutLog(T a, int type, bool newLine = false) {
|
||||
if (ConsoleWindowMode & 2) {
|
||||
WriteLog(std::cout, a, type, (ConsoleWindowMode & 1 ? "[sfall:" : "["), newLine);
|
||||
}
|
||||
WriteLog(Log, a, type, "[", newLine);
|
||||
Log.flush();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||
OutLog(a);
|
||||
OutLog(a, type);
|
||||
}
|
||||
}
|
||||
|
||||
void dlog(const std::string& a, int type) {
|
||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||
OutLog(a);
|
||||
OutLog(a, type);
|
||||
}
|
||||
}
|
||||
|
||||
void dlogr(const char* a, int type) {
|
||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||
OutLogN(a);
|
||||
OutLog(a, type, true);
|
||||
}
|
||||
}
|
||||
|
||||
void dlogr(const std::string& a, int type) {
|
||||
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
|
||||
OutLogN(a);
|
||||
OutLog(a, type, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +90,7 @@ void dlog_f(const char* fmt, int type, ...) {
|
||||
va_start(args, type);
|
||||
char buf[1024];
|
||||
vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
||||
OutLog(buf);
|
||||
OutLog(buf, type);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +103,7 @@ void devlog_f(const char* fmt, int type, ...) {
|
||||
va_start(args, type);
|
||||
char buf[1024];
|
||||
vsnprintf_s(buf, sizeof(buf), _TRUNCATE, fmt, args);
|
||||
OutLog(buf);
|
||||
OutLog(buf, type);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
@@ -92,9 +111,28 @@ void devlog_f(const char* fmt, int type, ...) {
|
||||
void devlog_f(...) {}
|
||||
#endif
|
||||
|
||||
static void __fastcall OutLogC(const char* a) {
|
||||
std::cout << a;
|
||||
}
|
||||
|
||||
static void __declspec(naked) debug_printf_hack() {
|
||||
static const DWORD backRet = 0x4C6F7C;
|
||||
__asm {
|
||||
call fo::funcoffs::vsprintf_;
|
||||
pushadc;
|
||||
mov ecx, esp;
|
||||
add ecx, 12;
|
||||
call OutLogC;
|
||||
popadc;
|
||||
jmp backRet;
|
||||
}
|
||||
}
|
||||
|
||||
void LoggingInit() {
|
||||
Log.open("sfall-log.txt", std::ios_base::out | std::ios_base::trunc);
|
||||
|
||||
ConsoleWindowMode = IniReader::GetIntDefaultConfig("Debugging", "ConsoleWindow", 0);
|
||||
|
||||
if (IniReader::GetIntDefaultConfig("Debugging", "Init", 0)) {
|
||||
DebugTypes |= DL_INIT;
|
||||
}
|
||||
@@ -110,6 +148,22 @@ void LoggingInit() {
|
||||
if (IniReader::GetIntDefaultConfig("Debugging", "Fixes", 0)) {
|
||||
DebugTypes |= DL_FIX;
|
||||
}
|
||||
if (ConsoleWindowMode > 0) {
|
||||
if (AllocConsole()) {
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
|
||||
if (ConsoleWindowMode & 1) {
|
||||
std::cout << "Displaying debug_printf output." << std::endl;
|
||||
MakeJump(0x4C6F77, debug_printf_hack);
|
||||
}
|
||||
if (ConsoleWindowMode & 2) {
|
||||
std::cout << "Displaying sfall debug output." << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dlog_f("Console Failed: %x", DL_MAIN, GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user