Пример #1
0
        private static bool Prefix(Inventory.SyncListItemInfo __instance, int index, float value)
        {
            var item = __instance[index].GetSynapseItem();

            if (item != null)
            {
                item.Durabillity = value;
                return(false);
            }
            return(true);
        }
Пример #2
0
        private static bool Prefix(Inventory.SyncListItemInfo __instance, int index, int s, int b, int o)
        {
            var item = __instance[index].GetSynapseItem();

            if (item != null)
            {
                item.Sight  = s;
                item.Barrel = b;
                item.Other  = o;
                return(false);
            }
            return(true);
        }
Пример #3
0
 private void RevealSpies()
 {
     if (spies.IsEmpty())
     {
         return;
     }
     foreach (KeyValuePair <Player, bool> spy in spies)
     {
         if (spy.Key == null)
         {
             continue;
         }
         Inventory.SyncListItemInfo items = new Inventory.SyncListItemInfo();
         foreach (var item in spy.Key.Inventory.items)
         {
             items.Add(item);
         }
         Vector3 pos    = spy.Key.Position;
         Vector3 rot    = spy.Key.Rotation;
         int     health = (int)spy.Key.Health;
         uint    ammo1  = spy.Key.Ammo[(int)AmmoType.Nato556];
         uint    ammo2  = spy.Key.Ammo[(int)AmmoType.Nato762];
         uint    ammo3  = spy.Key.Ammo[(int)AmmoType.Nato9];
         spy.Key.SetRole(RoleType.ChaosInsurgency);
         Timing.CallDelayed(0.3f, () =>
         {
             spy.Key.Position = pos;
             spy.Key.Rotation = rot;
             spy.Key.Inventory.items.Clear();
             foreach (var item in items)
             {
                 spy.Key.Inventory.AddNewItem(item.id);
             }
             spy.Key.Health = health;
             spy.Key.Ammo[(int)AmmoType.Nato556] = ammo1;
             spy.Key.Ammo[(int)AmmoType.Nato762] = ammo2;
             spy.Key.Ammo[(int)AmmoType.Nato9]   = ammo3;
         });
         spy.Key.Broadcast(10, "Tus compañeros <color=\"green\">Chaos Insurgency</color> murieron.\nLos MTF saben que eres un traidor!");
     }
     spies.Clear();
 }
Пример #4
0
        private bool Handle(Inventory.SyncListItemInfo inv, List <string> perms)
        {
            foreach (var item in inv)
            {
                RemoteKeycard.instance.Debug($"Processing an item in the player’s inventory: {item.id} ({(int)item.id})");

                if (RKConfig.Cards?.Length > 0 && !RKConfig.Cards.Contains(item.id))
                {
                    continue;
                }

                var gameItem = Array.Find(GetItems(), i => i.id == item.id);

                RemoteKeycard.instance.Debug($"Game item is null: {gameItem == null}");
                RemoteKeycard.instance.Debug($"Game item processing: C {gameItem.itemCategory} ({(int)gameItem.itemCategory}) | T {item.id} ({(int)item.id}) | P {string.Join(", ", gameItem.permissions)}");

                // Relevant for items whose type was not found
                if (gameItem == null)
                {
                    continue;
                }

                if (gameItem.permissions == null || gameItem.permissions.Length == 0)
                {
                    continue;
                }

                foreach (var itemPerm in gameItem.permissions)
                {
                    if (perms.Contains(itemPerm, StringComparison.Ordinal))
                    {
                        RemoteKeycard.instance.Debug($"Item has successfully passed permission validation: {gameItem.id} ({(int)gameItem.id})");
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #5
0
        private bool Handle(Inventory.SyncListItemInfo inv, Keycard.Permissions perms, bool requireAll = true)
        {
            if (perms == Keycard.Permissions.None)
            {
                return(true);
            }

            foreach (var item in inv)
            {
                RemoteKeycard.Debug($"Processing an item in the player’s inventory: {item.id} ({(int)item.id})");

                if (RKConfig.Cards?.Length > 0 && !RKConfig.Cards.Contains(item.id))
                {
                    continue;
                }

                var gameItem = Array.Find(GetItems(), i => i.id == item.id);

                RemoteKeycard.Debug($"Game item is null: {gameItem == null}");
                // Relevant for items whose type was not found
                if (gameItem == null)
                {
                    continue;
                }

                var itemPerms = Keycard.ToTruthyPermissions(gameItem.permissions);
                RemoteKeycard.Debug($"Game item processing: C {gameItem.itemCategory} ({(int)gameItem.itemCategory}) | T {item.id} ({(int)item.id}) | P {itemPerms} | P:string[] {string.Join(", ", gameItem.permissions)}");

                if (itemPerms.HasFlagFast(perms, requireAll))
                {
                    RemoteKeycard.Debug($"Item has successfully passed permission validation: {gameItem.id} ({(int)gameItem.id})");
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        public void OnPlayerLeave(PlayerLeaveEvent ev)
        {
            if (ev.Player.GetTeam() != Team.RIP)
            {
                bool is035 = false;
                bool isSH  = false;
                Dictionary <ReferenceHub, bool> spies = null;
                try
                {
                    is035 = ev.Player.queryProcessor.PlayerId == TryGet035()?.queryProcessor.PlayerId;
                }
                catch (Exception x)
                {
                    Log.Debug("SCP-035 is not installed, skipping method call...");
                }

                try
                {
                    isSH = TryGetSH().Contains(ev.Player.queryProcessor.PlayerId);
                }
                catch (Exception x)
                {
                    Log.Debug("Serpents Hand is not installed, skipping method call...");
                }

                try
                {
                    spies = TryGetSpies();
                }
                catch (Exception x)
                {
                    Log.Debug("CISpy is not installed, skipping method call...");
                }

                Inventory.SyncListItemInfo items = ev.Player.inventory.items;
                RoleType role   = ev.Player.GetRole();
                Vector3  pos    = ev.Player.transform.position;
                int      health = (int)ev.Player.playerStats.health;
                string   ammo   = ev.Player.ammoBox.amount;

                ReferenceHub player = Player.GetHubs().FirstOrDefault(x => x.GetRole() == RoleType.Spectator && x.characterClassManager.UserId != string.Empty && !x.GetOverwatch());
                if (player != null)
                {
                    if (isSH)
                    {
                        try
                        {
                            TrySpawnSH(player);
                        }
                        catch (Exception x)
                        {
                            Log.Debug("Serpents Hand is not installed, skipping method call...");
                        }
                    }
                    else
                    {
                        player.SetRole(role);
                    }
                    if (spies != null && spies.ContainsKey(ev.Player))
                    {
                        try
                        {
                            TrySpawnSpy(player, ev.Player, spies);
                        }
                        catch (Exception x)
                        {
                            Log.Debug("CISpy is not installed, skipping method call...");
                        }
                    }
                    if (is035)
                    {
                        try
                        {
                            TrySpawn035(player);
                        }
                        catch (Exception x)
                        {
                            Log.Debug("SCP-035 is not installed, skipping method call...");
                        }
                    }
                    Timing.CallDelayed(0.3f, () =>
                    {
                        player.SetPosition(pos);
                        player.inventory.items.ToList().Clear();
                        foreach (var item in items)
                        {
                            player.inventory.AddNewItem(item.id);
                        }
                        player.playerStats.health    = health;
                        player.ammoBox.Networkamount = ammo;
                        player.Broadcast(5, MsgConfig.ReplaceCustomMsg, false);
                    });
                }
            }
        }
        public static void _WriteStructSyncListItemInfo_Inventory(NetworkWriter writer, Inventory.SyncListItemInfo value)
        {
            ushort count = value.Count;

            writer.Write(count);
            for (ushort num = 0; num < count; num += 1)
            {
                value.SerializeItem(writer, value.GetItem((int)num));
            }
        }
        public static void _ReadStructSyncListItemInfo_Inventory(NetworkReader reader, Inventory.SyncListItemInfo instance)
        {
            ushort num = reader.ReadUInt16();

            instance.Clear();
            for (ushort num2 = 0; num2 < num; num2 += 1)
            {
                instance.AddInternal(instance.DeserializeItem(reader));
            }
        }
Пример #9
0
        public static void TryReplacePlayer(Player replacing)
        {
            Log.Info($"[Tryreplace] Tryreplace now on {replacing} currently {replacing.Role}");

            if (replacing.Role != RoleType.Spectator && replacing.Role != RoleType.None && replacing.Role != RoleType.Tutorial)
            {
                Log.Info($"[Tryreplace] ATTEMPTING REPLACE ON {replacing.Nickname}");
                // Credit: DCReplace :) -- Honestly though, this was really changed from DCReplace into a better check system.

                Inventory.SyncListItemInfo items = replacing.Inventory.items;
                RoleType role   = replacing.Role;
                Vector3  pos    = replacing.Position;
                float    health = replacing.Health;

                // New strange ammo system because the old one was f****d.
                Dictionary <Exiled.API.Enums.AmmoType, uint> ammo = new Dictionary <Exiled.API.Enums.AmmoType, uint>();
                foreach (Exiled.API.Enums.AmmoType atype in (Exiled.API.Enums.AmmoType[])Enum.GetValues(typeof(Exiled.API.Enums.AmmoType)))
                {
                    ammo.Add(atype, replacing.GetAmmo(atype));
                }

                bool isScp079 = (replacing.Role == RoleType.Scp079);
                // Stuff for 079
                byte  Level079 = 0;
                float Exp079 = 0f, AP079 = 0f;
                if (isScp079)
                {
                    Level079 = replacing.Level;
                    Exp079   = replacing.Experience;
                    AP079    = replacing.Energy;
                }

                for (; ;)
                {
                    Player player = Player.List.FirstOrDefault(x => x.Role == RoleType.Spectator && x.UserId != string.Empty && !x.IsOverwatchEnabled && x != replacing);
                    if (player.Role == RoleType.Spectator && player.UserId != string.Empty && !player.IsOverwatchEnabled && player != replacing)
                    {
                        Log.Info($"[TryReplace] Replacing player {replacing.Nickname} with player {player.Nickname}");
                        player.SetRole(role);
                        Timing.CallDelayed(0.3f, () =>
                        {
                            player.Position = pos;
                            player.Inventory.Clear();
                            foreach (var item in items)
                            {
                                player.Inventory.AddNewItem(item.id);
                            }
                            player.Health = health;

                            foreach (Exiled.API.Enums.AmmoType atype in (Exiled.API.Enums.AmmoType[])Enum.GetValues(typeof(Exiled.API.Enums.AmmoType)))
                            {
                                uint amount;
                                if (ammo.TryGetValue(atype, out amount))
                                {
                                    player.SetAmmo(atype, amount);
                                }
                                else
                                {
                                    Log.Error($"[KingsSCPSL] ERROR: Tried to get a value from dict that did not exist! (Ammo)");
                                }
                            }
                            if (isScp079)
                            {
                                player.Level      = Level079;
                                player.Experience = Exp079;
                                player.Energy     = AP079;
                            }
                            player.Broadcast(10, $"{MSG_PREFIX} You have replaced a player who has disconnected.");
                        });
                    }
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Set the ammo of an <see cref="Inventory.SyncItemInfo">item</see>.
 /// </summary>
 /// <param name="list">The list of items.</param>
 /// <param name="weapon">The weapon to be changed.</param>
 /// <param name="amount">The ammo amount.</param>
 public static void SetWeaponAmmo(this Inventory.SyncListItemInfo list, Inventory.SyncItemInfo weapon, int amount) => list.ModifyDuration(list.IndexOf(weapon), amount);
Пример #11
0
        // Called every 1 second according to the player's Update function. This is way more efficient than the old way of doing a forloop for every player.
        // Also, since the gameObject for the player is deleted when they disconnect, we don't need to worry about cleaning any variables :)
        private void AFKChecker()
        {
            //Log.Info($"AFK Time: {this.AFKTime} AFK Count: {this.AFKCount}");
            if (this.ply.Team == Team.RIP)
            {
                return;
            }

            bool isScp079          = (this.ply.Role == RoleType.Scp079) ? true : false;
            bool scp096TryNotToCry = false;

            // When SCP096 is in the state "TryNotToCry" he cannot move or it will cancel,
            // therefore, we don't want to AFK check 096 while he's in this state.
            if (this.ply.Role == RoleType.Scp096)
            {
                PlayableScps.Scp096 scp096 = this.ply.ReferenceHub.scpsController.CurrentScp as PlayableScps.Scp096;
                scp096TryNotToCry = (scp096.PlayerState == Scp096PlayerState.TryNotToCry) ? true : false;
            }

            Vector3 CurrentPos   = this.ply.Position;
            Vector3 CurrentAngle = (isScp079) ? this.ply.Camera.targetPosition.position : this.ply.Rotation;

            if (CurrentPos != this.AFKLastPosition || CurrentAngle != this.AFKLastAngle || scp096TryNotToCry)
            {
                this.AFKLastPosition = CurrentPos;
                this.AFKLastAngle    = CurrentAngle;
                this.AFKTime         = 0;
                return;
            }

            // The player hasn't moved past this point.
            this.AFKTime++;

            // If the player hasn't reached the time yet don't continue.
            if (this.AFKTime < plugin.Config.AfkTime)
            {
                return;
            }

            // Check if we're still in the "grace" period
            int secondsuntilspec = (plugin.Config.AfkTime + plugin.Config.GraceTime) - this.AFKTime;

            if (secondsuntilspec > 0)
            {
                string warning = plugin.Config.MsgGrace;
                warning = warning.Replace("%timeleft%", secondsuntilspec.ToString());

                this.ply.ClearBroadcasts();
                this.ply.Broadcast(1, $"{plugin.Config.MsgPrefix} {warning}");
                return;
            }

            // The player is AFK and action will be taken.
            Log.Info($"{this.ply.Nickname} ({this.ply.UserId}) was detected as AFK!");
            this.AFKTime = 0;

            // Let's make sure they are still alive before doing any replacement.
            if (this.ply.Team == Team.RIP)
            {
                return;
            }

            if (plugin.Config.TryReplace && !this.IsPastReplaceTime())
            {
                var roleEasyEvents = Loader.Plugins.FirstOrDefault(pl => pl.Name == "EasyEvents")?.Assembly.GetType("EasyEvents.Util")?.GetMethod("GetRole")?.Invoke(null, new object[] { this.ply });

                // SCP035 Support (Credit DCReplace)
                bool is035 = false;
                try
                {
                    is035 = this.ply.Id == TryGet035()?.Id;
                }
                catch (Exception e)
                {
                    Log.Debug($"SCP-035 is not installed, skipping method call: {e}");
                }

                // Credit: DCReplace :)
                // I mean at this point 90% of this has been rewritten lol...
                Inventory.SyncListItemInfo items = this.ply.Inventory.items;

                RoleType role   = this.ply.Role;
                Vector3  pos    = this.ply.Position;
                float    health = this.ply.Health;

                // New strange ammo system because the old one was f****d.
                Dictionary <Exiled.API.Enums.AmmoType, uint> ammo = new Dictionary <Exiled.API.Enums.AmmoType, uint>();
                foreach (Exiled.API.Enums.AmmoType atype in (Exiled.API.Enums.AmmoType[])Enum.GetValues(typeof(Exiled.API.Enums.AmmoType)))
                {
                    ammo.Add(atype, this.ply.Ammo[(int)atype]);
                    this.ply.Ammo[(int)atype] = 0; // We remove the ammo so the player doesn't drop it (duplicate ammo)
                }

                // Stuff for 079
                byte  Level079 = 0;
                float Exp079 = 0f, AP079 = 0f;
                if (isScp079)
                {
                    Level079 = this.ply.Level;
                    Exp079   = this.ply.Experience;
                    AP079    = this.ply.Energy;
                }

                Player player = Player.List.FirstOrDefault(x => x.Role == RoleType.Spectator && x.UserId != string.Empty && !x.IsOverwatchEnabled && x != this.ply);
                if (player != null)
                {
                    player.SetRole(role);
                    Timing.CallDelayed(0.3f, () =>
                    {
                        if (is035)
                        {
                            try
                            {
                                TrySpawn035(player);
                            }
                            catch (Exception e)
                            {
                                Log.Debug($"SCP-035 is not installed, skipping method call: {e}");
                            }
                        }
                        player.Position = pos;
                        player.Inventory.Clear();

                        foreach (Inventory.SyncItemInfo item in items)
                        {
                            player.Inventory.AddNewItem(item.id, item.durability, item.modSight, item.modBarrel, item.modOther);
                        }

                        player.Health = health;

                        foreach (Exiled.API.Enums.AmmoType atype in (Exiled.API.Enums.AmmoType[])Enum.GetValues(typeof(Exiled.API.Enums.AmmoType)))
                        {
                            uint amount;
                            if (ammo.TryGetValue(atype, out amount))
                            {
                                this.ply.Ammo[(int)atype] = amount;
                            }
                            else
                            {
                                Log.Error($"[uAFK] ERROR: Tried to get a value from dict that did not exist! (Ammo)");
                            }
                        }

                        if (isScp079)
                        {
                            player.Level      = Level079;
                            player.Experience = Exp079;
                            player.Energy     = AP079;
                        }

                        player.Broadcast(10, $"{plugin.Config.MsgPrefix} {plugin.Config.MsgReplace}");
                        if (roleEasyEvents != null)
                        {
                            Loader.Plugins.FirstOrDefault(pl => pl.Name == "EasyEvents")?.Assembly.GetType("EasyEvents.CustomRoles")?.GetMethod("ChangeRole")?.Invoke(null, new object[] { player, roleEasyEvents });
                        }

                        this.ply.Inventory.Clear(); // Clear their items to prevent dupes.
                        this.ply.SetRole(RoleType.Spectator);
                        this.ply.Broadcast(30, $"{plugin.Config.MsgPrefix} {plugin.Config.MsgFspec}");
                    });
                }
                else
                {
                    // Couldn't find a valid player to spawn, just ForceToSpec anyways.
                    this.ForceToSpec(this.ply);
                }
            }
            else
            {
                // Replacing is disabled, just ForceToSpec
                this.ForceToSpec(this.ply);
            }
            // If it's -1 we won't be kicking at all.
            if (plugin.Config.NumBeforeKick != -1)
            {
                // Increment AFK Count
                this.AFKCount++;
                if (this.AFKCount >= plugin.Config.NumBeforeKick)
                {
                    // Since AFKCount is greater than the config we're going to kick that player for being AFK too many times in one match.
                    ServerConsole.Disconnect(this.gameObject, plugin.Config.MsgKick);
                }
            }
        }