private void ReadTypeTree(List <TypeTree> typeTreeList, int depth) { var typeTree = new TypeTree(); typeTreeList.Add(typeTree); typeTree.m_Depth = depth; typeTree.m_Type = reader.ReadStringToNull(); typeTree.m_Name = reader.ReadStringToNull(); typeTree.m_ByteSize = reader.ReadInt32(); if (header.m_Version == 2) { var variableCount = reader.ReadInt32(); } if (header.m_Version != 3) { typeTree.m_Index = reader.ReadInt32(); } typeTree.m_IsArray = reader.ReadInt32(); typeTree.m_Version = reader.ReadInt32(); if (header.m_Version != 3) { typeTree.m_MetaFlag = reader.ReadInt32(); } int childrenCount = reader.ReadInt32(); for (int i = 0; i < childrenCount; i++) { ReadTypeTree(typeTreeList, depth + 1); } }
private void ReadTypeTree(TypeTree m_Type, int level = 0) { var typeTreeNode = new TypeTreeNode(); m_Type.m_Nodes.Add(typeTreeNode); typeTreeNode.m_Level = level; typeTreeNode.m_Type = reader.ReadStringToNull(); typeTreeNode.m_Name = reader.ReadStringToNull(); typeTreeNode.m_ByteSize = reader.ReadInt32(); if (header.m_Version == SerializedFileFormatVersion.kUnknown_2) { var variableCount = reader.ReadInt32(); } if (header.m_Version != SerializedFileFormatVersion.kUnknown_3) { typeTreeNode.m_Index = reader.ReadInt32(); } typeTreeNode.m_TypeFlags = reader.ReadInt32(); typeTreeNode.m_Version = reader.ReadInt32(); if (header.m_Version != SerializedFileFormatVersion.kUnknown_3) { typeTreeNode.m_MetaFlag = reader.ReadInt32(); } int childrenCount = reader.ReadInt32(); for (int i = 0; i < childrenCount; i++) { ReadTypeTree(m_Type, level + 1); } }
public OrderedDictionary ToType(TypeTree m_Type) { if (m_Type != null) { return(TypeTreeHelper.ReadType(m_Type, reader)); } return(null); }
public string Dump(TypeTree m_Type) { if (m_Type != null) { return(TypeTreeHelper.ReadTypeString(m_Type, reader)); } return(null); }
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()); } }
public static string ReadTypeString(TypeTree m_Type, ObjectReader reader) { reader.Reset(); var sb = new StringBuilder(); var m_Nodes = m_Type.m_Nodes; for (int i = 0; i < m_Nodes.Count; i++) { ReadStringValue(sb, m_Nodes, reader, ref i); } var readed = reader.Position - reader.byteStart; if (readed != reader.byteSize) { Logger.Info($"Error while read type, read {readed} bytes but expected {reader.byteSize} bytes"); } return(sb.ToString()); }
public static TypeTree ConvertToTypeTree(this MonoBehaviour m_MonoBehaviour, AssemblyLoader assemblyLoader) { var m_Type = new TypeTree(); m_Type.m_Nodes = new List <TypeTreeNode>(); var helper = new SerializedTypeHelper(m_MonoBehaviour.version); helper.AddMonoBehaviour(m_Type.m_Nodes, 0); if (m_MonoBehaviour.m_Script.TryGet(out var m_Script)) { var typeDef = assemblyLoader.GetTypeDefinition(m_Script.m_AssemblyName, string.IsNullOrEmpty(m_Script.m_Namespace) ? m_Script.m_ClassName : $"{m_Script.m_Namespace}.{m_Script.m_ClassName}"); if (typeDef != null) { var typeDefinitionConverter = new TypeDefinitionConverter(typeDef, helper, 1); m_Type.m_Nodes.AddRange(typeDefinitionConverter.ConvertToTypeTreeNodes()); } } return(m_Type); }
public static OrderedDictionary ReadType(TypeTree m_Types, ObjectReader reader) { reader.Reset(); var obj = new OrderedDictionary(); var m_Nodes = m_Types.m_Nodes; for (int i = 1; i < m_Nodes.Count; i++) { var m_Node = m_Nodes[i]; var varNameStr = m_Node.m_Name; obj[varNameStr] = ReadValue(m_Nodes, reader, ref i); } var readed = reader.Position - reader.byteStart; if (readed != reader.byteSize) { Logger.Info($"Error while read type, read {readed} bytes but expected {reader.byteSize} bytes"); } return(obj); }
private void ReadTypeTree5() { int classID = reader.ReadInt32(); if (header.m_Version > 15)//5.5.0 and up { reader.ReadByte(); int typeID = reader.ReadInt16(); if (typeID >= 0) { typeID = -1 - typeID; } else { typeID = classID; } classIDs.Add(new[] { typeID, classID }); if (classID == 114) { reader.Position += 16; } classID = typeID; } else if (classID < 0) { reader.Position += 16; } reader.Position += 16; if (serializedTypeTrees) { int varCount = reader.ReadInt32(); int stringSize = reader.ReadInt32(); reader.Position += varCount * 24; using (var stringReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringSize)))) { var typeTreeList = new List <TypeTree>(); reader.Position -= varCount * 24 + stringSize; for (int i = 0; i < varCount; i++) { var typeTree = new TypeTree(); typeTreeList.Add(typeTree); typeTree.m_Version = reader.ReadUInt16(); typeTree.m_Depth = reader.ReadByte(); typeTree.m_IsArray = reader.ReadBoolean() ? 1 : 0; ushort varTypeIndex = reader.ReadUInt16(); ushort test = reader.ReadUInt16(); if (test == 0) //varType is an offset in the string block { stringReader.BaseStream.Position = varTypeIndex; typeTree.m_Type = stringReader.ReadStringToNull(); } else //varType is an index in an internal strig array { typeTree.m_Type = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString(); } ushort varNameIndex = reader.ReadUInt16(); test = reader.ReadUInt16(); if (test == 0) { stringReader.BaseStream.Position = varNameIndex; typeTree.m_Name = stringReader.ReadStringToNull(); } else { typeTree.m_Name = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString(); } typeTree.m_ByteSize = reader.ReadInt32(); typeTree.m_Index = reader.ReadInt32(); typeTree.m_MetaFlag = reader.ReadInt32(); } reader.Position += stringSize; m_Type[classID] = typeTreeList; } } }