Skip to content
Merged
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
54 changes: 54 additions & 0 deletions difficulty-mod/docs/features/78-lake-hylia-tree-wall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 78. Lake Hylia tree Gold Skulltula: the wall waits for the Longshot chest

Bug fix. No new setting; settings strings are unchanged.

## Requested

The logic says the Gold Skulltula in the tree at Lake Hylia (`LH GS Tree`: Longshot, and night) is reachable once you hold the Longshot. In the game an invisible hookshot wall in front of it stays until the Longshot chest in the Water Temple has been opened, whatever that chest holds.

## Cause

- The tree has an invisible wall (`FldObj_AirWall_Hookshot`) 5.9 units from the token, in both `HyruleField_Adult_Dynamic` and `HyruleField_Child_Dynamic`. Its presence is negated `WaterTemple_Room07_00`: it is there until that flag is set. By the `<Scene>_RoomNN_NN` pattern of chest flags this is the Longshot chest's opened flag (inferred from the flag list, not seen in the game).
- With the Longshot shuffled, the chest can hold something else and the Longshot can be found elsewhere. Logic then expects the token reachable while the wall blocks it. If the route to that chest needs something placed at the token, the seed cannot be finished.
- Of the 25 hookshot walls in the game this is the only one with a presence flag; the other 24 are always there, in the original game too, and are left alone.

## The fix

New file `randomizer/core/src/lake_tree_wall.rs`, staged right after the Water Temple gate (`water_gate.rs`). In both Dynamic files it rewrites the wall's presence flag from `WaterTemple_Room07_00` to the always-true expression used by the gate fix, so the wall never appears. The adult file is edited by both; `edit_staged` chains the two edits. Each edit checks the actor's hash, name, negation and old flag, and refuses a second application.

Applied always, not only when items are shuffled: with vanilla placement the chest gives the Longshot, so by the time the player can hook the tree the wall would have gone anyway; the only change is that it is gone earlier. A condition on a setting would need a second code path for no gain.

The logic rule stays `can_use(Longshot)`. Whether the plain Hookshot reaches the token with the wall gone is not known; the rule stays conservative until someone sees it.

A build report line is added (`NOTE`).

## Tested

- Unit tests (`cargo test -p ootrr-core lake_tree_wall`, game files set, 3 of 3 pass): both Dynamic files carry the wall with the chest flag before the edit and the always-true flag after, the actor count is unchanged, a second application is refused; the adult file staged after the water gate keeps both edits and is staged once; the stage is in the stage list.
- Without the fix (the stage left out of the list, tests kept): `a_default_build_stages_the_tree_wall` fails, the other two pass. The unfixed file itself is checked by the first test, which asserts the wall waits for `WaterTemple_Room07_00` before the edit. How often the bug occurs in generated seeds was not counted: not reproduced in the game; this is a guard against a seed that needs the token before the Longshot chest is open.
- Full workspace tests (`cargo test --workspace`, game files set, through the build gate): 1763 passed, 1 failed, 10 ignored. The failure was the build-report note count in `defaults_are_accepted_and_noted` (24 to 25, fixed in this change; that test and the rest of `support::` then pass, 25 of 25). The workspace was not run a second time.
- Default output: see below.
- Played by hand on the fix build, adult at Lake Hylia with the Water Temple Longshot chest not opened: the person playing reported that it worked. Scripted runs could not fire the hook, so nothing was measured by script.

## Default output

Not byte-identical to nightly by design. A default-preset build (time savers and 20 hearts, same seed text) from this branch and from nightly 1e7d9943 gives 290 files each; exactly three differ: `HyruleField_Adult_Dynamic` and `HyruleField_Child_Dynamic` (the wall's presence) and the resource size table. Every other file is identical. Seeds and settings strings are unchanged.

## How to test it in the game

Plan: `playtest/lh-tree-wall/PLAN.md`. By hand: adult, night (or Gold Skulltulas at any time on), Longshot, Water Temple Longshot chest not opened. Stand at Lake Hylia below the tree and hook the token. Before the fix the hook is stopped by the wall; after it the token is collected. Then the same with the Hookshot only, to decide whether the logic may be relaxed.

## MR Drafts

### Initial MR Draft
**Title:** Improved Logic > Gold Skulltula Fix: Lake Hylia tree token without the Water Temple chest

The Gold Skulltula in the tree at Lake Hylia is counted as reachable once you have the Longshot (and it is night). In the game an invisible wall in front of it stays until the Longshot chest in the Water Temple has been opened, even if the Longshot was found somewhere else.

With the Longshot shuffled, you could hold the Longshot and still be unable to hook that token, and a seed could need it.

This PR removes that wall, so the token can be hooked whenever the logic says it can.

For details about implementation and testing, see difficulty-mod/docs/features/78-lake-hylia-tree-wall.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 change: 1 addition & 0 deletions difficulty-mod/docs/features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ All 19 are in rc 4 (`<builds>\rc-4\`).
| 72 | [Hyrule Field sun fix](72-field-sun-palette-fix.md) (the sunrise bug) | none, always on | Partly, by script |
| 75 | [Return with Navi: saving after a locked room](75-navi-warp-keeps-saving.md) | `navi_return` (fix for #71, #72) | Reproduced in the game; fix not yet |
| 77 | [Archipelago: a slot with Shopsanity builds](77-ap-shopsanity-build.md) | none (fix in `ap::patch::check`) | No, scripted command line only |
| 78 | [Lake Hylia tree Gold Skulltula: the hookshot wall](78-lake-hylia-tree-wall.md) | none (fix in `lake_tree_wall`) | No, unit tests and a build only; test plan written, not run |
| 60 | [Kakariko Gate open: no dungeon item handed out at new game](60-new-game-dungeon-item-fix.md) | `open_kakariko` (fix) | No, from the generator and built data only |

Features 01 to 08 I built directly. Features 09 to 19 were built by sub-agents; what those files say about investigation and testing comes from the agents' reports, which I did not re-run except where noted.
142 changes: 142 additions & 0 deletions randomizer/core/src/lake_tree_wall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
use std::path::Path as P;

use crate::byml::{Byml, Node};
use crate::error::{Error, Res};
use crate::romfs::Romfs;
use crate::staging::Out;

pub const ADULT: &str = "Banc/HyruleField/HyruleField_Adult_Dynamic.bcett.byml.zs";
pub const CHILD: &str = "Banc/HyruleField/HyruleField_Child_Dynamic.bcett.byml.zs";
pub const ADULT_WALL: u64 = 9829790505452123995;
pub const CHILD_WALL: u64 = 6295005719083773433;
pub const WALL_GYAML: &str = "FldObj_AirWall_Hookshot";
pub const CHEST: &str = "WaterTemple_Room07_00";
pub const NOTE: &str = "The Gold Skulltula in the tree at Lake Hylia can be hooked as soon as you have the Longshot, wherever it was found. An invisible wall (FldObj_AirWall_Hookshot) in front of it stayed until the Longshot chest in the Water Temple was opened. Its presence now reads Get_StoneOfFire_IsAfter_Ready_Exp (always true) negated, so it never appears.";

pub fn patch(y: &mut Byml, hash: u64) -> Res<()> {
let actors: &mut Vec<Node> = y.root.get_mut("Actors").and_then(|n| n.as_arr_mut()).ok_or(Error::Format("lake tree wall: the Hyrule Field map has no actors"))?;
let a: &mut Node = actors
.iter_mut()
.find(|a| matches!(a.get("Hash"), Some(Node::U64(h)) if *h == hash))
.ok_or(Error::Format("lake tree wall: the Hyrule Field map has no Lake Hylia tree wall"))?;
if a.get("Gyaml").and_then(|g| g.as_str()) != Some(WALL_GYAML) {
return Err(Error::Format("lake tree wall: the tree wall is not a hookshot air wall"));
}
let p: &mut Node = a.get_mut("Presence").ok_or(Error::Format("lake tree wall: the tree wall has no presence"))?;
if p.get("IsNegation") != Some(&Node::Bool(true)) {
return Err(Error::Format("lake tree wall: the tree wall's presence is not negated"));
}
match p.get_mut("FlagName") {
Some(n) if n.as_str() == Some(CHEST) => *n = Node::Str(crate::always::NAME.to_string()),
_ => return Err(Error::Format("lake tree wall: the tree wall does not wait for the Longshot chest")),
}
Ok(())
}

pub fn bytes(raw: &[u8], hash: u64) -> Res<Vec<u8>> {
let mut y: Byml = Byml::parse(raw)?;
patch(&mut y, hash)?;
let out: Vec<u8> = y.write()?;
if Byml::parse(&out)?.root != y.root {
return Err(Error::Format("lake tree wall: the patched map does not read back"));
}
Ok(out)
}

pub fn stage(rf: &mut Romfs, more: &mut Vec<Out>, work: &P) -> Res<()> {
crate::staging::edit_staged(rf, more, work, ADULT, true, |r| bytes(r, ADULT_WALL))?;
crate::staging::edit_staged(rf, more, work, CHILD, true, |r| bytes(r, CHILD_WALL))
}

#[cfg(test)]
mod tests {
use super::*;

fn flag(out: &[u8], hash: u64) -> Option<String> {
let y: Byml = Byml::parse(out).unwrap();
let acts: &[Node] = y.root.get("Actors").and_then(|n| n.as_arr()).unwrap();
let w: &Node = acts.iter().find(|a| a.get("Hash") == Some(&Node::U64(hash)))?;
w.get("Presence").and_then(|p| p.get("FlagName")).and_then(|n| n.as_str()).map(|s| s.to_string())
}

#[test]
fn the_tree_wall_never_appears() {
let p: std::path::PathBuf = ootrr_game::test_romfs::path();
if !p.join("Pack").join("ZsDic.pack.zs").is_file() {
eprintln!("skipped, no RomFS dump at {} (set OOTRR_ROMFS)", p.display());
return;
}
let mut rf: Romfs = Romfs::open(&p).unwrap();
for (file, hash) in [(ADULT, ADULT_WALL), (CHILD, CHILD_WALL)] {
let raw: Vec<u8> = rf.read_zs(file).unwrap();
assert_eq!(flag(&raw, hash).as_deref(), Some(CHEST));
let out: Vec<u8> = bytes(&raw, hash).unwrap();
assert_eq!(flag(&out, hash).as_deref(), Some(crate::always::NAME));
assert!(bytes(&out, hash).is_err());
let a: Byml = Byml::parse(&raw).unwrap();
let b: Byml = Byml::parse(&out).unwrap();
let n: usize = a.root.get("Actors").and_then(|n| n.as_arr()).unwrap().len();
assert_eq!(b.root.get("Actors").and_then(|n| n.as_arr()).unwrap().len(), n);
}
}

#[test]
fn only_the_tree_wall_changes() {
let p: std::path::PathBuf = ootrr_game::test_romfs::path();
if !p.join("Pack").join("ZsDic.pack.zs").is_file() {
eprintln!("skipped, no RomFS dump at {} (set OOTRR_ROMFS)", p.display());
return;
}
let mut rf: Romfs = Romfs::open(&p).unwrap();
for (file, hash) in [(ADULT, ADULT_WALL), (CHILD, CHILD_WALL)] {
let raw: Vec<u8> = rf.read_zs(file).unwrap();
let out: Vec<u8> = bytes(&raw, hash).unwrap();
let a: Byml = Byml::parse(&raw).unwrap();
let b: Byml = Byml::parse(&out).unwrap();
let before: &[Node] = a.root.get("Actors").and_then(|n| n.as_arr()).unwrap();
let after: &[Node] = b.root.get("Actors").and_then(|n| n.as_arr()).unwrap();
assert_eq!(before.len(), after.len());
let mut changed: usize = 0;
for (x, y) in before.iter().zip(after.iter()) {
if x != y {
changed += 1;
assert_eq!(x.get("Hash"), Some(&Node::U64(hash)));
}
}
assert_eq!(changed, 1);
let walls: usize = before
.iter()
.filter(|n| n.get("Gyaml").and_then(|g| g.as_str()) == Some(WALL_GYAML) && n.get("Presence").is_some())
.count();
assert_eq!(walls, 1);
}
}

#[test]
fn staged_edits_keep_the_water_gate_edit() {
let p: std::path::PathBuf = ootrr_game::test_romfs::path();
if !p.join("Pack").join("ZsDic.pack.zs").is_file() {
eprintln!("skipped, no RomFS dump at {} (set OOTRR_ROMFS)", p.display());
return;
}
let mut rf: Romfs = Romfs::open(&p).unwrap();
let work: std::path::PathBuf = std::env::temp_dir().join("ootrr-lake-tree-wall-test");
let mut more: Vec<Out> = Vec::new();
crate::water_gate::stage(&mut rf, &mut more, &work).unwrap();
stage(&mut rf, &mut more, &work).unwrap();
assert_eq!(more.iter().filter(|o| o.path == ADULT).count(), 1);
let z: Vec<u8> = more.iter().find(|o| o.path == ADULT).unwrap().z.clone();
let raw: Vec<u8> = rf.zs.decompress(&z).unwrap();
assert_eq!(flag(&raw, ADULT_WALL).as_deref(), Some(crate::always::NAME));
assert_eq!(flag(&raw, crate::water_gate::WALL).as_deref(), Some(crate::always::NAME));
let z: Vec<u8> = more.iter().find(|o| o.path == CHILD).unwrap().z.clone();
let raw: Vec<u8> = rf.zs.decompress(&z).unwrap();
assert_eq!(flag(&raw, CHILD_WALL).as_deref(), Some(crate::always::NAME));
}

#[test]
fn a_default_build_stages_the_tree_wall() {
let found: bool = crate::slice::stages::STAGES.iter().any(|(n, _)| *n == "lake hylia tree wall");
assert!(found);
}
}
1 change: 1 addition & 0 deletions randomizer/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod bombchu_open;
pub mod door_fix;
pub mod door_gate;
pub mod water_gate;
pub mod lake_tree_wall;
pub mod door_open;
pub mod dungeon_fixes;
pub mod dungeon_credit;
Expand Down
7 changes: 6 additions & 1 deletion randomizer/core/src/slice/stages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Ctx<'a> {

pub type Stage = fn(&mut Romfs, &Ctx, &mut Vec<Out>) -> Res<()>;

pub const STAGES: [(&str, Stage); 27] = [
pub const STAGES: [(&str, Stage); 28] = [
("boss heart chests", boss_hearts),
("songs", songs),
("song models", song_models),
Expand All @@ -44,6 +44,7 @@ pub const STAGES: [(&str, Stage); 27] = [
("master sword pedestal", pedestal),
("bombchu alley", bombchu),
("water temple gate", water_gate),
("lake hylia tree wall", lake_tree_wall),
("medallion gate", medal_gate),
("fire temple gorons", fire_gorons),
("start reward and flags", start_reward),
Expand Down Expand Up @@ -161,6 +162,10 @@ fn water_gate(rf: &mut Romfs, c: &Ctx, more: &mut Vec<Out>) -> Res<()> {
crate::water_gate::stage(rf, more, c.work)
}

fn lake_tree_wall(rf: &mut Romfs, c: &Ctx, more: &mut Vec<Out>) -> Res<()> {
crate::lake_tree_wall::stage(rf, more, c.work)
}

fn pedestal(rf: &mut Romfs, c: &Ctx, more: &mut Vec<Out>) -> Res<()> {
more.extend(crate::door_open::stage_pedestal(rf, Some(c.work))?);
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion randomizer/core/src/slice/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ pub fn plan(s: &Settings) -> Res<Plan> {
notes.extend(door.notes());
notes.push(crate::bombchu_open::NOTE.to_string());
notes.push(crate::water_gate::NOTE.to_string());
notes.push(crate::lake_tree_wall::NOTE.to_string());
if short {
notes.push(crate::short_get::NOTE.to_string());
}
Expand Down Expand Up @@ -474,7 +475,8 @@ mod tests {
assert_eq!(p.keys.map, Keep::Dungeon);
assert!(p.intro);
assert!(p.story && p.endings);
assert_eq!(p.notes.len(), 24);
assert_eq!(p.notes.len(), 25);
assert!(p.notes.iter().any(|n| n == crate::lake_tree_wall::NOTE));
assert!(p.notes.iter().any(|n| n == crate::qol::gear_cycle::NOTE), "the gear cycle is always on");
assert!(p.short && p.notes.iter().any(|n| n == crate::short_get::NOTE));
assert!(!p.notes.iter().any(|n| n == crate::deku_bridge::NOTE));
Expand Down
Loading