コード例 #1
0
        /// <summary>Get a Harmony patch method on the current patcher instance.</summary>
        /// <param name="name">The method name.</param>
        /// <param name="priority">The patch priority to apply, usually specified using Harmony's <see cref="Priority"/> enum, or <c>null</c> to keep the default value.</param>
        /// <param name="before">The Harmony patch ID before which this patch should be applied, if any.</param>
        protected HarmonyMethod GetHarmonyMethod(string name, int?priority = null, string before = null)
        {
            var method = new HarmonyMethod(
                AccessTools.Method(this.GetType(), name)
                ?? throw new InvalidOperationException($"Can't find patcher method {PatchHelper.GetMethodString(this.GetType(), name)}.")
                );

            if (priority.HasValue)
            {
                method.priority = priority.Value;
            }

            if (before != null)
            {
                method.before = new[] { before }
            }
            ;

            return(method);
        }
    }
コード例 #2
0
 /// <summary>Get a method and assert that it was found.</summary>
 /// <typeparam name="TTarget">The type containing the method.</typeparam>
 /// <param name="name">The method name.</param>
 /// <param name="parameters">The method parameter types, or <c>null</c> if it's not overloaded.</param>
 /// <param name="generics">The method generic types, or <c>null</c> if it's not generic.</param>
 /// <exception cref="InvalidOperationException">The type has no matching method.</exception>
 public static MethodInfo RequireMethod <TTarget>(string name, Type[] parameters = null, Type[] generics = null)
 {
     return
         (AccessTools.Method(typeof(TTarget), name, parameters, generics)
          ?? throw new InvalidOperationException($"Can't find method {PatchHelper.GetMethodString(typeof(TTarget), name, parameters, generics)} to patch."));
 }
コード例 #3
0
 /*********
 ** Public methods
 *********/
 /// <summary>Get a constructor and assert that it was found.</summary>
 /// <typeparam name="TTarget">The type containing the method.</typeparam>
 /// <param name="parameters">The method parameter types, or <c>null</c> if it's not overloaded.</param>
 /// <exception cref="InvalidOperationException">The type has no matching constructor.</exception>
 public static ConstructorInfo RequireConstructor <TTarget>(Type[] parameters = null)
 {
     return
         (AccessTools.Constructor(typeof(TTarget), parameters)
          ?? throw new InvalidOperationException($"Can't find constructor {PatchHelper.GetMethodString(typeof(TTarget), null, parameters)} to patch."));
 }
コード例 #4
0
 /// <summary>Get a method and assert that it was found.</summary>
 /// <typeparam name="TTarget">The type containing the method.</typeparam>
 /// <param name="name">The method name.</param>
 /// <param name="parameters">The method parameter types, or <c>null</c> if it's not overloaded.</param>
 /// <param name="generics">The method generic types, or <c>null</c> if it's not generic.</param>
 protected MethodInfo RequireMethod <TTarget>(string name, Type[] parameters = null, Type[] generics = null)
 {
     return(PatchHelper.RequireMethod <TTarget>(name, parameters, generics));
 }
コード例 #5
0
 /*********
 ** Protected methods
 *********/
 /// <summary>Get a method and assert that it was found.</summary>
 /// <typeparam name="TTarget">The type containing the method.</typeparam>
 /// <param name="parameters">The method parameter types, or <c>null</c> if it's not overloaded.</param>
 protected ConstructorInfo RequireConstructor <TTarget>(params Type[] parameters)
 {
     return(PatchHelper.RequireConstructor <TTarget>(parameters));
 }