Beispiel #1
0
        public static UType ReadUType(List <TypeTreeNode> members, BinaryReader reader)
        {
            var obj = new UType();

            for (int i = 1; i < members.Count; i++)
            {
                var member     = members[i];
                var varNameStr = member.m_Name;
                obj[varNameStr] = ReadValue(members, reader, ref i);
            }
            return(obj);
        }
        public static byte[] WriteUType(UType obj, List <TypeTreeNode> members)
        {
            var stream = new MemoryStream();
            var write  = new BinaryWriter(stream);

            for (int i = 0; i < members.Count; i++)
            {
                var member     = members[i];
                var varNameStr = member.m_Name;
                WriteValue(obj[varNameStr], members, write, ref i);
            }
            return(stream.ToArray());
        }
Beispiel #3
0
        private static object ReadValue(List <TypeTreeNode> members, BinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    varTypeStr = member.m_Type;
            object value;
            var    align = (member.m_MetaFlag & 0x4000) != 0;

            switch (varTypeStr)
            {
            case "SInt8":
                value = reader.ReadSByte();
                break;

            case "UInt8":
            case "char":
                value = reader.ReadByte();
                break;

            case "short":
            case "SInt16":
                value = reader.ReadInt16();
                break;

            case "UInt16":
            case "unsigned short":
                value = reader.ReadUInt16();
                break;

            case "int":
            case "SInt32":
                value = reader.ReadInt32();
                break;

            case "UInt32":
            case "unsigned int":
            case "Type*":
                value = reader.ReadUInt32();
                break;

            case "long long":
            case "SInt64":
                value = reader.ReadInt64();
                break;

            case "UInt64":
            case "unsigned long long":
            case "FileSize":
                value = reader.ReadUInt64();
                break;

            case "float":
                value = reader.ReadSingle();
                break;

            case "double":
                value = reader.ReadDouble();
                break;

            case "bool":
                value = reader.ReadBoolean();
                break;

            case "string":
                value = reader.ReadAlignedString();
                i    += 3;
                break;

            case "map": {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var map = GetMembers(members, i);
                i += map.Count - 1;
                var first  = GetMembers(map, 4);
                var next   = 4 + first.Count;
                var second = GetMembers(map, next);
                var size   = reader.ReadInt32();
                var dic    = new List <KeyValuePair <object, object> >(size);
                for (int j = 0; j < size; j++)
                {
                    int tmp1 = 0;
                    int tmp2 = 0;
                    dic.Add(new KeyValuePair <object, object>(ReadValue(first, reader, ref tmp1), ReadValue(second, reader, ref tmp2)));
                }
                value = dic;
                break;
            }

            case "TypelessData": {
                var size = reader.ReadInt32();
                value = reader.ReadBytes(size);
                i    += 2;
                break;
            }

            default: {
                if (i < members.Count - 1 && members[i + 1].m_Type == "Array")         //Array
                {
                    if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                    {
                        align = true;
                    }
                    var vector = GetMembers(members, i);
                    i += vector.Count - 1;
                    var size = reader.ReadInt32();
                    var list = new List <object>(size);
                    for (int j = 0; j < size; j++)
                    {
                        int tmp = 3;
                        list.Add(ReadValue(vector, reader, ref tmp));
                    }
                    value = list;
                    break;
                }
                else           //Class
                {
                    var @class = GetMembers(members, i);
                    i += @class.Count - 1;
                    var obj = new UType();
                    for (int j = 1; j < @class.Count; j++)
                    {
                        var classmember = @class[j];
                        var name        = classmember.m_Name;
                        obj[name] = ReadValue(@class, reader, ref j);
                    }
                    value = obj;
                    break;
                }
            }
            }
            if (align)
            {
                reader.AlignStream();
            }
            return(value);
        }