Example #1
0
    public HashSet <T> ReadHashSet <T>(string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._HashSet, type, null, tag);
        return(ReadHashSet <T>(type));
    }
Example #2
0
    public T[,,] Read3DArray <T>(string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._NativeArray, type, null, tag);
        return(Read3DArray <T>(type));
    }
Example #3
0
    public void ReadList <T>(string tag, List <T> c) where T : class
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._List, type, null, tag);
        ReadList <T>(type, c);
    }
Example #4
0
    protected void WriteAllComponents(ES2AutoSave autoSave, ES2Writer writer)
    {
        Component[] components = autoSave.GetComponents <Component>();

        foreach (Component c in components)
        {
            if (c == null)
            {
                continue;
            }

            ES2Type type;
            ES2AutoSaveComponentInfo info = autoSave.GetComponentInfo(c);

            type = ES2TypeManager.GetES2Type(c.GetType());
            if (type == null)
            {
                continue;
            }

            if (info == null)
            {
                info = new ES2AutoSaveComponentInfo(c, autoSave);
            }
            WriteVariableRecursive(autoSave, info, writer, c);
        }
    }
Example #5
0
    public Stack <T> ReadStack <T>(string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._Stack, type, null, tag);
        return(ReadStack <T>(type));
    }
Example #6
0
    public override void Write(object data, ES2Writer writer)
    {
        GameObject go = (GameObject)data;
        // Get the Components of the GameObject that you want to save and save them.
        var components          = go.GetComponents(typeof(Component));
        var supportedComponents = new List <Component>();

        // Get the supported Components and put them in a List.
        foreach (var component in components)
        {
            if (ES2TypeManager.GetES2Type(component.GetType()) != null)
            {
                supportedComponents.Add(component);
            }
        }

        // Write how many Components we're saving so we know when we're loading.
        writer.Write(supportedComponents.Count);

        // Save each Component individually.
        foreach (var component in supportedComponents)
        {
            // Save the id of the ES2Type.
            var es2Type = ES2TypeManager.GetES2Type(component.GetType());
            writer.Write(es2Type.hash);
            writer.Write(component);
        }
    }
Example #7
0
    public void ReadArray <T>(string tag, T[] c) where T : class
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._NativeArray, type, null, tag);
        ReadArray <T>(type, c);
    }
Example #8
0
    public T Read <T>(string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        ProcessHeader(ES2Keys.Key._Null, type, null, tag);
        return((T)Read <T>(type));
    }
Example #9
0
    public Dictionary <TKey, TValue> ReadDictionary <TKey, TValue>(string tag)
    {
        ES2Type keyType   = ES2TypeManager.GetES2Type(typeof(TKey));
        ES2Type valueType = ES2TypeManager.GetES2Type(typeof(TValue));

        ProcessHeader(ES2Keys.Key._Dictionary, valueType, keyType, tag);
        return(ReadDictionary <TKey, TValue>(keyType, valueType));
    }
Example #10
0
    private void ReadComponent(ES2AutoSave autoSave, ES2Reader reader)
    {
        string componentID = reader.reader.ReadString();
        int    endPosition = (int)reader.stream.Position;
        int    length      = reader.reader.ReadInt32();

        endPosition += length;

        // Read collection type byte which is not relevant to Components.
        reader.reader.ReadByte();

        int     typeHash = reader.reader.ReadInt32();
        ES2Type type     = ES2TypeManager.GetES2Type(typeHash);

        // If there's no ES2Type for this type of Component, skip it.
        if (type == null)
        {
            reader.stream.Position = endPosition;
            return;
        }

        // Get or create the Component.
        Component c;
        ES2AutoSaveComponentInfo componentInfo = autoSave.GetComponentInfo(componentID);

        if (componentInfo == null || componentInfo.component == null)
        {
            // If no Component info, look for the Component, or otherwise, add one.
            if (!(c = autoSave.gameObject.GetComponent(type.type)))
            {
                c = autoSave.gameObject.AddComponent(type.type);
            }
        }
        else
        {
            c = componentInfo.component;
        }

        string dataType = reader.reader.ReadString();

        if (dataType == "data")
        {
            reader.Read <System.Object>(type, c);
            return;
        }
        else if (dataType == "vars")        // Else we're reading a series of variables denoted by "vars".
        {
            while (reader.stream.Position != endPosition)
            {
                ReadVariableRecursive(autoSave, componentInfo, reader, c);
            }
        }
        else
        {
            reader.stream.Position = endPosition;
            return;
        }
    }
Example #11
0
    /* END ES2BinaryWriter functionality */

    #region User-Exposed Write Methods (With Tag)

    // These are user-exposed methods.

    public void Write <T>(T param, string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(param.GetType());

        WriteHeader(tag, ES2Keys.Key._Null, type, null);
        Write <T>(param, type);
        WriteTerminator();
        WriteLength();
        tagsToDelete.Add(tag);
    }
Example #12
0
    public override void Write(object data, ES2Writer writer)
    {
        var     dataType = data.GetType();
        ES2Type es2Type  = ES2TypeManager.GetES2Type(dataType);

        if (es2Type == null)
        {
            Debug.LogError("Cannot save Object of type " + dataType + " as it is not a supported type");
            return;
        }
        writer.Write(es2Type.hash);
        writer.Write(data, es2Type);
    }
Example #13
0
    public override object Read(ES2Reader reader)
    {
        int     hash    = reader.Read <int>();
        ES2Type es2Type = ES2TypeManager.GetES2Type(hash);

        if (es2Type == null)
        {
            Debug.LogError("Cannot load Object of this type as it is not a supported type");
            return(null);
        }

        return(reader.Read <object>(es2Type));
    }
Example #14
0
    private void SaveCurrentTag(ES2Header header)
    {
        try
        {
            ES2Type valueType = ES2TypeManager.GetES2Type(header.valueType);
            ES2Type keyType   = ES2TypeManager.GetES2Type(header.keyType);

            ES2Settings settings = new ES2Settings(currentFilePath);
            settings.encrypt            = header.settings.encrypt;
            settings.encryptionType     = header.settings.encryptionType;
            settings.encryptionPassword = header.settings.encryptionPassword;

            using (ES2Writer writer = new ES2Writer(settings))
            {
                if (header.collectionType == ES2Keys.Key._Null)
                {
                    writer.Write(currentValue, currentTag, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._NativeArray)
                {
                    writer.Write(currentValue as object[], currentTag, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._Dictionary)
                {
                    writer.Write(currentValue as Dictionary <object, object>, currentTag, keyType, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._List)
                {
                    writer.Write(currentValue as List <object>, currentTag, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._Queue)
                {
                    writer.Write(currentValue as Queue <object>, currentTag, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._Stack)
                {
                    writer.Write(currentValue as Stack <object>, currentTag, valueType);
                }
                else if (header.collectionType == ES2Keys.Key._HashSet)
                {
                    writer.Write(currentValue as HashSet <object>, currentTag, valueType);
                }

                writer.Save();
            }
        }
        catch (Exception e)
        {
            EditorUtility.DisplayDialog("Could not save file", "An error was thrown when trying to save to this file. See below for details.\n\n" + "Details: " + e.Message, "Ok");
        }
    }
Example #15
0
    public override void Read(ES2Reader reader, object obj)
    {
        int     hash    = reader.Read <int>();
        ES2Type es2Type = ES2TypeManager.GetES2Type(hash);

        if (es2Type == null)
        {
            Debug.LogError("Textures of type " + type.ToString() + " are not currently supported.");
        }
        else
        {
            reader.Read <object>(es2Type, obj);
        }
    }
Example #16
0
    public void Write <T>(Stack <T> param, string tag)
    {
        ES2Type type = ES2TypeManager.GetES2Type(typeof(T));

        if (type == null)
        {
            Debug.LogError(typeof(T).ToString() + " is not currently supported or it's ES2Type was not found, but you may be able to add support for it through Assets > Easy Save 2 > Manage Types");
        }
        WriteHeader(tag, ES2Keys.Key._Stack, type, null);
        Write <T>(param, type);
        WriteTerminator();
        WriteLength();
        tagsToDelete.Add(tag);
    }
Example #17
0
    public override void Write(object data, ES2Writer writer)
    {
        System.Type type    = data.GetType();
        ES2Type     es2Type = ES2TypeManager.GetES2Type(type);

        if (es2Type == null)
        {
            Debug.LogError("Textures of type " + type.ToString() + " are not currently supported.");
        }
        else
        {
            writer.Write(es2Type.hash);
            writer.Write(data, es2Type);
        }
    }
Example #18
0
    /*
     *  Reads an object from the file, using the header data to determine type
     *	and load appropriately using self-assigning method. Must be positioned before a tag before using.
     *	Should not be used to load collections or non-value types.
     */
    public void ReadObject(object obj)
    {
        ES2Header header = ReadHeader();

        ES2Type es2Type = ES2TypeManager.GetES2Type(header.valueType);

        // Handle encrypted data
        if (header.settings.encrypt)
        {
            ReadEncrypted <System.Object>(es2Type, obj);
        }
        else
        {
            Read <System.Object>(es2Type, obj);
        }
    }
Example #19
0
    public override void Read(ES2Reader reader, object c)
    {
        GameObject go = (GameObject)c;
        // How many components do we need to load?
        int componentCount = reader.Read <int>();

        for (int i = 0; i < componentCount; i++)
        {
            var es2Type = ES2TypeManager.GetES2Type(reader.Read <int>());

            // Get Component from GameObject, or add it if it doesn't have one.
            Component component = go.GetComponent(es2Type.type);
            if (component == null)
            {
                component = go.AddComponent(es2Type.type);
            }
            reader.Read <System.Object>(es2Type, component);
        }
    }
Example #20
0
    public void Write <TKey, TValue>(Dictionary <TKey, TValue> param, string tag)
    {
        ES2Type keyType   = ES2TypeManager.GetES2Type(typeof(TKey));
        ES2Type valueType = ES2TypeManager.GetES2Type(typeof(TValue));

        if (keyType == null)
        {
            Debug.LogError(typeof(TKey).ToString() + " is not currently supported or it's ES2Type was not found, but you may be able to add support for it through Assets > Easy Save 2 > Manage Types");
        }
        if (valueType == null)
        {
            Debug.LogError(typeof(TValue).ToString() + " is not currently supported or it's ES2Type was not found, but you may be able to add support for it through Assets > Easy Save 2 > Manage Types");
        }
        WriteHeader(tag, ES2Keys.Key._Dictionary, valueType, keyType);
        Write <TKey, TValue>(param, keyType, valueType);
        WriteTerminator();
        WriteLength();
        tagsToDelete.Add(tag);
    }
Example #21
0
 private string GetTypeName(ES2Header header, ES2EditorType valueType)
 {
     if (header.collectionType == ES2Keys.Key._Null)
     {
         return(valueType.type.ToString());
     }
     else if (header.collectionType == ES2Keys.Key._NativeArray)
     {
         return(valueType.type.ToString() + "[]");
     }
     else if (header.collectionType == ES2Keys.Key._Dictionary)
     {
         return("Dictionary<" + ES2TypeManager.GetES2Type(header.keyType).type.ToString() + "," + valueType.type.ToString() + ">");
     }
     else
     {
         string enumName = header.collectionType.ToString();
         return(enumName.Substring(1, enumName.Length - 1) + "<" + valueType.type.ToString() + ">");
     }
 }
Example #22
0
    /*
     *  Reads a Component from the file into Component on provided GameObject,
     *	using the header data to determine exact type.
     *  If GameObject doesn't contain Component, it will be added.
     */
    public void ReadComponent(GameObject go)
    {
        ES2Header header = ReadHeader();

        ES2Type es2Type = ES2TypeManager.GetES2Type(header.valueType);

        // Get Component from GameObject, or add it if it doesn't have one.
        Component c = go.GetComponent(es2Type.type);

        if (c == null)
        {
            c = go.AddComponent(es2Type.type);
        }

        // Handle encrypted data
        if (header.settings.encrypt)
        {
            ReadEncrypted <System.Object>(es2Type, c);
        }
        else
        {
            Read <System.Object>(es2Type, c);
        }
    }
Example #23
0
 public HashSet <T> ReadHashSet <T>()
 {
     return(ReadHashSet <T>(ES2TypeManager.GetES2Type(typeof(T))));
 }
Example #24
0
    public ES2Header ReadHeader()
    {
        ES2Keys.Key collectionType = ES2Keys.Key._Null;
        int         keyType        = 0;
        int         valueType      = 0;
        ES2Settings settings       = new ES2Settings();

        while (true)
        {
            byte currentByte = reader.ReadByte();

            if (currentByte == (byte)ES2Keys.Key._Encrypt)            // If encrypt, set encrypted in settings.
            {
                settings.encrypt        = true;
                settings.encryptionType = ES2Settings.EncryptionType.AES128;
            }
            else if (currentByte == (byte)ES2Keys.Key._Obfuscate)            // If encrypt, set encrypted in settings.
            {
                settings.encrypt        = true;
                settings.encryptionType = ES2Settings.EncryptionType.Obfuscate;
            }
            else if (currentByte == (byte)ES2Keys.Key._Terminator)
            {
                continue;
            }
            else if ((int)currentByte == 255)                  // We're loading data after v2.54 where types are identified by integer hashes.
            {
                if (collectionType == ES2Keys.Key._Dictionary) // keyType comes second if we're loading a Dictionary.
                {
                    keyType = reader.ReadInt32();
                }
                else
                {
                    valueType = reader.ReadInt32();
                }
                return(new ES2Header(collectionType, keyType, valueType, settings));
            }
            else if ((int)currentByte < 81)                    // LEGACY SAVE DATA before v2.54: If data type, set data type in settings. End of header.
            {
                if (collectionType == ES2Keys.Key._Dictionary) // keyType comes second if we're loading a Dictionary.
                {
                    keyType = ES2TypeManager.GetES2Type(currentByte).hash;
                }
                else
                {
                    valueType = ES2TypeManager.GetES2Type(currentByte).hash;
                }
                return(new ES2Header(collectionType, keyType, valueType, settings));
            }
            else if ((int)currentByte < 101)            //Array Type
            {
                collectionType = (ES2Keys.Key)currentByte;

                if (currentByte == (byte)ES2Keys.Key._Dictionary)                //If it's a Dictionary, the value byte comes first.
                {
                    byte valueByte = reader.ReadByte();

                    if ((int)valueByte == 255)                    // Handle value bytes after v2.54.
                    {
                        valueType = reader.ReadInt32();
                        keyType   = reader.ReadInt32();
                        return(new ES2Header(collectionType, keyType, valueType, settings));
                    }
                    else                     // Handle value bytes before v2.54.
                    {
                        valueType = ES2TypeManager.GetES2Type(valueByte).hash;
                    }
                }
            }
            else
            {
                throw new ES2InvalidDataException();
            }
        }
    }
Example #25
0
    public System.Object ReadObject()
    {
        ES2Header header = ReadHeader();

        ES2Type es2Type = ES2TypeManager.GetES2Type(header.valueType);

        // Handle encrypted data
        if (header.settings.encrypt)
        {
            // Handle non-encrypted data
            if (header.collectionType != ES2Keys.Key._Null)
            {
                if (header.collectionType == ES2Keys.Key._NativeArray)
                {
                    return(ReadEncryptedArray <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._List)
                {
                    return(ReadEncryptedList <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Queue)
                {
                    return(ReadEncryptedQueue <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Stack)
                {
                    return(ReadEncryptedStack <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._HashSet)
                {
                    return(ReadEncryptedHashSet <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Dictionary)
                {
                    ES2Type keyType = ES2TypeManager.GetES2Type(header.keyType);
                    return(ReadEncryptedDictionary <System.Object, System.Object>(keyType, es2Type));
                }
            }
            else
            {
                return(ReadEncrypted <System.Object>(es2Type));
            }
        }
        else
        {
            // Handle non-encrypted data
            if (header.collectionType != ES2Keys.Key._Null)
            {
                if (header.collectionType == ES2Keys.Key._NativeArray)
                {
                    return(ReadArray <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._List)
                {
                    return(ReadList <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Queue)
                {
                    return(ReadQueue <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Stack)
                {
                    return(ReadStack <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._HashSet)
                {
                    return(ReadHashSet <System.Object>(es2Type));
                }
                else if (header.collectionType == ES2Keys.Key._Dictionary)
                {
                    ES2Type keyType = ES2TypeManager.GetES2Type(header.keyType);
                    return(ReadDictionary <System.Object, System.Object>(keyType, es2Type));
                }
            }
            else
            {
                return(Read <System.Object>(es2Type));
            }
        }

        return(null);
    }
Example #26
0
 public Queue <T> ReadQueue <T>()
 {
     return(ReadQueue <T>(ES2TypeManager.GetES2Type(typeof(T))));
 }
Example #27
0
 public Dictionary <TKey, TValue> ReadDictionary <TKey, TValue>()
 {
     return(ReadDictionary <TKey, TValue>(ES2TypeManager.GetES2Type(typeof(TKey)), ES2TypeManager.GetES2Type(typeof(TValue))));
 }
Example #28
0
 public List <T> ReadList <T>()
 {
     return(ReadList <T>(ES2TypeManager.GetES2Type(typeof(T))));
 }
Example #29
0
 public void ReadList <T>(List <T> c) where T : class
 {
     ReadList <T>(ES2TypeManager.GetES2Type(typeof(T)), c);
 }
Example #30
0
 public Stack <T> ReadStack <T>()
 {
     return(ReadStack <T>(ES2TypeManager.GetES2Type(typeof(T))));
 }