|
| 1 | +using HarmonyLib; |
| 2 | +using Reactor.Utilities; |
| 3 | +using UnityEngine; |
| 4 | +using TownOfUs.CustomOption; |
| 5 | + |
| 6 | +namespace TownOfUs.Patches |
| 7 | +{ |
| 8 | + [HarmonyPatch] |
| 9 | + class CancelCountdownStart |
| 10 | + { |
| 11 | + private static PassiveButton CancelStartButton; |
| 12 | + |
| 13 | + [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Start))] |
| 14 | + [HarmonyPrefix] |
| 15 | + public static void PrefixStart(GameStartManager __instance) |
| 16 | + { |
| 17 | + CancelStartButton = Object.Instantiate(__instance.StartButton, __instance.transform); |
| 18 | + CancelStartButton.name = "CancelButton"; |
| 19 | + |
| 20 | + var cancelLabel = CancelStartButton.buttonText; |
| 21 | + cancelLabel.gameObject.GetComponent<TextTranslatorTMP>()?.OnDestroy(); |
| 22 | + cancelLabel.text = "Cancel"; |
| 23 | + |
| 24 | + var cancelButtonInactiveRenderer = CancelStartButton.inactiveSprites.GetComponent<SpriteRenderer>(); |
| 25 | + cancelButtonInactiveRenderer.color = new(0.8f, 0f, 0f, 1f); |
| 26 | + |
| 27 | + var cancelButtonActiveRenderer = CancelStartButton.activeSprites.GetComponent<SpriteRenderer>(); |
| 28 | + cancelButtonActiveRenderer.color = Color.red; |
| 29 | + |
| 30 | + var cancelButtonInactiveShine = CancelStartButton.inactiveSprites.transform.Find("Shine"); |
| 31 | + |
| 32 | + if (cancelButtonInactiveShine) |
| 33 | + cancelButtonInactiveShine.gameObject.SetActive(false); |
| 34 | + |
| 35 | + CancelStartButton.activeTextColor = CancelStartButton.inactiveTextColor = Color.white; |
| 36 | + |
| 37 | + CancelStartButton.OnClick = new(); |
| 38 | + CancelStartButton.OnClick.AddListener((UnityEngine.Events.UnityAction)(() => |
| 39 | + { |
| 40 | + __instance.ResetStartState(); |
| 41 | + })); |
| 42 | + CancelStartButton.gameObject.SetActive(false); |
| 43 | + } |
| 44 | + |
| 45 | + [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))] |
| 46 | + [HarmonyPrefix] |
| 47 | + public static void PrefixUpdate(GameStartManager __instance) |
| 48 | + { |
| 49 | + if (__instance == null || !AmongUsClient.Instance.AmHost) return; |
| 50 | + |
| 51 | + __instance.MinPlayers = 4; |
| 52 | + |
| 53 | + CancelStartButton.gameObject.SetActive(__instance.startState is GameStartManager.StartingStates.Countdown); |
| 54 | + |
| 55 | + var startTexttransform = __instance.GameStartText.transform; |
| 56 | + if (startTexttransform.localPosition.y != 2f) |
| 57 | + { |
| 58 | + startTexttransform.localPosition = new Vector3(startTexttransform.localPosition.x, 2f, startTexttransform.localPosition.z); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.ResetStartState))] |
| 63 | + [HarmonyPrefix] |
| 64 | + public static void Prefix(GameStartManager __instance) |
| 65 | + { |
| 66 | + if (__instance?.startState is GameStartManager.StartingStates.Countdown) |
| 67 | + { |
| 68 | + SoundManager.Instance.StopSound(__instance.gameStartSound); |
| 69 | + if (AmongUsClient.Instance.AmHost) |
| 70 | + { |
| 71 | + RandomMap.Reset(); |
| 72 | + GameManager.Instance.LogicOptions.SyncOptions(); |
| 73 | + Coroutines.Start(Rpc.SendRpc()); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.SetStartCounter))] |
| 79 | + [HarmonyPrefix] |
| 80 | + public static void Prefix(GameStartManager __instance, sbyte sec) |
| 81 | + { |
| 82 | + if (sec == -1) |
| 83 | + { |
| 84 | + SoundManager.Instance.StopSound(__instance.gameStartSound); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments