fix(weaver): Weaver finds correct log methods for unity 2020.2 (#2497)

Unity has added new private LogWarning methods in 2020.2 which causes weaver to find the wrong method. Checking the parameters as we as the name will find the correct method.

fixes: https://github.com/vis2k/Mirror/issues/2366
This commit is contained in:
James Frowen 2020-12-17 03:43:37 +00:00 committed by GitHub
parent 613851ff3c
commit 50a214613f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,9 +125,22 @@ public static void SetupTargetTypes(AssemblyDefinition currentAssembly)
registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterCommandDelegate"); registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterCommandDelegate");
registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterRpcDelegate"); registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterRpcDelegate");
TypeReference unityDebug = Import(typeof(UnityEngine.Debug)); TypeReference unityDebug = Import(typeof(UnityEngine.Debug));
logErrorReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, "LogError"); // these have multiple methods with same name, so need to check parameters too
logWarningReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, "LogWarning"); logErrorReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, (md) =>
{
return md.Name == "LogError" &&
md.Parameters.Count == 1 &&
md.Parameters[0].ParameterType.FullName == typeof(object).FullName;
});
logWarningReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, (md) =>
{
return md.Name == "LogWarning" &&
md.Parameters.Count == 1 &&
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, currentAssembly, "GetTypeFromHandle");