Skip to content

Commit 4cdcde0

Browse files
committed
Don't let you dreams be memes.
Aka I fixed some stupid shit.
1 parent cf0dc02 commit 4cdcde0

File tree

7 files changed

+856
-784
lines changed

7 files changed

+856
-784
lines changed

Controllers/LegalizeController.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public Legalize Legalize([FromForm] [Required] IFormFile pokemon, [FromForm] str
3434
{
3535
throw new System.ArgumentException("Bad data!");
3636
}
37+
generation = Utils.GetGeneration(pkm);
3738
}
3839
else
3940
{
@@ -54,8 +55,12 @@ public Legalize Legalize([FromForm] [Required] IFormFile pokemon, [FromForm] str
5455
{
5556
version = Utils.GetGameVersion(pkm).ToString();
5657
}
57-
58-
Legalize L = new Legalize(pkm, version);
58+
if(!Utils.PokemonExistsInGeneration(generation, pkm.Species))
59+
{
60+
Response.StatusCode = 400;
61+
return null;
62+
}
63+
Legalize L = new Legalize(pkm, version);
5964
return L;
6065
}
6166
// POST: api/LegalityCheck
@@ -76,6 +81,7 @@ public string CheckLegality([FromForm] [Required] IFormFile pokemon, [FromForm]
7681
{
7782
throw new System.ArgumentException("Bad data!");
7883
}
84+
generation = Utils.GetGeneration(pkm);
7985
}
8086
else
8187
{
@@ -92,6 +98,12 @@ public string CheckLegality([FromForm] [Required] IFormFile pokemon, [FromForm]
9298
return null;
9399
}
94100

101+
if (!Utils.PokemonExistsInGeneration(generation, pkm.Species))
102+
{
103+
Response.StatusCode = 400;
104+
return null;
105+
}
106+
95107
var la = new LegalityAnalysis(pkm);
96108
return la.Report();
97109
}
Lines changed: 105 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,119 @@
1-

2-
using Microsoft.AspNetCore.Http;
3-
using Microsoft.AspNetCore.Mvc;
4-
using CoreAPI.Helpers;
5-
using System.ComponentModel.DataAnnotations;
6-
using System.IO;
7-
using PKHeX.Core;
8-
using System;
9-
using CoreAPI.Models;
10-
using System.Linq;
11-
12-
namespace CoreAPI.Controllers
13-
{
14-
[ApiController]
15-
public class PokemonInfoController : ControllerBase
16-
{
17-
// POST: api/PokemonInfo
18-
[HttpPost]
19-
[Route("api/[controller]")]
20-
public PokemonSummary Post([FromForm] [Required] IFormFile pokemon, [FromForm] string generation)
21-
{
22-
using var memoryStream = new MemoryStream();
23-
pokemon.CopyTo(memoryStream);
24-
byte[] data = memoryStream.ToArray();
25-
PKM pkm;
26-
try
27-
{
1+

2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using CoreAPI.Helpers;
5+
using System.ComponentModel.DataAnnotations;
6+
using System.IO;
7+
using PKHeX.Core;
8+
using System;
9+
using CoreAPI.Models;
10+
using System.Linq;
11+
12+
namespace CoreAPI.Controllers
13+
{
14+
[ApiController]
15+
public class PokemonInfoController : ControllerBase
16+
{
17+
// POST: api/PokemonInfo
18+
[HttpPost]
19+
[Route("api/[controller]")]
20+
public PokemonSummary Post([FromForm] [Required] IFormFile pokemon, [FromForm] string generation)
21+
{
22+
using var memoryStream = new MemoryStream();
23+
pokemon.CopyTo(memoryStream);
24+
byte[] data = memoryStream.ToArray();
25+
PKM pkm;
26+
try
27+
{
2828
if (generation == "" || generation == null)
2929
{
3030
pkm = PKMConverter.GetPKMfromBytes(data);
3131
if (pkm == null)
3232
{
3333
throw new System.ArgumentException("Bad data!");
34-
}
35-
}
34+
}
35+
generation = Utils.GetGeneration(pkm);
36+
}
3637
else
3738
{
39+
Console.WriteLine(generation);
3840
pkm = Utils.GetPKMwithGen(generation, data);
3941
if (pkm == null)
4042
{
4143
throw new System.ArgumentException("Bad generation!");
4244
}
43-
}
44-
PokemonSummary PS = new PokemonSummary(pkm, GameInfo.Strings);
45-
return PS;
46-
}
47-
catch
48-
{
49-
return null;
50-
}
51-
}
52-
// POST: api/BasePokemon
53-
[HttpPost]
54-
[Route("api/BasePokemon")]
55-
public BasePokemon BasePokemon([FromForm] [Required] string pokemon, [FromForm] string form)
56-
{
57-
if (!Enum.GetNames(typeof(Species)).Any(s => s.ToLower() == pokemon))
58-
{
59-
Response.StatusCode = 400;
60-
return null;
61-
}
62-
try
63-
{
64-
Species s = (Species)Enum.Parse(typeof(Species), pokemon, true);
65-
var formNum = 0;
66-
if (form != null)
67-
{
68-
var forms = FormConverter.GetFormList((int)s, GameInfo.Strings.Types, GameInfo.Strings.forms, GameInfo.GenderSymbolASCII, 8);
69-
formNum = StringUtil.FindIndexIgnoreCase(forms, form);
70-
if (formNum < 0 || formNum >= forms.Length)
71-
{
72-
Response.StatusCode = 400;
73-
return null;
74-
}
75-
}
76-
77-
78-
79-
80-
var bp = Utils.GetBasePokemon((int)s, formNum);
81-
return bp;
82-
}
83-
catch
84-
{
85-
Response.StatusCode = 400;
86-
return null;
87-
}
88-
}
89-
// POST: api/GetForms
90-
[HttpPost]
91-
[Route("api/PokemonForms")]
92-
public string[] GetPokemonForms([FromForm] [Required] string pokemon)
93-
{
94-
if (!Enum.GetNames(typeof(Species)).Any(s => s.ToLower() == pokemon))
95-
{
96-
Response.StatusCode = 400;
97-
return null;
98-
}
99-
try
100-
{
101-
Species s = (Species)Enum.Parse(typeof(Species), pokemon, true);
102-
Utils.GetFormList((int)s);
103-
return Utils.GetFormList((int)s);
104-
}
105-
catch
106-
{
107-
return null;
108-
}
109-
}
110-
}
45+
}
46+
Console.WriteLine(pkm.Species);
47+
if (!Utils.PokemonExistsInGeneration(generation, pkm.Species))
48+
{
49+
Response.StatusCode = 400;
50+
return null;
51+
}
52+
PokemonSummary PS = new PokemonSummary(pkm, GameInfo.Strings);
53+
return PS;
54+
}
55+
catch
56+
{
57+
return null;
58+
}
59+
}
60+
// POST: api/BasePokemon
61+
[HttpPost]
62+
[Route("api/BasePokemon")]
63+
public BasePokemon BasePokemon([FromForm] [Required] string pokemon, [FromForm] string form)
64+
{
65+
if (!Enum.GetNames(typeof(Species)).Any(s => s.ToLower() == pokemon))
66+
{
67+
Response.StatusCode = 400;
68+
return null;
69+
}
70+
try
71+
{
72+
Species s = (Species)Enum.Parse(typeof(Species), pokemon, true);
73+
var formNum = 0;
74+
if (form != null)
75+
{
76+
var forms = FormConverter.GetFormList((int)s, GameInfo.Strings.Types, GameInfo.Strings.forms, GameInfo.GenderSymbolASCII, 8);
77+
formNum = StringUtil.FindIndexIgnoreCase(forms, form);
78+
if (formNum < 0 || formNum >= forms.Length)
79+
{
80+
Response.StatusCode = 400;
81+
return null;
82+
}
83+
}
84+
85+
86+
87+
88+
var bp = Utils.GetBasePokemon((int)s, formNum);
89+
return bp;
90+
}
91+
catch
92+
{
93+
Response.StatusCode = 400;
94+
return null;
95+
}
96+
}
97+
// POST: api/GetForms
98+
[HttpPost]
99+
[Route("api/PokemonForms")]
100+
public string[] GetPokemonForms([FromForm] [Required] string pokemon)
101+
{
102+
if (!Enum.GetNames(typeof(Species)).Any(s => s.ToLower() == pokemon))
103+
{
104+
Response.StatusCode = 400;
105+
return null;
106+
}
107+
try
108+
{
109+
Species s = (Species)Enum.Parse(typeof(Species), pokemon, true);
110+
Utils.GetFormList((int)s);
111+
return Utils.GetFormList((int)s);
112+
}
113+
catch
114+
{
115+
return null;
116+
}
117+
}
118+
}
111119
}

Helpers/AutoLegality.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public static void EnsureInitialized()
2626

2727
public static void Initalize()
2828
{
29-
//InitializeCoreStrings();
3029
Legalizer.AllowBruteForce = true;
3130
}
3231

@@ -39,18 +38,6 @@ public AutoLegality(PKM pk, string ver)
3938
return;
4039
}
4140

42-
private static void InitializeCoreStrings()
43-
{
44-
var lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Substring(0, 2);
45-
Util.SetLocalization(typeof(LegalityCheckStrings), lang);
46-
Util.SetLocalization(typeof(MessageStrings), lang);
47-
RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons);
48-
49-
// Update Legality Analysis strings
50-
LegalityAnalysis.MoveStrings = GameInfo.Strings.movelist;
51-
LegalityAnalysis.SpeciesStrings = GameInfo.Strings.specieslist;
52-
}
53-
5441
private void ProcessALM(PKM pkm, GameVersion ver = GameVersion.GP)
5542
{
5643
la = new LegalityAnalysis(pkm);

0 commit comments

Comments
 (0)