teeworlds 2.5.5 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{index.ts → index.d.ts} +6 -6
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/lib/MsgPacker.d.ts +11 -0
- package/lib/MsgPacker.js +1 -0
- package/lib/MsgPacker.js.map +1 -0
- package/lib/MsgUnpacker.d.ts +16 -0
- package/lib/MsgUnpacker.js +1 -0
- package/lib/MsgUnpacker.js.map +1 -0
- package/lib/UUIDManager.d.ts +27 -0
- package/lib/UUIDManager.js +1 -0
- package/lib/UUIDManager.js.map +1 -0
- package/lib/client.d.ts +135 -0
- package/lib/client.js +5 -4
- package/lib/client.js.map +1 -0
- package/lib/components/game.d.ts +32 -0
- package/lib/components/game.js +1 -0
- package/lib/components/game.js.map +1 -0
- package/lib/components/movement.d.ts +34 -0
- package/lib/components/movement.js +1 -0
- package/lib/components/movement.js.map +1 -0
- package/lib/components/rcon.d.ts +33 -0
- package/lib/components/rcon.js +1 -0
- package/lib/components/rcon.js.map +1 -0
- package/lib/components/snapshot.d.ts +59 -0
- package/lib/components/snapshot.js +1 -0
- package/lib/components/snapshot.js.map +1 -0
- package/lib/enums_types/protocol.d.ts +120 -0
- package/lib/enums_types/protocol.js +1 -0
- package/lib/enums_types/protocol.js.map +1 -0
- package/lib/huffman.d.ts +24 -0
- package/lib/huffman.js +1 -0
- package/lib/huffman.js.map +1 -0
- package/lib/snapshot.d.ts +49 -0
- package/lib/snapshot.js +1 -0
- package/lib/snapshot.js.map +1 -0
- package/package.json +21 -25
- package/docs/documentation.md +0 -371
- package/docs/examples/chat_bot.js +0 -25
- package/docs/examples/kill_on_freeze.js +0 -20
- package/lib/MsgPacker.ts +0 -45
- package/lib/MsgUnpacker.ts +0 -58
- package/lib/UUIDManager.ts +0 -45
- package/lib/client.ts +0 -947
- package/lib/components/game.ts +0 -133
- package/lib/components/movement.ts +0 -88
- package/lib/components/rcon.ts +0 -114
- package/lib/components/snapshot.ts +0 -187
- package/lib/enums_types/protocol.ts +0 -145
- package/lib/enums_types/types.d.ts +0 -236
- package/lib/huffman.ts +0 -226
- package/lib/snapshot.ts +0 -632
- package/tsconfig.json +0 -69
package/lib/snapshot.ts
DELETED
|
@@ -1,632 +0,0 @@
|
|
|
1
|
-
import { UUIDManager, createTwMD5Hash } from "./UUIDManager";
|
|
2
|
-
import { Client } from "./client";
|
|
3
|
-
import { MsgUnpacker } from "./MsgUnpacker";
|
|
4
|
-
import { SnapshotItemTypes, DeltaItem, DDNetItem, Item } from "./enums_types/types";
|
|
5
|
-
var decoder = new TextDecoder('utf-8');
|
|
6
|
-
|
|
7
|
-
const ___itemAppendix: {"type_id": number, "size": number, "name": string}[] = [ // only used for the events underneath. the actual itemAppendix below this is only used for size
|
|
8
|
-
{"type_id": 0, "size": 0, "name": "obj_ex"},
|
|
9
|
-
{"type_id": 1, "size": 10, "name": "obj_player_input"},
|
|
10
|
-
{"type_id": 2, "size": 6, "name": "obj_projectile"},
|
|
11
|
-
{"type_id": 3, "size": 5, "name": "obj_laser"},
|
|
12
|
-
{"type_id": 4, "size": 4, "name": "obj_pickup"},
|
|
13
|
-
{"type_id": 5, "size": 3, "name": "obj_flag"},
|
|
14
|
-
{"type_id": 6, "size": 8, "name": "obj_game_info"},
|
|
15
|
-
{"type_id": 7, "size": 4, "name": "obj_game_data"},
|
|
16
|
-
{"type_id": 8, "size": 15, "name": "obj_character_core"},
|
|
17
|
-
{"type_id": 9, "size": 22, "name": "obj_character"},
|
|
18
|
-
{"type_id": 10, "size": 5, "name": "obj_player_info"},
|
|
19
|
-
{"type_id": 11, "size": 17, "name": "obj_client_info"},
|
|
20
|
-
{"type_id": 12, "size": 3, "name": "obj_spectator_info"},
|
|
21
|
-
{"type_id": 13, "size": 2, "name": "common"}, // event_common
|
|
22
|
-
{"type_id": 14, "size": 2, "name": "explosion"}, // event_explosion
|
|
23
|
-
{"type_id": 15, "size": 2, "name": "spawn"}, // event_spawn
|
|
24
|
-
{"type_id": 16, "size": 2, "name": "hammerhit"}, // event_hammerhit
|
|
25
|
-
{"type_id": 17, "size": 3, "name": "death"}, // event_death
|
|
26
|
-
{"type_id": 18, "size": 3, "name": "sound_global"}, // event_sound_global
|
|
27
|
-
{"type_id": 19, "size": 3, "name": "sound_world"}, // event_sound_world
|
|
28
|
-
{"type_id": 20, "size": 3, "name": "damage_indicator"} // event_damage_indicator
|
|
29
|
-
]
|
|
30
|
-
const itemAppendix: number[] = [
|
|
31
|
-
0,
|
|
32
|
-
10,
|
|
33
|
-
6,
|
|
34
|
-
5,
|
|
35
|
-
4,
|
|
36
|
-
3,
|
|
37
|
-
8,
|
|
38
|
-
4,
|
|
39
|
-
15,
|
|
40
|
-
22,
|
|
41
|
-
5,
|
|
42
|
-
17,
|
|
43
|
-
3,
|
|
44
|
-
2,
|
|
45
|
-
2,
|
|
46
|
-
2,
|
|
47
|
-
2,
|
|
48
|
-
3,
|
|
49
|
-
3,
|
|
50
|
-
3,
|
|
51
|
-
3,
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
export enum items {
|
|
55
|
-
OBJ_EX,
|
|
56
|
-
OBJ_PLAYER_INPUT,
|
|
57
|
-
OBJ_PROJECTILE,
|
|
58
|
-
OBJ_LASER,
|
|
59
|
-
OBJ_PICKUP,
|
|
60
|
-
OBJ_FLAG,
|
|
61
|
-
OBJ_GAME_INFO,
|
|
62
|
-
OBJ_GAME_DATA,
|
|
63
|
-
OBJ_CHARACTER_CORE,
|
|
64
|
-
OBJ_CHARACTER,
|
|
65
|
-
OBJ_PLAYER_INFO,
|
|
66
|
-
OBJ_CLIENT_INFO,
|
|
67
|
-
OBJ_SPECTATOR_INFO,
|
|
68
|
-
EVENT_COMMON,
|
|
69
|
-
EVENT_EXPLOSION,
|
|
70
|
-
EVENT_SPAWN,
|
|
71
|
-
EVENT_HAMMERHIT,
|
|
72
|
-
EVENT_DEATH,
|
|
73
|
-
EVENT_SOUND_GLOBAL,
|
|
74
|
-
EVENT_SOUND_WORLD,
|
|
75
|
-
EVENT_DAMAGE_INDICATOR
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface eSnap {
|
|
79
|
-
Snapshot: {Key: number, Data: number[]},
|
|
80
|
-
ack: number,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// https://github.com/ddnet/ddnet/blob/571b0b36de83d18f2524ee371fc3223d04b94135/datasrc/network.py#L236
|
|
84
|
-
let supported_uuids = [
|
|
85
|
-
"my-own-object@heinrich5991.de",
|
|
86
|
-
"character@netobj.ddnet.tw", // validate_size=False
|
|
87
|
-
"player@netobj.ddnet.tw",
|
|
88
|
-
"gameinfo@netobj.ddnet.tw", // validate_size=False
|
|
89
|
-
"projectile@netobj.ddnet.tw",
|
|
90
|
-
"laser@netobj.ddnet.tw",
|
|
91
|
-
]
|
|
92
|
-
|
|
93
|
-
export class Snapshot {
|
|
94
|
-
deltas: DeltaItem[] = [];
|
|
95
|
-
eSnapHolder: eSnap[] = [];
|
|
96
|
-
crc_errors: number = 0;
|
|
97
|
-
client: Client;
|
|
98
|
-
uuid_manager: UUIDManager = new UUIDManager(32767, true); // snapshot max_type
|
|
99
|
-
|
|
100
|
-
constructor(_client: Client) {
|
|
101
|
-
this.client = _client;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private IntsToStr(pInts: number[]): string {
|
|
105
|
-
var pIntz: number[] = [];
|
|
106
|
-
// var pStr = ''
|
|
107
|
-
for (let x of pInts) {
|
|
108
|
-
// pStr += String.fromCharCode((((x) >> 24) & 0xff) - 128);
|
|
109
|
-
pIntz.push((((x) >> 24) & 0xff) - 128);
|
|
110
|
-
// pStr += String.fromCharCode((((x) >> 16) & 0xff) - 128);
|
|
111
|
-
pIntz.push((((x) >> 16) & 0xff) - 128);
|
|
112
|
-
// pStr += String.fromCharCode((((x) >> 8) & 0xff) - 128);
|
|
113
|
-
pIntz.push((((x) >> 8) & 0xff) - 128);
|
|
114
|
-
// pStr += String.fromCharCode(((x) & 0xff) - 128);
|
|
115
|
-
pIntz.push(((x) & 0xff) - 128);
|
|
116
|
-
}
|
|
117
|
-
pIntz.splice(-1, 1)
|
|
118
|
-
let pStr = decoder.decode(new Uint8Array(pIntz));
|
|
119
|
-
|
|
120
|
-
pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
|
|
121
|
-
return pStr;
|
|
122
|
-
}
|
|
123
|
-
private parseItem(data: number[], Type: number, id: number): Item | DDNetItem {
|
|
124
|
-
var _item = {} as Item | DDNetItem;
|
|
125
|
-
if (Type >= 0x4000) { // offset uuid type
|
|
126
|
-
if (this.uuid_manager.LookupType(Type)?.name == "my-own-object@heinrich5991.de") {
|
|
127
|
-
_item = {
|
|
128
|
-
m_Test: data[0]
|
|
129
|
-
} as SnapshotItemTypes.MyOwnObject;
|
|
130
|
-
} else if (this.uuid_manager.LookupType(Type)?.name == "character@netobj.ddnet.tw") {
|
|
131
|
-
_item = {
|
|
132
|
-
m_Flags: data[0],
|
|
133
|
-
m_FreezeEnd: data[1],
|
|
134
|
-
m_Jumps: data[2],
|
|
135
|
-
m_TeleCheckpoint: data[3],
|
|
136
|
-
m_StrongWeakID: data[4],
|
|
137
|
-
|
|
138
|
-
// # New data fields for jump display, freeze bar and ninja bar
|
|
139
|
-
// # Default values indicate that these values should not be used
|
|
140
|
-
m_JumpedTotal: data[5] ?? null,
|
|
141
|
-
m_NinjaActivationTick: data[6] ?? null,
|
|
142
|
-
m_FreezeStart: data[7] ?? null,
|
|
143
|
-
// # New data fields for improved target accuracy
|
|
144
|
-
m_TargetX: data[8] ?? null,
|
|
145
|
-
m_TargetY: data[9] ?? null,
|
|
146
|
-
id: id
|
|
147
|
-
|
|
148
|
-
} as SnapshotItemTypes.DDNetCharacter;
|
|
149
|
-
}
|
|
150
|
-
else if (this.uuid_manager.LookupType(Type)?.name == "player@netobj.ddnet.tw") {
|
|
151
|
-
_item = {
|
|
152
|
-
m_Flags: data[0],
|
|
153
|
-
m_AuthLevel: data[1],
|
|
154
|
-
id: id
|
|
155
|
-
} as SnapshotItemTypes.DDNetPlayer
|
|
156
|
-
}
|
|
157
|
-
else if (this.uuid_manager.LookupType(Type)?.name == "gameinfo@netobj.ddnet.tw") {
|
|
158
|
-
_item = {
|
|
159
|
-
m_Flags: data[0],
|
|
160
|
-
m_Version: data[1],
|
|
161
|
-
m_Flags2: data[2]
|
|
162
|
-
} as SnapshotItemTypes.GameInfoEx
|
|
163
|
-
}
|
|
164
|
-
else if (this.uuid_manager.LookupType(Type)?.name == "projectile@netobj.ddnet.tw") {
|
|
165
|
-
_item = {
|
|
166
|
-
m_X: data[0],
|
|
167
|
-
m_Y: data[1],
|
|
168
|
-
m_Angle: data[2],
|
|
169
|
-
m_Data: data[3],
|
|
170
|
-
m_Type: data[3],
|
|
171
|
-
m_StartTick: data[3]
|
|
172
|
-
} as SnapshotItemTypes.DDNetProjectile
|
|
173
|
-
}
|
|
174
|
-
else if (this.uuid_manager.LookupType(Type)?.name == "laser@netobj.ddnet.tw") {
|
|
175
|
-
_item = {
|
|
176
|
-
m_ToX: data[0],
|
|
177
|
-
m_ToY: data[1],
|
|
178
|
-
m_FromX: data[2],
|
|
179
|
-
m_FromY: data[3],
|
|
180
|
-
m_Owner: data[3],
|
|
181
|
-
m_Type: data[3]
|
|
182
|
-
} as SnapshotItemTypes.DDNetLaser
|
|
183
|
-
}
|
|
184
|
-
return _item;
|
|
185
|
-
}
|
|
186
|
-
switch (Type) {
|
|
187
|
-
case items.OBJ_EX:
|
|
188
|
-
break;
|
|
189
|
-
case items.OBJ_PLAYER_INPUT:
|
|
190
|
-
_item = {
|
|
191
|
-
direction: data[0],
|
|
192
|
-
target_x: data[1],
|
|
193
|
-
target_y: data[2],
|
|
194
|
-
jump: data[3],
|
|
195
|
-
fire: data[4],
|
|
196
|
-
hook: data[5],
|
|
197
|
-
player_flags: data[6],
|
|
198
|
-
wanted_weapon: data[7],
|
|
199
|
-
next_weapon: data[8],
|
|
200
|
-
prev_weapon: data[9],
|
|
201
|
-
} as SnapshotItemTypes.PlayerInput
|
|
202
|
-
break;
|
|
203
|
-
case items.OBJ_PROJECTILE:
|
|
204
|
-
_item = {
|
|
205
|
-
x: data[0],
|
|
206
|
-
y: data[1],
|
|
207
|
-
vel_x: data[2],
|
|
208
|
-
vel_y: data[3],
|
|
209
|
-
type_: data[4],
|
|
210
|
-
start_tick: data[5],
|
|
211
|
-
} as SnapshotItemTypes.Projectile
|
|
212
|
-
break;
|
|
213
|
-
case items.OBJ_LASER:
|
|
214
|
-
_item = {
|
|
215
|
-
x: data[0],
|
|
216
|
-
y: data[1],
|
|
217
|
-
from_x: data[2],
|
|
218
|
-
from_y: data[3],
|
|
219
|
-
start_tick: data[4],
|
|
220
|
-
} as SnapshotItemTypes.Laser
|
|
221
|
-
break;
|
|
222
|
-
case items.OBJ_PICKUP:
|
|
223
|
-
_item = {
|
|
224
|
-
x: data[0],
|
|
225
|
-
y: data[1],
|
|
226
|
-
type_: data[2],
|
|
227
|
-
subtype: data[3],
|
|
228
|
-
} as SnapshotItemTypes.Pickup
|
|
229
|
-
break;
|
|
230
|
-
case items.OBJ_FLAG:
|
|
231
|
-
_item = {
|
|
232
|
-
x: data[0],
|
|
233
|
-
y: data[1],
|
|
234
|
-
team: data[2],
|
|
235
|
-
} as SnapshotItemTypes.Flag
|
|
236
|
-
break;
|
|
237
|
-
case items.OBJ_GAME_INFO:
|
|
238
|
-
_item = {
|
|
239
|
-
game_flags: data[0],
|
|
240
|
-
game_state_flags: data[1],
|
|
241
|
-
round_start_tick: data[2],
|
|
242
|
-
warmup_timer: data[3],
|
|
243
|
-
score_limit: data[4],
|
|
244
|
-
time_limit: data[5],
|
|
245
|
-
round_num: data[6],
|
|
246
|
-
round_current: data[7],
|
|
247
|
-
|
|
248
|
-
} as SnapshotItemTypes.GameInfo
|
|
249
|
-
break;
|
|
250
|
-
case items.OBJ_GAME_DATA:
|
|
251
|
-
_item = {
|
|
252
|
-
teamscore_red: data[0],
|
|
253
|
-
teamscore_blue: data[1],
|
|
254
|
-
flag_carrier_red: data[2],
|
|
255
|
-
flag_carrier_blue: data[3],
|
|
256
|
-
} as SnapshotItemTypes.GameData
|
|
257
|
-
break;
|
|
258
|
-
case items.OBJ_CHARACTER_CORE:
|
|
259
|
-
_item = {
|
|
260
|
-
tick: data[0],
|
|
261
|
-
x: data[1],
|
|
262
|
-
y: data[2],
|
|
263
|
-
vel_x: data[3],
|
|
264
|
-
vel_y: data[4],
|
|
265
|
-
angle: data[5],
|
|
266
|
-
direction: data[6],
|
|
267
|
-
jumped: data[7],
|
|
268
|
-
hooked_player: data[8],
|
|
269
|
-
hook_state: data[9],
|
|
270
|
-
hook_tick: data[10],
|
|
271
|
-
hook_x: data[11],
|
|
272
|
-
hook_y: data[12],
|
|
273
|
-
hook_dx: data[13],
|
|
274
|
-
hook_dy: data[14],
|
|
275
|
-
} as SnapshotItemTypes.CharacterCore
|
|
276
|
-
break;
|
|
277
|
-
case items.OBJ_CHARACTER:
|
|
278
|
-
_item = {
|
|
279
|
-
character_core: {
|
|
280
|
-
tick: data[0],
|
|
281
|
-
x: data[1],
|
|
282
|
-
y: data[2],
|
|
283
|
-
vel_x: data[3],
|
|
284
|
-
vel_y: data[4],
|
|
285
|
-
angle: data[5],
|
|
286
|
-
direction: data[6],
|
|
287
|
-
jumped: data[7],
|
|
288
|
-
hooked_player: data[8],
|
|
289
|
-
hook_state: data[9],
|
|
290
|
-
hook_tick: data[10],
|
|
291
|
-
hook_x: data[11],
|
|
292
|
-
hook_y: data[12],
|
|
293
|
-
hook_dx: data[13],
|
|
294
|
-
hook_dy: data[14],
|
|
295
|
-
} as SnapshotItemTypes.CharacterCore,
|
|
296
|
-
player_flags: data[15],
|
|
297
|
-
health: data[16],
|
|
298
|
-
armor: data[17],
|
|
299
|
-
ammo_count: data[18],
|
|
300
|
-
weapon: data[19],
|
|
301
|
-
emote: data[20],
|
|
302
|
-
attack_tick: data[21],
|
|
303
|
-
|
|
304
|
-
client_id: id
|
|
305
|
-
} as SnapshotItemTypes.Character
|
|
306
|
-
break;
|
|
307
|
-
case items.OBJ_PLAYER_INFO:
|
|
308
|
-
_item = {
|
|
309
|
-
local: data[0],
|
|
310
|
-
client_id: data[1],
|
|
311
|
-
team: data[2],
|
|
312
|
-
score: data[3],
|
|
313
|
-
latency: data[4],
|
|
314
|
-
} as SnapshotItemTypes.PlayerInfo
|
|
315
|
-
break;
|
|
316
|
-
case items.OBJ_CLIENT_INFO:
|
|
317
|
-
_item = {
|
|
318
|
-
name: this.IntsToStr([data[0], data[1], data[2], data[3]]),
|
|
319
|
-
clan: this.IntsToStr([data[4], data[5], data[6]]),
|
|
320
|
-
country: data[7],
|
|
321
|
-
skin: this.IntsToStr([data[8], data[9], data[10], data[11], data[12], data[13]]),
|
|
322
|
-
use_custom_color: Number(data.slice(14, 15)),
|
|
323
|
-
color_body: Number(data.slice(15, 16)),
|
|
324
|
-
color_feet: Number(data.slice(16, 17)),
|
|
325
|
-
id: id
|
|
326
|
-
} as SnapshotItemTypes.ClientInfo
|
|
327
|
-
break;
|
|
328
|
-
case items.OBJ_SPECTATOR_INFO:
|
|
329
|
-
_item = {
|
|
330
|
-
spectator_id: data[0],
|
|
331
|
-
x: data[1],
|
|
332
|
-
y: data[2],
|
|
333
|
-
} as SnapshotItemTypes.SpectatorInfo
|
|
334
|
-
break;
|
|
335
|
-
case items.EVENT_COMMON:
|
|
336
|
-
_item = {
|
|
337
|
-
x: data[0],
|
|
338
|
-
y: data[1],
|
|
339
|
-
} as SnapshotItemTypes.Common
|
|
340
|
-
break;
|
|
341
|
-
case items.EVENT_EXPLOSION:
|
|
342
|
-
_item = {
|
|
343
|
-
common: {
|
|
344
|
-
x: data[0],
|
|
345
|
-
y: data[1]
|
|
346
|
-
} as SnapshotItemTypes.Common
|
|
347
|
-
} as SnapshotItemTypes.Explosion
|
|
348
|
-
break;
|
|
349
|
-
case items.EVENT_SPAWN:
|
|
350
|
-
_item = {
|
|
351
|
-
common: {
|
|
352
|
-
x: data[0],
|
|
353
|
-
y: data[1]
|
|
354
|
-
} as SnapshotItemTypes.Common
|
|
355
|
-
} as SnapshotItemTypes.Spawn
|
|
356
|
-
break;
|
|
357
|
-
case items.EVENT_HAMMERHIT:
|
|
358
|
-
_item = {
|
|
359
|
-
common: {
|
|
360
|
-
x: data[0],
|
|
361
|
-
y: data[1]
|
|
362
|
-
} as SnapshotItemTypes.Common
|
|
363
|
-
} as SnapshotItemTypes.HammerHit
|
|
364
|
-
break;
|
|
365
|
-
case items.EVENT_DEATH:
|
|
366
|
-
_item = {
|
|
367
|
-
client_id: data[0],
|
|
368
|
-
common: {
|
|
369
|
-
x: data[1],
|
|
370
|
-
y: data[2]
|
|
371
|
-
} as SnapshotItemTypes.Common
|
|
372
|
-
} as SnapshotItemTypes.Death
|
|
373
|
-
break;
|
|
374
|
-
case items.EVENT_SOUND_GLOBAL:
|
|
375
|
-
_item = {
|
|
376
|
-
common: {
|
|
377
|
-
x: data[0],
|
|
378
|
-
y: data[1]
|
|
379
|
-
} as SnapshotItemTypes.Common,
|
|
380
|
-
sound_id: data[2]
|
|
381
|
-
} as SnapshotItemTypes.SoundGlobal
|
|
382
|
-
break;
|
|
383
|
-
case items.EVENT_SOUND_WORLD:
|
|
384
|
-
_item = {
|
|
385
|
-
common: {
|
|
386
|
-
x: data[0],
|
|
387
|
-
y: data[1]
|
|
388
|
-
} as SnapshotItemTypes.Common,
|
|
389
|
-
sound_id: data[2]
|
|
390
|
-
} as SnapshotItemTypes.SoundWorld
|
|
391
|
-
break;
|
|
392
|
-
case items.EVENT_DAMAGE_INDICATOR:
|
|
393
|
-
_item = {
|
|
394
|
-
angle: data[0],
|
|
395
|
-
common: {
|
|
396
|
-
x: data[0],
|
|
397
|
-
y: data[1]
|
|
398
|
-
} as SnapshotItemTypes.Common,
|
|
399
|
-
} as SnapshotItemTypes.DamageInd
|
|
400
|
-
break;
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return _item;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
crc() {
|
|
408
|
-
var checksum = 0;
|
|
409
|
-
// this.eSnapHolder.forEach(snap => {
|
|
410
|
-
// if (snap.ack == tick)
|
|
411
|
-
// snap.Snapshot.Data.forEach(el => checksum += el);
|
|
412
|
-
// })
|
|
413
|
-
this.deltas.forEach(snap => {
|
|
414
|
-
// if (snap.ack == tick)
|
|
415
|
-
snap.data.forEach(el => checksum += el);
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
return checksum & 0xffffffff;
|
|
419
|
-
}
|
|
420
|
-
unpackSnapshot(snap: Buffer, deltatick: number, recvTick: number, WantedCrc: number) {
|
|
421
|
-
let unpacker = new MsgUnpacker(snap);
|
|
422
|
-
let deltaSnaps: eSnap[] = [];
|
|
423
|
-
if (deltatick == -1) {
|
|
424
|
-
this.eSnapHolder = [];
|
|
425
|
-
this.deltas = [];
|
|
426
|
-
} else {
|
|
427
|
-
this.eSnapHolder = this.eSnapHolder.filter(a => {
|
|
428
|
-
if (a.ack == deltatick)
|
|
429
|
-
deltaSnaps.push(a);
|
|
430
|
-
return a.ack >= deltatick
|
|
431
|
-
})
|
|
432
|
-
}
|
|
433
|
-
if (snap.length == 0) {
|
|
434
|
-
// empty snap, copy old one into new ack
|
|
435
|
-
this.eSnapHolder.forEach(snap => {
|
|
436
|
-
if (snap.ack == deltatick)
|
|
437
|
-
this.eSnapHolder.push({Snapshot: snap.Snapshot, ack: recvTick});
|
|
438
|
-
|
|
439
|
-
})
|
|
440
|
-
return {items: [], recvTick: recvTick};
|
|
441
|
-
}
|
|
442
|
-
let oldDeltas = this.deltas;
|
|
443
|
-
this.deltas = [];
|
|
444
|
-
/* key = (((type_id) << 16) | (id))
|
|
445
|
-
* key_to_id = ((key) & 0xffff)
|
|
446
|
-
* key_to_type_id = ((key >> 16) & 0xffff)
|
|
447
|
-
* https://github.com/heinrich5991/libtw2/blob/master/snapshot/src/
|
|
448
|
-
* https://github.com/heinrich5991/libtw2/blob/master/doc/snapshot.md
|
|
449
|
-
*/
|
|
450
|
-
var _events: {type_id: number, parsed: Item | DDNetItem}[] = [];
|
|
451
|
-
|
|
452
|
-
let num_removed_items = unpacker.unpackInt();
|
|
453
|
-
let num_item_deltas = unpacker.unpackInt();
|
|
454
|
-
unpacker.unpackInt(); // _zero padding
|
|
455
|
-
/*snapshot_delta:
|
|
456
|
-
[ 4] num_removed_items
|
|
457
|
-
[ 4] num_item_deltas
|
|
458
|
-
[ 4] _zero
|
|
459
|
-
[*4] removed_item_keys
|
|
460
|
-
[ ] item_deltas
|
|
461
|
-
*/
|
|
462
|
-
|
|
463
|
-
var deleted: number[] = [];
|
|
464
|
-
for (let i = 0; i < num_removed_items; i++) {
|
|
465
|
-
let deleted_key = unpacker.unpackInt(); // removed_item_keys
|
|
466
|
-
deleted.push(deleted_key)
|
|
467
|
-
}
|
|
468
|
-
/*item_delta:
|
|
469
|
-
[ 4] type_id
|
|
470
|
-
[ 4] id
|
|
471
|
-
[ 4] _size
|
|
472
|
-
[*4] data_delta*/
|
|
473
|
-
|
|
474
|
-
// let items: {'items': {'data': number[], 'type_id': number, 'id': number, 'key': number}[]/*, 'client_infos': client_info[], 'player_infos': player_info[]*/, lost: number} = {items: [],/* client_infos: client_infos, player_infos: player_infos,*/ lost: 0};
|
|
475
|
-
|
|
476
|
-
// let deltaSnaps = this.eSnapHolder.filter(a => a.ack === deltatick);
|
|
477
|
-
|
|
478
|
-
if (deltaSnaps.length == 0 && deltatick >= 0) {
|
|
479
|
-
return {items: [], recvTick: -1};
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
for (let i = 0; i < num_item_deltas; i++) {
|
|
484
|
-
let type_id = unpacker.unpackInt();
|
|
485
|
-
let id = unpacker.unpackInt();
|
|
486
|
-
const key = (((type_id) << 16) | (id))
|
|
487
|
-
|
|
488
|
-
let _size;
|
|
489
|
-
if (type_id > 0 && type_id < itemAppendix.length) {
|
|
490
|
-
_size = itemAppendix[type_id];
|
|
491
|
-
} else
|
|
492
|
-
_size = unpacker.unpackInt();
|
|
493
|
-
|
|
494
|
-
let data: number[] = [];
|
|
495
|
-
for (let j = 0; j < _size; j++) {
|
|
496
|
-
// if (unpacker.remaining.length > 0) {
|
|
497
|
-
data[j] = (unpacker.unpackInt());
|
|
498
|
-
// } else console.log(_size, "???")
|
|
499
|
-
}
|
|
500
|
-
let changed = false;
|
|
501
|
-
if (deltatick >= 0) {
|
|
502
|
-
// let index = deltaSnaps.map(delta => delta.Snapshot.Key).indexOf(key)
|
|
503
|
-
let delta = deltaSnaps.find(delta => delta.Snapshot.Key === key);
|
|
504
|
-
if (delta !== undefined) {
|
|
505
|
-
let out = UndiffItem(delta.Snapshot.Data, data)
|
|
506
|
-
data = out;
|
|
507
|
-
changed = true;
|
|
508
|
-
} // else no previous, use new data
|
|
509
|
-
}
|
|
510
|
-
let parsed: Item | DDNetItem;
|
|
511
|
-
if (type_id !== 0) {
|
|
512
|
-
if (!changed) {
|
|
513
|
-
let oldDelta = oldDeltas.find(delta => delta.key == key);
|
|
514
|
-
if (oldDelta !== undefined && compareArrays(data, oldDelta.data)) {
|
|
515
|
-
parsed = oldDelta.parsed;
|
|
516
|
-
|
|
517
|
-
} else
|
|
518
|
-
parsed = this.parseItem(data, type_id, id)
|
|
519
|
-
|
|
520
|
-
} else
|
|
521
|
-
parsed = this.parseItem(data, type_id, id)
|
|
522
|
-
|
|
523
|
-
this.eSnapHolder.push({Snapshot: {Data: data, Key: key}, ack: recvTick});
|
|
524
|
-
|
|
525
|
-
this.deltas.push({
|
|
526
|
-
data,
|
|
527
|
-
key,
|
|
528
|
-
id,
|
|
529
|
-
type_id,
|
|
530
|
-
parsed
|
|
531
|
-
});
|
|
532
|
-
if (type_id >= items.EVENT_COMMON && type_id <= items.EVENT_DAMAGE_INDICATOR) {
|
|
533
|
-
// this.client.SnapshotUnpacker.
|
|
534
|
-
|
|
535
|
-
_events.push({type_id, parsed});
|
|
536
|
-
// this.client.SnapshotUnpacker.emit(___itemAppendix[type_id].name, parsed);
|
|
537
|
-
}
|
|
538
|
-
} else {
|
|
539
|
-
|
|
540
|
-
this.eSnapHolder.push({Snapshot: {Data: data, Key: key}, ack: recvTick});
|
|
541
|
-
|
|
542
|
-
this.deltas.push({
|
|
543
|
-
data,
|
|
544
|
-
key,
|
|
545
|
-
id,
|
|
546
|
-
type_id,
|
|
547
|
-
parsed: {} as Item
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
let test = (int: number) => [(int >> 24) & 0xff, (int >> 16) & 0xff, (int >> 8) & 0xff, (int) & 0xff ];
|
|
551
|
-
let test2 = (ints: number[]) => ints.map(a => test(a)).flat();
|
|
552
|
-
|
|
553
|
-
let targetUUID = Buffer.from(test2(data));
|
|
554
|
-
if (!this.uuid_manager.LookupType(id)) {
|
|
555
|
-
|
|
556
|
-
supported_uuids.forEach((a, i) => {
|
|
557
|
-
let uuid = createTwMD5Hash(a);
|
|
558
|
-
if (targetUUID.compare(uuid) == 0) {
|
|
559
|
-
this.uuid_manager.RegisterName(a, id);
|
|
560
|
-
supported_uuids.splice(i, 1);
|
|
561
|
-
}
|
|
562
|
-
})
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
for (let newSnap of deltaSnaps) {
|
|
569
|
-
if (deleted.includes(newSnap.Snapshot.Key)) {
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
if (this.eSnapHolder.findIndex(a => a.ack == recvTick && a.Snapshot.Key == newSnap.Snapshot.Key) === -1) { // ugly copy new snap to eSnapHolder (if it isnt pushed already)
|
|
573
|
-
this.eSnapHolder.push({Snapshot: {Data: newSnap.Snapshot.Data, Key: newSnap.Snapshot.Key}, ack: recvTick});
|
|
574
|
-
let oldDelta = oldDeltas.find(delta => delta.key == newSnap.Snapshot.Key);
|
|
575
|
-
if (oldDelta !== undefined && compareArrays(newSnap.Snapshot.Data, oldDelta.data)) {
|
|
576
|
-
this.deltas.push(oldDelta);
|
|
577
|
-
|
|
578
|
-
} else {
|
|
579
|
-
this.deltas.push({
|
|
580
|
-
data: newSnap.Snapshot.Data,
|
|
581
|
-
key: newSnap.Snapshot.Key,
|
|
582
|
-
id: newSnap.Snapshot.Key & 0xffff,
|
|
583
|
-
type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff),
|
|
584
|
-
parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff))
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
let _crc = this.crc();
|
|
592
|
-
if (_crc !== WantedCrc) {
|
|
593
|
-
this.deltas = oldDeltas;
|
|
594
|
-
this.crc_errors++;
|
|
595
|
-
if (this.crc_errors > 5) {
|
|
596
|
-
recvTick = -1;
|
|
597
|
-
this.crc_errors = 0;
|
|
598
|
-
this.eSnapHolder = [];
|
|
599
|
-
this.deltas = [];
|
|
600
|
-
} else {
|
|
601
|
-
recvTick = deltatick;
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
} else if (this.crc_errors > 0)
|
|
605
|
-
this.crc_errors--;
|
|
606
|
-
_events.forEach(a => this.client.SnapshotUnpacker.emit(___itemAppendix[a.type_id].name, a.parsed))
|
|
607
|
-
return {items: this.deltas, recvTick};
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
function compareArrays(first: number[], second: number[]) {
|
|
611
|
-
if (first.length !== second.length)
|
|
612
|
-
return false;
|
|
613
|
-
for (var i = 0; i < first.length; i++) {
|
|
614
|
-
if (first[i] !== second[i])
|
|
615
|
-
return false;
|
|
616
|
-
}
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function UndiffItem(oldItem: number[], newItem: number[]): number[] {
|
|
621
|
-
let out: number[] = newItem;
|
|
622
|
-
// if (JSON.stringify(newItem) === JSON.stringify(oldItem))
|
|
623
|
-
// return newItem;
|
|
624
|
-
oldItem.forEach((a, i) => {
|
|
625
|
-
if (a !== undefined && out[i] !== undefined) {
|
|
626
|
-
out[i] += a;
|
|
627
|
-
} else {
|
|
628
|
-
out[i] = 0;
|
|
629
|
-
}
|
|
630
|
-
})
|
|
631
|
-
return out;
|
|
632
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Basic Options */
|
|
6
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
-
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
13
|
-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
-
// "composite": true, /* Enable project compilation */
|
|
20
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
-
|
|
27
|
-
/* Strict Type-Checking Options */
|
|
28
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
-
|
|
37
|
-
/* Additional Checks */
|
|
38
|
-
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
-
|
|
43
|
-
/* Module Resolution Options */
|
|
44
|
-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
45
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
46
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
47
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
48
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
49
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
50
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
51
|
-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
52
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
53
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
54
|
-
|
|
55
|
-
/* Source Map Options */
|
|
56
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
57
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
58
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
59
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
60
|
-
|
|
61
|
-
/* Experimental Options */
|
|
62
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
63
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
64
|
-
|
|
65
|
-
/* Advanced Options */
|
|
66
|
-
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
67
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
68
|
-
}
|
|
69
|
-
}
|