// Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // GameDataEditor.GDEDataManager using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using GameDataEditor; using UnityEngine; namespace GameDataEditor { public class GDEDataManager { private static bool isInitialized; private static Dictionary dataDictionary; private static Dictionary> dataKeysBySchema; private static string _dataFilePath; public static Dictionary DataDictionary => dataDictionary; public static string DataFilePath { get { return _dataFilePath; } private set { _dataFilePath = value; } } public static bool Init(string filePath, bool encrypted = false) { bool result = true; if (isInitialized) { return result; } try { DataFilePath = filePath; TextAsset dataAsset = Resources.Load(DataFilePath) as TextAsset; Init(dataAsset, encrypted); isInitialized = true; } catch (Exception message) { Debug.LogError(message); result = false; } return result; } public static bool Init(TextAsset dataAsset, bool encrypted = false) { bool result = true; if (isInitialized) { return result; } if (dataAsset == null) { Debug.LogError("GDEInit: TextAsset is null!"); return false; } try { string empty = string.Empty; empty = ((!encrypted) ? dataAsset.text : DecryptGDEData(dataAsset.bytes)); InitFromText(empty); isInitialized = true; } catch (Exception message) { Debug.LogError(message); result = false; } return result; } public static bool InitFromText(string dataString) { bool result = true; if (isInitialized) { return result; } try { dataDictionary = Json.Deserialize(dataString) as Dictionary; BuildDataKeysBySchemaList(); isInitialized = true; } catch (Exception message) { Debug.LogError(message); result = false; } return result; } public static string DecryptGDEData(byte[] encryptedContent) { GDECrypto gDECrypto = null; TextAsset textAsset = (TextAsset)Resources.Load("gde_meta_data", typeof(TextAsset)); byte[] buffer = Convert.FromBase64String(textAsset.text); Resources.UnloadAsset(textAsset); using (MemoryStream serializationStream = new MemoryStream(buffer)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); gDECrypto = (GDECrypto)binaryFormatter.Deserialize(serializationStream); } string result = string.Empty; if (gDECrypto != null) { result = gDECrypto.Decrypt(encryptedContent); } return result; } private static void BuildDataKeysBySchemaList() { dataKeysBySchema = new Dictionary>(); foreach (KeyValuePair item in dataDictionary) { if (!item.Key.StartsWith("_gdeSchema_")) { Dictionary variable = item.Value as Dictionary; variable.TryGetString("_gdeSchema", out var value); if (dataKeysBySchema.TryGetValue(value, out var value2)) { value2.Add(item.Key); continue; } value2 = new List(); value2.Add(item.Key); dataKeysBySchema.Add(value, value2); } } } public static bool Get(string key, out Dictionary data) { if (dataDictionary == null) { data = null; return false; } bool flag = true; flag = dataDictionary.TryGetValue(key, out var value); data = value as Dictionary; return flag; } public static bool GetAllDataBySchema(string schema, out Dictionary data) { if (dataDictionary == null) { data = null; return false; } bool result = true; data = new Dictionary(); if (dataKeysBySchema.TryGetValue(schema, out var value)) { foreach (string item in value) { if (Get(item, out var data2)) { data.Add(item.Clone().ToString(), data2.DeepCopy()); } } } else { result = false; } return result; } public static bool GetAllDataKeysBySchema(string schema, out List dataKeys) { if (dataDictionary == null) { dataKeys = null; return false; } return dataKeysBySchema.TryGetValue(schema, out dataKeys); } public static void ResetToDefault(string itemName, string fieldName) { PlayerPrefs.DeleteKey(itemName + "_" + fieldName); } public static string GetString(string key, string defaultVal) { string text = defaultVal; try { text = PlayerPrefs.GetString(key, text); } catch (Exception exception) { Debug.LogException(exception); } return text; } public static List GetStringList(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetStringList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetStringTwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DStringList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static int GetInt(string key, int defaultVal) { int num = defaultVal; try { num = PlayerPrefs.GetInt(key, num); } catch (Exception exception) { Debug.LogException(exception); } return num; } public static List GetIntList(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetIntList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetIntTwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DIntList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static float GetFloat(string key, float defaultVal) { float num = defaultVal; try { num = PlayerPrefs.GetFloat(key, num); } catch (Exception exception) { Debug.LogException(exception); } return num; } public static List GetFloatList(string key, List defaultVal) { List list = defaultVal; try { list = GDEPPX.GetFloatList(key, list); } catch (Exception exception) { Debug.LogException(exception); } return list; } public static List> GetFloatTwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DFloatList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static bool GetBool(string key, bool defaultVal) { bool result = defaultVal; try { result = GDEPPX.GetBool(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List GetBoolList(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetBoolList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetBoolTwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DBoolList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static Color32 GetColor(string key, Color32 defaultVal) { Color32 result = defaultVal; try { result = GDEPPX.GetColor(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List GetColorList(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetColorList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetColorTwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DColorList(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static Vector2 GetVector2(string key, Vector2 defaultVal) { Vector2 result = defaultVal; try { result = GDEPPX.GetVector2(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List GetVector2List(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetVector2List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetVector2TwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DVector2List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static Vector3 GetVector3(string key, Vector3 defaultVal) { Vector3 result = defaultVal; try { result = GDEPPX.GetVector3(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List GetVector3List(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetVector3List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetVector3TwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DVector3List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static Vector4 GetVector4(string key, Vector4 defaultVal) { Vector4 result = defaultVal; try { result = GDEPPX.GetVector4(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List GetVector4List(string key, List defaultVal) { List result = defaultVal; try { result = GDEPPX.GetVector4List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static List> GetVector4TwoDList(string key, List> defaultVal) { List> result = defaultVal; try { result = GDEPPX.Get2DVector4List(key, defaultVal); } catch (Exception exception) { Debug.LogException(exception); } return result; } public static GameObject GetGameObject(string key, GameObject defaultVal) { return defaultVal; } public static List GetGameObjectList(string key, List defaultVal) { return defaultVal; } public static List> GetGameObjectTwoDList(string key, List> defaultVal) { return defaultVal; } public static Texture2D GetTexture2D(string key, Texture2D defaultVal) { return defaultVal; } public static List GetTexture2DList(string key, List defaultVal) { return defaultVal; } public static List> GetTexture2DTwoDList(string key, List> defaultVal) { return defaultVal; } public static Material GetMaterial(string key, Material defaultVal) { return defaultVal; } public static List GetMaterialList(string key, List defaultVal) { return defaultVal; } public static List> GetMaterialTwoDList(string key, List> defaultVal) { return defaultVal; } public static AudioClip GetAudioClip(string key, AudioClip defaultVal) { return defaultVal; } public static List GetAudioClipList(string key, List defaultVal) { return defaultVal; } public static List> GetAudioClipTwoDList(string key, List> defaultVal) { return defaultVal; } public static T GetCustom(string key, T defaultVal) where T : IGDEData, new() { T value = defaultVal; try { string text = ((defaultVal == null) ? string.Empty : defaultVal.Key); string @string = GetString(key, text); if (@string != text) { DataDictionary.TryGetCustom(@string, out value); value.LoadFromSavedData(@string); } } catch (Exception exception) { Debug.LogException(exception); } return value; } public static List GetCustomList(string key, List defaultVal) where T : IGDEData, new() { List list = defaultVal; try { if (PlayerPrefs.HasKey(key)) { list = new List(); List stringList = GetStringList(key, null); if (stringList != null) { foreach (string item in stringList) { if (DataDictionary.TryGetCustom(item, out var value)) { list.Add(value); } } } } } catch (Exception exception) { Debug.LogException(exception); } return list; } public static List> GetCustomTwoDList(string key, List> defaultVal) where T : IGDEData, new() { List> list = defaultVal; try { if (PlayerPrefs.HasKey(key)) { list = new List>(); List> stringTwoDList = GetStringTwoDList(key, null); if (stringTwoDList != null) { foreach (List item in stringTwoDList) { List list2 = new List(); foreach (string item2 in item) { if (DataDictionary.TryGetCustom(item2, out var value)) { list2.Add(value); } } list.Add(list2); } } } } catch (Exception exception) { Debug.LogException(exception); } return list; } public static void SetString(string key, string val) { try { PlayerPrefs.SetString(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetStringList(string key, List val) { try { GDEPPX.SetStringList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetStringTwoDList(string key, List> val) { try { GDEPPX.Set2DStringList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetInt(string key, int val) { try { PlayerPrefs.SetInt(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetIntList(string key, List val) { try { GDEPPX.SetIntList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetIntTwoDList(string key, List> val) { try { GDEPPX.Set2DIntList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetFloat(string key, float val) { try { PlayerPrefs.SetFloat(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetFloatList(string key, List val) { try { GDEPPX.SetFloatList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetFloatTwoDList(string key, List> val) { try { GDEPPX.Set2DFloatList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetBool(string key, bool val) { try { GDEPPX.SetBool(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetBoolList(string key, List val) { try { GDEPPX.SetBoolList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetBoolTwoDList(string key, List> val) { try { GDEPPX.Set2DBoolList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetColor(string key, Color32 val) { try { GDEPPX.SetColor(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetColorList(string key, List val) { try { GDEPPX.SetColorList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetColorTwoDList(string key, List> val) { try { GDEPPX.Set2DColorList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector2(string key, Vector2 val) { try { GDEPPX.SetVector2(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector2List(string key, List val) { try { GDEPPX.SetVector2List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector2TwoDList(string key, List> val) { try { GDEPPX.Set2DVector2List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector3(string key, Vector3 val) { try { GDEPPX.SetVector3(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector3List(string key, List val) { try { GDEPPX.SetVector3List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector3TwoDList(string key, List> val) { try { GDEPPX.Set2DVector3List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector4(string key, Vector4 val) { try { GDEPPX.SetVector4(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector4List(string key, List val) { try { GDEPPX.SetVector4List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetVector4TwoDList(string key, List> val) { try { GDEPPX.Set2DVector4List(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetGameObject(string key, GameObject val) { try { GDEPPX.SetGameObject(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetGameObjectList(string key, List val) { try { GDEPPX.SetGameObjectList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetGameObjectTwoDList(string key, List> val) { try { GDEPPX.Set2DGameObjectList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetTexture2D(string key, Texture2D val) { try { GDEPPX.SetTexture2D(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetTexture2DList(string key, List val) { try { GDEPPX.SetTexture2DList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetTexture2DTwoDList(string key, List> val) { try { GDEPPX.Set2DTexture2DList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetMaterial(string key, Material val) { try { GDEPPX.SetMaterial(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetMaterialList(string key, List val) { try { GDEPPX.SetMaterialList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetMaterialTwoDList(string key, List> val) { try { GDEPPX.Set2DMaterialList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetAudioClip(string key, AudioClip val) { try { GDEPPX.SetAudioClip(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetAudioClipList(string key, List val) { try { GDEPPX.SetAudioClipList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetAudioClipTwoDList(string key, List> val) { try { GDEPPX.Set2DAudioClipList(key, val); } catch (Exception exception) { Debug.LogException(exception); } } public static void SetCustom(string key, T val) where T : IGDEData { SetString(key, val.Key); } public static void SetCustomList(string key, List val) where T : IGDEData { List customKeys = new List(); val.ForEach(delegate(T x) { customKeys.Add(x.Key); }); SetStringList(key, customKeys); } public static void SetCustomTwoDList(string key, List> val) where T : IGDEData { List> list = new List>(); foreach (List item in val) { List subListKeys = new List(); item.ForEach(delegate(T x) { subListKeys.Add(x.Key); }); list.Add(subListKeys); } SetStringTwoDList(key, list); } } }