From 04e637fbf2784ff89686dcfe526b4e88d2dcd2eb Mon Sep 17 00:00:00 2001 From: Chris Yeninas <844685+PhantomGamers@users.noreply.github.com> Date: Fri, 12 Nov 2021 16:48:40 -0500 Subject: [PATCH 1/5] fix error when upgrading blueprint previews --- .../Packets/Factory/UpgradeEntityRequest.cs | 4 ++- .../Entity/UpgradeEntityRequestProcessor.cs | 21 ++++++++++-- .../Patches/Dynamic/PlanetFactory_Patch.cs | 33 +++++++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/NebulaModel/Packets/Factory/UpgradeEntityRequest.cs b/NebulaModel/Packets/Factory/UpgradeEntityRequest.cs index c420497ae..94f9759a1 100644 --- a/NebulaModel/Packets/Factory/UpgradeEntityRequest.cs +++ b/NebulaModel/Packets/Factory/UpgradeEntityRequest.cs @@ -8,15 +8,17 @@ public class UpgradeEntityRequest public Float3 pos { get; set; } public Float4 rot { get; set; } public int UpgradeProtoId { get; set; } + public bool IsPrebuild { get; set; } public int AuthorId { get; set; } public UpgradeEntityRequest() { } - public UpgradeEntityRequest(int planetId, Float3 pos, Float4 rot, int upgradeProtoId, int authorId) + public UpgradeEntityRequest(int planetId, Float3 pos, Float4 rot, int upgradeProtoId, bool isPrebuild, int authorId) { PlanetId = planetId; this.pos = pos; this.rot = rot; UpgradeProtoId = upgradeProtoId; + IsPrebuild = isPrebuild; AuthorId = authorId; } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs index 3479645ac..5768fc11b 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -31,17 +31,32 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection Quaternion qRot = new Quaternion(packet.rot.x, packet.rot.y, packet.rot.z, packet.rot.w); Vector3 vPos = new Vector3(packet.pos.x, packet.pos.y, packet.pos.z); - EntityData[] ePool = planet.factory.entityPool; + + for (int i = 1; i < planet.factory.entityCursor; i++) { - if(ePool[i].pos == vPos && ePool[i].rot == qRot) + Quaternion poolRot; + Vector3 poolPos; + + if (packet.IsPrebuild) + { + poolRot = planet.factory.prebuildPool[i].rot; + poolPos = planet.factory.prebuildPool[i].pos; + } + else + { + poolRot = planet.factory.entityPool[i].rot; + poolPos = planet.factory.entityPool[i].pos; + } + + if (poolPos == vPos && poolRot == qRot) { // setting specifyPlanet here to avoid accessing a null object (see GPUInstancingManager activePlanet getter) PlanetData pData = GameMain.gpuiManager.specifyPlanet; GameMain.gpuiManager.specifyPlanet = GameMain.galaxy.PlanetById(packet.PlanetId); - planet.factory.UpgradeFinally(GameMain.mainPlayer, i, itemProto); + planet.factory.UpgradeFinally(GameMain.mainPlayer, packet.IsPrebuild ? -i : i, itemProto); GameMain.gpuiManager.specifyPlanet = pData; break; diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs index c9fcab0fa..04f76a5db 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs @@ -72,11 +72,40 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player return true; } + if(objId == 0 || replace_item_proto == null) + { + return false; + } + if (Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.Session.Factories.IsIncomingRequest.Value) { - EntityData eData = __instance.entityPool[objId]; + bool isPrebuild = false; + Vector3 pos; + Quaternion rot; + + if(objId > 0) + { + // real entity + EntityData eData = __instance.entityPool[objId]; + pos = eData.pos; + rot = eData.rot; + } + else if(-objId > 0) + { + // blueprint build preview + PrebuildData pData = __instance.prebuildPool[-objId]; + pos = pData.pos; + rot = pData.rot; + isPrebuild = true; + } + else + { + // this should never happen + Log.Warn("Unexpected upgrade behavior! You should not see this."); + return false; + } - Multiplayer.Session.Network.SendPacket(new UpgradeEntityRequest(__instance.planetId, new Float3(eData.pos.x, eData.pos.y, eData.pos.z), new Float4(eData.rot.x, eData.rot.y, eData.rot.z, eData.rot.w), replace_item_proto.ID, Multiplayer.Session.Factories.PacketAuthor == -1 ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); + Multiplayer.Session.Network.SendPacket(new UpgradeEntityRequest(__instance.planetId, new Float3(pos.x, pos.y, pos.z), new Float4(rot.x, rot.y, rot.z, rot.w), replace_item_proto.ID, isPrebuild, Multiplayer.Session.Factories.PacketAuthor == -1 ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); } return Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Factories.IsIncomingRequest.Value; From c58179122d0a67f8e7c813ee3c2ea50f90c47dd6 Mon Sep 17 00:00:00 2001 From: Chris Yeninas <844685+PhantomGamers@users.noreply.github.com> Date: Fri, 12 Nov 2021 17:08:22 -0500 Subject: [PATCH 2/5] use prebuildCursor for prebuilds --- .../Factory/Entity/UpgradeEntityRequestProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs index 5768fc11b..ad336b3b6 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -34,7 +34,7 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection - for (int i = 1; i < planet.factory.entityCursor; i++) + for (int i = 1; i < (packet.IsPrebuild ? planet.factory.prebuildCursor : planet.factory.entityCursor); i++) { Quaternion poolRot; Vector3 poolPos; From fc160b6cf1a76fb2a8162021ec857f62fc1f8cb9 Mon Sep 17 00:00:00 2001 From: Chris Yeninas <844685+PhantomGamers@users.noreply.github.com> Date: Fri, 12 Nov 2021 18:53:16 -0500 Subject: [PATCH 3/5] cleanup --- .../Entity/UpgradeEntityRequestProcessor.cs | 52 ++++++++++--------- .../Patches/Dynamic/PlanetFactory_Patch.cs | 12 ++--- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs index ad336b3b6..e4b38b0ef 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -32,34 +32,28 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection Quaternion qRot = new Quaternion(packet.rot.x, packet.rot.y, packet.rot.z, packet.rot.w); Vector3 vPos = new Vector3(packet.pos.x, packet.pos.y, packet.pos.z); - - - for (int i = 1; i < (packet.IsPrebuild ? planet.factory.prebuildCursor : planet.factory.entityCursor); i++) + if (packet.IsPrebuild) { - Quaternion poolRot; - Vector3 poolPos; - - if (packet.IsPrebuild) + for (int i = 1; i < planet.factory.prebuildCursor; i++) { - poolRot = planet.factory.prebuildPool[i].rot; - poolPos = planet.factory.prebuildPool[i].pos; + PrebuildData pbData = planet.factory.prebuildPool[i]; + if (pbData.pos == vPos && pbData.rot == qRot) + { + DoUpgrade(planet, -i, itemProto); + break; + } } - else + } + else + { + for (int i = 1; i < planet.factory.entityCursor; i++) { - poolRot = planet.factory.entityPool[i].rot; - poolPos = planet.factory.entityPool[i].pos; - } - - if (poolPos == vPos && poolRot == qRot) - { - // setting specifyPlanet here to avoid accessing a null object (see GPUInstancingManager activePlanet getter) - PlanetData pData = GameMain.gpuiManager.specifyPlanet; - - GameMain.gpuiManager.specifyPlanet = GameMain.galaxy.PlanetById(packet.PlanetId); - planet.factory.UpgradeFinally(GameMain.mainPlayer, packet.IsPrebuild ? -i : i, itemProto); - GameMain.gpuiManager.specifyPlanet = pData; - - break; + EntityData pbData = planet.factory.entityPool[i]; + if (pbData.pos == vPos && pbData.rot == qRot) + { + DoUpgrade(planet, i, itemProto); + break; + } } } @@ -67,5 +61,15 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE; } } + + private static void DoUpgrade(PlanetData planet, int objId, ItemProto itemProto) + { + // setting specifyPlanet here to avoid accessing a null object (see GPUInstancingManager activePlanet getter) + PlanetData pData = GameMain.gpuiManager.specifyPlanet; + + GameMain.gpuiManager.specifyPlanet = planet; + planet.factory.UpgradeFinally(GameMain.mainPlayer, objId, itemProto); + GameMain.gpuiManager.specifyPlanet = pData; + } } } diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs index 04f76a5db..09600edd5 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs @@ -72,7 +72,7 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player return true; } - if(objId == 0 || replace_item_proto == null) + if (objId == 0 || replace_item_proto == null) { return false; } @@ -83,14 +83,14 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player Vector3 pos; Quaternion rot; - if(objId > 0) + if (objId > 0) { // real entity EntityData eData = __instance.entityPool[objId]; pos = eData.pos; rot = eData.rot; } - else if(-objId > 0) + else { // blueprint build preview PrebuildData pData = __instance.prebuildPool[-objId]; @@ -98,12 +98,6 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player rot = pData.rot; isPrebuild = true; } - else - { - // this should never happen - Log.Warn("Unexpected upgrade behavior! You should not see this."); - return false; - } Multiplayer.Session.Network.SendPacket(new UpgradeEntityRequest(__instance.planetId, new Float3(pos.x, pos.y, pos.z), new Float4(rot.x, rot.y, rot.z, rot.w), replace_item_proto.ID, isPrebuild, Multiplayer.Session.Factories.PacketAuthor == -1 ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); } From e670937cf4dc559000fad52acf73cf25940dc91f Mon Sep 17 00:00:00 2001 From: Chris Yeninas <844685+PhantomGamers@users.noreply.github.com> Date: Fri, 12 Nov 2021 18:56:33 -0500 Subject: [PATCH 4/5] correct var name --- .../Factory/Entity/UpgradeEntityRequestProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs index e4b38b0ef..08c85de8f 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -48,8 +48,8 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection { for (int i = 1; i < planet.factory.entityCursor; i++) { - EntityData pbData = planet.factory.entityPool[i]; - if (pbData.pos == vPos && pbData.rot == qRot) + EntityData eData = planet.factory.entityPool[i]; + if (eData.pos == vPos && eData.rot == qRot) { DoUpgrade(planet, i, itemProto); break; From 234d7814505a73a38fe2793c657c9a7715d08c74 Mon Sep 17 00:00:00 2001 From: Chris Yeninas <844685+PhantomGamers@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:06:19 -0500 Subject: [PATCH 5/5] 0.7.3 --- CHANGELOG.md | 5 +++++ version.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4cfca745..c80c15f69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +0.7.3: + +- @PhantomGamers: Fixed error when upgrading blueprint previews. +- @sp00ktober: Added hotfix to prevent error caused by ILS ships + 0.7.2: - @sp00ktober: Fixed issue where the host would render buildings placed by players on other planets on his current planet. diff --git a/version.json b/version.json index 6fd1f442e..4d84aa200 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.7.2", + "version": "0.7.3", "assemblyVersion": { "precision": "build" },