From 7dcd7b56a37237b8c7aa37c75bb8affd5c265178 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Mon, 31 Jul 2023 23:56:23 +0800 Subject: [PATCH] LabOpt: v0.3.4 --- LabOpt/Functions.cs | 30 +++++++++++++++++++++++++++++- LabOpt/LabOpt.cs | 10 +++++----- LabOpt/LabOpt.csproj | 2 +- LabOpt/README.md | 2 ++ LabOpt/package/manifest.json | 2 +- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/LabOpt/Functions.cs b/LabOpt/Functions.cs index 206501f..bf43343 100644 --- a/LabOpt/Functions.cs +++ b/LabOpt/Functions.cs @@ -348,7 +348,35 @@ public static class LabOptPatchFunctions return (uint)(lab.products[0] - LabComponent.matrixIds[0] + 1); } - public static void SetFunctionNew(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool) + public static void SetFunctionManually(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool) + { + var rootLabId = (int)RootLabIdField.GetValue(lab); + if (rootLabId > 0) + { + ref var rootLab = ref labPool[rootLabId]; + if (researchMode != rootLab.researchMode) + { + SetFunctionInternal(ref rootLab, researchMode, recpId, techId, signPool, labPool); + } + else if (researchMode) + { + if (rootLab.techId != techId) + { + SetFunctionInternal(ref rootLab, true, recpId, techId, signPool, labPool); + } + } + else + { + if (rootLab.recipeId != recpId) + { + SetFunctionInternal(ref rootLab, false, recpId, techId, signPool, labPool); + } + } + } + SetFunctionInternal(ref lab, researchMode, recpId, techId, signPool, labPool); + } + + private static void SetFunctionInternal(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool) { // LabOptPatch.Logger.LogDebug($"SetFunctionNew: {lab.id} {(int)RootLabIdField.GetValue(lab)} {researchMode} {recpId} {techId}"); lab.replicating = false; diff --git a/LabOpt/LabOpt.cs b/LabOpt/LabOpt.cs index 7f34bb8..5e40133 100644 --- a/LabOpt/LabOpt.cs +++ b/LabOpt/LabOpt.cs @@ -172,7 +172,7 @@ public class LabOptPatch : BaseUnityPlugin return matcher.InstructionEnumeration(); } - // Redirect call of LabComponent.SetFunction() to SetFunctionNew() + // Redirect call of LabComponent.SetFunction() to SetFunctionManually() [HarmonyTranspiler] [HarmonyPatch(typeof(BuildingParameters), nameof(BuildingParameters.ApplyPrebuildParametersToEntity))] private static IEnumerable BuildingParameters_ApplyPrebuildParametersToEntity_Transpiler(IEnumerable instructions, ILGenerator generator) @@ -186,7 +186,7 @@ public class LabOptPatch : BaseUnityPlugin new CodeInstruction(OpCodes.Ldloc_2), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.labPool))) ).SetInstructionAndAdvance( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionNew))) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionManually))) ); }); return matcher.InstructionEnumeration(); @@ -205,7 +205,7 @@ public class LabOptPatch : BaseUnityPlugin new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), nameof(PlanetFactory.factorySystem))), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.labPool))) ).SetInstructionAndAdvance( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionNew))) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionManually))) ); }); return matcher.InstructionEnumeration(); @@ -227,7 +227,7 @@ public class LabOptPatch : BaseUnityPlugin new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.labPool))) ).SetInstructionAndAdvance( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionNew))) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionManually))) ); }); return matcher.InstructionEnumeration(); @@ -247,7 +247,7 @@ public class LabOptPatch : BaseUnityPlugin new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UILabWindow), nameof(UILabWindow.factorySystem))), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.labPool))) ).SetInstructionAndAdvance( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionNew))) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.SetFunctionManually))) ); }); return matcher.InstructionEnumeration(); diff --git a/LabOpt/LabOpt.csproj b/LabOpt/LabOpt.csproj index 96b50de..690f46b 100644 --- a/LabOpt/LabOpt.csproj +++ b/LabOpt/LabOpt.csproj @@ -5,7 +5,7 @@ LabOpt org.soardev.labopt DSP MOD - LabOpt - 0.3.3 + 0.3.4 true latest diff --git a/LabOpt/README.md b/LabOpt/README.md index 013ae21..c7498f6 100644 --- a/LabOpt/README.md +++ b/LabOpt/README.md @@ -4,6 +4,8 @@ #### 优化研究站性能 ## Updates +* 0.3.4 + * Fix various crashes on recipe/research mode changing on labs that are not base level. * 0.3.3 * Add a lock to `PlanetFactory.PickFrom()` to avoid thread-conflicts. * 0.3.2 diff --git a/LabOpt/package/manifest.json b/LabOpt/package/manifest.json index bf80b04..b3ba010 100644 --- a/LabOpt/package/manifest.json +++ b/LabOpt/package/manifest.json @@ -1,6 +1,6 @@ { "name": "LabOpt", - "version_number": "0.3.3", + "version_number": "0.3.4", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/LabOpt", "description": "Optimize Lab performance / 优化研究站性能", "dependencies": [