コード例 #1
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.Statusbar);

            StatusMax = reader.ReadInt32();
            Text = reader.ReadString();
        }
コード例 #2
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.DestroyProjectile);

            ProjectileId = reader.ReadInt16();
            PlayerId = reader.ReadByte();
        }
コード例 #3
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.SpawnBossInvsaion);

            PlayerId = (byte)reader.ReadInt16(); // i have no idea why this is a short.
            SpawnId = reader.ReadInt16();
        }
コード例 #4
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdateNpcName);

            UniqueNpcId = reader.ReadInt16();
            Name = reader.ReadString();
        }
コード例 #5
0
 protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
 {
     CheckForValidType(type, TerrPacketType.Time);
     IsDay = reader.ReadBoolean();
     Time = reader.ReadInt32();
     SunModY = reader.ReadInt16();
     MoonModY = reader.ReadInt16();
 }
コード例 #6
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            if (type != TerrPacketType.ChatMessage) throw new ArgumentException($"{nameof(type)} is not {TerrPacketType.ChatMessage}");

            PlayerId = reader.ReadByte();
            Color = reader.ReadTerrColor();
            Text = reader.ReadString();
        }
コード例 #7
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.NpcHomeUpdate);

            UniqueNpcId = reader.ReadInt16();
            HomeTileX = reader.ReadInt16();
            HomeTileY = reader.ReadInt16();
            IsHomeless = reader.ReadByte() != 0;
        }
コード例 #8
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            if (type != TerrPacketType.SetInventory) throw new ArgumentException(nameof(type));

            PlayerId = reader.ReadByte();
            SlotId = reader.ReadByte();
            Stack = reader.ReadInt16();
            Prefix = reader.ReadByte();
            Id = reader.ReadInt16();
        }
コード例 #9
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.KillMe);

            PlayerId = reader.ReadByte();
            HitDirection = reader.ReadByte();
            Damage = reader.ReadInt16();
            WasPvP = reader.ReadBoolean();
            DeathText = reader.ReadString();
        }
コード例 #10
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            if (type != TerrPacketType.UpdatePlayerBuff)
                throw new ArgumentException($"{nameof(type)} is not {TerrPacketType.UpdatePlayerBuff}");

            if (InternalBuffs == null)
                InternalBuffs = new byte[MaxBuffs];

            PlayerId = reader.ReadByte();
            for (byte i = 0; i < MaxBuffs; i++)
                InternalBuffs[i] = reader.ReadByte();
        }
コード例 #11
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.ProjectileUpdate);

            UniqueId = reader.ReadInt16();
            Position = new ValPair<float>(reader);
            Velocity = new ValPair<float>(reader);
            Knockback = reader.ReadSingle();
            Damage = reader.ReadInt16();
            OwnerPlayerId = reader.ReadByte();
            Type = reader.ReadInt16();
            AiFlags = new BitArray(new[] { reader.ReadByte() });

            List<float> aiBuilder = new List<float>();

            for (byte i = 0; i < MaxAi; i++)
                if (AiFlags[i])
                    aiBuilder.Add(reader.ReadSingle());

            Ai = aiBuilder.ToArray();
        }
コード例 #12
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.TogglePvp);

            PlayerId = reader.ReadByte();
            Value = reader.ReadBoolean();
        }
コード例 #13
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.AddNpcBuff);

            PlayerId = reader.ReadByte();
            Buff = reader.ReadByte();
            Time = reader.ReadInt16();
        }
コード例 #14
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.HealOtherPlayer);

            PlayerId = reader.ReadByte();
            HealAmount = reader.ReadInt16();
        }
コード例 #15
0
 protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
 {
     CheckForValidType(type, TerrPacketType.PlayerTeam);
     PlayerId = reader.ReadByte();
     Team = (Player.TeamType)reader.ReadByte();
 }
コード例 #16
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.PlayerAppearance);

            PlayerId = reader.ReadByte();

            foreach (PropertyInfo prop in GetType().GetProperties())
            {
                if (prop.PropertyType == typeof(byte))
                    prop.SetValue(this, reader.ReadByte());

                else if (prop.PropertyType == typeof(TerrColor))
                    prop.SetValue(this, reader.ReadTerrColor());

                else if (prop.PropertyType == typeof(string))
                    prop.SetValue(this, reader.ReadString());
            }
        }
コード例 #17
0
 protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
 {
     NpcType = reader.ReadInt16();
     KillCount = reader.ReadInt32();
 }
コード例 #18
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdatePlayer);

            PlayerId = reader.ReadByte();
            Control = reader.ReadByte();
            Pulley = reader.ReadByte();
            SelectedItem = reader.ReadByte();
            Position = new ValPair<float>(reader);

            // the server doesn't send us the velocity if there is none, thus requiring us to skip reading it if position == lenght.
            if (reader.BaseStream.Position == reader.BaseStream.Length) return;
            Velocity = new ValPair<float>(reader);
        }
コード例 #19
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdateItemDrop, TerrPacketType.UpdateItemDrop2);

            Item = new GameItem();
            UniqueId = reader.ReadInt16();
            Position = new ValPair<float>(reader);
            Velocity = new ValPair<float>(reader);
            Item.Stack = reader.ReadInt16();
            Item.Prefix = reader.ReadByte();
            NoDelay = reader.ReadByte();
            Item.Id = reader.ReadInt16();
        }
コード例 #20
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.RemoveItemOwner);

            ItemIndex = reader.ReadInt16();
        }
コード例 #21
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.AnglerQuest);

            Quest = reader.ReadByte();
            Completed = reader.ReadBoolean();
        }
コード例 #22
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.StrikeNpcWithHeldItem);

            NpcId = reader.ReadInt16();
            PlayerId = reader.ReadByte();
        }
コード例 #23
0
        public void Install(TerrariaClient client)
        {
            _client = client;
            _events = client.Packets();

            if (_events == null)
                throw new NullReferenceException(
                    $"{nameof(client)} doesn't have a valid {typeof (PacketEventService).Name} value.");

            #region Critical

            _events.Subscribe(TerrPacketType.Disconnect, packet =>
            {
                using (PayloadReader reader = new PayloadReader(packet.Payload))
                    client.SetDisconnectState(reader.ReadString());
            });

            _events.Subscribe(TerrPacketType.ContinueConnecting, packet =>
            {
                if (!client.IsLoggingIn) return;

                byte pid = packet.Payload[0];

                _client.CurrentPlayer = new CurrentPlayer(_client.Config.PlayerData)
                {
                    PlayerId = pid,
                    Client = _client,
                    Guid = _client.Config.PlayerGuid
                };

                SendLoginPackets();
            });

            _events.Subscribe(TerrPacketType.RequestPassword, packet =>
            {
                if (string.IsNullOrEmpty(client.Config.Password))
                    throw new ArgumentNullException(client.Config.Password);

                client.Send(TerrPacketType.SendPassword, client.Config.Password);
            });

            #endregion

            #region Player

            _events.Subscribe(TerrPacketType.TogglePvp, packet =>
            {
                TogglePvp pvpState = PacketWrapper.Parse<TogglePvp>(packet);
                Player player = _client.GetPlayer(pvpState.PlayerId);
                player.IsPvp = pvpState.Value;
            });

            _events.Subscribe(TerrPacketType.PlayerAppearance, packet =>
            {
                PlayerAppearance appearance = PacketWrapper.Parse<PlayerAppearance>(packet);
                Player player = _client.GetPlayer(appearance.PlayerId.Value);

                player.Appearance = appearance;
            });

            _events.Subscribe(TerrPacketType.SetInventory, packet =>
            {
                GameItem setItem = PacketWrapper.Parse<GameItem>(packet);
                Player player = _client.GetPlayer(setItem.PlayerId.Value);

                if (player.Inventory == null)
                    player.Inventory = new PlayerInventory();

                player.Inventory.InternalItems[setItem.SlotId.Value] = setItem;
            });

            _events.Subscribe(TerrPacketType.PlayerLife, packet =>
            {
                ValPidPair<short> lifePair = PacketWrapper.Parse<ValPidPair<short>>(packet);
                Player player = _client.GetPlayer(lifePair.PlayerId.Value);

                player.Health = lifePair;
            });

            _events.Subscribe(TerrPacketType.PlayerMana, packet =>
            {
                ValPidPair<short> manaPair = PacketWrapper.Parse<ValPidPair<short>>(packet);
                Player player = _client.GetPlayer(manaPair.PlayerId.Value);

                player.Mana = manaPair;
            });

            _events.Subscribe(TerrPacketType.UpdatePlayerBuff, packet =>
            {
                BuffList buffs = PacketWrapper.Parse<BuffList>(packet);
                Player player = _client.GetPlayer(buffs.PlayerId.Value);

                player.Buffs = buffs;
            });

            _events.Subscribe(TerrPacketType.AddPlayerBuff, packet =>
            {
                AddPlayerBuff addPlayerBuff = PacketWrapper.Parse<AddPlayerBuff>(packet);
                _client.RegisterPlayer(addPlayerBuff.PlayerId);
                _client.Log.Info(
                    $"Add player buff pid {addPlayerBuff.PlayerId} buff: {addPlayerBuff.Buff} time: {addPlayerBuff.Time}");
            });

            _events.Subscribe(TerrPacketType.UpdatePlayer, packet =>
            {
                UpdatePlayer update = PacketWrapper.Parse<UpdatePlayer>(packet);
                _client.GetPlayer(update.PlayerId).Update(update);
            });

            _events.Subscribe(TerrPacketType.PlayerActive, packet =>
            {
                PlayerActive active = PacketWrapper.Parse<PlayerActive>(packet);
                if (active.Active)
                    _client.RegisterPlayer(active.PlayerId);
                else
                    client.RemovePlayer(active.PlayerId);
            });

            _events.Subscribe(TerrPacketType.PlayerTeam, packet =>
            {
                PlayerTeam team = PacketWrapper.Parse<PlayerTeam>(packet);
                _client.GetPlayer(team.PlayerId).Team = team.Team;
            });

            #endregion

            #region World

            _events.Subscribe(TerrPacketType.WorldInformation,
                packet =>
                {
                    _client.World = PacketWrapper.Parse<WorldInfo>(packet);
                    _client.TryClearStars();
                });

            _events.Subscribe(TerrPacketType.Time, packet =>
            {
                WorldTime time = PacketWrapper.Parse<WorldTime>(packet);
                _client.World.RawTime = time.Time;
                _client.World.IsDay = time.IsDay;
                _client.World.SunModY = time.SunModY;
                _client.World.MoonModY = time.MoonModY;
                _client.TryClearStars();
            });

            _events.Subscribe(TerrPacketType.NotifyPlayerOfEvent, packet =>
                _client.OnWorldEventBegin(BitConverter.ToInt16(packet.Payload, 0)));

            _events.Subscribe(TerrPacketType.SetNpcShopItem, packet =>
            {
                _client.Log.Info("Received shop item data.");
            });

            #endregion

            #region Npc

            if (_client.Config.TrackNpcData)
            {
                _events.Subscribe(TerrPacketType.NpcUpdate, packet =>
                {
                    Npc npc = PacketWrapper.Parse<Npc>(packet);
                    _client.NpcAddOrUpdate(npc);
                });
                _events.Subscribe(TerrPacketType.UpdateNpcName, packet =>
                {
                    UpdateNpcName npcName = PacketWrapper.Parse<UpdateNpcName>(packet);
                    _client.GetExistingNpc(npcName.UniqueNpcId).Name = npcName.Name;
                });
                _events.Subscribe(TerrPacketType.TravellingMerchantInventory, packet =>
                {
                    TravellingMerchantInventory travellingMerchant =
                        PacketWrapper.Parse<TravellingMerchantInventory>(packet);

                    // find the traveling merchant in the npc list
                    foreach (var pair in client._npcs.Where(pair => pair.Value.NpcId == NpcId.TravellingMerchant))
                        pair.Value.Shop = travellingMerchant.Items;
                });
                _events.Subscribe(TerrPacketType.SetNpcKillCount,
                    packet => _client.World.SetNpcKc(PacketWrapper.Parse<SetNpcKillCount>(packet)));

                _events.Subscribe(TerrPacketType.NpcHomeUpdate, packet =>
                {
                    NpcHomeUpdate homeUpdate = PacketWrapper.Parse<NpcHomeUpdate>(packet);
                    Npc npc = _client.GetExistingNpc(homeUpdate.UniqueNpcId);
                    npc.HomeTileX = homeUpdate.HomeTileX;
                    npc.HomeTileY = homeUpdate.HomeTileY;
                    npc.IsHomeless = homeUpdate.IsHomeless;
                });

                _events.Subscribe(TerrPacketType.NotifyPlayerNpcKilled, packet =>
                    _client.RemoveNpc(BitConverter.ToInt16(packet.Payload, 0)));
            }

            #endregion

            #region Item

            _events.Subscribe(TerrPacketType.RemoveItemOwner, packet =>
            {
                RemoveItemOwner remItemOwner = PacketWrapper.Parse<RemoveItemOwner>(packet);
                _client.UpdateItemOwner(remItemOwner.ItemIndex, byte.MaxValue);
                // todo : figure out whether a RemoveItemOwner packet should call RemoveItem();
            });

            _events.Subscribe(TerrPacketType.UpdateItemOwner, packet =>
            {
                UpdateItemOwner updateOwner = PacketWrapper.Parse<UpdateItemOwner>(packet);
                _client.UpdateItemOwner(updateOwner.ItemId, updateOwner.Owner);
            });

            if (_client.Config.TrackItemData)
            {
                _events.SubscribeMany(packet =>
                {
                    WorldItem itemDrop = PacketWrapper.Parse<WorldItem>(packet);

                    if (itemDrop.Item.Id == ItemId.None) return;

                    _client.ItemAddOrUpdate(itemDrop);

                }, TerrPacketType.UpdateItemDrop, TerrPacketType.UpdateItemDrop2);
            }

            #endregion

            #region Projectile

            if (_client.Config.TrackProjectileData)
            {
                _events.Subscribe(TerrPacketType.ProjectileUpdate, packet =>
                {
                    WorldProjectile projUpdate = PacketWrapper.Parse<WorldProjectile>(packet);
                    _client.ProjectileAddOrUpdate(projUpdate);
                });

                _events.Subscribe(TerrPacketType.DestroyProjectile, packet =>
                {
                    DestroyProjectile destroyProjectile = PacketWrapper.Parse<DestroyProjectile>(packet);
                    _client.RemoveProjectile(destroyProjectile.ProjectileId);
                });
            }

            #endregion

            #region Misc

            _events.Subscribe(TerrPacketType.Statusbar,
                packet => _client.OnStatusReceived(PacketWrapper.Parse<Status>(packet)));

            _events.Subscribe(TerrPacketType.ChatMessage, packet =>
            {
                ChatMessage msg = PacketWrapper.Parse<ChatMessage>(packet);

                client.OnMessageReceived(msg,
                    client.GetPlayer(msg.PlayerId).IsServer
                        ? MessageReceivedEventArgs.SenderType.Server
                        : MessageReceivedEventArgs.SenderType.Player);
            });

            #endregion
        }
コード例 #24
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.SetActiveNpc);

            PlayerId = reader.ReadByte();
            NpcTalkTarget = reader.ReadInt16();
        }
コード例 #25
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.PlayerDamage);

            PlayerId = reader.ReadByte();
            HitDirecion = reader.ReadByte();
            Damage = reader.ReadInt16();
            DeathText = reader.ReadString();
            Flags = reader.ReadByte();
        }
コード例 #26
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.TravellingMerchantInventory);

            for (byte i = 0; i < Size; i++)
            {
                byte slot = reader.ReadByte();
                Items[i] = new GameItem(reader.ReadByte()) {SlotId = slot};
            }
        }
コード例 #27
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.PlayerActive);

            PlayerId = reader.ReadByte();
            Active = reader.ReadBoolean();
        }
コード例 #28
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdateItemOwner);

            ItemId = reader.ReadInt16();
            Owner = reader.ReadByte();
        }
コード例 #29
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.NumberOfAnglerQuestsCompleted);

            PlayerId = reader.ReadByte();
            QuestsCompleted = reader.ReadInt32();
        }
コード例 #30
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.WorldInformation);

            int tempTime = reader.ReadInt32(); // store this value so we have the correct IsDay when evalutaing real time.

            DayMoonInfo = reader.ReadByte();
            BitArray timeInfo = new BitArray(new [] {DayMoonInfo});
            IsDay = timeInfo[0];
            IsBloodmoon = timeInfo[1];
            IsEclipse = timeInfo[2];

            RawTime = tempTime;

            MoonPhase = (MoonPhaseType) reader.ReadByte();
            MaxTilesX = reader.ReadInt16();
            MaxTilesY = reader.ReadInt16();
            SpawnX = reader.ReadInt16();
            SpawnY = reader.ReadInt16();
            WorldSurface = reader.ReadInt16();
            RockLayer = reader.ReadInt16();
            WorldId = reader.ReadInt32();
            WorldName = reader.ReadString();
            MoonType = reader.ReadByte();
            TreeBackground = reader.ReadByte();
            CorruptionBackground = reader.ReadByte();
            JungleBackground = reader.ReadByte();
            SnowBackground = reader.ReadByte();
            HallowBackground = reader.ReadByte();
            CrimsonBackground = reader.ReadByte();
            DesertBackground = reader.ReadByte();
            OceanBackground = reader.ReadByte();
            IceBackStyle = reader.ReadByte();
            JungleBackStyle = reader.ReadByte();
            HellBackStyle = reader.ReadByte();
            WindSpeedSet = reader.ReadSingle();
            CloudNumber = reader.ReadByte();
            Tree1 = reader.ReadInt32();
            Tree2 = reader.ReadInt32();
            Tree3 = reader.ReadInt32();
            TreeStyle1 = reader.ReadByte();
            TreeStyle2 = reader.ReadByte();
            TreeStyle3 = reader.ReadByte();
            TreeStyle4 = reader.ReadByte();
            CaveBack1 = reader.ReadInt32();
            CaveBack2 = reader.ReadInt32();
            CaveBack3 = reader.ReadInt32();
            CaveBackStyle1 = reader.ReadByte();
            CaveBackStyle2 = reader.ReadByte();
            CaveBackStyle3 = reader.ReadByte();
            CaveBackStyle4 = reader.ReadByte();
            Rain = reader.ReadSingle();

            BitArray events1 = new BitArray(new [] {reader.ReadByte()});
            IsShadowOrbSmashed = events1[0];
            IsEyeOfCthuluDefeated = events1[1];
            IsEowOrBrainDefeated = events1[2];
            IsSkeletronDefeated = events1[3];
            IsHardmode = events1[4];
            IsClownDefeated = events1[5];
            // events1[6] is Main.serverSideCharacter.
            IsPlanteraDefeated = events1[7];

            BitArray events2 = new BitArray(new [] {reader.ReadByte()});
            IsDestroyedDeafeated = events2[0];
            AreTwinsDefeated = events2[1];
            IsSkeletronPrimeDefeated = events2[2];
            IsAnyMechBossDefeated = events2[3];
            IsCloudBgActive = events2[4];
            IsCrimson = events2[5];
            IsPumpkinMoonActive = events2[6];
            IsSnowMoonActive = events2[7];

            BitArray events3 = new BitArray(new [] {reader.ReadByte()});
            IsExpertMode = events3[0];
            IsFastForwardingTime = events3[1];
            IsSlimeRainActive = events3[2];
            IsSlimeKingDefeated = events3[3];
            IsQueenBeeDefeated = events3[4];
            IsFishronDefeated = events3[5];
            AreMartiansDefeated = events3[6];
            AreCultistsDefeated = events3[7];

            BitArray events4 = new BitArray(new [] {reader.ReadByte()});
            IsMoonlordDefeated = events4[0];
            IsHalloweenKingDefeated = events4[1];
            IsHalloweenTreeDefeated = events4[2];
            IsChristmasIceQueenDefeated = events4[3];
            IsChristmasSantankDefeated = events4[4];
            IsChristmasTreeDefeated = events4[5];
            IsGolemDefeated = events4[6];

            InvasionType = reader.ReadSByte();
            LobbyId = reader.ReadUInt64();
        }