public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            short identity = BitConverter.ToInt16(readBuffer, num);

            num += 2;
            byte owner = readBuffer[num];

            owner = (byte)whoAmI;

            int index = Projectile.FindExisting(identity, owner);

            if (index == 1000)
            {
                return;
            }

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player     = player,
                Sender     = player,
            };

            var args = new HookArgs.KillProjectileReceived
            {
                Id    = identity,
                Owner = owner,
                Index = (short)index,
            };

            HookPoints.KillProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                var msg = NetMessage.PrepareThreadInstance();
                msg.Projectile(Main.projectile[index]);
                msg.Send(whoAmI);
                return;
            }

            var projectile = Main.projectile[index];

            if (projectile.Owner == owner && projectile.identity == identity)
            {
                projectile.Kill();
                NetMessage.SendData(29, -1, whoAmI, "", (int)identity, (float)owner);
            }
        }
Esempio n. 2
0
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            //TODO [KillProjectileReceived]

            int identity = (int)ReadInt16(readBuffer);
            int playerId = (int)ReadByte(readBuffer);

            if (playerId != whoAmI && Entry.EnableCheatProtection)
            {
                Terraria.Netplay.Clients[whoAmI].Kick("Cheating detected (KILL_PROJECTILE forgery).");
                return;
            }

            var index = Tools.FindExistingProjectileForUser(whoAmI, identity);

            if (index == -1)
            {
                return;
            }

            var player = Main.player[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player     = player,
                Sender     = player,
            };

            var args = new HookArgs.KillProjectileReceived
            {
                Id    = identity,
                Owner = whoAmI,
                Index = index,
            };

            HookPoints.KillProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                var msg = NewNetMessage.PrepareThreadInstance();
                msg.Projectile(Main.projectile[index]);
                msg.Send(whoAmI);
                return;
            }

            var projectile = Main.projectile[index];

            if (projectile.owner == whoAmI && projectile.identity == identity)
            {
                projectile.Kill();
                NewNetMessage.SendData(29, -1, whoAmI, String.Empty, identity, (float)whoAmI);
            }
        }