Patch_Chunk_OnDestroy.cs 860 B

12345678910111213141516171819202122232425262728293031323334
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using UnityEngine;
  4. namespace Ships.Patches
  5. {
  6. [HarmonyPatch(typeof(Chunk))]
  7. [HarmonyPatch("OnDestroy")]
  8. [HarmonyGadget("Ships")]
  9. public static class Patch_Chunk_OnDestroyy
  10. {
  11. [HarmonyPrefix]
  12. [HarmonyPriority(1010)]
  13. public static void Prefix(Chunk __instance, ref GameObject[] ___networkStuff)
  14. {
  15. Core.shipPorterPlaced = false;
  16. if (___networkStuff.Length > 40)
  17. {
  18. if (Network.isServer)
  19. {
  20. for (int i = 0; i < ___networkStuff.Length; i++)
  21. {
  22. if (___networkStuff[i])
  23. {
  24. Network.RemoveRPCs(___networkStuff[i].GetComponent<NetworkView>().viewID);
  25. Network.Destroy(___networkStuff[i].gameObject);
  26. }
  27. }
  28. }
  29. ___networkStuff = new GameObject[40];
  30. }
  31. }
  32. }
  33. }