public Texture2D(ObjectReader reader) : base(reader) { m_Width = reader.ReadInt32(); m_Height = reader.ReadInt32(); var m_CompleteImageSize = reader.ReadInt32(); m_TextureFormat = (TextureFormat)reader.ReadInt32(); if (version[0] < 5 || (version[0] == 5 && version[1] < 2)) //5.2 down { m_MipMap = reader.ReadBoolean(); } else { m_MipCount = reader.ReadInt32(); } var m_IsReadable = reader.ReadBoolean(); //2.6.0 and up var m_ReadAllowed = reader.ReadBoolean(); //3.0.0 - 5.4 //bool m_StreamingMipmaps 2018.2 and up reader.AlignStream(); if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_StreamingMipmapsPriority = reader.ReadInt32(); } var m_ImageCount = reader.ReadInt32(); var m_TextureDimension = reader.ReadInt32(); m_TextureSettings = new GLTextureSettings(reader); if (version[0] >= 3) //3.0 and up { var m_LightmapFormat = reader.ReadInt32(); } if (version[0] > 3 || (version[0] == 3 && version[1] >= 5)) //3.5.0 and up { var m_ColorSpace = reader.ReadInt32(); } var image_data_size = reader.ReadInt32(); if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up { m_StreamData = new StreamingInfo(reader); } ResourceReader resourceReader; if (!string.IsNullOrEmpty(m_StreamData?.path)) { resourceReader = new ResourceReader(m_StreamData.path, assetsFile, m_StreamData.offset, (int)m_StreamData.size); } else { resourceReader = new ResourceReader(reader, reader.BaseStream.Position, image_data_size); } image_data = resourceReader; }
public Texture2D(ObjectReader reader) : base(reader) { m_Width = reader.ReadInt32(); m_Height = reader.ReadInt32(); var m_CompleteImageSize = reader.ReadInt32(); if (version[0] >= 2020) //2020.1 and up { var m_MipsStripped = reader.ReadInt32(); } m_TextureFormat = (TextureFormat)reader.ReadInt32(); if (version[0] < 5 || (version[0] == 5 && version[1] < 2)) //5.2 down { m_MipMap = reader.ReadBoolean(); } else { m_MipCount = reader.ReadInt32(); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and up { var m_IsReadable = reader.ReadBoolean(); } if (version[0] >= 2020) //2020.1 and up { var m_IsPreProcessed = reader.ReadBoolean(); } if (version[0] > 2019 || (version[0] == 2019 && version[1] >= 3)) //2019.3 and up { var m_IgnoreMasterTextureLimit = reader.ReadBoolean(); } if (version[0] >= 3) //3.0.0 - 5.4 { if (version[0] < 5 || (version[0] == 5 && version[1] <= 4)) { var m_ReadAllowed = reader.ReadBoolean(); } } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_StreamingMipmaps = reader.ReadBoolean(); } reader.AlignStream(); if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_StreamingMipmapsPriority = reader.ReadInt32(); } var m_ImageCount = reader.ReadInt32(); var m_TextureDimension = reader.ReadInt32(); m_TextureSettings = new GLTextureSettings(reader); if (version[0] >= 3) //3.0 and up { var m_LightmapFormat = reader.ReadInt32(); } if (version[0] > 3 || (version[0] == 3 && version[1] >= 5)) //3.5.0 and up { var m_ColorSpace = reader.ReadInt32(); } if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up { var m_PlatformBlob = reader.ReadUInt8Array(); reader.AlignStream(); } var image_data_size = reader.ReadInt32(); if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up { m_StreamData = new StreamingInfo(reader); } ResourceReader resourceReader; if (!string.IsNullOrEmpty(m_StreamData?.path)) { // no way in hell this is correct reader.AlignStream(); resourceReader = new ResourceReader(reader, reader.BaseStream.Length - m_CompleteImageSize, m_CompleteImageSize); //resourceReader = new ResourceReader(m_StreamData.path, assetsFile, m_StreamData.offset, m_StreamData.size); } else { resourceReader = new ResourceReader(reader, reader.BaseStream.Position, image_data_size); } image_data = resourceReader; }
public List <uint> m_Indices = new List <uint>(); //use a list because I don't always know the facecount for triangle strips public Mesh(ObjectReader reader) : base(reader) { if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.5 down { m_Use16BitIndices = reader.ReadInt32() > 0; } if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = reader.ReadUInt32Array(m_IndexBuffer_size / 4); } } int m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (int i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 1)) //4.1 and up { m_Shapes = new BlendShapeData(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { m_BindPose = reader.ReadMatrixArray(); m_BoneNameHashes = reader.ReadUInt32Array(); var m_RootBoneNameHash = reader.ReadUInt32(); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and up { if (version[0] >= 2019) //2019 and up { var m_BonesAABBSize = reader.ReadInt32(); var m_BonesAABB = new MinMaxAABB[m_BonesAABBSize]; for (int i = 0; i < m_BonesAABBSize; i++) { m_BonesAABB[i] = new MinMaxAABB(reader); } var m_VariableBoneCountWeights = reader.ReadUInt32Array(); } var m_MeshCompression = reader.ReadByte(); if (version[0] >= 4) { if (version[0] < 5) { var m_StreamCompression = reader.ReadByte(); } var m_IsReadable = reader.ReadBoolean(); var m_KeepVertices = reader.ReadBoolean(); var m_KeepIndices = reader.ReadBoolean(); } reader.AlignStream(); //Unity fixed it in 2017.3.1p1 and later versions if ((version[0] > 2017 || (version[0] == 2017 && version[1] >= 4)) || //2017.4 ((version[0] == 2017 && version[1] == 3 && version[2] == 1) && buildType.IsPatch) || //fixed after 2017.3.1px ((version[0] == 2017 && version[1] == 3) && m_MeshCompression == 0)) //2017.3.xfx with no compression { var m_IndexFormat = reader.ReadInt32(); } int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = reader.ReadUInt32Array(m_IndexBuffer_size / 4); } } if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.4.2 and earlier { m_VertexCount = reader.ReadInt32(); m_Vertices = reader.ReadSingleArray(m_VertexCount * 3); //Vector3 m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } m_BindPose = reader.ReadMatrixArray(); m_UV0 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 m_UV1 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_TangentSpace_size = reader.ReadInt32(); m_Normals = new float[m_TangentSpace_size * 3]; m_Tangents = new float[m_TangentSpace_size * 4]; for (int v = 0; v < m_TangentSpace_size; v++) { m_Normals[v * 3] = reader.ReadSingle(); m_Normals[v * 3 + 1] = reader.ReadSingle(); m_Normals[v * 3 + 2] = reader.ReadSingle(); m_Tangents[v * 3] = reader.ReadSingle(); m_Tangents[v * 3 + 1] = reader.ReadSingle(); m_Tangents[v * 3 + 2] = reader.ReadSingle(); m_Tangents[v * 3 + 3] = reader.ReadSingle(); //handedness } } else //2.6.0 and later { m_Tangents = reader.ReadSingleArray(reader.ReadInt32() * 4); //Vector4 m_Normals = reader.ReadSingleArray(reader.ReadInt32() * 3); //Vector3 } } else { if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } } if (version[0] == 3 || (version[0] == 4 && version[1] <= 2)) //4.2 and down { m_BindPose = reader.ReadMatrixArray(); } m_VertexData = new VertexData(reader); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { m_CompressedMesh = new CompressedMesh(reader); } reader.Position += 24; //AABB m_LocalAABB if (version[0] < 3 || (version[0] == 3 && version[1] <= 4)) //3.4.2 and earlier { int m_Colors_size = reader.ReadInt32(); m_Colors = new float[m_Colors_size * 4]; for (int v = 0; v < m_Colors_size * 4; v++) { m_Colors[v] = (float)reader.ReadByte() / 0xFF; } int m_CollisionTriangles_size = reader.ReadInt32(); reader.Position += m_CollisionTriangles_size * 4; //UInt32 indices int m_CollisionVertexCount = reader.ReadInt32(); } int m_MeshUsageFlags = reader.ReadInt32(); if (version[0] >= 5) //5.0 and up { var m_BakedConvexCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); var m_BakedTriangleCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_MeshMetrics = new float[2]; m_MeshMetrics[0] = reader.ReadSingle(); m_MeshMetrics[1] = reader.ReadSingle(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 3)) //2018.3 and up { reader.AlignStream(); m_StreamData = new StreamingInfo(reader); } ProcessData(); }
public List <uint> m_Indices = new List <uint>(); //use a list because I don't always know the facecount for triangle strips public Mesh(ObjectReader reader) : base(reader) { if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.5 down { m_Use16BitIndices = reader.ReadInt32() > 0; } if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = new uint[m_IndexBuffer_size / 4]; for (int i = 0; i < m_IndexBuffer_size / 4; i++) { m_IndexBuffer[i] = reader.ReadUInt32(); } } } int m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (int i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } if (version[0] == 4 && ((version[1] == 1 && !buildType.IsAlpha) || (version[1] > 1 && version[1] <= 2))) //4.1.0 to 4.2.x, excluding 4.1.0 alpha { int m_Shapes_size = reader.ReadInt32(); if (m_Shapes_size > 0) { //bool stop = true; } for (int s = 0; s < m_Shapes_size; s++) //untested { var shape_name = reader.ReadAlignedString(); reader.Position += 36; //uint firstVertex, vertexCount; Vector3f aabbMinDelta, aabbMaxDelta; bool hasNormals, hasTangents } int m_ShapeVertices_size = reader.ReadInt32(); reader.Position += m_ShapeVertices_size * 40; //vertex positions, normals, tangents & uint index } else if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3.0 and later { m_Shapes = new BlendShapeData(reader); m_BindPose = reader.ReadMatrixArray(); m_BoneNameHashes = reader.ReadUInt32Array(); var m_RootBoneNameHash = reader.ReadUInt32(); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { var m_MeshCompression = reader.ReadByte(); if (version[0] >= 4) { if (version[0] < 5) { var m_StreamCompression = reader.ReadByte(); } var m_IsReadable = reader.ReadBoolean(); var m_KeepVertices = reader.ReadBoolean(); var m_KeepIndices = reader.ReadBoolean(); } reader.AlignStream(); //Unity fixed it in 2017.3.1p1 and later versions if ((version[0] > 2017 || (version[0] == 2017 && version[1] >= 4)) || //2017.4 ((version[0] == 2017 && version[1] == 3 && version[2] == 1) && buildType.IsPatch) || //fixed after 2017.3.1px ((version[0] == 2017 && version[1] == 3) && m_MeshCompression == 0)) //2017.3.xfx with no compression { var m_IndexFormat = reader.ReadInt32(); } int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = new uint[m_IndexBuffer_size / 4]; for (int i = 0; i < m_IndexBuffer_size / 4; i++) { m_IndexBuffer[i] = reader.ReadUInt32(); } reader.AlignStream(); } } if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.4.2 and earlier { m_VertexCount = reader.ReadInt32(); m_Vertices = reader.ReadSingleArray(m_VertexCount * 3); //Vector3 m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } m_BindPose = reader.ReadMatrixArray(); m_UV0 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 m_UV1 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_TangentSpace_size = reader.ReadInt32(); m_Normals = new float[m_TangentSpace_size * 3]; for (int v = 0; v < m_TangentSpace_size; v++) { m_Normals[v * 3] = reader.ReadSingle(); m_Normals[v * 3 + 1] = reader.ReadSingle(); m_Normals[v * 3 + 2] = reader.ReadSingle(); reader.Position += 16; //Vector3f tangent & float handedness } } else //2.6.0 and later { m_Tangents = reader.ReadSingleArray(reader.ReadInt32() * 4); //Vector4 m_Normals = reader.ReadSingleArray(reader.ReadInt32() * 3); //Vector3 } } else { if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } } if (version[0] == 3 || (version[0] == 4 && version[1] <= 2)) //4.2 and down { m_BindPose = reader.ReadMatrixArray(); } m_VertexData = new VertexData(reader); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { m_CompressedMesh = new CompressedMesh(reader); } reader.Position += 24; //AABB m_LocalAABB if (version[0] < 3 || (version[0] == 3 && version[1] <= 4)) //3.4.2 and earlier { int m_Colors_size = reader.ReadInt32(); m_Colors = new float[m_Colors_size * 4]; for (int v = 0; v < m_Colors_size * 4; v++) { m_Colors[v] = (float)reader.ReadByte() / 0xFF; } int m_CollisionTriangles_size = reader.ReadInt32(); reader.Position += m_CollisionTriangles_size * 4; //UInt32 indices int m_CollisionVertexCount = reader.ReadInt32(); } int m_MeshUsageFlags = reader.ReadInt32(); if (version[0] >= 5) //5.0 and up { var m_BakedConvexCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); var m_BakedTriangleCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_MeshMetrics = new float[2]; m_MeshMetrics[0] = reader.ReadSingle(); m_MeshMetrics[1] = reader.ReadSingle(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 3)) //2018.3 and up { reader.AlignStream(); m_StreamData = new StreamingInfo(reader); } ProcessData(); }