Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ffi, bit = require("ffi"), require("bit");local cast, unpack, bor = ffi.cast, table.unpack, bit.bor;local buff = {free = {}};local vmt_hook = {hooks = {}};local target = utils.CreateInterface("vgui2.dll", "VGUI_Panel009");local interface_type = ffi.typeof("void***");local renderer = {};ffi.cdef[[int VirtualProtect(void* lpAddress, unsigned long dwSize, unsigned long flNewProtect, unsigned long* lpflOldProtect);void* VirtualAlloc(void* lpAddress, unsigned long dwSize, unsigned long flAllocationType, unsigned long flProtect);int VirtualFree(void* lpAddress, unsigned long dwSize, unsigned long dwFreeType);typedef unsigned char wchar_t;typedef int(__thiscall* ConvertAnsiToUnicode_t)(void*, const char*, wchar_t*, int);typedef int(__thiscall* ConvertUnicodeToAnsi_t)(void*, const wchar_t*, char*, int);typedef wchar_t*(__thiscall* FindSafe_t)(void*, const char*);typedef void(__thiscall* draw_set_text_color_t)(void*, int, int, int, int);typedef void(__thiscall* draw_set_color_t)(void*, int, int, int, int);typedef void(__thiscall* draw_filled_rect_fade_t)(void*, int, int, int, int, unsigned int, unsigned int, bool);typedef void(__thiscall* draw_set_text_font_t)(void*, unsigned long); typedef void(__thiscall* get_text_size_t)(void*, unsigned long, const wchar_t*, int&, int&);typedef void(__thiscall* draw_set_text_pos_t)(void*, int, int);typedef void(__thiscall* draw_print_text_t)(void*, const wchar_t*, int, int);typedef void(__thiscall* set_font_glyph_t)(void*, unsigned long, const char*, int, int, int, int, unsigned long, int, int);typedef unsigned int(__thiscall* create_font_t)(void*);]];local get_panel_name_type = ffi.typeof("const char*(__thiscall*)(void*, uint32_t)");local panel_interface = ffi.cast(interface_type, target);local panel_interface_vtbl = panel_interface[0];local get_panel_name_raw = panel_interface_vtbl[36];local get_panel_name = ffi.cast(get_panel_name_type, get_panel_name_raw);local function uuid(len) local res, len = "", len or 32;for i=1, len do res = res .. string.char(utils.RandomInt(97, 122));end;return res; end;local interface_mt = {};function interface_mt.get_function(self, index, ret, args) local ct = uuid() .. "_t"; args = args or {}; if type(args) == "table" then table.insert(args, 1, "void*"); else return error("args has to be of type table", 2); end; local success, res = pcall(ffi.cdef, "typedef " .. ret .. " (__thiscall* " .. ct .. ")(" .. table.concat(args, ", ") .. ");"); if not success then error("invalid typedef: " .. res, 2);end;local interface = self[1];local success, func = pcall(ffi.cast, ct, interface[0][index]);if not success then return error("failed to cast: " .. func, 2); end; return function(...) local success, res = pcall(func, interface, ...);if not success then return error("call: " .. res, 2); end;if ret == "const char*" then return res ~= nil and ffi.string(res) or nil; end;return res end end;local function create_interface(dll, interface_name) local interface = (type(dll) == "string" and type(interface_name) == "string") and utils.CreateInterface(dll, interface_name) or dll;return setmetatable({ffi.cast(ffi.typeof("void***"), interface)}, {__index = interface_mt}) end;local localize = create_interface("localize.dll", "Localize_001");local convert_ansi_to_unicode = localize:get_function(15, "int", {"const char*", "wchar_t*", "int"});local convert_unicode_to_ansi = localize:get_function(16, "int", {"const wchar_t*", "char*", "int"});local find_safe = localize:get_function(12, "wchar_t*", {"const char*"});local surface_mt = {};surface_mt.__index = surface_mt;surface_mt.isurface = create_interface("vguimatsurface.dll", "VGUI_Surface031");surface_mt.fn_draw_set_color = surface_mt.isurface:get_function(15, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_filled_rect = surface_mt.isurface:get_function(16, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_outlined_rect = surface_mt.isurface:get_function(18, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_filled_rect = surface_mt.isurface:get_function(16, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_line = surface_mt.isurface:get_function(19, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_set_text_font = surface_mt.isurface:get_function(23, "void", {"unsigned long"});surface_mt.fn_draw_set_text_color = surface_mt.isurface:get_function(25, "void", {"int", "int", "int", "int"});surface_mt.fn_draw_set_text_pos = surface_mt.isurface:get_function(26, "void", {"int", "int"});surface_mt.fn_draw_filled_rect_fade = surface_mt.isurface:get_function(123, "void", {"int", "int", "int", "int", "unsigned int", "unsigned int", "bool"});surface_mt.fn_draw_print_text = surface_mt.isurface:get_function(28, "void", {"const wchar_t*", "int", "int" });surface_mt.fn_create_font = surface_mt.isurface:get_function(71, "unsigned int");surface_mt.fn_set_font_glyph = surface_mt.isurface:get_function(72, "void", {"unsigned long", "const char*", "int", "int", "int", "int", "unsigned long", "int", "int"});surface_mt.fn_get_text_size = surface_mt.isurface:get_function(79, "void", {"unsigned long", "const wchar_t*", "int&", "int&"});function surface_mt:draw_set_color(r, g, b, a) self.fn_draw_set_color(r, g, b, a) end;function surface_mt:draw_filled_rect_fade(x0, y0, x1, y1, alpha0, alpha1, horizontal) self.fn_draw_filled_rect_fade(x0, y0, x1, y1, alpha0, alpha1, horizontal) end;function surface_mt:draw_filled_rect(x0, y0, x1, y1) self.fn_draw_filled_rect(x0, y0, x1, y1) end; function surface_mt:draw_set_text_font(font) self.fn_draw_set_text_font(font) end;function surface_mt:draw_set_text_color(r, g, b, a) self.fn_draw_set_text_color(r, g, b, a) end;function surface_mt:draw_set_text_pos(x, y) self.fn_draw_set_text_pos(x, y) end;function surface_mt:draw_print_text(text, localized) if localized then local char_buffer = ffi.new('char[1024]');convert_unicode_to_ansi(text, char_buffer, 1024);local test = ffi.string(char_buffer);self.fn_draw_print_text(text, test:len(), 0); else local wide_buffer = ffi.new('wchar_t[1024]');convert_ansi_to_unicode(text, wide_buffer, 1024);self.fn_draw_print_text(wide_buffer, text:len(), 0); end end;function surface_mt:create_font() return(self.fn_create_font()) end;function surface_mt:set_font_glyph(font, font_name, tall, weight, flags) local x = 0;if type(flags) == "number" then x = flags; elseif type(flags) == "table" then for i=1, #flags do x = x + flags[i];end end; self.fn_set_font_glyph(font, font_name, tall, weight, 0, 0, bit.bor(x), 0, 0) end;function surface_mt:get_text_size(font, text) local wide_buffer = ffi.new('wchar_t[1024]');local int_ptr = ffi.typeof("int[1]");local wide_ptr = int_ptr() local tall_ptr = int_ptr();convert_ansi_to_unicode(text, wide_buffer, 1024);self.fn_get_text_size(font, wide_buffer, wide_ptr, tall_ptr);local wide = tonumber(ffi.cast("int", wide_ptr[0]));local tall = tonumber(ffi.cast("int", tall_ptr[0]));return wide, tall; end;function renderer.draw_filled_rect(x, y, w, h, r, g, b, a) surface_mt:draw_set_color(r, g, b, a) ;surface_mt:draw_filled_rect(x, y, x + w, y + h) end; function renderer.draw_filled_gradient_rect(x, y, w, h, r0, g0, b0, a0, r1, g1, b1, a1, horizontal) surface_mt:draw_set_color(r0, g0, b0, a0);surface_mt:draw_filled_rect_fade(x, y, x + w, y + h, 255, 255, horizontal);surface_mt:draw_set_color(r1, g1, b1, a1);surface_mt:draw_filled_rect_fade(x, y, x + w, y + h, 0, 255, horizontal); end ;function renderer.create_font(windows_font_name, tall, weight, flags) local font = surface_mt:create_font();if type(flags) == "nil" then flags = 0; end surface_mt:set_font_glyph(font, windows_font_name, tall, weight, flags);return font; end;
- function renderer.localize_string(text) local localized_string = find_safe(text);local char_buffer = ffi.new('char[1024]');convert_unicode_to_ansi(localized_string, char_buffer, 1024);return ffi.string(char_buffer); end;function renderer.draw_text(x, y, r, g, b, a, font, text) surface_mt:draw_set_text_pos(x, y);surface_mt:draw_set_text_font(font);surface_mt:draw_set_text_color(r, g, b, a);surface_mt:draw_print_text(tostring(text), false); end;function renderer.draw_localized_text(x, y, r, g, b, a, font, text) surface_mt:draw_set_text_pos(x, y);surface_mt:draw_set_text_font(font);surface_mt:draw_set_text_color(r, g, b, a);local localized_string = find_safe(text);surface_mt:draw_print_text(localized_string, true); end;function renderer.draw_line(x0, y0, x1, y1, r, g, b, a) surface_mt:draw_set_color(r, g, b, a);surface_mt:draw_line(x0, y0, x1, y1) end;function renderer.test_font(x, y, r, g, b, a, font, string) local _, height_offset = surface_mt:get_text_size(font, "a b c d e f g h i j k l m n o p q r s t u v w x y z");renderer.draw_text(x, y, r, g, b, a, font, string) end;function renderer.get_text_size(font, text) return surface_mt:get_text_size(font, text) end;local function copy(dst, src, len) return ffi.copy(ffi.cast('void*', dst), ffi.cast('const void*', src), len) end;local function VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect) return ffi.C.VirtualProtect(ffi.cast('void*', lpAddress), dwSize, flNewProtect, lpflOldProtect) end;local function VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect, blFree) local alloc = ffi.C.VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);if blFree then table.insert(buff.free, function() ffi.C.VirtualFree(alloc, 0, 0x8000) end) end; return ffi.cast('intptr_t', alloc) end;function vmt_hook.new(vt) local new_hook = {};local org_func = {};local old_prot = ffi.new('unsigned long[1]');local virtual_table = ffi.cast('intptr_t**', vt)[0];new_hook.this = virtual_table;new_hook.hookMethod = function(cast, func, method) org_func[method] = virtual_table[method];VirtualProtect(virtual_table + method, 4, 0x4, old_prot);virtual_table[method] = ffi.cast('intptr_t', ffi.cast(cast, func));VirtualProtect(virtual_table + method, 4, old_prot[0], old_prot);return ffi.cast(cast, org_func[method]); end;new_hook.unHookMethod = function(method) VirtualProtect(virtual_table + method, 4, 0x4, old_prot);local alloc_addr = VirtualAlloc(nil, 5, 0x1000, 0x40, false);local trampoline_bytes = ffi.new('uint8_t[?]', 5, 0x90);trampoline_bytes[0] = 0xE9;ffi.cast('int32_t*', trampoline_bytes + 1)[0] = org_func[method] - tonumber(alloc_addr) - 5;copy(alloc_addr, trampoline_bytes, 5);virtual_table[method] = ffi.cast('intptr_t', alloc_addr);VirtualProtect(virtual_table + method, 4, old_prot[0], old_prot);org_func[method] = nil; end;new_hook.unHookAll = function() for method, func in pairs(org_func) do new_hook.unHookMethod(method); end end;table.insert(vmt_hook.hooks, new_hook.unHookMethod);return new_hook end;local orig = nil;local VGUI_Panel009 = vmt_hook.new(target);
- local ffi_cast = ffi.cast
- local surface_measure_text, surface_draw_text = renderer.get_text_size, renderer.draw_text
- --local entity_get_local_player, globals_tickinterval, math_abs, pcall, error, globals_frametime, globals_realtime, math_floor, math_max, math_min, math_sin, renderer_load_rgba, renderer_texture, string.format, ui_get, ui_reference, print = entity.get_local_player, globals.tickinterval, math.abs, pcall, error, globals.frametime, globals.realtime, math.floor, math.max, math.min, math.sin, renderer.load_rgba, renderer.texture, string.format, ui.get, ui.reference, print
- -- CONVARS
- local cl_interp = g_CVar:FindVar("cl_interp") -- 0.015625
- local cl_interp_ratio = g_CVar:FindVar("cl_interp_ratio") -- 1
- local cl_updaterate = g_CVar:FindVar("cl_updaterate")
- -- FFI STUFF
- local pflFrameTime = ffi.new("float[1]")
- local pflFrameTimeStdDeviation = ffi.new("float[1]")
- local pflFrameStartTimeStdDeviation = ffi.new("float[1]")
- local interface_ptr = ffi.typeof('void***')
- local netc_bool = ffi.typeof("bool(__thiscall*)(void*)")
- local netc_bool2 = ffi.typeof("bool(__thiscall*)(void*, int, int)")
- local netc_float = ffi.typeof("float(__thiscall*)(void*, int)")
- local netc_int = ffi.typeof("int(__thiscall*)(void*, int)")
- local net_fr_to = ffi.typeof("void(__thiscall*)(void*, float*, float*, float*)")
- local rawivengineclient = utils.CreateInterface("engine.dll", "VEngineClient014") or error("VEngineClient014 wasnt found", 2)
- local ivengineclient = ffi_cast(interface_ptr, rawivengineclient) or error("rawivengineclient is nil", 2)
- local get_net_channel_info = ffi_cast("void*(__thiscall*)(void*)", ivengineclient[0][78]) or error("ivengineclient is nil")
- local slv_is_ingame_t = ffi_cast("bool(__thiscall*)(void*)", ivengineclient[0][26]) or error("is_in_game is nil")
- local ping_spike = g_Config:FindVar("Miscellaneous", "Main", "Other", "Fake Ping")
- local LC_ALPHA = 1
- --local WarningIcon = "\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x02\xFF\xFF\xFF\x00\xFF\xFF\xFF\x6B\xFF\xFF\xFF\xFC\xFF\xFF\xFF\xFD\xFF\xFF\xFF\x6F\xFF\xFF\xFF\x00\xFF\xFF\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\xFF\xFF\x04\xFF\xFF\xFF\x04\xFF\xFF\xFF\x04\xFF\xFF\xFF\x04\xFF\xFF\xFF\x04\xFF\xFF\xFF\x04\xFF\xFF\xFF\x06\xFF\xFF\xFF\x00\xFF\xFF\xFF\x8A\xFF\xFF\xFF\xDC\xFF\xFF\xFF\x3F\xFF\xFF\xFF\xE7\xFF\xFF\xFF\xE4\xFF\xFF\xFF\xE1\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE3\xFF\xFF\xFF\xE3\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE2\xFF\xFF\xFF\xE1\xFF\xFF\xFF\xE5\xFF\xFF\xFF\xF0\xFF\xFF\xFF\x43"
- local verdana = renderer.create_font('Verdana', 12, 400, { 0x200 --[[ Outline ]] })
- --local warning_icon = renderer_load_rgba(WarningIcon, 20, 19) or error('couldnt initialize icon', 2)
- local ping_color = function(ping_value)
- if ping_value < 40 then return Color.new(255,255,255) end
- if ping_value < 100 then return Color.new(255,125,95) end
- return Color.new(255,60,80)
- end
- local GetNetChannel = function(INetChannelInfo)
- if INetChannelInfo == nil then
- return
- end
- local seqNr_out = ffi_cast(netc_int, INetChannelInfo[0][17])(INetChannelInfo, 1)
- return {
- seqNr_out = seqNr_out,
- is_loopback = ffi_cast(netc_bool, INetChannelInfo[0][6])(INetChannelInfo),
- is_timing_out = ffi_cast(netc_bool, INetChannelInfo[0][7])(INetChannelInfo),
- latency = {
- crn = function(flow) return ffi_cast(netc_float, INetChannelInfo[0][9])(INetChannelInfo, flow) end,
- average = function(flow) return ffi_cast(netc_float, INetChannelInfo[0][10])(INetChannelInfo, flow) end,
- },
- loss = ffi_cast(netc_float, INetChannelInfo[0][11])(INetChannelInfo, 1),
- choke = ffi_cast(netc_float, INetChannelInfo[0][12])(INetChannelInfo, 1),
- got_bytes = ffi_cast(netc_float, INetChannelInfo[0][13])(INetChannelInfo, 1),
- sent_bytes = ffi_cast(netc_float, INetChannelInfo[0][13])(INetChannelInfo, 0),
- is_valid_packet = ffi_cast(netc_bool2, INetChannelInfo[0][18])(INetChannelInfo, 1, seqNr_out-1),
- }
- end
- local GetNetFramerate = function(INetChannelInfo)
- if INetChannelInfo == nil then
- return 0, 0
- end
- local server_var = 0
- local server_framerate = 0
- ffi_cast(net_fr_to, INetChannelInfo[0][25])(INetChannelInfo, pflFrameTime, pflFrameTimeStdDeviation, pflFrameStartTimeStdDeviation)
- if pflFrameTime ~= nil and pflFrameTimeStdDeviation ~= nil and pflFrameStartTimeStdDeviation ~= nil then
- if pflFrameTime[0] > 0 then
- server_var = pflFrameStartTimeStdDeviation[0] * 1000
- server_framerate = pflFrameTime[0] * 1000
- end
- end
- return server_framerate, server_var
- end
- local color,alpha,x,y,net_state = Color.new(1,1,1),0,0,0,0
- local fl_text = ""
- local nd_width, nd_text = 0, ""
- local pc, tr_text, tr_width = Color.new(0,0,0,0), "", 0
- local additional_latency, lerp_clr = 1, Color.new(0,0,0,0)
- local bytes_in_text, bi_width, cn = "", 0, 0
- local sp_x, sp_y = 0,0
- local ccor_text, right_text = "", ""
- local lerp_time = 0
- local INetChannelInfo = ffi_cast("void***", get_net_channel_info(ivengineclient)) or error("netchaninfo is nil")
- local net_channel = GetNetChannel(INetChannelInfo)
- local server_framerate, server_var = GetNetFramerate(INetChannelInfo)
- local render_true = false
- -- warning icon
- local warning_bytes, warning_size = http.Get("https://i.imgur.com/QEMHCc5.png"), Vector2.new(20,19)
- local warning_icon = g_Render:LoadImage(warning_bytes, warning_size)
- local function engine_inits()
- color = Color.new(255,200,95,255)
- alpha = math.min(math.floor(math.sin((g_GlobalVars.realtime%3) * 4) * 125 + 200), 255)
- local xs, ys = g_EngineClient:GetScreenSize().x, g_EngineClient:GetScreenSize().y
- x, y = xs / 2 + 1, ys - 155
- local local_ent = g_EngineClient:GetLocalPlayer()
- local localp = g_EntityList:GetClientEntity(g_EngineClient:GetLocalPlayer())
- if localp == nil or not localp then render_true = false ; return end
- local me = g_EntityList:GetLocalPlayer()
- if not me or not slv_is_ingame_t(ivengineclient) then
- render_true = false ; return
- end
- render_true = true
- local INetChannelInfo = ffi_cast("void***", get_net_channel_info(ivengineclient)) or error("netchaninfo is nil")
- net_channel = GetNetChannel(INetChannelInfo)
- server_framerate, server_var = GetNetFramerate(INetChannelInfo)
- net_state = 0
- local net_data_text = {
- [0] = 'clock syncing',
- [1] = 'packet choke',
- [2] = 'packet loss',
- [3] = 'lost connection'
- }
- if net_channel.choke > 0.00 then net_state = 1 end
- if net_channel.loss > 0.00 then net_state = 2 end
- if net_channel.is_timing_out then
- net_state = 3
- net_channel.loss = 1
- LC_ALPHA = LC_ALPHA-g_GlobalVars.frametime
- LC_ALPHA = LC_ALPHA < 0.05 and 0.05 or LC_ALPHA
- else
- LC_ALPHA = LC_ALPHA+(g_GlobalVars.frametime*2)
- LC_ALPHA = LC_ALPHA > 1 and 1 or LC_ALPHA
- end
- right_text = net_state ~= 0 and
- string.format('%.1f%% (%.1f%%)', net_channel.loss*100, net_channel.choke*100) or
- string.format('%.1fms', server_var/2)
- if net_state ~= 0 then
- color = Color.new(255,50,50,alpha)
- end
- ccor_text = tostring(net_data_text[net_state])
- local ccor_width = surface_measure_text(verdana, ccor_text)
- sp_x = x - ccor_width - 25
- sp_y = y
- cn = 1
- g_Render:Image(warning_icon, Vector2.new(x-10, sp_y-8), warning_size, --[[ colors ]] Color.new(color:r()/255, color:g()/255, color:b()/255, color:a()/255))
- bytes_in_text = string.format('in: %.2fk/s ', net_channel.got_bytes/1024)
- bi_width = surface_measure_text(verdana, bytes_in_text)
- local tickrate = 1/g_GlobalVars.interval_per_tick
- lerp_time = cl_interp_ratio:GetFloat() * (1000 / tickrate)
- lerp_clr = Color.new(255,255,255)
- if lerp_time/1000 < 2/cl_updaterate:GetInt() then
- lerp_clr = Color.new(255,125,95)
- end
- local outgoing, incoming = net_channel.latency.crn(0), net_channel.latency.crn(1)
- local ping, avg_ping = outgoing*1000, net_channel.latency.average(0)*1000
- local ping_spike_val = ping_spike:GetInt()
- local latency_interval = (outgoing + incoming) / (ping_spike_val - g_GlobalVars.interval_per_tick)
- additional_latency = math.min(latency_interval*1000, 1) * 100 -- 100 = green 0 = red
- pc = ping_color(avg_ping)
- tr_text = string.format('tick: %dp/s ', tickrate)
- tr_width = surface_measure_text(verdana, tr_text)
- nd_text = string.format('delay: %dms (+- %dms) ', avg_ping, math.abs(avg_ping-ping))
- nd_width = surface_measure_text(verdana, nd_text)
- local incoming_latency = math.max(0, (incoming-outgoing)*1000)
- local fl_pre_text = (ping_spike_val ~= 1 and incoming_latency > 1) and string.format(': %dms', incoming_latency) or ''
- fl_text = string.format('datagram%s', fl_pre_text)
- end
- local function g_paint()
- if not render_true then return end
- --print("rendering")
- surface_draw_text(sp_x, sp_y, 255, 255, 255, net_state ~= 0 and 255 or alpha, verdana, ccor_text)
- surface_draw_text(x + 20, sp_y, 255, 255, 255, 255, verdana, string.format('+- %s', right_text))
- surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, LC_ALPHA*255, verdana, bytes_in_text);
- surface_draw_text(sp_x + bi_width, sp_y + 20*cn, lerp_clr:r(), lerp_clr:g(), lerp_clr:b(), LC_ALPHA*255, verdana, string.format('lerp: %.1fms', lerp_time)); cn=cn+1
- surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, LC_ALPHA*255, verdana, string.format('out: %.2fk/s', net_channel.sent_bytes/1024)); cn=cn+1
- surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, LC_ALPHA*255, verdana, string.format('sv: %.2f +- %.2fms var: %.3f ms', server_framerate, server_var, server_var)); cn=cn+1
- surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, 255, verdana, tr_text);cn=cn+1
- surface_draw_text(sp_x, sp_y + 20*cn, pc:r(), pc:g(), pc:b(), LC_ALPHA*255, verdana, nd_text);
- surface_draw_text(sp_x + nd_width, sp_y + 20*cn, 255, 255 / 100 * additional_latency, 255 / 100 * additional_latency, LC_ALPHA*255, verdana, fl_text); cn=cn+1
- end
- cheat.RegisterCallback("draw", engine_inits)
- function painttraverse_hk(one, two, three, four) local panel = two; local panel_name = ffi.string(get_panel_name(one, panel)); if(panel_name == "MatSystemTopPanel") then g_paint() end orig(one, two, three, four) end;orig = VGUI_Panel009.hookMethod("void(__thiscall*)(void*, unsigned int, bool, bool)", painttraverse_hk, 41)
- cheat.RegisterCallback("destroy", function()
- for i, unHookFunc in ipairs(vmt_hook.hooks) do unHookFunc(41) end
- end)
- --client_set_event_callback('paint', g_paint)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement