File size: 3,444 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
--[[
    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.require 'CVector'

shared.ffi.cdef[[
typedef struct STransmit STransmit;
#pragma pack(push, 1)
struct STransmit {
    union {
        struct {
            unsigned char m_bBox : 1;
            unsigned char m_bLeft : 1;
            unsigned char m_bRight : 1;
            unsigned char m_bCenter : 1;
            unsigned char m_bProportional : 1;
        };
        unsigned char m_nFlags;
    };
    float m_fLetterWidth;
    float m_fLetterHeight;
    D3DCOLOR m_letterColor;
    float m_fBoxWidth;
    float m_fBoxHeight;
    D3DCOLOR m_boxColor;
    unsigned char m_nShadow;
    bool m_bOutline;
    D3DCOLOR m_backgroundColor;
    unsigned char m_nStyle;
    unsigned char is_selectable;
    float m_fX;
    float m_fY;
    short unsigned int m_nModel;
    SCVector m_rotation;
    float m_fZoom;
    short unsigned int m_aColor[2];
};
#pragma pack(pop)

typedef struct SData SData;
#pragma pack(push, 1)
struct SData {
    float m_fLetterWidth;
    float m_fLetterHeight;
    D3DCOLOR m_letterColor;
    unsigned char unknown;
    unsigned char m_bCenter;
    unsigned char m_bBox;
    float m_fBoxSizeX;
    float m_fBoxSizeY;
    D3DCOLOR m_boxColor;
    unsigned char m_nProportional;
    D3DCOLOR m_backgroundColor;
    unsigned char m_nShadow;
    unsigned char m_nOutline;
    unsigned char m_bLeft;
    unsigned char m_bRight;
    int m_nStyle;
    float m_fX;
    float m_fY;
    unsigned char pad_[8];
    long unsigned int field_99B;
    long unsigned int field_99F;
    long unsigned int m_nIndex;
    unsigned char is_selectable;
    short unsigned int m_nModel;
    SCVector m_rotation;
    float m_fZoom;
    short unsigned int m_aColor[2];
    unsigned char field_9BE;
    unsigned char drawn_this_frame;
    unsigned char text_contains_keys;
    long unsigned int computed_left;
    long unsigned int computed_top;
    long unsigned int computed_right;
    long unsigned int computed_bottom;
    unsigned char is_selected;
    long unsigned int color_if_selected;
};
#pragma pack(pop)

typedef struct SCTextDraw SCTextDraw;
#pragma pack(push, 1)
struct SCTextDraw {
    char m_szText[801];
    char m_szString[1602];
    SData m_data;
};
#pragma pack(pop)
]]

shared.validate_size('struct STransmit', 0x3f)
shared.validate_size('struct SData', 0x73)
shared.validate_size('struct SCTextDraw', 0x9d6)

local CTextDraw_constructor = ffi.cast('void(__thiscall*)(SCTextDraw*, STransmit*, const char*)', 0xB36E0)
local CTextDraw_destructor = ffi.cast('void(__thiscall*)(SCTextDraw*)', 0xB2F50)
local function CTextDraw_new(...)
    local obj = ffi.gc(ffi.new('struct SCTextDraw[1]'), CTextDraw_destructor)
    CTextDraw_constructor(obj, ...)
    return obj
end

local SCTextDraw_mt = {
    SetText = ffi.cast('void(__thiscall*)(SCTextDraw*, const char*)', sampapi.GetAddress(0xB36E0)),
    Draw = ffi.cast('void(__thiscall*)(SCTextDraw*)', sampapi.GetAddress(0xB3480)),
}
mt.set_handler('struct SCTextDraw', '__index', SCTextDraw_mt)

return {
    new = CTextDraw_new,
}