Ejemplo n.º 1
0
        private static void LoadShip(Section sec)
        {
            var nickname = sec.GetFirstOf("nickname")[0];
            _log.NewMessage(LogType.Garbage, "Universe: Parsing ship {0}", nickname);
            var hash = CreateID(nickname.ToLowerInvariant());

            // fail if equip already presents
            if (Gis.Ships.FindByHash(hash) != null) return;

            uint holdSize = 0;

            if (sec.ContainsAnyOf("hold_size"))
                holdSize = uint.Parse(sec.GetFirstOf("hold_size")[0]);

            var shipReadableName = "";
            if (sec.ContainsAnyOf("ids_name", "strid_name"))
                shipReadableName = GetIDSParm(sec.GetAnySetting("ids_name", "strid_name")[0]);

            var infocard = "";
            if (sec.ContainsAnyOf("ids_info"))
                infocard = GetIDSParm(sec.GetFirstOf("ids_info")[0]);

            Gis.Ships.AddShipsRow(hash, nickname,shipReadableName, infocard,holdSize);

            foreach (var set in sec.GetSettings("da_archetype"))
            {
                var utf = new UtfFile(_flDataPath + Path.DirectorySeparatorChar + set[0]);
                foreach (var hp in utf.Hardpoints.Where(hp => hp.ToLowerInvariant().Contains("cloak")))
                {
                    var ghr = Gis.Ships.FindByHash(hash).GetHardpointsRows();

                    if (ghr.Any(hpS => hpS.Name == hp)) continue;
                    //TODO cloak names
                    Gis.Hardpoints.AddHardpointsRow(Gis.Ships.FindByHash(hash), hp, EquipTypes.Cloak.ToString(),"cloak");
                }
            }

            foreach (var hpSet in sec.GetSettings("hp_type"))
            {
                var type = HpMap[hpSet[0]];

                foreach (var hp in hpSet.Skip(1))
                {
                    var hp1 = hp;
                    var q = 0;
                    var ghr = Gis.Ships.FindByHash(hash).GetHardpointsRows().FirstOrDefault(hpS => hpS.Name == hp1);
                    if (nickname == "dsy_no_elite")
                        q++;
                    if (ghr != null)
                    {
                        ghr.HPType += String.Format(" {0}", hpSet[0]);
                        continue;
                    }
                    Gis.Hardpoints.AddHardpointsRow(Gis.Ships.FindByHash(hash), hp, type.ToString(),hpSet[0]);
                }
            }
        }
Ejemplo n.º 2
0
        private static void LoadSystem(Section sec)
        {
            var sysNick = sec.GetFirstOf("nickname")[0].ToLowerInvariant();
            _log.NewMessage(LogType.Garbage, "Universe: Parsing system {0}", sysNick);

            var stIDSName = GetIDSParm(sec.GetAnySetting("strid_name")[0]);

            var stIDSInfo1 = "";
            if (sec.ContainsAnyOf("ids_info1","ids_short_name"))
                stIDSInfo1 = GetIDSParm(sec.GetAnySetting("ids_info")[0]);

            Gis.Systems.AddSystemsRow(sysNick, stIDSName,stIDSInfo1);

            //string file = Directory.GetParent(ini.filePath).FullName + "\\" + section.GetSetting("file").Str(0);
            //TODO: Warning, hardcoded system path! :S
            var sysFile = new DataFile(_flDataPath + @"\Universe\" + sec.GetFirstOf("file")[0]);

            foreach (var obj in sysFile.GetSections("Object"))
            {
                Setting curset;
                //string pos;
                var idsInfo = "";
                var idsInfo1 = "";

                //TODO: do we need pos?
                //if (obj.TryGetFirstOf("pos", out curset))
                //    pos = string.Join(", ", curset);

                //get infocard for the object
                if (obj.TryGetFirstOf("ids_info", out curset))
                {
                    uint id;
                    if (!uint.TryParse(curset[0], out id))
                    {
                        _log.NewMessage(LogType.Warning, "Can't find ID for object: {0}", curset[0]);
                    }

                    idsInfo = GetIDString(id);
                    if (InfocardMap.ContainsKey(id))
                        idsInfo1 = GetIDString(InfocardMap[id]);
                }

                //add the icard to the base if object is base
                if (obj.TryGetFirstOf("base", out curset))
                    //TODO: really join the stuff, infos are in XML format.
                    Gis.Bases.FindByNickname(curset[0]).Infocard = idsInfo + idsInfo1;

            }

            //TODO: zones needed?
        }
Ejemplo n.º 3
0
        private static void LoadFaction(Section sec)
        {
            var nickname = sec.GetFirstOf("nickname")[0];
            _log.NewMessage(LogType.Garbage, "Universe: Parsing faction {0}", nickname);
            var hash = CreateFactionID(nickname);

            if (Gis.Factions.FindByHash(hash) != null) return;

            var factionName = "";
            if (sec.ContainsAnyOf("ids_name", "strid_name"))
                factionName = GetIDSParm(sec.GetAnySetting("ids_name", "strid_name")[0]);

            // TODO: ignore empty IDS based on setting
            if (factionName == "") return;

            var shortName = "";
            if (sec.ContainsAnyOf("ids_info1", "ids_short_name"))
                shortName = GetIDSParm(sec.GetAnySetting("ids_info1", "ids_short_name")[0]);

            var infocard = "";
            if (sec.ContainsAnyOf("ids_info"))
                infocard = GetIDSParm(sec.GetFirstOf("ids_info")[0]);

            Gis.Factions.AddFactionsRow(hash, nickname, factionName, shortName, infocard);
        }
Ejemplo n.º 4
0
        private static void LoadLoadout(Section sec, DataFile file)
        {
            //if (sec.GetFirstOf("category")[0] != "ship") return;
            //done in LINQ
            var hullNickName = sec.GetFirstOf("hull")[0];

            //TODO: foreach or FirstOrDefault?
            var shSection = file.GetSections("Good").FirstOrDefault(w =>
                (w.GetFirstOf("category")[0] == "shiphull") &
                (w.GetFirstOf("nickname")[0] == hullNickName)
                );

            if (shSection == null)
            {
                _log.NewMessage(LogType.Warning, "Can't find package for shiphull {0}!", hullNickName);
                return;
            }

                var shipNickname = shSection.GetFirstOf("ship")[0];
                var shiphash = CreateID(shipNickname);

                uint defaultSound = 0;
                uint defaultPowerPlant = 0;
                uint defaultEngine = 0;

                foreach (var set in sec.GetSettings("addon"))
                {
                    if (set.Count != 3)
                    {
                        _log.NewMessage(LogType.Warning,
                            "Package for ship {0}: addon {1} has wrong arg count", shipNickname, set[0]);
                        continue;
                    }

                    var equipNick = set[0];
                    var item = Gis.Equipment.FindByHash(CreateID(equipNick));
                    if (item == null)
                    {
                        _log.NewMessage(LogType.Warning, @"Can't find {0} in DB: from loadout {1} \ {2}", equipNick,
                            hullNickName, shipNickname);
                        continue;
                    }

                    EquipTypes eqType;
                    Enum.TryParse(item.Type, out eqType);

                    switch (eqType)
                    {
                        case EquipTypes.Engine:
                            defaultEngine = item.Hash;
                            break;
                        case EquipTypes.Powerplant:
                            defaultPowerPlant = item.Hash;
                            break;
                        case EquipTypes.InternalFX:
                            defaultSound = item.Hash;
                            break;
                            case EquipTypes.Light:
                            if (set[1] == "internal")
                                _log.NewMessage(LogType.Warning, "Invalid hardpoint for light {0} (internal): {1}", equipNick, hullNickName);
                            break;
                        case EquipTypes.AttachedFX:
                             if (set[1] == "internal")
                                 _log.NewMessage(LogType.Warning, "Invalid hardpoint for attachedFX {0} (internal): {1}", equipNick, hullNickName);
                            break;
                    }

                }
                Gis.ShipDefaultInternals.AddShipDefaultInternalsRow(Gis.Ships.FindByHash(shiphash), defaultEngine,
                    defaultSound, defaultPowerPlant);
        }
Ejemplo n.º 5
0
        private static void LoadEquipSection(Section eqSection)
        {
            switch (eqSection.Name)
            {
                case "Engine":
                    LoadEquip(eqSection, EquipTypes.Engine);
                    break;
                case "Power":
                    LoadEquip(eqSection, EquipTypes.Powerplant);
                    break;
                case "Scanner":
                    LoadEquip(eqSection, EquipTypes.Scanner);
                    break;
                case "Tractor":
                    LoadEquip(eqSection, EquipTypes.Tractor);
                    break;
                case "CloakingDevice":
                    LoadEquip(eqSection, EquipTypes.Cloak);
                    break;
                case "Armor":
                    LoadEquip(eqSection, EquipTypes.Armor);
                    break;
                case "InternalFX":
                    if (eqSection.ContainsAnyOf("use_sound"))
                    {
                        LoadEquip(eqSection, EquipTypes.InternalFX);
                    }
                    break;
                case "AttachedFX":
                    LoadEquip(eqSection, EquipTypes.AttachedFX);
                    break;
                case "Light":
                    LoadEquip(eqSection, EquipTypes.Light);
                    break;
                case "Gun":
                    if (eqSection.ContainsAnyOf("hp_gun_type"))
                    {
                        LoadEquip(eqSection, EquipTypes.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);
                    //}
                    break;
                case "ShieldGenerator":
                    if (eqSection.ContainsAnyOf("hp_type"))
                    {
                        LoadEquip(eqSection, EquipTypes.ShieldGen);
                    }
                    //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);
                    //}
                    break;
                case "CounterMeasureDropper":
                    LoadEquip(eqSection, EquipTypes.CountermeasureDropper);
                    break;
                case "Thruster":
                    LoadEquip(eqSection, EquipTypes.Thruster);
                    break;
                case "MineDropper":
                    LoadEquip(eqSection, EquipTypes.MineDropper);
                    break;
                case "Munition":
                    LoadEquip(eqSection, EquipTypes.Munition);
                    break;
                case "RepairKit":
                    LoadEquip(eqSection, EquipTypes.RepairKit);
                    break;
                case "CounterMeasure":
                    LoadEquip(eqSection, EquipTypes.Countermeasure);
                    break;
                case "ShieldBattery":
                    LoadEquip(eqSection, EquipTypes.ShieldBattery);
                    break;
                case "Mine":
                    LoadEquip(eqSection, EquipTypes.Mine);
                    break;
                case "Commodity":
                    LoadEquip(eqSection, EquipTypes.Cargo);
                    break;
                case "CargoPod":
                    break;
                case "LootCrate":
                    break;
                case "TradeLane":
                    break;
                case "Shield":
                    break;
                case "LOD":
                    break;
                case "Motor":
                    break;
                case "Explosion":
                    break;
                //default:
                //break;

            }
        }
Ejemplo n.º 6
0
        private static void LoadEquip(Section sec, EquipTypes equipType)
        {
            var nickname = sec.GetFirstOf("nickname")[0];
            _log.NewMessage(LogType.Garbage, "Universe: Parsing equipment {0}", nickname);
            var hash = CreateID(nickname.ToLowerInvariant());

            // fail if equip already presents
            if (Gis.Equipment.FindByHash(hash) != null) return;

            var stIDSName = "";
            if (sec.ContainsAnyOf("ids_name", "strid_name"))
                stIDSName = GetIDSParm(sec.GetAnySetting("ids_name", "strid_name")[0]);

            // TODO: ignore empty IDS based on setting
            //if (stIDSName == "") return;

            var infocard = "";
            if (sec.ContainsAnyOf("ids_info"))
                infocard = GetIDSParm(sec.GetFirstOf("ids_info")[0]);

            float volume = 0;
            if (sec.ContainsAnyOf("volume"))
                volume = float.Parse(sec.GetFirstOf("volume")[0], Nfi);

            // Tested on Disco 4.87.6, no hits beyond this line.
            //var stIDSInfo1 = "";
            //if (sec.ContainsAnyOf("ids_info1","ids_short_name"))
            //    stIDSInfo1 = GetIDSParm(sec.GetAnySetting("ids_info1", "ids_short_name")[0]);

            // Careful with this one below!
            //if (stIDSInfo1 == "") return;
            //var stIDSInfo2 = "";
            //if (sec.ContainsAnyOf("ids_info2"))
            //    stIDSInfo2 = GetIDSParm(sec.GetFirstOf("ids_info2")[0]);

            //var stIDSInfo3 = "";
            //if (sec.ContainsAnyOf("ids_info3"))
            //    stIDSInfo3 = GetIDSParm(sec.GetFirstOf("ids_info3")[0]);

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

            var hpType = "";
            switch (equipType)
            {
                case EquipTypes.Engine:
                    if (sec.ContainsAnyOf("hp_type"))
                        hpType = sec.GetFirstOf("hp_type")[0];
                    break;
                case EquipTypes.Gun:
                    hpType = sec.GetFirstOf("hp_gun_type")[0];
                    equipType = HpMap[hpType];
                    break;
               case EquipTypes.ShieldGen:
                    hpType = sec.GetFirstOf("hp_type")[0];
                    equipType = HpMap[hpType];
                    break;
               case EquipTypes.CountermeasureDropper:
                    hpType = "hp_countermeasure_dropper";
                    break;
               case EquipTypes.Thruster:
                    hpType = "hp_thruster";
                    break;
                    case EquipTypes.Cargo:
                    break;
                default:
                    break;
            }
            // ReSharper disable RedundantArgumentName
            Gis.Equipment.AddEquipmentRow(
                Hash: hash,
                Type: equipType.ToString(),
                Hardpoint: hpType,
                Nickname: nickname,
                Name: stIDSName,
                Infocard: infocard,
                Volume: volume);
            // ReSharper restore RedundantArgumentName
        }
Ejemplo n.º 7
0
        private static void LoadBase(Section sec)
        {
            var nickname = sec.GetFirstOf("nickname")[0];
            //var file = _flDataPath + sec.GetFirstOf("file");
            _log.NewMessage(LogType.Garbage, "Universe: Parsing base {0}", nickname);
            var stIDSName = GetIDSParm(sec.GetAnySetting("ids_name", "strid_name")[0]);
            var system = sec.GetFirstOf("system")[0];
            Gis.Bases.AddBasesRow(nickname, stIDSName,system,"");

            //TODO: do we rly need room data?
            //FLGameData:Ln 191
        }
Ejemplo n.º 8
0
        //TODO: clean dis
        private void ParseBinary(byte[] buf)
        {
            var p = 8;
            //var version = BitConverter.ToInt32(buf, p); p += 4;
            //not used, change the first offset to 4 if reenabled

            var strTableOffset = BitConverter.ToInt32(buf, p); p += 4;

            while (p < buf.Length && p < strTableOffset)
            {
                int sectionStrOffset = BitConverter.ToInt16(buf, p); p += 2;
                int sectionNumEntries = BitConverter.ToInt16(buf, p); p += 2;
                string sectionName = BufToString(buf, strTableOffset + sectionStrOffset);

                var section = new Section(sectionName);
                Sections.Add(section);

                while (sectionNumEntries-- > 0)
                {
                    int entryStrOffset = BitConverter.ToInt16(buf, p); p += 2;
                    int entryNumValues = buf[p++];

                    var set = new Setting(BufToString(buf, strTableOffset + entryStrOffset));
                    //string desc = fileName + ":0x" + p.ToString("x") + " '" + settingName + "'";
                    //object[] values = new object[entryNumValues];

                    for (var currentValue = 0; currentValue < entryNumValues; currentValue++)
                    {
                        int valueType = buf[p++];
                        var value = BitConverter.ToInt32(buf, p); p += 4;
                        switch (valueType)
                        {
                            case 1: // Integer
                                set.AddValue(value.ToString(CultureInfo.InvariantCulture));
                                break;
                            case 2: // Float
                                set.AddValue(BitConverter.ToString(buf, p - 4));
                                break;
                            case 3: // String
                                set.AddValue(BufToString(buf, strTableOffset + value));
                                break;
                            default:
                                throw new Exception("Unexpected value type at offset=" + (p - 1));
                        }
                    }
                    section.Settings.Add(set);
                }
            }
        }
Ejemplo n.º 9
0
        private void Parse(byte[] buf)
        {
            //Watch it go!

            using (var ms = new MemoryStream(buf))
            using (var sr = new StreamReader(ms))
            {
                string s;
                Section curSection = null;
                while ((s = sr.ReadLine()) != null)
                {
                    s = s.Trim();

                    if (s.Length == 0) continue;

                    if (s[0] == ';') continue;

                    if (s[0] == '[')
                    {
                        if (curSection != null)
                        {
                            Sections.Add(curSection);
                        }
                        curSection = new Section(s.Substring(1, s.Length - 2));
                    }
                    else
                    {
                        curSection.AddSetting(s);
                    }
                }

                Sections.Add(curSection);
            }
        }