From c3820206356cf4755d074f4bc480ab49949cedc1 Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Tue, 28 Dec 2021 01:15:12 +0100 Subject: [PATCH] Implement QHull print function properly Never seems to be called, but the function body was wrong. --- r5dev/core/logdef.h | 12 ++++++---- r5dev/vphysics/QHull.cpp | 52 ++++++++++++++++++++++++++++++---------- r5dev/vphysics/QHull.h | 15 ++++++------ 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/r5dev/core/logdef.h b/r5dev/core/logdef.h index 7a58613e..83d09dee 100644 --- a/r5dev/core/logdef.h +++ b/r5dev/core/logdef.h @@ -3,12 +3,12 @@ //------------------------------------------------------------------------- // NETCHAN | inline auto g_spd_netchan_logger = spdlog::basic_logger_mt("netchan_logger", "platform\\logs\\net_trace.log"); -static std::ostringstream g_spd_net_p_oss; -static auto g_spd_net_p_ostream_sink = std::make_shared(g_spd_net_p_oss); +inline std::ostringstream g_spd_net_p_oss; +inline auto g_spd_net_p_ostream_sink = std::make_shared(g_spd_net_p_oss); //------------------------------------------------------------------------- // FILESYSTEM | -static std::ostringstream fs_oss; -static auto fs_ostream_sink = std::make_shared(fs_oss); +inline std::ostringstream fs_oss; +inline auto fs_ostream_sink = std::make_shared(fs_oss); //------------------------------------------------------------------------- // SQUIRREL PRINTF | inline std::ostringstream g_spd_sqvm_p_oss; @@ -21,3 +21,7 @@ inline auto g_spd_sqvm_w_ostream_sink = std::make_shared(g_spd_sys_w_oss); +//------------------------------------------------------------------------- +// QHULL PRINTF | +inline std::ostringstream g_spd_qhull_p_w_oss; +inline auto g_spd_qhull_p_ostream_sink = std::make_shared(g_spd_qhull_p_w_oss); diff --git a/r5dev/vphysics/QHull.cpp b/r5dev/vphysics/QHull.cpp index b518c7ae..8cd91fb7 100644 --- a/r5dev/vphysics/QHull.cpp +++ b/r5dev/vphysics/QHull.cpp @@ -1,28 +1,56 @@ #include "core/stdafx.h" +#include "core/logdef.h" #include "vphysics/QHull.h" //----------------------------------------------------------------------------- // Purpose: qhull error and debug prints //----------------------------------------------------------------------------- -int HQHull_PrintError(char* fmt, va_list args) +int HQHull_PrintFunc(const char* fmt, ...) { - vprintf(fmt, args); - return QHull_PrintError(fmt, args); + static bool initialized = false; + static char buf[1024]; + + static auto iconsole = spdlog::stdout_logger_mt("qhull_print_iconsole"); // in-game console. + static auto wconsole = spdlog::stdout_logger_mt("qhull_print_wconsole"); // windows console. + static auto qhlogger = spdlog::basic_logger_mt("qhull_print_logger", "platform\\logs\\qhull_print.log"); // file logger. + + g_spd_sqvm_p_oss.str(""); + g_spd_sqvm_p_oss.clear(); + + if (!initialized) + { + iconsole = std::make_shared("qhull_print_ostream", g_spd_sqvm_p_ostream_sink); + iconsole->set_pattern("[%S.%e] %v"); + iconsole->set_level(spdlog::level::debug); + wconsole->set_pattern("[%S.%e] %v"); + wconsole->set_level(spdlog::level::debug); + qhlogger->set_pattern("[%S.%e] %v"); + qhlogger->set_level(spdlog::level::debug); + initialized = true; + } + + va_list args; + va_start(args, fmt); + + vsnprintf(buf, sizeof(buf), fmt, args); + + buf[sizeof(buf) - 1] = 0; + va_end(args); + + qhlogger->debug(buf); + iconsole->debug(buf); + wconsole->debug(buf); + + return NULL; } -int HQHull_PrintDebug(char* fmt, va_list args) -{ - vprintf(fmt, args); - return QHull_PrintDebug(fmt, args); -} +/////////////////////////////////////////////////////////////////////////////// void QHull_Attach() { - DetourAttach((LPVOID*)&QHull_PrintDebug, &HQHull_PrintDebug); - DetourAttach((LPVOID*)&QHull_PrintError, &HQHull_PrintError); + DetourAttach((LPVOID*)&QHull_PrintFunc, &HQHull_PrintFunc); } void QHull_Detach() { - DetourDetach((LPVOID*)&QHull_PrintDebug, &HQHull_PrintDebug); - DetourDetach((LPVOID*)&QHull_PrintError, &HQHull_PrintError); + DetourDetach((LPVOID*)&QHull_PrintFunc, &HQHull_PrintFunc); } diff --git a/r5dev/vphysics/QHull.h b/r5dev/vphysics/QHull.h index 79988035..204b7ad4 100644 --- a/r5dev/vphysics/QHull.h +++ b/r5dev/vphysics/QHull.h @@ -2,16 +2,15 @@ namespace { - ADDRESS p_QHull_PrintError = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x4C\x24\x08\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\xB8\x40\x27\x00\x00\x00\x00\x00\x00\x00\x48", "xxxxxxxxxxxxxxxxxxxxxxxxxx????xx"); - int (*QHull_PrintError)(char* fmt, va_list args) = (int (*)(char*, va_list))p_QHull_PrintError.GetPtr(); /*48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 B8 40 27 00 00 ?? ?? ?? ?? 00 48*/ + ADDRESS p_QHull_PrintFunc = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x4C\x24\x08\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\xB8\x40\x27\x00\x00\x00\x00\x00\x00\x00\x48", "xxxxxxxxxxxxxxxxxxxxxxxxxx????xx"); + int (*QHull_PrintFunc)(const char* fmt, ...) = (int (*)(const char* fmt, ...))p_QHull_PrintFunc.GetPtr(); /*48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 B8 40 27 00 00 ?? ?? ?? ?? 00 48*/ - ADDRESS p_QHull_PrintDebug = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\x56\x57\x48\x83\xEC\x30\x48\x8B\xFA\x48\x8D\x74\x24\x60\x48\x8B", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - int (*QHull_PrintDebug)(char* fmt, va_list args) = (int (*)(char*, va_list))p_QHull_PrintDebug.GetPtr(); /*48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 56 57 48 83 EC 30 48 8B FA 48 8D 74 24 60 48 8B*/ + //ADDRESS p_speex_warning_int = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\x56\x57\x48\x83\xEC\x30\x48\x8B\xFA\x48\x8D\x74\x24\x60\x48\x8B", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + //int (*speex_warning_int)(int a1, const char* fmt, ...) = (int (*)(int a1, const char* fmt, ...))p_speex_warning_int.GetPtr(); /*48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 56 57 48 83 EC 30 48 8B FA 48 8D 74 24 60 48 8B*/ } /////////////////////////////////////////////////////////////////////////////// -int HQHull_PrintError(char* fmt, va_list args); -int HQHull_PrintDebug(char* fmt, va_list args); +int HQHull_PrintFunc(const char* fmt, ...); void QHull_Attach(); void QHull_Detach(); @@ -21,8 +20,8 @@ class HQHull : public IDetour { virtual void debugp() { - std::cout << "| FUN: QHull_PrintError : 0x" << std::hex << std::uppercase << p_QHull_PrintError.GetPtr() << std::setw(npad) << " |" << std::endl; - std::cout << "| FUN: QHull_PrintDebug : 0x" << std::hex << std::uppercase << p_QHull_PrintDebug.GetPtr() << std::setw(npad) << " |" << std::endl; + std::cout << "| FUN: QHull_PrintFunc : 0x" << std::hex << std::uppercase << p_QHull_PrintFunc.GetPtr() << std::setw(npad) << " |" << std::endl; + //std::cout << "| FUN: speex_warning_int : 0x" << std::hex << std::uppercase << p_speex_warning_int.GetPtr() << std::setw(npad) << " |" << std::endl; std::cout << "+----------------------------------------------------------------+" << std::endl; } };