Advertisement

Python script for extracting npc file into txt and bmp files

import gzip

def filenameend(i):
if i == 2:
return ".bmp"
elif i == 3:
return ".txt"
elif i == 4:
return "_face.bmp"

name = input("Enter filename? ")
with open(name + '.npc', 'rb') as original:
for i in range(1,5):
bytes = original.read(40)
bytes = original.read(10)
if bytes[0:1] == b'':
break
j = 9
while j > 0 and bytes[j:j+1] == b'\00':
j -= 1
jump = int(bytes[0:j+1])
bytes = original.read(jump-50)
if (i > 1):
filename = name + filenameend(i)
with open(filename, 'wb') as file:
file.write(bytes)
bytes = bytearray()
with gzip.open(filename, 'rb') as f:
bytes = f.read()
with open(filename, 'wb') as f:
f.write(bytes)
Community content is available under CC-BY-SA unless otherwise noted.