Полезные сниппеты и функции

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,771
11,214
Описание: получает список команд (без самповских).
Автор: @kin4stat
Код:
Lua:
local ffi = require('ffi')
ffi.cdef([[
    struct std_string { union { char buf[16]; char* ptr; }; unsigned size; unsigned capacity; };
    struct stCommandInfo { struct std_string name; int type; void* owner; };
    struct std_vector_stCommandInfo{ struct stCommandInfo* first; struct stCommandInfo* last; struct stCommandInfo* end; };
]])
local _getChatCommands = ffi.cast('struct std_vector_stCommandInfo(__thiscall*)()', getModuleProcAddress('SAMPFUNCS.asi', '?getChatCommands@SAMPFUNCS@@QAE?AV?$vector@UstCommandInfo@@V?$allocator@UstCommandInfo@@@std@@@std@@XZ'))

function getChatCommands()
    local t = {}
    local commands = _getChatCommands()
    local it = commands.first
    while it ~= commands.last do
        table.insert(t, '/'..ffi.string(it[0].name.size <= 0x0F and it[0].name.buf or it[0].name.ptr))
        it = it + 1
    end
    return t
end
Пример использования:
1671822155787.png

Lua:
for _, cmd in ipairs(getChatCommands()) do
    imgui.Text(cmd)
end
 
Последнее редактирование:

VRush

https://t.me/vrushscript
Проверенный
2,341
1,090
Описание: Рисует полый квадрат в 3д
1672008217922.png

Пример использования:
Lua:
Lua:
for i=1, 4080 do
    if sampIs3dTextDefined(i) then
        local text, color, X, Y, Z, dist, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(i)
        renderDrawBoxIn3d(X, Y, Z, 0.6, 0.4, 2.5, 5)
    end
end
Код:
Lua:
Lua:
function renderDrawBoxIn3d(X, Y, Z, size, high, low, radius)
   --верх
   renderDrawLineBy3dCoords(X - size, Y - size, Z - high, X + size, Y - size, Z - high, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X + size, Y + size, Z - high, X - size, Y + size, Z - high, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X - size, Y - size, Z - high, X - size, Y + size, Z - high, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X + size, Y + size, Z - high, X + size, Y - size, Z - high, radius, 0xAA00CC00)
   --низ
   renderDrawLineBy3dCoords(X - size, Y - size, Z - low, X + size, Y - size, Z - low, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X + size, Y + size, Z - low, X - size, Y + size, Z - low, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X - size, Y - size, Z - low, X - size, Y + size, Z - low, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X + size, Y + size, Z - low, X + size, Y - size, Z - low, radius, 0xAA00CC00)
   --бок1
   renderDrawLineBy3dCoords(X - size, Y - size, Z - low, X - size, Y - size, Z - high, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X + size, Y - size, Z - low, X + size, Y - size, Z - high, radius, 0xAA00CC00)
   --бок2
   renderDrawLineBy3dCoords(X + size, Y + size, Z - low, X + size, Y + size, Z - high, radius, 0xAA00CC00)
   renderDrawLineBy3dCoords(X - size, Y + size, Z - low, X - size, Y + size, Z - high, radius, 0xAA00CC00)
end

function renderDrawLineBy3dCoords(X, Y, Z, X2, Y2, Z2, width, color)
   local pX, pY = convert3DCoordsToScreen(X, Y, Z)
   local pX2, pY2 = convert3DCoordsToScreen(X2, Y2, Z2)
   if isPointOnScreen(X, Y, Z, 1) and isPointOnScreen(X2, Y2, Z2, 1) then
      renderDrawLine(pX, pY, pX2, pY2, width, color)
   end
end
 
Последнее редактирование:

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Возвращает рендер худа при открытом Табе:
Lua:
local memory = require 'memory'

memory.fill(getModuleHandle("samp.dll") + 0x71345, 0x90, 13, true) --R1

memory.fill(getModuleHandle("samp.dll") + 0x75235, 0x90, 13, true) -- R3




Возвращает рендер худа при открытых текстдравах с выбором. ( Серверные инвентари, взаимодействие с всякими работами и т.д )
Lua:
local memory = require 'memory'

memory.fill(getModuleHandle("samp.dll") + 0x6CE47, 0x90, 13, true) --R1

memory.fill(getModuleHandle("samp.dll") + 0x70D37, 0x90, 13, true) -- R3

Возвращает рендер худа при выборе скина:
Lua:
local memory = require 'memory'

memory.fill(getModuleHandle('samp.dll') + 0x5F0C, 0x90, 12, true) -- R1

memory.fill(getModuleHandle('samp.dll') + 0x5F15, 0x90, 12, true) -- R3
 
Последнее редактирование:

Savchik Blazer

Но я, мечту свою лелея...
Проверенный
671
293
включает дебаг режим, использовать до загрузки
Lua:
local memory = require 'memory'

memory.setint8(getModuleHandle("samp.dll") + 0x219760, 1, true) --R2 - 0x219768, R3 - 0x26DD30, R4 - 0x26de60, R5 - 0x26DFE8
 

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Была недавно идея написать библиотеку ( API для муна ) на луа по типу SAMPFUNCS, но сделав только несколько функций - забил хуй. Вот функции которые я сделал ( не зависят от SAMPFUNCS'a, но всё адреса только для R3 версии SAMP'а. Кому надо - тот найдет себе вля всех остальных. ):
Lua:
local ffi = require 'ffi'

local samp_base = getModuleHandle("samp.dll")

--[[ Указатели ]]--
local pChat = memory.getuint32(samp_base + 0x26E8C8, true)
local pDialog = memory.getuint32(samp_base + 0x26E898, true)
local pInput = memory.getuint32(samp_base + 0x26E8CC, true)
local pGame = memory.getuint32(samp_base + 0x26E8F4, true)

-- Возвращает текущий режим отображения чата.
function getChatMode()
    return memory.getint8(pChat + 0x8, true)
end

-- Устанавливает режим отображения чату:
function setChatMode(mode)
    memory.setint8(pChat + 0x8, mode, true)
end

--[[
    Режимы чата:
    0 - отключен
    1 - без обводки
    2 - обычный
]]

-- Возвращает режим курсора:
function getCursorMode()
    return memory.getint8(pGame, true)
end

-- Устанавливает режим курсора:
function setCursorMode(mode)
    ffi.cast("void(__thiscall*)(void*, int, bool)", samp_base+ 0x9FFE0)(ffi.cast('void*', pGame), mode, true)
end

--[[
    Режимы курсора ( Спиздил с wiki ):
    0 - Отключен.
    1 - Управление клавиатурой заблокировано, курсор отключен.
    2 - Управление клавиатурой и мышкой заблокировано, курсор включен.
    3 - Управление мышкой заблокировано, курсор включен.
    4 - Управление мышкой заблокировано, курсор отключен.
]]

-- Показывает диалог:
function dialogShow(id, style, title, button1, button2, text)
    ffi.cast('void(__thiscall*)(void*, int, int, const char*, const char*, const char*, const char*, bool)', samp_base+ 0x6F8C0)(ffi.cast('void*', pDialog), id, style, title, button1, button2, text, false)
end

--Закрывает текущий диалог с помощью указаной кнопки:
function dialogClose(button)
    ffi.cast('void(__thiscall*)(void*, char)', samp_base+ 0x6FF40)(ffi.cast('void*', pDialog), button)
end

-- Проверяет открыт ли любой диалог:
function isDialogActive()
    return memory.getint8(pDialog + 0x28, true)
end

-- Возвращает стиль диалога:
function getDialogStyle()
    return memory.getint8(pDialog + 0x2C, true)
end

-- Возвращает ID диалога:
function getDialogId()
    return memory.getint8(pDialog + 0x30, true)
end

-- Возвращает название диалога:
function getDialogTitle()
    return memory.tostring(pDialog + 0x40, true)
end

-- Проверяет открыт ли input чата:
function isChatInputActive()
    return memory.getint8(pInput + 0x14E0, true)
end
 
Последнее редактирование:

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,771
11,214
Описание: меняет скин персонажа по хендлу (странно что в муне нет этой функции)
Код:
Lua:
local CPed_SetModelIndex = ffi.cast('void(__thiscall *)(void*, unsigned int)', 0x5E4880)
function setCharModel(ped, model)
    assert(doesCharExist(ped), 'ped not found')
    if not hasModelLoaded(model) then
        requestModel(model)
        loadAllModelsNow()
    end
    CPed_SetModelIndex(ffi.cast('void*', getCharPointer(ped)), ffi.cast('unsigned int', model))
end
Пример использования:
Lua:
    sampRegisterChatCommand('CHANGEMYFUCKINGSKINNIGGA', function(arg)
        if tonumber(arg) then
            setCharModel(PLAYER_PED, tonumber(arg))
        else
            sampAddChatMessage('incorrect skin id!', -1)
        end
    end)
 

lorgon

Известный
657
268
Описание: Перераспределяет значения UV по прямоугольнику(a, b)
* Т.е. вы можете линейно натянуть текстуру на любой примитив / Ориг

Пример использования:
- Для натягивание совы на глобус
1672779758798.png

Lua:
local bg = im.GetBackgroundDrawList()

local center = im.ImVec2(1000, 500)
local radius = 150
local a, b = im.ImVec2(center.x - radius, center.y - radius), im.ImVec2(center.x + radius, center.y + radius)
local uv_min, uv_max = im.ImVec2(0, 0), im.ImVec2(1, 1)

bg:PushTextureID(sova_texture)
          
local vert_start_idx = bg.VtxBuffer.Size
bg:PathArcToFast(center, radius, 1, 12)
bg:PathFillConvex(0xFFFFFFFF)
local vert_end_idx = bg.VtxBuffer.Size

im.ShadeVertsLinearUV(bg, vert_start_idx, vert_end_idx, a, b, uv_min, uv_max, false)

bg:PopTextureID()
1672780001487.png

Lua:
local bg = im.GetBackgroundDrawList()

local center = im.ImVec2(1000, 500)
local radius = 150
local a, b = im.ImVec2(center.x - radius, center.y - radius), im.ImVec2(center.x + radius, center.y + radius)
local uv_min, uv_max = im.ImVec2(0, 0), im.ImVec2(1, 1)

bg:PushTextureID(sova_texture)
          
local vert_start_idx = bg.VtxBuffer.Size
bg:AddRectFilled(a, b, 0xFFFFFFFF)
local vert_end_idx = bg.VtxBuffer.Size

im.ShadeVertsLinearUV(bg, vert_start_idx, vert_end_idx, a, b, uv_min, uv_max, false)

bg:PopTextureID()

Код:
Lua:
function imgui.ShadeVertsLinearUV(draw_list, vert_start_idx, vert_end_idx, a, b, uv_a, uv_b, clamp)
    local function ImMin(lhs, rhs) return imgui.ImVec2(math.min(lhs.x, rhs.x), math.min(lhs.y, rhs.y)); end
    local function ImMax(lhs, rhs) return imgui.ImVec2(math.max(lhs.x, rhs.x), math.max(lhs.y, rhs.y)); end
    local function ImClamp(v, mn, mx) return imgui.ImVec2((v.x < mn.x) and mn.x or ((v.x > mx.x) and mx.x or v.x), (v.y < mn.y) and mn.y or ((v.y > mx.y) and mx.y or v.y)); end
    local size = imgui.ImVec2(b.x - a.x, b.y - a.y)
    local uv_size = imgui.ImVec2(uv_b.x - uv_a.x, uv_b.y - uv_a.y)
    local scale = imgui.ImVec2(size.x ~= 0.0 and (uv_size.x / size.x) or 0.0, size.y ~= 0.0 and (uv_size.y / size.y) or 0.0)
    if clamp then
        local min = ImMin(uv_a, uv_b)
        local max = ImMax(uv_a, uv_b)
        for i = vert_start_idx, vert_end_idx do
            local vertex = draw_list.VtxBuffer.Data[i]
            vertex.uv = ImClamp(imgui.ImVec2(uv_a.x + (vertex.pos.x - a.x) * scale.x, uv_a.y + (vertex.pos.y - a.y) * scale.y), min, max)
        end
    else
        for i = vert_start_idx, vert_end_idx do
            local vertex = draw_list.VtxBuffer.Data[i]
            vertex.uv = imgui.ImVec2(uv_a.x + (vertex.pos.x - a.x) * scale.x, uv_a.y + (vertex.pos.y - a.y) * scale.y)
        end
    end
end
 
Последнее редактирование:

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: Отключает возвращеине чата вниз после отправления сообщения.

Code:
Lua:
local memory = require 'memory'

memory.fill(getModuleHandle("samp.dll") + 0x693B8, 0x90, 5, true) -- R3

--[[
R1: 0x65E88
R2: 0x65F58
R3: 0x693B8
R4: 0x69AE8
R5: 0x69B28
DL: 0x69568
]]
 

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: Изменяет цвет и прозрачность текста в килл листе

Код:
Lua:
--[[ R1 ]]--
-- Цвет обводки
memory.setint32(getModuleHandle("samp.dll") + 0x65FB0, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x65FE2, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x66012, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x66041, ARGB, true)

-- Прозрачность обводки
memory.setint8(getModuleHandle("samp.dll") + 0x65FD6, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x65FF3, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x66024, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x66052, Alpha, true)

-- Прозрачность текста
memory.setint8(getModuleHandle("samp.dll") + 0x66085, Alpha, true)

--[[ R3 ]]--
-- Цвет обводки
memory.setint32(getModuleHandle("samp.dll") + 0x694E0, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x69512, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x69542, ARGB, true)
memory.setint32(getModuleHandle("samp.dll") + 0x69571, ARGB, true)

-- Прозрачность обводки
memory.setint8(getModuleHandle("samp.dll") + 0x69506, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x69523, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x69554, Alpha, true)
memory.setint8(getModuleHandle("samp.dll") + 0x69582, Alpha, true)

-- Прозрачность текста
memory.setint8(getModuleHandle("samp.dll") + 0x695B5, Alpha, true)

Демонстрация:
1673389202697.png
 
  • Нравится
  • Вау
Реакции: aggressor, why ega и qdIbp

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: Моментально перезаряжает текущее оружие. ( Решил написать увидев этот стыд: https://www.blast.hk/threads/164510/ )

За основу взял функцию 4el0ve4ik

Lua:
local ffi = require 'ffi'

function reloadGun()
    local CPed = getCharPointer(playerPed)
    local currentWeapon = getCurrentCharWeapon(playerPed)
    local weaponSlot = getWeapontypeSlot(currentWeapon)
    local CWeapon = CPed + 0x5A0
    local currentCWeapon = CWeapon + weaponSlot * 0x1C
    ffi.cast('void(__thiscall*)(void* CWeapon, void* CPed)', 0x73AEB0)(ffi.cast('void*', currentCWeapon), ffi.cast('void*', CPed))
end

Пример использования: Автоматическая перезарядка если у игрока 1 патрон.
Lua:
local ffi = require 'ffi'
local memory = require 'memory'

function main()
    while not isSampAvailable() do wait (100) end

    while true do
        wait(0)
        local ammo = getAmmoInClip()
        if ammo == 1 then
            reloadGun()
        end
    end
end

function getAmmoInClip() -- Функция Человечка.
    local pointer = getCharPointer(playerPed)
    local weapon = getCurrentCharWeapon(playerPed)
    local slot = getWeapontypeSlot(weapon)
    local cweapon = pointer + 0x5A0
    local current_cweapon = cweapon + slot * 0x1C
    return memory.getuint32(current_cweapon + 0x8)
end

function reloadGun()
    local CPed = getCharPointer(playerPed)
    local currentWeapon = getCurrentCharWeapon(playerPed)
    local weaponSlot = getWeapontypeSlot(currentWeapon)
    local CWeapon = CPed + 0x5A0
    local currentCWeapon = CWeapon + weaponSlot * 0x1C
    ffi.cast('void(__thiscall*)(void* CWeapon, void* CPed)', 0x73AEB0)(ffi.cast('void*', currentCWeapon), ffi.cast('void*', CPed))
end
 
Последнее редактирование:

Vespan

loneliness
Проверенный
2,101
1,633
json где все анимации gta sa
пример использования:
Lua:
imgui = require 'imgui'
window = imgui.ImBool(false)
search = imgui.ImBuffer(256)
local f = io.open(getWorkingDirectory()..'/lib/all animation list.json'--[[json file!]],'r+')
anims = decodeJson(f:read('*a'))
f:close()
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('/anims',function() window.v = not window.v;    imgui.Process = true end)
    wait(-1)
end
function imgui.OnDrawFrame()
    local sw,sh = getScreenResolution()
    if window.v then
        imgui.SetNextWindowSize(imgui.ImVec2(300,300),1)
        imgui.SetNextWindowPos(imgui.ImVec2(sw/2-300/2,sh/2-300/2), imgui.Cond.FirstUseEver)
        imgui.Begin('window',window,32)
        if imgui.Button('clear anim') then clearCharTasksImmediately(playerPed) end
        imgui.InputText('search',search)
        for k,v in pairs(anims) do
            for _,vv in ipairs(v) do
                if (#search.v == 0 and true or (k:lower():find((search.v):lower()) or vv:lower():find((search.v):lower())) ) then
                    if imgui.Button(string.format('%s,%s',k,vv)) then
                        if k ~= "PED" then
                            requestAnimation(k)
                            loadAllModelsNow()
                        end
                        taskPlayAnim(PLAYER_PED,vv,k,4.0,false,0,0,0,-1)
                        if k ~= "PED" then
                            removeAnimation(vv)
                        end
                    end
                end
            end
        end
        imgui.End()
    else
        imgui.Process = false
    end

end
1673706801062.png
 

Вложения

  • all animation list.json
    26.5 KB · Просмотры: 21

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: Отключает рендер иконки севера ( буквы N ) на карте.

Код:
Lua:
local memory = require 'memory'

memory.fill(0x588188, 0x90, 5, true)

Чем это лучше обычной прозрачной текстуры в hud.txd? Этот ноп отключает рендер этой иконки, а при прозрачной текстуре вы просто не видите этой картинки, но рендер продолжается.
 

Gorskin

I shit on you
Проверенный
1,247
1,043
Описание: Патч позволяет сесть с любым тяжелым оружием. Визуально, другие игроки будут видеть вас стоя.
sa-mp-268.png
Lua:
writeMemory(0x692649+1, 1, 6, true)--patch anim duck
 

kjor32

¯\_(ツ)_/¯
Всефорумный модератор
1,685
1,399
Изменяет высоту прыжка на bmx
Lua:
local memory = require 'memory'

memory.setfloat(memory.getuint32(0x6C0449 + 2, true), значение, true) -- Стандартное значение 0.0599
 
Последнее редактирование:

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,771
11,214
Описание: получение и изменение режима insert в полях ввода
Код:
Lua:
local memory = require('memory')
local versions = {
    r1 = 0x21A0E8,
    r2 = 0x21A0F0,
    r3 = 0x26E8CC,
    r4 = 0x26E9FC
}
local pInput = versions.r1

function isInsertActive()
    return memory.getint8(memory.getuint32(memory.getuint32(getModuleHandle("samp.dll") + pInput, true) + 0x8, true) + 0x11D, true) == 1
end

function switchInsertMode()
    memory.setint8(memory.getuint32(memory.getuint32(getModuleHandle("samp.dll") + pInput, true) + 0x8, true) + 0x11D, isInsertActive() and 0 or 1, true)
end
адреса нашел мой кумир - @armor
 
  • Нравится
Реакции: lorgon, why ega и ARMOR