public bool Init(MainForm.UpdateStatusDelegate UpdateDelegate = null) { int objID = 0; foreach (var tmpTexture in Textures) { if (UpdateDelegate != null) { float percent = (100.0f / Textures.Count) * objID; UpdateDelegate((int)percent, "Initializing Textures..."); } tmpTexture.Init(); objID++; } objID = 0; foreach (var tmpRenderGraph in RenderGraphs) { if (UpdateDelegate != null) { float percent = (100.0f / RenderGraphs.Count) * objID; UpdateDelegate((int)percent, "Initializing Rendergraphs..."); } tmpRenderGraph.Init(); } return(true); }
public static TreeNode LoadCaffFile(string fileName, MainForm.UpdateStatusDelegate UpdateDelegate = null) { control.MakeCurrent(); //var tmpCaff = new CaffFile(); var tmpCaff = new KameoCaff(); if (tmpCaff.Read(fileName, UpdateDelegate)) { if (tmpCaff.Init(UpdateDelegate)) { return(tmpCaff.TreeViewNode); } } return(null); }
public bool Read(string _fileName, MainForm.UpdateStatusDelegate UpdateDelegate = null) { FileName = _fileName; TreeViewNode = new TreeNode(Path.GetFileName(FileName)); TreeViewNode.Tag = new TreeNodeTag(this, 0, 0, 0, TreeNodeTag.NodeType.File); FileStream fs = new FileStream(_fileName, FileMode.Open); bStream = new BinaryReader(fs); Header.HeaderString = IO.ReadStringF(bStream, 0x14); if (Header.HeaderString != "CAFF28.01.05.0031") { Logger.LogError("Error reading Caff File, Header section mismatch.\n"); return(false); } Header.Unk1 = IO.ReadBig32(bStream); //0x14 Header.FileCount = IO.ReadBig32(bStream); //0x18 Header.TocEntryCount = IO.ReadBig32(bStream); //0x1c Header.Unk4 = IO.ReadBig32(bStream); //0x20 Header.Unk5 = IO.ReadBig32(bStream); Header.Unk6 = IO.ReadBig32(bStream); Header.Unk7 = IO.ReadBig32(bStream); Header.Unk8 = IO.ReadBig32(bStream); //0x30 Header.TocOffset = IO.ReadBig32(bStream); Header.SectionStartOffset = IO.ReadBig32(bStream); Header.Unk11 = IO.ReadByte(bStream); Header.SectionCount = IO.ReadByte(bStream); Header.Unk13 = IO.ReadByte(bStream); Header.Unk14 = IO.ReadByte(bStream); Sections = new CaffSection[Header.SectionCount]; int sectionOffset = Header.SectionStartOffset; for (int i = 0; i < Header.SectionCount; i++) { CaffSection tmpSection = new CaffSection(); tmpSection.Name = IO.ReadString(bStream); IO.Align(bStream, 4); int tmpSectionType = IO.ReadBig32(bStream); switch (tmpSectionType) { case SECTION_TYPE_DATA: { tmpSection.Type = SectionType.Data; break; } case SECTION_TYPE_GPU: { tmpSection.Type = SectionType.GPU; break; } case SECTION_TYPE_STREAM: { tmpSection.Type = SectionType.Stream; break; } default: { Logger.LogError(string.Format("Error reading Caff File, Unknown caff section type {0:X} at 0x{1:X}", tmpSectionType, (int)bStream.BaseStream.Position)); return(false); } } tmpSection.Flags = IO.ReadBig32(bStream); tmpSection.DecompressedSize = IO.ReadBig32(bStream); tmpSection.Unk5 = IO.ReadBig32(bStream); tmpSection.Unk6 = IO.ReadBig32(bStream); tmpSection.Unk7 = IO.ReadBig32(bStream); tmpSection.Unk8 = IO.ReadBig32(bStream); tmpSection.CompressedSize = IO.ReadBig32(bStream); tmpSection.Offset = sectionOffset; Sections[i] = tmpSection; //If section isn't comrpessed, then CompressedSize and DecompressedSize will match anyways. sectionOffset += tmpSection.CompressedSize; } ReadContents(UpdateDelegate); return(true); }
public virtual void ReadContents(MainForm.UpdateStatusDelegate UpdateDelegate = null) { }
public override void ReadContents(MainForm.UpdateStatusDelegate UpdateDelegate = null) { var DataSection = GetSectionData(0); var GPUSection = GetSectionData(1); DataSection.BaseStream.Seek(Header.TocOffset + 4, System.IO.SeekOrigin.Begin); SubObjects = new Caff_SubObject[Header.FileCount]; for (int i = 0; i < Header.TocEntryCount; i++) { if (UpdateDelegate != null) { float percent = (100.0f / Header.TocEntryCount) * i; UpdateDelegate((int)percent, "Reading Caf TOC..."); } int tmpEntryID = IO.ReadBig32(DataSection) - 1; Caff_SubObject tmpSubObj = SubObjects[tmpEntryID]; if (tmpSubObj == null) { tmpSubObj = new Caff_SubObject(); SubObjects[tmpEntryID] = tmpSubObj; } int tmpOffset = IO.ReadBig32(DataSection); int tmpSize = IO.ReadBig32(DataSection); int tmpSectionID = IO.ReadByte(DataSection); int tmpUnk4 = IO.ReadByte(DataSection); tmpSubObj.SetSection(tmpSectionID - 1, tmpOffset, tmpSize, tmpUnk4); } #if VERBOSE_LOGGING using (var fs = new FileStream(FileName + ".txt", FileMode.OpenOrCreate)) { using (var ss = new StreamWriter(fs)) { int subObjID = 0; foreach (var tmpSubObj in SubObjects) { var tmpDataSection = tmpSubObj.GetSectionInfo(0); var tmpGPUSection = tmpSubObj.GetSectionInfo(1); var tmpStreamSection = tmpSubObj.GetSectionInfo(2); ss.WriteLine(string.Format("SubObject {0}", subObjID)); if (tmpDataSection.Offset != -1) { ss.WriteLine(string.Format("\t.data: Offset: 0x{0:X}, Size: 0x{1:X}", tmpDataSection.Offset, tmpDataSection.Size)); } if (tmpGPUSection.Offset != -1) { ss.WriteLine(string.Format("\t.gpu: Offset: 0x{0:X}, Size: 0x{1:X}", tmpGPUSection.Offset, tmpGPUSection.Size)); } if (tmpStreamSection.Offset != -1) { ss.WriteLine(string.Format("\t.stream: Offset: 0x{0:X}, Size: 0x{1:X}", tmpStreamSection.Offset, tmpStreamSection.Size)); } subObjID++; } } } #endif //var tmpXPR = new XPRFile(); string baseDir = System.IO.Path.GetDirectoryName(FileName); string baseFileName = System.IO.Path.GetFileNameWithoutExtension(FileName); int tmpSubObjID = 0; foreach (var tmpSubObj in SubObjects) { if (UpdateDelegate != null) { float percent = (100.0f / SubObjects.Length) * tmpSubObjID; UpdateDelegate((int)percent, "Reading Contents..."); } var tmpDataSectionInfo = tmpSubObj.GetSectionInfo(0); var tmpGPUSectionInfo = tmpSubObj.GetSectionInfo(1); if (tmpDataSectionInfo.Offset != -1) { DataSection.BaseStream.Seek(tmpDataSectionInfo.Offset, SeekOrigin.Begin); var tmpTypeStr = IO.ReadString(DataSection); if (tmpTypeStr == "texture") { var tmpTexture = new Texture(); DataSection.BaseStream.Seek(tmpDataSectionInfo.Offset, SeekOrigin.Begin); if (tmpGPUSectionInfo.Offset != -1) { GPUSection.BaseStream.Seek(tmpGPUSectionInfo.Offset, SeekOrigin.Begin); } else { Logger.LogError(string.Format("Texture Block at 0x{0:X} has no GPU Section Data.\n", tmpDataSectionInfo.Offset)); continue; } if (tmpTexture.Read(DataSection, GPUSection)) { Textures.Add(tmpTexture); var tmpNode = tmpTexture.ToNode(Textures.Count - 1); tmpNode.Tag = new TreeNodeTag(this, Textures.Count - 1, TreeNodeTag.OBJECT_TYPE_TEXTURE, 0, TreeNodeTag.NodeType.Main); TreeViewNode.Nodes.Add(tmpNode); } } else if (tmpTypeStr == "rendergraph") { var tmpRenderGraph = new RenderGraph(this, RenderGraphs.Count); DataSection.BaseStream.Seek(tmpDataSectionInfo.Offset, SeekOrigin.Begin); if (tmpGPUSectionInfo.Offset != -1) { GPUSection.BaseStream.Seek(tmpGPUSectionInfo.Offset, SeekOrigin.Begin); } else { Logger.LogError(string.Format("RenderGraph Block at 0x{0:X} has no GPU Section.\n", tmpDataSectionInfo.Offset)); continue; } if (tmpRenderGraph.Read(DataSection, GPUSection, tmpDataSectionInfo.Size, tmpGPUSectionInfo.Size)) { RenderGraphs.Add(tmpRenderGraph); var tmpNode = tmpRenderGraph.ToNode(RenderGraphs.Count - 1); tmpNode.Tag = new TreeNodeTag(this, RenderGraphs.Count - 1, TreeNodeTag.OBJECT_TYPE_RENDERGRAPH, 0, TreeNodeTag.NodeType.Main); TreeViewNode.Nodes.Add(tmpNode); } } } tmpSubObjID++; } //tmpXPR.Write(System.IO.Path.Combine(baseDir, string.Format("{0}.xpr", baseFileName))); DataSection.Close(); GPUSection.Close(); }