local ffi = require 'ffi' -- Structure definition for CVector, as it is used in the…
- User
local ffi = require 'ffi'
-- Structure definition for CVector, as it is used in the function ffi.cdef[[ typedef struct { float x; float y; float z; } CVector; ]]
--HOOKS local hook = {hooks = {}} addEventHandler('onScriptTerminate', function(scr) if scr == script.this then for i, hook in ipairs(hook.hooks) do if hook.status then hook.stop() end end end end) ffi.cdef [[ int VirtualProtect(void* lpAddress, unsigned long dwSize, unsigned long flNewProtect, unsigned long* lpflOldProtect); ]] function hook.new(cast, callback, hook_addr, size) jit.off(callback, true) --off jit compilation | thx FYP local size = size or 5 local new_hook = {} local detour_addr = tonumber(ffi.cast('intptr_t', ffi.cast('void*', ffi.cast(cast, callback)))) local void_addr = ffi.cast('void*', hook_addr) local old_prot = ffi.new('unsigned long[1]') local org_bytes = ffi.new('uint8_t[?]', size) ffi.copy(org_bytes, void_addr, size) local hook_bytes = ffi.new('uint8_t[?]', size, 0x90) hook_bytes[0] = 0xE9 ffi.cast('uint32_t*', hook_bytes + 1)[0] = detour_addr - hook_addr - 5 new_hook.call = ffi.cast(cast, hook_addr) new_hook.status = false local function set_status(bool) new_hook.status = bool ffi.C.VirtualProtect(void_addr, size, 0x40, old_prot) ffi.copy(void_addr, bool and hook_bytes or org_bytes, size) ffi.C.VirtualProtect(void_addr, size, old_prot[0], old_prot) end new_hook.stop = function() set_status(false) end new_hook.start = function() set_status(true) end new_hook.start() table.insert(hook.hooks, new_hook) return setmetatable(new_hook, { __call = function(self, ...) self.stop() local res = self.call(...) self.start() return res end }) end --HOOKS
-- Define the function address for CPlayerTags::DrawHealthBar local drawHealthBarFuncAddress = getModuleHandle('samp.dll') + 0x689C0 local drawHealthBarFunc = ffi.cast("void(__thiscall*)(void*, CVector*, float, float, float)", drawHealthBarFuncAddress)
local getBonePositionFunc = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
ffi.cdef[[ typedef struct CPlayerTags CPlayerTags;
typedef void (__thiscall* VoidEndHealthBarFunc)(CPlayerTags* this); typedef void (__thiscall* VoidBeginHealthBarFunc)(CPlayerTags* this); ]]
local EndHealthBarFuncAddress = getModuleHandle('samp.dll') + 0x68670 -- Замените реальным адресом local BeginHealthBarFuncAddress = getModuleHandle('samp.dll') + 0x68FD0 -- Замените реальным адресом
local EndHealthBar = ffi.cast("VoidEndHealthBarFunc", EndHealthBarFuncAddress) local BeginHealthBar = ffi.cast("VoidBeginHealthBarFunc", BeginHealthBarFuncAddress)
-- Получить координаты части тела local function getBodyPartCoordinates(boneId, pedHandle) local pedPointer = getCharPointer(pedHandle) local coordinates = ffi.new("float[3]") getBonePositionFunc(ffi.cast("void*", pedPointer), coordinates, boneId, true) return coordinates[0], coordinates[1], coordinates[2] end
-- Define the CPlayerTags instance local CPlayerTags = ffi.cast("void*", 0x04408fd0)
- Assistant
- User
ты поменял логику, код работает иначе
- Assistant
- User
- Assistant
- User
-- Hook pro upraveni chovani EndHealthBar function EndHealthBarHook(playerTags) local handle = playerPed
codeif sampIs3dTextDefined(textId) then sampDestroy3dText(textId) end if sampIs3dTextDefined(textId + 1) then sampDestroy3dText(textId + 1) end local charX, charY, charZ = getCharCoordinates(handle) local limbX, limbY, limbZ = getBodyPartCoordinates(8, handle) local cameraX, cameraY, cameraZ = getActiveCameraCoordinates() local cameraDistance = getDistanceBetweenCoords3d(charX, charY, charZ, cameraX, cameraY, cameraZ) local text = "{ffffff}pururin (30)" local measuredSize = sampGetMeasuredTextSize(text) local offse = f(measuredSize.cy) position.x, position.y, position.z = limbX, limbY, limbZ renderSetRenderState(19, 2) -- Nastaveni rendering renderSetRenderState(20, 3) renderSetRenderState(27, 1) drawHealthBarFunc(playerTags, position, 56.0, 0.0, cameraDistance) limbZ = limbZ + 0.21 + ((cameraDistance * 0.047499999) * offse) limbZ2 = limbZ + ((cameraDistance * 0.047499999) * offse) / 2 sampCreate3dTextEx(textId, text, 0xFFFFFFFF, limbX, limbY, limbZ, 600, false, -1, -1) sampCreate3dTextEx(textId + 1, "{d0aeeb} * patrzcie, umiem grac roleplay", 0xFFFFFFFF, limbX, limbY, limbZ2, 600, false, -1, -1) return EndHealthBar(playerTags) - Assistant
- User
добавь максимум дебажных принтов
local function sampGetMeasuredTextSize(text) print"voshli v function sampGetMeasuredTextSize(text)" local base = SAMP_BASE if base == 0 then print("Nie udalo sie pobrac bazowego adresu modulu SAMP.") end print("base: " .. SAMP_BASE)
codelocal g_fonts_address = ffi.cast("void**", base + OFFSET_CFONTS) local g_fonts = ffi.cast("void*", g_fonts_address[0]) local measureTextFunc = ffi.cast("void(__thiscall*)(void*, SIZE*, const char*, int)", base + OFFSET_MEASURE_TEXT_FUNC) measureTextFunc(g_fonts, size, text, bit.bor(0x0000, 0x400)) -- DT_LEFT | DT_NOCLIP print"VISHLI iz function sampGetMeasuredTextSize(text)" return sizeend
- Assistant
При добавлении множества отладочных сообщений (
print) в функцию, важно фиксировать как можно больше полезной информации на каждом шаге выполнения, чтобы иметь возможность отслеживать состояние программы и легко идентифицировать проблемы. Вот пример того, как можно максимально подробно использовать в вашей функции :