From 7d3426991a1cfec9f4b95b69ac23439b8c5934bb Mon Sep 17 00:00:00 2001 From: SokyranTheDragon Date: Sun, 3 Dec 2023 13:32:37 +0100 Subject: [PATCH 1/2] Fix syncing of copy/paste gizmos for Biosculpter/Growth Vat/Mortar, fixes #255 This fixes issue of copy/paste gizmos not working properly for: - Growth vats (`Building_GrowthVat`) - Biosculpter pods (`CompBiosculpterPod`) - Mortars (`CompChangeableProjectile`) The issue happened due to the storages associated to those losing their owner after loading them through `ExposeData`. The solution was to re-assign their owner in PostLoadInit. The patch is included in the generic `Patches.cs` file, as I felt it did not really fit any other existing source file containing patches (potentially `VanillaTweaks.cs`). However, if needed I could create a separate file for them or move them to a different location. I can also split them into separate patches, so a single class doesn't contain 3 postfixes. --- Source/Client/Patches/Patches.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Source/Client/Patches/Patches.cs b/Source/Client/Patches/Patches.cs index 175062bf..01ac4338 100644 --- a/Source/Client/Patches/Patches.cs +++ b/Source/Client/Patches/Patches.cs @@ -558,4 +558,32 @@ static void Postfix(PawnTextureAtlas __instance) ); } } + + [HarmonyPatch] + public static class NutritionStoragesKeepsItsOwner + { + [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() as the argument to expose data on StorageSetting. + static void FixStorage(IStoreSettingsParent __instance, StorageSettings ___allowedNutritionSettings) + { + if (Scribe.mode == LoadSaveMode.PostLoadInit) + ___allowedNutritionSettings.owner ??= __instance; + } + } } From ecaedb997a0f458caf483bffd4a5bf9ad5fc7b98 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon Date: Sun, 3 Dec 2023 13:35:30 +0100 Subject: [PATCH 2/2] NutritionStoragesKeepsItsOwner -> StoragesKeepsTheirOwners --- Source/Client/Patches/Patches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Client/Patches/Patches.cs b/Source/Client/Patches/Patches.cs index 01ac4338..7d8e76ab 100644 --- a/Source/Client/Patches/Patches.cs +++ b/Source/Client/Patches/Patches.cs @@ -560,7 +560,7 @@ static void Postfix(PawnTextureAtlas __instance) } [HarmonyPatch] - public static class NutritionStoragesKeepsItsOwner + public static class StoragesKeepsTheirOwners { [HarmonyPostfix] [HarmonyPatch(typeof(Building_GrowthVat), nameof(Building_GrowthVat.ExposeData))]