internal PBEPokemon(BinaryReader r, PBETeam team)
        {
            Team    = team;
            Id      = r.ReadByte();
            Species = OriginalSpecies = KnownSpecies = (PBESpecies)r.ReadUInt32();
            var pData = PBEPokemonData.GetData(Species);

            KnownType1       = Type1 = pData.Type1;
            KnownType2       = Type2 = pData.Type2;
            KnownWeight      = Weight = pData.Weight;
            Nickname         = KnownNickname = PBEUtils.StringFromBytes(r);
            Level            = r.ReadByte();
            Friendship       = r.ReadByte();
            Shiny            = KnownShiny = r.ReadBoolean();
            Ability          = OriginalAbility = (PBEAbility)r.ReadByte();
            KnownAbility     = PBEAbility.MAX;
            Nature           = (PBENature)r.ReadByte();
            Gender           = KnownGender = (PBEGender)r.ReadByte();
            Item             = OriginalItem = (PBEItem)r.ReadUInt16();
            KnownItem        = (PBEItem)ushort.MaxValue;
            EffortValues     = new PBEEffortValues(Team.Battle.Settings, r);
            IndividualValues = new PBEIndividualValues(Team.Battle.Settings, r);
            SetStats();
            HP                   = MaxHP;
            HPPercentage         = 1D;
            OriginalMoveset      = new PBEMoveset(Species, Level, Team.Battle.Settings, r);
            Moves                = new PBEBattleMoveset(OriginalMoveset);
            KnownMoves           = new PBEBattleMoveset(Team.Battle.Settings);
            TransformBackupMoves = new PBEBattleMoveset(Team.Battle.Settings);
            Team.Party.Add(this);
        }
Beispiel #2
0
 internal PBEPlayerJoinedPacket(ReadOnlyCollection <byte> buffer, BinaryReader r, PBEBattle battle)
 {
     Buffer      = buffer;
     IsMe        = r.ReadBoolean();
     BattleId    = r.ReadInt32();
     TrainerName = PBEUtils.StringFromBytes(r);
 }
        internal static PBEPokemonShell FromBytes(BinaryReader r)
        {
            var pkmn = new PBEPokemonShell
            {
                Species    = (PBESpecies)r.ReadUInt32(),
                Nickname   = PBEUtils.StringFromBytes(r),
                Level      = r.ReadByte(),
                Friendship = r.ReadByte(),
                Shiny      = r.ReadBoolean(),
                Ability    = (PBEAbility)r.ReadByte(),
                Nature     = (PBENature)r.ReadByte(),
                Gender     = (PBEGender)r.ReadByte(),
                Item       = (PBEItem)r.ReadUInt16(),
                EVs        = r.ReadBytes(6),
                IVs        = r.ReadBytes(6)
            };
            byte numMoves = r.ReadByte();

            pkmn.Moves = new PBEMove[numMoves];
            for (int i = 0; i < numMoves; i++)
            {
                pkmn.Moves[i] = (PBEMove)r.ReadUInt16();
            }
            pkmn.PPUps = r.ReadBytes(numMoves);
            return(pkmn);
        }
        internal void FromBytes(BinaryReader r)
        {
            TrainerName = PBEUtils.StringFromBytes(r);
            sbyte amt = r.ReadSByte();

            for (int i = 0; i < amt; i++)
            {
                new PBEPokemon(r, this);
            }
        }
 public PBEPlayerJoinedPacket(byte[] buffer, PBEBattle battle)
 {
     Buffer = buffer;
     using (var r = new BinaryReader(new MemoryStream(buffer)))
     {
         r.ReadInt16(); // Skip Code
         IsMe        = r.ReadBoolean();
         BattleId    = r.ReadInt32();
         TrainerName = PBEUtils.StringFromBytes(r);
     }
 }
Beispiel #6
0
        public static PBEBattle LoadReplay(string path)
        {
            PBESettings settings = PBESettings.DefaultSettings;

            byte[] fileBytes = File.ReadAllBytes(path);
            using (var s = new MemoryStream(fileBytes))
                using (var r = new BinaryReader(s))
                {
                    using (var md5 = MD5.Create())
                    {
                        byte[] hash = md5.ComputeHash(fileBytes, 0, fileBytes.Length - 16);
                        for (int i = 0; i < 16; i++)
                        {
                            if (hash[i] != fileBytes[fileBytes.Length - 16 + i])
                            {
                                throw new InvalidDataException();
                            }
                        }
                    }

                    ushort version = r.ReadUInt16();

                    var battle = new PBEBattle((PBEBattleFormat)r.ReadByte(), settings);

                    battle.Teams[0].TrainerName = PBEUtils.StringFromBytes(r);
                    var party = new PBEPokemonShell[r.ReadSByte()];
                    for (int i = 0; i < party.Length; i++)
                    {
                        party[i] = PBEPokemonShell.FromBytes(r, settings);
                    }
                    battle.Teams[0].CreateParty(party, ref battle.pkmnIdCounter);

                    battle.Teams[1].TrainerName = PBEUtils.StringFromBytes(r);
                    party = new PBEPokemonShell[r.ReadSByte()];
                    for (int i = 0; i < party.Length; i++)
                    {
                        party[i] = PBEPokemonShell.FromBytes(r, settings);
                    }
                    battle.Teams[1].CreateParty(party, ref battle.pkmnIdCounter);

                    var        packetProcessor = new PBEPacketProcessor(battle);
                    INetPacket packet;
                    do
                    {
                        byte[] buffer = r.ReadBytes(r.ReadInt16());
                        packet = packetProcessor.CreatePacket(buffer);
                        battle.Events.Add(packet);
                    } while (!(packet is PBEWinnerPacket));

                    return(battle);
                }
        }
 internal PBEIllusionPacket(ReadOnlyCollection <byte> buffer, BinaryReader r, PBEBattle battle)
 {
     Buffer         = buffer;
     Pokemon        = (PBEFieldPosition)r.ReadByte();
     PokemonTeam    = battle.Teams[r.ReadByte()];
     ActualGender   = (PBEGender)r.ReadByte();
     ActualNickname = PBEUtils.StringFromBytes(r);
     ActualShiny    = r.ReadBoolean();
     ActualSpecies  = (PBESpecies)r.ReadUInt16();
     ActualType1    = (PBEType)r.ReadByte();
     ActualType2    = (PBEType)r.ReadByte();
     ActualWeight   = r.ReadDouble();
 }
Beispiel #8
0
 public PBEIllusionPacket(byte[] buffer, PBEBattle battle)
 {
     Buffer = buffer;
     using (var r = new BinaryReader(new MemoryStream(buffer)))
     {
         r.ReadInt16(); // Skip Code
         Pokemon        = (PBEFieldPosition)r.ReadByte();
         PokemonTeam    = battle.Teams[r.ReadByte()];
         ActualGender   = (PBEGender)r.ReadByte();
         ActualNickname = PBEUtils.StringFromBytes(r);
         ActualShiny    = r.ReadBoolean();
         ActualSpecies  = (PBESpecies)r.ReadUInt16();
     }
 }
Beispiel #9
0
 internal PBESwitchInInfo(BinaryReader r)
 {
     PokemonId     = r.ReadByte();
     DisguisedAsId = r.ReadByte();
     Species       = (PBESpecies)r.ReadUInt32();
     Nickname      = PBEUtils.StringFromBytes(r);
     Level         = r.ReadByte();
     Shiny         = r.ReadBoolean();
     Gender        = (PBEGender)r.ReadByte();
     HP            = r.ReadUInt16();
     MaxHP         = r.ReadUInt16();
     HPPercentage  = r.ReadDouble();
     Status1       = (PBEStatus1)r.ReadByte();
     FieldPosition = (PBEFieldPosition)r.ReadByte();
 }
 internal static PBESwitchInInfo FromBytes(BinaryReader r)
 {
     return(new PBESwitchInInfo(r.ReadByte(), r.ReadByte(), (PBESpecies)r.ReadUInt32(), PBEUtils.StringFromBytes(r), r.ReadByte(), r.ReadBoolean(), (PBEGender)r.ReadByte(), r.ReadUInt16(), r.ReadUInt16(), r.ReadDouble(), (PBEStatus1)r.ReadByte(), (PBEFieldPosition)r.ReadByte()));
 }