public void FromFile_ShouldNotThrow_Batch()
 {
     foreach (var path in Directory.EnumerateFiles("TestResources\\Batch\\", "*.bf"))
     {
         var script = FlowScript.FromFile(path);
     }
 }
예제 #2
0
        public static void RandomizeFlowScript(string path)
        {
            var flowScript = FlowScript.FromFile(path);

            RandomizeFlowScript(flowScript);
            flowScript.ToFile(path + ".randomized");
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine($"Missing filename");
                return;
            }

            var filePath    = args[0];
            var outFilePath = $"{Path.GetFileNameWithoutExtension( args[ 0 ] )}_procedure_ids.txt";

            if (filePath.EndsWith("bf", StringComparison.InvariantCultureIgnoreCase))
            {
                var script = FlowScript.FromFile(filePath);
                WriteProcedureIds(outFilePath, script.Procedures.Select(x => x.Name));
            }
            else if (filePath.EndsWith("flow"))
            {
                var compilationUnit = FlowScriptParserHelper.ParseCompilationUnit(File.OpenText(filePath));
                WriteProcedureIds(outFilePath,
                                  compilationUnit.declarationStatement().Where(x => x.procedureDeclarationStatement() != null && x.procedureDeclarationStatement().ProcedureIdentifier() != null)
                                  .Select(x => x.procedureDeclarationStatement().ProcedureIdentifier().Symbol.Text));
            }
            else
            {
                Console.WriteLine("Can't detect input type (unknown extension)");
                return;
            }
        }
예제 #4
0
        public static void ReplaceFlowScript(string path, string originalPath)
        {
            var flowScript = FlowScript.FromFile(path);

            ReplaceFlowScript(flowScript);
            flowScript.ToFile(path + ".Replaced");
        }
예제 #5
0
        public static void FixFlowScript(string path, string originalPath)
        {
            var flowScript         = FlowScript.FromFile(path);
            var originalFlowScript = FlowScript.FromFile(originalPath);

            FixFlowScript(flowScript, originalFlowScript);
            flowScript.ToFile(path + ".Fixd");
        }
        private FlowScript FromFile_ResultNotNullAndFormatIsEqualToParameter(FormatVersion version, FormatVersion actualVersion)
        {
            var script = FlowScript.FromFile($"TestResources\\{actualVersion}.bf", null, version);

            Assert.IsNotNull(script, "Script object should not be null");
            Assert.AreEqual((FormatVersion)actualVersion, script.FormatVersion);

            return(script);
        }
예제 #7
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine($"Missing filename");
                return;
            }

            MessageScript msg      = null;
            var           filePath = args[0];

            if (filePath.EndsWith("bf", StringComparison.InvariantCultureIgnoreCase))
            {
                msg = FlowScript.FromFile(filePath).MessageScript;
            }
            else if (filePath.EndsWith("bmd"))
            {
                msg = MessageScript.FromFile(args[0]);
            }
            else if (filePath.EndsWith("msg"))
            {
                var msgCompiler = new MessageScriptCompiler(AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1);
                msg = msgCompiler.Compile(File.OpenText(filePath));
            }
            else
            {
                Console.WriteLine("Can't detect input type (unknown extension)");
                return;
            }

            using (var writer = File.CreateText($"{Path.GetFileNameWithoutExtension( args[ 0 ] )}_ids.txt"))
            {
                for (var i = 0; i < msg.Dialogs.Count; i++)
                {
                    var dialog = msg.Dialogs[i];
                    writer.WriteLine($"{i}\t\t{dialog.Name}");
                }
            }
        }
예제 #8
0
 private static IEnumerable <(FlowScript, string)> FindFlowScripts(string file, Archive archive = null, string archiveFilePath = null)
 {
     if (file.EndsWith("bf", StringComparison.InvariantCultureIgnoreCase))
     {
         if (archive == null)
         {
             yield return(FlowScript.FromFile(file, sEncoding), file);
         }
         else
         {
             yield return(FlowScript.FromStream(archive.OpenFile(file), sEncoding), Path.Combine(archiveFilePath, file));
         }
     }
     else if (archive == null ? Archive.TryOpenArchive(File.OpenRead(file), out var subArchive) : Archive.TryOpenArchive(archive.OpenFile(file), out subArchive))
     {
         foreach (string entry in subArchive)
         {
             foreach (var script in FindFlowScripts(entry, subArchive, archive == null ? file : Path.Combine(archiveFilePath, file)))
             {
                 yield return(script);
             }
         }
     }
 }
예제 #9
0
        private static bool TryDoFlowScriptDecompilation()
        {
            // Load binary file
            Logger.Info("Loading binary FlowScript file...");
            FlowScript flowScript = null;
            var        encoding   = MessageScriptEncoding;
            var        format     = GetFlowScriptFormatVersion();

            if (!TryPerformAction("Failed to load flow script from file", () => flowScript = FlowScript.FromFile(InputFilePath, encoding, format)))
            {
                return(false);
            }

            Logger.Info("Decompiling FlowScript...");

            var decompiler = new FlowScriptDecompiler();

            decompiler.SumBits = FlowScriptSumBits;
            decompiler.AddListener(Listener);

            if (LibraryName != null)
            {
                var library = LibraryLookup.GetLibrary(LibraryName);

                if (library == null)
                {
                    Logger.Error("Invalid library name specified");
                    return(false);
                }

                decompiler.Library = library;
            }

            if (!decompiler.TryDecompile(flowScript, OutputFilePath))
            {
                Logger.Error("Failed to decompile FlowScript");
                return(false);
            }

            return(true);
        }
예제 #10
0
 public void FromFile_ShouldThrowInvalidDataException_InvalidFileFormatBig()
 {
     Assert.ThrowsException <InvalidDataException>(() => FlowScript.FromFile("TestResources\\dummy_big.bin", null, FormatVersion.Unknown));
 }