From 3179a1ba9abb639bd3bfeaa5e87fee9dbdb16334 Mon Sep 17 00:00:00 2001 From: Jonah Butler <61718056+jonahnm@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:27:22 -0500 Subject: [PATCH 1/2] Add forceOriginal command to TerrainPatcher.TerrainRegistry.PatchTerrain --- src/Terrain.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Terrain.cs b/src/Terrain.cs index 2b39113..d11f4af 100644 --- a/src/Terrain.cs +++ b/src/Terrain.cs @@ -10,12 +10,13 @@ public static class TerrainRegistry /// Applies a terrain patch file to the game's terrain. /// The name of the patch file to apply. /// The patch file to apply. - public static void PatchTerrain(string patchName, Stream patchFile) + /// Whether or not to force usage of the original batch file. + public static void PatchTerrain(string patchName, Stream patchFile, bool forceOriginal = false) { try { Mod.LogInfo($"Applying patch '{patchName}'"); - ApplyPatchFile(patchFile); + ApplyPatchFile(patchFile,forceOrginal); } catch (Exception ex) { @@ -24,7 +25,7 @@ public static void PatchTerrain(string patchName, Stream patchFile) } // Applies a terrain patch. - internal static void ApplyPatchFile(Stream patchFile) + internal static void ApplyPatchFile(Stream patchFile, bool forceOriginal) { if (patchFile is null) { @@ -65,7 +66,7 @@ internal static void ApplyPatchFile(Stream patchFile) // Lists all batches as they are patched. Mod.LogInfo($"- Patching batch ({id.x}, {id.y}, {id.z})"); - ApplyBatchPatch(reader, id); + ApplyBatchPatch(reader, id, forceOriginal); } catch (EndOfStreamException ex) { @@ -93,11 +94,11 @@ internal static void ApplyPatchFile(Stream patchFile) new Dictionary { }; // Loads a batch into patchedBatches if necessary, then applies the patch. - private static void ApplyBatchPatch(BinaryReader patch, Int3 batchId) + private static void ApplyBatchPatch(BinaryReader patch, Int3 batchId, bool forceOriginal) { lock (patchedBatches) { - if (!patchedBatches.ContainsKey(batchId)) + if (!patchedBatches.ContainsKey(batchId) || forceOriginal) { RegisterNewBatch(batchId); } From d71ef9ec5abf73c6366a27aa10e23d7f718282d1 Mon Sep 17 00:00:00 2001 From: Esper Thomson Date: Wed, 3 Jan 2024 15:56:12 -0500 Subject: [PATCH 2/2] Fixed formatting and improved documentation. --- src/Terrain.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Terrain.cs b/src/Terrain.cs index d11f4af..5e40e21 100644 --- a/src/Terrain.cs +++ b/src/Terrain.cs @@ -10,13 +10,18 @@ public static class TerrainRegistry /// Applies a terrain patch file to the game's terrain. /// The name of the patch file to apply. /// The patch file to apply. - /// Whether or not to force usage of the original batch file. - public static void PatchTerrain(string patchName, Stream patchFile, bool forceOriginal = false) + /// Force-overwrites batches in this patch, resetting them to + /// their original states before applying patches. + public static void PatchTerrain( + string patchName, + Stream patchFile, + bool forceOriginal = false + ) { try { Mod.LogInfo($"Applying patch '{patchName}'"); - ApplyPatchFile(patchFile,forceOrginal); + ApplyPatchFile(patchFile, forceOriginal); } catch (Exception ex) { @@ -25,7 +30,7 @@ public static void PatchTerrain(string patchName, Stream patchFile, bool forceOr } // Applies a terrain patch. - internal static void ApplyPatchFile(Stream patchFile, bool forceOriginal) + internal static void ApplyPatchFile(Stream patchFile, bool forceOriginal = false) { if (patchFile is null) {