Patch_Chunk_OnDestroy.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. Core.meteorPorterPlaced = false;
  17. if (GameScript.townBiome != Core.meteroidPlanet.GetID() && GameScript.townBiome != Core.shipPlanet.GetID())
  18. Core.lastBiome = GameScript.townBiome;
  19. if (___networkStuff.Length > 40)
  20. {
  21. if (Network.isServer)
  22. {
  23. for (int i = 0; i < ___networkStuff.Length; i++)
  24. {
  25. if (___networkStuff[i])
  26. {
  27. Network.RemoveRPCs(___networkStuff[i].GetComponent<NetworkView>().viewID);
  28. Network.Destroy(___networkStuff[i].gameObject);
  29. }
  30. }
  31. }
  32. ___networkStuff = new GameObject[40];
  33. }
  34. }
  35. }
  36. }