Skip to content

Commit a68f9a6

Browse files
committed
Removed hard dependency on Nautilus.
1 parent d83269f commit a68f9a6

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Patches/Array3.cs

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using HarmonyLib;
3-
using Nautilus.Utility;
43

54
namespace TerrainPatcher
65
{
@@ -19,8 +18,7 @@ internal static void Patch(Harmony harmony)
1918
harmony.Patch(setMethod, prefix: new HarmonyMethod(
2019
AccessTools.Method(typeof(Array3Patches), nameof(SetPrefix))
2120
));
22-
23-
SaveUtils.RegisterOnQuitEvent(() => { _vanillaToNegativeArrays.Clear(); });
21+
harmony.PatchAll(typeof(IngameMenu_QuitGameAsync_Patch));
2422
}
2523

2624
private class NegativeEntityCell
@@ -33,7 +31,7 @@ public NegativeEntityCell(Dictionary<Int3, EntityCell> entityCells)
3331
}
3432
}
3533

36-
private static Dictionary<Array3<EntityCell>, NegativeEntityCell> _vanillaToNegativeArrays =
34+
private static Dictionary<Array3<EntityCell>, NegativeEntityCell> vanillaToNegativeArrays =
3735
new Dictionary<Array3<EntityCell>, NegativeEntityCell>();
3836

3937
private static bool GetPrefix(
@@ -49,15 +47,15 @@ ref EntityCell __result
4947
}
5048

5149
// At this point the index is negative, so we'll handle it ourselves.
52-
if (_vanillaToNegativeArrays.TryGetValue(__instance, out var negativesArray) &&
50+
if (vanillaToNegativeArrays.TryGetValue(__instance, out var negativesArray) &&
5351
negativesArray.EntityCells.TryGetValue(new Int3(x, y, z), out var entityCell))
5452
{
5553
__result = entityCell;
56-
Mod.LogDebug($"Get negative entity cell for ({x},{y},{z})");
54+
Mod.LogDebug($"Get negative entity cell for ({x}, {y}, {z})");
5755
return false;
5856
}
5957

60-
Mod.LogDebug($"Couldn't find negative entity cell for ({x},{y},{z})");
58+
Mod.LogDebug($"Couldn't find negative entity cell for ({x}, {y}, {z})");
6159
return false;
6260
}
6361

@@ -74,18 +72,29 @@ EntityCell value
7472
}
7573

7674
// At this point the index is negative, so we'll set it to our collection.
77-
if (!_vanillaToNegativeArrays.TryGetValue(__instance, out var negativeEntityCell))
75+
if (!vanillaToNegativeArrays.TryGetValue(__instance, out var negativeEntityCell))
7876
{
7977
negativeEntityCell = new NegativeEntityCell(
8078
new Dictionary<Int3, EntityCell>(Int3.equalityComparer)
8179
);
82-
_vanillaToNegativeArrays[__instance] = negativeEntityCell;
80+
vanillaToNegativeArrays[__instance] = negativeEntityCell;
8381
}
8482

8583
negativeEntityCell.EntityCells[new Int3(x, y, z)] = value;
86-
Mod.LogDebug($"Set negative entity cell for ({x},{y},{z})");
84+
Mod.LogDebug($"Set negative entity cell for ({x}, {y}, {z})");
8785

8886
return false;
8987
}
88+
89+
// Clear `vanillaToNegativeArrays` when the user quits the game.
90+
[HarmonyPatch(typeof(IngameMenu), nameof(IngameMenu.QuitGameAsync))]
91+
internal static class IngameMenu_QuitGameAsync_Patch
92+
{
93+
private static void Postfix()
94+
{
95+
Mod.LogDebug("Clearing negative entity cells on quit");
96+
vanillaToNegativeArrays.Clear();
97+
}
98+
}
9099
}
91100
}

src/Patches/Batch.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ private static bool SetResult(Int3 batchId, ref string result, bool runOriginal)
7979
internal static class LargeWorldStreamer_CheckBatch_Patches
8080
{
8181
[HarmonyPatch(nameof(LargeWorldStreamer.CheckBatch))]
82-
[HarmonyPatch(nameof(LargeWorldStreamer.CheckRoot), typeof(int), typeof(int), typeof(int))]
82+
[HarmonyPatch(
83+
nameof(LargeWorldStreamer.CheckRoot),
84+
typeof(int), typeof(int), typeof(int)
85+
)]
8386
[HarmonyPrefix]
8487
private static bool AllowOutOfBounds(ref bool __result)
8588
{

0 commit comments

Comments
 (0)