Skip to content

Commit

Permalink
Fix syncing of copy/paste gizmos for Biosculpter/Growth Vat/Mortar, f…
Browse files Browse the repository at this point in the history
…ixes #255 (#407)
  • Loading branch information
SokyranTheDragon authored Dec 27, 2023
1 parent 3cb3226 commit ceb2307
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Source/Client/Patches/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,32 @@ static void Postfix(PawnTextureAtlas __instance)
);
}
}

[HarmonyPatch]
public static class StoragesKeepsTheirOwners
{
[HarmonyPostfix]
[HarmonyPatch(typeof(Building_GrowthVat), nameof(Building_GrowthVat.ExposeData))]
static void PostBuildingGrowthVat(Building_GrowthVat __instance)
=> FixStorage(__instance, __instance.allowedNutritionSettings);

[HarmonyPostfix]
[HarmonyPatch(typeof(CompBiosculpterPod), nameof(CompBiosculpterPod.PostExposeData))]
static void PostCompBiosculpterPod(CompBiosculpterPod __instance)
=> FixStorage(__instance, __instance.allowedNutritionSettings);

[HarmonyPostfix]
[HarmonyPatch(typeof(CompChangeableProjectile), nameof(CompChangeableProjectile.PostExposeData))]
static void PostCompChangeableProjectile(CompChangeableProjectile __instance)
=> FixStorage(__instance, __instance.allowedShellsSettings);

// Fix syncing of copy/paste due to null StorageSettings.owner by assigning the parent
// in ExposeData. The patched types omit passing/assigning self as the owner by passing
// Array.Empty<object>() as the argument to expose data on StorageSetting.
static void FixStorage(IStoreSettingsParent __instance, StorageSettings ___allowedNutritionSettings)
{
if (Scribe.mode == LoadSaveMode.PostLoadInit)
___allowedNutritionSettings.owner ??= __instance;
}
}
}

0 comments on commit ceb2307

Please sign in to comment.