local ffi = require("ffi")
local origignalCallBitStreamWriteBits
local pvRakClient
local CRakClientGetAveragePing = ffi.cast("int(__thiscall*)(void* this)", 0x404290)
local fakePing = 228
local callHook = {hooks = {}}
ffi.cdef[[
int VirtualProtect(void* lpAddress, unsigned long dwSize, unsigned long flNewProtect, unsigned long* lpflOldProtect);
]]
local function callBitStreamWriteBits(this, data, size, rightAlignedBits)
local sendPingTime = ffi.cast("unsigned int*", data) -- кастуем байтики в значение
local averagePing = CRakClientGetAveragePing(pvRakClient) -- получаем наш средний пинг
sendPingTime[0] = (sendPingTime[0] + (averagePing - fakePing)) -- жоска формула изменения пинга1337
return origignalCallBitStreamWriteBits(this, data, size, rightAlignedBits)
end
registerHandler("onLoad", function()
pvRakClient = ffi.cast("void*", tonumber(ffi.cast("uintptr_t*", 0x4D369C)[0])) -- получаем указатель на РАКЛИЕНТИИИИК
origignalCallBitStreamWriteBits = callHook:new(
"void(__thiscall*)(void *this, uint8_t *data, unsigned int size, char rightAlignedBits)",
callBitStreamWriteBits, 0x40C797
) -- ставим хук на запись пинга в пакет
end)
registerHandler("onUnload", function()
for _, hook in ipairs(callHook.hooks) do -- выгружаем хуки
if hook.status then hook.stop() end
end
end)
function callHook:new(cast, callback, hook_addr)
--[[
AUTHOR: RTD/RutreD(https://www.blast.hk/members/126461/)
]]
if ffi.cast("uint8_t*", hook_addr)[0] ~= 0xE8 then return end
jit.off(callback, true) --off jit compilation | thx FYP
local new_hook = {}
local detour_addr = tonumber(ffi.cast("intptr_t", ffi.cast(cast, callback)))
local void_addr = ffi.cast("void*", hook_addr)
local old_prot = ffi.new("unsigned long[1]")
local org_bytes = ffi.new("uint8_t[?]", 5)
ffi.copy(org_bytes, void_addr, 5)
local hook_bytes = ffi.new("uint8_t[?]", 5, 0xE8)
ffi.cast("uint32_t*", hook_bytes + 1)[0] = detour_addr - hook_addr - 5
new_hook.call = ffi.cast(cast, ffi.cast("intptr_t*", hook_addr + 1)[0] + hook_addr + 5)
new_hook.status = false
local function set_status(bool)
new_hook.status = bool
ffi.C.VirtualProtect(void_addr, 5, 0x40, old_prot)
ffi.copy(void_addr, bool and hook_bytes or org_bytes, 5)
ffi.C.VirtualProtect(void_addr, 5, old_prot[0], old_prot)
end
new_hook.stop = function() set_status(false) end
new_hook.start = function() set_status(true) end
new_hook.start()
table.insert(self.hooks, new_hook)
return setmetatable(new_hook, {
__call = function(self, ...)
local res = self.call(...)
return res
end
})
end