mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-10-01 05:36:56 -05:00
Broke up one large namespace into several and reorganized.
This commit is contained in:
@@ -8,6 +8,7 @@ using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Data;
|
||||
using System.Net.Sockets;
|
||||
using System.Diagnostics;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GlobalTerminalService
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using PkmnFoundations.Data;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Sockets;
|
||||
using System.Diagnostics;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GlobalTerminalService
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace bvRestorer4
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace bvRestorer5
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using PkmnFoundations.Support;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using GamestatsBase;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Web;
|
||||
using GamestatsBase;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Wfc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System.IO;
|
||||
using GamestatsBase;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Security.Cryptography;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.Data
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using System.Configuration;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.Data
|
||||
{
|
||||
|
||||
@@ -75,33 +75,33 @@
|
||||
<Compile Include="Pokedex\Form.cs" />
|
||||
<Compile Include="Pokedex\Type.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Structures\BanStatus.cs" />
|
||||
<Compile Include="Structures\BattleSubwayPokemon5.cs" />
|
||||
<Compile Include="Structures\BattleSubwayProfile5.cs" />
|
||||
<Compile Include="Structures\BattleSubwayRecord5.cs" />
|
||||
<Compile Include="Structures\BattleTowerPokemon4.cs" />
|
||||
<Compile Include="Structures\BattleTowerPokemonBase.cs" />
|
||||
<Compile Include="Structures\BattleTowerProfileBase.cs" />
|
||||
<Compile Include="Structures\BattleTowerRecord4.cs" />
|
||||
<Compile Include="Structures\BattleTowerProfile4.cs" />
|
||||
<Compile Include="Structures\BattleTowerRecordBase.cs" />
|
||||
<Compile Include="Structures\BattleVideoHeader4.cs" />
|
||||
<Compile Include="Structures\BattleVideoHeader5.cs" />
|
||||
<Compile Include="Structures\BattleVideoRecord4.cs" />
|
||||
<Compile Include="Structures\BattleVideoRecord5.cs" />
|
||||
<Compile Include="Structures\BinarySerializableBase.cs" />
|
||||
<Compile Include="Structures\BoxRecord4.cs" />
|
||||
<Compile Include="Wfc\BanStatus.cs" />
|
||||
<Compile Include="Wfc\BattleSubwayPokemon5.cs" />
|
||||
<Compile Include="Wfc\BattleSubwayProfile5.cs" />
|
||||
<Compile Include="Wfc\BattleSubwayRecord5.cs" />
|
||||
<Compile Include="Wfc\BattleTowerPokemon4.cs" />
|
||||
<Compile Include="Wfc\BattleTowerPokemonBase.cs" />
|
||||
<Compile Include="Wfc\BattleTowerProfileBase.cs" />
|
||||
<Compile Include="Wfc\BattleTowerRecord4.cs" />
|
||||
<Compile Include="Wfc\BattleTowerProfile4.cs" />
|
||||
<Compile Include="Wfc\BattleTowerRecordBase.cs" />
|
||||
<Compile Include="Wfc\BattleVideoHeader4.cs" />
|
||||
<Compile Include="Wfc\BattleVideoHeader5.cs" />
|
||||
<Compile Include="Wfc\BattleVideoRecord4.cs" />
|
||||
<Compile Include="Wfc\BattleVideoRecord5.cs" />
|
||||
<Compile Include="Support\BinarySerializableBase.cs" />
|
||||
<Compile Include="Wfc\BoxRecord4.cs" />
|
||||
<Compile Include="Structures\ByteStatValues.cs" />
|
||||
<Compile Include="Structures\ContestStatValues.cs" />
|
||||
<Compile Include="Structures\DressupRecord4.cs" />
|
||||
<Compile Include="Wfc\DressupRecord4.cs" />
|
||||
<Compile Include="Structures\Format.cs" />
|
||||
<Compile Include="Structures\GtsRecord5.cs" />
|
||||
<Compile Include="Wfc\GtsRecord5.cs" />
|
||||
<Compile Include="Structures\Enums.cs" />
|
||||
<Compile Include="Structures\GtsRecord4.cs" />
|
||||
<Compile Include="Structures\GtsRecordBase.cs" />
|
||||
<Compile Include="Wfc\GtsRecord4.cs" />
|
||||
<Compile Include="Wfc\GtsRecordBase.cs" />
|
||||
<Compile Include="Structures\IvStatValues.cs" />
|
||||
<Compile Include="Structures\MoveSlot.cs" />
|
||||
<Compile Include="Structures\MusicalRecord5.cs" />
|
||||
<Compile Include="Wfc\MusicalRecord5.cs" />
|
||||
<Compile Include="Structures\Pokemon4.cs" />
|
||||
<Compile Include="Structures\Pokemon5.cs" />
|
||||
<Compile Include="Structures\PokemonBase.cs" />
|
||||
@@ -112,11 +112,11 @@
|
||||
<Compile Include="Structures\StatValues.cs" />
|
||||
<Compile Include="Structures\StatValuesBase.cs" />
|
||||
<Compile Include="Structures\TrainerMemo.cs" />
|
||||
<Compile Include="Structures\TrainerProfile4.cs" />
|
||||
<Compile Include="Structures\TrainerProfile5.cs" />
|
||||
<Compile Include="Structures\TrainerProfileBase.cs" />
|
||||
<Compile Include="Structures\TrainerProfilePlaza.cs" />
|
||||
<Compile Include="Structures\TrainerRankings.cs" />
|
||||
<Compile Include="Wfc\TrainerProfile4.cs" />
|
||||
<Compile Include="Wfc\TrainerProfile5.cs" />
|
||||
<Compile Include="Wfc\TrainerProfileBase.cs" />
|
||||
<Compile Include="Wfc\TrainerProfilePlaza.cs" />
|
||||
<Compile Include="Wfc\TrainerRankings.cs" />
|
||||
<Compile Include="Support\AssertHelper.cs" />
|
||||
<Compile Include="Support\EncodedString4.cs" />
|
||||
<Compile Include="Support\EncodedString5.cs" />
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for objects which serialize using BinaryReader and BinaryWriter
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BanStatus
|
||||
{
|
||||
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleSubwayPokemon5 : BattleTowerPokemonBase
|
||||
{
|
||||
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleSubwayProfile5 : BattleTowerProfileBase
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleSubwayRecord5 : BattleTowerRecordBase
|
||||
{
|
||||
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleTowerPokemon4 : BattleTowerPokemonBase
|
||||
{
|
||||
@@ -4,9 +4,10 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public abstract class BattleTowerPokemonBase : PokemonBase
|
||||
{
|
||||
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleTowerProfile4 : BattleTowerProfileBase
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public abstract class BattleTowerProfileBase
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleTowerRecord4 : BattleTowerRecordBase
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public abstract class BattleTowerRecordBase
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleVideoHeader4
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleVideoHeader5
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleVideoRecord4
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BattleVideoRecord5
|
||||
{
|
||||
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class BoxRecord4 : BinarySerializableBase
|
||||
{
|
||||
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class DressupRecord4 : BinarySerializableBase
|
||||
{
|
||||
@@ -1,282 +1,283 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.IO;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
{
|
||||
/// <summary>
|
||||
/// Structure used to represent Pokémon on the GTS in Generation IV.
|
||||
/// Includes a Pokémon box structure and metadata related to the trainer
|
||||
/// and request.
|
||||
/// </summary>
|
||||
public class GtsRecord4 : GtsRecordBase, IEquatable<GtsRecord4>
|
||||
{
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obfuscated Pokémon (pkm) data. 236 bytes
|
||||
/// </summary>
|
||||
public IList<byte> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data_readonly;
|
||||
}
|
||||
set
|
||||
{
|
||||
DataActual = value.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DataActual
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
m_data = null;
|
||||
m_data_readonly = null;
|
||||
m_pokemon = null;
|
||||
return;
|
||||
}
|
||||
if (value.Length != 0xEC) throw new ArgumentException("PKM length is incorrect");
|
||||
m_data = value;
|
||||
m_data_readonly = new ReadOnlyCollection<byte>(m_data);
|
||||
m_pokemon = null;
|
||||
}
|
||||
}
|
||||
private byte[] m_data;
|
||||
private ReadOnlyCollection<byte> m_data_readonly;
|
||||
private PokemonParty4 m_pokemon;
|
||||
|
||||
public override PokemonPartyBase Pokemon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataActual == null || m_pokedex == null)
|
||||
return null;
|
||||
if (m_pokemon == null)
|
||||
m_pokemon = new PokemonParty4(m_pokedex, DataActual);
|
||||
|
||||
return m_pokemon;
|
||||
}
|
||||
}
|
||||
|
||||
public byte Unknown1;
|
||||
public byte Unknown2;
|
||||
|
||||
/// <summary>
|
||||
/// 16 bytes
|
||||
/// </summary>
|
||||
public EncodedString4 TrainerNameEncoded;
|
||||
|
||||
public override string TrainerName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TrainerNameEncoded == null) return null;
|
||||
return TrainerNameEncoded.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString4(value, 16);
|
||||
else TrainerNameEncoded.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort TrainerOT;
|
||||
|
||||
protected override void Save(BinaryWriter writer)
|
||||
{
|
||||
// todo: enclose in properties and validate these when assigning.
|
||||
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
|
||||
|
||||
writer.Write(DataActual, 0, 0xec); // 0000
|
||||
writer.Write(Species); // 00EC
|
||||
writer.Write((byte)Gender); // 00EE
|
||||
writer.Write(Level); // 00EF
|
||||
writer.Write(RequestedSpecies); // 00F0
|
||||
writer.Write((byte)RequestedGender); // 00F2
|
||||
writer.Write(RequestedMinLevel); // 00F3
|
||||
writer.Write(RequestedMaxLevel); // 00F4
|
||||
writer.Write(Unknown1); // 00F5
|
||||
writer.Write((byte)TrainerGender); // 00F6
|
||||
writer.Write(Unknown2); // 00F7
|
||||
writer.Write(DateToTimestamp(TimeDeposited)); // 00F8
|
||||
writer.Write(DateToTimestamp(TimeExchanged)); // 0100
|
||||
writer.Write(PID); // 0108
|
||||
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 010C
|
||||
writer.Write(TrainerOT); // 011C
|
||||
writer.Write(TrainerCountry); // 011E
|
||||
writer.Write(TrainerRegion); // 011F
|
||||
writer.Write(TrainerClass); // 0120
|
||||
writer.Write(IsExchanged); // 0121
|
||||
writer.Write((byte)TrainerVersion); // 0122
|
||||
writer.Write((byte)TrainerLanguage); // 0123
|
||||
}
|
||||
|
||||
protected override void Load(BinaryReader reader)
|
||||
{
|
||||
DataActual = reader.ReadBytes(0xec); // 0000
|
||||
Species = reader.ReadUInt16(); // 00EC
|
||||
Gender = (Genders)reader.ReadByte(); // 00EE
|
||||
Level = reader.ReadByte(); // 00EF
|
||||
RequestedSpecies = reader.ReadUInt16(); // 00F0
|
||||
RequestedGender = (Genders)reader.ReadByte(); // 00F2
|
||||
RequestedMinLevel = reader.ReadByte(); // 00F3
|
||||
RequestedMaxLevel = reader.ReadByte(); // 00F4
|
||||
Unknown1 = reader.ReadByte(); // 00F5
|
||||
TrainerGender = (TrainerGenders)reader.ReadByte(); // 00F6
|
||||
Unknown2 = reader.ReadByte(); // 00F7
|
||||
TimeDeposited = TimestampToDate(reader.ReadUInt64()); // 00F8
|
||||
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0100
|
||||
PID = reader.ReadInt32(); // 0108
|
||||
TrainerNameEncoded = new EncodedString4(reader.ReadBytes(0x10)); // 010C
|
||||
TrainerOT = reader.ReadUInt16(); // 011C
|
||||
TrainerCountry = reader.ReadByte(); // 011E
|
||||
TrainerRegion = reader.ReadByte(); // 011F
|
||||
TrainerClass = reader.ReadByte(); // 0120
|
||||
IsExchanged = reader.ReadByte(); // 0121
|
||||
TrainerVersion = (Versions)reader.ReadByte(); // 0122
|
||||
TrainerLanguage = (Languages)reader.ReadByte(); // 0123
|
||||
}
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get { return 292; }
|
||||
}
|
||||
|
||||
public GtsRecord4 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord4(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
if (!base.Validate()) return false;
|
||||
|
||||
// Forbid ball capsules. Credit: Gannio
|
||||
if (((PokemonParty4)Pokemon).CapsuleIndex != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsRecord4 other)
|
||||
{
|
||||
if (IsExchanged != 0 || other.IsExchanged != 0) return false;
|
||||
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
if (other.RequestedGender != Genders.Either && Gender != other.RequestedGender) return false;
|
||||
if (!CheckLevels(other.RequestedMinLevel, other.RequestedMaxLevel, Level)) return false;
|
||||
|
||||
if (RequestedSpecies != other.Species) return false;
|
||||
if (RequestedGender != Genders.Either && other.Gender != RequestedGender) return false;
|
||||
if (!CheckLevels(RequestedMinLevel, RequestedMaxLevel, other.Level)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlagTraded(GtsRecord4 other)
|
||||
{
|
||||
Species = other.Species;
|
||||
Gender = other.Gender;
|
||||
Level = other.Level;
|
||||
RequestedSpecies = other.RequestedSpecies;
|
||||
RequestedGender = other.RequestedGender;
|
||||
RequestedMinLevel = other.RequestedMinLevel;
|
||||
RequestedMaxLevel = other.RequestedMaxLevel;
|
||||
TimeDeposited = other.TimeDeposited;
|
||||
TimeExchanged = DateTime.UtcNow;
|
||||
PID = other.PID;
|
||||
IsExchanged = 0x01;
|
||||
}
|
||||
|
||||
public override TrainerProfileBase ExtrapolateProfile()
|
||||
{
|
||||
TrainerProfile4 result = new TrainerProfile4();
|
||||
result.PID = PID;
|
||||
result.Version = TrainerVersion;
|
||||
result.Language = TrainerLanguage;
|
||||
result.Country = TrainerCountry;
|
||||
result.Region = TrainerRegion;
|
||||
result.OT = TrainerOT;
|
||||
result.Name = TrainerNameEncoded.Clone();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool operator ==(GtsRecord4 a, GtsRecord4 b)
|
||||
{
|
||||
if ((object)a == null && (object)b == null) return true;
|
||||
if ((object)a == null || (object)b == null) return false;
|
||||
// todo: optimize me
|
||||
return a.Save().SequenceEqual(b.Save());
|
||||
}
|
||||
|
||||
public static bool operator !=(GtsRecord4 a, GtsRecord4 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Equals(obj as GtsRecord4);
|
||||
}
|
||||
|
||||
public bool Equals(GtsRecord4 other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)DateToBinary(TimeDeposited) + (int)DateToBinary(TimeExchanged)) ^ PID;
|
||||
}
|
||||
|
||||
internal static long DateToBinary(DateTime ? dt)
|
||||
{
|
||||
if (dt == null) return 0L;
|
||||
return ((DateTime)dt).ToBinary();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.IO;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
/// <summary>
|
||||
/// Structure used to represent Pokémon on the GTS in Generation IV.
|
||||
/// Includes a Pokémon box structure and metadata related to the trainer
|
||||
/// and request.
|
||||
/// </summary>
|
||||
public class GtsRecord4 : GtsRecordBase, IEquatable<GtsRecord4>
|
||||
{
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord4(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obfuscated Pokémon (pkm) data. 236 bytes
|
||||
/// </summary>
|
||||
public IList<byte> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data_readonly;
|
||||
}
|
||||
set
|
||||
{
|
||||
DataActual = value.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DataActual
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
m_data = null;
|
||||
m_data_readonly = null;
|
||||
m_pokemon = null;
|
||||
return;
|
||||
}
|
||||
if (value.Length != 0xEC) throw new ArgumentException("PKM length is incorrect");
|
||||
m_data = value;
|
||||
m_data_readonly = new ReadOnlyCollection<byte>(m_data);
|
||||
m_pokemon = null;
|
||||
}
|
||||
}
|
||||
private byte[] m_data;
|
||||
private ReadOnlyCollection<byte> m_data_readonly;
|
||||
private PokemonParty4 m_pokemon;
|
||||
|
||||
public override PokemonPartyBase Pokemon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataActual == null || m_pokedex == null)
|
||||
return null;
|
||||
if (m_pokemon == null)
|
||||
m_pokemon = new PokemonParty4(m_pokedex, DataActual);
|
||||
|
||||
return m_pokemon;
|
||||
}
|
||||
}
|
||||
|
||||
public byte Unknown1;
|
||||
public byte Unknown2;
|
||||
|
||||
/// <summary>
|
||||
/// 16 bytes
|
||||
/// </summary>
|
||||
public EncodedString4 TrainerNameEncoded;
|
||||
|
||||
public override string TrainerName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TrainerNameEncoded == null) return null;
|
||||
return TrainerNameEncoded.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString4(value, 16);
|
||||
else TrainerNameEncoded.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ushort TrainerOT;
|
||||
|
||||
protected override void Save(BinaryWriter writer)
|
||||
{
|
||||
// todo: enclose in properties and validate these when assigning.
|
||||
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
|
||||
|
||||
writer.Write(DataActual, 0, 0xec); // 0000
|
||||
writer.Write(Species); // 00EC
|
||||
writer.Write((byte)Gender); // 00EE
|
||||
writer.Write(Level); // 00EF
|
||||
writer.Write(RequestedSpecies); // 00F0
|
||||
writer.Write((byte)RequestedGender); // 00F2
|
||||
writer.Write(RequestedMinLevel); // 00F3
|
||||
writer.Write(RequestedMaxLevel); // 00F4
|
||||
writer.Write(Unknown1); // 00F5
|
||||
writer.Write((byte)TrainerGender); // 00F6
|
||||
writer.Write(Unknown2); // 00F7
|
||||
writer.Write(DateToTimestamp(TimeDeposited)); // 00F8
|
||||
writer.Write(DateToTimestamp(TimeExchanged)); // 0100
|
||||
writer.Write(PID); // 0108
|
||||
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 010C
|
||||
writer.Write(TrainerOT); // 011C
|
||||
writer.Write(TrainerCountry); // 011E
|
||||
writer.Write(TrainerRegion); // 011F
|
||||
writer.Write(TrainerClass); // 0120
|
||||
writer.Write(IsExchanged); // 0121
|
||||
writer.Write((byte)TrainerVersion); // 0122
|
||||
writer.Write((byte)TrainerLanguage); // 0123
|
||||
}
|
||||
|
||||
protected override void Load(BinaryReader reader)
|
||||
{
|
||||
DataActual = reader.ReadBytes(0xec); // 0000
|
||||
Species = reader.ReadUInt16(); // 00EC
|
||||
Gender = (Genders)reader.ReadByte(); // 00EE
|
||||
Level = reader.ReadByte(); // 00EF
|
||||
RequestedSpecies = reader.ReadUInt16(); // 00F0
|
||||
RequestedGender = (Genders)reader.ReadByte(); // 00F2
|
||||
RequestedMinLevel = reader.ReadByte(); // 00F3
|
||||
RequestedMaxLevel = reader.ReadByte(); // 00F4
|
||||
Unknown1 = reader.ReadByte(); // 00F5
|
||||
TrainerGender = (TrainerGenders)reader.ReadByte(); // 00F6
|
||||
Unknown2 = reader.ReadByte(); // 00F7
|
||||
TimeDeposited = TimestampToDate(reader.ReadUInt64()); // 00F8
|
||||
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0100
|
||||
PID = reader.ReadInt32(); // 0108
|
||||
TrainerNameEncoded = new EncodedString4(reader.ReadBytes(0x10)); // 010C
|
||||
TrainerOT = reader.ReadUInt16(); // 011C
|
||||
TrainerCountry = reader.ReadByte(); // 011E
|
||||
TrainerRegion = reader.ReadByte(); // 011F
|
||||
TrainerClass = reader.ReadByte(); // 0120
|
||||
IsExchanged = reader.ReadByte(); // 0121
|
||||
TrainerVersion = (Versions)reader.ReadByte(); // 0122
|
||||
TrainerLanguage = (Languages)reader.ReadByte(); // 0123
|
||||
}
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get { return 292; }
|
||||
}
|
||||
|
||||
public GtsRecord4 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord4(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
if (!base.Validate()) return false;
|
||||
|
||||
// Forbid ball capsules. Credit: Gannio
|
||||
if (((PokemonParty4)Pokemon).CapsuleIndex != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsRecord4 other)
|
||||
{
|
||||
if (IsExchanged != 0 || other.IsExchanged != 0) return false;
|
||||
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
if (other.RequestedGender != Genders.Either && Gender != other.RequestedGender) return false;
|
||||
if (!CheckLevels(other.RequestedMinLevel, other.RequestedMaxLevel, Level)) return false;
|
||||
|
||||
if (RequestedSpecies != other.Species) return false;
|
||||
if (RequestedGender != Genders.Either && other.Gender != RequestedGender) return false;
|
||||
if (!CheckLevels(RequestedMinLevel, RequestedMaxLevel, other.Level)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlagTraded(GtsRecord4 other)
|
||||
{
|
||||
Species = other.Species;
|
||||
Gender = other.Gender;
|
||||
Level = other.Level;
|
||||
RequestedSpecies = other.RequestedSpecies;
|
||||
RequestedGender = other.RequestedGender;
|
||||
RequestedMinLevel = other.RequestedMinLevel;
|
||||
RequestedMaxLevel = other.RequestedMaxLevel;
|
||||
TimeDeposited = other.TimeDeposited;
|
||||
TimeExchanged = DateTime.UtcNow;
|
||||
PID = other.PID;
|
||||
IsExchanged = 0x01;
|
||||
}
|
||||
|
||||
public override TrainerProfileBase ExtrapolateProfile()
|
||||
{
|
||||
TrainerProfile4 result = new TrainerProfile4();
|
||||
result.PID = PID;
|
||||
result.Version = TrainerVersion;
|
||||
result.Language = TrainerLanguage;
|
||||
result.Country = TrainerCountry;
|
||||
result.Region = TrainerRegion;
|
||||
result.OT = TrainerOT;
|
||||
result.Name = TrainerNameEncoded.Clone();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool operator ==(GtsRecord4 a, GtsRecord4 b)
|
||||
{
|
||||
if ((object)a == null && (object)b == null) return true;
|
||||
if ((object)a == null || (object)b == null) return false;
|
||||
// todo: optimize me
|
||||
return a.Save().SequenceEqual(b.Save());
|
||||
}
|
||||
|
||||
public static bool operator !=(GtsRecord4 a, GtsRecord4 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Equals(obj as GtsRecord4);
|
||||
}
|
||||
|
||||
public bool Equals(GtsRecord4 other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)DateToBinary(TimeDeposited) + (int)DateToBinary(TimeExchanged)) ^ PID;
|
||||
}
|
||||
|
||||
internal static long DateToBinary(DateTime ? dt)
|
||||
{
|
||||
if (dt == null) return 0L;
|
||||
return ((DateTime)dt).ToBinary();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,280 +1,281 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.IO;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
{
|
||||
/// <summary>
|
||||
/// Structure used to represent Pokémon on the GTS in Generation V.
|
||||
/// Includes a Pokémon box structure and metadata related to the trainer
|
||||
/// and request.
|
||||
/// </summary>
|
||||
public class GtsRecord5 : GtsRecordBase, IEquatable<GtsRecord5>
|
||||
{
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obfuscated Pokémon (pkm) data. 236 bytes
|
||||
/// </summary>
|
||||
public IList<byte> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data_readonly;
|
||||
}
|
||||
set
|
||||
{
|
||||
DataActual = value.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DataActual
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
m_data = null;
|
||||
m_data_readonly = null;
|
||||
m_pokemon = null;
|
||||
return;
|
||||
}
|
||||
if (value.Length != 0xEC) throw new ArgumentException("PKM length is incorrect");
|
||||
m_data = value;
|
||||
m_data_readonly = new ReadOnlyCollection<byte>(m_data);
|
||||
m_pokemon = null;
|
||||
}
|
||||
}
|
||||
private byte[] m_data;
|
||||
private ReadOnlyCollection<byte> m_data_readonly;
|
||||
private PokemonParty5 m_pokemon;
|
||||
|
||||
public override PokemonPartyBase Pokemon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataActual == null || m_pokedex == null)
|
||||
return null;
|
||||
if (m_pokemon == null)
|
||||
m_pokemon = new PokemonParty5(m_pokedex, DataActual);
|
||||
|
||||
return m_pokemon;
|
||||
}
|
||||
}
|
||||
|
||||
public byte Unknown1;
|
||||
public byte Unknown2;
|
||||
|
||||
public uint TrainerOT;
|
||||
|
||||
/// <summary>
|
||||
/// 16 bytes
|
||||
/// </summary>
|
||||
public EncodedString5 TrainerNameEncoded;
|
||||
|
||||
public override string TrainerName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TrainerNameEncoded == null) return null;
|
||||
return TrainerNameEncoded.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString5(value, 16);
|
||||
else TrainerNameEncoded.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public byte TrainerBadges; // speculative. Usually 8.
|
||||
public byte TrainerUnityTower;
|
||||
|
||||
protected override void Save(BinaryWriter writer)
|
||||
{
|
||||
// todo: enclose in properties and validate these when assigning.
|
||||
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
|
||||
|
||||
writer.Write(DataActual, 0, 0xEC); // 0000
|
||||
writer.Write(Species); // 00EC
|
||||
writer.Write((byte)Gender); // 00EE
|
||||
writer.Write(Level); // 00EF
|
||||
writer.Write(RequestedSpecies); // 00F0
|
||||
writer.Write((byte)RequestedGender); // 00F2
|
||||
writer.Write(RequestedMinLevel); // 00F3
|
||||
writer.Write(RequestedMaxLevel); // 00F4
|
||||
writer.Write(Unknown1); // 00F5
|
||||
writer.Write((byte)TrainerGender); // 00F6
|
||||
writer.Write(Unknown2); // 00F7
|
||||
writer.Write(DateToTimestamp(TimeDeposited)); // 00F8
|
||||
writer.Write(DateToTimestamp(TimeExchanged)); // 0100
|
||||
writer.Write(PID); // 0108
|
||||
writer.Write(TrainerOT); // 010C
|
||||
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 0110
|
||||
writer.Write(TrainerCountry); // 0120
|
||||
writer.Write(TrainerRegion); // 0121
|
||||
writer.Write(TrainerClass); // 0122
|
||||
writer.Write(IsExchanged); // 0123
|
||||
writer.Write((byte)TrainerVersion); // 0124
|
||||
writer.Write((byte)TrainerLanguage); // 0125
|
||||
writer.Write(TrainerBadges); // 0126
|
||||
writer.Write(TrainerUnityTower); // 0127
|
||||
}
|
||||
|
||||
protected override void Load(BinaryReader reader)
|
||||
{
|
||||
DataActual = reader.ReadBytes(0xEC); // 0000
|
||||
Species = reader.ReadUInt16(); // 00EC
|
||||
Gender = (Genders)reader.ReadByte(); // 00EE
|
||||
Level = reader.ReadByte(); // 00EF
|
||||
RequestedSpecies = reader.ReadUInt16(); // 00F0
|
||||
RequestedGender = (Genders)reader.ReadByte(); // 00F2
|
||||
RequestedMinLevel = reader.ReadByte(); // 00F3
|
||||
RequestedMaxLevel = reader.ReadByte(); // 00F4
|
||||
Unknown1 = reader.ReadByte(); // 00F5
|
||||
TrainerGender = (TrainerGenders)reader.ReadByte(); // 00F6
|
||||
Unknown2 = reader.ReadByte(); // 00F7
|
||||
TimeDeposited = TimestampToDate(reader.ReadUInt64()); // 00F8
|
||||
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0100
|
||||
PID = reader.ReadInt32(); // 0108
|
||||
TrainerOT = reader.ReadUInt32(); // 010C
|
||||
TrainerNameEncoded = new EncodedString5(reader.ReadBytes(0x10)); // 0110
|
||||
TrainerCountry = reader.ReadByte(); // 0120
|
||||
TrainerRegion = reader.ReadByte(); // 0121
|
||||
TrainerClass = reader.ReadByte(); // 0122
|
||||
IsExchanged = reader.ReadByte(); // 0123
|
||||
TrainerVersion = (Versions)reader.ReadByte(); // 0124
|
||||
TrainerLanguage = (Languages)reader.ReadByte(); // 0125
|
||||
TrainerBadges = reader.ReadByte(); // 0126
|
||||
TrainerUnityTower = reader.ReadByte(); // 0127
|
||||
}
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get { return 296; }
|
||||
}
|
||||
|
||||
public GtsRecord5 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord5(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
if (!base.Validate()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsRecord5 other)
|
||||
{
|
||||
if (IsExchanged != 0 || other.IsExchanged != 0) return false;
|
||||
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
if (other.RequestedGender != Genders.Either && Gender != other.RequestedGender) return false;
|
||||
if (!CheckLevels(other.RequestedMinLevel, other.RequestedMaxLevel, Level)) return false;
|
||||
|
||||
if (RequestedSpecies != other.Species) return false;
|
||||
if (RequestedGender != Genders.Either && other.Gender != RequestedGender) return false;
|
||||
if (!CheckLevels(RequestedMinLevel, RequestedMaxLevel, other.Level)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlagTraded(GtsRecord5 other)
|
||||
{
|
||||
Species = other.Species;
|
||||
Gender = other.Gender;
|
||||
Level = other.Level;
|
||||
RequestedSpecies = other.RequestedSpecies;
|
||||
RequestedGender = other.RequestedGender;
|
||||
RequestedMinLevel = other.RequestedMinLevel;
|
||||
RequestedMaxLevel = other.RequestedMaxLevel;
|
||||
TimeDeposited = other.TimeDeposited;
|
||||
TimeExchanged = DateTime.UtcNow;
|
||||
PID = other.PID;
|
||||
IsExchanged = 0x01;
|
||||
}
|
||||
|
||||
public override TrainerProfileBase ExtrapolateProfile()
|
||||
{
|
||||
TrainerProfile5 result = new TrainerProfile5();
|
||||
result.PID = PID;
|
||||
result.Version = TrainerVersion;
|
||||
result.Language = TrainerLanguage;
|
||||
result.Country = TrainerCountry;
|
||||
result.Region = TrainerRegion;
|
||||
result.OT = TrainerOT;
|
||||
result.Name = TrainerNameEncoded.Clone();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool operator ==(GtsRecord5 a, GtsRecord5 b)
|
||||
{
|
||||
if ((object)a == null && (object)b == null) return true;
|
||||
if ((object)a == null || (object)b == null) return false;
|
||||
// todo: optimize me
|
||||
return a.Save().SequenceEqual(b.Save());
|
||||
}
|
||||
|
||||
public static bool operator !=(GtsRecord5 a, GtsRecord5 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Equals(obj as GtsRecord5);
|
||||
}
|
||||
|
||||
public bool Equals(GtsRecord5 other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)GtsRecord4.DateToBinary(TimeDeposited) + (int)GtsRecord4.DateToBinary(TimeExchanged)) ^ PID;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.IO;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
/// <summary>
|
||||
/// Structure used to represent Pokémon on the GTS in Generation V.
|
||||
/// Includes a Pokémon box structure and metadata related to the trainer
|
||||
/// and request.
|
||||
/// </summary>
|
||||
public class GtsRecord5 : GtsRecordBase, IEquatable<GtsRecord5>
|
||||
{
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, BinaryReader data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data);
|
||||
}
|
||||
|
||||
public GtsRecord5(Pokedex.Pokedex pokedex, byte[] data, int offset)
|
||||
: base(pokedex)
|
||||
{
|
||||
Initialize();
|
||||
Load(data, offset);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obfuscated Pokémon (pkm) data. 236 bytes
|
||||
/// </summary>
|
||||
public IList<byte> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data_readonly;
|
||||
}
|
||||
set
|
||||
{
|
||||
DataActual = value.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DataActual
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
m_data = null;
|
||||
m_data_readonly = null;
|
||||
m_pokemon = null;
|
||||
return;
|
||||
}
|
||||
if (value.Length != 0xEC) throw new ArgumentException("PKM length is incorrect");
|
||||
m_data = value;
|
||||
m_data_readonly = new ReadOnlyCollection<byte>(m_data);
|
||||
m_pokemon = null;
|
||||
}
|
||||
}
|
||||
private byte[] m_data;
|
||||
private ReadOnlyCollection<byte> m_data_readonly;
|
||||
private PokemonParty5 m_pokemon;
|
||||
|
||||
public override PokemonPartyBase Pokemon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataActual == null || m_pokedex == null)
|
||||
return null;
|
||||
if (m_pokemon == null)
|
||||
m_pokemon = new PokemonParty5(m_pokedex, DataActual);
|
||||
|
||||
return m_pokemon;
|
||||
}
|
||||
}
|
||||
|
||||
public byte Unknown1;
|
||||
public byte Unknown2;
|
||||
|
||||
public uint TrainerOT;
|
||||
|
||||
/// <summary>
|
||||
/// 16 bytes
|
||||
/// </summary>
|
||||
public EncodedString5 TrainerNameEncoded;
|
||||
|
||||
public override string TrainerName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TrainerNameEncoded == null) return null;
|
||||
return TrainerNameEncoded.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (TrainerNameEncoded == null) TrainerNameEncoded = new EncodedString5(value, 16);
|
||||
else TrainerNameEncoded.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public byte TrainerBadges; // speculative. Usually 8.
|
||||
public byte TrainerUnityTower;
|
||||
|
||||
protected override void Save(BinaryWriter writer)
|
||||
{
|
||||
// todo: enclose in properties and validate these when assigning.
|
||||
if (TrainerNameEncoded.RawData.Length != 0x10) throw new FormatException("Trainer name length is incorrect");
|
||||
|
||||
writer.Write(DataActual, 0, 0xEC); // 0000
|
||||
writer.Write(Species); // 00EC
|
||||
writer.Write((byte)Gender); // 00EE
|
||||
writer.Write(Level); // 00EF
|
||||
writer.Write(RequestedSpecies); // 00F0
|
||||
writer.Write((byte)RequestedGender); // 00F2
|
||||
writer.Write(RequestedMinLevel); // 00F3
|
||||
writer.Write(RequestedMaxLevel); // 00F4
|
||||
writer.Write(Unknown1); // 00F5
|
||||
writer.Write((byte)TrainerGender); // 00F6
|
||||
writer.Write(Unknown2); // 00F7
|
||||
writer.Write(DateToTimestamp(TimeDeposited)); // 00F8
|
||||
writer.Write(DateToTimestamp(TimeExchanged)); // 0100
|
||||
writer.Write(PID); // 0108
|
||||
writer.Write(TrainerOT); // 010C
|
||||
writer.Write(TrainerNameEncoded.RawData, 0, 0x10); // 0110
|
||||
writer.Write(TrainerCountry); // 0120
|
||||
writer.Write(TrainerRegion); // 0121
|
||||
writer.Write(TrainerClass); // 0122
|
||||
writer.Write(IsExchanged); // 0123
|
||||
writer.Write((byte)TrainerVersion); // 0124
|
||||
writer.Write((byte)TrainerLanguage); // 0125
|
||||
writer.Write(TrainerBadges); // 0126
|
||||
writer.Write(TrainerUnityTower); // 0127
|
||||
}
|
||||
|
||||
protected override void Load(BinaryReader reader)
|
||||
{
|
||||
DataActual = reader.ReadBytes(0xEC); // 0000
|
||||
Species = reader.ReadUInt16(); // 00EC
|
||||
Gender = (Genders)reader.ReadByte(); // 00EE
|
||||
Level = reader.ReadByte(); // 00EF
|
||||
RequestedSpecies = reader.ReadUInt16(); // 00F0
|
||||
RequestedGender = (Genders)reader.ReadByte(); // 00F2
|
||||
RequestedMinLevel = reader.ReadByte(); // 00F3
|
||||
RequestedMaxLevel = reader.ReadByte(); // 00F4
|
||||
Unknown1 = reader.ReadByte(); // 00F5
|
||||
TrainerGender = (TrainerGenders)reader.ReadByte(); // 00F6
|
||||
Unknown2 = reader.ReadByte(); // 00F7
|
||||
TimeDeposited = TimestampToDate(reader.ReadUInt64()); // 00F8
|
||||
TimeExchanged = TimestampToDate(reader.ReadUInt64()); // 0100
|
||||
PID = reader.ReadInt32(); // 0108
|
||||
TrainerOT = reader.ReadUInt32(); // 010C
|
||||
TrainerNameEncoded = new EncodedString5(reader.ReadBytes(0x10)); // 0110
|
||||
TrainerCountry = reader.ReadByte(); // 0120
|
||||
TrainerRegion = reader.ReadByte(); // 0121
|
||||
TrainerClass = reader.ReadByte(); // 0122
|
||||
IsExchanged = reader.ReadByte(); // 0123
|
||||
TrainerVersion = (Versions)reader.ReadByte(); // 0124
|
||||
TrainerLanguage = (Languages)reader.ReadByte(); // 0125
|
||||
TrainerBadges = reader.ReadByte(); // 0126
|
||||
TrainerUnityTower = reader.ReadByte(); // 0127
|
||||
}
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get { return 296; }
|
||||
}
|
||||
|
||||
public GtsRecord5 Clone()
|
||||
{
|
||||
// todo: I am not very efficient
|
||||
return new GtsRecord5(m_pokedex, Save());
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
if (!base.Validate()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanTrade(GtsRecord5 other)
|
||||
{
|
||||
if (IsExchanged != 0 || other.IsExchanged != 0) return false;
|
||||
|
||||
if (Species != other.RequestedSpecies) return false;
|
||||
if (other.RequestedGender != Genders.Either && Gender != other.RequestedGender) return false;
|
||||
if (!CheckLevels(other.RequestedMinLevel, other.RequestedMaxLevel, Level)) return false;
|
||||
|
||||
if (RequestedSpecies != other.Species) return false;
|
||||
if (RequestedGender != Genders.Either && other.Gender != RequestedGender) return false;
|
||||
if (!CheckLevels(RequestedMinLevel, RequestedMaxLevel, other.Level)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlagTraded(GtsRecord5 other)
|
||||
{
|
||||
Species = other.Species;
|
||||
Gender = other.Gender;
|
||||
Level = other.Level;
|
||||
RequestedSpecies = other.RequestedSpecies;
|
||||
RequestedGender = other.RequestedGender;
|
||||
RequestedMinLevel = other.RequestedMinLevel;
|
||||
RequestedMaxLevel = other.RequestedMaxLevel;
|
||||
TimeDeposited = other.TimeDeposited;
|
||||
TimeExchanged = DateTime.UtcNow;
|
||||
PID = other.PID;
|
||||
IsExchanged = 0x01;
|
||||
}
|
||||
|
||||
public override TrainerProfileBase ExtrapolateProfile()
|
||||
{
|
||||
TrainerProfile5 result = new TrainerProfile5();
|
||||
result.PID = PID;
|
||||
result.Version = TrainerVersion;
|
||||
result.Language = TrainerLanguage;
|
||||
result.Country = TrainerCountry;
|
||||
result.Region = TrainerRegion;
|
||||
result.OT = TrainerOT;
|
||||
result.Name = TrainerNameEncoded.Clone();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool operator ==(GtsRecord5 a, GtsRecord5 b)
|
||||
{
|
||||
if ((object)a == null && (object)b == null) return true;
|
||||
if ((object)a == null || (object)b == null) return false;
|
||||
// todo: optimize me
|
||||
return a.Save().SequenceEqual(b.Save());
|
||||
}
|
||||
|
||||
public static bool operator !=(GtsRecord5 a, GtsRecord5 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Equals(obj as GtsRecord5);
|
||||
}
|
||||
|
||||
public bool Equals(GtsRecord5 other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)GtsRecord4.DateToBinary(TimeDeposited) + (int)GtsRecord4.DateToBinary(TimeExchanged)) ^ PID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public abstract class GtsRecordBase : BinarySerializableBase
|
||||
{
|
||||
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class MusicalRecord5 : BinarySerializableBase
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class TrainerProfile4 : TrainerProfileBase
|
||||
{
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class TrainerProfile5 : TrainerProfileBase
|
||||
{
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using PkmnFoundations.Structures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public abstract class TrainerProfileBase
|
||||
{
|
||||
@@ -2,9 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class TrainerProfilePlaza
|
||||
{
|
||||
@@ -1,11 +1,12 @@
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PkmnFoundations.Structures
|
||||
namespace PkmnFoundations.Wfc
|
||||
{
|
||||
public class TrainerRankingsReport
|
||||
{
|
||||
@@ -7,6 +7,7 @@ using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace towerRestorer
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Web;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web.UI.WebControls;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Web;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS.admin
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.IO;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Web;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS.test
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS.admin
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Web;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using PkmnFoundations.Data;
|
||||
using PkmnFoundations.Pokedex;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Support;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.Web.gts
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using PkmnFoundations.Structures;
|
||||
using PkmnFoundations.Wfc;
|
||||
|
||||
namespace PkmnFoundations.GTS.test
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user