Информация MoonLoader - разработка

imring

Ride the Lightning
Всефорумный модератор
2,354
2,516
Так и АХК может. Нужен просчет структур на FFI)
Lua:
ffi = require 'ffi'
memory = require 'memory'

ffi.cdef[[
typedef struct stDialogInfo
{
    int    iTextPoxX;
    int    iTextPoxY;
    uint32_t    uiDialogSizeX;
    uint32_t    uiDialogSizeY;
    int    iBtnOffsetX;
    int    iBtnOffsetY;
    int    iIsActive;
    int    iType;
    uint32_t    DialogID;
    char        *pText;
    uint32_t    uiTextWidth;
    uint32_t    uiTextHeight;
    char        szCaption[65];
    int        bServerside;
} stDialogInfo;

int __stdcall GetModuleHandleA(const char* lpModuleName);
]]

local SAMP_DIALOG_INFO_OFFSET = 0x21A0B8

local function getStDialogInfo()
    return ffi.cast('stDialogInfo*', sampGetBase())
end

function sampGetBase()
    return ffi.C.GetModuleHandleA('samp.dll')
end

function isSampLoaded()
    return (sampGetBase() > 0x0) and true or false
end

function sampGetDialogPtr()
    return memory.getint32( sampGetBase() + SAMP_DIALOG_INFO_OFFSET )
end

function sampIsDialogActive()
    local int = memory.getint8( sampGetDialogPtr() + getStDialogInfo().iIsActive )
    return (int == 1) and true or false
end
 

AnWu

Guardian of Order
Всефорумный модератор
4,689
5,196
Lua:
ffi = require 'ffi'
memory = require 'memory'

ffi.cdef[[
typedef struct stDialogInfo
{
    int    iTextPoxX;
    int    iTextPoxY;
    uint32_t    uiDialogSizeX;
    uint32_t    uiDialogSizeY;
    int    iBtnOffsetX;
    int    iBtnOffsetY;
    int    iIsActive;
    int    iType;
    uint32_t    DialogID;
    char        *pText;
    uint32_t    uiTextWidth;
    uint32_t    uiTextHeight;
    char        szCaption[65];
    int        bServerside;
} stDialogInfo;

int __stdcall GetModuleHandleA(const char* lpModuleName);
]]

local SAMP_DIALOG_INFO_OFFSET = 0x21A0B8

local function getStDialogInfo()
    return ffi.cast('stDialogInfo*', sampGetBase())
end

function sampGetBase()
    return ffi.C.GetModuleHandleA('samp.dll')
end

function isSampLoaded()
    return (sampGetBase() > 0x0) and true or false
end

function sampGetDialogPtr()
    return memory.getint32( sampGetBase() + SAMP_DIALOG_INFO_OFFSET )
end

function sampIsDialogActive()
    local int = memory.getint8( sampGetDialogPtr() + getStDialogInfo().iIsActive )
    return (int == 1) and true or false
end
да бля, в том то и дело что диалогОффсет меняется из версии в версию. Тебе нужно найти способ не указывать прямые адреса на начало структуры.
 

imring

Ride the Lightning
Всефорумный модератор
2,354
2,516
Тебе нужно найти способ не указывать прямые адреса на начало структуры.
не нашёл (пока что). memory.strptr не подходит.
Lua:
ffi = require 'ffi'
memory = require 'memory'

SAMP_INFO_OFFSET                = 0x21A0F8

ffi.cdef[[

typedef struct stSAMP {
    void                    *pUnk0;
    struct stServerInfo            *pServerInfo;
    uint8_t                    byteSpace[24];
    char                    szIP[257];
    char                    szHostname[259];
    bool                    bNametagStatus;
    uint32_t                ulPort;
    uint32_t                ulMapIcons[100];
    int                        iLanMode;
    int                        iGameState;
    uint32_t                ulConnectTick;
    struct stServerPresets            *pSettings;
    void                    *pRakClientInterface;
    struct stSAMPPools        *pPools;
} stSAMP;

typedef struct stServerInfo {
    uint32_t             uiIP;
    uint16_t             usPort;
} stServerInfo;

int __stdcall GetModuleHandleA(const char* lpModuleName);
]]

function sampGetBase()
    return ffi.C.GetModuleHandleA('samp.dll')
end

function isSampLoaded()
    return sampGetBase() > 0x0
end

function sampGetSampInfoPtr()
    return memory.getint32( sampGetBase() + SAMP_INFO_OFFSET )
end

local function getDataStSamp()
    return ffi.cast('stSAMP*', sampGetSampInfoPtr())
end

function sampGetCurrentServerName()
    return ffi.string(getDataStSamp().szHostname)
end
 
  • Нравится
Реакции: AnWu

FYP

Известный
Автор темы
Администратор
1,758
5,728
Тебе нужно найти способ не указывать прямые адреса на начало структуры.
такого способа не существует. с этим у него всё сделано верно

@imring получать базовый адрес модуля не обязательно через ffi, можно использовать lua - getmodulehandle | BlastHack — DEV_WIKI(https://blast.hk/wiki/lua:getmodulehandle)
 
  • Нравится
Реакции: imring

imring

Ride the Lightning
Всефорумный модератор
2,354
2,516
@FYP почему ulPort выводит 0?
Lua:
ffi = require 'ffi'
memory = require 'memory'

SAMP_INFO_OFFSET                = 0x21A0F8

ffi.cdef[[

typedef struct stSAMP
{
    void                    *pUnk0;
    struct stServerInfo            *pServerInfo;
    uint8_t                    byteSpace[24];
    char                    szIP[257];
    char                    szHostname[259];
    bool                    bNametagStatus; // changes by /nametagstatus
    uint32_t                ulPort;
    uint32_t                ulMapIcons[100];
    int                        iLanMode;
    int                        iGameState;
    uint32_t                ulConnectTick;
    struct stServerPresets    *pSettings;
    void                    *pRakClientInterface;
    struct stSAMPPools        *pPools;
} stSAMP;

typedef struct stServerInfo {
    uint32_t             uiIP;
    uint16_t             usPort;
} stServerInfo;
]]

function sampGetBase()
    return getModuleHandle('samp.dll')
end

function isSampLoaded()
    return sampGetBase() > 0x0
end

function sampGetSampInfoPtr()
    return memory.getint32( sampGetBase() + SAMP_INFO_OFFSET )
end

local function getDataStSamp()
    return ffi.cast('stSAMP*', sampGetSampInfoPtr())
end

function sampGetCurrentServerName()
    return ffi.string(getDataStSamp().szHostname)
end

function sampGetCurrentServerAddress()
    return ffi.string(getDataStSamp().szIP), getDataStSamp().ulPort
end

скрипт:
Lua:
require 'sf'

function main()
    while not isSampAvailable() do wait(0) end
    print(sampGetCurrentServerAddress())
    wait(-1)
end

moonloader.log:
Код:
[ML] (script) aa.lua: 79.133.50.48   0
 

AnWu

Guardian of Order
Всефорумный модератор
4,689
5,196
такого способа не существует. с этим у него всё сделано верно

@imring получать базовый адрес модуля не обязательно через ffi, можно использовать lua - getmodulehandle | BlastHack — DEV_WIKI(https://blast.hk/wiki/lua:getmodulehandle)
Ну я немного не так выразился, суть в том что оффсеты всегда разные. Как я понял как раз и надо самое самое начало структуры сампа и строить крипичики. Я в этом нуб, поэтому вот слежу
 

imring

Ride the Lightning
Всефорумный модератор
2,354
2,516
что со структурой не так?
Lua:
local SAMP_DIALOG_INFO = 0x21A0B8

ffi.cdef[[
struct stDialogInfo
{
    int    iTextPoxX;
    int    iTextPoxY;
    uint32_t    uiDialogSizeX;
    uint32_t    uiDialogSizeY;
    int    iBtnOffsetX;
    int    iBtnOffsetY;
    struct _CDXUTDialog                        *pDialog;
    struct _CDXUTListBox                        *pList;
    struct _CDXUTIMEEditBox                        *pEditBox;
    uint8_t        iIsActive;
    int    iType;
    uint32_t    DialogID;
    char        *pText;
    uint32_t    uiTextWidth;
    uint32_t    uiTextHeight;
    char        szCaption[65];
    int        bServerside;
} __attribute__ ((packed));

typedef struct stDialogInfo stDialogInfo;]]

local function getStruct(struct_name, mem)
    return ffi.cast(struct_name..'*', mem)
end

function sampGetDialogInfoPtr()
    return memory.getint32( sampGetBase() + SAMP_DIALOG_INFO )
end

local stDIALOG = getStruct('stDialogInfo', sampGetDialogInfoPtr())

function sampGetDialogCaption()
    return ffi.string(stDIALOG.szCaption)
end
функция sampGetDialogCaption() выводит пустую строку.
 

ufdhbi

Известный
Проверенный
1,455
861
Не работает хук на onServerMessage, moonloader 026, логи чисты, весь остальной функционал работает, код который не работает:
Lua:
function hook.onServerMessage(color, message)
    sampAddChatMessage(message,-1)
end
На 025 работает, установил 026, не внося изменений в скрипт - не работает