Esempio n. 1
0
        /// <summary>
        /// Searches for a file entry with matching file name and parses the resource data for that file
        /// </summary>
        /// <typeparam name="T">Type of <see cref="GameResource"/> that will be returned</typeparam>
        /// <param name="fileName">Name of the file to search for</param>
        /// <param name="matchFileExtension">True if the file name should have a matching file extension, or false to ignore the file extension</param>
        /// <returns>The parsed game resource object, or null otherwise</returns>
        public T GetFileAsResource <T>(string fileName, bool matchFileExtension = false) where T : GameResource
        {
            // Search for file entry with matching file name.
            int index = FindFileFromName(fileName, matchFileExtension);

            if (index == -1)
            {
                // A file entry with matching file name was not found.
                return(null);
            }

            // Decompress the file data.
            byte[] decompressedData = DecompressFileEntry(index);
            if (decompressedData == null)
            {
                // Failed to decompress the file data.
                return(null);
            }

            // Parse the resource game and return the object.
            return((T)GameResource.FromGameResource(decompressedData, this.fileEntries[index].FileName,
                                                    new DatumIndex(this.ArchiveId, this.fileEntries[index].FileId), this.fileEntries[index].FileType, this.Endian == Endianness.Big));
        }
Esempio n. 2
0
        /// <summary>
        ///  Parses the resource data for the file with the specified file id
        /// </summary>
        /// <typeparam name="T">Type of <see cref="GameResource"/> that will be returned</typeparam>
        /// <param name="fileId">File id of the file to parse</param>
        /// <returns>The parsed game resource object, or null otherwise</returns>
        public T GetFileAsResource <T>(uint fileId) where T : GameResource
        {
            // Make sure we have a file id entry in the dictionary.
            if (this.fileEntryLookupDictionary.ContainsKey(fileId) == false)
            {
                // No dictionary entry for this file id.
                return(null);
            }

            // Get the index of the file from the file id.
            int fileIndex = this.fileEntryLookupDictionary[fileId];

            // Decompress the file data.
            byte[] decompressedData = DecompressFileEntry(fileIndex);
            if (decompressedData == null)
            {
                // Failed to decompress the file data.
                return(null);
            }

            // Parse the resource game and return the object.
            return((T)GameResource.FromGameResource(decompressedData, this.fileEntries[fileIndex].FileName,
                                                    new DatumIndex(this.ArchiveId, this.fileEntries[fileIndex].FileId), this.fileEntries[fileIndex].FileType, this.Endian == Endianness.Big));
        }