Advertisement
Guest User

FFI AutoBuy

a guest
Apr 7th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. local ffi = require("ffi")
  2.     function vmt_entry(instance, index, type)
  3.         return ffi.cast(type, (ffi.cast("void***", instance)[0])[index])
  4.     end
  5.  
  6.     function vmt_thunk(index, typestring)
  7.         local t = ffi.typeof(typestring)
  8.         return function(instance, ...)
  9.             assert(instance ~= nil)
  10.             if instance then
  11.                 return vmt_entry(instance, index, t)(instance, ...)
  12.             end
  13.         end
  14.     end
  15.  
  16.     function vmt_bind(module, interface, index, typestring)
  17.         local instance = client.create_interface(module, interface) or error("invalid interface")
  18.         local fnptr = vmt_entry(instance, index, ffi.typeof(typestring)) or error("invalid vtable")
  19.         return function(...)
  20.             return fnptr(instance, ...)
  21.         end
  22.     end
  23.  
  24.     native_GetNetChannelInfo = vmt_bind("engine.dll", "VEngineClient014", 78, "void*(__thiscall*)(void*)")
  25.     local native_GetName = vmt_thunk(0, "const char*(__thiscall*)(void*)")
  26.     local native_GetAddress = vmt_thunk(1, "const char*(__thiscall*)(void*)")
  27.     native_IsLoopback = vmt_thunk(6, "bool(__thiscall*)(void*)")
  28.     local native_IsTimingOut = vmt_thunk(7, "bool(__thiscall*)(void*)")
  29.     native_GetAvgLoss = vmt_thunk(11, "float(__thiscall*)(void*, int)")
  30.     native_GetAvgChoke = vmt_thunk(12, "float(__thiscall*)(void*, int)")
  31.     native_GetTimeSinceLastReceived = vmt_thunk(22, "float(__thiscall*)(void*)")
  32.     local native_GetRemoteFramerate = vmt_thunk(25, "void(__thiscall*)(void*, float*, float*, float*)")
  33.     local native_GetTimeoutSeconds = vmt_thunk(26, "float(__thiscall*)(void*)")
  34.  
  35.     local pflFrameTime = ffi.new("float[1]")
  36.     local pflFrameTimeStdDeviation = ffi.new("float[1]")
  37.     local pflFrameStartTimeStdDeviation = ffi.new("float[1]")
  38.  
  39.     function GetRemoteFramerate(netchannelinfo)
  40.         native_GetRemoteFramerate(netchannelinfo, pflFrameTime, pflFrameTimeStdDeviation, pflFrameStartTimeStdDeviation)
  41.         if pflFrameTime ~= nil and pflFrameTimeStdDeviation ~= nil and pflFrameStartTimeStdDeviation ~= nil then
  42.             return pflFrameTime[0], pflFrameTimeStdDeviation[0], pflFrameStartTimeStdDeviation[0]
  43.         end
  44.     end
  45.  
  46.     function GetAddress(netchannelinfo)
  47.         local addr = native_GetAddress(netchannelinfo)
  48.         if addr ~= nil then
  49.             return ffi.string(addr)
  50.         end
  51.     end
  52.  
  53.     function GetName(netchannelinfo)
  54.         local name = native_GetName(netchannelinfo)
  55.         if name ~= nil then
  56.             return ffi.string(name)
  57.         end
  58.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement