Last active
November 25, 2018 08:22
-
-
Save kizzard/5315952ca714cb94a1c04a6c802c758c to your computer and use it in GitHub Desktop.
Automatic patch tool to correct bad head tracking camera planes in Farming Simulator 19.
This file contains hidden or 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
# Automatic patch tool to correct bad head tracking camera planes in Farming Simulator 19. | |
# The tool scans for X rotation values in indoor camera nodes in i3d files and sets them to 0. | |
# | |
# Change "rootPath" to your game install directory + "data\\vehicles" | |
# | |
# * Run with "python farmingSimulatorCameraFix.py patch" | |
# * Undo with "python farmingSimulatorCameraFix.py restore" | |
# | |
# Notes: | |
# * Doesn't fix mods - only original vehicles | |
# * Doesn't seem to work on some harvesters (TX32, maybe others) due to strange camera values. | |
# | |
# Written for Python 3 by Kizzard | |
import os, shutil, re, sys | |
MODE_PATCH_FILES = 0 | |
MODE_RESTORE_FILES = 1 | |
if len(sys.argv) > 1: | |
arg = sys.argv[1].lower() | |
if arg == "restore": | |
mode = MODE_RESTORE_FILES | |
elif arg == "patch": | |
mode = MODE_PATCH_FILES | |
else: | |
print("Unknown mode. Use 'patch' or 'restore'") | |
exit(1) | |
else: | |
print("FS19 Head Tracking angle fixer by Kizzard") | |
print("Mode required. Specify either 'patch' to patch files") | |
print("or 'restore' to restore them from backup to original state") | |
exit(0) | |
if mode == MODE_PATCH_FILES: | |
print("Patching FS19 files") | |
elif mode == MODE_RESTORE_FILES: | |
print("Restoring FS19 files") | |
rootPath = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Farming Simulator 19\\data\\vehicles" | |
filesToModify = [] | |
for root, dirs, filenames in os.walk(rootPath): | |
for filename in filenames: | |
if filename.endswith(".i3d"): | |
filesToModify.append(root + "\\" + filename) | |
if mode == MODE_PATCH_FILES: | |
for filename in filesToModify: | |
# Scan file for required changes | |
output = [] | |
modificationRequired = False | |
shortFilename = filename[filename.rfind("\\")+1:] | |
with open(filename, 'r') as ifh: | |
for line in ifh: | |
match = re.search('(.*<Camera name="indoorCamera.*?rotation=")(-?\d+)( 180 0".*)', line) | |
if match and match.group(2) != "0": | |
modificationRequired = True | |
print("Found required camera adjustment for " + shortFilename + ": " + match.group(2) + " -> 0") | |
output.append(match.group(1) + '0' + match.group(3) + "\n") | |
else: | |
output.append(line) | |
if modificationRequired: | |
# Copy backup of file. | |
backupFilename = filename + ".bak" | |
shortbackupFilename = backupFilename[backupFilename.rfind("\\")+1:] | |
print(" | Backing up " + shortFilename + " to " + shortbackupFilename) | |
shutil.copyfile(filename, backupFilename) | |
print(" | Writing adjustment to file... ", end="") | |
with open(filename, 'w', newline='\n') as ofh: | |
for line in output: | |
ofh.write(line) | |
print("Done.") | |
elif mode == MODE_RESTORE_FILES: | |
for filename in filesToModify: | |
shortFilename = filename[filename.rfind("\\")+1:] | |
backupFilename = filename + ".bak" | |
if os.path.isfile(backupFilename): | |
print("Restoring backup for " + shortFilename) | |
shutil.copyfile(backupFilename, filename) | |
print("All done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment