Skip to content

Commit 6fd50be

Browse files
Kenzzerpsychonic
authored andcommitted
requested changes
1 parent 7ce3c45 commit 6fd50be

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

core/metamod.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static ConVar *mm_basedir = NULL;
124124
static CreateInterfaceFn engine_factory = NULL;
125125
static CreateInterfaceFn physics_factory = NULL;
126126
static CreateInterfaceFn filesystem_factory = NULL;
127-
#if !defined( PLATFORM_64BITS ) && !defined( _LINUX )
127+
#if !defined( __amd64__ )
128128
static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
129129
#endif
130130
static META_RES last_meta_res;
@@ -414,20 +414,43 @@ FileSystemFactory(const char *iface, int *ret)
414414
IFACE_MACRO(filesystem_factory, FileSystem);
415415
}
416416

417+
template<typename T>
418+
class SaveAndSet {
419+
public:
420+
SaveAndSet(T* location, const T& value)
421+
: location_(location),
422+
old_(*location)
423+
{
424+
*location_ = value;
425+
}
426+
~SaveAndSet() {
427+
*location_ = old_;
428+
}
429+
430+
private:
431+
T* location_;
432+
T old_;
433+
};
434+
417435
void
418436
mm_LogMessage(const char *msg, ...)
419437
{
420438
static bool g_logging = false;
421439
if (g_logging) {
422440
return;
423441
}
424-
g_logging = true;
442+
SaveAndSet<bool>(&g_logging, true);
443+
425444
va_list ap;
426445
static char buffer[2048];
427446

428447
va_start(ap, msg);
429448
size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
430-
len = std::min<size_t>(len, 2046);
449+
len = std::min<size_t>(len, sizeof(buffer) - 2);
450+
if (len < 0) {
451+
return;
452+
}
453+
431454
va_end(ap);
432455

433456
buffer[len++] = '\n';
@@ -438,7 +461,6 @@ mm_LogMessage(const char *msg, ...)
438461
fprintf(stdout, "%s", buffer);
439462
}
440463
provider->ConsolePrint(buffer);
441-
g_logging = false;
442464
}
443465

444466
static void

0 commit comments

Comments
 (0)