public override void ParseBytes(CR2WBinaryReader br, uint size) { base.ParseClass(br, this); var zero = br.ReadUInt32(); var mipCount = br.ReadUInt32(); var width = br.ReadUInt32(); var height = br.ReadUInt32(); var unknown5 = br.ReadUInt32(); var sizeorpitch = br.ReadUInt32(); //var unknown7 = br.ReadUInt32(); Console.WriteLine("zero {0}", zero); Console.WriteLine("mipCount {0}", mipCount); Console.WriteLine("width {0}", width); Console.WriteLine("height {0}", height); Console.WriteLine("unknown5 {0}", unknown5); Console.WriteLine("sizeorpitch {0}", sizeorpitch); //Console.WriteLine("unknown7 {0}", sizeorpitch); var ddsheader = new DDSStruct { size = 124, flags = 659463, width = width, height = height, sizeorpitch = sizeorpitch, depth = 1, mipmapcount = 1, reserved = new uint[10], }; ddsheader.ddscaps.caps1 = 4096; ddsheader.pixelformat.size = 32; ddsheader.pixelformat.flags = 5; ddsheader.pixelformat.fourcc = DDSHelper.FOURCC_DXT1; var dds = new DDSImage(br, ddsheader, true); Form form = new Form { Text = LinkageName, ClientSize = new Size((int)width, (int)height), }; PictureBox pictureBox = new PictureBox { Image = dds.BitmapImage, Width = (int)width, Height = (int)height }; form.Controls.Add(pictureBox); var t = new Task(() => { Application.Run(form); }); t.Start(); }
protected void ParseClass(CR2WBinaryReader br, object instance) { br.ReadByte(); while (true) { var nameId = br.ReadUInt16(); if (nameId == 0) { break; } var typeId = br.ReadInt16(); var size = br.ReadUInt32() - 4; var prop = GetPropertybyW3Name(br.names[nameId], instance.GetType()); var value = ParseProperty(br, prop.PropertyType); prop.SetValue(instance, value); } }
protected void ParseClass(CR2WBinaryReader br, object instance) { br.ReadByte(); while (true) { var nameId = br.ReadUInt16(); if (nameId == 0) { break; } var typeId = br.ReadInt16(); var size = br.ReadUInt32() - 4; var prop = instance.GetType().GetREDProperty(br.names[nameId], br.names[typeId]); if (prop == null) { Console.WriteLine("ERROR - Property ({0} : {1}) not found in {2}, skipping!", br.names[nameId], br.names[typeId], instance.GetType().Name); br.BaseStream.Seek(size, SeekOrigin.Current); continue; } var value = ParseProperty(br, prop.PropertyType); prop.SetValue(instance, value); } }
protected object ParseProperty(CR2WBinaryReader br, Type proptype) { //Basic / Value Types switch (proptype.Name) { case "Byte": return(br.ReadByte()); case "UInt16": return(br.ReadUInt16()); case "UInt32": return(br.ReadUInt32()); case "UInt64": return(br.ReadUInt64()); case "SByte": return(br.ReadSByte()); case "Int16": return(br.ReadInt16()); case "Int32": return(br.ReadInt32()); case "Int64": return(br.ReadInt64()); case "Boolean": return(br.ReadBoolean()); case "Single": return(br.ReadSingle()); case "Double": return(br.ReadDouble()); case "CName": return(br.ReadCName()); case "CGUID": return(br.ReadCGUID()); case "IdTag": return(br.ReadIdTag()); case "TagList": return(br.ReadTagList()); case "EngineTransform": return(br.ReadEngineTransform()); case "EngineQsTransform": return(br.ReadEngineQsTransform()); case "CDateTime": return(br.ReadCDateTime()); case "String": return(br.ReadStringDefaultSingle()); } //Parse Enumarators if (proptype.IsEnum) { return(br.ReadEnumarator(proptype)); } //Parse Generic Types (Array, Soft, Ptr, Handle) if (proptype.IsGenericType) { var instance = Activator.CreateInstance(proptype); var genprop = proptype.GetTypeInfo().GenericTypeArguments[0]; if (proptype.GetGenericTypeDefinition() == typeof(Array <>)) { var length = br.ReadUInt32(); for (int i = 0; i < length; i++) { var value = ParseProperty(br, genprop); proptype.GetMethod("Add").Invoke(instance, new[] { value }); } return(instance); } else if (proptype.GetGenericTypeDefinition() == typeof(Soft <>)) { var id = br.ReadUInt16() - 1; if (br.resources[id].type != genprop.Name) { throw new InvalidOperationException($"Soft type mistatch. Expected Type: {genprop.Name}. Type Read: {br.resources[id].type}."); } proptype.GetProperty("DepotPath").SetValue(instance, br.resources[id].path); proptype.GetProperty("Flags").SetValue(instance, br.resources[id].flags); return(instance); } } //Parse classes if (proptype.IsClass) { var instance = Activator.CreateInstance(proptype); ParseClass(br, instance); return(instance); } //Any Unknown Type //Should be impossible to reach if all types get covered above. return(null); }
public override void ParseBytes(CR2WBinaryReader br, uint size) { base.ParseBytes(br, size); /* * This is a temporary solution for reading the contents of a CBitmapTexture * What this does is contruct a dds header object and parse it and the raw bytes * using the dds library. * * The bitmap bytes from the cr2w has a header 28 bytes long, containing data about the * image such as size and height etc... * There are 4 unknown ones. * * This class should in the end support reading all xbm files with means supporting not just * dds but tga, bmp, png, and jpg. * */ var zero = br.ReadUInt32(); var mipCount = br.ReadUInt32(); var width = br.ReadUInt32(); var height = br.ReadUInt32(); var unknown5 = br.ReadUInt32(); var sizeorpitch = br.ReadUInt32(); Console.WriteLine("zero {0}", zero); Console.WriteLine("mipCount {0}", mipCount); Console.WriteLine("width {0}", width); Console.WriteLine("height {0}", height); Console.WriteLine("unknown5 {0}", unknown5); Console.WriteLine("sizeorpitch {0}", sizeorpitch); var ddsheader = new DDSStruct { size = 124, flags = 659463, width = width, height = height, sizeorpitch = sizeorpitch, depth = 1, mipmapcount = 1, reserved = new uint[10], }; ddsheader.ddscaps.caps1 = 4096; ddsheader.pixelformat.size = 32; ddsheader.pixelformat.flags = 5; ddsheader.pixelformat.fourcc = DDSHelper.FOURCC_DXT1; var dds = new DDSImage(br, ddsheader, true); Form form = new Form { Text = "Image", ClientSize = new Size((int)width, (int)height), }; PictureBox pictureBox = new PictureBox { Image = dds.BitmapImage, Width = (int)width, Height = (int)height }; form.Controls.Add(pictureBox); var t = new Task(() => { Application.Run(form); }); t.Start(); }