/// <summary> /// Needed to reset the values after each compile/decopmile /// </summary> static void ResetValues() { //library = null; InputFilePath = null; OutputFilePath = null; LibraryName = null; IsActionAssigned = false; DoCompile = false; DoDecompile = false; DoDisassemble = false; InputFileFormat = InputFileFormat.None; OutputFileFormat = OutputFileFormat.None; MessageScriptTextEncodingName = null; MessageScriptEncoding = Encoding.Default; //LibraryName = null; LogTrace = false; FlowScriptEnableProcedureTracing = false; FlowScriptEnableProcedureCallTracing = false; FlowScriptEnableFunctionCallTracing = false; FlowScriptEnableStackCookie = false; FlowScriptEnableProcedureHook = false; }
private static bool TryParseArguments(string[] args) { for (int i = 0; i < args.Length; i++) { bool isLast = i + 1 == args.Length; switch (args[i]) { // General case "-In": if (isLast) { Logger.Error("Missing argument for -In parameter"); return(false); } InputFilePath = args[++i]; break; case "-InFormat": if (isLast) { Logger.Error("Missing argument for -InFormat parameter"); return(false); } if (!Enum.TryParse(args[++i], true, out InputFileFormat)) { Logger.Error("Invalid input file format specified"); return(false); } break; case "-Out": if (isLast) { Logger.Error("Missing argument for -Out parameter"); return(false); } OutputFilePath = args[++i]; break; case "-OutFormat": if (isLast) { Logger.Error("Missing argument for -OutFormat parameter"); return(false); } if (!Enum.TryParse(args[++i], true, out OutputFileFormat)) { Logger.Error("Invalid output file format specified"); return(false); } break; case "-Compile": if (!IsActionAssigned) { IsActionAssigned = true; } else { Logger.Error("Attempted to assign compilation action while another action is already assigned."); return(false); } DoCompile = true; break; case "-Decompile": if (!IsActionAssigned) { IsActionAssigned = true; } else { Logger.Error("Attempted to assign decompilation action while another action is already assigned."); return(false); } DoDecompile = true; break; case "-Disassemble": if (!IsActionAssigned) { IsActionAssigned = true; } else { Logger.Error("Attempted to assign disassembly action while another action is already assigned."); return(false); } DoDisassemble = true; break; case "-Library": if (isLast) { Logger.Error("Missing argument for -Library parameter"); return(false); } LibraryName = args[++i]; break; case "-LogTrace": LogTrace = true; break; // MessageScript case "-Encoding": if (isLast) { Logger.Error("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.Error($"Unknown encoding: {MessageScriptTextEncodingName}"); return(false); } break; } Logger.Info($"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; case "-SumBits": FlowScriptSumBits = true; break; } } if (InputFilePath == null) { InputFilePath = args[0]; } if (!File.Exists(InputFilePath)) { Logger.Error($"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.Error("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.Error("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.Info($"Output file path is set to {OutputFilePath}"); return(true); }