Вопрос Крашит любой виртуальный метод в цикле спустя некоторое время

Начинающий
Статус
Оффлайн
Регистрация
2 Янв 2023
Сообщения
2
Реакции[?]
0
Поинты[?]
0
Если вызывать rectangle или любую другую функцию в цикле спустя время игра крашнет
code_language.lua:
local render = require("nix/include/surface")
render.draw(function()
    for i = 1, 10 do
        render.rectangle(0, 0, 100, 100, 255, 255, 255, 255) --крашит
    end
end)

render.draw(function()
    render.rectangle(0, 0, 100, 100, 255, 255, 255, 255) --не крашит
end)
Вот код либы
code_language.lua:
local ffi = require("ffi")
local vmt = require("nix/include/hooks").vmt

local function bind_vfunc(vtable, index, t, ...)
    local arg_types = {...}
    return function(...)
        local args = {...}
        for i, arg in ipairs(args) do
            if type(arg) ~= arg_types[i] then
                error("Argument " .. i .. " has incorrect type, expected " .. arg_types[i])
            end
        end
        return ffi.cast(t, vtable[0][index])(vtable, ...)
    end
end

local patterns = {}
patterns.start_drawing = client.find_pattern("vguimatsurface.dll", "55 8B EC 83 E4 ? 83 EC ? 80 3D ? ? ? ? 00 56 57 8B F9")
patterns.finish_drawing = client.find_pattern("vguimatsurface.dll", "8B 0D ? ? ? ? 56 C6 05 ? ? ? ? 00 8B 01 FF 90")

local intefaces = {}
intefaces.vgui = ffi.cast("void*", se.create_interface("engine.dll", "VEngineVGui001"))
intefaces.surface = ffi.cast("void*", se.create_interface("vguimatsurface.dll", "VGUI_Surface031"))

local vtables = {}
vtables.vgui = ffi.cast("uint32_t**", intefaces.vgui)
vtables.surface = ffi.cast("uint32_t**", intefaces.surface)

local surface = {}
surface.draw_set_color = bind_vfunc(vtables.surface, 15, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_filled_rect = bind_vfunc(vtables.surface, 16, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_outlined_rect = bind_vfunc(vtables.surface, 18, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_line = bind_vfunc(vtables.surface, 19, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.start_drawing = function()
    ffi.cast("void(__thiscall*)(void*)", patterns.start_drawing)(intefaces.surface)
end
surface.finish_drawing = function()
    ffi.cast("void(__thiscall*)(void*)", patterns.finish_drawing)(intefaces.surface)
end

local render = {}
render.callback = nil
render.rectangle_outline = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_outlined_rect(x, y, x + w, y + h)
end
render.rectangle = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_filled_rect(x, y, x + w, y + h)
end
render.line = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_line(x, y, x + w, y + h)
end
render.draw = function(callback)
    render.callback = callback
end

local hooks = {}
hooks.o_paint = nil
hooks.hk_paint = function(thisptr, mode)
    hooks.o_paint(thisptr, mode)
    if bit.band(mode, bit.lshift(1, 0)) then
        surface.start_drawing()
        if render.callback then
            render.callback()
        end
        surface.finish_drawing()
    end
end
hooks.o_paint = vmt.new(intefaces.vgui).hookMethod("void(__thiscall*)(void*, int)", hooks.hk_paint, 14)

return render
 
🍫
Участник
Статус
Оффлайн
Регистрация
13 Ноя 2020
Сообщения
1,230
Реакции[?]
181
Поинты[?]
71K
Если вызывать rectangle или любую другую функцию в цикле спустя время игра крашнет
code_language.lua:
local render = require("nix/include/surface")
render.draw(function()
    for i = 1, 10 do
        render.rectangle(0, 0, 100, 100, 255, 255, 255, 255) --крашит
    end
end)

render.draw(function()
    render.rectangle(0, 0, 100, 100, 255, 255, 255, 255) --не крашит
end)
Вот код либы
code_language.lua:
local ffi = require("ffi")
local vmt = require("nix/include/hooks").vmt

local function bind_vfunc(vtable, index, t, ...)
    local arg_types = {...}
    return function(...)
        local args = {...}
        for i, arg in ipairs(args) do
            if type(arg) ~= arg_types[i] then
                error("Argument " .. i .. " has incorrect type, expected " .. arg_types[i])
            end
        end
        return ffi.cast(t, vtable[0][index])(vtable, ...)
    end
end

local patterns = {}
patterns.start_drawing = client.find_pattern("vguimatsurface.dll", "55 8B EC 83 E4 ? 83 EC ? 80 3D ? ? ? ? 00 56 57 8B F9")
patterns.finish_drawing = client.find_pattern("vguimatsurface.dll", "8B 0D ? ? ? ? 56 C6 05 ? ? ? ? 00 8B 01 FF 90")

local intefaces = {}
intefaces.vgui = ffi.cast("void*", se.create_interface("engine.dll", "VEngineVGui001"))
intefaces.surface = ffi.cast("void*", se.create_interface("vguimatsurface.dll", "VGUI_Surface031"))

local vtables = {}
vtables.vgui = ffi.cast("uint32_t**", intefaces.vgui)
vtables.surface = ffi.cast("uint32_t**", intefaces.surface)

local surface = {}
surface.draw_set_color = bind_vfunc(vtables.surface, 15, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_filled_rect = bind_vfunc(vtables.surface, 16, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_outlined_rect = bind_vfunc(vtables.surface, 18, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.draw_line = bind_vfunc(vtables.surface, 19, "void(__thiscall*)(void*, int, int, int, int)", "number", "number", "number", "number")
surface.start_drawing = function()
    ffi.cast("void(__thiscall*)(void*)", patterns.start_drawing)(intefaces.surface)
end
surface.finish_drawing = function()
    ffi.cast("void(__thiscall*)(void*)", patterns.finish_drawing)(intefaces.surface)
end

local render = {}
render.callback = nil
render.rectangle_outline = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_outlined_rect(x, y, x + w, y + h)
end
render.rectangle = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_filled_rect(x, y, x + w, y + h)
end
render.line = function(x, y, w, h, r, g, b, a)
    surface.draw_set_color(r, g, b, a)
    surface.draw_line(x, y, x + w, y + h)
end
render.draw = function(callback)
    render.callback = callback
end

local hooks = {}
hooks.o_paint = nil
hooks.hk_paint = function(thisptr, mode)
    hooks.o_paint(thisptr, mode)
    if bit.band(mode, bit.lshift(1, 0)) then
        surface.start_drawing()
        if render.callback then
            render.callback()
        end
        surface.finish_drawing()
    end
end
hooks.o_paint = vmt.new(intefaces.vgui).hookMethod("void(__thiscall*)(void*, int)", hooks.hk_paint, 14)

return render
А нахуй ты рендеришь циклом?
 
Сверху Снизу