local ffi = require 'ffi'
ffi.cdef[[
typedef void (__thiscall *ApplyNetworkSimulator)(void* CRakPeer_this, double maxSendBPS, unsigned short minExtraPing, unsigned short extraPingVariance);
typedef void* HANDLE;
typedef uint32_t DWORD;
typedef int BOOL;
HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
int CloseHandle(HANDLE hObject);
HANDLE GetModuleHandleA(const char* lpModuleName);
int VirtualQueryEx(HANDLE hProcess, const void* lpAddress, void* lpBuffer, size_t dwLength);
int ReadProcessMemory(HANDLE hProcess, const void* lpBaseAddress, void* lpBuffer, size_t nSize, size_t* lpNumberOfBytesRead);
DWORD GetCurrentProcessId(void);
typedef struct {
void* BaseAddress;
void* AllocationBase;
DWORD AllocationProtect;
size_t RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION;
]]
function findSignatureInModule(signature, moduleName)
local moduleAddress = ffi.C.GetModuleHandleA(moduleName)
if moduleAddress == nil then
return nil, "Module not found"
end
local processId = ffi.C.GetCurrentProcessId()
local hProcess = ffi.C.OpenProcess(0x1F0FFF, 0, processId)
local moduleInfo = ffi.new("MEMORY_BASIC_INFORMATION")
local address = moduleAddress
local signatureBytes = {}
for byte in signature:gmatch("%S+") do
if byte == "??" then
table.insert(signatureBytes, false)
else
table.insert(signatureBytes, tonumber(byte, 16))
end
end
while ffi.C.VirtualQueryEx(hProcess, address, moduleInfo, ffi.sizeof(moduleInfo)) ~= 0 do
if moduleInfo.State == 0x1000 and moduleInfo.Protect == 0x20 then
local size = tonumber(moduleInfo.RegionSize)
local buffer = ffi.new("uint8_t[?]", size)
local bytesRead = ffi.new("size_t[1]")
ffi.C.ReadProcessMemory(hProcess, address, buffer, size, bytesRead)
for i = 0, size - #signatureBytes do
local found = true
for j = 1, #signatureBytes do
local byte = buffer[i + j - 1]
if signatureBytes[j] ~= false and byte ~= signatureBytes[j] then
found = false
break
end
end
if found then
ffi.C.CloseHandle(hProcess)
return ffi.cast("intptr_t", address) + i
end
end
end
address = ffi.cast("void*", ffi.cast("intptr_t", address) + moduleInfo.RegionSize)
end
ffi.C.CloseHandle(hProcess)
return nil, "Signature not found"
end
local state = false
function main()
repeat wait(0) until isSampAvailable()
local applyNetworkSimulator = ffi.cast('ApplyNetworkSimulator', findSignatureInModule("8B 44 24 10 DD 44 24 04 8B 54 24 0C 50 52 83 EC 08 DD", 'samp.dll'))
sampRegisterChatCommand("pl", function()
state = not state
applyNetworkSimulator(ffi.cast('void*', sampGetRakpeer()), state and 6 * 100000 or 9999999, 0, 0)
printStringNow(state and '~g~activated' or '~r~disabled', 1500)
end)
wait(-1)
end