Skip to content

Commit

Permalink
Merge pull request #692 from AlienXAXS/headless_shield_fix
Browse files Browse the repository at this point in the history
Headless now calculates planetary shields on CPU
  • Loading branch information
starfi5h authored Jul 18, 2024
2 parents 9200136 + 1832fb0 commit 59e37e7
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions NebulaPatcher/Patches/Dynamic/Dedicated_Server_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,42 @@ public static bool UICommunicatorIndicatorOnLateUpdate_Prefix()
return false;
}

[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(PlanetATField), nameof(PlanetATField.RecalculatePhysicsShape))]
public static void RecalculatePhysicsShape_Postfix(PlanetATField __instance)
public static bool RecalculatePhysicsShape_Prefix(PlanetATField __instance)
{
// vanilla use GPU to calculate the shape of shield that is not fully covered the whole planet
// In this patch it will act as it has been fully covered to make the planet shield effective
if (!__instance.isEmpty)
// If we're the server, let's update the planet shields manually.
// This is required as checks to planetary shields fail, as there is no GPU to simulate the shields
// they become `isEmpty = true`. This causes some checks to fail such as:
// - Relays still landing on a planet when a shield is online
// - Some space to surface weaponry ignoring the shields
if (__instance.generatorCount == 0)
{
__instance.ClearPhysics();
__instance.energyMaxTarget = 0L;
}

__instance.CreatePhysics();
__instance.isSpherical = true;

/*
* This is usually computed on the GPU, No idea what math the GPU does though, so we're shoving 0.95 here.
* On my own testing this goes as low as 0.35 during initial planet shield spin up
* and when it hits 1.0 it seems to stop calling this method.
*/
__instance.energyMaxTarget = (long)(1200000000000.0 * 0.95 + 0.5);

if (__instance.energy > 0)
{
__instance.isSpherical = true;
__instance.isEmpty = false;
}

// I believe these are used in raycasting tests to see if a relay would hit a shield, so we need them.
if (__instance.colliderHotTicks > 0)
__instance.OpenColliderObject();
else
__instance.CloseColliderObject();

return false;
}
}

0 comments on commit 59e37e7

Please sign in to comment.