public void Load(System.IO.Stream stream) { Text = FileName; CanSave = true; FileReader reader = new FileReader(stream); int SectionSize = 0; while (!reader.EndOfStream) { string magicCheck = reader.ReadString(4, Encoding.ASCII); if (magicCheck == "VFXB") { reader.Seek(-4); break; } SectionSize += 4; } if (SectionSize == reader.BaseStream.Length) { return; } DataStart = reader.getSection(0, SectionSize); Text = FileName; ptcl = new PTCL(); ptcl.IFileInfo = new IFileInfo(); ptcl.FileName = "Output.pctl"; Nodes.Add(ptcl); ptcl.Load(new SubStream(stream, reader.Position)); }
public void Read(FileReader reader, PTCL pctl) { uint Position = (uint)reader.Position; //Offsets are relative to this reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; string Signature = reader.ReadString(4, Encoding.ASCII); if (Signature == "SPBD") { IsSPBD = true; } Version = reader.ReadUInt32(); uint EmitterCount = reader.ReadUInt32(); uint Padding = reader.ReadUInt32(); EffectNameTableOffset = reader.ReadUInt32(); TextureBlockTableOffset = reader.ReadUInt32(); TextureBlockTableSize = reader.ReadUInt32(); if (Version > 11) { ShaderGtxTableOffset = reader.ReadUInt32(); ShaderGtxTableSize = reader.ReadUInt32(); uint KeyAnimationTableOffset = reader.ReadUInt32(); uint KeyAnimationTableSize = reader.ReadUInt32(); uint PrimativeTableOffset = reader.ReadUInt32(); uint PrimativeTableSize = reader.ReadUInt32(); uint ShaderParamTableOffset = reader.ReadUInt32(); uint ShaderParamTableSize = reader.ReadUInt32(); uint TotalTextureTableSize = reader.ReadUInt32(); uint Unknown1 = reader.ReadUInt32(); uint Unknown2 = reader.ReadUInt32(); } var groupEmitterSets = new TreeNode("Emitter Sets"); var textureFolder = new TreeNode("Textures"); pctl.Nodes.Add(textureFolder); pctl.Nodes.Add(groupEmitterSets); for (int i = 0; i < EmitterCount; i++) { EmitterSet emitterSet = new EmitterSet(); emitterSet.Read(reader, this); emitterSets.Add(emitterSet); groupEmitterSets.Nodes.Add(emitterSet); } int index = 0; foreach (var tex in Textures) { tex.Text = $"Texture{index++}"; textureFolder.Nodes.Add(tex); } }
public void Read(FileReader reader, PTCL ptcl) { uint Position = (uint)reader.Position; //Offsets are relative to this reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; Signature = reader.ReadString(4, Encoding.ASCII); if (Signature == "EFTB") { reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; reader.Seek(48, SeekOrigin.Begin); } else if (Signature == "VFXB") { uint padding = reader.ReadUInt32(); GraphicsAPIVersion = reader.ReadUInt16(); VFXVersion = reader.ReadUInt16(); ByteOrderMark = reader.ReadUInt16(); Alignment = reader.ReadByte(); TargetOffset = reader.ReadByte(); uint HeaderSize = reader.ReadUInt32(); Flag = reader.ReadUInt16(); BlockOffset = reader.ReadUInt16(); uint padding2 = reader.ReadUInt32(); uint FileSize = reader.ReadUInt32(); reader.Seek(Position + BlockOffset, SeekOrigin.Begin); } else { throw new Exception("Unknown ptcl format. Signature not valid " + Signature); } while (reader.Position < reader.BaseStream.Length) { SectionBase sectionBase = new SectionBase(); sectionBase.Read(reader, this); Sections.Add(sectionBase); ptcl.Nodes.Add(sectionBase); if (sectionBase.NextSectionOffset == NullOffset) { break; } } MapTextureIDs(ptcl); reader.Dispose(); reader.Close(); }
public void Load(System.IO.Stream stream) { Text = FileName; FileReader reader = new FileReader(stream); reader.Seek(4096, System.IO.SeekOrigin.Begin); PTCL pctl = new PTCL(); pctl.Text = "Output.pctl"; Nodes.Add(pctl); PTCL.Header Header = new PTCL.Header(); Header.Read(reader, pctl); }
public void Write(FileWriter writer, PTCL ptcl) { writer.ByteOrder = ByteOrder.LittleEndian; writer.Write(ptcl.data.ToArray()); foreach (TextureInfo tex in ptcl.header3DS.Textures) { //write texture blocks. Some slots are empty so check if it exists tex.Write(writer, this); } foreach (EmitterSet emitterSets in emitterSets) { foreach (Emitter3DS emitter in emitterSets.Nodes) { writer.Seek(((Emitter3DS)emitter).ColorPosition, SeekOrigin.Begin); foreach (var color0 in emitter.Color0Array) { writer.Write(color0.R); writer.Write(color0.G); writer.Write(color0.B); writer.Write(color0.A); } foreach (var color1 in emitter.Color1Array) { writer.Write(color1.R); writer.Write(color1.G); writer.Write(color1.B); writer.Write(color1.A); } } } writer.Flush(); writer.Close(); writer.Dispose(); }
public void Write(FileWriter writer, PTCL ptcl) { writer.ByteOrder = ByteOrder.BigEndian; writer.Write(ptcl.data.ToArray()); foreach (TextureInfo tex in ptcl.headerU.Textures) { //write texture blocks. Some slots are empty so check if it exists tex.Write(writer, this); } foreach (EmitterSet emitterSets in emitterSets) { foreach (EmitterU emitter in emitterSets.Nodes) { writer.Seek(((EmitterU)emitter).ColorPosition, SeekOrigin.Begin); for (int i = 0; i < emitter.Color0Array.Length; i++) { writer.Write(emitter.Color0Array[i].R); writer.Write(emitter.Color0Array[i].G); writer.Write(emitter.Color0Array[i].B); writer.Write(emitter.Color0AlphaArray[i].R); } for (int i = 0; i < emitter.Color1Array.Length; i++) { writer.Write(emitter.Color1Array[i].R); writer.Write(emitter.Color1Array[i].G); writer.Write(emitter.Color1Array[i].B); writer.Write(emitter.Color1AlphaArray[i].R); } } } writer.Flush(); writer.Close(); writer.Dispose(); }
private void MapTextureIDs(PTCL ptcl) { List <TextureDescriptor> texDescp = new List <TextureDescriptor>(); List <Emitter> emitters = new List <Emitter>(); BNTX bntx = null; List <TEXR> botwTex = new List <TEXR>(); //Used for BOTW foreach (var node in TreeViewExtensions.Collect(ptcl.Nodes)) { if (node is TextureDescriptor) { texDescp.Add((TextureDescriptor)node); } if (node is SectionBase && ((SectionBase)node).BinaryData is Emitter) { emitters.Add((Emitter)((SectionBase)node).BinaryData); } if (node is BNTX) { bntx = (BNTX)node; } if (node is SectionBase && ((SectionBase)node).BinaryData is TEXR) { botwTex.Add((TEXR)((SectionBase)node).BinaryData); } } int index = 0; if (botwTex.Count > 0) { TreeNode textureFolder = new TreeNode("Textures"); ptcl.Nodes.Add(textureFolder); List <TEXR> TextureList = new List <TEXR>(); foreach (var emitter in emitters) { foreach (TEXR tex in botwTex) { bool HasImage = TextureList.Any(item => item.data == tex.data); if (!HasImage) { tex.Text = "Texture " + index++; textureFolder.Nodes.Add(tex); } TextureList.Add(tex); foreach (var sampler in emitter.Samplers) { if (sampler.TextureID == tex.TextureID) { emitter.DrawableTex.Add(tex); } } } } TextureList.Clear(); } if (bntx == null) { return; } foreach (var emitter in emitters) { foreach (var tex in texDescp) { foreach (var sampler in emitter.Samplers) { if (sampler.TextureID == tex.TextureID) { if (bntx.Textures.ContainsKey(tex.TexName)) { emitter.DrawableTex.Add(bntx.Textures[tex.TexName]); } } } } } }