Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion tools/asm_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Calculate the number of instructions in a .s file
def calc_insns(f_path):
ret = 0
with open(f_path) as f:
with open(f_path, 'r', encoding='utf-8') as f:
Comment thread
Darxoon marked this conversation as resolved.
Outdated
f_lines = f.readlines()
for line in f_lines:
if line.startswith("/* "):
Expand Down
6 changes: 3 additions & 3 deletions tools/build/actor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, entry):
def read_actors_yaml(in_yaml: Path) -> List[ActorTypeEntry]:
actors: List[ActorTypeEntry] = []

with open(in_yaml) as f:
with open(in_yaml, "r", encoding="utf-8") as f:
entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader)

for entry in entry_list:
Expand Down Expand Up @@ -129,15 +129,15 @@ def generate_actors_enums(fout: TextIOWrapper, actors: List[ActorTypeEntry]):

actors = read_actors_yaml(args.actors_yaml)

with open(args.out_data, "w") as fout:
with open(args.out_data, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write('#include "common.h"\n')
fout.write('#include "message_ids.h"\n')
fout.write("\n")

generate_actors_data(fout, actors)

with open(args.out_enum, "w") as fout:
with open(args.out_enum, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write("\n")

Expand Down
2 changes: 1 addition & 1 deletion tools/build/audio/sbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_id(item):
def from_yaml(yaml_path: Path, asset_stack: Tuple[Path, ...]) -> SBN:
sbn = SBN()

with yaml_path.open("r") as f:
with yaml_path.open("r", encoding="utf-8") as f:
config = yaml.safe_load(f)

unknown_bin_path = get_asset_path("audio/unknown.bin", asset_stack)
Expand Down
6 changes: 3 additions & 3 deletions tools/build/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@

args.out_dir.mkdir(parents=True, exist_ok=True)

with open(args.out_dir / "effect_macros.h", "w") as f:
with open(args.out_dir / "effect_macros.h", "w", encoding="utf-8") as f:
f.write(macro_defs)

with open(args.out_dir / "effect_table.c", "w") as f:
with open(args.out_dir / "effect_table.c", "w", encoding="utf-8") as f:
f.write(main_decls_text + "\n" + effect_table_text + "};\n")

with open(args.out_dir / "effect_defs.h", "w") as f:
with open(args.out_dir / "effect_defs.h", "w", encoding="utf-8") as f:
f.write(effect_enum_text + "};\n\n" + fx_decls_text)
4 changes: 2 additions & 2 deletions tools/build/genobjcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
infile, outfile = sys.argv[1:]

# generate output based on input
file_data = open(infile, "r").read().split("\n")
file_data = open(infile, "r", encoding="utf-8").read().split("\n")
if len(file_data[-1]) == 0:
file_data.pop()

outdata = "-j " + " -j ".join(file_data)
with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
f.write(outdata)
2 changes: 1 addition & 1 deletion tools/build/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def build(out_bin: Path, out_header: Path, asset_stack: Tuple[Path, ...]):
with open(out_bin, "wb") as f:
f.write(out_bytes)

with open(out_header, "w") as f:
with open(out_header, "w", encoding="utf-8") as f:
f.write("#ifndef ICON_OFFSETS_H\n")
f.write("#define ICON_OFFSETS_H\n")
f.write(f"/* This file is auto-generated. Do not edit. */\n\n")
Expand Down
2 changes: 1 addition & 1 deletion tools/build/img/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
img = png.Reader(infile)
width, height, rows, info = img.read()

with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
f.write("// Generated file, do not edit.\n")
f.write(f"#ifndef _{cname.upper()}_\n")
f.write(f"#define _{cname.upper()}_\n")
Expand Down
4 changes: 2 additions & 2 deletions tools/build/imgfx/imgfx_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def fromJSON(name: str, data: Any) -> "Anim":


def build(inputs: List[Path], output: Path):
with open(output, "w") as f:
with open(output, "w", encoding="utf-8") as f:
f.write("/* NOTE: This file is autogenerated, do not edit */\n\n")
f.write('#include "PR/gbi.h"\n')
f.write('#include "macros.h"\n')
f.write('#include "imgfx.h"\n\n')

for input in inputs:
with open(input, "r") as fin:
with open(input, "r", encoding="utf-8") as fin:
in_json = json.load(fin)

anim = Anim.fromJSON(input.name[:-5], in_json)
Expand Down
6 changes: 3 additions & 3 deletions tools/build/item_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, entry):
def read_items_yaml(in_yaml: Path) -> List[ItemEntry]:
items: List[ItemEntry] = []

with open(in_yaml) as f:
with open(in_yaml, "r", encoding="utf-8") as f:
entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader)

for entry in entry_list:
Expand Down Expand Up @@ -309,7 +309,7 @@ def generate_item_icon_tables(fout: TextIOWrapper, items: List[ItemEntry]):
}
items.sort(key=lambda x: CATEGORY_ORDER.get(x.category, 999))

with open(args.out_data, "w") as fout:
with open(args.out_data, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write('#include "common.h"\n')
fout.write('#include "message_ids.h"\n')
Expand All @@ -334,7 +334,7 @@ def generate_item_icon_tables(fout: TextIOWrapper, items: List[ItemEntry]):
generate_item_entity_scripts_table(fout, items)
generate_item_icon_tables(fout, items)

with open(args.out_enum, "w") as fout:
with open(args.out_enum, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write("\n")

Expand Down
2 changes: 1 addition & 1 deletion tools/build/mapfs/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def run(in_bin: Path, out: Path) -> None:
shape = ShapeFile(map_name, file_bytes)
shape.digest()

with open(out, "w") as out_file:
with open(out, "w", encoding="utf-8") as out_file:
shape.write_to_c(out_file)


Expand Down
2 changes: 1 addition & 1 deletion tools/build/mapfs/tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def build(out_path: Path, tex_name: str, asset_stack: Tuple[Path, ...], endian:

json_path = get_asset_path(Path(f"mapfs/tex/{tex_name}.json"), asset_stack)

with open(json_path) as json_file:
with open(json_path, "r", encoding="utf-8") as json_file:
json_str = json_file.read()
json_data = json.loads(json_str)

Expand Down
6 changes: 3 additions & 3 deletions tools/build/move_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, entry):
def read_moves_yaml(in_yaml: Path) -> List[MoveEntry]:
items: List[MoveEntry] = []

with open(in_yaml) as f:
with open(in_yaml, "r", encoding="utf-8") as f:
entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader)

for entry in entry_list:
Expand Down Expand Up @@ -98,15 +98,15 @@ def generate_move_enum(fout: TextIOWrapper, moves: List[MoveEntry]):

moves = read_moves_yaml(args.moves_yaml)

with open(args.out_data, "w") as fout:
with open(args.out_data, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write('#include "common.h"\n')
fout.write('#include "message_ids.h"\n')
fout.write("\n")

generate_move_table(fout, moves)

with open(args.out_enum, "w") as fout:
with open(args.out_enum, "w", encoding="utf-8") as fout:
fout.write("/* This file is auto-generated. Do not edit. */\n")
fout.write("\n")

Expand Down
2 changes: 1 addition & 1 deletion tools/build/msg/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, d: dict, header_file_index: int):
f.write(b"\0\0\0\0")

if header_file is not None:
with open(header_file, "w") as f:
with open(header_file, "w", encoding="utf-8") as f:
f.write(f"#ifndef _MESSAGE_IDS_H_\n" f"#define _MESSAGE_IDS_H_\n" "\n" '#include "messages.h"\n' "\n")

for message in messages:
Expand Down
4 changes: 2 additions & 2 deletions tools/build/msg/parse_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,7 @@ def replacer(match):
messages = []

message = None
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
source = strip_c_comments(f.read())
lineno = 1

Expand Down Expand Up @@ -4452,7 +4452,7 @@ def replacer(match):
exit(1)

if is_output_format_c:
with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
f.write(f"#include <ultra64.h>\n")

for message in messages:
Expand Down
4 changes: 2 additions & 2 deletions tools/build/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, entry: List[str], order: Dict[str, int]):


def generate(in_yaml: Path, out_c: Path):
with open(in_yaml) as f:
with open(in_yaml, "r", encoding="utf-8") as f:
data = yaml.load(f.read(), Loader=yaml.SafeLoader)

products = data["Products"]
Expand Down Expand Up @@ -69,7 +69,7 @@ def generate(in_yaml: Path, out_c: Path):
# if not recipe[2] in product_idx:
# raise Exception(f"Product {recipe[2]} for ExtraDoubleRecipe ({recipe[0]}, {recipe[1]}) not listed in Products")

with open(out_c, "w") as f:
with open(out_c, "w", encoding="utf-8") as f:
f.write("/* This file is auto-generated. Do not edit. */\n\n")
f.write('#include "common.h"\n\n')

Expand Down
2 changes: 1 addition & 1 deletion tools/build/sprite/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

asset_stack = tuple(Path(d) for d in asset_stack_raw.split(","))

with open(outfile, "w") as f:
with open(outfile, "w", encoding="utf-8") as f:
# get sprite index
s = int(s_in)
assert s >= 1
Expand Down
4 changes: 2 additions & 2 deletions tools/build/sprite/sprite_shading_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def build(
):
END = ">" if endian == "big" else "<"

with open(input, "r") as f:
with open(input, "r", encoding="utf-8") as f:
json_data = json.load(f)

groups = groups_from_json(json_data)

# Header creation
with open(header_out, "w") as f:
with open(header_out, "w", encoding="utf-8") as f:
f.write("#ifndef SHADING_PROFILES_H\n")
f.write("#define SHADING_PROFILES_H\n")
f.write(f"/* This file is auto-generated from {input.name}. Do not edit. */\n\n")
Expand Down
2 changes: 1 addition & 1 deletion tools/build/sprite/sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def write_player_sprite_header(
sprite_id += 1

out_file.parent.mkdir(exist_ok=True, parents=True)
with open(out_file, "w") as f:
with open(out_file, "w", encoding="utf-8") as f:
f.write(f"#ifndef {ifdef_name}\n")
f.write(f"#define {ifdef_name}\n\n")

Expand Down
2 changes: 1 addition & 1 deletion tools/build/world_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def generate(in_xml: Path, out_c: Path):
xml = ET.parse(in_xml)
ScriptList = xml.getroot()

with open(out_c, "w") as f:
with open(out_c, "w", encoding="utf-8") as f:
f.write("#ifndef WORLD_MAP_H\n")
f.write("#define WORLD_MAP_H\n")
f.write("/* This file is auto-generated. Do not edit. */\n\n")
Expand Down
2 changes: 1 addition & 1 deletion tools/configure/src/configure/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ def main():
# add tools/build to import path
sys.path.insert(0, str(BUILD_TOOLS.resolve()))

ninja = ninja_syntax.Writer(open(str(ROOT / "build.ninja"), "w"), width=9999)
ninja = ninja_syntax.Writer(open(str(ROOT / "build.ninja"), "w", encoding="utf-8"), width=9999)

non_matching = args.non_matching or args.modern_gcc or args.shift

Expand Down
2 changes: 1 addition & 1 deletion tools/disasm_hud_element_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def print(self):

args = parser.parse_args()

with open(args.file, "r") as f:
with open(args.file, "r", encoding='utf-8') as f:
Comment thread
Darxoon marked this conversation as resolved.
Outdated
lines = f.readlines()
current_script = None

Expand Down
4 changes: 2 additions & 2 deletions tools/disasm_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def script_lib(offset=0):
LIB_LINE_RE = re.compile(r"\s+:\s+")
NAME_RE = re.compile(r"({[^}]*})?\s*([a-zA-Z0-9_]+)")
for filename in Path(path.dirname(__file__), "star-rod", "database").rglob("*.lib"):
with open(filename, "r") as file:
with open(filename, "r", encoding='utf-8') as file:
Comment thread
Darxoon marked this conversation as resolved.
Outdated
for line in file.readlines():
parts = LIB_LINE_RE.split(line)
if len(parts) >= 3:
Expand All @@ -37,7 +37,7 @@ def script_lib(offset=0):

repo_root = Path(__file__).resolve().parent.parent
symbols = Path(repo_root / "ver" / "current" / "symbol_addrs.txt")
with open(symbols, "r") as file:
with open(symbols, "r", encoding='utf-8') as file:
Comment thread
Darxoon marked this conversation as resolved.
Outdated
for line in file.readlines():
s = [s.strip() for s in line.split("=", 1)]
name = s[0]
Expand Down
39 changes: 18 additions & 21 deletions tools/find_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def parse_map(fname):
syms = {}
prev_sym = None
prev_line = ""
with open(fname) as f:
with open(fname, "r", encoding="utf-8") as f:
for line in f:
if "load address" in line:
if "noload" in line or "noload" in prev_line:
Expand Down Expand Up @@ -246,26 +246,23 @@ def output_match_dict(
num_perfect_dupes,
num_checked_files,
):
out_file = open(datetime.today().strftime("%Y-%m-%d-%H-%M-%S") + "_all_matches.txt", "w+")

out_file.write(
"Number of s-files: " + str(len(s_files)) + "\n"
"Number of checked s-files: " + str(round(num_checked_files)) + "\n"
"Number of decompiled duplicates found: " + str(num_decomped_dupes) + "\n"
"Number of undecompiled duplicates found: " + str(num_undecomped_dupes) + "\n"
"Number of overall exact duplicates found: " + str(num_perfect_dupes) + "\n\n"
)

sorted_dict = OrderedDict(sorted(match_dict.items(), key=lambda item: item[1][0], reverse=True))

print("Creating output file: " + out_file.name, end="\n")
for file_name, matches in sorted_dict.items():
out_file.write(file_name + " - found " + str(matches[0]) + " matches total:\n")
for match in matches[1]:
out_file.write(match + "\n")
out_file.write("\n")

out_file.close()
with open(datetime.today().strftime("%Y-%m-%d-%H-%M-%S") + "_all_matches.txt", "w+", encoding="utf-8") as out_file:
out_file.write(
"Number of s-files: " + str(len(s_files)) + "\n"
"Number of checked s-files: " + str(round(num_checked_files)) + "\n"
"Number of decompiled duplicates found: " + str(num_decomped_dupes) + "\n"
"Number of undecompiled duplicates found: " + str(num_undecomped_dupes) + "\n"
"Number of overall exact duplicates found: " + str(num_perfect_dupes) + "\n\n"
)

sorted_dict = OrderedDict(sorted(match_dict.items(), key=lambda item: item[1][0], reverse=True))

print("Creating output file: " + out_file.name, end="\n")
for file_name, matches in sorted_dict.items():
out_file.write(file_name + " - found " + str(matches[0]) + " matches total:\n")
for match in matches[1]:
out_file.write(match + "\n")
out_file.write("\n")


def is_decompiled(sym):
Expand Down
4 changes: 2 additions & 2 deletions tools/fix_sprite_xmls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def process_file(file_path):
with open(file_path, "r") as file:
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()

# Skip files that already have fixed="true"
Expand Down Expand Up @@ -35,7 +35,7 @@ def process_file(file_path):
r'<SetParent index="(\d+)"/>', lambda m: f'<SetParent index="{hex(int(m.group(1)))[2:].upper()}"/>', content
)

with open(file_path, "w") as file:
with open(file_path, "w", encoding="utf-8") as file:
file.write(content)
print(f"Updated: {file_path}")

Expand Down
Loading
Loading