diff --git a/include/cstrike/Classes/Interface.h b/include/cstrike/Classes/Interface.h deleted file mode 100644 index f1d4ecf..0000000 --- a/include/cstrike/Classes/Interface.h +++ /dev/null @@ -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; -}; \ No newline at end of file diff --git a/src/Utilities/Interfaces.h b/src/Utilities/Interfaces.h new file mode 100644 index 0000000..7664f96 --- /dev/null +++ b/src/Utilities/Interfaces.h @@ -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(interface_list_addr + 4); + + return nullptr; +} + +template 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(current->m_CreateFn()); + } + } + + return nullptr; +} \ No newline at end of file