Decompiled source of BetterSandbox v2.2.5
plugins/BetterSandbox.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using InControl; using Microsoft.CodeAnalysis; using ModdingUtils.AIMinion.Extensions; using ModdingUtils.Utils; using Photon.Pun; using Photon.Realtime; using RWF; using SoundImplementation; using TMPro; using UnboundLib; using UnboundLib.Extensions; using UnboundLib.GameModes; using UnboundLib.Networking; using UnboundLib.Utils; using UnboundLib.Utils.UI; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BetterSandbox { [BepInPlugin("com.mrnoa.rounds.bettersandbox", "BetterSandbox", "2.2.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInProcess("Rounds.exe")] public class BetterSandboxPlugin : BaseUnityPlugin { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__13_0; public static UnityAction<bool> <>9__14_0; public static UnityAction<bool> <>9__14_1; public static UnityAction<bool> <>9__14_2; public static UnityAction<bool> <>9__14_3; public static UnityAction<bool> <>9__14_4; public static UnityAction<bool> <>9__14_5; public static UnityAction<bool> <>9__14_6; internal void <Start>b__13_0() { } internal void <BuildMenu>b__14_0(bool v) { SwitchMapWhenOneLeft.Value = v; } internal void <BuildMenu>b__14_1(bool v) { RandomCardEveryone.Value = v; } internal void <BuildMenu>b__14_2(bool v) { RandomCardLosers.Value = v; } internal void <BuildMenu>b__14_3(bool v) { KeepScoreWhenOneLeft.Value = v; } internal void <BuildMenu>b__14_4(bool v) { RoundPick.Value = v; } internal void <BuildMenu>b__14_5(bool v) { RoundCardEveryone.Value = v; } internal void <BuildMenu>b__14_6(bool v) { RoundCardLosers.Value = v; } } public const string Guid = "com.mrnoa.rounds.bettersandbox"; public const string Name = "BetterSandbox"; public const string Version = "2.2.5"; internal static ManualLogSource Log; internal static ConfigEntry<KeyCode> MenuKey; internal static ConfigEntry<bool> SwitchMapWhenOneLeft; internal static ConfigEntry<bool> RandomCardEveryone; internal static ConfigEntry<bool> RandomCardLosers; internal static ConfigEntry<bool> KeepScoreWhenOneLeft; internal static ConfigEntry<bool> RoundPick; internal static ConfigEntry<bool> RoundCardEveryone; internal static ConfigEntry<bool> RoundCardLosers; private void Awake() { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "SandboxMenu", (KeyCode)283, "Sandbox only: opens and closes the sandbox menu."); SwitchMapWhenOneLeft = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "SwitchMapWhenOneLeft", false, "Sandbox: when only one player (or team) is left standing, load a new map and bring everyone back."); KeepScoreWhenOneLeft = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "KeepScoreWhenOneLeft", false, "Sandbox: when only one player (or team) is left standing, they win a point, like a normal game (points, rounds, victory). The score is kept while this is off."); RandomCardEveryone = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "RandomCardForEveryoneWhenOneLeft", false, "Sandbox: every time only one player (or team) is left standing, everyone gets a random card."); RandomCardLosers = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "RandomCardForLosersWhenOneLeft", false, "Sandbox: every time only one player (or team) is left standing, everyone who lost gets a random card."); RoundPick = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "CardPickWhenARoundIsWon", false, "Sandbox, with KeepScoreWhenOneLeft on: when a player wins a round, everyone who lost picks a card, like a normal game."); RoundCardEveryone = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "RandomCardForEveryoneWhenARoundIsWon", false, "Sandbox, with KeepScoreWhenOneLeft on: when a player wins a round, everyone gets a random card."); RoundCardLosers = ((BaseUnityPlugin)this).Config.Bind<bool>("Rounds", "RandomCardForLosersWhenARoundIsWon", false, "Sandbox, with KeepScoreWhenOneLeft on: when a player wins a round, everyone who lost gets a random card."); Unbound.RegisterClientSideMod("com.mrnoa.rounds.bettersandbox"); Harmony val = new Harmony("com.mrnoa.rounds.bettersandbox"); val.PatchAll(typeof(BetterSandboxPlugin).Assembly); SimulPicksGuard.Install(val); GameObject val2 = new GameObject("BetterSandbox"); Object.DontDestroyOnLoad((Object)val2); val2.AddComponent<SandboxController>(); ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded. In sandbox: {2} = sandbox menu.", "BetterSandbox", "2.2.5", MenuKey.Value)); } private void Start() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown object obj = <>c.<>9__13_0; if (obj == null) { UnityAction val = delegate { }; <>c.<>9__13_0 = val; obj = (object)val; } Unbound.RegisterMenu("BetterSandbox", (UnityAction)obj, (Action<GameObject>)BuildMenu, (GameObject)null, true); } private static void BuildMenu(GameObject menu) { TextMeshProUGUI val = default(TextMeshProUGUI); MenuHandler.CreateText("BetterSandbox", menu, ref val, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateText(" ", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); KeyButton("Sandbox Menu Key", MenuKey, menu); MenuHandler.CreateText("click it, then press the new key (Esc cancels)", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateText(" ", menu, ref val, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateText("When one player is left (offline sandbox)", menu, ref val, 35, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(SwitchMapWhenOneLeft.Value, "Switch Map", menu, (UnityAction<bool>)delegate(bool v) { SwitchMapWhenOneLeft.Value = v; }, 40, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(RandomCardEveryone.Value, "Everyone Gets A Random Card", menu, (UnityAction<bool>)delegate(bool v) { RandomCardEveryone.Value = v; }, 40, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(RandomCardLosers.Value, "Losers Get A Random Card", menu, (UnityAction<bool>)delegate(bool v) { RandomCardLosers.Value = v; }, 40, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(KeepScoreWhenOneLeft.Value, "Keep Score", menu, (UnityAction<bool>)delegate(bool v) { KeepScoreWhenOneLeft.Value = v; }, 40, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateText("When a player wins a round (Keep Score on)", menu, ref val, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(RoundPick.Value, "Card Pick Phase", menu, (UnityAction<bool>)delegate(bool v) { RoundPick.Value = v; }, 35, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(RoundCardEveryone.Value, "Everyone Gets A Random Card", menu, (UnityAction<bool>)delegate(bool v) { RoundCardEveryone.Value = v; }, 35, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); MenuHandler.CreateToggle(RoundCardLosers.Value, "Losers Get A Random Card", menu, (UnityAction<bool>)delegate(bool v) { RoundCardLosers.Value = v; }, 35, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); } private static void KeyButton(string label, ConfigEntry<KeyCode> entry, GameObject menu) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown TextMeshProUGUI tmp = null; GameObject val = MenuHandler.CreateButton(Text(), menu, (UnityAction)delegate { if ((Object)(object)tmp != (Object)null) { ((TMP_Text)tmp).text = label + ": press a key..."; } SandboxController.Instance?.CaptureKey(entry, delegate { if ((Object)(object)tmp != (Object)null) { ((TMP_Text)tmp).text = Text(); } }); }, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null); tmp = val.GetComponentInChildren<TextMeshProUGUI>(true); string Text() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) return $"{label}: {entry.Value}"; } } } [HarmonyPatch(typeof(EscapeMenuHandler), "Update")] internal static class EscapeMenuHandler_Update_Patch { [HarmonyPriority(800)] private static bool Prefix() { SandboxController instance = SandboxController.Instance; if ((Object)(object)instance == (Object)null || !Input.GetKeyDown((KeyCode)27) || !instance.HubOpen) { return true; } instance.CloseHub(); return false; } } internal static class SimulPicksGuard { private const string SimulPicksGuid = "com.redredrain.rounds.simulpicks"; private static FieldInfo phaseActive; private static FieldInfo localPickActive; private static MethodInfo hardReset; internal static void Install(Harmony harmony) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown if (!Chainloader.PluginInfos.ContainsKey("com.redredrain.rounds.simulpicks")) { return; } Type type = AccessTools.TypeByName("EveryonePicks.State"); Type key = AccessTools.TypeByName("EveryonePicks.LeaverResilience"); Type key2 = AccessTools.TypeByName("EveryonePicks.EveryonePicksPlugin"); KeyValuePair<Type, string>[] obj = new KeyValuePair<Type, string>[4] { new KeyValuePair<Type, string>(type, "OnPickStart"), new KeyValuePair<Type, string>(type, "Barrier"), new KeyValuePair<Type, string>(key, "ArmWatchdog"), new KeyValuePair<Type, string>(key2, "Announce") }; HarmonyMethod val = new HarmonyMethod(typeof(SimulPicksGuard), "SkipInSandbox", (Type[])null) { priority = 800 }; int num = 0; KeyValuePair<Type, string>[] array = obj; for (int i = 0; i < array.Length; i++) { KeyValuePair<Type, string> keyValuePair = array[i]; MethodInfo methodInfo = ((keyValuePair.Key != null) ? AccessTools.Method(keyValuePair.Key, keyValuePair.Value, (Type[])null, (Type[])null) : null); if (methodInfo == null || methodInfo.ReturnType != typeof(IEnumerator)) { BetterSandboxPlugin.Log.LogWarning((object)("SimulPicks has changed: couldn't find " + (keyValuePair.Key?.Name ?? "?") + "." + keyValuePair.Value + ", so it may still act in sandbox.")); } else { try { harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Couldn't keep SimulPicks' " + keyValuePair.Value + " out of sandbox: " + ex.Message)); } } } if (type != null) { phaseActive = AccessTools.Field(type, "phaseActive"); localPickActive = AccessTools.Field(type, "localPickActive"); hardReset = AccessTools.Method(type, "HardReset", new Type[1] { typeof(string) }, (Type[])null); } BetterSandboxPlugin.Log.LogInfo((object)$"SimulPicks found: it stays out of sandbox ({num} of its 4 hooks do nothing there)."); } private static bool SkipInSandbox(ref IEnumerator __result) { if (!SandboxController.InSandbox) { return true; } __result = Nothing(); return false; } private static IEnumerator Nothing() { yield break; } internal static void ResetIfActive() { try { if (((phaseActive != null && (bool)phaseActive.GetValue(null)) || (localPickActive != null && (bool)localPickActive.GetValue(null))) && !(hardReset == null)) { hardReset.Invoke(null, new object[1] { "BetterSandbox: entering sandbox" }); BetterSandboxPlugin.Log.LogInfo((object)"SimulPicks was still in a pick phase; reset it for sandbox."); } } catch (Exception ex) { BetterSandboxPlugin.Log.LogDebug((object)("SimulPicks reset: " + ex.Message)); } } } [HarmonyPatch(typeof(MapManager), "RPCA_LoadLevel")] internal static class MapManager_RPCA_LoadLevel_Patch { private static void Prefix(string sceneName) { ToggleLevelMenuHandler instance = ToggleLevelMenuHandler.instance; if (!((Object)(object)instance != (Object)null) || !instance.isDrawingLevels) { SandboxController.CurrentMapKey = sceneName; } } } [HarmonyPatch(typeof(GM_Test), "PlayerDied")] internal static class GM_Test_PlayerDied_Patch { private static bool Prefix(Player player) { SandboxController instance = SandboxController.Instance; if (!((Object)(object)instance == (Object)null)) { return !instance.OnPlayerDied(player); } return true; } } internal class SandboxController : MonoBehaviour { internal enum Act { Give, Take, Undo, Clear, Map, TakeAt } private class FontHolder { public TMP_FontAsset Font; } private class MapLoad { public string Key; public string Label; public bool Ok; public float StartedAt; } private class ScoreResult { public bool RoundWon; } internal static SandboxController Instance; private static readonly KeyCode[] AllKeys = ((KeyCode[])Enum.GetValues(typeof(KeyCode))).Distinct().ToArray(); private static readonly FieldInfo VelSimulated = AccessTools.Field(typeof(PlayerVelocity), "simulated"); private static readonly FieldInfo VelKinematic = AccessTools.Field(typeof(PlayerVelocity), "isKinematic"); private SandboxHub hub; private MapPicker mapPicker; internal static string CurrentMapKey; private bool wasInSandbox; private Coroutine helpRoutine; private bool menuOpen; private bool cardGiveMode = true; private Action[] giveActions; private int buildPanelAtFrame = -1; private CardPanel panel; private readonly List<GameObject> hiddenInCardMenu = new List<GameObject>(); internal const int Everyone = -2; private int targetID = -1; private bool changingMap; private bool roundRunning; private string lastMapKey; private float busyUntil; private bool hintShown; private float nextRefresh; private ConfigEntry<KeyCode> captureEntry; private Action captureDone; private readonly BottomHint hint = new BottomHint(); private float sandboxEnteredAt; private readonly HashSet<int> seenPlayers = new HashSet<int>(); private readonly Dictionary<int, float> joinChecks = new Dictionary<int, float>(); private static readonly MethodInfo PlayerWasAddedMethod = AccessTools.Method(typeof(GM_Test), "PlayerWasAdded", (Type[])null, (Type[])null); private bool barsRebuilt; private float nextBarCheck; private static readonly FieldInfo CardBarsField = AccessTools.Field(typeof(CardBarHandler), "cardBars"); private readonly List<Player> heldDead = new List<Player>(); private Coroutine roundCoroutine; private static readonly MethodInfo DelayReviveMethod = AccessTools.Method(typeof(GM_Test), "DelayRevive", (Type[])null, (Type[])null); private static readonly MethodInfo SetPlayersVisibleMethod = AccessTools.Method(typeof(PlayerManager), "SetPlayersVisible", (Type[])null, (Type[])null); private readonly Dictionary<int, int> teamPoints = new Dictionary<int, int>(); private readonly Dictionary<int, int> teamRounds = new Dictionary<int, int>(); private bool scoreShown; private string scoreTeams = ""; private float nextScoreCheck; internal static string HelpText => $"PRESS {BetterSandboxPlugin.MenuKey.Value} TO OPEN SANDBOX MENU"; internal static bool InSandbox { get { if ((Object)(object)GM_Test.instance != (Object)null) { return ((Component)GM_Test.instance).gameObject.activeInHierarchy; } return false; } } internal static bool Offline { get { if (!PhotonNetwork.OfflineMode) { return PhotonNetwork.CurrentRoom == null; } return true; } } private static bool IsHostOrOffline { get { if (!Offline) { return PhotonNetwork.IsMasterClient; } return true; } } internal bool MenuOpen => menuOpen; internal bool ChangingMap { get { if (!changingMap) { return roundRunning; } return true; } } internal bool CardGiveMode => cardGiveMode; internal bool AnyOpen { get { if (!hub.IsOpen && !menuOpen) { return mapPicker.IsOpen; } return true; } } internal bool HubOpen => hub.IsOpen; internal bool TargetsEveryone => targetID == -2; private string ToWhom { get { if (targetID != -2) { return ""; } return " TO EVERYONE"; } } private string FromWhom { get { if (targetID != -2) { return ""; } return " FROM EVERYONE"; } } internal bool CardsSettling => Time.unscaledTime < busyUntil; internal static bool RoundModeOn { get { if (!BetterSandboxPlugin.SwitchMapWhenOneLeft.Value && !BetterSandboxPlugin.KeepScoreWhenOneLeft.Value && !BetterSandboxPlugin.RandomCardEveryone.Value) { return BetterSandboxPlugin.RandomCardLosers.Value; } return true; } } internal static int PointsToWinRound => Setting("pointsToWinRound", 2); internal static int RoundsToWinGame => Setting("roundsToWinGame", 5); private void Awake() { Instance = this; mapPicker = new MapPicker(this); hub = new SandboxHub(this); } private void Update() { //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) if (captureEntry != null) { PollCapture(); return; } GameObject cardMenuCanvas = ToggleCardsMenuHandler.cardMenuCanvas; if (menuOpen && (!InSandbox || (Object)(object)cardMenuCanvas == (Object)null || !cardMenuCanvas.activeInHierarchy || !ToggleCardsMenuHandler.menuOpenFromOutside)) { AfterClosed(); } mapPicker.Watch(); hub.Watch(); hint.Tick(); if (!InSandbox) { hint.Hide(0.01f); } bool inSandbox = InSandbox; if (inSandbox && !wasInSandbox) { OnEnteredSandbox(); } wasInSandbox = inSandbox; if (!InSandbox && roundRunning) { roundRunning = false; } if (!InSandbox) { heldDead.Clear(); } else { ReleaseHeldDead(); } WatchScore(); WatchJoins(); WatchCardBars(); if (InSandbox) { KeyCode value = BetterSandboxPlugin.MenuKey.Value; if (Input.GetKeyDown(value) && !BlockedByTyping(value)) { if (AnyOpen) { CloseAll(); } else { OpenHub(); } } } if (menuOpen) { if (panel == null && buildPanelAtFrame >= 0 && Time.frameCount >= buildPanelAtFrame) { buildPanelAtFrame = -1; BuildPanel(); } panel?.Tick(); if (Time.unscaledTime >= nextRefresh) { nextRefresh = Time.unscaledTime + 0.25f; panel?.Refresh(); HideNamed(ToggleCardsMenuHandler.cardMenuCanvas, "CardsPresetPanel", hiddenInCardMenu); } } mapPicker.Tick(); } internal void CloseHub() { hub.Close(); } private void OnEnteredSandbox() { sandboxEnteredAt = Time.unscaledTime; TurnOffRoundSwitches(); SimulPicksGuard.ResetIfActive(); seenPlayers.Clear(); joinChecks.Clear(); if (helpRoutine != null) { ((MonoBehaviour)this).StopCoroutine(helpRoutine); } helpRoutine = ((MonoBehaviour)this).StartCoroutine(SandboxHelp()); } private IEnumerator SandboxHelp() { yield return (object)new WaitForSecondsRealtime(0.3f); if (!InSandbox) { helpRoutine = null; yield break; } FontHolder found = new FontHolder(); bool hidVanilla = HideVanillaHelp(found); if ((Object)(object)found.Font == (Object)null) { try { UIHandler instance = UIHandler.instance; object font; if (instance == null) { font = null; } else { TextMeshProUGUI jointGameText = instance.jointGameText; font = ((jointGameText != null) ? ((TMP_Text)jointGameText).font : null); } found.Font = (TMP_FontAsset)font; } catch { } } hint.Show(HelpText, found.Font); float fadeAt = Time.unscaledTime + 6f; float retryUntil = Time.unscaledTime + 8f; float nextTry = 0f; while (InSandbox && hint.Visible) { if (!hidVanilla && Time.unscaledTime < retryUntil && Time.unscaledTime >= nextTry) { nextTry = Time.unscaledTime + 0.25f; hidVanilla = HideVanillaHelp(found); } if (AnyOpen) { hint.Hide(0.15f); } else if (Time.unscaledTime > fadeAt) { hint.Hide(0.6f); } yield return null; } if (!InSandbox) { hint.Hide(0.01f); } helpRoutine = null; } private void WatchJoins() { if (!InSandbox || !Offline) { seenPlayers.Clear(); joinChecks.Clear(); return; } List<Player> list = Players(); foreach (Player item in list) { if (seenPlayers.Add(item.playerID)) { joinChecks[item.playerID] = Time.unscaledTime + 2f; } } if (joinChecks.Count == 0) { return; } foreach (int id in joinChecks.Keys.ToList()) { if (Time.unscaledTime < joinChecks[id]) { continue; } if (roundRunning || changingMap) { joinChecks[id] = Time.unscaledTime + 1f; continue; } joinChecks.Remove(id); Player val = ((IEnumerable<Player>)list).FirstOrDefault((Func<Player, bool>)((Player x) => x.playerID == id)); if ((Object)(object)val == (Object)null || val.data.dead) { continue; } PlayerVelocity playerVel = val.data.playerVel; bool flag = (Object)(object)playerVel == (Object)null || VelSimulated == null || (bool)VelSimulated.GetValue(playerVel); bool flag2 = (Object)(object)playerVel != (Object)null && VelKinematic != null && (bool)VelKinematic.GetValue(playerVel); if (flag && !flag2 && val.data.isPlaying) { continue; } BetterSandboxPlugin.Log.LogWarning((object)$"{PlayerName(val)} didn't spawn properly (playing={val.data.isPlaying}, simulated={flag}, kinematic={flag2}); spawning them again."); try { if ((Object)(object)playerVel != (Object)null) { VelSimulated?.SetValue(playerVel, true); VelKinematic?.SetValue(playerVel, false); } if ((Object)(object)GM_Test.instance != (Object)null) { PlayerWasAddedMethod?.Invoke(GM_Test.instance, new object[1] { val }); } val.data.isPlaying = true; } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Respawning them failed: " + ex.Message)); } } } private static bool IsVanillaHelp(string s) { if (!string.IsNullOrEmpty(s)) { if (s.IndexOf("TO CHAT", StringComparison.OrdinalIgnoreCase) < 0 && s.IndexOf("CARDS TO SPAWN THEM", StringComparison.OrdinalIgnoreCase) < 0 && s.IndexOf("CARDS TO PICK THEM", StringComparison.OrdinalIgnoreCase) < 0) { return s == HelpText; } return true; } return false; } private static bool HideVanillaHelp(FontHolder found) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) int num = 0; TMP_Text[] array = Resources.FindObjectsOfTypeAll<TMP_Text>(); Scene scene; foreach (TMP_Text val in array) { if ((Object)(object)val == (Object)null) { continue; } scene = ((Component)val).gameObject.scene; if (((Scene)(ref scene)).IsValid() && IsVanillaHelp(val.text)) { if ((Object)(object)found.Font == (Object)null) { found.Font = val.font; } val.text = ""; ((Behaviour)val).enabled = false; HideHelpBar(val.transform); num++; } } Text[] array2 = Resources.FindObjectsOfTypeAll<Text>(); foreach (Text val2 in array2) { if (!((Object)(object)val2 == (Object)null)) { scene = ((Component)val2).gameObject.scene; if (((Scene)(ref scene)).IsValid() && IsVanillaHelp(val2.text)) { val2.text = ""; ((Behaviour)val2).enabled = false; HideHelpBar(((Component)val2).transform); num++; } } } TextMesh[] array3 = Resources.FindObjectsOfTypeAll<TextMesh>(); foreach (TextMesh val3 in array3) { if ((Object)(object)val3 == (Object)null) { continue; } scene = ((Component)val3).gameObject.scene; if (((Scene)(ref scene)).IsValid() && IsVanillaHelp(val3.text)) { val3.text = ""; Renderer component = ((Component)val3).GetComponent<Renderer>(); if ((Object)(object)component != (Object)null) { component.enabled = false; } HideHelpBar(((Component)val3).transform); num++; } } return num > 0; } private static void HideHelpBar(Transform text) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) BetterSandboxPlugin.Log.LogInfo((object)("Hiding the game's sandbox help text at " + PathOf(text) + ".")); Transform parent = text.parent; if ((Object)(object)parent == (Object)null) { return; } List<Component> list = new List<Component>(((Component)parent).GetComponents<Component>()); if (parent.childCount <= 6) { foreach (Transform item in parent) { Transform val = item; if ((Object)(object)val != (Object)(object)text) { list.AddRange(((Component)val).GetComponents<Component>()); } } } if ((Object)(object)parent.parent != (Object)null) { list.AddRange(((Component)parent.parent).GetComponents<Component>()); } foreach (Component item2 in list) { Color? val2 = null; Graphic val3 = (Graphic)(object)((item2 is Graphic) ? item2 : null); if (val3 != null && !(item2 is TMP_Text) && !(item2 is Text)) { val2 = val3.color; } else { SpriteRenderer val4 = (SpriteRenderer)(object)((item2 is SpriteRenderer) ? item2 : null); if (val4 != null) { val2 = val4.color; } else { MeshRenderer val5 = (MeshRenderer)(object)((item2 is MeshRenderer) ? item2 : null); if (val5 != null && (Object)(object)item2.GetComponent<TMP_Text>() == (Object)null && (Object)(object)item2.GetComponent<TextMesh>() == (Object)null && (Object)(object)((Renderer)val5).sharedMaterial != (Object)null && ((Renderer)val5).sharedMaterial.HasProperty("_Color")) { val2 = ((Renderer)val5).sharedMaterial.color; } } } if (!val2.HasValue) { continue; } Color value = val2.Value; if (value.a < 0.2f || 0.299f * value.r + 0.587f * value.g + 0.114f * value.b > 0.3f) { continue; } Behaviour val6 = (Behaviour)(object)((item2 is Behaviour) ? item2 : null); if (val6 != null) { val6.enabled = false; } else { Renderer val7 = (Renderer)(object)((item2 is Renderer) ? item2 : null); if (val7 != null) { val7.enabled = false; } } BetterSandboxPlugin.Log.LogInfo((object)("Hid its bar: " + PathOf(item2.transform) + " (" + ((object)item2).GetType().Name + ").")); } } private static string PathOf(Transform t) { List<string> list = new List<string>(); Transform val = t; while ((Object)(object)val != (Object)null) { list.Insert(0, ((Object)val).name); val = val.parent; } return string.Join("/", list); } internal void CloseAll() { hub.Close(); if (menuOpen) { CloseMenu(); } mapPicker.Close(); } internal void OpenHub() { if (InSandbox) { if (menuOpen) { CloseMenu(); } mapPicker.Close(); hub.Open(); } } internal void OpenCardMenu() { hub.Close(); mapPicker.Close(); OpenMenu(); } private void OpenMenu() { if ((Object)(object)ToggleCardsMenuHandler.instance == (Object)null || (Object)(object)ToggleCardsMenuHandler.cardMenuCanvas == (Object)null || ToggleCardsMenuHandler.cardObjs.Count == 0) { BetterSandboxPlugin.Log.LogWarning((object)"The card menu isn't built yet. Open Toggle Cards once in the main menu, or wait a moment."); return; } if (ToggleCardsMenuHandler.menuOpenFromOutside) { BetterSandboxPlugin.Log.LogInfo((object)"Another mod has the card menu open; close it first."); return; } giveActions = ((IEnumerable<GameObject>)ToggleCardsMenuHandler.cardObjs.Keys.ToList()).Select((Func<GameObject, Action>)delegate(GameObject obj) { string key = ((Object)obj).name; return delegate { Give(key); }; }).ToArray(); ToggleCardsMenuHandler.Open(false, true, giveActions, (string[])null); menuOpen = true; foreach (GameObject key2 in ToggleCardsMenuHandler.cardObjs.Keys) { if ((Object)(object)key2 != (Object)null && (Object)(object)key2.GetComponent<RightClickTake>() == (Object)null) { key2.AddComponent<RightClickTake>(); } } if (!cardGiveMode) { ApplyCardClickMode(); } Target(); HideNamed(ToggleCardsMenuHandler.cardMenuCanvas, "CardsPresetPanel", hiddenInCardMenu); if (panel != null && panel.Alive) { ShowPanel(); } else { buildPanelAtFrame = Time.frameCount + 2; } } private void BuildPanel() { try { panel = CardPanel.TryBuild(this); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Sandbox buttons could not be built: " + ex)); } if (panel != null) { ShowPanel(); } } private void ShowPanel() { panel.Show(show: true); panel.Refresh(); if (!hintShown) { hintShown = true; panel.Flash("RIGHT-CLICK TAKES ONE", 3f); } } internal void CloseMenu() { if (ToggleCardsMenuHandler.menuOpenFromOutside) { ToggleCardsMenuHandler.Close(); } AfterClosed(); } internal void CardMenuBack() { CloseMenu(); OpenHub(); } private void AfterClosed() { if (menuOpen) { menuOpen = false; buildPanelAtFrame = -1; if (ToggleCardsMenuHandler.menuOpenFromOutside && !InSandbox) { ToggleCardsMenuHandler.Close(); } panel?.CloseDropdown(); panel?.Show(show: false); RestoreHidden(hiddenInCardMenu); SetCardCategoryControls(show: true); } } internal void ToggleCardClickMode() { if (cardGiveMode && !IsHostOrOffline) { panel?.Flash("HOST ONLY"); return; } cardGiveMode = !cardGiveMode; ApplyCardClickMode(); panel?.Flash(cardGiveMode ? "CLICK GIVES CARDS" : "CLICK TURNS CARDS ON/OFF"); } private void ApplyCardClickMode() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown if (cardGiveMode && giveActions != null && giveActions.Length == ToggleCardsMenuHandler.cardObjs.Count) { ToggleCardsMenuHandler.SetAllButtonActions(giveActions); } else { ToggleCardsMenuHandler.ResetCardActions(); } foreach (KeyValuePair<GameObject, Action> item in ToggleCardsMenuHandler.cardObjs.ToList()) { if ((Object)(object)item.Key == (Object)null) { continue; } Button component = item.Key.GetComponent<Button>(); if (!((Object)(object)component == (Object)null)) { Action action = item.Value; ButtonClickedEvent val = new ButtonClickedEvent(); ((UnityEvent)val).AddListener((UnityAction)delegate { action(); }); component.onClick = val; } } SetCardCategoryControls(!cardGiveMode); } private static void SetCardCategoryControls(bool show) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown GameObject cardMenuCanvas = ToggleCardsMenuHandler.cardMenuCanvas; if ((Object)(object)cardMenuCanvas == (Object)null) { return; } Transform val = cardMenuCanvas.transform.Find("CardMenu/Top/Categories/ButtonsScroll/Viewport/Content"); if ((Object)(object)val != (Object)null) { foreach (Transform item in val) { Transform val2 = item.Find("Toggle"); if ((Object)(object)val2 != (Object)null) { ((Component)val2).gameObject.SetActive(show); } } } Transform val3 = cardMenuCanvas.transform.Find("CardMenu/ScrollViews"); if (!((Object)(object)val3 != (Object)null)) { return; } foreach (Transform item2 in val3) { Transform val4 = item2; Transform val5 = val4.Find("Darken"); if ((Object)(object)val5 != (Object)null) { ((Component)val5).gameObject.SetActive(show && !CardManager.IsCategoryActive(((Object)val4).name)); } } } internal static void HideNamed(GameObject canvas, string name, List<GameObject> hidden) { if ((Object)(object)canvas == (Object)null) { return; } Transform val = ((IEnumerable<Transform>)canvas.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name == name)); if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(false); if (!hidden.Contains(((Component)val).gameObject)) { hidden.Add(((Component)val).gameObject); } } } internal static void RestoreHidden(List<GameObject> hidden) { foreach (GameObject item in hidden) { if ((Object)(object)item != (Object)null) { item.SetActive(true); } } hidden.Clear(); } internal void OpenMapMenu() { hub.Close(); if (menuOpen) { CloseMenu(); } mapPicker.Open(); } internal void MapMenuBack() { mapPicker.Close(); OpenHub(); } internal static List<Player> Players() { return (from p in PlayerManager.instance?.players?.Where((Player p) => (Object)(object)p != (Object)null && (Object)(object)p.data != (Object)null) orderby p.playerID select p).ToList() ?? new List<Player>(); } internal static bool IsBot(Player p) { try { if ((Object)(object)p == (Object)null || (Object)(object)p.data == (Object)null) { return false; } if (CharacterDataExtension.GetAdditionalData(p.data).isAIMinion) { return true; } if ((Object)(object)((Component)p).GetComponent("BotBrain") != (Object)null) { return true; } if (Offline && (Object)(object)p.data.input != (Object)null && p.data.input.controlledElseWhere) { return true; } MonoBehaviour[] componentsInChildren = ((Component)p).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if ((Object)(object)val != (Object)null && ((object)val).GetType().Name.StartsWith("PlayerAI")) { return true; } } return false; } catch { return false; } } internal static string PlayerName(Player p) { if ((Object)(object)p == (Object)null) { return "NOBODY"; } if (IsBot(p)) { return "BOT " + (p.playerID + 1); } try { Player owner = (((Object)(object)p.data.view != (Object)null) ? p.data.view.Owner : null); Player obj = owner; string text = ((obj != null) ? obj.NickName : null); bool flag = Players().Count((Player x) => !IsBot(x) && (Object)(object)x.data.view != (Object)null && x.data.view.Owner == owner) > 1; if (!string.IsNullOrEmpty(text) && !flag) { return text.Trim().ToUpper(); } } catch { } return "PLAYER " + (p.playerID + 1); } internal static string PlayerColorHex(Player p) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) try { return ColorUtility.ToHtmlStringRGB(PlayerSkinBank.GetPlayerSkinColors(PlayerExtensions.colorID(p)).winText); } catch { return "FFFFFF"; } } internal static string ColoredName(Player p) { if (!((Object)(object)p == (Object)null)) { return "<color=#" + PlayerColorHex(p) + ">" + PlayerName(p) + "</color>"; } return "NOBODY"; } internal Player Target() { if (targetID == -2) { return null; } List<Player> source = Players(); Player val = ((IEnumerable<Player>)source).FirstOrDefault((Func<Player, bool>)((Player x) => x.playerID == targetID)); if ((Object)(object)val == (Object)null) { val = ((IEnumerable<Player>)source).FirstOrDefault((Func<Player, bool>)((Player x) => (Object)(object)x.data.view != (Object)null && x.data.view.IsMine && !IsBot(x))) ?? source.FirstOrDefault(); targetID = (((Object)(object)val != (Object)null) ? val.playerID : (-1)); } return val; } internal List<Player> TargetPlayers() { if (targetID == -2) { return Players(); } Player val = Target(); if (!((Object)(object)val == (Object)null)) { return new List<Player> { val }; } return new List<Player>(); } internal string TargetLabel() { if (targetID == -2) { return "EVERYONE"; } Player val = Target(); if (!((Object)(object)val == (Object)null)) { return ColoredName(val); } return "NOBODY YET"; } internal void SetTarget(int playerID) { targetID = playerID; } internal void CycleTarget() { List<Player> list = Players(); if (list.Count == 0) { return; } if (targetID == -2) { targetID = list[0].playerID; return; } int num = list.FindIndex((Player x) => x.playerID == targetID); targetID = ((num == list.Count - 1) ? (-2) : list[(num + 1) % list.Count].playerID); } internal string AddBot() { PlayerAssigner instance = PlayerAssigner.instance; if (!Offline) { return "BOTS ARE OFFLINE ONLY"; } if ((Object)(object)instance == (Object)null) { return "CAN'T ADD BOTS HERE"; } if (instance.players.Count >= instance.maxPlayers) { return $"FULL ({instance.maxPlayers} PLAYERS)"; } ((MonoBehaviour)instance).StartCoroutine(instance.CreatePlayer((InputDevice)null, true)); BetterSandboxPlugin.Log.LogInfo((object)"Added a bot."); return "BOT ADDED"; } internal string KillEveryone() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (!Offline) { return "OFFLINE ONLY"; } int num = 0; foreach (Player item in Players()) { if (!item.data.dead && item.data.isPlaying && !((Object)(object)item.data.view == (Object)null)) { try { item.data.view.RPC("RPCA_Die", (RpcTarget)0, new object[1] { Vector2.up * 5f }); num++; } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Couldn't kill " + PlayerName(item) + ": " + ex.Message)); } } } if (num > 0) { BetterSandboxPlugin.Log.LogInfo((object)$"Killed {num} players."); } return num switch { 1 => "1 PLAYER KILLED", 0 => "NOBODY TO KILL", _ => num + " PLAYERS KILLED", }; } private void WatchCardBars() { if (!InSandbox || !Offline) { barsRebuilt = false; } else { if (Time.unscaledTime < nextBarCheck || roundRunning || changingMap) { return; } nextBarCheck = Time.unscaledTime + 0.5f; if (!(CardBarsField?.GetValue(CardBarHandler.instance) is CardBar[] array)) { return; } int count = Players().Count; if (count != 0 && (array.Length < count || (barsRebuilt && array.Length != count))) { try { RwfScore.RebuildCardBars(); barsRebuilt = true; ((MonoBehaviour)this).StartCoroutine(RefillCardBarsSoon(count)); } catch (Exception ex) { nextBarCheck = Time.unscaledTime + 30f; BetterSandboxPlugin.Log.LogInfo((object)("Couldn't add card bars for the extra players: " + ex.Message)); } } } } private IEnumerator RefillCardBarsSoon(int players) { yield return null; yield return null; if (InSandbox) { ResyncCardBars(0); BetterSandboxPlugin.Log.LogInfo((object)$"Card bars rebuilt for {players} players."); } } internal string RemoveBot(int playerID) { Player val = ((IEnumerable<Player>)Players()).FirstOrDefault((Func<Player, bool>)((Player p) => p.playerID == playerID && IsBot(p))); if ((Object)(object)val == (Object)null) { return "THAT BOT IS ALREADY GONE"; } string text = PlayerName(val); return RemovePlayers(new List<Player> { val }) ?? (text + " REMOVED"); } internal string RemoveAllBots() { List<Player> list = Players().Where(IsBot).ToList(); if (list.Count == 0) { return "NO BOTS"; } object obj = RemovePlayers(list); if (obj == null) { if (list.Count != 1) { return list.Count + " BOTS REMOVED"; } obj = "1 BOT REMOVED"; } return (string)obj; } private string RemovePlayers(List<Player> gone) { if (!Offline) { return "OFFLINE ONLY"; } if (roundRunning || changingMap) { return "WAIT FOR THE ROUND TO END"; } PlayerManager instance = PlayerManager.instance; if ((Object)(object)instance == (Object)null || gone.Count == 0) { return "NOBODY TO REMOVE"; } Player keepTarget = Target(); int firstChanged = gone.Min((Player p) => p.playerID); foreach (Player item in gone) { BetterSandboxPlugin.Log.LogInfo((object)$"Removing {PlayerName(item)} (player {item.playerID + 1})."); heldDead.Remove(item); try { PlayerAssigner.instance?.players.Remove(item.data); } catch { } instance.players.Remove(item); try { if ((Object)(object)item.data.view != (Object)null) { PhotonNetwork.Destroy(item.data.view); } else { Object.Destroy((Object)(object)((Component)item).gameObject); } } catch (Exception ex) { BetterSandboxPlugin.Log.LogDebug((object)("Photon destroy: " + ex.Message)); if ((Object)(object)item != (Object)null) { Object.Destroy((Object)(object)((Component)item).gameObject); } } } RenumberPlayers(firstChanged, keepTarget, gone); return null; } private void RenumberPlayers(int firstChanged, Player keepTarget, List<Player> gone) { List<Player> list = (from p in PlayerManager.instance.players where (Object)(object)p != (Object)null && !gone.Contains(p) orderby p.playerID select p).ToList(); int num = TeamCount(); Dictionary<Player, int> dictionary = list.ToDictionary((Player p) => p, (Player p) => p.teamID); for (int num2 = 0; num2 < list.Count; num2++) { Player val = list[num2]; if (val.playerID != num2) { int num3 = num2 % num; BetterSandboxPlugin.Log.LogInfo((object)$"{PlayerName(val)} is now player {num2 + 1} (team {num3})."); try { val.AssignTeamID(num3); val.AssignPlayerID(num2); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Renumbering failed: " + ex.Message)); val.teamID = num3; val.playerID = num2; } } } if (teamPoints.Count > 0 || teamRounds.Count > 0) { Dictionary<int, int> dictionary2 = new Dictionary<int, int>(); Dictionary<int, int> dictionary3 = new Dictionary<int, int>(); foreach (Player item in list) { if (teamPoints.TryGetValue(dictionary[item], out var value)) { dictionary2[item.teamID] = value; } if (teamRounds.TryGetValue(dictionary[item], out var value2)) { dictionary3[item.teamID] = value2; } } teamPoints.Clear(); foreach (KeyValuePair<int, int> item2 in dictionary2) { teamPoints[item2.Key] = item2.Value; } teamRounds.Clear(); foreach (KeyValuePair<int, int> item3 in dictionary3) { teamRounds[item3.Key] = item3.Value; } if (scoreShown) { ShowScore(); } } ResyncCardBars(firstChanged); if (targetID != -2) { targetID = (((Object)(object)keepTarget != (Object)null && list.Contains(keepTarget)) ? keepTarget.playerID : (-1)); } seenPlayers.Clear(); foreach (Player item4 in list) { seenPlayers.Add(item4.playerID); } joinChecks.Clear(); } private static int TeamCount() { try { if (Chainloader.PluginInfos.ContainsKey("io.olavim.rounds.rwf")) { return Math.Max(1, RwfScore.MaxTeams()); } } catch { } return 2; } private static void ResyncCardBars(int from) { if (!(CardBarsField?.GetValue(CardBarHandler.instance) is CardBar[] array)) { return; } List<Player> source = Players(); int i; for (i = Math.Max(0, from); i < array.Length; i++) { if ((Object)(object)array[i] == (Object)null) { continue; } try { array[i].ClearBar(); } catch { } Player val = ((IEnumerable<Player>)source).FirstOrDefault((Func<Player, bool>)((Player p) => p.playerID == i)); if ((Object)(object)val == (Object)null) { continue; } foreach (CardInfo item in val.data.currentCards.ToList()) { try { Cards.SilentAddToCardBar(i, item, "", 0f, 0f); } catch { } } } } private bool Busy() { if (Time.unscaledTime < busyUntil) { Flash("ONE MOMENT..."); return true; } return false; } private int TargetCode(List<Player> targets) { if (targetID != -2) { return targets[0].playerID; } return -2; } private void Give(string key) { CardInfo cardInfoWithName = CardManager.GetCardInfoWithName(key); List<Player> list = TargetPlayers(); if (!((Object)(object)cardInfoWithName == (Object)null)) { if (list.Count == 0) { Flash("JOIN FIRST"); } else if (!Busy()) { Request(Act.Give, TargetCode(list), key); Flash("+ " + cardInfoWithName.cardName.ToUpper() + ToWhom); } } } internal string GiveRandomCard() { List<Player> list = TargetPlayers(); if (list.Count == 0) { return "JOIN FIRST"; } if (Time.unscaledTime < busyUntil) { return "ONE MOMENT..."; } string text = null; foreach (Player item in list) { string text2 = RandomCardKey(item); if (text2 != null) { Request(Act.Give, item.playerID, text2); text = text2; } } if (text == null) { return "NO CARDS FOUND"; } if (list.Count <= 1) { return "+ " + (CardManager.GetCardInfoWithName(text)?.cardName ?? text).ToUpper(); } return "+ A RANDOM CARD FOR EVERYONE"; } private static string RandomCardKey(Player p) { List<string> list = (from kv in CardManager.cards where kv.Value != null && (Object)(object)kv.Value.cardInfo != (Object)null && kv.Value.enabled select kv.Key).ToList(); List<string> list2 = list.Where(delegate(string k) { try { return Cards.instance.PlayerIsAllowedCard(p, CardManager.cards[k].cardInfo); } catch { return true; } }).ToList(); List<string> list3 = ((list2.Count > 0) ? list2 : list); if (list3.Count == 0) { list3 = (from kv in CardManager.cards where (Object)(object)kv.Value?.cardInfo != (Object)null select kv.Key).ToList(); } if (list3.Count != 0) { return list3[Random.Range(0, list3.Count)]; } return null; } internal void TakeFromMenu(string key) { if (!menuOpen || !cardGiveMode) { return; } CardInfo card = CardManager.GetCardInfoWithName(key); List<Player> list = TargetPlayers(); if (!((Object)(object)card == (Object)null) && list.Count != 0) { if (!list.Any((Player p) => HasCard(p, card))) { Flash((list.Count > 1) ? "NOBODY HAS IT" : "DOESN'T HAVE IT"); } else if (!Busy()) { Request(Act.Take, TargetCode(list), key); Flash("- " + card.cardName.ToUpper() + FromWhom); } } } private static bool HasCard(Player p, CardInfo card) { return p.data.currentCards.Any((CardInfo c) => (Object)(object)c != (Object)null && ((Object)c).name == ((Object)card).name); } internal string UndoLast() { List<Player> list = TargetPlayers(); if (list.Count == 0) { return "JOIN FIRST"; } if (list.All((Player p) => p.data.currentCards.Count == 0)) { return "NO CARDS"; } if (Time.unscaledTime < busyUntil) { return "ONE MOMENT..."; } Request(Act.Undo, TargetCode(list), ""); if (list.Count > 1) { return "- EVERYONE'S LAST CARD"; } List<CardInfo> currentCards = list[0].data.currentCards; return "- " + (currentCards[currentCards.Count - 1]?.cardName ?? "CARD").ToUpper(); } internal bool RemoveCardAt(int playerID, int index, string cardName, out string message) { Player val = ((IEnumerable<Player>)Players()).FirstOrDefault((Func<Player, bool>)((Player x) => x.playerID == playerID)); message = ""; if ((Object)(object)val == (Object)null) { message = "THEY LEFT"; return false; } if (Time.unscaledTime < busyUntil) { message = "ONE MOMENT..."; return false; } string key = index + "|" + cardName; int num = CardIndex(val, key); if (num < 0) { message = "DOESN'T HAVE IT"; return false; } message = "- " + (val.data.currentCards[num]?.cardName ?? "CARD").ToUpper(); busyUntil = Time.unscaledTime + 0.35f; Request(Act.TakeAt, playerID, key); return true; } private static int CardIndex(Player p, string key) { List<CardInfo> currentCards = p.data.currentCards; string[] array = (key ?? "").Split(new char[1] { '|' }, 2); int.TryParse(array[0], out var result); string text = ((array.Length > 1) ? array[1] : null); if (result >= 0 && result < currentCards.Count && (Object)(object)currentCards[result] != (Object)null && (text == null || ((Object)currentCards[result]).name == text)) { return result; } if (text == null) { return -1; } for (int num = currentCards.Count - 1; num >= 0; num--) { if ((Object)(object)currentCards[num] != (Object)null && ((Object)currentCards[num]).name == text) { return num; } } return -1; } internal string ClearCards() { List<Player> list = TargetPlayers(); if (list.Count == 0) { return "JOIN FIRST"; } if (list.All((Player p) => p.data.currentCards.Count == 0)) { return "NO CARDS"; } if (Time.unscaledTime < busyUntil) { return "ONE MOMENT..."; } Request(Act.Clear, TargetCode(list), ""); if (list.Count <= 1) { return "CARDS CLEARED"; } return "EVERYONE'S CARDS CLEARED"; } internal string ChangeMap(string key) { if (ChangingMap) { return "LOADING MAP..."; } Request(Act.Map, -1, key ?? ""); if (!IsHostOrOffline) { return "ASKED THE HOST"; } return "LOADING " + MapLabel(key); } private void Request(Act act, int playerID, string key) { if (IsHostOrOffline) { Do(act, playerID, key); return; } NetworkingManager.RPC_Others(typeof(SandboxController), "RPCA_Request", new object[3] { (int)act, playerID, key ?? "" }); } [UnboundRPC] private static void RPCA_Request(int act, int playerID, string key) { if (PhotonNetwork.IsMasterClient && InSandbox && !((Object)(object)Instance == (Object)null)) { Instance.Do((Act)act, playerID, key); } } private void Do(Act act, int playerID, string key) { if (act == Act.Map) { if (!ChangingMap) { ((MonoBehaviour)this).StartCoroutine(MapRoutine(string.IsNullOrEmpty(key) ? null : key)); } return; } List<Player> obj = ((playerID == -2) ? Players() : (from x in Players() where x.playerID == playerID select x).ToList()); CardInfo card = ((string.IsNullOrEmpty(key) || act == Act.TakeAt) ? null : CardManager.GetCardInfoWithName(key)); foreach (Player item in obj) { DoFor(act, item, card, key); } } private void DoFor(Act act, Player p, CardInfo card, string key) { switch (act) { case Act.TakeAt: { int num = CardIndex(p, key); if (num >= 0) { string text = p.data.currentCards[num]?.cardName ?? "a card"; try { Cards.instance.RemoveCardFromPlayer(p, num, HasCardBar(p)); } catch (Exception ex5) { BetterSandboxPlugin.Log.LogWarning((object)("Taking " + text + " failed: " + ex5.Message)); } busyUntil = Time.unscaledTime + 0.35f; BetterSandboxPlugin.Log.LogInfo((object)$"Took {text} (card {num + 1}) from {PlayerName(p)}."); } break; } case Act.Give: if (!((Object)(object)card == (Object)null)) { bool flag = HasCardBar(p); try { Cards.instance.AddCardToPlayer(p, card, false, "", 0f, 0f, flag); } catch (Exception ex2) { BetterSandboxPlugin.Log.LogWarning((object)("Giving " + card.cardName + " to " + PlayerName(p) + " failed: " + ex2.Message)); break; } BetterSandboxPlugin.Log.LogInfo((object)("Gave " + card.cardName + " to " + PlayerName(p) + (flag ? "" : " (they have no card bar, so it isn't shown there)") + ".")); } break; case Act.Take: if (!((Object)(object)card == (Object)null) && HasCard(p, card)) { try { Cards.instance.RemoveCardFromPlayer(p, card, (SelectionType)2, HasCardBar(p)); } catch (Exception ex3) { BetterSandboxPlugin.Log.LogWarning((object)("Taking " + card.cardName + " failed: " + ex3.Message)); } busyUntil = Time.unscaledTime + 0.35f; BetterSandboxPlugin.Log.LogInfo((object)("Took " + card.cardName + " from " + PlayerName(p) + ".")); } break; case Act.Undo: if (p.data.currentCards.Count != 0) { try { Cards.instance.RemoveCardFromPlayer(p, p.data.currentCards.Count - 1, HasCardBar(p)); } catch (Exception ex4) { BetterSandboxPlugin.Log.LogWarning((object)("Undo failed: " + ex4.Message)); } busyUntil = Time.unscaledTime + 0.35f; } break; case Act.Clear: if (p.data.currentCards.Count != 0) { try { Cards.instance.RemoveAllCardsFromPlayer(p, HasCardBar(p)); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Clear failed: " + ex.Message)); } busyUntil = Time.unscaledTime + 0.2f; BetterSandboxPlugin.Log.LogInfo((object)("Cleared " + PlayerName(p) + "'s cards.")); } break; case Act.Map: break; } } internal static bool HasCardBar(Player p) { try { return CardBarsField?.GetValue(CardBarHandler.instance) is CardBar[] array && (Object)(object)p != (Object)null && p.playerID >= 0 && p.playerID < array.Length && (Object)(object)array[p.playerID] != (Object)null; } catch { return false; } } private IEnumerator MapRoutine(string key) { if (!((Object)(object)MapManager.instance == (Object)null) && !((Object)(object)PlayerManager.instance == (Object)null)) { changingMap = true; RefreshPanels(); bool offline = Offline; if (offline) { PlayerManager.instance.SetPlayersSimulated(false); } MapLoad load = new MapLoad { Key = key }; yield return LoadMap(load); if (load.Ok) { yield return CallInMap(load, offline); } else { RestorePlayers(offline); Flash("MAP DIDN'T LOAD"); } changingMap = false; RefreshPanels(); } } private IEnumerator LoadMap(MapLoad load) { MapManager mm = MapManager.instance; if (load.Key == null) { load.Key = RandomMapKey(mm); } load.Label = MapLabel(load.Key); MapWrapper old = mm.currentMap; load.StartedAt = Time.unscaledTime; bool flag = false; try { if (!string.IsNullOrEmpty(load.Key)) { mm.forceMap = load.Key; } mm.LoadNextLevel(false, true); flag = true; } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Map load failed: " + ex)); } finally { mm.forceMap = ""; } if (flag) { float giveUp = Time.unscaledTime + 10f; while (mm.currentMap == old && Time.unscaledTime < giveUp) { yield return null; } load.Ok = mm.currentMap != old; if (!load.Ok) { BetterSandboxPlugin.Log.LogWarning((object)(load.Label + " didn't finish loading within 10 seconds.")); } } } private IEnumerator CallInMap(MapLoad load, bool offline) { MapManager mm = MapManager.instance; yield return (object)new WaitForSecondsRealtime(0.3f); mm.CallInNewMapAndMovePlayers(mm.currentLevelID); PlayerManager.instance.RevivePlayers(); lastMapKey = load.Key; BetterSandboxPlugin.Log.LogInfo((object)("Changed map to " + load.Label + ".")); Flash("MAP: " + load.Label); yield return WaitForMoves(offline); while (Time.unscaledTime - load.StartedAt < 2.3f) { yield return null; } } private IEnumerator WaitForMoves(bool offline) { float t0 = Time.unscaledTime; while (Time.unscaledTime - t0 < 3f && Players().All((Player p) => p.data.isPlaying)) { yield return null; } while (Time.unscaledTime - t0 < 10f && Players().Any((Player p) => !p.data.isPlaying)) { yield return null; } yield return (object)new WaitForSecondsRealtime(0.2f); RestorePlayers(offline); } private static void RestorePlayers(bool offline) { PlayerManager instance = PlayerManager.instance; if ((Object)(object)instance == (Object)null) { return; } if (offline) { instance.SetPlayersSimulated(true); instance.SetPlayersPlaying(true); } foreach (Player item in Players()) { if (!offline && ((Object)(object)item.data.view == (Object)null || !item.data.view.IsMine)) { continue; } PlayerVelocity playerVel = item.data.playerVel; bool flag = (Object)(object)playerVel == (Object)null || VelSimulated == null || (bool)VelSimulated.GetValue(playerVel); bool flag2 = (Object)(object)playerVel != (Object)null && VelKinematic != null && (bool)VelKinematic.GetValue(playerVel); GeneralInput input = item.data.input; bool flag3 = (Object)(object)input == (Object)null || ((Behaviour)input).enabled; if (!(flag && !flag2 && item.data.isPlaying && flag3)) { BetterSandboxPlugin.Log.LogWarning((object)$"{PlayerName(item)} was still frozen after the map change (playing={item.data.isPlaying}, simulated={flag}, kinematic={flag2}, input={flag3}); unfreezing."); if ((Object)(object)playerVel != (Object)null) { VelSimulated?.SetValue(playerVel, true); VelKinematic?.SetValue(playerVel, false); } item.data.isPlaying = true; if ((Object)(object)input != (Object)null) { ((Behaviour)input).enabled = true; } } } } private string RandomMapKey(MapManager mm) { string[] array = (mm.levels ?? new string[0]).Where((string l) => !string.IsNullOrEmpty(l)).Distinct().ToArray(); if (array.Length == 0) { return null; } string current = lastMapKey; if (current == null && mm.currentLevelID >= 0 && mm.currentLevelID < mm.levels.Length) { current = mm.levels[mm.currentLevelID]; } string[] array2 = ((array.Length > 1) ? array.Where((string l) => l != current).ToArray() : array); if (array2.Length == 0) { array2 = array; } return array2[Random.Range(0, array2.Length)]; } internal static string MapLabel(string key) { if (string.IsNullOrEmpty(key)) { return "A RANDOM MAP"; } string text = key; try { if (LevelManager.levels != null && LevelManager.levels.TryGetValue(key, out var value) && value != null && !string.IsNullOrEmpty(value.name)) { text = value.name; } text = LevelManager.GetVisualName(text); } catch { } string text2 = text.Replace('_', ' ').Trim().ToUpper(); if (text2.Length <= 20) { return text2; } return text2.Substring(0, 19) + "."; } private static void TurnOffRoundSwitches() { ConfigEntry<bool>[] array = new ConfigEntry<bool>[7] { BetterSandboxPlugin.SwitchMapWhenOneLeft, BetterSandboxPlugin.RandomCardEveryone, BetterSandboxPlugin.RandomCardLosers, BetterSandboxPlugin.KeepScoreWhenOneLeft, BetterSandboxPlugin.RoundPick, BetterSandboxPlugin.RoundCardEveryone, BetterSandboxPlugin.RoundCardLosers }; foreach (ConfigEntry<bool> val in array) { if (val.Value) { val.Value = false; } } } internal string RespawnEveryone() { if (!Offline) { return "OFFLINE ONLY"; } if (roundCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(roundCoroutine); roundCoroutine = null; } roundRunning = false; changingMap = false; heldDead.Clear(); PlayerManager instance = PlayerManager.instance; if ((Object)(object)instance == (Object)null || (Object)(object)MapManager.instance == (Object)null) { return "NOBODY TO RESPAWN"; } instance.SetPlayersSimulated(false); try { instance.MovePlayers(MapManager.instance.GetSpawnPoints()); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Respawn move failed: " + ex.Message)); } instance.RevivePlayers(); ((MonoBehaviour)this).StartCoroutine(Safe(WaitForMoves(offline: true))); return "EVERYONE RESPAWNED"; } private void ReleaseHeldDead() { if (heldDead.Count == 0 || roundRunning || RoundModeOn) { return; } foreach (Player item in heldDead) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item.data == (Object)null) && item.data.dead && !((Object)(object)GM_Test.instance == (Object)null) && !(DelayReviveMethod == null)) { try { ((MonoBehaviour)GM_Test.instance).StartCoroutine((IEnumerator)DelayReviveMethod.Invoke(GM_Test.instance, new object[1] { item })); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Revive failed: " + ex.Message)); } } } heldDead.Clear(); } internal bool OnPlayerDied(Player player) { if (!RoundModeOn || !Offline || !InSandbox) { return false; } if ((Object)(object)player != (Object)null && !heldDead.Contains(player)) { heldDead.Add(player); } if (!roundRunning && (from p in Players() where !p.data.dead select p.teamID).Distinct().Count() <= 1) { roundCoroutine = ((MonoBehaviour)this).StartCoroutine(RoundEndGuarded()); } return true; } private IEnumerator RoundEndGuarded() { yield return Safe(RoundEnd()); if (roundRunning) { BetterSandboxPlugin.Log.LogWarning((object)"The round end stopped part-way; bringing everyone back."); roundCoroutine = null; RespawnEveryone(); } roundCoroutine = null; } private IEnumerator RoundEnd() { roundRunning = true; bool switchMap = BetterSandboxPlugin.SwitchMapWhenOneLeft.Value; bool cardsEveryone = BetterSandboxPlugin.RandomCardEveryone.Value; bool cardsLosers = BetterSandboxPlugin.RandomCardLosers.Value; bool value = BetterSandboxPlugin.KeepScoreWhenOneLeft.Value; bool roundPick = value && BetterSandboxPlugin.RoundPick.Value; bool roundEveryone = value && BetterSandboxPlugin.RoundCardEveryone.Value; bool roundLosers = value && BetterSandboxPlugin.RoundCardLosers.Value; List<Player> standing = (from p in Players() where !p.data.dead select p).ToList(); int winningTeam = ((standing.Select((Player p) => p.teamID).Distinct().Count() == 1) ? standing[0].teamID : (-1)); bool pointScored = value && winningTeam >= 0; BetterSandboxPlugin.Log.LogInfo((object)("Last one standing: " + ((winningTeam >= 0) ? ("team " + winningTeam) : "nobody") + ". Switch map " + On(switchMap) + ", random card for everyone " + On(cardsEveryone) + ", for losers " + On(cardsLosers) + ", keep score " + On(value) + "; when a round is won: card pick " + On(roundPick) + ", random card for everyone " + On(roundEveryone) + ", for losers " + On(roundLosers) + ".")); yield return (object)new WaitForSecondsRealtime(1f); if (!InSandbox) { roundRunning = false; yield break; } CloseAll(); PlayerManager pm = PlayerManager.instance; pm.SetPlayersSimulated(false); try { TimeHandler.instance.DoSpeedUp(); } catch { } ScoreResult result = new ScoreResult(); if (pointScored) { yield return Safe(ScorePoint(winningTeam, standing[0], result)); } GiveRandomCards(winningTeam, cardsEveryone, cardsLosers); MapLoad load = new MapLoad(); if (switchMap) { changingMap = true; yield return Safe(LoadMap(load)); } if (result.RoundWon) { List<Player> list = (from p in Players() where p.teamID != winningTeam select p).ToList(); if (roundPick && list.Count > 0) { yield return Safe(PickPhase(list)); } GiveRandomCards(winningTeam, roundEveryone, roundLosers); } if (!InSandbox) { changingMap = false; roundRunning = false; yield break; } if (switchMap && load.Ok) { yield return Safe(CallInMap(load, offline: true)); } else { try { pm.MovePlayers(MapManager.instance.GetSpawnPoints()); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Respawn move failed: " + ex.Message)); } pm.RevivePlayers(); yield return Safe(WaitForMoves(offline: true)); } RestorePlayers(offline: true); heldDead.Clear(); changingMap = false; roundRunning = false; roundCoroutine = null; if (BetterSandboxPlugin.KeepScoreWhenOneLeft.Value) { ShowScore(); } RefreshPanels(); } private static string On(bool b) { if (!b) { return "off"; } return "on"; } private void GiveRandomCard(Player p) { try { string text = RandomCardKey(p); if (text != null) { Do(Act.Give, p.playerID, text); } } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Random card for " + PlayerName(p) + " failed: " + ex.Message)); } } private void GiveRandomCards(int winningTeam, bool everyone, bool losers) { if (!everyone && !losers) { return; } foreach (Player item in Players()) { int num = (everyone ? 1 : 0) + ((losers && item.teamID != winningTeam) ? 1 : 0); for (int i = 0; i < num; i++) { GiveRandomCard(item); } } } private IEnumerator PickPhase(List<Player> losers) { PlayerManager pm = PlayerManager.instance; bool botsAi = Chainloader.PluginInfos.ContainsKey("com.kanty.rounds.bots"); try { TimeHandler.instance.DoSpeedUp(); } catch { } yield return Safe(GameModeManager.TriggerHook("PickStart")); try { SetPlayersVisibleMethod?.Invoke(pm, new object[1] { false }); } catch { } foreach (Player p in losers) { if ((Object)(object)p == (Object)null || !InSandbox) { continue; } if (IsBot(p) && !botsAi) { GiveRandomCard(p); continue; } yield return Safe(GameModeManager.TriggerHook("PlayerPickStart")); try { CardChoiceVisuals.instance.Show(p.playerID, true); } catch (Exception ex) { BetterSandboxPlugin.Log.LogDebug((object)("Pick visuals: " + ex.Message)); } yield return Safe(CardChoice.instance.DoPick(1, p.playerID, (PickerType)1)); yield return Safe(GameModeManager.TriggerHook("PlayerPickEnd")); yield return (object)new WaitForSecondsRealtime(0.1f); } try { CardChoiceVisuals.instance.Hide(); } catch { } yield return Safe(GameModeManager.TriggerHook("PickEnd")); } private static int Setting(string name, int fallback) { try { IGameModeHandler handler = GameModeManager.GetHandler("Arms race"); object obj = default(object); if (((handler != null) ? handler.Settings : null) != null && handler.Settings.TryGetValue(name, ref obj) && obj is int num && num > 0) { return num; } } catch { } return fallback; } private static void EnsureScoreSettings() { try { IGameModeHandler currentHandler = GameModeManager.CurrentHandler; GameSettings val = ((currentHandler != null) ? currentHandler.Settings : null); if (val != null) { if (!val.ContainsKey("pointsToWinRound")) { val.Add("pointsToWinRound", (object)PointsToWinRound); } if (!val.ContainsKey("roundsToWinGame")) { val.Add("roundsToWinGame", (object)RoundsToWinGame); } } } catch (Exception ex) { BetterSandboxPlugin.Log.LogDebug((object)("Score settings: " + ex.Message)); } } private void EnsureTeams() { foreach (Player item in Players()) { if (!teamPoints.ContainsKey(item.teamID)) { teamPoints[item.teamID] = 0; } if (!teamRounds.ContainsKey(item.teamID)) { teamRounds[item.teamID] = 0; } } } private IEnumerator ScorePoint(int team, Player winner, ScoreResult result) { EnsureScoreSettings(); EnsureTeams(); teamPoints[team]++; bool roundWon = teamPoints[team] >= PointsToWinRound; if (roundWon) { teamRounds[team]++; } result.RoundWon = roundWon; BetterSandboxPlugin.Log.LogInfo((object)$"Team {team} wins a point: {teamPoints[team]}/{PointsToWinRound} points, {teamRounds[team]}/{RoundsToWinGame} rounds."); Dictionary<int, int> points = new Dictionary<int, int>(teamPoints); Dictionary<int, int> rounds = new Dictionary<int, int>(teamRounds); IEnumerator enumerator; try { enumerator = RwfScore.Sequence(points, rounds, team, roundWon); } catch (Exception) { enumerator = VanillaSequence(points, rounds, team, roundWon); } if (enumerator != null) { ((MonoBehaviour)this).StartCoroutine(Safe(enumerator)); } yield return (object)new WaitForSecondsRealtime(roundWon ? 2f : 1f); if (!roundWon) { yield break; } foreach (int item in teamPoints.Keys.ToList()) { teamPoints[item] = 0; } if (teamRounds[team] < RoundsToWinGame) { yield break; } try { Color winText = PlayerSkinBank.GetPlayerSkinColors(((Object)(object)winner != (Object)null) ? PlayerExtensions.colorID(winner) : team).winText; UIHandler.instance.DisplayScreenText(winText, "VICTORY!", 1f); } catch (Exception ex2) { BetterSandboxPlugin.Log.LogDebug((object)("Victory text: " + ex2.Message)); } BetterSandboxPlugin.Log.LogInfo((object)$"Team {team} won the game ({RoundsToWinGame} rounds); the score starts over."); yield return (object)new WaitForSecondsRealtime(1.5f); foreach (int item2 in teamRounds.Keys.ToList()) { teamRounds[item2] = 0; } } private static IEnumerator VanillaSequence(Dictionary<int, int> points, Dictionary<int, int> rounds, int team, bool roundWon) { if (!roundWon) { return PointVisualizer.instance.DoSequence(Get(points, 0), Get(points, 1), team == 0); } return PointVisualizer.instance.DoWinSequence(Get(points, 0), Get(points, 1), Get(rounds, 0), Get(rounds, 1), team == 0); static int Get(Dictionary<int, int> d, int k) { if (!d.TryGetValue(k, out var value)) { return 0; } return value; } } internal void ShowScore() { if ((Object)(object)UIHandler.instance == (Object)null) { return; } EnsureScoreSettings(); EnsureTeams(); try { AccessTools.Method(typeof(UIHandler), "SetNumberOfRounds", (Type[])null, (Type[])null)?.Invoke(UIHandler.instance, new object[1] { RoundsToWinGame }); } catch { } try { RwfScore.ShowCounter(teamPoints, teamRounds); } catch (Exception) { try { UIHandler.instance.ShowRoundCounterSmall(Get(teamRounds, 0), Get(teamRounds, 1), Get(teamPoints, 0), Get(teamPoints, 1)); } catch (Exception ex2) { BetterSandboxPlugin.Log.LogDebug((object)("Score counter: " + ex2.Message)); } } scoreShown = true; scoreTeams = TeamsKey(); static int Get(Dictionary<int, int> d, int k) { if (!d.TryGetValue(k, out var value)) { return 0; } return value; } } private void HideScore() { try { UIHandler instance = UIHandler.instance; if (instance != null) { instance.HideRoundCounterSmall(); } } catch { } scoreShown = false; } internal string ResetScore() { teamPoints.Clear(); teamRounds.Clear(); if (scoreShown) { ShowScore(); } return "SCORE RESET"; } private static string TeamsKey() { return string.Join(",", from t in (from p in Players() select p.teamID).Distinct() orderby t select t); } private void WatchScore() { bool flag = BetterSandboxPlugin.KeepScoreWhenOneLeft.Value && InSandbox && Offline && Time.unscaledTime - sandboxEnteredAt > 1.5f && Players().Count > 0; if (!InSandbox && (teamPoints.Count > 0 || teamRounds.Count > 0)) { teamPoints.Clear(); teamRounds.Clear(); } if (flag != scoreShown) { if (flag) { ShowScore(); } else if (InSandbox) { HideScore(); } else { scoreShown = false; } } else if (flag && Time.unscaledTime >= nextScoreCheck) { nextScoreCheck = Time.unscaledTime + 1f; if (TeamsKey() != scoreTeams) { ShowScore(); } } } private static IEnumerator Safe(IEnumerator inner) { while (true) { object current; try { if (!inner.MoveNext()) { break; } current = inner.Current; } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Round step failed: " + ex)); break; } yield return current; } } internal void Flash(string message) { if (menuOpen) { panel?.Flash(message); } else if (mapPicker.IsOpen) { mapPicker.Flash(message); } else { hub.Status(message); } } private void RefreshPanels() { panel?.Refresh(); mapPicker.Refresh(); hub.Refresh(); } private static bool BlockedByTyping(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 if ((int)key >= 282 && (int)key <= 296) { return false; } if (DevConsole.isTyping) { return true; } EventSystem current = EventSystem.current; GameObject val = (((Object)(object)current != (Object)null) ? current.currentSelectedGameObject : null); if ((Object)(object)val == (Object)null) { return false; } TMP_InputField component = val.GetComponent<TMP_InputField>(); if ((Object)(object)component != (Object)null && component.isFocused) { return true; } InputField component2 = val.GetComponent<InputField>(); if ((Object)(object)component2 != (Object)null) { return component2.isFocused; } return false; } internal void CaptureKey(ConfigEntry<KeyCode> entry, Action done) { captureEntry = entry; captureDone = done; } private void PollCapture() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Invalid comparison between Unknown and I4 //IL_003c: Unknown result type (might be due to invalid IL or missing references) KeyCode[] allKeys = AllKeys; foreach (KeyCode val in allKeys) { if ((int)val != 0 && ((int)val < 323 || (int)val > 329) && (int)val < 330 && Input.GetKeyDown(val)) { if ((int)val != 27) { captureEntry.Value = val; } Action action = captureDone; captureEntry = null; captureDone = null; action?.Invoke(); break; } } } } internal class MapPicker { private readonly SandboxController owner; private readonly Dictionary<Button, ButtonClickedEvent> savedClicks = new Dictionary<Button, ButtonClickedEvent>(); private readonly Dictionary<Button, ButtonClickedEvent> loadClicks = new Dictionary<Button, ButtonClickedEvent>(); private readonly List<GameObject> hidden = new List<GameObject>(); private bool open; private bool loadMode = true; private int buildAtFrame = -1; private float nextCheck; private MapPanel panel; public bool IsOpen => open; public bool LoadMode => loadMode; internal bool ChangingMap => owner.ChangingMap; public MapPicker(SandboxController owner) { this.owner = owner; } public void Open() { //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown if (open) { return; } ToggleLevelMenuHandler instance = ToggleLevelMenuHandler.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.mapMenuCanvas == (Object)null || instance.lvlObjs == null || instance.lvlObjs.Count == 0) { BetterSandboxPlugin.Log.LogWarning((object)"The map menu isn't built yet. Open Toggle Maps once in the main menu, or wait a moment."); return; } instance.SetActive(true); open = true; foreach (GameObject lvlObj in instance.lvlObjs) { if ((Object)(object)lvlObj == (Object)null) { continue; } Button component = lvlObj.GetComponent<Button>(); if (!((Object)(object)component == (Object)null) && !savedClicks.ContainsKey(component)) { string key = ((Object)lvlObj).name; savedClicks[component] = component.onClick; ButtonClickedEvent val = new ButtonClickedEvent(); ((UnityEvent)val).AddListener((UnityAction)delegate { Pick(key); }); loadClicks[component] = val; } } Transform transform = instance.mapMenuCanvas.transform; Hide(transform.Find("MapMenu/Top/ToggleAll")); Hide(transform.Find("MapMenu/Top/RedrawAll")); Hide(transform.Find("MapMenu/Top/Help")); SandboxController.HideNamed(instance.mapMenuCanvas, "MapsPresetPanel", hidden); ApplyMode(); if (panel != null && panel.Alive) { panel.Show(show: true); panel.Refresh(); } else { buildAtFrame = Time.frameCount + 2; } } private void Hide(Transform t) { if (!((Object)(object)t == (Object)null) && ((Component)t).gameObject.activeSelf) { ((Component)t).gameObject.SetActive(false); hidden.Add(((Component)t).gameObject); } } internal void ToggleMode() { if (loadMode && !SandboxController.Offline && !PhotonNetwork.IsMasterClient) { Flash("HOST ONLY"); return; } loadMode = !loadMode; ApplyMode(); Flash(loadMode ? "CLICK LOADS A MAP" : "CLICK TURNS MAPS ON/OFF"); } private void ApplyMode() { foreach (KeyValuePair<Button, ButtonClickedEvent> savedClick in savedClicks) { if ((Object)(object)savedClick.Key != (Object)null) { savedClick.Key.onClick = (loadMode ? loadClicks[savedClick.Key] : savedClick.Value); } } SetCategoryControls(!loadMode); } private static void SetCategoryControls(bool show) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown ToggleLevelMenuHandler instance = ToggleLevelMenuHandler.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.mapMenuCanvas == (Object)null) { return; } Transform transform = instance.mapMenuCanvas.transform; Transform val = transform.Find("MapMenu/Top/Categories/ButtonsScroll/Viewport/Content"); if ((Object)(object)val != (Object)null) { foreach (Transform item in val) { Transform val2 = item.Find("Toggle"); if ((Object)(object)val2 != (Object)null) { ((Component)val2).gameObject.SetActive(show); } } } Transform val3 = transform.Find("MapMenu/ScrollViews"); if (!((Object)(object)val3 != (Object)null)) { return; } foreach (Transform item2 in val3) { Transform val4 = item2; Transform val5 = val4.Find("Darken"); if ((Object)(object)val5 != (Object)null) { ((Component)val5).gameObject.SetActive(show && !LevelManager.IsCategoryActive(((Object)val4).name)); } } } public void Close() { if (open) { ToggleLevelMenuHandler instance = ToggleLevelMenuHandler.instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.mapMenuCanvas != (Object)null && instance.mapMenuCanvas.activeSelf) { instance.mapMenuCanvas.SetActive(false); } AfterClosed(); } } public void Watch() { if (open) { ToggleLevelMenuHandler instance = ToggleLevelMenuHandler.instance; if (!SandboxController.InSandbox || (Object)(object)instance == (Object)null || (Object)(object)instance.mapMenuCanvas == (Object)null || !instance.mapMenuCanvas.activeInHierarchy) { Close(); } } } private void AfterClosed() { open = false; buildAtFrame = -1; foreach (KeyValuePair<Button, ButtonClickedEvent> savedClick in savedClicks) { if ((Object)(object)savedClick.Key != (Object)null) { savedClick.Key.onClick = savedClick.Value; } } savedClicks.Clear(); loadClicks.Clear(); SandboxController.RestoreHidden(hidden); SetCategoryControls(show: true); panel?.Show(show: false); } private void Pick(string key) { Close(); owner.Flash(owner.ChangeMap(key)); } internal void PickRandom() { Close(); owner.Flash(owner.ChangeMap(null)); } internal void Back() { owner.MapMenuBack(); } public void Tick() { if (!open) { return; } if (panel == null && buildAtFrame >= 0 && Time.frameCount >= buildAtFrame) { buildAtFrame = -1; try { panel = MapPanel.TryBuild(this); } catch (Exception ex) { BetterSandboxPlugin.Log.LogWarning((object)("Map menu buttons could not be built: " + ex)); } if (panel != null) { panel.Show(show: true); panel.Refresh(); } } panel?.Tick(); if (Time.unscaledTime >= nextCheck) { nextCheck = Time.unscaledTime + 0.25f; SandboxController.HideNamed(ToggleLevelMenuHandler.instance?.mapMenuCanvas, "MapsPresetPanel", hidden); } } public void Flash(string message) { if (open) { panel?.Flash(message); } } public void Refresh() { panel?.Refresh(); } } internal static class RwfScore { private static bool Loaded => Chainloader.PluginInfos.ContainsKey("io.olavim.rounds.rwf"); public static IEnumerator Sequence(Dictionary<int, int> points, Dictionary<int, int> rounds, int team, bool roundWon) { if (!Loaded) { throw new InvalidOperationException("RoundsWithFriends isn't loaded"); } return SequenceImpl(points, rounds, team, roundWon); } public static void ShowCounter(Dictionary<int, int> points, Dictionary<int, int> rounds) { if (!Loaded) { throw new InvalidOperationException("RoundsWithFriends isn't loaded"); } ShowCounterImpl(points, rounds); } public static void RebuildCardBars() { if (!Loaded) { throw new InvalidOperationException("RoundsWithFriends isn't loaded"); } RebuildCardBarsImpl(); } [MethodImpl(MethodImplOptions.NoInlining)] private static void RebuildCardBarsImpl() { CardBarHandlerExtensions.Rebuild(CardBarHandler.instance); } public static int MaxTeams() { if (!Loaded) { throw new InvalidOperationException("RoundsWithFriends isn't loaded"); } return MaxTeamsImpl(); } [MethodImpl(MethodImplOptions.NoInlining)] private static int MaxTeamsImpl() { return RWFMod.instance.MaxTeams; } [MethodImpl(MethodImplOptions.NoInlining)] private static IEnumerator SequenceImpl(Dictionary<int, int> points, Dictionary<int, int> rounds, int team, bool roundWon) { if (!roundWon) { return PointVisualizerExtensions.DoSequence(PointVisualizer.instance, points, rounds, team); } return PointVisualizerExtensions.DoWinSequence(PointVisualizer.instance, points, rounds, team); } [MethodImpl(MethodImplOptions.NoInlining)] private static void ShowCounterImpl(Dictionary<int, int> points, Dictionary<int, int> rounds) { UIHandlerExtensions.ShowRoundCounterSmall(UIHandler.instance, points, rounds); } } internal class BottomHint { private GameObject root; private TextMeshProUGUI text; private CanvasGroup group; private float hideFrom = -1f; private float fadeTime = 0.6f; public bool Visible { get { if ((Object)(object)root != (Object)null) { return root.activeSelf; } return false; } } private void Build(TMP_FontAsset font) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) root = new GameObject("BetterSandboxHint"); Object.DontDestroyOnLoad((Object)(object)root); Canvas obj = root.AddComponent<Canvas>(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 30; CanvasScaler obj2 = root.AddComponent<CanvasScaler>(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); obj2.matchWidthOrHeight = 0.5f; group = root.AddComponent<CanvasGroup>(); group.interactable = false; group.blocksRaycasts = false; GameObject val = new GameObject("Text", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(root.transform, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = new Vector2(0f, 0f); val2.anchorMax = new Vector2(1f, 0f); val2.pivot = new Vector2(0.5f, 0f); val2.anchoredPosition = new Vector2(0f, 6f); val2.sizeDelta = new Vector2(-40f, 56f); text = val.AddComponent<TextMeshProUGUI>(); if ((Object)(object)font != (Object)null) { ((TMP_Text)text).font = font; } ((TMP_Text)text).fontSize = 34f; ((TMP_Text)text).alignment = (TextAlignmentOptions)1026; ((Graphic)text).color = Color.white; ((Graphic)text).raycastTarget = false; ((TMP_Text)text).enableWordWrapping = false; ((TMP_Text)text).outlineWidth = 0.22f; ((TMP_Text)text).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); root.SetActive(false); } public void Show(string message, TMP_FontAsset font) { if ((Object)(object)root == (Object)null) { Build(font); } else if ((Object)(object)font != (Object)null && (Object)(object)((TMP_Text)text).font != (Object)(object)font) { ((TMP_Text)text).font = font; } ((TMP_Text)text).text = message; group.alpha = 1f; hideFrom = -1f; root.SetActive(true); } public void Hide(float fade) { if (!Visible) { return; } fade = Mathf.Max(0.01f, fade); if (hideFrom >= 0f) { float num = (1f - Mathf.Clamp01((Time.unscaledTime - hideFrom) / fadeTime)) * fadeTime; if (fade >= num) { return; } } hideFrom = Time.unscaledTime; fadeTime = fade; } public void Tick() { if (Visible && !(hideFrom < 0f)) { float num = (Time.unscaledTime - hideFrom) / fadeTime; group.alpha = 1f - Mathf.Clamp01(num); if (num >= 1f) { root.SetActive(false); hideFrom = -1f; } } } } internal class RightClickTake : MonoBehaviour, IPointerClickHandler, IEventSystemHandler { public void OnPointerClick(PointerEventData eventData) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 if ((int)eventData.button == 1) { SandboxController.Instance?.TakeFromMenu(((Object)((Component)this).gameObject).name); } } } internal class ButtonColumn { private readonly GameObject asset; private readonly float rowH; public readonly GameObject Root; public bool Alive => (Object)(object)Root != (Object)null; public static ButtonColumn TryBuild(GameObject canvas, string blockPath, string contentPath, GameObject asset, string name, int rows) { if ((Object)(object)canvas == (Object)null || (Object)(object)asset == (Object)null || !canvas.activeInHierarchy) { return null; } Transform val = canvas.transform.Find(contentPath); Transform val2 = canvas.transform.Find(blockPath); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || val.childCount == 0) { return null; } Canvas.ForceUpdateCanvases(); return new ButtonColumn(val2, val, asset, name, rows); } private ButtonColumn(Transform block, Transform content, GameObject asset, string name, int rows) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Expected O, but got Unknown //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) this.asset = asset; Transform transform = asset.transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); RectTransform val2 = (RectTransform)((content.childCount > 0) ? /*isinst with value type is only supported in some contexts*/: null); float[] array = new float[4]; float num; Rect rect; if (!((Object)(object)val2 != (Object)null)) { num = 0f; } else { rect = val2.rect; num = ((Rect)(ref rect)).width; } array[0] = num; Transform obj = ((content is RectTransform) ? content : null); float num2; if (obj == null) { num2 = 0f; } else { rect = ((RectTransform)obj).rect; num2 = ((Rect)(ref rect)).width; } array[1] = num2; array[2] = (((Object)(object)val != (Object)null) ? val.sizeDelta.x : 0f); array[3] = 220f; float num3 = FirstAbove(1f, array); float[] array2 = new float[3]; float num4; if (!((Object)(object)val2 != (Object)null)) { num4 = 0f; } else { rect = val2.rect; num4 = ((Rect)(ref rect)).height; } array2[0] = num4; array2[1] = (((Object)(object)val != (Object)null) ? val.sizeDelta.y : 0f); array2[2] = 40f; rowH = FirstAbove(1f, array2); RectTransform val3 = (RectTransform)block.parent; Bounds val4 = RectTransformUtility.CalculateRelativeRectTransformBounds((Transform)(object)val3, block); Slider[] componentsInChildren = ((Component)val3).GetComponentsInChildren<Slider>(false); foreach (Slider val5 in componentsInChildren) { if (!((Component)val5).transform.IsChildOf(block)) { Bounds val6 = RectTransformUtility.CalculateRelativeRectTransformBounds((Transform)(object)val3, ((Component)val5).transform); bool num5 = ((Bounds)(ref val6)).min.x < ((Bounds)(ref val4)).max.x && ((Bounds)(ref val6)).max.x > ((Bounds)(ref val4)).min.x; bool flag = ((Bounds)(ref val6)).min.y < ((Bounds)(ref val4)).max.y + rowH * 3f && ((Bounds)(ref val6)).max.y > ((Bounds)(ref val4)).min.y - rowH * 3f; if (num5 && flag) { ((Bounds)(ref val4)).Encapsulate(val6); } } } VerticalLayoutGroup component = ((Component)content).GetComponent<VerticalLayoutGroup>(); float num6 = (((Object)(object)component != (Object)null) ? ((HorizontalOrVerticalLayoutGroup)component).spacing : (rowH * 0.1f)); float num7 = rowH * 0.35f; float num8 = Mathf.Max(((Bounds)(ref val4)).size.x, num3); float num9 = (float)rows * rowH + (float)(rows - 1) * num6; Root = new GameObject(name, new Type[1] { typeof(RectTransform) }); Root.layer = ((Component)block).gameObject.layer; RectTransform val7 = (RectTransform)Root.transform; ((Transform)val7).SetParent((Transform)(object)val3, false); ((Transform)val7).SetAsLastSibling(); val7.anchorMin = (val7.anchorMax = val3.pivot); val7.pivot = new Vector2(0.5f, 1f); val7.anchoredPosition = new Vector2(((Bounds)(ref val4)).center.x, ((Bounds)(ref val4)).min.y - num7); val7.s