From 50a214613f3e8b01c00d59f78e9abd8a46221387 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Thu, 17 Dec 2020 03:43:37 +0000 Subject: [PATCH] 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 --- Assets/Mirror/Editor/Weaver/WeaverTypes.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/WeaverTypes.cs b/Assets/Mirror/Editor/Weaver/WeaverTypes.cs index 827f343e8..6102cb9a9 100644 --- a/Assets/Mirror/Editor/Weaver/WeaverTypes.cs +++ b/Assets/Mirror/Editor/Weaver/WeaverTypes.cs @@ -125,9 +125,22 @@ public static void SetupTargetTypes(AssemblyDefinition currentAssembly) registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterCommandDelegate"); registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, currentAssembly, "RegisterRpcDelegate"); + TypeReference unityDebug = Import(typeof(UnityEngine.Debug)); - logErrorReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, "LogError"); - logWarningReference = Resolvers.ResolveMethod(unityDebug, currentAssembly, "LogWarning"); + // these have multiple methods with same name, so need to check parameters too + 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)); getTypeFromHandleReference = Resolvers.ResolveMethod(typeType, currentAssembly, "GetTypeFromHandle");