Added Generation 4 String, so we can actually read text from G4.

This commit is contained in:
Admiral H. Curtiss 2014-05-23 22:41:06 +02:00
parent a0336822b9
commit ad9a731f52
4 changed files with 54 additions and 10 deletions

View File

@ -80,7 +80,7 @@ namespace PkmnFoundations.Data
public bool GtsDepositPokemon4(MySqlTransaction tran, GtsRecord4 record)
{
if (record.Data.Length != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.Length != 16) throw new FormatException("Trainer name must be 16 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.
@ -113,7 +113,7 @@ namespace PkmnFoundations.Data
public override bool GtsDepositPokemon4(GtsRecord4 record)
{
if (record.Data.Length != 236) throw new FormatException("pkm data must be 236 bytes.");
if (record.TrainerName.Length != 16) throw new FormatException("Trainer name must be 16 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.
@ -314,7 +314,7 @@ namespace PkmnFoundations.Data
data = new byte[16];
reader.GetBytes(14, 0, data, 0, 16);
result.TrainerName = data;
result.TrainerName = new String4(data);
data = null;
result.TrainerOT = reader.GetUInt16(15);
@ -346,7 +346,7 @@ namespace PkmnFoundations.Data
result[11] = new MySqlParameter("@TimeDeposited", record.TimeDeposited);
result[12] = new MySqlParameter("@TimeWithdrawn", record.TimeWithdrawn);
result[13] = new MySqlParameter("@pid", record.PID);
result[14] = new MySqlParameter("@TrainerName", record.TrainerName);
result[14] = new MySqlParameter("@TrainerName", record.TrainerName.RawData);
result[15] = new MySqlParameter("@TrainerOT", record.TrainerOT);
result[16] = new MySqlParameter("@TrainerCountry", record.TrainerCountry);
result[17] = new MySqlParameter("@TrainerRegion", record.TrainerRegion);

View File

@ -57,6 +57,7 @@
<Compile Include="Structures\Enums.cs" />
<Compile Include="Structures\GtsRecord4.cs" />
<Compile Include="Support\AssertHelper.cs" />
<Compile Include="Support\String4.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using PkmnFoundations.Support;
namespace PkmnFoundations.Structures
{
@ -68,8 +69,7 @@ namespace PkmnFoundations.Structures
/// <summary>
/// 16 bytes
/// </summary>
public byte[] TrainerName; // todo: decode/encode to unicode and provide a String wrapper.
// https://github.com/veekun/pokedex/blob/master/pokedex/struct/_pokemon_struct.py
public String4 TrainerName;
public ushort TrainerOT;
@ -86,7 +86,7 @@ namespace PkmnFoundations.Structures
{
// todo: enclose in properties and validate these when assigning.
if (Data.Length != 0xEC) throw new FormatException("PKM length is incorrect");
if (TrainerName.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
if (TrainerName.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
byte[] data = new byte[292];
MemoryStream s = new MemoryStream(data);
s.Write(Data, 0, 0xEC);
@ -103,7 +103,7 @@ namespace PkmnFoundations.Structures
s.Write(BitConverter.GetBytes(DateToTimestamp(TimeDeposited)), 0, 8);
s.Write(BitConverter.GetBytes(DateToTimestamp(TimeWithdrawn)), 0, 8);
s.Write(BitConverter.GetBytes(PID), 0, 4);
s.Write(TrainerName, 0, 0x10);
s.Write(TrainerName.RawData, 0, 0x10);
s.Write(BitConverter.GetBytes(TrainerOT), 0, 2);
s.WriteByte(TrainerCountry);
s.WriteByte(TrainerRegion);
@ -134,8 +134,7 @@ namespace PkmnFoundations.Structures
TimeDeposited = TimestampToDate(BitConverter.ToUInt64(data, 0xF8));
TimeWithdrawn = TimestampToDate(BitConverter.ToUInt64(data, 0x100));
PID = BitConverter.ToInt32(data, 0x108);
TrainerName = new byte[0x10];
Array.Copy(data, 0x10C, TrainerName, 0, 0x10);
TrainerName = new String4(data, 0x10C, 0x10);
TrainerOT = BitConverter.ToUInt16(data, 0x11C);
TrainerCountry = data[0x11E];
TrainerRegion = data[0x11F];

File diff suppressed because one or more lines are too long