local function vtable_bind(class, _type, index)
local this = [Link]("void***", class)
local ffitype = [Link](_type)
return function (...)
return [Link](ffitype, this[0][index])(this, ...)
end
end
local function vtable_thunk(_type, index)
local ffitype = [Link](_type)
return function (class, ...)
local this = [Link]("void***", class)
return [Link](ffitype, this[0][index])(this, ...)
end
end
[Link][[ struct vec3_t{ float x, y, z; }; ]]
local vec3_t = [Link]("struct vec3_t")
local nullchar = [Link]("const char*", 0)
local IEffects = utils.find_interface("[Link]", "IEffects001")
local EnergySplash = vtable_bind(IEffects, "void(__thiscall*)(void*, const
struct vec3_t&, const struct vec3_t&, bool)", 7)
local IMaterialSystem = utils.find_interface("[Link]",
"VMaterialSystem080")
local FindMaterial = vtable_bind(IMaterialSystem, "void*(__thiscall*)(void*,
const char*, const char*, bool, const char*)", 84)
local AlphaModulate = vtable_thunk("void(__thiscall*)(void*, float)", 27)
local ColorModulate = vtable_thunk("void(__thiscall*)(void*, float, float,
float)", 28)
local AutoPeek = gui.get_config_item("misc>movement>peek assist")
local Master = gui.add_checkbox("Custom peek assist", "misc>movement")
local Color = gui.add_colorpicker("misc>movement>Custom peek assist", true,
[Link](0, 150, 255, 255))
local AutoPeekPos = nil
local SparkMaterial = nil
local OldTickCount = -1
function on_paint()
if not Master:get_bool() then
AutoPeekPos = nil
return
end
-- This fixes the issue of cmd callbacks not being called while recharging dt
if OldTickCount == global_vars.tickcount then
return
else
OldTickCount = global_vars.tickcount
end
local LocalPlayer = entities.get_entity(engine.get_local_player())
if not AutoPeek:get_bool() or not LocalPlayer then
AutoPeekPos = nil
return
end
if not AutoPeekPos then
if [Link](LocalPlayer:get_prop("m_fFlags"), 1) == 1 then
AutoPeekPos = math.vec3(LocalPlayer:get_prop("m_vecOrigin"))
else
return
end
end
if not SparkMaterial then
SparkMaterial = FindMaterial("effects/spark", nullchar, true, nullchar)
else
local ColorTable = Color:get_color()
AlphaModulate(SparkMaterial, ColorTable.a / 255)
ColorModulate(SparkMaterial, ColorTable.r / 255, ColorTable.g / 255,
ColorTable.b / 255)
end
local Angle = (global_vars.realtime * 6) % 360
EnergySplash(vec3_t((AutoPeekPos + math.vec3([Link](Angle), [Link](Angle),
0) * 30):unpack()), vec3_t(), false)
end