コード例 #1
0
        public static Dictionary <string, object> DecryptDecodeDeserialize(byte[] key, byte[] iv, byte[] data, Encoding encoding)
        {
            try
            {
                using (RijndaelManaged crypto = new RijndaelManaged())
                {
                    crypto.BlockSize = KeySize;
                    crypto.Padding   = PaddingMode.PKCS7;
                    crypto.Key       = key;
                    crypto.IV        = iv;
                    crypto.Mode      = CipherMode.CBC;

                    // Create a decrytor to perform the stream transform.
                    ICryptoTransform decryptor = crypto.CreateDecryptor(crypto.Key, crypto.IV);

                    using (MemoryStream memStream = new MemoryStream(data))
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(memStream, decryptor, CryptoStreamMode.Read))
                        {
                            using (StreamReader streamReader = new StreamReader(cryptoStream, encoding))
                            {
                                return(MiniJSON.Deserialize(streamReader) as Dictionary <string, object>);
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError("AESEncryptor :: Decryption failed with exception: " + e.Message);
                Debug.LogError(e);
            }

            return(null);
        }
コード例 #2
0
        public static JsonData ToObject(string json)
        {
            object   obj      = MiniJSON.Deserialize(json);
            JsonData jsonData = obj == null ? null : new JsonData(obj);

            return(jsonData);
        }
コード例 #3
0
    public static void LoadStringTable(bool useJapanese = false)
    {
        if (StringTable == null)
        {
            StringTable = new Dictionary <string, string>();

            string fileName = "string_cn";
            if (useJapanese)
            {
                fileName = "string_jp";
            }

            TextAsset ta = Resources.Load <TextAsset>("Table/" + fileName);

            List <string> valueList = new List <string>();

            List <object> stringList = (List <object>)MiniJSON.Deserialize(ta.text);
            for (int i = 0; i < stringList.Count; i++)
            {
                Dictionary <string, object> kv = (Dictionary <string, object>)stringList[i];

                foreach (var kvs in kv)
                {
                    valueList.Add(kvs.Value.ToString());
                }
            }

            for (int i = 0; i < valueList.Count - 1; i += 2)
            {
                StringTable.Add(valueList[i], valueList[i + 1]);
            }

            //PrintStringTable();
        }
    }
コード例 #4
0
        public static void Load()
        {
            string key  = PlayerPrefs.GetString(StatsManager.SavingLoading.savingKey) + ".StatSystem";
            string data = PlayerPrefs.GetString(key);

            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            List <StatsHandler> results = Object.FindObjectsOfType <StatsHandler>().Where(x => x.saveable).ToList();
            List <object>       list    = MiniJSON.Deserialize(data) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> handlerData = list[i] as Dictionary <string, object>;
                string       handlerName = (string)handlerData["Name"];
                StatsHandler handler     = results.Find(x => x.HandlerName == handlerName);
                if (handler != null)
                {
                    handler.SetObjectData(handlerData);
                    handler.UpdateStats();
                }
            }

            if (StatsManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Stat System] Stats loaded " + StatsManager.SavingLoading.savingKey + ".StatSystem" + data);
            }
        }
コード例 #5
0
        public static void Load(Graph graph)
        {
            if (string.IsNullOrEmpty(graph.serializationData))
            {
                return;
            }
            Dictionary <string, object> data = MiniJSON.Deserialize(graph.serializationData) as Dictionary <string, object>;

            graph.nodes.Clear();
            object obj;

            if (data.TryGetValue("Nodes", out obj))
            {
                List <object> list = obj as List <object>;
                for (int i = 0; i < list.Count; i++)
                {
                    Node node = DeserializeNode(list[i] as Dictionary <string, object>, graph.serializedObjects);
                    node.graph = graph;
                    graph.nodes.Add(node);
                }

                for (int i = 0; i < graph.nodes.Count; i++)
                {
                    graph.nodes[i].OnAfterDeserialize();
                }
            }
        }
コード例 #6
0
        // Token: 0x0600025A RID: 602 RVA: 0x0001652C File Offset: 0x0001472C
        public static Task PasteTask(BehaviorSource behaviorSource, TaskSerializer serializer)
        {
            Dictionary <int, Task> dictionary = new Dictionary <int, Task>();
            Task task = JSONDeserialization.DeserializeTask(behaviorSource, MiniJSON.Deserialize(serializer.serialization) as Dictionary <string, object>, ref dictionary, serializer.unityObjects);

            TaskCopier.CheckSharedVariables(behaviorSource, task);
            return(task);
        }
コード例 #7
0
        public static JsonData ToObject(string json)
        {
            object obj = MiniJSON.Deserialize(json);

            if (obj == null)
            {
                return(null);
            }
            JsonData jsonData = new JsonData(obj);

            return(jsonData);
        }
コード例 #8
0
    public static Dictionary <string, object> GetMergedData(Dictionary <string, object> baseData, string overrideJson)
    {
        Dictionary <string, object> mergedData = null;

        Dictionary <string, object> overrideData = MiniJSON.Deserialize(overrideJson) as Dictionary <string, object>;

        if (overrideData != null)
        {
            mergedData = MergeGameDictionaries(baseData, overrideData);
        }
        else
        {
            Debug.LogError("GameDataUtils :: Failed to deserialize cached gameDB json!");
        }

        return(mergedData);
    }
コード例 #9
0
ファイル: QuestManager.cs プロジェクト: bp-tags/quest-system
        private static void LoadQuests(string json, ref List <Quest> quests, bool registerCallbacks = false)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            List <object> list = MiniJSON.Deserialize(json) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> mData = list[i] as Dictionary <string, object>;
                string name  = (string)mData["Name"];
                Quest  quest = QuestManager.Database.items.FirstOrDefault(x => x.Name == name);
                if (quest != null)
                {
                    Quest instance = Instantiate(quest);
                    for (int j = 0; j < instance.tasks.Count; j++)
                    {
                        instance.tasks[j].owner = instance;
                    }
                    instance.SetObjectData(mData);
                    if (registerCallbacks)
                    {
                        instance.OnStatusChanged       += QuestManager.current.NotifyQuestStatusChanged;
                        instance.OnTaskStatusChanged   += QuestManager.current.NotifyTaskStatusChanged;
                        instance.OnTaskProgressChanged += QuestManager.current.NotifyTaskProgressChanged;
                        instance.OnTaskTimerTick       += QuestManager.current.NotifyTaskTimerTick;
                    }
                    quests.Add(instance);
                }
                else
                {
                    Debug.LogWarning("Failed to laod quest " + name + ". Quest is not present in Database.");
                }
            }

            if (QuestManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Quest System] Quests Loaded");
            }
        }
コード例 #10
0
    public bool Merge(string json)
    {
        bool success = false;

        try
        {
            Dictionary <string, object> newStore = MiniJSON.Deserialize(json) as Dictionary <string, object>;

            if (newStore != null)
            {
                Action <Dictionary <string, object>, Dictionary <string, object> > merge = null;
                merge = delegate(Dictionary <string, object> baseStore, Dictionary <string, object> overrideStore)
                {
                    foreach (KeyValuePair <string, object> pair in overrideStore)
                    {
                        object currentVal = baseStore.ContainsKey(pair.Key) ? baseStore[pair.Key] : null;

                        //If this is a dictionary and the base is a dictionary we need to merge on those dictionaries as well
                        if (pair.Value.GetType() == typeof(Dictionary <string, object>) && (currentVal != null && currentVal.GetType() == typeof(Dictionary <string, object>)))
                        {
                            merge(currentVal as Dictionary <string, object>, pair.Value as Dictionary <string, object>);
                        }
                        else
                        {
                            baseStore[pair.Key] = pair.Value;
                        }
                    }
                };

                merge(m_store, newStore);

                success = true;
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(string.Format("JSONNestedKeyValueStore :: Failed to parse JSON - {0}", e.Message));
        }

        return(success);
    }
コード例 #11
0
    public bool FromJSON(TextReader json)
    {
        bool success = false;

        try
        {
            Dictionary <string, object> newStore = MiniJSON.Deserialize(json) as Dictionary <string, object>;

            if (newStore != null)
            {
                m_store = newStore;
                success = true;
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("JSONNestedKeyValueStore :: Failed to parse JSON - " + e.Message);
        }

        return(success);
    }
コード例 #12
0
    void SetupServer()
    {
        ws.Connect();
        ws.Send("{ \"Type\":\"ident\", \"Payload\":\"oculus\"}");
        ws.OnMessage += (sender, e) =>
        {
            var preDict = (Dictionary <string, object>)MiniJSON.Deserialize(e.Data);
            if (preDict["Type"].ToString() == "map")
            {
                Debug.Log("hey");
                var dict = (Dictionary <string, object>)MiniJSON.Deserialize(e.Data);

                var payload = (Dictionary <string, object>)dict["Payload"];
                var width   = MapMessage.CreateFromJSON(e.Data).Payload.Width;
                var height  = MapMessage.CreateFromJSON(e.Data).Payload.Height;
                Debug.Log(width);
                Debug.Log(height);
                var cells = (List <object>)payload["Cells"];
                int[,] map = new int[width, height];
                for (int row = 0; row < width; row++)
                {
                    var items = (List <object>)cells[row];
                    for (int col = 0; col < height; col++)
                    {
                        map[row, col] = Convert.ToInt32(items[col]);
                    }
                }
                UnityMainThreadDispatcher.Instance().Enqueue(CreateMaze(map));
            }
            if (preDict["Type"].ToString() == "registered")
            {
                JSONObject obj       = new JSONObject(e.Data);
                var        character = obj["Payload"]["Character"];
                var        x_spawn   = obj["Payload"]["Position"]["X"].n;
                var        z_spawn   = obj["Payload"]["Position"]["Z"].n;

                UnityMainThreadDispatcher.Instance().Enqueue(CreatePlayer(x_spawn, z_spawn));
            }
        };
    }
コード例 #13
0
        private static void LoadUI(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            List <object> list = MiniJSON.Deserialize(json) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> mData = list[i] as Dictionary <string, object>;
                string        prefab       = (string)mData["Prefab"];
                List <object> positionData = mData["Position"] as List <object>;
                List <object> rotationData = mData["Rotation"] as List <object>;
                string        type         = (string)mData["Type"];

                Vector3        position       = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2]));
                Quaternion     rotation       = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2])));
                ItemCollection itemCollection = null;
                if (type == "UI")
                {
                    UIWidget container = WidgetUtility.Find <UIWidget>(prefab);
                    if (container != null)
                    {
                        itemCollection = container.GetComponent <ItemCollection>();
                    }
                }
                if (itemCollection != null)
                {
                    itemCollection.SetObjectData(mData);
                }
            }
            if (InventoryManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Inventory System] UI Loaded: " + json);
            }
        }
コード例 #14
0
        private void ClearCloudSyncStatus(User user)
        {
            if (string.IsNullOrEmpty(user.ID))
            {
                return;
            }
            Dictionary <string, object> cloudSaveStatus = null;
            string cloudSaveStatusString = PlayerPrefs.GetString(CloudSaveStatusKey);

            if (!string.IsNullOrEmpty(cloudSaveStatusString))
            {
                try
                {
                    cloudSaveStatus = MiniJSON.Deserialize(cloudSaveStatusString) as Dictionary <string, object>;
                }
                catch (Exception) { }
            }
            if (cloudSaveStatus != null && user != null && !string.IsNullOrEmpty(user.ID) && cloudSaveStatus.ContainsKey(user.ID))
            {
                cloudSaveStatus.Remove(user.ID);
                PlayerPrefs.SetString(CloudSaveStatusKey, MiniJSON.Serialize(cloudSaveStatus));
                PlayerPrefs.Save();
            }
        }
コード例 #15
0
 public static Dictionary <string, object> DeserializeJson(string jsonText)
 {
     return(MiniJSON.Deserialize(jsonText) as Dictionary <string, object>);
 }
コード例 #16
0
        public static Task PasteTask(BehaviorSource behaviorSource, TaskSerializer serializer)
        {
            Dictionary <int, Task> dictionary = new Dictionary <int, Task>();

            return(DeserializeJSON.DeserializeTask(behaviorSource, MiniJSON.Deserialize(serializer.serialization) as Dictionary <string, object>, ref dictionary, serializer.unityObjects));
        }
コード例 #17
0
 public static bool IsJson(string json)
 {
     return(MiniJSON.Deserialize(json) != null);
 }
コード例 #18
0
        private static void LoadScene(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            ItemCollection[] itemCollections = FindObjectsOfType <ItemCollection>().Where(x => x.saveable).ToArray();
            for (int i = 0; i < itemCollections.Length; i++)
            {
                ItemCollection collection = itemCollections[i];

                //Dont destroy ui game objects
                if (collection.GetComponent <ItemContainer>() != null)
                {
                    continue;
                }

                GameObject prefabForCollection = InventoryManager.GetPrefab(collection.name);

                //Store real prefab to cache
                if (prefabForCollection == null)
                {
                    collection.transform.parent = InventoryManager.current.transform;
                    InventoryManager.m_PrefabCache.Add(collection.name, collection.gameObject);
                    collection.gameObject.SetActive(false);
                    continue;
                }

                Destroy(collection.gameObject);
            }

            List <object> list = MiniJSON.Deserialize(json) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> mData = list[i] as Dictionary <string, object>;
                string        prefab       = (string)mData["Prefab"];
                List <object> positionData = mData["Position"] as List <object>;
                List <object> rotationData = mData["Rotation"] as List <object>;

                Vector3    position = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2]));
                Quaternion rotation = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2])));

                GameObject collectionGameObject = CreateCollection(prefab, position, rotation);
                if (collectionGameObject != null)
                {
                    IGenerator[] generators = collectionGameObject.GetComponents <IGenerator>();
                    for (int j = 0; j < generators.Length; j++)
                    {
                        generators[j].enabled = false;
                    }
                    ItemCollection itemCollection = collectionGameObject.GetComponent <ItemCollection>();
                    itemCollection.SetObjectData(mData);
                }
            }

            if (InventoryManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Inventory System] Scene Loaded: " + json);
            }
        }
コード例 #19
0
 public static object Deserialize(string json)
 {
     return(MiniJSON.Deserialize(json));
 }
コード例 #20
0
    void SetupServer()
    {
        ws.Connect();
        ws.Send("{ \"Type\":\"ident\", \"Payload\":\"player\"}");
        ws.OnMessage += (sender, e) =>
        {
            var preDict = (Dictionary <string, object>)MiniJSON.Deserialize(e.Data);
            if (preDict["Type"].ToString() == "map")
            {
                Debug.Log("Map");

                var dict = (Dictionary <string, object>)MiniJSON.Deserialize(e.Data);

                var payload = (Dictionary <string, object>)dict["Payload"];
                var width   = MapMessage.CreateFromJSON(e.Data).Payload.Width;
                var height  = MapMessage.CreateFromJSON(e.Data).Payload.Height;
                Debug.Log(width);
                Debug.Log(height);
                mazeWidth  = width;
                mazeHeight = height;
                maze       = new Maze(width, height);
                var cells = (List <object>)payload["Cells"];
                int[,] map = new int[width, height];
                for (int row = 0; row < width; row++)
                {
                    var items = (List <object>)cells[row];
                    for (int col = 0; col < height; col++)
                    {
                        map[row, col] = Convert.ToInt32(items[col]);
                    }
                }
                UnityMainThreadDispatcher.Instance().Enqueue(CreateMaze(map));
            }
            if (preDict["Type"].ToString() == "registered")
            {
                JSONObject obj = new JSONObject(e.Data);
                Debug.Log(e.Data);
                var character = obj["Payload"]["You"]["Character"].n;
                myID = obj["Payload"]["You"]["ID"].str;
                Debug.Log("JOINING ID + " + obj["Payload"]["You"]["ID"].str);
                Debug.Log("Char " + character.ToString());
                var x_spawn = obj["Payload"]["You"]["Position"]["X"].n;
                var z_spawn = obj["Payload"]["You"]["Position"]["Z"].n;
                Debug.Log("registered on the server");
                Debug.Log(x_spawn);
                Debug.Log(z_spawn);
                UnityMainThreadDispatcher.Instance().Enqueue(CreatePlayer(x_spawn, z_spawn, character == 2));
                for (int m = 0; m < 10; m++)
                {
                    if (!obj["Payload"]["Players"][m].IsNull && obj["Payload"]["Players"][m]["ID"].str != myID)
                    {
                        string id = obj["Payload"]["Players"][m]["ID"].str;
                        x_spawn = obj["Payload"]["Players"][m]["Position"]["X"].n;
                        z_spawn = obj["Payload"]["Players"][m]["Position"]["Z"].n;
                        UnityMainThreadDispatcher.Instance().Enqueue(CreateOtherPlayer(id, x_spawn, z_spawn, obj["Payload"]["Players"][m]["Character"].n == 2, obj["Payload"]["Players"][m]["Character"].n == 1));
                    }
                }
            }
            if (preDict["Type"].ToString() == "joined")
            {
                JSONObject obj       = new JSONObject(e.Data);
                var        character = obj["Payload"]["Character"].n;
                Debug.Log("NEW USER DETECTED " + character.ToString());
                var    x_spawn = obj["Payload"]["Position"]["X"].n;
                var    z_spawn = obj["Payload"]["Position"]["Z"].n;
                string id      = obj["Payload"]["ID"].str;
                Debug.Log("joined on the server");
                Debug.Log(x_spawn);
                Debug.Log(z_spawn);
                UnityMainThreadDispatcher.Instance().Enqueue(CreateOtherPlayer(id, x_spawn, z_spawn, character == 2, character == 1));
            }
            if (preDict["Type"].ToString() == "player")
            {
                JSONObject obj = new JSONObject(e.Data);

                Debug.Log("Position of " + obj["Payload"]["ID"].str + " updated");
                string id       = obj["Payload"]["ID"].str;
                float  x_update = obj["Payload"]["Position"]["X"].n;
                float  z_update = obj["Payload"]["Position"]["Z"].n;
                UnityMainThreadDispatcher.Instance().Enqueue(UpdatePosition(id, x_update, z_update));
            }
            if (preDict["Type"].ToString() == "dead")
            {
                JSONObject obj = new JSONObject(e.Data);

                Debug.Log("PLayer " + obj["Payload"]["ID"].str + " is dead");
                string id = obj["Payload"]["ID"].str;
                UnityMainThreadDispatcher.Instance().Enqueue(KillPlayer(id));
                if (id == myID)
                {
                    Debug.Log("Its me "); UnityMainThreadDispatcher.Instance().Enqueue(KillMe());
                }
            }


            //Write join
        };
    }
コード例 #21
0
        public static void Load(string key, bool includePersistent = true)
        {
            key += "InventorySystem";
            key += " [" + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + "]";
            string data = PlayerPrefs.GetString(key);

            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            ItemCollection[] itemCollections = FindObjectsOfType <ItemCollection>();
            for (int i = 0; i < itemCollections.Length; i++)
            {
                if (InventoryManager.GetPrefab(itemCollections[i].name.Replace("(Clone)", "")) == null)
                {
                    continue;
                }
                Destroy(itemCollections[i].gameObject);
            }

            List <object> list = MiniJSON.Deserialize(data) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> mData = list[i] as Dictionary <string, object>;
                string        prefab       = (string)mData["Prefab"];
                List <object> positionData = mData["Position"] as List <object>;
                List <object> rotationData = mData["Rotation"] as List <object>;
                string        type         = (string)mData["Type"];

                Vector3        position       = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2]));
                Quaternion     rotation       = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2])));
                ItemCollection itemCollection = null;
                if (type == "UI")
                {
                    UIWidget container = WidgetUtility.Find <UIWidget>(prefab);
                    if (container != null && (includePersistent || container.gameObject.scene == UnityEngine.SceneManagement.SceneManager.GetActiveScene()))
                    {
                        itemCollection = container.GetComponent <ItemCollection>();
                    }
                }
                else
                {
                    GameObject collectionGameObject = CreateCollection(prefab, position, rotation);
                    if (collectionGameObject != null)
                    {
                        IGenerator[] generators = collectionGameObject.GetComponents <IGenerator>();
                        for (int j = 0; j < generators.Length; j++)
                        {
                            generators[j].enabled = false;
                        }
                        itemCollection = collectionGameObject.GetComponent <ItemCollection>();
                    }
                }

                if (itemCollection != null)
                {
                    itemCollection.SetObjectData(mData);
                }
            }

            if (InventoryManager.current != null && InventoryManager.current.onSceneLoaded != null)
            {
                InventoryManager.current.onSceneLoaded.Invoke();
            }

            if (InventoryManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Inventory System] Data loaded: " + data);
            }
        }