Upload 8 files
Browse files- bitstream_io.lua +267 -0
- core.lua +141 -0
- events.lua +293 -0
- extra_types.lua +45 -0
- handlers.lua +526 -0
- raknet.lua +236 -700
- synchronization.lua +199 -0
- utils.lua +45 -0
bitstream_io.lua
ADDED
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local mod = {}
|
7 |
+
local vector3d = require 'vector3d'
|
8 |
+
local ffi = require 'ffi'
|
9 |
+
|
10 |
+
local function bitstream_read_fixed_string(bs, size)
|
11 |
+
local buf = ffi.new('uint8_t[?]', size + 1)
|
12 |
+
raknetBitStreamReadBuffer(bs, tonumber(ffi.cast('intptr_t', buf)), size)
|
13 |
+
buf[size] = 0
|
14 |
+
-- Length is not specified to throw off trailing zeros.
|
15 |
+
return ffi.string(buf)
|
16 |
+
end
|
17 |
+
|
18 |
+
local function bitstream_write_fixed_string(bs, str, size)
|
19 |
+
local buf = ffi.new('uint8_t[?]', size, string.sub(str, 1, size))
|
20 |
+
raknetBitStreamWriteBuffer(bs, tonumber(ffi.cast('intptr_t', buf)), size)
|
21 |
+
end
|
22 |
+
|
23 |
+
mod.bool = {
|
24 |
+
read = function(bs) return raknetBitStreamReadBool(bs) end,
|
25 |
+
write = function(bs, value) return raknetBitStreamWriteBool(bs, value) end
|
26 |
+
}
|
27 |
+
|
28 |
+
mod.uint8 = {
|
29 |
+
read = function(bs) return raknetBitStreamReadInt8(bs) end,
|
30 |
+
write = function(bs, value) return raknetBitStreamWriteInt8(bs, value) end
|
31 |
+
}
|
32 |
+
|
33 |
+
mod.uint16 = {
|
34 |
+
read = function(bs) return raknetBitStreamReadInt16(bs) end,
|
35 |
+
write = function(bs, value) return raknetBitStreamWriteInt16(bs, value) end
|
36 |
+
}
|
37 |
+
|
38 |
+
mod.uint32 = {
|
39 |
+
read = function(bs)
|
40 |
+
local v = raknetBitStreamReadInt32(bs)
|
41 |
+
return v < 0 and 0x100000000 + v or v
|
42 |
+
end,
|
43 |
+
write = function(bs, value)
|
44 |
+
return raknetBitStreamWriteInt32(bs, value)
|
45 |
+
end
|
46 |
+
}
|
47 |
+
|
48 |
+
mod.int8 = {
|
49 |
+
read = function(bs)
|
50 |
+
local v = raknetBitStreamReadInt8(bs)
|
51 |
+
return v >= 0x80 and v - 0x100 or v
|
52 |
+
end,
|
53 |
+
write = function(bs, value)
|
54 |
+
return raknetBitStreamWriteInt8(bs, value)
|
55 |
+
end
|
56 |
+
}
|
57 |
+
|
58 |
+
mod.int16 = {
|
59 |
+
read = function(bs)
|
60 |
+
local v = raknetBitStreamReadInt16(bs)
|
61 |
+
return v >= 0x8000 and v - 0x10000 or v
|
62 |
+
end,
|
63 |
+
write = function(bs, value)
|
64 |
+
return raknetBitStreamWriteInt16(bs, value)
|
65 |
+
end
|
66 |
+
}
|
67 |
+
|
68 |
+
mod.int32 = {
|
69 |
+
read = function(bs) return raknetBitStreamReadInt32(bs) end,
|
70 |
+
write = function(bs, value) return raknetBitStreamWriteInt32(bs, value) end
|
71 |
+
}
|
72 |
+
|
73 |
+
mod.float = {
|
74 |
+
read = function(bs) return raknetBitStreamReadFloat(bs) end,
|
75 |
+
write = function(bs, value) return raknetBitStreamWriteFloat(bs, value) end
|
76 |
+
}
|
77 |
+
|
78 |
+
mod.string8 = {
|
79 |
+
read = function(bs)
|
80 |
+
local len = raknetBitStreamReadInt8(bs)
|
81 |
+
if len <= 0 then return '' end
|
82 |
+
return raknetBitStreamReadString(bs, len)
|
83 |
+
end,
|
84 |
+
write = function(bs, value)
|
85 |
+
raknetBitStreamWriteInt8(bs, #value)
|
86 |
+
raknetBitStreamWriteString(bs, value)
|
87 |
+
end
|
88 |
+
}
|
89 |
+
|
90 |
+
mod.string16 = {
|
91 |
+
read = function(bs)
|
92 |
+
local len = raknetBitStreamReadInt16(bs)
|
93 |
+
if len <= 0 then return '' end
|
94 |
+
return raknetBitStreamReadString(bs, len)
|
95 |
+
end,
|
96 |
+
write = function(bs, value)
|
97 |
+
raknetBitStreamWriteInt16(bs, #value)
|
98 |
+
raknetBitStreamWriteString(bs, value)
|
99 |
+
end
|
100 |
+
}
|
101 |
+
|
102 |
+
mod.string32 = {
|
103 |
+
read = function(bs)
|
104 |
+
local len = raknetBitStreamReadInt32(bs)
|
105 |
+
if len <= 0 then return '' end
|
106 |
+
return raknetBitStreamReadString(bs, len)
|
107 |
+
end,
|
108 |
+
write = function(bs, value)
|
109 |
+
raknetBitStreamWriteInt32(bs, #value)
|
110 |
+
raknetBitStreamWriteString(bs, value)
|
111 |
+
end
|
112 |
+
}
|
113 |
+
|
114 |
+
mod.bool8 = {
|
115 |
+
read = function(bs)
|
116 |
+
return raknetBitStreamReadInt8(bs) ~= 0
|
117 |
+
end,
|
118 |
+
write = function(bs, value)
|
119 |
+
raknetBitStreamWriteInt8(bs, value == true and 1 or 0)
|
120 |
+
end
|
121 |
+
}
|
122 |
+
|
123 |
+
mod.bool32 = {
|
124 |
+
read = function(bs)
|
125 |
+
return raknetBitStreamReadInt32(bs) ~= 0
|
126 |
+
end,
|
127 |
+
write = function(bs, value)
|
128 |
+
raknetBitStreamWriteInt32(bs, value == true and 1 or 0)
|
129 |
+
end
|
130 |
+
}
|
131 |
+
|
132 |
+
mod.int1 = {
|
133 |
+
read = function(bs)
|
134 |
+
if raknetBitStreamReadBool(bs) == true then return 1 else return 0 end
|
135 |
+
end,
|
136 |
+
write = function(bs, value)
|
137 |
+
raknetBitStreamWriteBool(bs, value ~= 0 and true or false)
|
138 |
+
end
|
139 |
+
}
|
140 |
+
|
141 |
+
mod.fixedString32 = {
|
142 |
+
read = function(bs)
|
143 |
+
return bitstream_read_fixed_string(bs, 32)
|
144 |
+
end,
|
145 |
+
write = function(bs, value)
|
146 |
+
bitstream_write_fixed_string(bs, value, 32)
|
147 |
+
end
|
148 |
+
}
|
149 |
+
|
150 |
+
mod.string256 = mod.fixedString32
|
151 |
+
|
152 |
+
mod.encodedString2048 = {
|
153 |
+
read = function(bs) return raknetBitStreamDecodeString(bs, 2048) end,
|
154 |
+
write = function(bs, value) raknetBitStreamEncodeString(bs, value) end
|
155 |
+
}
|
156 |
+
|
157 |
+
mod.encodedString4096 = {
|
158 |
+
read = function(bs) return raknetBitStreamDecodeString(bs, 4096) end,
|
159 |
+
write = function(bs, value) raknetBitStreamEncodeString(bs, value) end
|
160 |
+
}
|
161 |
+
|
162 |
+
mod.compressedFloat = {
|
163 |
+
read = function(bs)
|
164 |
+
return raknetBitStreamReadInt16(bs) / 32767.5 - 1
|
165 |
+
end,
|
166 |
+
write = function(bs, value)
|
167 |
+
if value < -1 then
|
168 |
+
value = -1
|
169 |
+
elseif value > 1 then
|
170 |
+
value = 1
|
171 |
+
end
|
172 |
+
raknetBitStreamWriteInt16(bs, (value + 1) * 32767.5)
|
173 |
+
end
|
174 |
+
}
|
175 |
+
|
176 |
+
mod.compressedVector = {
|
177 |
+
read = function(bs)
|
178 |
+
local magnitude = raknetBitStreamReadFloat(bs)
|
179 |
+
if magnitude ~= 0 then
|
180 |
+
local readCf = mod.compressedFloat.read
|
181 |
+
return vector3d(readCf(bs) * magnitude, readCf(bs) * magnitude, readCf(bs) * magnitude)
|
182 |
+
else
|
183 |
+
return vector3d(0, 0, 0)
|
184 |
+
end
|
185 |
+
end,
|
186 |
+
write = function(bs, data)
|
187 |
+
local x, y, z = data.x, data.y, data.z
|
188 |
+
local magnitude = math.sqrt(x * x + y * y + z * z)
|
189 |
+
raknetBitStreamWriteFloat(bs, magnitude)
|
190 |
+
if magnitude > 0 then
|
191 |
+
local writeCf = mod.compressedFloat.write
|
192 |
+
writeCf(bs, x / magnitude)
|
193 |
+
writeCf(bs, y / magnitude)
|
194 |
+
writeCf(bs, z / magnitude)
|
195 |
+
end
|
196 |
+
end
|
197 |
+
}
|
198 |
+
|
199 |
+
mod.normQuat = {
|
200 |
+
read = function(bs)
|
201 |
+
local readBool, readShort = raknetBitStreamReadBool, raknetBitStreamReadInt16
|
202 |
+
local cwNeg, cxNeg, cyNeg, czNeg = readBool(bs), readBool(bs), readBool(bs), readBool(bs)
|
203 |
+
local cx, cy, cz = readShort(bs), readShort(bs), readShort(bs)
|
204 |
+
local x = cx / 65535
|
205 |
+
local y = cy / 65535
|
206 |
+
local z = cz / 65535
|
207 |
+
if cxNeg then x = -x end
|
208 |
+
if cyNeg then y = -y end
|
209 |
+
if czNeg then z = -z end
|
210 |
+
local diff = 1 - x * x - y * y - z * z
|
211 |
+
if diff < 0 then diff = 0 end
|
212 |
+
local w = math.sqrt(diff)
|
213 |
+
if cwNeg then w = -w end
|
214 |
+
return {w, x, y, z}
|
215 |
+
end,
|
216 |
+
write = function(bs, value)
|
217 |
+
local w, x, y, z = value[1], value[2], value[3], value[4]
|
218 |
+
raknetBitStreamWriteBool(bs, w < 0)
|
219 |
+
raknetBitStreamWriteBool(bs, x < 0)
|
220 |
+
raknetBitStreamWriteBool(bs, y < 0)
|
221 |
+
raknetBitStreamWriteBool(bs, z < 0)
|
222 |
+
raknetBitStreamWriteInt16(bs, math.abs(x) * 65535)
|
223 |
+
raknetBitStreamWriteInt16(bs, math.abs(y) * 65535)
|
224 |
+
raknetBitStreamWriteInt16(bs, math.abs(z) * 65535)
|
225 |
+
-- w is calculated on the target
|
226 |
+
end
|
227 |
+
}
|
228 |
+
|
229 |
+
mod.vector3d = {
|
230 |
+
read = function(bs)
|
231 |
+
local x, y, z =
|
232 |
+
raknetBitStreamReadFloat(bs),
|
233 |
+
raknetBitStreamReadFloat(bs),
|
234 |
+
raknetBitStreamReadFloat(bs)
|
235 |
+
return vector3d(x, y, z)
|
236 |
+
end,
|
237 |
+
write = function(bs, value)
|
238 |
+
raknetBitStreamWriteFloat(bs, value.x)
|
239 |
+
raknetBitStreamWriteFloat(bs, value.y)
|
240 |
+
raknetBitStreamWriteFloat(bs, value.z)
|
241 |
+
end
|
242 |
+
}
|
243 |
+
|
244 |
+
mod.vector2d = {
|
245 |
+
read = function(bs)
|
246 |
+
local x = raknetBitStreamReadFloat(bs)
|
247 |
+
local y = raknetBitStreamReadFloat(bs)
|
248 |
+
return {x = x, y = y}
|
249 |
+
end,
|
250 |
+
write = function(bs, value)
|
251 |
+
raknetBitStreamWriteFloat(bs, value.x)
|
252 |
+
raknetBitStreamWriteFloat(bs, value.y)
|
253 |
+
end
|
254 |
+
}
|
255 |
+
|
256 |
+
local function bitstream_io_interface(field)
|
257 |
+
return setmetatable({}, {
|
258 |
+
__index = function(t, index)
|
259 |
+
return mod[index][field]
|
260 |
+
end
|
261 |
+
})
|
262 |
+
end
|
263 |
+
|
264 |
+
mod.bs_read = bitstream_io_interface('read')
|
265 |
+
mod.bs_write = bitstream_io_interface('write')
|
266 |
+
|
267 |
+
return mod
|
core.lua
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local MODULE = {
|
7 |
+
MODULEINFO = {
|
8 |
+
name = 'samp.events',
|
9 |
+
version = 4
|
10 |
+
},
|
11 |
+
INTERFACE = {
|
12 |
+
OUTCOMING_RPCS = {},
|
13 |
+
OUTCOMING_PACKETS = {},
|
14 |
+
INCOMING_RPCS = {},
|
15 |
+
INCOMING_PACKETS = {}
|
16 |
+
},
|
17 |
+
EXPORTS = {}
|
18 |
+
}
|
19 |
+
|
20 |
+
-- check dependencies
|
21 |
+
assert(isSampLoaded(), 'SA-MP is not loaded')
|
22 |
+
assert(isSampfuncsLoaded(), 'samp.events requires SAMPFUNCS')
|
23 |
+
assert(getMoonloaderVersion() >= 20, 'samp.events requires MoonLoader v.020 or greater')
|
24 |
+
|
25 |
+
local BitStreamIO = require 'samp.events.bitstream_io'
|
26 |
+
MODULE.INTERFACE.BitStreamIO = BitStreamIO
|
27 |
+
|
28 |
+
|
29 |
+
local function read_data(bs, dataType)
|
30 |
+
if type(dataType) ~= 'table' then
|
31 |
+
return BitStreamIO[dataType].read(bs)
|
32 |
+
else -- process nested structures
|
33 |
+
local values = {}
|
34 |
+
for _, it in ipairs(dataType) do
|
35 |
+
local name, t = next(it)
|
36 |
+
values[name] = read_data(bs, t)
|
37 |
+
end
|
38 |
+
return values
|
39 |
+
end
|
40 |
+
end
|
41 |
+
|
42 |
+
local function write_data(bs, dataType, value)
|
43 |
+
if type(dataType) ~= 'table' then
|
44 |
+
BitStreamIO[dataType].write(bs, value)
|
45 |
+
else -- process nested structures
|
46 |
+
for _, it in ipairs(dataType) do
|
47 |
+
local name, t = next(it)
|
48 |
+
write_data(bs, t, value[name])
|
49 |
+
end
|
50 |
+
end
|
51 |
+
end
|
52 |
+
|
53 |
+
local function process_event(bs, callback, struct, ignorebits)
|
54 |
+
local args = {}
|
55 |
+
if bs ~= 0 then
|
56 |
+
if ignorebits then
|
57 |
+
raknetBitStreamIgnoreBits(bs, ignorebits)
|
58 |
+
end
|
59 |
+
if type(struct[2]) == 'function' then
|
60 |
+
local r1, r2 = struct[2](bs) -- call custom reading function
|
61 |
+
if type(callback) == 'table' and type(r1) == 'string' then
|
62 |
+
callback = callback[r1]
|
63 |
+
if callback then
|
64 |
+
args = r2
|
65 |
+
else
|
66 |
+
return
|
67 |
+
end
|
68 |
+
else
|
69 |
+
args = r1
|
70 |
+
end
|
71 |
+
else
|
72 |
+
-- skip event name
|
73 |
+
for i = 2, #struct do
|
74 |
+
local _, t = next(struct[i]) -- type
|
75 |
+
table.insert(args, read_data(bs, t))
|
76 |
+
end
|
77 |
+
end
|
78 |
+
end
|
79 |
+
local result = callback(unpack(args))
|
80 |
+
if result == false then
|
81 |
+
return false -- consume packet
|
82 |
+
end
|
83 |
+
if bs ~= 0 and type(result) == 'table' then
|
84 |
+
raknetBitStreamSetWriteOffset(bs, ignorebits or 0)
|
85 |
+
if type(struct[3]) == 'function' then
|
86 |
+
struct[3](bs, result) -- call custom writing function
|
87 |
+
else
|
88 |
+
assert(#struct - 1 == #result)
|
89 |
+
for i = 2, #struct do
|
90 |
+
local _, t = next(struct[i]) -- type
|
91 |
+
write_data(bs, t, result[i - 1])
|
92 |
+
end
|
93 |
+
end
|
94 |
+
end
|
95 |
+
end
|
96 |
+
|
97 |
+
local function process_packet(id, bs, event_table, ignorebits)
|
98 |
+
local entry = event_table[id]
|
99 |
+
if entry ~= nil then
|
100 |
+
local key = entry[1]
|
101 |
+
local callback = nil
|
102 |
+
if type(key) == 'table' then
|
103 |
+
for i, name in ipairs(key) do
|
104 |
+
if type(MODULE[name]) == 'function' then
|
105 |
+
if not callback then callback = {} end
|
106 |
+
callback[name] = MODULE[name]
|
107 |
+
end
|
108 |
+
end
|
109 |
+
elseif type(MODULE[key]) == 'function' then
|
110 |
+
callback = MODULE[key]
|
111 |
+
end
|
112 |
+
if callback then
|
113 |
+
return process_event(bs, callback, entry, ignorebits)
|
114 |
+
end
|
115 |
+
end
|
116 |
+
end
|
117 |
+
|
118 |
+
|
119 |
+
local interface = MODULE.INTERFACE
|
120 |
+
local function samp_on_send_rpc(id, bitStream, priority, reliability, orderingChannel, shiftTs)
|
121 |
+
return process_packet(id, bitStream, interface.OUTCOMING_RPCS)
|
122 |
+
end
|
123 |
+
|
124 |
+
local function samp_on_send_packet(id, bitStream, priority, reliability, orderingChannel)
|
125 |
+
return process_packet(id, bitStream, interface.OUTCOMING_PACKETS, 8)
|
126 |
+
end
|
127 |
+
|
128 |
+
local function samp_on_receive_rpc(id, bitStream)
|
129 |
+
return process_packet(id, bitStream, interface.INCOMING_RPCS)
|
130 |
+
end
|
131 |
+
|
132 |
+
local function samp_on_receive_packet(id, bitStream)
|
133 |
+
return process_packet(id, bitStream, interface.INCOMING_PACKETS, 8)
|
134 |
+
end
|
135 |
+
|
136 |
+
addEventHandler('onSendRpc', samp_on_send_rpc)
|
137 |
+
addEventHandler('onSendPacket', samp_on_send_packet)
|
138 |
+
addEventHandler('onReceiveRpc', samp_on_receive_rpc)
|
139 |
+
addEventHandler('onReceivePacket', samp_on_receive_packet)
|
140 |
+
|
141 |
+
return MODULE
|
events.lua
ADDED
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local raknet = require 'samp.raknet'
|
7 |
+
local events = require 'samp.events.core'
|
8 |
+
local utils = require 'samp.events.utils'
|
9 |
+
local handler = require 'samp.events.handlers'
|
10 |
+
require 'samp.events.extra_types'
|
11 |
+
local RPC = raknet.RPC
|
12 |
+
local PACKET = raknet.PACKET
|
13 |
+
local OUTCOMING_RPCS = events.INTERFACE.OUTCOMING_RPCS
|
14 |
+
local OUTCOMING_PACKETS = events.INTERFACE.OUTCOMING_PACKETS
|
15 |
+
local INCOMING_RPCS = events.INTERFACE.INCOMING_RPCS
|
16 |
+
local INCOMING_PACKETS = events.INTERFACE.INCOMING_PACKETS
|
17 |
+
|
18 |
+
-- Outgoing rpcs
|
19 |
+
OUTCOMING_RPCS[RPC.ENTERVEHICLE] = {'onSendEnterVehicle', {vehicleId = 'uint16'}, {passenger = 'bool8'}}
|
20 |
+
OUTCOMING_RPCS[RPC.CLICKPLAYER] = {'onSendClickPlayer', {playerId = 'uint16'}, {source = 'uint8'}}
|
21 |
+
OUTCOMING_RPCS[RPC.CLIENTJOIN] = {'onSendClientJoin', {version = 'int32'}, {mod = 'uint8'}, {nickname = 'string8'}, {challengeResponse = 'int32'}, {joinAuthKey = 'string8'}, {clientVer = 'string8'}, {challengeResponse2 = 'int32'}}
|
22 |
+
--OUTCOMING_RPCS[RPC.SELECTOBJECT] = {'onSendSelectObject', {type = 'int32'}, {objectId = 'uint16'}, {model = 'int32'}, {position = 'vector3d'}}
|
23 |
+
OUTCOMING_RPCS[RPC.SELECTOBJECT] = {'onSendEnterEditObject', {type = 'int32'}, {objectId = 'uint16'}, {model = 'int32'}, {position = 'vector3d'}}
|
24 |
+
OUTCOMING_RPCS[RPC.SERVERCOMMAND] = {'onSendCommand', {command = 'string32'}}
|
25 |
+
OUTCOMING_RPCS[RPC.SPAWN] = {'onSendSpawn'}
|
26 |
+
OUTCOMING_RPCS[RPC.DEATH] = {'onSendDeathNotification', {reason = 'uint8'}, {killerId = 'uint16'}}
|
27 |
+
OUTCOMING_RPCS[RPC.DIALOGRESPONSE] = {'onSendDialogResponse', {dialogId = 'uint16'}, {button = 'uint8'}, {listboxId = 'uint16'}, {input = 'string8'}}
|
28 |
+
OUTCOMING_RPCS[RPC.CLICKTEXTDRAW] = {'onSendClickTextDraw', {textdrawId = 'uint16'}}
|
29 |
+
OUTCOMING_RPCS[RPC.SCMEVENT] = {'onSendVehicleTuningNotification', {vehicleId = 'int32'}, {param1 = 'int32'}, {param2 = 'int32'}, {event = 'int32'}}
|
30 |
+
OUTCOMING_RPCS[RPC.CHAT] = {'onSendChat', {message = 'string8'}}
|
31 |
+
OUTCOMING_RPCS[RPC.CLIENTCHECK] = {'onSendClientCheckResponse', {requestType = 'uint8'}, {result1 = 'int32'}, {result2 = 'uint8'}}
|
32 |
+
OUTCOMING_RPCS[RPC.DAMAGEVEHICLE] = {'onSendVehicleDamaged', {vehicleId = 'uint16'}, {panelDmg = 'int32'}, {doorDmg = 'int32'}, {lights = 'uint8'}, {tires = 'uint8'}}
|
33 |
+
OUTCOMING_RPCS[RPC.EDITATTACHEDOBJECT] = {'onSendEditAttachedObject', {response = 'int32'}, {index = 'int32'}, {model = 'int32'}, {bone = 'int32'}, {position = 'vector3d'}, {rotation = 'vector3d'}, {scale = 'vector3d'}, {color1 = 'int32'}, {color2 = 'int32'}}
|
34 |
+
OUTCOMING_RPCS[RPC.EDITOBJECT] = {'onSendEditObject', {playerObject = 'bool'}, {objectId = 'uint16'}, {response = 'int32'}, {position = 'vector3d'}, {rotation = 'vector3d'}}
|
35 |
+
OUTCOMING_RPCS[RPC.SETINTERIORID] = {'onSendInteriorChangeNotification', {interior = 'uint8'}}
|
36 |
+
OUTCOMING_RPCS[RPC.MAPMARKER] = {'onSendMapMarker', {position = 'vector3d'}}
|
37 |
+
OUTCOMING_RPCS[RPC.REQUESTCLASS] = {'onSendRequestClass', {classId = 'int32'}}
|
38 |
+
OUTCOMING_RPCS[RPC.REQUESTSPAWN] = {'onSendRequestSpawn'}
|
39 |
+
OUTCOMING_RPCS[RPC.PICKEDUPPICKUP] = {'onSendPickedUpPickup', {pickupId = 'int32'}}
|
40 |
+
OUTCOMING_RPCS[RPC.MENUSELECT] = {'onSendMenuSelect', {row = 'uint8'}}
|
41 |
+
OUTCOMING_RPCS[RPC.VEHICLEDESTROYED] = {'onSendVehicleDestroyed', {vehicleId = 'uint16'}}
|
42 |
+
OUTCOMING_RPCS[RPC.MENUQUIT] = {'onSendQuitMenu'}
|
43 |
+
OUTCOMING_RPCS[RPC.EXITVEHICLE] = {'onSendExitVehicle', {vehicleId = 'uint16'}}
|
44 |
+
OUTCOMING_RPCS[RPC.UPDATESCORESPINGSIPS] = {'onSendUpdateScoresAndPings'}
|
45 |
+
-- playerId = 'uint16', damage = 'float', weapon = 'int32', bodypart ='int32'
|
46 |
+
OUTCOMING_RPCS[RPC.GIVETAKEDAMAGE] = {{'onSendGiveDamage', 'onSendTakeDamage'}, handler.rpc_send_give_take_damage_reader, handler.rpc_send_give_take_damage_writer}
|
47 |
+
OUTCOMING_RPCS[RPC.SCRIPTCASH] = {'onSendMoneyIncreaseNotification', {amount = 'int32'}, {increaseType = 'int32'}}
|
48 |
+
OUTCOMING_RPCS[RPC.NPCJOIN] = {'onSendNPCJoin', {version = 'int32'}, {mod = 'uint8'}, {nickname = 'string8'}, {challengeResponse = 'int32'}}
|
49 |
+
OUTCOMING_RPCS[RPC.SRVNETSTATS] = {'onSendServerStatisticsRequest'}
|
50 |
+
OUTCOMING_RPCS[RPC.WEAPONPICKUPDESTROY] = {'onSendPickedUpWeapon', {id = 'uint16'}}
|
51 |
+
OUTCOMING_RPCS[RPC.CAMTARGETUPDATE] = {'onSendCameraTargetUpdate', {objectId = 'uint16'}, {vehicleId = 'uint16'}, {playerId = 'uint16'}, {actorId = 'uint16'}}
|
52 |
+
OUTCOMING_RPCS[RPC.GIVEACTORDAMAGE] = {'onSendGiveActorDamage', {_unused = 'bool'}, {actorId = 'uint16'}, {damage = 'float'}, {weapon = 'int32'}, {bodypart ='int32'}}
|
53 |
+
|
54 |
+
-- Incoming rpcs
|
55 |
+
-- int playerId, string hostName, table settings, table vehicleModels, bool vehicleFriendlyFire
|
56 |
+
INCOMING_RPCS[RPC.INITGAME] = {'onInitGame', handler.rpc_init_game_reader, handler.rpc_init_game_writer}
|
57 |
+
INCOMING_RPCS[RPC.SERVERJOIN] = {'onPlayerJoin', {playerId = 'uint16'}, {color = 'int32'}, {isNpc = 'bool8'}, {nickname = 'string8'}}
|
58 |
+
INCOMING_RPCS[RPC.SERVERQUIT] = {'onPlayerQuit', {playerId = 'uint16'}, {reason = 'uint8'}}
|
59 |
+
INCOMING_RPCS[RPC.REQUESTCLASS] = {'onRequestClassResponse', {canSpawn = 'bool8'}, {team = 'uint8'}, {skin = 'int32'}, {_unused = 'uint8'}, {positon = 'vector3d'}, {rotation = 'float'}, {weapons = 'Int32Array3'}, {ammo = 'Int32Array3'}}
|
60 |
+
INCOMING_RPCS[RPC.REQUESTSPAWN] = {'onRequestSpawnResponse', {response = 'bool8'}}
|
61 |
+
INCOMING_RPCS[RPC.SETPLAYERNAME] = {'onSetPlayerName', {playerId = 'uint16'}, {name = 'string8'}, {success = 'bool8'}}
|
62 |
+
INCOMING_RPCS[RPC.SETPLAYERPOS] = {'onSetPlayerPos', {position = 'vector3d'}}
|
63 |
+
INCOMING_RPCS[RPC.SETPLAYERPOSFINDZ] = {'onSetPlayerPosFindZ', {position = 'vector3d'}}
|
64 |
+
INCOMING_RPCS[RPC.SETPLAYERHEALTH] = {'onSetPlayerHealth', {health = 'float'}}
|
65 |
+
INCOMING_RPCS[RPC.TOGGLEPLAYERCONTROLLABLE] = {'onTogglePlayerControllable', {controllable = 'bool8'}}
|
66 |
+
INCOMING_RPCS[RPC.PLAYSOUND] = {'onPlaySound', {soundId = 'int32'}, {position = 'vector3d'}}
|
67 |
+
INCOMING_RPCS[RPC.SETPLAYERWORLDBOUNDS] = {'onSetWorldBounds', {maxX = 'float'}, {minX = 'float'}, {maxY = 'float'}, {minY = 'float'}}
|
68 |
+
INCOMING_RPCS[RPC.GIVEPLAYERMONEY] = {'onGivePlayerMoney', {money = 'int32'}}
|
69 |
+
INCOMING_RPCS[RPC.SETPLAYERFACINGANGLE] = {'onSetPlayerFacingAngle', {angle = 'float'}}
|
70 |
+
INCOMING_RPCS[RPC.RESETPLAYERMONEY] = {'onResetPlayerMoney'}
|
71 |
+
INCOMING_RPCS[RPC.RESETPLAYERWEAPONS] = {'onResetPlayerWeapons'}
|
72 |
+
INCOMING_RPCS[RPC.GIVEPLAYERWEAPON] = {'onGivePlayerWeapon', {weaponId = 'int32'}, {ammo = 'int32'}}
|
73 |
+
INCOMING_RPCS[RPC.CANCELEDIT] = {'onCancelEdit'}
|
74 |
+
INCOMING_RPCS[RPC.SETPLAYERTIME] = {'onSetPlayerTime', {hour = 'uint8'}, {minute = 'uint8'}}
|
75 |
+
INCOMING_RPCS[RPC.TOGGLECLOCK] = {'onSetToggleClock', {state = 'bool8'}}
|
76 |
+
INCOMING_RPCS[RPC.WORLDPLAYERADD] = {'onPlayerStreamIn', {playerId = 'uint16'}, {team = 'uint8'}, {model = 'int32'}, {position = 'vector3d'}, {rotation = 'float'}, {color = 'int32'}, {fightingStyle = 'uint8'}}
|
77 |
+
INCOMING_RPCS[RPC.SETPLAYERSHOPNAME] = {'onSetShopName', {name = 'fixedString32'}}
|
78 |
+
INCOMING_RPCS[RPC.SETPLAYERSKILLLEVEL] = {'onSetPlayerSkillLevel', {playerId = 'uint16'}, {skill = 'int32'}, {level = 'uint16'}}
|
79 |
+
INCOMING_RPCS[RPC.SETPLAYERDRUNKLEVEL] = {'onSetPlayerDrunk', {drunkLevel = 'int32'}}
|
80 |
+
INCOMING_RPCS[RPC.CREATE3DTEXTLABEL] = {'onCreate3DText', {id = 'uint16'}, {color = 'int32'}, {position = 'vector3d'}, {distance = 'float'}, {testLOS = 'bool8'}, {attachedPlayerId = 'uint16'}, {attachedVehicleId = 'uint16'}, {text = 'encodedString4096'}}
|
81 |
+
INCOMING_RPCS[RPC.DISABLECHECKPOINT] = {'onDisableCheckpoint'}
|
82 |
+
INCOMING_RPCS[RPC.SETRACECHECKPOINT] = {'onSetRaceCheckpoint', {type = 'uint8'}, {position = 'vector3d'}, {nextPosition = 'vector3d'}, {size = 'float'}}
|
83 |
+
INCOMING_RPCS[RPC.DISABLERACECHECKPOINT] = {'onDisableRaceCheckpoint'}
|
84 |
+
INCOMING_RPCS[RPC.GAMEMODERESTART] = {'onGamemodeRestart'}
|
85 |
+
INCOMING_RPCS[RPC.PLAYAUDIOSTREAM] = {'onPlayAudioStream', {url = 'string8'}, {position = 'vector3d'}, {radius = 'float'}, {usePosition = 'bool8'}}
|
86 |
+
INCOMING_RPCS[RPC.STOPAUDIOSTREAM] = {'onStopAudioStream'}
|
87 |
+
INCOMING_RPCS[RPC.REMOVEBUILDINGFORPLAYER] = {'onRemoveBuilding', {modelId = 'int32'}, {position = 'vector3d'}, {radius = 'float'}}
|
88 |
+
INCOMING_RPCS[RPC.CREATEOBJECT] = {'onCreateObject', handler.rpc_create_object_reader, handler.rpc_create_object_writer}
|
89 |
+
INCOMING_RPCS[RPC.SETOBJECTPOS] = {'onSetObjectPosition', {objectId = 'uint16'}, {position = 'vector3d'}}
|
90 |
+
INCOMING_RPCS[RPC.SETOBJECTROT] = {'onSetObjectRotation', {objectId = 'uint16'}, {rotation = 'vector3d'}}
|
91 |
+
INCOMING_RPCS[RPC.DESTROYOBJECT] = {'onDestroyObject', {objectId = 'uint16'}}
|
92 |
+
INCOMING_RPCS[RPC.DEATHMESSAGE] = {'onPlayerDeathNotification', {killerId = 'uint16'}, {killedId = 'uint16'}, {reason = 'uint8'}}
|
93 |
+
INCOMING_RPCS[RPC.SETPLAYERMAPICON] = {'onSetMapIcon', {iconId = 'uint8'}, {position = 'vector3d'}, {type = 'uint8'}, {color = 'int32'}, {style = 'uint8'}}
|
94 |
+
INCOMING_RPCS[RPC.REMOVEVEHICLECOMPONENT] = {'onRemoveVehicleComponent', {vehicleId = 'uint16'}, {componentId = 'uint16'}}
|
95 |
+
INCOMING_RPCS[RPC.DESTROY3DTEXTLABEL] = {'onRemove3DTextLabel', {textLabelId = 'uint16'}}
|
96 |
+
INCOMING_RPCS[RPC.CHATBUBBLE] = {'onPlayerChatBubble', {playerId = 'uint16'}, {color = 'int32'}, {distance = 'float'}, {duration = 'int32'}, {message = 'string8'}}
|
97 |
+
INCOMING_RPCS[RPC.UPDATETIME] = {'onUpdateGlobalTimer', {time = 'int32'}}
|
98 |
+
INCOMING_RPCS[RPC.SHOWDIALOG] = {'onShowDialog', {dialogId = 'uint16'}, {style = 'uint8'}, {title = 'string8'}, {button1 = 'string8'}, {button2 = 'string8'}, {text = 'encodedString4096'}}
|
99 |
+
INCOMING_RPCS[RPC.DESTROYPICKUP] = {'onDestroyPickup', {id = 'int32'}}
|
100 |
+
INCOMING_RPCS[RPC.LINKVEHICLETOINTERIOR] = {'onLinkVehicleToInterior', {vehicleId = 'uint16'}, {interiorId = 'uint8'}}
|
101 |
+
INCOMING_RPCS[RPC.SETPLAYERARMOUR] = {'onSetPlayerArmour', {armour = 'float'}}
|
102 |
+
INCOMING_RPCS[RPC.SETPLAYERARMEDWEAPON] = {'onSetPlayerArmedWeapon', {weaponId = 'int32'}}
|
103 |
+
INCOMING_RPCS[RPC.SETSPAWNINFO] = {'onSetSpawnInfo', {team = 'uint8'}, {skin = 'int32'}, {_unused = 'uint8'}, {position = 'vector3d'}, {rotation = 'float'}, {weapons = 'Int32Array3'}, {ammo = 'Int32Array3'}}
|
104 |
+
INCOMING_RPCS[RPC.SETPLAYERTEAM] = {'onSetPlayerTeam', {playerId = 'uint16'}, {teamId = 'uint8'}}
|
105 |
+
INCOMING_RPCS[RPC.PUTPLAYERINVEHICLE] = {'onPutPlayerInVehicle', {vehicleId = 'uint16'}, {seatId = 'uint8'}}
|
106 |
+
INCOMING_RPCS[RPC.REMOVEPLAYERFROMVEHICLE] = {'onRemovePlayerFromVehicle'}
|
107 |
+
INCOMING_RPCS[RPC.SETPLAYERCOLOR] = {'onSetPlayerColor', {playerId = 'uint16'}, {color = 'int32'}}
|
108 |
+
INCOMING_RPCS[RPC.DISPLAYGAMETEXT] = {'onDisplayGameText', {style = 'int32'}, {time = 'int32'}, {text = 'string32'}}
|
109 |
+
INCOMING_RPCS[RPC.FORCECLASSSELECTION] = {'onForceClassSelection'}
|
110 |
+
INCOMING_RPCS[RPC.ATTACHOBJECTTOPLAYER] = {'onAttachObjectToPlayer', {objectId = 'uint16'}, {playerId = 'uint16'}, {offsets = 'vector3d'}, {rotation = 'vector3d'}}
|
111 |
+
-- menuId = 'uint8', menuTitle = 'fixedString32', x = 'float', y = 'float', twoColumns = 'bool32', columns = 'table', rows = 'table', menu = 'bool32'
|
112 |
+
INCOMING_RPCS[RPC.INITMENU] = {'onInitMenu', handler.rpc_init_menu_reader, handler.rpc_init_menu_writer}
|
113 |
+
INCOMING_RPCS[RPC.SHOWMENU] = {'onShowMenu', {menuId = 'uint8'}}
|
114 |
+
INCOMING_RPCS[RPC.HIDEMENU] = {'onHideMenu', {menuId = 'uint8'}}
|
115 |
+
INCOMING_RPCS[RPC.CREATEEXPLOSION] = {'onCreateExplosion', {position = 'vector3d'}, {style = 'int32'}, {radius = 'float'}}
|
116 |
+
INCOMING_RPCS[RPC.SHOWPLAYERNAMETAGFORPLAYER] = {'onShowPlayerNameTag', {playerId = 'uint16'}, {show = 'bool8'}}
|
117 |
+
INCOMING_RPCS[RPC.ATTACHCAMERATOOBJECT] = {'onAttachCameraToObject', {objectId = 'uint16'}}
|
118 |
+
INCOMING_RPCS[RPC.INTERPOLATECAMERA] = {'onInterpolateCamera', {setPos = 'bool'}, {fromPos = 'vector3d'}, {destPos = 'vector3d'}, {time = 'int32'}, {mode = 'uint8'}}
|
119 |
+
INCOMING_RPCS[RPC.GANGZONESTOPFLASH] = {'onGangZoneStopFlash', {zoneId = 'uint16'}}
|
120 |
+
INCOMING_RPCS[RPC.APPLYANIMATION] = {'onApplyPlayerAnimation', {playerId = 'uint16'}, {animLib = 'string8'}, {animName = 'string8'}, {frameDelta = 'float'}, {loop = 'bool'}, {lockX = 'bool'}, {lockY = 'bool'}, {freeze = 'bool'}, {time = 'int32'}}
|
121 |
+
INCOMING_RPCS[RPC.CLEARANIMATIONS] = {'onClearPlayerAnimation', {playerId = 'uint16'}}
|
122 |
+
INCOMING_RPCS[RPC.SETPLAYERSPECIALACTION] = {'onSetPlayerSpecialAction', {actionId = 'uint8'}}
|
123 |
+
INCOMING_RPCS[RPC.SETPLAYERFIGHTINGSTYLE] = {'onSetPlayerFightingStyle', {playerId = 'uint16'}, {styleId = 'uint8'}}
|
124 |
+
INCOMING_RPCS[RPC.SETPLAYERVELOCITY] = {'onSetPlayerVelocity', {velocity = 'vector3d'}}
|
125 |
+
INCOMING_RPCS[RPC.SETVEHICLEVELOCITY] = {'onSetVehicleVelocity', {turn = 'bool8'}, {velocity = 'vector3d'}}
|
126 |
+
INCOMING_RPCS[RPC.CLIENTMESSAGE] = {'onServerMessage', {color = 'int32'}, {text = 'string32'}}
|
127 |
+
INCOMING_RPCS[RPC.SETWORLDTIME] = {'onSetWorldTime', {hour = 'uint8'}}
|
128 |
+
INCOMING_RPCS[RPC.CREATEPICKUP] = {'onCreatePickup', {id = 'int32'}, {model = 'int32'}, {pickupType = 'int32'}, {position = 'vector3d'}}
|
129 |
+
INCOMING_RPCS[RPC.MOVEOBJECT] = {'onMoveObject', {objectId = 'uint16'}, {fromPos = 'vector3d'}, {destPos = 'vector3d'}, {speed = 'float'}, {rotation = 'vector3d'}}
|
130 |
+
INCOMING_RPCS[RPC.ENABLESTUNTBONUSFORPLAYER] = {'onEnableStuntBonus', {state = 'bool'}}
|
131 |
+
INCOMING_RPCS[RPC.TEXTDRAWSETSTRING] = {'onTextDrawSetString', {id = 'uint16'}, {text = 'string16'}}
|
132 |
+
INCOMING_RPCS[RPC.SETCHECKPOINT] = {'onSetCheckpoint', {position = 'vector3d'}, {radius = 'float'}}
|
133 |
+
INCOMING_RPCS[RPC.GANGZONECREATE] = {'onCreateGangZone', {zoneId = 'uint16'}, {squareStart = 'vector2d'}, {squareEnd = 'vector2d'}, {color = 'int32'}}
|
134 |
+
INCOMING_RPCS[RPC.PLAYCRIMEREPORT] = {'onPlayCrimeReport', {suspectId = 'uint16'}, {inVehicle = 'bool32'}, {vehicleModel = 'int32'}, {vehicleColor = 'int32'}, {crime = 'int32'}, {coordinates = 'vector3d'}}
|
135 |
+
INCOMING_RPCS[RPC.GANGZONEDESTROY] = {'onGangZoneDestroy', {zoneId = 'uint16'}}
|
136 |
+
INCOMING_RPCS[RPC.GANGZONEFLASH] = {'onGangZoneFlash', {zoneId = 'uint16'}, {color = 'int32'}}
|
137 |
+
INCOMING_RPCS[RPC.STOPOBJECT] = {'onStopObject', {objectId = 'uint16'}}
|
138 |
+
INCOMING_RPCS[RPC.SETNUMBERPLATE] = {'onSetVehicleNumberPlate', {vehicleId = 'uint16'}, {text = 'string8'}}
|
139 |
+
INCOMING_RPCS[RPC.TOGGLEPLAYERSPECTATING] = {'onTogglePlayerSpectating', {state = 'bool32'}}
|
140 |
+
INCOMING_RPCS[RPC.PLAYERSPECTATEPLAYER] = {'onSpectatePlayer', {playerId = 'uint16'}, {camType = 'uint8'}}
|
141 |
+
INCOMING_RPCS[RPC.PLAYERSPECTATEVEHICLE] = {'onSpectateVehicle', {vehicleId = 'uint16'}, {camType = 'uint8'}}
|
142 |
+
INCOMING_RPCS[RPC.SHOWTEXTDRAW] = {'onShowTextDraw',
|
143 |
+
{textdrawId = 'uint16'},
|
144 |
+
{textdraw = {
|
145 |
+
{flags = 'uint8'},
|
146 |
+
{letterWidth = 'float'},
|
147 |
+
{letterHeight = 'float'},
|
148 |
+
{letterColor = 'int32'},
|
149 |
+
{lineWidth = 'float'},
|
150 |
+
{lineHeight = 'float'},
|
151 |
+
{boxColor = 'int32'},
|
152 |
+
{shadow = 'uint8'},
|
153 |
+
{outline = 'uint8'},
|
154 |
+
{backgroundColor = 'int32'},
|
155 |
+
{style = 'uint8'},
|
156 |
+
{selectable = 'uint8'},
|
157 |
+
{position = 'vector2d'},
|
158 |
+
{modelId = 'uint16'},
|
159 |
+
{rotation = 'vector3d'},
|
160 |
+
{zoom = 'float'},
|
161 |
+
{color1 = 'int16'},
|
162 |
+
{color2 = 'int16'},
|
163 |
+
{text = 'string16'}
|
164 |
+
}}
|
165 |
+
}
|
166 |
+
INCOMING_RPCS[RPC.SETPLAYERWANTEDLEVEL] = {'onSetPlayerWantedLevel', {wantedLevel = 'uint8'}}
|
167 |
+
INCOMING_RPCS[RPC.TEXTDRAWHIDEFORPLAYER] = {'onTextDrawHide', {textDrawId = 'uint16'}}
|
168 |
+
INCOMING_RPCS[RPC.REMOVEPLAYERMAPICON] = {'onRemoveMapIcon', {iconId = 'uint8'}}
|
169 |
+
INCOMING_RPCS[RPC.SETPLAYERAMMO] = {'onSetWeaponAmmo', {weaponId = 'uint8'}, {ammo = 'uint16'}}
|
170 |
+
INCOMING_RPCS[RPC.SETGRAVITY] = {'onSetGravity', {gravity = 'float'}}
|
171 |
+
INCOMING_RPCS[RPC.SETVEHICLEHEALTH] = {'onSetVehicleHealth', {vehicleId = 'uint16'}, {health = 'float'}}
|
172 |
+
INCOMING_RPCS[RPC.ATTACHTRAILERTOVEHICLE] = {'onAttachTrailerToVehicle', {trailerId = 'uint16'}, {vehicleId = 'uint16'}}
|
173 |
+
INCOMING_RPCS[RPC.DETACHTRAILERFROMVEHICLE] = {'onDetachTrailerFromVehicle', {vehicleId = 'uint16'}}
|
174 |
+
INCOMING_RPCS[RPC.SETWEATHER] = {'onSetWeather', {weatherId = 'uint8'}}
|
175 |
+
INCOMING_RPCS[RPC.SETPLAYERSKIN] = {'onSetPlayerSkin', {playerId = 'int32'}, {skinId = 'int32'}}
|
176 |
+
INCOMING_RPCS[RPC.SETPLAYERINTERIOR] = {'onSetInterior', {interior = 'uint8'}}
|
177 |
+
INCOMING_RPCS[RPC.SETPLAYERCAMERAPOS] = {'onSetCameraPosition', {position = 'vector3d'}}
|
178 |
+
INCOMING_RPCS[RPC.SETPLAYERCAMERALOOKAT] = {'onSetCameraLookAt', {lookAtPosition = 'vector3d'}, {cutType = 'uint8'}}
|
179 |
+
INCOMING_RPCS[RPC.SETVEHICLEPOS] = {'onSetVehiclePosition', {vehicleId = 'uint16'}, {position = 'vector3d'}}
|
180 |
+
INCOMING_RPCS[RPC.SETVEHICLEZANGLE] = {'onSetVehicleAngle', {vehicleId = 'uint16'}, {angle = 'float'}}
|
181 |
+
INCOMING_RPCS[RPC.SETVEHICLEPARAMSFORPLAYER] = {'onSetVehicleParams', {vehicleId = 'uint16'}, {objective = 'bool8'}, {doorsLocked = 'bool8'}}
|
182 |
+
INCOMING_RPCS[RPC.SETCAMERABEHINDPLAYER] = {'onSetCameraBehind'}
|
183 |
+
INCOMING_RPCS[RPC.CHAT] = {'onChatMessage', {playerId = 'uint16'}, {text = 'string8'}}
|
184 |
+
INCOMING_RPCS[RPC.CONNECTIONREJECTED] = {'onConnectionRejected', {reason = 'uint8'}}
|
185 |
+
INCOMING_RPCS[RPC.WORLDPLAYERREMOVE] = {'onPlayerStreamOut', {playerId = 'uint16'}}
|
186 |
+
INCOMING_RPCS[RPC.WORLDVEHICLEADD] = {'onVehicleStreamIn', handler.rpc_vehicle_stream_in_reader, handler.rpc_vehicle_stream_in_writer}
|
187 |
+
INCOMING_RPCS[RPC.WORLDVEHICLEREMOVE] = {'onVehicleStreamOut', {vehicleId = 'uint16'}}
|
188 |
+
INCOMING_RPCS[RPC.WORLDPLAYERDEATH] = {'onPlayerDeath', {playerId = 'uint16'}}
|
189 |
+
INCOMING_RPCS[RPC.ENTERVEHICLE] = {'onPlayerEnterVehicle', {playerId = 'uint16'}, {vehicleId = 'uint16'}, {passenger = 'bool8'}}
|
190 |
+
INCOMING_RPCS[RPC.UPDATESCORESPINGSIPS] = {'onUpdateScoresAndPings', handler.rpc_update_scores_and_pings_reader, handler.rpc_update_scores_and_pings_writer}
|
191 |
+
INCOMING_RPCS[RPC.SETOBJECTMATERIAL] = {{'onSetObjectMaterial', 'onSetObjectMaterialText'}, handler.rpc_set_object_material_reader, handler.rpc_set_object_material_writer}
|
192 |
+
INCOMING_RPCS[RPC.CREATEACTOR] = {'onCreateActor', {actorId = 'uint16'}, {skinId = 'int32'}, {position = 'vector3d'}, {rotation = 'float'}, {health = 'float'}}
|
193 |
+
INCOMING_RPCS[RPC.CLICKTEXTDRAW] = {'onToggleSelectTextDraw', {state = 'bool'}, {hovercolor = 'int32'}}
|
194 |
+
INCOMING_RPCS[RPC.SETVEHICLEPARAMSEX] = {'onSetVehicleParamsEx',
|
195 |
+
{vehicleId = 'uint16'},
|
196 |
+
{params = {
|
197 |
+
{engine = 'uint8'},
|
198 |
+
{lights = 'uint8'},
|
199 |
+
{alarm = 'uint8'},
|
200 |
+
{doors = 'uint8'},
|
201 |
+
{bonnet = 'uint8'},
|
202 |
+
{boot = 'uint8'},
|
203 |
+
{objective = 'uint8'},
|
204 |
+
{unknown = 'uint8'}
|
205 |
+
}},
|
206 |
+
{doors = {
|
207 |
+
{driver = 'uint8'},
|
208 |
+
{passenger = 'uint8'},
|
209 |
+
{backleft = 'uint8'},
|
210 |
+
{backright = 'uint8'}
|
211 |
+
}},
|
212 |
+
{windows = {
|
213 |
+
{driver = 'uint8'},
|
214 |
+
{passenger = 'uint8'},
|
215 |
+
{backleft = 'uint8'},
|
216 |
+
{backright = 'uint8'}
|
217 |
+
}}
|
218 |
+
}
|
219 |
+
INCOMING_RPCS[RPC.SETPLAYERATTACHEDOBJECT] = {'onSetPlayerAttachedObject',
|
220 |
+
{playerId = 'uint16'},
|
221 |
+
{index = 'int32'},
|
222 |
+
{create = 'bool'},
|
223 |
+
{object = {
|
224 |
+
{modelId = 'int32'},
|
225 |
+
{bone = 'int32'},
|
226 |
+
{offset = 'vector3d'},
|
227 |
+
{rotation = 'vector3d'},
|
228 |
+
{scale = 'vector3d'},
|
229 |
+
{color1 = 'int32'},
|
230 |
+
{color2 = 'int32'}}
|
231 |
+
}
|
232 |
+
}
|
233 |
+
INCOMING_RPCS[RPC.CLIENTCHECK] = {'onClientCheck', {requestType = 'uint8'}, {subject = 'int32'}, {offset = 'uint16'}, {length = 'uint16'}}
|
234 |
+
INCOMING_RPCS[RPC.DESTROYACTOR] = {'onDestroyActor', {actorId = 'uint16'}}
|
235 |
+
INCOMING_RPCS[RPC.DESTROYWEAPONPICKUP] = {'onDestroyWeaponPickup', {id = 'uint8'}}
|
236 |
+
INCOMING_RPCS[RPC.EDITATTACHEDOBJECT] = {'onEditAttachedObject', {index = 'int32'}}
|
237 |
+
INCOMING_RPCS[RPC.TOGGLECAMERATARGET] = {'onToggleCameraTargetNotifying', {enable = 'bool'}}
|
238 |
+
INCOMING_RPCS[RPC.SELECTOBJECT] = {'onEnterSelectObject'}
|
239 |
+
INCOMING_RPCS[RPC.EXITVEHICLE] = {'onPlayerExitVehicle', {playerId = 'uint16'}, {vehicleId = 'uint16'}}
|
240 |
+
INCOMING_RPCS[RPC.SCMEVENT] = {'onVehicleTuningNotification', {playerId = 'uint16'}, {event = 'int32'}, {vehicleId = 'int32'}, {param1 = 'int32'}, {param2 = 'int32'}}
|
241 |
+
INCOMING_RPCS[RPC.SRVNETSTATS] = {'onServerStatisticsResponse'} --, {data = 'RakNetStatisticsStruct'}}
|
242 |
+
INCOMING_RPCS[RPC.EDITOBJECT] = {'onEnterEditObject', {playerObject = 'bool'}, {objectId = 'uint16'}}
|
243 |
+
INCOMING_RPCS[RPC.DAMAGEVEHICLE] = {'onVehicleDamageStatusUpdate', {vehicleId = 'uint16'}, {panelDmg = 'int32'}, {doorDmg = 'int32'}, {lights = 'uint8'}, {tires = 'uint8'}}
|
244 |
+
INCOMING_RPCS[RPC.DISABLEVEHICLECOLLISIONS] = {'onDisableVehicleCollisions', {disable = 'bool'}}
|
245 |
+
INCOMING_RPCS[RPC.TOGGLEWIDESCREEN] = {'onToggleWidescreen', {enable = 'bool8'}}
|
246 |
+
INCOMING_RPCS[RPC.SETVEHICLETIRES] = {'onSetVehicleTires', {vehicleId = 'uint16'}, {tires = 'uint8'}}
|
247 |
+
INCOMING_RPCS[RPC.SETPLAYERDRUNKVISUALS] = {'onSetPlayerDrunkVisuals', {level = 'int32'}}
|
248 |
+
INCOMING_RPCS[RPC.SETPLAYERDRUNKHANDLING] = {'onSetPlayerDrunkHandling', {level = 'int32'}}
|
249 |
+
INCOMING_RPCS[RPC.APPLYACTORANIMATION] = {'onApplyActorAnimation', {actorId = 'uint16'}, {animLib = 'string8'}, {animName = 'string8'}, {frameDelta = 'float'}, {loop = 'bool'}, {lockX = 'bool'}, {lockY = 'bool'}, {freeze = 'bool'}, {time = 'int32'}}
|
250 |
+
INCOMING_RPCS[RPC.CLEARACTORANIMATION] = {'onClearActorAnimation', {actorId = 'uint16'}}
|
251 |
+
INCOMING_RPCS[RPC.SETACTORROTATION] = {'onSetActorFacingAngle', {actorId = 'uint16'}, {angle = 'float'}}
|
252 |
+
INCOMING_RPCS[RPC.SETACTORPOSITION] = {'onSetActorPos', {actorId = 'uint16'}, {position = 'vector3d'}}
|
253 |
+
INCOMING_RPCS[RPC.SETACTORHEALTH] = {'onSetActorHealth', {actorId = 'uint16'}, {health = 'float'}}
|
254 |
+
INCOMING_RPCS[RPC.SETPLAYEROBJECTNOCAMCOL] = {'onSetPlayerObjectNoCameraCol', {objectId = 'uint16'}}
|
255 |
+
INCOMING_RPCS[125] = {'_dummy125'}
|
256 |
+
INCOMING_RPCS[64] = {'_dummy64', {'uint16'}}
|
257 |
+
INCOMING_RPCS[48] = {'_unused48', {'int32'}}
|
258 |
+
|
259 |
+
|
260 |
+
-- Outgoing packets
|
261 |
+
OUTCOMING_PACKETS[PACKET.RCON_COMMAND] = {'onSendRconCommand', {command = 'string32'}}
|
262 |
+
OUTCOMING_PACKETS[PACKET.STATS_UPDATE] = {'onSendStatsUpdate', {money = 'int32'}, {drunkLevel = 'int32'}}
|
263 |
+
local function empty_writer() end
|
264 |
+
OUTCOMING_PACKETS[PACKET.PLAYER_SYNC] = {'onSendPlayerSync', function(bs) return utils.process_outcoming_sync_data(bs, 'PlayerSyncData') end, empty_writer}
|
265 |
+
OUTCOMING_PACKETS[PACKET.VEHICLE_SYNC] = {'onSendVehicleSync', function(bs) return utils.process_outcoming_sync_data(bs, 'VehicleSyncData') end, empty_writer}
|
266 |
+
OUTCOMING_PACKETS[PACKET.PASSENGER_SYNC] = {'onSendPassengerSync', function(bs) return utils.process_outcoming_sync_data(bs, 'PassengerSyncData') end, empty_writer}
|
267 |
+
OUTCOMING_PACKETS[PACKET.AIM_SYNC] = {'onSendAimSync', function(bs) return utils.process_outcoming_sync_data(bs, 'AimSyncData') end, empty_writer}
|
268 |
+
OUTCOMING_PACKETS[PACKET.UNOCCUPIED_SYNC] = {'onSendUnoccupiedSync', function(bs) return utils.process_outcoming_sync_data(bs, 'UnoccupiedSyncData') end, empty_writer}
|
269 |
+
OUTCOMING_PACKETS[PACKET.TRAILER_SYNC] = {'onSendTrailerSync', function(bs) return utils.process_outcoming_sync_data(bs, 'TrailerSyncData') end, empty_writer}
|
270 |
+
OUTCOMING_PACKETS[PACKET.BULLET_SYNC] = {'onSendBulletSync', function(bs) return utils.process_outcoming_sync_data(bs, 'BulletSyncData') end, empty_writer}
|
271 |
+
OUTCOMING_PACKETS[PACKET.SPECTATOR_SYNC] = {'onSendSpectatorSync', function(bs) return utils.process_outcoming_sync_data(bs, 'SpectatorSyncData') end, empty_writer}
|
272 |
+
OUTCOMING_PACKETS[PACKET.WEAPONS_UPDATE] = {'onSendWeaponsUpdate', handler.packet_weapons_update_reader, handler.packet_weapons_update_writer}
|
273 |
+
OUTCOMING_PACKETS[PACKET.AUTHENTICATION] = {'onSendAuthenticationResponse', {response = 'string8'}}
|
274 |
+
|
275 |
+
-- Incoming packets
|
276 |
+
INCOMING_PACKETS[PACKET.PLAYER_SYNC] = {'onPlayerSync', handler.packet_player_sync_reader, handler.packet_player_sync_writer}
|
277 |
+
INCOMING_PACKETS[PACKET.VEHICLE_SYNC] = {'onVehicleSync', handler.packet_vehicle_sync_reader, handler.packet_vehicle_sync_writer}
|
278 |
+
INCOMING_PACKETS[PACKET.MARKERS_SYNC] = {'onMarkersSync', handler.packet_markers_sync_reader, handler.packet_markers_sync_writer}
|
279 |
+
INCOMING_PACKETS[PACKET.AIM_SYNC] = {'onAimSync', {playerId = 'uint16'}, {data = 'AimSyncData'}}
|
280 |
+
INCOMING_PACKETS[PACKET.BULLET_SYNC] = {'onBulletSync', {playerId = 'uint16'}, {data = 'BulletSyncData'}}
|
281 |
+
INCOMING_PACKETS[PACKET.UNOCCUPIED_SYNC] = {'onUnoccupiedSync', {playerId = 'uint16'}, {data = 'UnoccupiedSyncData'}}
|
282 |
+
INCOMING_PACKETS[PACKET.TRAILER_SYNC] = {'onTrailerSync', {playerId = 'uint16'}, {data = 'TrailerSyncData'}}
|
283 |
+
INCOMING_PACKETS[PACKET.PASSENGER_SYNC] = {'onPassengerSync', {playerId = 'uint16'}, {data = 'PassengerSyncData'}}
|
284 |
+
INCOMING_PACKETS[PACKET.AUTHENTICATION] = {'onAuthenticationRequest', {key = 'string8'}}
|
285 |
+
INCOMING_PACKETS[PACKET.CONNECTION_REQUEST_ACCEPTED] = {'onConnectionRequestAccepted', {ip = 'int32'}, {port = 'uint16'}, {playerId = 'uint16'}, {challenge = 'int32'}}
|
286 |
+
INCOMING_PACKETS[PACKET.CONNECTION_LOST] = {'onConnectionLost'}
|
287 |
+
INCOMING_PACKETS[PACKET.CONNECTION_BANNED] = {'onConnectionBanned'}
|
288 |
+
INCOMING_PACKETS[PACKET.CONNECTION_ATTEMPT_FAILED] = {'onConnectionAttemptFailed'}
|
289 |
+
INCOMING_PACKETS[PACKET.NO_FREE_INCOMING_CONNECTIONS] = {'onConnectionNoFreeSlot'}
|
290 |
+
INCOMING_PACKETS[PACKET.INVALID_PASSWORD] = {'onConnectionPasswordInvalid'}
|
291 |
+
INCOMING_PACKETS[PACKET.DISCONNECTION_NOTIFICATION] = {'onConnectionClosed'}
|
292 |
+
|
293 |
+
return events
|
extra_types.lua
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local BitStreamIO = require 'samp.events.bitstream_io'
|
7 |
+
local utils = require 'samp.events.utils'
|
8 |
+
|
9 |
+
BitStreamIO.Int32Array3 = {
|
10 |
+
read = function(bs)
|
11 |
+
local arr = {}
|
12 |
+
for i = 1, 3 do arr[i] = raknetBitStreamReadInt32(bs) end
|
13 |
+
return arr
|
14 |
+
end,
|
15 |
+
write = function(bs, value)
|
16 |
+
for i = 1, 3 do raknetBitStreamWriteInt32(bs, value[i]) end
|
17 |
+
end
|
18 |
+
}
|
19 |
+
|
20 |
+
BitStreamIO.AimSyncData = {
|
21 |
+
read = function(bs) return utils.read_sync_data(bs, 'AimSyncData') end,
|
22 |
+
write = function(bs, value) utils.write_sync_data(bs, 'AimSyncData', value) end
|
23 |
+
}
|
24 |
+
|
25 |
+
BitStreamIO.UnoccupiedSyncData = {
|
26 |
+
read = function(bs) return utils.read_sync_data(bs, 'UnoccupiedSyncData') end,
|
27 |
+
write = function(bs, value) utils.write_sync_data(bs, 'UnoccupiedSyncData', value) end
|
28 |
+
}
|
29 |
+
|
30 |
+
BitStreamIO.PassengerSyncData = {
|
31 |
+
read = function(bs) return utils.read_sync_data(bs, 'PassengerSyncData') end,
|
32 |
+
write = function(bs, value) utils.write_sync_data(bs, 'PassengerSyncData', value) end
|
33 |
+
}
|
34 |
+
|
35 |
+
BitStreamIO.BulletSyncData = {
|
36 |
+
read = function(bs) return utils.read_sync_data(bs, 'BulletSyncData') end,
|
37 |
+
write = function(bs, value) utils.write_sync_data(bs, 'BulletSyncData', value) end
|
38 |
+
}
|
39 |
+
|
40 |
+
BitStreamIO.TrailerSyncData = {
|
41 |
+
read = function(bs) return utils.read_sync_data(bs, 'TrailerSyncData') end,
|
42 |
+
write = function(bs, value) utils.write_sync_data(bs, 'TrailerSyncData', value) end
|
43 |
+
}
|
44 |
+
|
45 |
+
return BitStreamIO
|
handlers.lua
ADDED
@@ -0,0 +1,526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local bs_io = require 'samp.events.bitstream_io'
|
7 |
+
local utils = require 'samp.events.utils'
|
8 |
+
local bsread, bswrite = bs_io.bs_read, bs_io.bs_write
|
9 |
+
local handler = {}
|
10 |
+
|
11 |
+
--- onSendGiveDamage, onSendTakeDamage
|
12 |
+
function handler.rpc_send_give_take_damage_reader(bs)
|
13 |
+
local take = bsread.bool(bs) -- 'true' is take damage
|
14 |
+
local data = {
|
15 |
+
bsread.uint16(bs), -- playerId
|
16 |
+
bsread.float(bs), -- damage
|
17 |
+
bsread.int32(bs), -- weapon
|
18 |
+
bsread.int32(bs), -- bodypart
|
19 |
+
take,
|
20 |
+
}
|
21 |
+
return (take and 'onSendTakeDamage' or 'onSendGiveDamage'), data
|
22 |
+
end
|
23 |
+
|
24 |
+
function handler.rpc_send_give_take_damage_writer(bs, data)
|
25 |
+
bswrite.bool(bs, data[5]) -- give or take
|
26 |
+
bswrite.uint16(bs, data[1]) -- playerId
|
27 |
+
bswrite.float(bs, data[2]) -- damage
|
28 |
+
bswrite.int32(bs, data[3]) -- weapon
|
29 |
+
bswrite.int32(bs, data[4]) -- bodypart
|
30 |
+
end
|
31 |
+
|
32 |
+
--- onInitGame
|
33 |
+
function handler.rpc_init_game_reader(bs)
|
34 |
+
local settings = {}
|
35 |
+
settings.zoneNames = bsread.bool(bs)
|
36 |
+
settings.useCJWalk = bsread.bool(bs)
|
37 |
+
settings.allowWeapons = bsread.bool(bs)
|
38 |
+
settings.limitGlobalChatRadius = bsread.bool(bs)
|
39 |
+
settings.globalChatRadius = bsread.float(bs)
|
40 |
+
settings.stuntBonus = bsread.bool(bs)
|
41 |
+
settings.nametagDrawDist = bsread.float(bs)
|
42 |
+
settings.disableEnterExits = bsread.bool(bs)
|
43 |
+
settings.nametagLOS = bsread.bool(bs)
|
44 |
+
settings.tirePopping = bsread.bool(bs)
|
45 |
+
settings.classesAvailable = bsread.int32(bs)
|
46 |
+
local playerId = bsread.uint16(bs)
|
47 |
+
settings.showPlayerTags = bsread.bool(bs)
|
48 |
+
settings.playerMarkersMode = bsread.int32(bs)
|
49 |
+
settings.worldTime = bsread.uint8(bs)
|
50 |
+
settings.worldWeather = bsread.uint8(bs)
|
51 |
+
settings.gravity = bsread.float(bs)
|
52 |
+
settings.lanMode = bsread.bool(bs)
|
53 |
+
settings.deathMoneyDrop = bsread.int32(bs)
|
54 |
+
settings.instagib = bsread.bool(bs)
|
55 |
+
settings.normalOnfootSendrate = bsread.int32(bs)
|
56 |
+
settings.normalIncarSendrate = bsread.int32(bs)
|
57 |
+
settings.normalFiringSendrate = bsread.int32(bs)
|
58 |
+
settings.sendMultiplier = bsread.int32(bs)
|
59 |
+
settings.lagCompMode = bsread.int32(bs)
|
60 |
+
local hostName = bsread.string8(bs)
|
61 |
+
local vehicleModels = {}
|
62 |
+
for i = 0, 212 - 1 do
|
63 |
+
vehicleModels[i] = bsread.uint8(bs)
|
64 |
+
end
|
65 |
+
settings.vehicleFriendlyFire = bsread.bool32(bs)
|
66 |
+
return {playerId, hostName, settings, vehicleModels, settings.vehicleFriendlyFire}
|
67 |
+
end
|
68 |
+
|
69 |
+
function handler.rpc_init_game_writer(bs, data)
|
70 |
+
local settings = data[3]
|
71 |
+
local vehicleModels = data[4]
|
72 |
+
bswrite.bool(bs, settings.zoneNames)
|
73 |
+
bswrite.bool(bs, settings.useCJWalk)
|
74 |
+
bswrite.bool(bs, settings.allowWeapons)
|
75 |
+
bswrite.bool(bs, settings.limitGlobalChatRadius)
|
76 |
+
bswrite.float(bs, settings.globalChatRadius)
|
77 |
+
bswrite.bool(bs, settings.stuntBonus)
|
78 |
+
bswrite.float(bs, settings.nametagDrawDist)
|
79 |
+
bswrite.bool(bs, settings.disableEnterExits)
|
80 |
+
bswrite.bool(bs, settings.nametagLOS)
|
81 |
+
bswrite.bool(bs, settings.tirePopping)
|
82 |
+
bswrite.int32(bs, settings.classesAvailable)
|
83 |
+
bswrite.uint16(bs, data[1]) -- playerId
|
84 |
+
bswrite.bool(bs, settings.showPlayerTags)
|
85 |
+
bswrite.int32(bs, settings.playerMarkersMode)
|
86 |
+
bswrite.uint8(bs, settings.worldTime)
|
87 |
+
bswrite.uint8(bs, settings.worldWeather)
|
88 |
+
bswrite.float(bs, settings.gravity)
|
89 |
+
bswrite.bool(bs, settings.lanMode)
|
90 |
+
bswrite.int32(bs, settings.deathMoneyDrop)
|
91 |
+
bswrite.bool(bs, settings.instagib)
|
92 |
+
bswrite.int32(bs, settings.normalOnfootSendrate)
|
93 |
+
bswrite.int32(bs, settings.normalIncarSendrate)
|
94 |
+
bswrite.int32(bs, settings.normalFiringSendrate)
|
95 |
+
bswrite.int32(bs, settings.sendMultiplier)
|
96 |
+
bswrite.int32(bs, settings.lagCompMode)
|
97 |
+
bswrite.string8(bs, data[2]) -- hostName
|
98 |
+
for i = 1, 212 do
|
99 |
+
bswrite.uint8(bs, vehicleModels[i])
|
100 |
+
end
|
101 |
+
bswrite.bool32(bs, settings.vehicleFriendlyFire)
|
102 |
+
end
|
103 |
+
|
104 |
+
--- onInitMenu
|
105 |
+
function handler.rpc_init_menu_reader(bs)
|
106 |
+
local colWidth2
|
107 |
+
local rows = {}
|
108 |
+
local columns = {}
|
109 |
+
local readColumn = function(width)
|
110 |
+
local title = bsread.fixedString32(bs)
|
111 |
+
local rowCount = bsread.uint8(bs)
|
112 |
+
local column = {title = title, width = width, text = {}}
|
113 |
+
for i = 1, rowCount do
|
114 |
+
column.text[i] = bsread.fixedString32(bs)
|
115 |
+
end
|
116 |
+
return column
|
117 |
+
end
|
118 |
+
local menuId = bsread.uint8(bs)
|
119 |
+
local twoColumns = bsread.bool32(bs)
|
120 |
+
local menuTitle = bsread.fixedString32(bs)
|
121 |
+
local x = bsread.float(bs)
|
122 |
+
local y = bsread.float(bs)
|
123 |
+
local colWidth1 = bsread.float(bs)
|
124 |
+
if twoColumns then
|
125 |
+
colWidth2 = bsread.float(bs)
|
126 |
+
end
|
127 |
+
local menu = bsread.bool32(bs)
|
128 |
+
for i = 1, 12 do
|
129 |
+
rows[i] = bsread.int32(bs)
|
130 |
+
end
|
131 |
+
columns[1] = readColumn(colWidth1)
|
132 |
+
if twoColumns then
|
133 |
+
columns[2] = readColumn(colWidth2)
|
134 |
+
end
|
135 |
+
return {menuId, menuTitle, x, y, twoColumns, columns, rows, menu}
|
136 |
+
end
|
137 |
+
|
138 |
+
function handler.rpc_init_menu_writer(bs, data)
|
139 |
+
local columns = data[6]
|
140 |
+
bswrite.uint8(bs, data[1]) -- menuId
|
141 |
+
bswrite.bool32(bs, data[5]) -- twoColumns
|
142 |
+
bswrite.fixedString32(bs, data[2]) -- title
|
143 |
+
bswrite.float(bs, data[3]) -- x
|
144 |
+
bswrite.float(bs, data[4]) -- y
|
145 |
+
-- columns width
|
146 |
+
bswrite.float(bs, columns[1].width)
|
147 |
+
if data[5] then
|
148 |
+
bswrite.float(bs, columns[2].width)
|
149 |
+
end
|
150 |
+
bswrite.bool32(bs, data[8]) -- menu
|
151 |
+
-- rows
|
152 |
+
for i = 1, 12 do
|
153 |
+
bswrite.int32(bs, data[7][i])
|
154 |
+
end
|
155 |
+
-- columns
|
156 |
+
for i = 1, (data[5] and 2 or 1) do
|
157 |
+
bswrite.fixedString32(bs, columns[i].title)
|
158 |
+
bswrite.uint8(bs, #columns[i].text)
|
159 |
+
for r, t in ipairs(columns[i].text) do
|
160 |
+
bswrite.fixedString32(bs, t)
|
161 |
+
end
|
162 |
+
end
|
163 |
+
end
|
164 |
+
|
165 |
+
--- onMarkersSync
|
166 |
+
function handler.packet_markers_sync_reader(bs)
|
167 |
+
local markers = {}
|
168 |
+
local players = bsread.int32(bs)
|
169 |
+
for i = 1, players do
|
170 |
+
local playerId = bsread.uint16(bs)
|
171 |
+
local active = bsread.bool(bs)
|
172 |
+
if active then
|
173 |
+
local vector3d = require 'vector3d'
|
174 |
+
local x, y, z = bsread.int16(bs), bsread.int16(bs), bsread.int16(bs)
|
175 |
+
table.insert(markers, {playerId = playerId, active = true, coords = vector3d(x, y, z)})
|
176 |
+
else
|
177 |
+
table.insert(markers, {playerId = playerId, active = false})
|
178 |
+
end
|
179 |
+
end
|
180 |
+
return {markers}
|
181 |
+
end
|
182 |
+
|
183 |
+
function handler.packet_markers_sync_writer(bs, data)
|
184 |
+
bswrite.int32(bs, #data)
|
185 |
+
for i = 1, #data do
|
186 |
+
local it = data[i]
|
187 |
+
bswrite.uint16(bs, it.playerId)
|
188 |
+
bswrite.bool(bs, it.active)
|
189 |
+
if it.active then
|
190 |
+
bswrite.uint16(bs, it.coords.x)
|
191 |
+
bswrite.uint16(bs, it.coords.y)
|
192 |
+
bswrite.uint16(bs, it.coords.z)
|
193 |
+
end
|
194 |
+
end
|
195 |
+
end
|
196 |
+
|
197 |
+
--- onPlayerSync
|
198 |
+
function handler.packet_player_sync_reader(bs)
|
199 |
+
local has_value = bsread.bool
|
200 |
+
local data = {}
|
201 |
+
local playerId = bsread.uint16(bs)
|
202 |
+
if has_value(bs) then data.leftRightKeys = bsread.uint16(bs) end
|
203 |
+
if has_value(bs) then data.upDownKeys = bsread.uint16(bs) end
|
204 |
+
data.keysData = bsread.uint16(bs)
|
205 |
+
data.position = bsread.vector3d(bs)
|
206 |
+
data.quaternion = bsread.normQuat(bs)
|
207 |
+
data.health, data.armor = utils.decompress_health_and_armor(bsread.uint8(bs))
|
208 |
+
data.weapon = bsread.uint8(bs)
|
209 |
+
data.specialAction = bsread.uint8(bs)
|
210 |
+
data.moveSpeed = bsread.compressedVector(bs)
|
211 |
+
if has_value(bs) then
|
212 |
+
data.surfingVehicleId = bsread.uint16(bs)
|
213 |
+
data.surfingOffsets = bsread.vector3d(bs)
|
214 |
+
end
|
215 |
+
if has_value(bs) then
|
216 |
+
data.animationId = bsread.uint16(bs)
|
217 |
+
data.animationFlags = bsread.uint16(bs)
|
218 |
+
end
|
219 |
+
return {playerId, data}
|
220 |
+
end
|
221 |
+
|
222 |
+
function handler.packet_player_sync_writer(bs, data)
|
223 |
+
local playerId = data[1]
|
224 |
+
local data = data[2]
|
225 |
+
bswrite.uint16(bs, playerId)
|
226 |
+
bswrite.bool(bs, data.leftRightKeys ~= nil)
|
227 |
+
if data.leftRightKeys then bswrite.uint16(bs, data.leftRightKeys) end
|
228 |
+
bswrite.bool(bs, data.upDownKeys ~= nil)
|
229 |
+
if data.upDownKeys then bswrite.uint16(bs, data.upDownKeys) end
|
230 |
+
bswrite.uint16(bs, data.keysData)
|
231 |
+
bswrite.vector3d(bs, data.position)
|
232 |
+
bswrite.normQuat(bs, data.quaternion)
|
233 |
+
bswrite.uint8(bs, utils.compress_health_and_armor(data.health, data.armor))
|
234 |
+
bswrite.uint8(bs, data.weapon)
|
235 |
+
bswrite.uint8(bs, data.specialAction)
|
236 |
+
bswrite.compressedVector(bs, data.moveSpeed)
|
237 |
+
bswrite.bool(bs, data.surfingVehicleId ~= nil)
|
238 |
+
if data.surfingVehicleId then
|
239 |
+
bswrite.uint16(bs, data.surfingVehicleId)
|
240 |
+
bswrite.vector3d(bs, data.surfingOffsets)
|
241 |
+
end
|
242 |
+
bswrite.bool(bs, data.animationId ~= nil)
|
243 |
+
if data.animationId then
|
244 |
+
bswrite.uint16(bs, data.animationId)
|
245 |
+
bswrite.uint16(bs, data.animationFlags)
|
246 |
+
end
|
247 |
+
end
|
248 |
+
|
249 |
+
--- onVehicleSync
|
250 |
+
function handler.packet_vehicle_sync_reader(bs)
|
251 |
+
local data = {}
|
252 |
+
local playerId = bsread.uint16(bs)
|
253 |
+
local vehicleId = bsread.uint16(bs)
|
254 |
+
data.leftRightKeys = bsread.uint16(bs)
|
255 |
+
data.upDownKeys = bsread.uint16(bs)
|
256 |
+
data.keysData = bsread.uint16(bs)
|
257 |
+
data.quaternion = bsread.normQuat(bs)
|
258 |
+
data.position = bsread.vector3d(bs)
|
259 |
+
data.moveSpeed = bsread.compressedVector(bs)
|
260 |
+
data.vehicleHealth = bsread.uint16(bs)
|
261 |
+
data.playerHealth, data.armor = utils.decompress_health_and_armor(bsread.uint8(bs))
|
262 |
+
data.currentWeapon = bsread.uint8(bs)
|
263 |
+
data.siren = bsread.bool(bs)
|
264 |
+
data.landingGear = bsread.bool(bs)
|
265 |
+
if bsread.bool(bs) then
|
266 |
+
data.trainSpeed = bsread.int32(bs)
|
267 |
+
end
|
268 |
+
if bsread.bool(bs) then
|
269 |
+
data.trailerId = bsread.uint16(bs)
|
270 |
+
end
|
271 |
+
return {playerId, vehicleId, data}
|
272 |
+
end
|
273 |
+
|
274 |
+
function handler.packet_vehicle_sync_writer(bs, data)
|
275 |
+
local playerId = data[1]
|
276 |
+
local vehicleId = data[2]
|
277 |
+
local data = data[3]
|
278 |
+
bswrite.uint16(bs, playerId)
|
279 |
+
bswrite.uint16(bs, vehicleId)
|
280 |
+
bswrite.uint16(bs, data.leftRightKeys)
|
281 |
+
bswrite.uint16(bs, data.upDownKeys)
|
282 |
+
bswrite.uint16(bs, data.keysData)
|
283 |
+
bswrite.normQuat(bs, data.quaternion)
|
284 |
+
bswrite.vector3d(bs, data.position)
|
285 |
+
bswrite.compressedVector(bs, data.moveSpeed)
|
286 |
+
bswrite.uint16(bs, data.vehicleHealth)
|
287 |
+
bswrite.uint8(bs, utils.compress_health_and_armor(data.playerHealth, data.armor))
|
288 |
+
bswrite.uint8(bs, data.currentWeapon)
|
289 |
+
bswrite.bool(bs, data.siren)
|
290 |
+
bswrite.bool(bs, data.landingGear)
|
291 |
+
bswrite.bool(bs, data.trainSpeed ~= nil)
|
292 |
+
if data.trainSpeed ~= nil then
|
293 |
+
bswrite.int32(bs, data.trainSpeed)
|
294 |
+
end
|
295 |
+
bswrite.bool(bs, data.trailerId ~= nil)
|
296 |
+
if data.trailerId ~= nil then
|
297 |
+
bswrite.uint16(bs, data.trailerId)
|
298 |
+
end
|
299 |
+
end
|
300 |
+
|
301 |
+
--- onVehicleStreamIn
|
302 |
+
function handler.rpc_vehicle_stream_in_reader(bs)
|
303 |
+
local data = {modSlots = {}}
|
304 |
+
local vehicleId = bsread.uint16(bs)
|
305 |
+
data.type = bsread.int32(bs)
|
306 |
+
data.position = bsread.vector3d(bs)
|
307 |
+
data.rotation = bsread.float(bs)
|
308 |
+
data.bodyColor1 = bsread.uint8(bs)
|
309 |
+
data.bodyColor2 = bsread.uint8(bs)
|
310 |
+
data.health = bsread.float(bs)
|
311 |
+
data.interiorId = bsread.uint8(bs)
|
312 |
+
data.doorDamageStatus = bsread.int32(bs)
|
313 |
+
data.panelDamageStatus = bsread.int32(bs)
|
314 |
+
data.lightDamageStatus = bsread.uint8(bs)
|
315 |
+
data.tireDamageStatus = bsread.uint8(bs)
|
316 |
+
data.addSiren = bsread.uint8(bs)
|
317 |
+
for i = 1, 14 do
|
318 |
+
data.modSlots[i] = bsread.uint8(bs)
|
319 |
+
end
|
320 |
+
data.paintJob = bsread.uint8(bs)
|
321 |
+
data.interiorColor1 = bsread.int32(bs)
|
322 |
+
data.interiorColor2 = bsread.int32(bs)
|
323 |
+
return {vehicleId, data}
|
324 |
+
end
|
325 |
+
|
326 |
+
function handler.rpc_vehicle_stream_in_writer(bs, data)
|
327 |
+
local vehicleId = data[1]
|
328 |
+
local data = data[2]
|
329 |
+
bswrite.uint16(bs, vehicleId)
|
330 |
+
bswrite.int32(bs, data.type)
|
331 |
+
bswrite.vector3d(bs, data.position)
|
332 |
+
bswrite.float(bs, data.rotation)
|
333 |
+
bswrite.uint8(bs, data.bodyColor1)
|
334 |
+
bswrite.uint8(bs, data.bodyColor2)
|
335 |
+
bswrite.float(bs, data.health)
|
336 |
+
bswrite.uint8(bs, data.interiorId)
|
337 |
+
bswrite.int32(bs, data.doorDamageStatus)
|
338 |
+
bswrite.int32(bs, data.panelDamageStatus)
|
339 |
+
bswrite.uint8(bs, data.lightDamageStatus)
|
340 |
+
bswrite.uint8(bs, data.tireDamageStatus)
|
341 |
+
bswrite.uint8(bs, data.addSiren)
|
342 |
+
for i = 1, 14 do
|
343 |
+
bswrite.uint8(bs, data.modSlots[i])
|
344 |
+
end
|
345 |
+
bswrite.uint8(bs, data.paintJob)
|
346 |
+
bswrite.int32(bs, data.interiorColor1)
|
347 |
+
bswrite.int32(bs, data.interiorColor2)
|
348 |
+
end
|
349 |
+
|
350 |
+
local MATERIAL_TYPE = {
|
351 |
+
NONE = 0,
|
352 |
+
TEXTURE = 1,
|
353 |
+
TEXT = 2,
|
354 |
+
}
|
355 |
+
|
356 |
+
local function read_object_material(bs)
|
357 |
+
local data = {}
|
358 |
+
data.materialId = bsread.uint8(bs)
|
359 |
+
data.modelId = bsread.uint16(bs)
|
360 |
+
data.libraryName = bsread.string8(bs)
|
361 |
+
data.textureName = bsread.string8(bs)
|
362 |
+
data.color = bsread.int32(bs)
|
363 |
+
data.type = MATERIAL_TYPE.TEXTURE
|
364 |
+
return data
|
365 |
+
end
|
366 |
+
|
367 |
+
local function write_object_material(bs, data)
|
368 |
+
bswrite.uint8(bs, data.type)
|
369 |
+
bswrite.uint8(bs, data.materialId)
|
370 |
+
bswrite.uint16(bs, data.modelId)
|
371 |
+
bswrite.string8(bs, data.libraryName)
|
372 |
+
bswrite.string8(bs, data.textureName)
|
373 |
+
bswrite.int32(bs, data.color)
|
374 |
+
end
|
375 |
+
|
376 |
+
local function read_object_material_text(bs)
|
377 |
+
local data = {}
|
378 |
+
data.materialId = bsread.uint8(bs)
|
379 |
+
data.materialSize = bsread.uint8(bs)
|
380 |
+
data.fontName = bsread.string8(bs)
|
381 |
+
data.fontSize = bsread.uint8(bs)
|
382 |
+
data.bold = bsread.uint8(bs)
|
383 |
+
data.fontColor = bsread.int32(bs)
|
384 |
+
data.backGroundColor = bsread.int32(bs)
|
385 |
+
data.align = bsread.uint8(bs)
|
386 |
+
data.text = bsread.encodedString2048(bs)
|
387 |
+
data.type = MATERIAL_TYPE.TEXT
|
388 |
+
return data
|
389 |
+
end
|
390 |
+
|
391 |
+
local function write_object_material_text(bs, data)
|
392 |
+
bswrite.uint8(bs, data.type)
|
393 |
+
bswrite.uint8(bs, data.materialId)
|
394 |
+
bswrite.uint8(bs, data.materialSize)
|
395 |
+
bswrite.string8(bs, data.fontName)
|
396 |
+
bswrite.uint8(bs, data.fontSize)
|
397 |
+
bswrite.uint8(bs, data.bold)
|
398 |
+
bswrite.int32(bs, data.fontColor)
|
399 |
+
bswrite.int32(bs, data.backGroundColor)
|
400 |
+
bswrite.uint8(bs, data.align)
|
401 |
+
bswrite.encodedString2048(bs, data.text)
|
402 |
+
end
|
403 |
+
|
404 |
+
--- onSetObjectMaterial
|
405 |
+
function handler.rpc_set_object_material_reader(bs)
|
406 |
+
local objectId = bsread.uint16(bs)
|
407 |
+
local materialType = bsread.uint8(bs)
|
408 |
+
local material
|
409 |
+
if materialType == MATERIAL_TYPE.TEXTURE then
|
410 |
+
material = read_object_material(bs)
|
411 |
+
elseif materialType == MATERIAL_TYPE.TEXT then
|
412 |
+
material = read_object_material_text(bs)
|
413 |
+
end
|
414 |
+
local ev = materialType == MATERIAL_TYPE.TEXTURE and 'onSetObjectMaterial' or 'onSetObjectMaterialText'
|
415 |
+
return ev, {objectId, material}
|
416 |
+
end
|
417 |
+
|
418 |
+
function handler.rpc_set_object_material_writer(bs, data)
|
419 |
+
local objectId = data[1]
|
420 |
+
local mat = data[2]
|
421 |
+
bswrite.uint16(bs, objectId)
|
422 |
+
if mat.type == MATERIAL_TYPE.TEXTURE then
|
423 |
+
write_object_material(bs, mat)
|
424 |
+
elseif mat.type == MATERIAL_TYPE.TEXT then
|
425 |
+
write_object_material_text(bs, mat)
|
426 |
+
end
|
427 |
+
end
|
428 |
+
|
429 |
+
--- onCreateObject
|
430 |
+
function handler.rpc_create_object_reader(bs)
|
431 |
+
local data = {materials = {}, materialText = {}}
|
432 |
+
local objectId = bsread.uint16(bs)
|
433 |
+
data.modelId = bsread.int32(bs)
|
434 |
+
data.position = bsread.vector3d(bs)
|
435 |
+
data.rotation = bsread.vector3d(bs)
|
436 |
+
data.drawDistance = bsread.float(bs)
|
437 |
+
data.noCameraCol = bsread.bool8(bs)
|
438 |
+
data.attachToVehicleId = bsread.uint16(bs)
|
439 |
+
data.attachToObjectId = bsread.uint16(bs)
|
440 |
+
if data.attachToVehicleId ~= 0xFFFF or data.attachToObjectId ~= 0xFFFF then
|
441 |
+
data.attachOffsets = bsread.vector3d(bs)
|
442 |
+
data.attachRotation = bsread.vector3d(bs)
|
443 |
+
data.syncRotation = bsread.bool8(bs)
|
444 |
+
end
|
445 |
+
data.texturesCount = bsread.uint8(bs)
|
446 |
+
while raknetBitStreamGetNumberOfUnreadBits(bs) >= 8 do
|
447 |
+
local materialType = bsread.uint8(bs)
|
448 |
+
if materialType == MATERIAL_TYPE.TEXTURE then
|
449 |
+
table.insert(data.materials, read_object_material(bs))
|
450 |
+
elseif materialType == MATERIAL_TYPE.TEXT then
|
451 |
+
table.insert(data.materialText, read_object_material_text(bs))
|
452 |
+
end
|
453 |
+
end
|
454 |
+
data.materials_text = data.materialText -- obsolete
|
455 |
+
return {objectId, data}
|
456 |
+
end
|
457 |
+
|
458 |
+
function handler.rpc_create_object_writer(bs, data)
|
459 |
+
local objectId = data[1]
|
460 |
+
local data = data[2]
|
461 |
+
bswrite.uint16(bs, objectId)
|
462 |
+
bswrite.int32(bs, data.modelId)
|
463 |
+
bswrite.vector3d(bs, data.position)
|
464 |
+
bswrite.vector3d(bs, data.rotation)
|
465 |
+
bswrite.float(bs, data.drawDistance)
|
466 |
+
bswrite.bool8(bs, data.noCameraCol)
|
467 |
+
bswrite.uint16(bs, data.attachToVehicleId)
|
468 |
+
bswrite.uint16(bs, data.attachToObjectId)
|
469 |
+
if data.attachToVehicleId ~= 0xFFFF or data.attachToObjectId ~= 0xFFFF then
|
470 |
+
bswrite.vector3d(bs, data.attachOffsets)
|
471 |
+
bswrite.vector3d(bs, data.attachRotation)
|
472 |
+
bswrite.bool8(bs, data.syncRotation)
|
473 |
+
end
|
474 |
+
bswrite.uint8(bs, data.texturesCount)
|
475 |
+
for _, it in ipairs(data.materials) do
|
476 |
+
write_object_material(bs, it)
|
477 |
+
end
|
478 |
+
for _, it in ipairs(data.materialText) do
|
479 |
+
write_object_material_text(bs, it)
|
480 |
+
end
|
481 |
+
end
|
482 |
+
|
483 |
+
function handler.rpc_update_scores_and_pings_reader(bs)
|
484 |
+
local data = {}
|
485 |
+
for i = 1, raknetBitStreamGetNumberOfBytesUsed(bs) / 10 do
|
486 |
+
local playerId = bsread.uint16(bs)
|
487 |
+
local playerScore = bsread.int32(bs)
|
488 |
+
local playerPing = bsread.int32(bs)
|
489 |
+
data[playerId] = {score = playerScore, ping = playerPing}
|
490 |
+
end
|
491 |
+
return {data}
|
492 |
+
end
|
493 |
+
|
494 |
+
function handler.rpc_update_scores_and_pings_writer(bs, data)
|
495 |
+
for id, info in pairs(data[1]) do
|
496 |
+
bswrite.uint16(bs, id)
|
497 |
+
bswrite.int32(bs, info.score)
|
498 |
+
bswrite.int32(bs, info.ping)
|
499 |
+
end
|
500 |
+
end
|
501 |
+
|
502 |
+
function handler.packet_weapons_update_reader(bs)
|
503 |
+
local playerTarget = bsread.uint16(bs)
|
504 |
+
local actorTarget = bsread.uint16(bs)
|
505 |
+
local weapons = {}
|
506 |
+
local count = raknetBitStreamGetNumberOfUnreadBits(bs) / 32
|
507 |
+
for i = 1, count do
|
508 |
+
local slot = bsread.uint8(bs)
|
509 |
+
local weapon = bsread.uint8(bs)
|
510 |
+
local ammo = bsread.uint16(bs)
|
511 |
+
weapons[i] = {slot = slot, weapon = weapon, ammo = ammo}
|
512 |
+
end
|
513 |
+
return {playerTarget, actorTarget, weapons}
|
514 |
+
end
|
515 |
+
|
516 |
+
function handler.packet_weapons_update_writer(bs, data)
|
517 |
+
bswrite.uint16(bs, data[1])
|
518 |
+
bswrite.uint16(bs, data[2])
|
519 |
+
for i, weap in ipairs(data[3]) do
|
520 |
+
bswrite.uint8(bs, weap.slot)
|
521 |
+
bswrite.uint8(bs, weap.weapon)
|
522 |
+
bswrite.uint16(bs, weap.ammo)
|
523 |
+
end
|
524 |
+
end
|
525 |
+
|
526 |
+
return handler
|
raknet.lua
CHANGED
@@ -1,700 +1,236 @@
|
|
1 |
-
--
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
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)
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local mod =
|
7 |
+
{
|
8 |
+
MODULEINFO = {
|
9 |
+
name = 'samp.raknet',
|
10 |
+
version = 2
|
11 |
+
}
|
12 |
+
}
|
13 |
+
require 'sampfuncs'
|
14 |
+
|
15 |
+
mod.RPC = {
|
16 |
+
CLICKPLAYER = RPC_CLICKPLAYER,
|
17 |
+
CLIENTJOIN = RPC_CLIENTJOIN,
|
18 |
+
ENTERVEHICLE = RPC_ENTERVEHICLE,
|
19 |
+
SCRIPTCASH = RPC_SCRIPTCASH,
|
20 |
+
SERVERCOMMAND = RPC_SERVERCOMMAND,
|
21 |
+
SPAWN = RPC_SPAWN,
|
22 |
+
DEATH = RPC_DEATH,
|
23 |
+
NPCJOIN = RPC_NPCJOIN,
|
24 |
+
DIALOGRESPONSE = RPC_DIALOGRESPONSE,
|
25 |
+
CLICKTEXTDRAW = RPC_CLICKTEXTDRAW,
|
26 |
+
SCMEVENT = RPC_SCMEVENT,
|
27 |
+
WEAPONPICKUPDESTROY = RPC_WEAPONPICKUPDESTROY,
|
28 |
+
CHAT = RPC_CHAT,
|
29 |
+
SRVNETSTATS = RPC_SRVNETSTATS,
|
30 |
+
CLIENTCHECK = RPC_CLIENTCHECK,
|
31 |
+
DAMAGEVEHICLE = RPC_DAMAGEVEHICLE,
|
32 |
+
GIVETAKEDAMAGE = RPC_GIVETAKEDAMAGE,
|
33 |
+
EDITATTACHEDOBJECT = RPC_EDITATTACHEDOBJECT,
|
34 |
+
EDITOBJECT = RPC_EDITOBJECT,
|
35 |
+
SETINTERIORID = RPC_SETINTERIORID,
|
36 |
+
MAPMARKER = RPC_MAPMARKER,
|
37 |
+
REQUESTCLASS = RPC_REQUESTCLASS,
|
38 |
+
REQUESTSPAWN = RPC_REQUESTSPAWN,
|
39 |
+
PICKEDUPPICKUP = RPC_PICKEDUPPICKUP,
|
40 |
+
MENUSELECT = RPC_MENUSELECT,
|
41 |
+
VEHICLEDESTROYED = RPC_VEHICLEDESTROYED,
|
42 |
+
MENUQUIT = RPC_MENUQUIT,
|
43 |
+
EXITVEHICLE = RPC_EXITVEHICLE,
|
44 |
+
UPDATESCORESPINGSIPS = RPC_UPDATESCORESPINGSIPS,
|
45 |
+
CAMTARGETUPDATE = 168,
|
46 |
+
GIVEACTORDAMAGE = 177,
|
47 |
+
|
48 |
+
CONNECTIONREJECTED = 130,
|
49 |
+
SETPLAYERNAME = RPC_SCRSETPLAYERNAME,
|
50 |
+
SETPLAYERPOS = RPC_SCRSETPLAYERPOS,
|
51 |
+
SETPLAYERPOSFINDZ = RPC_SCRSETPLAYERPOSFINDZ,
|
52 |
+
SETPLAYERHEALTH = RPC_SCRSETPLAYERHEALTH,
|
53 |
+
TOGGLEPLAYERCONTROLLABLE = RPC_SCRTOGGLEPLAYERCONTROLLABLE,
|
54 |
+
PLAYSOUND = RPC_SCRPLAYSOUND,
|
55 |
+
SETPLAYERWORLDBOUNDS = RPC_SCRSETPLAYERWORLDBOUNDS,
|
56 |
+
GIVEPLAYERMONEY = RPC_SCRGIVEPLAYERMONEY,
|
57 |
+
SETPLAYERFACINGANGLE = RPC_SCRSETPLAYERFACINGANGLE,
|
58 |
+
RESETPLAYERMONEY = RPC_SCRRESETPLAYERMONEY,
|
59 |
+
RESETPLAYERWEAPONS = RPC_SCRRESETPLAYERWEAPONS,
|
60 |
+
GIVEPLAYERWEAPON = RPC_SCRGIVEPLAYERWEAPON,
|
61 |
+
SETVEHICLEPARAMSEX = RPC_SCRSETVEHICLEPARAMSEX,
|
62 |
+
CANCELEDIT = RPC_SCRCANCELEDIT,
|
63 |
+
SETPLAYERTIME = RPC_SCRSETPLAYERTIME,
|
64 |
+
TOGGLECLOCK = RPC_SCRTOGGLECLOCK,
|
65 |
+
WORLDPLAYERADD = RPC_SCRWORLDPLAYERADD,
|
66 |
+
SETPLAYERSHOPNAME = RPC_SCRSETPLAYERSHOPNAME,
|
67 |
+
SETPLAYERSKILLLEVEL = RPC_SCRSETPLAYERSKILLLEVEL,
|
68 |
+
SETPLAYERDRUNKLEVEL = RPC_SCRSETPLAYERDRUNKLEVEL,
|
69 |
+
CREATE3DTEXTLABEL = RPC_SCRCREATE3DTEXTLABEL,
|
70 |
+
DISABLECHECKPOINT = RPC_SCRDISABLECHECKPOINT,
|
71 |
+
SETRACECHECKPOINT = RPC_SCRSETRACECHECKPOINT,
|
72 |
+
DISABLERACECHECKPOINT = RPC_SCRDISABLERACECHECKPOINT,
|
73 |
+
GAMEMODERESTART = RPC_SCRGAMEMODERESTART,
|
74 |
+
PLAYAUDIOSTREAM = RPC_SCRPLAYAUDIOSTREAM,
|
75 |
+
STOPAUDIOSTREAM = RPC_SCRSTOPAUDIOSTREAM,
|
76 |
+
REMOVEBUILDINGFORPLAYER = RPC_SCRREMOVEBUILDINGFORPLAYER,
|
77 |
+
CREATEOBJECT = RPC_SCRCREATEOBJECT,
|
78 |
+
SETOBJECTPOS = RPC_SCRSETOBJECTPOS,
|
79 |
+
SETOBJECTROT = RPC_SCRSETOBJECTROT,
|
80 |
+
DESTROYOBJECT = RPC_SCRDESTROYOBJECT,
|
81 |
+
DEATHMESSAGE = RPC_SCRDEATHMESSAGE,
|
82 |
+
SETPLAYERMAPICON = RPC_SCRSETPLAYERMAPICON,
|
83 |
+
REMOVEVEHICLECOMPONENT = RPC_SCRREMOVEVEHICLECOMPONENT,
|
84 |
+
CHATBUBBLE = RPC_SCRCHATBUBBLE,
|
85 |
+
UPDATETIME = RPC_SCRSOMEUPDATE,
|
86 |
+
SHOWDIALOG = RPC_SCRSHOWDIALOG,
|
87 |
+
DESTROYPICKUP = RPC_SCRDESTROYPICKUP,
|
88 |
+
LINKVEHICLETOINTERIOR = RPC_SCRLINKVEHICLETOINTERIOR,
|
89 |
+
SETPLAYERARMOUR = RPC_SCRSETPLAYERARMOUR,
|
90 |
+
SETPLAYERARMEDWEAPON = RPC_SCRSETPLAYERARMEDWEAPON,
|
91 |
+
SETSPAWNINFO = RPC_SCRSETSPAWNINFO,
|
92 |
+
SETPLAYERTEAM = RPC_SCRSETPLAYERTEAM,
|
93 |
+
PUTPLAYERINVEHICLE = RPC_SCRPUTPLAYERINVEHICLE,
|
94 |
+
REMOVEPLAYERFROMVEHICLE = RPC_SCRREMOVEPLAYERFROMVEHICLE,
|
95 |
+
SETPLAYERCOLOR = RPC_SCRSETPLAYERCOLOR,
|
96 |
+
DISPLAYGAMETEXT = RPC_SCRDISPLAYGAMETEXT,
|
97 |
+
FORCECLASSSELECTION = RPC_SCRFORCECLASSSELECTION,
|
98 |
+
ATTACHOBJECTTOPLAYER = RPC_SCRATTACHOBJECTTOPLAYER,
|
99 |
+
INITMENU = RPC_SCRINITMENU,
|
100 |
+
SHOWMENU = RPC_SCRSHOWMENU,
|
101 |
+
HIDEMENU = RPC_SCRHIDEMENU,
|
102 |
+
CREATEEXPLOSION = RPC_SCRCREATEEXPLOSION,
|
103 |
+
SHOWPLAYERNAMETAGFORPLAYER = RPC_SCRSHOWPLAYERNAMETAGFORPLAYER,
|
104 |
+
ATTACHCAMERATOOBJECT = RPC_SCRATTACHCAMERATOOBJECT,
|
105 |
+
INTERPOLATECAMERA = RPC_SCRINTERPOLATECAMERA,
|
106 |
+
SETOBJECTMATERIAL = RPC_SCRSETOBJECTMATERIAL,
|
107 |
+
GANGZONESTOPFLASH = RPC_SCRGANGZONESTOPFLASH,
|
108 |
+
APPLYANIMATION = RPC_SCRAPPLYANIMATION,
|
109 |
+
CLEARANIMATIONS = RPC_SCRCLEARANIMATIONS,
|
110 |
+
SETPLAYERSPECIALACTION = RPC_SCRSETPLAYERSPECIALACTION,
|
111 |
+
SETPLAYERFIGHTINGSTYLE = RPC_SCRSETPLAYERFIGHTINGSTYLE,
|
112 |
+
SETPLAYERVELOCITY = RPC_SCRSETPLAYERVELOCITY,
|
113 |
+
SETVEHICLEVELOCITY = RPC_SCRSETVEHICLEVELOCITY,
|
114 |
+
CLIENTMESSAGE = RPC_SCRCLIENTMESSAGE,
|
115 |
+
SETWORLDTIME = RPC_SCRSETWORLDTIME,
|
116 |
+
CREATEPICKUP = RPC_SCRCREATEPICKUP,
|
117 |
+
MOVEOBJECT = RPC_SCRMOVEOBJECT,
|
118 |
+
ENABLESTUNTBONUSFORPLAYER = RPC_SCRENABLESTUNTBONUSFORPLAYER,
|
119 |
+
TEXTDRAWSETSTRING = RPC_SCRTEXTDRAWSETSTRING,
|
120 |
+
SETCHECKPOINT = RPC_SCRSETCHECKPOINT,
|
121 |
+
GANGZONECREATE = RPC_SCRGANGZONECREATE,
|
122 |
+
PLAYCRIMEREPORT = RPC_SCRPLAYCRIMEREPORT,
|
123 |
+
SETPLAYERATTACHEDOBJECT = RPC_SCRSETPLAYERATTACHEDOBJECT,
|
124 |
+
GANGZONEDESTROY = RPC_SCRGANGZONEDESTROY,
|
125 |
+
GANGZONEFLASH = RPC_SCRGANGZONEFLASH,
|
126 |
+
STOPOBJECT = RPC_SCRSTOPOBJECT,
|
127 |
+
SETNUMBERPLATE = RPC_SCRSETNUMBERPLATE,
|
128 |
+
TOGGLEPLAYERSPECTATING = RPC_SCRTOGGLEPLAYERSPECTATING,
|
129 |
+
PLAYERSPECTATEPLAYER = RPC_SCRPLAYERSPECTATEPLAYER,
|
130 |
+
PLAYERSPECTATEVEHICLE = RPC_SCRPLAYERSPECTATEVEHICLE,
|
131 |
+
SETPLAYERWANTEDLEVEL = RPC_SCRSETPLAYERWANTEDLEVEL,
|
132 |
+
SHOWTEXTDRAW = RPC_SCRSHOWTEXTDRAW,
|
133 |
+
TEXTDRAWHIDEFORPLAYER = RPC_SCRTEXTDRAWHIDEFORPLAYER,
|
134 |
+
SERVERJOIN = RPC_SCRSERVERJOIN,
|
135 |
+
SERVERQUIT = RPC_SCRSERVERQUIT,
|
136 |
+
INITGAME = RPC_SCRINITGAME,
|
137 |
+
REMOVEPLAYERMAPICON = RPC_SCRREMOVEPLAYERMAPICON,
|
138 |
+
SETPLAYERAMMO = RPC_SCRSETPLAYERAMMO,
|
139 |
+
SETGRAVITY = RPC_SCRSETGRAVITY,
|
140 |
+
SETVEHICLEHEALTH = RPC_SCRSETVEHICLEHEALTH,
|
141 |
+
ATTACHTRAILERTOVEHICLE = RPC_SCRATTACHTRAILERTOVEHICLE,
|
142 |
+
DETACHTRAILERFROMVEHICLE = RPC_SCRDETACHTRAILERFROMVEHICLE,
|
143 |
+
SETWEATHER = RPC_SCRSETWEATHER,
|
144 |
+
SETPLAYERSKIN = RPC_SCRSETPLAYERSKIN,
|
145 |
+
SETPLAYERINTERIOR = RPC_SCRSETPLAYERINTERIOR,
|
146 |
+
SETPLAYERCAMERAPOS = RPC_SCRSETPLAYERCAMERAPOS,
|
147 |
+
SETPLAYERCAMERALOOKAT = RPC_SCRSETPLAYERCAMERALOOKAT,
|
148 |
+
SETVEHICLEPOS = RPC_SCRSETVEHICLEPOS,
|
149 |
+
SETVEHICLEZANGLE = RPC_SCRSETVEHICLEZANGLE,
|
150 |
+
SETVEHICLEPARAMSFORPLAYER = RPC_SCRSETVEHICLEPARAMSFORPLAYER,
|
151 |
+
SETCAMERABEHINDPLAYER = RPC_SCRSETCAMERABEHINDPLAYER,
|
152 |
+
WORLDPLAYERREMOVE = RPC_SCRWORLDPLAYERREMOVE,
|
153 |
+
WORLDVEHICLEADD = RPC_SCRWORLDVEHICLEADD,
|
154 |
+
WORLDVEHICLEREMOVE = RPC_SCRWORLDVEHICLEREMOVE,
|
155 |
+
WORLDPLAYERDEATH = RPC_SCRWORLDPLAYERDEATH,
|
156 |
+
CREATEACTOR = 171,
|
157 |
+
DESTROYACTOR = 172,
|
158 |
+
DESTROY3DTEXTLABEL = 58,
|
159 |
+
DESTROYWEAPONPICKUP = 151,
|
160 |
+
TOGGLECAMERATARGET = 170,
|
161 |
+
SELECTOBJECT = 27,
|
162 |
+
DISABLEVEHICLECOLLISIONS = 167,
|
163 |
+
TOGGLEWIDESCREEN = 111,
|
164 |
+
SETVEHICLETIRES = 98,
|
165 |
+
SETPLAYERDRUNKVISUALS = 92,
|
166 |
+
SETPLAYERDRUNKHANDLING = 150,
|
167 |
+
APPLYACTORANIMATION = 173,
|
168 |
+
CLEARACTORANIMATION = 174,
|
169 |
+
SETACTORROTATION = 175,
|
170 |
+
SETACTORPOSITION = 176,
|
171 |
+
SETACTORHEALTH = 178,
|
172 |
+
SETPLAYEROBJECTNOCAMCOL = 169,
|
173 |
+
|
174 |
+
-- Invalid. Retained only for backward compatibility.
|
175 |
+
ENTEREDITOBJECT = RPC_ENTEREDITOBJECT,
|
176 |
+
UPDATE3DTEXTLABEL = RPC_SCRUPDATE3DTEXTLABEL,
|
177 |
+
}
|
178 |
+
|
179 |
+
mod.PACKET = {
|
180 |
+
VEHICLE_SYNC = PACKET_VEHICLE_SYNC,
|
181 |
+
RCON_COMMAND = PACKET_RCON_COMMAND,
|
182 |
+
RCON_RESPONCE = PACKET_RCON_RESPONCE,
|
183 |
+
AIM_SYNC = PACKET_AIM_SYNC,
|
184 |
+
WEAPONS_UPDATE = PACKET_WEAPONS_UPDATE,
|
185 |
+
STATS_UPDATE = PACKET_STATS_UPDATE,
|
186 |
+
BULLET_SYNC = PACKET_BULLET_SYNC,
|
187 |
+
PLAYER_SYNC = PACKET_PLAYER_SYNC,
|
188 |
+
MARKERS_SYNC = PACKET_MARKERS_SYNC,
|
189 |
+
UNOCCUPIED_SYNC = PACKET_UNOCCUPIED_SYNC,
|
190 |
+
TRAILER_SYNC = PACKET_TRAILER_SYNC,
|
191 |
+
PASSENGER_SYNC = PACKET_PASSENGER_SYNC,
|
192 |
+
SPECTATOR_SYNC = PACKET_SPECTATOR_SYNC,
|
193 |
+
|
194 |
+
INTERNAL_PING = PACKET_INTERNAL_PING,
|
195 |
+
PING = PACKET_PING,
|
196 |
+
PING_OPEN_CONNECTIONS = PACKET_PING_OPEN_CONNECTIONS,
|
197 |
+
CONNECTED_PONG = PACKET_CONNECTED_PONG,
|
198 |
+
REQUEST_STATIC_DATA = PACKET_REQUEST_STATIC_DATA,
|
199 |
+
CONNECTION_REQUEST = PACKET_CONNECTION_REQUEST,
|
200 |
+
AUTHENTICATION = PACKET_AUTH_KEY,
|
201 |
+
BROADCAST_PINGS = PACKET_BROADCAST_PINGS,
|
202 |
+
SECURED_CONNECTION_RESPONSE = PACKET_SECURED_CONNECTION_RESPONSE,
|
203 |
+
SECURED_CONNECTION_CONFIRMATION = PACKET_SECURED_CONNECTION_CONFIRMATION,
|
204 |
+
RPC_MAPPING = PACKET_RPC_MAPPING,
|
205 |
+
SET_RANDOM_NUMBER_SEED = PACKET_SET_RANDOM_NUMBER_SEED,
|
206 |
+
RPC = PACKET_RPC,
|
207 |
+
RPC_REPLY = PACKET_RPC_REPLY,
|
208 |
+
DETECT_LOST_CONNECTIONS = PACKET_DETECT_LOST_CONNECTIONS,
|
209 |
+
OPEN_CONNECTION_REQUEST = PACKET_OPEN_CONNECTION_REQUEST,
|
210 |
+
OPEN_CONNECTION_REPLY = PACKET_OPEN_CONNECTION_REPLY,
|
211 |
+
CONNECTION_COOKIE = PACKET_CONNECTION_COOKIE,
|
212 |
+
RSA_PUBLIC_KEY_MISMATCH = PACKET_RSA_PUBLIC_KEY_MISMATCH,
|
213 |
+
CONNECTION_ATTEMPT_FAILED = PACKET_CONNECTION_ATTEMPT_FAILED,
|
214 |
+
NEW_INCOMING_CONNECTION = PACKET_NEW_INCOMING_CONNECTION,
|
215 |
+
NO_FREE_INCOMING_CONNECTIONS = PACKET_NO_FREE_INCOMING_CONNECTIONS,
|
216 |
+
DISCONNECTION_NOTIFICATION = PACKET_DISCONNECTION_NOTIFICATION,
|
217 |
+
CONNECTION_LOST = PACKET_CONNECTION_LOST,
|
218 |
+
CONNECTION_REQUEST_ACCEPTED = PACKET_CONNECTION_REQUEST_ACCEPTED,
|
219 |
+
INITIALIZE_ENCRYPTION = PACKET_INITIALIZE_ENCRYPTION,
|
220 |
+
CONNECTION_BANNED = PACKET_CONNECTION_BANNED,
|
221 |
+
INVALID_PASSWORD = PACKET_INVALID_PASSWORD,
|
222 |
+
MODIFIED_PACKET = PACKET_MODIFIED_PACKET,
|
223 |
+
PONG = PACKET_PONG,
|
224 |
+
TIMESTAMP = PACKET_TIMESTAMP,
|
225 |
+
RECEIVED_STATIC_DATA = PACKET_RECEIVED_STATIC_DATA,
|
226 |
+
REMOTE_DISCONNECTION_NOTIFICATION = PACKET_REMOTE_DISCONNECTION_NOTIFICATION,
|
227 |
+
REMOTE_CONNECTION_LOST = PACKET_REMOTE_CONNECTION_LOST,
|
228 |
+
REMOTE_NEW_INCOMING_CONNECTION = PACKET_REMOTE_NEW_INCOMING_CONNECTION,
|
229 |
+
REMOTE_EXISTING_CONNECTION = PACKET_REMOTE_EXISTING_CONNECTION,
|
230 |
+
REMOTE_STATIC_DATA = PACKET_REMOTE_STATIC_DATA,
|
231 |
+
ADVERTISE_SYSTEM = PACKET_ADVERTISE_SYSTEM,
|
232 |
+
|
233 |
+
AUTH_KEY = PACKET_AUTH_KEY,
|
234 |
+
}
|
235 |
+
|
236 |
+
return mod
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
synchronization.lua
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local mod =
|
7 |
+
{
|
8 |
+
MODULEINFO = {
|
9 |
+
name = 'samp.synchronization',
|
10 |
+
version = 2
|
11 |
+
}
|
12 |
+
}
|
13 |
+
local ffi = require 'ffi'
|
14 |
+
|
15 |
+
ffi.cdef[[
|
16 |
+
#pragma pack(push, 1)
|
17 |
+
|
18 |
+
typedef struct VectorXYZ {
|
19 |
+
float x, y, z;
|
20 |
+
} VectorXYZ;
|
21 |
+
|
22 |
+
typedef struct SampKeys {
|
23 |
+
uint8_t primaryFire : 1;
|
24 |
+
uint8_t horn_crouch : 1;
|
25 |
+
uint8_t secondaryFire_shoot : 1;
|
26 |
+
uint8_t accel_zoomOut : 1;
|
27 |
+
uint8_t enterExitCar : 1;
|
28 |
+
uint8_t decel_jump : 1;
|
29 |
+
uint8_t circleRight : 1;
|
30 |
+
uint8_t aim : 1;
|
31 |
+
uint8_t circleLeft : 1;
|
32 |
+
uint8_t landingGear_lookback : 1;
|
33 |
+
uint8_t unknown_walkSlow : 1;
|
34 |
+
uint8_t specialCtrlUp : 1;
|
35 |
+
uint8_t specialCtrlDown : 1;
|
36 |
+
uint8_t specialCtrlLeft : 1;
|
37 |
+
uint8_t specialCtrlRight : 1;
|
38 |
+
uint8_t _unknown : 1;
|
39 |
+
} SampKeys;
|
40 |
+
|
41 |
+
typedef struct PlayerSyncData {
|
42 |
+
uint16_t leftRightKeys;
|
43 |
+
uint16_t upDownKeys;
|
44 |
+
union {
|
45 |
+
uint16_t keysData;
|
46 |
+
SampKeys keys;
|
47 |
+
};
|
48 |
+
VectorXYZ position;
|
49 |
+
float quaternion[4];
|
50 |
+
uint8_t health;
|
51 |
+
uint8_t armor;
|
52 |
+
uint8_t weapon : 6;
|
53 |
+
uint8_t specialKey : 2;
|
54 |
+
uint8_t specialAction;
|
55 |
+
VectorXYZ moveSpeed;
|
56 |
+
VectorXYZ surfingOffsets;
|
57 |
+
uint16_t surfingVehicleId;
|
58 |
+
union {
|
59 |
+
struct {
|
60 |
+
uint16_t id;
|
61 |
+
uint8_t frameDelta;
|
62 |
+
union {
|
63 |
+
struct {
|
64 |
+
bool loop : 1;
|
65 |
+
bool lockX : 1;
|
66 |
+
bool lockY : 1;
|
67 |
+
bool freeze : 1;
|
68 |
+
uint8_t time : 2;
|
69 |
+
uint8_t _unused : 1;
|
70 |
+
bool regular : 1;
|
71 |
+
};
|
72 |
+
uint8_t value;
|
73 |
+
} flags;
|
74 |
+
} animation;
|
75 |
+
struct {
|
76 |
+
uint16_t animationId;
|
77 |
+
uint16_t animationFlags;
|
78 |
+
};
|
79 |
+
};
|
80 |
+
} PlayerSyncData;
|
81 |
+
|
82 |
+
typedef struct VehicleSyncData {
|
83 |
+
uint16_t vehicleId;
|
84 |
+
uint16_t leftRightKeys;
|
85 |
+
uint16_t upDownKeys;
|
86 |
+
union {
|
87 |
+
uint16_t keysData;
|
88 |
+
SampKeys keys;
|
89 |
+
};
|
90 |
+
float quaternion[4];
|
91 |
+
VectorXYZ position;
|
92 |
+
VectorXYZ moveSpeed;
|
93 |
+
float vehicleHealth;
|
94 |
+
uint8_t playerHealth;
|
95 |
+
uint8_t armor;
|
96 |
+
uint8_t currentWeapon : 6;
|
97 |
+
uint8_t specialKey : 2;
|
98 |
+
uint8_t siren;
|
99 |
+
uint8_t landingGearState;
|
100 |
+
uint16_t trailerId;
|
101 |
+
union {
|
102 |
+
float bikeLean;
|
103 |
+
float trainSpeed;
|
104 |
+
uint16_t hydraThrustAngle[2];
|
105 |
+
};
|
106 |
+
} VehicleSyncData;
|
107 |
+
|
108 |
+
typedef struct PassengerSyncData {
|
109 |
+
uint16_t vehicleId;
|
110 |
+
uint8_t seatId : 6;
|
111 |
+
bool driveBy : 1;
|
112 |
+
bool cuffed : 1;
|
113 |
+
uint8_t currentWeapon : 6;
|
114 |
+
uint8_t specialKey : 2;
|
115 |
+
uint8_t health;
|
116 |
+
uint8_t armor;
|
117 |
+
uint16_t leftRightKeys;
|
118 |
+
uint16_t upDownKeys;
|
119 |
+
union {
|
120 |
+
uint16_t keysData;
|
121 |
+
SampKeys keys;
|
122 |
+
};
|
123 |
+
VectorXYZ position;
|
124 |
+
} PassengerSyncData;
|
125 |
+
|
126 |
+
typedef struct UnoccupiedSyncData {
|
127 |
+
uint16_t vehicleId;
|
128 |
+
uint8_t seatId;
|
129 |
+
VectorXYZ roll;
|
130 |
+
VectorXYZ direction;
|
131 |
+
VectorXYZ position;
|
132 |
+
VectorXYZ moveSpeed;
|
133 |
+
VectorXYZ turnSpeed;
|
134 |
+
float vehicleHealth;
|
135 |
+
} UnoccupiedSyncData;
|
136 |
+
|
137 |
+
typedef struct TrailerSyncData {
|
138 |
+
uint16_t trailerId;
|
139 |
+
VectorXYZ position;
|
140 |
+
union {
|
141 |
+
struct {
|
142 |
+
float quaternion[4];
|
143 |
+
VectorXYZ moveSpeed;
|
144 |
+
VectorXYZ turnSpeed;
|
145 |
+
};
|
146 |
+
/* Invalid. Retained for backwards compatibility. */
|
147 |
+
struct {
|
148 |
+
VectorXYZ roll;
|
149 |
+
VectorXYZ direction;
|
150 |
+
VectorXYZ speed;
|
151 |
+
uint32_t unk;
|
152 |
+
};
|
153 |
+
};
|
154 |
+
} TrailerSyncData;
|
155 |
+
|
156 |
+
typedef struct SpectatorSyncData {
|
157 |
+
uint16_t leftRightKeys;
|
158 |
+
uint16_t upDownKeys;
|
159 |
+
union {
|
160 |
+
uint16_t keysData;
|
161 |
+
SampKeys keys;
|
162 |
+
};
|
163 |
+
VectorXYZ position;
|
164 |
+
} SpectatorSyncData;
|
165 |
+
|
166 |
+
typedef struct BulletSyncData {
|
167 |
+
uint8_t targetType;
|
168 |
+
uint16_t targetId;
|
169 |
+
VectorXYZ origin;
|
170 |
+
VectorXYZ target;
|
171 |
+
VectorXYZ center;
|
172 |
+
uint8_t weaponId;
|
173 |
+
} BulletSyncData;
|
174 |
+
|
175 |
+
typedef struct AimSyncData {
|
176 |
+
uint8_t camMode;
|
177 |
+
VectorXYZ camFront;
|
178 |
+
VectorXYZ camPos;
|
179 |
+
float aimZ;
|
180 |
+
uint8_t camExtZoom : 6;
|
181 |
+
uint8_t weaponState : 2;
|
182 |
+
uint8_t aspectRatio;
|
183 |
+
} AimSyncData;
|
184 |
+
|
185 |
+
#pragma pack(pop)
|
186 |
+
]]
|
187 |
+
|
188 |
+
assert(ffi.sizeof('VectorXYZ') == 12)
|
189 |
+
assert(ffi.sizeof('SampKeys') == 2)
|
190 |
+
assert(ffi.sizeof('PlayerSyncData') == 68)
|
191 |
+
assert(ffi.sizeof('VehicleSyncData') == 63)
|
192 |
+
assert(ffi.sizeof('PassengerSyncData') == 24)
|
193 |
+
assert(ffi.sizeof('UnoccupiedSyncData') == 67)
|
194 |
+
assert(ffi.sizeof('TrailerSyncData') == 54)
|
195 |
+
assert(ffi.sizeof('SpectatorSyncData') == 18)
|
196 |
+
assert(ffi.sizeof('BulletSyncData') == 40)
|
197 |
+
assert(ffi.sizeof('AimSyncData') == 31)
|
198 |
+
|
199 |
+
return mod
|
utils.lua
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- This file is part of the SAMP.Lua project.
|
2 |
+
-- Licensed under the MIT License.
|
3 |
+
-- Copyright (c) 2016, FYP @ BlastHack Team <blast.hk>
|
4 |
+
-- https://github.com/THE-FYP/SAMP.Lua
|
5 |
+
|
6 |
+
local ffi = require 'ffi'
|
7 |
+
local utils = {}
|
8 |
+
|
9 |
+
function utils.decompress_health_and_armor(hpAp)
|
10 |
+
local hp = math.min(bit.rshift(hpAp, 4) * 7, 100)
|
11 |
+
local armor = math.min(bit.band(hpAp, 0x0F) * 7, 100)
|
12 |
+
return hp, armor
|
13 |
+
end
|
14 |
+
|
15 |
+
function utils.compress_health_and_armor(health, armor)
|
16 |
+
local hp = health >= 100 and 0xF0 or bit.lshift(health / 7, 4)
|
17 |
+
local ap = armor >= 100 and 0x0F or bit.band(armor / 7, 0x0F)
|
18 |
+
return bit.bor(hp, ap)
|
19 |
+
end
|
20 |
+
|
21 |
+
function utils.create_sync_data(st)
|
22 |
+
require 'samp.synchronization'
|
23 |
+
return ffi.new(st)
|
24 |
+
end
|
25 |
+
|
26 |
+
function utils.read_sync_data(bs, st)
|
27 |
+
local dataStruct = utils.create_sync_data(st)
|
28 |
+
local ptr = tonumber(ffi.cast('intptr_t', ffi.cast('void*', dataStruct)))
|
29 |
+
raknetBitStreamReadBuffer(bs, ptr, ffi.sizeof(dataStruct))
|
30 |
+
return dataStruct
|
31 |
+
end
|
32 |
+
|
33 |
+
function utils.write_sync_data(bs, st, ffiobj)
|
34 |
+
require 'samp.synchronization'
|
35 |
+
local ptr = tonumber(ffi.cast('intptr_t', ffi.cast('void*', ffiobj)))
|
36 |
+
raknetBitStreamWriteBuffer(bs, ptr, ffi.sizeof(st))
|
37 |
+
end
|
38 |
+
|
39 |
+
function utils.process_outcoming_sync_data(bs, st)
|
40 |
+
local data = raknetBitStreamGetDataPtr(bs) + 1
|
41 |
+
require 'samp.synchronization'
|
42 |
+
return {ffi.cast(st .. '*', data)}
|
43 |
+
end
|
44 |
+
|
45 |
+
return utils
|