This class implements a resource loader that is compatible with the game's internal resource loader. It can be used to load up files out of the currently loaded module, haks, or game data zip files.
        public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode)
        {
            uint   Object = (uint)ScriptParameters[0];
            string Key = (string)ScriptParameters[1];
            string GFFName, ResRef;
            ushort ResType = 0;

            if (ResourceManager == null)
            {
                ResourceManager = new ALFA.ResourceManager(null);
            }

            ResRef = GetResRef(Object);

            switch (GetObjectType(Object))
            {
            case OBJECT_TYPE_CREATURE:
                ResType = ResourceManager.ResUTC;
                break;

            case OBJECT_TYPE_ITEM:
                ResType = ResourceManager.ResUTI;
                break;

            case OBJECT_TYPE_PLACEABLE:
                ResType = ResourceManager.ResUTP;
                break;

            default:
                break;
            }

            try {
                OEIShared.IO.GFF.GFFFile gff = ResourceManager.OpenGffResource(ResRef, ResType);
                GFFName = gff.TopLevelStruct.GetExoLocStringSafe(Key).Strings.First().Value;

                SetLocalString(Object, "RawText", GFFName.Replace("{", "[").Replace("}", "]"));
            }
            catch {
            }

            return(DefaultReturnCode);
        }
        public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode)
        {
            uint Object = (uint)ScriptParameters[0]; 
            string Key = (string)ScriptParameters[1]; 
            string GFFName, ResRef;
            ushort ResType = 0;

            if (ResourceManager == null)
                ResourceManager = new ALFA.ResourceManager(null);

            ResRef = GetResRef(Object);
	    
	    switch (GetObjectType(Object)) {
		    case OBJECT_TYPE_CREATURE:
                ResType = ResourceManager.ResUTC;
			    break;
		    case OBJECT_TYPE_ITEM:
                ResType = ResourceManager.ResUTI;
			    break;
		    case OBJECT_TYPE_PLACEABLE:
                ResType = ResourceManager.ResUTP;
			    break;
		    default:
			    break;
	    }
            
	    try {
            OEIShared.IO.GFF.GFFFile gff = ResourceManager.OpenGffResource(ResRef, ResType);
        	GFFName = gff.TopLevelStruct.GetExoLocStringSafe(Key).Strings.First().Value;

	    	SetLocalString(Object, "RawText", GFFName.Replace("{","[").Replace("}","]"));
	    }
	    catch {
	    }

            return DefaultReturnCode;
	}
        /// <summary>
        /// Discover and record resources located in the module proper, and log
        /// them to the database.
        /// </summary>
        private void RecordModuleResources()
        {
            uint Module = GetModule();

            if (GetLocalInt(Module, "ACR_MODULERESOURCEFILES") == 0)
                return;

            DeleteLocalInt(Module, "ACR_MODULERESOURCEFILES");

            try
            {
                StringBuilder Query = new StringBuilder();
                ALFA.ResourceManager ResourceManager = new ALFA.ResourceManager(null);
                ALFA.Database Database = GetDatabase();
                int ServerID = Database.ACR_GetServerID();

                ResourceManager.LoadCoreResources();

                Query.AppendFormat(
                    "DELETE FROM `server_resource_files` WHERE `ServerID` = {0};",
                    ServerID);

                var ResNames = (from ResEntry in ResourceManager.GetAllResources()
                                select ResEntry.FullName.ToLower()).Distinct();

                foreach (string ResName in ResNames)
                {
                    Query.AppendFormat(
                        "INSERT INTO `server_resource_files` (`ServerID`, `ResourceFileName`) VALUES ({0}, '{1}');",
                        ServerID,
                        Database.ACR_SQLEncodeSpecialChars(ResName));
                }

                Database.ACR_AsyncSQLQueryEx(Query.ToString(), Module, ACR_QUERY_FLAGS.ACR_QUERY_LOW_PRIORITY);
                WriteTimestampedLogEntry(String.Format(
                    "ACR_ServerCommunicator.RecordModuleResources: Recorded {0} module resources.",
                    ResNames.Count<string>()));
            }
            catch (Exception e)
            {
                WriteTimestampedLogEntry(String.Format(
                    "ACR_ServerCommunicator.RecordModuleResources: Exception {0}.", e));
            }
        }
        public void InitializeArchives(object Sender, EventArgs e)
        {
            // TODO: Allow this to be configured.
            try
            {
                Archivist.debug += "\nAttempting to make a new ResourceManager";
                manager = new ALFA.ResourceManager(null);
                LoadModuleProperties();

                Archivist.debug += "\nAttempting to open the default talk table";
                dialog = new OEIShared.IO.TalkTable.TalkTable();
                dialog.Open(OEIShared.Utils.BWLanguages.BWLanguage.English);

                Archivist.debug += "\nAttempting to open the custom talk table";
                if (!String.IsNullOrEmpty(customTlkFileName))
                {
                    customTlk = new OEIShared.IO.TalkTable.TalkTable();
                    customTlk.OpenCustom(OEIShared.Utils.BWLanguages.BWLanguage.English, customTlkFileName);
                }

                tlkLoaded = true;

                Archivist.debug += "\nInitializing ALFA.Shared collections";
                ALFA.Shared.Modules.InfoStore.ModuleItems = new Dictionary<string, ALFA.Shared.ItemResource>();
                ALFA.Shared.Modules.InfoStore.ModuleCreatures = new Dictionary<string, ALFA.Shared.CreatureResource>();
                ALFA.Shared.Modules.InfoStore.ModulePlaceables = new Dictionary<string, ALFA.Shared.PlaceableResource>();
                ALFA.Shared.Modules.InfoStore.ModuleWaypoints = new Dictionary<string, ALFA.Shared.WaypointResource>();
                ALFA.Shared.Modules.InfoStore.ModuleFactions = new Dictionary<int, ALFA.Shared.Faction>();
                ALFA.Shared.Modules.InfoStore.ModuleVisualEffects = new Dictionary<string, ALFA.Shared.VisualEffectResource>();
                ALFA.Shared.Modules.InfoStore.ModuleLights = new Dictionary<string, ALFA.Shared.LightResource>();
                ALFA.Shared.Modules.InfoStore.ModuleTraps = new Dictionary<string, ALFA.Shared.TrapResource>();

                ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers = new Dictionary<string, ALFA.Shared.ActiveTrap>();
                ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect = new Dictionary<string, ALFA.Shared.ActiveTrap>();

                ALFA.Shared.Modules.InfoStore.ModifiedGff = new Dictionary<string, GFFFile>();

                ALFA.Shared.Modules.InfoStore.AreaNames = new Dictionary<string,string>();

                Archivist.debug += "\nInitializing standard factions";
                List<int> factionIndex = new List<int>();
                factionIndex.Add(0); // Player
                factionIndex.Add(1); // Hostile
                factionIndex.Add(2); // Commoner
                factionIndex.Add(3); // Merchant
                factionIndex.Add(4); // Defender

                // The damage-doing traps from the original campaign, converted to
                // our purposes.
                Archivist.debug += "\nAdding standard traps";
                AddStandardTraps();

                #region Caching Information about All Items
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTI))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleItems.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            // If we have competing resources, we expect that GetResourcesByType will give us the
                            // resource of greatest priority first. Therefore, redundant entries of a given resref
                            // are trash.
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        ALFA.Shared.ItemResource addingItem = new ALFA.Shared.ItemResource();
                        addingItem.ResourceName = resource.FullName.Split('.')[0].ToLower();
                        try
                        {
                            addingItem.LocalizedName = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingItem.LocalizedName = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString();
                        }
                        if (addingItem.LocalizedName == "")
                        {
                            addingItem.LocalizedName = GetTlkEntry(currentGFF.TopLevelStruct["LocalizedName"].ValueCExoLocString.StringRef);
                        }

                        // Might be a talk table reference. Let's see...
                        if (addingItem.LocalizedName.Contains('{') && addingItem.LocalizedName.Contains('}'))
                        {
                            string attemptingName = GffStoreToTlk(addingItem.LocalizedName);
                            if (attemptingName != "") addingItem.LocalizedName = attemptingName;
                        }

                        addingItem.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());

                        addingItem.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();
                        addingItem.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();

                        int Cost, CostModify, BaseItem;
                        bool Cursed = false, Plot = false, Stolen = false;
                        Int32.TryParse(currentGFF.TopLevelStruct["Cost"].Value.ToString(), out Cost);
                        Int32.TryParse(currentGFF.TopLevelStruct["ModifyCost"].Value.ToString(), out CostModify);
                        Int32.TryParse(currentGFF.TopLevelStruct["BaseItem"].Value.ToString(), out BaseItem);
                        if (currentGFF.TopLevelStruct["Cursed"].Value.ToString() == "1") Cursed = true;
                        if (currentGFF.TopLevelStruct["Plot"].Value.ToString() == "1") Plot = true;
                        if (currentGFF.TopLevelStruct["Stolen"].Value.ToString() == "1") Stolen = true;

                        addingItem.Cost = Cost + CostModify;
                        addingItem.BaseItem = BaseItem;
                        addingItem.Cursed = Cursed;
                        addingItem.Plot = Plot;
                        addingItem.Stolen = Stolen;

                        addingItem.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModuleItems.Add(addingItem.ResourceName, addingItem);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Caching Information about All Creatures
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTC))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleCreatures.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        ALFA.Shared.CreatureResource addingCreature = new ALFA.Shared.CreatureResource();

                        addingCreature.ResourceName = resource.FullName.Split('.')[0].ToLower();
                        try
                        {
                            addingCreature.FirstName = currentGFF.TopLevelStruct["FirstName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingCreature.FirstName = currentGFF.TopLevelStruct["FirstName"].Value.ToString();
                        }
                        if (addingCreature.FirstName == "")
                        {
                            addingCreature.FirstName = GetTlkEntry(currentGFF.TopLevelStruct["FirstName"].ValueCExoLocString.StringRef);
                        }

                        try
                        {
                            addingCreature.LastName = currentGFF.TopLevelStruct["LastName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingCreature.LastName = currentGFF.TopLevelStruct["LastName"].Value.ToString();
                        }
                        if (addingCreature.LastName == "")
                        {
                            addingCreature.LastName = GetTlkEntry(currentGFF.TopLevelStruct["LastName"].ValueCExoLocString.StringRef);
                        }

                        addingCreature.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());

                        addingCreature.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();
                        addingCreature.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();

                        if (currentGFF.TopLevelStruct["IsImmortal"].Value.ToString() == "0")
                            addingCreature.IsImmortal = false;
                        else
                            addingCreature.IsImmortal = true;

                        float calculatedCR = 0.0f;
                        if (float.TryParse(currentGFF.TopLevelStruct["ChallengeRating"].Value.ToString(), out calculatedCR))
                        {
                            addingCreature.ChallengeRating = calculatedCR;
                        }

                        int faction;
                        if (Int32.TryParse(currentGFF.TopLevelStruct["FactionID"].Value.ToString(), out faction))
                        {
                            addingCreature.FactionID = faction;
                            if (!factionIndex.Contains(faction)) factionIndex.Add(faction);
                        }

                        int LawChaos;
                        if (Int32.TryParse(currentGFF.TopLevelStruct["LawfulChaotic"].Value.ToString(), out LawChaos))
                        {
                            addingCreature.LawfulChaotic = LawChaos;
                        }

                        int GoodEvil;
                        if (Int32.TryParse(currentGFF.TopLevelStruct["GoodEvil"].Value.ToString(), out GoodEvil))
                        {
                            addingCreature.GoodEvil = GoodEvil;
                        }

                        string AlignSummary;
                        if (GoodEvil < 31) AlignSummary = "E";
                        else if (GoodEvil < 70) AlignSummary = "N";
                        else AlignSummary = "G";

                        if (LawChaos < 31) AlignSummary = "C" + AlignSummary;
                        else if (LawChaos < 70 && AlignSummary == "N") AlignSummary = "TN";
                        else if (LawChaos < 70) AlignSummary = "N" + AlignSummary;
                        else AlignSummary = "L" + AlignSummary;

                        addingCreature.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModuleCreatures.Add(addingCreature.ResourceName, addingCreature);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Caching Information about All Placeables
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTP))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleCreatures.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        ALFA.Shared.PlaceableResource addingPlaceable = new ALFA.Shared.PlaceableResource();
                        addingPlaceable.ResourceName = resource.FullName.Split('.')[0].ToLower();
                        try
                        {
                            addingPlaceable.Name = currentGFF.TopLevelStruct["LocName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingPlaceable.Name = currentGFF.TopLevelStruct["LocName"].Value.ToString();
                        }
                        if (addingPlaceable.Name == "")
                        {
                            addingPlaceable.Name = GetTlkEntry(currentGFF.TopLevelStruct["LocName"].ValueCExoLocString.StringRef);
                        }

                        addingPlaceable.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());

                        addingPlaceable.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();
                        addingPlaceable.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();
                        addingPlaceable.Useable = currentGFF.TopLevelStruct["Useable"].Value.ToString() != "0";
                        addingPlaceable.HasInventory = currentGFF.TopLevelStruct["HasInventory"].ValueByte != 0;
                        addingPlaceable.Trapped = currentGFF.TopLevelStruct["TrapFlag"].ValueByte != 0;
                        addingPlaceable.Locked = currentGFF.TopLevelStruct["Locked"].ValueByte != 0;

                        addingPlaceable.TrapDetectDC = currentGFF.TopLevelStruct["TrapDetectDC"].ValueInt;
                        addingPlaceable.TrapDisarmDC = currentGFF.TopLevelStruct["DisarmDC"].ValueInt;                        
                        addingPlaceable.LockDC = currentGFF.TopLevelStruct["OpenLockDC"].ValueInt;

                        addingPlaceable.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModulePlaceables.Add(addingPlaceable.ResourceName, addingPlaceable);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Caching Information about Factions
                factionIndex.Sort();
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResFAC))
                {
                    try
                    {
                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);

                        int count = 0;
                        foreach (GFFStruct field in currentGFF.TopLevelStruct["FactionList"].ValueList.StructList)
                        {
                            ALFA.Shared.Faction addingFaction = new ALFA.Shared.Faction();
                            addingFaction.Name = field.GetFieldSafe("FactionName").Value.ToString();
                            ALFA.Shared.Modules.InfoStore.ModuleFactions.Add(factionIndex[count], addingFaction);
                            count++;
                        }

                        // If there are multiple .FAC resources, we only care about the one that gets priority.
                        if (ALFA.Shared.Modules.InfoStore.ModuleFactions.Count > 0) break;
                    }
                    catch { }
                }
                #endregion

                #region Caching Information about Waypoints
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTW))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleWaypoints.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        GFFStructCollection variables = currentGFF.TopLevelStruct["VarTable"].ValueList.StructList;
                        if (variables.Count > 0)
                        {
                            bool nonWaypoint = false;
                            // Waypoints can be a lot of things. Let's see if we can figure anything out about this one.
                            foreach (GFFStruct var in variables)
                            {
                                if (var["Name"].Value.ToString() == "ACR_TRAP_TRIGGER_AREA")
                                {
                                    // This is a trap. We should process as one.
                                    ParseTrapWaypoint(currentGFF, currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString());
                                    nonWaypoint = true;
                                    break;
                                }
                            }
                            if (nonWaypoint)
                            {
                                continue;
                            }
                        }

                        ALFA.Shared.WaypointResource addingWaypoint = new ALFA.Shared.WaypointResource();
                        addingWaypoint.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();
                        addingWaypoint.ResourceName = resource.FullName.Split('.')[0].ToLower();

                        try
                        {
                            addingWaypoint.Name = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingWaypoint.Name = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString();
                        }
                        if (addingWaypoint.Name == "")
                        {
                            addingWaypoint.Name = GetTlkEntry(currentGFF.TopLevelStruct["LocalizedName"].ValueCExoLocString.StringRef);
                        }
                        
                        addingWaypoint.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());
                        addingWaypoint.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();

                        addingWaypoint.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModuleWaypoints.Add(addingWaypoint.ResourceName, addingWaypoint);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Caching Information about Visual Effects
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUPE))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleCreatures.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        ALFA.Shared.VisualEffectResource addingVisual = new ALFA.Shared.VisualEffectResource();

                        addingVisual.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();
                        addingVisual.ResourceName = resource.FullName.Split('.')[0].ToLower();
                        try
                        {
                            addingVisual.Name = currentGFF.TopLevelStruct["LocName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingVisual.Name = currentGFF.TopLevelStruct["LocName"].Value.ToString();
                        }
                        if (addingVisual.Name == "")
                        {
                            addingVisual.Name = GetTlkEntry(currentGFF.TopLevelStruct["LocName"].ValueCExoLocString.StringRef);
                        }

                        addingVisual.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());
                        addingVisual.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();

                        addingVisual.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModuleVisualEffects.Add(addingVisual.ResourceName, addingVisual);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Caching Information about Lights
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResULT))
                {
                    try
                    {
                        if (ALFA.Shared.Modules.InfoStore.ModuleCreatures.Keys.Contains(resource.FullName.Split('.')[0].ToLower()))
                        {
                            continue;
                        }

                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        ALFA.Shared.LightResource addingLight = new ALFA.Shared.LightResource();
                        addingLight.ResourceName = resource.FullName.Split('.')[0].ToLower();
                        addingLight.TemplateResRef = currentGFF.TopLevelStruct["TemplateResRef"].Value.ToString();

                        try
                        {
                            addingLight.Name = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString().Split('"')[1];
                        }
                        catch
                        {
                            addingLight.Name = currentGFF.TopLevelStruct["LocalizedName"].Value.ToString();
                        }
                        if (addingLight.Name == "")
                        {
                            addingLight.Name = GetTlkEntry(currentGFF.TopLevelStruct["LocalizedName"].ValueCExoLocString.StringRef);
                        }

                        addingLight.Classification = ParseClassification(currentGFF.TopLevelStruct["Classification"].Value.ToString());
                        addingLight.Tag = currentGFF.TopLevelStruct["Tag"].Value.ToString();

                        addingLight.LightRange = currentGFF.TopLevelStruct["Range"].ValueFloat;
                        addingLight.LightIntensity = currentGFF.TopLevelStruct["Light"].ValueStruct["Intensity"].ValueFloat;
                        addingLight.ShadowIntensity = currentGFF.TopLevelStruct["ShadowIntensity"].ValueFloat * 100;

                        addingLight.ConfigureDisplayName();

                        ALFA.Shared.Modules.InfoStore.ModuleLights.Add(addingLight.ResourceName, addingLight);
                    }
                    catch 
                    {
                        Archivist.debug += String.Format("\n {0}", resource.FullName);
                    }
                }
                #endregion

                #region Gathering Information from 2da Files
                try
                {
                    OEIShared.IO.TwoDA.TwoDAFile twoda = manager.OpenTwoDAResource(manager.GetResource("spells", ALFA.ResourceManager.Res2DA).ResRef.Value, ALFA.ResourceManager.Res2DA);
                    ALFA.Shared.Modules.InfoStore.CoreSpells = new List<ALFA.Shared.Spell>(twoda.RowCount);
                    var ColumnFields = ALFA.Shared.TwoDAReader.GetColumnFieldInfo(typeof(ALFA.Shared.Spell));
                    for (int row = 0; row < twoda.RowCount; row++)
                    {
                        ALFA.Shared.Spell spell = ALFA.Shared.TwoDAReader.Read2DARow<ALFA.Shared.Spell>(twoda, row, ColumnFields);
                        int parseholder = 0;

                        if (spell.Name == null)
                            spell.Name = twoda["Label"][row];

                        if (spell.Name == "" ||
                            spell.Name == "padding" ||
                            spell.Name == "PADDING" ||
                            spell.Name == "PADDING_PERSONAL_VFX")
                        {
                            // This line is padding.
                            ALFA.Shared.Modules.InfoStore.CoreSpells.Add(null);
                            continue;
                        }

                        spell.SubSpells = new List<int>();
                        if (int.TryParse(twoda["SubRadSpell1"][row], out parseholder))
                            spell.SubSpells.Add(parseholder);
                        if (int.TryParse(twoda["SubRadSpell2"][row], out parseholder))
                            spell.SubSpells.Add(parseholder);
                        if (int.TryParse(twoda["SubRadSpell3"][row], out parseholder))
                            spell.SubSpells.Add(parseholder);
                        if (int.TryParse(twoda["SubRadSpell4"][row], out parseholder))
                            spell.SubSpells.Add(parseholder);
                        if (int.TryParse(twoda["SubRadSpell5"][row], out parseholder))
                            spell.SubSpells.Add(parseholder);

                        spell.CounterSpells = new List<int>();
                        if (int.TryParse(twoda["Counter1"][row], out parseholder))
                            spell.CounterSpells.Add(parseholder);
                        if (int.TryParse(twoda["Counter2"][row], out parseholder))
                            spell.CounterSpells.Add(parseholder);

                        ALFA.Shared.Modules.InfoStore.CoreSpells.Add(spell);
                    }
                }
                catch (Exception ex)
                {
                    Archivist.debug += "\n spells.2da error: " + ex.Message + "\n" + ex.StackTrace;
                }
                try
                {
                    OEIShared.IO.TwoDA.TwoDAFile twoda = manager.OpenTwoDAResource(manager.GetResource("iprp_spells", ALFA.ResourceManager.Res2DA).ResRef.Value, ALFA.ResourceManager.Res2DA);
                    ALFA.Shared.Modules.InfoStore.IPCastSpells = new List<ALFA.Shared.SpellCastItemProperties>(twoda.RowCount);
                    var ColumnFields = ALFA.Shared.TwoDAReader.GetColumnFieldInfo(typeof(ALFA.Shared.SpellCastItemProperties));
                    for (int row = 0; row < twoda.RowCount; row++)
                    {
                        ALFA.Shared.SpellCastItemProperties ip = ALFA.Shared.TwoDAReader.Read2DARow<ALFA.Shared.SpellCastItemProperties>(twoda, row, ColumnFields);
                        int parseholder = 0;

                        if (ip.Name == null)
                            ip.Name = twoda["Label"][row];

                        if (ip.Name == "" ||
                            ip.Name == "padding" ||
                            ip.Name == "PADDING" ||
                            ip.Name == "PADDING_PERSONAL_VFX")
                        {
                            // This line is padding.
                            ALFA.Shared.Modules.InfoStore.IPCastSpells.Add(null);
                            continue;
                        }

                        if (int.TryParse(twoda["SpellIndex"][row], out parseholder))
                        {
                            if (parseholder < ALFA.Shared.Modules.InfoStore.CoreSpells.Count &&
                                ALFA.Shared.Modules.InfoStore.CoreSpells[parseholder] != null)
                            {
                                ip.Spell = ALFA.Shared.Modules.InfoStore.CoreSpells[parseholder];
                            }
                            else
                            {
                                Archivist.debug += "\niprp_spells.2da : could not find a spell with index " + parseholder.ToString();
                                ALFA.Shared.Modules.InfoStore.IPCastSpells.Add(null);
                                continue;
                            }
                        }
                        else
                        {
                            Archivist.debug += "\niprp_spells.2da : could not parse the spell index of " + row.ToString();
                            ALFA.Shared.Modules.InfoStore.IPCastSpells.Add(null);
                            continue;
                        }

                        ALFA.Shared.Modules.InfoStore.IPCastSpells.Add(ip);
                    }
                }
                catch (Exception ex)
                {
                    Archivist.debug += "\n iprp_spells.2da error: " + ex.Message;
                }

                try
                {
                    OEIShared.IO.TwoDA.TwoDAFile twoda = manager.OpenTwoDAResource(manager.GetResource("baseitems", ALFA.ResourceManager.Res2DA).ResRef.Value, ALFA.ResourceManager.Res2DA);
                    ALFA.Shared.Modules.InfoStore.BaseItems = new List<ALFA.Shared.BaseItem>(twoda.RowCount);
                    var ColumnFields = ALFA.Shared.TwoDAReader.GetColumnFieldInfo(typeof(ALFA.Shared.BaseItem));
                    for (int row = 0; row < twoda.RowCount; row++)
                    {
                        ALFA.Shared.BaseItem item = ALFA.Shared.TwoDAReader.Read2DARow<ALFA.Shared.BaseItem>(twoda, row, ColumnFields);

                        if (item.Name == null)
                            item.Name = twoda["label"][row];

                        if (item.Name == "" ||
                            item.Name == "padding" ||
                            item.Name == "PADDING" ||
                            item.Name == "DELETED" ||
                            item.Name == "PADDING_PERSONAL_VFX")
                        {
                            // This line is padding.
                            ALFA.Shared.Modules.InfoStore.BaseItems.Add(null);
                            continue;
                        }

                        ALFA.Shared.Modules.InfoStore.BaseItems.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    Archivist.debug += "\n baseitems.2da error: " + ex.Message;
                }
                #endregion

                #region Gathering Information from Module.ifo
                foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResIFO))
                {
                    try
                    {
                        GFFFile currentGFF = manager.OpenGffResource(resource.ResRef.Value, resource.ResourceType);
                        int count = currentGFF.TopLevelStruct["Mod_Area_list"].ValueList.StructList.Count;
                        for (int c = 0; c < count; c++)
                        {
                            try
                            {
                                string areaResRef = currentGFF.TopLevelStruct["Mod_Area_list"].ValueList[c]["Area_Name"].ValueCExoString.ToString();
                                debug += areaResRef;
                                GFFFile currentArea = manager.OpenGffResource(areaResRef, ALFA.ResourceManager.ResARE);
                                ALFA.Shared.Modules.InfoStore.AreaNames.Add(areaResRef, currentArea.TopLevelStruct["Name"].ValueCExoLocString.ToString().Trim().Trim(',').Trim('\"'));
                            }
                            catch { }
                        }
                        if (currentGFF != null) break;
                    }
                    catch { }
                }
                #endregion

                #region Commented-Out Resource Types
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResARE))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResBBX))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResBIC))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResBMP))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResBMU))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResCAM))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResDDS))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResDFT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResDLG))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResDWK))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResFAC))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResFXA))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResGFF))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResGIC))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResGIT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResGR2))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResGUI))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResINI))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResINVALID))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResITP))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResJPG))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResJRL))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResLTR))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResMDB))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResMDL))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResNCS))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResNDB))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResNSS))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPFB))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPFX))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPLT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPTM))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPTT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPWC))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResPWK))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResSEF))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResSET))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResSPT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResSSF))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTGA))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTRn))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTRN))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTRx))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTRX))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTXI))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResTXT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUEN))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUPE))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUSC))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTD))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTE))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTM))
                //{ }

                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTR))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTS))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResUTT))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResWAV))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResWLK))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResWOK))
                //{ }
                //foreach (ResourceEntry resource in manager.GetResourcesByType(ALFA.ResourceManager.ResXML))
                //{ }
                #endregion
            }
            catch (Exception ex)
            {
                debug += ex;
            }

            ACR_Candlekeep.ArchivesInstance.Resources = manager;
            ACR_Candlekeep.ArchivesInstance.SetResourcesLoaded();
        }