Example #1
0
        /// <summary>
        ///     Creates a new Detour.
        /// </summary>
        /// <param name="target">
        ///     The original function to detour. (This delegate should already be registered via
        ///     Magic.RegisterDelegate)
        /// </param>
        /// <param name="newTarget">The new function to be called. (This delegate should NOT be registered!)</param>
        /// <param name="name">The name of the detour.</param>
        /// <param name="ignoreAntiCheatRules"></param>
        /// <returns>
        ///     A <see cref="Detour" /> object containing the required methods to apply, remove, and call the original
        ///     function.
        /// </returns>
        public Detour Create(Delegate target, Delegate newTarget, string name, bool ignoreAntiCheatRules = false)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (newTarget == null)
            {
                throw new ArgumentNullException(nameof(newTarget));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (!target.IsUnmanagedFunctionPointer())
            {
                throw new Exception("The target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }

            if (!newTarget.IsUnmanagedFunctionPointer())
            {
                throw new Exception(
                          "The new target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }

            if (InternalItems.ContainsKey(name))
            {
                throw new ArgumentException($"The {name} detour already exists!", nameof(name));
            }

            InternalItems[name] = new Detour(target, newTarget, name, ProcessPlus, ignoreAntiCheatRules);
            return(InternalItems[name]);
        }
        /// <summary>
        ///     Creates a new Detour.
        /// </summary>
        /// <param name="target">
        ///     The original function to detour. (This delegate should already be registered via
        ///     Magic.RegisterDelegate)
        /// </param>
        /// <param name="newTarget">The new function to be called. (This delegate should NOT be registered!)</param>
        /// <param name="name">The name of the detour.</param>
        /// <returns>
        ///     A <see cref="Detour" /> object containing the required methods to apply, remove, and call the original
        ///     function.
        /// </returns>
        public Detour Create(Delegate target, Delegate newTarget, string name)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (newTarget == null)
            {
                throw new ArgumentNullException(nameof(newTarget));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (!AttributesHelper.HasUfpAttribute(target))
            {
                throw new Exception(
                          "The target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }
            if (!AttributesHelper.HasUfpAttribute(newTarget))
            {
                throw new Exception(
                          "The new target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }

            if (InternalItems.ContainsKey(name))
            {
                throw new ArgumentException($"The {name} detour already exists!", nameof(name));
            }
            InternalItems[name] = new Detour(target, newTarget, name, MemoryPlus);
            return(InternalItems[name]);
        }
Example #3
0
 /// <summary>
 ///     Creates a new <see cref="APatch" /> at the specified address.
 /// </summary>
 /// <param name="address">The address to begin the patch.</param>
 /// <param name="patchWith">The bytes to be written as the patch.</param>
 /// <param name="name">The name of the patch.</param>
 /// <returns>A patch object that exposes the required methods to apply and remove the patch.</returns>
 public APatch Create(IntPtr address, byte[] patchWith, string name)
 {
     if (InternalItems.ContainsKey(name))
     {
         return(InternalItems[name]);
     }
     InternalItems.Add(name, new APatch(address, patchWith, name, MemoryBase));
     return(InternalItems[name]);
 }