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

Cosmo

Известный
Друг
653
2,724
Описание: Быстрый бег в любом месте. Например в интерьерах, где это ранее было запрещено (один из таких - завод около фермы)
Lua:
memory.hex2bin("B800000000C20400", 0x55E870, 8) -- ON
memory.hex2bin("8B4424048D04408B", 0x55E870, 8) -- OFF (default)
thanks @ARMOR

Описание: Снятие ограничение скорости транспорта в некоторых местах на карте. Например, одно из таких: мост SF-LV
Lua:
-- ON
memory.setuint8(0x72DDD0, 0x33, true)
memory.setuint8(0x72DDD1, 0xC0, true)
memory.setuint8(0x72DDD2, 0xC3, true)

-- OFF (default)
memory.setuint8(0x72DDD0, 0xA1, true)
memory.setuint8(0x72DDD1, 0xB8, true)
memory.setuint8(0x72DDD2, 0x7A, true)
thanks @ARMOR

Описание: Снятие ограничение скорости транспорта на железнодорожных рельсах (взято из SAP)
Lua:
memory.setfloat(0x8D34AC, 0.0, true) -- ON
memory.setfloat(0x8D34AC, 0.003, true) -- OFF (default)
 
Последнее редактирование:

Орк

Известный
211
136
Описание: Возвращает режим камеры. Код пару раз встречался на форуме, но сюда никто не занес.
Описание есть тут: https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/eCamMode.h
Или под спойлером
Lua:
local memory = require("memory")
eCamMode = memory.getint16(0xB6F1A8)
--or
eCamMode = readMemory(0xB6F1A8, 2, false)
Lua:
    -- MODE_NONE = 0,
    -- MODE_TOPDOWN = 1,
    -- MODE_GTACLASSIC = 2,
    -- MODE_BEHINDCAR = 3,
    -- MODE_FOLLOWPED = 4,
    -- MODE_AIMING = 5,
    -- MODE_DEBUG = 6,
    -- MODE_SNIPER = 7,
    -- MODE_ROCKETLAUNCHER = 8,
    -- MODE_MODELVIEW = 9,
    -- MODE_BILL = 10,
    -- MODE_SYPHON = 11,
    -- MODE_CIRCLE = 12,
    -- MODE_CHEESYZOOM = 13,
    -- MODE_WHEELCAM = 14,
    -- MODE_FIXED = 15,
    -- MODE_1STPERSON = 16,
    -- MODE_FLYBY = 17,
    -- MODE_CAM_ON_A_STRING = 18,
    -- MODE_REACTION = 19,
    -- MODE_FOLLOW_PED_WITH_BIND = 20,
    -- MODE_CHRIS = 21,
    -- MODE_BEHINDBOAT = 22,
    -- MODE_PLAYER_FALLEN_WATER = 23,
    -- MODE_CAM_ON_TRAIN_ROOF = 24,
    -- MODE_CAM_RUNNING_SIDE_TRAIN = 25,
    -- MODE_BLOOD_ON_THE_TRACKS = 26,
    -- MODE_IM_THE_PASSENGER_WOOWOO = 27,
    -- MODE_SYPHON_CRIM_IN_FRONT = 28,
    -- MODE_PED_DEAD_BABY = 29,
    -- MODE_PILLOWS_PAPS = 30,
    -- MODE_LOOK_AT_CARS = 31,
    -- MODE_ARRESTCAM_ONE = 32,
    -- MODE_ARRESTCAM_TWO = 33,
    -- MODE_M16_1STPERSON = 34,
    -- MODE_SPECIAL_FIXED_FOR_SYPHON = 35,
    -- MODE_FIGHT_CAM = 36,
    -- MODE_TOP_DOWN_PED = 37,
    -- MODE_LIGHTHOUSE = 38,
    -- MODE_SNIPER_RUNABOUT = 39,
    -- MODE_ROCKETLAUNCHER_RUNABOUT = 40,
    -- MODE_1STPERSON_RUNABOUT = 41,
    -- MODE_M16_1STPERSON_RUNABOUT = 42,
    -- MODE_FIGHT_CAM_RUNABOUT = 43,
    -- MODE_EDITOR = 44,
    -- MODE_HELICANNON_1STPERSON = 45,
    -- MODE_CAMERA = 46,
    -- MODE_ATTACHCAM = 47,
    -- MODE_TWOPLAYER = 48,
    -- MODE_TWOPLAYER_IN_CAR_AND_SHOOTING = 49,
    -- MODE_TWOPLAYER_SEPARATE_CARS = 50,
    -- MODE_ROCKETLAUNCHER_HS = 51,
    -- MODE_ROCKETLAUNCHER_RUNABOUT_HS = 52,
    -- MODE_AIMWEAPON = 53,
    -- MODE_TWOPLAYER_SEPARATE_CARS_TOPDOWN = 54,
    -- MODE_AIMWEAPON_FROMCAR = 55,
    -- MODE_DW_HELI_CHASE = 56,
    -- MODE_DW_CAM_MAN = 57,
    -- MODE_DW_BIRDY = 58,
    -- MODE_DW_PLANE_SPOTTER = 59,
    -- MODE_DW_DOG_FIGHT = 60,
    -- MODE_DW_FISH = 61,
    -- MODE_DW_PLANECAM1 = 62,
    -- MODE_DW_PLANECAM2 = 63,
    -- MODE_DW_PLANECAM3 = 64,
    -- MODE_AIMWEAPON_ATTACHED = 65

Пример:
Lua:
eCamMode = readMemory(0xB6F1A8, 2, false)
if eCamMode == 15 then print('Камера отсоединена от персонажа') end
if eCamMode == 53 then print('Вы целитесь из оружия') end
if eCamMode == 46 then print('Вы целитесь через камеру') end
 

ARMOR

Модератор по раксампу
Модератор
4,936
6,738
Описание: Меняет текстуру модели по указателю на неё ( скины, объекты и т.д )
ВНИМАНИЕ: Меняет текстуру всем игрокам с такой же моделью. Так же нельзя перезапускать скрипт ведь старая текстура удалится и вас крашнет нахуй, разве что сохраняйте старые текстуры моделей в таблице и при выгрузке скрипта устанавливайте старые текстурки

Lua:
local ffi = require("ffi")

ffi.cdef[[
    typedef void*(__cdecl *CallBack)(void* pMaterial, void* pData);
]]

local RpClumpForAllAtomics = ffi.cast("void*(__cdecl*)(void*, void*(__cdecl*)(void*, void*), void*)", 0x749B70)
local RpGeometryForAllMaterials = ffi.cast("void*(__cdecl*)(void*, void*(__cdecl*)(void*, void*), void*)", 0x74C790)

function materialTextureCB(pMaterial, pData)
    local pGeometry = ffi.cast("uintptr_t*", ffi.cast("uintptr_t", pMaterial) + 0x18)[0]
    ffi.cast("int*", pGeometry + 0x8)[0] = bit.bor(ffi.cast("int*", pGeometry + 0x8)[0], 0x40)
    RpGeometryForAllMaterials(ffi.cast("void*", pGeometry), ffi.cast("CallBack", atomicTextureCB), ffi.cast("void*", pData))
    return pMaterial
end

function atomicTextureCB(pAtomic, pData)
    local pTexture = ffi.cast("uintptr_t*", ffi.cast("uintptr_t", pAtomic) + 0x00)[0]
    local pRaster = ffi.cast("uintptr_t*", pTexture + 0x00)[0]
    ffi.cast("void**", pRaster + 0x34)[0] = pData
    return pAtomic
end

function setEntityModelTexture(pEntity, DxTexture)
    local pTexture = ffi.cast("void*", renderGetTextureStruct(DxTexture));
    local pRwObject = ffi.cast("uintptr_t*", pEntity + 0x18)[0];
    if (ffi.cast("unsigned char*", pRwObject)[0] == 1) then
        local pGeometry = ffi.cast("uintptr_t*", pRwObject + 0x18)[0]
        ffi.cast("int*", pGeometry + 0x8)[0] = bit.bor(ffi.cast("int*", pGeometry + 0x8)[0], 0x40)
        RpGeometryForAllMaterials(ffi.cast("void*", pGeometry), ffi.cast("CallBack", atomicTextureCB), ffi.cast("void*", pData))
    elseif ffi.cast("unsigned char*", pRwObject)[0] == 2 then
        RpClumpForAllAtomics(ffi.cast("void*", pRwObject), ffi.cast("CallBack", materialTextureCB), ffi.cast("void*", pTexture))
    end
end

Пример использования:
Lua:
function main()
    local myTexture = renderLoadTextureFromFile(".\\moonloader\\obama.png")
    while true do
        wait(0)
        if wasKeyPressed(49) then
            local pPed = getCharPointer(PLAYER_PED)
            setEntityModelTexture(pPed, myTexture)
        end
    end
end

Скриншот:
1730687765657.jpeg
 
Последнее редактирование:

hihihehe

Участник
6
27
Описание: генерирует билд версии скрипта в стиле GoldSrc (ссылка)
Пример использования:
example:
function generateBuildVersion(date)
    local day, month, year = date:match("(%d+).(%d+).(%d+)")
    local time = os.time({ day = tonumber(day), month = tonumber(month), year = tonumber(year), hour = 0 })
    local baseTime = os.time({ day = 1, month = 1, year = 1900, hour = 0 })

    return math.floor(os.difftime(time, baseTime) / (24 * 60 * 60) + 0.5)
end

local releaseDate = "24.10.1996"
local updateDate = "06.11.2024"
print(generateBuildVersion(updateDate) - generateBuildVersion(releaseDate)) -- output: 10240
Код:
code:
function generateBuildVersion(date)
    local day, month, year = date:match("(%d+).(%d+).(%d+)")
    local time = os.time({ day = tonumber(day), month = tonumber(month), year = tonumber(year), hour = 0 })
    local baseTime = os.time({ day = 1, month = 1, year = 1900, hour = 0 })

    return math.floor(os.difftime(time, baseTime) / (24 * 60 * 60) + 0.5)
end
 
Последнее редактирование:

Naito

Активный
116
26
Description: Add an expiration date.


code:
local function isModExpired()
    local currentTime = os.date("*t")
    if currentTime.year > endYear or
       (currentTime.year == endYear and currentTime.month > endMonth) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day > endDay) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day == endDay and currentTime.hour >= endHour and currentTime.min >= endMinute) then
        return true
    end
    return false
end

local endYear = 2025
local endMonth = 7
local endDay = 1
local endHour = 20
local endMinute = 30

-- Function to check if the current date is greater than or equal to the deactivation date
local function isModExpired()
    local currentTime = os.date("*t")
    if currentTime.year > endYear or
       (currentTime.year == endYear and currentTime.month > endMonth) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day > endDay) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day == endDay and currentTime.hour >= endHour and currentTime.min >= endMinute) then
        return true
    end
    return false
end

local function isModExpired()
    local currentTime = os.date("*t")
    if currentTime.year > endYear or
       (currentTime.year == endYear and currentTime.month > endMonth) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day > endDay) or
       (currentTime.year == endYear and currentTime.month == endMonth and currentTime.day == endDay and currentTime.hour >= endHour and currentTime.min >= endMinute) then
        return true
    end
    return false
end

-- Function to calculate the remaining time until deactivation
local function getTimeRemaining()
    local currentTime = os.time()
    local endTime = os.time{year = endYear, month = endMonth, day = endDay, hour = endHour, min = endMinute}

    local remaining = endTime - currentTime

    if remaining <= 0 then
        return "MOD EXPIRED!"
    end

    local days = math.floor(remaining / 86400)
    remaining = remaining % 86400

    local hours = math.floor(remaining / 3600)
    remaining = remaining % 3600

    local minutes = math.floor(remaining / 60)
    local seconds = remaining % 60

    return string.format("TIME LEFT UNTIL EXPIRATION: %d days, %02d:%02d:%02d", days, hours, minutes, seconds)
end
 

1NEXPL1CA

Известный
736
365
Описание: рисует текст с чёрной обводкой mimgui (т.к в mimgui вроде нельзя поменять флаг шрифта)
Думаю реализация не из лучших, посоветуйте свои варианты!
Код:

Lua:
function imgui.TextWithOutline(DRAW_LIST, X, Y, COLOR, TEXT, OFFSET)
    local OFFSETS = {
        {-OFFSET, 0}, {OFFSET, 0}, {0, -OFFSET}, {0, OFFSET},{-OFFSET, -OFFSET}, {-OFFSET, OFFSET}, {OFFSET, -OFFSET}, {OFFSET, OFFSET}
    }
    for _, OFFSET in ipairs(OFFSETS) do
        DRAW_LIST:AddText(imgui.ImVec2(X - OFFSET[1], Y - OFFSET[2]), 0xFF000000, TEXT)
    end
    DRAW_LIST:AddText(imgui.ImVec2(X, Y), COLOR, TEXT)
end