-
Notifications
You must be signed in to change notification settings - Fork 17
/
gamedata.ts
100 lines (87 loc) · 2.29 KB
/
gamedata.ts
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
/*
Parses actual game data
Please note that TimeSlotBlocks do not fully parse included actions.
They should be parsed block by block manually
afterwards to ensure proper error handling.
*/
import { Parser } from 'binary-parser'
import { CommandDataBlock } from './actions'
import { chatModeFormatter } from './formatters'
// 0x17
const LeaveGameBlock = new Parser()
.string('reason', { length: 4, encoding: 'hex' })
.int8('playerId')
.string('result', { length: 4, encoding: 'hex' })
.skip(4)
// 0x1A
const FirstStartBlock = new Parser()
.skip(4)
// 0x1B
const SecondStartBlock = new Parser()
.skip(4)
// 0x1C
const ThirdStartBlock = new Parser()
.skip(4)
// 0x1F 0x1E
const TimeSlotBlock = new Parser()
.int16le('byteCount')
.int16le('timeIncrement')
.array('actions', {
type: CommandDataBlock,
lengthInBytes () {
// @ts-ignore
return this.byteCount - 2
}
})
// 0x20
// @ts-ignore
const PlayerChatMessageBlock = new Parser()
.int8('playerId')
.int16le('byteCount')
.int8('flags')
.choice('',
{
tag: 'flags',
choices: {
0x10: new Parser(),
// @ts-ignore
0x20: new Parser().int8('mode', { length: 4, formatter: chatModeFormatter, encoding: 'hex' }).skip(3)
}
}
)
.string('message', { zeroTerminated: true, encoding: 'utf8' })
// 0x22
const Unknown0x22 = new Parser()
.uint8('length')
.string('content', { length: 'length' })
// 0x23
const Unknown0x23 = new Parser()
.skip(10)
// 0x2F
const ForcedGameEndCountdown = new Parser()
.skip(8)
// @ts-ignore
const GameData = new Parser()
.uint8('type')
.choice('', {
tag: 'type',
choices: {
0x17: LeaveGameBlock,
0x1a: FirstStartBlock,
0x1b: SecondStartBlock,
0x1c: ThirdStartBlock,
0x1f: TimeSlotBlock,
0x1e: TimeSlotBlock,
0x20: PlayerChatMessageBlock,
0x22: Unknown0x22,
0x23: Unknown0x23,
0x2f: ForcedGameEndCountdown,
0: new Parser()
}
})
const GameDataParser = new Parser()
// @ts-ignore
.array(null, { type: GameData, readUntil: 'eof' })
export {
GameDataParser
}