From dd554edf18fe42dca40c77a6ab1ba36fe16cd0ae Mon Sep 17 00:00:00 2001 From: Benjamin Popp Date: Thu, 6 Jun 2019 21:55:06 -0500 Subject: [PATCH] Auto-Search lvlmoves: Emerald Emerald didn't work because in Emerald, there's a false pointer at the start of one of the PLM runs. This is easy to correct: just add Pointer as a special case, since it is the only type of run that doesn't require having a name or pointer to it. --- src/HexManiac.Core/Models/PokemonModel.cs | 5 ++++- .../Models/Runs/ArrayRunElementSegment.cs | 2 +- src/HexManiac.Tests/AutoSearchTests.cs | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/HexManiac.Core/Models/PokemonModel.cs b/src/HexManiac.Core/Models/PokemonModel.cs index 6155676f..3a177d1c 100644 --- a/src/HexManiac.Core/Models/PokemonModel.cs +++ b/src/HexManiac.Core/Models/PokemonModel.cs @@ -804,7 +804,10 @@ namespace HavenSoft.HexManiac.Core.Models { var anchorRun = runs[index]; var newAnchorRun = anchorRun.RemoveSource(start); changeToken.RemoveRun(anchorRun); - if (newAnchorRun.PointerSources.Count == 0 && !anchorForAddress.ContainsKey(newAnchorRun.Start)) { + + // the only run that is allowed to exist with nothing pointing to it and no name is a pointer run. + // if it's any other kind of run with no name and no pointers to it, remove it. + if (newAnchorRun.PointerSources.Count == 0 && !anchorForAddress.ContainsKey(newAnchorRun.Start) && !(newAnchorRun is PointerRun)) { runs.RemoveAt(index); } else { runs[index] = newAnchorRun; diff --git a/src/HexManiac.Core/Models/Runs/ArrayRunElementSegment.cs b/src/HexManiac.Core/Models/Runs/ArrayRunElementSegment.cs index 6239296f..8bea0c26 100644 --- a/src/HexManiac.Core/Models/Runs/ArrayRunElementSegment.cs +++ b/src/HexManiac.Core/Models/Runs/ArrayRunElementSegment.cs @@ -180,7 +180,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { if (destination == Pointer.NULL) return true; var run = owner.GetNextAnchor(destination); if (run.Start < destination) return false; - if (run.Start > destination || (run.Start == destination && run is NoInfoRun)) { + if (run.Start > destination || (run.Start == destination && (run is NoInfoRun || run is PointerRun))) { // hard case: no format found, so check the data if (InnerFormat == PCSRun.SharedFormatString) { var length = PCSString.ReadString(owner, destination, true); diff --git a/src/HexManiac.Tests/AutoSearchTests.cs b/src/HexManiac.Tests/AutoSearchTests.cs index 8857c40d..af4e99e1 100644 --- a/src/HexManiac.Tests/AutoSearchTests.cs +++ b/src/HexManiac.Tests/AutoSearchTests.cs @@ -156,6 +156,17 @@ namespace HavenSoft.HexManiac.Tests { for (int i = 0; i < compareSet.Length; i++) Assert.Equal(compareSet[i], firstPokemonStats[i]); } + [SkippableTheory] + [MemberData(nameof(PokemonGames))] + public void LvlUpMovesAreFound(string game) { + var model = LoadModel(game); + var noChange = new NoDataChangeDeltaModel(); + + var address = model.GetAddressFromAnchor(noChange, -1, "lvlmoves"); + var run = (ArrayRun)model.GetNextAnchor(address); + Assert.NotNull(run); + } + [SkippableTheory] [MemberData(nameof(PokemonGames))] public void MoveDataFound(string game) {