private static IEnumerable <MethodBase> GetAllMethodsWithOverloads(string typeColonMethodname) { string[] arr = typeColonMethodname.Split(':'); if (arr.Length != 2) { throw new Exception("Not valid typeColonMethodname"); } var type = TypeByName.Get(arr[0]); if (type == null) { yield break; } var methods = type.GetMethods(AccessTools.all).Where(x => x.Name.Equals(arr[1])); foreach (var m in methods) { // check if method not generic, baseclass not generic and method from current assembly(was hook Object.GetHashCode, Equals) if (!m.IsGenericMethod && !m.ContainsGenericParameters /* && !m.DeclaringType.IsGenericType*/ && m.HasMethodBody() && m.Module == m.ReflectedType?.Module) { yield return(m); } } }
public static void ProfileMethods(string[] methodNames) { TypeByName.Initialize(); PatchHandler.StopCollectData(); int patchedCount = 0; foreach (var methodName in methodNames) { if (methodName.StartsWith("UnityEngine.")) { continue; // skip in 1.2 hooking UE submodules } //var method = AccessTools.Method(methodName); // TODO: overloaded functions foreach (var method in GetAllMethodsWithOverloads(methodName)) { if (method == null) { Logger.Add($"[ERROR] Can't patch: {methodName}"); Log.Error($"[ERROR] Can't patch: {methodName}"); continue; } if (TryAddProfiler(method)) { Logger.Add($"Patched: {method.GetMethodFullString()} asm: {method.Module.Assembly.GetName().Name}"); patchedCount++; } //else //{ // Logger.Add($"Already patched: {methodName}"); //} } } Log.Warning($"Patched methods: {patchedCount}"); TypeByName.Close(); PatchHandler.StartCollectData(); }