Skip to content

Commit

Permalink
Merge pull request #474 from PhantomGamers/pr-upgradefixes
Browse files Browse the repository at this point in the history
fix error when upgrading blueprint previews
  • Loading branch information
PhantomGamers authored Nov 13, 2021
2 parents b455254 + 234d781 commit 557d108
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion NebulaModel/Packets/Factory/UpgradeEntityRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,45 @@ 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;
}
}
}

Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE;
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;
}
}
}
27 changes: 25 additions & 2 deletions NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down

0 comments on commit 557d108

Please sign in to comment.