diff --git a/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs index e0cea6fdf..242419d8c 100644 --- a/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs @@ -221,6 +221,8 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer } // skip targets that we already asked the host about, but only ask as much as we can handle with our idle drones. + // replace: if (!factory.constructionSystem.constructServing.Contains(num12)) + // with the checks from below [HarmonyTranspiler] [HarmonyPatch(nameof(ConstructionModuleComponent.SearchForNewTargets))] public static IEnumerable SearchForNewTargets_Transpiler(IEnumerable instructions) @@ -255,20 +257,18 @@ public static IEnumerable SearchForNewTargets_Transpiler(IEnume int[] myDronePlans = DroneManager.GetPlayerDronePlans(Multiplayer.Session.LocalPlayer.Id); - // returning true here means the targetConstructionObjectId will not be selected as a valid next target - bool a = alreadyContained; - bool b = DroneManager.IsPendingBuildRequest(targetConstructionObjectId); - bool c = (Multiplayer.Session.LocalPlayer.IsClient && DroneManager.CountPendingBuildRequest() > GameMain.mainPlayer.mecha.constructionModule.droneCount); - bool d = (Multiplayer.Session.LocalPlayer.IsHost && (myDronePlans == null ? 0 : myDronePlans.Count()) > GameMain.mainPlayer.mecha.constructionModule.droneCount); + bool isPendingBuildRequest = DroneManager.IsPendingBuildRequest(targetConstructionObjectId); + bool clientNoIdleDrones = (Multiplayer.Session.LocalPlayer.IsClient && DroneManager.CountPendingBuildRequest() > GameMain.mainPlayer.mecha.constructionModule.droneCount); + bool hostNoIdleDrones = (Multiplayer.Session.LocalPlayer.IsHost && (myDronePlans == null ? 0 : myDronePlans.Count()) > GameMain.mainPlayer.mecha.constructionModule.droneCount); - if (!a && b && Multiplayer.Session.LocalPlayer.IsHost) + if (!alreadyContained && isPendingBuildRequest && Multiplayer.Session.LocalPlayer.IsHost) { // this seems to be a deadlock desync, but a should be the correct value DroneManager.RemoveBuildRequest(targetConstructionObjectId); } - //UnityEngine.Debug.LogWarning($"{a} | {b} | {c} | {d}"); - return a || b || c || d; + // returning true here means the targetConstructionObjectId will not be selected as a valid next target + return alreadyContained || isPendingBuildRequest || clientNoIdleDrones || hostNoIdleDrones; })); return matcher.InstructionEnumeration(); diff --git a/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs index cece84924..5d58b1915 100644 --- a/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs @@ -137,6 +137,8 @@ public static IEnumerable UpdateDrones_Transpiler2(IEnumerable< return instructions; } + // change: bool flag = ptr.owner == 0; + // to: bool flag = ptr.owner <= 0; matcher .SetInstruction(new CodeInstruction(OpCodes.Pop)) // remove the pushed 0 .Advance(1) @@ -164,6 +166,8 @@ public static IEnumerable UpdateDrones_Transpiler2(IEnumerable< return instructions; } + // change: if (constructionModuleComponent.id != ptr.owner || ptr2.id != ptr.craftId) + // to: if (ptr2.id != ptr.craftId) matcher .InsertAndAdvance( HarmonyLib.Transpilers.EmitDelegate((int id, int owner) => @@ -173,7 +177,7 @@ public static IEnumerable UpdateDrones_Transpiler2(IEnumerable< return id != owner; // game does exit when id does not match owner, so we do too when multiplayer is inactive } - return false; // we set owner to negative values in ConstructionModuleComponent_Transpiler to mark drones from other players. Those still need to be rendered/updated, as well as those from battle bases + return false; // this might be a bit too open but will render any drone regardless of the games checks. })); var jmpOut = matcher.Operand; matcher.SetInstruction(new CodeInstruction(OpCodes.Brtrue, jmpOut)); diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs index 41a8f53c6..8a814ea85 100644 --- a/NebulaWorld/Player/DroneManager.cs +++ b/NebulaWorld/Player/DroneManager.cs @@ -58,7 +58,6 @@ public static void RemovePlayerDronePlan(ushort playerId, int entityId) { value.Remove(entityId); } - UnityEngine.Debug.LogWarning($"There are still {PlayerDroneBuildingPlans.Count(kv => kv.Key == playerId)} PlayerDroneBuildingPlans left for this player ({playerId}."); } public static void RemovePlayerDronePlan(int entityId) { @@ -67,7 +66,6 @@ public static void RemovePlayerDronePlan(int entityId) if (kvp.Value.Contains(entityId)) { RemovePlayerDronePlan(kvp.Key, entityId); - UnityEngine.Debug.LogWarning($"There are still {PlayerDroneBuildingPlans.Count(kv => kv.Key == kvp.Key)} PlayerDroneBuildingPlans left for this player ({kvp.Key}."); return; } } @@ -78,7 +76,6 @@ public static void RemovePlayerDronePlans(ushort playerId) { PlayerDroneBuildingPlans.Remove(playerId); } - UnityEngine.Debug.LogWarning($"There are still {PlayerDroneBuildingPlans.Count(kv => kv.Key == playerId)} PlayerDroneBuildingPlans left for this player ({playerId}."); } public static int[] GetPlayerDronePlans(ushort playerId) @@ -152,7 +149,6 @@ public static int CountPendingBuildRequest() public static void RemoveBuildRequest(int entityId) { bool res = PendingBuildRequests.Remove(entityId); - UnityEngine.Debug.LogWarning($"There are still {PendingBuildRequests.Count} PendingBuildRequests left."); } public static void EjectDronesOfOtherPlayer(ushort playerId, int planetId, int targetObjectId)