Example #1
0
        /// <summary>
        /// Converts a DDS file into a mtrl file and returns the raw data
        /// </summary>
        /// <param name="xivMtrl">The XivMtrl data of the original</param>
        /// <param name="ddsFileDirectory">The dds directory of the new ColorSet</param>
        /// <param name="item">The item</param>
        /// <returns>The raw mtrl data</returns>
        public byte[] DDStoMtrlData(XivMtrl xivMtrl, DirectoryInfo ddsFileDirectory, IItem item, XivLanguage lang)
        {
            var colorSetData = GetColorsetDataFromDDS(ddsFileDirectory);

            var colorSetExtraData = new byte[32];

            // If the colorset size is 544, it contains extra data that must be imported
            try
            {
                colorSetExtraData = GetColorsetExtraDataFromDDS(ddsFileDirectory);
            } catch
            {
                colorSetExtraData = new byte[32];
            }

            // Replace the color set data with the imported data
            xivMtrl.ColorSetData    = colorSetData;
            xivMtrl.ColorSetDyeData = colorSetExtraData;

            if (xivMtrl.Unknown2.Length > 0)
            {
                // This byte enables the dye set if it's not already enabled.
                xivMtrl.Unknown2[0] = 12;
            }

            var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory);

            return(_mtrl.CreateMtrlFile(xivMtrl, item));
        }
Example #2
0
        /// <summary>
        /// Converts a DDS file into a mtrl file and returns the raw data
        /// </summary>
        /// <param name="xivMtrl">The XivMtrl data of the original</param>
        /// <param name="ddsFileDirectory">The dds directory of the new ColorSet</param>
        /// <param name="item">The item</param>
        /// <returns>The raw mtrl data</returns>
        public byte[] DDStoMtrlData(XivMtrl xivMtrl, DirectoryInfo ddsFileDirectory, IItem item, XivLanguage lang)
        {
            var colorSetData = new List <Half>();

            using (var br = new BinaryReader(File.OpenRead(ddsFileDirectory.FullName)))
            {
                // skip DDS header
                br.BaseStream.Seek(128, SeekOrigin.Begin);

                // color data is always 512 (4w x 16h = 64 x 8bpp = 512)
                // this reads 256 ushort values which is 256 x 2 = 512
                for (var i = 0; i < 256; i++)
                {
                    colorSetData.Add(new Half(br.ReadUInt16()));
                }
            }
            var colorSetExtraData = new byte[32];

            // If the colorset size is 544, it contains extra data that must be imported
            if (xivMtrl.ColorSetDataSize == 544)
            {
                var flagsPath = Path.Combine(Path.GetDirectoryName(ddsFileDirectory.FullName), (Path.GetFileNameWithoutExtension(ddsFileDirectory.FullName) + ".dat"));

                if (File.Exists(flagsPath))
                {
                    colorSetExtraData = File.ReadAllBytes(flagsPath);
                    //using (var br = new BinaryReader(File.OpenRead(flagsPath)))
                    //{
                    //    // The extra data after the colorset is always 32 bytes
                    //    // This reads 16 ushort values which is 16 x 2 = 32
                    //    for (var i = 0; i < 16; i++)
                    //    {
                    //        colorSetData.Add(new Half(br.ReadUInt16()));
                    //    }
                    //}
                }
            }

            // Replace the color set data with the imported data
            xivMtrl.ColorSetData      = colorSetData;
            xivMtrl.ColorSetExtraData = colorSetExtraData;

            var mtrl = new Mtrl(_gameDirectory, xivMtrl.TextureTypePathList[0].DataFile, lang);

            return(mtrl.CreateMtrlFile(xivMtrl, item));
        }