-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassets_manager.py
159 lines (146 loc) · 6.44 KB
/
assets_manager.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
from . import zones
from . import ties
from . import textures
from . import file_manager
from .stream_helper import (StreamHelper)
from .rat_types import (IGAssetRef, IGSectionChunk)
from .utils import (read_sections_chunks, read_ighw_header, query_section)
class AssetManager:
def __init__(self, fm: file_manager.FileManager, operator):
self.textures_ref: list[IGAssetRef] = list[IGAssetRef]()
isOld = fm.isIE2
self.fm: file_manager.FileManager = fm
self.mobys_refs: list[IGAssetRef] = list[IGAssetRef]()
self.ties_refs: list[IGAssetRef] = list[IGAssetRef]()
self.zones_refs: list[IGAssetRef] = list[IGAssetRef]()
self.ties_instances: list[zones.CTieInstance] = list[zones.CTieInstance]()
if isOld is False:
for idx, igfile in enumerate(fm.igfiles):
stream = fm.igfiles[igfile]
stream.seek(0x00)
headers = read_ighw_header(stream)
if igfile == "assetlookup.dat":
sections_chunks = read_sections_chunks(headers, stream)
self.sections: list[IGSectionChunk] = list[IGSectionChunk]()
for section_chunk in sections_chunks:
self.sections.append(section_chunk)
for idx, igfile in enumerate(fm.otherfiles):
stream = fm.otherfiles[igfile]
headers = read_ighw_header(stream)
if igfile == "ties.dat" and operator.use_ties:
self.LoadTies()
self.ties = dict()
for tie_ref in self.ties_refs:
tie = ties.TieRefReader(stream, tie_ref)
self.ties[tie.tie.tie.tuid] = tie
elif igfile == "zones.dat" and operator.use_zones:
self.LoadZones()
self.zones = list[zones.ZoneReader]()
for zone_ref in self.zones_refs:
zone = zones.ZoneReader(stream, zone_ref)
if zone.ties_instances is not None:
self.zones.append(zone)
elif igfile == "highmips.dat" and operator.use_textures:
self.LoadTextures()
self.textures = list[textures.TextureReader]()
for texture_ref in self.textures_ref:
print("----")
print(texture_ref.__dict__)
texture = textures.TextureReader(stream, texture_ref)
'''
if igfile == "mobys.dat" and operator.use_mobys == True:
self.LoadMobys()
mobys_refs = self.mobys
for moby_ref in mobys_refs:
print("----")
mobys.Moby(stream, moby_ref)
'''
else:
print("AssetManager: Is Old! Aborting...")
##############
#### TIES ####
##############
def LoadTies(self):
if self.fm.isIE2:
print("TIE_STREAM: Unsupported format !")
else:
self.LoadNewTies()
def LoadNewTies(self):
assetlookup: StreamHelper = self.fm.igfiles["assetlookup.dat"]
tieSection = query_section(self.sections, 0x1D300)
assetlookup.seek(tieSection.offset)
self.ties_refs = list[IGAssetRef]()
for i in range(int(tieSection.length / 0x10)):
asset_ref = IGAssetRef()
asset_ref.tuid = assetlookup.readULong(0x00)
asset_ref.offset = assetlookup.readUInt(0x08)
asset_ref.length = assetlookup.readUInt(0x0C)
assetlookup.jump(0x10)
self.ties_refs.append(asset_ref)
##################
#### TEXTURES ####
##################
def LoadTextures(self):
if self.fm.isIE2:
print("UNSUPPORTED GAME VERSION")
return
else:
self.LoadTexturesNew()
def LoadTexturesNew(self):
assetlookup: StreamHelper = self.fm.igfiles["assetlookup.dat"]
highresTexturesSection = query_section(self.sections, 0x1D1C0)
assetlookup.seek(highresTexturesSection.offset)
self.textures_ref = list[IGAssetRef]()
for i in range(int(highresTexturesSection.length / 0x10)):
asset_ref = IGAssetRef()
asset_ref.tuid = assetlookup.readULong(0x00)
asset_ref.offset = assetlookup.readUInt(0x08)
asset_ref.length = assetlookup.readUInt(0x0C)
assetlookup.jump(0x10)
self.textures_ref.append(asset_ref)
###############
#### ZONES ####
###############
def LoadZones(self):
if self.fm.isIE2:
print("UNSUPPORTED GAME VERSION")
return
# self.LoadOldZones()
# TISection = query_section(zones_chunks, 0x9240)
# if "debug.dat" in self.fm.igfiles:
else:
self.LoadZonesNew()
def LoadZonesNew(self):
assetlookup: StreamHelper = self.fm.igfiles["assetlookup.dat"]
zonesSection = query_section(self.sections, 0x1DA00)
assetlookup.seek(zonesSection.offset)
self.zones_refs = list[IGAssetRef]()
for i in range(zonesSection.length // 0x10):
asset_ref = IGAssetRef()
asset_ref.tuid = assetlookup.readULong(0x00)
asset_ref.offset = assetlookup.readUInt(0x08)
asset_ref.length = assetlookup.readUInt(0x0C)
assetlookup.jump(0x10)
self.zones_refs.append(asset_ref)
###############
#### MOBYS ####
###############
def LoadMobys(self):
if self.fm.isIE2:
print("MOBY_STREAM: Unsupported format!")
# self.LoadOldMobys()
else:
self.LoadNewMobys()
def LoadNewMobys(self):
assetlookup: StreamHelper = self.fm.igfiles["assetlookup.dat"]
mobySection = query_section(self.sections, 0x1D600)
print("o:{2} / MOBY_SECTION {0}: {1}".format(hex(mobySection.id), mobySection, hex(assetlookup.offset)))
assetlookup.seek(mobySection.offset)
for i in range(int(mobySection["length"] / 0x10)):
res: IGAssetRef = IGAssetRef()
res.tuid = assetlookup.readULong(0x00)
res.offset = assetlookup.readUInt(0x08)
res.length = assetlookup.readUInt(0x0C)
assetlookup.jump(0x10)
print("o:{2} MOBY_RAW-REF {0}: {1}".format(hex(res.tuid), res.__dict__, hex(assetlookup.offset)))
self.mobys.append(res)