Advertisement
mortalbotec

Untitled

Jun 9th, 2021
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.50 KB | None | 0 0
  1. 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;
  2. 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);
  3.  
  4. local ffi_cast = ffi.cast
  5. local surface_measure_text, surface_draw_text = renderer.get_text_size, renderer.draw_text
  6. --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
  7.  
  8. -- CONVARS
  9. local cl_interp = g_CVar:FindVar("cl_interp") -- 0.015625
  10. local cl_interp_ratio = g_CVar:FindVar("cl_interp_ratio") -- 1
  11. local cl_updaterate = g_CVar:FindVar("cl_updaterate")
  12.  
  13. -- FFI STUFF
  14. local pflFrameTime = ffi.new("float[1]")
  15. local pflFrameTimeStdDeviation = ffi.new("float[1]")
  16. local pflFrameStartTimeStdDeviation = ffi.new("float[1]")
  17.  
  18. local interface_ptr = ffi.typeof('void***')
  19. local netc_bool = ffi.typeof("bool(__thiscall*)(void*)")
  20. local netc_bool2 = ffi.typeof("bool(__thiscall*)(void*, int, int)")
  21. local netc_float = ffi.typeof("float(__thiscall*)(void*, int)")
  22. local netc_int = ffi.typeof("int(__thiscall*)(void*, int)")
  23. local net_fr_to = ffi.typeof("void(__thiscall*)(void*, float*, float*, float*)")
  24.  
  25. local rawivengineclient = utils.CreateInterface("engine.dll", "VEngineClient014") or error("VEngineClient014 wasnt found", 2)
  26. local ivengineclient = ffi_cast(interface_ptr, rawivengineclient) or error("rawivengineclient is nil", 2)
  27. local get_net_channel_info = ffi_cast("void*(__thiscall*)(void*)", ivengineclient[0][78]) or error("ivengineclient is nil")
  28. local slv_is_ingame_t = ffi_cast("bool(__thiscall*)(void*)", ivengineclient[0][26]) or error("is_in_game is nil")
  29.  
  30. local ping_spike = g_Config:FindVar("Miscellaneous", "Main", "Other", "Fake Ping")
  31.  
  32. local LC_ALPHA = 1
  33. --local WarningIcon = "\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\xFF\xFF\xFF\x00\x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xFF\x7D\xFF\xFF\xFF\x00\xFF\xFF\xFF\x07\xFF\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\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"
  34.  
  35. local verdana = renderer.create_font('Verdana', 12, 400, { 0x200 --[[ Outline ]] })
  36. --local warning_icon = renderer_load_rgba(WarningIcon, 20, 19) or error('couldnt initialize icon', 2)
  37.  
  38. local ping_color = function(ping_value)
  39. if ping_value < 40 then return Color.new(255,255,255) end
  40. if ping_value < 100 then return Color.new(255,125,95) end
  41.  
  42. return Color.new(255,60,80)
  43. end
  44.  
  45. local GetNetChannel = function(INetChannelInfo)
  46. if INetChannelInfo == nil then
  47. return
  48. end
  49.  
  50. local seqNr_out = ffi_cast(netc_int, INetChannelInfo[0][17])(INetChannelInfo, 1)
  51.  
  52. return {
  53. seqNr_out = seqNr_out,
  54.  
  55. is_loopback = ffi_cast(netc_bool, INetChannelInfo[0][6])(INetChannelInfo),
  56. is_timing_out = ffi_cast(netc_bool, INetChannelInfo[0][7])(INetChannelInfo),
  57.  
  58. latency = {
  59. crn = function(flow) return ffi_cast(netc_float, INetChannelInfo[0][9])(INetChannelInfo, flow) end,
  60. average = function(flow) return ffi_cast(netc_float, INetChannelInfo[0][10])(INetChannelInfo, flow) end,
  61. },
  62.  
  63. loss = ffi_cast(netc_float, INetChannelInfo[0][11])(INetChannelInfo, 1),
  64. choke = ffi_cast(netc_float, INetChannelInfo[0][12])(INetChannelInfo, 1),
  65. got_bytes = ffi_cast(netc_float, INetChannelInfo[0][13])(INetChannelInfo, 1),
  66. sent_bytes = ffi_cast(netc_float, INetChannelInfo[0][13])(INetChannelInfo, 0),
  67.  
  68. is_valid_packet = ffi_cast(netc_bool2, INetChannelInfo[0][18])(INetChannelInfo, 1, seqNr_out-1),
  69. }
  70. end
  71.  
  72. local GetNetFramerate = function(INetChannelInfo)
  73. if INetChannelInfo == nil then
  74. return 0, 0
  75. end
  76.  
  77. local server_var = 0
  78. local server_framerate = 0
  79.  
  80. ffi_cast(net_fr_to, INetChannelInfo[0][25])(INetChannelInfo, pflFrameTime, pflFrameTimeStdDeviation, pflFrameStartTimeStdDeviation)
  81.  
  82. if pflFrameTime ~= nil and pflFrameTimeStdDeviation ~= nil and pflFrameStartTimeStdDeviation ~= nil then
  83. if pflFrameTime[0] > 0 then
  84. server_var = pflFrameStartTimeStdDeviation[0] * 1000
  85. server_framerate = pflFrameTime[0] * 1000
  86. end
  87. end
  88.  
  89. return server_framerate, server_var
  90. end
  91.  
  92. local color,alpha,x,y,net_state = Color.new(1,1,1),0,0,0,0
  93. local fl_text = ""
  94. local nd_width, nd_text = 0, ""
  95. local pc, tr_text, tr_width = Color.new(0,0,0,0), "", 0
  96. local additional_latency, lerp_clr = 1, Color.new(0,0,0,0)
  97. local bytes_in_text, bi_width, cn = "", 0, 0
  98. local sp_x, sp_y = 0,0
  99. local ccor_text, right_text = "", ""
  100. local lerp_time = 0
  101. local INetChannelInfo = ffi_cast("void***", get_net_channel_info(ivengineclient)) or error("netchaninfo is nil")
  102. local net_channel = GetNetChannel(INetChannelInfo)
  103. local server_framerate, server_var = GetNetFramerate(INetChannelInfo)
  104. local render_true = false
  105.  
  106. -- warning icon
  107. local warning_bytes, warning_size = http.Get("https://i.imgur.com/QEMHCc5.png"), Vector2.new(20,19)
  108. local warning_icon = g_Render:LoadImage(warning_bytes, warning_size)
  109.  
  110. local function engine_inits()
  111. color = Color.new(255,200,95,255)
  112. alpha = math.min(math.floor(math.sin((g_GlobalVars.realtime%3) * 4) * 125 + 200), 255)
  113.  
  114. local xs, ys = g_EngineClient:GetScreenSize().x, g_EngineClient:GetScreenSize().y
  115. x, y = xs / 2 + 1, ys - 155
  116.  
  117. local local_ent = g_EngineClient:GetLocalPlayer()
  118. local localp = g_EntityList:GetClientEntity(g_EngineClient:GetLocalPlayer())
  119. if localp == nil or not localp then render_true = false ; return end
  120.  
  121. local me = g_EntityList:GetLocalPlayer()
  122.  
  123. if not me or not slv_is_ingame_t(ivengineclient) then
  124. render_true = false ; return
  125. end
  126.  
  127. render_true = true
  128.  
  129. local INetChannelInfo = ffi_cast("void***", get_net_channel_info(ivengineclient)) or error("netchaninfo is nil")
  130.  
  131. net_channel = GetNetChannel(INetChannelInfo)
  132. server_framerate, server_var = GetNetFramerate(INetChannelInfo)
  133.  
  134. net_state = 0
  135. local net_data_text = {
  136. [0] = 'clock syncing',
  137. [1] = 'packet choke',
  138. [2] = 'packet loss',
  139. [3] = 'lost connection'
  140. }
  141.  
  142. if net_channel.choke > 0.00 then net_state = 1 end
  143. if net_channel.loss > 0.00 then net_state = 2 end
  144.  
  145. if net_channel.is_timing_out then
  146. net_state = 3
  147. net_channel.loss = 1
  148.  
  149. LC_ALPHA = LC_ALPHA-g_GlobalVars.frametime
  150. LC_ALPHA = LC_ALPHA < 0.05 and 0.05 or LC_ALPHA
  151. else
  152. LC_ALPHA = LC_ALPHA+(g_GlobalVars.frametime*2)
  153. LC_ALPHA = LC_ALPHA > 1 and 1 or LC_ALPHA
  154. end
  155.  
  156. right_text = net_state ~= 0 and
  157. string.format('%.1f%% (%.1f%%)', net_channel.loss*100, net_channel.choke*100) or
  158. string.format('%.1fms', server_var/2)
  159.  
  160. if net_state ~= 0 then
  161. color = Color.new(255,50,50,alpha)
  162. end
  163.  
  164. ccor_text = tostring(net_data_text[net_state])
  165.  
  166. local ccor_width = surface_measure_text(verdana, ccor_text)
  167.  
  168. sp_x = x - ccor_width - 25
  169. sp_y = y
  170.  
  171. cn = 1
  172.  
  173. 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))
  174.  
  175. bytes_in_text = string.format('in: %.2fk/s ', net_channel.got_bytes/1024)
  176. bi_width = surface_measure_text(verdana, bytes_in_text)
  177.  
  178. local tickrate = 1/g_GlobalVars.interval_per_tick
  179. lerp_time = cl_interp_ratio:GetFloat() * (1000 / tickrate)
  180.  
  181. lerp_clr = Color.new(255,255,255)
  182.  
  183. if lerp_time/1000 < 2/cl_updaterate:GetInt() then
  184. lerp_clr = Color.new(255,125,95)
  185. end
  186.  
  187. local outgoing, incoming = net_channel.latency.crn(0), net_channel.latency.crn(1)
  188. local ping, avg_ping = outgoing*1000, net_channel.latency.average(0)*1000
  189.  
  190. local ping_spike_val = ping_spike:GetInt()
  191.  
  192. local latency_interval = (outgoing + incoming) / (ping_spike_val - g_GlobalVars.interval_per_tick)
  193. additional_latency = math.min(latency_interval*1000, 1) * 100 -- 100 = green 0 = red
  194.  
  195. pc = ping_color(avg_ping)
  196. tr_text = string.format('tick: %dp/s ', tickrate)
  197. tr_width = surface_measure_text(verdana, tr_text)
  198.  
  199. nd_text = string.format('delay: %dms (+- %dms) ', avg_ping, math.abs(avg_ping-ping))
  200. nd_width = surface_measure_text(verdana, nd_text)
  201.  
  202. local incoming_latency = math.max(0, (incoming-outgoing)*1000)
  203.  
  204. local fl_pre_text = (ping_spike_val ~= 1 and incoming_latency > 1) and string.format(': %dms', incoming_latency) or ''
  205. fl_text = string.format('datagram%s', fl_pre_text)
  206. end
  207.  
  208. local function g_paint()
  209. if not render_true then return end
  210.  
  211. --print("rendering")
  212. surface_draw_text(sp_x, sp_y, 255, 255, 255, net_state ~= 0 and 255 or alpha, verdana, ccor_text)
  213. surface_draw_text(x + 20, sp_y, 255, 255, 255, 255, verdana, string.format('+- %s', right_text))
  214. surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, LC_ALPHA*255, verdana, bytes_in_text);
  215. 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
  216. 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
  217. 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
  218. surface_draw_text(sp_x, sp_y + 20*cn, 255, 255, 255, 255, verdana, tr_text);cn=cn+1
  219. surface_draw_text(sp_x, sp_y + 20*cn, pc:r(), pc:g(), pc:b(), LC_ALPHA*255, verdana, nd_text);
  220. 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
  221. end
  222.  
  223. cheat.RegisterCallback("draw", engine_inits)
  224. 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)
  225. cheat.RegisterCallback("destroy", function()
  226. for i, unHookFunc in ipairs(vmt_hook.hooks) do unHookFunc(41) end
  227. end)
  228. --client_set_event_callback('paint', g_paint)
  229.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement