Skip to content

Commit

Permalink
Fixed error being thrown if form number is out of index.
Browse files Browse the repository at this point in the history
  • Loading branch information
FM1337 committed Jun 11, 2023
1 parent 6afc442 commit a025c89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
11 changes: 7 additions & 4 deletions coreconsole/Tests/SummaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!);
Expand Down
24 changes: 21 additions & 3 deletions coreconsole/models/Sprites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand All @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion internal/models/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a025c89

Please sign in to comment.