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

Widescreen HUD Hack Patch for Echoes #108

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4d778fb
WidescreenHUD Patch
Nystrata Apr 25, 2024
f7c4210
Renamed FRME files to match names in PWE
Nystrata Apr 25, 2024
47dcc7f
Summary (Required)
Nystrata May 16, 2024
74e913e
Update dol_patches.py
Nystrata May 16, 2024
5b77a25
Update dol_patches.py
Nystrata May 16, 2024
1b5a9eb
Summary (required)
Nystrata May 18, 2024
7e8cf3e
Summary (required)
Nystrata May 18, 2024
3ba54eb
Merge branch 'main' into WidescreenHUDPatch
Nystrata Jul 27, 2024
336a29d
Seperate out apply_widescreen_hack_patch into it's own function
Nystrata Jul 27, 2024
2e60b8e
Remove prints from widescreen_hud\__init__
Nystrata Jul 27, 2024
dc07441
Clean up
Nystrata Jul 27, 2024
9a37e80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2024
892cf34
Make configurable via EchoesDolPatchesData
Nystrata Jul 27, 2024
c195eeb
Merge branch 'WidescreenHUDPatch' of https://github.com/Nystrata/open…
Nystrata Jul 27, 2024
cf03ff1
Add docstrings, pass version.description instead of the entire versio…
Nystrata Jul 28, 2024
55320f8
Restore vanila instructions when widescreen hack is disabled
Nystrata Jul 31, 2024
1ae075a
Merge branch 'randovania:main' into WidescreenHUDPatch
Nystrata Jul 31, 2024
432fc18
Merge branch 'main' into WidescreenHUDPatch
Nystrata Oct 12, 2024
a5544d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2024
9b3ad55
Merge branch 'randovania:main' into WidescreenHUDPatch
Nystrata Oct 26, 2024
f531082
Merge branch 'randovania:main' into WidescreenHUDPatch
Nystrata Oct 26, 2024
1a1af32
Update __init__.py - Fixed comment typo
Nystrata Oct 29, 2024
807463b
Move addresses to dol_versions.py
Nystrata Oct 30, 2024
ac0461b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 30, 2024
9a15c3d
Fixed variable typos
Nystrata Oct 30, 2024
27a8e76
Add comment explaining manual version detection
Nystrata Oct 31, 2024
a7be495
Comment typo fix
Nystrata Oct 31, 2024
6dfe945
Check if asset exists, instead of needing to deal with game versions
Nystrata Nov 1, 2024
eaa0d5d
Merge branch 'randovania:main' into WidescreenHUDPatch
Nystrata Nov 13, 2024
fb4896b
Merge branch 'randovania:main' into WidescreenHUDPatch
Nystrata Dec 5, 2024
20dc608
Update __init__.py
Nystrata Dec 5, 2024
0ec11ad
Rename variables to be more accurate, added comments
Nystrata Dec 6, 2024
377549c
Replace culling section with a simple float value change, updated com…
Nystrata Dec 7, 2024
579ae9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 7, 2024
7e91bd9
Remove usage of storing to r2
Nystrata Dec 8, 2024
bda18b6
Rework culling code, rename variables for clarity
Nystrata Dec 9, 2024
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
4 changes: 4 additions & 0 deletions src/open_prime_rando/dol_patching/echoes/dol_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EchoesDolPatchesData:
unvisited_room_names: bool
teleporter_sounds: bool
dangerous_energy_tank: bool
widescreen_hack: bool

@classmethod
def from_json(cls, data: dict):
Expand All @@ -33,6 +34,7 @@ def from_json(cls, data: dict):
unvisited_room_names=data["unvisited_room_names"],
teleporter_sounds=data["teleporter_sounds"],
dangerous_energy_tank=data["dangerous_energy_tank"],
widescreen_hack=data["widescreen_hack"],
)


Expand Down Expand Up @@ -67,4 +69,6 @@ def apply_patches(dol_file: DolFile, patches_data: EchoesDolPatchesData):
version.safe_zone, version.sda2_base, patches_data.safe_zone_heal_per_second, dol_file
)
dol_patches.apply_starting_visor_patch(version.starting_beam_visor, patches_data.default_items, dol_file)

dol_patches.apply_map_door_changes(version.map_door_types, dol_file)
dol_patches.apply_widescreen_hack(version.description, dol_file, patches_data.widescreen_hack)
47 changes: 47 additions & 0 deletions src/open_prime_rando/dol_patching/echoes/dol_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,50 @@ def apply_map_door_changes(door_symbols: MapDoorTypeAddresses, dol_file: DolFile

dol_file.symbols["CTweakAutoMapper::GetDoorColor::DoorColorArray"] = door_color_array
dol_file.write("CTweakAutoMapper::GetDoorColor::DoorColorArray", DoorMapIcon.get_surface_colors_as_bytes())


def apply_widescreen_hack(version_description: str, dol_file: DolFile, enabled: bool):
"""
Apply widescreen render hack to render the game in 16:9
"""
# Ported from gamemasterplc's 16:9 gecko code for NTSC-U
match version_description:
case "Gamecube NTSC":
culling_replacement = 0x8030256C
culling_insertion = 0x80418E8C
viewport_replacement = 0x8036D684
viewport_insertion = 0x80003748
Nystrata marked this conversation as resolved.
Show resolved Hide resolved
case "Gamecube PAL":
culling_replacement = 0x803029E0
culling_insertion = 0x803C6C30
viewport_replacement = 0x8036DAA0
viewport_insertion = 0x803B1D60
case _:
raise NotImplementedError

if enabled:
dol_file.write_instructions(culling_replacement, [bl(culling_insertion, relative=False)])
dol_file.write_instructions(culling_insertion, [lis(r14, 0x4000), stw(r14, 0, r2), lfs(f26, 0, r2), blr()])

dol_file.write_instructions(viewport_replacement, [b(viewport_insertion, relative=False)])
dol_file.write_instructions(
viewport_insertion,
[
lis(r14, 0x3FAA),
Nystrata marked this conversation as resolved.
Show resolved Hide resolved
ori(r14, r14, 0xAAAB),
stw(r14, 0, r2),
lfs(f19, 0, r2),
fmuls(f9, f19, 0, f9),
fdivs(f11, f10, f9, 0),
b(viewport_replacement + 0x4, relative=False),
],
)

return

# Restore vanilla behavior when widescreen hack is disabled
# To be removed when RDV is updated to no longer cache patched DOL files
dol_file.write(culling_replacement, [0xFF, 0x40, 0x10, 0x90])
dol_file.write(culling_insertion, (b"\0" * 16))
dol_file.write(viewport_replacement, [0xED, 0x6A, 0x48, 0x24])
dol_file.write(viewport_insertion, (b"\0" * 28))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions src/open_prime_rando/echoes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"description": "Set elevators to be activated on room load",
"default": false
},
"widescreen_hud": {
"type": "boolean",
"description": "Enable 16:9 widescreen HUD patch",
"default": false
},
"cosmetics": {
"type": "object",
"properties": {
Expand Down
30 changes: 30 additions & 0 deletions src/open_prime_rando/echoes/widescreen_hud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from retro_data_structures.base_resource import RawResource

from open_prime_rando.echoes.custom_assets import custom_asset_path
from open_prime_rando.echoes.widescreen_hud.asset_map import WIDESCREEN_HUD_ASSETS
from open_prime_rando.patcher_editor import PatcherEditor


def apply_widescreen_hud(editor: PatcherEditor):
"""
Replaces certain FRMEf files to adjust HUD/Visor widgets to better fit a 16:9 screen aspect ratio
Nystrata marked this conversation as resolved.
Show resolved Hide resolved
"""
if editor.does_asset_exists(0xEEF43AA1) and editor.does_asset_exists(0xF7EC0850):
detectedversion = "ntscu"
elif editor.does_asset_exists(0xB5CF0C19) and editor.does_asset_exists(0xD9D58FA5):
detectedversion = "pal"
else:
raise NotImplementedError
Nystrata marked this conversation as resolved.
Show resolved Hide resolved

for assetversion, assets in WIDESCREEN_HUD_ASSETS.items():
if detectedversion == assetversion:
widescreen_assets = custom_asset_path().joinpath("widescreen_hud", detectedversion)
for asset_id, filename in assets.items():
asset = widescreen_assets.joinpath(filename)
if not asset.exists():
continue
res = RawResource(
type="FRME",
data=asset.read_bytes(),
)
editor.replace_asset(asset_id, res)
17 changes: 17 additions & 0 deletions src/open_prime_rando/echoes/widescreen_hud/asset_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://github.com/Nystrata/EchoesWidescreenHUD/wiki#gguisyspak
from retro_data_structures.base_resource import AssetId

WIDESCREEN_HUD_ASSETS: dict[str, dict[AssetId, str]] = {
"ntscu": {
0xE6F37215: "FRME_Helmet.FRME",
0x88738D60: "FRME_SamusHud1Ball.FRME",
0xEEF43AA1: "FRME_SamusHud1Combat.FRME",
0xF7EC0850: "FRME_ScanHudFlat_0.FRME",
},
"pal": {
0xE6F37215: "FRME_Helmet.FRME",
0x88738D60: "FRME_SamusHud1Ball.FRME",
0xB5CF0C19: "FRME_SamusHud1Combat_0.FRME",
0xD9D58FA5: "FRME_ScanHudFlat_1.FRME",
},
}
4 changes: 4 additions & 0 deletions src/open_prime_rando/echoes_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from open_prime_rando.echoes.inverted import apply_inverted
from open_prime_rando.echoes.small_randomizations import apply_small_randomizations
from open_prime_rando.echoes.suit_cosmetics import apply_custom_suits
from open_prime_rando.echoes.widescreen_hud import apply_widescreen_hud
from open_prime_rando.patcher_editor import PatcherEditor
from open_prime_rando.validator_with_default import DefaultValidatingDraft7Validator

Expand Down Expand Up @@ -192,6 +193,9 @@ def patch_paks(

apply_custom_suits(editor, configuration["cosmetics"]["suits"])

if configuration["widescreen_hud"]:
apply_widescreen_hud(editor)

# Save our changes
editor.flush_modified_assets()

Expand Down