示例#1
0
        private void WarnIfTargetMethodInlined(MethodBase target)
        {
            int callerCount = UnhollowerSupport.GetIl2CppMethodCallerCount(target) ?? -1;

            if (callerCount == 0 && !UnityMagicMethods.IsUnityMagicMethod(target))
            {
                string melonName = FindMelon(melon => melon.Harmony == instance);
                if (melonName == null)
                {
                    // Patching using a custom Harmony instance; try to infer the melon assembly from the container type, prefix, postfix, or transpiler.
                    Assembly melonAssembly = container?.Assembly ?? prefix?.declaringType?.Assembly ?? postfix?.declaringType?.Assembly ?? transpiler?.declaringType?.Assembly;
                    if (melonAssembly != null)
                    {
                        melonName = FindMelon(melon => melon.Assembly == melonAssembly);
                    }
                }
                MelonLogger.ManualWarning(melonName, $"Harmony: Method {target.FullDescription()} does not appear to get called directly from anywhere, " +
                                          "suggesting it may have been inlined and your patch may not be called.");
            }
        }
示例#2
0
        private void WarnIfOriginalMethodIsInlined(MelonLogger.Instance loggerInstance)
        {
            int callerCount = Main.unhollower.GetIl2CppMethodCallerCount(Original) ?? -1;

            if (callerCount > 0 ||
                UnityMagicMethods.IsUnityMagicMethod(Original))
            {
                return;
            }
            string txt = $"Harmony: Method {Original.FullDescription()} does not appear to get called directly from anywhere, " +
                         "suggesting it may have been inlined and your patch may not be called.";

            if (loggerInstance != null)
            {
                loggerInstance.Warning(txt);
            }
            else
            {
                MelonLogger.Warning(txt);
            }
        }