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

Fix syncing of copy/paste gizmos for Biosculpter/Growth Vat/Mortar, fixes #255 #407

Merged
merged 2 commits into from
Dec 27, 2023
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
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;
}
}
}
Loading