Pokemon Emerald: Fix terra/marine caves bugged internal id #3161
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.
What is this fixing or adding?
Terra and Marine Cave have 8 possible locations each with mutually exclusive internal location ids 1-16. Location id 0 means "no abnormal weather", hence starting at 1. But that means a possible value of 16 would require 5 bits, which is larger than the allotted size in the ROM of 4 bits.
I believe this results in a 1/8 chance that Kyogre is not findable, but nobody has reported that behavior. This was found while using #2995, which crashes when
struct.pack
is asked to fill a byte with a number that requires 9 bits to store.How was this tested?
Generated with a check in
_set_bytes_le
if the value was ever larger than the specified size until I hit the condition. Tried again with the same seed on this branch and it didn't fail. Though I suppose changing the size of the array it picks from affects RNG. Generating a few 20-player multis also didn't encounter the issue with the size check, which should happen 1/8 times.