Skip to content

Commit 6dd6917

Browse files
committed
Fix spawning in safezone (TEMP)
1 parent ec67e13 commit 6dd6917

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Torch.Managers.PatchManager;
2+
using System.Reflection;
3+
using NLog;
4+
using Sandbox.Game.Entities;
5+
using Sandbox.Game.World;
6+
using SpaceEngineers.Game.Entities.Blocks;
7+
using VRage.Game;
8+
using VRage.Game.Components;
9+
using VRageMath;
10+
11+
namespace Torch.Patches
12+
{
13+
[PatchShim]
14+
public static class MyRespawnComponentPatch
15+
{
16+
public static Logger _log = LogManager.GetCurrentClassLogger();
17+
public static void Patch(PatchContext ctx)
18+
{
19+
var target = typeof(MyRespawnComponent).GetMethod("CanPlayerSpawn", BindingFlags.Instance | BindingFlags.Public);
20+
var patch = typeof(MyRespawnComponentPatch).GetMethod(nameof(PrefixCanPlayerSpawn), BindingFlags.Static | BindingFlags.Public);
21+
22+
ctx.GetPattern(target).Prefixes.Add(patch);
23+
_log.Info("Patching MyRespawnComponent.CanPlayerSpawn");
24+
}
25+
26+
public static bool PrefixCanPlayerSpawn(MyRespawnComponent __instance, long playerId, bool acceptPublicRespawn, ref bool __result)
27+
{
28+
var block = __instance.Entity;
29+
if(block.HasPlayerAccess(playerId))
30+
{
31+
var idModule = block.IDModule;
32+
var relation = MyIDModule.GetRelationPlayerBlock(idModule.Owner, playerId, idModule.ShareMode, defaultShareWithAllRelations: MyRelationsBetweenPlayerAndBlock.Enemies);
33+
if(relation == MyRelationsBetweenPlayerAndBlock.Owner || relation == MyRelationsBetweenPlayerAndBlock.FactionShare)
34+
{
35+
__result = true;
36+
return false;
37+
}
38+
}
39+
40+
if(acceptPublicRespawn)
41+
{
42+
var medBay = block as MyMedicalRoom;
43+
if(medBay != null && medBay.SetFactionToSpawnee)
44+
{
45+
__result = true;
46+
return false;
47+
}
48+
}
49+
__result = false;
50+
return false;
51+
}
52+
}
53+
}

‎Torch/Torch.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
<Compile Include="Patches\KeenLogPatch.cs" />
248248
<Compile Include="Patches\MessageSizeLimitPatch.cs" />
249249
<Compile Include="Patches\ModsDownloadingPatch.cs" />
250+
<Compile Include="Patches\MyRespawnComponentPatch.cs" />
250251
<Compile Include="Patches\PhysicsMemoryPatch.cs" />
251252
<Compile Include="Patches\SessionDownloadPatch.cs" />
252253
<Compile Include="Patches\TorchAsyncSaving.cs" />

0 commit comments

Comments
 (0)