From 6ba7c564700f2f543f622991057cc08ee6c8e322 Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Sat, 10 Apr 2021 17:58:37 +0200
Subject: [PATCH 1/6] Added player and mecha objects
---
NebulaPatcher/NebulaPatcher.csproj | 1 +
1 file changed, 1 insertion(+)
diff --git a/NebulaPatcher/NebulaPatcher.csproj b/NebulaPatcher/NebulaPatcher.csproj
index c83d96f4b..46d90ae58 100644
--- a/NebulaPatcher/NebulaPatcher.csproj
+++ b/NebulaPatcher/NebulaPatcher.csproj
@@ -46,6 +46,7 @@
+
From fdd45b3d42aca375e91982dd05c765e2e5b52584 Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Mon, 12 Apr 2021 23:43:02 +0200
Subject: [PATCH 2/6] Added planet broadcast
---
NebulaClient/MultiplayerClientSession.cs | 4 ++
NebulaHost/MultiplayerHostSession.cs | 5 +++
NebulaHost/NebulaHost.csproj | 1 +
.../Routers/PlanetBroadcastProcessor.cs | 33 +++++++++++++++++
NebulaHost/PlayerManager.cs | 22 +++++++++++
NebulaModel/NebulaModel.csproj | 2 +
.../Packets/Players/NewDroneOrderPacket.cs | 18 +++++++++
.../Packets/Routers/PlanetBroadcastPacket.cs | 15 ++++++++
NebulaPatcher/NebulaPatcher.csproj | 1 +
.../Transpilers/MechaDroneLogic_Patch.cs | 37 +++++++++++++++++++
NebulaWorld/INetworkProvider.cs | 1 +
NebulaWorld/LocalPlayer.cs | 5 +++
NebulaWorld/NebulaWorld.csproj | 1 +
NebulaWorld/Player/DroneManager.cs | 17 +++++++++
NebulaWorld/RemotePlayerModel.cs | 6 +--
NebulaWorld/SimulatedWorld.cs | 2 +-
16 files changed, 166 insertions(+), 4 deletions(-)
create mode 100644 NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
create mode 100644 NebulaModel/Packets/Players/NewDroneOrderPacket.cs
create mode 100644 NebulaModel/Packets/Routers/PlanetBroadcastPacket.cs
create mode 100644 NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
create mode 100644 NebulaWorld/Player/DroneManager.cs
diff --git a/NebulaClient/MultiplayerClientSession.cs b/NebulaClient/MultiplayerClientSession.cs
index d6cb51955..2398ba4f0 100644
--- a/NebulaClient/MultiplayerClientSession.cs
+++ b/NebulaClient/MultiplayerClientSession.cs
@@ -81,6 +81,10 @@ public void DestroySession()
{
serverConnection?.SendPacket(new StarBroadcastPacket(PacketProcessor.Write(packet), GameMain.data.localStar?.id ?? -1));
}
+ public void SendPacketToLocalPlanet(T packet) where T : class, new()
+ {
+ serverConnection?.SendPacket(new PlanetBroadcastPacket(PacketProcessor.Write(packet), GameMain.mainPlayer.planetId));
+ }
public void Reconnect()
{
diff --git a/NebulaHost/MultiplayerHostSession.cs b/NebulaHost/MultiplayerHostSession.cs
index 52c761709..a73647492 100644
--- a/NebulaHost/MultiplayerHostSession.cs
+++ b/NebulaHost/MultiplayerHostSession.cs
@@ -89,6 +89,11 @@ public void DestroySession()
PlayerManager.SendPacketToLocalStar(packet);
}
+ public void SendPacketToLocalPlanet(T packet) where T : class, new()
+ {
+ PlayerManager.SendPacketToLocalPlanet(packet);
+ }
+
private void Update()
{
gameStateUpdateTimer += Time.deltaTime;
diff --git a/NebulaHost/NebulaHost.csproj b/NebulaHost/NebulaHost.csproj
index e2b54caef..3432b6d1a 100644
--- a/NebulaHost/NebulaHost.csproj
+++ b/NebulaHost/NebulaHost.csproj
@@ -82,6 +82,7 @@
+
diff --git a/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
new file mode 100644
index 000000000..850a391af
--- /dev/null
+++ b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
@@ -0,0 +1,33 @@
+using NebulaModel.Attributes;
+using NebulaModel.Networking;
+using NebulaModel.Packets.Processors;
+using NebulaModel.Packets.Routers;
+using NebulaWorld;
+
+namespace NebulaHost.PacketProcessors.Routers
+{
+ [RegisterPacketProcessor]
+ class PlanetBroadcastProcessor : IPacketProcessor
+ {
+ private PlayerManager playerManager;
+ public PlanetBroadcastProcessor()
+ {
+ playerManager = MultiplayerHostSession.Instance.PlayerManager;
+ }
+ public void ProcessPacket(PlanetBroadcastPacket packet, NebulaConnection conn)
+ {
+ Player player = playerManager.GetPlayer(conn);
+ if (player != null)
+ {
+ //Forward packet to other users
+ playerManager.SendRawPacketToPlanet(packet.PacketObject, packet.PlanetId, conn);
+
+ //Host probably does not need to know about flying drones of other players if he is not on the same planet
+ if (LocalPlayer.Data.LocalPlanetId == packet.PlanetId)
+ {
+ MultiplayerHostSession.Instance.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/NebulaHost/PlayerManager.cs b/NebulaHost/PlayerManager.cs
index 40d71ce4f..96471027f 100644
--- a/NebulaHost/PlayerManager.cs
+++ b/NebulaHost/PlayerManager.cs
@@ -81,6 +81,17 @@ public Player GetSyncingPlayer(NebulaConnection conn)
}
}
+ public void SendPacketToLocalPlanet(T packet) where T : class, new()
+ {
+ foreach (Player player in GetConnectedPlayers())
+ {
+ if (player.Data.LocalPlanetId == GameMain.data.mainPlayer.planetId)
+ {
+ player.SendPacket(packet);
+ }
+ }
+ }
+
public void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection sender)
{
foreach (Player player in GetConnectedPlayers())
@@ -92,6 +103,17 @@ public void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection s
}
}
+ public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, NebulaConnection sender)
+ {
+ foreach (Player player in GetConnectedPlayers())
+ {
+ if (player.Data.LocalPlanetId == planetId && player.Connection != sender)
+ {
+ player.SendRawPacket(rawPacket);
+ }
+ }
+ }
+
public void SendPacketToOtherPlayers(T packet, Player sender) where T : class, new()
{
foreach (Player player in GetConnectedPlayers())
diff --git a/NebulaModel/NebulaModel.csproj b/NebulaModel/NebulaModel.csproj
index a183d222e..decdad0dc 100644
--- a/NebulaModel/NebulaModel.csproj
+++ b/NebulaModel/NebulaModel.csproj
@@ -105,12 +105,14 @@
+
+
diff --git a/NebulaModel/Packets/Players/NewDroneOrderPacket.cs b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs
new file mode 100644
index 000000000..56afcd5cc
--- /dev/null
+++ b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs
@@ -0,0 +1,18 @@
+namespace NebulaModel.Packets.Players
+{
+ public class NewDroneOrderPacket
+ {
+ public int PlanetId { get; set; }
+ public int DroneId { get; set; }
+ public int EntityId { get; set; }
+ public int PlayerId { get; set; }
+ public NewDroneOrderPacket() { }
+ public NewDroneOrderPacket(int planetId, int droneId, int entityId, int playerId)
+ {
+ PlanetId = planetId;
+ DroneId = droneId;
+ EntityId = entityId;
+ PlayerId = playerId;
+ }
+ }
+}
diff --git a/NebulaModel/Packets/Routers/PlanetBroadcastPacket.cs b/NebulaModel/Packets/Routers/PlanetBroadcastPacket.cs
new file mode 100644
index 000000000..0f1e67cb0
--- /dev/null
+++ b/NebulaModel/Packets/Routers/PlanetBroadcastPacket.cs
@@ -0,0 +1,15 @@
+namespace NebulaModel.Packets.Routers
+{
+ public class PlanetBroadcastPacket
+ {
+ public byte[] PacketObject { get; set; }
+ public int PlanetId { get; set; }
+
+ public PlanetBroadcastPacket() { }
+ public PlanetBroadcastPacket(byte[] packetObject, int planetId)
+ {
+ PacketObject = packetObject;
+ PlanetId = planetId;
+ }
+ }
+}
diff --git a/NebulaPatcher/NebulaPatcher.csproj b/NebulaPatcher/NebulaPatcher.csproj
index 46d90ae58..55da014fb 100644
--- a/NebulaPatcher/NebulaPatcher.csproj
+++ b/NebulaPatcher/NebulaPatcher.csproj
@@ -78,6 +78,7 @@
+
diff --git a/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs b/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
new file mode 100644
index 000000000..c4e3defdc
--- /dev/null
+++ b/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
@@ -0,0 +1,37 @@
+using HarmonyLib;
+using NebulaWorld.Player;
+using System.Collections.Generic;
+using System.Reflection.Emit;
+
+namespace NebulaPatcher.Patches.Transpiler
+{
+ [HarmonyPatch(typeof(MechaDroneLogic))]
+ class MechaDroneLogic_Patch
+ {
+ /*
+ * Call DroneManager.BroadcastDroneOrder(int droneId, int entityId) when drone gets new order
+ */
+ [HarmonyTranspiler]
+ [HarmonyPatch("UpdateTargets")]
+ static IEnumerable UpdateTargets_Transpiler(IEnumerable instructions)
+ {
+ var codes = new List(instructions);
+ for (int i = 0; i < codes.Count; i++)
+ {
+ if (codes[i].opcode == OpCodes.Pop &&
+ codes[i - 1].opcode == OpCodes.Callvirt &&
+ codes[i + 1].opcode == OpCodes.Ldarg_0 &&
+ codes[i - 2].opcode == OpCodes.Ldloc_3)
+ {
+ codes.InsertRange(i + 1, new CodeInstruction[] {
+ new CodeInstruction(OpCodes.Ldloc_S, 11),
+ new CodeInstruction(OpCodes.Ldloc_3),
+ new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DroneManager), "BroadcastDroneOrder", new System.Type[] { typeof(int), typeof(int) }))
+ });
+ break;
+ }
+ }
+ return codes;
+ }
+ }
+}
diff --git a/NebulaWorld/INetworkProvider.cs b/NebulaWorld/INetworkProvider.cs
index 86778e9b5..990d141ff 100644
--- a/NebulaWorld/INetworkProvider.cs
+++ b/NebulaWorld/INetworkProvider.cs
@@ -6,6 +6,7 @@ public interface INetworkProvider
void SendPacketToLocalStar(T packet) where T : class, new();
+ void SendPacketToLocalPlanet(T packet) where T : class, new();
void DestroySession();
}
}
diff --git a/NebulaWorld/LocalPlayer.cs b/NebulaWorld/LocalPlayer.cs
index 5ba82a7a2..c761f442d 100644
--- a/NebulaWorld/LocalPlayer.cs
+++ b/NebulaWorld/LocalPlayer.cs
@@ -31,6 +31,11 @@ public static void SetNetworkProvider(INetworkProvider provider)
networkProvider?.SendPacketToLocalStar(packet);
}
+ public static void SendPacketToLocalPlanet(T packet) where T : class, new()
+ {
+ networkProvider?.SendPacketToLocalPlanet(packet);
+ }
+
public static void SetReady()
{
if (!IsMasterClient)
diff --git a/NebulaWorld/NebulaWorld.csproj b/NebulaWorld/NebulaWorld.csproj
index 2d11596d0..ad00f1e20 100644
--- a/NebulaWorld/NebulaWorld.csproj
+++ b/NebulaWorld/NebulaWorld.csproj
@@ -51,6 +51,7 @@
+
diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs
new file mode 100644
index 000000000..9f20d3873
--- /dev/null
+++ b/NebulaWorld/Player/DroneManager.cs
@@ -0,0 +1,17 @@
+using NebulaModel.Packets.Players;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace NebulaWorld.Player
+{
+ public static class DroneManager
+ {
+ public static void BroadcastDroneOrder(int droneId, int entityId)
+ {
+ UnityEngine.Debug.Log($"Drone {droneId} is going to {entityId}");
+ LocalPlayer.SendPacketToLocalPlanet(new NewDroneOrderPacket());
+ }
+ }
+}
diff --git a/NebulaWorld/RemotePlayerModel.cs b/NebulaWorld/RemotePlayerModel.cs
index 28f19366f..ef244b5b3 100644
--- a/NebulaWorld/RemotePlayerModel.cs
+++ b/NebulaWorld/RemotePlayerModel.cs
@@ -14,7 +14,7 @@ public class RemotePlayerModel
public RemotePlayerAnimation Animator { get; set; }
public RemotePlayerEffects Effects { get; set; }
- public Player PlayerInstance { get; set; }
+ public global::Player PlayerInstance { get; set; }
public Mecha MechaInstance { get; set; }
public RemotePlayerModel(ushort playerId)
@@ -42,9 +42,9 @@ public RemotePlayerModel(ushort playerId)
PlayerTransform.gameObject.name = $"Remote Player ({playerId})";
- PlayerInstance = new Player();
+ PlayerInstance = new global::Player();
MechaInstance = new Mecha();
- AccessTools.Property(typeof(Player), "mecha").SetValue(PlayerInstance, MechaInstance, null);
+ AccessTools.Property(typeof(global::Player), "mecha").SetValue(PlayerInstance, MechaInstance, null);
MechaInstance.Init(PlayerInstance);
}
diff --git a/NebulaWorld/SimulatedWorld.cs b/NebulaWorld/SimulatedWorld.cs
index 0186ad9b5..63ee116ec 100644
--- a/NebulaWorld/SimulatedWorld.cs
+++ b/NebulaWorld/SimulatedWorld.cs
@@ -252,7 +252,7 @@ public static void OnGameLoadCompleted()
GameMain.mainPlayer.uRotation = Quaternion.Euler(LocalPlayer.Data.Rotation.ToUnity());
//Load player's saved data from the last session.
- AccessTools.Property(typeof(Player), "package").SetValue(GameMain.mainPlayer, LocalPlayer.Data.Mecha.Inventory, null);
+ AccessTools.Property(typeof(global::Player), "package").SetValue(GameMain.mainPlayer, LocalPlayer.Data.Mecha.Inventory, null);
GameMain.mainPlayer.mecha.forge = LocalPlayer.Data.Mecha.Forge;
GameMain.mainPlayer.mecha.coreEnergy = LocalPlayer.Data.Mecha.CoreEnergy;
GameMain.mainPlayer.mecha.reactorEnergy = LocalPlayer.Data.Mecha.ReactorEnergy;
From 1c033272fc9e4c20fab91c5947a569fd9f1708fc Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Thu, 15 Apr 2021 12:14:04 +0200
Subject: [PATCH 3/6] Player's drone syncing + labor division
---
NebulaClient/NebulaClient.csproj | 1 +
.../Players/NewDroneOrderProcessor.cs | 17 ++++
NebulaHost/NebulaHost.csproj | 1 +
.../Players/NewDroneOrderProcessor.cs | 17 ++++
.../Routers/PlanetBroadcastProcessor.cs | 3 +-
.../Packets/Players/NewDroneOrderPacket.cs | 9 +-
.../Patches/Dynamic/GameData_Patch.cs | 4 +-
.../Transpilers/MechaDroneLogic_Patch.cs | 55 +++++++++++-
NebulaWorld/INetworkProvider.cs | 1 +
NebulaWorld/Player/DroneManager.cs | 19 +++--
NebulaWorld/RemotePlayerModel.cs | 5 ++
NebulaWorld/SimulatedWorld.cs | 84 +++++++++++++++++--
12 files changed, 194 insertions(+), 22 deletions(-)
create mode 100644 NebulaClient/PacketProcessors/Players/NewDroneOrderProcessor.cs
create mode 100644 NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
diff --git a/NebulaClient/NebulaClient.csproj b/NebulaClient/NebulaClient.csproj
index eec4f687b..745845dd1 100644
--- a/NebulaClient/NebulaClient.csproj
+++ b/NebulaClient/NebulaClient.csproj
@@ -79,6 +79,7 @@
+
diff --git a/NebulaClient/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaClient/PacketProcessors/Players/NewDroneOrderProcessor.cs
new file mode 100644
index 000000000..d53c4b6fb
--- /dev/null
+++ b/NebulaClient/PacketProcessors/Players/NewDroneOrderProcessor.cs
@@ -0,0 +1,17 @@
+using NebulaModel.Attributes;
+using NebulaModel.Networking;
+using NebulaModel.Packets.Players;
+using NebulaModel.Packets.Processors;
+using NebulaWorld;
+
+namespace NebulaClient.PacketProcessors.Players
+{
+ [RegisterPacketProcessor]
+ class NewDroneOrderProcessor : IPacketProcessor
+ {
+ public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
+ {
+ SimulatedWorld.UpdateRemotePlayerDrone(packet);
+ }
+ }
+}
diff --git a/NebulaHost/NebulaHost.csproj b/NebulaHost/NebulaHost.csproj
index 3432b6d1a..9dfc2f110 100644
--- a/NebulaHost/NebulaHost.csproj
+++ b/NebulaHost/NebulaHost.csproj
@@ -77,6 +77,7 @@
+
diff --git a/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
new file mode 100644
index 000000000..9fcd2d0d9
--- /dev/null
+++ b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
@@ -0,0 +1,17 @@
+using NebulaModel.Attributes;
+using NebulaModel.Networking;
+using NebulaModel.Packets.Players;
+using NebulaModel.Packets.Processors;
+using NebulaWorld;
+
+namespace NebulaHost.PacketProcessors.Players
+{
+ [RegisterPacketProcessor]
+ class NewDroneOrderProcessor : IPacketProcessor
+ {
+ public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
+ {
+ SimulatedWorld.UpdateRemotePlayerDrone(packet);
+ }
+ }
+}
diff --git a/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
index 850a391af..b98ff1c09 100644
--- a/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
+++ b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
@@ -2,7 +2,6 @@
using NebulaModel.Networking;
using NebulaModel.Packets.Processors;
using NebulaModel.Packets.Routers;
-using NebulaWorld;
namespace NebulaHost.PacketProcessors.Routers
{
@@ -23,7 +22,7 @@ public void ProcessPacket(PlanetBroadcastPacket packet, NebulaConnection conn)
playerManager.SendRawPacketToPlanet(packet.PacketObject, packet.PlanetId, conn);
//Host probably does not need to know about flying drones of other players if he is not on the same planet
- if (LocalPlayer.Data.LocalPlanetId == packet.PlanetId)
+ if (GameMain.mainPlayer.planetId == packet.PlanetId)
{
MultiplayerHostSession.Instance.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn);
}
diff --git a/NebulaModel/Packets/Players/NewDroneOrderPacket.cs b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs
index 56afcd5cc..da0015474 100644
--- a/NebulaModel/Packets/Players/NewDroneOrderPacket.cs
+++ b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs
@@ -5,14 +5,19 @@ public class NewDroneOrderPacket
public int PlanetId { get; set; }
public int DroneId { get; set; }
public int EntityId { get; set; }
- public int PlayerId { get; set; }
+ public ushort PlayerId { get; set; }
+ public int Stage { get; set; }
+ public int Priority { get; set; }
+
public NewDroneOrderPacket() { }
- public NewDroneOrderPacket(int planetId, int droneId, int entityId, int playerId)
+ public NewDroneOrderPacket(int planetId, int droneId, int entityId, ushort playerId, int stage, int priority)
{
PlanetId = planetId;
DroneId = droneId;
EntityId = entityId;
PlayerId = playerId;
+ Stage = stage;
+ Priority = priority;
}
}
}
diff --git a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
index f07f271a2..7f06fd843 100644
--- a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
+++ b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
@@ -146,9 +146,9 @@ private static void InitLandingPlace(GameData gameData, PlanetData planet)
gameData.mainPlayer.controller.velocityOnLanding = Vector3.zero;
}
- [HarmonyPrefix]
+ [HarmonyPostfix]
[HarmonyPatch("OnDraw")]
- public static void OnDraw_Prefix()
+ public static void OnDraw_Postfix()
{
if (SimulatedWorld.Initialized)
{
diff --git a/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs b/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
index c4e3defdc..4eb3cca68 100644
--- a/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
+++ b/NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Patch.cs
@@ -9,7 +9,7 @@ namespace NebulaPatcher.Patches.Transpiler
class MechaDroneLogic_Patch
{
/*
- * Call DroneManager.BroadcastDroneOrder(int droneId, int entityId) when drone gets new order
+ * Call DroneManager.BroadcastDroneOrder(int droneId, int entityId, int stage) when drone gets new order
*/
[HarmonyTranspiler]
[HarmonyPatch("UpdateTargets")]
@@ -26,7 +26,58 @@ static IEnumerable UpdateTargets_Transpiler(IEnumerable UpdateDrones_Transpiler(IEnumerable instructions)
+ {
+ var codes = new List(instructions);
+ for (int i = 0; i < codes.Count; i++)
+ {
+ if (codes[i].opcode == OpCodes.Brfalse &&
+ codes[i - 1].opcode == OpCodes.Call &&
+ codes[i + 2].opcode == OpCodes.Ldloc_S &&
+ codes[i + 1].opcode == OpCodes.Ldloc_0 &&
+ codes[i - 2].opcode == OpCodes.Ldloca_S)
+ {
+ codes.InsertRange(i + 1, new CodeInstruction[] {
+ new CodeInstruction(OpCodes.Ldloc_S, 4),
+ new CodeInstruction(OpCodes.Ldloc_S, 7),
+ new CodeInstruction(OpCodes.Ldc_I4_2),
+ new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DroneManager), "BroadcastDroneOrder", new System.Type[] { typeof(int), typeof(int), typeof(int) }))
+ });
+ break;
+ }
+ }
+
+ for (int i = 0; i < codes.Count; i++)
+ {
+ if (codes[i].opcode == OpCodes.Br &&
+ codes[i - 1].opcode == OpCodes.Pop &&
+ codes[i + 2].opcode == OpCodes.Ldloc_S &&
+ codes[i + 1].opcode == OpCodes.Ldloc_0 &&
+ codes[i - 2].opcode == OpCodes.Callvirt &&
+ codes[i - 3].opcode == OpCodes.Ldloc_S)
+ {
+ codes.InsertRange(i + 5, new CodeInstruction[] {
+ new CodeInstruction(OpCodes.Ldloc_S, 4),
+ new CodeInstruction(OpCodes.Ldloc_0),
+ new CodeInstruction(OpCodes.Ldloc_S, 4),
+ new CodeInstruction(OpCodes.Ldelema, typeof(MechaDrone)),
+ new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MechaDrone), "targetObject")),
+ new CodeInstruction(OpCodes.Ldc_I4_3),
+ new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DroneManager), "BroadcastDroneOrder", new System.Type[] { typeof(int), typeof(int), typeof(int) }))
});
break;
}
diff --git a/NebulaWorld/INetworkProvider.cs b/NebulaWorld/INetworkProvider.cs
index 990d141ff..2ac0de714 100644
--- a/NebulaWorld/INetworkProvider.cs
+++ b/NebulaWorld/INetworkProvider.cs
@@ -7,6 +7,7 @@ public interface INetworkProvider
void SendPacketToLocalStar(T packet) where T : class, new();
void SendPacketToLocalPlanet(T packet) where T : class, new();
+
void DestroySession();
}
}
diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs
index 9f20d3873..abf31b5f8 100644
--- a/NebulaWorld/Player/DroneManager.cs
+++ b/NebulaWorld/Player/DroneManager.cs
@@ -1,17 +1,22 @@
using NebulaModel.Packets.Players;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace NebulaWorld.Player
{
public static class DroneManager
{
- public static void BroadcastDroneOrder(int droneId, int entityId)
+ public static int[] DronePriorities = new int[255];
+ public static Random rnd = new Random();
+
+ public static void BroadcastDroneOrder(int droneId, int entityId, int stage)
{
- UnityEngine.Debug.Log($"Drone {droneId} is going to {entityId}");
- LocalPlayer.SendPacketToLocalPlanet(new NewDroneOrderPacket());
- }
+ int priority = 0;
+ if (stage == 1 || stage == 2)
+ {
+ priority = rnd.Next();
+ DronePriorities[droneId] = priority;
+ }
+ LocalPlayer.SendPacketToLocalPlanet(new NewDroneOrderPacket(GameMain.mainPlayer.planetId, droneId, entityId, LocalPlayer.PlayerId, stage, priority));
+ }
}
}
diff --git a/NebulaWorld/RemotePlayerModel.cs b/NebulaWorld/RemotePlayerModel.cs
index ef244b5b3..7626f7bc6 100644
--- a/NebulaWorld/RemotePlayerModel.cs
+++ b/NebulaWorld/RemotePlayerModel.cs
@@ -46,6 +46,11 @@ public RemotePlayerModel(ushort playerId)
MechaInstance = new Mecha();
AccessTools.Property(typeof(global::Player), "mecha").SetValue(PlayerInstance, MechaInstance, null);
MechaInstance.Init(PlayerInstance);
+
+ //Fix MechaDroneRenderers
+ AccessTools.Field(typeof(MechaDroneRenderer), "mat_0").SetValue(MechaInstance.droneRenderer, new Material(Configs.builtin.mechaDroneMat.shader));
+ Material mat = (Material)AccessTools.Field(typeof(MechaDroneRenderer), "mat_0").GetValue(MechaInstance.droneRenderer);
+ MethodInvoker.GetHandler(AccessTools.Method(typeof(Material), "CopyPropertiesFromMaterial", new System.Type[] { typeof(Material) })).Invoke(mat, Configs.builtin.mechaDroneMat);
}
public void Destroy()
diff --git a/NebulaWorld/SimulatedWorld.cs b/NebulaWorld/SimulatedWorld.cs
index 63ee116ec..7d95dff2d 100644
--- a/NebulaWorld/SimulatedWorld.cs
+++ b/NebulaWorld/SimulatedWorld.cs
@@ -6,6 +6,7 @@
using NebulaModel.Packets.Trash;
using NebulaWorld.Factory;
using NebulaWorld.MonoBehaviours.Remote;
+using NebulaWorld.Player;
using NebulaWorld.Trash;
using System.Collections.Generic;
using UnityEngine;
@@ -111,6 +112,72 @@ public static void UpdateRemotePlayerAnimation(PlayerAnimationUpdate packet)
}
}
+ public static void UpdateRemotePlayerDrone(NewDroneOrderPacket packet)
+ {
+ if (remotePlayersModels.TryGetValue(packet.PlayerId, out RemotePlayerModel player))
+ {
+ //Setup drone of remote player based on the drone data
+ ref MechaDrone drone = ref player.PlayerInstance.mecha.drones[packet.DroneId];
+ MechaDroneLogic droneLogic = player.PlayerInstance.mecha.droneLogic;
+
+ drone.stage = packet.Stage;
+ drone.targetObject = packet.Stage < 3 ? packet.EntityId : 0;
+ drone.movement = droneLogic.player.mecha.droneMovement;
+ if (packet.Stage == 1)
+ {
+ drone.position = player.Movement.GetLastPosition().LocalPlanetPosition.ToUnity();
+ }
+ drone.target = (Vector3)MethodInvoker.GetHandler(AccessTools.Method(typeof(MechaDroneLogic), "_obj_hpos", new System.Type[] { typeof(int) })).Invoke(GameMain.mainPlayer.mecha.droneLogic, packet.EntityId);
+ drone.initialVector = drone.position + drone.position.normalized * 4.5f + ((drone.target - drone.position).normalized + UnityEngine.Random.insideUnitSphere) * 1.5f;
+ drone.forward = drone.initialVector;
+ drone.progress = 0f;
+ player.MechaInstance.droneCount = GameMain.mainPlayer.mecha.droneCount;
+ player.MechaInstance.droneSpeed = GameMain.mainPlayer.mecha.droneSpeed;
+ Mecha myMecha = GameMain.mainPlayer.mecha;
+ if (packet.Stage == 3)
+ {
+ myMecha.droneLogic.serving.Remove(packet.EntityId);
+ }
+
+ if (drone.stage == 1 || drone.stage == 2) {
+ //Check if my drone is already going there
+ if (!myMecha.droneLogic.serving.Contains(packet.EntityId))
+ {
+ myMecha.droneLogic.serving.Add(packet.EntityId);
+ } else
+ {
+ //resolve conflict (two drones are going to the same building)
+ //find my drone that is going there
+ int priority = 0;
+ int droneId = 0;
+ for (int i = 0; i < myMecha.droneCount; i++)
+ {
+ if (myMecha.drones[i].stage > 0 && myMecha.drones[i].targetObject == drone.targetObject)
+ {
+ priority = DroneManager.DronePriorities[i];
+ droneId = i;
+ break;
+ }
+ }
+ //compare, who's drone has higher priority
+ if (packet.Priority > priority)
+ {
+ //their drone won, my drone has to return
+ ref MechaDrone myDrone = ref myMecha.drones[droneId];
+ myDrone.stage = 3;
+ myDrone.targetObject = 0;
+ } else
+ {
+ //my drone won, their has to return
+ drone.stage = 3;
+ drone.targetObject = 0;
+ }
+ }
+ }
+
+ }
+ }
+
public static void UpdatePlayerColor(ushort playerId, Float3 color)
{
Transform transform;
@@ -277,25 +344,28 @@ public static void OnDronesDraw()
{
foreach(KeyValuePair remoteModel in remotePlayersModels)
{
- remoteModel.Value.MechaInstance.droneRenderer.Draw();
+ //Render drones of players only on the local planet
+ if (GameMain.mainPlayer.planetId == remoteModel.Value.Movement.localPlanetId)
+ {
+ remoteModel.Value.MechaInstance.droneRenderer.Draw();
+ }
}
}
public static void OnDronesGameTick(long time, float dt)
{
- double tmp = 0;
- double tmp2 = 0;
+ double tmp = 1e10; //fake energy of remote player, needed to do the Update()
+ double tmp2 = 1;
//Update drones positions based on their targets
foreach (KeyValuePair remoteModel in remotePlayersModels)
{
MechaDrone[] drones = remoteModel.Value.PlayerInstance.mecha.drones;
- int droneCount = remoteModel.Value.PlayerInstance.mecha.droneCount;
+ int droneCount = GameMain.mainPlayer.mecha.droneCount;
for (int i = 0; i < droneCount; i++)
{
- if (drones[i].stage != 0)
+ //Update only moving drones of players on the same planet
+ if (drones[i].stage != 0 && GameMain.mainPlayer.planetId == remoteModel.Value.Movement.localPlanetId)
{
- //To-do: fix the correct factory here
- //To-do: Optimize getting local position of player
drones[i].Update(GameMain.localPlanet.factory.prebuildPool, remoteModel.Value.Movement.GetLastPosition().LocalPlanetPosition.ToUnity(), dt, ref tmp, ref tmp2, 0);
}
}
From ff46501778c935b75b0d3d9647d62610bb0a8930 Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Thu, 15 Apr 2021 19:29:52 +0200
Subject: [PATCH 4/6] bug fixes
---
NebulaClient/MultiplayerClientSession.cs | 5 ++++
NebulaClient/NebulaClient.csproj | 1 +
.../Players/RemoveDroneOrdersProcessor.cs | 20 +++++++++++++
NebulaHost/MultiplayerHostSession.cs | 5 ++++
.../Players/NewDroneOrderProcessor.cs | 24 ++++++++++++++-
NebulaHost/PlayerManager.cs | 30 ++++++++++++++++++-
NebulaModel/NebulaModel.csproj | 1 +
.../Players/RemoveDroneOrdersPacket.cs | 14 +++++++++
.../Patches/Dynamic/GameData_Patch.cs | 11 +++++++
NebulaWorld/INetworkProvider.cs | 2 ++
NebulaWorld/LocalPlayer.cs | 5 ++++
NebulaWorld/Player/DroneManager.cs | 30 ++++++++++++++++++-
NebulaWorld/SimulatedWorld.cs | 4 +--
13 files changed, 147 insertions(+), 5 deletions(-)
create mode 100644 NebulaClient/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs
create mode 100644 NebulaModel/Packets/Players/RemoveDroneOrdersPacket.cs
diff --git a/NebulaClient/MultiplayerClientSession.cs b/NebulaClient/MultiplayerClientSession.cs
index 3dc28767e..0a5bfcec1 100644
--- a/NebulaClient/MultiplayerClientSession.cs
+++ b/NebulaClient/MultiplayerClientSession.cs
@@ -85,6 +85,11 @@ public void DestroySession()
{
serverConnection?.SendPacket(new PlanetBroadcastPacket(PacketProcessor.Write(packet), GameMain.mainPlayer.planetId));
}
+ public void SendPacketToPlanet(T packet, int planetId) where T : class, new()
+ {
+ //Should send packet to particular planet
+ //Not needed at the moment, used only on the host side
+ }
public void Reconnect()
{
diff --git a/NebulaClient/NebulaClient.csproj b/NebulaClient/NebulaClient.csproj
index 745845dd1..8898b0444 100644
--- a/NebulaClient/NebulaClient.csproj
+++ b/NebulaClient/NebulaClient.csproj
@@ -83,6 +83,7 @@
+
diff --git a/NebulaClient/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs b/NebulaClient/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs
new file mode 100644
index 000000000..97bd1e2d3
--- /dev/null
+++ b/NebulaClient/PacketProcessors/Players/RemoveDroneOrdersProcessor.cs
@@ -0,0 +1,20 @@
+using NebulaModel.Networking;
+using NebulaHost.PacketProcessors.Players;
+using NebulaModel.Packets.Processors;
+
+namespace NebulaClient.PacketProcessors.Players
+{
+ class RemoveDroneOrdersProcessor : IPacketProcessor
+ {
+ public void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConnection conn)
+ {
+ if (packet.QueuedEntityIds != null)
+ {
+ for (int i = 0; i < packet.QueuedEntityIds.Length; i++)
+ {
+ GameMain.mainPlayer.mecha.droneLogic.serving.Remove(packet.QueuedEntityIds[i]);
+ }
+ }
+ }
+ }
+}
diff --git a/NebulaHost/MultiplayerHostSession.cs b/NebulaHost/MultiplayerHostSession.cs
index eb4bd14b5..efa4ca4cb 100644
--- a/NebulaHost/MultiplayerHostSession.cs
+++ b/NebulaHost/MultiplayerHostSession.cs
@@ -94,6 +94,11 @@ public void DestroySession()
PlayerManager.SendPacketToLocalPlanet(packet);
}
+ public void SendPacketToPlanet(T packet, int planetId) where T : class, new()
+ {
+ PlayerManager.SendPacketToPlanet(packet, planetId);
+ }
+
private void Update()
{
gameStateUpdateTimer += Time.deltaTime;
diff --git a/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
index 9fcd2d0d9..7edaf23f9 100644
--- a/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
+++ b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
@@ -3,15 +3,37 @@
using NebulaModel.Packets.Players;
using NebulaModel.Packets.Processors;
using NebulaWorld;
+using NebulaWorld.Player;
namespace NebulaHost.PacketProcessors.Players
{
[RegisterPacketProcessor]
class NewDroneOrderProcessor : IPacketProcessor
{
+ private PlayerManager playerManager;
+
+ public NewDroneOrderProcessor()
+ {
+ playerManager = MultiplayerHostSession.Instance.PlayerManager;
+ }
+
public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
{
- SimulatedWorld.UpdateRemotePlayerDrone(packet);
+ Player player = playerManager.GetPlayer(conn);
+
+ if (player != null)
+ {
+ if (packet.Stage == 1 || packet.Stage == 2)
+ {
+ DroneManager.AddPlayerDronePlan(player.Id, packet.EntityId);
+ }
+ else if (packet.Stage == 3)
+ {
+ DroneManager.RemovePlayerDronePlan(player.Id, packet.EntityId);
+ }
+
+ SimulatedWorld.UpdateRemotePlayerDrone(packet);
+ }
}
}
}
diff --git a/NebulaHost/PlayerManager.cs b/NebulaHost/PlayerManager.cs
index 96471027f..f0a64651f 100644
--- a/NebulaHost/PlayerManager.cs
+++ b/NebulaHost/PlayerManager.cs
@@ -1,8 +1,10 @@
-using NebulaModel.DataStructures;
+using NebulaHost.PacketProcessors.Players;
+using NebulaModel.DataStructures;
using NebulaModel.Logger;
using NebulaModel.Networking;
using NebulaModel.Packets.Session;
using NebulaWorld;
+using NebulaWorld.Player;
using NebulaWorld.Statistics;
using System.Collections.Generic;
using System.Linq;
@@ -92,6 +94,17 @@ public Player GetSyncingPlayer(NebulaConnection conn)
}
}
+ public void SendPacketToPlanet(T packet, int planetId) where T : class, new()
+ {
+ foreach (Player player in GetConnectedPlayers())
+ {
+ if (player.Data.LocalPlanetId == planetId)
+ {
+ player.SendPacket(packet);
+ }
+ }
+ }
+
public void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection sender)
{
foreach (Player player in GetConnectedPlayers())
@@ -147,6 +160,21 @@ public void PlayerDisconnected(NebulaConnection conn)
connectedPlayers.Remove(conn);
availablePlayerIds.Enqueue(player.Id);
StatisticsManager.instance.UnRegisterPlayer(player.Id);
+
+ //Notify players about queued building plans for drones
+ int[] DronePlans = DroneManager.GetPlayerDronePlans(player.Id);
+ if (DronePlans != null && DronePlans.Length > 0 && player.Data.LocalPlanetId > 0)
+ {
+ LocalPlayer.SendPacketToPlanet(new RemoveDroneOrdersPacket(DronePlans), player.Data.LocalPlanetId);
+ //Remove it also from host queue, if host is on the same planet
+ if (GameMain.mainPlayer.planetId == player.Data.LocalPlanetId)
+ {
+ for(int i = 0; i < DronePlans.Length; i++)
+ {
+ GameMain.mainPlayer.mecha.droneLogic.serving.Remove(DronePlans[i]);
+ }
+ }
+ }
}
else
{
diff --git a/NebulaModel/NebulaModel.csproj b/NebulaModel/NebulaModel.csproj
index decdad0dc..d952a057a 100644
--- a/NebulaModel/NebulaModel.csproj
+++ b/NebulaModel/NebulaModel.csproj
@@ -111,6 +111,7 @@
+
diff --git a/NebulaModel/Packets/Players/RemoveDroneOrdersPacket.cs b/NebulaModel/Packets/Players/RemoveDroneOrdersPacket.cs
new file mode 100644
index 000000000..2dcc80f40
--- /dev/null
+++ b/NebulaModel/Packets/Players/RemoveDroneOrdersPacket.cs
@@ -0,0 +1,14 @@
+namespace NebulaHost.PacketProcessors.Players
+{
+ public class RemoveDroneOrdersPacket
+ {
+ public int[] QueuedEntityIds { get; set; }
+
+ public RemoveDroneOrdersPacket() { }
+
+ public RemoveDroneOrdersPacket(int[] queuedEntityIds)
+ {
+ QueuedEntityIds = queuedEntityIds;
+ }
+ }
+}
diff --git a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
index 9e086d715..2016cd4f5 100644
--- a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
+++ b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
@@ -186,5 +186,16 @@ public static void LeaveStar_Prefix(GameData __instance)
}
}
}
+
+ [HarmonyPrefix]
+ [HarmonyPatch("LeavePlanet")]
+ public static void LeavePlanet_Prefix(GameData __instance)
+ {
+ //Players should clear the list of drone orders of other players when they leave the planet
+ if (SimulatedWorld.Initialized)
+ {
+ GameMain.mainPlayer.mecha.droneLogic.serving.Clear();
+ }
+ }
}
}
diff --git a/NebulaWorld/INetworkProvider.cs b/NebulaWorld/INetworkProvider.cs
index 2ac0de714..90178c2c6 100644
--- a/NebulaWorld/INetworkProvider.cs
+++ b/NebulaWorld/INetworkProvider.cs
@@ -8,6 +8,8 @@ public interface INetworkProvider
void SendPacketToLocalPlanet(T packet) where T : class, new();
+ void SendPacketToPlanet(T packet, int planetId) where T : class, new();
+
void DestroySession();
}
}
diff --git a/NebulaWorld/LocalPlayer.cs b/NebulaWorld/LocalPlayer.cs
index c761f442d..a5e625277 100644
--- a/NebulaWorld/LocalPlayer.cs
+++ b/NebulaWorld/LocalPlayer.cs
@@ -36,6 +36,11 @@ public static void SetNetworkProvider(INetworkProvider provider)
networkProvider?.SendPacketToLocalPlanet(packet);
}
+ public static void SendPacketToPlanet(T packet, int planetId) where T : class, new()
+ {
+ networkProvider?.SendPacketToPlanet(packet, planetId);
+ }
+
public static void SetReady()
{
if (!IsMasterClient)
diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs
index abf31b5f8..c3d1a8489 100644
--- a/NebulaWorld/Player/DroneManager.cs
+++ b/NebulaWorld/Player/DroneManager.cs
@@ -1,5 +1,6 @@
using NebulaModel.Packets.Players;
using System;
+using System.Collections.Generic;
namespace NebulaWorld.Player
{
@@ -7,6 +8,7 @@ public static class DroneManager
{
public static int[] DronePriorities = new int[255];
public static Random rnd = new Random();
+ public static Dictionary> PlayerDroneBuildingPlans = new Dictionary>();
public static void BroadcastDroneOrder(int droneId, int entityId, int stage)
{
@@ -17,6 +19,32 @@ public static void BroadcastDroneOrder(int droneId, int entityId, int stage)
DronePriorities[droneId] = priority;
}
LocalPlayer.SendPacketToLocalPlanet(new NewDroneOrderPacket(GameMain.mainPlayer.planetId, droneId, entityId, LocalPlayer.PlayerId, stage, priority));
- }
+ }
+
+ public static void AddPlayerDronePlan(ushort playerId, int entityId)
+ {
+ if (!PlayerDroneBuildingPlans.ContainsKey(playerId))
+ {
+ PlayerDroneBuildingPlans.Add(playerId, new List());
+ }
+ PlayerDroneBuildingPlans[playerId].Add(entityId);
+ }
+
+ public static void RemovePlayerDronePlan(ushort playerId, int entityId)
+ {
+ if (PlayerDroneBuildingPlans.ContainsKey(playerId))
+ {
+ PlayerDroneBuildingPlans[playerId].Remove(entityId);
+ }
+ }
+
+ public static int[] GetPlayerDronePlans(ushort playerId)
+ {
+ if (PlayerDroneBuildingPlans.ContainsKey(playerId))
+ {
+ return PlayerDroneBuildingPlans[playerId].ToArray();
+ }
+ return null;
+ }
}
}
diff --git a/NebulaWorld/SimulatedWorld.cs b/NebulaWorld/SimulatedWorld.cs
index 6a0f8aebc..a1fb1c976 100644
--- a/NebulaWorld/SimulatedWorld.cs
+++ b/NebulaWorld/SimulatedWorld.cs
@@ -126,7 +126,7 @@ public static void UpdateRemotePlayerDrone(NewDroneOrderPacket packet)
drone.movement = droneLogic.player.mecha.droneMovement;
if (packet.Stage == 1)
{
- drone.position = player.Movement.GetLastPosition().LocalPlanetPosition.ToUnity();
+ drone.position = player.Movement.GetLastPosition().LocalPlanetPosition.ToVector3();
}
drone.target = (Vector3)MethodInvoker.GetHandler(AccessTools.Method(typeof(MechaDroneLogic), "_obj_hpos", new System.Type[] { typeof(int) })).Invoke(GameMain.mainPlayer.mecha.droneLogic, packet.EntityId);
drone.initialVector = drone.position + drone.position.normalized * 4.5f + ((drone.target - drone.position).normalized + UnityEngine.Random.insideUnitSphere) * 1.5f;
@@ -375,7 +375,7 @@ public static void OnDronesGameTick(long time, float dt)
//Update only moving drones of players on the same planet
if (drones[i].stage != 0 && GameMain.mainPlayer.planetId == remoteModel.Value.Movement.localPlanetId)
{
- drones[i].Update(GameMain.localPlanet.factory.prebuildPool, remoteModel.Value.Movement.GetLastPosition().LocalPlanetPosition.ToUnity(), dt, ref tmp, ref tmp2, 0);
+ drones[i].Update(GameMain.localPlanet.factory.prebuildPool, remoteModel.Value.Movement.GetLastPosition().LocalPlanetPosition.ToVector3(), dt, ref tmp, ref tmp2, 0);
}
}
remoteModel.Value.MechaInstance.droneRenderer.Update();
From 9dbe27fd5c2337864c7bde7838b76fe10a9216fb Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Fri, 16 Apr 2021 21:15:29 +0200
Subject: [PATCH 5/6] Added MethodNotImplemented Exception
---
NebulaClient/MultiplayerClientSession.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/NebulaClient/MultiplayerClientSession.cs b/NebulaClient/MultiplayerClientSession.cs
index 0a5bfcec1..a4d746dda 100644
--- a/NebulaClient/MultiplayerClientSession.cs
+++ b/NebulaClient/MultiplayerClientSession.cs
@@ -6,6 +6,7 @@
using NebulaModel.Packets.Session;
using NebulaModel.Utils;
using NebulaWorld;
+using System;
using System.Net;
using UnityEngine;
using WebSocketSharp;
@@ -89,6 +90,7 @@ public void DestroySession()
{
//Should send packet to particular planet
//Not needed at the moment, used only on the host side
+ throw new NotImplementedException();
}
public void Reconnect()
From 26be60d8ccfde31b003f01f723dc988e9b0f43a1 Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Fri, 16 Apr 2021 21:29:55 +0200
Subject: [PATCH 6/6] planetId check moved to the particular packet processor.
---
.../PacketProcessors/Players/NewDroneOrderProcessor.cs | 6 ++++++
.../PacketProcessors/Routers/PlanetBroadcastProcessor.cs | 8 ++------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
index 7edaf23f9..881c678be 100644
--- a/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
+++ b/NebulaHost/PacketProcessors/Players/NewDroneOrderProcessor.cs
@@ -19,6 +19,12 @@ public NewDroneOrderProcessor()
public void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection conn)
{
+ //Host does not need to know about flying drones of other players if he is not on the same planet
+ if (GameMain.mainPlayer.planetId != packet.PlanetId)
+ {
+ return;
+ }
+
Player player = playerManager.GetPlayer(conn);
if (player != null)
diff --git a/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
index b98ff1c09..94ef86a17 100644
--- a/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
+++ b/NebulaHost/PacketProcessors/Routers/PlanetBroadcastProcessor.cs
@@ -20,12 +20,8 @@ public void ProcessPacket(PlanetBroadcastPacket packet, NebulaConnection conn)
{
//Forward packet to other users
playerManager.SendRawPacketToPlanet(packet.PacketObject, packet.PlanetId, conn);
-
- //Host probably does not need to know about flying drones of other players if he is not on the same planet
- if (GameMain.mainPlayer.planetId == packet.PlanetId)
- {
- MultiplayerHostSession.Instance.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn);
- }
+ //Forward packet to the host
+ MultiplayerHostSession.Instance.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn);
}
}
}