Esempio n. 1
0
        public static MethodSig Read(BinaryStreamReader signatureBlobReader)
        {
            var callingConvention = (CallingConventions)signatureBlobReader.ReadByte();

            MethodSig result;

            switch (callingConvention & ~CallingConventions.HasThis & ~CallingConventions.ExplicitThis)
            {
            case CallingConventions.Default:
                result = new Default();
                break;

            case CallingConventions.C:
                result = new C();
                break;

            case CallingConventions.StdCall:
                result = new StdCall();
                break;

            case CallingConventions.FastCall:
                result = new FastCall();
                break;

            case CallingConventions.VarArg:
                result = new VarArg();
                break;

            case CallingConventions.Generic:
            {
                var typed = new Generic();
                typed.ReadDetails(signatureBlobReader);
                result = typed;
            }
            break;

            default:
                throw new BadImageFormatException("Invalid calling convention byte " + callingConvention + ".");
            }

            result.ReadParameters(signatureBlobReader);

            return(result);
        }
Esempio n. 2
0
 public void Write(T obj, NetDataWriter writer)
 {
     for (int i = 0; i < _membersCount; i++)
     {
         FastCall <T> s = _serializers[i];
         if (s.Type == CallType.Basic)
         {
             s.Write(obj, writer);
         }
         else if (s.Type == CallType.Array)
         {
             s.WriteArray(obj, writer);
         }
         else
         {
             s.WriteList(obj, writer);
         }
     }
 }
Esempio n. 3
0
 public void Read(T obj, NetDataReader reader)
 {
     for (int i = 0; i < _membersCount; i++)
     {
         FastCall <T> s = _serializers[i];
         if (s.Type == CallType.Basic)
         {
             s.Read(obj, reader);
         }
         else if (s.Type == CallType.Array)
         {
             s.ReadArray(obj, reader);
         }
         else
         {
             s.ReadList(obj, reader);
         }
     }
 }
Esempio n. 4
0
 public static void BindNative(Delegate function, String name, String prototype)
 {
     FastCall.Invoke <IntPtr>(GameAddresses.BindNative, Utility.FunctionAsPtr(function), Memory.StringAsPtr(name), Memory.StringAsPtr(prototype));
 }
Esempio n. 5
0
 public static void BindNative(IntPtr function, String name, String prototype)
 {
     FastCall.Invoke <IntPtr>(GameAddresses.BindNative, function, Memory.StringAsPtr(name), Memory.StringAsPtr(prototype));
 }
Esempio n. 6
0
 /// <summary>
 /// Takes a pointer to a char* and returns a RCString reference.
 /// </summary>
 /// <param name="ansiStringPtr">The char* to convert.</param>
 /// <returns>The JassStringIndex</returns>
 public static Int32 StringToJassStringIndex(String str)
 {
     return(FastCall.Invoke <Int32>(GameAddresses.StringToJassStringIndex, Memory.StringAsPtr(str)));
 }
Esempio n. 7
0
 /// <summary>
 /// Gets a item from a item jass handle.
 /// </summary>
 /// <param name="itemJassHandle">The item jass handle.</param>
 /// <returns>The item.</returns>
 public static CItemPtr GetItemFromHandle(JassItem item)
 {
     return(FastCall.Invoke <CItemPtr>(GameAddresses.GetItemFromHandle, item));
 }
 /// <summary>
 /// Prepares method with specified signature for fast execution in AOT compiled environment.
 /// </summary>
 /// <typeparam name="InstanceT">Type of instance which method belongs.</typeparam>
 /// <typeparam name="ResultT">Method's return type.</typeparam>
 public static void RegisterForFastCall <InstanceT, ResultT>()
 {
     FastCall.RegisterInstanceMethod <InstanceT, ResultT>();
 }
Esempio n. 9
0
 public static AbilDataCacheNodePtr GetAbilDataCacheNodeFromId(ObjectIdL id)
 {
     return(FastCall.Invoke <AbilDataCacheNodePtr>(GameAddresses.GetAbilDataCacheNodeFromId, id));
 }
Esempio n. 10
0
 public static unsafe IntPtr sub_6F08AE90(int *a1)
 {
     return(FastCall.Invoke <IntPtr>(GameAddresses.sub_6F08AE90, new IntPtr((void *)a1)));
 }
Esempio n. 11
0
        private ClassInfo <T> RegisterInternal <T>()
        {
            if (ClassInfo <T> .Instance != null)
            {
                return(ClassInfo <T> .Instance);
            }

            Type t = typeof(T);

            PropertyInfo[] props = t.GetProperties(
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty);
            List <FastCall <T> > serializers = new List <FastCall <T> >();

            for (int i = 0; i < props.Length; i++)
            {
                PropertyInfo property     = props[i];
                Type         propertyType = property.PropertyType;

                Type     elementType = propertyType.IsArray ? propertyType.GetElementType() : propertyType;
                CallType callType    = propertyType.IsArray ? CallType.Array : CallType.Basic;

                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    elementType = propertyType.GetGenericArguments()[0];
                    callType    = CallType.List;
                }

                // Note from Cod: Required to get it to build
                // TODO: Fix this

                /*if (Attribute.IsDefined(property, typeof(IgnoreDataMemberAttribute)))
                 *  continue;*/

                MethodInfo getMethod = property.GetGetMethod();
                MethodInfo setMethod = property.GetSetMethod();
                if (getMethod == null || setMethod == null)
                {
                    continue;
                }

                FastCall <T> serialzer = null;
                if (propertyType.IsEnum)
                {
                    Type underlyingType = Enum.GetUnderlyingType(propertyType);
                    if (underlyingType == typeof(byte))
                    {
                        serialzer = new EnumByteSerializer <T>(property, propertyType);
                    }
                    else if (underlyingType == typeof(int))
                    {
                        serialzer = new EnumIntSerializer <T>(property, propertyType);
                    }
                    else
                    {
                        throw new InvalidTypeException("Not supported enum underlying type: " + underlyingType.Name);
                    }
                }
                else if (elementType == typeof(string))
                {
                    serialzer = new StringSerializer <T>(_maxStringLength);
                }
                else if (elementType == typeof(bool))
                {
                    serialzer = new BoolSerializer <T>();
                }
                else if (elementType == typeof(byte))
                {
                    serialzer = new ByteSerializer <T>();
                }
                else if (elementType == typeof(sbyte))
                {
                    serialzer = new SByteSerializer <T>();
                }
                else if (elementType == typeof(short))
                {
                    serialzer = new ShortSerializer <T>();
                }
                else if (elementType == typeof(ushort))
                {
                    serialzer = new UShortSerializer <T>();
                }
                else if (elementType == typeof(int))
                {
                    serialzer = new IntSerializer <T>();
                }
                else if (elementType == typeof(uint))
                {
                    serialzer = new UIntSerializer <T>();
                }
                else if (elementType == typeof(long))
                {
                    serialzer = new LongSerializer <T>();
                }
                else if (elementType == typeof(ulong))
                {
                    serialzer = new ULongSerializer <T>();
                }
                else if (elementType == typeof(float))
                {
                    serialzer = new FloatSerializer <T>();
                }
                else if (elementType == typeof(double))
                {
                    serialzer = new DoubleSerializer <T>();
                }
                else if (elementType == typeof(char))
                {
                    serialzer = new CharSerializer <T>();
                }
                else if (elementType == typeof(IPEndPoint))
                {
                    serialzer = new IPEndPointSerializer <T>();
                }
                else
                {
                    _registeredTypes.TryGetValue(elementType, out CustomType customType);
                    if (customType != null)
                    {
                        serialzer = customType.Get <T>();
                    }
                }

                if (serialzer != null)
                {
                    serialzer.Init(getMethod, setMethod, callType);
                    serializers.Add(serialzer);
                }
                else
                {
                    throw new InvalidTypeException("Unknown property type: " + propertyType.FullName);
                }
            }
            ClassInfo <T> .Instance = new ClassInfo <T>(serializers);
            return(ClassInfo <T> .Instance);
        }
Esempio n. 12
0
 public static CUnitInternal *FromHandle(IntPtr handle)
 {
     return(FastCall.Invoke <CUnit>(GameAddresses.GetUnitFromHandle, handle).AsUnsafe());
 }
Esempio n. 13
0
 public static CUnit FromHandle(JassUnit unit)
 {
     return(FastCall.Invoke <CUnit>(GameAddresses.GetUnitFromHandle, unit));
 }
Esempio n. 14
0
 public static CUnitInternal *FromHandle(JassUnit unit)
 {
     return(FastCall.Invoke <CUnit>(GameAddresses.GetUnitFromHandle, unit).AsUnsafe());
 }
Esempio n. 15
0
 public static String JassStringHandleToString(IntPtr jassStringHandle)
 {
     return(Memory.PtrAsString(FastCall.Invoke <IntPtr>(GameAddresses.JassStringHandleToString, jassStringHandle)));
 }
Esempio n. 16
0
 public static CUnit FromHandle(IntPtr handle)
 {
     return(FastCall.Invoke <CUnit>(GameAddresses.GetUnitFromHandle, handle));
 }
Esempio n. 17
0
 public static IntPtr sub_6F4786B0(Int32 *a1)
 {
     return(FastCall.Invoke <IntPtr>(GameAddresses.sub_6F4786B0, new IntPtr(a1)));
 }
Esempio n. 18
0
        //public static CTriggerWar3Ptr GetTriggerFromHandle(IntPtr trigger)
        //{
        //    return FastCall.Invoke<CTriggerWar3Ptr>(GameAddresses.GetTriggerFromHandle, (object)trigger);
        //}

        //public static CDestructablePtr GetDestructableFromHandle(IntPtr destructable)
        //{
        //    return FastCall.Invoke<CDestructablePtr>(GameAddresses.GetDestructableFromHandle, (object)destructable);
        //}

        //public static CItemPtr GetItemFromHandle(IntPtr item)
        //{
        //    return FastCall.Invoke<CItemPtr>(GameAddresses.GetItemFromHandle, (object)item);
        //}

        public static int StringToJassStringIndex(string str)
        {
            return(FastCall.Invoke <int>(GameAddresses.StringToJassStringIndex, (object)Memory.StringAsPtr(str)));
        }
Esempio n. 19
0
 /// <summary>
 /// Gets a trigger from a trigger jass handle.
 /// </summary>
 /// <param name="destructableHandle">The trigger jass handle.</param>
 /// <returns>The trigger.</returns>
 public static CTriggerWar3Ptr GetTriggerFromHandle(IntPtr trigger)
 {
     return(FastCall.Invoke <CTriggerWar3Ptr>(GameAddresses.GetTriggerFromHandle, trigger));
 }
Esempio n. 20
0
 /// <summary>
 /// Gets a destructable from a destructable jass handle.
 /// </summary>
 /// <param name="destructableJassHandle">The destructable jass handle.</param>
 /// <returns>The destructable.</returns>
 public static CDestructablePtr GetDestructableFromHandle(JassDestructable destructable)
 {
     return(FastCall.Invoke <CDestructablePtr>(GameAddresses.GetDestructableFromHandle, destructable));
 }
        private ClassInfo <T> RegisterInternal <T>()
        {
            if (ClassInfo <T> .Instance != null)
            {
                return(ClassInfo <T> .Instance);
            }

            var t     = typeof(T);
            var props = t.GetProperties(
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty);
            var serializers = new List <FastCall <T> >();

            for (var i = 0; i < props.Length; i++)
            {
                var property     = props[i];
                var propertyType = property.PropertyType;

                var elementType = propertyType.IsArray ? propertyType.GetElementType() : propertyType;
                var callType    = propertyType.IsArray ? CallType.Array : CallType.Basic;

                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    elementType = propertyType.GetGenericArguments()[0];
                    callType    = CallType.List;
                }

                var getMethod = property.GetGetMethod();
                var setMethod = property.GetSetMethod();
                if (getMethod == null || setMethod == null)
                {
                    continue;
                }

                FastCall <T> serialzer = null;
                if (propertyType.IsEnum)
                {
                    var underlyingType = Enum.GetUnderlyingType(propertyType);
                    if (underlyingType == typeof(byte))
                    {
                        serialzer = new EnumByteSerializer <T>(property, propertyType);
                    }
                    else if (underlyingType == typeof(int))
                    {
                        serialzer = new EnumIntSerializer <T>(property, propertyType);
                    }
                    else
                    {
                        throw new InvalidTypeException("Not supported enum underlying type: " + underlyingType.Name);
                    }
                }
                else if (elementType == typeof(string))
                {
                    serialzer = new StringSerializer <T>(_maxStringLength);
                }
                else if (elementType == typeof(bool))
                {
                    serialzer = new BoolSerializer <T>();
                }
                else if (elementType == typeof(byte))
                {
                    serialzer = new ByteSerializer <T>();
                }
                else if (elementType == typeof(sbyte))
                {
                    serialzer = new SByteSerializer <T>();
                }
                else if (elementType == typeof(short))
                {
                    serialzer = new ShortSerializer <T>();
                }
                else if (elementType == typeof(ushort))
                {
                    serialzer = new UShortSerializer <T>();
                }
                else if (elementType == typeof(int))
                {
                    serialzer = new IntSerializer <T>();
                }
                else if (elementType == typeof(uint))
                {
                    serialzer = new UIntSerializer <T>();
                }
                else if (elementType == typeof(long))
                {
                    serialzer = new LongSerializer <T>();
                }
                else if (elementType == typeof(ulong))
                {
                    serialzer = new ULongSerializer <T>();
                }
                else if (elementType == typeof(float))
                {
                    serialzer = new FloatSerializer <T>();
                }
                else if (elementType == typeof(double))
                {
                    serialzer = new DoubleSerializer <T>();
                }
                else if (elementType == typeof(char))
                {
                    serialzer = new CharSerializer <T>();
                }
                else if (elementType == typeof(IPEndPoint))
                {
                    serialzer = new IPEndPointSerializer <T>();
                }
                else
                {
                    CustomType customType;
                    _registeredTypes.TryGetValue(elementType, out customType);
                    if (customType != null)
                    {
                        serialzer = customType.Get <T>();
                    }
                }

                if (serialzer != null)
                {
                    serialzer.Init(getMethod, setMethod, callType);
                    serializers.Add(serialzer);
                }
                else
                {
                    throw new InvalidTypeException("Unknown property type: " + propertyType.FullName);
                }
            }

            ClassInfo <T> .Instance = new ClassInfo <T>(serializers);
            return(ClassInfo <T> .Instance);
        }
Esempio n. 22
0
        public static MethodSig Read(BinaryStreamReader signatureBlobReader)
        {
            var callingConvention = (CallingConventions)signatureBlobReader.ReadByte();

            MethodSig result;
            switch (callingConvention & ~CallingConventions.HasThis & ~CallingConventions.ExplicitThis)
            {
                case CallingConventions.Default:
                    result = new Default();
                    break;

                case CallingConventions.C:
                    result = new C();
                    break;

                case CallingConventions.StdCall:
                    result = new StdCall();
                    break;

                case CallingConventions.FastCall:
                    result = new FastCall();
                    break;

                case CallingConventions.VarArg:
                    result = new VarArg();
                    break;

                case CallingConventions.Generic:
                    {
                        var typed = new Generic();
                        typed.ReadDetails(signatureBlobReader);
                        result = typed;
                    }
                    break;

                default:
                    throw new BadImageFormatException("Invalid calling convention byte "+callingConvention+".");
            }

            result.ReadParameters(signatureBlobReader);

            return result;
        }