private Node ParseNode(Regex langEndLine, IEnumerable <string> languages, string[] parts, ref int nodeNum) { nodeNum++; var node = new Node { Id = Int32.Parse(parts[0]), ScriptString = parts[2], ShuffleAnswers = (parts[3] != "1") }; foreach (String lang in languages) { Regex langStartLine = new Regex("^\\[" + lang + "\\]"); node.Text[lang] = _textStrings.GetMSGValue(nodeNum * 1000, langStartLine, langEndLine); } return(node); }
private static void MakeNames() { StatNames = new List <string>(); SkillNames = new List <string>(); PerkNames = new List <string>(); for (int i = StatBegin; i <= StatEnd; i++) { String s = MsgParser.GetMSGValue(10 * i + 100001); if (s.Equals("")) { s = i.ToString(); } StatNames.Add(s); } for (int i = SkillBegin; i <= SkillEnd; i++) { String s = MsgParser.GetMSGValue(10 * i + 100001); if (s.Equals("")) { s = i.ToString(); } SkillNames.Add(s); } for (int i = PerkBegin; i <= PerkEnd; i++) { String s = MsgParser.GetMSGValue(10 * i + 100001); if (s.Equals("")) { s = i.ToString(); } PerkNames.Add(s); } }
// 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); }
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); }