Ejemplo n.º 1
0
        T RunMethod <S, T>(T defaultIfNotExisting, params object[] parameters)
        {
            if (container == null)
            {
                return(defaultIfNotExisting);
            }

            var methodName = typeof(S).Name.Replace("Harmony", "");
            var method     = PatchTools.GetPatchMethod <S>(container, methodName);

            if (method != null)
            {
                if (typeof(T).IsAssignableFrom(method.ReturnType))
                {
                    return((T)method.Invoke(null, Type.EmptyTypes));
                }

                var input            = (parameters ?? new object[0]).Union(new object[] { instance }).ToArray();
                var actualParameters = AccessTools.ActualParameters(method, input);
                method.Invoke(null, actualParameters);
                return(defaultIfNotExisting);
            }

            return(defaultIfNotExisting);
        }
Ejemplo n.º 2
0
        private T RunMethod <S, T>(T defaultIfNotExisting, params object[] parameters)
        {
            if (container == null)
            {
                return(defaultIfNotExisting);
            }
            var name = typeof(S).Name.Replace("Harmony", "");
            var list = new List <object>
            {
                instance
            };

            list.AddRange(parameters);
            var types       = AccessTools.GetTypes(list.ToArray());
            var patchMethod = PatchTools.GetPatchMethod <S>(container, name, types);

            if (patchMethod != null && typeof(T).IsAssignableFrom(patchMethod.ReturnType))
            {
                return((T)patchMethod.Invoke(null, list.ToArray()));
            }
            patchMethod = PatchTools.GetPatchMethod <S>(container, name, new[]
            {
                typeof(HarmonyInstance)
            });
            if (patchMethod != null && typeof(T).IsAssignableFrom(patchMethod.ReturnType))
            {
                return((T)patchMethod.Invoke(null, new object[]
                {
                    instance
                }));
            }
            patchMethod = PatchTools.GetPatchMethod <S>(container, name, Type.EmptyTypes);
            if (patchMethod == null)
            {
                return(defaultIfNotExisting);
            }
            object[] emptyTypes;
            if (typeof(T).IsAssignableFrom(patchMethod.ReturnType))
            {
                MethodBase methodBase = patchMethod;
                object     obj        = null;
                emptyTypes = Type.EmptyTypes;
                return((T)methodBase.Invoke(obj, emptyTypes));
            }

            MethodBase methodBase2 = patchMethod;
            object     obj2        = null;

            emptyTypes = Type.EmptyTypes;
            methodBase2.Invoke(obj2, emptyTypes);
            return(defaultIfNotExisting);
        }
Ejemplo n.º 3
0
        private void RunMethod <S>(params object[] parameters)
        {
            if (container == null)
            {
                return;
            }
            var name = typeof(S).Name.Replace("Harmony", "");
            var list = new List <object>
            {
                instance
            };

            list.AddRange(parameters);
            var types       = AccessTools.GetTypes(list.ToArray());
            var patchMethod = PatchTools.GetPatchMethod <S>(container, name, types);

            if (patchMethod != null)
            {
                patchMethod.Invoke(null, list.ToArray());
                return;
            }

            patchMethod = PatchTools.GetPatchMethod <S>(container, name, new[]
            {
                typeof(HarmonyInstance)
            });
            if (patchMethod != null)
            {
                patchMethod.Invoke(null, new object[]
                {
                    instance
                });
                return;
            }

            patchMethod = PatchTools.GetPatchMethod <S>(container, name, Type.EmptyTypes);
            if (patchMethod != null)
            {
                MethodBase methodBase = patchMethod;
                object     obj        = null;
                object[]   emptyTypes = Type.EmptyTypes;
                methodBase.Invoke(obj, emptyTypes);
            }
        }
Ejemplo n.º 4
0
        void RunMethod <S>(params object[] parameters)
        {
            if (container == null)
            {
                return;
            }

            var methodName = typeof(S).Name.Replace("Harmony", "");
            var method     = PatchTools.GetPatchMethod <S>(container, methodName);

            if (method != null)
            {
                var input            = (parameters ?? new object[0]).Union(new object[] { instance }).ToArray();
                var actualParameters = AccessTools.ActualParameters(method, input);
                method.Invoke(null, actualParameters);
            }

            return;
        }
Ejemplo n.º 5
0
        T RunMethod <S, T>(T defaultIfNotExisting, params object[] parameters)
        {
            if (container == null)
            {
                return(defaultIfNotExisting);
            }

            var methodName = typeof(S).Name.Replace("Harmony", "");

            var paramList = new List <object> {
                instance
            };

            paramList.AddRange(parameters);
            var paramTypes = AccessTools.GetTypes(paramList.ToArray());
            var method     = PatchTools.GetPatchMethod <S>(container, methodName, paramTypes);

            if (method != null && typeof(T).IsAssignableFrom(method.ReturnType))
            {
                return((T)method.Invoke(null, paramList.ToArray()));
            }

            method = PatchTools.GetPatchMethod <S>(container, methodName, new Type[] { typeof(HarmonyInstance) });
            if (method != null && typeof(T).IsAssignableFrom(method.ReturnType))
            {
                return((T)method.Invoke(null, new object[] { instance }));
            }

            method = PatchTools.GetPatchMethod <S>(container, methodName, Type.EmptyTypes);
            if (method != null)
            {
                if (typeof(T).IsAssignableFrom(method.ReturnType))
                {
                    return((T)method.Invoke(null, Type.EmptyTypes));
                }

                method.Invoke(null, Type.EmptyTypes);
                return(defaultIfNotExisting);
            }

            return(defaultIfNotExisting);
        }
Ejemplo n.º 6
0
        void RunMethod <S>(params object[] parameters)
        {
            if (container == null)
            {
                return;
            }

            var methodName = typeof(S).Name.Replace("Harmony", "");

            var paramList = new List <object> {
                instance
            };

            paramList.AddRange(parameters);
            var paramTypes = AccessTools.GetTypes(paramList.ToArray());
            var method     = PatchTools.GetPatchMethod <S>(container, methodName, paramTypes);

            if (method != null)
            {
                method.Invoke(null, paramList.ToArray());
                return;
            }

            method = PatchTools.GetPatchMethod <S>(container, methodName, new Type[] { typeof(HarmonyInstance) });
            if (method != null)
            {
                method.Invoke(null, new object[] { instance });
                return;
            }

            method = PatchTools.GetPatchMethod <S>(container, methodName, Type.EmptyTypes);
            if (method != null)
            {
                method.Invoke(null, Type.EmptyTypes);
                return;
            }
        }