From a0a1eaa65107c9ee6a9988747c3aac03b537f6ae Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Thu, 22 Apr 2021 19:17:01 +0200
Subject: [PATCH 1/4] Fix for belt building
---
NebulaClient/NebulaClient.csproj | 1 -
.../AddEntityPreviewRequestProcessor.cs | 36 ------------
NebulaHost/NebulaHost.csproj | 1 -
.../AddEntityPreviewRequestProcessor.cs | 57 -------------------
NebulaModel/NebulaModel.csproj | 1 -
.../Factory/AddEntityPreviewRequest.cs | 32 -----------
NebulaWorld/Factory/FactoryManager.cs | 2 +-
7 files changed, 1 insertion(+), 129 deletions(-)
delete mode 100644 NebulaClient/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
delete mode 100644 NebulaHost/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
delete mode 100644 NebulaModel/Packets/Factory/AddEntityPreviewRequest.cs
diff --git a/NebulaClient/NebulaClient.csproj b/NebulaClient/NebulaClient.csproj
index b2e6b48f2..b2f8811d3 100644
--- a/NebulaClient/NebulaClient.csproj
+++ b/NebulaClient/NebulaClient.csproj
@@ -66,7 +66,6 @@
-
diff --git a/NebulaClient/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs b/NebulaClient/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
deleted file mode 100644
index 813e706ed..000000000
--- a/NebulaClient/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using NebulaModel.Attributes;
-using NebulaModel.Networking;
-using NebulaModel.Packets.Factory;
-using NebulaModel.Packets.Processors;
-using NebulaWorld.Factory;
-
-namespace NebulaClient.PacketProcessors.Factory.Entity
-{
- [RegisterPacketProcessor]
- public class AddEntityPreviewRequestProcessor : IPacketProcessor
- {
- public void ProcessPacket(AddEntityPreviewRequest packet, NebulaConnection conn)
- {
- PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);
-
- // We only execute the code if the client has loaded the factory at least once.
- // Else it will get it once it goes to the planet for the first time.
- if (planet.factory != null)
- {
- using (FactoryManager.EventFromServer.On())
- {
- PrebuildData prebuild = packet.GetPrebuildData();
- int localPlanetId = GameMain.localPlanet?.id ?? -1;
- if (packet.PlanetId == localPlanetId)
- {
- planet.factory.AddPrebuildDataWithComponents(prebuild);
- }
- else
- {
- planet.factory.AddPrebuildData(prebuild);
- }
- }
- }
- }
- }
-}
diff --git a/NebulaHost/NebulaHost.csproj b/NebulaHost/NebulaHost.csproj
index 6bed15596..40ce0ca22 100644
--- a/NebulaHost/NebulaHost.csproj
+++ b/NebulaHost/NebulaHost.csproj
@@ -67,7 +67,6 @@
-
diff --git a/NebulaHost/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs b/NebulaHost/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
deleted file mode 100644
index 7515869cb..000000000
--- a/NebulaHost/PacketProcessors/Factory/Entity/AddEntityPreviewRequestProcessor.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using NebulaModel.Attributes;
-using NebulaModel.Logger;
-using NebulaModel.Networking;
-using NebulaModel.Packets.Factory;
-using NebulaModel.Packets.Processors;
-using NebulaWorld;
-using NebulaWorld.Factory;
-
-namespace NebulaHost.PacketProcessors.Factory.Entity
-{
- [RegisterPacketProcessor]
- public class AddEntityPreviewRequestProcessor : IPacketProcessor
- {
- private PlayerManager playerManager;
-
- public AddEntityPreviewRequestProcessor()
- {
- playerManager = MultiplayerHostSession.Instance.PlayerManager;
- }
-
- public void ProcessPacket(AddEntityPreviewRequest packet, NebulaConnection conn)
- {
- Player player = playerManager.GetPlayer(conn);
- if (player == null)
- {
- Log.Warn($"Received AddEntityPreviewRequest packet from unknown player connection");
- return;
- }
-
- PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);
- if (planet.factory == null)
- {
- Log.Warn($"planet.factory was null create new one");
- planet.factory = GameMain.data.GetOrCreateFactory(planet);
- }
-
- using (FactoryManager.EventFromClient.On())
- {
- int nextPrebuildId = FactoryManager.GetNextPrebuildId(packet.PlanetId);
- FactoryManager.SetPrebuildRequest(packet.PlanetId, nextPrebuildId, player.Id);
- PrebuildData prebuild = packet.GetPrebuildData();
- int localPlanetId = GameMain.localPlanet?.id ?? -1;
- if (planet.id == localPlanetId)
- {
- planet.factory.AddPrebuildDataWithComponents(prebuild);
- }
- else
- {
- planet.factory.AddPrebuildData(prebuild);
-
- // AddPrebuildData is not patched so we need to send the packet manually here
- LocalPlayer.SendPacket(packet);
- }
- }
- }
- }
-}
diff --git a/NebulaModel/NebulaModel.csproj b/NebulaModel/NebulaModel.csproj
index cc4e08e36..f48a28556 100644
--- a/NebulaModel/NebulaModel.csproj
+++ b/NebulaModel/NebulaModel.csproj
@@ -65,7 +65,6 @@
-
diff --git a/NebulaModel/Packets/Factory/AddEntityPreviewRequest.cs b/NebulaModel/Packets/Factory/AddEntityPreviewRequest.cs
deleted file mode 100644
index e42d2291c..000000000
--- a/NebulaModel/Packets/Factory/AddEntityPreviewRequest.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using NebulaModel.Networking;
-
-namespace NebulaModel.Packets.Factory
-{
- public class AddEntityPreviewRequest
- {
- public int PlanetId { get; set; }
- public byte[] PrebuildDataRaw { get; set; }
-
- public AddEntityPreviewRequest() { }
- public AddEntityPreviewRequest(int planetId, PrebuildData prebuild)
- {
- PlanetId = planetId;
-
- using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
- {
- prebuild.Export(writer.BinaryWriter);
- PrebuildDataRaw = writer.CloseAndGetBytes();
- }
- }
-
- public PrebuildData GetPrebuildData()
- {
- PrebuildData prebuild = new PrebuildData();
- using (BinaryUtils.Reader writer = new BinaryUtils.Reader(PrebuildDataRaw))
- {
- prebuild.Import(writer.BinaryReader);
- }
- return prebuild;
- }
- }
-}
diff --git a/NebulaWorld/Factory/FactoryManager.cs b/NebulaWorld/Factory/FactoryManager.cs
index 380f87bd1..a9b3325e4 100644
--- a/NebulaWorld/Factory/FactoryManager.cs
+++ b/NebulaWorld/Factory/FactoryManager.cs
@@ -74,7 +74,7 @@ public static int GetNextPrebuildId(PlanetFactory factory)
int prebuildRecycleCursor = GetPrebuildRecycleCursor(factory);
int[] prebuildRecycle = GetPrebuildRecycle(factory);
- return prebuildRecycleCursor <= 0 ? factory.prebuildCursor : prebuildRecycle[prebuildRecycleCursor - 1];
+ return prebuildRecycleCursor <= 0 ? factory.prebuildCursor+1 : prebuildRecycle[prebuildRecycleCursor - 1];
}
}
From 2c40d06b31a58393fdbcf2b154ecd3f510cd4dfc Mon Sep 17 00:00:00 2001
From: Lukas Michalec <79051050+Baldie-dev@users.noreply.github.com>
Date: Thu, 22 Apr 2021 21:52:01 +0200
Subject: [PATCH 2/4] Bug Fix: Prebuild indexes are now taken from the game
after prebuild is generated.
---
.../Entity/BuildEntityRequestProcessor.cs | 10 +++-------
.../Patches/Dynamic/PlanetFactory_Patch.cs | 16 +++++++---------
NebulaWorld/Player/DroneManager.cs | 8 ++++++++
NebulaWorld/SimulatedWorld.cs | 2 ++
4 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/NebulaClient/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs b/NebulaClient/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs
index 1656dc3f0..ee4f4fc18 100644
--- a/NebulaClient/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs
+++ b/NebulaClient/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs
@@ -34,14 +34,10 @@ public void ProcessPacket(BuildEntityRequest packet, NebulaConnection conn)
planet.audio.Init();
}
- //Remove building from drone queue
- GameMain.mainPlayer.mecha.droneLogic.serving.Remove(-packet.PrebuildId);
- planet.factory.BuildFinally(GameMain.mainPlayer, packet.PrebuildId);
- if (!DroneManager.RemoveBuildRequest(-packet.PrebuildId))
- {
- Log.Warn($"Build Request was not succesfully removed.");
- }
+ //Remove building from drone queue
+ GameMain.mainPlayer.mecha.droneLogic.serving.Remove(-packet.PrebuildId);
planet.factory.BuildFinally(GameMain.mainPlayer, packet.PrebuildId);
+ DroneManager.RemoveBuildRequest(-packet.PrebuildId);
// Make sure to free the physics once the FlattenTerrain is done
if (packet.PlanetId != GameMain.localPlanet?.id)
diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
index ddff75dff..b97515eee 100644
--- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
+++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
@@ -13,21 +13,19 @@ namespace NebulaPatcher.Patches.Dynamic
[HarmonyPatch(typeof(PlanetFactory))]
class BuildFinally_patch
{
- [HarmonyPrefix]
- [HarmonyPatch("AddPrebuildDataWithComponents")]
- public static bool AddPrebuildDataWithComponents_Prefix(PlanetFactory __instance, PrebuildData prebuild)
+ [HarmonyPostfix]
+ [HarmonyPatch("AddPrebuildData")]
+ public static void AddPrebuildData_Prefix(PlanetFactory __instance, PrebuildData prebuild, ref int __result)
{
if (!SimulatedWorld.Initialized)
- return true;
+ return;
// If the host game called the method, we need to compute the PrebuildId ourself
if (LocalPlayer.IsMasterClient && !FactoryManager.EventFromClient)
{
- int nextPrebuildId = FactoryManager.GetNextPrebuildId(__instance);
- FactoryManager.SetPrebuildRequest(__instance.planetId, nextPrebuildId, LocalPlayer.PlayerId);
+
+ FactoryManager.SetPrebuildRequest(__instance.planetId, __result, LocalPlayer.PlayerId);
}
-
- return true;
}
[HarmonyPrefix]
@@ -56,7 +54,7 @@ public static bool BuildFinally_Prefix(PlanetFactory __instance, Player player,
LocalPlayer.SendPacket(new BuildEntityRequest(__instance.planetId, prebuildId, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor));
}
- if (!LocalPlayer.IsMasterClient && !FactoryManager.EventFromServer)
+ if (!LocalPlayer.IsMasterClient && !FactoryManager.EventFromServer && !DroneManager.IsPendingBuildRequest(-prebuildId))
{
DroneManager.AddBuildRequestSent(-prebuildId);
}
diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs
index fdd796b51..88e879e17 100644
--- a/NebulaWorld/Player/DroneManager.cs
+++ b/NebulaWorld/Player/DroneManager.cs
@@ -13,6 +13,14 @@ public static class DroneManager
public static List PendingBuildRequests = new List();
public static Dictionary CachedPositions = new Dictionary();
+ public static void Initialize()
+ {
+ DronePriorities = new int[255];
+ PlayerDroneBuildingPlans = new Dictionary>();
+ PendingBuildRequests = new List();
+ CachedPositions = new Dictionary();
+ }
+
public static void BroadcastDroneOrder(int droneId, int entityId, int stage)
{
if (!SimulatedWorld.Initialized)
diff --git a/NebulaWorld/SimulatedWorld.cs b/NebulaWorld/SimulatedWorld.cs
index 440d70bcb..df214bdea 100644
--- a/NebulaWorld/SimulatedWorld.cs
+++ b/NebulaWorld/SimulatedWorld.cs
@@ -11,6 +11,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
+using NebulaWorld.Player;
namespace NebulaWorld
{
@@ -37,6 +38,7 @@ public static Locker GetRemotePlayersModels(out Dictionary
Date: Fri, 23 Apr 2021 08:35:33 +0200
Subject: [PATCH 3/4] Changing function name to match the naming convention
---
NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
index b97515eee..17061b453 100644
--- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
+++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
@@ -15,7 +15,7 @@ class BuildFinally_patch
{
[HarmonyPostfix]
[HarmonyPatch("AddPrebuildData")]
- public static void AddPrebuildData_Prefix(PlanetFactory __instance, PrebuildData prebuild, ref int __result)
+ public static void AddPrebuildData_Postfix(PlanetFactory __instance, PrebuildData prebuild, ref int __result)
{
if (!SimulatedWorld.Initialized)
return;
From dc8814ae674c6e4879ea229fa8b44173b3bb25f4 Mon Sep 17 00:00:00 2001
From: Hubert Gendron
Date: Fri, 23 Apr 2021 23:19:10 -0400
Subject: [PATCH 4/4] Bump version
---
NebulaPatcher/NebulaPlugin.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NebulaPatcher/NebulaPlugin.cs b/NebulaPatcher/NebulaPlugin.cs
index 045d42da0..fa2f6d181 100644
--- a/NebulaPatcher/NebulaPlugin.cs
+++ b/NebulaPatcher/NebulaPlugin.cs
@@ -8,7 +8,7 @@
namespace NebulaPatcher
{
- [BepInPlugin("com.github.hubertgendron.nebula", "Nebula - Multiplayer Mod", "0.0.1.0")]
+ [BepInPlugin("com.github.hubertgendron.nebula", "Nebula - Multiplayer Mod", "0.0.2.0")]
[BepInProcess("DSPGAME.exe")]
public class NebulaPlugin : BaseUnityPlugin
{