mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 14:13:31 +08:00
fixed rest issues
This commit is contained in:
@@ -1125,20 +1125,13 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
DeepProfiler.EndSample(DPEntry.Belt);
|
DeepProfiler.EndSample(DPEntry.Belt);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyTranspiler]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))]
|
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))]
|
||||||
public static IEnumerable<CodeInstruction> GameLogic_LogicFrame_Transpiler(IEnumerable<CodeInstruction> instructions)
|
public static void GameLogic_OnFactoryFrameBegin_Postfix()
|
||||||
{
|
{
|
||||||
var matcher = new CodeMatcher(instructions);
|
ProcessBeltSignals();
|
||||||
matcher.MatchForward(false,
|
|
||||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(DeepProfiler), nameof(DeepProfiler.EndSample), [typeof(int), typeof(long)]))
|
|
||||||
).Advance(1).Insert(
|
|
||||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(BeltSignalGenerator), nameof(ProcessBeltSignals)))
|
|
||||||
);
|
|
||||||
return matcher.InstructionEnumeration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* BEGIN: Item sources calculation */
|
/* BEGIN: Item sources calculation */
|
||||||
private static readonly Dictionary<int, ItemSource> ItemSources = [];
|
private static readonly Dictionary<int, ItemSource> ItemSources = [];
|
||||||
private static bool _itemSourcesInitialized;
|
private static bool _itemSourcesInitialized;
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ public static class ResourcePatch
|
|||||||
|
|
||||||
private class InfiniteResource : PatchImpl<InfiniteResource>
|
private class InfiniteResource : PatchImpl<InfiniteResource>
|
||||||
{
|
{
|
||||||
|
static private readonly float InfiniteResourceRate = 0f;
|
||||||
[HarmonyTranspiler]
|
[HarmonyTranspiler]
|
||||||
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))]
|
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))]
|
||||||
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool), typeof(int), typeof(int), typeof(int))]
|
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic._miner_parallel))]
|
||||||
[HarmonyPatch(typeof(ItemProto), nameof(ItemProto.GetPropValue))]
|
|
||||||
[HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))]
|
[HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))]
|
||||||
[HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))]
|
[HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))]
|
||||||
[HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))]
|
[HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))]
|
||||||
@@ -42,18 +42,29 @@ public static class ResourcePatch
|
|||||||
[HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))]
|
[HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))]
|
||||||
[HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
|
[HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
|
||||||
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
|
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
|
||||||
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))]
|
|
||||||
[HarmonyPatch(typeof(UIVeinCollectorPanel), nameof(UIVeinCollectorPanel._OnUpdate))]
|
[HarmonyPatch(typeof(UIVeinCollectorPanel), nameof(UIVeinCollectorPanel._OnUpdate))]
|
||||||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||||
{
|
{
|
||||||
var matcher = new CodeMatcher(instructions, generator);
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
matcher.MatchForward(false,
|
matcher.MatchForward(false,
|
||||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningCostRate)))
|
new CodeMatch(ci => (ci.opcode == OpCodes.Ldfld || ci.opcode == OpCodes.Ldflda) && ci.OperandIs(AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningCostRate))))
|
||||||
).Repeat(codeMatcher =>
|
).Repeat(codeMatcher =>
|
||||||
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
{
|
||||||
new CodeInstruction(OpCodes.Pop),
|
if (codeMatcher.Instruction.opcode == OpCodes.Ldfld)
|
||||||
new CodeInstruction(OpCodes.Ldc_R4, 0f)
|
{
|
||||||
)
|
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Pop),
|
||||||
|
new CodeInstruction(OpCodes.Ldc_R4, InfiniteResourceRate)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Pop),
|
||||||
|
new CodeInstruction(OpCodes.Ldsflda, AccessTools.Field(typeof(InfiniteResource), nameof(InfiniteResourceRate)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
@@ -61,15 +72,25 @@ public static class ResourcePatch
|
|||||||
|
|
||||||
private class FastMining : PatchImpl<FastMining>
|
private class FastMining : PatchImpl<FastMining>
|
||||||
{
|
{
|
||||||
|
static private readonly float FastMiningSpeed = 2400f;
|
||||||
|
|
||||||
[HarmonyTranspiler]
|
[HarmonyTranspiler]
|
||||||
|
[HarmonyPatch(typeof(AstroResourceStatPlan), nameof(AstroResourceStatPlan.AddPlanetResources))]
|
||||||
|
[HarmonyPatch(typeof(BuildingGizmo), nameof(BuildingGizmo.Update))]
|
||||||
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))]
|
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))]
|
||||||
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool), typeof(int), typeof(int), typeof(int))]
|
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic._miner_parallel))]
|
||||||
[HarmonyPatch(typeof(ItemProto), nameof(ItemProto.GetPropValue))]
|
[HarmonyPatch(typeof(ItemProto), nameof(ItemProto.GetPropValue))]
|
||||||
[HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))]
|
[HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))]
|
||||||
|
[HarmonyPatch(typeof(ProductionExtraInfoCalculator), nameof(ProductionExtraInfoCalculator.CalculateFactory))]
|
||||||
|
[HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))]
|
||||||
|
[HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))]
|
||||||
|
[HarmonyPatch(typeof(UIControlPanelStationStorage), nameof(UIControlPanelStationStorage.RefreshValues))]
|
||||||
|
[HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))]
|
||||||
[HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
|
[HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
|
||||||
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
|
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
|
||||||
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))]
|
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))]
|
||||||
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.RefreshDynamicProperties))]
|
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.RefreshDynamicProperties))]
|
||||||
|
[HarmonyPatch(typeof(UIReferenceSpeedTip), nameof(UIReferenceSpeedTip.AddEntryDataWithFactory))]
|
||||||
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))]
|
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))]
|
||||||
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.RefreshDynamicProperties))]
|
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.RefreshDynamicProperties))]
|
||||||
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))]
|
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))]
|
||||||
@@ -78,12 +99,24 @@ public static class ResourcePatch
|
|||||||
{
|
{
|
||||||
var matcher = new CodeMatcher(instructions, generator);
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
matcher.MatchForward(false,
|
matcher.MatchForward(false,
|
||||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningSpeedScale)))
|
new CodeMatch(ci => (ci.opcode == OpCodes.Ldfld || ci.opcode == OpCodes.Ldflda) && ci.OperandIs(AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningSpeedScale))))
|
||||||
).Repeat(codeMatcher =>
|
).Repeat(codeMatcher =>
|
||||||
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
{
|
||||||
new CodeInstruction(OpCodes.Pop),
|
if (codeMatcher.Instruction.opcode == OpCodes.Ldfld)
|
||||||
new CodeInstruction(OpCodes.Ldc_R4, 2400f)
|
{
|
||||||
)
|
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Pop),
|
||||||
|
new CodeInstruction(OpCodes.Ldc_R4, FastMiningSpeed)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
codeMatcher.RemoveInstruction().InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Pop),
|
||||||
|
new CodeInstruction(OpCodes.Ldsflda, AccessTools.Field(typeof(FastMining), nameof(FastMiningSpeed)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1832,91 +1832,82 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyTranspiler]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))]
|
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))]
|
||||||
public static IEnumerable<CodeInstruction> GameLogic_LogicFrame_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
public static void GameLogic_OnFactoryFrameBegin_Postfix()
|
||||||
{
|
{
|
||||||
var matcher = new CodeMatcher(instructions, generator);
|
var factories = GameMain.data?.factories;
|
||||||
matcher.MatchForward(false,
|
if (factories == null) return;
|
||||||
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(DeepProfiler), nameof(DeepProfiler.EndSample), [typeof(int), typeof(long)]))
|
var factoriesCount = factories.Length;
|
||||||
).Advance(1).Insert(
|
var propertySystem = DSPGame.propertySystem;
|
||||||
Transpilers.EmitDelegate(() =>
|
List<int> factoriesToRemove = null;
|
||||||
|
foreach (var factoryIndex in SignalBeltFactoryIndices)
|
||||||
|
{
|
||||||
|
if (factoryIndex >= factoriesCount)
|
||||||
{
|
{
|
||||||
var factories = GameMain.data?.factories;
|
if (factoriesToRemove == null)
|
||||||
if (factories == null) return;
|
factoriesToRemove = [factoryIndex];
|
||||||
var factoriesCount = factories.Length;
|
else
|
||||||
var propertySystem = DSPGame.propertySystem;
|
factoriesToRemove.Add(factoryIndex);
|
||||||
List<int> factoriesToRemove = null;
|
continue;
|
||||||
foreach (var factoryIndex in SignalBeltFactoryIndices)
|
}
|
||||||
|
var signalBelts = GetSignalBelts(factoryIndex);
|
||||||
|
if (signalBelts == null) continue;
|
||||||
|
var factory = factories[factoryIndex];
|
||||||
|
if (factory == null) continue;
|
||||||
|
var cargoTraffic = factory.cargoTraffic;
|
||||||
|
var beltCount = cargoTraffic.beltCursor;
|
||||||
|
List<int> beltsToRemove = null;
|
||||||
|
foreach (var kvp in signalBelts)
|
||||||
|
{
|
||||||
|
if (kvp.Key >= beltCount)
|
||||||
{
|
{
|
||||||
if (factoryIndex >= factoriesCount)
|
if (beltsToRemove == null)
|
||||||
{
|
beltsToRemove = [kvp.Key];
|
||||||
if (factoriesToRemove == null)
|
|
||||||
factoriesToRemove = [factoryIndex];
|
|
||||||
else
|
|
||||||
factoriesToRemove.Add(factoryIndex);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var signalBelts = GetSignalBelts(factoryIndex);
|
|
||||||
if (signalBelts == null) continue;
|
|
||||||
var factory = factories[factoryIndex];
|
|
||||||
if (factory == null) continue;
|
|
||||||
var cargoTraffic = factory.cargoTraffic;
|
|
||||||
var beltCount = cargoTraffic.beltCursor;
|
|
||||||
List<int> beltsToRemove = null;
|
|
||||||
foreach (var kvp in signalBelts)
|
|
||||||
{
|
|
||||||
if (kvp.Key >= beltCount)
|
|
||||||
{
|
|
||||||
if (beltsToRemove == null)
|
|
||||||
beltsToRemove = [kvp.Key];
|
|
||||||
else
|
|
||||||
beltsToRemove.Add(kvp.Key);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ref var belt = ref cargoTraffic.beltPool[kvp.Key];
|
|
||||||
var cargoPath = cargoTraffic.GetCargoPath(belt.segPathId);
|
|
||||||
var itemIdx = kvp.Value;
|
|
||||||
if (cargoPath == null) continue;
|
|
||||||
var itemId = DarkFogItemIds[itemIdx];
|
|
||||||
var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
|
|
||||||
if (consume < 4)
|
|
||||||
{
|
|
||||||
var metaverse = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006);
|
|
||||||
if (metaverse > 0)
|
|
||||||
{
|
|
||||||
if (metaverse > 10)
|
|
||||||
metaverse = 10;
|
|
||||||
propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse);
|
|
||||||
var mainPlayer = GameMain.mainPlayer;
|
|
||||||
GameMain.history.AddPropertyItemConsumption(6006, metaverse, true);
|
|
||||||
var count = DarkFogItemExchangeRate[itemIdx] * metaverse;
|
|
||||||
DarkFogItemsInVoid[itemIdx] += count;
|
|
||||||
consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
|
|
||||||
mainPlayer.mecha.AddProductionStat(itemId, count, mainPlayer.nearestFactory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consume > 0 && cargoPath.TryInsertItem(belt.segIndex + belt.segPivotOffset, itemId, consume, 0))
|
|
||||||
DarkFogItemsInVoid[itemIdx] -= consume;
|
|
||||||
}
|
|
||||||
if (beltsToRemove == null) continue;
|
|
||||||
foreach (var beltId in beltsToRemove)
|
|
||||||
signalBelts.Remove(beltId);
|
|
||||||
if (signalBelts.Count > 0) continue;
|
|
||||||
if (factoriesToRemove == null)
|
|
||||||
factoriesToRemove = [factoryIndex];
|
|
||||||
else
|
else
|
||||||
factoriesToRemove.Add(factoryIndex);
|
beltsToRemove.Add(kvp.Key);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (factoriesToRemove == null) return;
|
ref var belt = ref cargoTraffic.beltPool[kvp.Key];
|
||||||
foreach (var factoryIndex in factoriesToRemove)
|
var cargoPath = cargoTraffic.GetCargoPath(belt.segPathId);
|
||||||
|
var itemIdx = kvp.Value;
|
||||||
|
if (cargoPath == null) continue;
|
||||||
|
var itemId = DarkFogItemIds[itemIdx];
|
||||||
|
var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
|
||||||
|
if (consume < 4)
|
||||||
{
|
{
|
||||||
RemovePlanetSignalBelts(factoryIndex);
|
var metaverse = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006);
|
||||||
|
if (metaverse > 0)
|
||||||
|
{
|
||||||
|
if (metaverse > 10)
|
||||||
|
metaverse = 10;
|
||||||
|
propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse);
|
||||||
|
var mainPlayer = GameMain.mainPlayer;
|
||||||
|
GameMain.history.AddPropertyItemConsumption(6006, metaverse, true);
|
||||||
|
var count = DarkFogItemExchangeRate[itemIdx] * metaverse;
|
||||||
|
DarkFogItemsInVoid[itemIdx] += count;
|
||||||
|
consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
|
||||||
|
mainPlayer.mecha.AddProductionStat(itemId, count, mainPlayer.nearestFactory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
);
|
if (consume > 0 && cargoPath.TryInsertItem(belt.segIndex + belt.segPivotOffset, itemId, consume, 0))
|
||||||
return matcher.InstructionEnumeration();
|
DarkFogItemsInVoid[itemIdx] -= consume;
|
||||||
|
}
|
||||||
|
if (beltsToRemove == null) continue;
|
||||||
|
foreach (var beltId in beltsToRemove)
|
||||||
|
signalBelts.Remove(beltId);
|
||||||
|
if (signalBelts.Count > 0) continue;
|
||||||
|
if (factoriesToRemove == null)
|
||||||
|
factoriesToRemove = [factoryIndex];
|
||||||
|
else
|
||||||
|
factoriesToRemove.Add(factoryIndex);
|
||||||
|
}
|
||||||
|
if (factoriesToRemove == null) return;
|
||||||
|
foreach (var factoryIndex in factoriesToRemove)
|
||||||
|
{
|
||||||
|
RemovePlanetSignalBelts(factoryIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user