File size: 12,293 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
--[[
    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 'v037r5.CEntity'
shared.require 'CMatrix'
shared.require 'CVector'
shared.require 'v037r5.ControllerState'
shared.require 'v037r5.AimStuff'

shared.ffi.cdef[[
typedef struct SCObject SCObject;
struct SCObject;

enum {
    MAX_ACCESSORIES = 10,
};

enum SStuffType {
    STUFF_TYPE_NONE = 0,
    STUFF_TYPE_BEER = 1,
    STUFF_TYPE_DYN_BEER = 2,
    STUFF_TYPE_PINT_GLASS = 3,
    STUFF_TYPE_CIGGI = 4,
};
typedef enum SStuffType SStuffType;

typedef struct SAccessory SAccessory;
#pragma pack(push, 1)
struct SAccessory {
    int m_nModel;
    int m_nBone;
    SCVector m_offset;
    SCVector m_rotation;
    SCVector m_scale;
    D3DCOLOR m_firstMaterialColor;
    D3DCOLOR m_secondMaterialColor;
};
#pragma pack(pop)

typedef struct SCPed SCPed;
#pragma pack(push, 1)
struct SCPed : SCEntity {
    BOOL m_bUsingCellphone;
    struct {
        BOOL m_bNotEmpty[10];
        SAccessory m_info[10];
        SCObject* m_pObject[10];
    } m_accessories;
    struct CPed* m_pGamePed;
    unsigned int pad_2a8[2];
    unsigned char m_nPlayerNumber;
    unsigned int pad_2b1[2];
    GTAREF m_parachuteObject;
    GTAREF m_urinatingParticle;
    struct {
        int m_nType;
        GTAREF m_object;
        unsigned int m_nDrunkLevel;
    } m_stuff;
    GTAREF m_arrow;
    unsigned char field_2de;
    BOOL m_bDoesDancing;
    unsigned int m_nDanceStyle;
    unsigned int m_nLastDanceMove;
    unsigned char pad_2de[20];
    BOOL m_bDoesUrinating;
    unsigned char pad[55];
};
#pragma pack(pop)
]]

shared.validate_size('struct SAccessory', 0x34)
shared.validate_size('struct SCPed', 0x32d)

local CPed_constructor = ffi.cast('void(__thiscall*)(SCPed*)', 0xABA70)
local function CPed_new(...)
    local obj = ffi.new('struct SCPed[1]')
    CPed_constructor(obj, ...)
    return obj
end

local SCPed_mt = {
    ResetPointers = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABBB0)),
    SetInitialState = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABBD0)),
    GetAim = ffi.cast('SAim * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xABBF0)),
    SetAim = ffi.cast('void(__thiscall*)(SCPed*, const SAim*)', sampapi.GetAddress(0xABC30)),
    GetCurrentWeapon = ffi.cast('char(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABC50)),
    GetVehicleRef = ffi.cast('GTAREF(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABC90)),
    DeleteArrow = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABCB0)),
    IsOnScreen = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABCE0)),
    SetImmunities = ffi.cast('void(__thiscall*)(SCPed*, BOOL, BOOL, BOOL, BOOL, BOOL)', sampapi.GetAddress(0xABD00)),
    GetHealth = ffi.cast('float(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABD50)),
    SetHealth = ffi.cast('void(__thiscall*)(SCPed*, float)', sampapi.GetAddress(0xABD70)),
    GetArmour = ffi.cast('float(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABD90)),
    SetArmour = ffi.cast('void(__thiscall*)(SCPed*, float)', sampapi.GetAddress(0xABDB0)),
    GetFlags = ffi.cast('int(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABDD0)),
    SetFlags = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xABDF0)),
    IsDead = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABE10)),
    GetState = ffi.cast('char(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABE40)),
    SetState = ffi.cast('void(__thiscall*)(SCPed*, char)', sampapi.GetAddress(0xABE50)),
    GetRotation = ffi.cast('float(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABE90)),
    ForceRotation = ffi.cast('void(__thiscall*)(SCPed*, float)', sampapi.GetAddress(0xABF10)),
    SetRotation = ffi.cast('void(__thiscall*)(SCPed*, float)', sampapi.GetAddress(0xABF60)),
    IsPassenger = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xABFC0)),
    GetVehicle = ffi.cast('struct CVehicle * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC000)),
    ClearWeapons = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC010)),
    SetArmedWeapon = ffi.cast('void(__thiscall*)(SCPed*, int, bool)', sampapi.GetAddress(0xAC060)),
    RemoveWeaponWhenEnteringVehicle = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC140)),
    GetCurrentWeaponSlot = ffi.cast('struct CWeapon * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC140)),
    CurrentWeaponHasAmmo = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC160)),
    GetDistanceToEntity = ffi.cast('float(__thiscall*)(SCPed*, const SCEntity*)', sampapi.GetAddress(0xAC1A0)),
    GetVehicleSeatIndex = ffi.cast('int(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC200)),
    PutIntoVehicle = ffi.cast('void(__thiscall*)(SCPed*, GTAREF, int)', sampapi.GetAddress(0xAC290)),
    EnterVehicle = ffi.cast('void(__thiscall*)(SCPed*, GTAREF, BOOL)', sampapi.GetAddress(0xAC410)),
    ExitVehicle = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAC4E0)),
    WarpFromVehicle = ffi.cast('void(__thiscall*)(SCPed*, SCVector)', sampapi.GetAddress(0xAC570)),
    SetSpawnInfo = ffi.cast('void(__thiscall*)(SCPed*, const SCVector*, float)', sampapi.GetAddress(0xAC750)),
    SetControllable = ffi.cast('void(__thiscall*)(SCPed*, BOOL)', sampapi.GetAddress(0xAC790)),
    GetDeathInfo = ffi.cast('char(__thiscall*)(SCPed*, ID*)', sampapi.GetAddress(0xAC850)),
    GetFloor = ffi.cast('struct CEntity * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xACA10)),
    GetCurrentWeaponInfo = ffi.cast('struct CWeaponInfo * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xACAC0)),
    HandsUp = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACB10)),
    DoesHandsUp = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACB60)),
    HoldObject = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xACBC0)),
    EnableJetpack = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACD10)),
    DisableJetpack = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACD60)),
    HasJetpack = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACDC0)),
    EnablePassengerDrivebyMode = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xACF90)),
    Extinguish = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD0F0)),
    GetCurrentWeaponAmmo = ffi.cast('unsigned short(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD150)),
    GetWeaponSlot = ffi.cast('struct CWeapon * (__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAD190)),
    SetWalkStyle = ffi.cast('void(__thiscall*)(SCPed*, const char*)', sampapi.GetAddress(0xAD1D0)),
    PerformAnimation = ffi.cast('void(__thiscall*)(SCPed*, const char*, const char*, float, int, int, int, int, int)', sampapi.GetAddress(0xAD230)),
    LinkToInterior = ffi.cast('void(__thiscall*)(SCPed*, char, BOOL)', sampapi.GetAddress(0xAD340)),
    DestroyParachute = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD3E0)),
    OpenParachute = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD4D0)),
    ProcessParachuteEvent = ffi.cast('void(__thiscall*)(SCPed*, const char*)', sampapi.GetAddress(0xAD620)),
    IsOnGround = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD860)),
    ResetDamageEntity = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD880)),
    RemoveWeaponModel = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAD8B0)),
    GetAimZ = ffi.cast('float(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD8F0)),
    SetAimZ = ffi.cast('void(__thiscall*)(SCPed*, float)', sampapi.GetAddress(0xAD930)),
    GetContactEntity = ffi.cast('struct CEntity * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD9A0)),
    GetContactVehicle = ffi.cast('struct CVehicle * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD9B0)),
    GetStat = ffi.cast('int(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAD9E0)),
    PerformingCustomAnimation = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADA00)),
    StartDancing = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xADAD0)),
    StopDancing = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADB20)),
    DoesDancing = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADB60)),
    GetAnimationForDance = ffi.cast('const char*(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xADB70)),
    DropStuff = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADC00)),
    GetStuff = ffi.cast('int(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADC90)),
    ApplyStuff = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADCA0)),
    ProcessDrunk = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADDF0)),
    GetDrunkLevel = ffi.cast('int(__thiscall*)(SCPed*)', sampapi.GetAddress(0xADFA0)),
    SetDrunkLevel = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xADFB0)),
    ApplyCommandTask = ffi.cast('void(__thiscall*)(SCPed*, const char*, int, int, int, int, int, int, int, int, int)', sampapi.GetAddress(0xADFD0)),
    DestroyCommandTask = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE020)),
    EnableCellphone = ffi.cast('void(__thiscall*)(SCPed*, BOOL)', sampapi.GetAddress(0xAE070)),
    UsingCellphone = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE0A0)),
    SetFightingStyle = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAE0D0)),
    StartUrinating = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE100)),
    StopUrinating = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE1E0)),
    DoesUrinating = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE260)),
    GetLoadedShoppingDataSubsection = ffi.cast('const char*(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAE2E0)),
    LoadShoppingDataSubsection = ffi.cast('void(__thiscall*)(SCPed*, const char*)', sampapi.GetAddress(0xAE300)),
    GetAimedPed = ffi.cast('struct CPed * (__thiscall*)(SCPed*)', sampapi.GetAddress(0xAEF60)),
    SetKeys = ffi.cast('void(__thiscall*)(SCPed*, short, short, short)', sampapi.GetAddress(0xAF340)),
    GetKeys = ffi.cast('short(__thiscall*)(SCPed*, short*, short*)', sampapi.GetAddress(0xAF5D0)),
    CreateArrow = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAF730)),
    SetModelIndex = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAFF50)),
    Kill = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAFFD0)),
    SetWeaponAmmo = ffi.cast('void(__thiscall*)(SCPed*, unsigned char, unsigned short)', sampapi.GetAddress(0xB0080)),
    ProcessDancing = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xB00B0)),
    GiveStuff = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xB02D0)),
    Destroy = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xB0FA0)),
    SetCameraMode = ffi.cast('void(__thiscall*)(SCPed*, char)', sampapi.GetAddress(0x14340)),
    SetCameraExtZoomAndAspectRatio = ffi.cast('void(__thiscall*)(SCPed*, float, float)', sampapi.GetAddress(0x14360)),
    HasAccessory = ffi.cast('BOOL(__thiscall*)(SCPed*)', sampapi.GetAddress(0xAEE30)),
    DeleteAccessory = ffi.cast('void(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAEE50)),
    GetAccessoryState = ffi.cast('BOOL(__thiscall*)(SCPed*, int)', sampapi.GetAddress(0xAEEB0)),
    DeleteAllAccessories = ffi.cast('void(__thiscall*)(SCPed*)', sampapi.GetAddress(0xB0AB0)),
    AddAccessory = ffi.cast('void(__thiscall*)(SCPed*, int, const SAccessory*)', sampapi.GetAddress(0xB0B10)),
    GetAccessory = ffi.cast('SCObject * (__thiscall*)(SCPed*, int)', sampapi.GetAddress(0x13680)),
    GetCameraMode = ffi.cast('char(__thiscall*)(SCPed*)', sampapi.GetAddress(0x2CD0)),
    GetBonePosition = ffi.cast('void(__thiscall*)(SCPed*, unsigned int, SCVector*)', sampapi.GetAddress(0xAE480)),
}
mt.set_handler('struct SCPed', '__index', SCPed_mt)

local AimStuff = {}

return {
    new = CPed_new,
    AimStuff = AimStuff,
}