Skip to content

Commit

Permalink
update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jnackmclain committed Apr 10, 2024
1 parent 6969d7f commit 2026985
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 102 deletions.
237 changes: 135 additions & 102 deletions dependencies/python/configure_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,46 @@
from pathlib import Path
import sys
import argparse
import json
import os

game_name = "Rock Band 2 Deluxe"

#versions
#gh1, gh2 - " "
#rb1, track packs - "-v 4"
#rb2, tbrb, gdrb - "-v 5"
#rb3, dc, blitz - "-v 6"
ark_version = "-v 5"

#require user provided vanilla ark extract in "vanilla/platform" folder
vanilla_files = False
generate_texture_list = False

#set True for rb1 and newer
new_gen = True
#rock band 1 has quirks that mix old_gen and new_gen
rb1 = False

script_dir = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.join(script_dir, 'config.json')
with open(config_path, 'r') as f:
config = json.load(f)
#patch for patch arks, main for patchcreator, old gen, and rb1
hdr_name = "patch"

ninja = ninja_syntax.Writer(open("build.ninja", "w+"))
dtb_encrypt = "-e"
#versions
# gh1, gh2 - "--miloVersion 25"
# rb1 onward - "--miloVersion 26"
miloVersion = "--miloVersion 26"

#paths in _ark/dx/custom_textures that should generate list dtbs
custom_texture_paths = [
"gems"
]

#patchcreator options
patchcreator = False
new_ark_part = "2"
dol_name = "main.dol"
elf_name = " "
bin_name = " "
xex_name = " "

parser = argparse.ArgumentParser(prog="configure")
parser.add_argument("platform")
Expand All @@ -25,44 +52,32 @@

args = parser.parse_args()

game_name = config.get("game_name", "")
ark_version = config.get("ark_version", "")
vanilla_files = config.get("vanilla_files", False)
new_gen = config.get("new_gen", False)
hdr_name = config.get("hdr_name", "")
dtb_encrypt = config.get("dtb_encrypt", "")
miloVersion = config.get("miloVersion", "")

if game_name == "Guitar Hero II Deluxe":
from vanilla_files import vanilla
if args.platform == "ps2":
hdr_name = hdr_name.upper()
dtb_encrypt = dtb_encrypt.upper()
miloVersion = "--preset gh2"

#new gen games (rb2 onward) add platform suffix to ark name
if new_gen == True:
match args.platform:
case "ps3":
hdr_name = hdr_name + "_ps3"
case "xbox":
hdr_name = hdr_name + "_xbox"
case "ps2":
hdr_name = "main_ps2"
hdr_name = hdr_name + "_" + args.platform

if game_name == "Rock Band 2 Deluxe":
from vanilla_files import wii
if args.platform == "ps2":
#all milo ps2 games from gh to rb use MAIN_0.ARK
hdr_name = "MAIN"
if new_gen == False:
#pre rb2 does not use miloVersion for superfreq image generation on ps2
miloVersion = " "
if rb1 == False:
#pre rb1 uses -E for dtb encryption on ps2
dtb_encrypt = dtb_encrypt.upper()

print(f"Configuring {game_name}...")
print(f"Platform: {args.platform}")

ninja = ninja_syntax.Writer(open("build.ninja", "w+"))

# configure tools
ark_dir = Path("obj", args.platform, "ark")
match sys.platform:
case "win32":
ninja.variable("silence", ">nul")
ninja.rule("copy", "cmd /c copy $in $out $silence", description="COPY $in")
if new_gen == True:
ninja.rule("bswap", "dependencies\\windows\\swap_art_bytes.exe $in $out", description="BSWAP $in")
ninja.rule("bswap", "dependencies\\windows\\swap_art_bytes.exe $in $out", description="BSWAP $in")
ninja.rule("version", "python dependencies\\python\\gen_version.py $out", description="Writing version info")
ninja.rule("png_list", "python dependencies\\python\\png_list.py $dir $out", description="PNGLIST $dir")
ninja.variable("superfreq", "dependencies\\windows\\superfreq.exe")
Expand All @@ -72,8 +87,7 @@
case "darwin":
ninja.variable("silence", "> /dev/null")
ninja.rule("copy", "cp $in $out", description="COPY $in")
if new_gen == True:
ninja.rule("bswap", "python3 dependencies/python/swap_rb_art_bytes.py $in $out", description="BSWAP $in")
ninja.rule("bswap", "python3 dependencies/python/swap_rb_art_bytes.py $in $out", description="BSWAP $in")
ninja.rule("version", "python3 dependencies/python/gen_version.py $out", description="Writing version info")
ninja.rule("png_list", "python3 dependencies/python/png_list.py $dir $out", description="PNGLIST $dir")
ninja.variable("superfreq", "dependencies/macos/superfreq")
Expand All @@ -84,44 +98,61 @@
case "linux":
ninja.variable("silence", "> /dev/null")
ninja.rule("copy", "cp --reflink=auto $in $out",description="COPY $in")
if new_gen == True:
ninja.rule("bswap", "dependencies/linux/swap_art_bytes $in $out", "BSWAP $in")
ninja.rule("bswap", "dependencies/linux/swap_art_bytes $in $out", "BSWAP $in")
ninja.rule("version", "python dependencies/python/gen_version.py $out", description="Writing version info")
ninja.rule("png_list", "python dependencies/python/png_list.py $dir $out", description="PNGLIST $dir")
ninja.variable("superfreq", "dependencies/linux/superfreq")
ninja.variable("arkhelper", "dependencies/linux/arkhelper")
ninja.variable("dtab", "dependencies/linux/dtab")
ninja.variable("dtacheck", "dependencies/linux/dtacheck")

#specify output directories per platform
match args.platform:
case "ps3":
out_dir = Path("out", args.platform, "USRDIR", "gen")
ninja.rule(
"ark",
f"$arkhelper dir2ark -n {hdr_name} -e -s 4073741823 {ark_version} --logLevel error {ark_dir} {out_dir}",
description="Building ark",
)
case "xbox":
out_dir = Path("out", args.platform, "gen")
ninja.rule(
"ark",
f"$arkhelper dir2ark -n {hdr_name} -e {ark_version} -s 4073741823 --logLevel error {ark_dir} {out_dir}",
description="Building ark",
)
case "wii":
out_dir = Path("out", args.platform, "files")
ninja.rule(
"ark",
f"$arkhelper patchcreator -a {ark_dir} -o {out_dir} platform/wii/files/gen/main_wii.hdr platform/wii/sys/main.dol --logLevel error",
description="Building ark",
)
case "ps2":
out_dir = Path("out", args.platform, "GEN")
ninja.rule(
"ark",
f"$arkhelper dir2ark -n {hdr_name} {ark_version} -s 4073741823 --logLevel error {ark_dir} {out_dir}",
description="Building ark",
)

#building an ark
if args.platform in ["ps3", "xbox", "ps2"] and patchcreator == False:
ark_encrypt = "-e"
#ps2 pre rb1 does not encrypt the ark
if args.platform == "ps2" and new_gen == False and rb1 == False:
ark_encrypt = " "
ninja.rule(
"ark",
f"$arkhelper dir2ark -n {hdr_name} {ark_version} {ark_encrypt} -s 4073741823 --logLevel error {ark_dir} {out_dir}",
description="Building ark",
)
#patchcreating an ark
if args.platform == "wii" or patchcreator == True:
#patch creator time! force using main as the root name
hdr_name = "main"
#append platform if this is new style ark
if new_gen == True:
hdr_name = hdr_name + "_" + args.platform
match args.platform:
case "wii":
hdr_path = "platform/" + args.platform + "/files/gen/" + hdr_name + ".hdr"
exec_path = "platform/" + args.platform + "/sys/" + dol_name
case "ps2":
hdr_path = "platform/" + args.platform + "/GEN/" + hdr_name.upper() + ".HDR"
exec_path = "platform/" + args.platform + "/" + elf_name
case "ps3":
hdr_path = "platform/" + args.platform + "/USRDIR/gen/" + hdr_name + ".hdr"
exec_path = "platform/" + args.platform + "/USRDIR/" + bin_name
case "xbox":
hdr_path = "platform/" + args.platform + "/gen/" + hdr_name + ".hdr"
exec_path = "platform/" + args.platform + "/" + xex_name
ninja.rule(
"ark",
f"$arkhelper patchcreator -a {ark_dir} -o {out_dir} {hdr_path} {exec_path} --logLevel error",
description="Building ark",
)

ninja.rule(
"sfreq",
Expand All @@ -136,7 +167,7 @@
build_files = []

# copy platform files
if args.platform != "wii":
if args.platform != "wii" and patchcreator == False:
for f in filter(lambda x: x.is_file(), Path("platform", args.platform).rglob("*")):
index = f.parts.index(args.platform)
out_path = Path("out", args.platform).joinpath(*f.parts[index + 1 :])
Expand All @@ -152,7 +183,7 @@ def ark_file_filter(file: Path):
return False
if file.suffix.endswith("_wii") and args.platform != "wii":
return False
if file.suffix.endswith("mogg") and new_gen != True:
if file.suffix.endswith("mogg") and args.platform == "ps2":
return False
if any(file.suffix.endswith(suffix) for suffix in ["_ps2", "vgs"]) and args.platform != "ps2":
return False
Expand All @@ -164,10 +195,6 @@ def ark_file_filter(file: Path):
# build ark files
ark_files = []

match args.platform:
case "wii":
ark_files, vanilla_files = wii(ark_files, args.platform, ninja, Path)

for f in filter(ark_file_filter, Path("_ark").rglob("*")):
match f.suffixes:
case [".png"]:
Expand Down Expand Up @@ -201,8 +228,16 @@ def ark_file_filter(file: Path):
)
wii_output = wii_directory.joinpath(target_filename)
ninja.build(str(wii_output), "sfreq", str(f), variables={"platform": "wii"})
if str(out_path) not in ark_files:
ark_files.append(str(wii_output))
ark_files.append(str(wii_output))
#disabled as we need resizing
#case "ps2":
# target_filename = Path("gen", f.stem + ".png_ps2")
# ps2_directory = Path("obj", args.platform, "ark").joinpath(
# *f.parent.parts[1:]
# )
# ps2_output = ps2_directory.joinpath(target_filename)
# ninja.build(str(ps2_output), "sfreq", str(f), variables={"platform": "ps2"})
# ark_files.append(str(ps2_output))

case [".dta"]:
target_filename = Path("gen", f.stem + ".dtb")
Expand All @@ -226,14 +261,12 @@ def ark_file_filter(file: Path):
implicit=[str(stamp), "_always"],
)
ninja.build(str(encryption_output), "dtab_encrypt", str(serialize_output))
if str(out_path) not in ark_files:
ark_files.append(str(encryption_output))
ark_files.append(str(encryption_output))
case _:
index = f.parts.index("_ark")
out_path = Path("obj", args.platform, "ark").joinpath(*f.parts[index + 1 :])
ninja.build(str(out_path), "copy", str(f))
if str(out_path) not in ark_files:
ark_files.append(str(out_path))
ark_files.append(str(out_path))

# write version info
dta = Path("obj", args.platform, "raw", "dx", "locale", "dx_version.dta")
Expand All @@ -246,48 +279,48 @@ def ark_file_filter(file: Path):

ark_files.append(str(enc))

if vanilla_files == True:
#copy vanilla files to obj if required
if vanilla_files == True and patchcreator == False:
from vanilla_files import vanilla
ark_files, vanilla_files = vanilla(ark_files, args.platform, ninja, Path)

def generate_texture_list(input_path: Path):
base = input_path.parts[1:]
dta = Path("obj", args.platform, "raw").joinpath(*base).joinpath("_list.dta")
dtb = Path("obj", args.platform, "raw").joinpath(*base).joinpath("gen", "_list.dtb")
enc = Path("obj", args.platform, "ark").joinpath(*base).joinpath("gen", "_list.dtb")
ninja.build(str(dta), "png_list", variables={"dir": str(input_path)}, implicit="_always")
ninja.build(str(dtb), "dtab_serialize", str(dta))
ninja.build(str(enc), "dtab_encrypt", str(dtb))

root_path = Path("_ark", "dx", "custom_textures")
for texture_list_path in [root_path.joinpath(path) for path in custom_texture_paths]:
generate_texture_list(texture_list_path)

# build ark
ark_part = "0"
if patchcreator == True:
ark_part = new_ark_part
match args.platform:
case "ps3":
hdr = str(Path("out", args.platform, "USRDIR", "gen", "patch_ps3.hdr"))
ninja.build(
str(Path("out", args.platform, "USRDIR", "gen", "patch_ps3_0.ark")),
"ark",
implicit=ark_files,
implicit_outputs=[hdr],
)
build_files.append(hdr)
hdr = str(Path("out", args.platform, "USRDIR", hdr_name + ".hdr"))
ark = str(Path("out", args.platform, "USRDIR", hdr_name + "_" + ark_part + ".ark"))
case "xbox":
hdr = str(Path("out", args.platform, "gen", "patch_xbox.hdr"))
ninja.build(
str(Path("out", args.platform, "gen", "patch_xbox_0.ark")),
"ark",
implicit=ark_files,
implicit_outputs=hdr,
)
build_files.append(hdr)
hdr = str(Path("out", args.platform, hdr_name + ".hdr"))
ark = str(Path("out", args.platform, hdr_name + "_" + ark_part + ".ark"))
case "wii":
hdr = str(Path("out", args.platform, "files", "gen", "main_wii.hdr"))
ninja.build(
str(Path("out", args.platform, "files", "gen", "main_wii_10.ark")),
"ark",
implicit=ark_files,
implicit_outputs=hdr,
)
build_files.append(hdr)
hdr = str(Path("out", args.platform, "files", hdr_name + "_" + args.platform + ".hdr"))
ark = str(Path("out", args.platform, "files", hdr_name + "_" + args.platform + "_" + ark_part + ".ark"))
case "ps2":
hdr = str(Path("out", args.platform, "GEN", "MAIN.HDR"))
ninja.build(
str(Path("out", args.platform, "GEN", "MAIN_0.ARK")),
"ark",
implicit=ark_files,
implicit_outputs=hdr,
)
build_files.append(hdr)
hdr = str(Path("out", args.platform, hdr_name + ".HDR"))
ark = str(Path("out", args.platform, hdr_name + "_" + ark_part + ".ARK"))
ninja.build(
ark,
"ark",
implicit=ark_files,
implicit_outputs=[hdr],
)
build_files.append(hdr)

# make the all target build everything
ninja.build("all", "phony", build_files)
Expand Down
15 changes: 15 additions & 0 deletions dependencies/python/png_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path
import sys

directory = Path(sys.argv[1])

if not directory.is_dir():
raise Exception("not a directory")

out_path = sys.argv[2]

f = open(out_path, "w")
for file in sorted(directory.glob("*")):
f.write(f"'{file.stem}'\n")

f.close()

0 comments on commit 2026985

Please sign in to comment.