Last active
September 16, 2020 05:20
-
-
Save FromDarkHell/41bc5bb65d0319faacae1c6050a5b9c9 to your computer and use it in GitHub Desktop.
Judge Dredd: Dredd Vs. Death Extractors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from struct import * | |
import struct | |
def bread(filename): | |
with open(filename, 'rb') as f: | |
return f.read(-1) | |
def parseSoundFile(filename): | |
byteData = bread(filename) | |
byteData = byteData[36:] | |
print(f"Extracting files from: {filename}") | |
bTest = False | |
while byteData[0:4] != b'': | |
index = 0 | |
while(chr(byteData[index]) != '\\'): index += 1 | |
totalReadData = 0 | |
wavName = "" | |
while(byteData[index] != 0): | |
wavName += chr(byteData[index]) | |
index += 1 | |
# For SOME reason there's just a .INI file in this exact same file, for now we just return | |
if(".wav" not in wavName): | |
byteData = byteData[index:] | |
bTest = True | |
continue | |
while(byteData[index] == 0): index += 1 | |
totalReadData += index | |
wavName = "./extract" + wavName.replace("\\","/") | |
print(f"Reading .WAV: {wavName}") | |
byteData = byteData[totalReadData:] | |
fileLength = struct.unpack('<I', byteData[4:8])[0] | |
print(f".WAV Length: {fileLength}") | |
if not(os.path.exists(os.path.dirname(wavName))): os.makedirs(os.path.dirname(wavName)) | |
outputFile = open(wavName, 'wb+') | |
outputFile.write(byteData[0:fileLength+4]) | |
byteData = byteData[fileLength+4+32:] | |
parseSoundFile("./MPSnds.asr") | |
parseSoundFile("./en_gmsnd.asr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from struct import * | |
import struct | |
magic = b'ASURA ' | |
def bread(filename): | |
with open(filename, 'rb') as f: | |
bdata = [] | |
while True: | |
bytes = f.read(1) | |
if bytes == b'': | |
break | |
else: | |
bdata.append(struct.unpack('b', bytes)[0]) # 1byte | |
hdata = [hex(x) for x in bdata] | |
return struct.pack("b"*len(bdata), *bdata), hdata | |
def parseFile(filename): | |
outputFile = open(filename + ".txt", 'w+', encoding="utf-16-be") | |
byteData = bread(filename)[0] | |
magicNumber = byteData[0:8] | |
print(f"Magic: {magicNumber}") | |
if(magicNumber != b'Asura '): return "Magic Number does not match..." | |
fileType = byteData[8:12] | |
print(f"File Type: {fileType} ({chr(fileType[0])})") | |
if(fileType[1:] == b'TXT'): | |
# Handle the byte skipping | |
if(chr(fileType[0]) == 'L' or chr(fileType[0]) == 'H'): byteData = byteData[28:] | |
elif(chr(fileType[0]) == 'P'): byteData = byteData[44:] | |
print("\n") | |
i = 0 | |
# Read strings until we're at the end of file (aka just 16 (or 9 if its an HTXT) NULL bytes) | |
while (byteData != b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): | |
if(fileType == b'HTXT' and byteData[0:10] == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): break | |
if(fileType == b'HTXT'): | |
print(f"String {hex(byteData[0])}") | |
byteData = byteData[4:] | |
consumed = 0 | |
stringLength = struct.unpack('H', byteData[0:2])[0] | |
print(f"Test: {[hex(x) for x in byteData[0:10]]}") | |
print(f"Parsing string of length: {hex(stringLength)} ({stringLength * 2})") | |
byteData = byteData[3:] | |
consumed += 1 | |
output = byteData[:stringLength*2].decode('utf-16-be').rstrip('\x00') | |
print(f"Total String: \"{output}\"") | |
outputFile.write(output + "\n") | |
consumed += (stringLength * 2) | |
print(f"Complete reading string #{i}") | |
print(f"Consumed {consumed} bytes...\n") | |
# For some reason the HTXT files have a few extra bytes in between each string | |
byteData = byteData[consumed:] | |
i += 1 | |
return f"Done parsing: {filename}" | |
print(parseFile("English.asr")) | |
print(parseFile("./l_text/names/n_En.asr")) | |
print(parseFile("./l_text/control/c_En.asr")) | |
print(parseFile("./l_text/scripted/s_En.asr")) | |
print(parseFile("./l_text/tannoy/t_En.asr")) | |
print(parseFile("./CSText/CS_En.asr")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment