mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-21 19:45:10 +00:00
add scripts to rename CRC-named HD textures
as used by @originalgrego's fork
This commit is contained in:
parent
62e78a74c0
commit
8013b9a325
3 changed files with 1350 additions and 0 deletions
42
tools/cleancrcmap.py
Normal file
42
tools/cleancrcmap.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import glob
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
print("usage: cleancrcmap <in_map> <out_map> <searchdir>")
|
||||
sys.exit(1)
|
||||
|
||||
# load and check the old map
|
||||
searchpath = sys.argv[3]
|
||||
inmap = list()
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line == '' or line[0] == '#':
|
||||
continue
|
||||
tok = line.split(',')
|
||||
crcstr = tok[0].strip()
|
||||
if crcstr.startswith('0x'):
|
||||
crc = int(crcstr[2:], 16)
|
||||
else:
|
||||
crc = int(crcstr)
|
||||
tok[1] = tok[1].strip()
|
||||
[fname, fext] = os.path.splitext(tok[1])
|
||||
[fname, ffmt] = os.path.splitext(fname)
|
||||
fname = fname + ffmt[:-1] + '*'
|
||||
matches = glob.glob(os.path.join(searchpath, fname))
|
||||
if len(matches) == 0:
|
||||
print("warning: texture '{0}' does not match anything in '{1}'".format(fname, searchpath))
|
||||
else:
|
||||
for s in matches:
|
||||
tup = (crc, os.path.relpath(s, searchpath))
|
||||
if not (tup in inmap):
|
||||
inmap.append(tup)
|
||||
|
||||
# save cleaned up version to the new one
|
||||
with open(sys.argv[2], 'w') as f:
|
||||
for (crc, fpath) in inmap:
|
||||
f.write("0x{0:08x}, {1}\n".format(crc, fpath))
|
||||
|
1237
tools/default_crcmap.txt
Normal file
1237
tools/default_crcmap.txt
Normal file
File diff suppressed because it is too large
Load diff
71
tools/texrename.py
Normal file
71
tools/texrename.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: texrename <in_dir> <out_dir> [<crcmap_file>]")
|
||||
sys.exit(1)
|
||||
|
||||
inpath = sys.argv[1]
|
||||
outpath = sys.argv[2]
|
||||
mapfname = "crcmap.txt"
|
||||
if len(sys.argv) > 3:
|
||||
mapfname = sys.argv[3]
|
||||
|
||||
# catalog the original texture pack
|
||||
texmap = dict()
|
||||
imgexts = frozenset(['.png', '.bmp', '.jpg', '.tga', '.gif'])
|
||||
try:
|
||||
for root, dirs, files in os.walk(inpath):
|
||||
for f in files:
|
||||
ffull = os.path.join(root, f)
|
||||
[fpath, fname] = os.path.split(f)
|
||||
ext = os.path.splitext(fname)[1].lower()
|
||||
if fname[0] == '.' or not (ext in imgexts):
|
||||
continue
|
||||
crc = 0
|
||||
try:
|
||||
if '#' in fname: # rice pack format: "GAME NAME#hash#whatever"
|
||||
crc = int(fname.split('#')[1], 16)
|
||||
else: # just the crc probably
|
||||
crc = int(os.path.splitext(fname)[0], 16)
|
||||
except ValueError:
|
||||
print('unknown filename format: {0}'.format(ffull))
|
||||
continue
|
||||
texmap[crc] = ffull
|
||||
except OSError as e:
|
||||
print('error opening {0}: {1}'.format(inpath, e))
|
||||
sys.exit(2)
|
||||
|
||||
# load the CRC map
|
||||
crcmap = dict()
|
||||
try:
|
||||
with open(mapfname, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line == '' or line[0] == '#':
|
||||
continue
|
||||
tok = line.split(',')
|
||||
crcstr = tok[0].strip()
|
||||
if crcstr.startswith('0x'):
|
||||
crc = int(crcstr[2:], 16)
|
||||
else:
|
||||
crc = int(crcstr)
|
||||
crcmap[crc] = os.path.join(outpath, tok[1].strip())
|
||||
except OSError as e:
|
||||
print('could not open {0}: {1}'.format(mapfname, e))
|
||||
except ValueError as e:
|
||||
print('invalid integer in {0}: {1}'.format(mapfname, e))
|
||||
sys.exit(3)
|
||||
|
||||
# copy the files to the correct locations
|
||||
for crc, path in crcmap.items():
|
||||
if not (crc in texmap):
|
||||
print('unmatched CRC: {0} ({1})'.format(crc, path))
|
||||
else:
|
||||
[fpath, fname] = os.path.split(path)
|
||||
if not os.path.exists(fpath):
|
||||
os.makedirs(fpath)
|
||||
shutil.copy2(texmap[crc], path)
|
Loading…
Reference in a new issue