コード例 #1
0
 public override void ReadIndex()
 {
     ReadEntries();
     if (mEntries != null)
     {
         int numFiles = mEntries.GetUpperBound(0) + 1;
         mFileCount = numFiles;
         if (IsValidIndex)
         {
             Files = new BF.File[numFiles];
             for (int i = 0; i < numFiles; i++)
             {
                 BF.File tFile = new BF.File(mParentBigFile, this, mEntries[i], mNameHashPosition, mOffsetPosition, mLengthPosition);
                 Files[i] = tFile;
                 if (i > 0)
                 {
                     Files[i - 1].Length = (int)(Files[i].Offset - Files[i - 1].Offset);
                 }
                 if (i == (numFiles - 1))
                 {
                     Files[i].Length = (int)(mParentBigFile.FileSize - Files[i].Offset);
                 }
                 if (i > 0)
                 {
                     mLoadedPercent = (((float)i / (float)numFiles) * READ_CONTENT_PERCENT) + READ_INDEX_PERCENT;
                 }
             }
         }
     }
     else
     {
         mFileCount = 0;
     }
 }
        protected int GetEndOfIndex(BF.File checkFile)
        {
            int endOfIndexOffset = 0;

            FileStream   iStream;
            BinaryReader iReader;

            try
            {
                iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                iReader = new BinaryReader(iStream);
                iStream.Seek(checkFile.Offset, SeekOrigin.Begin);

                //read the count of entries in the index for this file
                int numEntries = iReader.ReadUInt16();
                endOfIndexOffset = (numEntries * mIndexEntryLength)
                                   - ((numEntries * mIndexEntryLength) % mIndexBlockSize)
                                   + mIndexBlockSize;

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new FileReadException
                          ("Failed to read file " + Name + "\r\n" +
                          "The specific error message is: \r\n" +
                          ex.Message
                          );
            }

            return(endOfIndexOffset);
        }
        public override void ReadIndex()
        {
            mEntryOffsets    = new List <int>();
            mFileHashedNames = new List <string>();
            mFileOffsets     = new List <int>();
            mFileLengths     = new List <int>();

            ReadEntries();
            int numFiles = mEntries.GetUpperBound(0) + 1;

            mFileCount = numFiles;
            if (IsValidIndex)
            {
                Files = new BF.File[numFiles];
                for (int i = 0; i < numFiles; i++)
                {
                    BF.File tFile = new BF.BloodOmen2WrappedFile(mParentBigFile, this, mEntries[i], mFileHashedNames[i], mFileOffsets[i], mFileLengths[i]);
                    Files[i] = tFile;
                    if (i > 0)
                    {
                        mLoadedPercent = (((float)i / (float)numFiles) * READ_CONTENT_PERCENT) + READ_INDEX_PERCENT;
                    }
                }
            }

            mEntryOffsets    = null;
            mFileHashedNames = null;
            mFileOffsets     = null;
            mFileLengths     = null;
        }
コード例 #4
0
        protected int GetRealHeaderLocation(BF.File checkFile)
        {
            int          headerLocation = 0;
            FileStream   iStream;
            BinaryReader iReader;

            try
            {
                iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                iReader = new BinaryReader(iStream);
                iStream.Seek(checkFile.Offset + mPointerOffset, SeekOrigin.Begin);

                //Read the number of bytes to jump ahead
                int numBytes = iReader.ReadUInt16();
                headerLocation = numBytes + mPointerOffset;

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new FileReadException
                          ("Failed to read file " + Name + "\r\n" +
                          "The specific error message is: \r\n" +
                          ex.Message
                          );
            }

            return(headerLocation);
        }
        public override string GetInternalName(BF.File checkFile)
        {
            return("");

            int    nameOffset   = mNameOffset;
            string internalName = "";

            Stream       iStream;
            BinaryReader iReader;

            try
            {
                if (checkFile.GetType() == typeof(CompressedFile))
                {
                    iStream = new MemoryStream(checkFile.Length);
                    CompressedFile compressedCheckFile = (CompressedFile)checkFile;
                    compressedCheckFile.ExportToStream(iStream);
                    iStream.Seek(0, SeekOrigin.Begin);
                    iReader = new BinaryReader(iStream);
                    iStream.Seek(nameOffset, SeekOrigin.Begin);
                }
                else
                {
                    iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                    iStream.Seek(checkFile.Offset, SeekOrigin.Begin);
                    iReader = new BinaryReader(iStream);
                    iStream.Seek(checkFile.Offset + nameOffset, SeekOrigin.Begin);
                }

                byte[] nameBuffer = sanitizeByteArray(iReader.ReadBytes(8), (byte)95);
                internalName = new string(Encoding.ASCII.GetChars(nameBuffer, 0, 8));
                internalName = internalName.Trim(new char[] { (char)'_' });
                internalName = internalName.ToLower();

                //String strModelName = new String(iReader.ReadChars(10)); // Need to check
                //try
                //{
                //    internalName = strModelName.Substring(0, strModelName.IndexOf('\0'));
                //}
                //catch
                //{
                //    internalName = strModelName;
                //}

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new FileReadException
                          ("Failed to read file " + Name + "\r\n" +
                          "The specific error message is: \r\n" +
                          ex.Message
                          );
            }
            return(internalName);
        }
コード例 #6
0
 public void AddFile(BF.File whichFile)
 {
     if (mFilenames.Contains(whichFile.Name + "." + whichFile.FileExtension))
     {
         whichFile.Name = GetNextUnusedName(mFilenames, whichFile);
     }
     mFiles.Add(whichFile);
     mFilenames.Add(whichFile.Name + "." + whichFile.FileExtension, mFiles.Count - 1);
 }
コード例 #7
0
 //for sorting
 public int CompareTo(object compObj)
 {
     if (!(compObj is BF.File))
     {
         throw new InvalidCastException("Can't compare BigFile File class with other classes.");
     }
     BF.File compFile = (BF.File)compObj;
     return(this.Name.CompareTo(compFile.Name));
 }
コード例 #8
0
        protected string GetSelectedItemInfo(TreeView tv)
        {
            string fullPath  = tv.SelectedNode.FullPath;
            int    padLength = tv.Nodes[0].FullPath.Length;

            fullPath = fullPath.Substring(padLength);

            //return nothing if nothing is selected
            if (tv.SelectedNode == null)
            {
                //MessageBox.Show("No item is currently selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DisableExportCurrent();
                DisableExportDirectory();
                DisableReplace();
                DisableHexEdit();
                return(null);
            }
            if ((mTVLookupTable != null) && (fullPath.Trim() != "") && (mTVLookupTable.Contains(fullPath)) && (tv.SelectedNode.GetNodeCount(false) == 0))
            {
                //a file is selected
                BF.File selectedFile = (BF.File)mTVLookupTable[fullPath];
                EnableExportCurrent();
                DisableExportDirectory();
                if ((selectedFile != null) && (selectedFile.CanBeReplaced))
                {
                    EnableReplace();
                    EnableHexEdit();
                }
                else
                {
                    DisableReplace();
                    DisableHexEdit();
                }
                return(selectedFile.GetInfo());
            }
            else
            {
                //a node is selected, so either return information about the entire bigfile or the currently-selected
                //directory
                DisableExportCurrent();
                EnableExportDirectory();
                DisableReplace();
                DisableHexEdit();
                if (fullPath.Contains("\\"))
                {
                    BF.Directory selectedDir = (BF.Directory)mTVLookupTable[fullPath + "\\"];
                    return(selectedDir.GetInfo());
                }
                else
                {
                    return(mBigFile.GetInfo());
                }
            }

            return(null);
        }
        public override string GetInternalName(BF.File checkFile)
        {
            int    endOfIndexOffset = GetEndOfIndex(checkFile);
            int    nameOffset       = mNameOffset;
            string internalName     = "";

            FileStream   iStream;
            BinaryReader iReader;

            if (NameOffsetIsPointer)
            {
                try
                {
                    iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                    iReader = new BinaryReader(iStream);
                    iStream.Seek(checkFile.Offset + endOfIndexOffset + nameOffset, SeekOrigin.Begin);

                    nameOffset = iReader.ReadUInt16();

                    iReader.Close();
                    iStream.Close();
                }
                catch (Exception ex)
                {
                    throw new FileReadException
                              ("Failed to read file " + Name + "\r\n" +
                              "The specific error message is: \r\n" +
                              ex.Message
                              );
                }
            }

            try
            {
                iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                iReader = new BinaryReader(iStream);
                iStream.Seek(checkFile.Offset + endOfIndexOffset + nameOffset, SeekOrigin.Begin);

                byte[] nameBuffer = sanitizeByteArray(iReader.ReadBytes(8), (byte)95);
                internalName = new string(Encoding.ASCII.GetChars(nameBuffer, 0, 8));

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new FileReadException
                          ("Failed to read file " + Name + "\r\n" +
                          "The specific error message is: \r\n" +
                          ex.Message
                          );
            }
            return(internalName);
        }
コード例 #10
0
        protected string GetNextUnusedName(Hashtable currentList, BF.File currentFile)
        {
            int    number  = 0;
            string newName = currentFile.Name;

            do
            {
                newName = currentFile.Name + "-duplicate-" + string.Format("{0:000}", number);
                number++;
            } while (currentList.Contains(newName + "." + currentFile.FileExtension));

            return(newName);
        }
        public override void ReadIndex()
        {
            ReadEntries();
            int numFiles = mEntries.GetUpperBound(0) + 1;

            Files = new BF.File[numFiles];
            for (int i = 0; i < numFiles; i++)
            {
                BF.File tFile = new BF.File(mParentBigFile, this, mEntries[i], mHashes[i], mOffsetPosition, mLengthPosition);
                Files[i] = tFile;
                if (i > 0)
                {
                    mLoadedPercent = (((float)i / numFiles) * READ_CONTENT_PERCENT) + READ_INDEX_PERCENT;
                }
            }
        }
        public override bool CheckType(BF.File checkFile)
        {
            byte[] hashedNameBytes = BLD.HexConverter.HexStringToBytes(checkFile.HashedName);
            if ((hashedNameBytes[hashedNameBytes.Length - 1] & 7) != 0)
            {
                return(false);
            }

            try
            {
                int realHeaderLocation = GetRealHeaderLocation(checkFile);
                return(CompareHeaders(checkFile, realHeaderLocation));
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #13
0
        protected BF.File GetSelectedFile(TreeView tv)
        {
            //return nothing if nothing is selected
            if (tv.SelectedNode == null)
            {
                return(null);
            }

            string fullPath  = tv.SelectedNode.FullPath;
            int    padLength = tv.Nodes[0].FullPath.Length;

            fullPath = fullPath.Substring(padLength);

            if (tv.SelectedNode.GetNodeCount(false) == 0)
            {
                //a file is selected
                BF.File selectedFile = (BF.File)mTVLookupTable[fullPath];
                return(selectedFile);
            }

            return(null);
        }
コード例 #14
0
        public override void ReadIndex()
        {
            ReadEntries();
            int numFiles = mEntries.GetUpperBound(0) + 1;

            Files = new BF.File[numFiles];
            for (int i = 0; i < numFiles; i++)
            {
                BF.File tFile;
                if (mEntries[i][mCompressedLengthPosition] > 0)
                {
                    tFile = new BF.SR1Proto1CompressedFile(mParentBigFile, this, mEntries[i], mNameHashPosition, mOffsetPosition, mLengthPosition, mCompressedLengthPosition);
                }
                else
                {
                    tFile = new BF.File(mParentBigFile, this, mEntries[i], mNameHashPosition, mOffsetPosition, mLengthPosition);
                }
                Files[i] = tFile;
                if (i > 0)
                {
                    mLoadedPercent = (((float)i / (float)numFiles) * READ_CONTENT_PERCENT) + READ_INDEX_PERCENT;
                }
            }
        }
コード例 #15
0
 public void LoadFile(string fileName, CDBigFile.File editFile, bool useStreamingMode)
 {
     mBigFilePath = fileName;
     mEditFile    = editFile;
     hpHex.Read(fileName, editFile.Offset, editFile.Length, useStreamingMode);
 }
コード例 #16
0
        public override bool CheckType(BF.File checkFile)
        {
            int realHeaderLocation = GetRealHeaderLocation(checkFile);

            return(CompareHeaders(checkFile, realHeaderLocation + mHeaderOffset));
        }
コード例 #17
0
 //in this generic class, a type match is always true
 public virtual bool CheckType(BF.File checkFile)
 {
     return(true);
 }
コード例 #18
0
 //very few subclasses will implement this, but it is handy
 public virtual string GetInternalName(BF.File checkFile)
 {
     return("");
 }
コード例 #19
0
        public virtual bool CompareHeaders(BF.File checkFile, int offset)
        {
            bool matchFound = true;

            //if the header data has already been read into the file, use its copy
            if (offset == 0)
            {
                if (mHeader.GetUpperBound(0) > checkFile.RawHeaderData.GetUpperBound(0))
                {
                    return(false);
                }
                for (int i = 0; i <= mHeader.GetUpperBound(0); i++)
                {
                    if (mHeader[i] != checkFile.RawHeaderData[i])
                    {
                        matchFound = false;
                    }
                }
            }
            //otherwise read the appropriate bytes
            else
            {
                if ((offset + mHeader.GetUpperBound(0) > checkFile.Length))
                {
                    return(false);
                }

                byte[] headerFromFile = new byte[mHeader.GetUpperBound(0) + 1];

                FileStream   iStream;
                BinaryReader iReader;

                try
                {
                    iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                    iReader = new BinaryReader(iStream);
                    iStream.Seek(checkFile.Offset + offset, SeekOrigin.Begin);

                    //read as many bytes as the header should hold
                    iStream.Read(headerFromFile, 0, headerFromFile.GetUpperBound(0) + 1);
                    for (int i = 0; i <= headerFromFile.GetUpperBound(0); i++)
                    {
                        if (mHeader[i] != headerFromFile[i])
                        {
                            matchFound = false;
                        }
                    }

                    iReader.Close();
                    iStream.Close();
                }
                catch (Exception ex)
                {
                    throw new FileReadException
                              ("Failed to read file " + Name + "\r\n" +
                              "The specific error message is: \r\n" +
                              ex.Message
                              );
                }
            }

            return(matchFound);
        }
コード例 #20
0
 public override bool CheckType(BF.File checkFile)
 {
     return(CompareHeaders(checkFile, mHeaderOffset));
 }
        public override bool CheckType(BF.File checkFile)
        {
            int endOfIndexOffset = GetEndOfIndex(checkFile);

            return(CompareHeaders(checkFile, endOfIndexOffset + mHeaderOffset));
        }
        protected int GetRealHeaderLocation(BF.File checkFile)
        {
            int          headerLocation = 0;
            Stream       iStream;
            BinaryReader iReader;

            try
            {
                if (checkFile.GetType() == typeof(CompressedFile))
                {
                    iStream = new MemoryStream(checkFile.Length);
                    CompressedFile compressedCheckFile = (CompressedFile)checkFile;
                    compressedCheckFile.ExportToStream(iStream);
                    iStream.Seek(0, SeekOrigin.Begin);
                }
                else
                {
                    iStream = new FileStream(checkFile.ParentBigFile.Path, FileMode.Open, FileAccess.Read);
                    iStream.Seek(checkFile.Offset, SeekOrigin.Begin);
                }

                iReader = new BinaryReader(iStream);

                Int32          nameOffsetLocation = 0;
                Int32          nameOffset         = 0;
                UInt32         startPosition      = (UInt32)iReader.BaseStream.Position;
                UInt32         bytesRead          = 0;
                RelativeStream relStream          = new RelativeStream(iReader, startPosition);

                relStream.Pos  = 0;
                relStream.Pos += 0x04;
                UInt32 regionCount = iReader.ReadUInt32();

                // AMF 02/08/14 - 500 seemed like a reasonable maximum
                if (regionCount > 500)
                {
                    throw new Exception("Too many regions to scan.");
                }

                UInt32   regionPosition      = 0;
                UInt32[] regionSizes         = new UInt32[regionCount];
                UInt32[] regionPositions     = new UInt32[regionCount];
                UInt32[] objectDataSizes     = new UInt32[regionCount];
                UInt32[] objectDataPositions = new UInt32[regionCount];
                for (UInt32 r = 0; r < regionCount; r++)
                {
                    regionSizes[r]     = iReader.ReadUInt32();
                    regionPositions[r] = regionPosition;
                    regionPosition    += regionSizes[r];
                    relStream.Pos     += 0x08;
                }

                UInt32 regionDataSize      = regionCount * 0x0C;
                UInt32 pointerDataPosition = (regionDataSize & 0x00000003) + ((regionDataSize + 0x17) & 0xFFFFFFF0);
                for (UInt32 r = 0; r < regionCount; r++)
                {
                    relStream.Pos = pointerDataPosition;
                    UInt32 pointerCount       = iReader.ReadUInt32();
                    UInt32 pointerDataSize    = pointerCount * 0x04;
                    UInt32 objectDataPosition = pointerDataPosition + ((pointerDataSize + 0x13) & 0xFFFFFFF0);
                    UInt32 objectDataSize     = (regionSizes[r] + 0x0F) & 0xFFFFFFF0;

                    objectDataSizes[r]     = objectDataSize;
                    objectDataPositions[r] = objectDataPosition;

                    relStream.Pos = objectDataPosition;
                    Byte[] objectData = iReader.ReadBytes((Int32)objectDataSize);
                    bytesRead += objectDataSize;

                    if (headerLocation == 0 && bytesRead >= mHeaderOffset)
                    {
                        Int64 overshot = (Int64)iReader.BaseStream.Position - (Int32)objectDataSize;
                        overshot      += (Int64)mHeaderOffset;
                        headerLocation = ((Int32)overshot) - ((Int32)startPosition + 0x04);
                    }

                    if (nameOffsetLocation == 0 && bytesRead >= mNamePointerOffset)
                    {
                        Int64 overshot = (Int64)iReader.BaseStream.Position - (Int32)objectDataSize;
                        overshot          += (Int64)mNamePointerOffset;
                        nameOffsetLocation = ((Int32)overshot) - ((Int32)startPosition + 0x04);
                    }

                    relStream.Pos = pointerDataPosition + 0x04;
                    UInt32[] pointers = new UInt32[pointerCount];
                    for (UInt32 p = 0; p < pointerCount; p++)
                    {
                        pointers[p] = iReader.ReadUInt32();
                    }

                    UInt32[] addresses = new UInt32[pointerCount];
                    for (UInt32 p = 0; p < pointerCount; p++)
                    {
                        relStream.Pos = objectDataPosition + pointers[p];

                        bool readingNameOffset = (relStream.Pos == nameOffsetLocation);

                        UInt32 value1 = iReader.ReadUInt32();
                        UInt32 value2 = value1 & 0x003FFFFF;
                        UInt32 value3 = value1 >> 0x16;

                        pointers[p] += regionPositions[r];
                        addresses[p] = regionPositions[value3] + value2;

                        if (readingNameOffset)
                        {
                            nameOffset = (Int32)addresses[p];
                        }
                    }

                    pointerDataPosition = objectDataPosition + objectDataSize;

                    if (headerLocation != 0 && nameOffsetLocation != 0)
                    {
                        break;
                    }
                }

                for (UInt32 r = 0; r < regionCount; r++)
                {
                    if (nameOffset < (Int32)objectDataSizes[r])
                    {
                        nameOffset += (Int32)objectDataPositions[r];
                        break;
                    }

                    if (r == (regionCount - 1))
                    {
                        nameOffset = 0;
                    }

                    nameOffset -= (Int32)objectDataSizes[r];
                }

                mNameOffset = nameOffset;

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new FileReadException
                          ("Failed to read file " + Name + "\r\n" +
                          "The specific error message is: \r\n" +
                          ex.Message
                          );
            }

            return(headerLocation);
        }