-
Автор темы
- #1
Код:
local ffi = require "ffi"; do
ffi.cdef [[
typedef uintptr_t (*GetInterfaceFn)();
typedef struct {
GetInterfaceFn Interface;
char* InterfaceName;
void* NextInterface;
} CInterface;
void* GetModuleHandleA(const char*);
void* GetProcAddress(void*, const char*);
]]
end
local memory = {}; do
function memory:create_interface(module, interface_name)
local handle = ffi.C.GetModuleHandleA(module);
assert(handle ~= ffi.NULL, string.format("module %s not found", module));
local pCreateInterface = ffi.cast("int", ffi.C.GetProcAddress(handle, "CreateInterface"));
local interface = ffi.cast("CInterface***", pCreateInterface + ffi.cast("int*", pCreateInterface + 5)[0] + 15)[0][0];
while interface ~= ffi.NULL do
if string.sub(ffi.string(interface.InterfaceName), 0, -4) == interface_name or ffi.string(interface.InterfaceName) == interface_name then
return interface.Interface();
end
interface = ffi.cast("CInterface*", interface.NextInterface);
end
return 0x0
end
end
local function vtable_bind(module_name, interface_name, index, typestring)
local addr = memory:create_interface(module_name, interface_name);
assert(addr, "invalid interface");
local ctype = ffi.typeof(typestring);
local vtable = ffi.cast("void***", addr);
local vfunc = ffi.cast(ctype, vtable[0][index]);
return function(...)
return vfunc(vtable, ...);
end
end
local native_GetPlayerForUserid = vtable_bind("engine.dll", "VEngineClient014", 9, "int(__thiscall*)(void*, int)");
local native_GetLocalPlayer = vtable_bind("engine.dll", "VEngineClient014", 12, "int(__thiscall*)(void*)");
local native_ExecuteClientCmd = vtable_bind("engine.dll", "VEngineClient014", 108, "void(__thiscall*)(void*, const char*)");
local autobuy = {}; do
local context = "auto buy/master";
local ui = {}; do
ui.master = menu.add_check_box("Auto buy [ ]", "Misc/Misc", false, context);
ui.primary = menu.add_combo_box("Primary", context, { "None", "Autosnipers", "Scout", "AWP", "AK-47 / M4", "AUG / SG553", "Famas / Galil", "Negev", "M249", "MP7 / MP5", "MP9 / Mac-10", "UMP-45", "P90", "Bizon", "Nova", "XM1014", "Mag7 / Sawed-Off" });
ui.secondary = menu.add_combo_box("Secondary", context, { "None", "R8 / Deagle", "Tec-9 / Five-S / CZ-75", "P-250", "Duals" });
ui.equipment = menu.add_multi_combo_box("Equipment", context, { "Kelvar", "Helmet", "Defuser", "Taser", "HE", "Molotov", "Smoke", "Flashbang", "Decoy" });
end
autobuy.weapons = {
{ ".g3sg1;.scar20;", ".ssg08;", ".awp;", ".ak47;.m4a1;", ".aug;.sg556;", ".galilar;.famas;", ".negev;", ".m249;", ".mp7;", ".mp9;.mac10;", ".ump45;", ".p90;", ".bizon;", ".nova;", ".xm1014;", ".mag7;.sawedoff;" },
{ ".revolver;.deagle;", ".tec9;.fiveseven;", ".p250;", ".elite;" },
{ ".vest;", ".vesthelm;", ".defuser;", ".taser;", ".hegrenade;", ".molotov;.incgrenade;", ".smokegrenade;", ".flashbang;", ".decoy;" }
};
function autobuy:buy()
local primary = self.weapons[1][ui.primary:get()] or ";";
local secondary = self.weapons[2][ui.secondary:get()] or ";";
local equipment = {};
for i, item in ipairs(autobuy.weapons[3]) do
if ui.equipment:get(i - 1) then
equipment[#equipment + 1] = item
end
end
local buy = table.concat({ primary, secondary, unpack(equipment) }):gsub("%.", "buy ");
native_ExecuteClientCmd(buy)
end
ui.force_buy = menu.add_button("Buy", context, function()
autobuy:buy()
end)
function autobuy:on_player_spawn(event)
local userid = event:get_int("userid", -1)
if userid == -1 then
return
end
local index = native_GetPlayerForUserid(userid);
if index ~= native_GetLocalPlayer() then
return
end
self:buy();
end
end
register_callback("player_spawn", function(e)
autobuy:on_player_spawn(e);
end)