From b13f567763ee1f6b7908448f257af2bbf00404cb Mon Sep 17 00:00:00 2001 From: Kappa322 Date: Sat, 13 Feb 2021 15:46:49 +0100 Subject: [PATCH] Add ARC_LOG function --- Log.cpp | 35 ++++++++++++++++++++++++++++++++++- Log.h | 4 ++++ dllmain.cpp | 7 ++++--- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Log.cpp b/Log.cpp index 378668f..8355675 100644 --- a/Log.cpp +++ b/Log.cpp @@ -9,6 +9,10 @@ #include #include +typedef void (*E3Signature)(const char* pString); +static HMODULE ARC_DLL = LoadLibraryA("d3d9.dll"); +static E3Signature ARC_E3 = reinterpret_cast(GetProcAddress(ARC_DLL, "e3")); + void LogImplementation_(const char* pFunctionName, const char* pFormatString, ...) { char timeBuffer[128]; @@ -37,4 +41,33 @@ void LogImplementation_(const char* pFunctionName, const char* pFormatString, .. DWORD written; bool result = WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buffer, static_cast(strlen(buffer)), &written, 0); assert(result == true); -} \ No newline at end of file +} + +void LogImplementationArc_(const char* pFunctionName, const char* pFormatString, ...) +{ + char timeBuffer[128]; + int64_t milliseconds = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + int64_t seconds = milliseconds / 1000; + milliseconds = milliseconds - seconds * 1000; + int64_t writtenChars = std::strftime(timeBuffer, sizeof(timeBuffer), "%H:%M:%S", std::localtime(&seconds)); + assert(writtenChars >= 0); + + char buffer[4096]; + writtenChars = snprintf(buffer, sizeof(buffer) - 1, "%s.%lli|%s|", timeBuffer, milliseconds, pFunctionName); + assert(writtenChars >= 0); + assert(writtenChars < sizeof(buffer) - 1); + + va_list args; + va_start(args, pFormatString); + + int writtenChars2 = vsnprintf(buffer + writtenChars, sizeof(buffer) - writtenChars - 1, pFormatString, args); + assert(writtenChars2 >= 0); + assert(writtenChars2 < (sizeof(buffer) - writtenChars - 1)); + buffer[writtenChars + writtenChars2] = '\n'; + buffer[writtenChars + writtenChars2 + 1] = '\0'; + + va_end(args); + + DWORD written; + ARC_E3(buffer); +} diff --git a/Log.h b/Log.h index 49f92ba..6fa4987 100644 --- a/Log.h +++ b/Log.h @@ -9,6 +9,10 @@ #define LOG(pFormatString, ...) #endif +#define LOG_ARC(pFormatString, ...) LogImplementationArc_(__func__, pFormatString, __VA_ARGS__); if (false) { printf(pFormatString, __VA_ARGS__); } + + void LogImplementation_(const char* pFunctionName, const char* pFormatString, ...); +void LogImplementationArc_(const char* pFunctionName, const char* pFormatString, ...); #define BOOL_STR(pBool) pBool == true ? "true" : "false" diff --git a/dllmain.cpp b/dllmain.cpp index f44f37d..710cb4f 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -36,9 +36,10 @@ uintptr_t mod_combat(cbtevent* ev, ag* src, ag* dst, const char* skillname, uint uintptr_t mod_combat_local(cbtevent* ev, ag* src, ag* dst, const char* skillname, uint64_t id, uint64_t revision); uintptr_t mod_wnd(HWND pWindowHandle, UINT pMessage, WPARAM pAdditionalW, LPARAM pAdditionalL); -typedef uint64_t(*ArcExportFunction)(); -HMODULE ARC_DLL = LoadLibraryA("d3d9.dll"); -ArcExportFunction ARC_E7 = reinterpret_cast(GetProcAddress(ARC_DLL, "e7")); +typedef uint64_t(*E7Signature)(); +static HMODULE ARC_DLL = LoadLibraryA("d3d9.dll"); +static E7Signature ARC_E7 = reinterpret_cast(GetProcAddress(ARC_DLL, "e7")); + std::mutex HEAL_TABLE_OPTIONS_MUTEX; static HealTableOptions HEAL_TABLE_OPTIONS;