Added stat caching, fixed all the bugs

Added RitualObligationTriggers analyzer category,
Fixed defs from other mods with broken market value breaking fish's storage patches,
Fixed storage caches not updating for quality, rotting and similar changes to stored things,
Fixed storage caches not updating capacity when reinstalling storage,
Fixed prison labor compatibility,
Improved multiplayer compatibility,
Fixed ideology style dominance and altar sharing patches throwing errors instead of defaulting to disabled when not having ideology,
Fixed compatibility with RIMMSqol's world pawn GC patch by disabling that patch,
Fixed rare threading issues throwing errors on startup
This commit is contained in:
bbradson
2024-03-10 20:05:24 +01:00
parent a4ee95fde1
commit be3dae46bb
45 changed files with 1090 additions and 414 deletions
@@ -0,0 +1,78 @@
// Copyright (c) 2023 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
namespace PerformanceFish.ModCompatibility;
public static class RIMMSqol
{
private const string ASSEMBLY_NAME = "RIMMSqol";
public static bool Active => ActiveMods.RIMMSqol;
public static string[] BlockedPatchNamespaces { get; } = ["WorldPawnGC"];
public static ModContentPack? ModContentPack { get; }
= ActiveMods.TryGetModContentPack(PackageIDs.RIMMSQOL);
public static Type? HarmonyPatchNamespaceType { get; }
public static MethodInfo? RegisterAllMethod { get; }
static RIMMSqol()
{
if (ModContentPack is null)
return;
if (ModContentPack.TryGetAssembly(ASSEMBLY_NAME) is not { } assembly)
{
LogFailureToFind("assembly");
return;
}
if ((HarmonyPatchNamespaceType = assembly.GetType("RIMMSqol.HarmonyPatchNamespace")) is null)
{
LogFailureToFind("harmony patch namespace type");
return;
}
if ((RegisterAllMethod = AccessTools.DeclaredMethod(HarmonyPatchNamespaceType, "registerAll")) is null)
LogFailureToFind("registerAll method");
}
private static void LogFailureToFind(string text)
=> Log.Error($"Performance Fish failed to find RIMMSqol's {
text}. This is likely to cause issues.");
public static bool TryPatch()
=> RegisterAllMethod is { } registerAllMethod
&& PerformanceFishMod.Harmony.Patch(registerAllMethod, postfix: new(methodof(RegisterAllPostfix))) != null;
public static void RegisterAllPostfix()
{
if (AccessTools.Field(HarmonyPatchNamespaceType, "namespaces").GetValue(null) is not IDictionary namespaces)
{
LogFailureToFind("harmony patch namespaces field");
return;
}
foreach (var blockedPatchNamespace in BlockedPatchNamespaces)
{
if (!namespaces.Contains(blockedPatchNamespace))
{
LogFailureToFind(blockedPatchNamespace);
continue;
}
var properties = namespaces[blockedPatchNamespace];
if (AccessTools.Field(properties.GetType(), "active") is not { } activeField)
{
LogFailureToFind("harmony patch active field");
return;
}
activeField.SetValue(properties, false);
}
}
}