private void ModifyUAsset(byte[] fileBytes, List <AudioRebuilderFileOutput> fileOutputs, AAudioBinaryFile file)
        {
            if (!TryGettingFileByExtension(TargetFileName, ".uasset", out var uAssetFilePath))
            {
                Logger.Error($"Failed to find project's original uasset! Looked for {TargetFileName} at: {ParentDirectory}");
                return;
            }

            var uassetBytes = File.ReadAllBytes(uAssetFilePath);

            uint originalExpectedSize = (uint)file.Header.FileSize + (uint)file.BytesBeforeFile.Length;
            var  originalSizeBytes    = BitConverter.GetBytes(originalExpectedSize);
            var  replacementPosition  = uassetBytes.FindSubArrayInReverse(originalSizeBytes);

            if (replacementPosition == -1)
            {
                Logger.Error($"Failed to find UAsset file size position! Looked for value {originalExpectedSize} at {uAssetFilePath}");
                return;
            }

            var offsetOverride = Settings.Parser.OverrideUAssetFileSizeOffsetFromEndOfFile;

            if (offsetOverride.HasValue)
            {
                replacementPosition = uassetBytes.Length - offsetOverride.Value;
            }

            Logger.Log($"Replacing UAsset file size expectation: {originalExpectedSize} -> {fileBytes.Length - 4}, at offset: {replacementPosition} (pos: {uassetBytes.Length - replacementPosition} from end-of-file)");

            var replacementSizeBytes = BitConverter.GetBytes((uint)(fileBytes.Length - 4));

            Buffer.BlockCopy(
                replacementSizeBytes, 0, uassetBytes,
                (int)replacementPosition,
                replacementSizeBytes.Length);

            var uassetFileOutput = new AudioRebuilderFileOutput()
            {
                Extension = ".uasset",
                FileBytes = uassetBytes,
            };

            fileOutputs.Add(uassetFileOutput);
        }
        public override void Run()
        {
            Logger.Log($"Beginning to repack {FilePathForConfig}!");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            TryLoadingProjectSettings();

            if (!GetNecessaryPaths())
            {
                return;
            }

            if (FindOriginalFile(out var originalFilePath, out var originalExtension))
            {
                return;
            }

            var parser = new FileParser();

            parser.Settings = Settings.Parser;
            parser.Logger   = Logger;

            var fileBytes       = File.ReadAllBytes(originalFilePath);
            var audioBinaryFile = parser.Parse(fileBytes);

            var fileInfo = new FileInfo(originalFilePath);
            var tracks   = new List <TemporaryTrack>();

            foreach (var entry in audioBinaryFile.MaterialSection.Entries)
            {
                tracks.Add(new TemporaryTrack()
                {
                    OriginalEntry = entry,
                    HeaderPortion = fileBytes.SubArray(entry.HeaderPosition, entry.NoStreamHeaderSize),
                    RawPortion    = fileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize),
                    ExpectedName  = $"{Path.GetFileNameWithoutExtension(fileInfo.Name)}_{entry.EntryIndex:D3}",
                    CurrentCodec  = entry.Codec,
                });
            }

            var blackboard = new Blackboard()
            {
                Settings  = _projectSettings,
                File      = audioBinaryFile,
                Logger    = Logger,
                Tracks    = tracks,
                FileBytes = fileBytes,
            };

            RunSteps(RunningDirectory, blackboard);

            fileBytes = blackboard.FileBytes;

            List <AudioRebuilderFileOutput> fileOutputs = new List <AudioRebuilderFileOutput>();

            var audioFileOutput = new AudioRebuilderFileOutput()
            {
                Extension = originalExtension,
                FileBytes = fileBytes,
            };

            fileOutputs.Add(audioFileOutput);

            GetAdditionalFileOutputsBasedOnFormat(originalFilePath, audioBinaryFile, fileBytes, fileOutputs);

            var outputFileName = Path.GetFileNameWithoutExtension(fileInfo.Name);
            var outputFolder   = RunningDirectory;

            WriteFilesTo(outputFolder, outputFileName, fileOutputs);

            var additionalPaths = _projectSettings?.AdditionalOutputFolders ?? new string[0];

            foreach (var additionalPath in additionalPaths)
            {
                if (!Directory.Exists(additionalPath))
                {
                    Logger.Warn($"Could not write files to additional output path: {additionalPath}, because it doesn't exist!");
                    continue;
                }
                WriteFilesTo(additionalPath, outputFileName, fileOutputs);
            }

            stopwatch.Stop();
            Logger.Log($"Done repacking {FilePathForConfig}! (total time: {stopwatch.Elapsed:s\\.fff}s)");
        }