ReadBitsLittleEndian() public method

public ReadBitsLittleEndian ( int length ) : Int32
length int
return System.Int32
Beispiel #1
0
        protected void NpcAssignment(byte type, List<byte> data)
        {
            byte[] packet = data.ToArray();
            NpcEntity output;
            //try
            //{
                BitReader br = new BitReader(data.ToArray());
                br.ReadBitsLittleEndian(8);
                UInt32 id = (uint)br.Read(32);
                UInt16 npctype = (ushort)br.Read(16);
                UInt16 x = (ushort)br.Read(16);
                UInt16 y = (ushort)br.Read(16);
                byte life = (byte)br.Read(8);
                byte size = (byte)br.Read(8);

                output = new NpcEntity(id, npctype, life, x, y);

                if(ClientlessBot.debugging)
                    Console.WriteLine("NPC id: {3}, Type: {0:X}, Life: {1:X}, Size: {2:X}", npctype, life, data.Count, id);

                int informationLength = 16;

                String[] entries;

                if (!m_owner.m_dm.m_monsterFields.Get(npctype, out entries))
                    Console.WriteLine("Failed to read monstats data for NPC of type {0}", type);
                if(entries.Length != informationLength)
                    Console.WriteLine("Invalid monstats entry for NPC of type {0}", type);

                bool lookupName = false;

                if (data.Count > 0x10)
                {
                    br.Read(4);
                    if (br.ReadBit())
                    {
                        for (int i = 0; i < informationLength; i++)
                        {
                            int temp;

                            int value = Int32.Parse(entries[i]);

                            if (!BitScanReverse(out temp, (uint)value - 1))
                                temp = 0;
                            if (temp == 31)
                                temp = 0;

                            //Console.WriteLine("BSR: {0} Bitcount: {1}", temp+1, bitCount);
                            int bits = br.Read(temp+1);
                        }
                    }

                    output.SuperUnique = false;

                    output.HasFlags = br.ReadBit();
                    if (output.HasFlags)
                    {
                        output.Champion = br.ReadBit();
                        output.Unique = br.ReadBit();
                        output.SuperUnique = br.ReadBit();
                        output.IsMinion = br.ReadBit();
                        output.Ghostly = br.ReadBit();
                        //Console.WriteLine("{0} {1} {2} {3} {4}", output.Champion, output.Unique, output.SuperUnique, output.IsMinion, output.Ghostly);
                    }

                    if (output.SuperUnique)
                    {
                        output.SuperUniqueId = br.ReadBitsLittleEndian(16);
                        String name;
                        if (!m_owner.m_dm.m_superUniques.Get(output.SuperUniqueId, out name))
                        {
                            Console.WriteLine("Failed to lookup super unique monster name for {0}", output.SuperUniqueId);
                            output.Name = "invalid";
                        }
                        else
                        {
                            output.Name = name;
                            //Console.WriteLine("NPC: {0}", name);
                        }
                    }
                    else
                        lookupName = true;

                    if (data.Count > 17 && lookupName != true && output.Name != "invalid")
                    {
                        output.IsLightning = false;
                        while (true)
                        {
                            byte mod = (byte)br.ReadBitsLittleEndian(8);
                            if (mod == 0)
                                break;
                            if (mod == 0x11)
                                output.IsLightning = true;
                        }
                    }
                }
                else
                    lookupName = true;

                if (lookupName)
                {
                    String name;
                    if (!m_owner.m_dm.m_monsterNames.Get((int)output.Type, out name))
                        Console.WriteLine("Failed to Look up monster name for {0}", output.Type);
                    else
                        output.Name = name;

                    //Console.WriteLine("NPC: {0}", name);
                }

                NpcEntity tempnpc;
                if (m_owner.BotGameData.Npcs.TryGetValue(id, out tempnpc))
                    m_owner.BotGameData.Npcs[id] = output;
                else
                    m_owner.BotGameData.Npcs.Add(id, output);

               // }
               // catch
               // {

               // }
        }
Beispiel #2
0
        protected void NpcAssignment(byte type, List <byte> data)
        {
            byte[]    packet = data.ToArray();
            NpcEntity output;
            //try
            //{
            BitReader br = new BitReader(data.ToArray());

            br.ReadBitsLittleEndian(8);
            UInt32 id      = (uint)br.Read(32);
            UInt16 npctype = (ushort)br.Read(16);
            UInt16 x       = (ushort)br.Read(16);
            UInt16 y       = (ushort)br.Read(16);
            byte   life    = (byte)br.Read(8);
            byte   size    = (byte)br.Read(8);

            output = new NpcEntity(id, npctype, life, x, y);

            if (ClientlessBot.debugging)
            {
                Console.WriteLine("NPC id: {3}, Type: {0:X}, Life: {1:X}, Size: {2:X}", npctype, life, data.Count, id);
            }

            int informationLength = 16;

            String[] entries;

            if (!m_owner.m_dm.m_monsterFields.Get(npctype, out entries))
            {
                Console.WriteLine("Failed to read monstats data for NPC of type {0}", type);
            }
            if (entries.Length != informationLength)
            {
                Console.WriteLine("Invalid monstats entry for NPC of type {0}", type);
            }

            bool lookupName = false;

            if (data.Count > 0x10)
            {
                br.Read(4);
                if (br.ReadBit())
                {
                    for (int i = 0; i < informationLength; i++)
                    {
                        int temp;

                        int value = Int32.Parse(entries[i]);

                        if (!BitScanReverse(out temp, (uint)value - 1))
                        {
                            temp = 0;
                        }
                        if (temp == 31)
                        {
                            temp = 0;
                        }

                        //Console.WriteLine("BSR: {0} Bitcount: {1}", temp+1, bitCount);
                        int bits = br.Read(temp + 1);
                    }
                }

                output.SuperUnique = false;

                output.HasFlags = br.ReadBit();
                if (output.HasFlags)
                {
                    output.Champion    = br.ReadBit();
                    output.Unique      = br.ReadBit();
                    output.SuperUnique = br.ReadBit();
                    output.IsMinion    = br.ReadBit();
                    output.Ghostly     = br.ReadBit();
                    //Console.WriteLine("{0} {1} {2} {3} {4}", output.Champion, output.Unique, output.SuperUnique, output.IsMinion, output.Ghostly);
                }

                if (output.SuperUnique)
                {
                    output.SuperUniqueId = br.ReadBitsLittleEndian(16);
                    String name;
                    if (!m_owner.m_dm.m_superUniques.Get(output.SuperUniqueId, out name))
                    {
                        Console.WriteLine("Failed to lookup super unique monster name for {0}", output.SuperUniqueId);
                        output.Name = "invalid";
                    }
                    else
                    {
                        output.Name = name;
                        //Console.WriteLine("NPC: {0}", name);
                    }
                }
                else
                {
                    lookupName = true;
                }

                if (data.Count > 17 && lookupName != true && output.Name != "invalid")
                {
                    output.IsLightning = false;
                    while (true)
                    {
                        byte mod = (byte)br.ReadBitsLittleEndian(8);
                        if (mod == 0)
                        {
                            break;
                        }
                        if (mod == 0x11)
                        {
                            output.IsLightning = true;
                        }
                    }
                }
            }
            else
            {
                lookupName = true;
            }

            if (lookupName)
            {
                String name;
                if (!m_owner.m_dm.m_monsterNames.Get((int)output.Type, out name))
                {
                    Console.WriteLine("Failed to Look up monster name for {0}", output.Type);
                }
                else
                {
                    output.Name = name;
                }

                //Console.WriteLine("NPC: {0}", name);
            }

            NpcEntity tempnpc;

            if (m_owner.BotGameData.Npcs.TryGetValue(id, out tempnpc))
            {
                m_owner.BotGameData.Npcs[id] = output;
            }
            else
            {
                m_owner.BotGameData.Npcs.Add(id, output);
            }


            // }
            // catch
            // {

            // }
        }