Code:
#include <cstdint>
#include <string>
#include <windows.h>
#define X3_NOT_INITIALIZED -536805375
typedef int32_t(__stdcall *t_x3_Dispatch)(OUT void *Function, IN uint32_t Type);
static t_x3_Dispatch o_x3_Dispatch = nullptr;
void __stdcall DllMain()
{
// add here your code
}
__declspec(dllexport) int32_t __stdcall x3_1(void *FunctionAddress, uint32_t Type)
{
if (o_x3_Dispatch == nullptr)
{
std::string ModulePath;
ModulePath.resize(MAX_PATH);
if (!GetModuleFileNameA(NULL, const_cast<LPSTR>(ModulePath.data()), MAX_PATH))
{
MessageBoxA(0, "GetModuleFileNameA failed!", "Error", 0);
return X3_NOT_INITIALIZED;
}
std::string S4_Folder = ModulePath.substr(0, ModulePath.find_last_of("\\"));
S4_Folder += "\\xigncode\\x3.dummy";
HMODULE hX3 = LoadLibraryA(S4_Folder.c_str());
if (hX3 == nullptr)
{
MessageBoxA(0, "LoadLibraryA failed!", "Error", 0);
return X3_NOT_INITIALIZED;
}
o_x3_Dispatch = reinterpret_cast<t_x3_Dispatch>(GetProcAddress(hX3, reinterpret_cast<LPCSTR>(1)));
if (o_x3_Dispatch == nullptr)
{
MessageBoxA(0, "GetProcAddress failed!", "Error", 0);
return X3_NOT_INITIALIZED;
}
DllMain();
}
return o_x3_Dispatch(FunctionAddress, Type);
}