Example #1
0
        private bool RPC_OnPlayerAttack(ERPCNetworkType type, Message message)
        {
            if (MeleeAim.HasCooldown() || AutoGather.HasCooldown())
            {
                return(true);
            }
            using (PlayerAttack playerAttack = PlayerAttack.Deserialize(message.read))
            {
                var attack = playerAttack.attack;
                if (attack.hitID == 0)
                {
                    return(true);
                }

                #region [BaseResource]
                var resource = Get <BaseResource>(attack.hitID);
                if (resource != null)
                {
                    attack.hitItem   = 0;
                    attack.hitBone   = 0;
                    attack.hitPartID = 0;
                    var pos = Settings.ManualGather_Bonus ? resource.GetHitPosition() : resource.Position;

                    // Если это OreResource
                    if (pos != resource.Position)
                    {
                        attack.hitPositionWorld = pos;
                        attack.hitNormalWorld   = pos;
                    }
                    AutoGather.SetCooldown((EPrefabUID)PrefabID);
                    if (VirtualServer.BaseClient.write.Start())
                    {
                        VirtualServer.BaseClient.write.PacketID(Message.Type.RPCMessage);
                        VirtualServer.BaseClient.write.EntityID(this.UID);
                        VirtualServer.BaseClient.write.UInt32((UInt32)ERPCMethodUID.PlayerAttack);
                        PlayerAttack.Serialize(VirtualServer.BaseClient.write, playerAttack);
                        VirtualServer.BaseClient.Send();
                        return(true);
                    }
                }
                #endregion

                #region [BasePlayer]
                if (Settings.Aimbot_Melee_Manual)
                {
                    var player = Get <BasePlayer>(playerAttack.attack.hitID);
                    if (player != null)
                    {
                        var typeHit = OpCodes.GetTargetHit((EHumanBone)attack.hitBone, Settings.Aimbot_Melee_Manual_AutoHeadshot);
                        MeleeAim.SetCooldown((EPrefabUID)this.PrefabID);
                        return(SendMeleeAttack(player, typeHit, player.Position));
                    }
                }
                #endregion
            }
            return(false);
        }
Example #2
0
        void OnRPC_PlayerAttack(Message packet)
        {
            BasePlayer player = packet.ToPlayer();

            using (PlayerAttack playerAttack = PlayerAttack.Deserialize(packet.read))
            {
                if (Find(playerAttack.attack.hitID, out BaseEntity hitEntity))
                {
                    if (hitEntity is BaseCombatEntity hitCombatEntity)
                    {
                        Item ActiveItem = player.ActiveItem;
                        if (ActiveItem.Information.IsHoldable())
                        {
                            hitCombatEntity.Hurt(ActiveItem.Information.BaseMelee.Damage);
                        }
                        else
                        {
                            ConsoleSystem.LogError($"[{nameof(OnRPC_PlayerAttack)}][NOT HELD ENTITY] Trying hit from <{ActiveItem.Information.ItemID}>");
                        }
                    }
                }
            }
        }
    public void PlayerAttack(BaseEntity.RPCMessage msg)
    {
        Vector3    parentVelocity;
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        using (TimeWarning timeWarning = TimeWarning.New("PlayerAttack", (long)50))
        {
            using (PlayerAttack playerAttack = PlayerAttack.Deserialize(msg.read))
            {
                if (playerAttack != null)
                {
                    HitInfo hitInfo = Facepunch.Pool.Get <HitInfo>();
                    hitInfo.LoadFromAttack(playerAttack.attack, true);
                    hitInfo.Initiator        = basePlayer;
                    hitInfo.Weapon           = this;
                    hitInfo.WeaponPrefab     = this;
                    hitInfo.Predicted        = msg.connection;
                    hitInfo.damageProperties = this.damageProperties;
                    if (Interface.CallHook("OnMeleeAttack", basePlayer, hitInfo) != null)
                    {
                        return;
                    }
                    if (!hitInfo.IsNaNOrInfinity())
                    {
                        if (ConVar.AntiHack.melee_protection > 0 && hitInfo.HitEntity)
                        {
                            bool  flag              = true;
                            float meleeForgiveness  = 1f + ConVar.AntiHack.melee_forgiveness;
                            float meleeClientframes = ConVar.AntiHack.melee_clientframes;
                            float meleeServerframes = ConVar.AntiHack.melee_serverframes;
                            float single            = meleeClientframes / 60f;
                            float single1           = meleeServerframes * Mathx.Max(UnityEngine.Time.deltaTime, UnityEngine.Time.smoothDeltaTime, UnityEngine.Time.fixedDeltaTime);
                            float single2           = (basePlayer.desyncTime + single + single1) * meleeForgiveness;
                            if (ConVar.AntiHack.projectile_protection >= 2)
                            {
                                float single3 = hitInfo.HitEntity.MaxVelocity();
                                parentVelocity = hitInfo.HitEntity.GetParentVelocity();
                                float single4 = single3 + parentVelocity.magnitude;
                                float single5 = hitInfo.HitEntity.BoundsPadding() + single2 * single4;
                                float single6 = hitInfo.HitEntity.Distance(hitInfo.HitPositionWorld);
                                if (single6 > single5)
                                {
                                    string shortPrefabName = base.ShortPrefabName;
                                    string str             = hitInfo.HitEntity.ShortPrefabName;
                                    AntiHack.Log(basePlayer, AntiHackType.MeleeHack, string.Concat(new object[] { "Entity too far away (", shortPrefabName, " on ", str, " with ", single6, "m > ", single5, "m in ", single2, "s)" }));
                                    basePlayer.stats.combat.Log(hitInfo, "melee_distance");
                                    flag = false;
                                }
                            }
                            if (ConVar.AntiHack.melee_protection >= 1)
                            {
                                float single7 = hitInfo.Initiator.MaxVelocity();
                                parentVelocity = hitInfo.Initiator.GetParentVelocity();
                                float single8  = single7 + parentVelocity.magnitude;
                                float single9  = hitInfo.Initiator.BoundsPadding() + single2 * single8 + meleeForgiveness * this.maxDistance;
                                float single10 = hitInfo.Initiator.Distance(hitInfo.HitPositionWorld);
                                if (single10 > single9)
                                {
                                    string shortPrefabName1 = base.ShortPrefabName;
                                    string str1             = hitInfo.HitEntity.ShortPrefabName;
                                    AntiHack.Log(basePlayer, AntiHackType.MeleeHack, string.Concat(new object[] { "Initiator too far away (", shortPrefabName1, " on ", str1, " with ", single10, "m > ", single9, "m in ", single2, "s)" }));
                                    basePlayer.stats.combat.Log(hitInfo, "melee_distance");
                                    flag = false;
                                }
                            }
                            if (ConVar.AntiHack.melee_protection >= 3)
                            {
                                Vector3 pointStart       = hitInfo.PointStart;
                                Vector3 hitPositionWorld = hitInfo.HitPositionWorld + (hitInfo.HitNormalWorld.normalized * 0.001f);
                                Vector3 vector3          = basePlayer.eyes.center;
                                Vector3 vector31         = basePlayer.eyes.position;
                                Vector3 vector32         = pointStart;
                                Vector3 vector33         = hitInfo.PositionOnRay(hitPositionWorld);
                                Vector3 vector34         = hitPositionWorld;
                                bool    flag1            = GamePhysics.LineOfSight(vector3, vector31, vector32, vector33, vector34, 2162688, 0f);
                                if (flag1)
                                {
                                    basePlayer.stats.Add(string.Concat("hit_", hitInfo.HitEntity.Categorize(), "_direct_los"), 1, Stats.Server);
                                }
                                else
                                {
                                    basePlayer.stats.Add(string.Concat("hit_", hitInfo.HitEntity.Categorize(), "_indirect_los"), 1, Stats.Server);
                                }
                                if (!flag1)
                                {
                                    string shortPrefabName2 = base.ShortPrefabName;
                                    string str2             = hitInfo.HitEntity.ShortPrefabName;
                                    AntiHack.Log(basePlayer, AntiHackType.MeleeHack, string.Concat(new object[] { "Line of sight (", shortPrefabName2, " on ", str2, ") ", vector3, " ", vector31, " ", vector32, " ", vector33, " ", vector34 }));
                                    basePlayer.stats.combat.Log(hitInfo, "melee_los");
                                    flag = false;
                                }
                            }
                            if (!flag)
                            {
                                AntiHack.AddViolation(basePlayer, AntiHackType.MeleeHack, ConVar.AntiHack.melee_penalty);
                                return;
                            }
                        }
                        basePlayer.metabolism.UseHeart(this.heartStress * 0.2f);
                        using (TimeWarning timeWarning1 = TimeWarning.New("DoAttackShared", (long)50))
                        {
                            this.DoAttackShared(hitInfo);
                        }
                    }
                    else
                    {
                        string shortPrefabName3 = base.ShortPrefabName;
                        AntiHack.Log(basePlayer, AntiHackType.MeleeHack, string.Concat("Contains NaN (", shortPrefabName3, ")"));
                        basePlayer.stats.combat.Log(hitInfo, "melee_nan");
                    }
                }
            }
        }
    }
Example #4
0
    public void PlayerAttack(BaseEntity.RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!this.VerifyClientAttack(player))
        {
            this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
        }
        else
        {
            using (TimeWarning.New(nameof(PlayerAttack), 50L))
            {
                using (PlayerAttack playerAttack = PlayerAttack.Deserialize((Stream)msg.read))
                {
                    if (playerAttack == null)
                    {
                        return;
                    }
                    HitInfo info = (HitInfo)Pool.Get <HitInfo>();
                    info.LoadFromAttack((Attack)playerAttack.attack, true);
                    info.Initiator        = (BaseEntity)player;
                    info.Weapon           = (AttackEntity)this;
                    info.WeaponPrefab     = (BaseEntity)this;
                    info.Predicted        = msg.connection;
                    info.damageProperties = this.damageProperties;
                    if (Interface.CallHook("OnMeleeAttack", (object)player, (object)info) != null)
                    {
                        return;
                    }
                    if (info.IsNaNOrInfinity())
                    {
                        string shortPrefabName = this.ShortPrefabName;
                        AntiHack.Log(player, AntiHackType.MeleeHack, "Contains NaN (" + shortPrefabName + ")");
                        player.stats.combat.Log(info, "melee_nan");
                    }
                    else
                    {
                        if (ConVar.AntiHack.melee_protection > 0 && Object.op_Implicit((Object)info.HitEntity))
                        {
                            bool   flag = true;
                            float  num1 = 1f + ConVar.AntiHack.melee_forgiveness;
                            double meleeClientframes = (double)ConVar.AntiHack.melee_clientframes;
                            float  meleeServerframes = ConVar.AntiHack.melee_serverframes;
                            float  num2 = (float)(meleeClientframes / 60.0);
                            float  num3 = meleeServerframes * Mathx.Max(Time.get_deltaTime(), Time.get_smoothDeltaTime(), Time.get_fixedDeltaTime());
                            float  num4 = (player.desyncTime + num2 + num3) * num1;
                            if (ConVar.AntiHack.projectile_protection >= 2)
                            {
                                double  num5           = (double)info.HitEntity.MaxVelocity();
                                Vector3 parentVelocity = info.HitEntity.GetParentVelocity();
                                double  magnitude      = (double)((Vector3) ref parentVelocity).get_magnitude();
                                float   num6           = (float)(num5 + magnitude);
                                float   num7           = info.HitEntity.BoundsPadding() + num4 * num6;
                                float   num8           = info.HitEntity.Distance(info.HitPositionWorld);
                                if ((double)num8 > (double)num7)
                                {
                                    string shortPrefabName1 = this.ShortPrefabName;
                                    string shortPrefabName2 = info.HitEntity.ShortPrefabName;
                                    AntiHack.Log(player, AntiHackType.MeleeHack, "Entity too far away (" + shortPrefabName1 + " on " + shortPrefabName2 + " with " + (object)num8 + "m > " + (object)num7 + "m in " + (object)num4 + "s)");
                                    player.stats.combat.Log(info, "melee_distance");
                                    flag = false;
                                }
                            }
                            if (ConVar.AntiHack.melee_protection >= 1)
                            {
                                double  num5           = (double)info.Initiator.MaxVelocity();
                                Vector3 parentVelocity = info.Initiator.GetParentVelocity();
                                double  magnitude      = (double)((Vector3) ref parentVelocity).get_magnitude();
                                float   num6           = (float)(num5 + magnitude);
                                float   num7           = (float)((double)info.Initiator.BoundsPadding() + (double)num4 * (double)num6 + (double)num1 * (double)this.maxDistance);
                                float   num8           = info.Initiator.Distance(info.HitPositionWorld);
                                if ((double)num8 > (double)num7)
                                {
                                    string shortPrefabName1 = this.ShortPrefabName;
                                    string shortPrefabName2 = info.HitEntity.ShortPrefabName;
                                    AntiHack.Log(player, AntiHackType.MeleeHack, "Initiator too far away (" + shortPrefabName1 + " on " + shortPrefabName2 + " with " + (object)num8 + "m > " + (object)num7 + "m in " + (object)num4 + "s)");
                                    player.stats.combat.Log(info, "melee_distance");
                                    flag = false;
                                }
                            }
                            if (ConVar.AntiHack.melee_protection >= 3)
                            {
                                Vector3 pointStart = info.PointStart;
                                Vector3 position1  = Vector3.op_Addition(info.HitPositionWorld, Vector3.op_Multiply(((Vector3) ref info.HitNormalWorld).get_normalized(), 1f / 1000f));
                                Vector3 center     = player.eyes.center;
                                Vector3 position2  = player.eyes.position;
                                Vector3 p2         = pointStart;
                                Vector3 p3         = info.PositionOnRay(position1);
                                Vector3 p4         = position1;
                                int     num5       = GamePhysics.LineOfSight(center, position2, p2, p3, p4, 2162688, 0.0f) ? 1 : 0;
                                if (num5 == 0)
                                {
                                    player.stats.Add("hit_" + info.HitEntity.Categorize() + "_indirect_los", 1, Stats.Server);
                                }
                                else
                                {
                                    player.stats.Add("hit_" + info.HitEntity.Categorize() + "_direct_los", 1, Stats.Server);
                                }
                                if (num5 == 0)
                                {
                                    string shortPrefabName1 = this.ShortPrefabName;
                                    string shortPrefabName2 = info.HitEntity.ShortPrefabName;
                                    AntiHack.Log(player, AntiHackType.MeleeHack, "Line of sight (" + shortPrefabName1 + " on " + shortPrefabName2 + ") " + (object)center + " " + (object)position2 + " " + (object)p2 + " " + (object)p3 + " " + (object)p4);
                                    player.stats.combat.Log(info, "melee_los");
                                    flag = false;
                                }
                            }
                            if (!flag)
                            {
                                AntiHack.AddViolation(player, AntiHackType.MeleeHack, ConVar.AntiHack.melee_penalty);
                                return;
                            }
                        }
                        player.metabolism.UseHeart(this.heartStress * 0.2f);
                        using (TimeWarning.New("DoAttackShared", 50L))
                            this.DoAttackShared(info);
                    }
                }
            }
        }
    }