NMizu commited on
Commit
57a3a9f
·
verified ·
1 Parent(s): b22af1b

Upload 21 files

Browse files
Files changed (21) hide show
  1. basic.lua +38 -0
  2. bitstream.lua +453 -0
  3. chat.lua +57 -0
  4. color.lua +41 -0
  5. deathwindow.lua +23 -0
  6. dialog.lua +101 -0
  7. dxut.lua +39 -0
  8. game.lua +39 -0
  9. gangzone.lua +21 -0
  10. init.lua +43 -0
  11. input.lua +105 -0
  12. label.lua +77 -0
  13. netgame.lua +104 -0
  14. object.lua +38 -0
  15. pickup.lua +35 -0
  16. player.lua +439 -0
  17. raknet.lua +700 -0
  18. scoreboard.lua +25 -0
  19. stringcompressor.lua +44 -0
  20. textdraw.lua +229 -0
  21. vehicle.lua +45 -0
basic.lua ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local ffi = require 'ffi'
8
+ local sampapi = require 'sampapi'
9
+ local netgame = sampapi.require('CNetGame', true)
10
+
11
+ require 'sampfuncs'
12
+
13
+ function sampGetBase()
14
+ return sampapi.GetBase()
15
+ end
16
+
17
+ function sampGetVersion()
18
+ return sampapi.GetSAMPVersion()
19
+ end
20
+
21
+ function isSampLoaded()
22
+ return sampapi.GetBase() ~= 0
23
+ end
24
+
25
+ function isSampfuncsLuaLoaded()
26
+ return sampapi.GetSAMPVersion() ~= ffi.C.SAMP_VERSION_UNKNOWN
27
+ end
28
+
29
+ function isSampAvailable()
30
+ return isSampLoaded() and netgame.RefNetGame() ~= nil
31
+ end
32
+ jit.off(isSampAvailable, true)
33
+
34
+ isSampfuncsLoaded = isSampfuncsLuaLoaded
35
+
36
+ if not isSampfuncsConsoleActive then
37
+ function isSampfuncsConsoleActive() return false end
38
+ end
bitstream.lua ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+
6
+ lite version of RakNet BitStream Copyright 2003 Kevin Jenkins.
7
+ ]]
8
+
9
+ local ffi = require 'ffi'
10
+ local bit = require 'bit'
11
+
12
+ ffi.cdef[[
13
+ void *malloc(size_t size);
14
+ void free(void * ptrmem);
15
+ void *realloc(void *ptr, size_t newsize);
16
+ void *memset(void *memptr, int val, size_t num);
17
+
18
+ typedef unsigned char BYTE;
19
+ typedef struct SBitStream SBitStream;
20
+
21
+ #pragma pack(push, 1)
22
+ struct SBitStream {
23
+ int numberOfBitsUsed;
24
+ int numberOfBitsAllocated;
25
+ int readOffset;
26
+ BYTE *data;
27
+ bool copyData;
28
+ BYTE stackData[256];
29
+ };
30
+ #pragma pack(pop)
31
+ ]]
32
+
33
+ local lshift, band, rshift, bor = bit.lshift, bit.band, bit.rshift, bit.bor
34
+ local cast, sizeof, gc, typeof, istype, new = ffi.cast, ffi.sizeof, ffi.gc, ffi.typeof, ffi.istype, ffi.new
35
+ local malloc, free, memcpy, memset, realloc = ffi.C.malloc, ffi.C.free, ffi.copy, ffi.C.memset, ffi.C.realloc
36
+
37
+ local BITSTREAM_STACK_ALLOCATION_SIZE = 256
38
+
39
+ local function BYTES_TO_BITS(x) return lshift(x, 3) end
40
+ local function BITS_TO_BYTES(x) return rshift(x + 7, 3) end
41
+
42
+ local BitStream = {}
43
+ BitStream.__index = BitStream
44
+ local BitStream_type = ffi.typeof('SBitStream')
45
+
46
+ local bs_initialize = {
47
+ function(self)
48
+ self.numberOfBitsUsed = 0
49
+ -- self.numberOfBitsAllocated = 32 * 8,
50
+ self.numberOfBitsAllocated = BITSTREAM_STACK_ALLOCATION_SIZE * 8
51
+ self.readOffset = 0
52
+ -- self.data = cast('BYTE*', malloc(32)),
53
+ self.data = cast('BYTE*', self.stackData)
54
+ self.copyData = true
55
+ end,
56
+
57
+ function(self, initialBytesToAllocate)
58
+ self.numberOfBitsUsed = 0
59
+ self.readOffset = 0
60
+ if initialBytesToAllocate <= BITSTREAM_STACK_ALLOCATION_SIZE then
61
+ self.data = cast('BYTE*', self.stackData)
62
+ self.numberOfBitsAllocated = BITSTREAM_STACK_ALLOCATION_SIZE * 8
63
+ else
64
+ self.data = cast('BYTE*', malloc(initialBytesToAllocate))
65
+ self.numberOfBitsAllocated = BYTES_TO_BITS(initialBytesToAllocate)
66
+ end
67
+ self.copyData = true
68
+ end,
69
+
70
+ function(self, _data, lengthInBytes, _copyData)
71
+ _data = cast('BYTE*', _data)
72
+
73
+ self.numberOfBitsUsed = BYTES_TO_BITS(lengthInBytes)
74
+ self.readOffset = 0
75
+ self.copyData = _copyData
76
+ self.numberOfBitsAllocated = BYTES_TO_BITS(lengthInBytes)
77
+ if self.copyData then
78
+ if lengthInBytes > 0 then
79
+ if lengthInBytes < BITSTREAM_STACK_ALLOCATION_SIZE then
80
+ self.data = cast('BYTE*', self.stackData)
81
+ self.numberOfBitsAllocated = BYTES_TO_BITS(BITSTREAM_STACK_ALLOCATION_SIZE)
82
+ else self.data = cast('BYTE*', malloc(lengthInBytes)) end
83
+ memcpy(self.data, _data, lengthInBytes)
84
+ else self.data = nil end
85
+ else self.data = _data end
86
+ end
87
+ }
88
+
89
+ local bs_write = {
90
+ function(self, bitStream)
91
+ bitStream = cast('SBitStream*', bitStream)
92
+ self:Write(bitStream, bitStream:GetNumberOfBitsUsed())
93
+ end,
94
+
95
+ function(self, input, numberOfBytes)
96
+ input = cast('const char*', input)
97
+ if not numberOfBytes or numberOfBytes == 0 then return end
98
+ if band(self.numberOfBitsUsed, 7) == 0 then
99
+ self:AddBitsAndReallocate(BYTES_TO_BITS(numberOfBytes))
100
+ memcpy(self.data + BITS_TO_BYTES(self.numberOfBitsUsed), input, numberOfBytes)
101
+ self.numberOfBitsUsed = self.numberOfBitsUsed + BYTES_TO_BITS(numberOfBytes)
102
+ else self:WriteBits(input, numberOfBytes * 8, true) end
103
+ end,
104
+
105
+ function(self, bitStream, numberOfBits)
106
+ self:AddBitsAndReallocate(numberOfBits)
107
+ local numberOfBitsMod8 = 0
108
+ while self.numberOfBits > 0 and bitStream.readOffset + 1 <= bitStream.numberOfBitsUsed do
109
+ self.numberOfBits = self.numberOfBits - 1
110
+ numberOfBitsMod8 = band(self.numberOfBitsUsed, 7)
111
+ if numberOfBitsMod8 == 0 then
112
+ local ro = bitStream.readOffset
113
+ bitStream.readOffset = bitStream.readOffset + 1
114
+ if band(bitStream.data[rshift(ro, 3)], rshift(0x80, ro % 8)) > 0 then
115
+ self.data[rshift(bitStream.numberOfBitsUsed, 3)] = 0x80
116
+ else
117
+ self.data[rshift(bitStream.numberOfBitsUsed, 3)] = 0
118
+ end
119
+ else
120
+ local ro = bitStream.readOffset
121
+ bitStream.readOffset = bitStream.readOffset + 1
122
+ if band(bitStream.data[rshift(ro, 3)], rshift(0x80, ro % 8)) > 0 then
123
+ self.data[rshift(self.numberOfBitsUsed, 3)] = bor(self.data[rshift(self.numberOfBitsUsed, 3)], rshift(0x80, numberOfBitsMod8))
124
+ end
125
+ end
126
+ self.numberOfBitsUsed = self.numberOfBitsUsed + 1
127
+ end
128
+ end
129
+ }
130
+
131
+ local bs_read = {
132
+ function(self, cdata)
133
+ return self:ReadBits(cdata, ffi.sizeof(cdata) * 8, true)
134
+ end,
135
+
136
+ function(self, output, numberOfBytes)
137
+ output = cast('char*', output)
138
+ if band(self.readOffset, 7) == 0 then
139
+ if self.readOffset + BYTES_TO_BITS(numberOfBytes) > self.numberOfBitsUsed then return false end
140
+ memcpy(output, self.data + rshift(self.readOffset, 3), numberOfBytes)
141
+ self.readOffset = self.readOffset + BYTES_TO_BITS(numberOfBytes)
142
+ return true
143
+ else
144
+ return self:ReadBits(output, numberOfBytes * 8)
145
+ end
146
+ end
147
+ }
148
+
149
+ function BitStream.__new(ctype, ...)
150
+ local v, func = select('#', ...)
151
+ if v == 0 then func = bs_initialize[1]
152
+ elseif v < 3 then func = bs_initialize[2]
153
+ else func = bs_initialize[3] end
154
+
155
+ local bs_data = gc(malloc(sizeof('SBitStream')), BitStream.__gc)
156
+ bs_data = cast('SBitStream*', bs_data)
157
+ func(bs_data, ...)
158
+ return bs_data
159
+ end
160
+
161
+ function BitStream:__gc()
162
+ if self.copyData and self.numberOfBitsAllocated > BYTES_TO_BITS(BITSTREAM_STACK_ALLOCATION_SIZE) then free(self) end
163
+ end
164
+
165
+ function BitStream:SetNumberOfBitsAllocated(lengthInBits)
166
+ self.numberOfBitsAllocated = lengthInBits
167
+ end
168
+
169
+ function BitStream:Reset()
170
+ if self.numberOfBitsUsed > 0 then
171
+ -- memset(data, BITS_TO_BYTES(numberOfBitsUsed), 0)
172
+ end
173
+ self.numberOfBitsUsed = 0
174
+ self.readOffset = 0
175
+ end
176
+
177
+ function BitStream:Write(...)
178
+ local v, func = select('#', ...)
179
+ local first = select(1, ...)
180
+ if v == 1 then func = bs_write[1]
181
+ elseif v > 1 and type(first) == 'cdata' and istype(typeof(first), BitStream_type) then func = bs_write[3]
182
+ elseif v > 1 then func = bs_write[2] end
183
+ func(self, ...)
184
+ end
185
+
186
+ function BitStream:Read(...)
187
+ local v, func = select('#', ...)
188
+ if v >= 2 then func = bs_read[2]
189
+ else func = bs_read[1] end
190
+ func(self, ...)
191
+ end
192
+
193
+ function BitStream:ResetReadPointer()
194
+ self.readOffset = 0
195
+ end
196
+
197
+ function BitStream:ResetWritePointer()
198
+ self.numberOfBitsUsed = 0
199
+ end
200
+
201
+ function BitStream:Write0()
202
+ self:AddBitsAndReallocate(1)
203
+ if band(self.numberOfBitsUsed, 7) == 0 then
204
+ self.data[rshift(numberOfBitsUsed, 3)] = 0
205
+ end
206
+ self.numberOfBitsUsed = self.numberOfBitsUsed + 1
207
+ end
208
+
209
+ function BitStream:Write1()
210
+ self:AddBitsAndReallocate(1)
211
+ local numberOfBitsMod8 = band(self.numberOfBitsUsed, 7)
212
+ if numberOfBitsMod8 == 0 then
213
+ self.data[rshift(self.numberOfBitsUsed, 3)] = 0x80
214
+ else
215
+ self.data[rshift(self.numberOfBitsUsed, 3)] = bor(self.data[rshift(self.numberOfBitsUsed, 3)], rshift(0x80, numberOfBitsMod8))
216
+ end
217
+ self.numberOfBitsUsed = self.numberOfBitsUsed + 1
218
+ end
219
+
220
+ function BitStream:ReadBit()
221
+ local res = band(self.data[rshift(self.readOffset, 3)], rshift(0x80, band(self.readOffset, 7)))
222
+ self.readOffset = self.readOffset + 1
223
+ return res > 0
224
+ end
225
+
226
+ function BitStream:WriteAlignedBytes(input, numberOfBytesToWrite)
227
+ self:AlignWriteToByteBoundary()
228
+ self:Write(input, numberOfBytesToWrite)
229
+ end
230
+
231
+ function BitStream:ReadAlignedBytes(output, numberOfBytesToRead)
232
+ if numberOfBytesToRead <= 0 then return false end
233
+ output = cast('BYTE*', output)
234
+ self:AlignReadToByteBoundary()
235
+ if self.readOffset + BYTES_TO_BITS(numberOfBytesToRead) > self.numberOfBitsUsed then return false end
236
+ memcpy(output, self.data + rshift(self.readOffset, 3), numberOfBytesToRead)
237
+ self.readOffset = self.readOffset + BYTES_TO_BITS(numberOfBytesToRead)
238
+ return true
239
+ end
240
+
241
+ function BitStream:AlignWriteToByteBoundary()
242
+ if self.numberOfBitsUsed > 0 then
243
+ self.numberOfBitsUsed = self.numberOfBitsUsed + ( 8 - band(self.numberOfBitsUsed - 1, 7) + 1 )
244
+ end
245
+ end
246
+
247
+ function BitStream:AlignReadToByteBoundary()
248
+ if self.readOffset > 0 then
249
+ self.readOffset = self.readOffset + ( 8 - band(self.readOffset - 1, 7) + 1 )
250
+ end
251
+ end
252
+
253
+ function BitStream:WriteBits(input, numberOfBitsToWrite, rightAlignedBits)
254
+ if numberOfBitsToWrite <= 0 then return end
255
+ input = cast('BYTE*', input)
256
+
257
+ self:AddBitsAndReallocate(numberOfBitsToWrite)
258
+ local offset = 0
259
+ local dataByte = 0
260
+ local numberOfBitsUsedMod8 = 0
261
+
262
+ numberOfBitsUsedMod8 = band(self.numberOfBitsUsed, 7)
263
+
264
+ while numberOfBitsToWrite > 0 do
265
+ dataByte = (input + offset)[0]
266
+
267
+ if numberOfBitsToWrite < 8 and rightAlignedBits then
268
+ dataByte = lshift(dataByte, 8 - numberOfBitsToWrite)
269
+ end
270
+
271
+ if numberOfBitsUsedMod8 == 0 then
272
+ (self.data + rshift(self.numberOfBitsUsed, 3))[0] = dataByte
273
+ else
274
+ (self.data + rshift(self.numberOfBitsUsed, 3))[0] = bor((self.data + rshift(self.numberOfBitsUsed, 3))[0], rshift(dataByte, numberOfBitsUsedMod8))
275
+
276
+ if 8 - numberOfBitsUsedMod8 < 8 and 8 - numberOfBitsUsedMod8 < numberOfBitsToWrite then
277
+ (self.data + rshift(self.numberOfBitsUsed, 3) + 1)[0] = lshift(dataByte, 8 - numberOfBitsUsedMod8)
278
+ end
279
+ end
280
+
281
+ if numberOfBitsToWrite >= 8 then self.numberOfBitsUsed = self.numberOfBitsUsed + 8
282
+ else self.numberOfBitsUsed = self.numberOfBitsUsed + numberOfBitsToWrite end
283
+
284
+ numberOfBitsToWrite = numberOfBitsToWrite - 8
285
+
286
+ offset = offset + 1
287
+ end
288
+ end
289
+
290
+ function BitStream:SetData(input)
291
+ self.data = cast('BYTE*', input)
292
+ self.copyData = false
293
+ end
294
+
295
+ function BitStream:WriteCompressed(input, size, unsignedData)
296
+ input = cast('BYTE*', input)
297
+ local currentByte = rshift(size, 3) - 1
298
+ local byteMatch = 0
299
+ if not unsignedData then byteMatch = 0xFF end
300
+ while currentByte > 0 do
301
+ if input[currentByte] == byteMatch then
302
+ -- self:Write(true)
303
+ else
304
+ -- self:Write(false)
305
+ self:WriteBits(input, BYTES_TO_BITS(currentByte + 1), true)
306
+ return
307
+ end
308
+ currentByte = currentByte - 1
309
+ end
310
+ if ( unsignedData and band((input + currentByte)[0], 0xF0) == 0x00 ) or
311
+ ( unsignedData == false and band((input + currentByte)[0], 0xF0) == 0xF0 ) then
312
+ -- self:Write(true)
313
+ self:WriteBits(input + currentByte, 4, true)
314
+ else
315
+ -- self:Write(false)
316
+ self:WriteBits(input + currentByte, 8, true)
317
+ end
318
+ end
319
+
320
+ function BitStream:ReadBits(output, numberOfBitsToRead, alignBitsToRight)
321
+ output = cast('BYTE*', output)
322
+ if numberOfBitsToRead <= 0 then return false end
323
+
324
+ if self.readOffset + numberOfBitsToRead > self.numberOfBitsUsed then return false end
325
+
326
+ local readOffsetMod8, offset = 0, 0
327
+ memset(output, 0, BITS_TO_BYTES(numberOfBitsToRead))
328
+
329
+ readOffsetMod8 = band(self.readOffset, 7)
330
+ while numberOfBitsToRead > 0 do
331
+ local this = output + offset
332
+ this[0] = bor(this[0], lshift((self.data + rshift(self.readOffset, 3))[0], readOffsetMod8))
333
+ if readOffsetMod8 > 0 and numberOfBitsToRead > 8 - readOffsetMod8 then
334
+ this[0] = bor(this[0], rshift((self.data + rshift(self.readOffset, 3) + 1)[0], 8 - readOffsetMod8))
335
+ end
336
+ numberOfBitsToRead = numberOfBitsToRead - 8
337
+ if numberOfBitsToRead < 0 then
338
+ if alignBitsToRight then this[0] = rshift(this[0], -numberOfBitsToRead) end
339
+ self.readOffset = self.readOffset + 8 + numberOfBitsToRead
340
+ else self.readOffset = self.readOffset + 8 end
341
+ offset = offset + 1
342
+ end
343
+ return true
344
+ end
345
+
346
+ function BitStream:ReadCompressed(output, size, unsignedData)
347
+ output = cast('BYTE*', output)
348
+ local currentByte = rhsift(size, 3) - 1
349
+
350
+ local byteMatch, halfByteMatch = 0, 0
351
+
352
+ if not unsignedData then byteMatch, halfByteMatch = 0xFF, 0xF0 end
353
+
354
+ while currentByte > 0 do
355
+ local b = ffi.new('bool[1]')
356
+
357
+ if self:Read(b) == false then return false end
358
+
359
+ if b[0] then
360
+ output[currentByte] = byteMatch
361
+ currentByte = currentByte - 1
362
+ else
363
+ if self:ReadBits(output, BYTES_TO_BITS(currentByte + 1)) == false then return false end
364
+
365
+ return true
366
+ end
367
+ end
368
+
369
+ if readOffset + 1 > self.numberOfBitsUsed then
370
+ return false
371
+ end
372
+
373
+ local b = ffi.new('bool[1]')
374
+ if self:Read(b) == false then return false end
375
+ if b[0] then
376
+ if self:ReadBits(output + currentByte, 4) == false then
377
+ return false
378
+ end
379
+ output[currentByte] = bor(output[currentByte], halfByteMatch)
380
+ else
381
+ if self:ReadBits(output + currentByte, 8) == false then return false end
382
+ end
383
+
384
+ return true
385
+ end
386
+
387
+ function BitStream:AddBitsAndReallocate(numberOfBitsToWrite)
388
+ if numberOfBitsToWrite <= 0 then return end
389
+
390
+ local newNumberOfBitsAllocated = numberOfBitsToWrite + self.numberOfBitsUsed
391
+
392
+ if numberOfBitsToWrite + self.numberOfBitsUsed > 0 and rshift(self.numberOfBitsAllocated - 1, 3) < rshift(newNumberOfBitsAllocated - 1, 3) then
393
+ newNumberOfBitsAllocated = ( numberOfBitsToWrite + self.numberOfBitsUsed ) * 2
394
+ local amountToAllocate = BITS_TO_BYTES(newNumberOfBitsAllocated)
395
+ if self.data == cast('BYTE*', self.stackData) then
396
+ if amountToAllocate > BITSTREAM_STACK_ALLOCATION_SIZE then
397
+ data = cast('BYTE*', malloc(amountToAllocate))
398
+
399
+ memcpy(cast('void*', data), cast('void*', stackData), BITS_TO_BYTES(self.numberOfBitsAllocated))
400
+ end
401
+ else
402
+ data = cast('BYTE*', realloc(self.data, amountToAllocate))
403
+ end
404
+ end
405
+
406
+ if newNumberOfBitsAllocated > self.numberOfBitsAllocated then
407
+ self.numberOfBitsAllocated = newNumberOfBitsAllocated
408
+ end
409
+ end
410
+
411
+ function BitStream:AssertStreamEmpty()
412
+ assert(self.readOffset == self.numberOfBitsUsed)
413
+ end
414
+
415
+ function BitStream:CopyData(_data)
416
+ _data = cast('BYTE**', _data)
417
+ _data[0] = ffi.new('BYTE[?]', BITS_TO_BYTES( self.numberOfBitsUsed ))
418
+ memcpy(_data[0], self.data, ffi.sizeof('BYTE') * BITS_TO_BYTES( self.numberOfBitsUsed ))
419
+ return self.numberOfBitsUsed
420
+ end
421
+
422
+ function BitStream:IgnoreBits(numberOfBits)
423
+ self.readOffset = self.readOffset + numberOfBits
424
+ end
425
+
426
+ function BitStream:SetWriteOffset(offset)
427
+ self.numberOfBitsUsed = offset
428
+ end
429
+
430
+ function BitStream:AssertCopyData()
431
+ if self.copyData == false then
432
+ self.copyData = true
433
+
434
+ if self.numberOfBitsAllocated > 0 then
435
+ local newdata = malloc(BITS_TO_BYTES( self.numberOfBitsAllocated ) )
436
+
437
+ memcpy(newdata, data, BITS_TO_BYTES( self.numberOfBitsAllocated ))
438
+ self.data = newdata
439
+ else self.data = nil end
440
+ end
441
+ end
442
+
443
+ function BitStream:ReverseBytes(input, output, length)
444
+ input = cast('BYTE*', input)
445
+ output = cast('BYTE*', output)
446
+ for i = 0, length - 1 do
447
+ output[i] = input[length-i-1]
448
+ end
449
+ end
450
+
451
+ ffi.metatype(BitStream_type, BitStream)
452
+
453
+ return BitStream_type
chat.lua ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local chat = sampapi.require('CChat', true)
12
+
13
+ function sampGetChatInfoPtr()
14
+ return shared.get_pointer(dialog.RefChat())
15
+ end
16
+ jit.off(sampGetChatInfoPtr, true)
17
+
18
+ function sampAddChatMessage(text, color)
19
+ sampAddChatMessageEx(ffi.C.ENTRY_TYPE_DEBUG, text, '', color, -1)
20
+ end
21
+
22
+ function sampGetChatDisplayMode()
23
+ return chat.RefChat():GetMode()
24
+ end
25
+ jit.off(sampGetChatDisplayMode, true)
26
+
27
+ function sampSetChatDisplayMode(mode)
28
+ chat.RefChat().m_nMode = id
29
+ end
30
+ jit.off(sampSetChatDisplayMode, true)
31
+
32
+ function sampGetChatString(id)
33
+ local entry = chat.RefChat().m_entry[id]
34
+ return ffi.string(entry.m_szText), ffi.string(entry.m_szPrefix), entry.m_textColor, entry.m_prefixColor
35
+ end
36
+ jit.off(sampGetChatString, true)
37
+
38
+ function sampSetChatString(id, text, prefix, color, pcolor)
39
+ chat.RefChat().m_entry[id] = {
40
+ m_szText = text,
41
+ m_szPrefix = prefix,
42
+ m_textColor = color,
43
+ m_prefixColor = pcolor
44
+ }
45
+ end
46
+ jit.off(sampSetChatString, true)
47
+
48
+ function sampIsChatVisible()
49
+ return sampGetChatDisplayMode() ~= ffi.C.DISPLAY_MODE_OFF
50
+ end
51
+
52
+ -- New functions
53
+
54
+ function sampAddChatMessageEx(type_msg, text, prefix, color, pcolor)
55
+ chat.RefChat():AddEntry(type_msg, text, prefix, color, pcolor)
56
+ end
57
+ jit.off(sampAddChatMessageEx, true)
color.lua ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local module = {}
8
+
9
+ -- from https://www.blast.hk/threads/13380/post-124527
10
+ function module.explode_color(color)
11
+ local a = bit.band(bit.rshift(color, 24), 0xFF)
12
+ local r = bit.band(bit.rshift(color, 16), 0xFF)
13
+ local g = bit.band(bit.rshift(color, 8), 0xFF)
14
+ local b = bit.band(color, 0xFF)
15
+ return a, r, g, b
16
+ end
17
+
18
+ function module.join_color(a, r, g, b)
19
+ local color = b -- b
20
+ color = bit.bor(color, bit.lshift(g, 8)) -- g
21
+ color = bit.bor(color, bit.lshift(r, 16)) -- r
22
+ color = bit.bor(color, bit.lshift(a, 24)) -- a
23
+ return color % 0x100000000
24
+ end
25
+
26
+ function module.argb_to_rgba(color)
27
+ local a, r, g, b = module.explode_color(color)
28
+ return module.join_color(r, g, b, a)
29
+ end
30
+
31
+ function module.rgba_to_argb(color)
32
+ local r, g, b, a = module.explode_color(color)
33
+ return module.join_color(a, r, g, b)
34
+ end
35
+
36
+ function module.abgr_to_argb(color)
37
+ local a, r, g, b = module.explode_color(color)
38
+ return module.join_color(a, b, g, r)
39
+ end
40
+
41
+ return module
deathwindow.lua ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local deathwindow = sampapi.require('CDeathWindow', true)
12
+
13
+ function sampGetKillInfoPtr()
14
+ return shared.get_pointer(deathwindow.RefDeathWindow())
15
+ end
16
+ jit.off(sampGetKillInfoPtr, true)
17
+
18
+ -- New functions
19
+
20
+ function sampAddDeathMessage(killer, killed, clkiller, clkilled, reason)
21
+ deathwindow.RefDeathWindow():AddMessage(killer, killed, clkiller, clkilled, reason)
22
+ end
23
+ jit.off(sampAddDeathMessage, true)
dialog.lua ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ require 'sflua.cdef.dxut'
12
+ local dialog = sampapi.require('CDialog', true)
13
+
14
+ function sampGetDialogInfoPtr()
15
+ return shared.get_pointer(dialog.RefDialog())
16
+ end
17
+ jit.off(sampGetDialogInfoPtr, true)
18
+
19
+ function sampShowDialog(id, caption, text, button1, button2, style)
20
+ dialog.RefDialog():Show(id, style, caption, text, button1, button2, false)
21
+ end
22
+ jit.off(sampShowDialog, true)
23
+
24
+ function sampCloseCurrentDialogWithButton(button)
25
+ dialog.RefDialog():Close(button)
26
+ end
27
+ jit.off(sampCloseCurrentDialogWithButton, true)
28
+
29
+ function sampGetCurrentDialogListItem()
30
+ local listbox = ffi.cast('char*', dialog.RefDialog().m_pListbox)
31
+ return ffi.cast('int*', listbox + 0x143)[0] -- CDXUTListBox::m_nSelected
32
+ end
33
+ jit.off(sampGetCurrentDialogListItem, true)
34
+
35
+ function sampSetCurrentDialogListItem(list)
36
+ local listbox = ffi.cast('char*', dialog.RefDialog().m_pListbox)
37
+ ffi.cast('int*', listbox + 0x143)[0] = list -- CDXUTListBox::m_nSelected
38
+ end
39
+ jit.off(sampSetCurrentDialogListItem, true)
40
+
41
+ function sampGetCurrentDialogEditboxText()
42
+ return ffi.string(dialog.RefDialog().m_pEditbox:GetText())
43
+ end
44
+ jit.off(sampGetCurrentDialogEditboxText, true)
45
+
46
+ function sampSetCurrentDialogEditboxText(text)
47
+ dialog.RefDialog().m_pEditbox:SetText(text, false)
48
+ end
49
+ jit.off(sampSetCurrentDialogEditboxText, true)
50
+
51
+ function sampIsDialogActive()
52
+ return dialog.RefDialog().m_bIsActive ~= 0
53
+ end
54
+ jit.off(sampIsDialogActive, true)
55
+
56
+ function sampGetCurrentDialogType()
57
+ return dialog.RefDialog().m_nType
58
+ end
59
+ jit.off(sampGetCurrentDialogType, true)
60
+
61
+ function sampGetCurrentDialogId()
62
+ return dialog.RefDialog().m_nId
63
+ end
64
+ jit.off(sampGetCurrentDialogId, true)
65
+
66
+ function sampGetDialogCaption()
67
+ return ffi.string(dialog.RefDialog().m_szCaption)
68
+ end
69
+ jit.off(sampGetDialogCaption, true)
70
+
71
+ function sampGetDialogText()
72
+ return ffi.string(dialog.RefDialog().m_szText)
73
+ end
74
+ jit.off(sampGetDialogText, true)
75
+
76
+ function sampIsDialogClientside()
77
+ return dialog.RefDialog().m_bServerside == 0
78
+ end
79
+ jit.off(sampIsDialogClientside, true)
80
+
81
+ function sampSetDialogClientside(client)
82
+ dialog.RefDialog().m_bServerside = client and 0 or 1
83
+ end
84
+ jit.off(sampSetDialogClientside, true)
85
+
86
+ function sampGetListboxItemsCount()
87
+ local listbox = ffi.cast('char*', dialog.RefDialog().m_pListbox)
88
+ return ffi.cast('int*', listbox + 0x150)[0] -- CDXUTListBox::m_Items::m_nSize
89
+ end
90
+ jit.off(sampGetListboxItemsCount, true)
91
+
92
+ function sampGetListboxItemText(list)
93
+ list = tonumber(list) or 0
94
+ local listbox = ffi.cast('char*', dialog.RefDialog().m_pListbox)
95
+ if list >= 0 and sampGetListboxItemsCount() - 1 >= list then
96
+ local data = ffi.cast('struct DXUTComboBoxItem***', listbox + 0x14C)[0] -- CDXUTListBox::m_Items::m_pData
97
+ return ffi.string(data[list].strText)
98
+ end
99
+ return ''
100
+ end
101
+ jit.off(sampGetListboxItemText, true)
dxut.lua ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local mt = require 'sampapi.metatype'
10
+ local ffi = shared.ffi
11
+
12
+ sampapi.require 'CRect'
13
+
14
+ ffi.cdef[[
15
+ struct DXUTComboBoxItem {
16
+ char strText[256];
17
+ void* pData;
18
+ SCRect rcActive;
19
+ bool bVisible;
20
+ };
21
+ ]]
22
+
23
+ local CDXUTEditBox_GetText_addr = {
24
+ [ffi.C.SAMP_VERSION_037R1] = 0x81030,
25
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x84F40,
26
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x85650
27
+ }
28
+
29
+ local CDXUTEditBox_SetText_addr = {
30
+ [ffi.C.SAMP_VERSION_037R1] = 0x80F60,
31
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x84E70,
32
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x85580
33
+ }
34
+
35
+ local CDXUTEditBox_mt = {
36
+ GetText = ffi.cast('const char*(__thiscall*)(struct CDXUTEditBox*)', sampapi.GetAddress(CDXUTEditBox_GetText_addr[sampapi.GetSAMPVersion()])),
37
+ SetText = ffi.cast('void(__thiscall*)(struct CDXUTEditBox*, const char *, bool)', sampapi.GetAddress(CDXUTEditBox_SetText_addr[sampapi.GetSAMPVersion()])),
38
+ }
39
+ mt.set_handler('struct CDXUTEditBox', '__index', CDXUTEditBox_mt)
game.lua ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local game = sampapi.require('CGame', true)
12
+
13
+ function sampGetMiscInfoPtr()
14
+ return shared.get_pointer(game.RefGame())
15
+ end
16
+ jit.off(sampGetMiscInfoPtr, true)
17
+
18
+ function sampToggleCursor(show)
19
+ game.RefGame():SetCursorMode(show and ffi.C.CURSOR_LOCKCAM or ffi.C.CURSOR_NONE, show)
20
+ if not show then
21
+ game.RefGame():ProcessInputEnabling()
22
+ end
23
+ end
24
+ jit.off(sampToggleCursor, true)
25
+
26
+ function sampIsCursorActive()
27
+ return game.RefGame().m_nCursorMode ~= ffi.C.CURSOR_NONE
28
+ end
29
+ jit.off(sampIsCursorActive, true)
30
+
31
+ function sampGetCursorMode()
32
+ return game.RefGame().m_nCursorMode
33
+ end
34
+ jit.off(sampGetCursorMode, true)
35
+
36
+ function sampSetCursorMode(mode)
37
+ game.RefGame().m_nCursorMode = mode
38
+ end
39
+ jit.off(sampSetCursorMode, true)
gangzone.lua ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ sampapi.require('CGangZonePool', true)
13
+
14
+ local function gangzonepool()
15
+ return netgame.RefNetGame().m_pPools.m_pGangZone
16
+ end
17
+
18
+ function sampGetGangzonePoolPtr()
19
+ return shared.get_pointer(gangzonepool())
20
+ end
21
+ jit.off(sampGetGangzonePoolPtr, true)
init.lua ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local ok, raklua = pcall(require, 'RakLua')
8
+ if ok then
9
+ raklua.defineSampLuaCompatibility()
10
+ end
11
+
12
+ require 'sflua.basic'
13
+ require 'sflua.chat'
14
+ require 'sflua.deathwindow'
15
+ require 'sflua.dialog'
16
+ require 'sflua.game'
17
+ require 'sflua.gangzone'
18
+ require 'sflua.input'
19
+ require 'sflua.label'
20
+ require 'sflua.netgame'
21
+ require 'sflua.object'
22
+ require 'sflua.pickup'
23
+ require 'sflua.player'
24
+ require 'sflua.scoreboard'
25
+ require 'sflua.textdraw'
26
+ require 'sflua.vehicle'
27
+ require 'sflua.raknet'
28
+
29
+ -- TODO:
30
+ -- sampHasDialogRespond
31
+ -- sampForcePassengerSyncSeatId
32
+ -- sampForceWeaponsSync
33
+ -- sampGetRakclientFuncAddressByIndex
34
+ -- sampGetRpcCallbackByRpcId
35
+ -- sampGetRpcNodeByRpcId
36
+ -- raknetEmulRpcReceiveBitStream
37
+ -- raknetEmulPacketReceiveBitStream
38
+ -- sampSetClientCommandDescription: needed?
39
+ -- sampGetStreamedOutPlayerPos: RakLua?
40
+ -- onSendRpc
41
+ -- onSendPacket
42
+ -- onReceiveRpc
43
+ -- onReceivePacket
input.lua ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ require 'sflua.cdef.dxut'
12
+ local input = sampapi.require('CInput', true)
13
+
14
+ local registered_cmds = {}
15
+
16
+ function sampGetInputInfoPtr()
17
+ return shared.get_pointer(dialog.RefInputBox())
18
+ end
19
+ jit.off(sampGetInputInfoPtr, true)
20
+
21
+ function sampRegisterChatCommand(cmd, func)
22
+ if input.RefInputBox():GetCommandHandler(cmd) ~= nil then
23
+ print(('WARNING: The "%s" command is already registered.'):format(cmd))
24
+ return
25
+ end
26
+
27
+ jit.off(func, true)
28
+ local cb = ffi.cast('CMDPROC', function(args) func(ffi.string(args)) end)
29
+ input.RefInputBox():AddCommand(cmd, cb)
30
+ registered_cmds[cmd] = true
31
+ return true
32
+ end
33
+ jit.off(sampRegisterChatCommand, true)
34
+
35
+ function sampUnregisterChatCommand(cmd)
36
+ local ref = input.RefInputBox()
37
+ for i = 0, ref.m_nCommandCount - 1 do
38
+ if ffi.string(ref.m_szCommandName[i]) == cmd then
39
+ local needs = ref.m_nCommandCount - i - 1
40
+ local clear = i
41
+ if needs > 0 then
42
+ ffi.copy(ref.m_szCommandName[i], ref.m_szCommandName[i + 1], ffi.sizeof(ref.m_szCommandName[i]) * needs)
43
+ ffi.copy(ref.m_commandProc + i, ref.m_commandProc + i + 1, ffi.sizeof(ref.m_commandProc[i]) * needs)
44
+ clear = i + needs
45
+ end
46
+ ffi.fill(ref.m_szCommandName[clear], ffi.sizeof(ref.m_szCommandName[clear]), 0)
47
+ ref.m_commandProc[clear] = nil
48
+ ref.m_nCommandCount = ref.m_nCommandCount - 1
49
+ registered_cmds[cmd] = nil
50
+ return true
51
+ end
52
+ end
53
+ return false
54
+ end
55
+ jit.off(sampUnregisterChatCommand, true)
56
+
57
+ function sampSetChatInputText(text)
58
+ input.RefInputBox().m_pEditbox:SetText(text, false)
59
+ end
60
+ jit.off(sampSetChatInputText, true)
61
+
62
+ function sampGetChatInputText()
63
+ return input.RefInputBox().m_pEditbox:GetText()
64
+ end
65
+ jit.off(sampGetChatInputText, true)
66
+
67
+ function sampSetChatInputEnabled(enabled)
68
+ if enabled then
69
+ input.RefInputBox():Open()
70
+ else
71
+ input.RefInputBox():Close()
72
+ end
73
+ end
74
+ jit.off(sampSetChatInputEnabled, true)
75
+
76
+ function sampIsChatInputActive()
77
+ return input.RefInputBox().m_bEnabled == 1
78
+ end
79
+ jit.off(sampIsChatInputActive, true)
80
+
81
+ function sampIsChatCommandDefined(cmd)
82
+ local ref = input.RefInputBox()
83
+ for i = 0, ffi.C.MAX_CLIENT_CMDS - 1 do
84
+ if ffi.string(ref.m_szCommandName[i]) == cmd then
85
+ return true
86
+ end
87
+ end
88
+ return false
89
+ end
90
+ jit.off(sampIsChatCommandDefined, true)
91
+
92
+ function sampProcessChatInput(text)
93
+ sampSetChatInputText(text)
94
+ input.RefInputBox():ProcessInput()
95
+ end
96
+ jit.off(sampProcessChatInput, true)
97
+
98
+ -- unregister commands when unloading the script
99
+ addEventHandler('onScriptTerminate', function (s, quitGame)
100
+ if s == script.this then
101
+ for i in pairs(registered_cmds) do
102
+ sampUnregisterChatCommand(i)
103
+ end
104
+ end
105
+ end)
label.lua ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ sampapi.require('CLabelPool', true)
13
+
14
+ ffi.cdef[[
15
+ void *calloc(size_t nmemb, size_t size);
16
+ void *realloc(void *ptr, size_t size);
17
+ ]]
18
+
19
+ local function labelpool()
20
+ return netgame.RefNetGame().m_pPools.m_pLabel
21
+ end
22
+
23
+ function sampGetTextlabelPoolPtr()
24
+ return shared.get_pointer(labelpool())
25
+ end
26
+ jit.off(sampGetTextlabelPoolPtr, true)
27
+
28
+ function sampCreate3dText(text, color, posX, posY, posZ, distance, ignoreWalls, playerId, vehicleId)
29
+ for i = 0, ffi.C.MAX_TEXT_LABELS - 1 do
30
+ if not sampIs3dTextDefined(i) then
31
+ sampCreate3dTextEx(i, text, color, posX, posY, posZ, distance, ignoreWalls, playerId, vehicleId)
32
+ return i
33
+ end
34
+ end
35
+ return -1
36
+ end
37
+
38
+ function sampIs3dTextDefined(id)
39
+ return labelpool().m_bNotEmpty[id] == 1
40
+ end
41
+ jit.off(sampIs3dTextDefined, true)
42
+
43
+ function sampGet3dTextInfoById(id)
44
+ if sampIs3dTextDefined(id) then
45
+ local obj = labelpool().m_object[id]
46
+ return ffi.string(obj.m_pText), obj.m_color,
47
+ obj.m_position.x, obj.m_position.y, obj.m_position.z,
48
+ obj.m_fDrawDistance, obj.m_bBehindWalls, obj.m_nAttachedToPlayer, obj.m_nAttachedToVehicle
49
+ end
50
+ end
51
+ jit.off(sampGet3dTextInfoById, true)
52
+
53
+ function sampSet3dTextString(id, text)
54
+ if sampIs3dTextDefined(id) then
55
+ local obj = labelpool().m_object[id]
56
+ if obj.m_pText == nil then
57
+ obj.m_pText = ffi.cast('char*', ffi.C.calloc(ffi.sizeof('char'), #text + 1))
58
+ else
59
+ obj.m_pText = ffi.cast('char*', ffi.C.realloc(obj.m_pText, #text + 1))
60
+ end
61
+ ffi.copy(obj.m_pText, text)
62
+ end
63
+ end
64
+ jit.off(sampSet3dTextString, true)
65
+
66
+ function sampDestroy3dText(id)
67
+ if sampIs3dTextDefined(id) then
68
+ labelpool():Delete(id)
69
+ end
70
+ end
71
+ jit.off(sampDestroy3dText, true)
72
+
73
+ function sampCreate3dTextEx(id, text, color, posX, posY, posZ, distance, ignoreWalls, playerId, vehicleId)
74
+ sampDestroy3dText(id) -- if the label exists
75
+ labelpool():Create(id, text, color, { x = posX, y = posY, z = posZ }, distance, ignoreWalls, playerId, vehicleId)
76
+ end
77
+ jit.off(sampCreate3dTextEx, true)
netgame.lua ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ local localplayer = sampapi.require('CLocalPlayer', true)
13
+
14
+ local AnimList_addr = {
15
+ [ffi.C.SAMP_VERSION_037R1] = 0xF15B0,
16
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x1039D0,
17
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x1039E8,
18
+ }
19
+ local AnimList = ffi.cast('char*', sampapi.GetAddress(AnimList_addr[sampapi.GetSAMPVersion()])) -- char[1812][36]
20
+
21
+ function sampGetSampInfoPtr()
22
+ return shared.get_pointer(netgame.RefNetGame())
23
+ end
24
+ jit.off(sampGetSampInfoPtr, true)
25
+
26
+ function sampGetSampPoolsPtr()
27
+ return shared.get_pointer(netgame.RefNetGame().m_pPools)
28
+ end
29
+ jit.off(sampGetSampPoolsPtr, true)
30
+
31
+ function sampGetServerSettingsPtr()
32
+ return shared.get_pointer(netgame.RefNetGame().m_pSettings)
33
+ end
34
+ jit.off(sampGetServerSettingsPtr, true)
35
+
36
+ function sampGetCurrentServerName()
37
+ return ffi.string(netgame.RefNetGame().m_szHostname)
38
+ end
39
+ jit.off(sampGetCurrentServerName, true)
40
+
41
+ function sampGetCurrentServerAddress()
42
+ return ffi.string(netgame.RefNetGame().m_szHostAddress), netgame.RefNetGame().m_nPort
43
+ end
44
+ jit.off(sampGetCurrentServerAddress, true)
45
+
46
+ function sampGetGamestate()
47
+ local convert = {
48
+ [ffi.C.GAME_MODE_WAITCONNECT] = GAMESTATE_WAIT_CONNECT,
49
+ [ffi.C.GAME_MODE_CONNECTING] = GAMESTATE_DISCONNECTED, -- TODO: correct?
50
+ [ffi.C.GAME_MODE_CONNECTED] = GAMESTATE_CONNECTED,
51
+ [ffi.C.GAME_MODE_WAITJOIN] = GAMESTATE_AWAIT_JOIN,
52
+ [ffi.C.GAME_MODE_RESTARTING] = GAMESTATE_RESTARTING
53
+ }
54
+ return convert[netgame.RefNetGame().m_nGameState] or GAMESTATE_NONE
55
+ end
56
+ jit.off(sampGetGamestate, true)
57
+
58
+ function sampSetGamestate(gamestate)
59
+ local convert = {
60
+ [GAMESTATE_WAIT_CONNECT] = ffi.C.GAME_MODE_WAITCONNECT,
61
+ [GAMESTATE_DISCONNECTED] = ffi.C.GAME_MODE_CONNECTING, -- TODO: correct?
62
+ [GAMESTATE_CONNECTED] = ffi.C.GAME_MODE_CONNECTED,
63
+ [GAMESTATE_AWAIT_JOIN] = ffi.C.GAME_MODE_WAITJOIN,
64
+ [GAMESTATE_RESTARTING] = ffi.C.GAME_MODE_RESTARTING
65
+ }
66
+ if convert[gamestate] then
67
+ netgame.RefNetGame().m_nGameState = convert[gamestate]
68
+ end
69
+ end
70
+ jit.off(sampSetGamestate, true)
71
+
72
+ function sampGetAnimationNameAndFile(id)
73
+ id = tonumber(id) or 0
74
+ local name, file = ffi.string(AnimList + 36 * id):match('(.*):(.*)')
75
+ return name or '', file or ''
76
+ end
77
+ jit.off(sampGetAnimationNameAndFile, true)
78
+
79
+ function sampFindAnimationIdByNameAndFile(name, file)
80
+ local filename = ('%s:%s'):format(name, file)
81
+ for i = 0, 1812 - 1 do
82
+ if ffi.string(AnimList + 36 * i) == filename then
83
+ return i
84
+ end
85
+ end
86
+ return -1
87
+ end
88
+ jit.off(sampFindAnimationIdByNameAndFile, true)
89
+
90
+ function sampSetSendrate(type, rate)
91
+ local ref
92
+ if type == ONFOOTSENDRATE then
93
+ ref = localplayer.RefOnfootSendrate()
94
+ elseif type == INCARSENDRATE then
95
+ ref = localplayer.RefIncarSendrate()
96
+ elseif type == AIMSENDRATE then
97
+ ref = localplayer.RefFiringSendrate()
98
+ end
99
+
100
+ if ref then
101
+ ref[0] = rate
102
+ end
103
+ end
104
+ jit.off(sampSetSendrate, true)
object.lua ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ sampapi.require('CObjectPool', true)
13
+
14
+ local function objectpool()
15
+ return netgame.RefNetGame():GetObjectPool()
16
+ end
17
+
18
+ function sampGetObjectPoolPtr()
19
+ return shared.get_pointer(objectpool())
20
+ end
21
+ jit.off(sampGetObjectPoolPtr, true)
22
+
23
+ function sampGetObjectHandleBySampId(id)
24
+ if objectpool().m_bNotEmpty[id] == 1 then
25
+ local obj = objectpool():Get(id)
26
+ return obj.__parent.m_handle
27
+ end
28
+ return -1
29
+ end
30
+ jit.off(sampGetObjectHandleBySampId, true)
31
+
32
+ function sampGetObjectSampIdByHandle(object)
33
+ for i = 0, ffi.C.MAX_OBJECTS - 1 do
34
+ local res, handle = sampGetObjectHandleBySampId(i)
35
+ if res and handle == object then return true, i end
36
+ end
37
+ return false, -1
38
+ end
pickup.lua ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ sampapi.require('CPickupPool', true)
13
+
14
+ local function pickuppool()
15
+ return netgame.RefNetGame().m_pPools.m_pPickup
16
+ end
17
+
18
+ function sampGetPickupPoolPtr()
19
+ return shared.get_pointer(pickuppool())
20
+ end
21
+ jit.off(sampGetPickupPoolPtr, true)
22
+
23
+ function sampGetPickupHandleBySampId(id)
24
+ return pickuppool().m_handle[id]
25
+ end
26
+ jit.off(sampGetPickupHandleBySampId, true)
27
+
28
+ function sampGetPickupSampIdByHandle(handle)
29
+ for i = 0, ffi.C.MAX_PICKUPS - 1 do
30
+ if sampGetPickupHandleBySampId(i) == handle then
31
+ return i
32
+ end
33
+ end
34
+ return -1
35
+ end
player.lua ADDED
@@ -0,0 +1,439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ local input = sampapi.require('CInput', true)
13
+ sampapi.require('CPlayerPool', true)
14
+
15
+ local function playerpool()
16
+ return netgame.RefNetGame():GetPlayerPool()
17
+ end
18
+
19
+ function sampGetPlayerPoolPtr()
20
+ return shared.get_pointer(playerpool())
21
+ end
22
+ jit.off(sampGetPlayerPoolPtr, true)
23
+
24
+ function sampIsPlayerConnected(id)
25
+ return playerpool():IsConnected(id)
26
+ end
27
+ jit.off(sampIsPlayerConnected, true)
28
+
29
+ function sampGetPlayerNickname(id)
30
+ if not sampIsPlayerConnected(id) then
31
+ return ''
32
+ end
33
+ netgame.RefNetGame():UpdatePlayers()
34
+ return ffi.string(playerpool():GetName(id))
35
+ end
36
+ jit.off(sampGetPlayerNickname, true)
37
+
38
+ function sampSpawnPlayer()
39
+ local localplayer = playerpool():GetLocalPlayer()
40
+ localplayer:RequestSpawn()
41
+ localplayer:Spawn()
42
+ end
43
+ jit.off(sampSpawnPlayer, true)
44
+
45
+ function sampSendChat(text)
46
+ if text:byte(1) == 47 then -- character "/"
47
+ input.RefInput():Send(text)
48
+ else
49
+ local localplayer = playerpool():GetLocalPlayer()
50
+ playerpool():GetLocalPlayer():Chat(text)
51
+ end
52
+ end
53
+ jit.off(sampSendChat, true)
54
+
55
+ function sampIsPlayerNpc(id)
56
+ return sampIsPlayerConnected(id) and playerpool().m_pObject[id].m_bIsNPC == 1
57
+ end
58
+ jit.off(sampIsPlayerNpc, true)
59
+
60
+ function sampGetPlayerScore(id)
61
+ if not sampIsPlayerConnected(id) then
62
+ return 0
63
+ end
64
+ netgame.RefNetGame():UpdatePlayers()
65
+ if id == sampGetLocalPlayerId() then
66
+ return playerpool():GetLocalPlayerScore()
67
+ end
68
+ return playerpool():GetScore(id)
69
+ end
70
+ jit.off(sampGetPlayerScore, true)
71
+
72
+ function sampGetPlayerPing(id)
73
+ if not sampIsPlayerConnected(id) then
74
+ return 0
75
+ end
76
+ netgame.RefNetGame():UpdatePlayers()
77
+ if id == sampGetLocalPlayerId() then
78
+ return playerpool():GetLocalPlayerPing()
79
+ end
80
+ return playerpool():GetPing(id)
81
+ end
82
+ jit.off(sampGetPlayerPing, true)
83
+
84
+ function sampRequestClass(class)
85
+ local localplayer = playerpool():GetLocalPlayer()
86
+ localplayer:RequestClass(class)
87
+ end
88
+ jit.off(sampRequestClass, true)
89
+
90
+ function sampSendInteriorChange(id)
91
+ local localplayer = playerpool():GetLocalPlayer()
92
+ localplayer:ChangeInterior(id)
93
+ end
94
+ jit.off(sampSendInteriorChange, true)
95
+
96
+ function sampForceUnoccupiedSyncSeatId(id, seat)
97
+ local localplayer = playerpool():GetLocalPlayer()
98
+ localplayer:SendUnoccupiedData(id, seat)
99
+ end
100
+ jit.off(sampForceUnoccupiedSyncSeatId, true)
101
+
102
+ function sampGetCharHandleBySampPlayerId(id)
103
+ if id == sampGetLocalPlayerId() then
104
+ return true, PLAYER_PED
105
+ elseif sampIsPlayerDefined(id) then
106
+ local remoteplayer = playerpool():GetPlayer(id)
107
+ if remoteplayer ~= nil then
108
+ local ped = remoteplayer.m_pPed.m_pGamePed
109
+ return true, getCharPointerHandle(shared.get_pointer(ped))
110
+ end
111
+ end
112
+ return false, -1
113
+ end
114
+ jit.off(sampGetCharHandleBySampPlayerId, true)
115
+
116
+ function sampGetPlayerIdByCharHandle(handle)
117
+ if handle == PLAYER_PED then
118
+ return true, sampGetLocalPlayerId()
119
+ end
120
+ for i = 0, ffi.C.MAX_PLAYERS - 1 do
121
+ local res, pped = sampGetCharHandleBySampPlayerId(i)
122
+ if res and pped == handle then return true, i end
123
+ end
124
+ return false, -1
125
+ end
126
+ jit.off(sampGetPlayerIdByCharHandle, true)
127
+
128
+ function sampGetPlayerArmor(id)
129
+ if id == sampGetLocalPlayerId() then
130
+ return getCharArmour(PLAYER_PED)
131
+ elseif sampIsPlayerDefined(id) then
132
+ local remoteplayer = playerpool():GetPlayer(id)
133
+ if remoteplayer ~= nil then
134
+ return remoteplayer.m_fReportedArmour
135
+ end
136
+ end
137
+ return 0
138
+ end
139
+ jit.off(sampGetPlayerArmor, true)
140
+
141
+ function sampGetPlayerHealth(id)
142
+ if id == sampGetLocalPlayerId() then
143
+ return getCharHealth(PLAYER_PED)
144
+ elseif sampIsPlayerDefined(id) then
145
+ local remoteplayer = playerpool():GetPlayer(id)
146
+ if remoteplayer ~= nil then
147
+ return remoteplayer.m_fReportedHealth
148
+ end
149
+ end
150
+ return 0
151
+ end
152
+ jit.off(sampGetPlayerHealth, true)
153
+
154
+ function sampIsPlayerPaused(id)
155
+ if id == sampGetLocalPlayerId() then
156
+ -- TODO: CMenuManager?
157
+ return false
158
+ elseif sampIsPlayerConnected(id) then
159
+ local remoteplayer = playerpool():GetPlayer(id)
160
+ if remoteplayer ~= nil then
161
+ return remoteplayer.m_nStatus == ffi.C.PLAYER_STATE_NONE
162
+ end
163
+ end
164
+ end
165
+ jit.off(sampIsPlayerPaused, true)
166
+
167
+ function sampSetSpecialAction(action)
168
+ local localplayer = playerpool():GetLocalPlayer()
169
+ localplayer:SetSpecialAction(action)
170
+ end
171
+ jit.off(sampSetSpecialAction, true)
172
+
173
+ function sampGetPlayerCount(streamed)
174
+ if not streamed then
175
+ return playerpool():GetCount(true)
176
+ end
177
+
178
+ local players = 0
179
+ for i = 0, ffi.C.MAX_PLAYERS - 1 do
180
+ if i ~= sampGetLocalPlayerId() then
181
+ local res, ped = sampGetCharHandleBySampPlayerId(i)
182
+ local bool = res and doesCharExist(ped)
183
+ if bool then players = players + 1 end
184
+ end
185
+ end
186
+ return players
187
+ end
188
+ jit.off(sampGetPlayerCount, true)
189
+
190
+ function sampGetMaxPlayerId(streamed)
191
+ if not streamed then
192
+ return playerpool().m_nLargestId
193
+ end
194
+
195
+ local mid = sampGetLocalPlayerId()
196
+ for i = 0, ffi.C.MAX_PLAYERS - 1 do
197
+ if i ~= sampGetLocalPlayerId() then
198
+ local res, ped = sampGetCharHandleBySampPlayerId(i)
199
+ local bool = res and doesCharExist(ped)
200
+ if bool and i > mid then mid = i end
201
+ end
202
+ end
203
+ return mid
204
+ end
205
+ jit.off(sampGetMaxPlayerId, true)
206
+
207
+ function sampGetPlayerSpecialAction(id)
208
+ if id == sampGetLocalPlayerId() then
209
+ local localplayer = playerpool():GetLocalPlayer()
210
+ return localplayer:GetSpecialAction()
211
+ elseif sampIsPlayerDefined(id) then
212
+ local remoteplayer = playerpool():GetPlayer(id)
213
+ if remoteplayer ~= nil then
214
+ return remoteplayer.m_nSpecialAction
215
+ end
216
+ end
217
+ return -1
218
+ end
219
+ jit.off(sampGetPlayerSpecialAction, true)
220
+
221
+ function sampStorePlayerOnfootData(id, data)
222
+ local player
223
+ if id == sampGetLocalPlayerId() then
224
+ player = playerpool():GetLocalPlayer()
225
+ elseif sampIsPlayerDefined(id) then
226
+ player = playerpool():GetPlayer(id)
227
+ end
228
+
229
+ if player then
230
+ ffi.copy(ffi.cast('void*', data), player.m_onfootData, ffi.sizeof(player.m_onfootData))
231
+ end
232
+ end
233
+ jit.off(sampStorePlayerOnfootData, true)
234
+
235
+ function sampStorePlayerIncarData(id, data)
236
+ local player
237
+ if id == sampGetLocalPlayerId() then
238
+ player = playerpool():GetLocalPlayer()
239
+ elseif sampIsPlayerDefined(id) then
240
+ player = playerpool():GetPlayer(id)
241
+ end
242
+
243
+ if player then
244
+ ffi.copy(ffi.cast('void*', data), player.m_incarData, ffi.sizeof(player.m_incarData))
245
+ end
246
+ end
247
+ jit.off(sampStorePlayerIncarData, true)
248
+
249
+ function sampStorePlayerPassengerData(id, data)
250
+ local player
251
+ if id == sampGetLocalPlayerId() then
252
+ player = playerpool():GetLocalPlayer()
253
+ elseif sampIsPlayerDefined(id) then
254
+ player = playerpool():GetPlayer(id)
255
+ end
256
+
257
+ if player then
258
+ ffi.copy(ffi.cast('void*', data), player.m_passengerData, ffi.sizeof(player.m_passengerData))
259
+ end
260
+ end
261
+ jit.off(sampStorePlayerPassengerData, true)
262
+
263
+ function sampStorePlayerTrailerData(id, data)
264
+ local player
265
+ if id == sampGetLocalPlayerId() then
266
+ player = playerpool():GetLocalPlayer()
267
+ elseif sampIsPlayerDefined(id) then
268
+ player = playerpool():GetPlayer(id)
269
+ end
270
+
271
+ if player then
272
+ ffi.copy(ffi.cast('void*', data), player.m_trailerData, ffi.sizeof(player.m_trailerData))
273
+ end
274
+ end
275
+ jit.off(sampStorePlayerTrailerData, true)
276
+
277
+ function sampStorePlayerAimData(id, data)
278
+ local player
279
+ if id == sampGetLocalPlayerId() then
280
+ player = playerpool():GetLocalPlayer()
281
+ elseif sampIsPlayerDefined(id) then
282
+ player = playerpool():GetPlayer(id)
283
+ end
284
+
285
+ if player then
286
+ ffi.copy(ffi.cast('void*', data), player.m_aimData, ffi.sizeof(player.m_aimData))
287
+ end
288
+ end
289
+ jit.off(sampStorePlayerAimData, true)
290
+
291
+ function sampSendSpawn()
292
+ local localplayer = playerpool():GetLocalPlayer()
293
+ localplayer:Spawn()
294
+ end
295
+ jit.off(sampSendSpawn, true)
296
+
297
+ function sampGetPlayerAnimationId(id)
298
+ if id == sampGetLocalPlayerId() then
299
+ local localplayer = playerpool():GetLocalPlayer()
300
+ return localplayer.m_animation.m_value
301
+ elseif sampIsPlayerDefined(id) then
302
+ local remoteplayer = playerpool():GetPlayer(id)
303
+ if remoteplayer ~= nil then
304
+ return remoteplayer.m_animation.m_value
305
+ end
306
+ end
307
+ return -1
308
+ end
309
+ jit.off(sampGetPlayerAnimationId, true)
310
+
311
+ function sampSetLocalPlayerName(name)
312
+ playerpool():SetLocalPlayerName(name)
313
+ end
314
+ jit.off(sampSetLocalPlayerName, true)
315
+
316
+ function sampGetPlayerStructPtr(id)
317
+ if id == sampGetLocalPlayerId() then
318
+ local localplayer = playerpool():GetLocalPlayer()
319
+ return shared.get_pointer(localplayer)
320
+ elseif sampIsPlayerConnected(id) then
321
+ local remoteplayer = playerpool():GetPlayer(id)
322
+ return shared.get_pointer(remoteplayer)
323
+ end
324
+ return 0
325
+ end
326
+ jit.off(sampGetPlayerStructPtr, true)
327
+
328
+ function sampSendEnterVehicle(id, passenger)
329
+ local localplayer = playerpool():GetLocalPlayer()
330
+ localplayer:EnterVehicle(id, passenger)
331
+ end
332
+ jit.off(sampSendEnterVehicle, true)
333
+
334
+ function sampSendExitVehicle(id)
335
+ local localplayer = playerpool():GetLocalPlayer()
336
+ localplayer:ExitVehicle(id)
337
+ end
338
+ jit.off(sampSendExitVehicle, true)
339
+
340
+ function sampIsLocalPlayerSpawned()
341
+ -- TODO: works fine?
342
+ local localplayer = playerpool():GetLocalPlayer()
343
+ return localplayer.m_bClearedToSpawn == 1 and localplayer.m_bHasSpawnInfo == 1 and ( localplayer.m_bIsActive == 1 or isCharDead(PLAYER_PED) )
344
+ end
345
+ jit.off(sampIsLocalPlayerSpawned, true)
346
+
347
+ function sampGetPlayerColor(id)
348
+ if id == sampGetLocalPlayerId() then
349
+ local localplayer = playerpool():GetLocalPlayer()
350
+ return localplayer:GetColorAsARGB()
351
+ elseif sampIsPlayerConnected(id) then
352
+ local remoteplayer = playerpool():GetPlayer(id)
353
+ if remoteplayer ~= nil then
354
+ return remoteplayer:GetColorAsARGB()
355
+ end
356
+ end
357
+ return 0
358
+ end
359
+ jit.off(sampGetPlayerColor, true)
360
+
361
+ function sampForceAimSync()
362
+ local localplayer = playerpool():GetLocalPlayer()
363
+ localplayer.m_lastAnyUpdate = 0 -- lol
364
+ localplayer:SendAimData()
365
+ end
366
+ jit.off(sampForceAimSync, true)
367
+
368
+ function sampForceOnfootSync()
369
+ local localplayer = playerpool():GetLocalPlayer()
370
+ localplayer.m_lastAnyUpdate = 0
371
+ localplayer:SendOnfootData()
372
+ end
373
+ jit.off(sampForceOnfootSync, true)
374
+
375
+ function sampForceStatsSync()
376
+ local localplayer = playerpool():GetLocalPlayer()
377
+ localplayer.m_lastAnyUpdate = 0
378
+ localplayer:SendStats()
379
+ end
380
+ jit.off(sampForceStatsSync, true)
381
+
382
+ function sampForceTrailerSync(id)
383
+ local localplayer = playerpool():GetLocalPlayer()
384
+ localplayer.m_lastAnyUpdate = 0
385
+ localplayer:SendTrailerData(id)
386
+ end
387
+ jit.off(sampForceTrailerSync, true)
388
+
389
+ function sampForceVehicleSync(id)
390
+ local localplayer = playerpool():GetLocalPlayer()
391
+ localplayer.m_lastAnyUpdate = 0
392
+ localplayer:SendIncarData(id)
393
+ end
394
+ jit.off(sampForceVehicleSync, true)
395
+
396
+ -- New functions
397
+
398
+ function sampGetLocalPlayerId()
399
+ return playerpool().m_localInfo.m_nId
400
+ end
401
+ jit.off(sampGetLocalPlayerId, true)
402
+
403
+ function sampIsPlayerDefined(id)
404
+ if id == sampGetLocalPlayerId() then
405
+ local localplayer = playerpool():GetLocalPlayer()
406
+ return localplayer ~= nil
407
+ end
408
+
409
+ if not sampIsPlayerConnected(id) then
410
+ return false
411
+ end
412
+ local remoteplayer = playerpool():GetPlayer(id)
413
+ if remoteplayer == nil then
414
+ return false
415
+ end
416
+ return remoteplayer:DoesExist() ~= 0
417
+ end
418
+ jit.off(sampIsPlayerDefined, true)
419
+
420
+ function sampGetLocalPlayerNickname()
421
+ return sampGetPlayerNickname(sampGetLocalPlayerId())
422
+ end
423
+
424
+ function sampGetLocalPlayerColor()
425
+ return sampGetPlayerColor(sampGetLocalPlayerId())
426
+ end
427
+
428
+ function sampSetPlayerColor(id, color)
429
+ if id == sampGetLocalPlayerId() then
430
+ local localplayer = playerpool():GetLocalPlayer()
431
+ return localplayer:SetColor(color)
432
+ elseif sampIsPlayerConnected(id) then
433
+ local remoteplayer = playerpool():GetPlayer(id)
434
+ if remoteplayer ~= nil then
435
+ return remoteplayer:SetColor(color)
436
+ end
437
+ end
438
+ end
439
+ jit.off(sampSetPlayerColor, true)
raknet.lua ADDED
@@ -0,0 +1,700 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ local rakluaLoaded, raklua = pcall(require, 'RakLua')
13
+
14
+ if not rakluaLoaded then
15
+ require 'sflua.cdef.bitstream'
16
+ local StringCompressor = require 'sflua.cdef.stringcompressor'
17
+
18
+ function raknetBitStreamReadBool(bitstream)
19
+ bitstream = ffi.cast('SBitStream*', bitstream)
20
+ return bitstream:ReadBit()
21
+ end
22
+ jit.off(raknetBitStreamReadBool, true)
23
+
24
+ function raknetBitStreamReadBuffer(bitstream, dest, size)
25
+ bitstream = ffi.cast('SBitStream*', bitstream)
26
+ bitstream:ReadBits(dest, size * 8, true)
27
+ end
28
+ jit.off(raknetBitStreamReadBuffer, true)
29
+
30
+ function raknetBitStreamReadInt8(bitstream)
31
+ local buf = ffi.new('char[1]')
32
+ raknetBitStreamReadBuffer(bitstream, buf, ffi.sizeof(buf))
33
+ return buf[0]
34
+ end
35
+ jit.off(raknetBitStreamReadInt8, true)
36
+
37
+ function raknetBitStreamReadInt16(bitstream)
38
+ local buf = ffi.new('short[1]')
39
+ raknetBitStreamReadBuffer(bitstream, buf, ffi.sizeof(buf))
40
+ return buf[0]
41
+ end
42
+ jit.off(raknetBitStreamReadInt16, true)
43
+
44
+ function raknetBitStreamReadInt32(bitstream)
45
+ local buf = ffi.new('long [1]')
46
+ raknetBitStreamReadBuffer(bitstream, buf, ffi.sizeof(buf))
47
+ return buf[0]
48
+ end
49
+ jit.off(raknetBitStreamReadInt32, true)
50
+
51
+ function raknetBitStreamReadFloat(bitstream)
52
+ local buf = ffi.new('float[1]')
53
+ raknetBitStreamReadBuffer(bitstream, buf, ffi.sizeof(buf))
54
+ return buf[0]
55
+ end
56
+ jit.off(raknetBitStreamReadFloat, true)
57
+
58
+ function raknetBitStreamReadString(bitstream, size)
59
+ local buf = ffi.new('char[?]', size + 1)
60
+ raknetBitStreamReadBuffer(bitstream, buf, ffi.sizeof(buf) - 1)
61
+ buf[size] = 0
62
+ return ffi.string(buf)
63
+ end
64
+ jit.off(raknetBitStreamReadString, true)
65
+
66
+ function raknetBitStreamResetReadPointer(bitstream)
67
+ bitstream = ffi.cast('SBitStream*', bitstream)
68
+ bitstream:ResetReadPointer()
69
+ end
70
+ jit.off(raknetBitStreamResetReadPointer, true)
71
+
72
+ function raknetBitStreamResetWritePointer(bitstream)
73
+ bitstream = ffi.cast('SBitStream*', bitstream)
74
+ bitstream:ResetWritePointer()
75
+ end
76
+ jit.off(raknetBitStreamResetWritePointer, true)
77
+
78
+ function raknetBitStreamIgnoreBits(bitstream, amount)
79
+ bitstream = ffi.cast('SBitStream*', bitstream)
80
+ bitstream:IgnoreBits(amount)
81
+ end
82
+ jit.off(raknetBitStreamIgnoreBits, true)
83
+
84
+ function raknetBitStreamSetWriteOffset(bitstream, offset)
85
+ bitstream = ffi.cast('SBitStream*', bitstream)
86
+ bitstream:SetWriteOffset(offset)
87
+ end
88
+ jit.off(raknetBitStreamSetWriteOffset, true)
89
+
90
+ function raknetBitStreamSetReadOffset(bitstream, offset)
91
+ bitstream = ffi.cast('SBitStream*', bitstream)
92
+ bitstream.readOffset = offset
93
+ end
94
+ jit.off(raknetBitStreamSetReadOffset, true)
95
+
96
+ function raknetBitStreamGetNumberOfBitsUsed(bitstream)
97
+ bitstream = ffi.cast('SBitStream*', bitstream)
98
+ return bitstream.numberOfBitsUsed
99
+ end
100
+ jit.off(raknetBitStreamGetNumberOfBitsUsed, true)
101
+
102
+ function raknetBitStreamGetNumberOfBytesUsed(bitstream)
103
+ local bits = raknetBitStreamGetNumberOfBitsUsed(bitstream)
104
+ return bit.rshift(bits + 7, 3)
105
+ end
106
+ jit.off(raknetBitStreamGetNumberOfBytesUsed, true)
107
+
108
+ function raknetBitStreamGetNumberOfUnreadBits(bitstream)
109
+ bitstream = ffi.cast('SBitStream*', bitstream)
110
+ return bitstream.numberOfBitsAllocated - bitstream.numberOfBitsUsed
111
+ end
112
+ jit.off(raknetBitStreamGetNumberOfUnreadBits, true)
113
+
114
+ function raknetBitStreamGetWriteOffset(bitstream)
115
+ bitstream = ffi.cast('SBitStream*', bitstream)
116
+ return bitstream.numberOfBitsUsed
117
+ end
118
+ jit.off(raknetBitStreamGetWriteOffset, true)
119
+
120
+ function raknetBitStreamGetReadOffset(bitstream)
121
+ bitstream = ffi.cast('SBitStream*', bitstream)
122
+ return bitstream.readOffset
123
+ end
124
+ jit.off(raknetBitStreamGetReadOffset, true)
125
+
126
+ function raknetBitStreamGetDataPtr(bitstream)
127
+ bitstream = ffi.cast('SBitStream*', bitstream)
128
+ return shared.get_pointer(bitstream.data)
129
+ end
130
+ jit.off(raknetBitStreamGetDataPtr, true)
131
+
132
+ function raknetNewBitStream()
133
+ local bitstream = bs()
134
+ return shared.get_pointer(bitstream)
135
+ end
136
+ jit.off(raknetNewBitStream, true)
137
+
138
+ function raknetDeleteBitStream(bitstream)
139
+ bitstream = ffi.cast('SBitStream*', bitstream)
140
+ bitstream:__gc()
141
+ end
142
+ jit.off(raknetDeleteBitStream, true)
143
+
144
+ function raknetResetBitStream(bitstream)
145
+ bitstream = ffi.cast('SBitStream*', bitstream)
146
+ bitstream:Reset()
147
+ end
148
+ jit.off(raknetResetBitStream, true)
149
+
150
+ function raknetBitStreamWriteBool(bitstream, value)
151
+ bitstream = ffi.cast('SBitStream*', bitstream)
152
+ if value then bitstream:Write1()
153
+ else bitstream:Write0() end
154
+ end
155
+ jit.off(raknetBitStreamWriteBool, true)
156
+
157
+ function raknetBitStreamWriteInt8(bitstream, value)
158
+ local buf = ffi.new('char[1]', value)
159
+ raknetBitStreamWriteBuffer(bitstream, buf, ffi.sizeof(buf))
160
+ end
161
+ jit.off(raknetBitStreamWriteInt8, true)
162
+
163
+ function raknetBitStreamWriteInt16(bitstream, value)
164
+ local buf = ffi.new('short[1]', value)
165
+ raknetBitStreamWriteBuffer(bitstream, buf, ffi.sizeof(buf))
166
+ end
167
+ jit.off(raknetBitStreamWriteInt16, true)
168
+
169
+ function raknetBitStreamWriteInt32(bitstream, value)
170
+ local buf = ffi.new('long[1]', value)
171
+ raknetBitStreamWriteBuffer(bitstream, buf, ffi.sizeof(buf))
172
+ end
173
+ jit.off(raknetBitStreamWriteInt32, true)
174
+
175
+ function raknetBitStreamWriteFloat(bitstream, value)
176
+ local buf = ffi.new('float[1]', value)
177
+ raknetBitStreamWriteBuffer(bitstream, buf, ffi.sizeof(buf))
178
+ end
179
+ jit.off(raknetBitStreamWriteFloat, true)
180
+
181
+ function raknetBitStreamWriteBuffer(bitstream, dest, size)
182
+ bitstream = ffi.cast('SBitStream*', bitstream)
183
+ bitstream:WriteBits(dest, size * 8, true)
184
+ end
185
+ jit.off(raknetBitStreamWriteBuffer, true)
186
+
187
+ function raknetBitStreamWriteString(bitstream, str)
188
+ local buf = ffi.new('char[?]', #str + 1, str)
189
+ raknetBitStreamWriteBuffer(bitstream, buf, ffi.sizeof(buf) - 1)
190
+ end
191
+ jit.off(raknetBitStreamWriteString, true)
192
+
193
+ function raknetBitStreamDecodeString(bitstream, size)
194
+ bitstream = ffi.cast('SBitStream*', bitstream)
195
+ local buf = ffi.new('char[?]', size + 1)
196
+ StringCompressor.Instance():DecodeString(buf, size, bitstream, 0)
197
+ buf[size] = 0
198
+ return ffi.string(buf)
199
+ end
200
+ jit.off(raknetBitStreamDecodeString, true)
201
+
202
+ function raknetBitStreamEncodeString(bitstream, str)
203
+ bitstream = ffi.cast('SBitStream*', bitstream)
204
+ local buf = ffi.new('char[?]', #str + 1, str)
205
+ StringCompressor.Instance():EncodeString(buf, #str, bitstream, 0)
206
+ end
207
+ jit.off(raknetBitStreamEncodeString, true)
208
+
209
+ function raknetBitStreamWriteBitStream(bitstream, bitStream)
210
+ bitstream = ffi.cast('SBitStream*', bitstream)
211
+ bitstream:Write(bitStream)
212
+ end
213
+ jit.off(raknetBitStreamWriteBitStream, true)
214
+
215
+ function raknetSendRpcEx(rpc, bs, priority, reliability, channel, timestamp)
216
+ local rakclient = ffi.cast('void***', netgame.RefNetGame().m_pRakClient)
217
+ local vtbl = rakclient[0]
218
+ rpc = ffi.new('int[1]', rpc)
219
+ bs = ffi.cast('SBitStream*', bs)
220
+
221
+ -- RPC(int *uniqueID, RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, bool shiftTimestamp)
222
+ local RPC = ffi.cast('bool(__thiscall *)(void *, int *, SBitStream *, int, int, char, bool)', vtbl[25])
223
+ return RPC(rakclient, rpc, bs, priority, reliability, channel, timestamp)
224
+ end
225
+ jit.off(raknetSendRpcEx, true)
226
+
227
+ function raknetSendBitStreamEx(bs, priority, reliability, channel)
228
+ local rakclient = ffi.cast('void***', netgame.RefNetGame().m_pRakClient)
229
+ local vtbl = rakclient[0]
230
+ bs = ffi.cast('SBitStream*', bs)
231
+
232
+ -- Send(RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel)
233
+ local Send = ffi.cast('bool(__thiscall *)(void *, SBitStream *, int, int, char)', vtbl[6])
234
+ return Send(rakclient, bs, priority, reliability, channel)
235
+ end
236
+ jit.off(raknetSendBitStreamEx, true)
237
+
238
+ function raknetSendRpc(rpc, bs)
239
+ return raknetSendRpcEx(rpc, bs, HIGH_PRIORITY, RELIABLE, 0, false)
240
+ end
241
+
242
+ function raknetSendBitStream(bs)
243
+ return raknetSendBitStreamEx(bs, HIGH_PRIORITY, UNRELIABLE_SEQUENCED, 0)
244
+ end
245
+
246
+ end
247
+
248
+ function raknetGetRpcName(id)
249
+ local tab = {
250
+ [23] = 'ClickPlayer',
251
+ [25] = 'ClientJoin',
252
+ [26] = 'EnterVehicle',
253
+ [27] = 'EnterEditObject',
254
+ [31] = 'ScriptCash',
255
+ [50] = 'ServerCommand',
256
+ [52] = 'Spawn',
257
+ [53] = 'Death',
258
+ [54] = 'NPCJoin',
259
+ [62] = 'DialogResponse',
260
+ [83] = 'ClickTextDraw',
261
+ [96] = 'SCMEvent',
262
+ [101] = 'Chat',
263
+ [102] = 'SrvNetStats',
264
+ [103] = 'ClientCheck',
265
+ [106] = 'DamageVehicle',
266
+ [115] = 'GiveTakeDamage',
267
+ [116] = 'EditAttachedObject',
268
+ [117] = 'EditObject',
269
+ [118] = 'SetInteriorId',
270
+ [119] = 'MapMarker',
271
+ [128] = 'RequestClass',
272
+ [129] = 'RequestSpawn',
273
+ [131] = 'PickedUpPickup',
274
+ [132] = 'MenuSelect',
275
+ [136] = 'VehicleDestroyed',
276
+ [140] = 'MenuQuit',
277
+ [154] = 'ExitVehicle',
278
+ [155] = 'UpdateScoresPingsIPs',
279
+ [11] = 'SetPlayerName',
280
+ [12] = 'SetPlayerPos',
281
+ [13] = 'SetPlayerPosFindZ',
282
+ [14] = 'SetPlayerHealth',
283
+ [15] = 'TogglePlayerControllable',
284
+ [16] = 'PlaySound',
285
+ [17] = 'SetPlayerWorldBounds',
286
+ [18] = 'GivePlayerMoney',
287
+ [19] = 'SetPlayerFacingAngle',
288
+ [20] = 'ResetPlayerMoney',
289
+ [21] = 'ResetPlayerWeapons',
290
+ [22] = 'GivePlayerWeapon',
291
+ [24] = 'SetVehicleParamsEx',
292
+ [28] = 'CancelEdit',
293
+ [29] = 'SetPlayerTime',
294
+ [30] = 'ToggleClock',
295
+ [32] = 'WorldPlayerAdd',
296
+ [33] = 'SetPlayerShopName',
297
+ [34] = 'SetPlayerSkillLevel',
298
+ [35] = 'SetPlayerDrunkLevel',
299
+ [36] = 'Create3DTextLabel',
300
+ [37] = 'DisableCheckpoint',
301
+ [38] = 'SetRaceCheckpoint',
302
+ [39] = 'DisableRaceCheckpoint',
303
+ [40] = 'GameModeRestart',
304
+ [41] = 'PlayAudioStream',
305
+ [42] = 'StopAudioStream',
306
+ [43] = 'RemoveBuildingForPlayer',
307
+ [44] = 'CreateObject',
308
+ [45] = 'SetObjectPos',
309
+ [46] = 'SetObjectRot',
310
+ [47] = 'DestroyObject',
311
+ [55] = 'DeathMessage',
312
+ [56] = 'SetPlayerMapIcon',
313
+ [57] = 'RemoveVehicleComponent',
314
+ [58] = 'Update3DTextLabel',
315
+ [59] = 'ChatBubble',
316
+ [60] = 'UpdateSystemTime',
317
+ [61] = 'ShowDialog',
318
+ [63] = 'DestroyPickup',
319
+ [64] = 'WeaponPickupDestroy',
320
+ [65] = 'LinkVehicleToInterior',
321
+ [66] = 'SetPlayerArmour',
322
+ [67] = 'SetPlayerArmedWeapon',
323
+ [68] = 'SetSpawnInfo',
324
+ [69] = 'SetPlayerTeam',
325
+ [70] = 'PutPlayerInVehicle',
326
+ [71] = 'RemovePlayerFromVehicle',
327
+ [72] = 'SetPlayerColor',
328
+ [73] = 'DisplayGameText',
329
+ [74] = 'ForceClassSelection',
330
+ [75] = 'AttachObjectToPlayer',
331
+ [76] = 'InitMenu',
332
+ [77] = 'ShowMenu',
333
+ [78] = 'HideMenu',
334
+ [79] = 'CreateExplosion',
335
+ [80] = 'ShowPlayerNameTagForPlayer',
336
+ [81] = 'AttachCameraToObject',
337
+ [82] = 'InterpolateCamera',
338
+ [84] = 'SetObjectMaterial',
339
+ [85] = 'GangZoneStopFlash',
340
+ [86] = 'ApplyAnimation',
341
+ [87] = 'ClearAnimations',
342
+ [88] = 'SetPlayerSpecialAction',
343
+ [89] = 'SetPlayerFightingStyle',
344
+ [90] = 'SetPlayerVelocity',
345
+ [91] = 'SetVehicleVelocity',
346
+ [92] = 'SetPlayerDrunkVisuals',
347
+ [93] = 'ClientMessage',
348
+ [94] = 'SetWorldTime',
349
+ [95] = 'CreatePickup',
350
+ [98] = 'SetVehicleTireStatus',
351
+ [99] = 'MoveObject',
352
+ [104] = 'EnableStuntBonusForPlayer',
353
+ [105] = 'TextDrawSetString',
354
+ [107] = 'SetCheckpoint',
355
+ [108] = 'GangZoneCreate',
356
+ [112] = 'PlayCrimeReport',
357
+ [113] = 'SetPlayerAttachedObject',
358
+ [120] = 'GangZoneDestroy',
359
+ [121] = 'GangZoneFlash',
360
+ [122] = 'StopObject',
361
+ [123] = 'SetNumberPlate',
362
+ [124] = 'TogglePlayerSpectating',
363
+ [126] = 'PlayerSpectatePlayer',
364
+ [127] = 'PlayerSpectateVehicle',
365
+ [133] = 'SetPlayerWantedLevel',
366
+ [134] = 'ShowTextDraw',
367
+ [135] = 'TextDrawHideForPlayer',
368
+ [137] = 'ServerJoin',
369
+ [138] = 'ServerQuit',
370
+ [139] = 'InitGame',
371
+ [144] = 'RemovePlayerMapIcon',
372
+ [145] = 'SetPlayerAmmo',
373
+ [146] = 'SetPlayerGravity',
374
+ [147] = 'SetVehicleHealth',
375
+ [148] = 'AttachTrailerToVehicle',
376
+ [149] = 'DetachTrailerFromVehicle',
377
+ [150] = 'SetPlayerDrunkHandling',
378
+ [151] = 'DestroyPickups',
379
+ [152] = 'SetWeather',
380
+ [153] = 'SetPlayerSkin',
381
+ [156] = 'SetPlayerInterior',
382
+ [157] = 'SetPlayerCameraPos',
383
+ [158] = 'SetPlayerCameraLookAt',
384
+ [159] = 'SetVehiclePos',
385
+ [160] = 'SetVehicleZAngle',
386
+ [161] = 'SetVehicleParamsForPlayer',
387
+ [162] = 'SetCameraBehindPlayer',
388
+ [163] = 'WorldPlayerRemove',
389
+ [164] = 'WorldVehicleAdd',
390
+ [165] = 'WorldVehicleRemove',
391
+ [166] = 'WorldPlayerDeath'
392
+ }
393
+ return tab[id]
394
+ end
395
+
396
+ function raknetGetPacketName(id)
397
+ local tab = {
398
+ [6] = 'INTERNAL_PING',
399
+ [7] = 'PING',
400
+ [8] = 'PING_OPEN_CONNECTIONS',
401
+ [9] = 'CONNECTED_PONG',
402
+ [10] = 'REQUEST_STATIC_DATA',
403
+ [11] = 'CONNECTION_REQUEST',
404
+ [12] = 'AUTH_KEY',
405
+ [14] = 'BROADCAST_PINGS',
406
+ [15] = 'SECURED_CONNECTION_RESPONSE',
407
+ [16] = 'SECURED_CONNECTION_CONFIRMATION',
408
+ [17] = 'RPC_MAPPING',
409
+ [19] = 'SET_RANDOM_NUMBER_SEED',
410
+ [20] = 'RPC',
411
+ [21] = 'RPC_REPLY',
412
+ [23] = 'DETECT_LOST_CONNECTIONS',
413
+ [24] = 'OPEN_CONNECTION_REQUEST',
414
+ [25] = 'OPEN_CONNECTION_REPLY',
415
+ [26] = 'CONNECTION_COOKIE',
416
+ [28] = 'RSA_PUBLIC_KEY_MISMATCH',
417
+ [29] = 'CONNECTION_ATTEMPT_FAILED',
418
+ [30] = 'NEW_INCOMING_CONNECTION',
419
+ [31] = 'NO_FREE_INCOMING_CONNECTIONS',
420
+ [32] = 'DISCONNECTION_NOTIFICATION',
421
+ [33] = 'CONNECTION_LOST',
422
+ [34] = 'CONNECTION_REQUEST_ACCEPTED',
423
+ [35] = 'INITIALIZE_ENCRYPTION',
424
+ [36] = 'CONNECTION_BANNED',
425
+ [37] = 'INVALID_PASSWORD',
426
+ [38] = 'MODIFIED_PACKET',
427
+ [39] = 'PONG',
428
+ [40] = 'TIMESTAMP',
429
+ [41] = 'RECEIVED_STATIC_DATA',
430
+ [42] = 'REMOTE_DISCONNECTION_NOTIFICATION',
431
+ [43] = 'REMOTE_CONNECTION_LOST',
432
+ [44] = 'REMOTE_NEW_INCOMING_CONNECTION',
433
+ [45] = 'REMOTE_EXISTING_CONNECTION',
434
+ [46] = 'REMOTE_STATIC_DATA',
435
+ [56] = 'ADVERTISE_SYSTEM',
436
+ [200] = 'VEHICLE_SYNC',
437
+ [201] = 'RCON_COMMAND',
438
+ [202] = 'RCON_RESPONCE',
439
+ [203] = 'AIM_SYNC',
440
+ [204] = 'WEAPONS_UPDATE',
441
+ [205] = 'STATS_UPDATE',
442
+ [206] = 'BULLET_SYNC',
443
+ [207] = 'PLAYER_SYNC',
444
+ [208] = 'MARKERS_SYNC',
445
+ [209] = 'UNOCCUPIED_SYNC',
446
+ [210] = 'TRAILER_SYNC',
447
+ [211] = 'PASSENGER_SYNC',
448
+ [212] = 'SPECTATOR_SYNC'
449
+ }
450
+ return tab[id]
451
+ end
452
+
453
+ function sampGetRakclientInterface()
454
+ return shared.get_pointer(netgame.RefNetGame().m_pRakClient)
455
+ end
456
+ jit.off(sampGetRakclientInterface, true)
457
+
458
+ function sampGetRakpeer()
459
+ return shared.get_pointer(netgame.RefNetGame().m_pRakClient) - 0xDDE -- 0xDDE = sizeof(RakPeer)
460
+ end
461
+ jit.off(sampGetRakpeer, true)
462
+
463
+ function sampSendAimData(data)
464
+ local bs = raknetNewBitStream()
465
+ raknetBitStreamReadInt8(bs, PACKET_AIM_SYNC)
466
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SAimData'))
467
+ raknetSendBitStream(bs)
468
+ raknetDeleteBitStream(bs)
469
+ end
470
+
471
+ function sampSendBulletData(data)
472
+ local bs = raknetNewBitStream()
473
+ raknetBitStreamReadInt8(bs, PACKET_BULLET_SYNC)
474
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SBulletData'))
475
+ raknetSendBitStream(bs)
476
+ raknetDeleteBitStream(bs)
477
+ end
478
+
479
+ function sampSendIncarData(data)
480
+ local bs = raknetNewBitStream()
481
+ raknetBitStreamReadInt8(bs, PACKET_VEHICLE_SYNC)
482
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SIncarData'))
483
+ raknetSendBitStream(bs)
484
+ raknetDeleteBitStream(bs)
485
+ end
486
+
487
+ function sampSendOnfootData(data)
488
+ local bs = raknetNewBitStream()
489
+ raknetBitStreamReadInt8(bs, PACKET_PLAYER_SYNC)
490
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SOnfootData'))
491
+ raknetSendBitStream(bs)
492
+ raknetDeleteBitStream(bs)
493
+ end
494
+
495
+ function sampSendSpectatorData(data)
496
+ local bs = raknetNewBitStream()
497
+ raknetBitStreamReadInt8(bs, PACKET_SPECTATOR_SYNC)
498
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SSpectatorData'))
499
+ raknetSendBitStream(bs)
500
+ raknetDeleteBitStream(bs)
501
+ end
502
+
503
+ function sampSendTrailerData(data)
504
+ local bs = raknetNewBitStream()
505
+ raknetBitStreamReadInt8(bs, PACKET_TRAILER_SYNC)
506
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('STrailerData'))
507
+ raknetSendBitStream(bs)
508
+ raknetDeleteBitStream(bs)
509
+ end
510
+
511
+ function sampSendPassengerData(data)
512
+ local bs = raknetNewBitStream()
513
+ raknetBitStreamReadInt8(bs, PACKET_PASSENGER_SYNC)
514
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SPassengerData'))
515
+ raknetSendBitStream(bs)
516
+ raknetDeleteBitStream(bs)
517
+ end
518
+
519
+ function sampSendUnoccupiedData(data)
520
+ local bs = raknetNewBitStream()
521
+ raknetBitStreamReadInt8(bs, PACKET_UNOCCUPIED_SYNC)
522
+ raknetBitStreamWriteBuffer(bs, data, ffi.sizeof('SUnoccupiedData'))
523
+ raknetSendBitStream(bs)
524
+ raknetDeleteBitStream(bs)
525
+ end
526
+
527
+ function sampSendDamageVehicle(car, panel, doors, lights, tires)
528
+ local bs = raknetNewBitStream()
529
+ raknetBitStreamWriteInt16(bs, car) -- TODO: is car a handle or an id?
530
+ raknetBitStreamWriteInt32(bs, panel)
531
+ raknetBitStreamWriteInt32(bs, doors)
532
+ raknetBitStreamWriteInt8(bs, lights)
533
+ raknetBitStreamWriteInt8(bs, tires)
534
+ raknetSendRpc(RPC_DAMAGEVEHICLE, bs)
535
+ raknetDeleteBitStream(bs)
536
+ end
537
+
538
+ function sampSendScmEvent(event, id, param1, param2)
539
+ local bs = raknetNewBitStream()
540
+ raknetBitStreamWriteInt32(bs, id)
541
+ raknetBitStreamWriteInt32(bs, param1)
542
+ raknetBitStreamWriteInt32(bs, param2)
543
+ raknetBitStreamWriteInt32(bs, event)
544
+ raknetSendRpc(RPC_SCMEVENT, bs)
545
+ raknetDeleteBitStream(bs)
546
+ end
547
+
548
+ function sampSendGiveDamage(id, damage, weapon, bodypart)
549
+ local bs = raknetNewBitStream()
550
+ raknetBitStreamWriteBool(bs, false)
551
+ raknetBitStreamWriteInt16(bs, id)
552
+ raknetBitStreamWriteFloat(bs, damage)
553
+ raknetBitStreamWriteInt32(bs, weapon)
554
+ raknetBitStreamWriteInt32(bs, bodypart)
555
+ raknetSendRpc(RPC_GIVETAKEDAMAGE, bs)
556
+ raknetDeleteBitStream(bs)
557
+ end
558
+
559
+ function sampSendTakeDamage(id, damage, weapon, bodypart)
560
+ local bs = raknetNewBitStream()
561
+ raknetBitStreamWriteBool(bs, true)
562
+ raknetBitStreamWriteInt16(bs, id)
563
+ raknetBitStreamWriteFloat(bs, damage)
564
+ raknetBitStreamWriteInt32(bs, weapon)
565
+ raknetBitStreamWriteInt32(bs, bodypart)
566
+ raknetSendRpc(RPC_GIVETAKEDAMAGE, bs)
567
+ raknetDeleteBitStream(bs)
568
+ end
569
+
570
+ function sampSendRequestSpawn()
571
+ local bs = raknetNewBitStream()
572
+ raknetSendRpc(RPC_REQUESTSPAWN, bs)
573
+ raknetDeleteBitStream(bs)
574
+ end
575
+
576
+ function sampSendClickPlayer(id, source)
577
+ local bs = raknetNewBitStream()
578
+ raknetBitStreamWriteInt16(bs, id)
579
+ raknetBitStreamWriteInt8(bs, source)
580
+ raknetSendRpc(RPC_CLICKPLAYER, bs)
581
+ raknetDeleteBitStream(bs)
582
+ end
583
+
584
+ function sampSendClickTextdraw(id)
585
+ local bs = raknetNewBitStream()
586
+ raknetBitStreamWriteInt16(bs, id)
587
+ raknetSendRpc(RPC_CLICKTEXTDRAW, bs)
588
+ raknetDeleteBitStream(bs)
589
+ end
590
+
591
+ function sampSendDeathByPlayer(playerId, reason)
592
+ local bs = raknetNewBitStream()
593
+ raknetBitStreamWriteInt8(bs, reason)
594
+ raknetBitStreamWriteInt16(bs, playerId)
595
+ raknetSendRpc(RPC_DEATH, bs)
596
+ raknetDeleteBitStream(bs)
597
+ end
598
+
599
+ function sampSendDialogResponse(id, button, listitem, input)
600
+ local bs = raknetNewBitStream()
601
+ raknetBitStreamWriteInt16(bs, id)
602
+ raknetBitStreamWriteInt8(bs, button)
603
+ raknetBitStreamWriteInt16(bs, listitem)
604
+ raknetBitStreamWriteInt8(bs, #input)
605
+ raknetBitStreamWriteString(bs, input)
606
+ raknetSendRpc(RPC_DIALOGRESPONSE, bs)
607
+ raknetDeleteBitStream(bs)
608
+ end
609
+
610
+ function sampSendEditAttachedObject(response, index, model, bone, offsetX, offsetY, offsetZ, rotX, rotY, rotZ, scaleX, scaleY, scaleZ)
611
+ local bs = raknetNewBitStream()
612
+ raknetBitStreamWriteInt32(bs, response)
613
+ raknetBitStreamWriteInt32(bs, index)
614
+ raknetBitStreamWriteInt32(bs, model)
615
+ raknetBitStreamWriteInt32(bs, bone)
616
+ raknetBitStreamWriteFloat(bs, offsetX)
617
+ raknetBitStreamWriteFloat(bs, offsetY)
618
+ raknetBitStreamWriteFloat(bs, offsetZ)
619
+ raknetBitStreamWriteFloat(bs, rotX)
620
+ raknetBitStreamWriteFloat(bs, rotY)
621
+ raknetBitStreamWriteFloat(bs, rotZ)
622
+ raknetBitStreamWriteFloat(bs, scaleX)
623
+ raknetBitStreamWriteFloat(bs, scaleY)
624
+ raknetBitStreamWriteFloat(bs, scaleZ)
625
+ -- TODO: color1/color2?
626
+ raknetSendRpc(RPC_EDITATTACHEDOBJECT, bs)
627
+ raknetDeleteBitStream(bs)
628
+ end
629
+
630
+ function sampSendEditObject(playerObject, objectId, response, posX, posY, posZ, rotX, rotY, rotZ)
631
+ local bs = raknetNewBitStream()
632
+ raknetBitStreamWriteBool(bs, playerObject)
633
+ raknetBitStreamWriteInt16(bs, objectId)
634
+ raknetBitStreamWriteInt32(bs, response)
635
+ raknetBitStreamWriteFloat(bs, posX)
636
+ raknetBitStreamWriteFloat(bs, posY)
637
+ raknetBitStreamWriteFloat(bs, posZ)
638
+ raknetBitStreamWriteFloat(bs, rotX)
639
+ raknetBitStreamWriteFloat(bs, rotY)
640
+ raknetBitStreamWriteFloat(bs, rotZ)
641
+ raknetSendRpc(RPC_EDITOBJECT, bs)
642
+ raknetDeleteBitStream(bs)
643
+ end
644
+
645
+ function sampSendMenuQuit()
646
+ local bs = raknetNewBitStream()
647
+ raknetSendRpc(RPC_MENUQUIT, bs)
648
+ raknetDeleteBitStream(bs)
649
+ end
650
+
651
+ function sampSendMenuSelectRow(id)
652
+ local bs = raknetNewBitStream()
653
+ raknetBitStreamWriteInt8(bs, id)
654
+ raknetSendRpc(RPC_MENUSELECT, bs)
655
+ raknetDeleteBitStream(bs)
656
+ end
657
+
658
+ function sampSendPickedUpPickup(id)
659
+ local bs = raknetNewBitStream()
660
+ raknetBitStreamWriteInt32(bs, id)
661
+ raknetSendRpc(RPC_PICKEDUPPICKUP, bs)
662
+ raknetDeleteBitStream(bs)
663
+ end
664
+
665
+ function sampSendRconCommand(cmd)
666
+ local bs = raknetNewBitStream()
667
+ raknetBitStreamWriteInt8(bs, PACKET_RCON_COMMAND)
668
+ raknetBitStreamWriteInt32(bs, #cmd)
669
+ raknetBitStreamWriteString(bs, cmd)
670
+ raknetSendBitStream(bs)
671
+ raknetDeleteBitStream(bs)
672
+ end
673
+
674
+ function sampSendVehicleDestroyed(id)
675
+ local bs = raknetNewBitStream()
676
+ raknetBitStreamWriteInt16(bs, id)
677
+ raknetSendRpc(RPC_VEHICLEDESTROYED, bs)
678
+ raknetDeleteBitStream(bs)
679
+ end
680
+
681
+ function sampDisconnectWithReason(reason)
682
+ local ref = netgame.RefNetGame()
683
+ local rakclient = ffi.cast('void***', ref.m_pRakClient)
684
+ local vtbl = rakclient[0]
685
+
686
+ -- Disconnect(unsigned int blockDuration, unsigned char orderingChannel = 0)
687
+ local Disconnect = ffi.cast('void(__thiscall *)(void *, unsigned int, unsigned char)', vtbl[2])
688
+ Disconnect(rakclient, reason, 0)
689
+
690
+ ref:ShutdownForRestart()
691
+ end
692
+ jit.off(sampDisconnectWithReason, true)
693
+
694
+ function sampConnectToServer(ip, port)
695
+ local ref = netgame.RefNetGame()
696
+ ffi.copy(ref.m_szHostAddress, ip)
697
+ ref.m_nPort = port
698
+ sampSetGamestate(GAMESTATE_WAIT_CONNECT)
699
+ end
700
+ jit.off(sampConnectToServer, true)
scoreboard.lua ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local scoreboard = sampapi.require('CScoreboard', true)
12
+
13
+ function sampToggleScoreboard(show)
14
+ if show then
15
+ scoreboard.RefScoreboard():Enable()
16
+ else
17
+ scoreboard.RefScoreboard():Close(true)
18
+ end
19
+ end
20
+ jit.off(sampToggleScoreboard, true)
21
+
22
+ function sampIsScoreboardOpen()
23
+ return scoreboard.RefScoreboard().m_bIsEnabled == 1
24
+ end
25
+ jit.off(sampIsScoreboardOpen, true)
stringcompressor.lua ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ local sampapi = require 'sampapi'
2
+ --[[
3
+ Project: SF.lua <https://github.com/imring/SF.lua>
4
+ License: MIT License
5
+ Author: imring
6
+ ]]
7
+
8
+ local shared = require 'sampapi.shared'
9
+ local mt = require 'sampapi.metatype'
10
+ local ffi = shared.ffi
11
+
12
+ ffi.cdef[[
13
+ typedef struct StringCompressor StringCompressor;
14
+ ]]
15
+
16
+ local Instance_addr = {
17
+ [ffi.C.SAMP_VERSION_037R1] = 0x50140,
18
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x534F0,
19
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x53C30
20
+ }
21
+
22
+ local StringCompressor_DecodeString_addr = {
23
+ [ffi.C.SAMP_VERSION_037R1] = 0x507E0,
24
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x53B90,
25
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x542D0
26
+ }
27
+
28
+ local StringCompressor_EncodeString_addr = {
29
+ [ffi.C.SAMP_VERSION_037R1] = 0x506B0,
30
+ [ffi.C.SAMP_VERSION_037R3_1] = 0x53A60,
31
+ [ffi.C.SAMP_VERSION_037R5_1] = 0x541A0
32
+ }
33
+
34
+ local Instance = ffi.cast('StringCompressor*(__cdecl*)()', sampapi.GetAddress(Instance_addr[sampapi.GetSAMPVersion()]))
35
+
36
+ local StringCompressor_mt = {
37
+ DecodeString = ffi.cast('bool(__thiscall*)(StringCompressor *, char *, int, SBitStream *, int)', sampapi.GetAddress(StringCompressor_DecodeString_addr[sampapi.GetSAMPVersion()])),
38
+ EncodeString = ffi.cast('void(__thiscall*)(StringCompressor *, const char *, int, SBitStream *, int)', sampapi.GetAddress(StringCompressor_EncodeString_addr[sampapi.GetSAMPVersion()])),
39
+ }
40
+ mt.set_handler('StringCompressor', '__index', StringCompressor_mt)
41
+
42
+ return {
43
+ Instance = Instance
44
+ }
textdraw.lua ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local color = require 'sflua.color'
12
+ local netgame = sampapi.require('CNetGame', true)
13
+ sampapi.require('CTextDrawPool', true)
14
+
15
+ local function textdrawpool()
16
+ return netgame.RefNetGame().m_pPools.m_pTextDraw
17
+ end
18
+
19
+ function sampGetTextdrawPoolPtr()
20
+ return shared.get_pointer(textdrawpool())
21
+ end
22
+ jit.off(sampGetTextdrawPoolPtr, true)
23
+
24
+ function sampTextdrawIsExists(id)
25
+ return textdrawpool().m_bNotEmpty[id] == 1
26
+ end
27
+ jit.off(sampTextdrawIsExists, true)
28
+
29
+ function sampTextdrawCreate(id, text, posX, posY)
30
+ local transmit = ffi.new('STransmit[1]', { { m_fX = posX, m_fY = posY } })
31
+ textdrawpool():Create(id, transmit, text)
32
+ end
33
+ jit.off(sampTextdrawCreate, true)
34
+
35
+ function sampTextdrawSetBoxColorAndSize(id, box, color, sizeX, sizeY)
36
+ if sampTextdrawIsExists(id) then
37
+ local obj = textdrawpool().m_pObject[id]
38
+ obj.m_data.m_bBox = box
39
+ obj.m_data.m_boxColor = color
40
+ obj.m_data.m_fBoxSizeX = sizeX
41
+ obj.m_data.m_fBoxSizeY = sizeY
42
+ end
43
+ end
44
+ jit.off(sampTextdrawSetBoxColorAndSize, true)
45
+
46
+ function sampTextdrawGetString(id)
47
+ if sampTextdrawIsExists(id) then
48
+ local obj = textdrawpool().m_pObject[id]
49
+ return ffi.string(obj.m_szString)
50
+ end
51
+ end
52
+ jit.off(sampTextdrawGetString, true)
53
+
54
+ function sampTextdrawDelete(id)
55
+ textdrawpool():Delete(id)
56
+ end
57
+ jit.off(sampTextdrawDelete, true)
58
+
59
+ function sampTextdrawGetLetterSizeAndColor(id)
60
+ if sampTextdrawIsExists(id) then
61
+ local obj = textdrawpool().m_pObject[id]
62
+ return obj.m_data.m_fLetterWidth, obj.m_data.m_fLetterHeight, color.abgr_to_argb(obj.m_data.m_letterColor)
63
+ end
64
+ end
65
+ jit.off(sampTextdrawGetLetterSizeAndColor, true)
66
+
67
+ function sampTextdrawGetPos(id)
68
+ if sampTextdrawIsExists(id) then
69
+ local obj = textdrawpool().m_pObject[id]
70
+ return obj.m_data.m_fX, obj.m_data.m_fY
71
+ end
72
+ end
73
+ jit.off(sampTextdrawGetPos, true)
74
+
75
+ function sampTextdrawGetShadowColor(id)
76
+ if sampTextdrawIsExists(id) then
77
+ local obj = textdrawpool().m_pObject[id]
78
+ return obj.m_data.m_nShadow, obj.m_data.m_backgroundColor
79
+ end
80
+ end
81
+ jit.off(sampTextdrawGetShadowColor, true)
82
+
83
+ function sampTextdrawGetOutlineColor(id)
84
+ if sampTextdrawIsExists(id) then
85
+ local obj = textdrawpool().m_pObject[id]
86
+ return obj.m_data.m_nOutline, obj.m_data.m_backgroundColor
87
+ end
88
+ end
89
+ jit.off(sampTextdrawGetOutlineColor, true)
90
+
91
+ function sampTextdrawGetStyle(id)
92
+ if sampTextdrawIsExists(id) then
93
+ local obj = textdrawpool().m_pObject[id]
94
+ return obj.m_data.m_nStyle
95
+ end
96
+ end
97
+ jit.off(sampTextdrawGetStyle, true)
98
+
99
+ function sampTextdrawGetProportional(id)
100
+ if sampTextdrawIsExists(id) then
101
+ local obj = textdrawpool().m_pObject[id]
102
+ return obj.m_data.m_nProportional
103
+ end
104
+ end
105
+ jit.off(sampTextdrawGetProportional, true)
106
+
107
+ function sampTextdrawGetAlign(id)
108
+ if sampTextdrawIsExists(id) then
109
+ local obj = textdrawpool().m_pObject[id]
110
+ if obj.m_data.m_bLeft == 1 then
111
+ return 1
112
+ elseif obj.m_data.m_bCenter == 1 then
113
+ return 2
114
+ elseif obj.m_data.m_bRight == 1 then
115
+ return 3
116
+ else
117
+ return 0
118
+ end
119
+ end
120
+ end
121
+ jit.off(sampTextdrawGetAlign, true)
122
+
123
+ function sampTextdrawGetBoxEnabledColorAndSize(id)
124
+ if sampTextdrawIsExists(id) then
125
+ local obj = textdrawpool().m_pObject[id]
126
+ return obj.m_data.m_bBox, color.abgr_to_argb(obj.m_data.m_boxColor),
127
+ obj.m_data.m_fBoxSizeX, obj.m_data.m_fBoxSizeY
128
+ end
129
+ end
130
+ jit.off(sampTextdrawGetBoxEnabledColorAndSize, true)
131
+
132
+ function sampTextdrawGetModelRotationZoomVehColor(id)
133
+ if sampTextdrawIsExists(id) then
134
+ local obj = textdrawpool().m_pObject[id]
135
+ return obj.m_data.m_nModel,
136
+ obj.m_data.m_rotation.x, obj.m_data.m_rotation.y, obj.m_data.m_rotation.z,
137
+ obj.m_data.m_fZoom, obj.m_data.m_aColor[1], obj.m_data.m_aColor[2]
138
+ end
139
+ end
140
+ jit.off(sampTextdrawGetModelRotationZoomVehColor, true)
141
+
142
+ function sampTextdrawSetLetterSizeAndColor(id, letSizeX, letSizeY, color)
143
+ if sampTextdrawIsExists(id) then
144
+ local obj = textdrawpool().m_pObject[id]
145
+ obj.m_data.m_fLetterWidth = letSizeX
146
+ obj.m_data.m_fLetterHeight = letSizeY
147
+ obj.m_data.m_letterColor = color
148
+ end
149
+ end
150
+ jit.off(sampTextdrawSetLetterSizeAndColor, true)
151
+
152
+ function sampTextdrawSetPos(id, posX, posY)
153
+ if sampTextdrawIsExists(id) then
154
+ local obj = textdrawpool().m_pObject[id]
155
+ obj.m_data.m_fX = posX
156
+ obj.m_data.m_fY = posY
157
+ end
158
+ end
159
+ jit.off(sampTextdrawSetPos, true)
160
+
161
+ function sampTextdrawSetString(id, str)
162
+ if sampTextdrawIsExists(id) then
163
+ local obj = textdrawpool().m_pObject[id]
164
+ obj.m_szString = str
165
+ end
166
+ end
167
+ jit.off(sampTextdrawSetString, true)
168
+
169
+ function sampTextdrawSetModelRotationZoomVehColor(id, model, rotX, rotY, rotZ, zoom, clr1, clr2)
170
+ if sampTextdrawIsExists(id) then
171
+ local obj = textdrawpool().m_pObject[id]
172
+ obj.m_data.m_nModel = model
173
+ obj.m_data.m_rotation = { x = rotX, y = rotY, z = rotZ }
174
+ obj.m_data.m_fZoom = zoom
175
+ obj.m_data.sColor = { clr1, clr2 }
176
+ end
177
+ end
178
+ jit.off(sampTextdrawSetModelRotationZoomVehColor, true)
179
+
180
+ function sampTextdrawSetOutlineColor(id, outline, color)
181
+ if sampTextdrawIsExists(id) then
182
+ local obj = textdrawpool().m_pObject[id]
183
+ obj.m_data.m_nOutline = outline
184
+ obj.m_data.m_backgroundColor = color
185
+ end
186
+ end
187
+ jit.off(sampTextdrawSetOutlineColor, true)
188
+
189
+ function sampTextdrawSetShadow(id, shadow, color)
190
+ if sampTextdrawIsExists(id) then
191
+ local obj = textdrawpool().m_pObject[id]
192
+ obj.m_data.m_nShadow = shadow
193
+ obj.m_data.m_backgroundColor = color
194
+ end
195
+ end
196
+ jit.off(sampTextdrawSetShadow, true)
197
+
198
+ function sampTextdrawSetStyle(id, style)
199
+ if sampTextdrawIsExists(id) then
200
+ local obj = textdrawpool().m_pObject[id]
201
+ obj.m_data.m_nStyle = style
202
+ end
203
+ end
204
+ jit.off(sampTextdrawSetStyle, true)
205
+
206
+ function sampTextdrawSetProportional(id, proportional)
207
+ if sampTextdrawIsExists(id) then
208
+ local obj = textdrawpool().m_pObject[id]
209
+ obj.m_data.m_nProportional = proportional
210
+ end
211
+ end
212
+ jit.off(sampTextdrawSetProportional, true)
213
+
214
+ function sampTextdrawSetAlign(id, align)
215
+ if sampTextdrawIsExists(id) then
216
+ local obj = textdrawpool().m_pObject[id]
217
+ obj.m_data.m_bLeft = 0
218
+ obj.m_data.m_bCenter = 0
219
+ obj.m_data.m_bRight = 0
220
+ if align == 1 then
221
+ obj.m_data.m_bLeft = 1
222
+ elseif align == 2 then
223
+ obj.m_data.m_bCenter = 1
224
+ elseif align == 3 then
225
+ obj.m_data.m_bRight = 1
226
+ end
227
+ end
228
+ end
229
+ jit.off(sampTextdrawSetAlign, true)
vehicle.lua ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --[[
2
+ Project: SF.lua <https://github.com/imring/SF.lua>
3
+ License: MIT License
4
+ Author: imring
5
+ ]]
6
+
7
+ local sampapi = require 'sampapi'
8
+ local shared = require 'sampapi.shared'
9
+ local ffi = shared.ffi
10
+
11
+ local netgame = sampapi.require('CNetGame', true)
12
+ sampapi.require('CVehiclePool', true)
13
+
14
+ local function vehiclepool()
15
+ return netgame.RefNetGame().m_pPools.m_pVehicle
16
+ end
17
+
18
+ function sampGetVehiclePoolPtr()
19
+ return shared.get_pointer(vehiclepool())
20
+ end
21
+ jit.off(sampGetVehiclePoolPtr, true)
22
+
23
+ function sampGetCarHandleBySampVehicleId(id)
24
+ if sampIsVehicleDefined(id) then
25
+ return true, getVehiclePointerHandle(shared.get_pointer(vehiclepool().m_pGameObject[id]))
26
+ end
27
+ return false, -1
28
+ end
29
+ jit.off(sampGetCarHandleBySampVehicleId, true)
30
+
31
+ function sampGetVehicleIdByCarHandle(car)
32
+ for i = 0, ffi.C.MAX_VEHICLES - 1 do
33
+ local res, handle = sampGetCarHandleBySampVehicleId(i)
34
+ if res and handle == car then
35
+ return true, i
36
+ end
37
+ end
38
+ end
39
+
40
+ -- New functions
41
+
42
+ function sampIsVehicleDefined(id)
43
+ return vehiclepool().m_bNotEmpty[id] == 1 and vehiclepool().m_pObject[id] ~= nil and vehiclepool().m_pGameObject[id] ~= nil
44
+ end
45
+ jit.off(sampIsVehicleDefined, true)