File size: 2,448 Bytes
d7c5875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--[[
    Project: SAMP-API.lua <https://github.com/imring/SAMP-API.lua>
    Developers: imring, LUCHARE, FYP

    Special thanks:
        SAMemory (https://www.blast.hk/threads/20472/) for implementing the basic functions.
        SAMP-API (https://github.com/BlastHackNet/SAMP-API) for the structures and addresses.
]]

local sampapi = require 'sampapi'
local shared = sampapi.shared
local mt = require 'sampapi.metatype'
local ffi = require 'ffi'

shared.ffi.cdef[[
enum {
    MAX_MENU_ITEMS = 12,
    MAX_COLUMNS = 2,
    MAX_MENU_LINE = 33,
};

typedef struct SInteraction SInteraction;
#pragma pack(push, 1)
struct SInteraction {
    BOOL m_bMenu;
    BOOL m_bRow[12];
    BOOL m_bPadding[3];
};
#pragma pack(pop)

typedef struct SCMenu SCMenu;
#pragma pack(push, 1)
struct SCMenu {
    unsigned char m_nId;
    char m_szTitle[33];
    char m_szItems[12][2][33];
    char m_szHeader[2][33];
    float m_fPosX;
    float m_fPosY;
    float m_fFirstColumnWidth;
    float m_fSecondColumnWidth;
    unsigned char m_nColumns;
    SInteraction m_interaction;
    unsigned char m_nColumnCount[2];
    GTAREF m_panel;
};
#pragma pack(pop)
]]

shared.validate_size('struct SInteraction', 0x40)
shared.validate_size('struct SCMenu', 0x3d3)

local CMenu_constructor = ffi.cast('void(__thiscall*)(SCMenu*, float, float, char, float, float, const SInteraction*)', 0xA7420)
local function CMenu_new(...)
    local obj = ffi.new('struct SCMenu[1]')
    CMenu_constructor(obj, ...)
    return obj
end

local SCMenu_mt = {
    SetTitle = ffi.cast('void(__thiscall*)(SCMenu*, const char*)', sampapi.GetAddress(0xA7530)),
    AddItem = ffi.cast('void(__thiscall*)(SCMenu*, NUMBER, NUMBER, const char*)', sampapi.GetAddress(0xA7580)),
    SetColumnTitle = ffi.cast('void(__thiscall*)(SCMenu*, NUMBER, const char*)', sampapi.GetAddress(0xA7600)),
    Hide = ffi.cast('void(__thiscall*)(SCMenu*)', sampapi.GetAddress(0xA7670)),
    GetItem = ffi.cast('char*(__thiscall*)(SCMenu*, NUMBER, NUMBER)', sampapi.GetAddress(0xA7690)),
    GetTitle = ffi.cast('char*(__thiscall*)(SCMenu*)', sampapi.GetAddress(0xA76B0)),
    MS = ffi.cast('char*(__thiscall*)(SCMenu*, NUMBER, NUMBER)', sampapi.GetAddress(0xA76E0)),
    GetActiveRow = ffi.cast('char(__thiscall*)(SCMenu*)', sampapi.GetAddress(0xA7710)),
    Show = ffi.cast('void(__thiscall*)(SCMenu*)', sampapi.GetAddress(0xA7740)),
}
mt.set_handler('struct SCMenu', '__index', SCMenu_mt)

return {
    new = CMenu_new,
}