public ReadString ( byte terminator = 0x0 ) : string | ||
terminator | byte | |
return | string |
public BrgHeader(BrgBinaryReader reader) { this.Magic = reader.ReadString(4); this.Unknown01 = reader.ReadInt32(); this.NumMaterials = reader.ReadInt32(); this.Unknown02 = reader.ReadInt32(); this.NumMeshes = reader.ReadInt32(); this.Reserved = reader.ReadInt32(); this.Unknown03 = reader.ReadInt32(); }
public BrgHeader(BrgBinaryReader reader) { this.Magic = reader.ReadString(4); this.Unknown01 = reader.ReadInt32(); this.NumMaterials = reader.ReadInt32(); this.Unknown02 = reader.ReadInt32(); this.NumMeshes = reader.ReadInt32(); this.Reserved = reader.ReadInt32(); this.Unknown03 = reader.ReadInt32(); }
public BrgMaterial(BrgBinaryReader reader, BrgFile file) : this(file) { Id = reader.ReadInt32(); Flags = (BrgMatFlag)reader.ReadInt32(); unknown01b = reader.ReadInt32(); int nameLength = reader.ReadInt32(); this.DiffuseColor = reader.ReadColor3D(); this.AmbientColor = reader.ReadColor3D(); this.SpecularColor = reader.ReadColor3D(); this.EmissiveColor = reader.ReadColor3D(); this.DiffuseMap = reader.ReadString(nameLength); if (Flags.HasFlag(BrgMatFlag.SpecularExponent)) { this.SpecularExponent = reader.ReadSingle(); } if (Flags.HasFlag(BrgMatFlag.BumpMap)) { this.BumpMap = reader.ReadString(reader.ReadInt32()); } if (Flags.HasFlag(BrgMatFlag.Alpha)) { this.Opacity = reader.ReadSingle(); } if (Flags.HasFlag(BrgMatFlag.REFLECTIONTEXTURE)) { byte numSFX = reader.ReadByte(); sfx = new List <BrgMatSFX>(numSFX); for (int i = 0; i < numSFX; i++) { sfx.Add(reader.ReadMaterialSFX()); } } else { sfx = new List <BrgMatSFX>(); } }
public void Read(Stream stream) { using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), stream)) { uint magic = reader.ReadUInt32(); if (magic != 1280463949) { throw new Exception("This is not a MTRL file!"); } uint nameLength = reader.ReadUInt32(); for (int i = 0; i < 5; ++i) { this.unk[i] = reader.ReadUInt32(); } this.Diffuse = reader.ReadColor3D(); this.Ambient = reader.ReadColor3D(); this.Specular = reader.ReadColor3D(); this.Emissive = reader.ReadColor3D(); this.SpecularLevel = reader.ReadSingle(); this.Alpha = reader.ReadSingle(); this.Id = reader.ReadInt32(); this.SelfIlluminating = reader.ReadByte(); this.ClampU = reader.ReadByte(); this.ClampV = reader.ReadByte(); this.LightSpecular = reader.ReadByte(); this.AffectsAmbient = reader.ReadByte(); this.AffectsDiffuse = reader.ReadByte(); this.AffectsSpecular = reader.ReadByte(); this.Updateable = reader.ReadByte(); this.AlphaMode = reader.ReadInt32(); // Seems to be very often 10, wave has a 2 here, phoenix has 6 this.AmbientIntensity = reader.ReadInt32(); this.DiffuseIntensity = reader.ReadInt32(); this.SpecularIntensity = reader.ReadInt32(); this.EmissiveIntensity = reader.ReadInt32(); this.ColorTransform = reader.ReadInt32(); // Val of 4 seems to be PC this.TextureTransform = reader.ReadInt32(); this.TextureFactor = reader.ReadInt32(); // Has something to do with Cube Map this.MultiTextureMode = reader.ReadInt32(); // Has something to do with Cube Map this.TexGenMode0 = reader.ReadInt32(); this.TexGenMode1 = reader.ReadInt32(); // Has something to do with Cube Map this.TexCoordSet0 = reader.ReadInt32(); this.TexCoordSet1 = reader.ReadInt32(); this.TexCoordSet2 = reader.ReadInt32(); this.TexCoordSet3 = reader.ReadInt32(); this.TexCoordSet4 = reader.ReadInt32(); this.TexCoordSet5 = reader.ReadInt32(); this.TexCoordSet6 = reader.ReadInt32(); this.TexCoordSet7 = reader.ReadInt32(); for (int i = 0; i < 3; ++i) { this.unk2[i] = reader.ReadTexel(); } for (int i = 0; i < 3; ++i) { this.unk3[i] = reader.ReadTexel(); } for (int i = 0; i < 4; ++i) { this.unk4[i] = reader.ReadInt32(); } if (nameLength > 0) { this.Texture = reader.ReadString(); } } }
private static void Convert(string f) { string magic; using (FileStream fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)) { BrgBinaryReader reader = new BrgBinaryReader(EndianBitConverter.Little, fs); magic = reader.ReadString(4); } if (f.EndsWith("anim.txt")) { AnimFile.ConvertToXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Anim converted."); } else if (f.EndsWith(".prt")) { PrtFile file = new PrtFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)); file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Prt converted."); } else if (magic == "MTRL") { MtrlFile file = new MtrlFile(); file.Read(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)); file.SerializeAsXml(File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Mtrl converted."); } else if (magic == "BANG") { string brgMtrlOutputPath = Path.Combine(Path.GetDirectoryName(f), "materials"); if (!Directory.Exists(brgMtrlOutputPath)) { Directory.CreateDirectory(brgMtrlOutputPath); } BrgFile file = new BrgFile(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)); for (int i = 0; i < file.Materials.Count; ++i) { MtrlFile mtrl = new MtrlFile(file.Materials[i]); mtrl.Write(File.Open(Path.Combine(brgMtrlOutputPath, Path.GetFileNameWithoutExtension(f) + "_" + i + ".mtrl"), FileMode.Create, FileAccess.Write, FileShare.Read)); } Console.WriteLine("Success! Mtrl files created."); } else { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(f); if (xmlDoc.DocumentElement.Name == "AnimFile") { AnimFile.ConvertToAnim(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read), File.Open(f + ".txt", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Anim converted."); } else if (xmlDoc.DocumentElement.Name == "ParticleFile") { PrtFile file = PrtFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)); file.Write(File.Open(f + ".prt", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Prt converted."); } else { MtrlFile file = MtrlFile.DeserializeAsXml(File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)); file.Write(File.Open(f + ".mtrl", FileMode.Create, FileAccess.Write, FileShare.Read)); Console.WriteLine("Success! Mtrl converted."); } } }
public void Read(Stream stream) { using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), stream)) { uint magic = reader.ReadUInt32(); if (magic != 1280463949) { throw new Exception("This is not a MTRL file!"); } uint nameLength = reader.ReadUInt32(); for (int i = 0; i < 5; ++i) { this.unk[i] = reader.ReadUInt32(); } this.Diffuse = reader.ReadColor3D(); this.Ambient = reader.ReadColor3D(); this.Specular = reader.ReadColor3D(); this.Emissive = reader.ReadColor3D(); this.SpecularLevel = reader.ReadSingle(); this.Alpha = reader.ReadSingle(); this.Id = reader.ReadInt32(); this.SelfIlluminating = reader.ReadByte(); this.ClampU = reader.ReadByte(); this.ClampV = reader.ReadByte(); this.LightSpecular = reader.ReadByte(); this.AffectsAmbient = reader.ReadByte(); this.AffectsDiffuse = reader.ReadByte(); this.AffectsSpecular = reader.ReadByte(); this.Updateable = reader.ReadByte(); this.AlphaMode = reader.ReadInt32(); // Seems to be very often 10, wave has a 2 here, phoenix has 6 this.AmbientIntensity = reader.ReadInt32(); this.DiffuseIntensity = reader.ReadInt32(); this.SpecularIntensity = reader.ReadInt32(); this.EmissiveIntensity = reader.ReadInt32(); this.ColorTransform = reader.ReadInt32(); // Val of 4 seems to be PC this.TextureTransform = reader.ReadInt32(); this.TextureFactor = reader.ReadInt32(); // Has something to do with Cube Map this.MultiTextureMode = reader.ReadInt32(); // Has something to do with Cube Map this.TexGenMode0 = reader.ReadInt32(); this.TexGenMode1 = reader.ReadInt32(); // Has something to do with Cube Map this.TexCoordSet0 = reader.ReadInt32(); this.TexCoordSet1 = reader.ReadInt32(); this.TexCoordSet2 = reader.ReadInt32(); this.TexCoordSet3 = reader.ReadInt32(); this.TexCoordSet4 = reader.ReadInt32(); this.TexCoordSet5 = reader.ReadInt32(); this.TexCoordSet6 = reader.ReadInt32(); this.TexCoordSet7 = reader.ReadInt32(); for (int i = 0; i < 3; ++i) { this.unk2[i] = reader.ReadTexel(); } for (int i = 0; i < 3; ++i) { this.unk3[i] = reader.ReadTexel(); } for (int i = 0; i < 4; ++i) { this.unk4[i] = reader.ReadInt32(); } if (nameLength > 0) { this.Texture = reader.ReadString(); } } }
public BrgFile(System.IO.FileStream fileStream) : base() { using (BrgBinaryReader reader = new BrgBinaryReader(new LittleEndianBitConverter(), fileStream)) { this.FileName = fileStream.Name; this.Header = new BrgHeader(reader); if (this.Header.Magic != "BANG") { throw new Exception("This is not a BRG file!"); } this.AsetHeader = new BrgAsetHeader(); int asetCount = 0; this.Meshes = new List <BrgMesh>(this.Header.NumMeshes); this.Materials = new List <BrgMaterial>(); while (reader.BaseStream.Position < reader.BaseStream.Length) { string magic = reader.ReadString(4); if (magic == "ASET") { this.AsetHeader = new BrgAsetHeader(reader); ++asetCount; } else if (magic == "MESI") { if (this.Meshes.Count > 0) { this.Meshes[0].MeshAnimations.Add(new BrgMesh(reader, this)); } else { this.Meshes.Add(new BrgMesh(reader, this)); } } else if (magic == "MTRL") { BrgMaterial mat = new BrgMaterial(reader, this); Materials.Add(mat); if (!ContainsMaterialID(mat.Id)) { //Materials.Add(mat); } else { //throw new Exception("Duplicate material ids!"); } } else { throw new Exception("The type tag " + /* magic +*/ " is not recognized!"); } } if (asetCount > 1) { //throw new Exception("Multiple ASETs!"); } if (Header.NumMeshes < Meshes.Count) { throw new Exception("Inconsistent mesh count!"); } if (Header.NumMaterials < Materials.Count) { throw new Exception("Inconsistent material count!"); } if (reader.BaseStream.Position < reader.BaseStream.Length) { throw new Exception("The end of stream was not reached!"); } this.Animation.Duration = this.Meshes[0].ExtendedHeader.AnimationLength; this.Animation.TimeStep = this.Meshes[0].ExtendedHeader.AnimationLength / (float)(this.Meshes[0].MeshAnimations.Count + 1); if (this.Meshes[0].Header.AnimationType.HasFlag(BrgMeshAnimType.NonUniform)) { for (int i = 0; i <= this.Meshes[0].MeshAnimations.Count; ++i) { this.Animation.MeshKeys.Add(this.Meshes[0].NonUniformKeys[i] * this.Animation.Duration); } } else if (this.Meshes[0].MeshAnimations.Count > 0) { for (int i = 0; i <= this.Meshes[0].MeshAnimations.Count; ++i) { this.Animation.MeshKeys.Add((float)i / ((float)this.Meshes[0].MeshAnimations.Count) * this.Animation.Duration); } } else { this.Animation.MeshKeys.Add(0); } } }