示例#1
0
        public static bool Init(string[] _basicFileNames, string[] _fileNames, MSGParser DLGParser)
        {
            ProtoNames = DLGParser.GetData();

            if (_fileNames.Length == 0)
            {
                Message.Show("ProtoManager::Init: no extra files specified.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            foreach (string shortfilename in _basicFileNames)
            {
                string filename = Config.PathCritterProtoDir + shortfilename;
                if (!File.Exists(filename))
                {
                    Message.Show("ProtoManager::Init: " + filename + " not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            foreach (string shortfilename in _fileNames)
            {
                string filename = Config.PathCritterProtoDir + shortfilename;
                if (!File.Exists(filename))
                {
                    Message.Show("ProtoManager::Init: " + filename + " not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            BasicFileNames = _basicFileNames;
            FileNames      = _fileNames;
            return(true);
        }
示例#2
0
        public frmEncounterGroupEditor(List <IZone> Zones, FOGAMEParser GameParser, EncounterGroupParser GroupParser, DialogListParser DialogParser, MSGParser FOObj, MSGParser FODLG, DefineParser DefineParser)
        {
            this.Zones        = Zones;
            this.FODLG        = FODLG;
            this.DefineParser = DefineParser;
            this.GameParser   = GameParser;
            this.GroupParser  = GroupParser;
            this.DialogParser = DialogParser;
            InitializeComponent();
            LoadCrTypeDefines();
            LoadArmorProtos(Config.PathArmorProtos, Config.PathHelmetProtos, FOObj);

            foreach (ArmorProto ItProt in ArmorProtos)
            {
                AddArmorProtoToCmb(ItProt, cmbArmorPid);
            }
            foreach (ArmorProto ItProt in HelmetProtos)
            {
                AddArmorProtoToCmb(ItProt, cmbHelmetPid);
            }

            cmbArmorPid.SelectedIndex  = 0;
            cmbHelmetPid.SelectedIndex = 0;

            this.frmFilter = new frmFilter(this.DefineParser, null);
        }
示例#3
0
 public EncounterGroupParser(string filename, FOGAMEParser gameParser, DialogListParser dialogParser, FOGMParser gmParser, MSGParser fodlgParser)
 {
     _gameParser = gameParser;
     _gmParser = gmParser;
     _fodlgParser = fodlgParser;
     _filename = filename;
     _groups = EncounterGroupFormat.Load(filename);
 }
        public List<SimpleItemProto> Load(string FilePath, List<String> Lines, MSGParser FOObj, out bool DuplicateFound)
        {
            SimpleItemProto Prot = null;
            DuplicateFound = false;

            List<int> ProcessedPids = new List<int>();

            foreach (SimpleItemProto LProt in LoadedProtos)
                ProcessedPids.Add(LProt.ProtoId);

            int j = Lines.Count;
            for (int i = 0; i < j; i++)// String Line in Lines)
            {
                String Line = Lines[i];
                if (Line == "[Proto]" || i == Lines.Count - 1)
                {
                    if (Prot != null)
                    {
                        if (FOObj != null)
                        {
                            Prot.Name = FOObj.GetMSGValue(Prot.ProtoId * 100);
                            Prot.Description = FOObj.GetMSGValue(Prot.ProtoId * 100 + 1);
                        }
                        Prot.FileName = Path.GetFileName(FilePath);
                        if (ProcessedPids.Contains(Prot.ProtoId))
                        {
                            DuplicateFound = true;
                            Utils.Log("An object with the ProtoId " + Prot.ProtoId + " was already loaded. Overwriting proto.");
                            for (ushort u = 0; u < LoadedProtos.Count; u++)
                                if (LoadedProtos[u].ProtoId == Prot.ProtoId)
                                    LoadedProtos[u] = Prot;
                        }
                        else
                            LoadedProtos.Add(Prot);

                        ProcessedPids.Add(Prot.ProtoId);
                    }
                    Prot = CreateInstance();
                    continue;
                }

                if (string.IsNullOrEmpty(Lines[i]) || (Lines[i].Length > 0 && Lines[i][0] == '#'))
                    continue;

                String[] Parts = Line.Split('=');
                if (Parts.Length != 2)
                    continue;
                FieldName = Parts[0].Trim();
                FieldValue = Parts[1].TrimStart(' ', '\t');

                if (Prot == null) continue;
                if (FieldName == "ProtoId") { Prot.ProtoId = ushort.Parse(FieldValue); }

                LoadData(Prot);
            }
            return LoadedProtos;
        }
示例#5
0
        private bool LoadArmorProtos(string ArmorPath, string HelmetPath, MSGParser FOObj)
        {
            FOCommon.Parsers.SimpleItemProtoParser ItemParser = new FOCommon.Parsers.SimpleItemProtoParser(new ArmorProto());
            bool DuplicatesFound = false;

            ArmorProtos  = ItemParser.LoadProtosFromFile(ArmorPath, FOObj, out DuplicatesFound).Cast <ArmorProto>().ToList();
            ItemParser   = new FOCommon.Parsers.SimpleItemProtoParser(new ArmorProto());
            HelmetProtos = ItemParser.LoadProtosFromFile(HelmetPath, FOObj, out DuplicatesFound).Cast <ArmorProto>().ToList();
            return(true);
        }
        public frmEncounterGroupEditor(List<IZone> Zones, FOGAMEParser GameParser, EncounterGroupParser GroupParser, DialogListParser DialogParser, MSGParser FOObj, MSGParser FODLG, DefineParser DefineParser)
        {
            this.Zones = Zones;
            this.FODLG = FODLG;
            this.DefineParser = DefineParser;
            this.GameParser = GameParser;
            this.GroupParser = GroupParser;
            this.DialogParser = DialogParser;
            InitializeComponent();
            LoadCrTypeDefines();
            LoadArmorProtos(Config.PathArmorProtos, Config.PathHelmetProtos, FOObj);

            foreach (ArmorProto ItProt in ArmorProtos)
                AddArmorProtoToCmb(ItProt, cmbArmorPid);
            foreach (ArmorProto ItProt in HelmetProtos)
                AddArmorProtoToCmb(ItProt, cmbHelmetPid);

            cmbArmorPid.SelectedIndex = 0;
            cmbHelmetPid.SelectedIndex = 0;

            this.frmFilter = new frmFilter(this.DefineParser, null);
        }
        private bool LoadArmorProtos(string ArmorPath, string HelmetPath, MSGParser FOObj)
        {
            FOCommon.Parsers.SimpleItemProtoParser ItemParser = new FOCommon.Parsers.SimpleItemProtoParser(new ArmorProto());
            bool DuplicatesFound=false;

            ArmorProtos = ItemParser.LoadProtosFromFile(ArmorPath, FOObj, out DuplicatesFound).Cast<ArmorProto>().ToList();
            ItemParser = new FOCommon.Parsers.SimpleItemProtoParser(new ArmorProto());
            HelmetProtos = ItemParser.LoadProtosFromFile(HelmetPath, FOObj, out DuplicatesFound).Cast<ArmorProto>().ToList();
            return true;
        }
示例#8
0
 private void InitFOObj()
 {
     FOObj = new MSGParser(Config.PathObjMsg);
     if (!FOObj.Parse())
         Utils.Log("Failed to parse FOObj.msg");
 }
示例#9
0
        private void resourceLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\items");
            this.EditorData.GraphicsPaths.Add("art\\tiles");
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\walls");
            this.EditorData.GraphicsPaths.Add("art\\door");
            this.EditorData.GraphicsPaths.Add("art\\scenery");

            Stream stream;
            BinaryFormatter formatter = new BinaryFormatter();

            stream = null;

            this.BeginInvoke((MethodInvoker)delegate
            {
                frmLoading = new frmLoading();
                frmLoading.ShowDialog();

                int count = mapperSettings.Paths.DataFiles.Count;

                if (!File.Exists("./critters.dat")) count++;
                if (!File.Exists("./items.dat")) count++;

                frmLoading.SetFilesNum(count);
            });

            if (File.Exists("./critters.dat"))
            {
                stream = File.OpenRead("./critters.dat");
                critterData = (CritterData)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                List<string> crFiles = new List<string>(Directory.GetFiles(mapperSettings.Paths.CritterProtos));

                this.BeginInvoke((MethodInvoker)delegate
                {
                    frmLoading.SetNextFile(mapperSettings.Paths.CritterProtos);
                    frmLoading.SetResourceNum(crFiles.Count);
                });

                foreach (string file in crFiles)
                {
                    this.BeginInvoke((MethodInvoker)delegate
                    {
                        frmLoading.SetNextResource(file);
                    });

                    int pid = 0;
                    int crType = 0;
                    bool parse = false;
                    foreach (var line in File.ReadAllLines(file))
                    {
                        if (line == "[Critter proto]")
                            if (parse)
                                critterData.crProtos[pid] = crType;
                        parse = true;
                        if (!parse) continue;
                        if (line.StartsWith("Pid="))
                            pid = int.Parse(line.Split('=')[1]);
                        if (line.StartsWith("ST_BASE_CRTYPE="))
                            crType = int.Parse(line.Split('=')[1]);
                    }
                }

                char[] delim = { '\t', ' ' };
                foreach (var line in File.ReadAllLines(mapperSettings.Paths.CritterTypes))
                {
                    if (!line.StartsWith("@")) continue;
                    var toks = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    critterData.crTypeGraphic[int.Parse(toks[1])] = toks[2];
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./critters.dat");
                    formatter.Serialize(stream, critterData);
                }
            }

            if (File.Exists("./items.dat"))
            {
                stream = File.OpenRead("./items.dat");
                items = (List<ItemProto>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                MSGParser FOObj = new MSGParser(mapperSettings.Paths.FOOBJ);
                FOObj.Parse();

                string itemslst = mapperSettings.Paths.ItemProtos + "\\items.lst";

                if (!File.Exists(itemslst))
                {
                    MessageBox.Show("No " + itemslst + " , unable to load item protos.", "No items.lst", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    List<string> protFiles = new List<string>(File.ReadAllLines(itemslst));

                    this.BeginInvoke((MethodInvoker)delegate
                    {
                        frmLoading.SetNextFile(itemslst);
                        frmLoading.SetResourceNum(protFiles.Count);
                    });

                    foreach (string file in protFiles)
                    {
                        this.BeginInvoke((MethodInvoker)delegate { frmLoading.SetNextResource(file); });
                        protoParser.LoadProtosFromFile(mapperSettings.Paths.ItemProtos + file, "1.0", FOObj, items, null);
                    }
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./items.dat");
                    formatter.Serialize(stream, items);
                }
            }

            foreach (var item in items)
                EditorData.itemsPid[item.ProtoId] = item;

            if (File.Exists("./graphics.dat"))
            {
                stream = File.OpenRead("./graphics.dat");
                Frms = (Dictionary<String, FalloutFRM>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                if (mapperSettings.Paths.DataFiles == null || mapperSettings.Paths.DataFiles.Count == 0)
                {
                    MessageBox.Show("No datafiles specified, unable to load graphics!");
                    frmPaths.ShowDialog();
                }

                if (mapperSettings.Paths.DataFiles != null || mapperSettings.Paths.DataFiles.Count != 0)
                {

                    List<string> crFiles = new List<string>();
                    foreach (var crType in critterData.crTypeGraphic.Values)
                    {
                        crFiles.Add("art\\critters\\" + crType.ToUpper() + "AA.FRM"); // Idle anim
                        crFiles.Add("art\\critters\\" + crType.ToLower() + "aa.frm");
                    }

                    foreach (string dataFile in mapperSettings.Paths.DataFiles)
                    {
                        string ext = Path.GetExtension(dataFile).ToLower();
                        if (ext != ".dat" && ext != ".zip")
                        {
                            MessageBox.Show("Unknown datafile extension : " + dataFile);
                            continue;
                        }
                        if (ext == ".dat")
                            LoadDat(dataFile, crFiles, transparency);
                        else
                            LoadZip(dataFile, crFiles, transparency);
                    }

                    if (mapperSettings.Performance.CacheResources)
                    {
                        stream = File.Create("./graphics.dat");
                        formatter.Serialize(stream, Frms);
                    }
                }
            }

            showLoadMaps();

            if (stream != null) stream.Close();
        }
示例#10
0
 public DialogParser(String fileName)
 {
     this._fileName = fileName;
     _textStrings = new MSGParser(fileName);
 }
示例#11
0
        private void resourceLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\items");
            this.EditorData.GraphicsPaths.Add("art\\tiles");
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\walls");
            this.EditorData.GraphicsPaths.Add("art\\door");
            this.EditorData.GraphicsPaths.Add("art\\scenery");

            Stream          stream;
            BinaryFormatter formatter = new BinaryFormatter();

            stream = null;

            this.BeginInvoke((MethodInvoker) delegate
            {
                frmLoading = new frmLoading();
                frmLoading.ShowDialog();

                int count = mapperSettings.Paths.DataFiles.Count;

                if (!File.Exists("./critters.dat"))
                {
                    count++;
                }
                if (!File.Exists("./items.dat"))
                {
                    count++;
                }

                frmLoading.SetFilesNum(count);
            });


            if (File.Exists("./critters.dat"))
            {
                stream      = File.OpenRead("./critters.dat");
                critterData = (CritterData)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                List <string> crFiles = new List <string>(Directory.GetFiles(mapperSettings.Paths.CritterProtos));

                this.BeginInvoke((MethodInvoker) delegate
                {
                    frmLoading.SetNextFile(mapperSettings.Paths.CritterProtos);
                    frmLoading.SetResourceNum(crFiles.Count);
                });

                foreach (string file in crFiles)
                {
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        frmLoading.SetNextResource(file);
                    });

                    int  pid    = 0;
                    int  crType = 0;
                    bool parse  = false;
                    foreach (var line in File.ReadAllLines(file))
                    {
                        if (line == "[Critter proto]")
                        {
                            if (parse)
                            {
                                critterData.crProtos[pid] = crType;
                            }
                        }
                        parse = true;
                        if (!parse)
                        {
                            continue;
                        }
                        if (line.StartsWith("Pid="))
                        {
                            pid = int.Parse(line.Split('=')[1]);
                        }
                        if (line.StartsWith("ST_BASE_CRTYPE="))
                        {
                            crType = int.Parse(line.Split('=')[1]);
                        }
                    }
                }

                char[] delim = { '\t', ' ' };
                foreach (var line in File.ReadAllLines(mapperSettings.Paths.CritterTypes))
                {
                    if (!line.StartsWith("@"))
                    {
                        continue;
                    }
                    var toks = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    critterData.crTypeGraphic[int.Parse(toks[1])] = toks[2];
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./critters.dat");
                    formatter.Serialize(stream, critterData);
                }
            }

            if (File.Exists("./items.dat"))
            {
                stream = File.OpenRead("./items.dat");
                items  = (List <ItemProto>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                MSGParser FOObj = new MSGParser(mapperSettings.Paths.FOOBJ);
                FOObj.Parse();

                string itemslst = mapperSettings.Paths.ItemProtos + "\\items.lst";

                if (!File.Exists(itemslst))
                {
                    MessageBox.Show("No " + itemslst + " , unable to load item protos.", "No items.lst", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    List <string> protFiles = new List <string>(File.ReadAllLines(itemslst));

                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        frmLoading.SetNextFile(itemslst);
                        frmLoading.SetResourceNum(protFiles.Count);
                    });

                    foreach (string file in protFiles)
                    {
                        this.BeginInvoke((MethodInvoker) delegate { frmLoading.SetNextResource(file); });
                        protoParser.LoadProtosFromFile(mapperSettings.Paths.ItemProtos + file, "1.0", FOObj, items, null);
                    }
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./items.dat");
                    formatter.Serialize(stream, items);
                }
            }

            foreach (var item in items)
            {
                EditorData.itemsPid[item.ProtoId] = item;
            }

            if (File.Exists("./graphics.dat"))
            {
                stream = File.OpenRead("./graphics.dat");
                Frms   = (Dictionary <String, FalloutFRM>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                if (mapperSettings.Paths.DataFiles == null || mapperSettings.Paths.DataFiles.Count == 0)
                {
                    MessageBox.Show("No datafiles specified, unable to load graphics!");
                    frmPaths.ShowDialog();
                }

                if (mapperSettings.Paths.DataFiles != null || mapperSettings.Paths.DataFiles.Count != 0)
                {
                    List <string> crFiles = new List <string>();
                    foreach (var crType in critterData.crTypeGraphic.Values)
                    {
                        crFiles.Add("art\\critters\\" + crType.ToUpper() + "AA.FRM"); // Idle anim
                        crFiles.Add("art\\critters\\" + crType.ToLower() + "aa.frm");
                    }

                    foreach (string dataFile in mapperSettings.Paths.DataFiles)
                    {
                        string ext = Path.GetExtension(dataFile).ToLower();
                        if (ext != ".dat" && ext != ".zip")
                        {
                            MessageBox.Show("Unknown datafile extension : " + dataFile);
                            continue;
                        }
                        if (ext == ".dat")
                        {
                            LoadDat(dataFile, crFiles, transparency);
                        }
                        else
                        {
                            LoadZip(dataFile, crFiles, transparency);
                        }
                    }

                    if (mapperSettings.Performance.CacheResources)
                    {
                        stream = File.Create("./graphics.dat");
                        formatter.Serialize(stream, Frms);
                    }
                }
            }

            showLoadMaps();

            if (stream != null)
            {
                stream.Close();
            }
        }
示例#12
0
        // TODO: Refactor
        public bool Load(string FilePath, string Version, List<String> Lines, MSGParser FOObj, Dictionary<String, ItemProtoCustomField> CustomFields)
        {
            ItemProto Prot = null;
            bool CompatibilityMode = false;
            bool DuplicateFound = false;

            List<int> ProcessedPids = new List<int>();

            foreach (ItemProto LProt in _loadedProtos)
                ProcessedPids.Add(LProt.ProtoId);

            bool IsCar = false; // Compatibility
            bool IsNoOpen = false; // Compatibility

            int j = Lines.Count;
            for(int i=0;i<j;i++)// String Line in Lines)
            {
                    String Line = Lines[i];
                    if (Line == "[Proto]"||i==Lines.Count-1)
                    {

                        if (Prot != null)
                        {

                            if (FOObj != null)
                            {
                                Prot.Name = FOObj.GetMSGValue(Prot.ProtoId * 100);
                                Prot.Description = FOObj.GetMSGValue(Prot.ProtoId * 100 + 1);
                            }
                            //Prot.FileName = Path.GetFileName(FilePath);
                            Prot.FileName = FilePath;
                            if (CompatibilityMode)
                            {
                                ConvertStuff(ref Prot, IsCar, IsNoOpen);
                                CompatibilityMode = false;
                            }
                            IsCar = false;
                            IsNoOpen = false;

                            if (ProcessedPids.Contains(Prot.ProtoId))
                            {
                                DuplicateFound = true;
                                Utils.Log("An object with the ProtoId " + Prot.ProtoId + " was already loaded. Overwriting proto.");
                                for (ushort u = 0; u < _loadedProtos.Count; u++)
                                    if (_loadedProtos[u].ProtoId == Prot.ProtoId)
                                        _loadedProtos[u] = Prot;
                            }
                            else
                            {
                                if(Prot.ProtoId!=0)
                                    _loadedProtos.Add(Prot);
                            }

                            ProcessedPids.Add(Prot.ProtoId);
                        }
                        Prot = new ItemProto();
                        continue;
                    }

                    if (string.IsNullOrEmpty(Lines[i]) || (Lines[i].Length>0 && Lines[i][0]=='#'))
                        continue;

                    if (FOObj != null && Prot!=null)
                    {
                        Prot.Name = FOObj.GetMSGValue(Prot.ProtoId * 100);
                        Prot.Description = FOObj.GetMSGValue(Prot.ProtoId * 100 + 1);
                    }

                    String[] Parts = Line.Split('=');
                    if (Parts.Length != 2)
                        continue;
                    _fieldName = Parts[0].Trim();
                    _fieldValue = Parts[1].TrimStart(' ','\t');

                    if (Prot == null) continue;

                    if (_fieldName == "Pid") { Prot.ProtoId = ushort.Parse(_fieldValue); CompatibilityMode = true; }
                    if (_fieldName == "MiscEx.IsCar") IsCar=true;
                    if (_fieldName == "Container.IsNoOpen") IsNoOpen = true;

                    if(Prot!=null)
                        ParseData(ref Prot, CompatibilityMode, true);

                    if (CustomFields == null)
                        continue;
                foreach (KeyValuePair<String, ItemProtoCustomField> kvp in CustomFields)
                {
                    if (_fieldName == kvp.Key || _fieldName.Replace('.', '_') == kvp.Key)
                    {
                        try
                        {
                            ItemProtoCustomField NewCustom = new ItemProtoCustomField(kvp.Key,
                                                                                      (Utils.DataType)
                                                                                      kvp.Value.Type);
                            if (NewCustom.Type == (Byte)Utils.DataType.BOOL)
                                NewCustom.Value = (_fieldValue == "1");
                            else if (NewCustom.Type == (Byte)Utils.DataType.SBYTE)
                                NewCustom.Value = SByte.Parse(_fieldValue);
                            else if (NewCustom.Type == (Byte)Utils.DataType.INT)
                                NewCustom.Value = Int32.Parse(_fieldValue);
                            else if (NewCustom.Type == (Byte)Utils.DataType.INT16)
                                NewCustom.Value = Int16.Parse(_fieldValue);
                            else if (NewCustom.Type == (Byte)Utils.DataType.UINT)
                                NewCustom.Value = UInt32.Parse(_fieldValue);
                            else if (NewCustom.Type == (Byte)Utils.DataType.UINT16)
                                NewCustom.Value = UInt16.Parse(_fieldValue);
                            Prot.CustomFields.Add(kvp.Key, NewCustom);
                        }
                        catch (OverflowException ex)
                        {
                            Utils.Log(ex.Message + " in ProtoId " + Prot.ProtoId + " ,field " + _fieldName +
                                      " value: " + _fieldValue);
                        }
                    }
                }
            }
                return DuplicateFound;
        }
示例#13
0
 public List<SimpleItemProto> LoadProtosFromFile(String Path, MSGParser FOObj, out bool DuplicatesFound)
 {
     List<String> Lines = new List<string>(File.ReadAllLines(Path));
     return Load(Path, Lines, FOObj, out DuplicatesFound);
 }
示例#14
0
 public bool SaveProtosToFile(String Path, String Version, MSGParser FOObj, List<ItemProto> SaveProtos, Dictionary<string, ItemProtoCustomField> CustomFields, bool FormatWithSpace)
 {
     this._saveProtos = SaveProtos;
     this._formatWithSpaces = FormatWithSpace;
     bool DuplicateFound = Save(Path, Version, null, FOObj, CustomFields);
     File.WriteAllLines(Path, _saveLines.ToArray(), new UTF8Encoding(false));
     return DuplicateFound;
 }
示例#15
0
        public bool Save(string FilePath, string Version, List<String> Lines, MSGParser FOObj, Dictionary<String, ItemProtoCustomField> CustomFields)
        {
            List<int> ProcessedPids = new List<int>();
            bool DuplicateFound = false;

            _saveLines.Clear();
            _saveLines.Add("# " + Version);
            _saveLines.Add("");

            _saveProtos.Sort();

            int j = _saveProtos.Count;
            for (int i = 0; i < j; i++)
            {
                _saveLines.Add("[Proto]");
                ItemProto Prot = _saveProtos[i];

                ParseData(ref Prot, false, false);

                if (ProcessedPids.Contains(Prot.ProtoId))
                {
                    Utils.Log("An object with the ProtoId " + Prot.ProtoId + " was already saved. Skipping proto '" + Prot.Name + '\'');
                    //Message.Show("An object with the ProtoId " + Prot.ProtoId + " was already saved. Skipping proto '"+Prot.Name+'\'',
                    //    System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, true);
                    DuplicateFound = true;
                    continue;
                }
                if (Prot != null && Prot.CustomFields != null)
                {
                    foreach (KeyValuePair<String, ItemProtoCustomField> kvp in Prot.CustomFields)
                    {
                        if (kvp.Value.Value is bool)
                            _saveLines.Add(kvp.Key + "=" + ((bool)kvp.Value.Value==true?"1":"0") );
                        else
                            _saveLines.Add(kvp.Key + "=" + kvp.Value.Value.ToString());
                    }
                }
                if(!String.IsNullOrEmpty(Prot.Name))
                    FOObj.WriteMSGLine(Prot.ProtoId * 100, Prot.Name, 0);
                if (!String.IsNullOrEmpty(Prot.Description))
                    FOObj.WriteMSGLine(Prot.ProtoId * 100 + 1, Prot.Description, 0);
                _saveLines.Add("");

                ProcessedPids.Add(Prot.ProtoId);
            }

            FOObj.WriteFile(); // Flush file.
            return DuplicateFound;
        }
示例#16
0
 public bool LoadProtosFromFile(String Path, String Version, MSGParser FOObj, List<ItemProto> LoadedProtos,
     Dictionary<string, ItemProtoCustomField> CustomFields)
 {
     List<String> Lines = new List<string>(File.ReadAllLines(Path, new UTF8Encoding(false)));
     this._loadedProtos = LoadedProtos;
     return Load(Path, Version, Lines, FOObj, CustomFields);
 }
示例#17
0
        public static bool Init(string[] _basicFileNames, string[] _fileNames, MSGParser DLGParser)
        {
            ProtoNames = DLGParser.GetData();

            if (_fileNames.Length == 0)
            {
                Message.Show("ProtoManager::Init: no extra files specified.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            foreach (string shortfilename in _basicFileNames)
            {
                string filename = Config.PathCritterProtoDir + shortfilename;
                if (!File.Exists(filename))
                {
                    Message.Show("ProtoManager::Init: " + filename + " not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            foreach (string shortfilename in _fileNames)
            {
                string filename = Config.PathCritterProtoDir + shortfilename;
                if (!File.Exists(filename))
                {
                    Message.Show("ProtoManager::Init: " + filename + " not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }

            BasicFileNames = _basicFileNames;
            FileNames = _fileNames;
            return true;
        }
示例#18
0
 public FOGAMEParser(string path)
 {
     this._msgParser = new MSGParser(path);
 }