diff --git a/NebulaModel/Packets/Factory/Storage/StorageSyncRealtimeChangePacket.cs b/NebulaModel/Packets/Factory/Storage/StorageSyncRealtimeChangePacket.cs index 1210d372a..804f2b1c2 100644 --- a/NebulaModel/Packets/Factory/Storage/StorageSyncRealtimeChangePacket.cs +++ b/NebulaModel/Packets/Factory/Storage/StorageSyncRealtimeChangePacket.cs @@ -81,9 +81,10 @@ public enum StorageSyncRealtimeChangeEvent AddItem1 = 1, AddItem2 = 2, AddItemStacked = 3, - TakeItem = 4, - TakeItemFromGrid = 5, - TakeHeadItems = 6, - TakeTailItems1 = 7, - TakeTailItems2 = 8 + AddItemFiltered = 4, + TakeItem = 5, + TakeItemFromGrid = 6, + TakeHeadItems = 7, + TakeTailItems1 = 8, + TakeTailItems2 = 9 } diff --git a/NebulaModel/Packets/Factory/Turret/TurretPhaseUpdatePacket.cs b/NebulaModel/Packets/Factory/Turret/TurretPhaseUpdatePacket.cs new file mode 100644 index 000000000..7cf25305c --- /dev/null +++ b/NebulaModel/Packets/Factory/Turret/TurretPhaseUpdatePacket.cs @@ -0,0 +1,17 @@ +namespace NebulaModel.Packets.Factory.Turret; + +public class TurretPhaseUpdatePacket +{ + public TurretPhaseUpdatePacket() { } + + public TurretPhaseUpdatePacket(int turretId, int phasePos, int planetId) + { + TurretId = turretId; + PhasePos = phasePos; + PlanetId = planetId; + } + + public int TurretId { get; set; } + public int PhasePos { get; set; } + public int PlanetId { get; set; } +} diff --git a/NebulaModel/Packets/Factory/Turret/TurretSuperNovaPacket.cs b/NebulaModel/Packets/Factory/Turret/TurretSuperNovaPacket.cs index 722585c3e..9affcbb63 100644 --- a/NebulaModel/Packets/Factory/Turret/TurretSuperNovaPacket.cs +++ b/NebulaModel/Packets/Factory/Turret/TurretSuperNovaPacket.cs @@ -4,14 +4,16 @@ public class TurretSuperNovaPacket { public TurretSuperNovaPacket() { } - public TurretSuperNovaPacket(int turretIndex, bool inSuperNova, int planetId) + public TurretSuperNovaPacket(int turretIndex, int brustModeIndex, bool setSuperNova, int planetId) { TurretIndex = turretIndex; - InSuperNova = inSuperNova; + BrustModeIndex = brustModeIndex; + SetSuperNova = setSuperNova; PlanetId = planetId; } public int TurretIndex { get; set; } - public bool InSuperNova { get; set; } + public int BrustModeIndex { get; set; } + public bool SetSuperNova { get; set; } public int PlanetId { get; set; } } diff --git a/NebulaNetwork/PacketProcessors/Factory/BattleBase/BattleBaseSettingUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/BattleBase/BattleBaseSettingUpdateProcessor.cs index ad27ecb50..17a8964cf 100644 --- a/NebulaNetwork/PacketProcessors/Factory/BattleBase/BattleBaseSettingUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/BattleBase/BattleBaseSettingUpdateProcessor.cs @@ -49,7 +49,7 @@ protected override void ProcessPacket(BattleBaseSettingUpdatePacket packet, Nebu break; case BattleBaseSettingEvent.ChangeDronesPriority: - battleBase.constructionModule.ChangeDronesPriority(factory, packet.Arg1); + battleBase.constructionModule.ChangeDronesPriority(factory, (int)packet.Arg1); break; case BattleBaseSettingEvent.ToggleCombatModuleEnabled: @@ -58,6 +58,10 @@ protected override void ProcessPacket(BattleBaseSettingUpdatePacket packet, Nebu case BattleBaseSettingEvent.ToggleAutoReconstruct: battleBase.constructionModule.autoReconstruct = packet.Arg1 != 0f; + if (battleBase.constructionModule.autoReconstruct) + { + battleBase.constructionModule.SearchAutoReconstructTargets(factory, GameMain.mainPlayer, true); + } break; case BattleBaseSettingEvent.ToggleAutoPickEnabled: diff --git a/NebulaNetwork/PacketProcessors/Factory/BattleBase/NewBattleBaseDroneOrderProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/BattleBase/NewBattleBaseDroneOrderProcessor.cs index 4fb8c9ec4..7c7a6dbed 100644 --- a/NebulaNetwork/PacketProcessors/Factory/BattleBase/NewBattleBaseDroneOrderProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/BattleBase/NewBattleBaseDroneOrderProcessor.cs @@ -42,17 +42,22 @@ protected override void ProcessPacket(NewBattleBaseDroneOrderPacket packet, Nebu switch (packet.IsConstruction) { + // TODO(0.10.29.21869) + /* case true when factory.constructionSystem.TakeEnoughItemsFromBase(battleBaseComponent, packet.EntityId): battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData, packet.EntityId); battleBaseComponent.energy -= (long)droneEjectEnergy; + factory.constructionSystem.constructServing.Add(packet.EntityId); return; + */ case false: - battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData, - packet.EntityId); + // TODO(0.10.29.21869) + // battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData, + // packet.EntityId); battleBaseComponent.energy -= (long)droneEjectEnergy; /* TODO: needed? diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs index 1803452cf..de0b4d58d 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs @@ -34,20 +34,23 @@ protected override void ProcessPacket(StorageSyncRealtimeChangePacket packet, Ne var inc = packet.Inc; switch (packet.StorageEvent) { + case StorageSyncRealtimeChangeEvent.AddItem1: + storage.AddItem(itemId, count, inc, out _, true); + break; case StorageSyncRealtimeChangeEvent.AddItem2: storage.AddItem(itemId, count, packet.StartIndex, packet.Length, inc, out _); break; case StorageSyncRealtimeChangeEvent.AddItemStacked: storage.AddItemStacked(itemId, count, inc, out _); break; - case StorageSyncRealtimeChangeEvent.TakeItemFromGrid: - storage.TakeItemFromGrid(packet.Length, ref itemId, ref count, out _); - break; - case StorageSyncRealtimeChangeEvent.AddItem1: //BattleBase AutoPickTrash - storage.AddItem(itemId, count, inc, out _, true); + case StorageSyncRealtimeChangeEvent.AddItemFiltered: // Use by BattleBaseComponent.AutoPickTrash + storage.AddItemFiltered(itemId, count, inc, out _, true); break; case StorageSyncRealtimeChangeEvent.TakeItem: break; + case StorageSyncRealtimeChangeEvent.TakeItemFromGrid: + storage.TakeItemFromGrid(packet.Length, ref itemId, ref count, out _); + break; case StorageSyncRealtimeChangeEvent.TakeHeadItems: break; case StorageSyncRealtimeChangeEvent.TakeTailItems1: diff --git a/NebulaNetwork/PacketProcessors/Factory/Turret/TurretGroupUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretGroupUpdateProcessor.cs index 475ad89b2..a706afaf1 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Turret/TurretGroupUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretGroupUpdateProcessor.cs @@ -19,10 +19,22 @@ protected override void ProcessPacket(TurretGroupUpdatePacket packet, NebulaConn { return; } - var turret = pool.buffer[packet.TurretIndex]; + ref var turret = ref pool.buffer[packet.TurretIndex]; if (turret.id != -1) { turret.SetGroup(packet.Group); } + + // Refresh UI if viewing on the same turret + var uiTurret = UIRoot.instance.uiGame.turretWindow; + if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretIndex) + { + return; + } + for (var i = 0; i < uiTurret.groupSelectionBtns.Length; i++) + { + var uibutton = uiTurret.groupSelectionBtns[i]; + uibutton.highlighted = uibutton.data == (int)turret.group; + } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Turret/TurretPhaseUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretPhaseUpdateProcessor.cs new file mode 100644 index 000000000..b8c7e548a --- /dev/null +++ b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretPhaseUpdateProcessor.cs @@ -0,0 +1,33 @@ +#region + +using NebulaAPI.Packets; +using NebulaModel.Networking; +using NebulaModel.Packets; +using NebulaModel.Packets.Factory.Turret; + +#endregion + +namespace NebulaNetwork.PacketProcessors.Factory.Turret; + +[RegisterPacketProcessor] +internal class TurretPhaseUpdateProcessor : PacketProcessor +{ + protected override void ProcessPacket(TurretPhaseUpdatePacket packet, NebulaConnection conn) + { + var pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.defenseSystem.turrets; + if (pool == null || packet.TurretId < 0 || packet.TurretId >= pool.buffer.Length) + { + return; + } + ref var turret = ref pool.buffer[packet.TurretId]; + turret.phasePos = packet.PhasePos; + + // Refresh UI if viewing on the same turret + var uiTurret = UIRoot.instance.uiGame.turretWindow; + if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretId) + { + return; + } + uiTurret.phaseText.text = (turret.phasePos / 60f).ToString("0.##"); + } +} diff --git a/NebulaNetwork/PacketProcessors/Factory/Turret/TurretSuperNovaProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretSuperNovaProcessor.cs index 5bd172743..2e20504a5 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Turret/TurretSuperNovaProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Turret/TurretSuperNovaProcessor.cs @@ -4,6 +4,7 @@ using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Turret; +using NebulaWorld; #endregion @@ -14,23 +15,29 @@ internal class TurretSuperNovaProcessor : PacketProcessor { protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnection conn) { - var defenseSystem = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.defenseSystem; + var planet = GameMain.galaxy.PlanetById(packet.PlanetId); + var defenseSystem = planet?.factory?.defenseSystem; var pool = defenseSystem?.turrets; if (pool == null || packet.TurretIndex == -1 || packet.TurretIndex >= pool.buffer.Length || pool.buffer[packet.TurretIndex].id == -1) { return; } - //TODO: Evaluate in PR, should I count on other packet, or should I pass through? - var burstModeIndex = UITurretWindow.burstModeIndex; - var inSuperNova = packet.InSuperNova; - var refTurret = pool.buffer[packet.TurretIndex]; + if (IsHost) + { + // Broadcast supernova events to other players in the system + var starId = planet.star.id; + Multiplayer.Session.Network.SendPacketToStar(packet, starId); + } - switch (burstModeIndex) + var setSuperNova = packet.SetSuperNova; + UITurretWindow.burstModeIndex = packet.BrustModeIndex; // Leave a mark in UI + ref var refTurret = ref pool.buffer[packet.TurretIndex]; + switch (packet.BrustModeIndex) { case 1: - if (inSuperNova) + if (setSuperNova) { refTurret.SetSupernova(); } @@ -40,7 +47,7 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec } break; case 2: - if (inSuperNova) + if (setSuperNova) { defenseSystem.SetGroupTurretsSupernova(refTurret.group); } @@ -50,7 +57,7 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec } break; case 3: - if (inSuperNova) + if (setSuperNova) { defenseSystem.SetGlobalTurretsSupernova(); } @@ -60,5 +67,16 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec } break; } + + var uiTurret = UIRoot.instance.uiGame.turretWindow; + if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretIndex) + { + return; + } + uiTurret.supernovaWait = packet.SetSuperNova; + if (refTurret.inSupernova) + { + GameMain.gameScenario.NotifyOnSupernovaUITriggered(); + } } } diff --git a/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs index 5ec3e98e5..be7ab9e2e 100644 --- a/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs @@ -90,7 +90,8 @@ protected override void ProcessPacket(NewMechaDroneOrderPacket packet, NebulaCon if (factory != null) { DroneManager.EjectDronesOfOtherPlayer(packet.PlayerId, packet.PlanetId, packet.EntityId); - factory.constructionSystem.constructServing.Add(packet.EntityId); + // TODO(0.10.29.21869) + // factory.constructionSystem.constructServing.Add(packet.EntityId); } break; } @@ -100,11 +101,15 @@ protected override void ProcessPacket(NewMechaDroneOrderPacket packet, NebulaCon if (factory != null) { + // TODO(0.10.29.21869) + /* factory.constructionSystem.TakeEnoughItemsFromPlayer(packet.EntityId); GameMain.mainPlayer.mecha.constructionModule.EjectMechaDrone(factory, GameMain.mainPlayer, packet.EntityId, packet.Priority); + factory.constructionSystem.constructServing.Add(packet.EntityId); + */ } break; } @@ -155,7 +160,8 @@ private void informAndEjectRemoteDrones(NewMechaDroneOrderPacket packet, PlanetF Multiplayer.Session.Network.SendPacketToPlanet( new NewMechaDroneOrderPacket(packet.PlanetId, packet.EntityId, closestPlayerId, packet.Priority), packet.PlanetId); - factory.constructionSystem.constructServing.Add(packet.EntityId); + // TODO(0.10.29.21869) + // factory.constructionSystem.constructServing.Add(packet.EntityId); // only render other drones when on same planet if (packet.PlanetId == GameMain.mainPlayer.planetId) @@ -175,9 +181,12 @@ private void informAndEjectLocalDrones(NewMechaDroneOrderPacket packet, PlanetFa new NewMechaDroneOrderPacket(packet.PlanetId, packet.EntityId, closestPlayerId, packet.Priority), packet.PlanetId); + // TODO(0.10.29.21869) + /* factory.constructionSystem.TakeEnoughItemsFromPlayer(packet.EntityId); GameMain.mainPlayer.mecha.constructionModule.EjectMechaDrone(factory, GameMain.mainPlayer, packet.EntityId, packet.Priority); factory.constructionSystem.constructServing.Add(packet.EntityId); + */ } } diff --git a/NebulaNetwork/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs b/NebulaNetwork/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs index 17dd74cca..f2cdd0c4e 100644 --- a/NebulaNetwork/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs @@ -52,7 +52,8 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn { continue; } - factory.constructionSystem.constructServing.Remove(targetObjectId); // in case it was a construction drone. + // TODO(0.10.29.21869) + // factory.constructionSystem.constructServing.Remove(targetObjectId); // in case it was a construction drone. if (GameMain.mainPlayer.planetId == player.Data.LocalPlanetId) { @@ -81,7 +82,9 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn Multiplayer.Session.Network.SendPacketToPlanet( new NewMechaDroneOrderPacket(player.Data.LocalPlanetId, targetObjectId, nextClosestPlayer, /*TODO: rip*/true), player.Data.LocalPlanetId); - factory.constructionSystem.constructServing.Add(targetObjectId); + + // TODO(0.10.29.21869) + //factory.constructionSystem.constructServing.Add(targetObjectId); // only render other drones when on same planet if (player.Data.LocalPlanetId == GameMain.mainPlayer.planetId) @@ -117,8 +120,9 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn } DroneManager.RemoveBuildRequest(drone.targetObjectId); - factory.constructionSystem.constructServing - .Remove(drone.targetObjectId); // in case it was a construction drone. + // TODO(0.10.29.21869) + //factory.constructionSystem.constructServing + // .Remove(drone.targetObjectId); // in case it was a construction drone. } } } diff --git a/NebulaPatcher/Patches/Dynamic/ConstructionModuleComponent_Patch.cs b/NebulaPatcher/Patches/Dynamic/ConstructionModuleComponent_Patch.cs index 8aed64676..e329529d9 100644 --- a/NebulaPatcher/Patches/Dynamic/ConstructionModuleComponent_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/ConstructionModuleComponent_Patch.cs @@ -23,8 +23,9 @@ public static void RecycleDrone_Postfix(ConstructionModuleComponent __instance, } // clients should skip the procedure for BattleBases. The host will tell them when to eject drones. - [HarmonyPrefix] - [HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))] + // TODO(0.10.29.21869) + //[HarmonyPrefix] + //[HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))] public static bool IdleDroneProcedure_Prefix(ConstructionModuleComponent __instance) { if (!Multiplayer.IsActive) diff --git a/NebulaPatcher/Patches/Dynamic/UIBattleBaseWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIBattleBaseWindow_Patch.cs index a8f041c6a..57abaa515 100644 --- a/NebulaPatcher/Patches/Dynamic/UIBattleBaseWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIBattleBaseWindow_Patch.cs @@ -59,9 +59,9 @@ public static bool OnDronePriorityButtonClick_Prefix(UIBattleBaseWindow __instan { return true; } - var ratio = __instance.constructionModule.dronePriorConstructRatio; - var newRatio = ratio < 0.25f ? 0.5f : ratio < 0.75f ? 1f : 0f; - SendEvent(__instance, BattleBaseSettingEvent.ChangeDronesPriority, newRatio); + var dronePriority = __instance.constructionModule.dronePriority; + var newDronePriority = (dronePriority + 1) % 3; + SendEvent(__instance, BattleBaseSettingEvent.ChangeDronesPriority, newDronePriority); return Multiplayer.Session.LocalPlayer.IsHost; } diff --git a/NebulaPatcher/Patches/Dynamic/UITurretWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UITurretWindow_Patch.cs index 397a04128..f88ad3c5d 100644 --- a/NebulaPatcher/Patches/Dynamic/UITurretWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UITurretWindow_Patch.cs @@ -11,6 +11,30 @@ namespace NebulaPatcher.Patches.Dynamic; [HarmonyPatch(typeof(UITurretWindow))] internal class UITurretWindow_Patch { + [HarmonyPostfix] + [HarmonyPatch(nameof(UITurretWindow.OnTurretShiftValueChange))] + public static void OnTurretShiftValueChange_Postfix(UITurretWindow __instance) + { + //Notify about manual bullet inserting / withdrawing change + if (!Multiplayer.IsActive || __instance is null) + { + return; + } + + if (__instance._turretId == 0 || __instance.factory == null || __instance.player == null) + { + return; + } + ref var turret = ref __instance.defenseSystem.turrets.buffer[__instance.turretId]; + if (turret.id != __instance.turretId || turret.type != ETurretType.Disturb) + { + return; + } + + Multiplayer.Session.Network.SendPacketToLocalStar(new TurretPhaseUpdatePacket( + turret.id, turret.phasePos, __instance.factory.planetId)); + } + [HarmonyPostfix] [HarmonyPatch(nameof(UITurretWindow.OnHandFillAmmoButtonClick))] public static void OnHandFillAmmoButtonClick_Postfix(UITurretWindow __instance) @@ -50,9 +74,6 @@ public static void AmmoButtonClick_Postfix(UITurretWindow __instance) Multiplayer.Session.Network.SendPacketToLocalStar(new TurretStorageUpdatePacket(turret, GameMain.localPlanet?.id ?? -1)); - - //Multiplayer.Session.Network.SendPacketToLocalStar(new TurretStorageUpdatePacket(__instance.turretId, - // turret.itemId, turret.itemCount, turret.itemInc, GameMain.localPlanet?.id ?? -1)); } @@ -99,19 +120,40 @@ public static void OnSetBurstMode_Postfix(UITurretWindow __instance, int obj) GameMain.localPlanet?.id ?? -1)); } - //TODO: Work In Progress on SuperNova - //[HarmonyPostfix] - //[HarmonyPatch(nameof(UITurretWindow.SuperNovaBtn_onClick))] - //public static void OnSetSuperNova_Postfix(UITurretWindow __instance, int obj) - //{ - // if (!Multiplayer.IsActive) - // return; + [HarmonyPrefix] + [HarmonyPatch(nameof(UITurretWindow.SuperNovaBtn_onClick))] + public static bool OnSetSuperNova_Prefix(UITurretWindow __instance) + { + if (!Multiplayer.IsActive) + { + return true; + } - // bool superNovaOn = __instance.defenseSystem.turrets.buffer[__instance.turretId].inSupernova; + if (__instance.turretId == 0 || __instance.factory == null || __instance.player == null) + { + return false; + } + ref var turret = ref __instance.defenseSystem.turrets.buffer[__instance.turretId]; + if (turret.id != __instance.turretId) + { + return false; + } + var packet = new TurretSuperNovaPacket(__instance.turretId, + UITurretWindow.burstModeIndex, !turret.inSupernova, __instance.factory.planetId); - // Multiplayer.Session.Network.SendPacketToLocalStar(new TurretSuperNovaPacket(__instance.turretId, superNovaOn, - // GameMain.localPlanet?.id ?? -1)); - //} + if (Multiplayer.Session.IsClient) + { + // Client will wait for server to authorize + Multiplayer.Session.Network.SendPacket(packet); + __instance.supernovaWait &= !turret.inSupernova; + return false; + } + else + { + Multiplayer.Session.Network.SendPacketToLocalStar(packet); + return true; + } + } [HarmonyPostfix] diff --git a/NebulaPatcher/Patches/Transpilers/BattleBaseComponent_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/BattleBaseComponent_Transpiler.cs index b74814240..c39785f0e 100644 --- a/NebulaPatcher/Patches/Transpilers/BattleBaseComponent_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/BattleBaseComponent_Transpiler.cs @@ -86,9 +86,9 @@ public static IEnumerable BattleBaseComponent_AutoPickTrash_Tra // To: BattleBaseComponent_Transpiler.AddItem(nextStorage, item, num11, num12, out num14, true, factory); codeMatcher - .MatchForward(false, new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "AddItem")) + .MatchForward(false, new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "AddItemFiltered")) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1)) - .SetAndAdvance(OpCodes.Call, AccessTools.Method(typeof(BattleBaseComponent_Transpiler), nameof(AddItem))); + .SetAndAdvance(OpCodes.Call, AccessTools.Method(typeof(BattleBaseComponent_Transpiler), nameof(AddItemFiltered))); return codeMatcher.InstructionEnumeration(); } @@ -126,9 +126,9 @@ private static void AddPlayerSandCount(TrashSystem trashSystem, int trashId, int } } - private static int AddItem(StorageComponent storage, int itemId, int count, int inc, ref int remainInc, bool useBan, PlanetFactory factory) + private static int AddItemFiltered(StorageComponent storage, int itemId, int count, int inc, ref int remainInc, bool useBan, PlanetFactory factory) { - var addedCount = storage.AddItem(itemId, count, inc, out remainInc, useBan); + var addedCount = storage.AddItemFiltered(itemId, count, inc, out remainInc, useBan); if (!Multiplayer.IsActive) { return addedCount; @@ -141,7 +141,7 @@ private static int AddItem(StorageComponent storage, int itemId, int count, int Multiplayer.Session.Network.SendPacketToStar( new StorageSyncRealtimeChangePacket( storage.id, - StorageSyncRealtimeChangeEvent.AddItem1, + StorageSyncRealtimeChangeEvent.AddItemFiltered, itemId, addedCount, useBan, planetId), starId); } return addedCount; diff --git a/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs index 5ce9f7c0d..8c24a3599 100644 --- a/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/ConstructionModuleComponent_Transpiler.cs @@ -23,8 +23,9 @@ internal delegate void BroadcastEjectBattleBaseDrone(ConstructionModuleComponent [HarmonyPatch(typeof(ConstructionModuleComponent))] internal class ConstructionModuleComponent_Transpiler { - [HarmonyTranspiler] - [HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))] + // TODO(0.10.29.21869) + //[HarmonyTranspiler] + //[HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))] public static IEnumerable IdleDroneProcedure_Transpiler(IEnumerable instructions, ILGenerator il) { @@ -128,6 +129,8 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer new NewMechaDroneOrderPacket(GameMain.mainPlayer.planetId, targetObjectId, closestPlayer, priority), GameMain.mainPlayer.planetId); + // TODO(0.10.29.21869) + /* if (constructing) { factory.constructionSystem.TakeEnoughItemsFromPlayer(targetObjectId); @@ -135,6 +138,7 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer GameMain.mainPlayer.mecha.constructionModule.EjectMechaDrone(factory, GameMain.mainPlayer, targetObjectId, priority); factory.constructionSystem.constructServing.Add(targetObjectId); + */ } return false; @@ -177,7 +181,8 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer { if (!Multiplayer.IsActive) { - _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); + // TODO(0.10.29.21869) + // _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); return; } if (DroneManager.IsPendingBuildRequest(targetId)) @@ -190,8 +195,9 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer new NewBattleBaseDroneOrderPacket(factory.planetId, targetId, _this.id, true), factory.planetId); DroneManager.TakeEnoughItemsFromBattleBase(factory, targetId, _this); - _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); - factory.constructionSystem.constructServing.Add(targetId); + // TODO(0.10.29.21869) + // _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); + // factory.constructionSystem.constructServing.Add(targetId); })) .Set(OpCodes.Nop, null); // remove original call }); @@ -230,7 +236,8 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer { if (!Multiplayer.IsActive) { - _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); + // TODO(0.10.29.21869) + //_this.EjectBaseDrone(factory, ref drone, ref cData, targetId); return; } if (!DroneManager.IsPendingBuildRequest(targetId)) @@ -240,7 +247,8 @@ public static IEnumerable IdleDroneProcedure_Transpiler(IEnumer Multiplayer.Session.Network.SendPacketToPlanet( new NewBattleBaseDroneOrderPacket(factory.planetId, targetId, _this.id, false), factory.planetId); - _this.EjectBaseDrone(factory, ref drone, ref cData, targetId); + // TODO(0.10.29.21869) + //_this.EjectBaseDrone(factory, ref drone, ref cData, targetId); } })) .Set(OpCodes.Nop, null); // remove original call @@ -252,8 +260,10 @@ 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))] + + // TODO(0.10.29.21869) + //[HarmonyTranspiler] + //[HarmonyPatch(nameof(ConstructionModuleComponent.SearchForNewTargets))] public static IEnumerable SearchForNewTargets_Transpiler(IEnumerable instructions) { var codeInstructions = instructions as CodeInstruction[] ?? instructions.ToArray(); diff --git a/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs index a48a9a8d8..5990b66fb 100644 --- a/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/ConstructionSystem_Transpiler.cs @@ -18,8 +18,9 @@ namespace NebulaPatcher.Patches.Transpilers; [HarmonyPatch(typeof(ConstructionSystem))] internal class ConstructionSystem_Transpiler { - [HarmonyTranspiler] - [HarmonyPatch(nameof(ConstructionSystem.UpdateDrones))] + // TODO(0.10.29.21869): runtime error + //[HarmonyTranspiler] + //[HarmonyPatch(nameof(ConstructionSystem.UpdateDrones))] public static IEnumerable UpdateDrones_Transpiler1(IEnumerable instructions) { /* @@ -119,8 +120,10 @@ public static IEnumerable UpdateDrones_Transpiler1(IEnumerable< } // still update rendering of other player drones, make sure this happens here. - [HarmonyTranspiler] - [HarmonyPatch(nameof(ConstructionSystem.UpdateDrones))] + + // TODO(0.10.29.21869): runtime error + //[HarmonyTranspiler] + //[HarmonyPatch(nameof(ConstructionSystem.UpdateDrones))] public static IEnumerable UpdateDrones_Transpiler2(IEnumerable instructions, ILGenerator generator) { diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs index da8d18a6d..0a2112438 100644 --- a/NebulaWorld/Player/DroneManager.cs +++ b/NebulaWorld/Player/DroneManager.cs @@ -141,7 +141,8 @@ public static bool IsPendingBuildRequest(int entityId) } Multiplayer.Session.Network.SendPacket(new RemoveDroneOrdersPacket(new[] { entityId }, GameMain.mainPlayer.planetId)); RemoveBuildRequest(entityId); - GameMain.galaxy.PlanetById(GameMain.mainPlayer.planetId)?.factory?.constructionSystem.constructServing.Remove(entityId); + // TODO(0.10.29.21869) + // GameMain.galaxy.PlanetById(GameMain.mainPlayer.planetId)?.factory?.constructionSystem.constructServing.Remove(entityId); return false; }