-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfco.py
More file actions
68 lines (47 loc) · 2.07 KB
/
fco.py
File metadata and controls
68 lines (47 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from binary import Binary
from typing import IO
class FCO(Binary):
def __init__(self, io: IO) -> None:
super().__init__(io, "ascii", "big")
self.groups = []
def read_fco(self, offset: int = 0):
self.move_to_position(offset)
# i will use 00 00 00 04 00 00 00 00 as magic header
assert self.read_bytes(8) == b"\x00\x00\x00\x04\x00\x00\x00\x00"
self.groups = []
group_count = self.read_integer()
for i in range(group_count):
group_name = self.read_string()
message_count = self.read_integer()
messages = []
for j in range(message_count):
message_name = self.read_string()
symbol_count = self.read_integer()
message_symbols = []
for l in range(symbol_count):
symbol_code = self.read_integer()
message_symbols.append(symbol_code)
# 00 00 00 04 00 00 00 00 means end of message
assert self.read_bytes(8) == b"\x00\x00\x00\x04\x00\x00\x00\x00"
unknown_1 = self.read_bytes(4)
self.move_to_position(4, from_start=False, from_current=True)
# FF FF FF FF 00 00 00 00 means termination (???)
assert self.read_bytes(8) == b"\xFF\xFF\xFF\xFF\x00\x00\x00\x00"
# Skipping the unknown bytes (probably "second" variation)
# TODO: Needed to make it work with all FCO files
while self.read_bytes(4) == unknown_1:
self.move_to_position(12, from_start=False, from_current=True)
message = {
"name": message_name,
"symbols": message_symbols
}
messages.append(message)
group = {
"name": group_name,
"messages": messages
}
self.groups.append(group)
@staticmethod
def create_empty():
io = IO()
return FCO(io)