コード例 #1
0
 public void RegisterFromAssembly(Assembly assembly)
 {
     if (assembly == null)
     {
         return;
     }
     foreach (var type in assembly.GetTypes())
     {
         if (MyTypeTable.ShouldRegister(type))
         {
             m_typeTable.Register(type);
         }
     }
 }
コード例 #2
0
        public void RegisterFromAssembly(Assembly assembly)
        {
            if (assembly == null)
            {
                return;
            }
#if XB1 // XB1_ALLINONEASSEMBLY
            System.Diagnostics.Debug.Assert(m_registered == false);
            if (m_registered == true)
            {
                return;
            }
            m_registered = true;
            foreach (var type in MyAssembly.GetTypes())
#else // !XB1
            foreach (var type in assembly.GetTypes())
#endif // !XB1
            {
                if (MyTypeTable.ShouldRegister(type))
                {
                    m_typeTable.Register(type);
                }
            }
        }
コード例 #3
0
        public void InitNetworkIntercept()
        {
            m_typeTable = typeof(MyReplicationLayerBase).GetField("m_typeTable", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(MyMultiplayer.ReplicationLayer) as MyTypeTable;

            if (m_typeTable == null)
            {
                ApplicationLog.Error("Failed reflection for m_typeTable in NetworkIntercept!");
                return;
            }

            var info = typeof(MySyncLayer).GetField("TransportLayer", BindingFlags.NonPublic | BindingFlags.Instance);
            var transportType = info?.FieldType;
            if (transportType == null)
            {
                ApplicationLog.Error("Failed reflection for transportType in NetworkIntercept!");
                return;
            }
            object transportInstance = typeof(MySyncLayer).GetField("TransportLayer", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(MyMultiplayer.Static.SyncLayer);
            if (transportInstance == null)
            {
                ApplicationLog.Error("Failed reflection for transportInstance in NetworkIntercept!");
                return;
            }
            var handlers = transportType.GetField("m_handlers", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(transportInstance) as Dictionary<MyMessageId, Action<MyPacket>>;
            if (handlers == null)
            {
                ApplicationLog.Error("Failed reflection for m_handlers in NetworkIntercept!");
                return;
            }
            //remove Keen's network listener
            handlers.Remove(MyMessageId.RPC);
            //replace it with our own
            handlers.Add(MyMessageId.RPC, ProcessEvent);
            ApplicationLog.Info("Initialized network intercept!");
        }