예제 #1
0
        /// <summary>
        /// Updates the .index files offset for a given item.
        /// </summary>
        /// <param name="offset">The new offset to be used.</param>
        /// <param name="fullPath">The internal path of the file whos offset is to be updated.</param>
        /// <returns>The offset which was replaced.</returns>
        public static int UpdateIndex(long offset, string fullPath, string indexName)
        {
            var folderHash = FFCRC.GetHash(fullPath.Substring(0, fullPath.LastIndexOf("/")));
            var fileHash   = FFCRC.GetHash(Path.GetFileName(fullPath));
            int oldOffset  = 0;

            var indexPath = string.Format(Info.indexDir, indexName);

            try
            {
                using (var index = File.Open(indexPath, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(index))
                    {
                        using (BinaryWriter bw = new BinaryWriter(index))
                        {
                            br.BaseStream.Seek(1036, SeekOrigin.Begin);
                            int numOfFiles = br.ReadInt32();

                            br.BaseStream.Seek(2048, SeekOrigin.Begin);
                            for (int i = 0; i < numOfFiles; br.ReadBytes(4), i += 16)
                            {
                                int fileNameHash = br.ReadInt32();

                                if (fileNameHash == fileHash)
                                {
                                    int folderPathHash = br.ReadInt32();

                                    if (folderPathHash == folderHash)
                                    {
                                        oldOffset = br.ReadInt32();
                                        bw.BaseStream.Seek(br.BaseStream.Position - 4, SeekOrigin.Begin);
                                        bw.Write(offset / 8);
                                        break;
                                    }
                                    else
                                    {
                                        br.ReadBytes(4);
                                    }
                                }
                                else
                                {
                                    br.ReadBytes(8);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DisplayError(e, "Index File", false);
            }

            return(oldOffset);
        }
예제 #2
0
        /// <summary>
        /// Updates the .index files offset for a given item.
        /// </summary>
        /// <param name="offset">The new offset to be used.</param>
        /// <param name="fullPath">The internal path of the file whos offset is to be updated.</param>
        /// <returns>The offset which was replaced.</returns>
        public static int UpdateIndex(long offset, string fullPath)
        {
            var folderHash = FFCRC.GetHash(fullPath.Substring(0, fullPath.LastIndexOf("/")));
            var fileHash   = FFCRC.GetHash(Path.GetFileName(fullPath));
            int oldOffset  = 0;

            try
            {
                using (var index = File.Open(Info.indexDir, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(index))
                    {
                        using (BinaryWriter bw = new BinaryWriter(index))
                        {
                            br.BaseStream.Seek(1036, SeekOrigin.Begin);
                            int numOfFiles = br.ReadInt32();

                            br.BaseStream.Seek(2048, SeekOrigin.Begin);
                            for (int i = 0; i < numOfFiles; br.ReadBytes(4), i += 16)
                            {
                                int fileNameHash = br.ReadInt32();

                                if (fileNameHash == fileHash)
                                {
                                    int folderPathHash = br.ReadInt32();

                                    if (folderPathHash == folderHash)
                                    {
                                        oldOffset = br.ReadInt32();
                                        bw.BaseStream.Seek(br.BaseStream.Position - 4, SeekOrigin.Begin);
                                        bw.Write(offset / 8);
                                        break;
                                    }
                                    else
                                    {
                                        br.ReadBytes(4);
                                    }
                                }
                                else
                                {
                                    br.ReadBytes(8);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("[Helper] Error Accessing Index File \n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(oldOffset);
        }
예제 #3
0
        /// <summary>
        /// Updates the .index2 files offset for a given item.
        /// </summary>
        /// <param name="offset">The new offset to be used.</param>
        /// <param name="fullPath">The internal path of the file whos offset is to be updated.</param>
        /// <returns>The offset which was replaced.</returns>
        public static void UpdateIndex2(long offset, string fullPath, string indexName)
        {
            var pathHash = FFCRC.GetHash(fullPath);

            var index2Path = string.Format(Info.index2Dir, indexName);

            try
            {
                using (var index = File.Open(index2Path, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(index))
                    {
                        using (BinaryWriter bw = new BinaryWriter(index))
                        {
                            br.BaseStream.Seek(1036, SeekOrigin.Begin);
                            int numOfFiles = br.ReadInt32();

                            br.BaseStream.Seek(2048, SeekOrigin.Begin);
                            for (int i = 0; i < numOfFiles; i += 8)
                            {
                                int fullPathHash = br.ReadInt32();

                                if (fullPathHash == pathHash)
                                {
                                    bw.BaseStream.Seek(br.BaseStream.Position, SeekOrigin.Begin);
                                    bw.Write((int)(offset / 8));
                                    break;
                                }
                                else
                                {
                                    br.ReadBytes(4);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DisplayError(e, "Index 2 File", false);
            }
        }
예제 #4
0
        /// <summary>
        /// Updates the .index2 files offset for a given item.
        /// </summary>
        /// <param name="offset">The new offset to be used.</param>
        /// <param name="fullPath">The internal path of the file whos offset is to be updated.</param>
        /// <returns>The offset which was replaced.</returns>
        public static void UpdateIndex2(long offset, string fullPath)
        {
            var pathHash = FFCRC.GetHash(fullPath);

            try
            {
                using (var index = File.Open(Info.index2Dir, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(index))
                    {
                        using (BinaryWriter bw = new BinaryWriter(index))
                        {
                            br.BaseStream.Seek(1036, SeekOrigin.Begin);
                            int numOfFiles = br.ReadInt32();

                            br.BaseStream.Seek(2048, SeekOrigin.Begin);
                            for (int i = 0; i < numOfFiles; i += 8)
                            {
                                int fullPathHash = br.ReadInt32();

                                if (fullPathHash == pathHash)
                                {
                                    bw.BaseStream.Seek(br.BaseStream.Position, SeekOrigin.Begin);
                                    bw.Write((int)(offset / 8));
                                    break;
                                }
                                else
                                {
                                    br.ReadBytes(4);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("[Helper] Error Accessing Index 2 File \n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #5
0
        /// <summary>
        /// Gets the offset of the item data.
        /// </summary>
        /// <remarks>
        /// Used to obtain the offset of the items IMC, MTRL, MDL, and TEX data
        /// </remarks>
        /// <param name="folderHash">The hash value of the internal folder path.</param>
        /// <param name="fileHash">The hash value of the internal file path.</param>
        /// <returns>The offset in which the items data is located</returns>
        public static bool IsActive(string fullPath, string indexName)
        {
            var folderHash = FFCRC.GetHash(fullPath.Substring(0, fullPath.LastIndexOf("/")));
            var fileHash   = FFCRC.GetHash(Path.GetFileName(fullPath));

            int itemOffset = 0;

            var indexPath = string.Format(Info.indexDir, indexName);

            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(indexPath)))
                {
                    br.BaseStream.Seek(1036, SeekOrigin.Begin);
                    int numOfFiles = br.ReadInt32();

                    br.BaseStream.Seek(2048, SeekOrigin.Begin);
                    for (int i = 0; i < numOfFiles; br.ReadBytes(4), i += 16)
                    {
                        int fileNameHash = br.ReadInt32();

                        if (fileNameHash == fileHash)
                        {
                            int folderPathHash = br.ReadInt32();

                            if (folderPathHash == folderHash)
                            {
                                itemOffset = br.ReadInt32() * 8;
                                break;
                            }
                            else
                            {
                                br.ReadBytes(4);
                            }
                        }
                        else
                        {
                            br.ReadBytes(8);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DisplayError(e, "Index File", false);
            }

            int datNum = ((itemOffset / 8) & 0x0F) / 2;

            if (indexName.Equals(Strings.ItemsDat) && datNum >= 4)
            {
                return(true);
            }
            else if (indexName.Equals(Strings.UIDat) && datNum >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }