soopercool101 / BrawlCrate

BrawlBox/BrawlTools Fork, Wii File Editor
https://discord.gg/s7c8763
GNU Lesser General Public License v3.0
144 stars 38 forks source link

Fix U8 tree corruption when saving #64

Closed Kevinn1109 closed 1 year ago

Kevinn1109 commented 1 year ago

BrawlCrate for a long time had issues with the U8 tree when saving any changes, or no changes at all in some cases. This was caused by two seperate bugs that influenced the value of the dataLength value in directory nodes:

  1. An off-by-one error when opening the archive combined with a ChildEndIndex check on a child node instead of the parent directory caused directories to be wrongfully put under a subdirectory of a sibling directory, something that would not be visible in the tree view because the tree view uses the parent idx field from the imported file instead.
  2. The last subdirectory in any directory would automatically put every single other node that followed in the tree under itself, as it unintendedly used a fallback value (the end of the tree).

Both points are addressed in this PR and U8 archives are now properly saved in the correct format.

soopercool101 commented 1 year ago

Looks good to me, appears to fix save corruption from my test cases. Thank you for the PR!