Ejemplo n.º 1
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));
        }
 public EncounterGroupParser(string filename, FOGAMEParser gameParser, DialogListParser dialogParser, FOGMParser gmParser, MSGParser fodlgParser)
 {
     _gameParser  = gameParser;
     _gmParser    = gmParser;
     _fodlgParser = fodlgParser;
     _filename    = filename;
     _groups      = EncounterGroupFormat.Load(filename);
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public FOGAMEParser(string path)
 {
     this._msgParser = new MSGParser(path);
 }
Ejemplo n.º 6
0
 public DialogParser(String fileName)
 {
     this._fileName = fileName;
     _textStrings   = new MSGParser(fileName);
 }
Ejemplo n.º 7
0
        public static bool LoadConfig()
        {
            StreamReader file;
            try
            {
                file = File.OpenText("PerkEditor.cfg");
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot open the config file.");
                return false;
            }

            try
            {
                string rec = file.ReadLine();
                Regex regexp = new Regex(@"([^=]+)=([^=]+)");
                Match match = regexp.Match(rec);
                if (!match.Success || !match.Groups[1].Value.Equals("server"))
                {
                    MessageBox.Show("Cannot parse the config file.");
                    return false;
                }
                ServerPath = match.Groups[2].Value;
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot parse the config file.");
                return false;
            }
            MsgParser = new FOCommon.Parsers.MSGParser(ServerPath + "/text/engl/FOGAME.MSG");
            if (!MsgParser.Parse())
            {
                MessageBox.Show("Cannot parse FOGAME.MSG.");
                return false;
            }

            try
            {
                StreamReader reader = new StreamReader(ServerPath + "/scripts/_defines.fos");

                Regex expr = new Regex(@"#pragma[\s]+crdata[\s]+""[\s]*([^\s]+)[\s]+([^\s]+)[\s]+([^\s]+)[\s]*""");
                while (!reader.EndOfStream)
                {
                    string s = reader.ReadLine();
                    Match match = expr.Match(s);
                    if (!match.Success) continue;
                    //MessageBox.Show(match.Groups[1].Value + "," + match.Groups[2].Value + "," + match.Groups[3].Value);
                    if (match.Groups[1].Value.Equals("Stat"))
                    {
                        StatBegin = Int32.Parse(match.Groups[2].Value);
                        StatEnd = Int32.Parse(match.Groups[3].Value);
                    }
                    else if (match.Groups[1].Value.Equals("Skill"))
                    {
                        SkillBegin = Int32.Parse(match.Groups[2].Value);
                        SkillEnd = Int32.Parse(match.Groups[3].Value);
                    }
                    else if (match.Groups[1].Value.Equals("Perk"))
                    {
                        PerkBegin = Int32.Parse(match.Groups[2].Value);
                        PerkEnd = Int32.Parse(match.Groups[3].Value);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot open _defines.fos.");
                return false;
            }
            MakeNames();
            return true;
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public static bool LoadConfig()
        {
            StreamReader file;

            try
            {
                file = File.OpenText("PerkEditor.cfg");
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot open the config file.");
                return(false);
            }

            try
            {
                string rec    = file.ReadLine();
                Regex  regexp = new Regex(@"([^=]+)=([^=]+)");
                Match  match  = regexp.Match(rec);
                if (!match.Success || !match.Groups[1].Value.Equals("server"))
                {
                    MessageBox.Show("Cannot parse the config file.");
                    return(false);
                }
                ServerPath = match.Groups[2].Value;
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot parse the config file.");
                return(false);
            }
            MsgParser = new FOCommon.Parsers.MSGParser(ServerPath + "/text/engl/FOGAME.MSG");
            if (!MsgParser.Parse())
            {
                MessageBox.Show("Cannot parse FOGAME.MSG.");
                return(false);
            }

            try
            {
                StreamReader reader = new StreamReader(ServerPath + "/scripts/_defines.fos");

                Regex expr = new Regex(@"[\s]*#[\s]*pragma[\s]+crdata[\s]+""[\s]*([^\s]+)[\s]+([^\s]+)[\s]+([^\s]+)[\s]*""");
                while (!reader.EndOfStream)
                {
                    string s     = reader.ReadLine();
                    Match  match = expr.Match(s);
                    if (!match.Success)
                    {
                        continue;
                    }
                    //MessageBox.Show(match.Groups[1].Value + "," + match.Groups[2].Value + "," + match.Groups[3].Value);
                    if (match.Groups[1].Value.Equals("Stat"))
                    {
                        StatBegin = Int32.Parse(match.Groups[2].Value);
                        StatEnd   = Int32.Parse(match.Groups[3].Value);
                    }
                    else if (match.Groups[1].Value.Equals("Skill"))
                    {
                        SkillBegin = Int32.Parse(match.Groups[2].Value);
                        SkillEnd   = Int32.Parse(match.Groups[3].Value);
                    }
                    else if (match.Groups[1].Value.Equals("Perk"))
                    {
                        PerkBegin = Int32.Parse(match.Groups[2].Value);
                        PerkEnd   = Int32.Parse(match.Groups[3].Value);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot parse _defines.fos.");
                return(false);
            }
            MakeNames();
            return(true);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
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));
        }