-
-
Notifications
You must be signed in to change notification settings - Fork 28
fix(lgpe): stop SAV7b party crashes + encounter NRE (#942–#946, #948, #949) #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9e4bcba
style: fix indentation in switch case blocks
codemonkey85 c84d835
Merge branch 'main' into dev
codemonkey85 c36ee7d
fix(lgpe): stop ArgumentOutOfRangeException crashes on SAV7b party + …
codemonkey85 040f42e
fix(lgpe): address PR #950 review — honor non-throw contract + avoid …
codemonkey85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| namespace Pkmds.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Regression tests for LGPE (SAV7b) party handling. Let's Go stores the party as a pointer list | ||
| /// into unified storage; an empty slot holds the SLOT_EMPTY sentinel, and reading or writing such | ||
| /// a slot via the index API throws <see cref="ArgumentOutOfRangeException"/>. Saves in the wild | ||
| /// (emulator / JKSM dumps) can report a <see cref="SaveFile.PartyCount"/> larger than the number of | ||
| /// populated pointer slots, which crashed the party grid, the editor save path, and CompactParty | ||
| /// (issues #942–#948). The safe extension helpers must tolerate that state instead of throwing. | ||
| /// </summary> | ||
| public class LgpePartySafetyTests | ||
| { | ||
| /// <summary> | ||
| /// Builds a Let's Go save whose reported party count exceeds the number of populated pointer | ||
| /// slots — the malformed state of the user-reported saves. The pointers stay at SLOT_EMPTY, so | ||
| /// every reported slot throws when read/written through PKHeX's index API. | ||
| /// </summary> | ||
| private static SAV7b CreateLgpeWithOverReportedParty(int reportedCount) | ||
| { | ||
| var sav = new SAV7b(); | ||
| sav.Storage.PartyCount = reportedCount; | ||
| return sav; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RawGetPartySlotAtIndex_PhantomSlot_Throws() | ||
| { | ||
| // Documents the underlying PKHeX behavior the safe helpers shield callers from. | ||
| var sav = CreateLgpeWithOverReportedParty(2); | ||
|
|
||
| Action act = () => sav.GetPartySlotAtIndex(0); | ||
|
|
||
| act.Should().Throw<ArgumentOutOfRangeException>(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetPartySlot_PhantomSlot_ReturnsNullInsteadOfThrowing() | ||
| { | ||
| var sav = CreateLgpeWithOverReportedParty(2); | ||
|
|
||
| sav.TryGetPartySlot(0).Should().BeNull(); | ||
| sav.TryGetPartySlot(5).Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetSafePartyCount_NoPopulatedSlots_ReturnsZero() | ||
| { | ||
| var sav = CreateLgpeWithOverReportedParty(6); | ||
|
|
||
| sav.GetSafePartyCount().Should().Be(0); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CompactParty_Lgpe_DoesNotThrow() | ||
| { | ||
| var sav = CreateLgpeWithOverReportedParty(6); | ||
|
|
||
| Action act = sav.CompactParty; | ||
|
|
||
| act.Should().NotThrow(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TrySetPartySlot_PhantomSlot_ReturnsFalseAndDoesNotThrow() | ||
| { | ||
| var sav = CreateLgpeWithOverReportedParty(2); | ||
| var pkm = new PB7 { Species = (ushort)Species.Pikachu }; | ||
|
|
||
| var result = true; | ||
| Action act = () => result = sav.TrySetPartySlot(pkm, 1); | ||
|
|
||
| act.Should().NotThrow(); | ||
| result.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetSafePartyCount_NonLgpeSave_EqualsPartyCount() | ||
| { | ||
| var sav = new SAV8SWSH(); | ||
|
|
||
| sav.GetSafePartyCount().Should().Be(sav.PartyCount); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.