Beispiel #1
0
        private static bool TryDoMessageScriptCompilation()
        {
            // Compile source
            Logger.Info("Compiling MessageScript...");

            var version = GetMessageScriptFormatVersion();

            if (version == AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Detect)
            {
                Logger.Error("Invalid MessageScript file format");
                return(false);
            }

            var encoding = GetEncoding();
            var compiler = new MessageScriptCompiler(GetMessageScriptFormatVersion(), encoding);

            compiler.AddListener(Listener);

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

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

                compiler.Library = library;
            }

            bool          success = false;
            MessageScript script  = null;

            try
            {
                success = compiler.TryCompile(File.OpenText(InputFilePath), out script);
            }
            catch (UnsupportedCharacterException e)
            {
                Logger.Error($"Character '{e.Character}' not supported by encoding '{e.EncodingName}'");
            }

            if (!success)
            {
                Logger.Error("One or more errors occured during compilation!");
                return(false);
            }

            // Write binary
            Logger.Info("Writing binary to file...");
            if (!TryPerformAction("An error occured while saving the file.", () => script.ToFile(OutputFilePath)))
            {
                return(false);
            }

            return(true);
        }
        public static void ParseArgs(string[] args)
        {
            var iterator = new ArgumentIterator(args);

            while (iterator.HasNext)
            {
                var arg = iterator.Current;

                switch (arg)
                {
                case "-Library":
                {
                    if (!iterator.TryGetNextArg(out var libraryName))
                    {
                        throw new MissingArgumentValueException("Library", "library name");
                    }

                    Library = LibraryLookup.GetLibrary(libraryName);
                    if (Library == null)
                    {
                        throw new InvalidLibraryException(libraryName);
                    }
                }
                break;

                case "-DocFormat":
                {
                    if (!iterator.TryGetNextArg(out var docFormatStr))
                    {
                        throw new MissingArgumentValueException("DocFormat", "documentation format name");
                    }

                    if (!Enum.TryParse <DocumentationFormat>(docFormatStr, out var docFormat))
                    {
                        throw new InvalidDocumentationFormatException(docFormatStr);
                    }

                    DocFormat = docFormat;
                }
                break;

                case "-Out":
                {
                    if (!iterator.TryGetNextArg(out var outPath))
                    {
                        throw new MissingArgumentValueException("Out", "out path");
                    }

                    OutPath = outPath;
                }
                break;
                }
            }
        }
Beispiel #3
0
        public ILibraryInformation GetLibraryInformation(string name, string aspect)
        {
            ILibraryInformation information;

            if (LibraryLookup.TryGetValue(name, out information))
            {
                return(information);
            }

            return(null);
        }
        private static bool TryDoFlowScriptCompilation()
        {
            Logger.Info("Compiling FlowScript...");

            // Get format verson
            var version = GetFlowScriptFormatVersion();

            if (version == FormatVersion.Unknown)
            {
                Logger.Error("Invalid FlowScript file format specified");
                return(false);
            }

            // Compile source
            var compiler = new FlowScriptCompiler(version);

            compiler.AddListener(Listener);
            compiler.Encoding = GetEncoding();
            compiler.EnableProcedureTracing     = FlowScriptEnableProcedureTracing;
            compiler.EnableProcedureCallTracing = FlowScriptEnableProcedureCallTracing;
            compiler.EnableFunctionCallTracing  = FlowScriptEnableFunctionCallTracing;
            compiler.EnableStackCookie          = FlowScriptEnableStackCookie;

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

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

                compiler.Library = library;
            }

            FlowScript flowScript;

            using (var file = File.Open(InputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                if (!compiler.TryCompile(file, out flowScript))
                {
                    Logger.Error("One or more errors occured during compilation!");
                    return(false);
                }
            }

            // Write binary
            Logger.Info("Writing binary to file...");
            return(TryPerformAction("An error occured while saving the file.", () => flowScript.ToFile(OutputFilePath)));
        }
        private void RunTest(string source, IEnumerable <Instruction> instructions)
        {
            var compiler = new FlowScriptCompiler(FormatVersion.Version3BigEndian);

            compiler.Library = LibraryLookup.GetLibrary("p5");
            compiler.EnableProcedureTracing = false;
            compiler.AddListener(new DebugLogListener());
            if (!compiler.TryCompile(source, out var script))
            {
                throw new Exception("Script failed to compile");
            }

            Assert.IsTrue(script.EnumerateInstructions().SequenceEqual(instructions));
        }
        public static void Main(string[] args)
        {
#if DEBUG
            var generator = new NppLibraryDocumentationGenerator(LibraryLookup.GetLibrary("p5"));
            generator.Generate("FlowScript.xml");
#else
            if (!TryParseArgs(args))
            {
                return;
            }

            var generator = LibraryDocumentationGeneratorFactory.Create(Library, DocFormat);
            generator.Generate(OutPath);
#endif
        }
        public static void Main(string[] args)
        {
#if DEBUG
            var generator = new SweetScape010EditorEnumGenerator(LibraryLookup.GetLibrary("p5"));
            generator.Generate("P5_Enums.bt");
#else
            if (!TryParseArgs(args))
            {
                Console.WriteLine(sUsage);
                return;
            }

            var generator = LibraryDocumentationGeneratorFactory.Create(sLibrary, sDocFormat);
            generator.Generate(sOutPath);
#endif
        }
Beispiel #8
0
        /// <summary>
        /// decompiles the flowscript returns true if it is successful
        /// </summary>
        private static bool TryDoFlowScriptDecompilation()
        {
            // Load binary file
            Logger.ConsoleInfo("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.ConsoleInfo("Decompiling FlowScript...");

            var decompiler = new FlowScriptDecompiler();

            decompiler.Library = library;

            decompiler.AddListener(Listener);

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

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

                decompiler.Library = library;
            }

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

            //open flow script


            return(true);
        }
Beispiel #9
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Missing directory path argument");
                return;
            }

            var directoryPath = args[0];   // @"D:\Modding\Persona 5 EU\Main game\ExtractedClean"
            var logger        = new Logger(nameof(AtlusFlowScriptExtractor));
            var listener      = new ConsoleLogListener(true, LogLevel.All);

            listener.Subscribe(logger);

            using (var streamWriter = FileUtils.CreateText("AtlusFlowScriptExtractorOutput.txt"))
            {
                foreach (var file in Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories))
                {
                    foreach (var foundScript in FindFlowScripts(file))
                    {
                        var decompiler = new FlowScriptDecompiler();
                        decompiler.AddListener(listener);
                        decompiler.Library = LibraryLookup.GetLibrary("p5");
                        decompiler.DecompileMessageScript = false;

                        if (!decompiler.TryDecompile(foundScript.Item1, out var compilationUnit))
                        {
                            logger.Error($"Failed to decompile FlowScript in: {foundScript.Item2}");
                            continue;
                        }

                        var writer = new CompilationUnitWriter();
                        streamWriter.WriteLine();
                        streamWriter.WriteLine("//");
                        streamWriter.WriteLine($"// File: {foundScript.Item2}");
                        streamWriter.WriteLine("//");
                        streamWriter.WriteLine();
                        writer.Write(compilationUnit, streamWriter);
                    }
                }
            }

            logger.Info("Done");
        }
Beispiel #10
0
        /// <summary>
        /// decompiles the messagescript returns true if it is successful
        /// </summary>
        private static bool TryDoMessageScriptDecompilation()
        {
            // load binary file
            Logger.ConsoleInfo("Loading binary MessageScript file...");
            MessageScript script   = null;
            var           encoding = MessageScriptEncoding;
            var           format   = GetMessageScriptFormatVersion();

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

            Logger.ConsoleInfo("Decompiling MessageScript...");

            if (!TryPerformAction("Failed to decompile message script to file.", () =>
            {
                using (var decompiler = new MessageScriptDecompiler(new FileTextWriter(OutputFilePath)))
                {
                    if (LibraryName != null)
                    {
                        var library = LibraryLookup.GetLibrary(LibraryName);

                        if (library == null)
                        {
                            Logger.ConsoleError("Invalid library name specified");
                        }

                        decompiler.Library = library;
                    }

                    decompiler.Decompile(script);
                }
            }))
            {
                return(false);
            }

            //open msg file

            return(true);
        }
        public string RunTest(FormatVersion version, string library, string source)
        {
            var compiler = new FlowScriptCompiler(version);

            compiler.Library = LibraryLookup.GetLibrary(library);
            compiler.EnableProcedureTracing = false;
            compiler.AddListener(new DebugLogListener());
            if (!compiler.TryCompile(source, out var script))
            {
                Console.WriteLine("Script failed to compile");
                return(null);
            }

            var textOutput  = new StringWriter();
            var interpreter = new FlowScriptInterpreter(script);

            interpreter.TextOutput = textOutput;
            interpreter.Run();
            return(textOutput.GetStringBuilder().ToString());
        }
Beispiel #12
0
        private void ToolTipIsNeeded(object sender, ToolTipNeededEventArgs e)
        {
            if (String.IsNullOrEmpty(e.HoveredWord))
            {
                return;
            }

            var library = LibraryLookup.GetLibrary(game);

            var    range       = new FastColoredTextBoxNS.Range(sender as FastColoredTextBox, e.Place, e.Place);
            string hoveredWord = range.GetFragment("[^ ( \n \r ]").Text;

            e.ToolTipTitle = hoveredWord;

            for (int i = 0; i < library.FlowScriptModules.Count; i++)
            {
                for (int j = 0; j < library.FlowScriptModules[i].Functions.Count; j++)
                {
                    e.ToolTipText = ToolTip(hoveredWord, library) + "'";
                }
            }
        }
Beispiel #13
0
        private static void Main(string[] args)
        {
            var source = @"
void Main()
{
    float x = DegreesToRadians( 0 );
    float y = DegreesToRadians( 45 );
    float z = DegreesToRadians( 0 );
    
    PUTS( ""x = %f y = %f z = %f"", x, y, z );

    CreateQuaternion( x, y, z );

    PUTS( ""x = %f y = %f z = %f w = %f"", quaternionX, quaternionY, quaternionZ, quaternionW );
}

float quaternionX;
float quaternionY;
float quaternionZ;
float quaternionW;

// Construct a new Quaternion from given Euler angles in radians. 
// The rotations will get applied in following order:
// 1. around X axis, 2. around Y axis, 3. around Z axis
// Result is stored in quaternionX/Y/Z/W
void CreateQuaternion(float rotationX, float rotationY, float rotationZ)
{
    rotationX *= 0.5f;
    rotationY *= 0.5f;
    rotationZ *= 0.5f;

    float c1 = COS(rotationX);
    float c2 = COS(rotationY);
    float c3 = COS(rotationZ);
    float s1 = SIN(rotationX);
    float s2 = SIN(rotationY);
    float s3 = SIN(rotationZ);

    quaternionW = c1 * c2 * c3 - s1 * s2 * s3;
    quaternionX = s1 * c2 * c3 + c1 * s2 * s3;
    quaternionY = c1 * s2 * c3 - s1 * c2 * s3;
    quaternionZ = c1 * c2 * s3 + s1 * s2 * c3;
}

const float PI = 3.14159265358979323846f;
float DegreesToRadians( float degrees )
{
    return degrees * PI / 180f;
}
";

            source = @"
void Main()
{
    float qX;
    float qY;
    float qZ;
    float qW;
    QuatFromEulerDegrees( 0, 45, 0, out qX, out qY, out qZ, out qW );

    PUTS( ""x = %f y = %f z = %f w = %f"", qX, qY, qZ, qW );
}

void QuatFromEulerDegrees( float x, float y, float z, out float qX, out float qY, out float qZ, out float qW )
{
	x = DegreesToRadians( x );
	y = DegreesToRadians( y );
	z = DegreesToRadians( z );
	
	QuatFromEuler( x, y, z, out qX, out qY, out qZ, out qW );
}

void QuatFromEuler( float x, float y, float z, out float qX, out float qY, out float qZ, out float qW )
{
    x *= 0.5f;
    y *= 0.5f;
    z *= 0.5f;

    float c1 = COS( x );
    float c2 = COS( y );
    float c3 = COS( z );
    float s1 = SIN( x );
    float s2 = SIN( y );
    float s3 = SIN( z );

    qW = c1 * c2 * c3 - s1 * s2 * s3;
    qX = s1 * c2 * c3 + c1 * s2 * s3;
    qY = c1 * s2 * c3 - s1 * c2 * s3;
    qZ = c1 * c2 * s3 + s1 * s2 * c3;
}

const float PI = 3.14159265358979323846f;
float DegreesToRadians( float degrees )
{
    return degrees * PI / 180f;
}
";
//            source = @"
//void Main()
//{
//    int test = 69;

//    Test( 0, out test );

//    if ( test == 1 )
//    {
//        PUTS( ""Success!!"" );
//    }
//}

//void Test( int a, out int test )
//{
//    test = 1;
//}";

            source = @"
void Main()
{
    int x = 2;
    int n = 4;
    PUTS( ""Pow( %d, %d ) = %d"", x, n, Pow( x, n ) );
}

int Pow( int x, int n )
{
    int i; /* Variable used in loop counter */
    int number = 1;

    for ( i = 0; i < n; ++i )
        number *= x;

    return number;
}";


            var compiler = new FlowScriptCompiler(FormatVersion.Version3BigEndian);

            compiler.Library = LibraryLookup.GetLibrary("p5");
            compiler.EnableProcedureTracing = false;
            compiler.AddListener(new ConsoleLogListener(true, LogLevel.All));
            if (!compiler.TryCompile(source, out var script))
            {
                Console.WriteLine("Script failed to compile");
                return;
            }

            script.ToFile("test.bf");

            var dissassembler = new FlowScriptBinaryDisassembler("test.flowasm");

            dissassembler.Disassemble(script.ToBinary());
            dissassembler.Dispose();

            var interpreter = new FlowScriptInterpreter(script);

            interpreter.Run();
        }
Beispiel #14
0
        private static bool TryDoFlowScriptCompilation()
        {
            Logger.Info("Compiling FlowScript...");

            // Get format verson
            var version = GetFlowScriptFormatVersion();

            if (version == FormatVersion.Unknown)
            {
                Logger.Error("Invalid FlowScript file format specified");
                return(false);
            }

            // Compile source
            var compiler = new FlowScriptCompiler(version);

            compiler.AddListener(Listener);
            compiler.Encoding = MessageScriptEncoding;
            compiler.EnableProcedureTracing     = FlowScriptEnableProcedureTracing;
            compiler.EnableProcedureCallTracing = FlowScriptEnableProcedureCallTracing;
            compiler.EnableFunctionCallTracing  = FlowScriptEnableFunctionCallTracing;
            compiler.EnableStackCookie          = FlowScriptEnableStackCookie;
            compiler.ProcedureHookMode          = FlowScriptEnableProcedureHook ? ProcedureHookMode.ImportedOnly : ProcedureHookMode.None;

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

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

                compiler.Library = library;
            }

            FlowScript flowScript = null;
            var        success    = false;

            using (var file = File.Open(InputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    success = compiler.TryCompile(file, out flowScript);
                }
                catch (UnsupportedCharacterException e)
                {
                    Logger.Error($"Character '{e.Character}' not supported by encoding '{e.EncodingName}'");
                }

                if (!success)
                {
                    Logger.Error("One or more errors occured during compilation!");
                    return(false);
                }
            }

            // Write binary
            Logger.Info("Writing binary to file...");
            return(TryPerformAction("An error occured while saving the file.", () => flowScript.ToFile(OutputFilePath)));
        }
Beispiel #15
0
        private string ToolTip(string word)
        {
            var library = LibraryLookup.GetLibrary(game);

            return(ToolTip(word, library));
        }
Beispiel #16
0
        /// <summary>
        /// returns true if it successfully could parse the input of the compiler
        /// </summary>
        private static bool TryParseArguments(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                bool isLast = i + 1 == args.Length;
                //MessageBox.Show(args[i]);
                switch (args[i])
                {
                // General
                case "-In":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -In parameter");
                        return(false);
                    }

                    InputFilePath = args[++i];
                    break;

                case "-InFormat":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -InFormat parameter");
                        return(false);
                    }

                    if (!Enum.TryParse(args[++i], true, out InputFileFormat))
                    {
                        Logger.ConsoleError("Invalid input file format specified");
                        return(false);
                    }

                    break;

                case "-Out":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -Out parameter");
                        return(false);
                    }

                    OutputFilePath = args[++i];
                    break;

                case "-OutFormat":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -OutFormat parameter");
                        return(false);
                    }

                    if (!Enum.TryParse(args[++i], true, out OutputFileFormat))
                    {
                        Logger.ConsoleError("Invalid output file format specified");
                        return(false);
                    }

                    break;

                case "-Compile":
                    if (!IsActionAssigned)
                    {
                        IsActionAssigned = true;
                    }
                    else
                    {
                        Logger.ConsoleError("Attempted to assign compilation action while another action is already assigned.");
                        return(false);
                    }

                    DoCompile = true;
                    break;

                case "-Decompile":
                    if (!IsActionAssigned)
                    {
                        IsActionAssigned = true;
                    }
                    else
                    {
                        Logger.ConsoleError("Attempted to assign decompilation action while another action is already assigned.");
                        return(false);
                    }

                    DoDecompile = true;
                    break;

                case "-Disassemble":
                    if (!IsActionAssigned)
                    {
                        IsActionAssigned = true;
                    }
                    else
                    {
                        Logger.ConsoleError("Attempted to assign disassembly action while another action is already assigned.");
                        return(false);
                    }

                    DoDisassemble = true;
                    break;

                case "-Library":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -Library parameter");
                        return(false);
                    }

                    //MessageBox.Show("Library before: " + args[i]);
                    LibraryName = args[++i];
                    //MessageBox.Show("Library after: " + LibraryName);
                    library = LibraryLookup.GetLibrary(LibraryName);
                    break;

                case "-LogTrace":
                    LogTrace = true;
                    break;

                // MessageScript
                case "-Encoding":
                    if (isLast)
                    {
                        Logger.ConsoleError("Missing argument for -Encoding parameter");
                        return(false);
                    }

                    MessageScriptTextEncodingName = args[++i];

                    switch (MessageScriptTextEncodingName.ToLower())
                    {
                    case "sj":
                    case "shiftjis":
                    case "shift-jis":
                        MessageScriptEncoding = ShiftJISEncoding.Instance;
                        break;

                    default:
                        try
                        {
                            MessageScriptEncoding = AtlusEncoding.GetByName(MessageScriptTextEncodingName);
                        }
                        catch (ArgumentException)
                        {
                            Logger.ConsoleError($"Unknown encoding: {MessageScriptTextEncodingName}");
                            return(false);
                        }
                        break;
                    }

                    Logger.ConsoleInfo($"Using {MessageScriptTextEncodingName} encoding");
                    break;

                case "-TraceProcedure":
                    FlowScriptEnableProcedureTracing = true;
                    break;

                case "-TraceProcedureCalls":
                    FlowScriptEnableProcedureCallTracing = true;
                    break;

                case "-TraceFunctionCalls":
                    FlowScriptEnableFunctionCallTracing = true;
                    break;

                case "-StackCookie":
                    FlowScriptEnableStackCookie = true;
                    break;

                case "-Hook":
                    FlowScriptEnableProcedureHook = true;
                    break;
                }
            }

            if (InputFilePath == null)
            {
                InputFilePath = args[0];
            }
            //MessageBox.Show(InputFilePath);
            if (!File.Exists(InputFilePath))
            {
                Logger.ConsoleError($"Specified input file doesn't exist! ({InputFilePath})");
                return(false);
            }

            if (InputFileFormat == InputFileFormat.None)
            {
                var extension = Path.GetExtension(InputFilePath);

                switch (extension.ToLowerInvariant())
                {
                case ".bf":
                    InputFileFormat = InputFileFormat.FlowScriptBinary;
                    break;

                case ".flow":
                    InputFileFormat = InputFileFormat.FlowScriptTextSource;
                    break;

                case ".flowasm":
                    InputFileFormat = InputFileFormat.FlowScriptAssemblerSource;
                    break;

                case ".bmd":
                    InputFileFormat = InputFileFormat.MessageScriptBinary;
                    break;

                case ".msg":
                    InputFileFormat = InputFileFormat.MessageScriptTextSource;
                    break;

                default:
                    Logger.ConsoleError("Unable to detect input file format");
                    return(false);
                }
            }


            if (!IsActionAssigned)
            {
                // Decide on default action based on input file format
                switch (InputFileFormat)
                {
                case InputFileFormat.FlowScriptBinary:
                case InputFileFormat.MessageScriptBinary:
                    DoDecompile = true;
                    break;

                case InputFileFormat.FlowScriptTextSource:
                case InputFileFormat.MessageScriptTextSource:
                    DoCompile = true;
                    break;

                default:
                    Logger.ConsoleError("No compilation, decompilation or disassemble instruction given!");
                    return(false);
                }
            }

            if (OutputFilePath == null)
            {
                if (DoCompile)
                {
                    switch (InputFileFormat)
                    {
                    case InputFileFormat.FlowScriptTextSource:
                    case InputFileFormat.FlowScriptAssemblerSource:
                        OutputFilePath = InputFilePath + ".bf";
                        break;

                    case InputFileFormat.MessageScriptTextSource:
                        OutputFilePath = InputFilePath + ".bmd";
                        break;
                    }
                }
                else if (DoDecompile)
                {
                    switch (InputFileFormat)
                    {
                    case InputFileFormat.FlowScriptBinary:
                        OutputFilePath = InputFilePath + ".flow";
                        break;

                    case InputFileFormat.MessageScriptBinary:
                        OutputFilePath = InputFilePath + ".msg";
                        break;
                    }
                }
                else if (DoDisassemble)
                {
                    switch (InputFileFormat)
                    {
                    case InputFileFormat.FlowScriptBinary:
                        OutputFilePath = InputFilePath + ".flowasm";
                        break;
                    }
                }
            }

            Logger.ConsoleInfo($"Output file path is set to {OutputFilePath}");

            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// Runs the Compiler hopefully asynchronous
        /// </summary>
        public static void Run(string[] args)
        {
            if (args.Length == 0)
            {
                Logger.ConsoleError("No arguments specified!");
                //DisplayUsage(); //this one originally is here to show all the commands to compile/decompile. not needed anymore
                return;
            }



            library = LibraryLookup.GetLibrary(FilePaths.SelectedGamePath());

            // Set up log listener
            Listener.Subscribe(Logger);

            // Log arguments
            Logger.ConsoleTrace($"Arguments: {string.Join(" ", args)}");

            if (!TryParseArguments(args))
            {
                Logger.ConsoleError("Failed to parse arguments!");
                //DisplayUsage();
                return;
            }

            if (LogTrace)
            {
                Listener.Filter |= LogLevel.Trace;
            }


            bool success;

#if !DEBUG
            try
#endif
            {
                if (DoCompile)
                {
                    //if (MessageBox.Show("Do you want to Start game together with the mod?", "Start Game?", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                    //{
                    //    OutputFilePath = Path.Combine(FilePaths.modFolderPath, Path.GetFileNameWithoutExtension(InputFilePath) + ".bf");
                    //}
                    success = TryDoCompilation();
                }
                else if (DoDecompile)
                {
                    success = TryDoDecompilation();
                    //MessageBox.Show(OutputFilePath);
                }
                else if (DoDisassemble)
                {
                    success = TryDoDisassembling();
                }
                else
                {
                    ResetValues();
                    Array.Clear(args, 0, args.Length);
                    Logger.ConsoleError("No compilation, decompilation or disassemble instruction given!");
                    //DisplayUsage();
                    return;
                }
            }
#if !DEBUG
            catch (Exception e)
            {
                //LogException( "Unhandled exception thrown", e );
                success = false;

                if (Debugger.IsAttached)
                {
                    throw;
                }
            }
#endif

            if (success)
            {
                Logger.ConsoleInfo("Task completed successfully!");
                MessageBox.Show("Task completed sucessfully");
            }
            else
            {
                Logger.ConsoleError("One or more errors occured while executing task!");
            }

            ResetValues();
            Array.Clear(args, 0, args.Length);
            Console.ForegroundColor = ConsoleColor.Gray;
        }
Beispiel #18
0
        //ToDo popup only show up if you write at least 2 letters so make that 1
        public void setUpAutoComplete()
        {
            //for the flow script (tbh i just copy pasted this one this is way more time efficent)
            string[] keywords            = { /*Added by me (FLOW script exclusive)*/ "import", /*This part was copy pasted*/ "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "add", "alias", "ascending", "descending", "dynamic", "from", "get", "global", "group", "into", "join", "let", "orderby", "partial", "remove", "select", "set", "value", "var", "where", "yield" };
            string[] methods             = { "Equals()", "GetHashCode()", "GetType()", "ToString()" };
            string[] snippets            = { "if(^)\n{\n;\n}", "if(^)\n{\n;\n}\nelse\n{\n;\n}", "for(^;;)\n{\n;\n}", "while(^)\n{\n;\n}", "do${\n^;\n}while();", "switch(^)\n{\ncase : break;\n}" };
            string[] declarationSnippets =
            {
                "public class ^\n{\n}",     "private class ^\n{\n}",     "internal class ^\n{\n}",
                "public struct ^\n{\n;\n}", "private struct ^\n{\n;\n}", "internal struct ^\n{\n;\n}",
                "public void ^()\n{\n;\n}", "private void ^()\n{\n;\n}", "internal void ^()\n{\n;\n}","protected void ^()\n{\n;\n}",
                "public ^{ get; set; }",    "private ^{ get; set; }",    "internal ^{ get; set; }",   "protected ^{ get; set; }"
            };
            //To add for MSG "scripts" can i call it a script? like is it one?? WTH IS IT IF ITS NOT A SCRIPT

            if (FilePaths.libraryPath == null)
            {
                MessageBox.Show("[ERROR] Library Path is set to null");
                return;
            }

            var functionNameList = new List <string>();

            game = File.ReadAllLines("Game.txt")[0];
            switch (game)
            {
            case "SMT Digital Devil Saga":
                game = "Digital Devil Saga";     //or dds
                break;

            case "SMT 3 Nocturne":
                game = "Shin Megami Tensei III: Nocturne";     // or smt3
                break;
            }
            var library = LibraryLookup.GetLibrary(game);

            if (library == null)
            {
                MessageBox.Show("[ERROR] Couldn't find library folder please make sure that AtlusScriptCompiler.exe was selected in the Cofingaration Settings");
                return;
            }
            for (int i = 0; i < library.FlowScriptModules.Count; i++)
            {
                for (int j = 0; j < library.FlowScriptModules[i].Functions.Count; j++)
                {
                    functionNameList.Add(library.FlowScriptModules[i].Functions[j].Name);
                }
            }


            List <AutocompleteItem> items = new List <AutocompleteItem>();

            foreach (var item in functionNameList)
            {
                items.Add(new AutocompleteItem(item)
                {
                    ToolTipTitle = item, ToolTipText = ToolTip(item, library)
                });
            }
            foreach (var item in snippets)
            {
                items.Add(new SnippetAutocompleteItem(item)
                {
                    ImageIndex = 1
                });
            }
            foreach (var item in declarationSnippets)
            {
                items.Add(new DeclarationSnippet(item)
                {
                    ImageIndex = 0
                });
            }
            foreach (var item in methods)
            {
                items.Add(new MethodAutocompleteItem(item)
                {
                    ImageIndex = 2, ToolTipText = "WALUIGIIIIIIIIIIIIII"
                });
            }
            foreach (var item in keywords)
            {
                items.Add(new AutocompleteItem(item)
                {
                });
            }



            items.Add(new InsertSpaceSnippet());
            items.Add(new InsertSpaceSnippet(@"(\w+)([=<>!:]+)(\w+)$"));
            items.Add(new InsertEnterSnippet());

            popupMenu.Items.SetAutocompleteItems(items);
        }