Exemplo n.º 1
0
        public static DotArkProperty ReadPropertyFromDisk(DotArkDeserializer d)
        {
            var ms = d.ms;

            //First, read a name and open it.
            ArkClassName name = ms.ReadArkClassname(d);

            //If this name is null, we've done something wrong.
            if (name == null)
            {
                throw new Exception("A property reading error occurred and got an unexpected NULL value; do not save");
            }

            //If the name is None, we've read to the final property and we can stop.
            if (name.IsNone())
            {
                return(null);
            }

            //Now, read the type
            ArkClassName type = ms.ReadArkClassname(d);

            //If the type is None or unreadable, something has gone wrong.
            if (type == null)
            {
                throw new Exception($"A property name was identified as {name.classname}, but the type failed to read.");
            }

            //Read in the index and size
            int size  = ms.ReadInt();
            int index = ms.ReadInt();

            //Based on the type, deserialize this.
            DotArkProperty prop;

            switch (type.classname)
            {
            case "IntProperty":
                prop = new IntProperty(d, index, size);
                break;

            case "UInt32Property":
                prop = new UInt32Property(d, index, size);
                break;

            case "Int8Property":
                prop = new Int8Property(d, index, size);
                break;

            case "Int16Property":
                prop = new Int16Property(d, index, size);
                break;

            case "UInt16Property":
                prop = new UInt16Property(d, index, size);
                break;

            case "UInt64Property":
                prop = new UInt64Property(d, index, size);
                break;

            case "BoolProperty":
                prop = new BoolProperty(d, index, size);
                break;

            case "ByteProperty":
                prop = new ByteProperty(d, index, size);
                break;

            case "FloatProperty":
                prop = new FloatProperty(d, index, size);
                break;

            case "DoubleProperty":
                prop = new DoubleProperty(d, index, size);
                break;

            case "NameProperty":
                prop = new NameProperty(d, index, size);
                break;

            case "ObjectProperty":
                prop = new ObjectProperty(d, index, size);
                break;

            case "StrProperty":
                prop = new StrProperty(d, index, size);
                break;

            case "StructProperty":
                prop = new StructProperty(d, index, size);
                break;

            case "ArrayProperty":
                prop = DotArkArray.ReadArray(d, index, size);     //UNFINISHED
                break;

            case "TextProperty":
                prop = new TextProperty(d, index, size);
                break;

            default:
                //Unknown
                throw new Exception($"Type {type.classname} was not a valid property type. Something failed to read.");
            }
            //Set additional values in the property and return it.
            prop.type  = type;
            prop.name  = name;
            prop.index = index;
            prop.size  = size;

            return(prop);
        }
Exemplo n.º 2
0
        public static UProperty ReadProp(IOMemoryStream ms, UAssetFile f, string arrayType, bool isStruct)
        {
            //Read the name
            long start = ms.position;

            //Read the remainder of the properties
            string name;
            int    u1;
            string type;
            int    u2;
            int    length;
            int    index;

            if (arrayType == null)
            {
                //Not an array
                name = ms.ReadNameTableEntry(f);

                //Return null if this is "None". That means we're done reading
                if (name == "None")
                {
                    return(null);
                }

                u1     = ms.ReadInt();
                type   = ms.ReadNameTableEntry(f);
                u2     = ms.ReadInt();
                length = ms.ReadInt();
                index  = ms.ReadInt();
            }
            else
            {
                name   = null;
                u1     = 0;
                type   = arrayType;
                u2     = 0;
                length = 0;
                index  = 0;
            }
            long payloadStart = ms.position;

            //Create the object
            UProperty u;

            switch (type)
            {
            case "ArrayProperty": u = new ArrayProperty(ms, f); break;

            case "BoolProperty": u = new BoolProperty(ms, f); break;

            case "ByteProperty": u = new ByteProperty(ms, f); break;

            case "DoubleProperty": u = new DoubleProperty(ms, f); break;

            case "FloatProperty": u = new FloatProperty(ms, f); break;

            case "Int16Property": u = new Int16Property(ms, f); break;

            case "Int8Property": u = new Int8Property(ms, f); break;

            case "IntProperty": u = new IntProperty(ms, f); break;

            case "NameProperty": u = new NameProperty(ms, f); break;

            case "ObjectProperty": u = new ObjectProperty(ms, f); break;

            case "StrProperty": u = new StrProperty(ms, f); break;

            case "StructProperty": u = new StructProperty(ms, f); break;

            case "TextProperty": u = new TextProperty(ms, f); break;

            case "UInt16Property": u = new UInt16Property(ms, f); break;

            case "UInt32Property": u = new UInt32Property(ms, f); break;

            case "UInt64Property": u = new UInt64Property(ms, f); break;

            default:
                throw new Exception($"FAILED TO READ UPROPERTY: Type {type} was not a valid type. Name={name}, u1={u1}, u2={u2}, length={length}, index={index}, position={start}");
            }

            //Set attributes
            u.name         = name;
            u.unknown1     = u1;
            u.type         = type;
            u.unknown2     = u2;
            u.length       = length;
            u.index        = index;
            u.start        = start;
            u.payloadStart = payloadStart;
            u.isArray      = arrayType != null;

            //Dump
            f.DebugDump("UProperty Reading", ConsoleColor.Green, "name", name, "u1", u1.ToString(), "type", type, "u2", u2.ToString(), "length", length.ToString(), "index", index.ToString(), "start", start.ToString(), "payloadStart", payloadStart.ToString());

            //Read
            u.Read(ms, f);

            //Log
            string msg = u.WriteString();

            f.Debug("UProperty Read " + type, msg, ConsoleColor.DarkGreen);

            return(u);
        }