// Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // GameDataEditor.DictionaryExtensions using System; using System.Collections.Generic; using System.Reflection; using GameDataEditor; using UnityEngine; namespace GameDataEditor { public static class DictionaryExtensions { public static MethodInfo DeepCopyMethodInfo = typeof(DictionaryExtensions).GetMethod("DeepCopy"); public static bool TryAddOrUpdateValue(this Dictionary variable, TKey key, TValue value) { try { if (variable.ContainsKey(key)) { variable[key] = value; return true; } return variable.TryAddValue(key, value); } catch { return false; } } public static bool TryAddValue(this Dictionary variable, TKey key, TValue value) { try { variable.Add(key, value); return true; } catch { return false; } } public static bool TryGetList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { variable.TryGetValue(key, out var value2); value = value2 as List; } catch { result = false; } return result; } public static bool TryGetTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { value = new List>(); if (variable.TryGetList(key, out var value2)) { value = value2.ConvertAll((object obj) => obj as List); } } catch { result = false; } return result; } public static bool TryGetBool(this Dictionary variable, TKey key, out bool value) { bool result = true; value = false; try { variable.TryGetValue(key, out var value2); value = Convert.ToBoolean(value2); } catch { result = false; } return result; } public static bool TryGetBoolList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = value2.ConvertAll(Convert.ToBoolean); } } catch { result = false; } return result; } public static bool TryGetBoolTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List>(); foreach (object item2 in value2) { List list = item2 as List; List item = list.ConvertAll(Convert.ToBoolean); value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetString(this Dictionary variable, TKey key, out string value) { bool result = true; value = string.Empty; try { variable.TryGetValue(key, out var value2); value = value2.ToString(); } catch { result = false; } return result; } public static bool TryGetStringList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = value2.ConvertAll((object obj) => obj.ToString()); } } catch { result = false; } return result; } public static bool TryGetStringTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List>(); foreach (object item2 in value2) { List list = item2 as List; List item = list.ConvertAll((object obj) => obj.ToString()); value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetFloat(this Dictionary variable, TKey key, out float value) { bool result = true; value = 0f; try { variable.TryGetValue(key, out var value2); value = Convert.ToSingle(value2); } catch { result = false; } return result; } public static bool TryGetFloatList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = value2.ConvertAll(Convert.ToSingle); } } catch { result = false; } return result; } public static bool TryGetFloatTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List>(); foreach (object item2 in value2) { List list = item2 as List; List item = list.ConvertAll(Convert.ToSingle); value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetInt(this Dictionary variable, TKey key, out int value) { bool result = true; value = 0; try { variable.TryGetValue(key, out var value2); value = Convert.ToInt32(value2); } catch { result = false; } return result; } public static bool TryGetIntList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = value2.ConvertAll(Convert.ToInt32); } } catch { result = false; } return result; } public static bool TryGetIntTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List>(); foreach (object item2 in value2) { List list = item2 as List; List item = list.ConvertAll(Convert.ToInt32); value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetVector2(this Dictionary variable, TKey key, out Vector2 value) { bool result = true; value = Vector2.zero; try { variable.TryGetValue(key, out var value2); if ((object)value2 is Dictionary dictionary) { value.x = Convert.ToSingle(dictionary["x"]); value.y = Convert.ToSingle(dictionary["y"]); } } catch { result = false; } return result; } public static bool TryGetVector2List(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List(); foreach (object item2 in value2) { Dictionary dictionary = item2 as Dictionary; Vector2 item = default(Vector2); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); } value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetVector2TwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetTwoDList(key, out var value2)) { value = new List>(); foreach (List item2 in value2) { List list = item2 as List; List list2 = new List(); foreach (object item3 in list) { Dictionary dictionary = item3 as Dictionary; Vector2 item = default(Vector2); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); } list2.Add(item); } value.Add(list2); } } } catch { result = false; } return result; } public static bool TryGetVector3(this Dictionary variable, TKey key, out Vector3 value) { bool result = true; value = Vector3.zero; try { variable.TryGetValue(key, out var value2); if ((object)value2 is Dictionary dictionary) { value.x = Convert.ToSingle(dictionary["x"]); value.y = Convert.ToSingle(dictionary["y"]); value.z = Convert.ToSingle(dictionary["z"]); } } catch { result = false; } return result; } public static bool TryGetVector3List(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List(); foreach (object item2 in value2) { Dictionary dictionary = item2 as Dictionary; Vector3 item = default(Vector3); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); dictionary.TryGetFloat("z", out item.z); } value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetVector3TwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetTwoDList(key, out var value2)) { value = new List>(); foreach (List item2 in value2) { List list = item2 as List; List list2 = new List(); foreach (object item3 in list) { Dictionary dictionary = item3 as Dictionary; Vector3 item = default(Vector3); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); dictionary.TryGetFloat("z", out item.z); } list2.Add(item); } value.Add(list2); } } } catch { result = false; } return result; } public static bool TryGetVector4(this Dictionary variable, TKey key, out Vector4 value) { bool result = true; value = Vector4.zero; try { variable.TryGetValue(key, out var value2); if ((object)value2 is Dictionary dictionary) { value.x = Convert.ToSingle(dictionary["x"]); value.y = Convert.ToSingle(dictionary["y"]); value.z = Convert.ToSingle(dictionary["z"]); value.w = Convert.ToSingle(dictionary["w"]); } } catch { result = false; } return result; } public static bool TryGetVector4List(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List(); foreach (object item2 in value2) { Dictionary dictionary = item2 as Dictionary; Vector4 item = default(Vector4); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); dictionary.TryGetFloat("z", out item.z); dictionary.TryGetFloat("w", out item.w); } value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetVector4TwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetTwoDList(key, out var value2)) { value = new List>(); foreach (List item2 in value2) { List list = item2 as List; List list2 = new List(); foreach (object item3 in list) { Dictionary dictionary = item3 as Dictionary; Vector4 item = default(Vector4); if (dictionary != null) { dictionary.TryGetFloat("x", out item.x); dictionary.TryGetFloat("y", out item.y); dictionary.TryGetFloat("z", out item.z); dictionary.TryGetFloat("w", out item.w); } list2.Add(item); } value.Add(list2); } } } catch { result = false; } return result; } public static bool TryGetColor(this Dictionary variable, TKey key, out Color value) { bool result = true; value = Color.black; try { variable.TryGetValue(key, out var value2); if ((object)value2 is Dictionary variable2) { variable2.TryGetFloat("r", out value.r); variable2.TryGetFloat("g", out value.g); variable2.TryGetFloat("b", out value.b); variable2.TryGetFloat("a", out value.a); } } catch { result = false; } return result; } public static bool TryGetColorList(this Dictionary variable, TKey key, out List value) { bool result = true; value = null; try { if (variable.TryGetList(key, out var value2)) { value = new List(); foreach (object item2 in value2) { Dictionary dictionary = item2 as Dictionary; Color item = default(Color); if (dictionary != null) { dictionary.TryGetFloat("r", out item.r); dictionary.TryGetFloat("g", out item.g); dictionary.TryGetFloat("b", out item.b); dictionary.TryGetFloat("a", out item.a); } value.Add(item); } } } catch { result = false; } return result; } public static bool TryGetColorTwoDList(this Dictionary variable, TKey key, out List> value) { bool result = true; value = null; try { if (variable.TryGetTwoDList(key, out var value2)) { value = new List>(); foreach (List item2 in value2) { List list = item2 as List; List list2 = new List(); foreach (object item3 in list) { Dictionary dictionary = item3 as Dictionary; Color item = default(Vector4); if (dictionary != null) { dictionary.TryGetFloat("r", out item.r); dictionary.TryGetFloat("g", out item.g); dictionary.TryGetFloat("b", out item.b); dictionary.TryGetFloat("a", out item.a); } list2.Add(item); } value.Add(list2); } } } catch { result = false; } return result; } public static bool TryGetUnityType(this Dictionary variable, TKey key, out T value) where T : UnityEngine.Object { bool result = true; value = (T)null; try { if (variable.TryGetString(key, out var value2)) { value = Resources.Load(value2); } } catch { result = false; } return result; } public static bool TryGetUnityTypeList(this Dictionary variable, TKey key, out List value) where T : UnityEngine.Object { bool result = true; value = null; try { if (variable.TryGetStringList(key, out var value2)) { value = new List(); foreach (string item in value2) { value.Add(Resources.Load(item)); } } } catch { result = false; } return result; } public static bool TryGetUnityTypeTwoDList(this Dictionary variable, TKey key, out List> value) where T : UnityEngine.Object { bool result = true; value = null; try { if (variable.TryGetStringTwoDList(key, out var value2)) { value = new List>(); foreach (List item in value2) { List list = new List(); foreach (string item2 in item) { list.Add(Resources.Load(item2)); } value.Add(list); } } } catch { result = false; } return result; } public static bool TryGetGameObject(this Dictionary variable, TKey key, out GameObject value) { return variable.TryGetUnityType(key, out value); } public static bool TryGetGameObjectList(this Dictionary variable, TKey key, out List value) { return variable.TryGetUnityTypeList(key, out value); } public static bool TryGetGameObjectTwoDList(this Dictionary variable, TKey key, out List> value) { return variable.TryGetUnityTypeTwoDList(key, out value); } public static bool TryGetTexture2D(this Dictionary variable, TKey key, out Texture2D value) { return variable.TryGetUnityType(key, out value); } public static bool TryGetTexture2DList(this Dictionary variable, TKey key, out List value) { return variable.TryGetUnityTypeList(key, out value); } public static bool TryGetTexture2DTwoDList(this Dictionary variable, TKey key, out List> value) { return variable.TryGetUnityTypeTwoDList(key, out value); } public static bool TryGetMaterial(this Dictionary variable, TKey key, out Material value) { return variable.TryGetUnityType(key, out value); } public static bool TryGetMaterialList(this Dictionary variable, TKey key, out List value) { return variable.TryGetUnityTypeList(key, out value); } public static bool TryGetMaterialTwoDList(this Dictionary variable, TKey key, out List> value) { return variable.TryGetUnityTypeTwoDList(key, out value); } public static bool TryGetAudioClip(this Dictionary variable, TKey key, out AudioClip value) { return variable.TryGetUnityType(key, out value); } public static bool TryGetAudioClipList(this Dictionary variable, TKey key, out List value) { return variable.TryGetUnityTypeList(key, out value); } public static bool TryGetAudioClipTwoDList(this Dictionary variable, TKey key, out List> value) { return variable.TryGetUnityTypeTwoDList(key, out value); } public static bool TryGetCustom(this Dictionary variable, TKey key, out T value) where T : IGDEData, new() { bool result = true; value = new T(); try { if (variable.TryGetValue(key, out var value2)) { value.LoadFromDict(key.ToString(), value2 as Dictionary); } else { value.LoadFromSavedData(key.ToString()); } } catch { result = false; } return result; } public static bool TryGetCustomList(this Dictionary variable, TKey key, out List value) where T : IGDEData, new() { bool result = true; value = new List(); try { variable.TryGetStringList(key, out var value2); foreach (string item in value2) { GDEDataManager.DataDictionary.TryGetCustom(item, out var value3); value.Add(value3); } } catch { result = false; } return result; } public static bool TryGetCustomTwoDList(this Dictionary variable, TKey key, out List> value) where T : IGDEData, new() { bool result = true; value = new List>(); try { variable.TryGetStringTwoDList(key, out var value2); foreach (List item in value2) { List list = new List(); foreach (string item2 in item) { GDEDataManager.DataDictionary.TryGetCustom(item2, out var value3); list.Add(value3); } value.Add(list); } } catch { result = false; } return result; } public static Dictionary DeepCopy(this Dictionary variable) { Dictionary dictionary = new Dictionary(); TKey val = default(TKey); TValue val2 = default(TValue); foreach (KeyValuePair item in variable) { if (item.Key == null) { val = item.Key; } else if (item.Key.IsCloneableType()) { val = (TKey)((ICloneable)(object)item.Key).Clone(); } else if (item.Key.IsGenericList()) { Type type = item.Key.GetType().GetGenericArguments()[0]; MethodInfo methodInfo = ListExtensions.DeepCopyMethodInfo.MakeGenericMethod(type); val = (TKey)methodInfo.Invoke(item.Key, new object[1] { item.Key }); } else if (item.Key.IsGenericDictionary()) { Type[] genericArguments = item.Key.GetType().GetGenericArguments(); Type type2 = genericArguments[0]; Type type3 = genericArguments[1]; MethodInfo methodInfo2 = DeepCopyMethodInfo.MakeGenericMethod(type2, type3); val = (TKey)methodInfo2.Invoke(item.Key, new object[1] { item.Key }); } else { val = item.Key; } if (item.Value == null) { val2 = item.Value; } else if (item.Value.IsCloneableType()) { val2 = (TValue)((ICloneable)(object)item.Value).Clone(); } else if (item.Value.IsGenericList()) { Type type4 = item.Value.GetType().GetGenericArguments()[0]; MethodInfo methodInfo3 = ListExtensions.DeepCopyMethodInfo.MakeGenericMethod(type4); val2 = (TValue)methodInfo3.Invoke(item.Value, new object[1] { item.Value }); } else if (item.Value.IsGenericDictionary()) { Type[] genericArguments2 = item.Value.GetType().GetGenericArguments(); Type type5 = genericArguments2[0]; Type type6 = genericArguments2[1]; MethodInfo methodInfo4 = DeepCopyMethodInfo.MakeGenericMethod(type5, type6); val2 = (TValue)methodInfo4.Invoke(item.Value, new object[1] { item.Value }); } else { val2 = item.Value; } dictionary.Add(val, val2); } return dictionary; } } }