// 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); }
void SetCustomTabPage(ref ItemProto Prot, TabPage Page, bool ToUI) { foreach (Control Ctrl in Page.Controls) { if (Ctrl is NumericUpDown) { NumericUpDown Num = (NumericUpDown)Ctrl; FieldObject FieldData; FieldData = (FieldObject)Num.Tag; if (FieldData == null) continue; if (ToUI) { Num.Value = 0; if (Prot.CustomFields.ContainsKey(FieldData.CustomFieldName)) { if (Prot.CustomFields[FieldData.CustomFieldName].Value is Decimal) Num.Value = (decimal)Prot.CustomFields[FieldData.CustomFieldName].Value; if (Prot.CustomFields[FieldData.CustomFieldName].Value is int) Num.Value = (int)Prot.CustomFields[FieldData.CustomFieldName].Value; if (Prot.CustomFields[FieldData.CustomFieldName].Value is uint) Num.Value = (uint)Prot.CustomFields[FieldData.CustomFieldName].Value; if (Prot.CustomFields[FieldData.CustomFieldName].Value is UInt16) Num.Value = (UInt16)Prot.CustomFields[FieldData.CustomFieldName].Value; if (Prot.CustomFields[FieldData.CustomFieldName].Value is Int16) Num.Value = (Int16)Prot.CustomFields[FieldData.CustomFieldName].Value; if (Prot.CustomFields[FieldData.CustomFieldName].Value is SByte) Num.Value = (SByte)Prot.CustomFields[FieldData.CustomFieldName].Value; } } else { if (Prot.CustomFields.ContainsKey(FieldData.CustomFieldName)) Prot.CustomFields[FieldData.CustomFieldName].Value = Num.Value; if (Num.Value != 0 && !Prot.CustomFields.ContainsKey(FieldData.CustomFieldName)) { ItemProtoCustomField NewField = new ItemProtoCustomField(FieldData.CustomFieldName, FOCommon.Utils.GetTypeFromString(FieldData.DataType)); NewField.Value = Num.Value; Prot.CustomFields.Add(FieldData.CustomFieldName, NewField); } } } else if (Ctrl is CheckBox) { CheckBox Chk = (CheckBox)Ctrl; FieldObject FieldData; FieldData = (FieldObject)Chk.Tag; if (FieldData == null) continue; if (ToUI) { if (Prot.CustomFields.ContainsKey(FieldData.CustomFieldName) && Prot.CustomFields[FieldData.CustomFieldName].Value is bool) Chk.Checked = (bool)Prot.CustomFields[FieldData.CustomFieldName].Value; else Chk.Checked = false; } else { if (Prot.CustomFields.ContainsKey(FieldData.CustomFieldName)) Prot.CustomFields[FieldData.CustomFieldName].Value = Chk.Checked; if (Chk.Checked && !Prot.CustomFields.ContainsKey(FieldData.CustomFieldName)) { ItemProtoCustomField NewField = new ItemProtoCustomField(FieldData.CustomFieldName, FOCommon.Utils.GetTypeFromString(FieldData.DataType)); NewField.Value = true; Prot.CustomFields.Add(FieldData.CustomFieldName, NewField); } } } } }
// 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; }