mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 19:33:27 +08:00
work in progress
This commit is contained in:
@@ -24,6 +24,13 @@ public static class FactoryFunctions
|
|||||||
cargoTraffic.AlterBeltConnections(beltId, 0, i0, i1, i2);
|
cargoTraffic.AlterBeltConnections(beltId, 0, i0, i1, i2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool ObjectIsBeltOrInserter(PlanetFactory factory, int objId)
|
||||||
|
{
|
||||||
|
if (objId == 0) return false;
|
||||||
|
ItemProto proto = LDB.items.Select(objId > 0 ? factory.entityPool[objId].protoId : factory.prebuildPool[-objId].protoId);
|
||||||
|
return proto != null && (proto.prefabDesc.isBelt || proto.prefabDesc.isInserter);
|
||||||
|
}
|
||||||
|
|
||||||
public static void DismantleBlueprintSelectedBuildings()
|
public static void DismantleBlueprintSelectedBuildings()
|
||||||
{
|
{
|
||||||
var player = GameMain.mainPlayer;
|
var player = GameMain.mainPlayer;
|
||||||
@@ -50,7 +57,7 @@ public static class FactoryFunctions
|
|||||||
for (var j = 0; j < 2; j++)
|
for (var j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||||
if (connObjId == 0 || factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)) continue;
|
if (connObjId == 0 || ObjectIsBeltOrInserter(factory, connObjId)) continue;
|
||||||
needCheck = true;
|
needCheck = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -59,7 +66,7 @@ public static class FactoryFunctions
|
|||||||
for (var k = 0; k < 16; k++)
|
for (var k = 0; k < 16; k++)
|
||||||
{
|
{
|
||||||
factory.ReadObjectConn(objId, k, out _, out var connObjId, out _);
|
factory.ReadObjectConn(objId, k, out _, out var connObjId, out _);
|
||||||
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && (factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)))
|
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && ObjectIsBeltOrInserter(factory, connObjId))
|
||||||
buildPreviewsToRemove.Insert(~index, connObjId);
|
buildPreviewsToRemove.Insert(~index, connObjId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +77,7 @@ public static class FactoryFunctions
|
|||||||
for (var j = 0; j < 2; j++)
|
for (var j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
factory.ReadObjectConn(connObjId, j, out _, out var connObjId2, out _);
|
factory.ReadObjectConn(connObjId, j, out _, out var connObjId2, out _);
|
||||||
if (connObjId2 == 0 || (index = buildPreviewsToRemove.BinarySearch(connObjId2)) >= 0 || factory.ObjectIsBelt(connObjId2) || blueprintCopyTool.ObjectIsInserter(connObjId2)) continue;
|
if (connObjId2 == 0 || (index = buildPreviewsToRemove.BinarySearch(connObjId2)) >= 0 || ObjectIsBeltOrInserter(factory, connObjId2)) continue;
|
||||||
buildPreviewsToRemove.Insert(~index, connObjId);
|
buildPreviewsToRemove.Insert(~index, connObjId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -81,7 +88,7 @@ public static class FactoryFunctions
|
|||||||
for (var j = 0; j < 16; j++)
|
for (var j = 0; j < 16; j++)
|
||||||
{
|
{
|
||||||
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||||
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && (factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)))
|
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && ObjectIsBeltOrInserter(factory, connObjId))
|
||||||
buildPreviewsToRemove.Insert(~index, connObjId);
|
buildPreviewsToRemove.Insert(~index, connObjId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
79
UXAssist/ModsCompat/BlueprintTweaks.cs
Normal file
79
UXAssist/ModsCompat/BlueprintTweaks.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using UXAssist.Functions;
|
||||||
|
|
||||||
|
namespace UXAssist.ModsCompat;
|
||||||
|
|
||||||
|
class BlueprintTweaks
|
||||||
|
{
|
||||||
|
public const string BlueprintTweaksGuid = "org.kremnev8.plugin.BlueprintTweaks";
|
||||||
|
private static FieldInfo selectObjIdsField;
|
||||||
|
|
||||||
|
public static bool Run(Harmony harmony)
|
||||||
|
{
|
||||||
|
if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BlueprintTweaksGuid, out var pluginInfo)) return false;
|
||||||
|
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||||
|
var classType = assembly.GetType("BlueprintTweaks.DragRemoveBuildTool");
|
||||||
|
selectObjIdsField = AccessTools.Field(classType, "selectObjIds");
|
||||||
|
harmony.Patch(AccessTools.Method(classType, "DeterminePreviews"),
|
||||||
|
new HarmonyMethod(AccessTools.Method(typeof(BlueprintTweaks), nameof(PatchDeterminePreviews))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PatchDeterminePreviews(object __instance)
|
||||||
|
{
|
||||||
|
var selectObjIds = (HashSet<int>)selectObjIdsField.GetValue(__instance);
|
||||||
|
var buildTool = (BuildTool)__instance;
|
||||||
|
var factory = buildTool.factory;
|
||||||
|
HashSet<int> extraObjIds = [];
|
||||||
|
foreach (var objId in selectObjIds)
|
||||||
|
{
|
||||||
|
var desc = buildTool.GetPrefabDesc(objId);
|
||||||
|
var isBelt = desc.isBelt;
|
||||||
|
var isInserter = desc.isInserter;
|
||||||
|
if (isInserter) continue;
|
||||||
|
if (isBelt)
|
||||||
|
{
|
||||||
|
var needCheck = false;
|
||||||
|
for (var j = 0; j < 2; j++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||||
|
if (connObjId == 0 || FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId)) continue;
|
||||||
|
needCheck = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (needCheck)
|
||||||
|
{
|
||||||
|
for (var k = 0; k < 16; k++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(objId, k, out _, out var connObjId, out _);
|
||||||
|
if (connObjId != 0 && !selectObjIds.Contains(connObjId) && !extraObjIds.Contains(connObjId) && FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId))
|
||||||
|
extraObjIds.Add(connObjId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var m = 0; m < 4; m++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(objId, m, out _, out var connObjId, out _);
|
||||||
|
if (connObjId == 0 || !factory.ObjectIsBelt(connObjId) || selectObjIds.Contains(connObjId) || extraObjIds.Contains(connObjId)) continue;
|
||||||
|
for (var j = 0; j < 2; j++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(connObjId, j, out _, out var connObjId2, out _);
|
||||||
|
if (connObjId2 == 0 || selectObjIds.Contains(connObjId2) || extraObjIds.Contains(connObjId2) || FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId2)) continue;
|
||||||
|
extraObjIds.Add(connObjId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (desc.addonType == EAddonType.Belt) continue;
|
||||||
|
for (var j = 0; j < 16; j++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||||
|
if (connObjId != 0 && !selectObjIds.Contains(connObjId) && !extraObjIds.Contains(connObjId) && FactoryFunctions.ObjectIsBeltOrInserter(factory, connObjId))
|
||||||
|
extraObjIds.Add(connObjId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectObjIds.UnionWith(extraObjIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ using System.Reflection.Emit;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UXAssist.Patches;
|
namespace UXAssist.Patches;
|
||||||
|
|
||||||
@@ -12,10 +13,12 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
Enable(true);
|
Enable(true);
|
||||||
|
GameLogicProc.OnGameBegin += GameMain_Begin_Postfix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Uninit()
|
public static void Uninit()
|
||||||
{
|
{
|
||||||
|
GameLogicProc.OnGameBegin -= GameMain_Begin_Postfix;
|
||||||
Enable(false);
|
Enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +226,8 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long nextTimei = 0;
|
||||||
|
|
||||||
private static void EntityFastTakeOutAlt(PlanetFactory factory, int entityId, bool toPackage, out ItemBundle itemBundle, out bool full)
|
private static void EntityFastTakeOutAlt(PlanetFactory factory, int entityId, bool toPackage, out ItemBundle itemBundle, out bool full)
|
||||||
{
|
{
|
||||||
if (factory._tmp_items == null)
|
if (factory._tmp_items == null)
|
||||||
@@ -235,6 +240,8 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
}
|
}
|
||||||
itemBundle = factory._tmp_items;
|
itemBundle = factory._tmp_items;
|
||||||
full = false;
|
full = false;
|
||||||
|
if (GameMain.instance.timei < nextTimei) return;
|
||||||
|
nextTimei = GameMain.instance.timei + 12;
|
||||||
if (entityId == 0 || factory.entityPool[entityId].id != entityId)
|
if (entityId == 0 || factory.entityPool[entityId].id != entityId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -249,6 +256,31 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
var buffer = cargoPath.buffer;
|
var buffer = cargoPath.buffer;
|
||||||
Dictionary<int, long> takeOutItems = [];
|
Dictionary<int, long> takeOutItems = [];
|
||||||
var mainPlayer = factory.gameData.mainPlayer;
|
var mainPlayer = factory.gameData.mainPlayer;
|
||||||
|
var factorySystem = factory.factorySystem;
|
||||||
|
foreach (var beltId in cargoPath.belts)
|
||||||
|
{
|
||||||
|
ref var b = ref cargoTraffic.beltPool[beltId];
|
||||||
|
if (b.id != beltId) return;
|
||||||
|
// From WriteObjectConn: Only slot 4 to 11 is used for belt <-> inserter connections (slot/otherSlot is -1 there)
|
||||||
|
for (int cidx = 4; cidx < 12; cidx++)
|
||||||
|
{
|
||||||
|
factory.ReadObjectConn(b.entityId, cidx, out var isOutput, out var otherObjId, out var otherSlot);
|
||||||
|
if (otherObjId <= 0) continue;
|
||||||
|
var inserterId = factory.entityPool[otherObjId].inserterId;
|
||||||
|
if (inserterId <= 0) continue;
|
||||||
|
ref var inserter = ref factorySystem.inserterPool[inserterId];
|
||||||
|
if (inserter.id != inserterId) continue;
|
||||||
|
if (inserter.itemId > 0 && inserter.stackCount > 0)
|
||||||
|
{
|
||||||
|
takeOutItems[inserter.itemId] = (takeOutItems.TryGetValue(inserter.itemId, out var value) ? value : 0)
|
||||||
|
+ ((long)inserter.itemCount | ((long)inserter.itemInc << 32));
|
||||||
|
inserter.itemId = 0;
|
||||||
|
inserter.stackCount = 0;
|
||||||
|
inserter.itemCount = 0;
|
||||||
|
inserter.itemInc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i <= end)
|
while (i <= end)
|
||||||
{
|
{
|
||||||
@@ -285,4 +317,9 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void GameMain_Begin_Postfix()
|
||||||
|
{
|
||||||
|
nextTimei = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
|||||||
UXAssist()
|
UXAssist()
|
||||||
{
|
{
|
||||||
ModsCompat.PlanetVeinUtilization.Run(_harmony);
|
ModsCompat.PlanetVeinUtilization.Run(_harmony);
|
||||||
|
ModsCompat.BlueprintTweaks.Run(_harmony);
|
||||||
ModsCompat.CommonAPIWrapper.Run(_harmony);
|
ModsCompat.CommonAPIWrapper.Run(_harmony);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user