Skip to content

Commit 0b2c9ac

Browse files
committed
Add a way to retrieve some global methods directly from Core module.
1 parent 644c8cd commit 0b2c9ac

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

include/classicspatch_api.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,48 @@ class IClassicsPatchAPI
102102
// Retrieve pointer to the main virtual interface
103103
PATCH_API IClassicsPatchAPI *PATCH_CALLTYPE ClassicsPatchAPI(void);
104104

105+
// Pointers to extra functions that aren't available through the main virtual interface
106+
struct ClassicsPatchGlobalFunctions
107+
{
108+
typedef EVerifyAPIResult (PATCH_CALLTYPE *FVerifyInternal)(PatchVer_t, ClassicsPatchErrMsg *);
109+
typedef bool (PATCH_CALLTYPE *FIsRunning)(void);
110+
typedef void (PATCH_CALLTYPE *FSetup)(EClassicsPatchAppType);
111+
typedef void (PATCH_CALLTYPE *FInit)(void);
112+
typedef void (PATCH_CALLTYPE *FShutdown)(void);
113+
114+
FVerifyInternal _VerifyInternal;
115+
FIsRunning _IsRunning;
116+
FSetup _Setup;
117+
FInit _Init;
118+
FShutdown _Shutdown;
119+
120+
// Simple wrapper for ClassicsPatchAPI_Verify()
121+
inline EVerifyAPIResult _Verify(ClassicsPatchErrMsg *pOutErrMsg) {
122+
return _VerifyInternal(CLASSICSPATCH_INTERFACE_VERSION, pOutErrMsg);
123+
};
124+
};
125+
126+
// Retrieve pointers to some global functions directly from the module
127+
// This function should be used when the library cannot be directly linked, like this:
128+
// ClassicsPatchGlobalFunctions functions;
129+
//
130+
// if (ClassicsPatch_GetGlobalFunctionsFromModule(&functions)) {
131+
// // Call functions by pointers from the struct
132+
// }
133+
inline bool ClassicsPatch_GetGlobalFunctionsFromModule(ClassicsPatchGlobalFunctions *pFunctions) {
134+
HMODULE hCore = GetModuleHandleA("ClassicsCore.dll");
135+
136+
if (hCore != NULL) {
137+
pFunctions->_VerifyInternal = (ClassicsPatchGlobalFunctions::FVerifyInternal)GetProcAddress(hCore, "ClassicsPatchAPI_VerifyInternal");
138+
pFunctions->_IsRunning = (ClassicsPatchGlobalFunctions::FIsRunning)GetProcAddress(hCore, "ClassicsPatchAPI_IsRunning");
139+
pFunctions->_Setup = (ClassicsPatchGlobalFunctions::FSetup)GetProcAddress(hCore, "ClassicsPatch_Setup");
140+
pFunctions->_Init = (ClassicsPatchGlobalFunctions::FInit)GetProcAddress(hCore, "ClassicsPatch_Init");
141+
pFunctions->_Shutdown = (ClassicsPatchGlobalFunctions::FShutdown)GetProcAddress(hCore, "ClassicsPatch_Shutdown");
142+
143+
return true;
144+
}
145+
146+
return false;
147+
};
148+
105149
#endif // CLASSICSPATCH_API_H

0 commit comments

Comments
 (0)