Skip to content

Commit

Permalink
Merge pull request #468 from sp00ktober/master
Browse files Browse the repository at this point in the history
fix for #467
  • Loading branch information
sp00ktober authored Oct 30, 2021
2 parents a86d9c0 + 3792a22 commit 6f5b056
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

0.7.2:

- @sp00ktober: Fixed issue where the host would render buildings placed by players on other planets on his current planet.

0.7.1:

- @starfi5h: Fixed research desync issues
Expand Down
34 changes: 2 additions & 32 deletions NebulaPatcher/Patches/Dynamic/GPUInstancingManager_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,15 @@

namespace NebulaPatcher.Patches.Dynamic
{
// This is part of the weird planet movement fix
// as we delay setting localPlanet and planetId we need to be able to load FactoryData without them beeing set
// LoadingPlanetFactoryMain() -> factoryModel.gpuiManager.AddModel -> VegeRenderer::AddInst() -> base.manager.activeFactory -> GPUInstancingManager::get_activeFactory() -> get_activePlanet()
// which accesses GameMain.localPlanet which is null in that case which causes a NullReferenceException
// we need to return the right PlanetData in that case, luckily we make use of PlanetData.factoryLoading while loading the factory
[HarmonyPatch(typeof(GPUInstancingManager))]
internal class GPUInstancingManager_Patch
{
[HarmonyPrefix]
[HarmonyPatch(nameof(GPUInstancingManager.activePlanet), MethodType.Getter)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static bool get_activePlanet_Prefix(GPUInstancingManager __instance, ref PlanetData __result)
{
if (!Multiplayer.IsActive)
{
return true;
}

__result = __instance.specifyPlanet ?? GameMain.localPlanet;
if (__result == null && GameMain.localStar != null)
{
foreach (PlanetData p in GameMain.galaxy.StarById(GameMain.localStar.id).planets)
{
if (p.factoryLoading)
{
__result = p;
break;
}
}
}
return false;
}

[HarmonyPrefix]
[HarmonyPatch(nameof(GPUInstancingManager.AddModel))]
public static bool AddModel_Prefix(GPUInstancingManager __instance, ref int __result)
{
//Do not add model to the GPU queue if player is not on the same planet as building that was build
if (Multiplayer.IsActive && Multiplayer.Session.Factories.EventFactory != null && Multiplayer.Session.Factories.EventFactory.planet != __instance.activePlanet)
if (Multiplayer.IsActive && Multiplayer.Session.Factories.EventFactory != null && Multiplayer.Session.Factories.EventFactory.planet != GameMain.localPlanet)
{
__result = 0;
return false;
Expand All @@ -54,7 +24,7 @@ public static bool AddModel_Prefix(GPUInstancingManager __instance, ref int __re
public static bool AddPrebuildModel_Prefix(GPUInstancingManager __instance, ref int __result)
{
//Do not add model to the GPU queue if player is not on the same planet as building that was build
if (Multiplayer.IsActive && Multiplayer.Session.Factories.EventFactory != null && Multiplayer.Session.Factories.EventFactory.planet != __instance.activePlanet)
if (Multiplayer.IsActive && Multiplayer.Session.Factories.EventFactory != null && Multiplayer.Session.Factories.EventFactory.planet != GameMain.localPlanet)
{
__result = 0;
return false;
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.1",
"version": "0.7.2",
"assemblyVersion": {
"precision": "build"
},
Expand Down

0 comments on commit 6f5b056

Please sign in to comment.