File size: 4,813 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
--[[
    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 'CPoint'
shared.require 'CRect'
shared.require 'CMatrix'
shared.require 'CVector'

shared.ffi.cdef[[
enum SObjectEditType {
    OBJECT_EDIT_TYPE_NONE = 0,
    OBJECT_EDIT_TYPE_ATTACHEDOBJECT = 2,
    OBJECT_EDIT_TYPE_OBJECT = 1,
};
typedef enum SObjectEditType SObjectEditType;

enum SObjectEditMode {
    OBJECT_EDIT_MODE_POSITION = 0,
    OBJECT_EDIT_MODE_ROTATION = 1,
    OBJECT_EDIT_MODE_SCALE = 2,
};
typedef enum SObjectEditMode SObjectEditMode;

enum SObjectEditProcessType {
    OBJECT_EDIT_PROCESS_TYPE_XAXIS = 0,
    OBJECT_EDIT_PROCESS_TYPE_YAXIS = 1,
    OBJECT_EDIT_PROCESS_TYPE_ZAXIS = 2,
    OBJECT_EDIT_PROCESS_TYPE_SETPOSITION = 3,
    OBJECT_EDIT_PROCESS_TYPE_SETROTATION = 4,
    OBJECT_EDIT_PROCESS_TYPE_SETSCALE = 5,
    OBJECT_EDIT_PROCESS_TYPE_SAVE = 10,
};
typedef enum SObjectEditProcessType SObjectEditProcessType;

typedef struct SCObjectEdit SCObjectEdit;
#pragma pack(push, 1)
struct SCObjectEdit {
    SCPoint m_CharMaxSize;
    SCRect m_xAxisButtonRect;
    SCRect m_yAxisButtonRect;
    SCRect m_zAxisButtonRect;
    SCRect m_PositionButtonRect;
    SCRect m_RotationButtonRect;
    SCRect m_ScaleButtonRect;
    SCRect m_SaveButtonRect;
    int m_nEditType;
    int m_nEditMode;
    BOOL m_bEnabled;
    BOOL m_bRenderedThisFrame;
    ID m_nEditObjectId;
    unsigned int m_nAttachedObjectIndex;
    BOOL m_bIsPlayerObject;
    SCVector m_vRotation;
    unsigned int m_nLastSentNotificationTick;
    bool m_bRenderScaleButton;
    bool m_bEditingRightNow;
    bool m_bTopXOfObjectIsOnLeftOfScreen;
    bool m_bTopYOfObjectIsOnLeftOfScreen;
    bool m_bTopZOfObjectIsOnLeftOfScreen;
    SCPoint m_EditStartPos;
    SCPoint m_CursorPosInGame;
    BOOL m_bObjectXSizeYCoordDiffMoreThanX;
    BOOL m_bObjectYSizeYCoordDiffMoreThanX;
    BOOL m_bObjectZSizeYCoordDiffMoreThanX;
    SCMatrix m_entityMatrix;
    struct IDirect3DDevice9* m_pDevice;
    struct ID3DXLine* m_pLine;
    struct ID3DXFont* m_pIconFontSmall;
    struct ID3DXFont* m_pIconFontBig;
    int m_nProcessType;
};
#pragma pack(pop)
]]

shared.validate_size('struct SCObjectEdit', 0x117)

local CObjectEdit_constructor = ffi.cast('SCObjectEdit*(__thiscall*)(SCObjectEdit*, IDirect3DDevice9*)', 0x71B60)
local function CObjectEdit_new(...)
    local obj = ffi.new('struct SCObjectEdit[1]')
    CObjectEdit_constructor(obj, ...)
    return obj
end

local GetMaxSizeChar = ffi.cast('const char*(__cdecl*)()', sampapi.GetAddress(0x71F90))

local SCObjectEdit_mt = {
    WorldToScreen = ffi.cast('float(__thiscall*)(SCObjectEdit*, SCVector*, float*)', sampapi.GetAddress(0x71C20)),
    RenderAxes = ffi.cast('int(__thiscall*)(SCObjectEdit*, SCMatrix*, float)', sampapi.GetAddress(0x71D20)),
    GetRenderChar = ffi.cast('const char*(__thiscall*)(SCObjectEdit*, BOOL)', sampapi.GetAddress(0x71FA0)),
    TryChangeProcessType = ffi.cast('void(__thiscall*)(SCObjectEdit*)', sampapi.GetAddress(0x720A0)),
    SetEditMode = ffi.cast('void(__thiscall*)(SCObjectEdit*, SObjectEditMode)', sampapi.GetAddress(0x721F0)),
    ResetMousePos = ffi.cast('void(__thiscall*)(SCObjectEdit*)', sampapi.GetAddress(0x723C0)),
    EnterEditObject = ffi.cast('void(__thiscall*)(SCObjectEdit*, ID, BOOL)', sampapi.GetAddress(0x72420)),
    SendEditEndNotification = ffi.cast('void(__thiscall*)(SCObjectEdit*, int)', sampapi.GetAddress(0x728B0)),
    SendAttachedEditEndNotification = ffi.cast('void(__thiscall*)(SCObjectEdit*, int)', sampapi.GetAddress(0x72AC0)),
    Disable = ffi.cast('void(__thiscall*)(SCObjectEdit*, BOOL)', sampapi.GetAddress(0x72BC0)),
    RenderControlsForObject = ffi.cast('BOOL(__thiscall*)(SCObjectEdit*, SCMatrix*, float)', sampapi.GetAddress(0x72C30)),
    ApplyChanges = ffi.cast('void(__thiscall*)(SCObjectEdit*, SObjectEditProcessType, float)', sampapi.GetAddress(0x73460)),
    ProcessMouseMove = ffi.cast('float(__thiscall*)(SCObjectEdit*)', sampapi.GetAddress(0x73480)),
    MsgProc = ffi.cast('BOOL(__thiscall*)(SCObjectEdit*, int, int, int)', sampapi.GetAddress(0x73550)),
    Render = ffi.cast('void(__thiscall*)(SCObjectEdit*)', sampapi.GetAddress(0x73780)),
}
mt.set_handler('struct SCObjectEdit', '__index', SCObjectEdit_mt)

local function RefObjectEdit() return ffi.cast('SCObjectEdit**', sampapi.GetAddress(0x26EB60))[0] end

return {
    new = CObjectEdit_new,
    GetMaxSizeChar = GetMaxSizeChar,
    RefObjectEdit = RefObjectEdit,
}