public static bool Prefix(PlayerInteract __instance, GameObject doorId)
        {
            try
            {
                var  allowTheAccess = true;
                Door door           = null;

                if (!__instance._playerInteractRateLimit.CanExecute() || (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract))
                {
                    return(false);
                }

                if (doorId == null)
                {
                    return(false);
                }

                if (__instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator)
                {
                    return(false);
                }

                if (!doorId.TryGetComponent(out door))
                {
                    return(false);
                }


                if ((door.Buttons.Count == 0) ? (!__instance.ChckDis(doorId.transform.position)) : Enumerable.All(door.Buttons, item => !__instance.ChckDis(item.button.transform.position)))
                {
                    return(false);
                }

                __instance.OnInteract();

                if (!__instance._sr.BypassMode && !(door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) &&
                                                    __instance._ccm.CurRole.team == Team.SCP))
                {
                    try
                    {
                        if (door.PermissionLevels == 0)
                        {
                            allowTheAccess = !door.locked;
                        }
                        else if (!door.RequireAllPermissions)
                        {
                            var itemPerms = __instance._inv.GetItemByID(__instance._inv.curItem).permissions;
                            allowTheAccess = itemPerms.Any(p =>
                                                           Door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
                                                           door.PermissionLevels.HasPermission(flag));
                        }
                        else
                        {
                            allowTheAccess = false;
                        }
                    }
                    catch
                    {
                        allowTheAccess = false;
                    }
                }

                Events.InvokeDoorInteraction(__instance.gameObject.GetPlayer(), door, ref allowTheAccess);

                if (allowTheAccess)
                {
                    door.ChangeState(__instance._sr.BypassMode);
                }
                else
                {
                    __instance.RpcDenied(doorId);
                }

                return(false);
            }
            catch (Exception e)
            {
                Log.Error($"DoorInteraction Error: {e}");

                return(true);
            }
        }
Beispiel #2
0
        private static bool Prefix(PlayerInteract __instance, GameObject doorId)
        {
            if (!__instance._playerInteractRateLimit.CanExecute() ||
                (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract) ||
                doorId == null ||
                !doorId.TryGetComponent(out Door door) ||
                (__instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator) ||
                (door.buttons.Count == 0 ?
                 (__instance.ChckDis(doorId.transform.position) ? 1 : 0) :
                 (door.buttons.Any(item => __instance.ChckDis(item.transform.position)) ? 1 : 0)) == 0)
            {
                return(false);
            }

            var ev = new InteractingDoorEventArgs(API.Features.Player.Get(__instance.gameObject), door);

            __instance.OnInteract();

            if (__instance._sr.BypassMode)
            {
                ev.IsAllowed = true;
            }
            else if (ev.Door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) && __instance._ccm.CurRole.team == Team.SCP)
            {
                ev.IsAllowed = true;
            }
            else
            {
                try
                {
                    if (ev.Door.PermissionLevels == 0)
                    {
                        ev.IsAllowed = !ev.Door.locked;
                    }
                    else if (!ev.Door.RequireAllPermissions)
                    {
                        var itemPerms = __instance._inv.GetItemByID(__instance._inv.curItem).permissions;

                        ev.IsAllowed = itemPerms.Any(p =>
                                                     ev.Door.backwardsCompatPermissions.TryGetValue(p, out var flag) &&
                                                     ev.Door.PermissionLevels.HasPermission(flag)) || false;
                    }
                    else
                    {
                        ev.IsAllowed = false;
                    }
                }
                catch
                {
                    ev.IsAllowed = false;
                }
            }

            Player.OnInteractingDoor(ev);

            if (ev.IsAllowed)
            {
                ev.Door.ChangeState(__instance._sr.BypassMode);
            }
            else
            {
                __instance.RpcDenied(doorId);
            }

            return(false);
        }
        public static bool Prefix(PlayerInteract __instance, GameObject doorId)
        {
            if (EventPlugin.DoorInteractionEventPatchDisable)
            {
                return(true);
            }

            try
            {
                bool allow = true;
                if (!__instance._playerInteractRateLimit.CanExecute() ||
                    __instance._hc.CufferId > 0 && !__instance.CanDisarmedInteract ||
                    (doorId == null || __instance._ccm.CurClass == RoleType.None ||
                     __instance._ccm.CurClass == RoleType.Spectator))
                {
                    return(false);
                }
                Door component1 = doorId.GetComponent <Door>();
                if (component1 == null || (component1.buttons.Count == 0
                                            ? (__instance.ChckDis(doorId.transform.position) ? 1 : 0)
                                            : (component1.buttons.Any(item => __instance.ChckDis(item.transform.position)) ? 1 : 0)) == 0)
                {
                    return(false);
                }
                Scp096PlayerScript component2 = __instance.GetComponent <Scp096PlayerScript>();
                if (component1.destroyedPrefab != null && (!component1.isOpen || component1.curCooldown > 0.0) &&
                    (component2.iAm096 && component2.enraged == Scp096PlayerScript.RageState.Enraged))
                {
                    if (!__instance._096DestroyLockedDoors && component1.locked && !__instance._sr.BypassMode)
                    {
                        return(false);
                    }
                    component1.DestroyDoor(true);
                }
                else
                {
                    __instance.OnInteract();
                    if (__instance._sr.BypassMode)
                    {
                        try
                        {
                            Events.InvokeDoorInteract(__instance.gameObject, component1, ref allow);

                            if (allow == false)
                            {
                                __instance.RpcDenied(doorId);
                                return(false);
                            }

                            component1.ChangeState();
                        }
                        catch (Exception e)
                        {
                            Log.Error($"Door interaction error: {e}");

                            if (allow)
                            {
                                component1.ChangeState();
                            }
                            else
                            {
                                __instance.RpcDenied(doorId);
                            }
                            return(false);
                        }
                    }
                    else if (string.Equals(component1.permissionLevel, "CHCKPOINT_ACC",
                                           StringComparison.OrdinalIgnoreCase) && __instance.GetComponent <CharacterClassManager>()
                             .Classes.SafeGet(__instance.GetComponent <CharacterClassManager>().CurClass).team ==
                             Team.SCP)
                    {
                        try
                        {
                            Events.InvokeDoorInteract(__instance.gameObject, component1, ref allow);

                            if (allow == false)
                            {
                                __instance.RpcDenied(doorId);
                                return(false);
                            }

                            component1.ChangeState();
                        }
                        catch (Exception e)
                        {
                            Log.Error($"Door interaction error: {e}");

                            if (allow)
                            {
                                component1.ChangeState();
                            }
                            else
                            {
                                __instance.RpcDenied(doorId);
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(component1.permissionLevel))
                        {
                            if (component1.locked)
                            {
                                __instance.RpcDenied(doorId);
                                return(false);
                            }

                            try
                            {
                                Events.InvokeDoorInteract(__instance.gameObject, component1, ref allow);

                                if (allow == false)
                                {
                                    __instance.RpcDenied(doorId);
                                    return(false);
                                }

                                component1.ChangeState();
                                return(false);
                            }
                            catch (Exception e)
                            {
                                Log.Error($"Door interaction error: {e}");

                                if (allow)
                                {
                                    component1.ChangeState();
                                }
                                else
                                {
                                    __instance.RpcDenied(doorId);
                                }
                                return(false);
                            }
                        }

                        Item item = __instance._inv.GetItemByID(__instance._inv.curItem);
                        if (item != null && item.permissions.Contains(component1.permissionLevel))
                        {
                            if (!component1.locked)
                            {
                                try
                                {
                                    Events.InvokeDoorInteract(__instance.gameObject, component1, ref allow);

                                    if (allow == false)
                                    {
                                        __instance.RpcDenied(doorId);
                                        return(false);
                                    }

                                    component1.ChangeState();
                                }
                                catch (Exception e)
                                {
                                    Log.Error($"Door interaction error: {e}");

                                    if (allow)
                                    {
                                        component1.ChangeState();
                                    }
                                    else
                                    {
                                        __instance.RpcDenied(doorId);
                                    }
                                }
                            }
                            else
                            {
                                __instance.RpcDenied(doorId);
                            }
                        }
                        else
                        {
                            // Let the plugins decide in case the default options to open the door weren't met
                            if (!component1.locked)
                            {
                                // Instead of passing allow as true, pass it as false
                                allow = false;
                                try
                                {
                                    Events.InvokeDoorInteract(__instance.gameObject, component1, ref allow);

                                    if (allow == false)
                                    {
                                        __instance.RpcDenied(doorId);
                                        return(false);
                                    }

                                    component1.ChangeState();
                                }
                                catch (Exception e)
                                {
                                    Log.Error($"Door interaction error: {e}");

                                    if (allow)
                                    {
                                        component1.ChangeState();
                                    }
                                    else
                                    {
                                        __instance.RpcDenied(doorId);
                                    }
                                }
                            }
                            else
                            {
                                __instance.RpcDenied(doorId);
                            }
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Log.Error($"DoorInteraction Error: {e}");
                return(true);
            }
        }
Beispiel #4
0
        public static bool Prefix(PlayerInteract __instance, GameObject doorId)
        {
            if (EventPlugin.DoorInteractionEventPatchDisable)
            {
                return(true);
            }

            bool allow = true;
            Door door  = doorId.GetComponent <Door>();

            try
            {
                if (!__instance._playerInteractRateLimit.CanExecute() ||
                    __instance._hc.CufferId > 0 && !__instance.CanDisarmedInteract ||
                    (doorId == null || __instance._ccm.CurClass == RoleType.None ||
                     __instance._ccm.CurClass == RoleType.Spectator))
                {
                    return(false);
                }

                if (door == null || (door.buttons.Count == 0
                                                ? (__instance.ChckDis(doorId.transform.position) ? 1 : 0)
                                                : (door.buttons.Any(item => __instance.ChckDis(item.transform.position)) ? 1 : 0)) == 0)
                {
                    return(false);
                }

                Scp096PlayerScript component2 = __instance.GetComponent <Scp096PlayerScript>();

                if (door.destroyedPrefab != null && (!door.isOpen || door.curCooldown > 0.0) &&
                    (component2.iAm096 && component2.enraged == Scp096PlayerScript.RageState.Enraged))
                {
                    if (!__instance._096DestroyLockedDoors && door.locked && !__instance._sr.BypassMode)
                    {
                        return(false);
                    }

                    door.DestroyDoor(true);
                }
                else
                {
                    __instance.OnInteract();
                    if (__instance._sr.BypassMode)
                    {
                        allow = true;
                    }
                    else if (string.Equals(door.permissionLevel, "CHCKPOINT_ACC", StringComparison.OrdinalIgnoreCase) &&
                             __instance.GetComponent <CharacterClassManager>().Classes.SafeGet(__instance.GetComponent <CharacterClassManager>().CurClass).team == Team.SCP)
                    {
                        allow = true;
                    }
                    else
                    {
                        Item item = __instance._inv.GetItemByID(__instance._inv.curItem);
                        if (string.IsNullOrEmpty(door.permissionLevel))
                        {
                            allow = !door.locked;
                        }
                        else if (item != null && item.permissions.Contains(door.permissionLevel))
                        {
                            allow = !door.locked;
                        }
                        else
                        {
                            allow = false;
                        }
                    }

                    Events.InvokeDoorInteract(__instance.gameObject, door, ref allow);

                    if (!allow)
                    {
                        __instance.RpcDenied(doorId);
                        return(false);
                    }

                    door.ChangeState();
                }

                return(false);
            }
            catch (Exception exception)
            {
                Log.Error($"DoorInteractionEvent error: {exception}");

                if (allow)
                {
                    door.ChangeState();
                }
                else
                {
                    __instance.RpcDenied(doorId);
                }

                return(false);
            }
        }