Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to work with racer.tab #9

Merged
merged 1 commit into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ This is a collection of small scripts to extract files from the 1999 Game "Star
- out_splineblock.py: Extract out_splineblock.bin to Wavefront OBJ files
- out_spriteblock.py: Extract out_spriteblock.bin to PNG files
- out_textureblock.py: Extract out_textureblock.bin to PNG files
- extract-racer-tab.py: Extracts strings from swep1rcr.exe which are typcially translated
- parse-racer-tab.py: Validates racer.tab translation files

Licensed under GPL version 2 or later.
49 changes: 49 additions & 0 deletions extract-racer-tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

import sys

strings = {}

for path in sys.argv[1:]:
with open(path, 'rb') as in_file:
data = in_file.read()

identifiers = [
b"/LANGID",
b"/CREDITS_H_",
b"/MONDOTEXT_H_",
b"/SCREENTEXT_"
]

for identifier in identifiers:
cursor = 0
while True:
start = data.find(identifier, cursor)
if start == -1:
break
sep = data.find(b"/", start + 1)
assert(sep > start)
end = data.find(b"\0", sep + 1)
assert(end > sep)

key = data[start + 1:sep]
value = data[sep + 1:end]

tmp = value.decode('windows-1252')
tmp = tmp.translate(str.maketrans({"\n": r"\n",
"\t": r"\t",
"\r": r"\r",
"\"": r"\"",
"\\": r"\\"}))
value = tmp.encode('windows-1252')

if key in strings:
print("Warning: duplicate key " + str(key), file=sys.stderr)
strings[key] = value

cursor = end + 1

for key in strings:
value = strings[key].decode('windows-1252')
key = key.decode('ascii')
print(key + "\t" + value + "\r\n", end='', flush=True)
40 changes: 40 additions & 0 deletions parse-racer-tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

import sys

strings = {}

for path in sys.argv[1:]:
with open(path, 'rb') as in_file:
data = in_file.read()

# FIXME: Make sure first 4 bytes are not 'ENCR' or decrypt file

cursor = 0
while(cursor < len(data)):
start = cursor

# Find end of this entry
while(cursor < len(data)):
if (data[cursor] == 10 or data[cursor] == 13):
break
cursor += 1
end = cursor

sep = data.find(9, start)
key = data[start:sep]
value = data[sep + 1:end]
if key in strings:
print("Warning: duplicate key " + str(key), file=sys.stderr)
strings[key] = value

# Move to next entry
while(cursor < len(data)):
if (data[cursor] != 10 and data[cursor] != 13):
break
cursor += 1

for key in strings:
value = strings[key].decode('windows-1252')
key = key.decode('ascii')
print("'" + key + "' -> '" + value + "'")