Skip to content

Commit

Permalink
Add ARC_LOG function
Browse files Browse the repository at this point in the history
  • Loading branch information
Krappa322 committed Feb 13, 2021
1 parent d74f262 commit b13f567
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
35 changes: 34 additions & 1 deletion Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <chrono>
#include <ctime>

typedef void (*E3Signature)(const char* pString);
static HMODULE ARC_DLL = LoadLibraryA("d3d9.dll");
static E3Signature ARC_E3 = reinterpret_cast<E3Signature>(GetProcAddress(ARC_DLL, "e3"));

void LogImplementation_(const char* pFunctionName, const char* pFormatString, ...)
{
char timeBuffer[128];
Expand Down Expand Up @@ -37,4 +41,33 @@ void LogImplementation_(const char* pFunctionName, const char* pFormatString, ..
DWORD written;
bool result = WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buffer, static_cast<DWORD>(strlen(buffer)), &written, 0);
assert(result == true);
}
}

void LogImplementationArc_(const char* pFunctionName, const char* pFormatString, ...)
{
char timeBuffer[128];
int64_t milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(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);
}
4 changes: 4 additions & 0 deletions Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 4 additions & 3 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArcExportFunction>(GetProcAddress(ARC_DLL, "e7"));
typedef uint64_t(*E7Signature)();
static HMODULE ARC_DLL = LoadLibraryA("d3d9.dll");
static E7Signature ARC_E7 = reinterpret_cast<E7Signature>(GetProcAddress(ARC_DLL, "e7"));


std::mutex HEAL_TABLE_OPTIONS_MUTEX;
static HealTableOptions HEAL_TABLE_OPTIONS;
Expand Down

0 comments on commit b13f567

Please sign in to comment.