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+ }
0 commit comments