public SpellRadius(MainWindow window, SpellDBC theSpellDBC)
        {
            main = window;
            spell = theSpellDBC;

            if (!File.Exists("SpellRadius.dbc"))
            {
                main.ERROR_STR = "SpellRadius.dbc was not found!";
                return;
            }

            FileStream fs = new FileStream("SpellRadius.dbc", FileMode.Open);
            // Read header
            int count = Marshal.SizeOf(typeof(SpellDBC_Header));
            byte[] readBuffer = new byte[count];
            BinaryReader reader = new BinaryReader(fs);
            readBuffer = reader.ReadBytes(count);
            GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
            header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
            handle.Free();

            body.records = new SpellRadiusRecord[header.record_count];
            // Read body
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                count = Marshal.SizeOf(typeof(SpellRadiusRecord));
                readBuffer = new byte[count];
                reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                body.records[i] = (SpellRadiusRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellRadiusRecord));
                handle.Free();
            }

            reader.Close();
            fs.Close();

            body.lookup = new List<RadiusLookup>();

            main.RadiusIndex1.Items.Add("0 - 0");
            main.RadiusIndex2.Items.Add("0 - 0");
            main.RadiusIndex3.Items.Add("0 - 0");

            int boxIndex = 1;
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                RadiusLookup temp;

                temp.ID = (int)body.records[i].ID;
                temp.comboBoxIndex = boxIndex;

                main.RadiusIndex1.Items.Add(body.records[i].radius + " - " + body.records[i].maxRadius);
                main.RadiusIndex2.Items.Add(body.records[i].radius + " - " + body.records[i].maxRadius);
                main.RadiusIndex3.Items.Add(body.records[i].radius + " - " + body.records[i].maxRadius);

                body.lookup.Add(temp);

                boxIndex++;
            }
        }
        public Task loadImages()
        {
            return (new TaskFactory()).StartNew(() =>
            {
                if (!File.Exists("SpellIcon.dbc"))
                {
                    main.ERROR_STR = "SpellIcon.dbc was not found!";
                    return;
                }   

                FileStream fs = new FileStream("SpellIcon.dbc", FileMode.Open);
                // Read header
                int count = Marshal.SizeOf(typeof(SpellDBC_Header));
                byte[] readBuffer = new byte[count];
                BinaryReader reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
                handle.Free();

                body.records = new IconDBC_Record[header.record_count];
                // Read body
                for (UInt32 i = 0; i < header.record_count; ++i)
                {
                    count = Marshal.SizeOf(typeof(IconDBC_Record));
                    readBuffer = new byte[count];
                    reader = new BinaryReader(fs);
                    readBuffer = reader.ReadBytes(count);
                    handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                    body.records[i] = (IconDBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(IconDBC_Record));
                    handle.Free();
                }

                body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.string_block_size));

                reader.Close();
                fs.Close();

                updateMainWindowIcons();
            }); 
        }
Beispiel #3
0
        public bool loadDBCFile(string fileName)
        {
            try
            {
                FileStream fs = new FileStream(fileName, FileMode.Open);
                FileSize = fs.Length;

                // Read header
                int count = Marshal.SizeOf(typeof(SpellDBC_Header));
                byte[] readBuffer = new byte[count];
                BinaryReader reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
                handle.Free();

                // Prepare body
                body.records = new SpellDBC_RecordMap[header.record_count];

                // Read body
                for (UInt32 i = 0; i < header.record_count; ++i)
                {
                    count = Marshal.SizeOf(typeof(SpellDBC_Record));
                    readBuffer = new byte[count];
                    readBuffer = reader.ReadBytes(count);
                    handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                    body.records[i].record = (SpellDBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Record));
                    handle.Free();
                }

                string string_block;
                Dictionary<UInt32, VirtualStrTableEntry> strings = new Dictionary<UInt32, VirtualStrTableEntry>();;

                // Read string block
                string_block = Encoding.UTF8.GetString(reader.ReadBytes(header.string_block_size));

                // Turn the string block into something readable
                string temp = "";
                UInt32 lastString = 0;
                //for (UInt32 i = 0; i < header.string_block_size; ++i)
                UInt32 counter = 0;
                Int32 length = new System.Globalization.StringInfo(string_block).LengthInTextElements;
                while (counter < length)
                {
                    var t = string_block[(int)counter];
                    if (t == '\0')
                    {
                        VirtualStrTableEntry n = new VirtualStrTableEntry();
                        n.value = temp;
                        n.newValue = 0;
                        strings.Add(lastString, n);
                        lastString += (UInt32) Encoding.UTF8.GetByteCount(temp) + 1;
                        temp = "";
                    }
                    else
                    {
                        temp += t;
                    }
                    ++counter;
                }

                // Clean up for bad computers GC
                string_block = null;

                for (int i = 0; i < body.records.Length; ++i)
                {
                    body.records[i].spellName = new string[9];
                    body.records[i].spellRank = new string[9];
                    body.records[i].spellDesc = new string[9];
                    body.records[i].spellTool = new string[9];
                    for (int j = 0; j < 9; ++j)
                    {
                        body.records[i].spellName[j] = strings[body.records[i].record.SpellName[j]].value;
                        body.records[i].spellRank[j] = strings[body.records[i].record.Rank[j]].value;
                        body.records[i].spellDesc[j] = strings[body.records[i].record.Description[j]].value;
                        body.records[i].spellTool[j] = strings[body.records[i].record.ToolTip[j]].value;
                    }
                }

                reader.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }

            return true;
        }
        public SpellDispelType(MainWindow window, SpellDBC theSpellDBC)
        {
            main = window;
            spell = theSpellDBC;

            if (!File.Exists("SpellDispelType.dbc"))
            {
                main.ERROR_STR = "SpellDispelType.dbc was not found!";
                return;
            }

            FileStream fs = new FileStream("SpellDispelType.dbc", FileMode.Open);
            // Read header
            int count = Marshal.SizeOf(typeof(SpellDBC_Header));
            byte[] readBuffer = new byte[count];
            BinaryReader reader = new BinaryReader(fs);
            readBuffer = reader.ReadBytes(count);
            GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
            header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
            handle.Free();

            body.records = new DispelDBC_Record[header.record_count];
            // Read body
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                count = Marshal.SizeOf(typeof(DispelDBC_Record));
                readBuffer = new byte[count];
                reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                body.records[i] = (DispelDBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DispelDBC_Record));
                handle.Free();
            }

            body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.string_block_size));

            reader.Close();
            fs.Close();

            int boxIndex = 0;

            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                int offset = (int)body.records[i].Name[0];
                if (offset == 0)
                    continue;
                int returnValue = offset;
                string toAdd = "";
                while (body.StringBlock[offset] != '\0')
                    toAdd += body.StringBlock[offset++];

                // Index to ID
                IndexToIDMap.Add(boxIndex, body.records[i].ID);
                // Hash to index
                stringHashMap.Add(toAdd.GetHashCode(), boxIndex++);
                // Offset to hash
                offsetHashMap.Add(returnValue, toAdd.GetHashCode());
                // Add to box
                main.DispelType.Items.Add(toAdd);
            }
        }
        public SpellRange(MainWindow window, SpellDBC theSpellDBC)
        {
            main = window;
            spell = theSpellDBC;

            if (!File.Exists("SpellRange.dbc"))
            {
                main.ERROR_STR = "SpellRange.dbc was not found!";
                return;
            }

            FileStream fs = new FileStream("SpellRange.dbc", FileMode.Open);
            // Read header
            int count = Marshal.SizeOf(typeof(SpellDBC_Header));
            byte[] readBuffer = new byte[count];
            BinaryReader reader = new BinaryReader(fs);
            readBuffer = reader.ReadBytes(count);
            GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
            header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
            handle.Free();

            body.records = new SpellRangeDBC_Record[header.record_count];
            // Read body
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                count = Marshal.SizeOf(typeof(SpellRangeDBC_Record));
                readBuffer = new byte[count];
                reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                body.records[i] = (SpellRangeDBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellRangeDBC_Record));
                handle.Free();
            }

            body.StringBlock = reader.ReadBytes(header.string_block_size);

            reader.Close();
            fs.Close();

            body.lookup = new List<SpellRange_Lookup>();
            int boxIndex = 0;

            int locale = 0;
            // Attempt to get the nearest locality
            for (int i = 0; i < 9; ++i)
            {
                if (body.records[0].Name[i] > 0)
                {
                    locale = i;
                    break;
                }
            }

            List<byte> bytes = new List<byte>();
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                int offset = (int)body.records[i].Name[locale];
                if (offset == 0)
                    continue;
                int returnValue = offset;

                while (body.StringBlock[offset] != 0)
                    bytes.Add(body.StringBlock[offset++]);

                string toAdd = body.records[i].ID + " - ";
                toAdd += Encoding.UTF8.GetString(bytes.ToArray<byte>());

                bytes.Clear();

                SpellRange_Lookup temp;
                temp.ID = (int)body.records[i].ID;
                temp.comboBoxIndex = boxIndex;

                main.SpellRange.Items.Add(toAdd);

                body.lookup.Add(temp);

                boxIndex++;
            }
        }
        public SpellMechanic(MainWindow window, SpellDBC theSpellDBC)
        {
            main = window;
            spell = theSpellDBC;

            if (!File.Exists("SpellMechanic.dbc"))
            {
                main.ERROR_STR = "SpellMechanic.dbc was not found!";
                return;
            }

            FileStream fs = new FileStream("SpellMechanic.dbc", FileMode.Open);
            // Read header
            int count = Marshal.SizeOf(typeof(SpellDBC_Header));
            byte[] readBuffer = new byte[count];
            BinaryReader reader = new BinaryReader(fs);
            readBuffer = reader.ReadBytes(count);
            GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
            header = (SpellDBC_Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SpellDBC_Header));
            handle.Free();

            body.records = new MechanicDBC_Record[header.record_count];
            // Read body
            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                count = Marshal.SizeOf(typeof(MechanicDBC_Record));
                readBuffer = new byte[count];
                reader = new BinaryReader(fs);
                readBuffer = reader.ReadBytes(count);
                handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                body.records[i] = (MechanicDBC_Record)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(MechanicDBC_Record));
                handle.Free();
            }

            body.StringBlock = Encoding.UTF8.GetString(reader.ReadBytes(header.string_block_size));

            reader.Close();
            fs.Close();

            body.lookup = new List<MechanicLookup>();
            int boxIndex = 1;

            main.MechanicType.Items.Add("None");
            MechanicLookup t;
            t.ID = 0;
            t.offset = 0;
            t.stringHash = "None".GetHashCode();
            t.comboBoxIndex = 0;
            body.lookup.Add(t);

            for (UInt32 i = 0; i < header.record_count; ++i)
            {
                int offset = (int)body.records[i].Name[0];
                if (offset == 0)
                    continue;
                int returnValue = offset;
                string toAdd = "";
                while (body.StringBlock[offset] != '\0')
                    toAdd += body.StringBlock[offset++];

                MechanicLookup temp;

                temp.ID = (int)body.records[i].ID;
                temp.stringHash = toAdd.GetHashCode();
                temp.offset = returnValue;
                temp.comboBoxIndex = boxIndex;

                main.MechanicType.Items.Add(toAdd);

                body.lookup.Add(temp);

                boxIndex++;
            }
        }