add updated Rolling ROLL_P.WAD extraction utility

This commit is contained in:
Lily Tsuru 2023-11-09 18:18:40 -05:00
parent 88cd7adf23
commit 280965d81b
1 changed files with 17 additions and 23 deletions

View File

@ -92,40 +92,34 @@ class WadEntry: # a wad file entry
self.children = [] self.children = []
def read_directory_children(self):
last_ofs = self.next_link
self._file.seek(last_ofs, os.SEEK_SET)
# Bit of a bug right now but it seems to work.
def read_children(self):
ofs = self.next_link
#print(f'seeking to {ofs:x}')
self._file.seek(ofs, os.SEEK_SET)
# read all of the children nodes
entry = WadEntry(self._file) entry = WadEntry(self._file)
entry.parent = self entry.parent = self
while True: while True:
#print(entry.name, entry.type, "parent:", entry.parent.name) #print(entry.name, entry.type, "parent dir:", entry.parent.name)
# let child directory read its children
if entry.type == WadEntryType.DIRECTORY:
#print(entry.name, "reading children")
entry.read_children()
if entry.type == WadEntryType.DIRECTORY and entry.next_link != 0:
entry.read_directory_children()
if entry.next_file != 0: if entry.next_file != 0:
#print(f'seeking to {entry.next_file:x} (loop)') #print(f'seeking to {entry.next_file:x} (loop)')
self._file.seek(entry.next_file, os.SEEK_SET) self._file.seek(entry.next_file, os.SEEK_SET)
if entry.next_file == 0 and entry.next_link == 0: self.children.append(entry)
if entry.next_file == 0:
#print("done reading", self.name) #print("done reading", self.name)
self._file.seek(ofs, os.SEEK_SET) self._file.seek(last_ofs, os.SEEK_SET)
self.children.append(entry)
return return
else:
self.children.append(entry)
entry = WadEntry(self._file) entry = WadEntry(self._file)
entry.parent = self entry.parent = self
def dump(self, pathObj): def dump(self, pathObj):
self._file.seek(blocks_to_bytes(self.block_offset), os.SEEK_SET) self._file.seek(blocks_to_bytes(self.block_offset), os.SEEK_SET)
path = str(pathObj) path = str(pathObj)
@ -153,7 +147,7 @@ rootPath.mkdir(exist_ok=True)
with open(sys.argv[1], "rb") as file: with open(sys.argv[1], "rb") as file:
header = WadHeader(file) header = WadHeader(file)
root = WadEntry(file) root = WadEntry(file)
root.read_children() root.read_directory_children()
for tup in root.walk(rootPath): for tup in root.walk(rootPath):
if tup[1].type == WadEntryType.FILE: if tup[1].type == WadEntryType.FILE: