コード例 #1
0
        public static T ReadChunk <T>(IntPtr h) where T : new()
        {
            byte[]   b;
            int      size;
            GCHandle pinnedArray;
            IntPtr   addr;
            T        type = new T();
            string   id;

            b = MPQ.ReadFile(h, 4);

            Array.Reverse(b);
            id = Encoding.Default.GetString(b);

            b    = MPQ.ReadFile(h, 4);
            size = BitConverter.ToInt32(b, 0);

            b = MPQ.ReadFile(h, size);

            pinnedArray = GCHandle.Alloc(b, GCHandleType.Pinned);
            addr        = pinnedArray.AddrOfPinnedObject();
            type        = (T)Marshal.PtrToStructure(addr, typeof(T));
            pinnedArray.Free();

            return(type);
        }
コード例 #2
0
        public static T Read <T>(IntPtr h) where T : new()
        {
            object ret;

            switch (Type.GetTypeCode(typeof(T)))
            {
            case TypeCode.Int32:
                ret = BitConverter.ToInt32(MPQ.ReadFile(h, 4), 0);
                break;

            case TypeCode.Int64:
                ret = BitConverter.ToInt64(MPQ.ReadFile(h, 8), 0);
                break;

            case TypeCode.Single:
                ret = BitConverter.ToSingle(MPQ.ReadFile(h, 4), 0);
                break;

            case TypeCode.Byte:
                ret = MPQ.ReadFile(h, 1)[0];
                break;

            default:
                throw new NotSupportedException(typeof(T).FullName + " is not currently supported by Read<T>");
            }
            return((T)ret);
        }
コード例 #3
0
        public static T ReadStruct <T>(IntPtr h) where T : new()
        {
            T   ret  = new T();
            int size = Marshal.SizeOf(ret);

            Byte[]   b           = MPQ.ReadFile(h, size);
            GCHandle pinnedArray = GCHandle.Alloc(b, GCHandleType.Pinned);
            IntPtr   addr        = pinnedArray.AddrOfPinnedObject();

            ret = (T)Marshal.PtrToStructure(addr, typeof(T));
            pinnedArray.Free();

            return(ret);
        }
コード例 #4
0
        public static void SkipChunk(IntPtr h)
        {
            byte[]   b;
            int      size;
            GCHandle pinnedArray;
            IntPtr   addr;
            string   id;

            b = MPQ.ReadFile(h, 4);

            Array.Reverse(b);
            id = Encoding.Default.GetString(b);

            b    = MPQ.ReadFile(h, 4);
            size = BitConverter.ToInt32(b, 0);

            b = MPQ.ReadFile(h, size);
        }