# Game: Xenoblade (Wii)
# by Falo - 2010
# script for QuickBMS
http://aluigi.org/papers.htm#quickbms
#
# usage :
#
# use WiiScrubber to extract all *.pkb files
# use any u8 tool (arc extractor) to extract static.arc
# you should then have *.pkb and *.pkh files
# use this script on *.pkb
endian big
Open FDDE PKH 1
get Temp long 1 # always 0x00FE1200
get Temp long 1
get ofsHashTable long 1 # not sure, HashTable or FileIDTable
get FileSize long 1
get numFiles long 1
set ofsSizeTable numFiles
set ofsOffsetTable numFiles
math ofsSizeTable *= 8
math ofsOffsetTable *= 2
math ofsSizeTable += ofsHashTable
math ofsOffsetTable += ofsSizeTable
for i = 0 < numFiles
goto ofsHashTable 1
get Hash long 1 # not sure, Hash or FileID
get Temp long 1 # always 0x0
goto ofsSizeTable 1
get Size short 1
goto ofsOffsetTable 1
get Offset long 1
math Size *= 2048
math Offset *= 2048
# use hash/fileid as filename
set Name Hash
set FileExt ".dat"
# get FileExt
goto Offset
get FileID long
if FileID = 1437218861 # Nintendo ARC (U8)
set FileExt ".arc"
endif
if FileID = 1651664243 # Nintendo BRRES
set FileExt ".brres"
endif
if FileID = 2142000 # Nintendo TPL
set FileExt ".tpl"
endif
if FileID = 1264144384 # Xenoblade KYP -> BRRES Archive
set FileExt ".kyp"
endif
if FileID = 1835229440 # Xenoblade MCA
set FileExt ".mca"
endif
if FileID = 1145131057 # Xenoblade DAP1
set FileExt ".dap"
endif
if FileID = 1280263241 # Xenoblade LODI
set FileExt ".lod"
endif
string Name += FileExt
log Name Offset Size
# next file, increase all offsets
math ofsHashTable += 8
math ofsSizeTable += 2
math ofsOffsetTable += 4
next i
CleanExit