1212using Sandbox . ModAPI ;
1313using Torch . Commands ;
1414using Torch . Commands . Permissions ;
15+ using Torch . Utils ;
1516using VRage . Collections ;
1617using VRage . Game . Entity ;
1718using VRage . Game . ModAPI ;
@@ -25,6 +26,21 @@ namespace Essentials
2526 [ Category ( "entities" ) ]
2627 public class EntityModule : CommandModule
2728 {
29+ #pragma warning disable 649
30+ [ ReflectedGetter ( Name = "m_clientStates" ) ]
31+ private static Func < MyReplicationServer , IDictionary > _clientStates ;
32+
33+ private const string CLIENT_DATA_TYPE_NAME = "VRage.Network.MyReplicationServer+ClientData, VRage" ;
34+ [ ReflectedGetter ( TypeName = CLIENT_DATA_TYPE_NAME , Name = "Replicables" ) ]
35+ private static Func < object , MyConcurrentDictionary < IMyReplicable , MyReplicableClientData > > _replicables ;
36+
37+ [ ReflectedMethod ( Name = "RemoveForClient" , OverrideTypeNames = new [ ] { null , null , CLIENT_DATA_TYPE_NAME , null } ) ]
38+ private static Action < MyReplicationServer , IMyReplicable , Endpoint , object , bool > _removeForClient ;
39+
40+ [ ReflectedMethod ( Name = "ForceReplicable" ) ]
41+ private static Action < MyReplicationServer , IMyReplicable , Endpoint > _forceReplicable ;
42+ #pragma warning restore 649
43+
2844 [ Command ( "refresh" , "Resyncs all entities for the player running the command." ) ]
2945 [ Permission ( MyPromoteLevel . None ) ]
3046 public void Refresh ( )
@@ -34,7 +50,7 @@ public void Refresh()
3450
3551 var playerEndpoint = new Endpoint ( Context . Player . SteamUserId , 0 ) ;
3652 var replicationServer = ( MyReplicationServer ) MyMultiplayer . ReplicationLayer ;
37- var clientDataDict = typeof ( MyReplicationServer ) . GetField ( "m_clientStates" , BindingFlags . Instance | BindingFlags . NonPublic ) ? . GetValue ( replicationServer ) as IDictionary ;
53+ var clientDataDict = _clientStates . Invoke ( replicationServer ) ;
3854 object clientData ;
3955 try
4056 {
@@ -45,18 +61,16 @@ public void Refresh()
4561 return ;
4662 }
4763
48- var clientReplicables = clientData . GetType ( ) . GetField ( "Replicables" ) . GetValue ( clientData ) as MyConcurrentDictionary < IMyReplicable , MyReplicableClientData > ;
49- var removeForClientMethod = typeof ( MyReplicationServer ) . GetMethod ( "RemoveForClient" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
50- var forceReplicableMethod = typeof ( MyReplicationServer ) . GetMethod ( "ForceReplicable" , BindingFlags . Instance | BindingFlags . NonPublic , null , new [ ] { typeof ( IMyReplicable ) , typeof ( Endpoint ) } , null ) ;
64+ var clientReplicables = _replicables . Invoke ( clientData ) ;
5165
5266 var replicableList = new List < IMyReplicable > ( clientReplicables . Count ) ;
5367 foreach ( var pair in clientReplicables )
5468 replicableList . Add ( pair . Key ) ;
5569
5670 foreach ( var replicable in replicableList )
5771 {
58- removeForClientMethod . Invoke ( replicationServer , new object [ ] { replicable , playerEndpoint , clientData , true } ) ;
59- forceReplicableMethod . Invoke ( replicationServer , new object [ ] { replicable , playerEndpoint } ) ;
72+ _removeForClient . Invoke ( replicationServer , replicable , playerEndpoint , clientData , true ) ;
73+ _forceReplicable . Invoke ( replicationServer , replicable , playerEndpoint ) ;
6074 }
6175
6276 Context . Respond ( $ "Forced replication of { replicableList . Count } entities.") ;
0 commit comments