diff --git a/r5dev/include/opcptc.h b/r5dev/include/opcptc.h index e563def9..697374a5 100644 --- a/r5dev/include/opcptc.h +++ b/r5dev/include/opcptc.h @@ -53,7 +53,5 @@ namespace PRINT_ADDRESS("FairFight_Init", FairFight_Init.GetPtr()); PRINT_ADDRESS("Squirrel_CompileError", Squirrel_CompileError.GetPtr()); std::cout << "+--------------------------------------------------------+" << std::endl; - - // TODO implement error handling when sigscan fails or result is 0 } } diff --git a/r5dev/src/hooks/cvengineserver.cpp b/r5dev/src/hooks/cvengineserver.cpp index 0c7cad18..73b84f1f 100644 --- a/r5dev/src/hooks/cvengineserver.cpp +++ b/r5dev/src/hooks/cvengineserver.cpp @@ -21,14 +21,7 @@ bool Hooks::IsPersistenceDataAvailable(__int64 thisptr, int client) *(char*)(targetPlayerStruct + persistenceVar) = (char)0x5; if (!isPersistenceVarSet[client]) - { - printf("\n"); - printf("##################################################\n"); - printf("] SETTING PERSISTENCE VAR FOR CLIENT #%d\n", client); - printf("##################################################\n"); - printf("\n"); isPersistenceVarSet[client] = true; - } return originalIsPersistenceDataAvailable(thisptr, client); } \ No newline at end of file diff --git a/r5dev/src/hooks/msgbox.cpp b/r5dev/src/hooks/msgbox.cpp index 4592d1f1..4846a4f6 100644 --- a/r5dev/src/hooks/msgbox.cpp +++ b/r5dev/src/hooks/msgbox.cpp @@ -8,7 +8,7 @@ namespace Hooks int Hooks::MSG_EngineError(char* fmt, va_list args) { - printf("\nENGINE ERROR #####################################\n"); + std::cout << "\nENGINE ERROR #####################################\n"; vprintf(fmt, args); return originalMSG_EngineError(fmt, args); diff --git a/r5dev/src/hooks/net.cpp b/r5dev/src/hooks/net.cpp index 562894a0..21a1b259 100644 --- a/r5dev/src/hooks/net.cpp +++ b/r5dev/src/hooks/net.cpp @@ -8,8 +8,9 @@ namespace Hooks NET_SendDatagramFn originalNET_SendDatagram = nullptr; } -static std::ostringstream oss; -static auto ostream_sink = std::make_shared(oss); +static std::ostringstream oss_print; +static auto ostream_sink_print = std::make_shared(oss_print); +static auto log_sink_print = std::make_shared("logs/NET_Print.txt", true); //----------------------------------------------------------------------------- // Purpose: log the clients signonstate to the console @@ -19,19 +20,18 @@ void Hooks::NET_PrintFunc(const char* fmt, ...) static bool initialized = false; static char buf[1024]; - static auto iconsole = spdlog::stdout_logger_mt("net_iconsole"); // in-game console - static auto wconsole = spdlog::stdout_logger_mt("net_wconsole"); // windows console + oss_print.str(""); + oss_print.clear(); - oss.str(""); - oss.clear(); + static spdlog::logger logger("sqvm_print", { log_sink_print, ostream_sink_print }); if (!initialized) { - iconsole = std::make_shared("ostream", ostream_sink); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v\n"); - wconsole->set_level(spdlog::level::debug); + log_sink_print->set_level(spdlog::level::debug); + ostream_sink_print->set_level(spdlog::level::debug); + logger.set_level(spdlog::level::debug); + logger.set_pattern("[%S.%e] %v"); + initialized = true; } @@ -43,10 +43,9 @@ void Hooks::NET_PrintFunc(const char* fmt, ...) buf[sizeof(buf) - 1] = 0; va_end(args); - iconsole->debug(buf); - wconsole->debug(buf); + logger.debug(buf); - std::string s = oss.str(); + std::string s = oss_print.str(); const char* c = s.c_str(); Items.push_back(Strdup((const char*)c)); diff --git a/r5dev/src/hooks/sqvm.cpp b/r5dev/src/hooks/sqvm.cpp index 1ffba120..65b1ecc4 100644 --- a/r5dev/src/hooks/sqvm.cpp +++ b/r5dev/src/hooks/sqvm.cpp @@ -10,33 +10,32 @@ namespace Hooks static std::ostringstream oss_print; static auto ostream_sink_print = std::make_shared(oss_print); +static auto log_sink_print = std::make_shared("logs/SQVM_Print.txt", true); //--------------------------------------------------------------------------------- // Purpose: prints the output of each VM to the console //--------------------------------------------------------------------------------- void* Hooks::SQVM_Print(void* sqvm, char* fmt, ...) { - int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); static bool initialized = false; - static char buf[1024]; static std::string vmType[3] = { "Script(S):", "Script(C):", "Script(U):" }; - static auto iconsole = spdlog::stdout_logger_mt("sqvm_print_iconsole"); // in-game console - static auto wconsole = spdlog::stdout_logger_mt("sqvm_print_wconsole"); // windows console - + int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); std::string vmStr = vmType[vmIdx].c_str(); oss_print.str(""); oss_print.clear(); + static spdlog::logger logger("sqvm_print", { log_sink_print, ostream_sink_print }); + if (!initialized) { - iconsole = std::make_shared("ostream", ostream_sink_print); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v"); - wconsole->set_level(spdlog::level::debug); + log_sink_print->set_level(spdlog::level::debug); + ostream_sink_print->set_level(spdlog::level::debug); + logger.set_level(spdlog::level::debug); + logger.set_pattern("[%S.%e] %v"); + initialized = true; } @@ -50,8 +49,7 @@ void* Hooks::SQVM_Print(void* sqvm, char* fmt, ...) vmStr.append(buf); - iconsole->debug(vmStr); - wconsole->debug(vmStr); + logger.debug(vmStr); std::string s = oss_print.str(); const char* c = s.c_str(); @@ -62,6 +60,7 @@ void* Hooks::SQVM_Print(void* sqvm, char* fmt, ...) static std::ostringstream oss_warning; static auto ostream_sink_warning = std::make_shared(oss_warning); +static auto log_sink_warning = std::make_shared("logs/SQVM_Warning.txt", true); __int64 Hooks::SQVM_Warning(void* sqvm, int a2, int a3, int* stringSize, void** string) { @@ -73,33 +72,30 @@ __int64 Hooks::SQVM_Warning(void* sqvm, int a2, int a3, int* stringSize, void** return result; // If not return. static bool initialized = false; - static auto iconsole = spdlog::stdout_logger_mt("sqvm_warning_iconsole"); // in-game console - static auto wconsole = spdlog::stdout_logger_mt("sqvm_warning_wconsole"); // windows console - static std::string vmType[3] = { "Script(S) Warning:", "Script(C) Warning:", "Script(U) Warning:" }; - int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); // Get vm index. + int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); + std::string vmStr = vmType[vmIdx].c_str(); - std::string vmStr = vmType[vmIdx].c_str(); // Get string prefix for vm. + oss_print.str(""); + oss_print.clear(); - oss_warning.str(""); - oss_warning.clear(); + static spdlog::logger logger("sqvm_warning", { log_sink_warning, ostream_sink_warning }); if (!initialized) { - iconsole = std::make_shared("ostream", ostream_sink_warning); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v\n"); - wconsole->set_level(spdlog::level::debug); + log_sink_warning->set_level(spdlog::level::debug); + ostream_sink_warning->set_level(spdlog::level::debug); + logger.set_level(spdlog::level::debug); + logger.set_pattern("[%S.%e] %v"); + initialized = true; } std::string stringConstructor((char*)*string, *stringSize); // Get string from memory via std::string constructor. vmStr.append(stringConstructor); - iconsole->debug(vmStr.c_str()); - wconsole->debug(vmStr.c_str()); + logger.debug(vmStr); std::string s = oss_warning.str(); const char* c = s.c_str();