public ConstantClip(ObjectReader reader) { data = reader.ReadSingleArray(); }
private static void DumpType(TypeSig typeSig, StringBuilder sb, ObjectReader reader, string name, int indent, bool isRoot = false) { var typeDef = typeSig.ToTypeDefOrRef().ResolveTypeDefThrow(); if (typeSig.IsPrimitive) { object value = null; switch (typeSig.TypeName) { case "Boolean": value = reader.ReadBoolean(); break; case "Byte": value = reader.ReadByte(); break; case "SByte": value = reader.ReadSByte(); break; case "Int16": value = reader.ReadInt16(); break; case "UInt16": value = reader.ReadUInt16(); break; case "Int32": value = reader.ReadInt32(); break; case "UInt32": value = reader.ReadUInt32(); break; case "Int64": value = reader.ReadInt64(); break; case "UInt64": value = reader.ReadUInt64(); break; case "Single": value = reader.ReadSingle(); break; case "Double": value = reader.ReadDouble(); break; case "Char": value = reader.ReadChar(); break; } reader.AlignStream(4); sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {value}"); return; } if (typeSig.FullName == "System.String") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = \"{reader.ReadAlignedString()}\""); return; } if (typeSig.FullName == "System.Object") { return; } if (typeDef.IsDelegate) { return; } if (typeSig is ArraySigBase) { if (!typeDef.IsEnum && !IsBaseType(typeDef) && !IsAssignFromUnityObject(typeDef) && !IsEngineType(typeDef) && !typeDef.IsSerializable) { return; } var size = reader.ReadInt32(); sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}"); for (int i = 0; i < size; i++) { sb.AppendLine($"{new string('\t', indent + 2)}[{i}]"); DumpType(typeDef.ToTypeSig(), sb, reader, "data", indent + 2); } return; } if (!isRoot && typeSig is GenericInstSig genericInstSig) { if (genericInstSig.GenericArguments.Count == 1) { var type = genericInstSig.GenericArguments[0].ToTypeDefOrRef().ResolveTypeDefThrow(); if (!type.IsEnum && !IsBaseType(type) && !IsAssignFromUnityObject(type) && !IsEngineType(type) && !type.IsSerializable) { return; } var size = reader.ReadInt32(); sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}"); for (int i = 0; i < size; i++) { sb.AppendLine($"{new string('\t', indent + 2)}[{i}]"); DumpType(genericInstSig.GenericArguments[0], sb, reader, "data", indent + 2); } } return; } if (indent != -1 && IsAssignFromUnityObject(typeDef)) { var pptr = new PPtr <Object>(reader); sb.AppendLine($"{new string('\t', indent)}PPtr<{typeDef.Name}> {name} = {{fileID: {pptr.m_FileID}, pathID: {pptr.m_PathID}}}"); return; } if (typeDef.IsEnum) { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {reader.ReadUInt32()}"); return; } if (indent != -1 && !IsEngineType(typeDef) && !typeDef.IsSerializable) { return; } if (typeDef.FullName == "UnityEngine.Rect") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var rect = reader.ReadSingleArray(4); return; } if (typeDef.FullName == "UnityEngine.LayerMask") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var value = reader.ReadInt32(); return; } if (typeDef.FullName == "UnityEngine.AnimationCurve") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var animationCurve = new AnimationCurve <float>(reader, reader.ReadSingle); return; } if (typeDef.FullName == "UnityEngine.Gradient") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); if (reader.version[0] == 5 && reader.version[1] < 5) { reader.Position += 68; } else if (reader.version[0] == 5 && reader.version[1] < 6) { reader.Position += 72; } else { reader.Position += 168; } return; } if (typeDef.FullName == "UnityEngine.RectOffset") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var left = reader.ReadSingle(); var right = reader.ReadSingle(); var top = reader.ReadSingle(); var bottom = reader.ReadSingle(); return; } if (typeDef.FullName == "UnityEngine.GUIStyle") //TODO { throw new NotSupportedException(); } if (typeDef.IsClass || typeDef.IsValueType) { if (name != null && indent != -1) { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); } if (indent == -1 && typeDef.BaseType.FullName != "UnityEngine.Object") { DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true); } if (indent != -1 && typeDef.BaseType.FullName != "System.Object") { DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true); } foreach (var fieldDef in typeDef.Fields) { var access = fieldDef.Access & FieldAttributes.FieldAccessMask; if (access != FieldAttributes.Public) { if (fieldDef.CustomAttributes.Any(x => x.TypeFullName.Contains("SerializeField"))) { DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1); } } else if ((fieldDef.Attributes & FieldAttributes.Static) == 0 && (fieldDef.Attributes & FieldAttributes.InitOnly) == 0 && (fieldDef.Attributes & FieldAttributes.NotSerialized) == 0) { DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1); } } } }
private void ReadAssets() { Logger.Info("Read assets..."); var progressCount = assetsFileList.Sum(x => x.m_Objects.Count); int i = 0; Progress.Reset(); foreach (var assetsFile in assetsFileList) { foreach (var objectInfo in assetsFile.m_Objects) { var objectReader = new ObjectReader(assetsFile.reader, assetsFile, objectInfo); try { Object obj; switch (objectReader.type) { case ClassIDType.Animation: obj = new Animation(objectReader); break; case ClassIDType.AnimationClip: obj = new AnimationClip(objectReader); break; case ClassIDType.Animator: obj = new Animator(objectReader); break; case ClassIDType.AnimatorController: obj = new AnimatorController(objectReader); break; case ClassIDType.AnimatorOverrideController: obj = new AnimatorOverrideController(objectReader); break; case ClassIDType.AssetBundle: obj = new AssetBundle(objectReader); break; case ClassIDType.AudioClip: obj = new AudioClip(objectReader); break; case ClassIDType.Avatar: obj = new Avatar(objectReader); break; case ClassIDType.Font: obj = new Font(objectReader); break; case ClassIDType.GameObject: obj = new GameObject(objectReader); break; case ClassIDType.Material: obj = new Material(objectReader); break; case ClassIDType.Mesh: obj = new Mesh(objectReader); break; case ClassIDType.MeshFilter: obj = new MeshFilter(objectReader); break; case ClassIDType.MeshRenderer: obj = new MeshRenderer(objectReader); break; case ClassIDType.MonoBehaviour: obj = new MonoBehaviour(objectReader); break; case ClassIDType.MonoScript: obj = new MonoScript(objectReader); break; case ClassIDType.MovieTexture: obj = new MovieTexture(objectReader); break; case ClassIDType.PlayerSettings: obj = new PlayerSettings(objectReader); break; case ClassIDType.RectTransform: obj = new RectTransform(objectReader); break; case ClassIDType.Shader: obj = new Shader(objectReader); break; case ClassIDType.SkinnedMeshRenderer: obj = new SkinnedMeshRenderer(objectReader); break; case ClassIDType.Sprite: obj = new Sprite(objectReader); break; case ClassIDType.SpriteAtlas: obj = new SpriteAtlas(objectReader); break; case ClassIDType.TextAsset: obj = new TextAsset(objectReader); break; case ClassIDType.Texture2D: obj = new Texture2D(objectReader); break; case ClassIDType.Transform: obj = new Transform(objectReader); break; case ClassIDType.VideoClip: obj = new VideoClip(objectReader); break; case ClassIDType.ResourceManager: obj = new ResourceManager(objectReader); break; default: obj = new Object(objectReader); break; } assetsFile.AddObject(obj); } catch (Exception e) { var sb = new StringBuilder(); sb.AppendLine("Unable to load object") .AppendLine($"Assets {assetsFile.fileName}") .AppendLine($"Type {objectReader.type}") .AppendLine($"PathID {objectInfo.m_PathID}") .Append(e); Logger.Error(sb.ToString()); } Progress.Report(++i, progressCount); } } }
public BoneWeights4(ObjectReader reader) { weight = reader.ReadSingleArray(4); boneIndex = reader.ReadInt32Array(4); }
public SerializedSubProgram(ObjectReader reader) { var version = reader.version; m_BlobIndex = reader.ReadUInt32(); m_Channels = new ParserBindChannels(reader); m_KeywordIndices = reader.ReadUInt16Array(); if (version[0] >= 2017) //2017 and up { reader.AlignStream(); } m_ShaderHardwareTier = reader.ReadSByte(); m_GpuProgramType = (ShaderGpuProgramType)reader.ReadSByte(); reader.AlignStream(); int numVectorParams = reader.ReadInt32(); m_VectorParams = new VectorParameter[numVectorParams]; for (int i = 0; i < numVectorParams; i++) { m_VectorParams[i] = new VectorParameter(reader); } int numMatrixParams = reader.ReadInt32(); m_MatrixParams = new MatrixParameter[numMatrixParams]; for (int i = 0; i < numMatrixParams; i++) { m_MatrixParams[i] = new MatrixParameter(reader); } int numTextureParams = reader.ReadInt32(); m_TextureParams = new TextureParameter[numTextureParams]; for (int i = 0; i < numTextureParams; i++) { m_TextureParams[i] = new TextureParameter(reader); } int numBufferParams = reader.ReadInt32(); m_BufferParams = new BufferBinding[numBufferParams]; for (int i = 0; i < numBufferParams; i++) { m_BufferParams[i] = new BufferBinding(reader); } int numConstantBuffers = reader.ReadInt32(); m_ConstantBuffers = new ConstantBuffer[numConstantBuffers]; for (int i = 0; i < numConstantBuffers; i++) { m_ConstantBuffers[i] = new ConstantBuffer(reader); } int numConstantBufferBindings = reader.ReadInt32(); m_ConstantBufferBindings = new BufferBinding[numConstantBufferBindings]; for (int i = 0; i < numConstantBufferBindings; i++) { m_ConstantBufferBindings[i] = new BufferBinding(reader); } int numUAVParams = reader.ReadInt32(); m_UAVParams = new UAVParameter[numUAVParams]; for (int i = 0; i < numUAVParams; i++) { m_UAVParams[i] = new UAVParameter(reader); } if (version[0] >= 2017) //2017 and up { int numSamplers = reader.ReadInt32(); m_Samplers = new SamplerParameter[numSamplers]; for (int i = 0; i < numSamplers; i++) { m_Samplers[i] = new SamplerParameter(reader); } } if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up { var m_ShaderRequirements = reader.ReadInt32(); } }
public SpriteRenderData(ObjectReader reader) { var version = reader.version; texture = new PPtr <Texture2D>(reader); if (version[0] > 5 || (version[0] == 5 && version[1] >= 2)) //5.2 and up { alphaTexture = new PPtr <Texture2D>(reader); } if (version[0] >= 2019) //2019 and up { var secondaryTexturesSize = reader.ReadInt32(); secondaryTextures = new SecondarySpriteTexture[secondaryTexturesSize]; for (int i = 0; i < secondaryTexturesSize; i++) { secondaryTextures[i] = new SecondarySpriteTexture(reader); } } if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { var m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (int i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } m_IndexBuffer = reader.ReadUInt8Array(); reader.AlignStream(); m_VertexData = new VertexData(reader); } else { var verticesSize = reader.ReadInt32(); vertices = new SpriteVertex[verticesSize]; for (int i = 0; i < verticesSize; i++) { vertices[i] = new SpriteVertex(reader); } indices = reader.ReadUInt16Array(); reader.AlignStream(); } if (version[0] >= 2018) //2018 and up { m_Bindpose = reader.ReadMatrixArray(); if (version[0] == 2018 && version[1] < 2) //2018.2 down { var m_SourceSkinSize = reader.ReadInt32(); for (int i = 0; i < m_SourceSkinSize; i++) { m_SourceSkin[i] = new BoneWeights4(reader); } } } textureRect = new Rectf(reader); textureRectOffset = reader.ReadVector2(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { atlasRectOffset = reader.ReadVector2(); } settingsRaw = new SpriteSettings(reader); if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up { uvTransform = reader.ReadVector4(); } if (version[0] >= 2017) //2017 and up { downscaleMultiplier = reader.ReadSingle(); } }
public static bool ExportMesh(ObjectReader reader, string exportPath) { var m_Mesh = new Mesh(reader); if (m_Mesh.m_VertexCount <= 0) { return(false); } var exportFullName = exportPath + reader.exportName + ".obj"; if (ExportFileExists(exportFullName)) { return(false); } var sb = new StringBuilder(); sb.AppendLine("g " + m_Mesh.m_Name); #region Vertices if (m_Mesh.m_Vertices == null || m_Mesh.m_Vertices.Length == 0) { return(false); } int c = 3; if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4) { c = 4; } for (int v = 0; v < m_Mesh.m_VertexCount; v++) { sb.AppendFormat("v {0} {1} {2}\r\n", -m_Mesh.m_Vertices[v * c], m_Mesh.m_Vertices[v * c + 1], m_Mesh.m_Vertices[v * c + 2]); } #endregion #region UV if (m_Mesh.m_UV1 != null && m_Mesh.m_UV1.Length == m_Mesh.m_VertexCount * 2) { for (int v = 0; v < m_Mesh.m_VertexCount; v++) { sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV1[v * 2], m_Mesh.m_UV1[v * 2 + 1]); } } else if (m_Mesh.m_UV2 != null && m_Mesh.m_UV2.Length == m_Mesh.m_VertexCount * 2) { for (int v = 0; v < m_Mesh.m_VertexCount; v++) { sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV2[v * 2], m_Mesh.m_UV2[v * 2 + 1]); } } #endregion #region Normals if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0) { if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3) { c = 3; } else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 4) { c = 4; } for (int v = 0; v < m_Mesh.m_VertexCount; v++) { sb.AppendFormat("vn {0} {1} {2}\r\n", -m_Mesh.m_Normals[v * c], m_Mesh.m_Normals[v * c + 1], m_Mesh.m_Normals[v * c + 2]); } } #endregion #region Face int sum = 0; for (var i = 0; i < m_Mesh.m_SubMeshes.Count; i++) { sb.AppendLine($"g {m_Mesh.m_Name}_{i}"); int indexCount = (int)m_Mesh.m_SubMeshes[i].indexCount; var end = sum + indexCount / 3; for (int f = sum; f < end; f++) { sb.AppendFormat("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\r\n", m_Mesh.m_Indices[f * 3 + 2] + 1, m_Mesh.m_Indices[f * 3 + 1] + 1, m_Mesh.m_Indices[f * 3] + 1); } sum = end; } #endregion sb.Replace("NaN", "0"); File.WriteAllText(exportFullName, sb.ToString()); return(true); }
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 = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } 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 = new float[m_VertexCount * 3]; for (int v = 0; v < m_VertexCount * 3; v++) { m_Vertices[v] = reader.ReadSingle(); } m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } m_BindPose = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } 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 = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } } 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(); }
private int index = -2; //-2 - Prepare, -1 - Missing public PPtr(ObjectReader reader) { m_FileID = reader.ReadInt32(); m_PathID = reader.m_Version < 14 ? reader.ReadInt32() : reader.ReadInt64(); assetsFile = reader.assetsFile; }
//public AnimationEvent[] m_Events; public AnimationClip(ObjectReader reader) : base(reader) { if (version[0] >= 5)//5.0 and up { m_Legacy = reader.ReadBoolean(); } else if (version[0] >= 4)//4.0 and up { m_AnimationType = (AnimationType)reader.ReadInt32(); if (m_AnimationType == AnimationType.kLegacy) { m_Legacy = true; } } else { m_Legacy = true; } m_Compressed = reader.ReadBoolean(); if (version[0] > 4 || (version[0] == 4 && version[1] >= 3))//4.3 and up { m_UseHighQualityCurve = reader.ReadBoolean(); } reader.AlignStream(); int numRCurves = reader.ReadInt32(); m_RotationCurves = new QuaternionCurve[numRCurves]; for (int i = 0; i < numRCurves; i++) { m_RotationCurves[i] = new QuaternionCurve(reader); } int numCRCurves = reader.ReadInt32(); m_CompressedRotationCurves = new CompressedAnimationCurve[numCRCurves]; for (int i = 0; i < numCRCurves; i++) { m_CompressedRotationCurves[i] = new CompressedAnimationCurve(reader); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 3))//5.3 and up { int numEulerCurves = reader.ReadInt32(); m_EulerCurves = new Vector3Curve[numEulerCurves]; for (int i = 0; i < numEulerCurves; i++) { m_EulerCurves[i] = new Vector3Curve(reader); } } int numPCurves = reader.ReadInt32(); m_PositionCurves = new Vector3Curve[numPCurves]; for (int i = 0; i < numPCurves; i++) { m_PositionCurves[i] = new Vector3Curve(reader); } int numSCurves = reader.ReadInt32(); m_ScaleCurves = new Vector3Curve[numSCurves]; for (int i = 0; i < numSCurves; i++) { m_ScaleCurves[i] = new Vector3Curve(reader); } int numFCurves = reader.ReadInt32(); m_FloatCurves = new FloatCurve[numFCurves]; for (int i = 0; i < numFCurves; i++) { m_FloatCurves[i] = new FloatCurve(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { int numPtrCurves = reader.ReadInt32(); m_PPtrCurves = new PPtrCurve[numPtrCurves]; for (int i = 0; i < numPtrCurves; i++) { m_PPtrCurves[i] = new PPtrCurve(reader); } } m_SampleRate = reader.ReadSingle(); m_WrapMode = reader.ReadInt32(); if (version[0] > 3 || (version[0] == 3 && version[1] >= 4)) //3.4 and up { m_Bounds = new AABB(reader); } if (version[0] >= 4)//4.0 and up { m_MuscleClipSize = reader.ReadUInt32(); m_MuscleClip = new ClipMuscleConstant(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { m_ClipBindingConstant = new AnimationClipBindingConstant(reader); } //m_HasGenericRootTransform 2018.3 //m_HasMotionFloatCurves 2018.3 /*int numEvents = reader.ReadInt32(); * m_Events = new AnimationEvent[numEvents]; * for (int i = 0; i < numEvents; i++) * { * m_Events[i] = new AnimationEvent(reader); * }*/ }
public PointF[][] m_PhysicsShape; //Vector2[][] public Sprite(ObjectReader reader) : base(reader) { //Rectf m_Rect m_Rect = reader.ReadRectangleF(); //Vector2f m_Offset reader.Position += 8; if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up { //Vector4f m_Border reader.Position += 16; } m_PixelsToUnits = reader.ReadSingle(); if (version[0] > 5 || (version[0] == 5 && version[1] > 4) || (version[0] == 5 && version[1] == 4 && version[2] >= 2)) //5.4.2 and up { //Vector2f m_Pivot m_Pivot = reader.ReadVector2(); } var m_Extrude = reader.ReadUInt32(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up { var m_IsPolygon = reader.ReadBoolean(); reader.AlignStream(4); } if (version[0] >= 2017) //2017 and up { //pair m_RenderDataKey var first = new Guid(reader.ReadBytes(16)); var second = reader.ReadInt64(); m_RenderDataKey = new Tuple <Guid, long>(first, second); //vector m_AtlasTags var size = reader.ReadInt32(); for (int i = 0; i < size; i++) { var data = reader.ReadAlignedString(); } //PPtr<SpriteAtlas> m_SpriteAtlas m_SpriteAtlas = reader.ReadPPtr(); } //SpriteRenderData m_RD // PPtr<Texture2D> texture texture = reader.ReadPPtr(); // PPtr<Texture2D> alphaTexture if (version[0] > 5 || (version[0] == 5 && version[1] >= 2)) //5.2 and up { var alphaTexture = reader.ReadPPtr(); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { // vector m_SubMeshes var size = reader.ReadInt32(); // SubMesh data if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up { reader.Position += 48 * size; } else { reader.Position += 44 * size; } // vector m_IndexBuffer size = reader.ReadInt32(); reader.Position += size; //UInt8 data reader.AlignStream(4); // VertexData m_VertexData if (version[0] < 2018)//2018 down { var m_CurrentChannels = reader.ReadInt32(); } var m_VertexCount = reader.ReadUInt32(); // vector m_Channels size = reader.ReadInt32(); reader.Position += size * 4; //ChannelInfo data // TypelessData m_DataSize size = reader.ReadInt32(); reader.Position += size; //UInt8 data reader.AlignStream(4); if (version[0] >= 2018)//2018 and up { // vector m_Bindpose // Matrix4x4f data size = reader.ReadInt32(); reader.Position += size * 64; if (version[0] == 2018 && version[1] < 2) //2018.2 down { // vector m_SourceSkin // BoneWeights4 data size = reader.ReadInt32(); reader.Position += size * 32; } } } else { // vector vertices var size = reader.ReadInt32(); for (int i = 0; i < size; i++) { //SpriteVertex data reader.Position += 12; //Vector3f pos if (version[0] < 4 || (version[0] == 4 && version[1] <= 3)) //4.3 and down { reader.Position += 8; //Vector2f uv } } // vector indices size = reader.ReadInt32(); reader.Position += 2 * size; //UInt16 data reader.AlignStream(4); } // Rectf textureRect textureRect = reader.ReadRectangleF(); // Vector2f textureRectOffset reader.Position += 8; // Vector2f atlasRectOffset - 5.6 and up if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { reader.Position += 8; } // unsigned int settingsRaw settingsRaw = new SpriteSettings(reader); // Vector4f uvTransform - 4.5 and up if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up { reader.Position += 16; } if (version[0] >= 2017) //2017 and up { // float downscaleMultiplier - 2017 and up reader.Position += 4; //vector m_PhysicsShape - 2017 and up var m_PhysicsShape_size = reader.ReadInt32(); m_PhysicsShape = new PointF[m_PhysicsShape_size][]; for (int i = 0; i < m_PhysicsShape_size; i++) { var data_size = reader.ReadInt32(); //Vector2f m_PhysicsShape[i] = new PointF[data_size]; for (int j = 0; j < data_size; j++) { m_PhysicsShape[i][j] = new PointF(reader.ReadSingle(), reader.ReadSingle()); } } } //vector m_Bones 2018 and up }
public ClipMuscleConstant(ObjectReader reader) { var version = reader.version; m_DeltaPose = new HumanPose(reader); m_StartX = new xform(reader); if (version[0] > 5 || (version[0] == 5 && version[1] >= 5))//5.5 and up { m_StopX = new xform(reader); } m_LeftFootStartX = new xform(reader); m_RightFootStartX = new xform(reader); if (version[0] < 5)//5.0 down { m_MotionStartX = new xform(reader); m_MotionStopX = new xform(reader); } m_AverageSpeed = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4();//5.4 and up m_Clip = new Clip(reader); m_StartTime = reader.ReadSingle(); m_StopTime = reader.ReadSingle(); m_OrientationOffsetY = reader.ReadSingle(); m_Level = reader.ReadSingle(); m_CycleOffset = reader.ReadSingle(); m_AverageAngularSpeed = reader.ReadSingle(); m_IndexArray = reader.ReadInt32Array(); if (version[0] < 4 || (version[0] == 4 && version[1] < 3)) //4.3 down { var m_AdditionalCurveIndexArray = reader.ReadInt32Array(); } int numDeltas = reader.ReadInt32(); m_ValueArrayDelta = new ValueDelta[numDeltas]; for (int i = 0; i < numDeltas; i++) { m_ValueArrayDelta[i] = new ValueDelta(reader); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 3))//5.3 and up { m_ValueArrayReferencePose = reader.ReadSingleArray(); } m_Mirror = reader.ReadBoolean(); if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { m_LoopTime = reader.ReadBoolean(); } m_LoopBlend = reader.ReadBoolean(); m_LoopBlendOrientation = reader.ReadBoolean(); m_LoopBlendPositionY = reader.ReadBoolean(); m_LoopBlendPositionXZ = reader.ReadBoolean(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 5))//5.5 and up { m_StartAtOrigin = reader.ReadBoolean(); } m_KeepOriginalOrientation = reader.ReadBoolean(); m_KeepOriginalPositionY = reader.ReadBoolean(); m_KeepOriginalPositionXZ = reader.ReadBoolean(); m_HeightFromFeet = reader.ReadBoolean(); reader.AlignStream(); }
public ValueDelta(ObjectReader reader) { m_Start = reader.ReadSingle(); m_Stop = reader.ReadSingle(); }
public QuaternionCurve(ObjectReader reader) { curve = new AnimationCurve <Quaternion>(reader, reader.ReadQuaternion); path = reader.ReadAlignedString(); }
public Human(ObjectReader reader) { var version = reader.version; m_RootX = new xform(reader); m_Skeleton = new Skeleton(reader); m_SkeletonPose = new SkeletonPose(reader); m_LeftHand = new Hand(reader); m_RightHand = new Hand(reader); if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { int numHandles = reader.ReadInt32(); m_Handles = new List <Handle>(numHandles); for (int i = 0; i < numHandles; i++) { m_Handles.Add(new Handle(reader)); } int numColliders = reader.ReadInt32(); m_ColliderArray = new List <Collider>(numColliders); for (int i = 0; i < numColliders; i++) { m_ColliderArray.Add(new Collider(reader)); } } int numIndexes = reader.ReadInt32(); m_HumanBoneIndex = new List <int>(numIndexes); for (int i = 0; i < numIndexes; i++) { m_HumanBoneIndex.Add(reader.ReadInt32()); } int numMasses = reader.ReadInt32(); m_HumanBoneMass = new List <float>(numMasses); for (int i = 0; i < numMasses; i++) { m_HumanBoneMass.Add(reader.ReadSingle()); } if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { int numColliderIndexes = reader.ReadInt32(); m_ColliderIndex = new List <int>(numColliderIndexes); for (int i = 0; i < numColliderIndexes; i++) { m_ColliderIndex.Add(reader.ReadInt32()); } } m_Scale = reader.ReadSingle(); m_ArmTwist = reader.ReadSingle(); m_ForeArmTwist = reader.ReadSingle(); m_UpperLegTwist = reader.ReadSingle(); m_LegTwist = reader.ReadSingle(); m_ArmStretch = reader.ReadSingle(); m_LegStretch = reader.ReadSingle(); m_FeetSpacing = reader.ReadSingle(); m_HasLeftHand = reader.ReadBoolean(); m_HasRightHand = reader.ReadBoolean(); m_HasTDoF = reader.ReadBoolean(); reader.AlignStream(4); }
private static void DumpType(TypeSig typeSig, StringBuilder sb, ObjectReader reader, string name, int indent, bool isRoot = false, bool align = true) { var typeDef = typeSig.ToTypeDefOrRef().ResolveTypeDefThrow(); if (typeSig.IsPrimitive) { object value = null; switch (typeSig.TypeName) { case "Boolean": value = reader.ReadBoolean(); break; case "Byte": value = reader.ReadByte(); break; case "SByte": value = reader.ReadSByte(); break; case "Int16": value = reader.ReadInt16(); break; case "UInt16": value = reader.ReadUInt16(); break; case "Int32": value = reader.ReadInt32(); break; case "UInt32": value = reader.ReadUInt32(); break; case "Int64": value = reader.ReadInt64(); break; case "UInt64": value = reader.ReadUInt64(); break; case "Single": value = reader.ReadSingle(); break; case "Double": value = reader.ReadDouble(); break; case "Char": value = reader.ReadChar(); break; } if (align) { reader.AlignStream(); } sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {value}"); return; } if (typeSig.FullName == "System.String") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = \"{reader.ReadAlignedString()}\""); return; } if (typeSig.FullName == "System.Object") { return; } if (typeDef.IsDelegate) { return; } if (typeSig is ArraySigBase) { if (!typeDef.IsEnum && !IsBaseType(typeDef) && !IsAssignFromUnityObject(typeDef) && !IsEngineType(typeDef) && !typeDef.IsSerializable) { return; } var size = reader.ReadInt32(); sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}"); for (int i = 0; i < size; i++) { sb.AppendLine($"{new string('\t', indent + 2)}[{i}]"); DumpType(typeDef.ToTypeSig(), sb, reader, "data", indent + 2); } return; } if (!isRoot && typeSig is GenericInstSig genericInstSig) { if (genericInstSig.GenericArguments.Count == 1) { var genericType = genericInstSig.GenericType.ToTypeDefOrRef().ResolveTypeDefThrow(); var type = genericInstSig.GenericArguments[0].ToTypeDefOrRef().ResolveTypeDefThrow(); if (genericInstSig.GenericArguments[0] is ArraySigBase) { return; } if (!type.IsEnum && !IsBaseType(type) && !IsAssignFromUnityObject(type) && !IsEngineType(type) && !type.IsSerializable) { return; } sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}"); if (genericType.Interfaces.Any(x => x.Interface.FullName == "System.Collections.Generic.ICollection`1<T>")) //System.Collections.Generic.IEnumerable`1<T> { var size = reader.ReadInt32(); sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}"); for (int i = 0; i < size; i++) { sb.AppendLine($"{new string('\t', indent + 2)}[{i}]"); DumpType(genericInstSig.GenericArguments[0], sb, reader, "data", indent + 2, false, false); } reader.AlignStream(); } else { DumpType(genericType.ToTypeSig(), sb, reader, "data", indent + 1); } } return; } if (indent != -1 && IsAssignFromUnityObject(typeDef)) { var pptr = new PPtr <Object>(reader); sb.AppendLine($"{new string('\t', indent)}PPtr<{typeDef.Name}> {name} = {{fileID: {pptr.m_FileID}, pathID: {pptr.m_PathID}}}"); return; } if (typeDef.IsEnum) { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {reader.ReadUInt32()}"); return; } if (!isRoot && !IsEngineType(typeDef) && !typeDef.IsSerializable) { return; } if (typeDef.FullName == "UnityEngine.AnimationCurve") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}<truncated>"); var animationCurve = new AnimationCurve <float>(reader, reader.ReadSingle); return; } if (typeDef.FullName == "UnityEngine.Bounds") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}<truncated>"); new AABB(reader); return; } if (typeDef.FullName == "UnityEngine.BoundsInt") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}<truncated>"); reader.Position += 24; return; } if (typeDef.FullName == "UnityEngine.Color32") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}byte r = {reader.ReadByte()}"); sb.AppendLine($"{prefix}byte g = {reader.ReadByte()}"); sb.AppendLine($"{prefix}byte b = {reader.ReadByte()}"); sb.AppendLine($"{prefix}byte a = {reader.ReadByte()}"); reader.AlignStream(); return; } if (typeDef.FullName == "UnityEngine.Gradient") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}<truncated>"); if (reader.version[0] == 5 && reader.version[1] < 5) { reader.Position += 68; } else if (reader.version[0] == 5 && reader.version[1] < 6) { reader.Position += 72; } else { reader.Position += 168; } return; } if (typeDef.FullName == "UnityEngine.GUIStyle") //TODO { throw new NotSupportedException(); } if (typeDef.FullName == "UnityEngine.LayerMask") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}uint m_Bits = {reader.ReadUInt32()}"); return; } if (typeDef.FullName == "UnityEngine.PropertyName") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); sb.AppendLine($"{new string('\t', indent + 1)}int id = {reader.ReadInt32()}"); return; } if (typeDef.FullName == "UnityEngine.Rect") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}float x = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float y = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float width = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float height = {reader.ReadSingle()}"); return; } if (typeDef.FullName == "UnityEngine.RectInt") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}int x = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int y = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int width = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int height = {reader.ReadInt32()}"); return; } if (typeDef.FullName == "UnityEngine.RectOffset") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}float left = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float right = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float top = {reader.ReadSingle()}"); sb.AppendLine($"{prefix}float bottom = {reader.ReadSingle()}"); return; } if (typeDef.FullName == "UnityEngine.Vector2Int") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}int x = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int y = {reader.ReadInt32()}"); return; } if (typeDef.FullName == "UnityEngine.Vector3Int") { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); var prefix = new string('\t', indent + 1); sb.AppendLine($"{prefix}int x = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int y = {reader.ReadInt32()}"); sb.AppendLine($"{prefix}int z = {reader.ReadInt32()}"); return; } if (typeDef.IsClass || typeDef.IsValueType) { if (name != null && indent != -1) { sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}"); } if (indent == -1 && typeDef.BaseType.FullName != "UnityEngine.Object") { DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true); } if (indent != -1 && typeDef.BaseType.FullName != "System.Object") { DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true); } foreach (var fieldDef in typeDef.Fields) { var flag = false; var access = fieldDef.Access & FieldAttributes.FieldAccessMask; if (access != FieldAttributes.Public) { if (fieldDef.CustomAttributes.Any(x => x.TypeFullName == "UnityEngine.SerializeField")) { flag = true; } } else if ((fieldDef.Attributes & FieldAttributes.Static) == 0 && (fieldDef.Attributes & FieldAttributes.InitOnly) == 0 && (fieldDef.Attributes & FieldAttributes.NotSerialized) == 0) { flag = true; } if (flag) { if (fieldDef.FieldType.IsGenericParameter) { for (var i = 0; i < typeDef.GenericParameters.Count; i++) { var g = typeDef.GenericParameters[i]; if (g.FullName == fieldDef.FieldType.FullName) { var type = ((GenericInstSig)typeSig).GenericArguments[i]; DumpType(type, sb, reader, fieldDef.Name, indent + 1); break; } } } else if (fieldDef.FieldType is GenericInstSig genericSig && genericSig.GenericArguments.Count == 1 && genericSig.GenericArguments[0].IsGenericParameter) { for (var i = 0; i < typeDef.GenericParameters.Count; i++) { var g = typeDef.GenericParameters[i]; if (g.FullName == genericSig.GenericArguments[0].FullName) { var type = ((GenericInstSig)typeSig).GenericArguments[i]; var fieldTypeDef = fieldDef.FieldType.ToTypeDefOrRef().ResolveTypeDefThrow(); if (fieldTypeDef.Interfaces.Any(x => x.Interface.FullName == "System.Collections.Generic.ICollection`1<T>")) //System.Collections.Generic.IEnumerable`1<T> { var size = reader.ReadInt32(); sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}"); for (int j = 0; j < size; j++) { sb.AppendLine($"{new string('\t', indent + 2)}[{i}]"); DumpType(type, sb, reader, "data", indent + 2, false, false); } } else { DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1); } } } } else { DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1); } } } }
public SecondarySpriteTexture(ObjectReader reader) { texture = new PPtr <Texture2D>(reader); name = reader.ReadStringToNull(); }
public UnityTexEnv(ObjectReader reader) { m_Texture = new PPtr <Texture>(reader); m_Scale = reader.ReadVector2(); m_Offset = reader.ReadVector2(); }
private void ReadAssets() { Logger.Info("Read assets..."); var progressCount = assetsFileList.Sum(x => x.m_Objects.Count); int i = 0; Progress.Reset(); foreach (var assetsFile in assetsFileList) { assetsFile.Objects = new Dictionary <long, Object>(assetsFile.m_Objects.Count); foreach (var objectInfo in assetsFile.m_Objects) { var objectReader = new ObjectReader(assetsFile.reader, assetsFile, objectInfo); switch (objectReader.type) { case ClassIDType.Animation: assetsFile.Objects.Add(objectInfo.m_PathID, new Animation(objectReader)); break; case ClassIDType.AnimationClip: assetsFile.Objects.Add(objectInfo.m_PathID, new AnimationClip(objectReader)); break; case ClassIDType.Animator: assetsFile.Objects.Add(objectInfo.m_PathID, new Animator(objectReader)); break; case ClassIDType.AnimatorController: assetsFile.Objects.Add(objectInfo.m_PathID, new AnimatorController(objectReader)); break; case ClassIDType.AnimatorOverrideController: assetsFile.Objects.Add(objectInfo.m_PathID, new AnimatorOverrideController(objectReader)); break; case ClassIDType.AssetBundle: assetsFile.Objects.Add(objectInfo.m_PathID, new AssetBundle(objectReader)); break; case ClassIDType.AudioClip: assetsFile.Objects.Add(objectInfo.m_PathID, new AudioClip(objectReader)); break; case ClassIDType.Avatar: assetsFile.Objects.Add(objectInfo.m_PathID, new Avatar(objectReader)); break; case ClassIDType.Font: assetsFile.Objects.Add(objectInfo.m_PathID, new Font(objectReader)); break; case ClassIDType.GameObject: assetsFile.Objects.Add(objectInfo.m_PathID, new GameObject(objectReader)); break; case ClassIDType.Material: assetsFile.Objects.Add(objectInfo.m_PathID, new Material(objectReader)); break; case ClassIDType.Mesh: assetsFile.Objects.Add(objectInfo.m_PathID, new Mesh(objectReader)); break; case ClassIDType.MeshFilter: assetsFile.Objects.Add(objectInfo.m_PathID, new MeshFilter(objectReader)); break; case ClassIDType.MeshRenderer: assetsFile.Objects.Add(objectInfo.m_PathID, new MeshRenderer(objectReader)); break; case ClassIDType.MonoBehaviour: assetsFile.Objects.Add(objectInfo.m_PathID, new MonoBehaviour(objectReader)); break; case ClassIDType.MonoScript: assetsFile.Objects.Add(objectInfo.m_PathID, new MonoScript(objectReader)); break; case ClassIDType.MovieTexture: assetsFile.Objects.Add(objectInfo.m_PathID, new MovieTexture(objectReader)); break; case ClassIDType.PlayerSettings: assetsFile.Objects.Add(objectInfo.m_PathID, new PlayerSettings(objectReader)); break; case ClassIDType.RectTransform: assetsFile.Objects.Add(objectInfo.m_PathID, new RectTransform(objectReader)); break; case ClassIDType.Shader: assetsFile.Objects.Add(objectInfo.m_PathID, new Shader(objectReader)); break; case ClassIDType.SkinnedMeshRenderer: assetsFile.Objects.Add(objectInfo.m_PathID, new SkinnedMeshRenderer(objectReader)); break; case ClassIDType.Sprite: assetsFile.Objects.Add(objectInfo.m_PathID, new Sprite(objectReader)); break; case ClassIDType.SpriteAtlas: assetsFile.Objects.Add(objectInfo.m_PathID, new SpriteAtlas(objectReader)); break; case ClassIDType.TextAsset: assetsFile.Objects.Add(objectInfo.m_PathID, new TextAsset(objectReader)); break; case ClassIDType.Texture2D: assetsFile.Objects.Add(objectInfo.m_PathID, new Texture2D(objectReader)); break; case ClassIDType.Transform: assetsFile.Objects.Add(objectInfo.m_PathID, new Transform(objectReader)); break; case ClassIDType.VideoClip: assetsFile.Objects.Add(objectInfo.m_PathID, new VideoClip(objectReader)); break; default: assetsFile.Objects.Add(objectInfo.m_PathID, new Object(objectReader)); break; } Progress.Report(++i, progressCount); } } }
public static void ReadTypeString(StringBuilder sb, List <TypeTreeNode> members, ObjectReader reader) { reader.Reset(); for (int i = 0; i < members.Count; i++) { ReadStringValue(sb, members, reader, ref i); } var readed = reader.Position - reader.byteStart; if (readed != reader.byteSize) { Logger.Error($"Error while read type, read {readed} bytes but expected {reader.byteSize} bytes"); } }
public NamedObject(ObjectReader reader) : base(reader) { m_Name = reader.ReadAlignedString(); }
public StaticBatchInfo(ObjectReader reader) { firstSubMesh = reader.ReadUInt16(); subMeshCount = reader.ReadUInt16(); }
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 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 = 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(); }
protected Renderer(ObjectReader reader) : base(reader) { if (version[0] < 5) //5.0 down { var m_Enabled = reader.ReadBoolean(); var m_CastShadows = reader.ReadBoolean(); var m_ReceiveShadows = reader.ReadBoolean(); var m_LightmapIndex = reader.ReadByte(); } else //5.0 and up { if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) //5.4 and up { var m_Enabled = reader.ReadBoolean(); var m_CastShadows = reader.ReadByte(); var m_ReceiveShadows = reader.ReadByte(); if (version[0] > 2017 || (version[0] == 2017 && version[0] >= 2)) //2017.2 and up { var m_DynamicOccludee = reader.ReadByte(); } var m_MotionVectors = reader.ReadByte(); var m_LightProbeUsage = reader.ReadByte(); var m_ReflectionProbeUsage = reader.ReadByte(); reader.AlignStream(); } else { var m_Enabled = reader.ReadBoolean(); reader.AlignStream(); var m_CastShadows = reader.ReadByte(); var m_ReceiveShadows = reader.ReadBoolean(); reader.AlignStream(); } if (version[0] >= 2018) //2018 and up { var m_RenderingLayerMask = reader.ReadUInt32(); } var m_LightmapIndex = reader.ReadUInt16(); var m_LightmapIndexDynamic = reader.ReadUInt16(); } if (version[0] >= 3) //3.0 and up { var m_LightmapTilingOffset = reader.ReadVector4(); } if (version[0] >= 5) //5.0 and up { var m_LightmapTilingOffsetDynamic = reader.ReadVector4(); } var m_MaterialsSize = reader.ReadInt32(); m_Materials = new PPtr <Material> [m_MaterialsSize]; for (int i = 0; i < m_MaterialsSize; i++) { m_Materials[i] = new PPtr <Material>(reader); } if (version[0] < 3) //3.0 down { var m_LightmapTilingOffset = reader.ReadVector4(); } else //3.0 and up { if (version[0] > 5 || (version[0] == 5 && version[1] >= 5)) //5.5 and up { m_StaticBatchInfo = new StaticBatchInfo(reader); } else { m_SubsetIndices = reader.ReadUInt32Array(); } var m_StaticBatchRoot = new PPtr <Transform>(reader); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) //5.4 and up { var m_ProbeAnchor = new PPtr <Transform>(reader); var m_LightProbeVolumeOverride = new PPtr <GameObject>(reader); } else if (version[0] > 3 || (version[0] == 3 && version[1] >= 5)) //3.5 - 5.3 { var m_UseLightProbes = reader.ReadBoolean(); reader.AlignStream(); if (version[0] >= 5)//5.0 and up { var m_ReflectionProbeUsage = reader.ReadInt32(); } var m_LightProbeAnchor = new PPtr <Transform>(reader); //5.0 and up m_ProbeAnchor } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { if (version[0] == 4 && version[1] == 3) //4.3 { var m_SortingLayer = reader.ReadInt16(); } else { var m_SortingLayerID = reader.ReadUInt32(); } //SInt16 m_SortingLayer 5.6 and up var m_SortingOrder = reader.ReadInt16(); reader.AlignStream(); } }
private static Bitmap CutImage(ObjectReader texture2DAsset, RectangleF textureRect, Sprite m_Sprite, SpriteSettings settingsRaw) { var texture2D = new Texture2DConverter(new Texture2D(texture2DAsset, true)); var originalImage = texture2D.ConvertToBitmap(false); if (originalImage != null) { using (originalImage) { textureRect.Width = textureRect.Width > originalImage.Width ? originalImage.Width : textureRect.Width; textureRect.Height = textureRect.Height > originalImage.Height ? originalImage.Height : textureRect.Height; var spriteImage = originalImage.Clone(textureRect, PixelFormat.Format32bppArgb); //RotateAndFlip switch (settingsRaw.packingRotation) { case SpritePackingRotation.kSPRFlipHorizontal: spriteImage.RotateFlip(RotateFlipType.RotateNoneFlipX); break; case SpritePackingRotation.kSPRFlipVertical: spriteImage.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case SpritePackingRotation.kSPRRotate180: spriteImage.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case SpritePackingRotation.kSPRRotate90: spriteImage.RotateFlip(RotateFlipType.Rotate270FlipNone); break; } /* TODO Tight * 2017之前没有PhysicsShape * 5.6之前使用vertices * 5.6需要使用VertexData */ if (settingsRaw.packingMode == SpritePackingMode.kSPMTight && m_Sprite.m_PhysicsShape?.Length > 0) //Tight { try { using (var brush = new TextureBrush(spriteImage)) { using (var path = new GraphicsPath()) { foreach (var p in m_Sprite.m_PhysicsShape) { path.AddPolygon(p); } using (var matr = new Matrix()) { matr.Translate(m_Sprite.m_Rect.Width * m_Sprite.m_Pivot.X, m_Sprite.m_Rect.Height * m_Sprite.m_Pivot.Y); matr.Scale(m_Sprite.m_PixelsToUnits, m_Sprite.m_PixelsToUnits); path.Transform(matr); var bitmap = new Bitmap((int)textureRect.Width, (int)textureRect.Height); using (var graphic = Graphics.FromImage(bitmap)) { graphic.FillPath(brush, path); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); return(bitmap); } } } } } catch { spriteImage = originalImage.Clone(textureRect, PixelFormat.Format32bppArgb); spriteImage.RotateFlip(RotateFlipType.RotateNoneFlipY); return(spriteImage); } } //Rectangle spriteImage.RotateFlip(RotateFlipType.RotateNoneFlipY); return(spriteImage); } } return(null); }
public Node(ObjectReader reader) { m_ParentId = reader.ReadInt32(); m_AxesId = reader.ReadInt32(); }
protected Behaviour(ObjectReader reader) : base(reader) { m_Enabled = reader.ReadByte(); reader.AlignStream(4); }
public Handle(ObjectReader reader) { m_X = new xform(reader); m_ParentHumanIndex = reader.ReadUInt32(); m_ID = reader.ReadUInt32(); }
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(); } 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 StreamedClip(ObjectReader reader) { data = reader.ReadUInt32Array(); curveCount = reader.ReadUInt32(); }