These ads disappear when you log in.

Results 1 to 1 of 1
  1. #1
    Member Pentagasm's Avatar
    Join Date
    Sep 2017
    Thanks G/R
    Trade Feedback
    0 (0%)

    Class for Dynamic Method Creation

    Hey all. I was working on my hacking library and I came across the need to create some methods using IL. Here is a class I wrote, hopefully someone finds it useful.

    The Class:
        public static class DynamicMethodFactory
            static AssemblyName assemblyName;
            static AssemblyBuilder assembly;
            static ModuleBuilder module;
            static DynamicMethodFactory()
                assemblyName = new AssemblyName("DynamicMethodFactory");
                assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                module = assembly.DefineDynamicModule($"<Module-{Guid.NewGuid()}>");
            public static T CreateDelegate<T>(Action<ILGenerator> generate) where T : class
                if (!typeof(T).IsSubclassOf(typeof(Delegate)))
                    throw new ArgumentException("T must be a delegate type.");
                var type = module.DefineType($"<Type-{Guid.NewGuid()}>");
                var methodName = $"<Method-{Guid.NewGuid()}>";
                var methodInfo = typeof(T).GetMethod("Invoke");
                var method = type.DefineMethod(methodName, MethodAttributes.Static | MethodAttributes.Public, methodInfo.ReturnType, methodInfo.GetParameters().Select(x => x.ParameterType).ToArray());
                return type.GetMethod(methodName).CreateDelegate(typeof(T)) as T;
    Possible Use:
        public static class StructHelper<T> where T : struct
            private delegate IntPtr AddressOfDelegate(ref T value);
            public static AddressOfDelegate AddressOf { get; }
            static StructHelper()
                AddressOf = DynamicMethodFactory.CreateDelegate<AddressOfDelegate>(il =>
                    il.Emit(OpCodes.Ldarg, 0);

    These ads disappear when you log in.



Similar Threads

  1. Custom classes for Glider Elite
    By azzi88 in forum World of Warcraft Bots and Programs
    Replies: 13
    Last Post: 06-04-2008, 04:12 PM
  2. reskins for all classes for both male and female
    By Corroasive in forum WoW ME Questions and Requests
    Replies: 0
    Last Post: 05-17-2008, 12:08 PM
  3. Looking for dedicated acount creation page guide
    By Bloodstain in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 03-23-2008, 04:29 PM
  4. [Request] Shaman Custom class for Mmoglider
    By lohkies in forum World of Warcraft General
    Replies: 5
    Last Post: 02-05-2008, 01:31 AM
  5. [Help] Website for TBC acc creation
    By Gadella in forum World of Warcraft Emulator Servers
    Replies: 6
    Last Post: 12-19-2007, 08:08 AM
All times are GMT -5. The time now is 08:53 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved. Digital Point modules: Sphinx-based search