|
| 1 | +using HarmonyLib; |
| 2 | +using NebulaWorld; |
| 3 | + |
| 4 | +namespace NebulaPatcher.Patches.Dynamic |
| 5 | +{ |
| 6 | + [HarmonyPatch(typeof(PlanetData))] |
| 7 | + class PlanetData_Patch |
| 8 | + { |
| 9 | + [HarmonyPrefix] |
| 10 | + [HarmonyPatch("UnloadMeshes")] |
| 11 | + public static bool UnloadMeshes_Prefix(PlanetData __instance) |
| 12 | + { |
| 13 | + //Host should not unload planet meshes, since he need to permorm all terrain operations |
| 14 | + if (SimulatedWorld.Initialized && LocalPlayer.IsMasterClient) |
| 15 | + { |
| 16 | + //Do not unload meshes, just hide them so it is not visible |
| 17 | + UnloadVisuals(__instance); |
| 18 | + return false; |
| 19 | + } |
| 20 | + |
| 21 | + return true; |
| 22 | + } |
| 23 | + |
| 24 | + [HarmonyPrefix] |
| 25 | + [HarmonyPatch("UnloadData")] |
| 26 | + public static bool UnloadData_Prefix() |
| 27 | + { |
| 28 | + //Host should not unload planet data, since he need to permorm all operations from users |
| 29 | + if (SimulatedWorld.Initialized && LocalPlayer.IsMasterClient) |
| 30 | + { |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + return true; |
| 35 | + } |
| 36 | + |
| 37 | + public static void UnloadVisuals(PlanetData __instance) |
| 38 | + { |
| 39 | + if (__instance.gameObject != null) |
| 40 | + { |
| 41 | + __instance.gameObject.SetActive(false); |
| 42 | + } |
| 43 | + if (__instance.terrainMaterial != null) |
| 44 | + { |
| 45 | + UnityEngine.Object.Destroy(__instance.terrainMaterial); |
| 46 | + __instance.terrainMaterial = null; |
| 47 | + } |
| 48 | + if (__instance.oceanMaterial != null) |
| 49 | + { |
| 50 | + UnityEngine.Object.Destroy(__instance.oceanMaterial); |
| 51 | + __instance.oceanMaterial = null; |
| 52 | + } |
| 53 | + if (__instance.atmosMaterial != null) |
| 54 | + { |
| 55 | + UnityEngine.Object.Destroy(__instance.atmosMaterial); |
| 56 | + __instance.atmosMaterial = null; |
| 57 | + } |
| 58 | + if (__instance.minimapMaterial != null) |
| 59 | + { |
| 60 | + UnityEngine.Object.Destroy(__instance.minimapMaterial); |
| 61 | + __instance.minimapMaterial = null; |
| 62 | + } |
| 63 | + if (__instance.reformMaterial0 != null) |
| 64 | + { |
| 65 | + UnityEngine.Object.Destroy(__instance.reformMaterial0); |
| 66 | + __instance.reformMaterial0 = null; |
| 67 | + } |
| 68 | + if (__instance.reformMaterial1 != null) |
| 69 | + { |
| 70 | + UnityEngine.Object.Destroy(__instance.reformMaterial1); |
| 71 | + __instance.reformMaterial1 = null; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments