Patch_Chunk_OnDestroy.cs 829 B

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