コード例 #1
0
ファイル: FLGameData.cs プロジェクト: HeIIoween/FLHook
        /// <summary>
        /// Scan the goods files for the specifed shiphull to add the effects entries
        /// from the goods package to the ship as synthetic hardpoints.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="loadout"></param>
        void AddFXFromGoods(FLDataFile flGoodsIni, string flDataPath, FLDataFile.Section shipPackageSection, LogRecorderInterface log)
        {
            try
            {
                string hullNickName = shipPackageSection.GetSetting("hull").Str(0);

                foreach (FLDataFile.Section section in flGoodsIni.sections)
                {
                    if (section.sectionName.ToLowerInvariant() != "good")
                        continue;

                    if (section.GetSetting("category").Str(0)!="shiphull")
                        continue;

                    if (section.GetSetting("nickname").Str(0)!=hullNickName)
                        continue;

                    string shipNickName = section.GetSetting("ship").Str(0);
                    uint shiphash = FLUtility.CreateID(shipNickName);

                    long defaultSound = 0;
                    long defaultPowerPlant = 0;
                    long defaultEngine = 0;

                    // Get the loadout for the ship.
                    foreach (FLDataFile.Setting setting in shipPackageSection.settings)
                    {
                        try
                        {
                            if (setting.settingName.ToLowerInvariant() != "addon")
                                continue;

                            if (setting.NumValues() != 3)
                                throw new Exception(setting.desc + "setting '" + setting.desc + "' should have 3 values");

                            string equipNickName = setting.Str(0);
                            GameDataSet.HashListRow item = GetItemByNickName(equipNickName);
                            if (item == null)
                                throw new Exception(setting.desc + " cannot find " + equipNickName + " in game data table");

                            if (item.ItemType == GAMEDATA_LIGHTS)
                            {
                                if (setting.Str(1) == "internal")
                                    throw new Exception(setting.desc + " invalid hardpoint for " + equipNickName);
                                DataStore.HardPointList.AddHardPointListRow(shiphash, setting.Str(1), item.ItemType, "", item.ItemHash);
                            }
                            else if (item.ItemType == GAMEDATA_FX)
                            {
                                if (setting.Str(1) == "internal")
                                    throw new Exception(setting.desc + " invalid hardpoint for " + equipNickName);
                                DataStore.HardPointList.AddHardPointListRow(shiphash, setting.Str(1), item.ItemType, "", item.ItemHash);
                            }
                            else if (item.ItemType == GAMEDATA_SOUND)
                            {
                                defaultSound = item.ItemHash;
                            }
                            else if (item.ItemType == GAMEDATA_POWERGEN)
                            {
                                defaultPowerPlant = item.ItemHash;
                            }
                            else if (item.ItemType == GAMEDATA_ENGINES)
                            {
                                defaultEngine = item.ItemHash;
                            }
                        }
                        catch (Exception e)
                        {
                            log.AddLog("Error '" + e.Message + "'");
                        }
                    }

                    DataStore.ShipInfoList.AddShipInfoListRow(shiphash, defaultEngine, defaultSound, defaultPowerPlant);
                }
            }
            catch (Exception e)
            {
                log.AddLog("Error '" + e.Message + "'");
            }
        }
コード例 #2
0
ファイル: FLGameData.cs プロジェクト: HeIIoween/FLHook
 private string GetIDSParm(FLDataFile.Section section, string parmName)
 {
     string stInfo = "";
     if (section.SettingExists(parmName))
     {
         uint idsInfo = section.GetSetting(parmName).UInt(0);
         stInfo = GetIDString(idsInfo);
         if (stInfo == null)
             throw new Exception("ids_info not found " + idsInfo);
         stInfo = stInfo.Trim();
     }
     return stInfo;
 }
コード例 #3
0
ファイル: FLGameData.cs プロジェクト: HeIIoween/FLHook
        private bool AddGameData(GameDataSet.HashListDataTable items, FLDataFile.Section section, string gameDataType, bool ignoreEntriesWithNoIds)
        {
            string nickName = section.GetSetting("nickname").Str(0);
            
            string stIDSName = GetIDSParm(section, "ids_name");
            if (stIDSName == "")
                stIDSName = GetIDSParm(section, "strid_name");

            if (ignoreEntriesWithNoIds && stIDSName == "")
                return false;

            uint hash = FLUtility.CreateID(nickName.ToLowerInvariant());
            if (gameDataType == GAMEDATA_FACTIONS)
                hash = FLUtility.CreateFactionID(nickName);

            GameDataSet.HashListRow conflictingHashEntry = items.FindByItemHash(hash);
            if (conflictingHashEntry != null)
                return false;

            string stIDSInfo = GetIDSParm(section, "ids_info");
            
            string stIDSInfo1 = GetIDSParm(section, "ids_info1");
            if (stIDSInfo1 == "")
                stIDSInfo1 = GetIDSParm(section, "ids_short_name");

            string stIDSInfo2 = GetIDSParm(section, "ids_info2");
            string stIDSInfo3 = GetIDSParm(section, "ids_info3");

            string keys = hash.ToString() + " 0x" + hash.ToString("X");

            items.AddHashListRow(hash, nickName, gameDataType, stIDSName, stIDSInfo, stIDSInfo1, stIDSInfo2, stIDSInfo3, keys);
            return true;
        }
コード例 #4
0
ファイル: FLGameData.cs プロジェクト: HeIIoween/FLHook
        /// <summary>
        /// Load all game data.
        /// </summary>
        public void LoadAll(string flExePath, LogRecorderInterface log)
        {
            DataStore.Clear();

            FLDataFile flIni = null;
            try
            {
                flIni = new FLDataFile(flExePath + Path.DirectorySeparatorChar + "Freelancer.ini", true);
            }
            catch (Exception e)
            {
                log.AddLog("Error '" + e.Message + "' when parsing '" + flExePath);
                return;
            }
            string flDataPath = Path.GetFullPath(Path.Combine(flExePath, flIni.GetSetting("Freelancer", "data path").Str(0)));

            log.AddLog("Loading strings...");

            // Load the string dlls.
            LoadLibrary(flExePath + Path.DirectorySeparatorChar + "resources.dll");
            foreach (FLDataFile.Setting flIniEntry in flIni.GetSettings("Resources", "DLL"))
                LoadLibrary(flExePath + Path.DirectorySeparatorChar + flIniEntry.Str(0));

            log.AddLog("Loading universe...");

            // Scan ini files and parse base entries
            foreach (FLDataFile.Setting flIniEntry in flIni.GetSettings("Data", "universe"))
            {
                string iniPath = flDataPath + Path.DirectorySeparatorChar + flIniEntry.Str(0);
                try
                {
                    FLDataFile ini = new FLDataFile(iniPath, true);
                    foreach (FLDataFile.Section section in ini.sections)
                    {
                        try
                        {
                            string sectionName = section.sectionName.ToLowerInvariant();
                            if (sectionName == "base")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_BASES, true);
                                string baseNick = section.GetSetting("nickname").Str(0);
                                string baseFilePath = flDataPath + Path.DirectorySeparatorChar + section.GetSetting("file").Str(0);
                                LoadRoomData(DataStore, baseNick, baseFilePath);
                            }
                            else if (sectionName == "system")
                            {
                                string baseNick = section.GetSetting("nickname").Str(0).ToLowerInvariant();
                                AddGameData(DataStore.HashList, section, GAMEDATA_SYSTEMS, true);
                                string file = Directory.GetParent(ini.filePath).FullName + "\\" + section.GetSetting("file").Str(0);
                                ParseSystem(file, log);
                            }
                        }
                        catch (Exception e)
                        {
                            log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                        }
                    }
                }
                catch (Exception e)
                {
                    log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                }
            }

            log.AddLog("Loading ships...");

            // Scan ship files and parse ship entries
            foreach (FLDataFile.Setting flIniEntry in flIni.GetSettings("Data", "ships"))
            {
                string iniPath = flDataPath + Path.DirectorySeparatorChar + flIniEntry.Str(0);
                try
                {
                    FLDataFile ini = new FLDataFile(iniPath, true);
                    foreach (FLDataFile.Section section in ini.sections)
                    {
                        if (section.sectionName.ToLowerInvariant() == "ship")
                        {
                            AddGameData(DataStore.HashList, section, GAMEDATA_SHIPS, true);

                            string nickName = section.GetSetting("nickname").Str(0);
                            uint hash = FLUtility.CreateID(nickName.ToLowerInvariant());

                            foreach (FLDataFile.Setting setting in section.settings)
                            {
                                try
                                {
                                    if (setting.settingName.ToLowerInvariant() == "da_archetype")
                                    {
                                        // UTF hardpoints are only really useful to validate the shiparch and ship default loadout.
                                        // Don't bother loading them.
                                        // UtfFile utf = new UtfFile(flDataPath + Path.DirectorySeparatorChar + setting.Str(0));
                                        // foreach (string hp in utf.hardpoints)
                                        // {
                                        //    DataStore.HardPointList.AddHardPointListRow(hash, hp, "");
                                        // }
                                    }
                                    else if (setting.settingName.ToLowerInvariant() == "hp_type")
                                    {

                                        string type = setting.Str(0);
                                        for (int i = 1; i < setting.NumValues(); i++)
                                        {
                                            string hp = setting.Str(i);
                                            GameDataSet.HardPointListRow hpInfo = GetHardPointByShipAndHPName(hash, hp);
                                            if (hpInfo == null)
                                                hpInfo = DataStore.HardPointList.AddHardPointListRow(hash, hp, HardpointClassToGameDataClass(type), "", 0);
                                            hpInfo.MountableTypes += " " + type;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.AddLog(String.Format("Error '{0}' when reading {1}", ex.Message, setting.desc));
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                }
            }

            log.AddLog("Loading equipment...");

            // Scan ini files and parse equipment entries.
            foreach (FLDataFile.Setting flIniEntry in flIni.GetSettings("Data", "equipment"))
            {
                string iniPath = flDataPath + Path.DirectorySeparatorChar + flIniEntry.Str(0);
                try
                {
                    FLDataFile ini = new FLDataFile(iniPath, true);
                    foreach (FLDataFile.Section section in ini.sections)
                    {
                        try
                        {
                            string sectionName = section.sectionName.ToLowerInvariant();
                            // Internal equipment; these are mounted internally.
                            if (sectionName == "engine")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_ENGINES, true);
                            }
                            else if (sectionName == "power")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_POWERGEN, true);
                            }
                            else if (sectionName == "scanner")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_SCANNERS, true);
                            }
                            else if (sectionName == "tractor")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_TRACTORS, true);
                            }
                            else if (sectionName == "cloakingdevice")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_CLOAK, true);
                            }
                            else if (sectionName == "armor")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_ARMOR, true);
                            }
                            else if (sectionName == "internalfx")
                            {
                                if (section.SettingExists("use_sound"))
                                {
                                    AddGameData(DataStore.HashList, section, GAMEDATA_SOUND, false);
                                }
                            }
                            // External hardpoints.
                            else if (sectionName == "attachedfx")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_FX, false);
                            }
                            else if (sectionName == "light")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_LIGHTS, false);
                            }
                            else if (sectionName == "gun")
                            {
                                if (section.SettingExists("hp_gun_type"))
                                {
                                    string hpType = section.GetSetting("hp_gun_type").Str(0);
                                    AddGameData(DataStore.HashList, section, HardpointClassToGameDataClass(hpType), true);
                                    DataStore.EquipInfoList.AddEquipInfoListRow(
                                        FLUtility.CreateID(section.GetSetting("nickname").Str(0)),
                                        HardpointClassToGameDataClass(hpType), hpType);
                                }
                                // Probably an npc gun
                                else
                                {
                                    AddGameData(DataStore.HashList, section, GAMEDATA_GEN, false);
                                }
                            }
                            else if (sectionName == "shieldgenerator")
                            {
                                if (section.SettingExists("hp_type"))
                                {
                                    string hpType = section.GetSetting("hp_type").Str(0);
                                    AddGameData(DataStore.HashList, section, HardpointClassToGameDataClass(hpType), true);
                                    DataStore.EquipInfoList.AddEquipInfoListRow(
                                        FLUtility.CreateID(section.GetSetting("nickname").Str(0)),
                                        HardpointClassToGameDataClass(hpType), hpType);
                                }
                                // Probably an npc shield
                                else
                                {
                                    AddGameData(DataStore.HashList, section, GAMEDATA_GEN, false);
                                }
                            }
                            else if (sectionName == "countermeasuredropper")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_CM, true);
                            }
                            else if (sectionName == "thruster")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_THRUSTERS, true);
                            }
                            else if (sectionName == "minedropper")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_MINES, true);
                            }

                            // Cargo and ammo.
                            else if (sectionName == "munition")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_AMMO, true);
                            }
                            else if (sectionName == "repairkit")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_CARGO, true);
                            }
                            else if (sectionName == "countermeasure")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_AMMO, true);
                            }
                            else if (sectionName == "shieldbattery")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_CARGO, true);
                            }
                            else if (sectionName == "mine")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_AMMO, true);
                            }
                            else if (sectionName == "commodity")
                            {
                                AddGameData(DataStore.HashList, section, GAMEDATA_CARGO, true);
                            }

                            // Random stuff I don't know what to do with.
                            else if (sectionName == "shield")
                            { } // ignore this section
                            else if (sectionName == "lootcrate")
                            { } // ignore this section
                            else if (sectionName == "lod")
                            { } // ignore this section - it has no nickname
                            else if (sectionName == "tradelane")
                            { } // ignore this section
                            else if (sectionName == "motor")
                            { } // ignore this section
                            else if (sectionName == "explosion")
                            { } // ignore this section
                            else if (sectionName == "cargopod")
                            { } // ignore this section
                            else if (sectionName == "tradelane")
                            { } // ignore this section

                            else
                            {
                            }
                        }
                        catch (Exception e)
                        {
                            log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                        }
                    }
                }
                catch (Exception e)
                {
                    log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                }
            }

            log.AddLog("Loading factions...");

            // Scan ini files and parse faction entries
            foreach (FLDataFile.Setting flIniEntry in flIni.GetSettings("Data", "groups"))
            {
                string iniPath = flDataPath + Path.DirectorySeparatorChar + flIniEntry.Str(0);
                try
                {
                    FLDataFile ini = new FLDataFile(iniPath, true);
                    foreach (FLDataFile.Section section in ini.sections)
                    {
                        if (section.sectionName.ToLowerInvariant() == "group")
                        {
                            AddGameData(DataStore.HashList, section, GAMEDATA_FACTIONS, true);
                        }
                    }
                }
                catch (Exception e)
                {
                    log.AddLog("Error '" + e.Message + "' when parsing '" + iniPath);
                }
            }
            foreach (IntPtr hInstance in vDLLs)
                FreeLibrary(hInstance);
            vDLLs.Clear();
        }