1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-26 06:36:19 +00:00
oot/tools/convert_chars.py
adaliaramon 6eb3bf401c
Removed unused imports and other minor improvements (#1602)
* Removed unused imports and other minor improvements

* revert tools/ZAPD/ZAPD/genbuildinfo.py

* revert diff.py

* Update sym_info.py

* revert asm_processor/

---------

Co-authored-by: fig02 <fig02srl@gmail.com>
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
2024-01-11 11:04:53 -05:00

61 lines
1.4 KiB
Python

#! /usr/bin/python3
import os
import re
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = script_dir + "/../"
def handle_match(match):
original_text = match.group()
match_text = original_text.replace("\\x", "")
if match_text.lower() == "1b":
return original_text
end = ""
if original_text.lower().endswith("\\x1b"):
end = original_text[-4:]
match_text = match_text[:-2]
try:
text = bytes.fromhex(match_text).decode("EUC-JP")
except UnicodeDecodeError:
return original_text
if text[2:].lower() == match_text.lower():
return original_text
return text + end
def process_file(file_path):
with open(file_path) as f:
file_text = f.read()
new_file_text = re.sub("(\\\\x[0-9a-zA-Z]{2})+", handle_match, file_text)
if new_file_text != file_text:
with open(file_path, "w") as f:
f.write(new_file_text)
return True
return False
def main():
i = 0
skip_list = ["z_file_choose.rodata.s", "z_kaleido_scope.rodata.s"]
for root, dirs, files in os.walk(root_dir):
for file in files:
if i == 100:
return
if file.endswith(".s") and file not in skip_list:
path = os.path.join(root, file)
if process_file(path):
print("Processed " + path)
i += 1
main()