Skip to content

Instantly share code, notes, and snippets.

@marcusbirkeland
Last active September 10, 2021 11:13
Show Gist options
  • Save marcusbirkeland/68a598802c2033fa98653b641f359a14 to your computer and use it in GitHub Desktop.
Save marcusbirkeland/68a598802c2033fa98653b641f359a14 to your computer and use it in GitHub Desktop.
[Umodel/NMH3 ] WIP NMH3 texture fixer script. credit: CABALEX
import os
from shutil import move
def findBlocksize(filesize):
print("Filesize for loaded file: " , filesize)
d = {
# texture w/h -> blocksize
# 0 = UNKNOWN
64: 0,
128: 0,
256: 0,
512: 256,
1024: 256,
2048: 256
}
if filesize > 150000:
return d[1024]
else:
return d[256]
dir_path = os.path.dirname(os.path.realpath(__file__))
files = [f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path,f))]
ubulk = []
for f in files:
if ".ubulk" in f:
ubulk.append(f)
print("Files to convert: " , ubulk)
for f in ubulk:
fin = f
fout = fin.replace(".", "-new.")
filesize = os.path.getsize(fin)
blocksize = findBlocksize(filesize)
print("CURRENT FILE: " , f)
print("BLOCKSIZE FOR CURRENT FILE: " , blocksize)
f = open(fout, "wb")
blocksize *= 16
with open(fin, 'rb') as raw:
while raw.tell() < filesize:
bs = raw.read(blocksize)
if bs == b"".join([b'\x00'] * blocksize):
continue
f.write(bs)
while f.tell() < filesize:
f.write(b"".join([b'\x00'] * blocksize))
f.close()
os.remove(fin)s
move(fout, fin)
print("done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment