Skip to content

Commit

Permalink
Add ExtraInfo syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Dec 21, 2023
1 parent 30eff48 commit c60039c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
17 changes: 17 additions & 0 deletions NebulaModel/Packets/Factory/ExtraInfoUpdatePacket.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
@@ -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<ExtraInfoUpdatePacket>
{
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);
}
}
}
}
}
24 changes: 24 additions & 0 deletions NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c60039c

Please sign in to comment.