Last active
February 21, 2023 20:52
-
-
Save DouglasAntunes/094d837a740dfcc7c1f4314326a42cce to your computer and use it in GitHub Desktop.
This script fixes .col files to not crash on the PS2 version of GTA: SA, after conversion from col3 to col1
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
""" | |
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