1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-04 23:02:23 +08:00

LabOpt 0.3.6

This commit is contained in:
2023-09-05 01:24:19 +08:00
parent 42200de729
commit d7943f1751
5 changed files with 48 additions and 17 deletions

View File

@@ -12,15 +12,28 @@ public static class LabOptPatchFunctions
{ {
private static readonly FieldInfo RootLabIdField = AccessTools.Field(typeof(LabComponent), "rootLabId"); private static readonly FieldInfo RootLabIdField = AccessTools.Field(typeof(LabComponent), "rootLabId");
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetRootId(ref LabComponent lab, int rootId)
{
RootLabIdField.SetValueDirect(__makeref(lab), rootId);
}
public static void SetRootLabIdForStacking(FactorySystem factorySystem, int labId, int nextEntityId) public static void SetRootLabIdForStacking(FactorySystem factorySystem, int labId, int nextEntityId)
{ {
var labPool = factorySystem.labPool; var labPool = factorySystem.labPool;
var factory = factorySystem.factory;
var rootId = (int)RootLabIdField.GetValue(labPool[labId]); var rootId = (int)RootLabIdField.GetValue(labPool[labId]);
var targetLabId = factorySystem.factory.entityPool[nextEntityId].labId; if (rootId <= 0)
if (rootId <= 0) rootId = labId; {
var radiusBear = factory.planet.radius + 2.0f;
if (factory.entityPool[labPool[labId].entityId].pos.sqrMagnitude > radiusBear * radiusBear)
return;
rootId = labId;
}
ref var rootLab = ref labPool[rootId]; ref var rootLab = ref labPool[rootId];
var needSetFunction = rootLab.researchMode || rootLab.recipeId > 0; var needSetFunction = rootLab.researchMode || rootLab.recipeId > 0;
var entitySignPool = needSetFunction ? factorySystem.factory.entitySignPool : null; var entitySignPool = needSetFunction ? factorySystem.factory.entitySignPool : null;
var targetLabId = factory.entityPool[nextEntityId].labId;
do do
{ {
ref var targetLab = ref labPool[targetLabId]; ref var targetLab = ref labPool[targetLabId];
@@ -77,6 +90,7 @@ public static class LabOptPatchFunctions
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AssignRootLabValues(ref LabComponent rootLab, ref LabComponent thisLab) private static void AssignRootLabValues(ref LabComponent rootLab, ref LabComponent thisLab)
{ {
int len; int len;
@@ -367,23 +381,25 @@ public static class LabOptPatchFunctions
ref var rootLab = ref labPool[rootLabId]; ref var rootLab = ref labPool[rootLabId];
if (researchMode != rootLab.researchMode) if (researchMode != rootLab.researchMode)
{ {
SetFunctionInternal(ref rootLab, researchMode, recpId, techId, signPool, labPool); SetFunctionManually(ref rootLab, researchMode, recpId, techId, signPool, labPool);
} }
else if (researchMode) else if (researchMode)
{ {
if (techId != rootLab.techId) if (techId != rootLab.techId)
{ {
SetFunctionInternal(ref rootLab, true, recpId, techId, signPool, labPool); SetFunctionManually(ref rootLab, true, recpId, techId, signPool, labPool);
} }
} }
else else
{ {
if (recpId != rootLab.recipeId) if (recpId != rootLab.recipeId)
{ {
SetFunctionInternal(ref rootLab, false, recpId, techId, signPool, labPool); SetFunctionManually(ref rootLab, false, recpId, techId, signPool, labPool);
} }
} }
} }
else
{
SetFunctionInternal(ref lab, researchMode, recpId, techId, signPool, labPool); SetFunctionInternal(ref lab, researchMode, recpId, techId, signPool, labPool);
var thisId = lab.id; var thisId = lab.id;
var needs = lab.needs; var needs = lab.needs;
@@ -397,6 +413,7 @@ public static class LabOptPatchFunctions
nextLabId = nextLab.nextLabId; nextLabId = nextLab.nextLabId;
} }
} }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void SetFunctionInternal(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool) private static void SetFunctionInternal(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool)

View File

@@ -326,4 +326,10 @@ public class LabOptPatch : BaseUnityPlugin
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
} }
[HarmonyPostfix]
[HarmonyPatch(typeof(LabComponent), nameof(LabComponent.SetEmpty))]
private static void LabComponent_SetEmpty_Postfix(ref LabComponent __instance)
{
LabOptPatchFunctions.SetRootId(ref __instance, 0);
}
} }

View File

@@ -5,7 +5,7 @@
<AssemblyName>LabOpt</AssemblyName> <AssemblyName>LabOpt</AssemblyName>
<BepInExPluginGuid>org.soardev.labopt</BepInExPluginGuid> <BepInExPluginGuid>org.soardev.labopt</BepInExPluginGuid>
<Description>DSP MOD - LabOpt</Description> <Description>DSP MOD - LabOpt</Description>
<Version>0.3.5</Version> <Version>0.3.6</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>

View File

@@ -4,6 +4,8 @@
#### 优化研究站性能 #### 优化研究站性能
## Updates ## Updates
* 0.3.6
+ Fix a critical problem that cause labs not working, as well as optimizations in some functions.
* 0.3.5 * 0.3.5
+ Add some codes to avoid labs malfunctioning on stacking. + Add some codes to avoid labs malfunctioning on stacking.
* 0.3.4 * 0.3.4
@@ -32,6 +34,9 @@
* Insert into or pick from any level of Matrix Labs apply to base level actually. * Insert into or pick from any level of Matrix Labs apply to base level actually.
* Increased capacity input and output of Matrix Labs to 15 and 30, to avoid lack of supply or output jam. * Increased capacity input and output of Matrix Labs to 15 and 30, to avoid lack of supply or output jam.
## Notes
* If get any lab not working, just save and reload the game to fix it as a temporary solution.
## Known issue ## Known issue
* In researching mode, you will find the progress circle runs faster on stacked Labs * In researching mode, you will find the progress circle runs faster on stacked Labs
* This is normal due to mechanism of calculation, it does not change the real consumptions and output hashes. * This is normal due to mechanism of calculation, it does not change the real consumptions and output hashes.
@@ -48,6 +53,9 @@
* 向任意层放入或取出物品实际上都是对底层的操作 * 向任意层放入或取出物品实际上都是对底层的操作
* 增加研究站的输入和输出容量到15和30以避免输入供应不足和输出堵塞 * 增加研究站的输入和输出容量到15和30以避免输入供应不足和输出堵塞
## 说明
* 如果发现有任何研究站不工作,只需保存并重新加载游戏即可暂时解决。
## 已知问题 ## 已知问题
* 在研发模式下,你会发现堆叠研究站的进度圈运行得更快 * 在研发模式下,你会发现堆叠研究站的进度圈运行得更快
* 这是正常的,因为计算机制的原因,它并不会改变真实的消耗和产出 * 这是正常的,因为计算机制的原因,它并不会改变真实的消耗和产出

View File

@@ -1,6 +1,6 @@
{ {
"name": "LabOpt", "name": "LabOpt",
"version_number": "0.3.5", "version_number": "0.3.6",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/LabOpt", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/LabOpt",
"description": "Optimize Lab performance / 优化研究站性能", "description": "Optimize Lab performance / 优化研究站性能",
"dependencies": [ "dependencies": [