Beispiel #1
0
        private void TypeTreeBlobRead(List <TypeTreeNode> typeTree)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            for (int i = 0; i < numberOfNodes; i++)
            {
                var typeTreeNode = new TypeTreeNode();
                typeTree.Add(typeTreeNode);
                typeTreeNode.m_Version       = reader.ReadUInt16();
                typeTreeNode.m_Level         = reader.ReadByte();
                typeTreeNode.m_IsArray       = reader.ReadBoolean() ? 1 : 0;
                typeTreeNode.m_TypeStrOffset = reader.ReadUInt32();
                typeTreeNode.m_NameStrOffset = reader.ReadUInt32();
                typeTreeNode.m_ByteSize      = reader.ReadInt32();
                typeTreeNode.m_Index         = reader.ReadInt32();
                typeTreeNode.m_MetaFlag      = reader.ReadInt32();
                if (header.m_Version >= 19)
                {
                    typeTreeNode.m_RefTypeHash = reader.ReadUInt64();
                }
            }
            var m_StringBuffer = reader.ReadBytes(stringBufferSize);

            using (var stringBufferReader = new BinaryReader(new MemoryStream(m_StringBuffer)))
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var typeTreeNode = typeTree[i];
                    typeTreeNode.m_Type = ReadString(stringBufferReader, typeTreeNode.m_TypeStrOffset);
                    typeTreeNode.m_Name = ReadString(stringBufferReader, typeTreeNode.m_NameStrOffset);
                }
            }

            string ReadString(BinaryReader stringBufferReader, uint value)
            {
                var isOffset = (value & 0x80000000) == 0;

                if (isOffset)
                {
                    stringBufferReader.BaseStream.Position = value;
                    return(stringBufferReader.ReadStringToNull());
                }
                var offset = value & 0x7FFFFFFF;

                if (CommonString.StringBuffer.TryGetValue(offset, out var str))
                {
                    return(str);
                }
                return(offset.ToString());
            }
        }
Beispiel #2
0
        private void TypeTreeBlobRead(TypeTree m_Type)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            for (int i = 0; i < numberOfNodes; i++)
            {
                var typeTreeNode = new TypeTreeNode();
                m_Type.m_Nodes.Add(typeTreeNode);
                typeTreeNode.m_Version       = reader.ReadUInt16();
                typeTreeNode.m_Level         = reader.ReadByte();
                typeTreeNode.m_TypeFlags     = reader.ReadByte();
                typeTreeNode.m_TypeStrOffset = reader.ReadUInt32();
                typeTreeNode.m_NameStrOffset = reader.ReadUInt32();
                typeTreeNode.m_ByteSize      = reader.ReadInt32();
                typeTreeNode.m_Index         = reader.ReadInt32();
                typeTreeNode.m_MetaFlag      = reader.ReadInt32();
                if (header.m_Version >= SerializedFileFormatVersion.kTypeTreeNodeWithTypeFlags)
                {
                    typeTreeNode.m_RefTypeHash = reader.ReadUInt64();
                }
            }
            m_Type.m_StringBuffer = reader.ReadBytes(stringBufferSize);

            using (var stringBufferReader = new BinaryReader(new MemoryStream(m_Type.m_StringBuffer)))
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var m_Node = m_Type.m_Nodes[i];
                    m_Node.m_Type = ReadString(stringBufferReader, m_Node.m_TypeStrOffset);
                    m_Node.m_Name = ReadString(stringBufferReader, m_Node.m_NameStrOffset);
                }
            }

            string ReadString(BinaryReader stringBufferReader, uint value)
            {
                var isOffset = (value & 0x80000000) == 0;

                if (isOffset)
                {
                    stringBufferReader.BaseStream.Position = value;
                    return(stringBufferReader.ReadStringToNull());
                }
                var offset = value & 0x7FFFFFFF;

                if (CommonString.StringBuffer.TryGetValue(offset, out var str))
                {
                    return(str);
                }
                return(offset.ToString());
            }
        }
Beispiel #3
0
        private static object ReadValue(List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            object value;
            var    align = (member.m_MetaFlag & 0x4000) != 0;

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

            case "UInt8":
                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":
                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 "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size   = reader.ReadInt32();
                var list   = new List <object>(size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    int tmp = 0;
                    list.Add(ReadValue(vector, reader, ref tmp));
                }
                value = list;
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size = reader.ReadInt32();
                var dic  = new List <KeyValuePair <object, object> >(size);
                var map  = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                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 && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                var obj    = new ExpandoObject();
                var objdic = (IDictionary <string, object>)obj;
                for (int j = 0; j < @class.Count; j++)
                {
                    var classmember = @class[j];
                    var name        = classmember.m_Name;
                    objdic[name] = ReadValue(@class, reader, ref j);
                }
                value = obj;
                break;
            }
            }
            if (align)
            {
                reader.AlignStream(4);
            }
            return(value);
        }
Beispiel #4
0
        private static void ReadStringValue(StringBuilder sb, List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            var    varNameStr = member.m_Name;
            object value      = null;
            var    append     = true;
            var    align      = (member.m_MetaFlag & 0x4000) != 0;

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

            case "UInt8":
                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":
                value = reader.ReadUInt64();
                break;

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

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

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

            case "string":
                append = false;
                var str = reader.ReadAlignedString();
                sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                i += 3;
                break;

            case "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    int tmp = 0;
                    ReadStringValue(sb, vector, reader, ref tmp);
                }
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var map = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 2)), "pair", "data");
                    int tmp1 = 0;
                    int tmp2 = 0;
                    ReadStringValue(sb, first, reader, ref tmp1);
                    ReadStringValue(sb, second, reader, ref tmp2);
                }
                break;
            }

            case "TypelessData":
            {
                append = false;
                var size = reader.ReadInt32();
                reader.ReadBytes(size);
                i += 2;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                break;
            }

            default:
            {
                if (i != members.Count && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                for (int j = 0; j < @class.Count; j++)
                {
                    ReadStringValue(sb, @class, reader, ref j);
                }
                break;
            }
            }
            if (append)
            {
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
            }
            if (align)
            {
                reader.AlignStream(4);
            }
        }
Beispiel #5
0
        public static void ReadClassStruct(StringBuilder sb, List <ClassMember> members, EndianBinaryReader reader)
        {
            for (int i = 0; i < members.Count; i++)
            {
                var    member     = members[i];
                var    level      = member.Level;
                var    varTypeStr = member.Type;
                var    varNameStr = member.Name;
                object value      = null;
                var    align      = (member.Flag & 0x4000) != 0;
                var    append     = true;
                if (member.alignBefore)
                {
                    reader.AlignStream(4);
                }
                switch (varTypeStr)
                {
                case "SInt8":
                    value = reader.ReadSByte();
                    break;

                case "UInt8":
                    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":
                    value = reader.ReadUInt64();
                    break;

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

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

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

                case "string":
                    append = false;
                    var str = reader.ReadAlignedString();
                    sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                    i += 3;    //skip
                    break;

                case "Array":
                {
                    append = false;
                    if ((members[i - 1].Flag & 0x4000) != 0)
                    {
                        align = true;
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    var size = reader.ReadInt32();
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    var array = ReadArray(members, level, i);
                    for (int j = 0; j < size; j++)
                    {
                        sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 1)), j);
                        ReadClassStruct(sb, array, reader);
                    }
                    i += array.Count + 1;        //skip
                    break;
                }

                case "TypelessData":
                {
                    append = false;
                    var size = reader.ReadInt32();
                    reader.ReadBytes(size);
                    i += 2;
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    break;
                }

                default:
                    append = false;
                    if (align)
                    {
                        align = false;
                        SetAlignBefore(members, level, i + 1);
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    break;
                }
                if (append)
                {
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
                }
                if (align)
                {
                    reader.AlignStream(4);
                }
            }
        }