From a025c89788ef6cdc4b4b1601720d0862c0c1721c Mon Sep 17 00:00:00 2001 From: FM1337 <5448220+FM1337@users.noreply.github.com> Date: Sun, 11 Jun 2023 15:20:03 -0300 Subject: [PATCH] Fixed error being thrown if form number is out of index. --- coreconsole/Tests/SummaryTest.cs | 11 +++++++---- coreconsole/models/Sprites.cs | 24 +++++++++++++++++++++--- internal/models/requests.go | 1 - 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/coreconsole/Tests/SummaryTest.cs b/coreconsole/Tests/SummaryTest.cs index 0769235..be5543d 100644 --- a/coreconsole/Tests/SummaryTest.cs +++ b/coreconsole/Tests/SummaryTest.cs @@ -41,10 +41,13 @@ public void CanGetPokemonSummary() // "93376e1600009bec650300009bbc892640420f00af001200000000007ad56b4f0a0a04000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000788100000000000041006c006300720065006d00690065000000000000000000000021005502ba00090323140a0f0000000021005502000000000f013ffcff370a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000020000000000ff00000000000000000000000000000053006c0065006500700079000000000000000000000000000000a40513001d000715071d15071d0062ea280004810000000000000000000000000000000000000000000000000000000000000000000064000f017100ba00b400000112010000"; // const string a = // "000000000000bef065030000f87eb53840420f00a50014000000000051f74348121204000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041006c006300720065006d006900650000000000680000000000760107019c005502102010200303030321005502000000000f01ffffff3f0a000000000000000000000000000000000000000000000050004b0048006500580000000000000000000000000000000000000201000000320000000000000000000000000000000000000000002d000000020000000000ff00000000000000000000000000000054006f006d000000580000000000000000000000000000000000000000000000001501061501060062ea4400040100000000000000000000000000000000000000000000000000000000000000000000"; - const string a = - "1a9b12b00000701626020000537e0c70d8000000467800020000000000000000000000000000000021003700fd00000023190a0000000000b9227415000000000a13000000000000420061007300630075006c0069006e00ffff0000ffff001400000000000000004400650073006d0075006e006400ffff00000017021000000e00000406000000"; - var pkmnBytes = Helpers.StringToByteArray(a); - var pkmn = EntityFormat.GetFromBytes(pkmnBytes, EntityContext.Gen3); + // const string a = + // "1a9b12b00000701626020000537e0c70d8000000467800020000000000000000000000000000000021003700fd00000023190a0000000000b9227415000000000a13000000000000420061007300630075006c0069006e00ffff0000ffff001400000000000000004400650073006d0075006e006400ffff00000017021000000e00000406000000"; + var pkmn = Helpers.PokemonFromBase64( + "Wv//kAAADV2sAAAAXGjqBnhpAAAJAQAAWv//kAQKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEcAcgDpAGcAbwBpAHIAZQAAAAAAAAAAAAAADgFYAc8A3AAFBQUFAAAAAAAAAAAAAAAAAAD/UiCaQwBvAHIAZQB5AAAAAAAAAAAAAAAAAAAAAAAAAQYxAAAAAAAAAAAAAAAARgABBAcAAAAAAAAAAABTAEEAWQBGAAAAAAAAAAAAAAAAAAAAAAAAAEYAAAAAAAAAAAATCwIAAAAxdQQeAAgxBgEDAAAAAA=="); + + // var pkmnBytes = Helpers.StringToByteArray(a); + // var pkmn = EntityFormat.GetFromBytes(pkmnBytes, EntityContext.Gen3); // Get the summary var summary = Summary.GetSummary(pkmn!); diff --git a/coreconsole/models/Sprites.cs b/coreconsole/models/Sprites.cs index b5fd52f..f8fdb4c 100644 --- a/coreconsole/models/Sprites.cs +++ b/coreconsole/models/Sprites.cs @@ -89,8 +89,17 @@ private string ConstructSpeciesSprite(EntitySummary summary, PKM pkmn) { var checkBinding = true; var species = summary.Species.ToLower(); - var forms = FormConverter.GetFormList(pkmn.Species, GameInfo.Strings.types, GameInfo.Strings.forms, - GameInfo.GenderSymbolASCII, pkmn.Context); + string[] forms; + try + { + forms = FormConverter.GetFormList(pkmn.Species, GameInfo.Strings.types, GameInfo.Strings.forms, + GameInfo.GenderSymbolASCII, pkmn.Context); + } + catch (Exception e) + { + SentrySdk.CaptureException(e); + return ""; + } var path = $"{BaseUrl}"; @@ -100,7 +109,16 @@ private string ConstructSpeciesSprite(EntitySummary summary, PKM pkmn) path += "pokemon-gen8/"; path += pkmn.IsShiny ? "shiny/" : "regular/"; - var form = (forms[pkmn.Form] ?? "").ToLower(); + string form; + try + { + form = (forms[pkmn.Form] ?? "").ToLower(); + } + catch (Exception e) + { + SentrySdk.CaptureException(e); + form = ""; + } if (SpeciesWithFemaleForms.Contains(species) && pkmn.Gender == 2) { diff --git a/internal/models/requests.go b/internal/models/requests.go index 5d65a75..19af9b0 100644 --- a/internal/models/requests.go +++ b/internal/models/requests.go @@ -6,7 +6,6 @@ type GetInfoRequest struct { type GetInfoRequestB64 struct { Generation string `json:"generation" form:"generation" query:"generation" validate:"omitempty,oneof=Gen6 Gen7 Gen8 Gen8b"` - Base64 string `json:"base64" form:"base64" query:"base64" validate:"required"` } type LegalityCheckRequest struct {