script_name("SAMP Editor (BETA)")
script_author("seven.")
script_version("1.0")
require "moonloader"
local a = require "ffi"
local b = require "inicfg"
local c = b.load(nil, "samp-editor.lua.ini")
local d = {hooks = {}}
addEventHandler(
"onScriptTerminate",
function(e)
if e == script.this then
for f, d in ipairs(d.hooks) do
if d.status then
d.stop()
end
end
end
end
)
a.cdef [[
int VirtualProtect(void* lpAddress, unsigned long dwSize, unsigned long flNewProtect, unsigned long* lpflOldProtect);
]]
function d.new(g, h, i, j)
local j = j or 5
local k = {}
local l = tonumber(a.cast("intptr_t", a.cast("void*", a.cast(g, h))))
local m = a.cast("void*", i)
local n = a.new("unsigned long[1]")
local o = a.new("uint8_t[?]", j)
a.copy(o, m, j)
local p = a.new("uint8_t[?]", j, 0x90)
p[0] = 0xE9
a.cast("uint32_t*", p + 1)[0] = l - i - 5
k.call = a.cast(g, i)
k.status = false
local function q(r)
k.status = r
a.C.VirtualProtect(m, j, 0x40, n)
a.copy(m, r and p or o, j)
a.C.VirtualProtect(m, j, n[0], n)
end
k.stop = function()
q(false)
end
k.start = function()
q(true)
end
k.start()
table.insert(d.hooks, k)
return setmetatable(
k,
{__call = function(self, ...)
self.stop()
local s = self.call(...)
self.start()
return s
end}
)
end
function main()
sampChatHook =
d.new(
"void(__thiscall *)(void *this, uint32_t type, const char* text, const char* prefix, uint32_t color, uint32_t pcolor)",
fsampChatHook,
getModuleHandle("samp.dll") + 0x64010
)
wait(-1)
end
function fsampChatHook(t, u, v, w, x, y)
if a.string(v):find("Started") and x == 4289316068 then
return sampChatHook(t, u, c.settings.Samp037_Msg, w, c.settings.Samp037_Color, y)
end
if a.string(v):find("Connecting to") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Connecting to", c.settings.ConnectingTo_Msg),
w,
c.settings.ConnectingTo_Color,
y
)
end
if a.string(v):find("Connected. Joining the game...") then
return sampChatHook(t, u, c.settings.JoiningTheGame_Msg, w, c.settings.JoiningTheGame_Color, y)
end
if a.string(v):find("Connected to") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Connected to", c.settings.ConnectedTo_Msg),
w,
c.settings.ConnectedTo_Color,
y
)
end
if a.string(v):find("The server didn't respond. Retrying..") then
return sampChatHook(t, u, c.settings.TheServerDidntRespond_Msg, w, c.settings.TheServerDidntRespond_Color, y)
end
if a.string(v):find("CONNECTION REJECTED: Unacceptable NickName") then
return sampChatHook(t, u, c.settings.ConnectionRejected_Msg, w, c.settings.ConnectionRejected_Color, y)
end
if a.string(v):find("Please choose another nick") then
return sampChatHook(
t,
u,
c.settings.PleaseChooseAnotherNick_Msg,
w,
c.settings.PleaseChooseAnotherNick_Color,
y
)
end
if a.string(v):find("Please use only") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Please use only", c.settings.PleaseUseOnly_Msg),
w,
c.settings.PleaseUseOnly_Color,
y
)
end
if a.string(v):find("Use /quit to exit or press ESC and select Quit Game") then
return sampChatHook(t, u, c.settings.UseQToExit_Msg, w, c.settings.UseQToExit_Color, y)
end
if a.string(v):find("The server is restarting..") then
return sampChatHook(t, u, c.settings.TheServerIsRestarting_Msg, w, c.settings.TheServerIsRestarting_Color, y)
end
if a.string(v):find("CONNECTION REJECTED: Incorrent Version") then
return sampChatHook(t, u, c.settings.ConnectingRejectedVer_Msg, w, c.settings.ConnectionRejectedVer_Color, y)
end
if a.string(v):find("OnFoot position saved") then
return sampChatHook(t, u, c.settings.OnFootPos_Msg, w, c.settings.OnFootPos_Color, y)
end
if a.string(v):find("InCar position saved") then
return sampChatHook(t, u, c.settings.InCarPos_Msg, w, c.settings.InCarPos_Color, y)
end
if a.string(v):find("-> OnFoot pos saved") then
return sampChatHook(t, u, c.settings.OnFootSaved_Msg, w, c.settings.OnFootSaved_Color, y)
end
if a.string(v):find("-> InCar pos saved") then
return sampChatHook(t, u, c.settings.InCarSaved_Msg, w, c.settings.InCarSaved_Color, y)
end
if a.string(v):find("Current Interior:") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Current Interior:", c.settings.CurrentInterior_Msg),
w,
c.settings.CurrentInterior_Color,
y
)
end
if a.string(v):find("-> Frame Limiter:") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "-> Frame Limiter:", c.settings.FrameLimiter_Msg),
w,
c.settings.FrameLimiter_Color,
y
)
end
if a.string(v):find("Valid fontsize:") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Valid fontsize:", c.settings.ValidFontSize_Msg),
w,
c.settings.ValidFontSize_Color,
y
)
end
if a.string(v):find("-> Head movements disabled") then
return sampChatHook(t, u, c.settings.HMoveDis_Msg, w, c.settings.HMoveDis_Color, y)
end
if a.string(v):find("-> Head movements enabled") then
return sampChatHook(t, u, c.settings.HMoveEn_Msg, w, c.settings.HMoveEn_Color, y)
end
if a.string(v):find("Memory:") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Memory:", c.settings.Memory_Msg),
w,
c.settings.Memory_Color,
y
)
end
if a.string(v):find("Audio messages:") then
return sampChatHook(
t,
u,
string.gsub(a.string(v), "Audio messages:", c.settings.AudioMsg_Msg),
w,
c.settings.AudioMsg_Color,
y
)
end
sampChatHook(t, u, v, w, x, y)
end