Example #1
0
    private void ServerFractionalReloadInsert(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientRPC(player))
        {
            SendNetworkUpdate();
            reloadStarted  = false;
            reloadFinished = false;
            return;
        }
        if (!fractionalReload)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "Fractional reload not allowed (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_type");
            return;
        }
        if (!reloadStarted)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "Fractional reload request skipped (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_skip");
            reloadStarted  = false;
            reloadFinished = false;
            return;
        }
        if (GetReloadIdle() > 3f)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "T+" + GetReloadIdle() + "s (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_time");
            reloadStarted  = false;
            reloadFinished = false;
            return;
        }
        if (UnityEngine.Time.time < startReloadTime + reloadStartDuration)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "Fractional reload too early (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_fraction_too_early");
            reloadStarted  = false;
            reloadFinished = false;
        }
        if (UnityEngine.Time.time < startReloadTime + reloadStartDuration + (float)fractionalInsertCounter * reloadFractionDuration)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "Fractional reload rate too high (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_fraction_rate");
            reloadStarted  = false;
            reloadFinished = false;
        }
        else
        {
            fractionalInsertCounter++;
            if (primaryMagazine.contents < primaryMagazine.capacity)
            {
                ReloadMagazine(1);
            }
        }
    }
    protected bool ValidateEyePos(BasePlayer player, Vector3 eyePos)
    {
        bool flag = true;

        if (Vector3Ex.IsNaNOrInfinity(eyePos))
        {
            string shortPrefabName = this.ShortPrefabName;
            AntiHack.Log(player, AntiHackType.EyeHack, "Contains NaN (" + shortPrefabName + ")");
            player.stats.combat.Log(this, "eye_nan");
            flag = false;
        }
        if (ConVar.AntiHack.eye_protection > 0)
        {
            float  num1            = 1f + ConVar.AntiHack.eye_forgiveness;
            double eyeClientframes = (double)ConVar.AntiHack.eye_clientframes;
            float  eyeServerframes = ConVar.AntiHack.eye_serverframes;
            float  num2            = (float)(eyeClientframes / 60.0);
            float  num3            = eyeServerframes * Mathx.Max(Time.get_deltaTime(), Time.get_smoothDeltaTime(), Time.get_fixedDeltaTime());
            float  num4            = (player.desyncTime + num2 + num3) * num1;
            if (ConVar.AntiHack.eye_protection >= 1)
            {
                double  num5           = (double)player.MaxVelocity();
                Vector3 parentVelocity = player.GetParentVelocity();
                double  magnitude      = (double)((Vector3) ref parentVelocity).get_magnitude();
                float   num6           = (float)(num5 + magnitude);
                float   num7           = player.BoundsPadding() + num4 * num6;
                float   num8           = Vector3.Distance(player.eyes.position, eyePos);
                if ((double)num8 > (double)num7)
                {
                    string shortPrefabName = this.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, "Distance (" + shortPrefabName + " on attack with " + (object)num8 + "m > " + (object)num7 + "m)");
                    player.stats.combat.Log(this, "eye_distance");
                    flag = false;
                }
            }
            if (ConVar.AntiHack.eye_protection >= 2)
            {
                Vector3 center   = player.eyes.center;
                Vector3 position = player.eyes.position;
                Vector3 p2       = eyePos;
                if (!GamePhysics.LineOfSight(center, position, p2, 2162688, 0.0f))
                {
                    string shortPrefabName = this.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, "Line of sight (" + shortPrefabName + " on attack) " + (object)center + " " + (object)position + " " + (object)p2);
                    player.stats.combat.Log(this, "eye_los");
                    flag = false;
                }
            }
            if (!flag)
            {
                AntiHack.AddViolation(player, AntiHackType.EyeHack, ConVar.AntiHack.eye_penalty);
            }
        }
        return(flag);
    }
Example #3
0
    protected bool ValidateEyePos(BasePlayer player, Vector3 eyePos)
    {
        bool flag = true;

        if (eyePos.IsNaNOrInfinity())
        {
            string shortPrefabName = base.ShortPrefabName;
            AntiHack.Log(player, AntiHackType.EyeHack, "Contains NaN (" + shortPrefabName + ")");
            player.stats.combat.Log(this, "eye_nan");
            flag = false;
        }
        if (ConVar.AntiHack.eye_protection > 0)
        {
            float num = 1f + ConVar.AntiHack.eye_forgiveness;
            float eye_clientframes = ConVar.AntiHack.eye_clientframes;
            float eye_serverframes = ConVar.AntiHack.eye_serverframes;
            float num2             = eye_clientframes / 60f;
            float num3             = eye_serverframes * Mathx.Max(UnityEngine.Time.deltaTime, UnityEngine.Time.smoothDeltaTime, UnityEngine.Time.fixedDeltaTime);
            float num4             = (player.desyncTimeClamped + num2 + num3) * num;
            int   layerMask        = (ConVar.AntiHack.eye_terraincheck ? 10551296 : 2162688);
            if (ConVar.AntiHack.eye_protection >= 1)
            {
                float num5 = player.MaxVelocity() + player.GetParentVelocity().magnitude;
                float num6 = player.BoundsPadding() + num4 * num5;
                float num7 = Vector3.Distance(player.eyes.position, eyePos);
                if (num7 > num6)
                {
                    string shortPrefabName2 = base.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, "Distance (" + shortPrefabName2 + " on attack with " + num7 + "m > " + num6 + "m)");
                    player.stats.combat.Log(this, "eye_distance");
                    flag = false;
                }
            }
            if (ConVar.AntiHack.eye_protection >= 2)
            {
                Vector3 center   = player.eyes.center;
                Vector3 position = player.eyes.position;
                if (!GamePhysics.LineOfSight(center, position, eyePos, layerMask))
                {
                    string shortPrefabName3 = base.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, string.Concat("Line of sight (", shortPrefabName3, " on attack) ", center, " ", position, " ", eyePos));
                    player.stats.combat.Log(this, "eye_los");
                    flag = false;
                }
            }
            if (!flag)
            {
                AntiHack.AddViolation(player, AntiHackType.EyeHack, ConVar.AntiHack.eye_penalty);
            }
        }
        return(flag);
    }
Example #4
0
    protected bool ValidateEyePos(BasePlayer player, Vector3 eyePos)
    {
        bool flag = true;

        if (eyePos.IsNaNOrInfinity())
        {
            string shortPrefabName = base.ShortPrefabName;
            AntiHack.Log(player, AntiHackType.EyeHack, string.Concat("Contains NaN (", shortPrefabName, ")"));
            player.stats.combat.Log(this, "eye_nan");
            flag = false;
        }
        if (ConVar.AntiHack.eye_protection > 0)
        {
            float eyeForgiveness  = 1f + ConVar.AntiHack.eye_forgiveness;
            float eyeClientframes = ConVar.AntiHack.eye_clientframes;
            float eyeServerframes = ConVar.AntiHack.eye_serverframes;
            float single          = eyeClientframes / 60f;
            float single1         = eyeServerframes * Mathx.Max(UnityEngine.Time.deltaTime, UnityEngine.Time.smoothDeltaTime, UnityEngine.Time.fixedDeltaTime);
            float single2         = (player.desyncTime + single + single1) * eyeForgiveness;
            if (ConVar.AntiHack.eye_protection >= 1)
            {
                float single3 = player.MaxVelocity() + player.GetParentVelocity().magnitude;
                float single4 = player.BoundsPadding() + single2 * single3;
                float single5 = Vector3.Distance(player.eyes.position, eyePos);
                if (single5 > single4)
                {
                    string str = base.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, string.Concat(new object[] { "Distance (", str, " on attack with ", single5, "m > ", single4, "m)" }));
                    player.stats.combat.Log(this, "eye_distance");
                    flag = false;
                }
            }
            if (ConVar.AntiHack.eye_protection >= 2)
            {
                Vector3 vector3  = player.eyes.center;
                Vector3 vector31 = player.eyes.position;
                Vector3 vector32 = eyePos;
                if (!GamePhysics.LineOfSight(vector3, vector31, vector32, 2162688, 0f))
                {
                    string shortPrefabName1 = base.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.EyeHack, string.Concat(new object[] { "Line of sight (", shortPrefabName1, " on attack) ", vector3, " ", vector31, " ", vector32 }));
                    player.stats.combat.Log(this, "eye_los");
                    flag = false;
                }
            }
            if (!flag)
            {
                AntiHack.AddViolation(player, AntiHackType.EyeHack, ConVar.AntiHack.eye_penalty);
            }
        }
        return(flag);
    }
 protected virtual bool VerifyClientAttack(BasePlayer player)
 {
     if (!this.VerifyClientRPC(player))
     {
         return(false);
     }
     if (!this.HasAttackCooldown())
     {
         return(true);
     }
     AntiHack.Log(player, AntiHackType.CooldownHack, "T-" + (object)this.GetAttackCooldown() + "s (" + this.ShortPrefabName + ")");
     player.stats.combat.Log(this, "attack_cooldown");
     return(false);
 }
Example #6
0
 protected virtual bool VerifyClientAttack(BasePlayer player)
 {
     if (!this.VerifyClientRPC(player))
     {
         return(false);
     }
     if (!this.HasAttackCooldown())
     {
         return(true);
     }
     AntiHack.Log(player, AntiHackType.CooldownHack, string.Concat(new object[] { "T-", this.GetAttackCooldown(), "s (", base.ShortPrefabName, ")" }));
     player.stats.combat.Log(this, "attack_cooldown");
     return(false);
 }
Example #7
0
    private void Reload(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientRPC(player))
        {
            SendNetworkUpdate();
            reloadStarted  = false;
            reloadFinished = false;
            return;
        }
        if (!reloadStarted)
        {
            AntiHack.Log(player, AntiHackType.ReloadHack, "Request skipped (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_skip");
            reloadStarted  = false;
            reloadFinished = false;
            return;
        }
        if (!fractionalReload)
        {
            if (GetReloadCooldown() > 1f)
            {
                AntiHack.Log(player, AntiHackType.ReloadHack, "T-" + GetReloadCooldown() + "s (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "reload_time");
                reloadStarted  = false;
                reloadFinished = false;
                return;
            }
            if (GetReloadIdle() > 1.5f)
            {
                AntiHack.Log(player, AntiHackType.ReloadHack, "T+" + GetReloadIdle() + "s (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "reload_time");
                reloadStarted  = false;
                reloadFinished = false;
                return;
            }
        }
        if (fractionalReload)
        {
            ResetReloadCooldown();
        }
        reloadStarted  = false;
        reloadFinished = true;
        if (!fractionalReload)
        {
            ReloadMagazine();
        }
    }
    protected bool VerifyClientRPC(BasePlayer player)
    {
        if (Object.op_Equality((Object)player, (Object)null))
        {
            Debug.LogWarning((object)"Received RPC from null player");
            return(false);
        }
        BasePlayer ownerPlayer = this.GetOwnerPlayer();

        if (Object.op_Equality((Object)ownerPlayer, (Object)null))
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Owner not found (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "owner_missing");
            return(false);
        }
        if (Object.op_Inequality((Object)ownerPlayer, (Object)player))
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player mismatch (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_mismatch");
            return(false);
        }
        if (player.IsDead())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player dead (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_dead");
            return(false);
        }
        if (player.IsWounded())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player down (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_down");
            return(false);
        }
        if (player.IsSleeping())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player sleeping (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_sleeping");
            return(false);
        }
        if ((double)player.desyncTime > (double)ConVar.AntiHack.maxdesync)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player stalled (" + this.ShortPrefabName + " with " + (object)player.desyncTime + "s)");
            player.stats.combat.Log(this, "player_stalled");
            return(false);
        }
        Item ownerItem = this.GetOwnerItem();

        if (ownerItem == null)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Item not found (" + this.ShortPrefabName + ")");
            player.stats.combat.Log(this, "item_missing");
            return(false);
        }
        if (!ownerItem.isBroken)
        {
            return(true);
        }
        AntiHack.Log(player, AntiHackType.AttackHack, "Item broken (" + this.ShortPrefabName + ")");
        player.stats.combat.Log(this, "item_broken");
        return(false);
    }
    private void CLProject(BaseEntity.RPCMessage msg)
    {
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        if (basePlayer == null)
        {
            return;
        }
        if (basePlayer.IsHeadUnderwater())
        {
            return;
        }
        if (!this.canThrowAsProjectile)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Not throwable (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "not_throwable");
            return;
        }
        Item item = this.GetItem();

        if (item == null)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item not found (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "item_missing");
            return;
        }
        ItemModProjectile component = item.info.GetComponent <ItemModProjectile>();

        if (component == null)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item mod not found (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "mod_missing");
            return;
        }
        ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read);

        if (projectileShoot.projectiles.Count != 1)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Projectile count mismatch (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "count_mismatch");
            return;
        }
        basePlayer.CleanupExpiredProjectiles();
        foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles)
        {
            if (!basePlayer.HasFiredProjectile(projectile.projectileID))
            {
                if (!base.ValidateEyePos(basePlayer, projectile.startPos))
                {
                    continue;
                }
                basePlayer.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, item.info, item);
                Effect effect = new Effect();
                effect.Init(Effect.Type.Projectile, projectile.startPos, projectile.startVel, msg.connection);
                effect.scale        = 1f;
                effect.pooledString = component.projectileObject.resourcePath;
                effect.number       = projectile.seed;
                EffectNetwork.Send(effect);
            }
            else
            {
                AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Duplicate ID (", projectile.projectileID, ")"));
                basePlayer.stats.combat.Log(this, "duplicate_id");
            }
        }
        item.SetParent(null);
        Interface.CallHook("OnMeleeThrown", basePlayer, item);
        if (this.canAiHearIt)
        {
            float single = 0f;
            if (component.projectileObject != null)
            {
                GameObject gameObject = component.projectileObject.Get();
                if (gameObject != null)
                {
                    Projectile component1 = gameObject.GetComponent <Projectile>();
                    if (component1 != null)
                    {
                        foreach (DamageTypeEntry damageType in component1.damageTypes)
                        {
                            single += damageType.amount;
                        }
                    }
                }
            }
            if (basePlayer != null)
            {
                Sensation sensation = new Sensation()
                {
                    Type            = SensationType.ThrownWeapon,
                    Position        = basePlayer.transform.position,
                    Radius          = 50f,
                    DamagePotential = single,
                    InitiatorPlayer = basePlayer,
                    Initiator       = basePlayer
                };
                Sense.Stimulate(sensation);
            }
        }
    }
    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");
                    }
                }
            }
        }
    }
    private void SV_Launch(BaseEntity.RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!this.VerifyClientAttack(player))
        {
            this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
        }
        else if (this.reloadFinished && this.HasReloadCooldown())
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Reloading (" + this.ShortPrefabName + ")");
            player.stats.combat.Log((AttackEntity)this, "reload_cooldown");
        }
        else
        {
            this.reloadStarted  = false;
            this.reloadFinished = false;
            if (this.primaryMagazine.contents <= 0)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + this.ShortPrefabName + ")");
                player.stats.combat.Log((AttackEntity)this, "magazine_empty");
            }
            else
            {
                --this.primaryMagazine.contents;
                this.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, player.net.get_connection());
                Vector3    eyePos     = msg.read.Vector3();
                Vector3    vector3    = msg.read.Vector3();
                Vector3    inputVec   = ((Vector3) ref vector3).get_normalized();
                int        num1       = msg.read.Bit() ? 1 : 0;
                BaseEntity baseEntity = player.GetParentEntity();
                if (Object.op_Equality((Object)baseEntity, (Object)null))
                {
                    baseEntity = (BaseEntity)player.GetMounted();
                }
                if (num1 != 0)
                {
                    if (Object.op_Inequality((Object)baseEntity, (Object)null))
                    {
                        eyePos   = ((Component)baseEntity).get_transform().TransformPoint(eyePos);
                        inputVec = ((Component)baseEntity).get_transform().TransformDirection(inputVec);
                    }
                    else
                    {
                        eyePos   = player.eyes.position;
                        inputVec = player.eyes.BodyForward();
                    }
                }
                if (!this.ValidateEyePos(player, eyePos))
                {
                    return;
                }
                ItemModProjectile component1 = (ItemModProjectile)((Component)this.primaryMagazine.ammoType).GetComponent <ItemModProjectile>();
                if (!Object.op_Implicit((Object)component1))
                {
                    AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + this.ShortPrefabName + ")");
                    player.stats.combat.Log((AttackEntity)this, "mod_missing");
                }
                else
                {
                    float aimCone = this.GetAimCone() + component1.projectileSpread;
                    if ((double)aimCone > 0.0)
                    {
                        inputVec = AimConeUtil.GetModifiedAimConeDirection(aimCone, inputVec, true);
                    }
                    float      num2 = 1f;
                    RaycastHit raycastHit;
                    if (Physics.Raycast(eyePos, inputVec, ref raycastHit, num2, 1236478737))
                    {
                        num2 = ((RaycastHit) ref raycastHit).get_distance() - 0.1f;
                    }
                    BaseEntity entity = GameManager.server.CreateEntity(component1.projectileObject.resourcePath, Vector3.op_Addition(eyePos, Vector3.op_Multiply(inputVec, num2)), (Quaternion)null, true);
                    if (Object.op_Equality((Object)entity, (Object)null))
                    {
                        return;
                    }
                    entity.creatorEntity = (BaseEntity)player;
                    ServerProjectile component2 = (ServerProjectile)((Component)entity).GetComponent <ServerProjectile>();
                    if (Object.op_Implicit((Object)component2))
                    {
                        component2.InitializeVelocity(Vector3.op_Addition(player.GetInheritedProjectileVelocity(), Vector3.op_Multiply(inputVec, component2.speed)));
                    }
                    entity.Spawn();
                    this.StartAttackCooldown(this.ScaleRepeatDelay(this.repeatDelay));
                    Interface.CallHook("OnRocketLaunched", (object)player, (object)entity);
                    this.GetOwnerItem()?.LoseCondition(Random.Range(1f, 2f));
                }
            }
        }
    }
Example #12
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);
                    }
                }
            }
        }
    }
Example #13
0
    public void PlayerAttack(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientAttack(player))
        {
            SendNetworkUpdate();
            return;
        }
        using (TimeWarning.New("PlayerAttack", 50))
        {
            using (PlayerAttack playerAttack = ProtoBuf.PlayerAttack.Deserialize(msg.read))
            {
                if (playerAttack == null)
                {
                    return;
                }
                HitInfo hitInfo = Facepunch.Pool.Get <HitInfo>();
                hitInfo.LoadFromAttack(playerAttack.attack, true);
                hitInfo.Initiator        = player;
                hitInfo.Weapon           = this;
                hitInfo.WeaponPrefab     = this;
                hitInfo.Predicted        = msg.connection;
                hitInfo.damageProperties = damageProperties;
                if (Interface.CallHook("OnMeleeAttack", player, hitInfo) != null)
                {
                    return;
                }
                if (hitInfo.IsNaNOrInfinity())
                {
                    string shortPrefabName = base.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.MeleeHack, "Contains NaN (" + shortPrefabName + ")");
                    player.stats.combat.Log(hitInfo, "melee_nan");
                    return;
                }
                BaseEntity hitEntity  = hitInfo.HitEntity;
                BasePlayer basePlayer = hitInfo.HitEntity as BasePlayer;
                bool       flag       = basePlayer != null;
                bool       flag2      = flag && basePlayer.IsSleeping();
                bool       flag3      = flag && basePlayer.IsWounded();
                bool       flag4      = flag && basePlayer.isMounted;
                bool       flag5      = flag && basePlayer.HasParent();
                bool       flag6      = hitEntity != null;
                bool       flag7      = flag6 && hitEntity.IsNpc;
                if (ConVar.AntiHack.melee_protection <= 0)
                {
                    goto IL_0903;
                }
                bool  flag8 = true;
                float num   = 1f + ConVar.AntiHack.melee_forgiveness;
                float melee_clientframes = ConVar.AntiHack.melee_clientframes;
                float melee_serverframes = ConVar.AntiHack.melee_serverframes;
                float num2      = melee_clientframes / 60f;
                float num3      = melee_serverframes * Mathx.Max(UnityEngine.Time.deltaTime, UnityEngine.Time.smoothDeltaTime, UnityEngine.Time.fixedDeltaTime);
                float num4      = (player.desyncTimeClamped + num2 + num3) * num;
                int   layerMask = (ConVar.AntiHack.melee_terraincheck ? 10551296 : 2162688);
                if (flag && hitInfo.boneArea == (HitArea)(-1))
                {
                    string shortPrefabName2 = base.ShortPrefabName;
                    string shortPrefabName3 = basePlayer.ShortPrefabName;
                    AntiHack.Log(player, AntiHackType.MeleeHack, "Bone is invalid  (" + shortPrefabName2 + " on " + shortPrefabName3 + " bone " + hitInfo.HitBone + ")");
                    player.stats.combat.Log(hitInfo, "melee_bone");
                    flag8 = false;
                }
                if (ConVar.AntiHack.melee_protection >= 2)
                {
                    if (flag6)
                    {
                        float num5 = hitEntity.MaxVelocity() + hitEntity.GetParentVelocity().magnitude;
                        float num6 = hitEntity.BoundsPadding() + num4 * num5;
                        float num7 = hitEntity.Distance(hitInfo.HitPositionWorld);
                        if (num7 > num6)
                        {
                            string shortPrefabName4 = base.ShortPrefabName;
                            string shortPrefabName5 = hitEntity.ShortPrefabName;
                            AntiHack.Log(player, AntiHackType.MeleeHack, "Entity too far away (" + shortPrefabName4 + " on " + shortPrefabName5 + " with " + num7 + "m > " + num6 + "m in " + num4 + "s)");
                            player.stats.combat.Log(hitInfo, "melee_target");
                            flag8 = false;
                        }
                    }
                    if (ConVar.AntiHack.melee_protection >= 4 && flag8 && flag && !flag7 && !flag2 && !flag3 && !flag4 && !flag5)
                    {
                        float magnitude = basePlayer.GetParentVelocity().magnitude;
                        float num8      = basePlayer.BoundsPadding() + num4 * magnitude + ConVar.AntiHack.tickhistoryforgiveness;
                        float num9      = basePlayer.tickHistory.Distance(basePlayer, hitInfo.HitPositionWorld);
                        if (num9 > num8)
                        {
                            string shortPrefabName6 = base.ShortPrefabName;
                            string shortPrefabName7 = basePlayer.ShortPrefabName;
                            AntiHack.Log(player, AntiHackType.ProjectileHack, "Player too far away (" + shortPrefabName6 + " on " + shortPrefabName7 + " with " + num9 + "m > " + num8 + "m in " + num4 + "s)");
                            player.stats.combat.Log(hitInfo, "player_distance");
                            flag8 = false;
                        }
                    }
                }
                if (ConVar.AntiHack.melee_protection >= 1)
                {
                    if (ConVar.AntiHack.melee_protection >= 4)
                    {
                        float magnitude2 = player.GetParentVelocity().magnitude;
                        float num10      = player.BoundsPadding() + num4 * magnitude2 + num * maxDistance;
                        float num11      = player.tickHistory.Distance(player, hitInfo.HitPositionWorld);
                        if (num11 > num10)
                        {
                            string shortPrefabName8 = base.ShortPrefabName;
                            string text             = (flag6 ? hitEntity.ShortPrefabName : "world");
                            AntiHack.Log(player, AntiHackType.MeleeHack, "Initiator too far away (" + shortPrefabName8 + " on " + text + " with " + num11 + "m > " + num10 + "m in " + num4 + "s)");
                            player.stats.combat.Log(hitInfo, "melee_initiator");
                            flag8 = false;
                        }
                    }
                    else
                    {
                        float num12 = player.MaxVelocity() + player.GetParentVelocity().magnitude;
                        float num13 = player.BoundsPadding() + num4 * num12 + num * maxDistance;
                        float num14 = player.Distance(hitInfo.HitPositionWorld);
                        if (num14 > num13)
                        {
                            string shortPrefabName9 = base.ShortPrefabName;
                            string text2            = (flag6 ? hitEntity.ShortPrefabName : "world");
                            AntiHack.Log(player, AntiHackType.MeleeHack, "Initiator too far away (" + shortPrefabName9 + " on " + text2 + " with " + num14 + "m > " + num13 + "m in " + num4 + "s)");
                            player.stats.combat.Log(hitInfo, "melee_initiator");
                            flag8 = false;
                        }
                    }
                }
                if (ConVar.AntiHack.melee_protection >= 3)
                {
                    if (flag6)
                    {
                        Vector3 pointStart = hitInfo.PointStart;
                        Vector3 vector     = hitInfo.HitPositionWorld + hitInfo.HitNormalWorld.normalized * 0.001f;
                        Vector3 center     = player.eyes.center;
                        Vector3 position   = player.eyes.position;
                        Vector3 vector2    = pointStart;
                        Vector3 vector3    = hitInfo.PositionOnRay(vector);
                        Vector3 vector4    = vector;
                        bool    num15      = GamePhysics.LineOfSight(center, position, vector2, vector3, vector4, layerMask);
                        if (!num15)
                        {
                            player.stats.Add("hit_" + hitEntity.Categorize() + "_indirect_los", 1, Stats.Server);
                        }
                        else
                        {
                            player.stats.Add("hit_" + hitEntity.Categorize() + "_direct_los", 1, Stats.Server);
                        }
                        if (!num15)
                        {
                            string shortPrefabName10 = base.ShortPrefabName;
                            string shortPrefabName11 = hitEntity.ShortPrefabName;
                            AntiHack.Log(player, AntiHackType.MeleeHack, string.Concat("Line of sight (", shortPrefabName10, " on ", shortPrefabName11, ") ", center, " ", position, " ", vector2, " ", vector3, " ", vector4));
                            player.stats.combat.Log(hitInfo, "melee_los");
                            flag8 = false;
                        }
                    }
                    if (flag8 && flag && !flag7)
                    {
                        Vector3 vector5   = hitInfo.HitPositionWorld + hitInfo.HitNormalWorld.normalized * 0.001f;
                        Vector3 position2 = basePlayer.eyes.position;
                        Vector3 vector6   = basePlayer.CenterPoint();
                        if ((!GamePhysics.LineOfSight(vector5, position2, layerMask, 0f, ConVar.AntiHack.losforgiveness) || !GamePhysics.LineOfSight(position2, vector5, layerMask, ConVar.AntiHack.losforgiveness, 0f)) && (!GamePhysics.LineOfSight(vector5, vector6, layerMask, 0f, ConVar.AntiHack.losforgiveness) || !GamePhysics.LineOfSight(vector6, vector5, layerMask, ConVar.AntiHack.losforgiveness, 0f)))
                        {
                            string shortPrefabName12 = base.ShortPrefabName;
                            string shortPrefabName13 = basePlayer.ShortPrefabName;
                            AntiHack.Log(player, AntiHackType.MeleeHack, string.Concat("Line of sight (", shortPrefabName12, " on ", shortPrefabName13, ") ", vector5, " ", position2, " or ", vector5, " ", vector6));
                            player.stats.combat.Log(hitInfo, "melee_los");
                            flag8 = false;
                        }
                    }
                }
                if (flag8)
                {
                    goto IL_0903;
                }
                AntiHack.AddViolation(player, AntiHackType.MeleeHack, ConVar.AntiHack.melee_penalty);
                goto end_IL_0031;
IL_0903:
                player.metabolism.UseHeart(heartStress * 0.2f);
                using (TimeWarning.New("DoAttackShared", 50))
                {
                    DoAttackShared(hitInfo);
                }
                end_IL_0031 :;
            }
        }
    }
Example #14
0
    private void CLProject(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientAttack(player))
        {
            SendNetworkUpdate();
        }
        else
        {
            if (player == null || player.IsHeadUnderwater())
            {
                return;
            }
            if (!canThrowAsProjectile)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Not throwable (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "not_throwable");
                return;
            }
            Item item = GetItem();
            if (item == null)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Item not found (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "item_missing");
                return;
            }
            ItemModProjectile component = item.info.GetComponent <ItemModProjectile>();
            if (component == null)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "mod_missing");
                return;
            }
            ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read);
            if (projectileShoot.projectiles.Count != 1)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Projectile count mismatch (" + base.ShortPrefabName + ")");
                player.stats.combat.Log(this, "count_mismatch");
                return;
            }
            player.CleanupExpiredProjectiles();
            foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles)
            {
                if (player.HasFiredProjectile(projectile.projectileID))
                {
                    AntiHack.Log(player, AntiHackType.ProjectileHack, "Duplicate ID (" + projectile.projectileID + ")");
                    player.stats.combat.Log(this, "duplicate_id");
                }
                else if (ValidateEyePos(player, projectile.startPos))
                {
                    player.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, item.info, item);
                    Effect effect = new Effect();
                    effect.Init(Effect.Type.Projectile, projectile.startPos, projectile.startVel, msg.connection);
                    effect.scale        = 1f;
                    effect.pooledString = component.projectileObject.resourcePath;
                    effect.number       = projectile.seed;
                    EffectNetwork.Send(effect);
                }
            }
            projectileShoot?.Dispose();
            item.SetParent(null);
            Interface.CallHook("OnMeleeThrown", player, item);
            if (!canAiHearIt)
            {
                return;
            }
            float num = 0f;
            if (component.projectileObject != null)
            {
                GameObject gameObject = component.projectileObject.Get();
                if (gameObject != null)
                {
                    Projectile component2 = gameObject.GetComponent <Projectile>();
                    if (component2 != null)
                    {
                        foreach (DamageTypeEntry damageType in component2.damageTypes)
                        {
                            num += damageType.amount;
                        }
                    }
                }
            }
            if (player != null)
            {
                Sensation sensation = default(Sensation);
                sensation.Type            = SensationType.ThrownWeapon;
                sensation.Position        = player.transform.position;
                sensation.Radius          = 50f;
                sensation.DamagePotential = num;
                sensation.InitiatorPlayer = player;
                sensation.Initiator       = player;
                Sense.Stimulate(sensation);
            }
        }
    }
Example #15
0
    private void CLProject(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientAttack(player))
        {
            SendNetworkUpdate();
            return;
        }
        if (reloadFinished && HasReloadCooldown())
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Reloading (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_cooldown");
            return;
        }
        reloadStarted  = false;
        reloadFinished = false;
        if (primaryMagazine.contents <= 0 && !UsingInfiniteAmmoCheat)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "ammo_missing");
            return;
        }
        ItemDefinition  primaryMagazineAmmo = PrimaryMagazineAmmo;
        ProjectileShoot projectileShoot     = ProjectileShoot.Deserialize(msg.read);

        if (primaryMagazineAmmo.itemid != projectileShoot.ammoType)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Ammo mismatch (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "ammo_mismatch");
            return;
        }
        if (!UsingInfiniteAmmoCheat)
        {
            primaryMagazine.contents--;
        }
        ItemModProjectile component = primaryMagazineAmmo.GetComponent <ItemModProjectile>();

        if (component == null)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "mod_missing");
            return;
        }
        if (projectileShoot.projectiles.Count > component.numProjectiles)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Count mismatch (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "count_mismatch");
            return;
        }
        Interface.CallHook("OnWeaponFired", this, msg.player, component, projectileShoot);
        if (player.InGesture)
        {
            return;
        }
        SignalBroadcast(Signal.Attack, string.Empty, msg.connection);
        player.CleanupExpiredProjectiles();
        foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles)
        {
            if (player.HasFiredProjectile(projectile.projectileID))
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Duplicate ID (" + projectile.projectileID + ")");
                player.stats.combat.Log(this, "duplicate_id");
            }
            else if (ValidateEyePos(player, projectile.startPos))
            {
                player.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, primaryMagazineAmmo);
                if (!player.limitNetworking)
                {
                    CreateProjectileEffectClientside(component.projectileObject.resourcePath, projectile.startPos, projectile.startVel, projectile.seed, msg.connection, IsSilenced());
                }
            }
        }
        player.MakeNoise(player.transform.position, BaseCombatEntity.ActionVolume.Loud);
        player.stats.Add(component.category + "_fired", projectileShoot.projectiles.Count(), (Stats)5);
        player.LifeStoryShotFired(this);
        StartAttackCooldown(ScaleRepeatDelay(repeatDelay) + animationDelay);
        player.MarkHostileFor();
        UpdateItemCondition();
        DidAttackServerside();
        float num = 0f;

        if (component.projectileObject != null)
        {
            GameObject gameObject = component.projectileObject.Get();
            if (gameObject != null)
            {
                Projectile component2 = gameObject.GetComponent <Projectile>();
                if (component2 != null)
                {
                    foreach (DamageTypeEntry damageType in component2.damageTypes)
                    {
                        num += damageType.amount;
                    }
                }
            }
        }
        float num2 = NoiseRadius;

        if (IsSilenced())
        {
            num2 *= AI.npc_gun_noise_silencer_modifier;
        }
        Sensation sensation = default(Sensation);

        sensation.Type            = SensationType.Gunshot;
        sensation.Position        = player.transform.position;
        sensation.Radius          = num2;
        sensation.DamagePotential = num;
        sensation.InitiatorPlayer = player;
        sensation.Initiator       = player;
        Sense.Stimulate(sensation);
        if (EACServer.playerTracker != null)
        {
            using (TimeWarning.New("LogPlayerShooting"))
            {
                UnityEngine.Vector3    networkPosition = player.GetNetworkPosition();
                UnityEngine.Quaternion networkRotation = player.GetNetworkRotation();
                int weaponID = GetItem()?.info.itemid ?? 0;
                EasyAntiCheat.Server.Hydra.Client client = EACServer.GetClient(player.net.connection);
                PlayerUseWeapon eventParams = default(PlayerUseWeapon);
                eventParams.Position     = new EasyAntiCheat.Server.Cerberus.Vector3(networkPosition.x, networkPosition.y, networkPosition.z);
                eventParams.ViewRotation = new EasyAntiCheat.Server.Cerberus.Quaternion(networkRotation.w, networkRotation.x, networkRotation.y, networkRotation.z);
                eventParams.WeaponID     = weaponID;
                EACServer.playerTracker.LogPlayerUseWeapon(client, eventParams);
            }
        }
    }
Example #16
0
    private void SV_Launch(RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!VerifyClientAttack(player))
        {
            SendNetworkUpdate();
            return;
        }
        if (reloadFinished && HasReloadCooldown())
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Reloading (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "reload_cooldown");
            return;
        }
        reloadStarted  = false;
        reloadFinished = false;
        if (primaryMagazine.contents <= 0)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Magazine empty (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "magazine_empty");
            return;
        }
        primaryMagazine.contents--;
        SignalBroadcast(Signal.Attack, string.Empty, player.net.connection);
        Vector3    vector  = msg.read.Vector3();
        Vector3    vector2 = msg.read.Vector3().normalized;
        bool       num     = msg.read.Bit();
        BaseEntity mounted = player.GetParentEntity();

        if (mounted == null)
        {
            mounted = player.GetMounted();
        }
        if (num)
        {
            if (mounted != null)
            {
                vector  = mounted.transform.TransformPoint(vector);
                vector2 = mounted.transform.TransformDirection(vector2);
            }
            else
            {
                vector  = player.eyes.position;
                vector2 = player.eyes.BodyForward();
            }
        }
        if (!ValidateEyePos(player, vector))
        {
            return;
        }
        ItemModProjectile component = primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        if (!component)
        {
            AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "mod_missing");
            return;
        }
        float num2 = GetAimCone() + component.projectileSpread;

        if (num2 > 0f)
        {
            vector2 = AimConeUtil.GetModifiedAimConeDirection(num2, vector2);
        }
        float      num3 = 1f;
        RaycastHit hitInfo;

        if (UnityEngine.Physics.Raycast(vector, vector2, out hitInfo, num3, 1236478737))
        {
            num3 = hitInfo.distance - 0.1f;
        }
        BaseEntity baseEntity = GameManager.server.CreateEntity(component.projectileObject.resourcePath, vector + vector2 * num3);

        if (!(baseEntity == null))
        {
            baseEntity.creatorEntity = player;
            ServerProjectile component2 = baseEntity.GetComponent <ServerProjectile>();
            if ((bool)component2)
            {
                component2.InitializeVelocity(GetInheritedVelocity(player) + vector2 * component2.speed);
            }
            baseEntity.Spawn();
            StartAttackCooldown(ScaleRepeatDelay(repeatDelay));
            Interface.CallHook("OnRocketLaunched", player, baseEntity);
            GetOwnerItem()?.LoseCondition(UnityEngine.Random.Range(1f, 2f));
        }
    }
Example #17
0
    private void SV_Launch(BaseEntity.RPCMessage msg)
    {
        RaycastHit raycastHit;
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        if (this.reloadFinished && base.HasReloadCooldown())
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Reloading (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "reload_cooldown");
            return;
        }
        this.reloadStarted  = false;
        this.reloadFinished = false;
        if (this.primaryMagazine.contents <= 0)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Magazine empty (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "magazine_empty");
            return;
        }
        this.primaryMagazine.contents--;
        base.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, basePlayer.net.connection);
        Vector3    vector3 = msg.read.Vector3();
        Vector3    modifiedAimConeDirection = msg.read.Vector3().normalized;
        bool       flag         = msg.read.Bit();
        BaseEntity parentEntity = basePlayer.GetParentEntity();

        if (parentEntity == null)
        {
            parentEntity = basePlayer.GetMounted();
        }
        if (flag)
        {
            if (parentEntity == null)
            {
                vector3 = basePlayer.eyes.position;
                modifiedAimConeDirection = basePlayer.eyes.BodyForward();
            }
            else
            {
                vector3 = parentEntity.transform.TransformPoint(vector3);
                modifiedAimConeDirection = parentEntity.transform.TransformDirection(modifiedAimConeDirection);
            }
        }
        if (!base.ValidateEyePos(basePlayer, vector3))
        {
            return;
        }
        ItemModProjectile component = this.primaryMagazine.ammoType.GetComponent <ItemModProjectile>();

        if (!component)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item mod not found (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "mod_missing");
            return;
        }
        float aimCone = this.GetAimCone() + component.projectileSpread;

        if (aimCone > 0f)
        {
            modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(aimCone, modifiedAimConeDirection, true);
        }
        float single = 1f;

        if (UnityEngine.Physics.Raycast(vector3, modifiedAimConeDirection, out raycastHit, single, 1236478737))
        {
            single = raycastHit.distance - 0.1f;
        }
        GameManager gameManager = GameManager.server;
        string      str         = component.projectileObject.resourcePath;
        Vector3     vector31    = vector3 + (modifiedAimConeDirection * single);
        Quaternion  quaternion  = new Quaternion();
        BaseEntity  baseEntity  = gameManager.CreateEntity(str, vector31, quaternion, true);

        if (baseEntity == null)
        {
            return;
        }
        baseEntity.creatorEntity = basePlayer;
        ServerProjectile serverProjectile = baseEntity.GetComponent <ServerProjectile>();

        if (serverProjectile)
        {
            serverProjectile.InitializeVelocity(basePlayer.GetInheritedProjectileVelocity() + (modifiedAimConeDirection * serverProjectile.speed));
        }
        baseEntity.Spawn();
        base.StartAttackCooldown(base.ScaleRepeatDelay(this.repeatDelay));
        Interface.CallHook("OnRocketLaunched", basePlayer, baseEntity);
        Item ownerItem = base.GetOwnerItem();

        if (ownerItem == null)
        {
            return;
        }
        ownerItem.LoseCondition(UnityEngine.Random.Range(1f, 2f));
    }
Example #18
0
    private void CLProject(BaseEntity.RPCMessage msg)
    {
        BasePlayer player = msg.player;

        if (!this.VerifyClientAttack(player))
        {
            this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
        }
        else
        {
            if (Object.op_Equality((Object)player, (Object)null) || player.IsHeadUnderwater())
            {
                return;
            }
            if (!this.canThrowAsProjectile)
            {
                AntiHack.Log(player, AntiHackType.ProjectileHack, "Not throwable (" + this.ShortPrefabName + ")");
                player.stats.combat.Log((AttackEntity)this, "not_throwable");
            }
            else
            {
                Item pickupItem = this.GetItem();
                if (pickupItem == null)
                {
                    AntiHack.Log(player, AntiHackType.ProjectileHack, "Item not found (" + this.ShortPrefabName + ")");
                    player.stats.combat.Log((AttackEntity)this, "item_missing");
                }
                else
                {
                    ItemModProjectile component1 = (ItemModProjectile)((Component)pickupItem.info).GetComponent <ItemModProjectile>();
                    if (Object.op_Equality((Object)component1, (Object)null))
                    {
                        AntiHack.Log(player, AntiHackType.ProjectileHack, "Item mod not found (" + this.ShortPrefabName + ")");
                        player.stats.combat.Log((AttackEntity)this, "mod_missing");
                    }
                    else
                    {
                        ProjectileShoot projectileShoot = ProjectileShoot.Deserialize((Stream)msg.read);
                        if (((List <ProjectileShoot.Projectile>)projectileShoot.projectiles).Count != 1)
                        {
                            AntiHack.Log(player, AntiHackType.ProjectileHack, "Projectile count mismatch (" + this.ShortPrefabName + ")");
                            player.stats.combat.Log((AttackEntity)this, "count_mismatch");
                        }
                        else
                        {
                            player.CleanupExpiredProjectiles();
                            using (List <ProjectileShoot.Projectile> .Enumerator enumerator = ((List <ProjectileShoot.Projectile>)projectileShoot.projectiles).GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    ProjectileShoot.Projectile current = enumerator.Current;
                                    if (player.HasFiredProjectile((int)current.projectileID))
                                    {
                                        AntiHack.Log(player, AntiHackType.ProjectileHack, "Duplicate ID (" + (object)(int)current.projectileID + ")");
                                        player.stats.combat.Log((AttackEntity)this, "duplicate_id");
                                    }
                                    else if (this.ValidateEyePos(player, (Vector3)current.startPos))
                                    {
                                        player.NoteFiredProjectile((int)current.projectileID, (Vector3)current.startPos, (Vector3)current.startVel, (AttackEntity)this, pickupItem.info, pickupItem);
                                        Effect effect = new Effect();
                                        effect.Init(Effect.Type.Projectile, (Vector3)current.startPos, (Vector3)current.startVel, msg.connection);
                                        effect.scale        = (__Null)1.0;
                                        effect.pooledString = component1.projectileObject.resourcePath;
                                        effect.number       = current.seed;
                                        EffectNetwork.Send(effect);
                                    }
                                }
                            }
                            pickupItem.SetParent((ItemContainer)null);
                            Interface.CallHook("OnMeleeThrown", (object)player, (object)pickupItem);
                            if (!this.canAiHearIt)
                            {
                                return;
                            }
                            float num = 0.0f;
                            if (component1.projectileObject != null)
                            {
                                GameObject gameObject = component1.projectileObject.Get();
                                if (Object.op_Inequality((Object)gameObject, (Object)null))
                                {
                                    Projectile component2 = (Projectile)gameObject.GetComponent <Projectile>();
                                    if (Object.op_Inequality((Object)component2, (Object)null))
                                    {
                                        foreach (DamageTypeEntry damageType in component2.damageTypes)
                                        {
                                            num += damageType.amount;
                                        }
                                    }
                                }
                            }
                            if (!Object.op_Inequality((Object)player, (Object)null))
                            {
                                return;
                            }
                            Sense.Stimulate(new Sensation()
                            {
                                Type            = SensationType.ThrownWeapon,
                                Position        = ((Component)player).get_transform().get_position(),
                                Radius          = 50f,
                                DamagePotential = num,
                                InitiatorPlayer = player,
                                Initiator       = (BaseEntity)player
                            });
                        }
                    }
                }
            }
        }
    }
Example #19
0
    private void CLProject(BaseEntity.RPCMessage msg)
    {
        BasePlayer basePlayer = msg.player;

        if (!this.VerifyClientAttack(basePlayer))
        {
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            return;
        }
        if (this.reloadFinished && this.HasReloadCooldown())
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Reloading (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "reload_cooldown");
            return;
        }
        this.reloadStarted  = false;
        this.reloadFinished = false;
        if (this.primaryMagazine.contents <= 0 && !this.UsingInfiniteAmmoCheat)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Magazine empty (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "ammo_missing");
            return;
        }
        ItemDefinition  itemDefinition  = this.primaryMagazine.ammoType;
        ProjectileShoot projectileShoot = ProjectileShoot.Deserialize(msg.read);

        if (itemDefinition.itemid != projectileShoot.ammoType)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Ammo mismatch (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "ammo_mismatch");
            return;
        }
        if (!this.UsingInfiniteAmmoCheat)
        {
            this.primaryMagazine.contents--;
        }
        ItemModProjectile component = itemDefinition.GetComponent <ItemModProjectile>();

        if (component == null)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Item mod not found (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "mod_missing");
            return;
        }
        if (projectileShoot.projectiles.Count > component.numProjectiles)
        {
            AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Count mismatch (", base.ShortPrefabName, ")"));
            basePlayer.stats.combat.Log(this, "count_mismatch");
            return;
        }
        Interface.CallHook("OnWeaponFired", this, msg.player, component, projectileShoot);
        base.SignalBroadcast(BaseEntity.Signal.Attack, string.Empty, msg.connection);
        basePlayer.CleanupExpiredProjectiles();
        foreach (ProjectileShoot.Projectile projectile in projectileShoot.projectiles)
        {
            if (!basePlayer.HasFiredProjectile(projectile.projectileID))
            {
                if (!base.ValidateEyePos(basePlayer, projectile.startPos))
                {
                    continue;
                }
                basePlayer.NoteFiredProjectile(projectile.projectileID, projectile.startPos, projectile.startVel, this, itemDefinition, null);
                this.CreateProjectileEffectClientside(component.projectileObject.resourcePath, projectile.startPos, projectile.startVel, projectile.seed, msg.connection, this.IsSilenced(), false);
            }
            else
            {
                AntiHack.Log(basePlayer, AntiHackType.ProjectileHack, string.Concat("Duplicate ID (", projectile.projectileID, ")"));
                basePlayer.stats.combat.Log(this, "duplicate_id");
            }
        }
        basePlayer.stats.Add(string.Concat(component.category, "_fired"), projectileShoot.projectiles.Count <ProjectileShoot.Projectile>(), Stats.Steam);
        base.StartAttackCooldown(this.ScaleRepeatDelay(this.repeatDelay) + this.animationDelay);
        basePlayer.MarkHostileFor(60f);
        this.UpdateItemCondition();
        this.DidAttackServerside();
        float single = 0f;

        if (component.projectileObject != null)
        {
            GameObject gameObject = component.projectileObject.Get();
            if (gameObject != null)
            {
                Projectile component1 = gameObject.GetComponent <Projectile>();
                if (component1 != null)
                {
                    foreach (DamageTypeEntry damageType in component1.damageTypes)
                    {
                        single += damageType.amount;
                    }
                }
            }
        }
        float noiseRadius = this.NoiseRadius;

        if (this.IsSilenced())
        {
            noiseRadius *= AI.npc_gun_noise_silencer_modifier;
        }
        Sensation sensation = new Sensation()
        {
            Type            = SensationType.Gunshot,
            Position        = basePlayer.transform.position,
            Radius          = noiseRadius,
            DamagePotential = single,
            InitiatorPlayer = basePlayer,
            Initiator       = basePlayer
        };

        Sense.Stimulate(sensation);
        if (EACServer.playerTracker != null)
        {
            using (TimeWarning timeWarning = TimeWarning.New("LogPlayerShooting", 0.1f))
            {
                UnityEngine.Vector3    networkPosition = basePlayer.GetNetworkPosition();
                UnityEngine.Quaternion networkRotation = basePlayer.GetNetworkRotation();
                Item item = this.GetItem();
                int  num  = (item != null ? item.info.itemid : 0);
                EasyAntiCheat.Server.Hydra.Client client = EACServer.GetClient(basePlayer.net.connection);
                PlayerUseWeapon playerUseWeapon          = new PlayerUseWeapon()
                {
                    Position     = new EasyAntiCheat.Server.Cerberus.Vector3(networkPosition.x, networkPosition.y, networkPosition.z),
                    ViewRotation = new EasyAntiCheat.Server.Cerberus.Quaternion(networkRotation.x, networkRotation.y, networkRotation.z, networkRotation.w),
                    WeaponID     = num
                };
                EACServer.playerTracker.LogPlayerUseWeapon(client, playerUseWeapon);
            }
        }
    }
Example #20
0
    protected bool VerifyClientRPC(BasePlayer player)
    {
        if (player == null)
        {
            Debug.LogWarning("Received RPC from null player");
            return(false);
        }
        BasePlayer ownerPlayer = GetOwnerPlayer();

        if (ownerPlayer == null)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Owner not found (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "owner_missing");
            return(false);
        }
        if (ownerPlayer != player)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player mismatch (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_mismatch");
            return(false);
        }
        if (player.IsDead())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player dead (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_dead");
            return(false);
        }
        if (player.IsWounded())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player down (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_down");
            return(false);
        }
        if (player.IsSleeping())
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player sleeping (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "player_sleeping");
            return(false);
        }
        if (player.desyncTimeRaw > ConVar.AntiHack.maxdesync)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Player stalled (" + base.ShortPrefabName + " with " + player.desyncTimeRaw + "s)");
            player.stats.combat.Log(this, "player_stalled");
            return(false);
        }
        Item ownerItem = GetOwnerItem();

        if (ownerItem == null)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Item not found (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "item_missing");
            return(false);
        }
        if (ownerItem.isBroken)
        {
            AntiHack.Log(player, AntiHackType.AttackHack, "Item broken (" + base.ShortPrefabName + ")");
            player.stats.combat.Log(this, "item_broken");
            return(false);
        }
        return(true);
    }