diff --git a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/EggCreatorTests.cs b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/EggCreatorTests.cs
new file mode 100644
index 0000000..32e831d
--- /dev/null
+++ b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/EggCreatorTests.cs
@@ -0,0 +1,29 @@
+using pkhexEgglocke;
+using pkhexEgglockeTests;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace pkhexEgglockeTests
+{
+ [TestClass]
+ public class EggCreatorTests
+ {
+ [TestMethod]
+ public void TestDecoder()
+ {
+ SaveWriter sw = new SaveWriter(testConstants.JOHTO_PLUS_SOUL_SILVER_SAVE);
+
+ EggCreator ec = EggCreator.decodeJSON(testConstants.BLANK_GEN4_MAREEP_VALID);
+
+ sw.addEgg(ec, 1);
+
+ sw.export("testPROG.sav");
+
+ }
+
+
+ }
+}
diff --git a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/SaveWriterTest.cs b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/SaveWriterTest.cs
index fb602c9..d095656 100644
--- a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/SaveWriterTest.cs
+++ b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/SaveWriterTest.cs
@@ -12,7 +12,7 @@ public class SaveWriterTest
public void TestSaveImportConstructorDoesNotCrashOnValidFile()
{
- SaveWriter sw = new SaveWriter(testConstants.BLANK_SOULSILVER_SAVE);
+ SaveWriter sw = new SaveWriter(testConstants.JOHTO_PLUS_SOUL_SILVER_SAVE);
}
@@ -30,7 +30,7 @@ public void TestSaveExportConstructorCrashesOnInvalidFile()
public void TestSaveImportOTMatches()
{
string expectedOT = testConstants.BLANK_SOULSILVER_OT_STRING;
- SaveWriter sw = new SaveWriter(testConstants.BLANK_SOULSILVER_SAVE);
+ SaveWriter sw = new SaveWriter(testConstants.JOHTO_PLUS_SOUL_SILVER_SAVE);
string actualOT = sw.getOTString();
Assert.AreEqual(expectedOT, actualOT);
@@ -42,7 +42,7 @@ public void TestSaveImportOTMatches()
public void TestSaveImportVersionMatches()
{
string expectedOT = testConstants.BLANK_SOULSILVER_OT_STRING;
- SaveWriter sw = new SaveWriter(testConstants.BLANK_SOULSILVER_SAVE);
+ SaveWriter sw = new SaveWriter(testConstants.JOHTO_PLUS_SOUL_SILVER_SAVE);
string actualOT = sw.getOTString();
Assert.AreEqual(expectedOT, actualOT);
diff --git a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/pkhexEgglockeTests.csproj b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/pkhexEgglockeTests.csproj
index 9adefdf..0d0b4a2 100644
--- a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/pkhexEgglockeTests.csproj
+++ b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/pkhexEgglockeTests.csproj
@@ -33,6 +33,9 @@
Always
+
+ Always
+
diff --git a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testConstants.cs b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testConstants.cs
index 78f0ee9..38c06fb 100644
--- a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testConstants.cs
+++ b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testConstants.cs
@@ -10,13 +10,18 @@ namespace pkhexEgglockeTests
public static class testConstants
{
// Gen 4 - Soul Silver Blank Save File
- public static string BLANK_SOULSILVER_SAVE => Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"testSources"), "emptySoulSilver.sav");
+ public static string JOHTO_PLUS_SOUL_SILVER_SAVE => Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"testSources"), "emptySoulSilver.sav");
public static string BLANK_SOULSILVER_OT_STRING => "Egg";
+ // Gen 4 - Blank JSON
+ public static string BLANK_GEN4_MAREEP_VALID => Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"testSources"), "Mareep.json");
// Gen 6 - Omega Ruby Save File
public static string BLANK_OMEGARUBY_SAVE => Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"testSources"), "emptyOmegaRuby.sav");
+
+
+
}
}
diff --git a/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testSources/Mareep.json b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testSources/Mareep.json
new file mode 100644
index 0000000..7500fb5
--- /dev/null
+++ b/pkhex/pkhex-egglocke-tests/pkhex-egglocke-tests/testSources/Mareep.json
@@ -0,0 +1,15 @@
+{
+ "dexNumber": 179,
+ "ball": 2,
+ "language": 1,
+ "ability":9,
+ "nature": 1,
+ "OT": "Dawn",
+ "OTGender": 1,
+ "nickname": "WLW",
+ "IV": [ 31, 31, 31, 31, 31, 31 ],
+ "EV": [ 0, 0, 0, 0, 0, 0 ],
+ "moves": [ 425, 262 ],
+ "movespp": [ 30, 40 ]
+
+}
\ No newline at end of file
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/EggCreator.cs b/pkhex/pkhex-egglocke/pkhex-egglocke/EggCreator.cs
new file mode 100644
index 0000000..5e564d5
--- /dev/null
+++ b/pkhex/pkhex-egglocke/pkhex-egglocke/EggCreator.cs
@@ -0,0 +1,137 @@
+/* PokemonCreator.cs
+* Bridge class that creates PkHEX pokemon files based on JSON objects exported from web app.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PKHeX.Core;
+using Newtonsoft.Json;
+using System.Text.RegularExpressions;
+
+namespace pkhexEgglocke
+{
+ ///
+ /// PokemonCreator: Pokemon data class that decodes JSON pokemon descriptors and
+ ///
+ ///
+
+ // Parameters
+ // These parameters mostly allow you to set rules around what user submissions you'd like to include (ex. allow user-supplied IVs)
+
+
+ internal class EggCreator
+ {
+
+ protected bool allowUserIVs => true;
+ protected bool allowUserShiny => true;
+ protected bool allowUser => true;
+
+ // Egg Parameters that are always true
+ public bool IsEgg = true;
+ public ushort EggLocationDP = Locations.Daycare4;
+ public byte MetLevel = 0;
+
+ //Other constant fields
+ public int language = (int)LanguageID.English;
+
+
+ // Mutable fields
+ public byte ball = (int)Ball.Dive;
+
+ public ushort dexNumber = 1;
+ public int Language = 1;
+ public int Ability = 2;
+ public Nature Nature = Nature.Adamant;
+
+
+
+ //Misc creator stuff
+ public string OT = "Default";
+ public byte OTGender = (int)Gender.Female;
+ public string nickname = "Hello";
+
+ public int[] IV = [31, 31, 31, 31, 31, 31];
+ public int[] EV = [0, 0, 0, 0, 0, 0];
+
+ public ushort [] moves = {425, 262};
+ public ushort[] movespp = { 30, 40 };
+
+
+ public EggCreator(byte ball, ushort dexNumber, int language, int ability, Nature Nature, string OT, byte OTGender, string nickname, int[] IV, int[] EV, ushort[] moves, ushort[] movespp) {
+
+ this.ball = ball;
+ this.dexNumber = dexNumber;
+ this.language = language;
+ this.Ability = ability;
+ this.Nature = Nature;
+ this.OT = OT;
+ this.OTGender = OTGender;
+ this.nickname = nickname;
+ this.IV = IV;
+ this.EV = EV;
+ this.moves = moves;
+ this.movespp = movespp;
+
+
+ }
+
+
+ public static EggCreator decodeJSON(string filepath) {
+ string json = File.ReadAllText(filepath);
+
+ dynamic newObject = JsonConvert.DeserializeObject(json);
+
+ Nature nature = lookupNatureInt((int) newObject.nature.Value);
+
+ int[] IV = newObject.IV.ToObject();
+ int[] EV = newObject.EV.ToObject();
+
+ int[] moves = newObject.moves.ToObject();
+ int[] movespp = newObject.movespp.ToObject();
+
+ return new EggCreator(
+ newObject.ball,
+ newObject.dexNumber,
+ newObject.language,
+ newObject.ability,
+ nature,
+ newObject.OT,
+ newObject.OTGender,
+ newObject.nickname,
+ IV,
+ EV,
+ convertIntArrayViaCast(moves),
+ convertIntArrayViaCast(movespp)
+
+ );
+
+ }
+
+ public static Nature lookupNatureInt(int nature)
+ {
+ if (nature == 1) {
+ return Nature.Adamant;
+ }
+
+ return Nature.Bashful;
+ }
+
+ public static ushort[] convertIntArrayViaCast(int[] array)
+ {
+
+ ushort[] result = new ushort[array.Length];
+
+ for (int i = 0; i < result.Length; i++)
+ {
+ result[i] = (ushort) array[i];
+ }
+
+ return result;
+ }
+
+
+ }
+}
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/JSONDecoder.cs b/pkhex/pkhex-egglocke/pkhex-egglocke/JSONDecoder.cs
new file mode 100644
index 0000000..0e8230e
--- /dev/null
+++ b/pkhex/pkhex-egglocke/pkhex-egglocke/JSONDecoder.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace pkhex_egglocke
+{
+ internal class JSONDecoder
+ {
+
+ // Very annoying code that decodes strings to class-defined integers
+
+ }
+}
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/PokemonCreator.cs b/pkhex/pkhex-egglocke/pkhex-egglocke/PokemonCreator.cs
deleted file mode 100644
index aeec6e8..0000000
--- a/pkhex/pkhex-egglocke/pkhex-egglocke/PokemonCreator.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-/* PokemonCreator.cs
-* Bridge class that creates PkHEX pokemon files based on JSON objects exported from web app.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using PKHeX.Core;
-
-namespace pkhexEgglocke
-{
- internal class PokemonCreator
- {
-
-
-
- }
-}
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/Program.cs b/pkhex/pkhex-egglocke/pkhex-egglocke/Program.cs
index e1e8e44..0fb64b0 100644
--- a/pkhex/pkhex-egglocke/pkhex-egglocke/Program.cs
+++ b/pkhex/pkhex-egglocke/pkhex-egglocke/Program.cs
@@ -1,12 +1,35 @@
// See https://aka.ms/new-console-template for more information
+using pkhexEgglocke;
+using System.Reflection;
+
class Program {
public static void Main(string[] args)
{
- Console.WriteLine("Hello World!");
+ var BLANK_SOULSILVER_SAVE = @"C:\Users\Evin Jaff\Downloads\johtocomplete.sav";
+
+ SaveWriter sw = new SaveWriter(BLANK_SOULSILVER_SAVE);
+
+ //EggCreator pc = new EggCreator();
+
+ //sw.addEgg(pc, 1);
+
+ // Output the new one
+ //sw.export("testPROG.sav");
+
+ //Console.WriteLine("Dumped to testPROG.sav!!");
+ var BLANK_GEN4_MAREEP_VALID = Path.Combine("C:\\Users\\Evin Jaff\\Documents\\egglocke-maker\\pkhex\\pkhex-egglocke-tests\\pkhex-egglocke-tests\\testSources", "Mareep.json");
+
+ EggCreator ec = EggCreator.decodeJSON(BLANK_GEN4_MAREEP_VALID);
+
+ sw.addEgg(ec, 1);
+
+ sw.export("testPROG.sav");
+
+ Console.WriteLine("Dumped testPROG");
}
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/SaveWriter.cs b/pkhex/pkhex-egglocke/pkhex-egglocke/SaveWriter.cs
index 4723b50..389957a 100644
--- a/pkhex/pkhex-egglocke/pkhex-egglocke/SaveWriter.cs
+++ b/pkhex/pkhex-egglocke/pkhex-egglocke/SaveWriter.cs
@@ -51,9 +51,74 @@ public SaveWriter(string savePath) {
}
+ public void addEgg( EggCreator pokemon, int boxIndex) {
+
+ // hacky start - hardcoded to box 1
+
+ var mew = new PK4();
+
+ // Standard Egg attributes
+ mew.IsEgg = pokemon.IsEgg;
+ mew.EggLocationDP = pokemon.EggLocationDP;
+ mew.MetLevel = pokemon.MetLevel;
+ mew.Ball = pokemon.ball;
+
+
+ // Pokemon Info
+ mew.Species = pokemon.dexNumber;
+ mew.Nickname = pokemon.nickname;
+ mew.Language = pokemon.language;
+ mew.OriginalTrainerName = pokemon.OT;
+ mew.OriginalTrainerGender = pokemon.OTGender;
+
+
+ mew.Ability = pokemon.Ability;
+ mew.Nature = pokemon.Nature;
+
+ // Moveset
+ mew.Move1 = (int)Move.ShadowSneak;
+ mew.Move1_PP = 30;
+ mew.Move2 = (int)Move.Memento;
+ mew.Move2_PP = 20;
+
+
+ mew.IVs = pokemon.IV;
+
+ var box = this.currentSave.BoxData;
+
+ // Check legality of the pokemon
+
+ LegalityAnalysis legalitychecker = new LegalityAnalysis(mew);
+
+ #if DEBUG
+ if (legalitychecker.Valid)
+ {
+ Console.WriteLine("Legal Egg created!");
+ }
+ else {
+ Console.WriteLine("Illegal Egg Created!");
+ }
+ #endif
+
+ box[boxIndex] = mew;
+
+
+ // update box
+ this.currentSave.BoxData = box;
+
+ // this.currentSave.AddBoxData( , 1, 1 );
+
+
+ }
+
+
+ public void export(string location) {
+
+ byte[] modifiedSaveData = this.currentSave.Write();
+
+ // dump to location
+ File.WriteAllBytes(location, modifiedSaveData);
- public void export() {
- Console.WriteLine("To be Implemented!");
}
diff --git a/pkhex/pkhex-egglocke/pkhex-egglocke/pkhexEgglocke.csproj b/pkhex/pkhex-egglocke/pkhex-egglocke/pkhexEgglocke.csproj
index 42b34a5..d76cacf 100644
--- a/pkhex/pkhex-egglocke/pkhex-egglocke/pkhexEgglocke.csproj
+++ b/pkhex/pkhex-egglocke/pkhex-egglocke/pkhexEgglocke.csproj
@@ -9,6 +9,7 @@
+