rename field

This commit is contained in:
vis2k 2021-08-17 17:20:28 +08:00
parent d996ef23ac
commit 49d8608b7b

View File

@ -51,31 +51,31 @@ public class WeaverTypes
public MethodReference readNetworkBehaviourGeneric; public MethodReference readNetworkBehaviourGeneric;
AssemblyDefinition currentAssembly; AssemblyDefinition assembly;
public TypeReference Import<T>() => Import(typeof(T)); public TypeReference Import<T>() => Import(typeof(T));
public TypeReference Import(Type t) => currentAssembly.MainModule.ImportReference(t); public TypeReference Import(Type t) => assembly.MainModule.ImportReference(t);
// constructor resolves the types and stores them in fields // constructor resolves the types and stores them in fields
public WeaverTypes(AssemblyDefinition currentAssembly) public WeaverTypes(AssemblyDefinition assembly)
{ {
// system types // system types
this.currentAssembly = currentAssembly; this.assembly = assembly;
TypeReference ArraySegmentType = Import(typeof(ArraySegment<>)); TypeReference ArraySegmentType = Import(typeof(ArraySegment<>));
ArraySegmentConstructorReference = Resolvers.ResolveMethod(ArraySegmentType, currentAssembly, ".ctor"); ArraySegmentConstructorReference = Resolvers.ResolveMethod(ArraySegmentType, assembly, ".ctor");
TypeReference ListType = Import(typeof(System.Collections.Generic.List<>)); TypeReference ListType = Import(typeof(System.Collections.Generic.List<>));
TypeReference NetworkServerType = Import(typeof(NetworkServer)); TypeReference NetworkServerType = Import(typeof(NetworkServer));
NetworkServerGetActive = Resolvers.ResolveMethod(NetworkServerType, currentAssembly, "get_active"); NetworkServerGetActive = Resolvers.ResolveMethod(NetworkServerType, assembly, "get_active");
NetworkServerGetLocalClientActive = Resolvers.ResolveMethod(NetworkServerType, currentAssembly, "get_localClientActive"); NetworkServerGetLocalClientActive = Resolvers.ResolveMethod(NetworkServerType, assembly, "get_localClientActive");
TypeReference NetworkClientType = Import(typeof(NetworkClient)); TypeReference NetworkClientType = Import(typeof(NetworkClient));
NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, currentAssembly, "get_active"); NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, assembly, "get_active");
TypeReference cmdDelegateReference = Import<RemoteCalls.CmdDelegate>(); TypeReference cmdDelegateReference = Import<RemoteCalls.CmdDelegate>();
CmdDelegateConstructor = Resolvers.ResolveMethod(cmdDelegateReference, currentAssembly, ".ctor"); CmdDelegateConstructor = Resolvers.ResolveMethod(cmdDelegateReference, assembly, ".ctor");
TypeReference NetworkBehaviourType = Import<NetworkBehaviour>(); TypeReference NetworkBehaviourType = Import<NetworkBehaviour>();
TypeReference RemoteCallHelperType = Import(typeof(RemoteCalls.RemoteCallHelper)); TypeReference RemoteCallHelperType = Import(typeof(RemoteCalls.RemoteCallHelper));
@ -83,56 +83,56 @@ public WeaverTypes(AssemblyDefinition currentAssembly)
TypeReference ScriptableObjectType = Import<UnityEngine.ScriptableObject>(); TypeReference ScriptableObjectType = Import<UnityEngine.ScriptableObject>();
ScriptableObjectCreateInstanceMethod = Resolvers.ResolveMethod( ScriptableObjectCreateInstanceMethod = Resolvers.ResolveMethod(
ScriptableObjectType, currentAssembly, ScriptableObjectType, assembly,
md => md.Name == "CreateInstance" && md.HasGenericParameters); md => md.Name == "CreateInstance" && md.HasGenericParameters);
NetworkBehaviourDirtyBitsReference = Resolvers.ResolveProperty(NetworkBehaviourType, currentAssembly, "syncVarDirtyBits"); NetworkBehaviourDirtyBitsReference = Resolvers.ResolveProperty(NetworkBehaviourType, assembly, "syncVarDirtyBits");
TypeReference NetworkWriterPoolType = Import(typeof(NetworkWriterPool)); TypeReference NetworkWriterPoolType = Import(typeof(NetworkWriterPool));
GetPooledWriterReference = Resolvers.ResolveMethod(NetworkWriterPoolType, currentAssembly, "GetWriter"); GetPooledWriterReference = Resolvers.ResolveMethod(NetworkWriterPoolType, assembly, "GetWriter");
RecycleWriterReference = Resolvers.ResolveMethod(NetworkWriterPoolType, currentAssembly, "Recycle"); RecycleWriterReference = Resolvers.ResolveMethod(NetworkWriterPoolType, assembly, "Recycle");
ReadyConnectionReference = Resolvers.ResolveMethod(NetworkClientType, currentAssembly, "get_readyConnection"); ReadyConnectionReference = Resolvers.ResolveMethod(NetworkClientType, assembly, "get_readyConnection");
syncVarEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SyncVarEqual"); syncVarEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SyncVarEqual");
syncVarNetworkIdentityEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SyncVarNetworkIdentityEqual"); syncVarNetworkIdentityEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SyncVarNetworkIdentityEqual");
syncVarGameObjectEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SyncVarGameObjectEqual"); syncVarGameObjectEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SyncVarGameObjectEqual");
setSyncVarReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SetSyncVar"); setSyncVarReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SetSyncVar");
setSyncVarHookGuard = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "setSyncVarHookGuard"); setSyncVarHookGuard = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "setSyncVarHookGuard");
getSyncVarHookGuard = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "getSyncVarHookGuard"); getSyncVarHookGuard = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "getSyncVarHookGuard");
setSyncVarGameObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SetSyncVarGameObject"); setSyncVarGameObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SetSyncVarGameObject");
getSyncVarGameObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "GetSyncVarGameObject"); getSyncVarGameObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "GetSyncVarGameObject");
setSyncVarNetworkIdentityReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SetSyncVarNetworkIdentity"); setSyncVarNetworkIdentityReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SetSyncVarNetworkIdentity");
getSyncVarNetworkIdentityReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "GetSyncVarNetworkIdentity"); getSyncVarNetworkIdentityReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "GetSyncVarNetworkIdentity");
syncVarNetworkBehaviourEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SyncVarNetworkBehaviourEqual"); syncVarNetworkBehaviourEqualReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SyncVarNetworkBehaviourEqual");
setSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SetSyncVarNetworkBehaviour"); setSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SetSyncVarNetworkBehaviour");
getSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "GetSyncVarNetworkBehaviour"); getSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "GetSyncVarNetworkBehaviour");
registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterCommandDelegate"); registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, assembly, "RegisterCommandDelegate");
registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterRpcDelegate"); registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, assembly, "RegisterRpcDelegate");
TypeReference unityDebug = Import(typeof(UnityEngine.Debug)); TypeReference unityDebug = Import(typeof(UnityEngine.Debug));
// these have multiple methods with same name, so need to check parameters too // these have multiple methods with same name, so need to check parameters too
logErrorReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, md => logErrorReference = Resolvers.ResolveMethod(unityDebug, assembly, md =>
md.Name == "LogError" && md.Name == "LogError" &&
md.Parameters.Count == 1 && md.Parameters.Count == 1 &&
md.Parameters[0].ParameterType.FullName == typeof(object).FullName); md.Parameters[0].ParameterType.FullName == typeof(object).FullName);
logWarningReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, md => logWarningReference = Resolvers.ResolveMethod(unityDebug, assembly, md =>
md.Name == "LogWarning" && md.Name == "LogWarning" &&
md.Parameters.Count == 1 && md.Parameters.Count == 1 &&
md.Parameters[0].ParameterType.FullName == typeof(object).FullName); md.Parameters[0].ParameterType.FullName == typeof(object).FullName);
TypeReference typeType = Import(typeof(Type)); TypeReference typeType = Import(typeof(Type));
getTypeFromHandleReference = Resolvers.ResolveMethod(typeType, currentAssembly, "GetTypeFromHandle"); getTypeFromHandleReference = Resolvers.ResolveMethod(typeType, assembly, "GetTypeFromHandle");
sendCommandInternal = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SendCommandInternal"); sendCommandInternal = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SendCommandInternal");
sendRpcInternal = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SendRPCInternal"); sendRpcInternal = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SendRPCInternal");
sendTargetRpcInternal = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "SendTargetRPCInternal"); sendTargetRpcInternal = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "SendTargetRPCInternal");
InitSyncObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, currentAssembly, "InitSyncObject"); InitSyncObjectReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, "InitSyncObject");
TypeReference readerExtensions = Import(typeof(NetworkReaderExtensions)); TypeReference readerExtensions = Import(typeof(NetworkReaderExtensions));
readNetworkBehaviourGeneric = Resolvers.ResolveMethod(readerExtensions, currentAssembly, (md => readNetworkBehaviourGeneric = Resolvers.ResolveMethod(readerExtensions, assembly, (md =>
{ {
return md.Name == nameof(NetworkReaderExtensions.ReadNetworkBehaviour) && return md.Name == nameof(NetworkReaderExtensions.ReadNetworkBehaviour) &&
md.HasGenericParameters; md.HasGenericParameters;