1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 20:53:28 +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

@@ -11,16 +11,29 @@ namespace LabOpt;
public static class LabOptPatchFunctions
{
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)
{
var labPool = factorySystem.labPool;
var factory = factorySystem.factory;
var rootId = (int)RootLabIdField.GetValue(labPool[labId]);
var targetLabId = factorySystem.factory.entityPool[nextEntityId].labId;
if (rootId <= 0) rootId = labId;
if (rootId <= 0)
{
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];
var needSetFunction = rootLab.researchMode || rootLab.recipeId > 0;
var entitySignPool = needSetFunction ? factorySystem.factory.entitySignPool : null;
var targetLabId = factory.entityPool[nextEntityId].labId;
do
{
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)
{
int len;
@@ -367,34 +381,37 @@ public static class LabOptPatchFunctions
ref var rootLab = ref labPool[rootLabId];
if (researchMode != rootLab.researchMode)
{
SetFunctionInternal(ref rootLab, researchMode, recpId, techId, signPool, labPool);
SetFunctionManually(ref rootLab, researchMode, recpId, techId, signPool, labPool);
}
else if (researchMode)
{
if (techId != rootLab.techId)
{
SetFunctionInternal(ref rootLab, true, recpId, techId, signPool, labPool);
SetFunctionManually(ref rootLab, true, recpId, techId, signPool, labPool);
}
}
else
{
if (recpId != rootLab.recipeId)
{
SetFunctionInternal(ref rootLab, false, recpId, techId, signPool, labPool);
SetFunctionManually(ref rootLab, false, recpId, techId, signPool, labPool);
}
}
}
SetFunctionInternal(ref lab, researchMode, recpId, techId, signPool, labPool);
var thisId = lab.id;
var needs = lab.needs;
var nextLabId = lab.nextLabId;
while (nextLabId > 0)
else
{
ref var nextLab = ref labPool[nextLabId];
if ((int)RootLabIdField.GetValue(nextLab) != thisId) break;
if (needs != nextLab.needs)
SetFunctionInternal(ref nextLab, researchMode, recpId, techId, signPool, labPool);
nextLabId = nextLab.nextLabId;
SetFunctionInternal(ref lab, researchMode, recpId, techId, signPool, labPool);
var thisId = lab.id;
var needs = lab.needs;
var nextLabId = lab.nextLabId;
while (nextLabId > 0)
{
ref var nextLab = ref labPool[nextLabId];
if ((int)RootLabIdField.GetValue(nextLab) != thisId) break;
if (needs != nextLab.needs)
SetFunctionInternal(ref nextLab, researchMode, recpId, techId, signPool, labPool);
nextLabId = nextLab.nextLabId;
}
}
}

View File

@@ -326,4 +326,10 @@ public class LabOptPatch : BaseUnityPlugin
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>
<BepInExPluginGuid>org.soardev.labopt</BepInExPluginGuid>
<Description>DSP MOD - LabOpt</Description>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

View File

@@ -4,6 +4,8 @@
#### 优化研究站性能
## Updates
* 0.3.6
+ Fix a critical problem that cause labs not working, as well as optimizations in some functions.
* 0.3.5
+ Add some codes to avoid labs malfunctioning on stacking.
* 0.3.4
@@ -32,6 +34,9 @@
* 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.
## Notes
* If get any lab not working, just save and reload the game to fix it as a temporary solution.
## Known issue
* 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.
@@ -48,6 +53,9 @@
* 向任意层放入或取出物品实际上都是对底层的操作
* 增加研究站的输入和输出容量到15和30以避免输入供应不足和输出堵塞
## 说明
* 如果发现有任何研究站不工作,只需保存并重新加载游戏即可暂时解决。
## 已知问题
* 在研发模式下,你会发现堆叠研究站的进度圈运行得更快
* 这是正常的,因为计算机制的原因,它并不会改变真实的消耗和产出

View File

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