using GadgetCore.API; using GadgetCore.Util; using HarmonyLib; using System.Collections; using System.Threading; using System.Windows.Threading; using UnityEngine; namespace MultiplayerClientSpawn.Patches { [HarmonyPatch(typeof(KylockeStand))] [HarmonyPatch("Awake")] [HarmonyGadget("MultiplayerClientSpawn")] public static class Patch_KylockeStand_Awake { [HarmonyPostfix] public static void Prefix(KylockeStand __instance) { __instance.StartCoroutine(StartUpdateLoop(__instance)); } public static IEnumerator LightColorUpdateLoop(KylockeStand instance) { while (!Network.isServer && !Network.isClient) { yield return new WaitForSeconds(0f); } if (Network.isServer) { while (true) { yield return new WaitForSeconds(1f); if (instance.gameObject.activeSelf && Network.isServer) { instance.itemID = getItemIdFromIndex(colorIndex); instance.GetComponent().RPC("Set", RPCMode.All, new object[] { new int[]{ instance.itemID, instance.cost } }); } yield return new WaitForSeconds(9f); colorIndex = (colorIndex + 1) % 2; } } } private static IEnumerator StartUpdateLoop(KylockeStand instance) { if (instance.itemID == 2403) { instance.StartCoroutine(LightColorUpdateLoop(instance)); CoroutineManager newComponent = instance.gameObject.AddComponent(); newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(LightColorUpdateLoop(instance)); })); } yield break; } private static int colorIndex = 0; private static int getItemIdFromIndex(int i) { switch (i) { case 0: return 2403; case 1: return Core.itemSpawnId; } return 2403; } } }