Last active
August 26, 2020 02:53
-
-
Save pmdevita/77651f53d09055cf8fa78a4f27a78a5b to your computer and use it in GitHub Desktop.
Search and replace text in Steins;Gate 0
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
[ | |
["Rintaro Okabe", "Okabe Rintaro"], | |
["Mayuri Shiina", "Shiina Mayuri"], | |
["Itaru Hashida", "Hashida Itaru"], | |
["Kurisu Makise", "Makise Kurisu"], | |
["Moeka Kiryu", "Kiryu Moeka"], | |
["Luka Urushibara", "Urushibara Luka"], | |
["Suzuha Amane", "Amane Suzuha"], | |
["Yugo Tennouji", "Tennouji Yugo"], | |
["Nae Tennouji", "Tennouji Nae"], | |
["Yuki Amane", "Amane Yuki"], | |
["Rumiho Akiha", "Akiha Rumiho"], | |
["Maho Hiyajo", "Hiyajo Maho"], | |
["Kagari Shiina", "Shiina Kagari"], | |
["Katsumi Nakase", "Nakase Katsumi"], | |
["Kaede Kurushima", "Kurushima Kaede"] | |
] |
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
import json | |
import sys | |
import os | |
from string import ascii_uppercase, ascii_lowercase | |
if len(sys.argv) == 1: | |
print("Drag the script.mpk file here and then hit enter. Also, make sure the patches.json file is next to this exe.") | |
file = input()[1:-1] | |
else: | |
file = sys.argv[1] | |
# Chdir to the same dir as the exe because patches.json is there | |
os.chdir(os.path.dirname(sys.argv[0])) | |
# Convert text to the byte string Steins;Gate 0 uses | |
def text_to_bytes(thing): | |
ascii_numbers = "0123456789" | |
ascii_punctuation = " ,.:;?! ‘’“”" # TODO: get the actual characters | |
convert = [] | |
for i in thing: | |
convert.append(128) | |
if i in ascii_uppercase: | |
convert.append(ascii_uppercase.find(i) + 138) | |
elif i in ascii_lowercase: | |
convert.append(ascii_lowercase.find(i) + 164) | |
elif i in ascii_numbers: | |
convert.append(ascii_numbers.find(i) + 128) | |
elif i == " ": | |
convert.append(63) | |
# print(bytes(convert)) | |
return bytes(convert) | |
with open(file, "rb") as f: | |
data = f.read() | |
try: | |
with open("patches.json", "r") as f: | |
patches = json.load(f) | |
except FileNotFoundError: | |
print("Make sure patches.json is next to the exe") | |
print("Press enter to exit...") | |
input() | |
sys.exit(0) | |
for i in patches: | |
print("Replaced", data.count(text_to_bytes(i[0])), "occurrences of", i[0], "to", i[1]) | |
data = data.replace(text_to_bytes(i[0]), text_to_bytes(i[1])) | |
with open(file, "wb") as f: | |
f.write(data) | |
print("Press enter to exit...") | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Committee of Zero has now released their patch for SG0, making this redundant. Go check it out here http://sonome.dareno.me/projects/sg0-steam.html