public void FromStream_ShouldNotThrow_Version1BigEndian() { using (var fileStream = File.OpenRead("TestResources\\Version1BigEndian.bmd")) { var script = MessageScript.FromStream(fileStream); } }
public static Stream RandomizeMessageScript(Stream stream) { var messageScript = MessageScript.FromStream(stream, true); RandomizeMessageScript(messageScript); return(messageScript.ToStream()); }
public static Stream ReplaceMessageScript(Stream stream) { var messageScript = MessageScript.FromStream(stream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true); ReplaceMessageScript(messageScript); return(messageScript.ToStream()); }
public static Stream FixMessageScript(Stream stream, Stream originalStream) { var messageScript = MessageScript.FromStream(stream, true); var originalMessageScript = MessageScript.FromStream(originalStream, true); FixMessageScript(messageScript, originalMessageScript); return(messageScript.ToStream()); }
public static Stream FixMessageScript(Stream stream, Stream originalStream) { var messageScript = MessageScript.FromStream(stream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true); var originalMessageScript = MessageScript.FromStream(originalStream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true); FixMessageScript(messageScript, originalMessageScript); return(messageScript.ToStream()); }
static void ExtractMessageScript(string file, Stream stream, string parentArchiveFile) { string prettyFileName; if (parentArchiveFile == null) { prettyFileName = file.Remove(0, DirectoryPath.Length); } else { prettyFileName = Path.Combine(parentArchiveFile, file); } // print some useful info if (parentArchiveFile == null) { Console.WriteLine($"Processing file: {prettyFileName}"); } else { Console.WriteLine($"Processing archive file: {prettyFileName}"); } // extract script MessageScript script = null; string fileExtension = Path.GetExtension(file); // Check if it is a plain message script file if (fileExtension.Equals(".bmd", StringComparison.InvariantCultureIgnoreCase)) { script = MessageScript.FromStream(stream, FormatVersion.Detect, Encoding, true); } // Check if it is a flow script file that can maybe contain a message script else if (fileExtension.Equals(".bf", StringComparison.InvariantCultureIgnoreCase)) { var flowScriptBinary = FlowScriptBinary.FromStream(stream, true); if (flowScriptBinary.MessageScriptSection != null) { script = MessageScript.FromBinary(flowScriptBinary.MessageScriptSection, FormatVersion.Detect, Encoding); } else { return; } } if (script != null) { // We have found a script, yay! Console.WriteLine("Writing message script to file..."); if (UseDecompiler) { WriteMessageScriptWithDecompiler(prettyFileName, script); } else { WriteMessageScript(prettyFileName, script); } } else { // Try to open the file as an archive if (!Archive.TryOpenArchive(stream, out var archive)) { // If we can't open the file as an archive, try brute force scanning if it is enabled if (EnableBruteforceScanning && (BruteforceExclusionList == null || BruteforceExclusionList != null && !BruteforceExclusionList.Any(x => x.Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase))) && (BruteforceInclusionList == null || BruteforceInclusionList != null && BruteforceInclusionList.Any(x => x.Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase))) ) { Console.WriteLine($"Bruteforce scanning..."); var scanCancel = new CancellationTokenSource(); var scanTask = Task.Factory.StartNew(() => ScanForMessageScripts(prettyFileName, stream, scanCancel.Token)); while (!scanTask.IsCompleted) { // Don't want to block, so wait for key to be available if (Console.KeyAvailable) { // Blocking is fine after this point var key = Console.ReadKey(true); if (key.Key == ConsoleKey.S) { Console.WriteLine("Do you want to skip scanning this file? Y/N"); if (Console.ReadKey(true).Key == ConsoleKey.Y) { scanCancel.Cancel(); Console.WriteLine("Do you want to add this file extension to the list of excluded files? Y/N"); if (Console.ReadKey(true).Key == ConsoleKey.Y) { if (BruteforceExclusionList == null) { BruteforceExclusionList = new List <string>(); } BruteforceExclusionList.Add(Path.GetExtension(prettyFileName)); } } } } } } } else { foreach (var entry in archive) { ExtractMessageScript(entry, archive.OpenFile(entry), prettyFileName); } } } }