Patch_Chunk_OnDestroy.cs 831 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. public static class Patch_Chunk_OnDestroyy
  10. {
  11. [HarmonyPrefix]
  12. [HarmonyPriority(1010)]
  13. public static void Prefix(Chunk __instance, ref GameObject[] ___networkStuff)
  14. {
  15. if (___networkStuff.Length > 40)
  16. {
  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. }