mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
Work in progress
This commit is contained in:
@@ -19,7 +19,7 @@ public static class LabOptPatchFunctions
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
RootLabIdField.SetValueDirect(__makeref(labPool[targetLabId]), rootId);
|
RootLabIdField.SetValueDirect(__makeref(labPool[targetLabId]), rootId);
|
||||||
LabOptPatch.Logger.LogDebug($"Set rootLabId of lab {targetLabId} to {rootId}");
|
// LabOptPatch.Logger.LogDebug($"Set rootLabId of lab {targetLabId} to {rootId}");
|
||||||
} while ((targetLabId = labPool[targetLabId].nextLabId) > 0);
|
} while ((targetLabId = labPool[targetLabId].nextLabId) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public static class LabOptPatchFunctions
|
|||||||
var rootId = pair.Value;
|
var rootId = pair.Value;
|
||||||
while (parentDict.TryGetValue(rootId, out var parentId)) rootId = parentId;
|
while (parentDict.TryGetValue(rootId, out var parentId)) rootId = parentId;
|
||||||
RootLabIdField.SetValueDirect(__makeref(labPool[pair.Key]), rootId);
|
RootLabIdField.SetValueDirect(__makeref(labPool[pair.Key]), rootId);
|
||||||
LabOptPatch.Logger.LogDebug($"Set rootLabId of lab {pair.Key} to {rootId}");
|
// LabOptPatch.Logger.LogDebug($"Set rootLabId of lab {pair.Key} to {rootId}");
|
||||||
AssignRootLabValues(ref labPool[rootId], ref labPool[pair.Key]);
|
AssignRootLabValues(ref labPool[rootId], ref labPool[pair.Key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ public static class LabOptPatchFunctions
|
|||||||
|
|
||||||
public static void SetFunctionNew(ref LabComponent lab, bool researchMode, int recpId, int techId, SignData[] signPool, LabComponent[] labPool)
|
public static void SetFunctionNew(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}");
|
// LabOptPatch.Logger.LogDebug($"SetFunctionNew: {lab.id} {(int)RootLabIdField.GetValue(lab)} {researchMode} {recpId} {techId}");
|
||||||
lab.replicating = false;
|
lab.replicating = false;
|
||||||
lab.time = 0;
|
lab.time = 0;
|
||||||
lab.hashBytes = 0;
|
lab.hashBytes = 0;
|
||||||
@@ -503,4 +503,39 @@ public static class LabOptPatchFunctions
|
|||||||
signPool[lab.entityId].iconId0 = (uint)lab.recipeId;
|
signPool[lab.entityId].iconId0 = (uint)lab.recipeId;
|
||||||
signPool[lab.entityId].iconType = lab.recipeId == 0 ? 0U : 2U;
|
signPool[lab.entityId].iconType = lab.recipeId == 0 ? 0U : 2U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int InsertIntoLab(PlanetFactory factory, int labId, int itemId, byte itemCount, byte itemInc, ref byte remainInc, int[] needs)
|
||||||
|
{
|
||||||
|
var factorySystem = factory.factorySystem;
|
||||||
|
var served = factorySystem.labPool[labId].served;
|
||||||
|
var incServed = factorySystem.labPool[labId].incServed;
|
||||||
|
var matrixServed = factorySystem.labPool[labId].matrixServed;
|
||||||
|
var matrixIncServed = factorySystem.labPool[labId].matrixIncServed;
|
||||||
|
var len = needs.Length;
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (needs[i] != itemId) continue;
|
||||||
|
if (served != null)
|
||||||
|
{
|
||||||
|
lock (served)
|
||||||
|
{
|
||||||
|
served[i] += itemCount;
|
||||||
|
incServed[i] += itemInc;
|
||||||
|
}
|
||||||
|
remainInc = 0;
|
||||||
|
return itemCount;
|
||||||
|
}
|
||||||
|
if (matrixServed != null)
|
||||||
|
{
|
||||||
|
lock (matrixServed)
|
||||||
|
{
|
||||||
|
matrixServed[i] += 3600 * itemCount;
|
||||||
|
matrixIncServed[i] += 3600 * itemInc;
|
||||||
|
}
|
||||||
|
remainInc = 0;
|
||||||
|
return itemCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
|
using System.Threading;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
@@ -267,5 +268,43 @@ public class LabOptPatch : BaseUnityPlugin
|
|||||||
);
|
);
|
||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change locks on PlanetFactory.InsertInto()
|
||||||
|
[HarmonyTranspiler]
|
||||||
|
[HarmonyPatch(typeof(PlanetFactory), nameof(PlanetFactory.InsertInto))]
|
||||||
|
private static IEnumerable<CodeInstruction> PlanetFactory_InsertInto_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||||
|
{
|
||||||
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
|
/* Remove following codes:
|
||||||
|
465 0427 ldarg.0
|
||||||
|
466 0428 ldfld class Mutex[] PlanetFactory::entityMutexs
|
||||||
|
467 042D ldarg.1
|
||||||
|
468 042E ldelem.ref
|
||||||
|
469 042F stloc.s V_10 (10)
|
||||||
|
470 0431 ldc.i4.0
|
||||||
|
471 0432 stloc.s V_11 (11)
|
||||||
|
472 0434 ldloc.s V_10 (10)
|
||||||
|
473 0436 ldloca.s V_11 (11)
|
||||||
|
474 0438 call void [netstandard]System.Threading.Monitor::Enter(object, bool&)
|
||||||
|
*/
|
||||||
|
matcher.MatchForward(false,
|
||||||
|
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EntityData), nameof(EntityData.labId)))
|
||||||
|
).Advance(1).MatchForward(false,
|
||||||
|
new CodeMatch(OpCodes.Ret)
|
||||||
|
).Advance(1);
|
||||||
|
var labels = matcher.Instruction.labels;
|
||||||
|
matcher.InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
|
||||||
|
new CodeInstruction(OpCodes.Ldloc_S, 5),
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_3),
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_S, 4),
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_S, 5),
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_S, 6),
|
||||||
|
new CodeInstruction(OpCodes.Ldloc_1),
|
||||||
|
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(LabOptPatchFunctions), nameof(LabOptPatchFunctions.InsertIntoLab))),
|
||||||
|
new CodeInstruction(OpCodes.Ret)
|
||||||
|
);
|
||||||
|
matcher.Instruction.labels.Clear();
|
||||||
|
return matcher.InstructionEnumeration();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.0</Version>
|
<Version>0.3.2</Version>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "LabOpt",
|
"name": "LabOpt",
|
||||||
"version_number": "0.3.0",
|
"version_number": "0.3.2",
|
||||||
"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": [
|
||||||
|
|||||||
Reference in New Issue
Block a user