This commit is contained in:
2025-05-25 23:37:40 +03:00
commit 7f054e2904
79 changed files with 4850 additions and 0 deletions

53
tools/makepak64.py Normal file
View File

@@ -0,0 +1,53 @@
#
# Copyright (C) 2013 The Tome of Preach
# Copyright (C) 2025 kotofyt
#
# This script implement generator of 64 bit version of pak.
# Basically all size 32 bit offsets and sizes replaced with 64 bit values
#
# Original source code is available at https://tomeofpreach.wordpress.com/2013/06/22/makepak-py/
#
import sys
import struct
import os
#dummy class for stuffing the file headers into
class FileEntry:
pass
#arguments are source directory, then target filename e.g. "pak1.pak"
rootdir = sys.argv[1]
pakfilename = sys.argv[2]
pakfile = open(pakfilename,"wb")
#write a dummy header to start with
pakfile.write(struct.Struct("<8s2q").pack(b"rttpacku",0,0))
#walk the directory recursively, add the files and record the file entries
offset = 24
fileentries = []
for root, subFolders, files in os.walk(rootdir):
for file in files:
entry = FileEntry()
impfilename = os.path.join(root,file)
entry.filename = os.path.relpath(impfilename,rootdir).replace("\\","/")
with open(impfilename, "rb") as importfile:
pakfile.write(importfile.read())
entry.offset = offset
entry.length = importfile.tell()
offset = offset + entry.length
fileentries.append(entry)
tablesize = 0
#after all the file data, write the list of entries
for entry in fileentries:
pakfile.write(struct.Struct("<56s").pack(entry.filename.encode("ascii")))
pakfile.write(struct.Struct("<q").pack(entry.offset))
pakfile.write(struct.Struct("<q").pack(entry.length))
tablesize = tablesize + 72
#return to the header and write the values correctly
pakfile.seek(0)
pakfile.write(struct.Struct("<8s2q").pack(b"rttpacku",offset,tablesize))