public KeyResource BuildKeyResourceNew(byte[] content)
        {
            var keyResource = new KeyResource();

            int headerSize = Marshal.SizeOf(typeof(Header));
            byte[] headerContent = BinaryHelper.GetBytes(content, 0, (uint)headerSize);
            var header = _genericStructConverter.ConvertToStruct<Header>(headerContent, 0);

            uint biffEntriesCount = header.BiffEntriesCount;
            uint resourceEntriesCount = header.ResourceEntriesCount;
            uint biffEntriesOffset = header.BiffEntriesOffset;
            uint resourceEntriesOffset = header.ResourceEntriesOffset;

            string keyStructCode = string.Format(Templates.KeyStructTemplate, biffEntriesOffset, resourceEntriesOffset, biffEntriesCount, resourceEntriesCount);

            Assembly generatedAssembly = _structGenerator.GenerateStruct(keyStructCode);
            Type structType = generatedAssembly.GetType("CodeFiction.InfinityFiction.Structure.Structures.Key.KeyStruct");
            object convertToStruct = _genericStructConverter.ConvertToStruct(structType, content, 0);

            var biffEntries = (Array)convertToStruct.GetType().GetField("BiffEntries").GetValue(convertToStruct);
            var resourceEntries = (Array)convertToStruct.GetType().GetField("ResourceEntries").GetValue(convertToStruct);

            keyResource.Header = new HeaderResource();
            keyResource.BiffEntries = new BiffEntryResource[biffEntriesCount];
            keyResource.ResourceEntries = new ResourceEntryResource[resourceEntriesCount];

            _resourceConverter.Convert(header, keyResource.Header);
            _resourceConverter.Convert(typeof(BiffEntry), biffEntries, keyResource.BiffEntries);
            _resourceConverter.Convert(typeof(ResourceEntry), resourceEntries, keyResource.ResourceEntries);

            return keyResource;
        }
        public KeyResource BuildKeyResource(byte[] content)
        {
            var keyResource = new KeyResource();

            var header = _genericStructConverter.ConvertToStruct<Header>(content, 0);

            uint biffEntriesCount = header.BiffEntriesCount;
            uint resourceEntriesCount = header.ResourceEntriesCount;
            uint biffEntriesOffset = header.BiffEntriesOffset;
            uint resourceEntriesOffset = header.ResourceEntriesOffset;

            keyResource.Header = new HeaderResource();
            keyResource.BiffEntries = new BiffEntryResource[biffEntriesCount];
            keyResource.ResourceEntries = new ResourceEntryResource[resourceEntriesCount];

            uint sizeOfBiffEntry;
            const uint SizeOfResourceEntry = 14;
            unsafe
            {
                sizeOfBiffEntry = (uint)sizeof(BiffEntry);
            }

            _resourceConverter.Convert(header, keyResource.Header);
            _resourceConverter.Convert<BiffEntry, BiffEntryResource>(content, keyResource.BiffEntries, biffEntriesOffset, sizeOfBiffEntry);
            _resourceConverter.Convert<ResourceEntry, ResourceEntryResource>(content, keyResource.ResourceEntries, resourceEntriesOffset, SizeOfResourceEntry);

            return keyResource;
        }
        public KeyResource BuildKeyResourceNew2(byte[] content, Type structType)
        {
            var keyResource = new KeyResource();

            int headerSize = Marshal.SizeOf(typeof(Header));
            byte[] headerContent = BinaryHelper.GetBytes(content, 0, (uint)headerSize);
            var header = _genericStructConverter.ConvertToStruct<Header>(headerContent, 0);

            uint biffEntriesCount = header.BiffEntriesCount;
            uint resourceEntriesCount = header.ResourceEntriesCount;
            uint biffEntriesOffset = header.BiffEntriesOffset;
            uint resourceEntriesOffset = header.ResourceEntriesOffset;

            object convertToStruct = _genericStructConverter.ConvertToStruct(structType, content, 0);

            var biffEntries = (Array)convertToStruct.GetType().GetField("BiffEntries").GetValue(convertToStruct);
            var resourceEntries = (Array)convertToStruct.GetType().GetField("ResourceEntries").GetValue(convertToStruct);

            keyResource.Header = new HeaderResource();
            keyResource.BiffEntries = new BiffEntryResource[biffEntriesCount];
            keyResource.ResourceEntries = new ResourceEntryResource[resourceEntriesCount];

            _resourceConverter.Convert(header, keyResource.Header);
            _resourceConverter.Convert(typeof(BiffEntry), biffEntries, keyResource.BiffEntries);
            _resourceConverter.Convert(typeof(ResourceEntry), resourceEntries, keyResource.ResourceEntries);

            return keyResource;
        }
        private void LoadResources()
        {
            GameConfig game = _games[_gameEnum];
            _dialogFilePath = Path.Combine(_rootPath, DialogFilename);
            bool dialogfileExists = File.Exists(_dialogFilePath);
            if (!dialogfileExists)
            {
                _dialogFilePath = Path.Combine(_rootPath, "lang", "en_US", DialogFilename);
            }

            _keyResource = _keyResourceService.GetKeyResource(_gameEnum, _keyFilePath);

            foreach (var resourceEntryResource in _keyResource.ResourceEntries)
            {
                var resourceFile = new ResourceFile();
                resourceFile.Extension = resourceEntryResource.Extension;
                resourceFile.Folder = resourceEntryResource.Extension;
                resourceFile.RootFolder = resourceEntryResource.Extension;
                resourceFile.File = resourceEntryResource.FileName;
                resourceFile.ResourceEntry = true;
                _resourceFiles.Add(resourceFile);
            }

            List<string> currentExtraDirs = game.ExtraDirs.Select(GetFullPath).ToList();

            if (currentExtraDirs.IsNullOrEmpty())
            {
                // TODO: throw Exception
            }

            foreach (var extraDir in currentExtraDirs)
            {
                if (Directory.Exists(extraDir))
                {
                    _extraDirs.Add(extraDir);
                    LoadResourceFiles(extraDir, currentExtraDirs);
                }
            }

            string overrideFullPath = Path.Combine(_rootPath, OverrideFolder);
            if (Directory.Exists(overrideFullPath))
            {
                string[] overrideFiles = Directory.GetFiles(overrideFullPath);

                foreach (var overrideFile in overrideFiles)
                {
                    string fileName = Path.GetFileName(overrideFile);
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(overrideFile);
                    string extension = Path.GetExtension(overrideFile);
                    ResourceFile resourceFile = _resourceFiles.FirstOrDefault(file => file.File == fileNameWithoutExtension);

                    string overrideFolder = OverrideFolder.Split(Path.DirectorySeparatorChar).Last();

                    if (resourceFile == null)
                    {
                        resourceFile = new ResourceFile();
                        resourceFile.File = fileName;
                        resourceFile.FullPath = Path.Combine(OverrideFolder, overrideFile);
                        resourceFile.RootFolder = overrideFolder;
                        resourceFile.Folder = overrideFolder;
                        resourceFile.Extension = string.IsNullOrEmpty(extension)
                             ? string.Empty
                             : extension.ToUpper().Replace(".", string.Empty);

                        _resourceFiles.Add(resourceFile);
                    }
                    else
                    {
                        ResourceEntryResource resourceEntryResource = _keyResource.ResourceEntries.FirstOrDefault(resource => resource.FileName == fileName);
                        if (resourceEntryResource != null)
                        {
                            resourceEntryResource.HasOverride = true;
                        }
                    }
                }
            }
        }