From 6fd50bebc708b4abbbff8702121614731571f247 Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Wed, 5 Jun 2024 19:12:24 +0200 Subject: [PATCH] requested changes --- core/metamod.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/core/metamod.cpp b/core/metamod.cpp index 78a8a8e..3b2cbc3 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -124,7 +124,7 @@ static ConVar *mm_basedir = NULL; static CreateInterfaceFn engine_factory = NULL; static CreateInterfaceFn physics_factory = NULL; static CreateInterfaceFn filesystem_factory = NULL; -#if !defined( PLATFORM_64BITS ) && !defined( _LINUX ) +#if !defined( __amd64__ ) static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook); #endif static META_RES last_meta_res; @@ -414,6 +414,24 @@ FileSystemFactory(const char *iface, int *ret) IFACE_MACRO(filesystem_factory, FileSystem); } +template +class SaveAndSet { +public: + SaveAndSet(T* location, const T& value) + : location_(location), + old_(*location) + { + *location_ = value; + } + ~SaveAndSet() { + *location_ = old_; + } + +private: + T* location_; + T old_; +}; + void mm_LogMessage(const char *msg, ...) { @@ -421,13 +439,18 @@ mm_LogMessage(const char *msg, ...) if (g_logging) { return; } - g_logging = true; + SaveAndSet(&g_logging, true); + va_list ap; static char buffer[2048]; va_start(ap, msg); size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap); - len = std::min(len, 2046); + len = std::min(len, sizeof(buffer) - 2); + if (len < 0) { + return; + } + va_end(ap); buffer[len++] = '\n'; @@ -438,7 +461,6 @@ mm_LogMessage(const char *msg, ...) fprintf(stdout, "%s", buffer); } provider->ConsolePrint(buffer); - g_logging = false; } static void