Skip to content

Commit

Permalink
Use get_init_addr HMODULE to discover arcdps exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Krappa322 committed Feb 13, 2021
1 parent 59b43fa commit 2e9c7da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
8 changes: 7 additions & 1 deletion ArcDPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ typedef struct ag {
uint32_t elite; /* elite spec at time of event. refer to evtc notes for identification */
uint32_t self; /* 1 if self, 0 if not */
uint16_t team; /* sep21+ */
} ag;
} ag;

typedef uint64_t(*E7Signature)();
static inline E7Signature ARC_E7 = nullptr;

typedef void (*E3Signature)(const char* pString);
static inline E3Signature ARC_E3 = nullptr;
11 changes: 7 additions & 4 deletions Log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Log.h"

#include "ArcDPS.h"

#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
Expand All @@ -9,10 +11,6 @@
#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 @@ -45,6 +43,11 @@ void LogImplementation_(const char* pFunctionName, const char* pFormatString, ..

void LogImplementationArc_(const char* pFunctionName, const char* pFormatString, ...)
{
if (ARC_E3 == nullptr)
{
return;
}

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;
Expand Down
16 changes: 9 additions & 7 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ char* arcvers;

void dll_init(HANDLE hModule);
void dll_exit();
extern "C" __declspec(dllexport) void* get_init_addr(char* arcversionstr, void* imguicontext, IDirect3DDevice9 * id3dd9);
extern "C" __declspec(dllexport) void* get_init_addr(char* arcversionstr, void* imguicontext, IDirect3DDevice9 * id3dd9, HMODULE pArcModule);
extern "C" __declspec(dllexport) void* get_release_addr();
arcdps_exports* mod_init();
uintptr_t mod_release();
Expand All @@ -36,11 +36,6 @@ 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(*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 All @@ -67,9 +62,16 @@ void dll_exit() {
}

/* export -- arcdps looks for this exported function and calls the address it returns on client load */
extern "C" __declspec(dllexport) void* get_init_addr(char* arcversionstr, void* imguicontext, IDirect3DDevice9 * id3dd9) {
extern "C" __declspec(dllexport) void* get_init_addr(char* arcversionstr, void* imguicontext, IDirect3DDevice9 * id3dd9, HMODULE pArcModule)
{
ARC_E7 = reinterpret_cast<E7Signature>(GetProcAddress(pArcModule, "e7"));
assert(ARC_E7 != nullptr);
ARC_E3 = reinterpret_cast<E3Signature>(GetProcAddress(pArcModule, "e3"));
assert(ARC_E3 != nullptr);

arcvers = arcversionstr;
SetContext(imguicontext);

return mod_init;
}

Expand Down

0 comments on commit 2e9c7da

Please sign in to comment.