mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-02-04 13:52:17 +08:00
CheatEnabler: Immediate Build fix
This commit is contained in:
@@ -119,9 +119,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<int> _beltIds = [];
|
private static HashSet<int> _beltIds = [];
|
||||||
private static HashSet<int> _alterBeltRendererIds;
|
|
||||||
private static HashSet<int> _alterPathRendererIds;
|
|
||||||
private static HashSet<int> _refreshPathUVIds;
|
|
||||||
|
|
||||||
private static void OnDataLoaded()
|
private static void OnDataLoaded()
|
||||||
{
|
{
|
||||||
@@ -168,16 +165,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
var prebuilds = factory.prebuildPool;
|
var prebuilds = factory.prebuildPool;
|
||||||
if (imm)
|
if (imm)
|
||||||
{
|
{
|
||||||
var anyBelt = false;
|
var player = GameMain.mainPlayer;
|
||||||
var anyBuilt = false;
|
|
||||||
_alterBeltRendererIds ??= [];
|
|
||||||
_alterPathRendererIds ??= [];
|
|
||||||
_refreshPathUVIds ??= [];
|
|
||||||
CargoTrafficPatch.IsBatchBuilding = true;
|
|
||||||
factory.BeginFlattenTerrain();
|
|
||||||
factory.cargoTraffic._batch_buffer_no_refresh = true;
|
|
||||||
PlanetFactory.batchBuild = true;
|
|
||||||
CargoTrafficPatch.DisableRefreshBatchesBuffers = true;
|
|
||||||
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
ref var pb = ref prebuilds[i];
|
ref var pb = ref prebuilds[i];
|
||||||
@@ -187,14 +175,54 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
if (!architect) continue;
|
if (!architect) continue;
|
||||||
pb.itemRequired = 0;
|
pb.itemRequired = 0;
|
||||||
}
|
}
|
||||||
anyBelt = anyBelt || _beltIds.Contains(pb.protoId);
|
CargoTrafficPatch.TryStartBatchBuilding(factory);
|
||||||
factory.BuildFinally(GameMain.mainPlayer, i, false);
|
CargoTrafficPatch.InstantBuild(player, factory, i);
|
||||||
anyBuilt = true;
|
|
||||||
}
|
}
|
||||||
|
CargoTrafficPatch.TryEndBatchBuilding(factory);
|
||||||
|
}
|
||||||
|
else if (architect)
|
||||||
|
{
|
||||||
|
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
ref var pb = ref prebuilds[i];
|
||||||
|
if (pb.id != i || pb.isDestroyed || pb.itemRequired == 0) continue;
|
||||||
|
pb.itemRequired = 0;
|
||||||
|
factory.AlterPrebuildModelState(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CargoTrafficPatch : PatchImpl<CargoTrafficPatch>
|
||||||
|
{
|
||||||
|
private static bool _isBatchBuilding;
|
||||||
|
private static bool _disableRefreshBatchesBuffers;
|
||||||
|
private static bool _anyBelt;
|
||||||
|
private static readonly HashSet<int> _alterBeltRendererIds = [];
|
||||||
|
private static readonly HashSet<int> _alterPathRendererIds = [];
|
||||||
|
private static readonly HashSet<int> _refreshPathUVIds = [];
|
||||||
|
|
||||||
|
public static void StartBatchBuilding(PlanetFactory factory)
|
||||||
|
{
|
||||||
|
factory.BeginFlattenTerrain();
|
||||||
|
factory.cargoTraffic._batch_buffer_no_refresh = true;
|
||||||
|
PlanetFactory.batchBuild = true;
|
||||||
|
_isBatchBuilding = true;
|
||||||
|
_disableRefreshBatchesBuffers = true;
|
||||||
|
_anyBelt = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryStartBatchBuilding(PlanetFactory factory)
|
||||||
|
{
|
||||||
|
if (_isBatchBuilding) return;
|
||||||
|
StartBatchBuilding(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EndBatchBuilding(PlanetFactory factory)
|
||||||
|
{
|
||||||
PlanetFactory.batchBuild = false;
|
PlanetFactory.batchBuild = false;
|
||||||
factory.cargoTraffic._batch_buffer_no_refresh = false;
|
factory.cargoTraffic._batch_buffer_no_refresh = false;
|
||||||
factory.EndFlattenTerrain();
|
factory.EndFlattenTerrain();
|
||||||
CargoTrafficPatch.IsBatchBuilding = false;
|
_isBatchBuilding = false;
|
||||||
var cargoTraffic = factory.cargoTraffic;
|
var cargoTraffic = factory.cargoTraffic;
|
||||||
var entityPool = factory.entityPool;
|
var entityPool = factory.entityPool;
|
||||||
var colChunks = factory.planet.physics?.colChunks;
|
var colChunks = factory.planet.physics?.colChunks;
|
||||||
@@ -213,40 +241,35 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
_alterBeltRendererIds.Clear();
|
_alterBeltRendererIds.Clear();
|
||||||
_alterPathRendererIds.Clear();
|
_alterPathRendererIds.Clear();
|
||||||
_refreshPathUVIds.Clear();
|
_refreshPathUVIds.Clear();
|
||||||
CargoTrafficPatch.DisableRefreshBatchesBuffers = false;
|
_disableRefreshBatchesBuffers = false;
|
||||||
if (anyBelt)
|
if (_anyBelt)
|
||||||
{
|
{
|
||||||
factory.cargoTraffic.RefreshBeltBatchesBuffers();
|
factory.cargoTraffic.RefreshBeltBatchesBuffers();
|
||||||
factory.cargoTraffic.RefreshPathBatchesBuffers();
|
factory.cargoTraffic.RefreshPathBatchesBuffers();
|
||||||
}
|
}
|
||||||
if (anyBuilt)
|
_anyBelt = false;
|
||||||
{
|
factory.planet.physics?.raycastLogic?.NotifyBatchObjectRemove();
|
||||||
factory.planet.physics?.raycastLogic?.NotifyBatchObjectRemove();
|
factory.planet.audio?.SetPlanetAudioDirty();
|
||||||
factory.planet.audio?.SetPlanetAudioDirty();
|
}
|
||||||
}
|
|
||||||
|
public static void TryEndBatchBuilding(PlanetFactory factory)
|
||||||
|
{
|
||||||
|
if (!_isBatchBuilding) return;
|
||||||
|
EndBatchBuilding(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InstantBuild(Player player, PlanetFactory factory, int id)
|
||||||
|
{
|
||||||
|
_anyBelt = _anyBelt || _beltIds.Contains(factory.prebuildPool[id].protoId);
|
||||||
|
factory.BuildFinally(player, id, false);
|
||||||
}
|
}
|
||||||
else if (architect)
|
|
||||||
{
|
|
||||||
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
|
||||||
{
|
|
||||||
ref var pb = ref prebuilds[i];
|
|
||||||
if (pb.id != i || pb.isDestroyed || pb.itemRequired == 0) continue;
|
|
||||||
pb.itemRequired = 0;
|
|
||||||
factory.AlterPrebuildModelState(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CargoTrafficPatch : PatchImpl<CargoTrafficPatch>
|
|
||||||
{
|
|
||||||
public static bool IsBatchBuilding;
|
|
||||||
public static bool DisableRefreshBatchesBuffers;
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPriority(Priority.First)]
|
[HarmonyPriority(Priority.First)]
|
||||||
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterBeltRenderer))]
|
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterBeltRenderer))]
|
||||||
private static bool CargoTraffic_AlterBeltRenderer_Prefix(int beltId)
|
private static bool CargoTraffic_AlterBeltRenderer_Prefix(int beltId)
|
||||||
{
|
{
|
||||||
if (!IsBatchBuilding) return true;
|
if (!_isBatchBuilding) return true;
|
||||||
_alterBeltRendererIds.Add(beltId);
|
_alterBeltRendererIds.Add(beltId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -256,7 +279,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterPathRenderer))]
|
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterPathRenderer))]
|
||||||
private static bool CargoTraffic_AlterPathRenderer_Prefix(int pathId)
|
private static bool CargoTraffic_AlterPathRenderer_Prefix(int pathId)
|
||||||
{
|
{
|
||||||
if (!IsBatchBuilding) return true;
|
if (!_isBatchBuilding) return true;
|
||||||
_alterPathRendererIds.Add(pathId);
|
_alterPathRendererIds.Add(pathId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -266,7 +289,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathUV))]
|
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathUV))]
|
||||||
private static bool CargoTraffic_RefreshPathUV_Prefix(int pathId)
|
private static bool CargoTraffic_RefreshPathUV_Prefix(int pathId)
|
||||||
{
|
{
|
||||||
if (!IsBatchBuilding) return true;
|
if (!_isBatchBuilding) return true;
|
||||||
_refreshPathUVIds.Add(pathId);
|
_refreshPathUVIds.Add(pathId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -277,7 +300,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathBatchesBuffers))]
|
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathBatchesBuffers))]
|
||||||
private static bool CargoTraffic_RefreshBeltBatchesBuffers_Prefix()
|
private static bool CargoTraffic_RefreshBeltBatchesBuffers_Prefix()
|
||||||
{
|
{
|
||||||
return !DisableRefreshBatchesBuffers;
|
return !_disableRefreshBatchesBuffers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,6 +442,43 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
return matcher.InstructionEnumeration();
|
return matcher.InstructionEnumeration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyTranspiler]
|
||||||
|
[HarmonyPatch(typeof(ConstructionModuleComponent), nameof(ConstructionModuleComponent.PlaceItems))]
|
||||||
|
private static IEnumerable<CodeInstruction> ConstructionModuleComponent_PlaceItems_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||||
|
{
|
||||||
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
|
matcher.MatchForward(false,
|
||||||
|
new CodeMatch(OpCodes.Ldarg_1),
|
||||||
|
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), nameof(PlanetFactory.constructionSystem))),
|
||||||
|
new CodeMatch(ci => ci.IsLdloc()),
|
||||||
|
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PrebuildData), nameof(PrebuildData.id))),
|
||||||
|
new CodeMatch(ci => ci.IsLdloc()),
|
||||||
|
new CodeMatch(OpCodes.Ldflda, AccessTools.Field(typeof(PrebuildData), nameof(PrebuildData.pos))),
|
||||||
|
new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(ConstructionSystem), nameof(ConstructionSystem.AddBuildTargetToModules)))
|
||||||
|
);
|
||||||
|
matcher.Repeat(codeMatcher =>
|
||||||
|
{
|
||||||
|
codeMatcher.Advance(4).InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Dup),
|
||||||
|
new CodeInstruction(OpCodes.Ldarg_1),
|
||||||
|
Transpilers.EmitDelegate((int objId, PlanetFactory factory) =>
|
||||||
|
{
|
||||||
|
CargoTrafficPatch.TryStartBatchBuilding(factory);
|
||||||
|
CargoTrafficPatch.InstantBuild(GameMain.mainPlayer, factory, objId);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.Advance(3);
|
||||||
|
});
|
||||||
|
return matcher.InstructionEnumeration();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.GameTick))]
|
||||||
|
private static void ConstructionSystem_GameTick_Postfix(ConstructionSystem __instance)
|
||||||
|
{
|
||||||
|
CargoTrafficPatch.TryEndBatchBuilding(__instance.factory);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[HarmonyTranspiler]
|
[HarmonyTranspiler]
|
||||||
[HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.AddBuildTargetToModules))]
|
[HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.AddBuildTargetToModules))]
|
||||||
|
|||||||
Reference in New Issue
Block a user