Skip to content

DirectoryBlob: fix data alignment for GC/Triforce and skip Triforce DIMM memory range#14599

Merged
JosJuice merged 1 commit into
dolphin-emu:masterfrom
naari3:fix/directoryblob-gc-triforce-alignment
Jun 28, 2026
Merged

DirectoryBlob: fix data alignment for GC/Triforce and skip Triforce DIMM memory range#14599
JosJuice merged 1 commit into
dolphin-emu:masterfrom
naari3:fix/directoryblob-gc-triforce-alignment

Conversation

@naari3

@naari3 naari3 commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

DirectoryBlob uses 0x8000 alignment for file data offsets when rebuilding the FST. This is needed for Wii disc group encryption, but for GC/Triforce it just inflates the disc image.

On Triforce games with many files (MKGP2 has ~8600), the inflated offsets can land in the DIMM memory range (0x1F000000-0x1F800000). AMMediaboard Read returns SRAM data instead of disc data for those offsets, which causes the game to hang.

This changes GC/Triforce alignment to 0x20 (matching original disc layout) and, for Triforce specifically, skips the DIMM memory range when assigning data offsets as a safety net for very large mods.

Tested with MKGP2 (GNLJ) + Riivolution:

  • A no-op patch (just triggering FST rebuild, no file changes) that hangs without this fix
  • ~60 MB of additional create="true" files pushing past the DIMM range, confirming the skip works
Riivolution patches used for testing

No-op patch (reproduces the hang without this fix):

<wiidisc version="1">
  <id game="GNLJ"/>
  <options>
    <section name="Test">
      <option name="Empty patch" default="1">
        <choice name="Enabled">
          <patch id="noop"/>
        </choice>
      </option>
    </section>
  </options>
  <patch id="noop"/>
</wiidisc>

DIMM range skip test (60 x 1MB files to push past 0x1F000000):

<wiidisc version="1">
  <id game="GNLJ"/>
  <options>
    <section name="Test">
      <option name="Add files" default="1">
        <choice name="Enabled">
          <patch id="add_files"/>
        </choice>
      </option>
    </section>
  </options>
  <patch id="add_files">
    <file disc="/dummy_01.bin" external="/testmod/dummy_01.bin" create="true"/>
    <file disc="/dummy_02.bin" external="/testmod/dummy_02.bin" create="true"/>
    <!-- ... 60 x 1MB random files total -->
    <file disc="/dummy_60.bin" external="/testmod/dummy_60.bin" create="true"/>
  </patch>
</wiidisc>

@naari3 naari3 changed the title DirectoryBlob: fix data alignment for GC/Triforce Riivolution patches DirectoryBlob: fix data alignment for GC/Triforce and skip Triforce DIMM memory range Apr 16, 2026
@naari3

naari3 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

I'm not familiar with how the actual Triforce hardware works, but perhaps disk reads should be performed before DIMM memory access. Since I couldn't determine the impact of that operation in this pull request, I've opted for the current approach.

@jordan-woyak

Copy link
Copy Markdown
Member

I'm not familiar with how the actual Triforce hardware works, but perhaps disk reads should be performed before DIMM memory access. Since I couldn't determine the impact of that operation in this pull request, I've opted for the current approach.

It does seem odd that the Disc would need to actively avoid the 0x1F000000-0x1F800000 region.

@JosJuice

Copy link
Copy Markdown
Member

0x20000000 is the max size of a Triforce game anyway, right? I feel like that's close enough to not be a coincidence.

Comment thread Source/Core/DiscIO/DirectoryBlob.cpp Outdated
Comment thread Source/Core/DiscIO/DirectoryBlob.cpp Outdated
Comment thread Source/Core/DiscIO/DirectoryBlob.cpp Outdated
@naari3

naari3 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

@JosJuice thanks a lot for the thorough review! I hadn't done enough homework here tbh.

On the overall direction: I'm not sure whether Riivolution added files should actually be constrained by Triforce's hardware layout. If they should, then even with 0x20 alignment the usable capacity is still pretty limited.

If they shouldn't be, we'd need some kind of special handling (for example, the skip in this PR, or moving the disc read check ahead of the DIMM dispatch in AMMediaboard, or running a special code path only when Riivolution is active). These are clear trade-offs though, so I'd understand if this ends up not being accepted.

@JosJuice

Copy link
Copy Markdown
Member

The skip in this PR sounds reasonable.

@naari3
naari3 requested a review from JosJuice April 21, 2026 15:58
@naari3
naari3 force-pushed the fix/directoryblob-gc-triforce-alignment branch from adcfcc6 to 7fc473c Compare April 24, 2026 09:44
Comment thread Source/Core/DiscIO/DirectoryBlob.cpp Outdated
@JosJuice

Copy link
Copy Markdown
Member

LGTM after squashing the commits into one.

…IMM memory range

The 0x8000 alignment in DirectoryBlob is needed for Wii disc group encryption,
but for GC/Triforce it inflates file offsets unnecessarily. Use 0x20 alignment
for Triforce (matching original disc layout) while keeping 0x8000 for GC due
to DTK audio streaming requirements.

On Triforce games with many files, the inflated offsets can land in the
AMMediaboard DIMM memory range (0x1F000000-0x1F800000). Reads from that
region return SRAM data instead of disc data, causing the game to hang.

Skip the DIMM range when assigning per-file data offsets if any portion of
the file would overlap [0x1F000000, 0x1F800000).
@naari3
naari3 force-pushed the fix/directoryblob-gc-triforce-alignment branch from 53f390d to e013d95 Compare April 25, 2026 10:48
@naari3

naari3 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

@JosJuice Squashed into one, thanks!

@JosJuice
JosJuice merged commit 9416eb9 into dolphin-emu:master Jun 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants