Patch_Chunk_OnDestroy.cs 1.1 KB

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