Patch_Chunk_OnDestroy.cs 1.1 KB

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