diff --git a/NebulaModel/Packets/Factory/ExtraInfoUpdatePacket.cs b/NebulaModel/Packets/Factory/ExtraInfoUpdatePacket.cs new file mode 100644 index 000000000..e81c17096 --- /dev/null +++ b/NebulaModel/Packets/Factory/ExtraInfoUpdatePacket.cs @@ -0,0 +1,17 @@ +namespace NebulaModel.Packets.Factory; + +public class ExtraInfoUpdatePacket +{ + public ExtraInfoUpdatePacket() { } + + public ExtraInfoUpdatePacket(int planetId, int objId, string info) + { + PlanetId = planetId; + ObjId = objId; + Info = info; + } + + public int PlanetId { get; set; } + public int ObjId { get; set; } + public string Info { get; set; } +} diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/ExtraInfoUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/ExtraInfoUpdateProcessor.cs new file mode 100644 index 000000000..d77910928 --- /dev/null +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/ExtraInfoUpdateProcessor.cs @@ -0,0 +1,44 @@ +#region + +using NebulaAPI.Packets; +using NebulaModel.Networking; +using NebulaModel.Packets; +using NebulaModel.Packets.Factory; +using NebulaWorld; + +#endregion + +namespace NebulaNetwork.PacketProcessors.Factory.Entity; + +[RegisterPacketProcessor] +internal class ExtraInfoUpdateProcessor : PacketProcessor +{ + protected override void ProcessPacket(ExtraInfoUpdatePacket packet, NebulaConnection conn) + { + var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory; + if (factory == null) + { + return; + } + + using (Multiplayer.Session.Factories.IsIncomingRequest.On()) + { + if (packet.ObjId < 0) + { + var prebuildId = -packet.ObjId; + if (prebuildId > 0 && prebuildId < factory.prebuildCursor) + { + factory.WriteExtraInfoOnPrebuild(prebuildId, packet.Info); + } + } + else + { + var entityId = packet.ObjId; + if (entityId > 0 && entityId < factory.entityCursor) + { + factory.WriteExtraInfoOnEntity(entityId, packet.Info); + } + } + } + } +} diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs index c729e0fd4..cc7b343f5 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs @@ -269,6 +269,30 @@ public static void RemoveVeinWithComponents_Postfix(PlanetFactory __instance, in } } + [HarmonyPostfix] + [HarmonyPatch(nameof(PlanetFactory.WriteExtraInfoOnEntity))] + public static void WriteExtraInfoOnEntity_Postfix(PlanetFactory __instance, int entityId, string info) + { + if (!Multiplayer.IsActive || Multiplayer.Session.Factories.IsIncomingRequest.Value) + { + return; + } + Multiplayer.Session.Network.SendPacketToLocalStar( + new ExtraInfoUpdatePacket(__instance.planetId, entityId, info)); + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(PlanetFactory.WriteExtraInfoOnPrebuild))] + public static void WriteExtraInfoOnPrebuild_Postfix(PlanetFactory __instance, int prebuildId, string info) + { + if (!Multiplayer.IsActive || Multiplayer.Session.Factories.IsIncomingRequest.Value) + { + return; + } + Multiplayer.Session.Network.SendPacketToLocalStar( + new ExtraInfoUpdatePacket(__instance.planetId, -prebuildId, info)); + } + [HarmonyPostfix] [HarmonyPatch(nameof(PlanetFactory.EnableEntityWarning))] public static void EnableEntityWarning_Postfix(PlanetFactory __instance, int entityId)