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/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..08c85de8f 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -31,20 +31,29 @@ 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 (packet.IsPrebuild) { - if(ePool[i].pos == vPos && ePool[i].rot == qRot) + for (int i = 1; i < planet.factory.prebuildCursor; i++) { - // 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); - GameMain.gpuiManager.specifyPlanet = pData; - - break; + PrebuildData pbData = planet.factory.prebuildPool[i]; + if (pbData.pos == vPos && pbData.rot == qRot) + { + DoUpgrade(planet, -i, itemProto); + break; + } + } + } + else + { + for (int i = 1; i < planet.factory.entityCursor; i++) + { + EntityData eData = planet.factory.entityPool[i]; + if (eData.pos == vPos && eData.rot == qRot) + { + DoUpgrade(planet, i, itemProto); + break; + } } } @@ -52,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 c9fcab0fa..09600edd5 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs @@ -72,11 +72,34 @@ 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 + { + // blueprint build preview + PrebuildData pData = __instance.prebuildPool[-objId]; + pos = pData.pos; + rot = pData.rot; + isPrebuild = true; + } - 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; 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" },