Skip to content

Commit

Permalink
Fixed issue with filename guessing that was caused by changes to valu…
Browse files Browse the repository at this point in the history
…e returned by adf file parser including value file offsets
  • Loading branch information
kk49 committed May 2, 2019
1 parent 89921f0 commit 0a3079e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 17 additions & 3 deletions deca/ff_adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,20 @@ def adf_format(v, type_map, indent=0):
return s


def adf_convert_to_value_only(v):
if isinstance(v, AdfValue):
return v.value
elif isinstance(v, dict):
n = {}
for k, iv in v.items():
n[k] = adf_convert_to_value_only(iv)
return n
elif isinstance(v, list):
return [adf_convert_to_value_only(iv) for iv in v]
else:
return v


def read_instance(f, type_id, map_typdef, map_stringhash, table_name, abs_offset, bit_offset=None, found_strings=None):
dpos = f.tell()
if type_id == typedef_s8:
Expand Down Expand Up @@ -427,12 +441,12 @@ def read_instance(f, type_id, map_typdef, map_stringhash, table_name, abs_offset
# v = b''.join(v)
v = f.read_strz()

v = AdfValue(v, type_id, dpos + abs_offset, offset + abs_offset)

if found_strings is not None:
found_strings.add(v)

f.seek(opos)

v = AdfValue(v, type_id, dpos + abs_offset, offset + abs_offset)
# TODO: optional type? this seems to be missing in some cases, i.e. the case of meshc files for CharacterMesh1UVMesh
elif type_id == 0xdefe88ed: # Optional value
v0 = f.read_u32(4)
Expand All @@ -442,8 +456,8 @@ def read_instance(f, type_id, map_typdef, map_stringhash, table_name, abs_offset
opos = f.tell()
f.seek(v0[0])
v = read_instance(f, v0[2], map_typdef, map_stringhash, table_name, abs_offset, found_strings=found_strings)
v = AdfValue(v, v0[2], dpos + abs_offset, v0[0] + abs_offset)
f.seek(opos)
v = AdfValue(v, v0[2], dpos + abs_offset, v0[0] + abs_offset)
elif type_id == 0x178842fe: # gdc/global.gdcc
# TODO this should probably be it's own file type and the adf should be considered a wrapper
v = []
Expand Down
7 changes: 4 additions & 3 deletions deca/ff_vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from deca.game_info import GameInfo, game_info_load
from deca.ff_types import *
from deca.ff_txt import load_json
from deca.ff_adf import load_adf, load_adf_bare, AdfTypeMissing, GdcArchiveEntry
from deca.ff_adf import load_adf, load_adf_bare, AdfTypeMissing, GdcArchiveEntry, adf_convert_to_value_only
from deca.ff_adf_export_import import adf_export
from deca.ff_rtpc import Rtpc
from deca.ff_aaf import extract_aaf
Expand Down Expand Up @@ -377,7 +377,8 @@ def load_from_archives(self, ver=3, debug=False): # game_dir, archive_paths,
size_u=adf.table_instance[0].size)
self.node_add(bnode)

for entry in adf.table_instance_values[0]:
adf_instance = adf_convert_to_value_only(adf.table_instance_values[0])
for entry in adf_instance:
if isinstance(entry, GdcArchiveEntry):
# self.logger.log('GDCC: {:08X} {}'.format(entry.vpath_hash, entry.vpath))
adf_type = entry.adf_type_hash
Expand Down Expand Up @@ -654,7 +655,7 @@ def find_vpath_adf_core(self, q, indexs):
if len(adf.table_instance_values) > 0 and \
adf.table_instance_values[0] is not None and \
isinstance(adf.table_instance_values[0], dict):
obj0 = adf.table_instance_values[0]
obj0 = adf_convert_to_value_only(adf.table_instance_values[0])

fns = []
# self name patch files
Expand Down

0 comments on commit 0a3079e

Please sign in to comment.