-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.lua
251 lines (228 loc) · 9.02 KB
/
client.lua
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
----------------- DATAVIEW FUNCTIONS -------------
----------------- -------------
----------------- BIG THNKS to gottfriedleibniz for this DataView in LUA. -------------
----------------- https://gist.github.com/gottfriedleibniz/8ff6e4f38f97dd43354a60f8494eedff -------------
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
local _strblob = string.blob or function(length)
return string.rep("\0", math.max(40 + 1, length))
end
DataView = {
EndBig = ">",
EndLittle = "<",
Types = {
Int8 = { code = "i1", size = 1 },
Uint8 = { code = "I1", size = 1 },
Int16 = { code = "i2", size = 2 },
Uint16 = { code = "I2", size = 2 },
Int32 = { code = "i4", size = 4 },
Uint32 = { code = "I4", size = 4 },
Int64 = { code = "i8", size = 8 },
Uint64 = { code = "I8", size = 8 },
LuaInt = { code = "j", size = 8 },
UluaInt = { code = "J", size = 8 },
LuaNum = { code = "n", size = 8},
Float32 = { code = "f", size = 4 },
Float64 = { code = "d", size = 8 },
String = { code = "z", size = -1, },
},
FixedTypes = {
String = { code = "c", size = -1, },
Int = { code = "i", size = -1, },
Uint = { code = "I", size = -1, },
},
}
DataView.__index = DataView
local function _ib(o, l, t) return ((t.size < 0 and true) or (o + (t.size - 1) <= l)) end
local function _ef(big) return (big and DataView.EndBig) or DataView.EndLittle end
local SetFixed = nil
function DataView.ArrayBuffer(length)
return setmetatable({
offset = 1, length = length, blob = _strblob(length)
}, DataView)
end
function DataView.Wrap(blob)
return setmetatable({
offset = 1, blob = blob, length = blob:len(),
}, DataView)
end
function DataView:Buffer() return self.blob end
function DataView:ByteLength() return self.length end
function DataView:ByteOffset() return self.offset end
function DataView:SubView(offset)
return setmetatable({
offset = offset, blob = self.blob, length = self.length,
}, DataView)
end
for label,datatype in pairs(DataView.Types) do
DataView["Get" .. label] = function(self, offset, endian)
local o = self.offset + offset
if _ib(o, self.length, datatype) then
local v,_ = string.unpack(_ef(endian) .. datatype.code, self.blob, o)
return v
end
return nil
end
DataView["Set" .. label] = function(self, offset, value, endian)
local o = self.offset + offset
if _ib(o, self.length, datatype) then
return SetFixed(self, o, value, _ef(endian) .. datatype.code)
end
return self
end
if datatype.size >= 0 and string.packsize(datatype.code) ~= datatype.size then
local msg = "Pack size of %s (%d) does not match cached length: (%d)"
error(msg:format(label, string.packsize(fmt[#fmt]), datatype.size))
return nil
end
end
for label,datatype in pairs(DataView.FixedTypes) do
DataView["GetFixed" .. label] = function(self, offset, typelen, endian)
local o = self.offset + offset
if o + (typelen - 1) <= self.length then
local code = _ef(endian) .. "c" .. tostring(typelen)
local v,_ = string.unpack(code, self.blob, o)
return v
end
return nil
end
DataView["SetFixed" .. label] = function(self, offset, typelen, value, endian)
local o = self.offset + offset
if o + (typelen - 1) <= self.length then
local code = _ef(endian) .. "c" .. tostring(typelen)
return SetFixed(self, o, value, code)
end
return self
end
end
SetFixed = function(self, offset, value, code)
local fmt = { }
local values = { }
if self.offset < offset then
local size = offset - self.offset
fmt[#fmt + 1] = "c" .. tostring(size)
values[#values + 1] = self.blob:sub(self.offset, size)
end
fmt[#fmt + 1] = code
values[#values + 1] = value
local ps = string.packsize(fmt[#fmt])
if (offset + ps) <= self.length then
local newoff = offset + ps
local size = self.length - newoff + 1
fmt[#fmt + 1] = "c" .. tostring(size)
values[#values + 1] = self.blob:sub(newoff, self.length)
end
self.blob = string.pack(table.concat(fmt, ""), table.unpack(values))
self.length = self.blob:len()
return self
end
DataStream = { }
DataStream.__index = DataStream
function DataStream.New(view)
return setmetatable({ view = view, offset = 0, }, DataStream)
end
for label,datatype in pairs(DataView.Types) do
DataStream[label] = function(self, endian, align)
local o = self.offset + self.view.offset
if not _ib(o, self.view.length, datatype) then
return nil
end
local v,no = string.unpack(_ef(endian) .. datatype.code, self.view:Buffer(), o)
if align then
self.offset = self.offset + math.max(no - o, align)
else
self.offset = no - self.view.offset
end
return v
end
end
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
----------------- ------------
----------------- END OF DATAVIEW FUNCTIONS ------------
----------------- ------------
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
MenuData = {}
if Config.framework == "rsg" then
TriggerEvent("rsg-menubase:getData",function(call)
MenuData = call
end)
elseif Config.framework == "redemrp" then
TriggerEvent("redemrp_menu_base:getData",function(call)
MenuData = call
end)
end
Citizen.CreateThread(function() --
while true do
Citizen.Wait(4)
if Citizen.InvokeNative(0x580417101DDB492F, 0, Config.StartKey) then
TriggerEvent("ricx_scenarios:open")
end
end
end)
function TaskStartScenarioInPlaceHash(ped, hash, p1, p2, p3, p4, p5)
return Citizen.InvokeNative(0x524B54361229154F,ped, hash, p1, p2, p3, p4, p5)
end
function GetScenarioPointCoords(id, p1)
return Citizen.InvokeNative(0xA8452DD321607029, id, p1)
end
function GetScenarioPointType(id)
return Citizen.InvokeNative(0xA92450B5AE687AAF, id)
end
RegisterNetEvent("ricx_scenarios:open")
AddEventHandler("ricx_scenarios:open", function()
MenuData.CloseAll()
local elements = {}
local DataStruct = DataView.ArrayBuffer(256 * 4)
local is_data_exists = Citizen.InvokeNative(0x345EC3B7EBDE1CB5, GetEntityCoords(PlayerPedId()), 1.5, DataStruct:Buffer(), 10)
print("Starts", is_data_exists)
if is_data_exists ~= false then
for i = 1, is_data_exists, 1 do
local scenario = DataStruct:GetInt32(8 * i)
print(scenario)
local hash = GetScenarioPointType(scenario)
for c, v in pairs(Config.Scenarios) do
if GetHashKey(v[1]) == hash then
if v[2] == "" then
elements[i] = {label = v[1], value = "scenario"..i, desc = "Play this", hash = scenario}
else
elements[i] = {label = v[2], value = "scenario"..i, desc = "Play this", hash = scenario}
end
end
end
end
elements[#elements+1] = {label = "Finish scenario", value = "finish", desc = "Finish scenario"}
Citizen.Wait(200)
MenuData.Open('default', GetCurrentResourceName(), 'scenariolist',{
title = "Scenarios",
subtext = "",
align = 'top-right',
elements = elements,
},
function(data, menu)
if data.current.value ~= "finish" then
TaskUseScenarioPoint(PlayerPedId(), data.current.hash, "" , -1.0, true, false, 0, false, -1.0, true)
menu.close()
else
ClearPedTasks(PlayerPedId())
end
end,
function(data, menu)
menu.close()
end)
end
end)
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
MenuData.CloseAll()
if IsPedActiveInScenario(PlayerPedId()) then
ClearPedTasksImmediately(PlayerPedId())
end
end)