private static void InitFloors(GraphicsDevice gd)
        {
            m_Floors = new List<Floor>();

            string floors1dat = GlobalSettings.Default.StartupPath + "housedata\\floors\\floors.far";
            string floors2dat = GlobalSettings.Default.StartupPath + "housedata\\floors2\\floors2.far";
            string floors3dat = GlobalSettings.Default.StartupPath + "housedata\\floors3\\floors3.far";
            string floors4dat = GlobalSettings.Default.StartupPath + "housedata\\floors4\\floors4.far";
            string floors5iff = GlobalSettings.Default.StartupPath + "objectdata\\globals\\floors.iff";
            string floors5Namesiff = GlobalSettings.Default.StartupPath + "objectdata\\globals\\build.iff";

            FARArchive floors1 = new FARArchive(floors1dat);
            FARArchive floors2 = new FARArchive(floors2dat);
            FARArchive floors3 = new FARArchive(floors3dat);
            FARArchive floors4 = new FARArchive(floors4dat);
            Iff floors5        = new Iff       (File.OpenRead(floors5iff));
            Iff floors5names   = new Iff       (File.OpenRead(floors5Namesiff));

            // Load the first floor data
            List<KeyValuePair<string, byte[]>> floors = floors1.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in floors)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;

                lock (m_Floors)
                {
                    m_Floors.Add(new Floor(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[] {flr.SPR2s.Find(delegate (SPR2Parser sp) {
                            return sp.ID == 1; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 257; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 513; }).GetFrame(0).BitmapData.BitMap},
                        gd, flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the second floor data
            floors = floors2.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in floors)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;

                lock (m_Floors)
                {
                    m_Floors.Add(new Floor(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[] {flr.SPR2s.Find(delegate (SPR2Parser sp)
                        { return sp.ID == 1; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 257; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 513; }).GetFrame(0).BitmapData.BitMap},
                        gd, flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the third floor data
            floors = floors3.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in floors)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;

                lock (m_Floors)
                {
                    m_Floors.Add(new Floor(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[] { flr.SPR2s.Find(delegate (SPR2Parser sp)
                        { return sp.ID == 1; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 257; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 513; }).GetFrame(0).BitmapData.BitMap},
                        gd, flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the fourth floor data
            floors = floors4.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in floors)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;

                lock (m_Floors)
                {
                    m_Floors.Add(new Floor(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[] {
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 1; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 257; }).GetFrame(0).BitmapData.BitMap,
                    flr.SPR2s.Find(delegate (SPR2Parser sp) { return sp.ID == 513; }).GetFrame(0).BitmapData.BitMap},
                        gd, flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            for (int i = 1; i < 30; i++)
            {
                Bitmap[] frames = new Bitmap[3];

                string spriteName = floors5.SPR2s[i].Name;
                frames[0] = floors5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i; }).GetFrame(0).BitmapData.BitMap;
                frames[1] = floors5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i + 256; }).GetFrame(0).BitmapData.BitMap;
                frames[2] = floors5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i + 512; }).GetFrame(0).BitmapData.BitMap;

                string price = floors5names.StringTables[2].StringSets[0].Strings[(i - 1) * 3].Str;
                string title = floors5names.StringTables[2].StringSets[0].Strings[(i - 1) * 3 + 1].Str;
                string description = floors5names.StringTables[2].StringSets[0].Strings[(i - 1) * 3 + 2].Str;

                m_Floors.Add(new Floor(title, price, description, frames, gd, spriteName));
            }

            myLoadingScreenEWH.Set();
        }
        private static void InitWalls(GraphicsDevice gd)
        {
            m_Walls = new List<Wall>();

            string walls1dat = GlobalSettings.Default.StartupPath + "housedata\\walls\\walls.far";
            string walls2dat = GlobalSettings.Default.StartupPath + "housedata\\walls2\\walls2.far";
            string walls3dat = GlobalSettings.Default.StartupPath + "housedata\\walls3\\walls3.far";
            string walls4dat = GlobalSettings.Default.StartupPath + "housedata\\walls4\\walls4.far";
            string walls5iff = GlobalSettings.Default.StartupPath + "objectdata\\globals\\walls.iff";
            string walls5Namesiff = GlobalSettings.Default.StartupPath + "objectdata\\globals\\build.iff";

            FARArchive walls1 = new FARArchive(walls1dat);
            FARArchive walls2 = new FARArchive(walls2dat);
            FARArchive walls3 = new FARArchive(walls3dat);
            FARArchive walls4 = new FARArchive(walls4dat);
            Iff walls5 = new Iff(File.OpenRead(walls5iff));
            Iff walls5names = new Iff(File.OpenRead(walls5Namesiff));

            // Load the first wall data
            List<KeyValuePair<string, byte[]>> walls = walls1.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in walls)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;
                SPR2Parser spr1 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; });
                SPR2Parser spr2 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1793; });
                SPR2Parser spr3 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 2049; });

                lock (m_Walls)
                {
                    m_Walls.Add(new Wall(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[,] {{spr1.GetFrame(0).BitmapData.BitMap, spr1.GetFrame(1).BitmapData.BitMap,
                    spr1.GetFrame(2).BitmapData.BitMap, spr1.GetFrame(3).BitmapData.BitMap}, {spr2.GetFrame(0).BitmapData.BitMap,
                    spr2.GetFrame(1).BitmapData.BitMap, spr2.GetFrame(2).BitmapData.BitMap, spr2.GetFrame(3).BitmapData.BitMap},
                    {spr3.GetFrame(0).BitmapData.BitMap, spr3.GetFrame(1).BitmapData.BitMap, spr3.GetFrame(2).BitmapData.BitMap,
                    spr3.GetFrame(3).BitmapData.BitMap} }, gd,
                        flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the second wall data
            walls = walls2.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in walls)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;
                SPR2Parser spr1 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; });
                SPR2Parser spr2 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1793; });
                SPR2Parser spr3 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 2049; });

                lock (m_Walls)
                {
                    m_Walls.Add(new Wall(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[,] {{spr1.GetFrame(0).BitmapData.BitMap, spr1.GetFrame(1).BitmapData.BitMap,
                    spr1.GetFrame(2).BitmapData.BitMap, spr1.GetFrame(3).BitmapData.BitMap}, {spr2.GetFrame(0).BitmapData.BitMap,
                    spr2.GetFrame(1).BitmapData.BitMap, spr2.GetFrame(2).BitmapData.BitMap, spr2.GetFrame(3).BitmapData.BitMap},
                    {spr3.GetFrame(0).BitmapData.BitMap, spr3.GetFrame(1).BitmapData.BitMap, spr3.GetFrame(2).BitmapData.BitMap,
                    spr3.GetFrame(3).BitmapData.BitMap} }, gd,
                        flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the third wall data
            walls = walls3.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in walls)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;
                SPR2Parser spr1 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; });
                SPR2Parser spr2 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1793; });
                SPR2Parser spr3 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 2049; });

                lock (m_Walls)
                {
                    m_Walls.Add(new Wall(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[,] {{spr1.GetFrame(0).BitmapData.BitMap, spr1.GetFrame(1).BitmapData.BitMap,
                    spr1.GetFrame(2).BitmapData.BitMap, spr1.GetFrame(3).BitmapData.BitMap}, {spr2.GetFrame(0).BitmapData.BitMap,
                    spr2.GetFrame(1).BitmapData.BitMap, spr2.GetFrame(2).BitmapData.BitMap, spr2.GetFrame(3).BitmapData.BitMap},
                    {spr3.GetFrame(0).BitmapData.BitMap, spr3.GetFrame(1).BitmapData.BitMap, spr3.GetFrame(2).BitmapData.BitMap,
                    spr3.GetFrame(3).BitmapData.BitMap} }, gd,
                        flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            // Load the fourth wall data
            walls = walls4.GetAllEntries();
            foreach (KeyValuePair<string, byte[]> kvp in walls)
            {
                Iff flr;

                if (kvp.Key.Contains("iff") || kvp.Key.Contains("spf"))
                    flr = new Iff(new MemoryStream(kvp.Value));
                else
                    flr = new Iff(new MemoryStream(kvp.Value));

                List<StringTableString> catalogInfo = (flr.StringTables[0].StringSets.Count > 0) ? flr.StringTables[0].StringSets[0].Strings : flr.StringTables[0].Strings;
                SPR2Parser spr1 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; });
                SPR2Parser spr2 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1793; });
                SPR2Parser spr3 = flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 2049; });

                lock (m_Walls)
                {
                    m_Walls.Add(new Wall(catalogInfo[0].Str, catalogInfo[1].Str, catalogInfo[2].Str,
                        new Bitmap[,] {{spr1.GetFrame(0).BitmapData.BitMap, spr1.GetFrame(1).BitmapData.BitMap,
                    spr1.GetFrame(2).BitmapData.BitMap, spr1.GetFrame(3).BitmapData.BitMap}, {spr2.GetFrame(0).BitmapData.BitMap,
                    spr2.GetFrame(1).BitmapData.BitMap, spr2.GetFrame(2).BitmapData.BitMap, spr2.GetFrame(3).BitmapData.BitMap},
                    {spr3.GetFrame(0).BitmapData.BitMap, spr3.GetFrame(1).BitmapData.BitMap, spr3.GetFrame(2).BitmapData.BitMap,
                    spr3.GetFrame(3).BitmapData.BitMap} }, gd,
                        flr.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == 1; }).Name));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            int numActualWalls = 0;
            for (int i = 2; i < 31; i++)
            {
                Bitmap[,] frames = new Bitmap[3, 4];

                string spriteName = walls5.SPR2s[i].Name;
                SPR2Parser spr1 = walls5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i; });
                SPR2Parser spr2 = walls5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i + 1792; });
                SPR2Parser spr3 = walls5.SPR2s.Find(delegate(SPR2Parser sp) { return sp.ID == i + 2048; });

                if (spr1 != null && spr2 != null && spr3 != null && !(i >= 3 && i <= 9) && !(i >= 18 && i <= 532) &&
                    !(i >= 548 && i <= 1047) && !(i >= 1543 && i <= 1554) && !(i >= 1557 && i <= 2049))
                {
                    numActualWalls++;
                    frames = new Bitmap[,] {
                {spr1.GetFrame(0).BitmapData.BitMap, spr1.GetFrame(1).BitmapData.BitMap, spr1.GetFrame(2).BitmapData.BitMap, spr1.GetFrame(3).BitmapData.BitMap},
                {spr2.GetFrame(0).BitmapData.BitMap, spr2.GetFrame(1).BitmapData.BitMap, spr2.GetFrame(2).BitmapData.BitMap, spr2.GetFrame(3).BitmapData.BitMap},
                {spr3.GetFrame(0).BitmapData.BitMap, spr3.GetFrame(1).BitmapData.BitMap, spr3.GetFrame(2).BitmapData.BitMap, spr3.GetFrame(3).BitmapData.BitMap} };

                    string price = walls5names.StringTables[6].StringSets[0].Strings[(numActualWalls - 1) * 3].Str;
                    string title = walls5names.StringTables[6].StringSets[0].Strings[(numActualWalls - 1) * 3 + 1].Str;
                    string description = walls5names.StringTables[6].StringSets[0].Strings[(numActualWalls - 1) * 3 + 2].Str;

                    m_Walls.Add(new Wall(title, price, description, frames, gd, spriteName));
                }
            }

            LuaInterfaceManager.CallFunction("UpdateLoadingscreen");

            //m_Walls.Sort(delegate(Wall f1, Wall f2) { return f1.FloorName.CompareTo(f2.FloorName); });
        }
        /// <summary>
        /// This function searches through all the IFFs in the game to
        /// find chunks of the type specified by the user.
        /// </summary>
        private void ScanIFFs()
        {
            string ObjDataPath = "", HouseDataPath = "";
            bool LookingForSprites = false;

            if (m_TSOPath != "" || TxtTSOPath.Text != "")
            {
                if (TxtChunkType.Text != "")
                {
                    if(TxtChunkType.Text.Contains("SPR#") || TxtChunkType.Text.Contains("SPR2") || 
                        TxtChunkType.Text.Contains("DGRP"))
                        LookingForSprites = true;

                    string[] Dirs = Directory.GetDirectories(m_TSOPath);

                    foreach (string Dir in Dirs)
                    {
                        if (Dir.Contains("objectdata"))
                            ObjDataPath = Dir;

                        if (Dir.Contains("housedata"))
                            HouseDataPath = Dir;
                    }

                    string[] ObjDataDirs = Directory.GetDirectories(ObjDataPath);
                    string[] HouseDataDirs = Directory.GetDirectories(HouseDataPath);

                    foreach (string Dir in ObjDataDirs)
                    {
                        string[] Files = Directory.GetFiles(Dir);

                        foreach (string ArchivePath in Files)
                        {
                            if (ArchivePath.Contains(".far"))
                            {
                                FARArchive Archive = new FARArchive(ArchivePath);
                                List<KeyValuePair<string, byte[]>> ArchiveFiles = Archive.GetAllEntries();

                                foreach (KeyValuePair<string, byte[]> ArchiveFile in ArchiveFiles)
                                {
                                    if (!LookingForSprites)
                                    {
                                        //Skip the OTFs in 'objotf.far'...
                                        if (ArchiveFile.Key.Contains(".iff"))
                                        {
                                            Iff IffFile;
                                            List<IffChunk> Chunks = new List<IffChunk>();
                                            int NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            else
                                                IffFile = new Iff(ArchiveFile.Value);

                                            //Figure out how many chunks of the type being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                    NumChunks++;
                                            }

                                            List<IffInfo> InfoList = new List<IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName = ArchiveFile.Key;
                                                    Info.NumChunks = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                    else
                                    {
                                        Iff IffFile;
                                        int NumChunks = 0;

                                        if (ArchiveFile.Key.Contains(".spf") || ArchiveFile.Key.Contains(".wll") || ArchiveFile.Key.Contains(".flr"))
                                        {
                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            else
                                                IffFile = new Iff(ArchiveFile.Value);

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                    NumChunks++;
                                            }

                                            List<IffInfo> InfoList = new List<IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName = ArchiveFile.Key;
                                                    Info.NumChunks = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                }
                            }
                            else //The files in "objectdata\globals\" are not in a FAR archive...
                            {
                                //Some of the files in "objectdata\globals\" are *.otf files...
                                if (ArchivePath.Contains(".iff"))
                                {
                                    if (!LookingForSprites)
                                    {
                                        Iff IffFile = new Iff(ArchivePath);
                                        int NumChunks = 0;

                                        LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchivePath });

                                        //Figure out how many chunks of the type is being searched for
                                        //is in the current IFF archive. Is there a faster way to do this?
                                        foreach (IffChunk Chunk in IffFile.Chunks)
                                        {
                                            if (Chunk.Resource == TxtChunkType.Text)
                                                NumChunks++;
                                        }

                                        List<IffInfo> InfoList = new List<IffInfo>();

                                        foreach (IffChunk Chunk in IffFile.Chunks)
                                        {
                                            if (Chunk.Resource == TxtChunkType.Text)
                                            {
                                                LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { Path.GetFileName(ArchivePath) });

                                                IffInfo Info = new IffInfo();
                                                Info.ArchivePath = "";
                                                Info.IffName = IffFile.Path;
                                                Info.NumChunks = NumChunks;

                                                InfoList.Add(Info);
                                            }
                                        }

                                        m_IffInfoList.Add(Path.GetFileName(ArchivePath), InfoList);
                                    }
                                }
                            }
                        }
                    }

                    foreach (string Dir in HouseDataDirs)
                    {
                        string[] Files = Directory.GetFiles(Dir);

                        if (Dir.Contains("walls") || Dir.Contains("floors"))
                        {
                            foreach (string ArchivePath in Files)
                            {
                                FARArchive Archive = new FARArchive(ArchivePath);
                                List<KeyValuePair<string, byte[]>> ArchiveFiles = Archive.GetAllEntries();

                                foreach (KeyValuePair<string, byte[]> ArchiveFile in ArchiveFiles)
                                {
                                    if (!LookingForSprites)
                                    {
                                        //Don't waste time scanning *.spf files if not looking for sprites...
                                        if(!ArchiveFile.Key.Contains(".spf"))
                                        {
                                            Iff IffFile;
                                            int NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            else
                                                IffFile = new Iff(ArchiveFile.Value);

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                    NumChunks++;
                                            }

                                            List<IffInfo> InfoList = new List<IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName = ArchiveFile.Key;
                                                    Info.NumChunks = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                    else
                                    {
                                        if (ArchiveFile.Key.Contains(".spf") || ArchiveFile.Key.Contains(".wll") || ArchiveFile.Key.Contains(".flr"))
                                        {
                                            Iff IffFile;
                                            int NumChunks = 0;

                                            LblScanning.Invoke(m_OnUpdateStatus, new object[] { ArchiveFile.Key });

                                            if (!m_Debug)
                                                IffFile = new Iff(ArchiveFile.Value, ArchiveFile.Key);
                                            else
                                                IffFile = new Iff(ArchiveFile.Value);

                                            //Figure out how many chunks of the type is being searched for
                                            //is in the current IFF archive. Is there a faster way to do this?
                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                    NumChunks++;
                                            }

                                            List<IffInfo> InfoList = new List<IffInfo>();

                                            foreach (IffChunk Chunk in IffFile.Chunks)
                                            {
                                                if (Chunk.Resource == TxtChunkType.Text)
                                                {
                                                    LstChunkTypes.Invoke(m_OnFoundChunk, new object[] { ArchiveFile.Key });

                                                    IffInfo Info = new IffInfo();
                                                    Info.ArchivePath = ArchivePath;
                                                    Info.IffName = ArchiveFile.Key;
                                                    Info.NumChunks = NumChunks;

                                                    InfoList.Add(Info);
                                                }
                                            }

                                            m_IffInfoList.Add(Path.GetFileName(ArchivePath) + "\\" + ArchiveFile.Key, InfoList);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                    MessageBox.Show("Please specify a chunktype to search for!");
            }

            LblScanning.Invoke((MethodInvoker)delegate() 
            { 
                LblScanning.Text = "Done, found: " + TotalNumberOfChunksFound() + " chunks."; 
            });
            BtnAbort.Invoke((MethodInvoker)delegate() { BtnAbort.Visible = false; }); 
            m_WorkerThread.Abort();
        }