Skip to content

Instantly share code, notes, and snippets.

@FromDarkHell
Created November 19, 2020 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FromDarkHell/9d729df807ba5231a624d41ad2dcf6e1 to your computer and use it in GitHub Desktop.
Save FromDarkHell/9d729df807ba5231a624d41ad2dcf6e1 to your computer and use it in GitHub Desktop.
Call of Juarzez: Gunslinger Python Parts
from struct import *
import struct
import os
import sys, traceback
import json
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])
return struct.pack("b" * len(bdata), *bdata)
def readShort(arr):
sh = struct.unpack("<h", arr[0:2])[0]
arr = arr[2:]
return sh, arr
def readInt(arr):
val = struct.unpack("<i", arr[0:4])[0]
arr = arr[4:]
return val, arr
def readStr(arr):
stringLength = struct.unpack("<h", arr[0:2])[0]
arr = arr[2:]
output = arr[:stringLength]
if b"\x00" in output and stringLength != 1:
output = arr[: stringLength * 2]
stringLength *= 2
elif stringLength == 1:
output = arr[1:2]
stringLength += 1
elif output[0:3] == b"\xe5e," and stringLength == 3:
output = arr[0:6]
stringLength = 6
elif output[0:3] == b" \x04C" and stringLength == 7:
output = arr[0:14]
stringLength = 14
arr = arr[stringLength:]
return output, arr
magic = b"\x01\x00\x00\x00"
def parseFile(filename):
#
byteData = bread(filename)
if byteData[:4] != magic:
print("Magic does not match....")
return
print("Magic matches...")
byteData = byteData[4:]
entryAmount, byteData = readInt(byteData)
print(f"# of Entries: {entryAmount}")
kvpDict = {}
for x in range(entryAmount):
try:
keyName, byteData = readStr(byteData)
value, byteData = readStr(byteData)
kvpDict.update({str(keyName): str(value)})
except:
traceback.print_exc(file=sys.stdout)
break
with open(filename + "_IGNORE.json", "w+") as outputFile:
json.dump(kvpDict, outputFile, indent=4)
parseFile("./cotexts.bin")
parseFile("./covoices.bin")
parseFile("./coj4 voices&texts.bin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment