Last active
March 22, 2020 15:54
-
-
Save rafalcieslak/6449dc03608ae48f77449091aef1b31e to your computer and use it in GitHub Desktop.
ReVolt stiff distant hood camera
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
import re | |
import os | |
import glob | |
CAMDATA = """ | |
;==================== | |
; Custom Camera | |
;==================== | |
CAMATTACHED { | |
HoodOffset 0.000000 -130.000000 -450.000000 | |
HoodLook 0.010000 | |
RearOffset 0.000000 0.000000 0.000000 | |
RearLook 0.000000 | |
UseDefault false | |
} | |
""" | |
# Before you run the script, backup original car data to `cars_backup` dir. | |
os.system("cp -r -T cars_backup cars") | |
pattern = re.compile("^([^{]*{.*}[^}]*)(}[^}]*)$", re.DOTALL) | |
for path in glob.glob("cars/*/parameters.txt"): | |
print(f"Patching {path}...") | |
with open(path, 'rb') as f: | |
# Some files use non-unicode characters in comments. | |
data = f.read().decode('utf8', errors='ignore') | |
count = 0 | |
def repl(m): | |
global count | |
count += 1 | |
return m.group(1) + CAMDATA + m.group(2) | |
data = re.sub(pattern, repl, data) | |
if count != 1: | |
raise RuntimeError(f"More than 1 match in file {path}") | |
with open(path, 'w') as f2: | |
f2.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment