Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forceOriginal param to TerrainPatcher.TerrainRegistry.PatchTerrain #7

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ public static class TerrainRegistry
/// <summary>Applies a terrain patch file to the game's terrain.</summary>
/// <param name="patchName">The name of the patch file to apply.</param>
/// <param name="patchFile">The patch file to apply.</param>
public static void PatchTerrain(string patchName, Stream patchFile)
/// <param name="forceOriginal">Force-overwrites batches in this patch, resetting them to
/// their original states before applying patches.</param>
public static void PatchTerrain(
string patchName,
Stream patchFile,
bool forceOriginal = false
)
{
try
{
Mod.LogInfo($"Applying patch '{patchName}'");
ApplyPatchFile(patchFile);
ApplyPatchFile(patchFile, forceOriginal);
}
catch (Exception ex)
{
Expand All @@ -24,7 +30,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 = false)
{
if (patchFile is null)
{
Expand Down Expand Up @@ -65,7 +71,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)
{
Expand Down Expand Up @@ -93,11 +99,11 @@ internal static void ApplyPatchFile(Stream patchFile)
new Dictionary<Int3, string> { };

// 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);
}
Expand Down
Loading