@@ -48,42 +48,47 @@ def __init__(self, stream):
48
48
self .file_number : int = Datum (stream ).d
49
49
50
50
# READ THE SECTIONS.
51
- section_type : int = Datum (stream ).d
51
+ section_type : int = Datum (stream , Datum . Type . UINT16_1 ).d
52
52
if section_type != GlobalParameters .SectionType .EMPTY :
53
53
if section_type == GlobalParameters .SectionType .NAME :
54
- assert_equal (Datum (stream ).d , self .file_number )
55
- self .name = Datum (stream ).d
56
- assert_equal (Datum (stream ).d , 0x0000 )
54
+ repeated_file_number = Datum (stream , Datum .Type .UINT16_1 ).d
55
+ assert_equal (repeated_file_number , self .file_number )
56
+ self .name = Datum (stream , Datum .Type .STRING ).d
57
+ unk1 = Datum (stream , Datum .Type .UINT16_1 ).d # Always 0x0000
57
58
58
59
elif section_type == GlobalParameters .SectionType .FILE_NUMBER :
59
- self .read_file_number_section (stream )
60
+ unk1 = UnknownFileNumberSection (stream )
61
+ assert_equal (unk1 .file_number , self .file_number )
60
62
61
63
else :
62
64
# TODO: Document what this stuff is. My original code had zero documentation.
63
- section_type = Datum (stream )
65
+ section_type = Datum (stream , Datum . Type . UINT16_1 )
64
66
while section_type .d != GlobalParameters .SectionType .NULL :
65
67
assert_equal (section_type .d , self .file_number , "file ID" )
66
68
67
- id = Datum (stream )
68
- self .entries .update ({id .d : self .entity (Datum (stream ), stream )})
69
+ id = Datum (stream ).d
70
+ entity = self .entity (Datum (stream ), stream )
71
+ self .entries .update ({id : entity })
69
72
70
73
check = Datum (stream )
71
74
if check .d != GlobalParameters .SectionType .EMPTY :
72
75
break
73
76
74
- section_type = Datum (stream )
77
+ section_type = Datum (stream , Datum . Type . UINT16_1 )
75
78
76
79
if check .d == GlobalParameters .SectionType .FILE_NUMBER :
77
- self .read_file_number_section (stream )
80
+ unk1 = UnknownFileNumberSection (stream )
81
+ assert_equal (unk1 .file_number , self .file_number )
78
82
79
83
# READ THE CONTEXT-GLOBAL BYTECODE.
80
84
# TODO: Does this run when the context is first loaded?
81
85
if global_variables .version .is_first_generation_engine :
82
- section_type = Datum (stream )
86
+ section_type = Datum (stream , Datum . Type . UINT16_1 )
83
87
self .init = []
84
88
while section_type .d == GlobalParameters .SectionType .BYTECODE :
85
89
self .init .append (Script (stream , in_independent_asset_chunk = False ))
86
- section_type = Datum (stream )
90
+ section_type = Datum (stream , Datum .Type .UINT16_1 )
91
+
87
92
88
93
# TODO: Document what this stuff is. My original code had zero documentation.
89
94
def entity (self , section_type , stream ):
@@ -100,28 +105,35 @@ def entity(self, section_type, stream):
100
105
string = stream .read (size ).decode ('latin-1' )
101
106
entries .append (string )
102
107
103
- else :
108
+ # TODO: It looks like the only section types are
109
+ # - 0x0005
110
+ # - 0x0002
111
+ # - 0x0003?
112
+ # - 0x0001
113
+ else : # literal
104
114
entry = Datum (stream ).d
105
115
entries .append (entry )
106
116
107
117
return {"section_type" : section_type .d , "entries" : entries }
108
118
109
- ## I don't know what this structure is, but it's in every old-style game.
110
- ## The fields aside from the file numbers are constant.
111
- ## \param[in] stream - A binary stream that supports the read method.
112
- def read_file_number_section (self , stream ):
119
+ ## I don't know what this structure is, but it's in every old-style game.
120
+ ## The fields aside from the file numbers are constant.
121
+ ## \param[in] stream - A binary stream that supports the read method.
122
+ class UnknownFileNumberSection :
123
+ def __init__ (self , stream ):
113
124
# VERIFY THE FILE NUMBER.
114
- repeated_file_number = Datum (stream ).d
115
- assert_equal (repeated_file_number , self .file_number )
125
+ self .file_number = Datum (stream , Datum .Type .UINT16_1 ).d
116
126
# TODO: Figure out what this is.
117
- unk1 = Datum (stream ).d # This seems to always be 0x0001.
127
+ unk1 = Datum (stream , Datum . Type . UINT16_1 ).d # This seems to always be 0x0001.
118
128
119
129
# VERIFY THE FILE NUMBER.
120
- repeated_file_number = Datum (stream ).d
130
+ repeated_file_number = Datum (stream , Datum . Type . UINT16_1 ).d
121
131
assert_equal (repeated_file_number , self .file_number )
122
132
# TODO: Figure out what these are.
123
- unk2 = Datum (stream ).d # This seems to always be 0x0022.
124
- unk3 = Datum (stream ).d
133
+ unk2 = Datum (stream , Datum .Type .UINT16_1 ).d # This seems to always be 0x0022.
134
+ unk3 = Datum (stream , Datum .Type .UINT16_1 ).d # Is this always zero?
135
+ if unk3 != 0 :
136
+ raise ValueError ('Not zero!' )
125
137
126
138
## A "context" is the logical entity serialized in each CXT data file.
127
139
## Subfile 0 of this file always contains the header sections for the context.
0 commit comments