local ffi = require("ffi")
local hook = require("hooks")
local _AddChatEntry
local samp_dll = getModuleHandle("samp.dll")
function init()
print('loaded')
wait(1)
end
function ChatEntryHandler(self, messageType, messageText, prefixText, msgColor, prefixTextColor)
if (messageType == 4) then
local text = ffi.string(messageText)
local clean_text = removeColorCodes(text)
if clean_text:find('You are now AFK, use') then
local afkCommand = clean_text:match("You are now AFK, use '/afk (.+)' to exit AFK mode and resume playing!")
SendCommand('/afk ' .. afkCommand)
end
end
return _AddChatEntry(self, messageType, messageText, prefixText, msgColor, prefixTextColor)
end
_AddChatEntry = hook.jmp.new(
"unsigned int(__thiscall*)(void *self, int messageType, const char *messageText, const char *prefixText, unsigned int msgColor, unsigned int prefixTextColor)",
ChatEntryHandler, (samp_dll + 0x67650))
function SendCommand(text)
--[[
0.3DL
SendCommand('/hello')
]]
local samp10 = getModuleHandle('samp.dll')
local ADDR_FUNC_SEND_COMMAND = samp10 + 0x69340
local send = ffi.cast("void (__stdcall*)(char*)", ADDR_FUNC_SEND_COMMAND)
if send ~= 0 then
local c_str = ffi.new("char[?]", #text + 1)
ffi.copy(c_str, text)
send(c_str)
end
end
function removeColorCodes(text)
return text:gsub("{%x%x%x%x%x%x}", "")
end