Support all .wpak files with a wpak target
Replaces the config target with wpak, which handles every known pak or a single one named on the command line. Map icon .tga entries are stored unencrypted (sb.exe 0xAACA60). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8a8ebc5632
commit
b2e38bdc06
2 files changed
+85
-47
No files matched your search
@@ -45,7 +45,6 @@ MOTION_DIRECTORY = os.path.join(TARGET_DIRECTORY, 'MOTION')
|
||||
TILE_DIRECTORY = os.path.join(TARGET_DIRECTORY, 'TILE')
|
||||
SKELETON_DIRECTORY = os.path.join(TARGET_DIRECTORY, 'SKELETON')
|
||||
RENDER_DIRECTORY = os.path.join(TARGET_DIRECTORY, 'RENDER')
|
||||
CONFIG_DIRECTORY = os.path.join(TARGET_DIRECTORY, 'Config')
|
||||
COBJECTS_MAGIC = 0x434c4e54
|
||||
|
||||
COBJECTS_MAP = {
|
||||
@@ -86,10 +85,25 @@ EDITOR_TARGETS = [
|
||||
'skeleton',
|
||||
'terrain',
|
||||
'render',
|
||||
'config',
|
||||
'wpak',
|
||||
'all'
|
||||
]
|
||||
|
||||
# Each pak unpacks to ARCANE_DUMP/<name> and packs back to <name>.wpak.
|
||||
WPAK_NAMES = [
|
||||
'AerynthIcons',
|
||||
'Config',
|
||||
'DalgothIcons',
|
||||
'Environment',
|
||||
'GeneralItemTables',
|
||||
'ItemTables',
|
||||
'ModTables',
|
||||
'ModTypeTables',
|
||||
'Transitions',
|
||||
'VendorENGLISH',
|
||||
'VorringiaIcons'
|
||||
]
|
||||
|
||||
|
||||
def create_unpack_directory(base_directory):
|
||||
# Never unpack over an existing folder; use the next free numbered name.
|
||||
@@ -155,11 +169,6 @@ def init_render():
|
||||
os.makedirs(directory_path, exist_ok=True)
|
||||
|
||||
|
||||
def init_config():
|
||||
directory_path = CONFIG_DIRECTORY
|
||||
os.makedirs(directory_path, exist_ok=True)
|
||||
|
||||
|
||||
def unpack_cobjects():
|
||||
resources = load_cache_file('CObjects.cache')
|
||||
directory = create_unpack_directory(COBJECTS_DIRECTORY)
|
||||
@@ -848,37 +857,59 @@ def test_render():
|
||||
print(res_id, in_stream.buffer.tell(), out_stream.buffer.tell())
|
||||
|
||||
|
||||
def unpack_config():
|
||||
entries = load_wpak_file('Config.wpak')
|
||||
directory = create_unpack_directory(CONFIG_DIRECTORY)
|
||||
def selected_wpak_names():
|
||||
# An optional third argument picks a single pak, e.g. "unpack wpak Config".
|
||||
return sys.argv[3:] or WPAK_NAMES
|
||||
|
||||
|
||||
def unpack_wpak():
|
||||
for wpak_name in selected_wpak_names():
|
||||
wpak_filename = wpak_name + '.wpak'
|
||||
if not os.path.isfile(wpak_filename):
|
||||
print('***Skipping: ' + wpak_filename + ' not found.')
|
||||
continue
|
||||
|
||||
entries = load_wpak_file(wpak_filename)
|
||||
directory = create_unpack_directory(os.path.join(TARGET_DIRECTORY, wpak_name))
|
||||
|
||||
with tqdm(total=len(entries)) as pBar:
|
||||
for filename, data in entries:
|
||||
filepath = os.path.join(directory, filename)
|
||||
with open(filepath, 'wb') as fp:
|
||||
fp.write(data)
|
||||
pBar.update(1)
|
||||
|
||||
|
||||
def pack_wpak():
|
||||
for wpak_name in selected_wpak_names():
|
||||
directory = os.path.join(TARGET_DIRECTORY, wpak_name)
|
||||
if not os.path.isdir(directory):
|
||||
print('***Skipping: ' + directory + ' not found.')
|
||||
continue
|
||||
|
||||
entries = load_wpak_directory(directory)
|
||||
save_wpak_file(wpak_name + '.wpak', entries)
|
||||
|
||||
|
||||
def test_wpak():
|
||||
for wpak_name in selected_wpak_names():
|
||||
wpak_filename = wpak_name + '.wpak'
|
||||
if not os.path.isfile(wpak_filename):
|
||||
print('***Skipping: ' + wpak_filename + ' not found.')
|
||||
continue
|
||||
|
||||
print(wpak_filename)
|
||||
entries = load_wpak_file(wpak_filename)
|
||||
out_stream = io.BytesIO()
|
||||
|
||||
build_wpak_bytes(entries, out_stream)
|
||||
repacked = dict(load_wpak_file(out_stream))
|
||||
|
||||
with tqdm(total=len(entries)) as pBar:
|
||||
for filename, data in entries:
|
||||
filepath = os.path.join(directory, filename)
|
||||
with open(filepath, 'wb') as fp:
|
||||
fp.write(data)
|
||||
pBar.update(1)
|
||||
|
||||
|
||||
def pack_config():
|
||||
init_config()
|
||||
|
||||
entries = load_wpak_directory(CONFIG_DIRECTORY)
|
||||
save_wpak_file('Config.wpak', entries)
|
||||
|
||||
|
||||
def test_config():
|
||||
entries = load_wpak_file('Config.wpak')
|
||||
out_stream = io.BytesIO()
|
||||
|
||||
build_wpak_bytes(entries, out_stream)
|
||||
repacked = dict(load_wpak_file(out_stream))
|
||||
|
||||
for filename, data in entries:
|
||||
try:
|
||||
assert repacked[filename] == data
|
||||
except:
|
||||
print(filename, len(data), len(repacked.get(filename, b'')))
|
||||
try:
|
||||
assert repacked[filename] == data
|
||||
except:
|
||||
print(filename, len(data), len(repacked.get(filename, b'')))
|
||||
|
||||
|
||||
def unpack_all():
|
||||
@@ -922,6 +953,7 @@ def usage():
|
||||
print('')
|
||||
print('example: unpack texture')
|
||||
print('example: pack texture')
|
||||
print('example: unpack wpak Config')
|
||||
exit(1)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user