Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple versions and romhacks for the same title id. #52

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ generator/output
generator/data/customsound.wav
bannertool*
makerom*
venv
venv
Binary file added assets/CPU.1/CPU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/CPU.1/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Renegade Platinum
Binary file added assets/CPU.2/CPU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/CPU.2/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Following Renegade Platinum
Binary file added assets/CPU/CPU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/CPU/CPU.wav
Binary file not shown.
108 changes: 94 additions & 14 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(self, infile: str, *, boxart: Optional[str], output: Optional[str],
gamecode: str = None
boxartcustom: bool = False
uniqueid: int = None
versions: list = ["Default"]
version_codes: list = [("Default", "Default")]
selected_version = 0

def message(self, output: str):
"""Outputting text. Defaults to print(). Can be replaced with other frontends (i.e. a GUI?)"""
Expand Down Expand Up @@ -172,21 +175,89 @@ def getgamecode(self):
self.gamecode = code
return 0

def checklocalassets(self):
if not self.boxart:
if os.path.isfile(f"assets/{self.gamecode}/{self.gamecode}.png"):
self.boxart = os.path.abspath(f"assets/{self.gamecode}/{self.gamecode}.png")
self.boxartcustom = True
elif os.path.isfile(f"assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.png"):
self.boxart = os.path.abspath(f"assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.png")
self.boxartcustom = True
if not self.sound:
if os.path.isfile(f"assets/{self.gamecode}/{self.gamecode}.wav"):
self.sound = os.path.abspath(f"assets/{self.gamecode}/{self.gamecode}.wav")
elif os.path.isfile(f"assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.wav"):
self.sound = os.path.abspath(f"assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.wav")
return 0

def get_available_versions(self):
misses = 0
idx = 1
codes = [self.gamecode, self.gamecode[0:3]]

for code in [self.gamecode, self.gamecode[0:3]]:
misses = 0
while misses < 2:
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{code}.{idx}/description.txt", timeout=15)
if r.status_code == 200:
self.versions.append(f"{r.text} ({code}.{str(idx)})")
self.version_codes.append((code, str(idx)))
idx = idx + 1
misses = 0
else:
misses = misses + 1 #allow 1 miss so that a deleted ID.1 does not cause ID.2 to be missed as well

def select_version(self):
self.message(f"Multiple versions found for {self.gamecode}")
self.message("Please select one of the following:")
for i in range(0, len(self.versions)):
self.message(f"{i} - {self.versions[i]}")
inp = input("Selection: ")
if inp.isnumeric():
inp = int(inp)
if inp >= 0 and inp < len(self.versions):
self.selected_version = inp
else:
self.message("Invalid selection, default version will be used.")
return 0

def download_version_from_github(self, version_id: int):
if version_id == 0:
return
version_code = self.version_codes[version_id][0]
version_nr = self.version_codes[version_id][1]
if not self.boxart:
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{version_code}.{version_nr}/{version_code}.png", timeout=15)
if r.status_code == 200:
f = open("data/banner.png", "wb")
f.write(r.content)
f.close()
self.boxart = os.path.abspath("data/banner.png")
self.boxartcustom = True
if not self.sound:
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{version_code}.{version_nr}/{version_code}.wav", timeout=15)
if r.status_code == 200:
f = open("data/customsound.wav", 'wb')
f.write(r.content)
f.close()
self.sound = os.path.abspath("data/customsound.wav")
return 0

def downloadfromgithub(self):
if not self.boxart:
r = requests.get(f"https://raw.githubusercontent.com/YANBForwarder/assets/main/assets/{self.gamecode}/{self.gamecode}.png", timeout=15)
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{self.gamecode}/{self.gamecode}.png", timeout=15)
if r.status_code != 200:
r = requests.get(f"https://raw.githubusercontent.com/YANBForwarder/assets/main/assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.png", timeout=15)
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.png", timeout=15)
if r.status_code == 200:
f = open("data/banner.png", "wb")
f.write(r.content)
f.close()
self.boxart = os.path.abspath("data/banner.png")
self.boxartcustom = True
if not self.sound:
r = requests.get(f"https://raw.githubusercontent.com/YANBForwarder/assets/main/assets/{self.gamecode}/{self.gamecode}.wav", timeout=15)
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{self.gamecode}/{self.gamecode}.wav", timeout=15)
if r.status_code != 200:
r = requests.get(f"https://raw.githubusercontent.com/YANBForwarder/assets/main/assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.wav", timeout=15)
r = requests.get(f"https://raw.githubusercontent.com/pivotiiii/YANBF/multiple_versions_romhacks/assets/{self.gamecode[0:3]}/{self.gamecode[0:3]}.wav", timeout=15)
if r.status_code == 200:
f = open("data/customsound.wav", 'wb')
f.write(r.content)
Expand Down Expand Up @@ -237,7 +308,7 @@ def resizebanner(self):
return 0

def makebanner(self):
bannertoolarg = f'bannertool makebanner -i "data/banner.png" -a "{self.sound}" -o "data/banner.bin"'
bannertoolarg = f'bannertool makebanner -i "{self.boxart}" -a "{self.sound}" -o "data/banner.bin"'
self.message(f"Using arguments: {bannertoolarg}")
bannertoolrun = subprocess.run(f'{self.cmdarg}{bannertoolarg}', shell=True, capture_output=True, universal_newlines=True)
if bannertoolrun.returncode != 0:
Expand Down Expand Up @@ -321,15 +392,22 @@ def start(self):
self.message("Creating SMDH...")
self.makesmdh()
if not self.boxart or not self.sound:
self.message("Checking API if a custom banner or sound is provided...")
self.downloadfromgithub()
if not self.sound:
self.sound = os.path.abspath("data/dsboot.wav")
if not self.boxart:
self.message("No banner provided. Checking GameTDB for standard boxart...")
if self.downloadboxart() != 0:
self.message("Banner was not found. Exiting.")
exit()
self.message("Checking local files for a custom banner or sound...")
self.checklocalassets()
if not self.sound or not self.boxart:
self.message("Checking API if a custom banner or sound is provided...")
self.get_available_versions()
if len(self.versions) > 1:
self.select_version()
self.download_version_from_github(self.selected_version)
self.downloadfromgithub() #again if custom version only had banner or sound
if not self.sound:
self.sound = os.path.abspath("data/dsboot.wav")
if not self.boxart:
self.message("No banner provided. Checking GameTDB for standard boxart...")
if self.downloadboxart() != 0:
self.message("Banner was not found. Exiting.")
exit()
self.message(f"Using sound file: {self.sound}")
self.message(f"Using banner image: {self.boxart}")
if not self.boxartcustom:
Expand Down Expand Up @@ -367,6 +445,8 @@ def start(self):
infile = args.input[0]
if args.output:
output = args.output[0]
else:
output = f"output/{os.path.basename(args.input[0])}.cia" #should be safe since infile is required
if args.sound:
sound = args.sound[0]
if args.path:
Expand Down