Example #1
0
 private IDictionary ReadEncryptedIDictionary(System.Type dictionaryType, ES2Type keyType, ES2Type valueType)
 {
     using (ES2Reader encryptedReader = GetEncryptedReader())
         return(encryptedReader.ReadIDictionary(dictionaryType, keyType, valueType));
 }
Example #2
0
    private void ReadVariableRecursive(ES2AutoSave autoSave, ES2AutoSaveVariableInfo variable, ES2Reader reader, object obj)
    {
        string variableID  = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read Type data
        ES2Keys.Key collectionType = (ES2Keys.Key)reader.reader.ReadByte();
        int         typeHash       = reader.reader.ReadInt32();
        int         dictValueHash  = 0;

        if (collectionType == ES2Keys.Key._Dictionary)
        {
            dictValueHash = reader.reader.ReadInt32();
        }

        ES2AutoSaveVariableInfo info = autoSave.GetCachedVariableInfo(variableID);

        if (info == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            // Get ES2Types.
            ES2Type type          = ES2TypeManager.GetES2Type(typeHash);
            ES2Type dictValueType = null;
            if (collectionType == ES2Keys.Key._Dictionary)
            {
                dictValueType = ES2TypeManager.GetES2Type(dictValueHash);
            }

            // If the type of data we're loading isn't supported, skip it.
            if (type == null || (collectionType == ES2Keys.Key._Dictionary && dictValueType == null))
            {
                reader.stream.Position = endPosition;
                return;
            }

            bool valueWasSet = false;

            if (collectionType == ES2Keys.Key._Null)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.Read <System.Object>(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._NativeArray)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadSystemArray(type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._List)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(List <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Queue)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Queue <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Stack)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(Stack <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._HashSet)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadICollection(typeof(HashSet <>), type), info.isProperty);
            }
            else if (collectionType == ES2Keys.Key._Dictionary)
            {
                valueWasSet = ES2Reflection.SetValue(obj, info.name, reader.ReadIDictionary(typeof(Dictionary <,>), type, dictValueType), info.isProperty);
            }

            if (!valueWasSet)
            {
                reader.stream.Position = endPosition;
                return;
            }
        }
        // Else, we have variables to load.
        else if (dataType == "vars")
        {
            object thisObj = ES2Reflection.GetValue(obj, info.name, info.isProperty);
            if (thisObj == null)
            {
                reader.stream.Position = endPosition;
            }
            ReadVariableRecursive(autoSave, info, reader, thisObj);
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }