Move interface stuff to utility file.
* Alternative method to using dlopen and dlsym. * Accepts partial version strings. Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
parent
5e10af4344
commit
27eb1e65e2
|
@ -1,11 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
typedef void* (*CreateInterfaceFn) (const char*, int*);
|
|
||||||
typedef void* (*InstantiateInterfaceFn) ();
|
|
||||||
|
|
||||||
class InterfaceReg {
|
|
||||||
public:
|
|
||||||
InstantiateInterfaceFn m_CreateFn;
|
|
||||||
const char* m_pName;
|
|
||||||
InterfaceReg* m_pNext;
|
|
||||||
};
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef void* (*InstantiateInterfaceFn) ();
|
||||||
|
|
||||||
|
class InterfaceReg {
|
||||||
|
public:
|
||||||
|
InstantiateInterfaceFn m_CreateFn;
|
||||||
|
const char* m_pName;
|
||||||
|
InterfaceReg* m_pNext;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline const InterfaceReg* GetInterfaces(const char* library) {
|
||||||
|
// Find the pointer to the 'InterfaceReg::s_pInterfaceRegs' linked list - same on all game libraries.
|
||||||
|
uintptr_t interface_list_addr = FindPattern(library, "\x89\x10\x8B\x15\x00\x00\x00\x00\xA3", "xxxx????x");
|
||||||
|
|
||||||
|
if (interface_list_addr)
|
||||||
|
return **reinterpret_cast<InterfaceReg***>(interface_list_addr + 4);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> inline T* GetInterface(const char* library, const char* partial_version) {
|
||||||
|
for (const InterfaceReg* current = GetInterfaces(library); current; current = current->m_pNext) {
|
||||||
|
if (std::string(current->m_pName).find(partial_version) != std::string::npos) {
|
||||||
|
return reinterpret_cast<T*>(current->m_CreateFn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
Loading…
Reference in New Issue