Repository navigation
fix(asset tools, Windows): write dungeon maps in binary mode ("w" → "wb"); Windows text mode shifted 462 map offsets - #214
Merged
Conversation
Text mode turned 0x0A into 0x0D 0x0A on Windows, growing a 64-byte dungeon map to 67 bytes and shifting 462 offsets in map_offsets.h by +4 in full builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Result: on Windows, the asset tool wrote one binary dungeon map in text mode, so it grew from 64 to 67 bytes. The full build then recalculated every later map offset from file sizes, shifting 462 of them by 4 bytes. The game was compiled pointing at the wrong ROM data for late-game pause-screen dungeon maps and the Gyorg boss arena. Writing the file in binary mode keeps every offset matching the ROM.
The fix is one character,
"w"→"wb". On Linux and macOS, text and binary mode write identical bytes, so the line was always correct there. Only Windows translates0x0Ainto0x0D 0x0Ain text mode, so"wb"makes Windows behave the way Linux already does, with no change on other platforms.Files:
tools/src/asset_processor/assets/dungeonmap.cpp(1 line)Cause
DungeonMapAsset::buildToBinary()writesPalaceOfWinds_DarknutMiniboss/dungeon_map.bin(64 bytes, three0x0As) with"w", so Windows writes 67.build_assetsthen recomputes offsets from rebuilt sizes (67 → aligned 68) and overwritesbuild/USA/assets/map_offsets.h. 462 of 1,846 offsets, fromPalaceOfWinds_BombWallInsideon, move by +4. Slim builds and release CI never run this step.The
"w"dates from zeldaret/tmc (2022), where it's harmless: the decomp builds a new ROM from the same files, normally on Linux. Picori builds the tools on Windows and reads map data from the original ROM through these offsets.It also persists. The 67-byte file overwrites the extracted one, and the next
convert_assetsreads it back intodungeon_map.txt, so the corruption spreads into the editable files too. On an affected Windows tree, 8 Palace of Winds dungeon maps didn't match the ROM even after the one-character fix. Extraction skips files that already exist, so they stay wrong until re-extracted (#218 forces a re-extract when asset inputs change, which heals such trees).Effect in game (late game only)
src/common.c: Palace of Winds, Dark Hyrule Castle, others) draw shifted or garbled.src/enemy/gyorgFemale.c) decompresses its arena from the wrong start, giving wrong tiles and collision, possibly a softlock. The bounded LZ77 decompressor prevents a crash. Rooms loaded from the extracted area tables are unaffected.Verified
Each offset was checked in the USA ROM for the LZ77 header byte (
0x10):map_offsets.hPlay-tested to the Picori Festival (early game only). The affected rooms come later, so this rests on the ROM check.
Suggestion
build_assetsoverwriting a tracked header with sizes from rebuilt files is fragile for the PC port. Build mode could write elsewhere, or fail if its offsets differ from extract mode's.Developed with assistance from Claude Code (Opus 5.5). I reviewed and tested the changes as described above.