Patch_Chunk_OnDestroy.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using UnityEngine;
  4. namespace Subworlds.Patches
  5. {
  6. [HarmonyPatch(typeof(Chunk))]
  7. [HarmonyPatch("OnDestroy")]
  8. [HarmonyGadget("SubworldCore")]
  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. if (GameScript.townBiome != Core.meteroidPlanet.GetID() && GameScript.townBiome != Core.shipPlanet.GetID())
  32. Core.lastBiome = GameScript.townBiome;
  33. }
  34. }
  35. }