Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script fixes .col files to not crash on the PS2 version of GTA: SA, after conversion from col3 to col1
"""
This script fixes .col files to no crash on the PS2 version of GTA: SA, after conversion from col3 to col1.
Automating a step from this Tutorial[PT-BR] https://forum.mixmods.com.br/f49-tutoriais/t1411-gta-ps2-veiculos-beta
Fix Header of .col files located on the same folder of this script.
WARNING: This script overwrites the original files located on the script folder.
"""
from os import listdir
from os.path import isfile, join, dirname, splitext
fileList = [
f for f in listdir(dirname(__file__)) if isfile(join(dirname(__file__), f))
]
for file in fileList:
_, ext = splitext(file)
if ext == ".col":
print("Fixing header of", file, "...")
with open(file, mode="rb") as originalBinaryFile:
originalBinaryFile.seek(0, 2)
numOfBytes = originalBinaryFile.tell()
for i in range(numOfBytes):
originalBinaryFile.seek(i)
sample = originalBinaryFile.read(4)
# Search for 'CED2'
if sample == b"\x43\x45\x44\x32":
#print(">Header found at", str(i))
# Seek back to current index and jumps 'CED2'
originalBinaryFile.seek(i + 4)
data = originalBinaryFile.read(numOfBytes - i - 4)
# Overwrites the file
with open(file, mode="wb") as outputBinaryFile:
outputBinaryFile.write(data)
break
print("\nDone.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.