Move all deprecated junk to the deprecated file
This commit is contained in:
@@ -11,6 +11,7 @@ using VRage.Serialization;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public abstract class NetworkHandlerBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -18,6 +19,7 @@ namespace Torch.Managers
|
||||
/// </summary>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public abstract bool CanHandle(CallSite site);
|
||||
|
||||
/// <summary>
|
||||
@@ -29,6 +31,7 @@ namespace Torch.Managers
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="packet"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public abstract bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj, MyPacket packet);
|
||||
|
||||
/// <summary>
|
||||
@@ -38,6 +41,7 @@ namespace Torch.Managers
|
||||
/// <param name="info"></param>
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="arg1"></param>
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1>(MethodInfo info, BitStream stream, ref T1 arg1)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -55,6 +59,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -76,6 +81,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2, T3>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -101,6 +107,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2, T3, T4>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -130,6 +137,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2, T3, T4, T5>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -163,6 +171,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2, T3, T4, T5, T6>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5, ref T6 arg6)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
@@ -200,6 +209,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("The entire network intercept system is deprecated. Please use method patches instead.")]
|
||||
public void Serialize<T1, T2, T3, T4, T5, T6, T7>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5, ref T6 arg6, ref T7 arg7)
|
||||
{
|
||||
var s1 = MyFactory.GetSerializer<T1>();
|
||||
|
@@ -1,111 +1,25 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Sandbox.Engine.Multiplayer;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Utils;
|
||||
using VRage;
|
||||
using VRage.Library.Collections;
|
||||
using VRage.Network;
|
||||
using VRageMath;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
//TOOD: Make this not a manager, and instead just a static class?
|
||||
public partial class NetworkManager : Manager, INetworkManager
|
||||
{
|
||||
private static Logger _log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private const string _myTransportLayerField = "TransportLayer";
|
||||
private const string _transportHandlersField = "m_handlers";
|
||||
private readonly HashSet<INetworkHandler> _networkHandlers = new HashSet<INetworkHandler>();
|
||||
private bool _init;
|
||||
|
||||
[ReflectedGetter(Name = "m_typeTable")]
|
||||
private static Func<MyReplicationLayerBase, MyTypeTable> _typeTableGetter;
|
||||
[ReflectedMethod(Type = typeof(MyReplicationLayer), Name = "GetObjectByNetworkId")]
|
||||
private static Func<MyReplicationLayer, NetworkId, IMyNetObject> _getObjectByNetworkId;
|
||||
|
||||
public NetworkManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static bool ReflectionUnitTest(bool suppress = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var syncLayerType = typeof(MySyncLayer);
|
||||
var transportLayerField = syncLayerType.GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if (transportLayerField == null)
|
||||
throw new TypeLoadException("Could not find internal type for TransportLayer");
|
||||
|
||||
var transportLayerType = transportLayerField.FieldType;
|
||||
|
||||
if (!Reflection.HasField(transportLayerType, _transportHandlersField))
|
||||
throw new TypeLoadException("Could not find Handlers field");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (TypeLoadException ex)
|
||||
{
|
||||
_log.Error(ex);
|
||||
if (suppress)
|
||||
return false;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Attach()
|
||||
{
|
||||
if (_init)
|
||||
return;
|
||||
|
||||
_init = true;
|
||||
|
||||
if (!ReflectionUnitTest())
|
||||
throw new InvalidOperationException("Reflection unit test failed.");
|
||||
|
||||
//don't bother with nullchecks here, it was all handled in ReflectionUnitTest
|
||||
var transportType = typeof(MySyncLayer).GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance).FieldType;
|
||||
var transportInstance = typeof(MySyncLayer).GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(MyMultiplayer.Static.SyncLayer);
|
||||
var handlers = (IDictionary)transportType.GetField(_transportHandlersField, BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(transportInstance);
|
||||
var handlerTypeField = handlers.GetType().GenericTypeArguments[0].GetField("messageId"); //Should be MyTransportLayer.HandlerId
|
||||
object id = null;
|
||||
foreach (var key in handlers.Keys)
|
||||
{
|
||||
if ((MyMessageId)handlerTypeField.GetValue(key) != MyMessageId.RPC)
|
||||
continue;
|
||||
|
||||
id = key;
|
||||
break;
|
||||
}
|
||||
if (id == null)
|
||||
throw new InvalidOperationException("RPC handler not found.");
|
||||
|
||||
//remove Keen's network listener
|
||||
handlers.Remove(id);
|
||||
//replace it with our own
|
||||
handlers.Add(id, new Action<MyPacket>(OnEvent));
|
||||
|
||||
//PrintDebug();
|
||||
|
||||
_log.Debug("Initialized network intercept");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Detach()
|
||||
{
|
||||
// TODO reverse what was done in Attach
|
||||
}
|
||||
|
||||
#region Network Injection
|
||||
|
||||
private static Dictionary<MethodInfo, Delegate> _delegateCache = new Dictionary<MethodInfo, Delegate>();
|
||||
|
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sandbox.Engine.Multiplayer;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Utils;
|
||||
using VRage;
|
||||
@@ -27,6 +29,86 @@ namespace Torch.Managers
|
||||
|
||||
private static MethodInfo DispatchEventInfo => _dispatchInfo ?? (_dispatchInfo = typeof(MyReplicationLayerBase).GetMethod("DispatchEvent", BindingFlags.NonPublic | BindingFlags.Instance));
|
||||
|
||||
private const string _myTransportLayerField = "TransportLayer";
|
||||
private const string _transportHandlersField = "m_handlers";
|
||||
private readonly HashSet<INetworkHandler> _networkHandlers = new HashSet<INetworkHandler>();
|
||||
private bool _init;
|
||||
|
||||
[ReflectedGetter(Name = "m_typeTable")]
|
||||
private static Func<MyReplicationLayerBase, MyTypeTable> _typeTableGetter;
|
||||
[ReflectedMethod(Type = typeof(MyReplicationLayer), Name = "GetObjectByNetworkId")]
|
||||
private static Func<MyReplicationLayer, NetworkId, IMyNetObject> _getObjectByNetworkId;
|
||||
|
||||
private static bool ReflectionUnitTest(bool suppress = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var syncLayerType = typeof(MySyncLayer);
|
||||
var transportLayerField = syncLayerType.GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if (transportLayerField == null)
|
||||
throw new TypeLoadException("Could not find internal type for TransportLayer");
|
||||
|
||||
var transportLayerType = transportLayerField.FieldType;
|
||||
|
||||
if (!Reflection.HasField(transportLayerType, _transportHandlersField))
|
||||
throw new TypeLoadException("Could not find Handlers field");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (TypeLoadException ex)
|
||||
{
|
||||
_log.Error(ex);
|
||||
if (suppress)
|
||||
return false;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Attach()
|
||||
{
|
||||
if (_init)
|
||||
return;
|
||||
|
||||
_init = true;
|
||||
|
||||
if (!ReflectionUnitTest())
|
||||
throw new InvalidOperationException("Reflection unit test failed.");
|
||||
|
||||
//don't bother with nullchecks here, it was all handled in ReflectionUnitTest
|
||||
var transportType = typeof(MySyncLayer).GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance).FieldType;
|
||||
var transportInstance = typeof(MySyncLayer).GetField(_myTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(MyMultiplayer.Static.SyncLayer);
|
||||
var handlers = (IDictionary)transportType.GetField(_transportHandlersField, BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(transportInstance);
|
||||
var handlerTypeField = handlers.GetType().GenericTypeArguments[0].GetField("messageId"); //Should be MyTransportLayer.HandlerId
|
||||
object id = null;
|
||||
foreach (var key in handlers.Keys)
|
||||
{
|
||||
if ((MyMessageId)handlerTypeField.GetValue(key) != MyMessageId.RPC)
|
||||
continue;
|
||||
|
||||
id = key;
|
||||
break;
|
||||
}
|
||||
if (id == null)
|
||||
throw new InvalidOperationException("RPC handler not found.");
|
||||
|
||||
//remove Keen's network listener
|
||||
handlers.Remove(id);
|
||||
//replace it with our own
|
||||
handlers.Add(id, new Action<MyPacket>(OnEvent));
|
||||
|
||||
//PrintDebug();
|
||||
|
||||
_log.Debug("Initialized network intercept");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Detach()
|
||||
{
|
||||
// TODO reverse what was done in Attach
|
||||
}
|
||||
|
||||
#region Network Injection
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user