diff --git a/Misc/CodeGenerator.cs b/Misc/CodeGenerator.cs index 9ff7dbdb4..2930f6278 100644 --- a/Misc/CodeGenerator.cs +++ b/Misc/CodeGenerator.cs @@ -16,7 +16,7 @@ public partial class CodeGenerator : Form { byte[] codedata = new byte[232]; byte[] newdata = new byte[232]; - PKX.SaveGames.SaveStruct SaveGame = new PKX.SaveGames.SaveStruct(null); + PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame(null); Form1 m_parent; byte[] tabdata = null; diff --git a/Misc/PKX.cs b/Misc/PKX.cs index abf541db6..382b5d3f1 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -848,13 +848,151 @@ public PKX(byte[] pkx, string ident) #endregion #region SaveGame - public class SaveGames + public class Structures { - public struct SaveStruct + public struct PK6 + { + public uint EC; + public ushort Checksum, Sanity; + + public uint PID, Experience; + public ushort Species, HeldItem, TID, SID; + public byte Ability, AbilityNumber, Nature, Gender, Form; + public bool Fateful; + + public byte HP_EV, ATK_EV, DEF_EV, SPA_EV, SPD_EV, SPE_EV; + public byte HP_IV, ATK_IV, DEF_IV, SPA_IV, SPD_IV, SPE_IV; + public byte CNT_Cool, CNT_Beauty, CNT_Cute, CNT_Clever, CNT_Tough, CNT_Sheen; + public bool MARK_Circle, MARK_Triangle, MARK_Square, MARK_Heart, MARK_Star, MARK_Diamond; + public byte PKRS_Strain, PKRS_Duration; + + public string Nickname, OT, CT; + public ushort Move1, Move2, Move3, Move4, Relearn1, Relearn2, Relearn3, Relearn4; + public byte Move1_PP, Move2_PP, Move3_PP, Move4_PP, Move1_PPUps, Move2_PPUps, Move3_PPUps, Move4_PPUps; + + public bool isNicknamed, isEgg, notWithOT; + public byte Ball, MetLevel, OTGender, CTGender, OTFriendship, OTAffection, CTFriendship, CTAffection; + public ushort MetLocation, EggLocation; + public byte MetYear, MetMonth, MetDay, EggYear, EggMonth, EggDay; + public byte Gen4EncounterType, GameLanguage, GameVersion, ConsoleRegionID, CountryID, SubRegionID; + + // Misc + public byte HitsRemaining, TrainingBag; + public PK6(byte[] pk6) + { + // Encryption Constant + EC = BitConverter.ToUInt32(pk6, 0); + Sanity = BitConverter.ToUInt16(pk6, 4); + Checksum = BitConverter.ToUInt16(pk6, 6); + + // Block A + Species = BitConverter.ToUInt16(pk6, 0x08); + HeldItem = BitConverter.ToUInt16(pk6, 0x0A); + TID = BitConverter.ToUInt16(pk6, 0x0C); + SID = BitConverter.ToUInt16(pk6, 0x0E); + Experience = BitConverter.ToUInt32(pk6, 0x10); + Ability = pk6[0x14]; + AbilityNumber = pk6[0x15]; + HitsRemaining = pk6[0x16]; + TrainingBag = pk6[0x17]; + PID = BitConverter.ToUInt32(pk6, 0x18); + Nature = pk6[0x1C]; + Fateful = (pk6[0x1D] % 2 == 0); + Gender = (byte)((pk6[0x1D] >> 1) & 0x3); + Form = (byte)(pk6[0x1D] >> 3); + HP_EV = pk6[0x1E]; + ATK_EV = pk6[0x1F]; + DEF_EV = pk6[0x20]; + SPA_EV = pk6[0x22]; + SPD_EV = pk6[0x23]; + SPE_EV = pk6[0x21]; + CNT_Cool = pk6[0x24]; + CNT_Beauty = pk6[0x25]; + CNT_Cute = pk6[0x26]; + CNT_Clever = pk6[0x27]; + CNT_Tough = pk6[0x28]; + CNT_Sheen = pk6[0x29]; + MARK_Circle = ((pk6[0x2A] >> 0) & 1) == 1; + MARK_Triangle = ((pk6[0x2A] >> 1) & 1) == 1; + MARK_Square = ((pk6[0x2A] >> 2) & 1) == 1; + MARK_Heart = ((pk6[0x2A] >> 3) & 1) == 1; + MARK_Star = ((pk6[0x2A] >> 4) & 1) == 1; + MARK_Diamond = ((pk6[0x2A] >> 5) & 1) == 1; + PKRS_Strain = (byte)(pk6[0x2B] >> 4); + PKRS_Duration = (byte)(pk6[0x2B] % 0x10); + + // Block B + Nickname = Util.TrimFromZero(Encoding.Unicode.GetString(pk6, 0x40, 24)); + // 0x58, 0x59 - Null Terminator + Move1 = BitConverter.ToUInt16(pk6, 0x5A); + Move2 = BitConverter.ToUInt16(pk6, 0x5C); + Move3 = BitConverter.ToUInt16(pk6, 0x5E); + Move4 = BitConverter.ToUInt16(pk6, 0x60); + Move1_PP = pk6[0x62]; + Move2_PP = pk6[0x63]; + Move3_PP = pk6[0x64]; + Move4_PP = pk6[0x65]; + Move1_PPUps = pk6[0x66]; + Move2_PPUps = pk6[0x67]; + Move3_PPUps = pk6[0x68]; + Move4_PPUps = pk6[0x69]; + Relearn1 = BitConverter.ToUInt16(pk6, 0x6A); + Relearn2 = BitConverter.ToUInt16(pk6, 0x6C); + Relearn3 = BitConverter.ToUInt16(pk6, 0x6E); + Relearn4 = BitConverter.ToUInt16(pk6, 0x70); + + // 0x72 - Super Training Flag - Passed with buff to new form + + // 0x73 - unused/unknown + uint IV32 = BitConverter.ToUInt32(pk6, 0x74); + HP_IV = (byte)(IV32 & 0x1F); + ATK_IV = (byte)((IV32 >> 5) & 0x1F); + DEF_IV = (byte)((IV32 >> 10) & 0x1F); + SPE_IV = (byte)((IV32 >> 15) & 0x1F); + SPA_IV = (byte)((IV32 >> 20) & 0x1F); + SPD_IV = (byte)((IV32 >> 25) & 0x1F); + isEgg = ((IV32 >> 30) & 1) == 1; + isNicknamed = (IV32 >> 31) == 1; + + // Block C + CT = Util.TrimFromZero(Encoding.Unicode.GetString(pk6, 0x78, 24)); + CTGender = pk6[0x92]; + notWithOT = pk6[0x93] == 1; + CTFriendship = pk6[0xA2]; + CTAffection = pk6[0xA3]; + // Memory Editor edits everything else with buff in a new form + + // Block D + OT = Util.TrimFromZero(Encoding.Unicode.GetString(pk6, 0xB0, 24)); + // 0xC8, 0xC9 - unused + OTFriendship = pk6[0xCA]; + OTAffection = pk6[0xCB]; + // 0xCC, 0xCD, 0xCE, 0xCF, 0xD0 unused + EggYear = pk6[0xD1]; + EggMonth = pk6[0xD2]; + EggDay = pk6[0xD3]; + MetYear = pk6[0xD4]; + MetMonth = pk6[0xD5]; + MetDay = pk6[0xD6]; + // 0xD7 - unused + EggLocation = BitConverter.ToUInt16(pk6, 0xD8); + MetLocation = BitConverter.ToUInt16(pk6, 0xDA); + Ball = pk6[0xDC]; + MetLevel = (byte)(pk6[0xDD] & 0x7F); + OTGender = (byte)(pk6[0xDD] >> 7); + Gen4EncounterType = pk6[0xDE]; + GameVersion = pk6[0xDF]; + CountryID = pk6[0xE0]; + SubRegionID = pk6[0xE1]; + ConsoleRegionID = pk6[0xE2]; + GameLanguage = pk6[0xE3]; + } + } + public struct SaveGame { public int Box, TrainerCard, Party, BattleBox, GTS, Daycare, Fused, SUBE, Puff, Item, Trainer1, Trainer2, PCLayout, Wondercard, BerryField, OPower, EventFlag, PokeDex, HoF, PSS, JPEG; public string Name; - public SaveStruct(string GameID) + public SaveGame(string GameID) { if (GameID == "XY") { diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index 0564b653f..f7eabc052 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -4176,7 +4176,6 @@ public void InitializeComponent() private System.Windows.Forms.Label Label_Country; private System.Windows.Forms.Label Label_PKRSdays; private System.Windows.Forms.Label Label_PKRS; - public System.Windows.Forms.CheckBox CHK_IsEgg; private System.Windows.Forms.OpenFileDialog OpenPKX; private System.Windows.Forms.SaveFileDialog SavePKX; private System.Windows.Forms.Button BTN_RerollEC; @@ -4409,7 +4408,6 @@ public void InitializeComponent() private System.Windows.Forms.ToolStripComboBox CB_MainLanguage; private System.Windows.Forms.ToolStripMenuItem Menu_About; private System.Windows.Forms.ToolStripMenuItem Menu_BoxIO; - public System.Windows.Forms.ComboBox CB_Species; public System.Windows.Forms.ComboBox CB_Move1; public System.Windows.Forms.ComboBox CB_MetLocation; public System.Windows.Forms.Label Label_Friendship; @@ -4448,6 +4446,8 @@ public void InitializeComponent() public System.Windows.Forms.ComboBox CB_HeldItem; public System.Windows.Forms.ComboBox CB_Nature; private System.Windows.Forms.PictureBox dragout; + public System.Windows.Forms.ComboBox CB_Species; + public System.Windows.Forms.CheckBox CHK_IsEgg; } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 1504a10b3..cd7a25b4d 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -235,7 +235,7 @@ public Form1() public ToolTip Tip1 = new ToolTip(); public ToolTip Tip2 = new ToolTip(); public ToolTip Tip3 = new ToolTip(); - public PKX.SaveGames.SaveStruct SaveGame = new PKX.SaveGames.SaveStruct("XY"); + public PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame("XY"); #endregion #region //// MAIN MENU FUNCTIONS //// @@ -538,7 +538,7 @@ private void openFile(byte[] input, string path, string ext) private void openMAIN(byte[] input, string path, string GameType, bool oras) { L_Save.Text = "SAV: " + Path.GetFileName(path); - SaveGame = new PKX.SaveGames.SaveStruct(GameType); + SaveGame = new PKX.Structures.SaveGame(GameType); // Load CyberGadget this.savindex = 0; @@ -553,7 +553,7 @@ private void openMAIN(byte[] input, string path, string GameType, bool oras) private void open1MB(byte[] input, string path, string GameType, bool oras) { L_Save.Text = "SAV: " + Path.GetFileName(path); - SaveGame = new PKX.SaveGames.SaveStruct(GameType); + SaveGame = new PKX.Structures.SaveGame(GameType); savegame_oras = oras; savefile = input; @@ -1078,7 +1078,7 @@ private void populateFields(byte[] buff) } getQuickFiller(dragout); } - // General Use Functions shared by other Forms + // General Use Functions shared by other Forms // public void setCountrySubRegion(object sender, string type) { ComboBox CB = sender as ComboBox; @@ -1432,7 +1432,7 @@ private void setMarkings() int gameindex = Util.getIndex(CB_GameOrigin); PB_MarkPentagon.Image = Util.ChangeOpacity(PB_MarkPentagon.InitialImage, (float)(Convert.ToUInt16(gameindex == 24 || gameindex == 25 || gameindex == 26 || gameindex == 27)) * 0.9 + 0.1); } - // Clicked Label Shortcuts + // Clicked Label Shortcuts // private void clickFriendship(object sender, EventArgs e) { if (ModifierKeys == Keys.Control) // prompt to reset @@ -3601,12 +3601,12 @@ private void getSAVOffsets() if (BitConverter.ToUInt32(savefile, 0x6A810 + 0x7F000 * savindex) == 0x42454546) { enableInterface = true; - SaveGame = new PKX.SaveGames.SaveStruct("XY"); + SaveGame = new PKX.Structures.SaveGame("XY"); } else { Util.Error("Unrecognized Save File loaded."); - SaveGame = new PKX.SaveGames.SaveStruct("Error"); + SaveGame = new PKX.Structures.SaveGame("Error"); } // Enable Buttons diff --git a/SAV/frmReport.cs b/SAV/frmReport.cs index 47240fcf5..124b7b1fa 100644 --- a/SAV/frmReport.cs +++ b/SAV/frmReport.cs @@ -26,7 +26,7 @@ public void PopulateData(byte[] InputData, int savindex, int baseoffset) SaveData = new byte[InputData.Length]; Array.Copy(InputData, SaveData, InputData.Length); PokemonList PL = new PokemonList(); - PKX.SaveGames.SaveStruct SaveGame = new PKX.SaveGames.SaveStruct("XY"); + PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame("XY"); if (savindex > 1) savindex = 0; for (int BoxNum = 0; BoxNum < 31; BoxNum++) {