Exemplo n.º 1
0
        public Character(DirectoryInfo gameDirectory, XivLanguage lang)
        {
            _gameDirectory = gameDirectory;
            _language      = lang;

            _index = new Index(_gameDirectory);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the description from the enum value, in this case the Language
        /// </summary>
        /// <param name="value">The enum value</param>
        /// <returns>The Language Code</returns>
        public static string GetLanguageCode(this XivLanguage value)
        {
            var field     = value.GetType().GetField(value.ToString());
            var attribute = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attribute.Length > 0 ? attribute[0].Description : value.ToString());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Reads and parses Ex Header files.
 /// </summary>
 /// <param name="gameDirectory">The install directory for the game.</param>
 /// <param name="lang">The language in which to read the data.</param>
 public Ex(DirectoryInfo gameDirectory, XivLanguage lang)
 {
     _gameDirectory = gameDirectory;
     _langCode      = lang.GetLanguageCode();
     _index         = new Index(_gameDirectory);
     _dat           = new Dat(_gameDirectory);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor for GameInfo
        /// </summary>
        /// <param name="gameDirectory">The directory in which the game is installed.</param>
        /// <param name="xivLanguage">The language to use when parsing the game data.</param>
        public GameInfo(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
        {
            GameDirectory = gameDirectory;
            GameLanguage  = xivLanguage;
            GameVersion   = GetGameVersion();

            if (!gameDirectory.FullName.Contains("game\\sqpack\\ffxiv"))
            {
                throw new DirectoryNotFoundException("The given directory is incorrect.\n\nThe directory sould point to the \\game\\sqpack\\ffxiv folder");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor for GameInfo
        /// </summary>
        /// <param name="gameDirectory">The directory in which the game is installed.</param>
        /// <param name="xivLanguage">The language to use when parsing the game data.</param>
        public GameInfo(DirectoryInfo gameDirectory, XivLanguage xivLanguage, int dxMode = 11, DirectoryInfo luminaDirectory = null, bool useLumina = false)
        {
            GameDirectory   = gameDirectory;
            GameLanguage    = xivLanguage;
            GameVersion     = GetGameVersion();
            LuminaDirectory = luminaDirectory;
            UseLumina       = useLumina;
            DxMode          = dxMode;

            if (!gameDirectory.FullName.Contains(Path.Combine("game", "sqpack", "ffxiv")))
            {
                throw new DirectoryNotFoundException("The given directory is incorrect.\n\nThe directory sould point to the \\game\\sqpack\\ffxiv folder");
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
 public Gear(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
 {
     _gameDirectory = gameDirectory;
     _xivLanguage   = xivLanguage;
     _index         = new Index(_gameDirectory);
 }
Exemplo n.º 8
0
 public Housing(Modding modding, XivLanguage xivLanguage)
 {
     _modding     = modding;
     _xivLanguage = xivLanguage;
 }
Exemplo n.º 9
0
 public Character(Modding modding, XivLanguage lang)
 {
     _modding  = modding;
     _language = lang;
 }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
 public UI(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
 {
     _gameDirectory = gameDirectory;
     _xivLanguage   = xivLanguage;
     _ex            = new Ex(_gameDirectory, _xivLanguage);
 }
Exemplo n.º 12
0
 public Gear(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
 {
     _gameDirectory = gameDirectory;
     _xivLanguage   = xivLanguage;
 }
Exemplo n.º 13
0
 public Companions(Modding modding, XivLanguage xivLanguage)
 {
     _modding     = modding;
     _xivLanguage = xivLanguage;
     _ex          = new Ex(modding, _xivLanguage);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Reads and parses Ex Header files.
 /// </summary>
 /// <param name="gameDirectory">The install directory for the game.</param>
 /// <param name="lang">The language in which to read the data.</param>
 public Ex(DirectoryInfo gameDirectory, XivLanguage lang)
 {
     _gameDirectory = gameDirectory;
     _langCode      = lang.GetLanguageCode();
 }
Exemplo n.º 15
0
 public Companions(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
 {
     _gameDirectory = gameDirectory;
     _xivLanguage   = xivLanguage;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Imports a ColorSet file
        /// </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>
        /// <param name="source">The source importing the file</param>
        /// <returns>The new offset</returns>
        public async Task <int> TexColorImporter(XivMtrl xivMtrl, DirectoryInfo ddsFileDirectory, IItem item, string source, XivLanguage lang)
        {
            var colorSetData = new List <Half>();

            byte[] colorSetExtraData = null;

            using (var br = new BinaryReader(File.OpenRead(ddsFileDirectory.FullName)))
            {
                // Check DDS type
                br.BaseStream.Seek(84, SeekOrigin.Begin);

                var          texType = br.ReadInt32();
                XivTexFormat textureType;

                if (DDSType.ContainsKey(texType))
                {
                    textureType = DDSType[texType];
                }
                else
                {
                    throw new Exception($"DDS Type ({texType}) not recognized. Expecting A16B16G16R16F.");
                }

                if (textureType != XivTexFormat.A16B16G16R16F)
                {
                    throw new Exception($"Incorrect file type. Expected: A16B16G16R16F  Given: {textureType}");
                }

                // Skip past rest of the 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()));
                }
            }

            // 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))
                {
                    // The extra data after the colorset is always 32 bytes
                    // This reads 16 ushort values which is 16 x 2 = 32
                    colorSetExtraData = File.ReadAllBytes(flagsPath);

                    // If for whatever reason there is a .dat file but it's missing data
                    if (colorSetExtraData.Length != 32)
                    {
                        // Set all dye modifiers to 0 (undyeable)
                        colorSetExtraData = new byte[32];
                    }
                }
                else
                {
                    // If .dat file is missing set all values to 0 (undyeable)
                    colorSetExtraData = new byte[32];
                }
            }

            // 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(await mtrl.ImportMtrl(xivMtrl, item, source));
        }
Exemplo n.º 17
0
 public UI(Modding modding, XivLanguage xivLanguage)
 {
     _modding     = modding;
     _xivLanguage = xivLanguage;
     _ex          = new Ex(modding, _xivLanguage);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Imports a ColorSet file
        /// </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>
        /// <param name="source">The source importing the file</param>
        /// <returns>The new offset</returns>
        public async Task <long> TexColorImporter(XivMtrl xivMtrl, DirectoryInfo ddsFileDirectory, IItem item, string source, XivLanguage lang)
        {
            var colorSetData = new List <Half>();

            byte[] colorSetExtraData = null;


            colorSetData      = GetColorsetDataFromDDS(ddsFileDirectory);
            colorSetExtraData = GetColorsetExtraDataFromDDS(ddsFileDirectory);

            // 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(await _mtrl.ImportMtrl(xivMtrl, item, source));
        }
Exemplo n.º 19
0
        public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress <string> progress = null, XivLanguage language = XivLanguage.None)
        {
            return(Task.Run(async() =>
            {
                var modding = new Modding(_gameDirectory);
                var backupsRestored = false;

                // Stop the cache worker since we're blowing up the entire index file and db anyways.
                // The cache rebuild will start it up again after the cache is rebuilt.
                XivCache.CacheWorkerEnabled = false;

                try
                {
                    // Try restoring the indexes FIRST.
                    backupsRestored = await RestoreBackups(backupsDirectory);
                    progress?.Report("Restoring index file backups...");

                    if (!backupsRestored)
                    {
                        throw new Exception("Start Over Failed: Index backups missing/outdated.");
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        // If the index restore failed, try just disabling.
                        await modding.DeleteAllFilesAddedByTexTools();
                        await modding.ToggleAllMods(false);
                        progress?.Report("Index restore failed, attempting to delete all mods instead...");
                    } catch
                    {
                        throw new Exception("Start Over Failed: Index Backups Invalid and Unable to Disable all mods.");
                    }
                }
                finally
                {
                    progress?.Report("Deleting modded dat files...");

                    var dat = new Dat(_gameDirectory);

                    // Delete modded dat files
                    foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
                    {
                        var datFiles = await dat.GetModdedDatList(xivDataFile);

                        foreach (var datFile in datFiles)
                        {
                            File.Delete(datFile);
                        }

                        if (datFiles.Count > 0)
                        {
                            await RepairIndexDatCounts(xivDataFile);
                        }
                    }

                    progress?.Report("Cleaning up mod list...");

                    var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));

                    // Delete mod list
                    File.Delete(modListDirectory.FullName);

                    modding.CreateModlist();

                    progress?.Report("Rebuilding Cache...");

                    await Task.Run(async() =>
                    {
                        XivCache.RebuildCache();
                    });
                }
            }));
        }
Exemplo n.º 20
0
 public Mtrl(DirectoryInfo gameDirectory, XivDataFile dataFile, XivLanguage lang)
 {
     _gameDirectory = gameDirectory;
     _language      = lang;
     DataFile       = dataFile;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Language is not actually required for Cache -reading-, only for cache generation, so it is
 /// technically an optional parameter if you know you're just reading cache data.
 /// </summary>
 /// <param name="gameDirectory"></param>
 /// <param name="language"></param>
 /// <param name="validateCache"></param>
 public XivCache(DirectoryInfo gameDirectory, XivLanguage language = XivLanguage.None, bool validateCache = true) : this(new GameInfo(gameDirectory, language), validateCache)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Reads and parses Ex Header files.
 /// </summary>
 /// <param name="gameDirectory">The install directory for the game.</param>
 /// <param name="lang">The language in which to read the data.</param>
 public Ex(Modding modding, XivLanguage lang)
 {
     _modding  = modding;
     _langCode = lang.GetLanguageCode();
 }
Exemplo n.º 23
0
 public Housing(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
 {
     _gameDirectory = gameDirectory;
     _xivLanguage   = xivLanguage;
 }
Exemplo n.º 24
0
 public Mtrl(Modding modding, XivDataFile dataFile, XivLanguage lang)
 {
     _modding  = modding;
     _language = lang;
     DataFile  = dataFile;
 }
Exemplo n.º 25
0
 public Gear(Modding modding, XivLanguage xivLanguage)
 {
     _modding     = modding;
     _xivLanguage = xivLanguage;
 }
Exemplo n.º 26
0
        public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress <string> progress = null, XivLanguage language = XivLanguage.None)
        {
            return(Task.Run(async() =>
            {
                progress?.Report("Deleting mods...");

                var modding = new Modding(_gameDirectory);
                var backupsRestored = false;

                try
                {
                    // Try to restore the index entries to their original values by deleting any files added by TexTools
                    // and setting mods to disabled
                    await modding.DeleteAllFilesAddedByTexTools();
                    await modding.ToggleAllMods(false);
                    progress?.Report("Restoring index file backups...");
                }
                catch
                {
                    // If an exception occurred due to a corrupted modlist which couldn't be deserealized restore the backup index
                    // files by force
                    backupsRestored = await RestoreBackups(backupsDirectory);

                    if (!backupsRestored)
                    {
                        throw new Exception("Start Over Failed: Index backups missing/outdated.");
                    }
                }
                finally
                {
                    // If no exception occured, restore the backups anyway just to be safe but don't throw an exception if it fails
                    // due to outdated or missing backups since setting back the original index values should be enough hopefully
                    if (!backupsRestored)
                    {
                        backupsRestored = await RestoreBackups(backupsDirectory);

                        // If backups were not restored that means they were missing/outdated so try to make new backups now
                        if (!backupsRestored)
                        {
                            try
                            {
                                await BackupIndexFiles(backupsDirectory);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("Start Over Failed: Failed to update outdated backups.\n\n" + ex.Message);
                            }
                        }
                    }

                    progress?.Report("Deleting modded dat files...");

                    var dat = new Dat(_gameDirectory);

                    // Delete modded dat files
                    foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
                    {
                        var datFiles = await dat.GetModdedDatList(xivDataFile);

                        foreach (var datFile in datFiles)
                        {
                            File.Delete(datFile);
                        }

                        if (datFiles.Count > 0)
                        {
                            await RepairIndexDatCounts(xivDataFile);
                        }
                    }

                    progress?.Report("Cleaning up mod list...");

                    var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));

                    // Delete mod list
                    File.Delete(modListDirectory.FullName);

                    modding.CreateModlist();

                    progress?.Report("Rebuilding Cache...");

                    await Task.Run(async() =>
                    {
                        var _cache = new XivCache(_gameDirectory, language);
                        _cache.RebuildCache();
                    });
                }
            }));
        }