public void ToXXX()
        {
            var sut = new LittleEndianBitConverter();

            var data = new byte[] { 0x03, 0, 0, 0, 0, 0, 0, 0 };

            Check.That(sut.ToBoolean(data, 0)).IsTrue();
            Check.That(sut.ToBoolean(data, 7)).IsFalse();
            Check.That(sut.ToChar(data, 0)).IsEqualTo('\u0003');
            Check.That(sut.ToChar(data, 6)).IsEqualTo('\0');
            Check.That(sut.ToInt16(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt16(data, 6)).IsEqualTo(0);
            Check.That(sut.ToUInt16(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt16(data, 6)).IsEqualTo(0u);
            Check.That(sut.ToInt32(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt32(data, 4)).IsEqualTo(0);
            Check.That(sut.ToUInt32(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt32(data, 4)).IsEqualTo(0u);
            Check.That(sut.ToInt64(data, 0)).IsEqualTo(3L);
            Check.That(sut.ToUInt64(data, 0)).IsEqualTo(3UL);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x20, 0x41 };
            Check.That(sut.ToSingle(data, 0)).IsEqualTo(0.0f);
            Check.That(sut.ToSingle(data, 4)).IsEqualTo(10.0f);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x24, 0x40 };
            Check.That(sut.ToDouble(data, 0)).IsEqualTo(10.0);
        }
예제 #2
0
        public uint DecodeUint32(byte[] bytes, Iterator it)
        {
            uint value = bitConverter.ToUInt32(bytes, it.Offset);

            it.Offset += 4;
            return(value);
        }
예제 #3
0
파일: Class444.cs 프로젝트: 15831944/WW
        public unsafe uint imethod_44()
        {
            uint uint32;

            fixed(byte *pointer = this.byte_5)
            {
                this.method_1(pointer);
                uint32 = LittleEndianBitConverter.ToUInt32(this.byte_5);
            }

            return(uint32);
        }
        public void LittleEndianBitConverter_UInt32()
        {
            const int n = sizeof(UInt32);

            const UInt32 pos  = 0x11223344;
            const UInt32 zero = 0;

            var posRepr = new byte[] { 0x44, 0x33, 0x22, 0x11 };

            // --------------------------------------------------------------

            var buffer = new byte[n];

            LittleEndianBitConverter.FillBytes(pos, buffer);
            Assert.IsTrue(buffer.SequenceEqual(posRepr));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(pos).SequenceEqual(buffer));
            Assert.AreEqual(pos, LittleEndianBitConverter.ToUInt32(buffer));

            LittleEndianBitConverter.FillBytes(zero, buffer);
            Assert.IsTrue(buffer.SequenceEqual(new byte[n]));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(zero).SequenceEqual(buffer));
            Assert.AreEqual(zero, LittleEndianBitConverter.ToUInt32(buffer));
        }
예제 #5
0
 public static uint smethod_10(Stream stream)
 {
     byte[] numArray = new byte[4];
     stream.Read(numArray, 0, 4);
     return(LittleEndianBitConverter.ToUInt32(numArray, 0));
 }
예제 #6
0
파일: Class810.cs 프로젝트: 15831944/WW
        internal static Class895 smethod_0(string fontFileName)
        {
            lock (Class810.dictionary_0)
            {
                Class895 class895;
                if (Class810.dictionary_0.TryGetValue(fontFileName, out class895))
                {
                    return(class895);
                }
                Struct9  struct9  = new Struct9();
                Struct10 struct10 = new Struct10();
                Struct11 struct11 = new Struct11();
                Struct12 struct12 = new Struct12();
                string   path     = !Path.IsPathRooted(fontFileName) ? (!(Path.GetFileName(fontFileName) == fontFileName) ? fontFileName : Environment.ExpandEnvironmentVariables(Path.Combine("%WINDIR%\\Fonts", fontFileName))) : fontFileName;
                if (!File.Exists(path))
                {
                    return((Class895)null);
                }
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                try
                {
                    BinaryReader r       = new BinaryReader((Stream)fs);
                    byte[]       source1 = Class810.smethod_2(r.ReadBytes(Marshal.SizeOf((object)struct9)));
                    IntPtr       num1    = Marshal.AllocHGlobal(source1.Length);
                    Marshal.Copy(source1, 0, num1, source1.Length);
                    Struct9 structure1 = (Struct9)Marshal.PtrToStructure(num1, typeof(Struct9));
                    Marshal.FreeHGlobal(num1);
                    if (structure1.ushort_0 != (ushort)1 || structure1.ushort_1 != (ushort)0)
                    {
                        return((Class895)null);
                    }
                    bool     flag   = false;
                    Struct10 tbName = new Struct10();
                    for (int index = 0; index < (int)structure1.ushort_2; ++index)
                    {
                        byte[] source2 = r.ReadBytes(Marshal.SizeOf((object)struct10));
                        IntPtr num2    = Marshal.AllocHGlobal(source2.Length);
                        Marshal.Copy(source2, 0, num2, source2.Length);
                        tbName = (Struct10)Marshal.PtrToStructure(num2, typeof(Struct10));
                        Marshal.FreeHGlobal(num2);
                        string str = tbName.char_0.ToString() + tbName.char_1.ToString() + tbName.char_2.ToString() + tbName.char_3.ToString();
                        if (str != null && str.ToString() == "name")
                        {
                            flag = true;
                            byte[] bytes1 = LittleEndianBitConverter.GetBytes(tbName.uint_2);
                            byte[] bytes2 = LittleEndianBitConverter.GetBytes(tbName.uint_1);
                            Array.Reverse((Array)bytes1);
                            Array.Reverse((Array)bytes2);
                            tbName.uint_2 = LittleEndianBitConverter.ToUInt32(bytes1);
                            tbName.uint_1 = LittleEndianBitConverter.ToUInt32(bytes2);
                            break;
                        }
                    }
                    if (flag)
                    {
                        fs.Position = (long)tbName.uint_1;
                        byte[] source2 = Class810.smethod_2(r.ReadBytes(Marshal.SizeOf((object)struct11)));
                        IntPtr num2    = Marshal.AllocHGlobal(source2.Length);
                        Marshal.Copy(source2, 0, num2, source2.Length);
                        Struct11 structure2 = (Struct11)Marshal.PtrToStructure(num2, typeof(Struct11));
                        Marshal.FreeHGlobal(num2);
                        class895 = new Class895();
                        for (int index = 0; index < (int)structure2.ushort_1; ++index)
                        {
                            byte[] source3 = Class810.smethod_2(r.ReadBytes(Marshal.SizeOf((object)struct12)));
                            IntPtr num3    = Marshal.AllocHGlobal(source3.Length);
                            Marshal.Copy(source3, 0, num3, source3.Length);
                            Struct12 structure3 = (Struct12)Marshal.PtrToStructure(num3, typeof(Struct12));
                            Marshal.FreeHGlobal(num3);
                            if (structure3.ushort_0 == (ushort)3 && structure3.ushort_2 == (ushort)1033)
                            {
                                switch (structure3.ushort_3)
                                {
                                case 1:
                                    class895.FamilyName = Class810.smethod_1(fs, r, ref tbName, ref structure2, ref structure3);
                                    continue;

                                case 2:
                                    class895.SubFamilyName = Class810.smethod_1(fs, r, ref tbName, ref structure2, ref structure3);
                                    continue;

                                case 3:
                                    class895.UniqueFontIdentifier = Class810.smethod_1(fs, r, ref tbName, ref structure2, ref structure3);
                                    continue;

                                case 4:
                                    class895.FullFontName = Class810.smethod_1(fs, r, ref tbName, ref structure2, ref structure3);
                                    continue;

                                default:
                                    continue;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    fs.Close();
                }
                if (class895 != null)
                {
                    class895.FullFilename = path;
                    Class810.dictionary_0[fontFileName] = class895;
                }
                return(class895);
            }
        }
예제 #7
0
 public virtual uint vmethod_10()
 {
     byte[] numArray = new byte[4];
     this.stream_0.Read(numArray, 0, 4);
     return(LittleEndianBitConverter.ToUInt32(numArray));
 }
예제 #8
0
        private void DispatchPacket(AgarPacket p)
        {
            Console.WriteLine("Received {0} packet with {1} bytes of data.", (ServerPacketType)p.OpCode, p.Payload.Length);

            switch ((ServerPacketType)p.OpCode)
            {
            case ServerPacketType.GameAreaSize:
                // TODO Assert PayloadLength == 32
                double min_x = bc.ToDouble(p.Payload, 0);
                double min_y = bc.ToDouble(p.Payload, 8);
                double max_x = bc.ToDouble(p.Payload, 16);
                double max_y = bc.ToDouble(p.Payload, 24);
                world.SetBounds(min_x, min_y, max_x, max_y);
                break;

            case ServerPacketType.WorldUpdate:
                // Read eat events
                uint       count = bc.ToUInt16(p.Payload, 0);
                EatEvent[] eats  = new EatEvent[count];
                for (int i = 0; i < count; i++)
                {
                    eats[i] = new EatEvent()
                    {
                        eater_id  = bc.ToUInt32(p.Payload, i * 8),
                        victim_id = bc.ToUInt32(p.Payload, i * 8 + 4)
                    };
                }

                // Read cell updates (names, size, position)
                List <UpdateEvent> updates = new List <UpdateEvent>();
                UpdateEvent        current;
                int offset = 0;

                while (true)
                {
                    current.blob_id = bc.ToUInt32(p.Payload, offset);
                    if (current.blob_id == 0)
                    {
                        break;
                    }

                    current.x = bc.ToUInt32(p.Payload, offset + 4);
                    current.y = bc.ToUInt32(p.Payload, offset + 8);

                    current.radius = bc.ToUInt16(p.Payload, offset + 10);
                    current.red    = p.Payload[offset + 11];
                    current.green  = p.Payload[offset + 12];
                    current.blue   = p.Payload[offset + 13];
                    current.flags  = p.Payload[offset + 14];

                    if ((current.flags & 0x02) != 0)
                    {
                        offset += 4;         // Unsure about this...
                    }
                    current.skin_url = null; // Just to fully initialize the struct

                    if ((current.flags & 0x04) != 0)
                    {
                        current.skin_url = bc.ToNullStr8(p.Payload, offset + 15, ref offset);     // Will increment offset by num bytes
                    }
                    current.name = bc.ToNullStr16(p.Payload, offset + 15, ref offset);

                    updates.Add(current);
                }

                // Read cell removals (out of sight, disconnect, etc)
                count = bc.ToUInt32(p.Payload, offset + 15);
                uint[] removals = new uint[count];
                for (int i = 0; i < count; i++)
                {
                    removals[i] = bc.ToUInt32(p.Payload, offset + 17 + i * 4);
                }

                world.RegisterEats(eats);
                world.RegisterUpdates(updates);
                world.RegisterRemovals(removals);

                break;

            case ServerPacketType.FFALeaderboard:
                count  = bc.ToUInt32(p.Payload, 0);
                offset = 4;
                for (uint i = 0; i < count; i++)
                {
                    uint   blob_id = bc.ToUInt32(p.Payload, offset); offset += 4;
                    string name    = bc.ToNullStr16(p.Payload, offset, ref offset);

                    // We got the data, add it to a list or something. TODO create a leaderboard class
                }
                break;
            }
        }