private void ReadFileRecursive(byte[] data) { if (GZ.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { GZ gz = new GZ(memstream); ReadFileRecursive(gz.ContentBuffer); } } if (AFS.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { AFS afs = new AFS(memstream); foreach (var entry in afs.Entries) { ReadFileRecursive(entry.Buffer); } } } if (PKF.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { PKF pkf = new PKF(memstream); foreach (var entry in pkf.Entries) { ReadFileRecursive(entry.Buffer); } } } if (PKS.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { PKS pks = new PKS(memstream); foreach (var entry in pks.IPAC.Entries) { ReadFileRecursive(entry.Buffer); } } } if (TEXN.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { TEXN tex = new TEXN(memstream); TexEntry entry = new TexEntry(); entry.texID = tex.TextureID; entry.image = tex.Texture; textures.Add(entry); } } if (MT5.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { MT5 mt5 = new MT5(memstream); foreach (var tex in mt5.Textures) { if (tex.Image != null) { TexEntry entry = new TexEntry(); entry.texID = tex.TextureID; entry.image = tex.Image; textures.Add(entry); } } } } if (MT7.IsValid(data)) { using (MemoryStream memstream = new MemoryStream(data)) { MT7 mt7 = new MT7(memstream); foreach (var tex in mt7.Textures) { if (tex.Image != null) { TexEntry entry = new TexEntry(); entry.texID = tex.TextureID; entry.image = tex.Image; textures.Add(entry); } } } } }
/// <summary> /// Trys to find the fitting file type for the given file with the file signature. /// </summary> public static Type GetFileTypeFromSignature(Stream stream) { byte[] buffer = new byte[8]; stream.Read(buffer, 0, buffer.Length); //Archives if (AFS.IsValid(buffer)) { return(typeof(AFS)); } if (GZ.IsValid(buffer)) { return(typeof(GZ)); } if (IDX.IsValid(buffer)) { return(typeof(IDX)); } if (IPAC.IsValid(buffer)) { return(typeof(IPAC)); } if (PKF.IsValid(buffer)) { return(typeof(PKF)); } if (PKS.IsValid(buffer)) { return(typeof(PKS)); } //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension if (TAD.IsValid(buffer)) { return(typeof(TAD)); } //Textures/Images if (TEXN.IsValid(buffer)) { return(typeof(TEXN)); } if (PVRT.IsValid(buffer)) { return(typeof(PVRT)); } if (DDS.IsValid(buffer)) { return(typeof(DDS)); } //Models if (MT5.IsValid(buffer)) { return(typeof(MT5)); } if (MT7.IsValid(buffer)) { return(typeof(MT7)); } //Subtitles if (SUB.IsValid(buffer)) { return(typeof(SUB)); } return(null); }
public static string GetExtensionFromBuffer(byte[] buffer) { //Archives if (AFS.IsValid(buffer)) { return("AFS"); } if (GZ.IsValid(buffer)) { return("GZ"); } if (IDX.IsValid(buffer)) { return("IDX"); } if (IPAC.IsValid(buffer)) { return("IPAC"); } if (PKF.IsValid(buffer)) { return("PKF"); } if (PKS.IsValid(buffer)) { return("PKS"); } //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension if (TAD.IsValid(buffer)) { return("TAD"); } //Textures/Images if (TEXN.IsValid(buffer)) { return("TEXN"); } if (PVRT.IsValid(buffer)) { return("PVRT"); } if (DDS.IsValid(buffer)) { return("DDS"); } //Models if (MT5.IsValid(buffer)) { return("MT5"); } if (MT7.IsValid(buffer)) { return("MT7"); } //Subtitles if (SUB.IsValid(buffer)) { return("SUB"); } return("UNKNOWN"); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Supported files|*.mt5;*.mt7;*.mapm;*.chrm;*.prop;*.fbx;*.obj"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string extension = Path.GetExtension(openFileDialog.FileName); byte[] buffer = new byte[4]; using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open)) { stream.Read(buffer, 0, 4); stream.Seek(0, SeekOrigin.Begin); } if (MT5.IsValid(buffer)) { m_model = new MT5(openFileDialog.FileName); m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip; view3D.SetTextures(m_model.Textures); view3D.SetModel(m_model, m_primitiveType); m_modelType = ModelType.MT5; } else if (MT7.IsValid(buffer)) { m_model = new MT7(openFileDialog.FileName); m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles; view3D.SetTextures(m_model.Textures); view3D.SetModel(m_model, m_primitiveType); m_modelType = ModelType.MT7; } else if (FBXD3T.IsValid(buffer)) { m_model = new FBXD3T(openFileDialog.FileName); m_modelType = ModelType.FBXD3T; } else if (extension == ".obj") { m_model = new OBJ(openFileDialog.FileName); m_primitiveType = OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles; view3D.SetTextures(m_model.Textures); view3D.SetModel(m_model, m_primitiveType); } else { Console.WriteLine("Invalid file format!"); } treeView_MeshNodes.Nodes.Clear(); listBox_Textures.Items.Clear(); m_model.RootNode.GenerateTree(null); TreeNode treeNode = new TreeNode(openFileDialog.FileName); GenerateTree(treeNode, m_model.RootNode); treeView_MeshNodes.Nodes.Add(treeNode); foreach (Texture texture in m_model.Textures) { if (texture == null) { continue; } listBox_Textures.Items.Add(texture); } } if (m_modelType == ModelType.MT5) { mt5Control.Enabled = true; mt7Control.Enabled = false; } if (m_modelType == ModelType.MT7) { mt5Control.Enabled = false; mt7Control.Enabled = true; } }