Exemplo n.º 1
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.Statusbar);

            StatusMax = reader.ReadInt32();
            Text = reader.ReadString();
        }
Exemplo n.º 2
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdateNpcName);

            UniqueNpcId = reader.ReadInt16();
            Name = reader.ReadString();
        }
Exemplo n.º 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();
        }
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.DestroyProjectile);

            ProjectileId = reader.ReadInt16();
            PlayerId = reader.ReadByte();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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();
 }
Exemplo n.º 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;
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
 /// <summary>
 /// Subscribes to a given PacketType event, which is called every time we receive a packet of that type.
 /// </summary>
 public void Subscribe(TerrPacketType type, OnPacketReceivedEvent evnt)
 {
     if (TerrPacket.IsValidType(type))
     {
         if (_packetEvents.ContainsKey(type))
             _packetEvents[type] += evnt;
         else
             _packetEvents.Add(type, evnt);
     }
     else
         throw new ArgumentException($"{type} is not a valid TerrPacketType type.");
 }
        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();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates bytes that represent a payloadless terraria client -> server packet.
        /// </summary>
        /// <param name="type">The type of the packet.</param>
        /// <returns>A new byte array containing the bytes of the packet.</returns>
        public static byte[] Create(TerrPacketType type)
        {
            ushort packetLength = Size_Length + Size_PacketId;
            byte[] packet = new byte[packetLength];

            //set the length of the packet.
            Buffer.BlockCopy(BitConverter.GetBytes(packetLength), 0, packet, 0, Size_Length);

            //set the type
            packet[Index_PacketId] = (byte) type;

            return packet;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates bytes that represent a terraria client -> server (with payload) packet.
        /// </summary>
        /// <param name="type">The type of the packet.</param>
        /// <param name="payload">The payload, which we will be sending to the server.</param>
        /// <returns>A new byte array containing the bytes of the packet.</returns>
        public static byte[] Create(TerrPacketType type, byte[] payload)
        {
            byte[] packet = PayloadlessToPayloadPacket(Create(type), (short) payload.Length);

            //Set payload
            Buffer.BlockCopy(payload, 0, packet, Index_Payload, payload.Length);

            return packet;
        }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.PlayerActive);

            PlayerId = reader.ReadByte();
            Active = reader.ReadBoolean();
        }
Exemplo n.º 18
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();
        }
 public bool ContainsEvent(TerrPacketType type) => _packetEvents.ContainsKey(type);
Exemplo n.º 20
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.AddNpcBuff);

            PlayerId = reader.ReadByte();
            Buff = reader.ReadByte();
            Time = reader.ReadInt16();
        }
Exemplo n.º 21
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.HealOtherPlayer);

            PlayerId = reader.ReadByte();
            HealAmount = reader.ReadInt16();
        }
Exemplo n.º 22
0
 protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
 {
     CheckForValidType(type, TerrPacketType.PlayerTeam);
     PlayerId = reader.ReadByte();
     Team = (Player.TeamType)reader.ReadByte();
 }
Exemplo n.º 23
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.UpdateItemOwner);

            ItemId = reader.ReadInt16();
            Owner = reader.ReadByte();
        }
Exemplo n.º 24
0
 protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
 {
     NpcType = reader.ReadInt16();
     KillCount = reader.ReadInt32();
 }
Exemplo n.º 25
0
 public static byte[] Create(TerrPacketType type, string payload)
     => Create(type, Utils.EncodeTerrString(payload));
Exemplo n.º 26
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.TogglePvp);

            PlayerId = reader.ReadByte();
            Value = reader.ReadBoolean();
        }
Exemplo n.º 27
0
 public static bool IsValidType(TerrPacketType type) => Enum.IsDefined(typeof(TerrPacketType), type) && type != TerrPacketType.None;
Exemplo n.º 28
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();
        }
Exemplo n.º 29
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());
            }
        }
Exemplo n.º 30
0
        protected override void ReadPayload(PayloadReader reader, TerrPacketType type)
        {
            CheckForValidType(type, TerrPacketType.RemoveItemOwner);

            ItemIndex = reader.ReadInt16();
        }