コード例 #1
0
ファイル: MessagePackParser.cs プロジェクト: ousttrue/Osaru
        /// <summary>
        /// Array又はMapの子要素の数を得る
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        ArraySegment <Byte> GetItemCount(out UInt32 count)
        {
            switch (FormatType)
            {
            case MsgPackType.FIX_ARRAY: count = 0; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x1: count = 1; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x2: count = 2; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x3: count = 3; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x4: count = 4; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x5: count = 5; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x6: count = 6; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x7: count = 7; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x8: count = 8; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0x9: count = 9; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xA: count = 10; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xB: count = 11; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xC: count = 12; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xD: count = 13; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xE: count = 14; return(Bytes.Advance(1));

            case MsgPackType.FIX_ARRAY_0xF: count = 15; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP: count = 0; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x1: count = 1; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x2: count = 2; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x3: count = 3; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x4: count = 4; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x5: count = 5; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x6: count = 6; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x7: count = 7; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x8: count = 8; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0x9: count = 9; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xA: count = 10; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xB: count = 11; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xC: count = 12; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xD: count = 13; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xE: count = 14; return(Bytes.Advance(1));

            case MsgPackType.FIX_MAP_0xF: count = 15; return(Bytes.Advance(1));

            case MsgPackType.ARRAY16:
            case MsgPackType.MAP16:
                count = EndianConverter.NetworkByteWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 2));

            case MsgPackType.ARRAY32:
            case MsgPackType.MAP32:
                count = EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 4));

            default:
                throw new ArgumentException("is not collection: " + FormatType);
            }
        }
コード例 #2
0
ファイル: MessagePackParser.cs プロジェクト: ousttrue/Osaru
        /// <summary>
        /// ArrayとMap以外のタイプのペイロードを得る
        /// </summary>
        /// <returns></returns>
        public ArraySegment <Byte> GetBody()
        {
            switch (FormatType)
            {
            case MsgPackType.FIX_STR: return(Bytes.Advance(1).Take(0));

            case MsgPackType.FIX_STR_0x01: return(Bytes.Advance(1).Take(1));

            case MsgPackType.FIX_STR_0x02: return(Bytes.Advance(1).Take(2));

            case MsgPackType.FIX_STR_0x03: return(Bytes.Advance(1).Take(3));

            case MsgPackType.FIX_STR_0x04: return(Bytes.Advance(1).Take(4));

            case MsgPackType.FIX_STR_0x05: return(Bytes.Advance(1).Take(5));

            case MsgPackType.FIX_STR_0x06: return(Bytes.Advance(1).Take(6));

            case MsgPackType.FIX_STR_0x07: return(Bytes.Advance(1).Take(7));

            case MsgPackType.FIX_STR_0x08: return(Bytes.Advance(1).Take(8));

            case MsgPackType.FIX_STR_0x09: return(Bytes.Advance(1).Take(9));

            case MsgPackType.FIX_STR_0x0A: return(Bytes.Advance(1).Take(10));

            case MsgPackType.FIX_STR_0x0B: return(Bytes.Advance(1).Take(11));

            case MsgPackType.FIX_STR_0x0C: return(Bytes.Advance(1).Take(12));

            case MsgPackType.FIX_STR_0x0D: return(Bytes.Advance(1).Take(13));

            case MsgPackType.FIX_STR_0x0E: return(Bytes.Advance(1).Take(14));

            case MsgPackType.FIX_STR_0x0F: return(Bytes.Advance(1).Take(15));

            case MsgPackType.FIX_STR_0x10: return(Bytes.Advance(1).Take(16));

            case MsgPackType.FIX_STR_0x11: return(Bytes.Advance(1).Take(17));

            case MsgPackType.FIX_STR_0x12: return(Bytes.Advance(1).Take(18));

            case MsgPackType.FIX_STR_0x13: return(Bytes.Advance(1).Take(19));

            case MsgPackType.FIX_STR_0x14: return(Bytes.Advance(1).Take(20));

            case MsgPackType.FIX_STR_0x15: return(Bytes.Advance(1).Take(21));

            case MsgPackType.FIX_STR_0x16: return(Bytes.Advance(1).Take(22));

            case MsgPackType.FIX_STR_0x17: return(Bytes.Advance(1).Take(23));

            case MsgPackType.FIX_STR_0x18: return(Bytes.Advance(1).Take(24));

            case MsgPackType.FIX_STR_0x19: return(Bytes.Advance(1).Take(25));

            case MsgPackType.FIX_STR_0x1A: return(Bytes.Advance(1).Take(26));

            case MsgPackType.FIX_STR_0x1B: return(Bytes.Advance(1).Take(27));

            case MsgPackType.FIX_STR_0x1C: return(Bytes.Advance(1).Take(28));

            case MsgPackType.FIX_STR_0x1D: return(Bytes.Advance(1).Take(29));

            case MsgPackType.FIX_STR_0x1E: return(Bytes.Advance(1).Take(30));

            case MsgPackType.FIX_STR_0x1F: return(Bytes.Advance(1).Take(31));

            case MsgPackType.STR8:
            case MsgPackType.BIN8:
            {
                var count = Bytes.Get(1);
                return(Bytes.Advance(1 + 1).Take(count));
            }

            case MsgPackType.STR16:
            case MsgPackType.BIN16:
            {
                var count = EndianConverter.NetworkByteWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 2).Take(count));
            }

            case MsgPackType.STR32:
            case MsgPackType.BIN32:
            {
                var count = EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 4).Take((int)count));
            }

            case MsgPackType.NIL:
            case MsgPackType.TRUE:
            case MsgPackType.FALSE:
            case MsgPackType.POSITIVE_FIXNUM:
            case MsgPackType.POSITIVE_FIXNUM_0x01:
            case MsgPackType.POSITIVE_FIXNUM_0x02:
            case MsgPackType.POSITIVE_FIXNUM_0x03:
            case MsgPackType.POSITIVE_FIXNUM_0x04:
            case MsgPackType.POSITIVE_FIXNUM_0x05:
            case MsgPackType.POSITIVE_FIXNUM_0x06:
            case MsgPackType.POSITIVE_FIXNUM_0x07:
            case MsgPackType.POSITIVE_FIXNUM_0x08:
            case MsgPackType.POSITIVE_FIXNUM_0x09:
            case MsgPackType.POSITIVE_FIXNUM_0x0A:
            case MsgPackType.POSITIVE_FIXNUM_0x0B:
            case MsgPackType.POSITIVE_FIXNUM_0x0C:
            case MsgPackType.POSITIVE_FIXNUM_0x0D:
            case MsgPackType.POSITIVE_FIXNUM_0x0E:
            case MsgPackType.POSITIVE_FIXNUM_0x0F:

            case MsgPackType.POSITIVE_FIXNUM_0x10:
            case MsgPackType.POSITIVE_FIXNUM_0x11:
            case MsgPackType.POSITIVE_FIXNUM_0x12:
            case MsgPackType.POSITIVE_FIXNUM_0x13:
            case MsgPackType.POSITIVE_FIXNUM_0x14:
            case MsgPackType.POSITIVE_FIXNUM_0x15:
            case MsgPackType.POSITIVE_FIXNUM_0x16:
            case MsgPackType.POSITIVE_FIXNUM_0x17:
            case MsgPackType.POSITIVE_FIXNUM_0x18:
            case MsgPackType.POSITIVE_FIXNUM_0x19:
            case MsgPackType.POSITIVE_FIXNUM_0x1A:
            case MsgPackType.POSITIVE_FIXNUM_0x1B:
            case MsgPackType.POSITIVE_FIXNUM_0x1C:
            case MsgPackType.POSITIVE_FIXNUM_0x1D:
            case MsgPackType.POSITIVE_FIXNUM_0x1E:
            case MsgPackType.POSITIVE_FIXNUM_0x1F:

            case MsgPackType.POSITIVE_FIXNUM_0x20:
            case MsgPackType.POSITIVE_FIXNUM_0x21:
            case MsgPackType.POSITIVE_FIXNUM_0x22:
            case MsgPackType.POSITIVE_FIXNUM_0x23:
            case MsgPackType.POSITIVE_FIXNUM_0x24:
            case MsgPackType.POSITIVE_FIXNUM_0x25:
            case MsgPackType.POSITIVE_FIXNUM_0x26:
            case MsgPackType.POSITIVE_FIXNUM_0x27:
            case MsgPackType.POSITIVE_FIXNUM_0x28:
            case MsgPackType.POSITIVE_FIXNUM_0x29:
            case MsgPackType.POSITIVE_FIXNUM_0x2A:
            case MsgPackType.POSITIVE_FIXNUM_0x2B:
            case MsgPackType.POSITIVE_FIXNUM_0x2C:
            case MsgPackType.POSITIVE_FIXNUM_0x2D:
            case MsgPackType.POSITIVE_FIXNUM_0x2E:
            case MsgPackType.POSITIVE_FIXNUM_0x2F:

            case MsgPackType.POSITIVE_FIXNUM_0x30:
            case MsgPackType.POSITIVE_FIXNUM_0x31:
            case MsgPackType.POSITIVE_FIXNUM_0x32:
            case MsgPackType.POSITIVE_FIXNUM_0x33:
            case MsgPackType.POSITIVE_FIXNUM_0x34:
            case MsgPackType.POSITIVE_FIXNUM_0x35:
            case MsgPackType.POSITIVE_FIXNUM_0x36:
            case MsgPackType.POSITIVE_FIXNUM_0x37:
            case MsgPackType.POSITIVE_FIXNUM_0x38:
            case MsgPackType.POSITIVE_FIXNUM_0x39:
            case MsgPackType.POSITIVE_FIXNUM_0x3A:
            case MsgPackType.POSITIVE_FIXNUM_0x3B:
            case MsgPackType.POSITIVE_FIXNUM_0x3C:
            case MsgPackType.POSITIVE_FIXNUM_0x3D:
            case MsgPackType.POSITIVE_FIXNUM_0x3E:
            case MsgPackType.POSITIVE_FIXNUM_0x3F:

            case MsgPackType.POSITIVE_FIXNUM_0x40:
            case MsgPackType.POSITIVE_FIXNUM_0x41:
            case MsgPackType.POSITIVE_FIXNUM_0x42:
            case MsgPackType.POSITIVE_FIXNUM_0x43:
            case MsgPackType.POSITIVE_FIXNUM_0x44:
            case MsgPackType.POSITIVE_FIXNUM_0x45:
            case MsgPackType.POSITIVE_FIXNUM_0x46:
            case MsgPackType.POSITIVE_FIXNUM_0x47:
            case MsgPackType.POSITIVE_FIXNUM_0x48:
            case MsgPackType.POSITIVE_FIXNUM_0x49:
            case MsgPackType.POSITIVE_FIXNUM_0x4A:
            case MsgPackType.POSITIVE_FIXNUM_0x4B:
            case MsgPackType.POSITIVE_FIXNUM_0x4C:
            case MsgPackType.POSITIVE_FIXNUM_0x4D:
            case MsgPackType.POSITIVE_FIXNUM_0x4E:
            case MsgPackType.POSITIVE_FIXNUM_0x4F:

            case MsgPackType.POSITIVE_FIXNUM_0x50:
            case MsgPackType.POSITIVE_FIXNUM_0x51:
            case MsgPackType.POSITIVE_FIXNUM_0x52:
            case MsgPackType.POSITIVE_FIXNUM_0x53:
            case MsgPackType.POSITIVE_FIXNUM_0x54:
            case MsgPackType.POSITIVE_FIXNUM_0x55:
            case MsgPackType.POSITIVE_FIXNUM_0x56:
            case MsgPackType.POSITIVE_FIXNUM_0x57:
            case MsgPackType.POSITIVE_FIXNUM_0x58:
            case MsgPackType.POSITIVE_FIXNUM_0x59:
            case MsgPackType.POSITIVE_FIXNUM_0x5A:
            case MsgPackType.POSITIVE_FIXNUM_0x5B:
            case MsgPackType.POSITIVE_FIXNUM_0x5C:
            case MsgPackType.POSITIVE_FIXNUM_0x5D:
            case MsgPackType.POSITIVE_FIXNUM_0x5E:
            case MsgPackType.POSITIVE_FIXNUM_0x5F:

            case MsgPackType.POSITIVE_FIXNUM_0x60:
            case MsgPackType.POSITIVE_FIXNUM_0x61:
            case MsgPackType.POSITIVE_FIXNUM_0x62:
            case MsgPackType.POSITIVE_FIXNUM_0x63:
            case MsgPackType.POSITIVE_FIXNUM_0x64:
            case MsgPackType.POSITIVE_FIXNUM_0x65:
            case MsgPackType.POSITIVE_FIXNUM_0x66:
            case MsgPackType.POSITIVE_FIXNUM_0x67:
            case MsgPackType.POSITIVE_FIXNUM_0x68:
            case MsgPackType.POSITIVE_FIXNUM_0x69:
            case MsgPackType.POSITIVE_FIXNUM_0x6A:
            case MsgPackType.POSITIVE_FIXNUM_0x6B:
            case MsgPackType.POSITIVE_FIXNUM_0x6C:
            case MsgPackType.POSITIVE_FIXNUM_0x6D:
            case MsgPackType.POSITIVE_FIXNUM_0x6E:
            case MsgPackType.POSITIVE_FIXNUM_0x6F:

            case MsgPackType.POSITIVE_FIXNUM_0x70:
            case MsgPackType.POSITIVE_FIXNUM_0x71:
            case MsgPackType.POSITIVE_FIXNUM_0x72:
            case MsgPackType.POSITIVE_FIXNUM_0x73:
            case MsgPackType.POSITIVE_FIXNUM_0x74:
            case MsgPackType.POSITIVE_FIXNUM_0x75:
            case MsgPackType.POSITIVE_FIXNUM_0x76:
            case MsgPackType.POSITIVE_FIXNUM_0x77:
            case MsgPackType.POSITIVE_FIXNUM_0x78:
            case MsgPackType.POSITIVE_FIXNUM_0x79:
            case MsgPackType.POSITIVE_FIXNUM_0x7A:
            case MsgPackType.POSITIVE_FIXNUM_0x7B:
            case MsgPackType.POSITIVE_FIXNUM_0x7C:
            case MsgPackType.POSITIVE_FIXNUM_0x7D:
            case MsgPackType.POSITIVE_FIXNUM_0x7E:
            case MsgPackType.POSITIVE_FIXNUM_0x7F:

            case MsgPackType.NEGATIVE_FIXNUM:
            case MsgPackType.NEGATIVE_FIXNUM_0x01:
            case MsgPackType.NEGATIVE_FIXNUM_0x02:
            case MsgPackType.NEGATIVE_FIXNUM_0x03:
            case MsgPackType.NEGATIVE_FIXNUM_0x04:
            case MsgPackType.NEGATIVE_FIXNUM_0x05:
            case MsgPackType.NEGATIVE_FIXNUM_0x06:
            case MsgPackType.NEGATIVE_FIXNUM_0x07:
            case MsgPackType.NEGATIVE_FIXNUM_0x08:
            case MsgPackType.NEGATIVE_FIXNUM_0x09:
            case MsgPackType.NEGATIVE_FIXNUM_0x0A:
            case MsgPackType.NEGATIVE_FIXNUM_0x0B:
            case MsgPackType.NEGATIVE_FIXNUM_0x0C:
            case MsgPackType.NEGATIVE_FIXNUM_0x0D:
            case MsgPackType.NEGATIVE_FIXNUM_0x0E:
            case MsgPackType.NEGATIVE_FIXNUM_0x0F:
            case MsgPackType.NEGATIVE_FIXNUM_0x10:
            case MsgPackType.NEGATIVE_FIXNUM_0x11:
            case MsgPackType.NEGATIVE_FIXNUM_0x12:
            case MsgPackType.NEGATIVE_FIXNUM_0x13:
            case MsgPackType.NEGATIVE_FIXNUM_0x14:
            case MsgPackType.NEGATIVE_FIXNUM_0x15:
            case MsgPackType.NEGATIVE_FIXNUM_0x16:
            case MsgPackType.NEGATIVE_FIXNUM_0x17:
            case MsgPackType.NEGATIVE_FIXNUM_0x18:
            case MsgPackType.NEGATIVE_FIXNUM_0x19:
            case MsgPackType.NEGATIVE_FIXNUM_0x1A:
            case MsgPackType.NEGATIVE_FIXNUM_0x1B:
            case MsgPackType.NEGATIVE_FIXNUM_0x1C:
            case MsgPackType.NEGATIVE_FIXNUM_0x1D:
            case MsgPackType.NEGATIVE_FIXNUM_0x1E:
            case MsgPackType.NEGATIVE_FIXNUM_0x1F:
                return(Bytes.Advance(1).Take(0));

            case MsgPackType.UINT8:
            case MsgPackType.INT8:
                return(Bytes.Advance(1).Take(1));

            case MsgPackType.UINT16:
            case MsgPackType.INT16:
                return(Bytes.Advance(1).Take(2));

            case MsgPackType.UINT32:
            case MsgPackType.INT32:
            case MsgPackType.FLOAT:
                return(Bytes.Advance(1).Take(4));

            case MsgPackType.UINT64:
            case MsgPackType.INT64:
            case MsgPackType.DOUBLE:
                return(Bytes.Advance(1).Take(8));

            case MsgPackType.FIX_EXT_1:
                return(Bytes.Advance(2).Take(1));

            case MsgPackType.FIX_EXT_2:
                return(Bytes.Advance(2).Take(2));

            case MsgPackType.FIX_EXT_4:
                return(Bytes.Advance(2).Take(4));

            case MsgPackType.FIX_EXT_8:
                return(Bytes.Advance(2).Take(8));

            case MsgPackType.FIX_EXT_16:
                return(Bytes.Advance(2).Take(16));

            case MsgPackType.EXT8:
            {
                var count = Bytes.Get(1);
                return(Bytes.Advance(1 + 1 + 1).Take(count));
            }

            case MsgPackType.EXT16:
            {
                var count = EndianConverter.NetworkByteWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 2 + 1).Take(count));
            }

            case MsgPackType.EXT32:
            {
                var count = EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(Bytes.Advance(1));
                return(Bytes.Advance(1 + 4 + 1).Take((int)count));
            }

            default:
                throw new ArgumentException("unknown type: " + FormatType);
            }
        }
コード例 #3
0
 public ulong ReadUint64()
 {
     return(EndianConverter.BytesToUint64(ReadOctets(8)));
 }
コード例 #4
0
 /// <summary>
 ///     Creates a converter for changing data from the current
 ///     Endian setting to the target Endian setting.
 /// </summary>
 public EndianConverter To(Endian target)
 {
     return(EndianConverter.Create(this != target));
 }
コード例 #5
0
 public ushort ReadUint16()
 {
     return(EndianConverter.BytesToUint16(ReadOctets(2)));
 }
コード例 #6
0
 public uint ReadUint32()
 {
     return(EndianConverter.BytesToUint32(ReadOctets(4)));
 }
コード例 #7
0
 public void WriteUint32(uint data)
 {
     Write(EndianConverter.Uint32ToBytes(data));
 }
コード例 #8
0
ファイル: GrfArchive.cs プロジェクト: landergate/rolib
        private void ReadHeader()
        {
            if (FileStream.CanWrite && FileStream.Length < 1)
            {
                byte[] zbuf        = ZlibStream.CompressBuffer(new byte[0]);
                byte[] zero        = new byte[4];
                int    zlen_le     = EndianConverter.LittleEndian(zbuf.Length),
                       zero_fcount = EndianConverter.LittleEndian(7),
                       create_ver  = EndianConverter.LittleEndian(m_IntVersion);

                FileStream.Write(Encoding.ASCII.GetBytes(GRF_HEADER), 0, GRF_HEADER_LEN);
                FileStream.Write(CryptWatermark, 0, CryptWatermark.Length);
                FileStream.Write(zero, 0, 4);
                FileStream.Write(zero, 0, 4);
                FileStream.Write(BitConverter.GetBytes(zero_fcount), 0, 4);
                FileStream.Write(BitConverter.GetBytes(create_ver), 0, 4);
                FileStream.Write(BitConverter.GetBytes(zlen_le), 0, 4);
                FileStream.Write(zero, 0, 4);
                FileStream.Write(zbuf, 0, zbuf.Length);

                FileStream.Seek(0, SeekOrigin.Begin);
            }

            byte[] buf = new byte[GRF_HEADER_FULL_LEN];
            FileStream.Read(buf, 0, buf.Length);

            if (buf[GRF_HEADER_LEN + 1] == 1)
            {
                m_AllowCrypt = true;
                // 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E
                for (byte i = 0; i < 0xF; i++)
                {
                    if (buf[GRF_HEADER_LEN + i] != i)
                    {
                        throw new GrfException();
                    }
                }
            }
            else if (buf[GRF_HEADER_LEN] == 0)
            {
                m_AllowCrypt = false;
                // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                for (byte i = 0; i < 0xF; i++)
                {
                    if (buf[GRF_HEADER_LEN + i] != 0)
                    {
                        throw new GrfException();
                    }
                }
            }
            else
            {
                throw new GrfException();
            }

            using (IntPtrEx pBuffer = new IntPtrEx(buf))
            {
                m_Items = new GrfItemCollection(this);

                m_IntVersion     = EndianConverter.LittleEndian(pBuffer.Read <int>(GRF_HEADER_MID_LEN + 0xC));
                m_Items.Capacity = EndianConverter.LittleEndian(pBuffer.Read <int>(GRF_HEADER_MID_LEN + 8))
                                   - EndianConverter.LittleEndian(pBuffer.Read <int>(GRF_HEADER_MID_LEN + 4))
                                   - 7;

                FileStream.Seek(EndianConverter.LittleEndian(pBuffer.Read <int>(GRF_HEADER_MID_LEN) + GRF_HEADER_FULL_LEN), SeekOrigin.Begin);
            }

            switch (m_IntVersion & 0xFF00)
            {
            case 0x0200: ReadVer2Info(); break;

            case 0x0100: ReadVer1Info(); break;

            default: throw new GrfException();
            }
        }
コード例 #9
0
 static EndianConverter()
 {
     LinearCopier = new EndianConverter(CopyLinear);
     ReverseCopier = new EndianConverter(CopyReverse);
 }
コード例 #10
0
 public void WriteUint16(ushort data)
 {
     Write(EndianConverter.Uint16ToBytes(data));
 }
コード例 #11
0
ファイル: GrfArchive.cs プロジェクト: landergate/rolib
        private void FlushVer2()
        {
            byte[]      buffer = new byte[m_Items.Count * GRF_ITEM_SIZE];
            IntPtrEx    pName;
            int         i, offset, len;
            GrfFileInfo gfile = null;

            try
            {
                m_Items.SortToPosition();

                using (IntPtrEx pBuffer = new IntPtrEx(buffer))
                {
                    for (i = offset = 0; i < Items.Count; i++)
                    {
                        len = m_Items[i].FullName.Length + 1;
                        using (pName = new IntPtrEx(m_Items[i].FullName))
                        {
                            Marshal.Copy(pName, buffer, offset, len);
                        }

                        offset += len;

                        if (m_Items[i] is GrfFileInfo)
                        {
                            gfile = (GrfFileInfo)m_Items[i];

                            if (m_ForceRepack)
                            {
                                gfile.CompressedLength        = 0;
                                gfile.AlignedCompressedLength = 0;
                                gfile.Position = 0;
                            }

                            if (gfile.CompressedLength == 0 &&
                                gfile.AlignedCompressedLength == 0 &&
                                gfile.Position == 0 &&
                                gfile.Length != 0)
                            {
                                if (!m_AllowCrypt)
                                {
                                    gfile.Flags &= ~(GrfFileFlags.MixCrypt | GrfFileFlags.Des_0x14);
                                }

                                FlushFile(i);
                            }

                            pBuffer.Write <int>(offset, EndianConverter.LittleEndian(gfile.CompressedLength));
                            pBuffer.Write <int>(offset + 4, EndianConverter.LittleEndian(gfile.AlignedCompressedLength));
                            pBuffer.Write <int>(offset + 8, EndianConverter.LittleEndian(gfile.Length));
                            pBuffer.Write <int>(offset + 0xD, EndianConverter.LittleEndian(gfile.Position - GRF_HEADER_FULL_LEN));
                        }
                        else
                        {
                            pBuffer.Write <int>(offset, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZSMALL));
                            pBuffer.Write <int>(offset + 4, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZFILE));
                            pBuffer.Write <int>(offset + 8, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZORIG));
                            pBuffer.Write <int>(offset + 0xD, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_OFFSET - GRF_HEADER_FULL_LEN));
                        }

                        pBuffer.Write <byte>(offset + 0xC, (byte)m_Items[i].Flags);

                        offset += 0x11;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            Array.Resize <byte>(ref buffer, offset);
            buffer = ZlibStream.CompressBuffer(buffer);

            m_Items.SortToPosition();

            int writeOffset = m_Items.FindUnused(8 + buffer.Length);

            if (writeOffset == 0)
            {
                FileStream.Seek(0, SeekOrigin.End);
                writeOffset = (int)FileStream.Position;
            }
            else
            {
                FileStream.Seek(writeOffset, SeekOrigin.Begin);
            }

            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(buffer.Length)), 0, 4);
            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(offset)), 0, 4);
            FileStream.Write(buffer, 0, buffer.Length);

            FileStream.Seek(GRF_HEADER_MID_LEN, SeekOrigin.Begin);

            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(writeOffset - GRF_HEADER_FULL_LEN)), 0, 4);
            FileStream.Write(BitConverter.GetBytes(0), 0, 4);
            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(i + 7)), 0, 4);
        }
コード例 #12
0
ファイル: GrfArchive.cs プロジェクト: landergate/rolib
        private void FlushVer1()
        {
            byte[]      buffer = new byte[m_Items.Count * GRF_ITEM_SIZE];
            int         i, offset, len, writeOffset;
            GrfFileInfo gfile = null;

            try
            {
                m_Items.SortToPosition();

                using (IntPtrEx pBuffer = new IntPtrEx(buffer))
                {
                    for (i = offset = 0; i < Items.Count; i++)
                    {
                        if (m_Items[i] is GrfFileInfo)
                        {
                            gfile = (GrfFileInfo)m_Items[i];

                            if (m_ForceRepack)
                            {
                                gfile.CompressedLength        = 0;
                                gfile.AlignedCompressedLength = 0;
                                gfile.Position = 0;
                            }

                            if (gfile.CompressedLength == 0 &&
                                gfile.AlignedCompressedLength == 0 &&
                                gfile.Position == 0 &&
                                gfile.Length != 0)
                            {
                                if (gfile.CheckExtension())
                                {
                                    gfile.Flags = (gfile.Flags & ~GrfFileFlags.MixCrypt) | GrfFileFlags.Des_0x14;
                                }
                                else
                                {
                                    gfile.Flags = (gfile.Flags & ~GrfFileFlags.Des_0x14) | GrfFileFlags.MixCrypt;
                                }

                                FlushFile(i);
                            }
                        }

                        len = m_Items[i].FullName.Length + 1;
                        if (m_IntVersion < 0x101)
                        {
                            pBuffer.Write <int>(offset, len);
                            SwapNibbles(pBuffer + offset + 4, m_Items[i].FullName, len);
                            offset += 4 + len;
                        }
                        else if (m_IntVersion < 0x104)
                        {
                            pBuffer.Write <int>(offset, len + 6);
                            offset += 4;
                            SwapNibbles(pBuffer + offset + 6, GrfCrypt.EncryptNameVer1(m_Items[i].Name, len), len);
                            offset += len + 6;
                        }

                        if (m_Items[i] is GrfDirectoryInfo)
                        {
                            pBuffer.Write <int>(offset, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZSMALL + GrfItem.GRFFILE_DIR_SZORIG + 0x02CB));
                            pBuffer.Write <int>(offset + 4, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZFILE + 0x92CB));
                            pBuffer.Write <int>(offset + 8, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_SZORIG));
                            pBuffer.Write <int>(offset + 0xD, EndianConverter.LittleEndian(GrfItem.GRFFILE_DIR_OFFSET - GRF_HEADER_FULL_LEN));
                        }
                        else
                        {
                            pBuffer.Write <int>(offset, EndianConverter.LittleEndian(gfile.CompressedLength + gfile.Length + 0x02CB));
                            pBuffer.Write <int>(offset + 4, EndianConverter.LittleEndian(gfile.AlignedCompressedLength + 0x92CB));
                            pBuffer.Write <int>(offset + 8, EndianConverter.LittleEndian(gfile.Length));
                            pBuffer.Write <int>(offset + 0xD, EndianConverter.LittleEndian(gfile.Position - GRF_HEADER_FULL_LEN));
                        }

                        pBuffer.Write <byte>(offset + 0xC, (byte)(m_Items[i].Flags & GrfFileFlags.File));

                        offset += 0x11;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            FileStream.Seek(0, SeekOrigin.End);
            writeOffset = (int)FileStream.Position;
            FileStream.Write(buffer, 0, offset);
            FileStream.Seek(GRF_HEADER_MID_LEN, SeekOrigin.End);

            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(writeOffset - GRF_HEADER_FULL_LEN)), 0, 4);
            FileStream.Write(BitConverter.GetBytes(0), 0, 4);
            FileStream.Write(BitConverter.GetBytes(EndianConverter.LittleEndian(i + 0 + 7)), 0, 4);
        }
コード例 #13
0
ファイル: GrfArchive.cs プロジェクト: landergate/rolib
        private void ReadVer1Info()
        {
            if (m_IntVersion > 0x103)
            {
                throw new GrfException();
            }

            int offset = (int)FileStream.Position;
            int len2, len = (int)FileStream.Length - offset;

            byte[] buffer = new byte[len], namebuf = new byte[GRF_NAMELEN];

            try
            {
                FileStream.Read(buffer, 0, len);

                string  name = null;
                GrfItem item;

                using (IntPtrEx pBuffer = new IntPtrEx(buffer))
                {
                    for (int i = offset = 0; i < m_Items.Capacity; i++)
                    {
                        len     = EndianConverter.LittleEndian(pBuffer.Read <int>(offset));
                        offset += 4;

                        if (m_IntVersion < 0x101)
                        {
                            len2 = pBuffer.Read <string>(offset).Length;
                            if (len2 >= GRF_NAMELEN)
                            {
                                throw new GrfException();
                            }

                            name = SwapNibbles(pBuffer + offset, len2);
                        }
                        else if (m_IntVersion < 0x104)
                        {
                            offset += 2;
                            len2    = len - 6;
                            if (len2 >= GRF_NAMELEN)
                            {
                                throw new GrfException();
                            }

                            SwapNibbles(namebuf, pBuffer + offset, len2);
                            name = GrfCrypt.DecryptNameVer1(namebuf, len2);

                            len -= 2;
                        }

                        offset += len;

                        item = GrfItem.CreateV1
                               (
                            this,
                            name,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset)) - EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 8)) - 0x02CB,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 4)) - 0x92CB,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 8)),
                            (GrfFileFlags)pBuffer[offset + 0xC],
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 0xD)) + GRF_HEADER_FULL_LEN
                               );

                        m_Items.GrfAdd(item);

                        offset += 0x11;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #14
0
ファイル: MessagePackParser.cs プロジェクト: ousttrue/Osaru
        /// <summary>
        /// ArrayとMap以外のタイプの値を得る
        /// </summary>
        /// <returns></returns>
        public object GetValue()
        {
            switch (FormatType)
            {
            case MsgPackType.NIL: return(null);

            case MsgPackType.TRUE: return(true);

            case MsgPackType.FALSE: return(false);

            case MsgPackType.POSITIVE_FIXNUM: return(0);

            case MsgPackType.POSITIVE_FIXNUM_0x01: return(1);

            case MsgPackType.POSITIVE_FIXNUM_0x02: return(2);

            case MsgPackType.POSITIVE_FIXNUM_0x03: return(3);

            case MsgPackType.POSITIVE_FIXNUM_0x04: return(4);

            case MsgPackType.POSITIVE_FIXNUM_0x05: return(5);

            case MsgPackType.POSITIVE_FIXNUM_0x06: return(6);

            case MsgPackType.POSITIVE_FIXNUM_0x07: return(7);

            case MsgPackType.POSITIVE_FIXNUM_0x08: return(8);

            case MsgPackType.POSITIVE_FIXNUM_0x09: return(9);

            case MsgPackType.POSITIVE_FIXNUM_0x0A: return(10);

            case MsgPackType.POSITIVE_FIXNUM_0x0B: return(11);

            case MsgPackType.POSITIVE_FIXNUM_0x0C: return(12);

            case MsgPackType.POSITIVE_FIXNUM_0x0D: return(13);

            case MsgPackType.POSITIVE_FIXNUM_0x0E: return(14);

            case MsgPackType.POSITIVE_FIXNUM_0x0F: return(15);

            case MsgPackType.POSITIVE_FIXNUM_0x10: return(16);

            case MsgPackType.POSITIVE_FIXNUM_0x11: return(17);

            case MsgPackType.POSITIVE_FIXNUM_0x12: return(18);

            case MsgPackType.POSITIVE_FIXNUM_0x13: return(19);

            case MsgPackType.POSITIVE_FIXNUM_0x14: return(20);

            case MsgPackType.POSITIVE_FIXNUM_0x15: return(21);

            case MsgPackType.POSITIVE_FIXNUM_0x16: return(22);

            case MsgPackType.POSITIVE_FIXNUM_0x17: return(23);

            case MsgPackType.POSITIVE_FIXNUM_0x18: return(24);

            case MsgPackType.POSITIVE_FIXNUM_0x19: return(25);

            case MsgPackType.POSITIVE_FIXNUM_0x1A: return(26);

            case MsgPackType.POSITIVE_FIXNUM_0x1B: return(27);

            case MsgPackType.POSITIVE_FIXNUM_0x1C: return(28);

            case MsgPackType.POSITIVE_FIXNUM_0x1D: return(29);

            case MsgPackType.POSITIVE_FIXNUM_0x1E: return(30);

            case MsgPackType.POSITIVE_FIXNUM_0x1F: return(31);

            case MsgPackType.POSITIVE_FIXNUM_0x20: return(32);

            case MsgPackType.POSITIVE_FIXNUM_0x21: return(33);

            case MsgPackType.POSITIVE_FIXNUM_0x22: return(34);

            case MsgPackType.POSITIVE_FIXNUM_0x23: return(35);

            case MsgPackType.POSITIVE_FIXNUM_0x24: return(36);

            case MsgPackType.POSITIVE_FIXNUM_0x25: return(37);

            case MsgPackType.POSITIVE_FIXNUM_0x26: return(38);

            case MsgPackType.POSITIVE_FIXNUM_0x27: return(39);

            case MsgPackType.POSITIVE_FIXNUM_0x28: return(40);

            case MsgPackType.POSITIVE_FIXNUM_0x29: return(41);

            case MsgPackType.POSITIVE_FIXNUM_0x2A: return(42);

            case MsgPackType.POSITIVE_FIXNUM_0x2B: return(43);

            case MsgPackType.POSITIVE_FIXNUM_0x2C: return(44);

            case MsgPackType.POSITIVE_FIXNUM_0x2D: return(45);

            case MsgPackType.POSITIVE_FIXNUM_0x2E: return(46);

            case MsgPackType.POSITIVE_FIXNUM_0x2F: return(47);

            case MsgPackType.POSITIVE_FIXNUM_0x30: return(48);

            case MsgPackType.POSITIVE_FIXNUM_0x31: return(49);

            case MsgPackType.POSITIVE_FIXNUM_0x32: return(50);

            case MsgPackType.POSITIVE_FIXNUM_0x33: return(51);

            case MsgPackType.POSITIVE_FIXNUM_0x34: return(52);

            case MsgPackType.POSITIVE_FIXNUM_0x35: return(53);

            case MsgPackType.POSITIVE_FIXNUM_0x36: return(54);

            case MsgPackType.POSITIVE_FIXNUM_0x37: return(55);

            case MsgPackType.POSITIVE_FIXNUM_0x38: return(56);

            case MsgPackType.POSITIVE_FIXNUM_0x39: return(57);

            case MsgPackType.POSITIVE_FIXNUM_0x3A: return(58);

            case MsgPackType.POSITIVE_FIXNUM_0x3B: return(59);

            case MsgPackType.POSITIVE_FIXNUM_0x3C: return(60);

            case MsgPackType.POSITIVE_FIXNUM_0x3D: return(61);

            case MsgPackType.POSITIVE_FIXNUM_0x3E: return(62);

            case MsgPackType.POSITIVE_FIXNUM_0x3F: return(63);

            case MsgPackType.POSITIVE_FIXNUM_0x40: return(64);

            case MsgPackType.POSITIVE_FIXNUM_0x41: return(65);

            case MsgPackType.POSITIVE_FIXNUM_0x42: return(66);

            case MsgPackType.POSITIVE_FIXNUM_0x43: return(67);

            case MsgPackType.POSITIVE_FIXNUM_0x44: return(68);

            case MsgPackType.POSITIVE_FIXNUM_0x45: return(69);

            case MsgPackType.POSITIVE_FIXNUM_0x46: return(70);

            case MsgPackType.POSITIVE_FIXNUM_0x47: return(71);

            case MsgPackType.POSITIVE_FIXNUM_0x48: return(72);

            case MsgPackType.POSITIVE_FIXNUM_0x49: return(73);

            case MsgPackType.POSITIVE_FIXNUM_0x4A: return(74);

            case MsgPackType.POSITIVE_FIXNUM_0x4B: return(75);

            case MsgPackType.POSITIVE_FIXNUM_0x4C: return(76);

            case MsgPackType.POSITIVE_FIXNUM_0x4D: return(77);

            case MsgPackType.POSITIVE_FIXNUM_0x4E: return(78);

            case MsgPackType.POSITIVE_FIXNUM_0x4F: return(79);

            case MsgPackType.POSITIVE_FIXNUM_0x50: return(80);

            case MsgPackType.POSITIVE_FIXNUM_0x51: return(81);

            case MsgPackType.POSITIVE_FIXNUM_0x52: return(82);

            case MsgPackType.POSITIVE_FIXNUM_0x53: return(83);

            case MsgPackType.POSITIVE_FIXNUM_0x54: return(84);

            case MsgPackType.POSITIVE_FIXNUM_0x55: return(85);

            case MsgPackType.POSITIVE_FIXNUM_0x56: return(86);

            case MsgPackType.POSITIVE_FIXNUM_0x57: return(87);

            case MsgPackType.POSITIVE_FIXNUM_0x58: return(88);

            case MsgPackType.POSITIVE_FIXNUM_0x59: return(89);

            case MsgPackType.POSITIVE_FIXNUM_0x5A: return(90);

            case MsgPackType.POSITIVE_FIXNUM_0x5B: return(91);

            case MsgPackType.POSITIVE_FIXNUM_0x5C: return(92);

            case MsgPackType.POSITIVE_FIXNUM_0x5D: return(93);

            case MsgPackType.POSITIVE_FIXNUM_0x5E: return(94);

            case MsgPackType.POSITIVE_FIXNUM_0x5F: return(95);

            case MsgPackType.POSITIVE_FIXNUM_0x60: return(96);

            case MsgPackType.POSITIVE_FIXNUM_0x61: return(97);

            case MsgPackType.POSITIVE_FIXNUM_0x62: return(98);

            case MsgPackType.POSITIVE_FIXNUM_0x63: return(99);

            case MsgPackType.POSITIVE_FIXNUM_0x64: return(100);

            case MsgPackType.POSITIVE_FIXNUM_0x65: return(101);

            case MsgPackType.POSITIVE_FIXNUM_0x66: return(102);

            case MsgPackType.POSITIVE_FIXNUM_0x67: return(103);

            case MsgPackType.POSITIVE_FIXNUM_0x68: return(104);

            case MsgPackType.POSITIVE_FIXNUM_0x69: return(105);

            case MsgPackType.POSITIVE_FIXNUM_0x6A: return(106);

            case MsgPackType.POSITIVE_FIXNUM_0x6B: return(107);

            case MsgPackType.POSITIVE_FIXNUM_0x6C: return(108);

            case MsgPackType.POSITIVE_FIXNUM_0x6D: return(109);

            case MsgPackType.POSITIVE_FIXNUM_0x6E: return(110);

            case MsgPackType.POSITIVE_FIXNUM_0x6F: return(111);

            case MsgPackType.POSITIVE_FIXNUM_0x70: return(112);

            case MsgPackType.POSITIVE_FIXNUM_0x71: return(113);

            case MsgPackType.POSITIVE_FIXNUM_0x72: return(114);

            case MsgPackType.POSITIVE_FIXNUM_0x73: return(115);

            case MsgPackType.POSITIVE_FIXNUM_0x74: return(116);

            case MsgPackType.POSITIVE_FIXNUM_0x75: return(117);

            case MsgPackType.POSITIVE_FIXNUM_0x76: return(118);

            case MsgPackType.POSITIVE_FIXNUM_0x77: return(119);

            case MsgPackType.POSITIVE_FIXNUM_0x78: return(120);

            case MsgPackType.POSITIVE_FIXNUM_0x79: return(121);

            case MsgPackType.POSITIVE_FIXNUM_0x7A: return(122);

            case MsgPackType.POSITIVE_FIXNUM_0x7B: return(123);

            case MsgPackType.POSITIVE_FIXNUM_0x7C: return(124);

            case MsgPackType.POSITIVE_FIXNUM_0x7D: return(125);

            case MsgPackType.POSITIVE_FIXNUM_0x7E: return(126);

            case MsgPackType.POSITIVE_FIXNUM_0x7F: return(127);

            case MsgPackType.NEGATIVE_FIXNUM: return(-32);

            case MsgPackType.NEGATIVE_FIXNUM_0x01: return(-1);

            case MsgPackType.NEGATIVE_FIXNUM_0x02: return(-2);

            case MsgPackType.NEGATIVE_FIXNUM_0x03: return(-3);

            case MsgPackType.NEGATIVE_FIXNUM_0x04: return(-4);

            case MsgPackType.NEGATIVE_FIXNUM_0x05: return(-5);

            case MsgPackType.NEGATIVE_FIXNUM_0x06: return(-6);

            case MsgPackType.NEGATIVE_FIXNUM_0x07: return(-7);

            case MsgPackType.NEGATIVE_FIXNUM_0x08: return(-8);

            case MsgPackType.NEGATIVE_FIXNUM_0x09: return(-9);

            case MsgPackType.NEGATIVE_FIXNUM_0x0A: return(-10);

            case MsgPackType.NEGATIVE_FIXNUM_0x0B: return(-11);

            case MsgPackType.NEGATIVE_FIXNUM_0x0C: return(-12);

            case MsgPackType.NEGATIVE_FIXNUM_0x0D: return(-13);

            case MsgPackType.NEGATIVE_FIXNUM_0x0E: return(-14);

            case MsgPackType.NEGATIVE_FIXNUM_0x0F: return(-15);

            case MsgPackType.NEGATIVE_FIXNUM_0x10: return(-16);

            case MsgPackType.NEGATIVE_FIXNUM_0x11: return(-17);

            case MsgPackType.NEGATIVE_FIXNUM_0x12: return(-18);

            case MsgPackType.NEGATIVE_FIXNUM_0x13: return(-19);

            case MsgPackType.NEGATIVE_FIXNUM_0x14: return(-20);

            case MsgPackType.NEGATIVE_FIXNUM_0x15: return(-21);

            case MsgPackType.NEGATIVE_FIXNUM_0x16: return(-22);

            case MsgPackType.NEGATIVE_FIXNUM_0x17: return(-23);

            case MsgPackType.NEGATIVE_FIXNUM_0x18: return(-24);

            case MsgPackType.NEGATIVE_FIXNUM_0x19: return(-25);

            case MsgPackType.NEGATIVE_FIXNUM_0x1A: return(-26);

            case MsgPackType.NEGATIVE_FIXNUM_0x1B: return(-27);

            case MsgPackType.NEGATIVE_FIXNUM_0x1C: return(-28);

            case MsgPackType.NEGATIVE_FIXNUM_0x1D: return(-29);

            case MsgPackType.NEGATIVE_FIXNUM_0x1E: return(-30);

            case MsgPackType.NEGATIVE_FIXNUM_0x1F: return(-31);

            case MsgPackType.INT8: return((SByte)GetBody().Get(0));

            case MsgPackType.INT16: return(EndianConverter.NetworkByteWordToSignedNativeByteOrder(GetBody()));

            case MsgPackType.INT32: return(EndianConverter.NetworkByteDWordToSignedNativeByteOrder(GetBody()));

            case MsgPackType.INT64: return(EndianConverter.NetworkByteQWordToSignedNativeByteOrder(GetBody()));

            case MsgPackType.UINT8: return(GetBody().Get(0));

            case MsgPackType.UINT16: return(EndianConverter.NetworkByteWordToUnsignedNativeByteOrder(GetBody()));

            case MsgPackType.UINT32: return(EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(GetBody()));

            case MsgPackType.UINT64: return(EndianConverter.NetworkByteQWordToUnsignedNativeByteOrder(GetBody()));

            case MsgPackType.FLOAT: return(EndianConverter.NetworkByteDWordToFloatNativeByteOrder(GetBody()));

            case MsgPackType.DOUBLE: return(EndianConverter.NetworkByteQWordToFloatNativeByteOrder(GetBody()));

            case MsgPackType.FIX_STR: return("");

            case MsgPackType.FIX_STR_0x01:
            case MsgPackType.FIX_STR_0x02:
            case MsgPackType.FIX_STR_0x03:
            case MsgPackType.FIX_STR_0x04:
            case MsgPackType.FIX_STR_0x05:
            case MsgPackType.FIX_STR_0x06:
            case MsgPackType.FIX_STR_0x07:
            case MsgPackType.FIX_STR_0x08:
            case MsgPackType.FIX_STR_0x09:
            case MsgPackType.FIX_STR_0x0A:
            case MsgPackType.FIX_STR_0x0B:
            case MsgPackType.FIX_STR_0x0C:
            case MsgPackType.FIX_STR_0x0D:
            case MsgPackType.FIX_STR_0x0E:
            case MsgPackType.FIX_STR_0x0F:
            case MsgPackType.FIX_STR_0x10:
            case MsgPackType.FIX_STR_0x11:
            case MsgPackType.FIX_STR_0x12:
            case MsgPackType.FIX_STR_0x13:
            case MsgPackType.FIX_STR_0x14:
            case MsgPackType.FIX_STR_0x15:
            case MsgPackType.FIX_STR_0x16:
            case MsgPackType.FIX_STR_0x17:
            case MsgPackType.FIX_STR_0x18:
            case MsgPackType.FIX_STR_0x19:
            case MsgPackType.FIX_STR_0x1A:
            case MsgPackType.FIX_STR_0x1B:
            case MsgPackType.FIX_STR_0x1C:
            case MsgPackType.FIX_STR_0x1D:
            case MsgPackType.FIX_STR_0x1E:
            case MsgPackType.FIX_STR_0x1F:
            case MsgPackType.STR8:
            case MsgPackType.STR16:
            case MsgPackType.STR32:
            {
                var body = GetBody();
                var str  = Encoding.UTF8.GetString(body.Array, body.Offset, body.Count);
                return(str);
            }

            case MsgPackType.BIN8:
            case MsgPackType.BIN16:
            case MsgPackType.BIN32:
            {
                var body = GetBody();
                return(body);
            }

            default:
                throw new ArgumentException("GetValue to array or map: " + FormatType);
            }
        }
コード例 #15
0
 public void WriteUint64(ulong data)
 {
     Write(EndianConverter.Uint64ToBytes(data));
 }
コード例 #16
0
        private static object GetValue(Type type, byte[] buf, bool convertEndian)
        {
            object result = null;

            if (!type.IsArray)
            {
                switch (type.Name)
                {
                case "Char":
                    result = (char)buf[0];
                    break;

                case "SByte":
                    result = (sbyte)buf[0];
                    break;

                case "Byte":
                    result = buf[0];
                    break;

                case "Int16":
                    result = BitConverter.ToInt16(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((short)result);
                    }
                    break;

                case "UInt16":
                    result = BitConverter.ToUInt16(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((ushort)result);
                    }
                    break;

                case "Int32":
                    result = BitConverter.ToInt32(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((int)result);
                    }
                    break;

                case "UInt32":
                    result = BitConverter.ToUInt32(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((uint)result);
                    }
                    break;

                case "Int64":
                    result = BitConverter.ToInt64(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((long)result);
                    }
                    break;

                case "UInt64":
                    result = BitConverter.ToUInt64(buf, 0);
                    if (convertEndian)
                    {
                        result = EndianConverter.Convert((ulong)result);
                    }
                    break;

                case "String":
                    result = Encoding.ASCII.GetString(buf);
                    break;
                }
            }
            return(result);
        }
コード例 #17
0
ファイル: FifFile.cs プロジェクト: exelotl/puyo-text-editor
        public FifFile(string path)
        {
            Entries = new OrderedDictionary <char, FifEntry>();

            using (var source = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (var reader = new BinaryReader(source, Encoding.Unicode))
                {
                    // FNT files start with the magic code FONTDATF
                    if (!(reader.ReadByte() == 'F' && reader.ReadByte() == 'O' && reader.ReadByte() == 'N' && reader.ReadByte() == 'T' &&
                          reader.ReadByte() == 'D' && reader.ReadByte() == 'A' && reader.ReadByte() == 'T' && reader.ReadByte() == 'F'))
                    {
                        throw new IOException(string.Format(ErrorMessages.InvalidFifFile + "1", path));
                    }

                    // The next 4 bytes tell us the endianess of the file.
                    // 1 if this file is big-endian
                    // 0 if this file is little-endian
                    IsBigEndian = reader.ReadInt32() == 1;

                    Func <char>  ReadChar;
                    Func <short> ReadInt16;
                    Func <int>   ReadInt32;

                    if (IsBigEndian)
                    {
                        ReadChar  = () => EndianConverter.Convert(reader.ReadChar());
                        ReadInt16 = () => EndianConverter.Convert(reader.ReadInt16());
                        ReadInt32 = () => EndianConverter.Convert(reader.ReadInt32());
                    }
                    else
                    {
                        ReadChar  = reader.ReadChar;
                        ReadInt16 = reader.ReadInt16;
                        ReadInt32 = reader.ReadInt32;
                    }

                    // The next 16-bit integer appears to always be 101 (0x65)
                    if (ReadInt16() != 101)
                    {
                        throw new IOException(string.Format(ErrorMessages.InvalidFifFile, path));
                    }

                    var entryTableOffset = ReadInt16(); // This is usually always 56
                    var entryCount       = ReadInt32();

                    // Check the file size and make sure it is expected size
                    if (source.Length != entryTableOffset + (entryCount * 16))
                    {
                        throw new IOException(string.Format(ErrorMessages.InvalidFifFile, path));
                    }

                    CharactersPerTexture = ReadInt32();
                    TextureCount         = ReadInt16();
                    Width            = ReadInt16();
                    Height           = ReadInt16();
                    LastWidth        = ReadInt16();
                    LastHeight       = ReadInt16();
                    CharactersPerRow = ReadInt16();
                    RowCount         = ReadInt16();
                    CharacterWidth   = ReadInt16();
                    CharacterHeight  = ReadInt16();
                    ColumnWidth      = ReadInt16();
                    RowHeight        = ReadInt16();

                    // The next value appears to always be equal to CharacterHeight
                    if (ReadInt16() != CharacterHeight)
                    {
                        throw new IOException(string.Format(ErrorMessages.InvalidFifFile, path));
                    }

                    // The next two bytes appear to be 32 and 1
                    if (!(reader.ReadByte() == 32 && reader.ReadByte() == 1))
                    {
                        throw new IOException(string.Format(ErrorMessages.InvalidFifFile, path));
                    }

                    source.Position = entryTableOffset;

                    Entries = new OrderedDictionary <char, FifEntry>(entryCount);

                    for (var i = 0; i < entryCount; i++)
                    {
                        var left      = ReadInt32();
                        var right     = ReadInt32();
                        var spacing   = ReadInt32();
                        var character = ReadChar();
                        var index     = ReadInt16();

                        // The final 2 bytes are the index of the character within the entry table
                        // If it's not equal to i, throw an exception.
                        if (index != i)
                        {
                            throw new IOException(string.Format(ErrorMessages.InvalidFifFile, path));
                        }

                        Entries.Add(character, new FifEntry
                        {
                            Left    = left,
                            Right   = right,
                            Spacing = spacing,
                        });
                    }
                }
        }