diff --git a/dll/base.cpp b/dll/base.cpp index 7a69f0a..e11355c 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -18,6 +18,42 @@ #include "base.h" #ifdef STEAM_WIN32 + +#ifndef EMU_RELEASE_BUILD +#ifdef VS_TRACE_DEBUG +#include + +// Visual Studio doesn't seem to support hh* or ll* in OutputDebugString +// So process it before sending it to debug console +bool _trace(const char* format, ...) +{ + constexpr const int len = 1024; // Initial buffer size, hope it is big enought, we will exapnd it if not. + int res; + char *buffer = new char[len]; + + va_list argptr; + va_start(argptr, format); + res = vsnprintf(buffer, len, format, argptr); + va_end(argptr); + if (res >= len) + { + delete[]buffer; + // Now we are sure we have enought free space to contain the string + buffer = new char[++res]; + va_start(argptr, format); + vsnprintf(buffer, res, format, argptr); + va_end(argptr); + } + + OutputDebugString(buffer); + delete[]buffer; + + return true; +} +#endif // VS_TRACE_DEBUG +#endif // EMU_RELEASE_BUILD + + #include #include diff --git a/dll/base.h b/dll/base.h index 5999799..66dd53f 100644 --- a/dll/base.h +++ b/dll/base.h @@ -44,7 +44,12 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; #define PATH_SEPARATOR "\\" #ifndef EMU_RELEASE_BUILD +#ifdef VS_TRACE_DEBUG +bool _trace(const char* format, ...); +#define PRINT_DEBUG(FMT, ...) _trace(FMT, ##__VA_ARGS__) +#else // VS_TRACE_DEBUG #define PRINT_DEBUG(a, ...) do {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t); WSASetLastError(0);} while (0) +#endif // VS_TRACE_DEBUG #endif #else #include