예제 #1
0
        private static IEnumerator <float> Process(RoundSummary instance)
        {
            RoundSummary roundSummary = instance;

            while (roundSummary != null)
            {
                int count = PlayerManager.players.Count - Npc.Dictionary.Keys.Count;
                while (RoundSummary.RoundLock || !RoundSummary.RoundInProgress() || ((roundSummary._keepRoundOnOne && count < 2) && !__npc_endRequested))
                {
                    if (count == 0 && Npc.Dictionary.Keys.Count > 0)
                    {
                        foreach (Npc n in Npc.List)
                        {
                            n.Kill(false);
                        }
                    }
                    count = PlayerManager.players.Count - Npc.Dictionary.Keys.Count;
                    yield return(0.0f);
                }
                yield return(0.0f);

                RoundSummary.SumInfo_ClassList newList = default;
                foreach (GameObject player in PlayerManager.players)
                {
                    if (!(player == null))
                    {
                        Npc npc = Npc.Get(player);
                        if (npc == null || npc.AffectRoundSummary)
                        {
                            CharacterClassManager component = player.GetComponent <CharacterClassManager>();
                            if (component.Classes.CheckBounds(component.CurClass))
                            {
                                switch (component.Classes.SafeGet(component.CurClass).team)
                                {
                                case Team.SCP:
                                    if (component.CurClass == RoleType.Scp0492)
                                    {
                                        ++newList.zombies;
                                        continue;
                                    }

                                    ++newList.scps_except_zombies;
                                    continue;

                                case Team.MTF:
                                    ++newList.mtf_and_guards;
                                    continue;

                                case Team.CHI:
                                    ++newList.chaos_insurgents;
                                    continue;

                                case Team.RSC:
                                    ++newList.scientists;
                                    continue;

                                case Team.CDP:
                                    ++newList.class_ds;
                                    continue;

                                default:
                                    continue;
                                }
                            }
                        }
                    }
                }

                newList.warhead_kills = AlphaWarheadController.Host.detonated ? AlphaWarheadController.Host.warheadKills : -1;
                yield return(float.NegativeInfinity);

                newList.time = (int)Time.realtimeSinceStartup;
                yield return(float.NegativeInfinity);

                RoundSummary.roundTime = newList.time - roundSummary.classlistStart.time;
                int   num1 = newList.mtf_and_guards + newList.scientists;
                int   num2 = newList.chaos_insurgents + newList.class_ds;
                int   num3 = newList.scps_except_zombies + newList.zombies;
                float num4 = roundSummary.classlistStart.class_ds == 0 ? 0.0f : (RoundSummary.escaped_ds + newList.class_ds) / roundSummary.classlistStart.class_ds;
                float num5 = roundSummary.classlistStart.scientists == 0 ? 1f : (RoundSummary.escaped_scientists + newList.scientists) / roundSummary.classlistStart.scientists;

                if (newList.class_ds == 0 && num1 == 0)
                {
                    roundSummary._roundEnded = true;
                }
                else
                {
                    int num6 = 0;
                    if (num1 > 0)
                    {
                        ++num6;
                    }
                    if (num2 > 0)
                    {
                        ++num6;
                    }
                    if (num3 > 0)
                    {
                        ++num6;
                    }
                    if (num6 <= 1)
                    {
                        roundSummary._roundEnded = true;
                    }
                }

                var endingRoundEventArgs = new EndingRoundEventArgs(Exiled.API.Enums.LeadingTeam.Draw, newList, roundSummary._roundEnded);

                if (num1 > 0)
                {
                    if (RoundSummary.escaped_ds == 0 && RoundSummary.escaped_scientists != 0)
                    {
                        endingRoundEventArgs.LeadingTeam = Exiled.API.Enums.LeadingTeam.FacilityForces;
                    }
                }
                else
                {
                    endingRoundEventArgs.LeadingTeam = RoundSummary.escaped_ds != 0 ? Exiled.API.Enums.LeadingTeam.ChaosInsurgency : Exiled.API.Enums.LeadingTeam.Anomalies;
                }

                Server.OnEndingRound(endingRoundEventArgs);

                roundSummary._roundEnded = endingRoundEventArgs.IsRoundEnded && endingRoundEventArgs.IsAllowed;

                if (roundSummary._roundEnded || __npc_endRequested)
                {
                    FriendlyFireConfig.PauseDetector = true;
                    string str = "Round finished! Anomalies: " + num3 + " | Chaos: " + num2 + " | Facility Forces: " + num1 + " | D escaped percentage: " + num4 + " | S escaped percentage: : " + num5;
                    GameCore.Console.AddLog(str, Color.gray, false);
                    ServerLogs.AddLog(ServerLogs.Modules.Logger, str, ServerLogs.ServerLogType.GameEvent);
                    byte i1;
                    for (i1 = 0; i1 < 75; ++i1)
                    {
                        yield return(0.0f);
                    }
                    int timeToRoundRestart = Mathf.Clamp(ConfigFile.ServerConfig.GetInt("auto_round_restart_time", 10), 5, 1000);

                    if (roundSummary != null)
                    {
                        newList.scps_except_zombies -= newList.zombies;

                        var roundEndedEventArgs = new RoundEndedEventArgs(endingRoundEventArgs.LeadingTeam, newList, timeToRoundRestart);

                        Server.OnRoundEnded(roundEndedEventArgs);

                        roundSummary.RpcShowRoundSummary(roundSummary.classlistStart, roundEndedEventArgs.ClassList, (RoundSummary.LeadingTeam)roundEndedEventArgs.LeadingTeam, RoundSummary.escaped_ds, RoundSummary.escaped_scientists, RoundSummary.kills_by_scp, roundEndedEventArgs.TimeToRestart);
                    }

                    for (int i2 = 0; i2 < 50 * (timeToRoundRestart - 1); ++i2)
                    {
                        yield return(0.0f);
                    }
                    roundSummary.RpcDimScreen();
                    for (i1 = 0; i1 < 50; ++i1)
                    {
                        yield return(0.0f);
                    }
                    PlayerManager.localPlayer.GetComponent <PlayerStats>().Roundrestart();
                    yield break;
                }
            }
        }
예제 #2
0
        private static bool Prefix(PlayerPositionManager __instance)
        {
            try
            {
                if (++__instance._frame != __instance._syncFrequency)
                {
                    return(false);
                }

                __instance._frame = 0;

                List <GameObject> players = PlayerManager.players;
                __instance._usedData = players.Count;

                if (__instance._receivedData == null ||
                    __instance._receivedData.Length < __instance._usedData)
                {
                    __instance._receivedData = new PlayerPositionData[__instance._usedData * 2];
                }

                for (int index = 0; index < __instance._usedData; ++index)
                {
                    __instance._receivedData[index] = new PlayerPositionData(ReferenceHub.GetHub(players[index]));
                }

                if (__instance._transmitBuffer == null ||
                    __instance._transmitBuffer.Length < __instance._usedData)
                {
                    __instance._transmitBuffer = new PlayerPositionData[__instance._usedData * 2];
                }

                foreach (GameObject gameObject in players)
                {
                    if (Npc.Dictionary.ContainsKey(gameObject))
                    {
                        continue;
                    }

                    Player player = Player.Get(gameObject);
                    Array.Copy(__instance._receivedData, __instance._transmitBuffer, __instance._usedData);

                    if (player.Role.Is939())
                    {
                        for (int index = 0; index < __instance._usedData; ++index)
                        {
                            if (__instance._transmitBuffer[index].position.y < 800f)
                            {
                                ReferenceHub hub2 = ReferenceHub.GetHub(__instance._transmitBuffer[index].playerID);

                                if (hub2.characterClassManager.CurRole.team != Team.SCP &&
                                    hub2.characterClassManager.CurRole.team != Team.RIP &&
                                    !hub2
                                    .GetComponent <Scp939_VisionController>()
                                    .CanSee(player.ReferenceHub.characterClassManager.Scp939))
                                {
                                    MakeGhost(index, __instance._transmitBuffer);
                                }
                            }
                        }
                    }
                    else if (player.Role != RoleType.Spectator && player.Role != RoleType.Scp079)
                    {
                        for (int index = 0; index < __instance._usedData; ++index)
                        {
                            PlayerPositionData ppd           = __instance._transmitBuffer[index];
                            Player             currentTarget = Player.Get(ppd.playerID);
                            Scp096             scp096        = player.ReferenceHub.scpsController.CurrentScp as Scp096;

                            if (currentTarget?.ReferenceHub == null)
                            {
                                continue;
                            }

                            Vector3 vector3 = ppd.position - player.ReferenceHub.playerMovementSync.RealModelPosition;
                            if (Math.Abs(vector3.y) > 35f)
                            {
                                MakeGhost(index, __instance._transmitBuffer);
                            }
                            else
                            {
                                float sqrMagnitude = vector3.sqrMagnitude;
                                if (player.ReferenceHub.playerMovementSync.RealModelPosition.y < 800f)
                                {
                                    if (sqrMagnitude >= 1764f)
                                    {
                                        if (!(sqrMagnitude < 4225f))
                                        {
                                            MakeGhost(index, __instance._transmitBuffer);
                                            continue;
                                        }
                                        if (!(currentTarget.ReferenceHub.scpsController.CurrentScp is Scp096 scp) || !scp.EnragedOrEnraging)
                                        {
                                            MakeGhost(index, __instance._transmitBuffer);
                                            continue;
                                        }
                                    }
                                }
                                else if (sqrMagnitude >= 7225f)
                                {
                                    MakeGhost(index, __instance._transmitBuffer);
                                    continue; // As the target is already ghosted
                                }

                                // The code below doesn't have to follow a ELSE statement!
                                // Otherwise Scp268 won't be processed

                                if (scp096 != null &&
                                    scp096.EnragedOrEnraging &&
                                    !scp096.HasTarget(currentTarget.ReferenceHub) &&
                                    currentTarget.Team != Team.SCP)
                                {
#if DEBUG
                                    Log.Debug($"[Scp096@GhostModePatch] {player.UserId} can't see {currentTarget.UserId}");
#endif
                                    MakeGhost(index, __instance._transmitBuffer);
                                }
                                else if (currentTarget.ReferenceHub.playerEffectsController.GetEffect <Scp268>().Enabled)
                                {
                                    bool flag2 = false;
                                    if (scp096 != null)
                                    {
                                        flag2 = scp096.HasTarget(currentTarget.ReferenceHub);
                                    }

                                    if (player.Role != RoleType.Scp079 &&
                                        player.Role != RoleType.Spectator &&
                                        !flag2)
                                    {
                                        MakeGhost(index, __instance._transmitBuffer);
                                    }
                                }
                            }
                        }
                    }

                    // We do another FOR for the ghost things
                    // because it's hard to do it without
                    // whole code changes in the game code
                    for (var z = 0; z < __instance._usedData; z++)
                    {
                        var ppd = __instance._transmitBuffer[z];

                        // Do you remember the bug
                        // when you can't pick up any item?
                        // - Me too;
                        // It was because for a reason
                        // we made the source player
                        // invisible to themself
                        if (player.Id == ppd.playerID)
                        {
                            continue;
                        }

                        // If it's already has the ghost position
                        if (ppd.position == GhostPos)
                        {
                            continue;
                        }

                        if (!ReferenceHub.TryGetHub(ppd.playerID, out var targetHub))
                        {
                            continue;
                        }

                        var target = GetPlayerOrServer(targetHub.gameObject);
                        // If for some reason the player/their ref hub is null
                        if (target?.ReferenceHub == null)
                        {
                            continue;
                        }

                        Npc npc = Npc.Get(target);

                        if (target.IsInvisible || PlayerCannotSee(player, target.Id) || (npc != null && npc.VisibleForRoles.Count != 0 && !npc.VisibleForRoles.Contains(player.Role)) || (npc != null && npc.VisibleForPlayers.Count != 0 && !npc.VisibleForPlayers.Contains(player)))
                        {
                            MakeGhost(z, __instance._transmitBuffer);
                        }
                        // Rotate the player because
                        // those movement checks are
                        // in client-side
                        else if (player.Role == RoleType.Scp173 &&
                                 ((!Exiled.Events.Events.Instance.Config.CanTutorialBlockScp173 &&
                                   target.Role == RoleType.Tutorial) ||
                                  Scp173.TurnedPlayers.Contains(target)))
                        {
                            RotatePlayer(z, __instance._transmitBuffer, FindLookRotation(player.Position, target.Position));
                        }
                    }

                    NetworkConnection networkConnection = player.ReferenceHub.characterClassManager.netIdentity.isLocalPlayer
                        ? NetworkServer.localConnection
                        : player.ReferenceHub.characterClassManager.netIdentity.connectionToClient;
                    if (__instance._usedData <= 20)
                    {
                        networkConnection.Send(
                            new PlayerPositionManager.PositionMessage(__instance._transmitBuffer, (byte)__instance._usedData, 0), 1);
                    }
                    else
                    {
                        byte part;
                        for (part = 0; part < __instance._usedData / 20; ++part)
                        {
                            networkConnection.Send(new PlayerPositionManager.PositionMessage(__instance._transmitBuffer, 20, part), 1);
                        }
                        byte count = (byte)(__instance._usedData % (part * 20));
                        if (count > 0)
                        {
                            networkConnection.Send(new PlayerPositionManager.PositionMessage(__instance._transmitBuffer, count, part), 1);
                        }
                    }
                }

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