Example #1
0
        /// <inheritdoc />
        public INetPacket CreatePacket(byte[] bytes)
        {
            INetPacket packet;

            using (var r = new BinaryReader(new MemoryStream(bytes)))
            {
                var list = new List <byte>(bytes);
                list.InsertRange(0, BitConverter.GetBytes((short)bytes.Length));
                var   buffer = new ReadOnlyCollection <byte>(list);
                short code   = r.ReadInt16();
                switch (code)
                {
                case PBEResponsePacket.Code: packet = new PBEResponsePacket(buffer, r, _battle); break;

                case PBEPlayerJoinedPacket.Code: packet = new PBEPlayerJoinedPacket(buffer, r, _battle); break;

                case PBEMatchCancelledPacket.Code: packet = new PBEMatchCancelledPacket(buffer, r, _battle); break;

                case PBEPartyRequestPacket.Code: packet = new PBEPartyRequestPacket(buffer, r, _battle); break;

                case PBEPartyResponsePacket.Code: packet = new PBEPartyResponsePacket(buffer, r, _battle); break;

                case PBETeamPacket.Code: packet = new PBETeamPacket(buffer, r, _battle); break;

                case PBEPkmnSwitchInPacket.Code: packet = new PBEPkmnSwitchInPacket(buffer, r, _battle); break;

                case PBEActionsRequestPacket.Code: packet = new PBEActionsRequestPacket(buffer, r, _battle); break;

                case PBEActionsResponsePacket.Code: packet = new PBEActionsResponsePacket(buffer, r, _battle); break;

                case PBEMoveUsedPacket.Code: packet = new PBEMoveUsedPacket(buffer, r, _battle); break;

                case PBEPkmnHPChangedPacket.Code: packet = new PBEPkmnHPChangedPacket(buffer, r, _battle); break;

                case PBEMoveEffectivenessPacket.Code: packet = new PBEMoveEffectivenessPacket(buffer, r, _battle); break;

                case PBEPkmnSwitchOutPacket.Code: packet = new PBEPkmnSwitchOutPacket(buffer, r, _battle); break;

                case PBEMoveMissedPacket.Code: packet = new PBEMoveMissedPacket(buffer, r, _battle); break;

                case PBEPkmnFaintedPacket.Code: packet = new PBEPkmnFaintedPacket(buffer, r, _battle); break;

                case PBEMoveCritPacket.Code: packet = new PBEMoveCritPacket(buffer, r, _battle); break;

                case PBEPkmnStatChangedPacket.Code: packet = new PBEPkmnStatChangedPacket(buffer, r, _battle); break;

                case PBEStatus1Packet.Code: packet = new PBEStatus1Packet(buffer, r, _battle); break;

                case PBEStatus2Packet.Code: packet = new PBEStatus2Packet(buffer, r, _battle); break;

                case PBETeamStatusPacket.Code: packet = new PBETeamStatusPacket(buffer, r, _battle); break;

                case PBEWeatherPacket.Code: packet = new PBEWeatherPacket(buffer, r, _battle); break;

                case PBEMoveFailedPacket.Code: packet = new PBEMoveFailedPacket(buffer, r, _battle); break;

                case PBEItemPacket.Code: packet = new PBEItemPacket(buffer, r, _battle); break;

                case PBEMovePPChangedPacket.Code: packet = new PBEMovePPChangedPacket(buffer, r, _battle); break;

                case PBETransformPacket.Code: packet = new PBETransformPacket(buffer, r, _battle); break;

                case PBEAbilityPacket.Code: packet = new PBEAbilityPacket(buffer, r, _battle); break;

                case PBESpecialMessagePacket.Code: packet = new PBESpecialMessagePacket(buffer, r, _battle); break;

                case PBEBattleStatusPacket.Code: packet = new PBEBattleStatusPacket(buffer, r, _battle); break;

                case PBEPsychUpPacket.Code: packet = new PBEPsychUpPacket(buffer, r, _battle); break;

                case PBESwitchInRequestPacket.Code: packet = new PBESwitchInRequestPacket(buffer, r, _battle); break;

                case PBESwitchInResponsePacket.Code: packet = new PBESwitchInResponsePacket(buffer, r, _battle); break;

                case PBEIllusionPacket.Code: packet = new PBEIllusionPacket(buffer, r, _battle); break;

                case PBEWinnerPacket.Code: packet = new PBEWinnerPacket(buffer, r, _battle); break;

                case PBETurnBeganPacket.Code: packet = new PBETurnBeganPacket(buffer, r, _battle); break;

                case PBEMoveLockPacket.Code: packet = new PBEMoveLockPacket(buffer, r, _battle); break;

                case PBEPkmnFormChangedPacket.Code: packet = new PBEPkmnFormChangedPacket(buffer, r, _battle); break;

                case PBEAutoCenterPacket.Code: packet = new PBEAutoCenterPacket(buffer, r, _battle); break;

                default: throw new ArgumentOutOfRangeException(nameof(code));
                }
            }
            return(packet);
        }
        /// <inheritdoc />
        public INetPacket CreatePacket(byte[] buffer)
        {
            INetPacket packet;
            short      code = BitConverter.ToInt16(buffer, 0);

            switch (code)
            {
            case PBEResponsePacket.Code: packet = new PBEResponsePacket(buffer, battle); break;

            case PBEPlayerJoinedPacket.Code: packet = new PBEPlayerJoinedPacket(buffer, battle); break;

            case PBEMatchCancelledPacket.Code: packet = new PBEMatchCancelledPacket(buffer, battle); break;

            case PBEPartyRequestPacket.Code: packet = new PBEPartyRequestPacket(buffer, battle); break;

            case PBEPartyResponsePacket.Code: packet = new PBEPartyResponsePacket(buffer, battle); break;

            case PBESetPartyPacket.Code: packet = new PBESetPartyPacket(buffer, battle); break;

            case PBEPkmnSwitchInPacket.Code: packet = new PBEPkmnSwitchInPacket(buffer, battle); break;

            case PBEActionsRequestPacket.Code: packet = new PBEActionsRequestPacket(buffer, battle); break;

            case PBEActionsResponsePacket.Code: packet = new PBEActionsResponsePacket(buffer, battle); break;

            case PBEMoveUsedPacket.Code: packet = new PBEMoveUsedPacket(buffer, battle); break;

            case PBEPkmnHPChangedPacket.Code: packet = new PBEPkmnHPChangedPacket(buffer, battle); break;

            case PBEMoveEffectivenessPacket.Code: packet = new PBEMoveEffectivenessPacket(buffer, battle); break;

            case PBEPkmnSwitchOutPacket.Code: packet = new PBEPkmnSwitchOutPacket(buffer, battle); break;

            case PBEMoveMissedPacket.Code: packet = new PBEMoveMissedPacket(buffer, battle); break;

            case PBEPkmnFaintedPacket.Code: packet = new PBEPkmnFaintedPacket(buffer, battle); break;

            case PBEMoveCritPacket.Code: packet = new PBEMoveCritPacket(buffer, battle); break;

            case PBEPkmnStatChangedPacket.Code: packet = new PBEPkmnStatChangedPacket(buffer, battle); break;

            case PBEStatus1Packet.Code: packet = new PBEStatus1Packet(buffer, battle); break;

            case PBEStatus2Packet.Code: packet = new PBEStatus2Packet(buffer, battle); break;

            case PBETeamStatusPacket.Code: packet = new PBETeamStatusPacket(buffer, battle); break;

            case PBEWeatherPacket.Code: packet = new PBEWeatherPacket(buffer, battle); break;

            case PBEMoveFailedPacket.Code: packet = new PBEMoveFailedPacket(buffer, battle); break;

            case PBEItemPacket.Code: packet = new PBEItemPacket(buffer, battle); break;

            case PBEMovePPChangedPacket.Code: packet = new PBEMovePPChangedPacket(buffer, battle); break;

            case PBETransformPacket.Code: packet = new PBETransformPacket(buffer, battle); break;

            case PBEAbilityPacket.Code: packet = new PBEAbilityPacket(buffer, battle); break;

            case PBESpecialMessagePacket.Code: packet = new PBESpecialMessagePacket(buffer, battle); break;

            case PBEBattleStatusPacket.Code: packet = new PBEBattleStatusPacket(buffer, battle); break;

            case PBEPsychUpPacket.Code: packet = new PBEPsychUpPacket(buffer, battle); break;

            case PBESwitchInRequestPacket.Code: packet = new PBESwitchInRequestPacket(buffer, battle); break;

            case PBESwitchInResponsePacket.Code: packet = new PBESwitchInResponsePacket(buffer, battle); break;

            case PBEIllusionPacket.Code: packet = new PBEIllusionPacket(buffer, battle); break;

            case PBEWinnerPacket.Code: packet = new PBEWinnerPacket(buffer, battle); break;

            case PBETurnBeganPacket.Code: packet = new PBETurnBeganPacket(buffer, battle); break;

            case PBEMoveLockPacket.Code: packet = new PBEMoveLockPacket(buffer, battle); break;

            case PBEPkmnFormChangedPacket.Code: packet = new PBEPkmnFormChangedPacket(buffer, battle); break;

            case PBEAutoCenterPacket.Code: packet = new PBEAutoCenterPacket(buffer, battle); break;

            default: throw new ArgumentOutOfRangeException(nameof(code));
            }
            return(packet);
        }