From 4c7e46bcdbae891346e4f5e456f7b435d41aa1a8 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Sat, 18 Apr 2015 17:29:47 -0400 Subject: [PATCH] Retire GtsRecord5.Unknown0 --- library/Data/DataMysql.cs | 28 ++++++++++++++-------------- library/Structures/GtsRecord5.cs | 14 +++----------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/library/Data/DataMysql.cs b/library/Data/DataMysql.cs index dfada936..db0f02d4 100644 --- a/library/Data/DataMysql.cs +++ b/library/Data/DataMysql.cs @@ -1191,8 +1191,7 @@ namespace PkmnFoundations.Data public bool GtsDepositPokemon5(MySqlTransaction tran, GtsRecord5 record) { if (record == null) throw new ArgumentNullException("record"); - if (record.Data.Length != 220) throw new FormatException("pkm data must be 220 bytes."); - if (record.Unknown0.Length != 16) throw new FormatException("pkm padding must be 16 bytes."); + if (record.Data.Length != 236) throw new FormatException("pkm data must be 220 bytes."); if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes."); // note that IsTraded being true in the record is not an error condition // since it might have use later on. You should check for this in the upload handler. @@ -1226,8 +1225,7 @@ namespace PkmnFoundations.Data public override bool GtsDepositPokemon5(GtsRecord5 record) { if (record == null) throw new ArgumentNullException("record"); - if (record.Data.Length != 220) throw new FormatException("pkm data must be 220 bytes."); - if (record.Unknown0.Length != 16) throw new FormatException("pkm padding must be 16 bytes."); + if (record.Data.Length != 236) throw new FormatException("pkm data must be 236 bytes."); if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes."); return WithTransactionSuccessful(tran => GtsDepositPokemon5(tran, record)); @@ -1407,16 +1405,14 @@ namespace PkmnFoundations.Data // xxx: Don't use ordinals here GtsRecord5 result = new GtsRecord5(); - byte[] data = new byte[220]; + // xxx: Data and Unknown0 should share a database field. + // (This requires migrating a lot of existing data) + byte[] data = new byte[236]; reader.GetBytes(0, 0, data, 0, 220); + reader.GetBytes(1, 0, data, 220, 16); result.Data = data; data = null; - data = new byte[16]; - reader.GetBytes(1, 0, data, 0, 16); - result.Unknown0 = data; - data = null; - result.Species = reader.GetUInt16(2); result.Gender = (Genders)reader.GetByte(3); result.Level = reader.GetByte(4); @@ -1455,8 +1451,13 @@ namespace PkmnFoundations.Data { MySqlParameter[] result = new MySqlParameter[25]; - result[0] = new MySqlParameter("@Data", record.Data); - result[1] = new MySqlParameter("@Unknown0", record.Unknown0); + byte[] data = new byte[220]; + byte[] unknown0 = new byte[16]; + Array.Copy(record.Data, 0, data, 0, 220); + Array.Copy(record.Data, 220, unknown0, 0, 16); + + result[0] = new MySqlParameter("@Data", data); + result[1] = new MySqlParameter("@Unknown0", unknown0); result[2] = new MySqlParameter("@Species", record.Species); result[3] = new MySqlParameter("@Gender", (byte)record.Gender); result[4] = new MySqlParameter("@Level", record.Level); @@ -1503,8 +1504,7 @@ namespace PkmnFoundations.Data { // todo: Bring these out into a ValidateRecord5 method if (record == null) throw new ArgumentNullException("record"); - if (record.Data.Length != 220) throw new FormatException("pkm data must be 220 bytes."); - if (record.Unknown0.Length != 16) throw new FormatException("pkm padding must be 16 bytes."); + if (record.Data.Length != 236) throw new FormatException("pkm data must be 236 bytes."); if (record.TrainerName.RawData.Length != 16) throw new FormatException("Trainer name must be 16 bytes."); // note that IsTraded being true in the record is not an error condition // since it might have use later on. You should check for this in the upload handler. diff --git a/library/Structures/GtsRecord5.cs b/library/Structures/GtsRecord5.cs index c01b1aea..ddf84c3a 100644 --- a/library/Structures/GtsRecord5.cs +++ b/library/Structures/GtsRecord5.cs @@ -38,11 +38,6 @@ namespace PkmnFoundations.Structures /// public byte[] Data; - /// - /// Unknown padding between pkm and rest of data. 16 bytes. - /// - public byte[] Unknown0; - /// /// National Dex species number /// @@ -101,12 +96,10 @@ namespace PkmnFoundations.Structures protected override void Save(BinaryWriter writer) { // todo: enclose in properties and validate these when assigning. - if (Data.Length != 0xDC) throw new FormatException("PKM length is incorrect"); + if (Data.Length != 0xEC) throw new FormatException("PKM length is incorrect"); if (TrainerName.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect"); - writer.Write(Data, 0, 0xDC); // 0x0000 - writer.Write(Unknown0, 0, 0x10); // 0x00DC - + writer.Write(Data, 0, 0xEC); // 0x0000 writer.Write(Species); // 0x00EC writer.Write((byte)Gender); // 0x00EE writer.Write(Level); // 0x00EF @@ -134,8 +127,7 @@ namespace PkmnFoundations.Structures protected override void Load(BinaryReader reader) { - Data = reader.ReadBytes(0xDC); // 0x0000 - Unknown0 = reader.ReadBytes(0x10); // 0x00DC + Data = reader.ReadBytes(0xEC); // 0x0000 Species = reader.ReadUInt16(); // 0x00EC Gender = (Genders)reader.ReadByte(); // 0x00EE Level = reader.ReadByte(); // 0x00EF