forked from paimooon/YSAssetIdx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset_index.py
184 lines (139 loc) · 6.42 KB
/
asset_index.py
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
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
import kaitaistruct
from kaitaistruct import KaitaiStruct, KaitaiStream, BytesIO
if getattr(kaitaistruct, 'API_VERSION', (0, 9)) < (0, 9):
raise Exception("Incompatible Kaitai Struct Python API: 0.9 or later is required, but you have %s" % (kaitaistruct.__version__))
class AssetIndex(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.type_mapping_count = self._io.read_u4le()
self.type_mapping = []
for i in range(self.type_mapping_count):
self.type_mapping.append(AssetIndex.TypeMappingEntry(self._io, self, self._root))
self.asset_count = self._io.read_u4le()
self.assets = []
for i in range(self.asset_count):
self.assets.append(AssetIndex.AssetInfo(self._io, self, self._root))
self.dependency_count = self._io.read_u4le()
self.magic_31 = self._io.read_u4le()
self.dependencies = []
for i in range(self.dependency_count):
self.dependencies.append(AssetIndex.DependencyInfo(self._io, self, self._root))
self.preload_blocks_count = self._io.read_u4le()
self.preload_blocks = []
for i in range(self.preload_blocks_count):
self.preload_blocks.append(self._io.read_u4le())
self.preload_shader_blocks_count = self._io.read_u4le()
self.preload_shader_blocks = []
for i in range(self.preload_shader_blocks_count):
self.preload_shader_blocks.append(self._io.read_u4le())
self.block_group_count = self._io.read_u4le()
self.block_groups = []
for i in range(self.block_group_count):
self.block_groups.append(AssetIndex.BlockGroup(self._io, self, self._root))
self.block_info_count = self._io.read_u4le()
self.block_infos = []
for i in range(self.block_info_count):
self.block_infos.append(AssetIndex.BlockInfo(self._io, self, self._root))
self.sort_list_count = self._io.read_u4le()
self.sort_list = []
for i in range(self.sort_list_count):
self.sort_list.append(self._io.read_u4le())
class BlockInfo(KaitaiStruct):
"""Specifies which assets this specific block contains and their offsets in the BLK file."""
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.block_id = self._io.read_u4le()
self.asset_offset_count = self._io.read_u4le()
self.asset_offsets = []
for i in range(self.asset_offset_count):
self.asset_offsets.append(AssetIndex.AssetOffsetInfo(self._io, self, self._root))
class BlockListMagic(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.block_list = self._io.read_u4le()
self.magic = self._io.read_u2le()
class TypeMappingEntry(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.name = AssetIndex.String(self._io, self, self._root)
self.mapped_to = AssetIndex.String(self._io, self, self._root)
class String(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.len = self._io.read_u4le()
self.data = (self._io.read_bytes(self.len)).decode(u"UTF-8")
class DependencyInfo(KaitaiStruct):
"""Describes that asset asset_id depends on assets from the specified list."""
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.asset_id = self._io.read_u4le()
self.dependency_info_count = self._io.read_u4le()
self.dependencies_list = []
for i in range(self.dependency_info_count):
self.dependencies_list.append(self._io.read_u4le())
class AssetOffsetInfo(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.path_hash_pre = self._io.read_u4le()
self.offset = self._io.read_u4le()
class BlockGroup(KaitaiStruct):
"""List of BLKs in a directory specified by the group_id."""
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.group_id = self._io.read_u4le()
self.block_count = self._io.read_u4le()
self.block_list = []
for i in range(self.block_count):
self.block_list.append(AssetIndex.BlockListMagic(self._io, self, self._root))
class AssetInfo(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.path_hash_pre = self._io.read_u1()
self.path_hash_last = self._io.read_u4le()
self.magic = []
for i in range(3):
self.magic.append(self._io.read_u1())
self.magic_real = self._io.read_u1()
self.magic_2 = self._io.read_u1()
self.sub_asset_id = self._io.read_u4le()
if self.magic_real == 2:
self.magic_conditional = []
for i in range(5):
self.magic_conditional.append(self._io.read_u1())