diff --git a/EmotesMod/EmotesPlugin.cs b/EmotesMod/EmotesPlugin.cs index 13ff784..195bacf 100644 --- a/EmotesMod/EmotesPlugin.cs +++ b/EmotesMod/EmotesPlugin.cs @@ -13,7 +13,7 @@ namespace EmotesMod; -[BepInAutoPlugin("EmotesMod", "Emotes Mod", "1.1.2")] +[BepInAutoPlugin("EmotesMod", "Emotes Mod", "1.2.0")] [BepInProcess("Among Us.exe")] [ReactorModFlags(ModFlags.RequireOnAllClients)] [BepInDependency(ReactorPlugin.Id)] @@ -23,6 +23,7 @@ public partial class EmotesPlugin : BasePlugin public override void Load() { ClassInjector.RegisterTypeInIl2Cpp(); + ClassInjector.RegisterTypeInIl2Cpp(); ClassInjector.RegisterTypeInIl2Cpp(); ClassInjector.RegisterTypeInIl2Cpp(); ClassInjector.RegisterTypeInIl2Cpp(); diff --git a/EmotesMod/Modules/Components/EmoteBehaviour.cs b/EmotesMod/Modules/Components/EmoteBehaviour.cs index fee2c19..bbdd734 100644 --- a/EmotesMod/Modules/Components/EmoteBehaviour.cs +++ b/EmotesMod/Modules/Components/EmoteBehaviour.cs @@ -24,12 +24,12 @@ public void PlayEmote() public IEnumerator CoHandleIdleEmote(bool loop) { - if (pc.amOwner) HudManagerPatches.EmoteCanvas.transform.GetChild(1).gameObject.SetActive(true); + if (pc.AmOwner) HudManagerPatches.EmoteCanvas.transform.GetChild(1).gameObject.SetActive(true); pc.cosmetics.gameObject.SetActive(false); if (loop) { Vector2 originalPos = pc.GetTruePosition(); - while (originalPos == pc.GetTruePosition()) + while (currentEmote && originalPos == pc.GetTruePosition()) { pc.MyPhysics.Animations.Animator.Play(currentEmote.anim.Value); yield return new WaitForSeconds(currentEmote.anim.Value.length); @@ -40,7 +40,7 @@ public IEnumerator CoHandleIdleEmote(bool loop) pc.cosmetics.gameObject.SetActive(true); currentEmote = null!; pc.MyPhysics.Animations.PlayIdleAnimation(); - HudManagerPatches.EmoteCanvas.transform.GetChild(1).gameObject.SetActive(false); + if (pc.AmOwner) HudManagerPatches.EmoteCanvas.transform.GetChild(1).gameObject.SetActive(false); yield break; } diff --git a/EmotesMod/Patches/HudManagerPatches.cs b/EmotesMod/Patches/HudManagerPatches.cs index 5617b04..037c10f 100644 --- a/EmotesMod/Patches/HudManagerPatches.cs +++ b/EmotesMod/Patches/HudManagerPatches.cs @@ -1,9 +1,7 @@ using System; using EmotesMod.Modules.Components; using HarmonyLib; -using Rewired; using UnityEngine; -using UnityEngine.Events; using UnityEngine.UI; using Object = UnityEngine.Object; @@ -12,56 +10,67 @@ namespace EmotesMod.Patches; [HarmonyPatch] public class HudManagerPatches { - public static GameObject EmoteCanvas; - + private static GameObject _emoteCanvas; + + public static GameObject EmoteCanvas + { + get + { + if (_emoteCanvas.IsDestroyedOrNull()) LazyInstantiateHud(); + + return _emoteCanvas; + } + } + [HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] [HarmonyPostfix] public static void HudManager_Update_Postfix(HudManager __instance) { - if (EmoteCanvas == null) return; - - if (/*ReInput.players.GetPlayer(0).GetButtonDown(InputPatches.OpenEmoteWheelBind.id)*/ Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.LeftControl) && PlayerControl.LocalPlayer && !PlayerControl.LocalPlayer.Data.IsDead) + if ( /*ReInput.players.GetPlayer(0).GetButtonDown(InputPatches.OpenEmoteWheelBind.id)*/ + Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.LeftControl) && PlayerControl.LocalPlayer && + !PlayerControl.LocalPlayer.Data.IsDead) { var wheel = EmoteCanvas.transform.GetChild(0).gameObject; wheel.SetActive(!wheel.activeSelf); } - if (/*ReInput.players.GetPlayer(0).GetButtonDown(InputPatches.StopEmotingBind.id)*/ Input.GetKeyDown(KeyCode.X)&& PlayerControl.LocalPlayer.GetComponent().currentEmote) - { + if ( /*ReInput.players.GetPlayer(0).GetButtonDown(InputPatches.StopEmotingBind.id)*/ + Input.GetKeyDown(KeyCode.X) && PlayerControl.LocalPlayer.GetComponent().currentEmote) PlayerControl.LocalPlayer.RpcStopEmote(); - } } - + [HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))] [HarmonyPostfix] public static void HudManager_Start_Postfix(HudManager __instance) { - EmoteCanvas = Object.Instantiate(Assets.EmoteCanvas); - EmoteCanvas.transform.GetChild(0).gameObject.SetActive(false); - EmoteCanvas.transform.GetChild(1).gameObject.SetActive(false); - EmoteCanvas.transform.GetChild(1).GetChild(1).GetComponent