Skip to content

Instantly share code, notes, and snippets.

@Kodiologist
Created November 4, 2022 18:31
Show Gist options
  • Save Kodiologist/63c6af6dc0f760b4e0de7e1aafa85f79 to your computer and use it in GitHub Desktop.
Save Kodiologist/63c6af6dc0f760b4e0de7e1aafa85f79 to your computer and use it in GitHub Desktop.
Rename races in Remnants of the Precursors
#!/usr/bin/env python3
# (Requires Python 3.8 or later.)
#
# This script edits a JAR distribution of Remnants of the Precursors
# to rename the game's races. Edit `replacements` below to set
# the new names, or comment out a line to leave that race alone.
# Only English names are changed.
#
# This script was tested with RotP version 1.04.
#
# Usage: python3 rotp_race_rename.py INPUT_JAR_PATH OUTPUT_JAR_PATH
import sys, re
from zipfile import ZipFile as ZF
input_path, output_path = sys.argv[1:]
replacements = dict(
Altairi = 'New_Name_0',
Ursinathi = 'New_Name_1',
Nazlok = 'New_Name_2',
Human = 'New_Name_3',
Kholdan = 'New_Name_4',
Meklonar = 'New_Name_5',
Fiershan = 'New_Name_6',
Mentaran = 'New_Name_7',
Ssslaura = 'New_Name_8',
Cryslonoid = 'New_Name_9',
)
with ZF(input_path, 'r') as inp, ZF(output_path, 'w') as out:
old_names = {
m.group(1):
re.search(r'\nname: (\S+?),', inp.read(item).decode('UTF-8')).group(1)
for item in inp.namelist()
for m in [re.fullmatch(
r'rotp/lang/en/races/([^./]+)\.names\.txt',
item)]
if m}
for item in inp.namelist():
x = inp.read(item)
m = re.fullmatch(
r'rotp/lang/en/races/([^./]+)\.(intro|labels|names)\.txt',
item)
if m and (old_name := old_names[m.group(1)]) in replacements:
x = re.sub(old_name, replacements[old_name], x.decode('UTF-8'))
out.writestr(item, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment