示例#1
0
        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();
        }
示例#2
0
 public virtual void ParseBytes(CR2WBinaryReader br, uint size)
 {
     ParseClass(br, this);
     #region Comments
     // - TODO:
     //      Figure out an elegant solution to map the data within a chunk to the class structure.
     //      Problems so far are:
     //          1) Looping through an unknown number of nested types and mapping the values whilst
     //             keeing track of where the stream position is.
     //             On top of that use attributes to find the right values and using the right
     //             object parser for each type of variable.
     //             Solutions are:
     //                  - Use the attrubutes themselves to cascade down parsring and setting the values
     //                  - Have a standalone set of functions within CR2W.IO.CR2WParser that work on recursion
     //                    to keep nesting throughout the class structure.
     //                  - Write a parser into each base variable type (ints, floats, CName etc...) as an extenstion method
     //                    and call those methods, if not found then nest into the class and repeat.
     //
     //          2) Figure out how to get array to map properly.
     //             Arrays are annoying to work with. In particular arrays of arrays. Atributes are not really a decent solution.
     //             Alternative is to write the parser into the CArray class type which would work but would cause a headache later
     //             when it has to fit with the rest of the system that may use attributes to parse the value.
     //
     //          3) Get a system that can read past the class structure bytes
     //             For some files such as CSwfResource, CBitmapTexture, or CRagdoll where there is more info in the chunk that extends
     //             beyond the class structre. Data there needs specific parsers for each specific case.
     //             These can be written into the CResource class on an individual basis, but as before if the system uses
     //             attributes to map the values then there will be problems trying to integrate this.
     #endregion
 }
示例#3
0
        public DDSImage(CR2WBinaryReader reader, DDSStruct header, bool alpha)
        {
            Utils.PixelFormat pixelFormat = Utils.PixelFormat.UNKNOWN;
            byte[]            data        = null;

            if (header.depth == 0)
            {
                header.depth = 1;
            }

            _isValid = true;
            _alpha   = alpha;

            uint blocksize = 0;

            pixelFormat = GetFormat(header, ref blocksize);
            if (pixelFormat == Utils.PixelFormat.UNKNOWN)
            {
                throw new InvalidFileHeaderException();
            }

            data = ReadData(reader, header);
            if (data != null)
            {
                byte[] rawData = DDSDecompressor.Expand(header, data, pixelFormat);
                _bitmap = CreateBitmap((int)header.width, (int)header.height, rawData);
            }
        }
示例#4
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            base.ParseBytes(br, size);
            var dataSize = br.ReadInt32();

            Data = br.ReadBytes(dataSize);
        }
示例#5
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            base.ParseBytes(br, size);

            /* - TODO parse the bytes in the buffers
             *        That block 6 point to.
             */
        }
示例#6
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            //Parse the bytes at the beginning which will map the class structure
            base.ParseBytes(br, size);

            //Now read the XML document at the end of the object data
            Data = br.ReadXMLDocument();
        }
示例#7
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            base.ParseBytes(br, size);

            /* - ToDo
             *   parse the remaining bytes that is the swf resource.
             */
        }
示例#8
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            base.ParseBytes(br, size);

            var length = br.ReadInt32();
            var xmlstr = Encoding.UTF8.GetString(br.ReadBytes(length));

            Data = new XmlDocument();
            Data.LoadXml(xmlstr);
        }
示例#9
0
 /// <summary>
 /// Load a CR2W file as a CResource
 /// </summary>
 /// <param name="resource">Path of the resource file</param>
 /// <param name="isDepotPath">Use the absolute depot path of the file</param>
 /// <returns>CResource instance from the file</returns>
 public static CResource LoadResource(string resource, bool isDepotPath = false)
 {
     if (!File.Exists(resource))
     {
         throw new FileNotFoundException($"The file '{resource}' could not be found.");
     }
     using (var br = new CR2WBinaryReader(resource, false))
     {
         return(br.CreateResource());
     }
 }
示例#10
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            base.ParseBytes(br, size);

            /* - Info Parsing Extra Bytes
             *   Specifically to sound_info.redicsv
             *
             *   1st byte gives the length of the Array of Headers
             *   Read off that many strings using br.ReadStringDefaultSingle()
             *
             *   Next byte is the size of of the array of data.
             *   Read off that many arrays, where the beginning of each sub array is prefixed with the size of that sub one.
             */
        }
示例#11
0
 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);
     }
 }
示例#12
0
 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);
     }
 }
示例#13
0
        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);
        }
示例#14
0
 public override void ParseBytes(CR2WBinaryReader br, uint size)
 {
     base.ParseBytes(br, size);
 }
示例#15
0
        public override void ParseBytes(CR2WBinaryReader br, uint size)
        {
            var end = br.BaseStream.Position + size;

            base.ParseBytes(br, size);
        }
示例#16
0
        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();
        }