Skip to content

Commit

Permalink
Fixed Ghost asteroid issue on multiplayer servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwin99 committed Nov 9, 2024
1 parent e4501f1 commit 4181df2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SEWorldGenPlugin/Patches/MultiplayerGhostAsteroidPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HarmonyLib;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using SEWorldGenPlugin.Session;
using VRage.Game;

namespace SEWorldGenPlugin.Patches
{
/// <summary>
/// Patch class to patch the client side procedural generation on a multiplayer server.
/// If a player connects to a server, the client requests the server world settings. If the procedural density is not 0, the client will generate asteroids.
/// </summary>
public class MultiplayerGhostAsteroidPatch : HarmonyPatchBase
{
public MultiplayerGhostAsteroidPatch() : base("Multiplayer ghost asteroid fix")
{
}

public static void Postfix(bool includeEntities, bool isClientRequest, ref MyObjectBuilder_World __result)
{
if (Sync.IsServer && isClientRequest && MySettingsSession.Static.Settings.GeneratorSettings.AsteroidGenerator == ObjectBuilders.AsteroidGenerationMethod.PLUGIN)
{
__result.Checkpoint.Settings.ProceduralDensity = 0;
}
}

public override void ApplyPatch(Harmony harmony)
{
base.ApplyPatch(harmony);

var baseMethod = typeof(MySession).GetMethod("GetWorld", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
var postfix = typeof(MultiplayerGhostAsteroidPatch).GetMethod("Postfix");

harmony.Patch(baseMethod, postfix: new HarmonyMethod(postfix));
}
}
}
1 change: 1 addition & 0 deletions SEWorldGenPlugin/SEWorldGenPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="GUI\AdminMenu\SubMenus\StarSystemDesigner\MyOrbitRenderObject.cs" />
<Compile Include="Patches\CopyDirectoryPatch.cs" />
<Compile Include="Patches\MainMenuPatch.cs" />
<Compile Include="Patches\MultiplayerGhostAsteroidPatch.cs" />
<Compile Include="Patches\WorldSettingsMenuPatch.cs" />
<Compile Include="Patches\PatchAsteroidGeneration.cs" />
<Compile Include="Patches\ScenarioCustomizationPatch.cs" />
Expand Down
2 changes: 2 additions & 0 deletions SEWorldGenPlugin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ private void Patch()
worldSettingsPatch.ApplyPatch(harmony);
var scenarioCustomizationPatch = new ScenarioCustomizationPatch();
scenarioCustomizationPatch.ApplyPatch(harmony);
var ghostAsteroidServerPatch = new MultiplayerGhostAsteroidPatch();
ghostAsteroidServerPatch.ApplyPatch(harmony);
}

/// <summary>
Expand Down

0 comments on commit 4181df2

Please sign in to comment.