Exemple #1
0
        void OnSendBytes(SendBytesEventArgs e)
        {
            bool build = (pause || !match); // (pause || !match)

            switch (e.Buffer[2])
            {
            case 23:
                NPC npc = Main.npc[BitConverter.ToInt16(e.Buffer, 3)];
                if (!npc.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.X), 0, e.Buffer, 5, 4);
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.Y), 0, e.Buffer, 9, 4);
                }
                break;

            case 27:
                short      id    = BitConverter.ToInt16(e.Buffer, 3);
                int        owner = e.Buffer[27];
                Projectile proj  = Main.projectile[TShock.Utils.SearchProjectile(id, owner)];
                if (!proj.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes((short)(build ? 0 : proj.type)), 0, e.Buffer, 28, 2);
                }
                break;
            }
        }
Exemple #2
0
 private void BlockSentData(SendBytesEventArgs args)
 {
     if (ShouldDropPacket(args.Buffer, args.Offset, args.Count, (byte)args.Socket.Id))
     {
         args.Handled = true;
     }
 }
Exemple #3
0
 private void OnSendBytes(SendBytesEventArgs args)
 {
     if (_forward[args.Socket.Id].Server.Name != _config.Name)
     {
         args.Handled = true;
     }
 }
Exemple #4
0
        void OnSendBytes(SendBytesEventArgs e)
        {
            bool build = Build[e.Socket.WhoAmI];

            switch (e.Buffer[2])
            {
            case 7:
                using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                {
                    writer.Write(build ? 27000 : (int)Main.time);
                    BitsByte bb = 0;
                    bb[0] = build ? true : Main.dayTime;
                    bb[1] = build ? false : Main.bloodMoon;
                    bb[2] = build ? false : Main.eclipse;
                    writer.Write(bb);

                    writer.BaseStream.Position += 9;
                    writer.Write(build ? (short)Main.maxTilesY : (short)Main.worldSurface);
                    writer.Write(build ? (short)Main.maxTilesY : (short)Main.rockLayer);

                    writer.BaseStream.Position += 4;
                    writer.Write(Main.worldName);

                    writer.BaseStream.Position += 49;
                    writer.Write(build ? 0f : Main.maxRaining);
                }
                break;

            case 18:
                using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                {
                    writer.Write(build ? true : Main.dayTime);
                    writer.Write(build ? 27000 : (int)Main.time);
                }
                break;

            case 23:
                NPC npc = Main.npc[BitConverter.ToInt16(e.Buffer, 3)];
                if (!npc.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.X), 0, e.Buffer, 5, 4);
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.Y), 0, e.Buffer, 9, 4);
                }
                break;

            case 27:
                short      id    = BitConverter.ToInt16(e.Buffer, 3);
                int        owner = e.Buffer[27];
                Projectile proj  = Main.projectile[TShock.Utils.SearchProjectile(id, owner)];
                if (!proj.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes((short)(build ? 0 : proj.type)), 0, e.Buffer, 28, 2);
                }
                break;
            }
        }
Exemple #5
0
        private void OnNetSendBytes(SendBytesEventArgs e)
        {
            if (!_configuration.ToggleFriendlyFire)
            {
                return;
            }

            var packetType = e.Buffer[2];

            if (e.Handled && packetType == (int)PacketTypes.PlayerHurtV2)
            {
                return;
            }

            var playerMetadata = TShock.Players[e.Socket.Id]?.GetData <PlayerMetadata>(DataKey);

            if (playerMetadata == null || playerMetadata.Clan.IsFriendlyFire)
            {
                return;
            }

            var dealerIndex       = -1;
            var playerDeathReason = (BitsByte)e.Buffer[4];

            if (playerDeathReason[0])
            {
                dealerIndex = e.Buffer[5];
            }
            if (dealerIndex != -1)
            {
                var dealer         = TShock.Players[dealerIndex];
                var dealerMetadata = dealer?.GetData <PlayerMetadata>(DataKey);
                if (dealerMetadata?.Clan.Name != playerMetadata.Clan.Name)
                {
                    return;
                }

                using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                {
                    writer.Write((byte)255);
                    writer.Write((byte)0);
                    writer.Write((short)0);
                }
            }

            e.Handled = true;
        }
Exemple #6
0
 private void ServerHooks_SendBytes(SendBytesEventArgs args)
 {
     args.Handled = true;
     BufferBytes(args.Socket, args.Buffer, args.Offset, args.Count);
 }
Exemple #7
0
        void OnSendBytes(SendBytesEventArgs e)
        {
            if (TShock.Players[e.Socket.Id] == null)
            {
                return;
            }

            bool build = TShock.Players[e.Socket.Id].GetData <bool>("buildmode");

            switch (e.Buffer[2])
            {
            case (byte)PacketTypes.WorldInfo:                     //7
                using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                {
                    writer.Write(build ? 27000 : (int)Main.time);
                    BitsByte bb = 0;
                    bb[0] = build ? true : Main.dayTime;
                    bb[1] = build ? false : Main.bloodMoon;
                    bb[2] = build ? false : Main.eclipse;
                    writer.Write(bb);

                    writer.BaseStream.Position += 9;
                    writer.Write(build ? (short)Main.maxTilesY : (short)Main.worldSurface);
                    writer.Write(build ? (short)Main.maxTilesY : (short)Main.rockLayer);

                    writer.BaseStream.Position += 4;
                    writer.Write(Main.worldName);
                    writer.Write(Main.ActiveWorldFileData.UniqueId.ToString());

                    writer.BaseStream.Position += 49;
                    writer.Write(build ? 0f : Main.maxRaining);
                }
                break;

            case (byte)PacketTypes.TimeSet:                     //18
                using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3)))
                {
                    writer.Write(build ? true : Main.dayTime);
                    writer.Write(build ? 27000 : (int)Main.time);
                }
                break;

            case (byte)PacketTypes.MassWireOperationPay:
                TSPlayer tsplr = TShock.Players[e.Buffer[7]];
                if (tsplr.GetData <bool>("buildmode"))
                {
                    e.Handled = true;                     //Will never decrement wires/actuators in inventory
                }
                break;

            case (byte)PacketTypes.NpcUpdate:                     //23
                NPC npc = Main.npc[BitConverter.ToInt16(e.Buffer, 3)];
                if (!npc.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.X), 0, e.Buffer, 5, 4);
                    Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.Y), 0, e.Buffer, 9, 4);
                }
                break;

            case (byte)PacketTypes.ProjectileNew:                     //27
                short      id    = BitConverter.ToInt16(e.Buffer, 3);
                int        owner = e.Buffer[21];
                Projectile proj  = Main.projectile[TShock.Utils.SearchProjectile(id, owner)];
                if (!proj.friendly)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes((short)(build ? 0 : proj.type)), 0, e.Buffer, 22, 2);
                }
                break;
            }
        }
Exemple #8
0
        private void OnSendBytes(SendBytesEventArgs args)
        {
            byte seer = (byte)args.Socket.Id, seen;
            int  bOffset = args.Offset + 3;

            switch (args.Buffer[args.Offset + 2])
            {
            case 4:
            case 5:
            case 12:
            case 13:
            case 14:
            case 16:
            case 30:
            case 35:
            case 36:
            case 40:
            case 41:
            case 42:
            case 43:
            case 45:
            case 50:
            case 51:
            case 55:
            case 58:
            case 62:
            case 66:
            case 80:
            case 84:
            case 96:
            case 99:
            case 102:
            case 115:
            case 117:
            case 118:
                seen = args.Buffer[bOffset];
                break;

            case 22:
            case 24:
            case 29:
            case 70:
                seen = args.Buffer[bOffset + 2];
                break;

            case 61:
                seen = args.Buffer[bOffset];
                break;

            case 27:
                seen = args.Buffer[bOffset + 24];
                break;

            case 65:
                byte flag = args.Buffer[bOffset];
                if (((flag & 1) == 0) && ((flag & 4) == 0))
                {
                    return;
                }
                seen = args.Buffer[bOffset + 1];
                break;

            case 108:
                seen = args.Buffer[bOffset + 14];
                break;

            case 110:
                seen = args.Buffer[bOffset + 4];
                break;

            default:
                return;
            }

            if (!GPAPI.CheckCanSee(seer, seen))
            {
                args.Handled = true;
            }
        }
Exemple #9
0
        /// <summary>
        /// Modifies outgoing packets to send fake data to the player.
        /// </summary>
        /// <param name="args"></param>
        private void OnSendBytes(SendBytesEventArgs args)
        {
            var player = TShock.Players[args.Socket.Id];

            if (player == null || !player.IsBuildModeOn())
            {
                return;
            }

            PacketTypes packetType = (PacketTypes)args.Buffer[2];

            switch (packetType)
            {
            /// Invoked whenever the server sends WorldInfo data.
            /// Sending crafted data to the player such as:
            /// Setting time to noon, stopping rain, wind and sandstorm,
            /// as well as modifying world surface and rock layer height
            /// to display a surface background to the player.
            case PacketTypes.WorldInfo:
            {
                WorldInfoPacket packet = new WorldInfoPacket();
                packet.time             = 27000;
                packet.BitsByte1        = new BitsByte(true);   // isDayTime = true
                packet.worldSurface     = (short)Main.maxTilesY;
                packet.rockLayer        = (short)Main.maxTilesY;
                packet.windSpeedTarget  = 0;
                packet.maxRaining       = 0;
                packet.IntendedSeverity = 0;
                packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count));

                break;
            }

            /// Invoked whenever time is modified on the server.
            /// Sending crafted data to the player such as:
            /// Setting time to noon.
            case PacketTypes.TimeSet:
            {
                TimeSetPacket packet = new TimeSetPacket();
                packet.dayTime = true;
                packet.time    = 27000;
                packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count));

                break;
            }

            /// Invoked whenever Server sends updated data of an NPC.
            /// Sending crafted data to the player such as:
            /// If NPC is not friendly, change its position to make them invisible for the player.
            case PacketTypes.NpcUpdate:
            {
                NPCUpdatePacket packet = new NPCUpdatePacket();
                packet.Read(new MemoryStream(args.Buffer, args.Offset, args.Count));
                if (!Main.npc[packet.npcIndex].active || Main.npc[packet.npcIndex].friendly)
                {
                    return;
                }
                packet.position = new Microsoft.Xna.Framework.Vector2();
                packet.velocity = new Microsoft.Xna.Framework.Vector2();
                packet.Write(new MemoryStream(args.Buffer, args.Offset, args.Count));
                break;
            }

            /// Invoked whenever Server sends updated data of a Projectile.
            /// Sending crafted data to the player such as:
            /// If projectile is hostile and it is not the player's projectile, change its position to make it invisible for the player.
            case PacketTypes.ProjectileNew:
            {
                ProjectileNewPacket projectilePacket = new ProjectileNewPacket();
                projectilePacket.Read(new MemoryStream(args.Buffer, args.Offset, args.Count));

                if (Main.projectile.First(e => e.identity == projectilePacket.Index && e.owner == projectilePacket.Owner).friendly)
                {
                    return;
                }
                projectilePacket.Type = 0;
                projectilePacket.Write(new MemoryStream(args.Buffer, args.Offset, args.Count));
                break;
            }
            }
        }
Exemple #10
0
        private void OnSendBytes(SendBytesEventArgs args)
        {
            var player = TShock.Players[args.Socket.Id];

            if (player == null || !player.ContainsData("buildmode") || !player.GetData <bool>("buildmode"))
            {
                return;
            }

            switch (args.Buffer[2])
            {
            case 7:     //WorldInfo
                using (var writer = new BinaryWriter(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    writer.BaseStream.Position += 3;
                    writer.Write(27000);                 //Time
                    writer.Write(new BitsByte(true));    // isDayTime = true
                    writer.BaseStream.Position += 9;
                    writer.Write((short)Main.maxTilesY); //worldSurface
                    writer.Write((short)Main.maxTilesY); //rockLayer
                    writer.BaseStream.Position += 4;
                    writer.Write(Main.worldName);        //worldName
                    writer.BaseStream.Position += 92;
                    writer.Write((Single)0);             //Rain
                    writer.BaseStream.Position += 30;
                    writer.Write((Single)0);             //Sandstorm
                }
                break;

            case 18:
                using (var writer = new BinaryWriter(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    writer.BaseStream.Position += 3;
                    writer.Write(true);     // isDayTime
                    writer.Write(27000);    // Time
                }
                break;

            case 23:
                int npcIndex;
                using (var reader = new BinaryReader(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    reader.ReadBytes(3);
                    npcIndex = reader.ReadInt16();
                }
                if (Main.npc[npcIndex].friendly)
                {
                    return;
                }
                using (var writer = new BinaryWriter(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    //Hide all NPCs at 0,0
                    writer.BaseStream.Position += 5;
                    writer.Write((Single)0);     //PosX
                    writer.Write((Single)0);     //PosY
                }
                break;

            case 27:
                short projectileID;
                byte  projectileOwner;
                using (var reader = new BinaryReader(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    reader.ReadBytes(3);
                    projectileID = reader.ReadInt16();
                    reader.ReadBytes(16);
                    projectileOwner = reader.ReadByte();
                }
                if (Main.projectile.First(e => e.identity == projectileID && e.owner == projectileOwner).friendly)
                {
                    return;
                }
                using (var writer = new BinaryWriter(new MemoryStream(args.Buffer, args.Offset, args.Count)))
                {
                    writer.BaseStream.Position += 3;
                    writer.BaseStream.Position += 19;
                    writer.Write((Int16)0);     //Type
                }
                break;
            }
        }