local vtable = {}
local __thiscall = function(func, this)
return function(...) return func(this, ...) end
end
local interface_ptr = ffi.typeof("void***")
vtable.bind = function(module, interface, index, typedef)
local addr = ffi.cast("void***", utils.create_interface(module, interface)) or error(interface .. " was not found")
return __thiscall(ffi.cast(typedef, addr[0][index]), addr)
end
vtable.entry = function(instance, i, ct)
return ffi.cast(ct, ffi.cast(interface_ptr, instance)[0][i])
end
local MaterialAdapterInfo_t = ffi.typeof([[
struct {
char m_pDriverName[512];
unsigned int m_VendorID;
unsigned int m_DeviceID;
unsigned int m_SubSysID;
unsigned int m_Revision;
int m_nDXSupportLevel;
int m_nMinDXSupportLevel;
int m_nMaxDXSupportLevel;
unsigned int m_nDriverVersionHigh;
unsigned int m_nDriverVersionLow;
}
]])
local get_current_adapter = vtable.bind('materialsystem.dll', 'VMaterialSystem080', 25, 'int(__thiscall*)(void*)')
local get_adapter_info = vtable.bind('materialsystem.dll', 'VMaterialSystem080', 26, 'void(__thiscall*)(void*, int, void*)')
local current_adapter = get_current_adapter()
local adapter_struct = ffi.new(MaterialAdapterInfo_t)
get_adapter_info(current_adapter, adapter_struct)
local driverName = tostring(ffi.string(adapter_struct['m_pDriverName']))