-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions2.lua
More file actions
451 lines (391 loc) · 11.5 KB
/
Copy pathfunctions2.lua
File metadata and controls
451 lines (391 loc) · 11.5 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
--------------------------
-- Online Functions
--------------------------
--- @return boolean
function IS_IN_SESSION()
return util.is_session_started() and not util.is_session_transition_active()
end
--------------------------
-- Script Functions
--------------------------
--- @param script string
--- @return boolean
function IS_SCRIPT_RUNNING(script)
return SCRIPT.GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(util.joaat(script)) > 0
end
--- @param script string
--- @param stackSize integer
--- @return boolean
function START_SCRIPT(script, arg_count)
if not SCRIPT.DOES_SCRIPT_EXIST(script) then
return false
end
if IS_SCRIPT_RUNNING(script) then
return true
end
SCRIPT.REQUEST_SCRIPT(script)
while not SCRIPT.HAS_SCRIPT_LOADED(script) do
util.yield()
end
SYSTEM.START_NEW_SCRIPT(script, arg_count or 0)
SCRIPT.SET_SCRIPT_AS_NO_LONGER_NEEDED(script)
return true
end
--- @return boolean
function IS_MISSION_CONTROLLER_SCRIPT_RUNNING()
return IS_SCRIPT_RUNNING("fm_mission_controller") or IS_SCRIPT_RUNNING("fm_mission_controller_2020")
end
--- @return string|nil
function GET_RUNNING_MISSION_CONTROLLER_SCRIPT()
local script = "fm_mission_controller"
if IS_SCRIPT_RUNNING(script) then
return script
end
script = "fm_mission_controller_2020"
if IS_SCRIPT_RUNNING(script) then
return script
end
return nil
end
--- @param script string
--- @param func function
function SPOOF_SCRIPT(script, func)
if not IS_SCRIPT_RUNNING(script) then
return
end
if not util.request_script_host(script) then
return
end
util.yield()
util.spoof_script(script, function()
if not NETWORK.NETWORK_IS_HOST_OF_THIS_SCRIPT() then
return
end
func(script)
end)
end
--------------------------
-- Stat Functions
--------------------------
--- @param stat string
--- @return string
function ADD_MP_INDEX(stat)
local Exceptions = {
"MP_CHAR_STAT_RALLY_ANIM",
"MP_CHAR_ARMOUR_1_COUNT",
"MP_CHAR_ARMOUR_2_COUNT",
"MP_CHAR_ARMOUR_3_COUNT",
"MP_CHAR_ARMOUR_4_COUNT",
"MP_CHAR_ARMOUR_5_COUNT",
}
for _, exception in pairs(Exceptions) do
if stat == exception then
return "MP" .. util.get_char_slot() .. "_" .. stat
end
end
if stat:sub(1, 3) == "MP_" or stat:sub(1, 6) == "MPPLY_" then
return stat
end
return "MP" .. util.get_char_slot() .. "_" .. stat
end
--- @param stat string
--- @param value integer
function STAT_SET_INT(stat, value)
STATS.STAT_SET_INT(util.joaat(ADD_MP_INDEX(stat)), value, true)
end
--- @param stat string
--- @param value float
function STAT_SET_FLOAT(stat, value)
STATS.STAT_SET_FLOAT(util.joaat(ADD_MP_INDEX(stat)), value, true)
end
--- @param stat string
--- @param value boolean
function STAT_SET_BOOL(stat, value)
STATS.STAT_SET_BOOL(util.joaat(ADD_MP_INDEX(stat)), value, true)
end
--- @param stat string
--- @param value string
function STAT_SET_STRING(stat, value)
STATS.STAT_SET_STRING(util.joaat(ADD_MP_INDEX(stat)), value, true)
end
function STAT_SET_DATE(stat, year, month, day, hour, min)
local DatePTR = memory.alloc(8 * 7)
memory.write_int(DatePTR, year)
memory.write_int(DatePTR + 8, month)
memory.write_int(DatePTR + 16, day)
memory.write_int(DatePTR + 24, hour)
memory.write_int(DatePTR + 32, min)
memory.write_int(DatePTR + 40, 0) -- Seconds
memory.write_int(DatePTR + 48, 0) -- Milliseconds
STATS.STAT_SET_DATE(util.joaat(ADD_MP_INDEX(stat)), DatePTR, 7, true)
end
function STAT_INCREMENT(stat, value)
STATS.STAT_INCREMENT(util.joaat(ADD_MP_INDEX(stat)), value, true)
end
--- @param stat string
--- @return integer
function STAT_GET_INT(stat)
local IntPTR = memory.alloc_int()
STATS.STAT_GET_INT(util.joaat(ADD_MP_INDEX(stat)), IntPTR, -1)
return memory.read_int(IntPTR)
end
--- @param stat string
--- @return float
function STAT_GET_FLOAT(stat)
local FloatPTR = memory.alloc_int()
STATS.STAT_GET_FLOAT(util.joaat(ADD_MP_INDEX(stat)), FloatPTR, -1)
return tonumber(string.format("%.3f", memory.read_float(FloatPTR)))
end
--- @param stat string
--- @return boolean
function STAT_GET_BOOL(stat)
if STAT_GET_INT(stat) ~= 0 then
return "true"
else
return "false"
end
end
--- @param stat string
--- @return string
function STAT_GET_STRING(stat)
return STATS.STAT_GET_STRING(util.joaat(ADD_MP_INDEX(stat)), -1)
end
function STAT_GET_DATE(stat, type)
local DatePTR = memory.alloc(8 * 7)
STATS.STAT_GET_DATE(util.joaat(ADD_MP_INDEX(stat)), DatePTR, 7, true)
local DateTypes = {
"Years",
"Months",
"Days",
"Hours",
"Mins",
-- Seconds,
-- Milliseconds,
}
for i = 1, #DateTypes do
if type == DateTypes[i] then
return memory.read_int(DatePTR + 8 * (i - 1))
end
end
end
------------------------------
-- Packed Stat Functions
------------------------------
--- @param statIndex integer
--- @return integer
function GET_PACKED_STAT_INT_CODE(statIndex)
return STATS.GET_PACKED_STAT_INT_CODE(statIndex, util.get_char_slot())
end
--- @param statIndex integer
--- @return boolean
function GET_PACKED_STAT_BOOL_CODE(statIndex)
return STATS.GET_PACKED_STAT_BOOL_CODE(statIndex, util.get_char_slot())
end
--- @param statIndex integer
--- @param value integer
function SET_PACKED_STAT_INT_CODE(statIndex, value)
STATS.SET_PACKED_STAT_INT_CODE(statIndex, value, util.get_char_slot())
end
--- @param statIndex integer
--- @param value boolean
function SET_PACKED_STAT_BOOL_CODE(statIndex, value)
STATS.SET_PACKED_STAT_BOOL_CODE(statIndex, value, util.get_char_slot())
end
----------------------------
-- Global Functions
----------------------------
--- @param global integer
--- @param value integer
function GLOBAL_SET_INT(global, value)
memory.write_int(memory.script_global(global), value)
end
--- @param global integer
--- @param value float
function GLOBAL_SET_FLOAT(global, value)
memory.write_float(memory.script_global(global), value)
end
--- @param global integer
--- @param value string
function GLOBAL_SET_STRING(global, value)
memory.write_string(memory.script_global(global), value)
end
--- @param global integer
--- @param value boolean
function GLOBAL_SET_BOOL(global, value)
memory.write_int(memory.script_global(global), value and 1 or 0)
end
--- @param global integer
--- @return integer
function GLOBAL_GET_INT(global)
return memory.read_int(memory.script_global(global))
end
--- @param global integer
--- @return float
function GLOBAL_GET_FLOAT(global)
return memory.read_float(memory.script_global(global))
end
--- @param global integer
---@return string
function GLOBAL_GET_STRING(global)
return memory.read_string(memory.script_global(global))
end
--- @param global integer
--- @return boolean
function GLOBAL_GET_BOOL(global)
return memory.read_int(memory.script_global(global)) == 1
end
--- @param global integer
--- @param bit integer
function GLOBAL_SET_BIT(global, bit)
local addr = memory.script_global(global)
memory.write_int(addr, SET_BIT(memory.read_int(addr), bit))
end
--- @param global integer
--- @param bit integer
function GLOBAL_CLEAR_BIT(global, bit)
local addr = memory.script_global(global)
memory.write_int(addr, CLEAR_BIT(memory.read_int(addr), bit))
end
--- @param global integer
--- @param bit integer
--- @return boolean
function GLOBAL_BIT_TEST(global, bit)
local addr = memory.script_global(global)
return BIT_TEST(memory.read_int(addr), bit)
end
--- @param global integer
--- @param ... bits
function GLOBAL_SET_BITS(global, ...)
local addr = memory.script_global(global)
memory.write_int(addr, SET_BITS(memory.read_int(addr), ...))
end
---------------------------
-- Local Functions
---------------------------
--- @param script string
--- @param script_local integer
--- @param value integer
function LOCAL_SET_INT(script, script_local, value)
if memory.script_local(script, script_local) ~= 0 then
memory.write_int(memory.script_local(script, script_local), value)
end
end
--- @param script string
--- @param script_local integer
--- @param value float
function LOCAL_SET_FLOAT(script, script_local, value)
if memory.script_local(script, script_local) ~= 0 then
memory.write_float(memory.script_local(script, script_local), value)
end
end
--- @param script string
--- @param script_local integer
---@return integer
function LOCAL_GET_INT(script, script_local)
if memory.script_local(script, script_local) ~= 0 then
return memory.read_int(memory.script_local(script, script_local))
end
end
--- @param script string
--- @param script_local integer
---@return float
function LOCAL_GET_FLOAT(script, script_local)
if memory.script_local(script, script_local) ~= 0 then
return memory.read_float(memory.script_local(script, script_local))
end
end
--- @param script string
--- @param script_local integer
--- @param bit integer
function LOCAL_SET_BIT(script, script_local, bit)
local addr = memory.script_local(script, script_local)
if addr ~= 0 then
memory.write_int(addr, SET_BIT(memory.read_int(addr), bit))
end
end
--- @param script string
--- @param script_local integer
--- @param bit integer
function LOCAL_CLEAR_BIT(script, script_local, bit)
local addr = memory.script_local(script, script_local)
if addr ~= 0 then
memory.write_int(addr, CLEAR_BIT(memory.read_int(addr), bit))
end
end
--- @param script string
--- @param script_local integer
--- @param bit integer
--- @return boolean
function LOCAL_BIT_TEST(script, script_local, bit)
local addr = memory.script_local(script, script_local)
if addr ~= 0 then
return BIT_TEST(memory.read_int(addr), bit)
end
end
---------------------------
-- Bit Functions
---------------------------
--- @param value integer
--- @param position integer
--- @return integer
function SET_BIT(value, position)
return (value | (1 << position))
end
--- @param value integer
--- @param position integer
--- @return integer
function CLEAR_BIT(value, position)
return (value & ~(1 << position))
end
--- @param value integer
--- @param position integer
--- @return boolean
function BIT_TEST(value, position)
return (value & (1 << position)) ~= 0
end
--- @param value integer
--- @param ... positions
--- @return integer
function SET_BITS(value, ...)
local positions = { ... }
for _, position in ipairs(positions) do
value = value | (1 << position)
end
return value
end
--- @param value integer
--- @param ... positions
--- @return integer
function CLEAR_BITS(value, ...)
local positions = { ... }
for _, position in ipairs(positions) do
value = value & ~(1 << position)
end
return value
end
--- Checks if **all** specified bit positions are set to 1 in the given value.
--- @param value integer
--- @param ... positions
--- @return boolean
function BITS_TEST(value, ...)
local positions = { ... }
for _, position in ipairs(positions) do
if (value & (1 << position)) == 0 then
return false
end
end
return true
end
--- Checks if **any** of the specified bit positions are set to 1 in the given value.
--- @param value integer
--- @param ... positions
--- @return boolean
function IS_ANY_BIT_SET(value, ...)
local positions = { ... }
for _, position in ipairs(positions) do
if (value & (1 << position)) ~= 0 then
return true
end
end
return false
end