private void ParseContent() { Data = new TypedObject(); string[] strLines = strDecryptedContent.Split(new string[] { "\n" }, StringSplitOptions.None); this.intLines = strLines.Length; ArrayList arrTabDepth = new ArrayList(); ArrayList arrBlocks = new ArrayList(); ArrayList arrSections = new ArrayList(); TypedObject htDataGroup = new TypedObject(); int intKeyID = 0; // Loop trough each line. for (int i = 0; i < strLines.Length; i++) { string strCurrentLine = strLines[i]; string strBegin = strLines[i].Split('=')[0]; int intTabCount = strBegin.Length - strBegin.Replace("\t", "").Length; // Tab count is depth int intDirection = 0; if (arrTabDepth.Count != intTabCount) { intDirection = intTabCount - arrTabDepth.Count; } // Remove Tabs string strValue = strBegin.Replace("\t", "").Trim(); // Check type if (strValue.StartsWith("[") && strValue.EndsWith("]")) { string strArrayKey = strValue.Replace("[", "").Replace("]", "").ToLower(); // Remove brachets if (!strArrayKey.StartsWith("/")) { // ADD BLOCKS // if (arrTabDepth.Count <= intTabCount) { arrTabDepth.Add(strArrayKey); } else { arrTabDepth[arrTabDepth.Count - 1] = strArrayKey; } arrBlocks.Add(new TypedObject()); } else { // End of the block, Save it int intCurrentKeyIndex = arrTabDepth.Count - 1; string strCurrentKey = arrTabDepth[intCurrentKeyIndex].ToString(); int intCurrentBlock = arrBlocks.Count - 1; // Copy it all over, lazy way. TypedObject htCopy = new TypedObject(htDataGroup.Type); if (intKeyID > 0) { foreach (DictionaryEntry entry in htDataGroup) { if (htCopy.ContainsKey(entry.Key)) { htCopy[entry.Key] = entry.Value; } else { htCopy.Add(entry.Key, entry.Value); } } htDataGroup.Clear(); intKeyID = 0; } else { foreach (DictionaryEntry entry in (TypedObject)arrBlocks[intCurrentBlock]) { if (htCopy.ContainsKey(entry.Key)) { htCopy[entry.Key] = entry.Value; } else { htCopy.Add(entry.Key, entry.Value); } } } // Remove Hashtable // arrBlocks.RemoveAt(intCurrentBlock); if (arrBlocks.Count > 0) { ((TypedObject)arrBlocks[arrBlocks.Count - 1]).Add(strCurrentKey, htCopy); // move to previous block } else { Data.Add(strCurrentKey, htCopy); } arrTabDepth.RemoveAt(intCurrentKeyIndex); // Remove from index. } } else if (strValue.StartsWith("<") && !strValue.StartsWith("<!") && strValue.EndsWith(">")) { // Sub section we go one deeper! string strSectionKey = strValue.Replace("<", "").Replace(">", "").ToLower(); // Remove <> if (!strSectionKey.StartsWith("/")) // NEW SECTION // { if (arrTabDepth.Count <= intTabCount) { arrTabDepth.Add(strSectionKey); } else { arrTabDepth[arrTabDepth.Count - 1] = strSectionKey; } //Console.WriteLine("<" + strSectionKey.ToUpper() + "> @ Line: " + (i + 1).ToString() + " ADD SECTION"); arrSections.Add(new TypedObject()); } else { // REMOVE SECTION // int intSectionIndex = arrTabDepth.Count - 1; string strCurrentKey = arrTabDepth[intSectionIndex].ToString(); int intCurrentSubSection = arrSections.Count - 1; // Copy it all over, lazy way. TypedObject htCopy = new TypedObject(); foreach (DictionaryEntry entry in (TypedObject)(arrSections[intCurrentSubSection])) { if (htCopy.ContainsKey(entry.Key)) { htCopy[entry.Key] = entry.Value; } else { htCopy.Add(entry.Key, entry.Value); } } // Remove Hashtable of the current section // arrSections.RemoveAt(intCurrentSubSection); //Console.WriteLine("<" + strSectionKey.ToUpper() + "> @ Line: " + (i + 1).ToString() + " REMOVE SECTION"); // Are there sub sections underneath? if (arrSections.Count > 0) // Yes, Let's insert the data in the previous one. // Check for duplicates. { if (((TypedObject)arrSections[arrSections.Count - 1]).ContainsKey(strCurrentKey)) { int intNumber = 1; string newKey = string.Concat(strCurrentKey, intNumber); while (((TypedObject)arrSections[arrSections.Count - 1]).ContainsKey(newKey)) { intNumber++; newKey = string.Concat(strCurrentKey, i); } ((TypedObject)arrSections[arrSections.Count - 1]).Add(newKey, htCopy); } else { ((TypedObject)arrSections[arrSections.Count - 1]).Add(strCurrentKey, htCopy); // Add it } } else // No, okay.. Add the data to the branch. { ((TypedObject)arrBlocks[arrBlocks.Count - 1]).Add(strCurrentKey, htCopy); } arrTabDepth.RemoveAt(intSectionIndex); // Remove section } } else { if (arrTabDepth.Count > 1) { string strLine = strCurrentLine.Replace("\t", "").Replace(" ", ""); // Remove tabs + spaces if (strLine.StartsWith("<!")) { // New group of data. intKeyID = intKeyID + 1; // Increase key ID } else if (strLine.StartsWith("//") && strLine.EndsWith("->")) { // Copy it all over, lazy way. TypedObject htCopy = new TypedObject(); foreach (DictionaryEntry entry in (TypedObject)arrBlocks[arrBlocks.Count - 1]) { if (htCopy.ContainsKey(entry.Key)) { htCopy[entry.Key] = entry.Value; } else { htCopy.Add(entry.Key, entry.Value); } } htDataGroup.Add(intKeyID, htCopy); ((TypedObject)arrBlocks[arrBlocks.Count - 1]).Clear(); } else { string[] sectionData = strLine.Split('='); string key = sectionData[0]; string value = ""; if (sectionData.Length > 1) // Just in case { value = sectionData[1]; } ((TypedObject)arrSections[arrSections.Count - 1]).Add(key.ToLower(), value); } } else { // Unknown line. } } } }
public TypedObject GetBaseTypedObject() { TypedObject obj2 = new TypedObject(this.TypeName); Type type = base.GetType(); foreach (PropertyInfo info in type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { InternalNameAttribute attribute = info.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute; if (attribute != null) { object item = null; Type propertyType = info.PropertyType; string name = propertyType.Name; if (propertyType == typeof(int[])) { int[] source = info.GetValue(this) as int[]; if (source != null) { item = source.Cast <object>().ToArray <object>(); } } else if (propertyType == typeof(double[])) { double[] numArray2 = info.GetValue(this) as double[]; if (numArray2 != null) { item = numArray2.Cast <object>().ToArray <object>(); } } else if (propertyType == typeof(string[])) { string[] strArray = info.GetValue(this) as string[]; if (strArray != null) { item = strArray.Cast <object>().ToArray <object>(); } } else if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(List <>))) { IList list = info.GetValue(this) as IList; if (list != null) { object[] array = new object[list.Count]; list.CopyTo(array, 0); List <object> list2 = new List <object>(); foreach (object obj4 in array) { Type c = obj4.GetType(); if (typeof(RiotGamesObject).IsAssignableFrom(c)) { item = (obj4 as RiotGamesObject).GetBaseTypedObject(); } else { item = obj4; } list2.Add(item); } item = TypedObject.MakeArrayCollection(list2.ToArray()); } } else if (typeof(RiotGamesObject).IsAssignableFrom(propertyType)) { RiotGamesObject obj5 = info.GetValue(this) as RiotGamesObject; if (obj5 != null) { item = obj5.GetBaseTypedObject(); } } else { item = info.GetValue(this); } obj2.Add(attribute.Name, item); } } Type baseType = type.BaseType; if (baseType != null) { foreach (PropertyInfo info2 in baseType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { InternalNameAttribute attribute2 = info2.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute; if ((attribute2 != null) && !obj2.ContainsKey(attribute2.Name)) { obj2.Add(attribute2.Name, info2.GetValue(this)); } } } return(obj2); }
public TypedObject GetBaseTypedObject() { TypedObject typedObject = new TypedObject(TypeName); Type objectType = this.GetType(); foreach (var prop in objectType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var intern = prop.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault() as InternalNameAttribute; if (intern == null) { continue; } object value = null; var type = prop.PropertyType; string typeName = type.Name; if (type == typeof(int[])) { var test = prop.GetValue(this) as int[]; if (test != null) { value = test.Cast <object>().ToArray(); } } else if (type == typeof(double[])) { var test = prop.GetValue(this) as double[]; if (test != null) { value = test.Cast <object>().ToArray(); } } else if (type == typeof(string[])) { var test = prop.GetValue(this) as string[]; if (test != null) { value = test.Cast <object>().ToArray(); } } //List = Array Collection. Object array = object array else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { IList listValues = prop.GetValue(this) as IList; if (listValues != null) { object[] finalArray = new object[listValues.Count]; listValues.CopyTo(finalArray, 0); List <object> finalObjList = new List <object>(); foreach (object ob in finalArray) { Type obType = ob.GetType(); if (typeof(RiotGamesObject).IsAssignableFrom(obType)) { RiotGamesObject rgo = ob as RiotGamesObject; value = rgo.GetBaseTypedObject(); } else { value = ob; } finalObjList.Add(value); } value = TypedObject.MakeArrayCollection(finalObjList.ToArray()); } } else if (typeof(RiotGamesObject).IsAssignableFrom(type)) { RiotGamesObject rgo = prop.GetValue(this) as RiotGamesObject; if (rgo != null) { value = rgo.GetBaseTypedObject(); } } else { value = prop.GetValue(this); } typedObject.Add(intern.Name, value); } Type objectBaseType = objectType.BaseType; if (objectBaseType != null) { foreach (var prop in objectBaseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var intern = prop.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault() as InternalNameAttribute; if (intern == null || typedObject.ContainsKey(intern.Name)) { continue; } typedObject.Add(intern.Name, prop.GetValue(this)); } } return(typedObject); }
public TypedObject GetBaseTypedObject() { TypedObject typedObject = new TypedObject(this.TypeName); Type type = base.GetType(); PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int i = 0; i < properties.Length; i++) { PropertyInfo propertyInfo = properties[i]; InternalNameAttribute internalNameAttribute = propertyInfo.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute; if (internalNameAttribute != null) { object obj = null; Type propertyType = propertyInfo.PropertyType; string arg_5F_0 = propertyType.Name; if (propertyType == typeof(int[])) { int[] array = propertyInfo.GetValue(this) as int[]; if (array != null) { obj = array.Cast <object>().ToArray <object>(); } } else if (propertyType == typeof(double[])) { double[] array2 = propertyInfo.GetValue(this) as double[]; if (array2 != null) { obj = array2.Cast <object>().ToArray <object>(); } } else if (propertyType == typeof(string[])) { string[] array3 = propertyInfo.GetValue(this) as string[]; if (array3 != null) { obj = array3.Cast <object>().ToArray <object>(); } } else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>)) { IList list = propertyInfo.GetValue(this) as IList; if (list != null) { object[] array4 = new object[list.Count]; list.CopyTo(array4, 0); List <object> list2 = new List <object>(); object[] array5 = array4; for (int j = 0; j < array5.Length; j++) { object obj2 = array5[j]; Type type2 = obj2.GetType(); if (typeof(RiotGamesObject).IsAssignableFrom(type2)) { RiotGamesObject riotGamesObject = obj2 as RiotGamesObject; obj = riotGamesObject.GetBaseTypedObject(); } else { obj = obj2; } list2.Add(obj); } obj = TypedObject.MakeArrayCollection(list2.ToArray()); } } else if (typeof(RiotGamesObject).IsAssignableFrom(propertyType)) { RiotGamesObject riotGamesObject2 = propertyInfo.GetValue(this) as RiotGamesObject; if (riotGamesObject2 != null) { obj = riotGamesObject2.GetBaseTypedObject(); } } else { obj = propertyInfo.GetValue(this); } typedObject.Add(internalNameAttribute.Name, obj); } } Type baseType = type.BaseType; if (baseType != null) { PropertyInfo[] properties2 = baseType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int k = 0; k < properties2.Length; k++) { PropertyInfo propertyInfo2 = properties2[k]; InternalNameAttribute internalNameAttribute2 = propertyInfo2.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute; if (internalNameAttribute2 != null && !typedObject.ContainsKey(internalNameAttribute2.Name)) { typedObject.Add(internalNameAttribute2.Name, propertyInfo2.GetValue(this)); } } } return(typedObject); }