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

@ -83,7 +83,7 @@ class WadEntry: # a wad file entry
self.next_file = data[1] # used in files to go to next file in folder self.next_file = data[1] # used in files to go to next file in folder
self.next_link = data[2] # used in folders to go to first entry self.next_link = data[2] # used in folders to go to first entry
self.size_bytes = data[3] # data size in bytes. 0x80000000 for folders self.size_bytes = data[3] # data size in bytes. 0x80000000 for folders
self.name = read_asciiz(file) # pretty self explainatory self.name = read_asciiz(file) # pretty self explainatory
if self.size_bytes == 0x80000000: if self.size_bytes == 0x80000000:
self.type = WadEntryType.DIRECTORY self.type = WadEntryType.DIRECTORY
@ -92,39 +92,33 @@ 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)
#print ("done reading", self.name)
self._file.seek(ofs, os.SEEK_SET) if entry.next_file == 0:
self.children.append(entry) #print("done reading", self.name)
self._file.seek(last_ofs, os.SEEK_SET)
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)
@ -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: