Example #1
0
        public CommandLineSettings(aCommandLine cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            mDecomp = false;
            foreach (var param in cmd)
            {
                switch (param.Name)
                {
                case "-in": mInput = param[0]; continue;

                case "-out": mOutput = param[0]; continue;

                case "-H": mOutputHeader = true; continue;

                case "-h": mOutputHeader = false; continue;

                case "-T": mOutputText = true; continue;

                case "-t": mOutputText = false; continue;

                case "-D": mOutputData = true; continue;

                case "-d": mOutputData = false; continue;

                case "-S": mOutputSym = true; continue;

                case "-s": mOutputSym = false; continue;

                case "-V": mOutputVars = true; continue;

                case "-v": mOutputVars = false; continue;

                case "-sun": mDecomp = true; continue;
                }
            }
            ///Debug///
            mInput  = "C:\\Users\\August\\Downloads\\Sunshine ROM hacking\\ssc\\Decompile\\talkevent.sb";
            mDecomp = true;
            ///Debug///
            if (mInput == null)
            {
                throw new Exception("Missing input file setting.");
            }
            if (mOutput == null)
            {
                mOutput = Path.ChangeExtension(mInput, ".txt");
            }
        }
Example #2
0
        static int Main(string[] args)
        {
            var cmd = new aCommandLine(args);

            Console.Title = String.Format("joblo v{0}", blojob.getVersion());
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            switch (args.Length)
            {
            case 0: return(doUsage());

            default: return(doCommandLine(cmd));
            }
        }
Example #3
0
        public virtual void LoadParams(string[] arguments)
        {
            var cmdline = new aCommandLine(arguments);
            aCommandLineParameter parameter;

            parameter = mareep.GetLastCmdParam(cmdline, "-input");

            if (parameter == null)
            {
                mareep.WriteError("SYSTEM: missing -input parameter.");
            }

            if (parameter.Count != 2)
            {
                mareep.WriteError("SYSTEM: -input parameter requires two arguments.");
            }

            mInputFile = parameter[0];

            if (!File.Exists(mInputFile))
            {
                mareep.WriteError("SYSTEM: input file '{0}' could not be found.", mInputFile);
            }

            if (!Enum.TryParse(parameter[1], true, out mInputFormat))
            {
                mareep.WriteError("SYSTEM: unknown input format '{0}'.", parameter[1]);
            }

            parameter = mareep.GetLastCmdParam(cmdline, "-output");

            if (parameter == null)
            {
                mareep.WriteError("SYSTEM: missing -output parameter.");
            }

            if (parameter.Count != 2)
            {
                mareep.WriteError("SYSTEM: -output parameter requires two arguments.");
            }

            mOutputFile = parameter[0];

            if (!Enum.TryParse(parameter[1], true, out mOutputFormat))
            {
                mareep.WriteError("SYSTEM: unknown output format '{0}'.", parameter[1]);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var cmd = new aCommandLine(args, '-');

            Console.Title = String.Format("pablo v{0}", blojob.getVersion());
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            // do not use cmd for this check, as both d&d and -input will both return 1
            switch (args.Length)
            {
            case 0: doUsage(); break;

            case 1: doDragAndDrop(cmd[0].Name); break;

            default: doCommandLine(cmd); break;
            }
        }
Example #5
0
File: main.cs Project: RenolY2/ssc
		// command-line
		static void ReadCmdLine(aCommandLine cmd, out string inputFile, out string outputFile) {
			inputFile = null;
			outputFile = null;
			foreach (var prm in cmd) {
				switch (prm.Name) {
					case "-input": GetInput(prm, ref inputFile); break;
					case "-output": GetOutput(prm, ref outputFile); break;
				}
			}
			if (inputFile == null) {
				Error("Missing -input option.\n");
				Pause();
				Exit(1);
			}
			if (outputFile == null) {
				outputFile = Path.ChangeExtension(inputFile, ".sb");
			}
		}
Example #6
0
        public CommandLineSettings(aCommandLine cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            foreach (var param in cmd)
            {
                switch (param.Name)
                {
                case "-in": mInput = param[0]; continue;

                case "-out": mOutput = param[0]; continue;

                case "-H": mOutputHeader = true; continue;

                case "-h": mOutputHeader = false; continue;

                case "-T": mOutputText = true; continue;

                case "-t": mOutputText = false; continue;

                case "-D": mOutputData = true; continue;

                case "-d": mOutputData = false; continue;

                case "-S": mOutputSym = true; continue;

                case "-s": mOutputSym = false; continue;

                case "-V": mOutputVars = true; continue;

                case "-v": mOutputVars = false; continue;
                }
            }
            if (mInput == null)
            {
                throw new Exception("Missing input file setting.");
            }
            if (mOutput == null)
            {
                mOutput = Path.ChangeExtension(mInput, ".txt");
            }
        }
Example #7
0
File: main.cs Project: RenolY2/ssc
		static void Main(string[] args) {
			Message("ssc v0.1 arookas\n");
			var cmd = new aCommandLine(args);
			if (cmd.Count == 0) {
				Message("Usage: ssc -input <input.sun> [-output <output.sb>]\n");
				Pause();
				Exit(1);
			}
			var compiler = new sunCompiler();
			int exitCode = 0;
			string inputFile, outputFile;
			ReadCmdLine(cmd, out inputFile, out outputFile);
			using (var output = OpenOutput(outputFile)) {
				var results = compiler.Compile(inputFile, output);
				if (results.Success) {
					Message("Finished compiling in {0:F2}ms.\n", results.CompileTime.TotalMilliseconds);
					Message("  Data count: {0}\n", results.Data.Length);
					Message("Symbol count: {0}\n", results.Symbols.Length);
					Message(" -  builtins: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Builtin));
					Message(" - functions: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Function));
					Message(" - variables: {0}\n", results.Symbols.Count(i => i.Type == sunSymbolType.Variable));
				}
				else {
					if (results.Error is sunSourceException) {
						var error = results.Error as sunSourceException;
						Error("  in file \"{0}\"\n  at line {1}, col {2}\n\n{3}{4}", error.Location.ScriptName, error.Location.Line, error.Location.Column, GetErrorPreview(error.Location), error.Message);
						exitCode = 1;
					}
					else {
						var error = results.Error;
						Error("{0}", error.Message);
						exitCode = 1;
					}
				}
			}
			Pause();
			Exit(exitCode);
		}
        public CorrupterOptions(aCommandLine cmd)
            : this()
        {
            foreach (var param in cmd)
            {
                switch (param.Name.ToLowerInvariant())
                {
                case "-start": LoadStart(param); continue;

                case "-end": LoadEnd(param); continue;

                case "-inc": LoadInc(param); continue;

                case "-mode": LoadMode(param); continue;

                case "-skip": LoadSkip(param); continue;

                case "-only": LoadOnly(param); continue;

                case "-zdoom": LoadZDOOM(param); continue;
                }
                DOOMWADCorrupter.Warning("Skipping unknown option '{0}'...", param.Name);
            }
        }
Example #9
0
        static void Main(string[] arguments)
        {
            Message("doomwadcorrupter v{0} arookas", new Version(0, 1, 12));
            Separator();
            if (arguments == null || arguments.Length < 2)
            {
                Message("Usage: doomwadcorrupter <input.wad> <output.wad> [options]");
                Message();
                Message("Options:");
                Message("    -start <value>");
                Message("    -end <value>");
                Message("    -inc <value>");
                Message("    -mode <type> [<value>]");
                Message("    -skip <filter> [<filter> [...]]");
                Message("    -only <filter> [<filter> [...]]");
                Message("    -zdoom");
                Message();
                Message("For more detailed instructions, refer to the official repo page.");
                Pause();
                Exit(false);
            }
            var inputWAD  = arguments[0];
            var outputWAD = arguments[1];

            cmd     = new aCommandLine(arguments.Skip(2).ToArray());
            options = new CorrupterOptions(cmd);
            DisplayOptions(inputWAD, outputWAD);

            int lumpCount;
            var lumpsCorrupted = 0;
            var lumpsSkipped   = 0;
            var bytesCorrupted = 0;

            rnd = new Random((uint)options.CorruptSeed);
            var timeTaken = Stopwatch.StartNew();

            using (var instream = OpenWAD(inputWAD)) {
                var reader = new aBinaryReader(instream, Endianness.Little, Encoding.ASCII);

                // header
                var wadType = reader.ReadString(4);

                if (wadType != "IWAD" && wadType != "PWAD")
                {
                    Error("Input file is not a DOOM WAD.");
                }

                lumpCount = reader.ReadS32();
                var directoryOffset = reader.ReadS32();

                // directory
                reader.Goto(directoryOffset);
                var lumps = aCollection.Initialize(lumpCount, () => new Lump(reader));

                using (var outstream = CreateWAD(outputWAD)) {
                    var writer = new aBinaryWriter(outstream, Endianness.Little, Encoding.ASCII);
                    // header
                    writer.WriteString(wadType);
                    writer.WriteS32(lumpCount);
                    writer.WriteS32(directoryOffset);

                    // data
                    var corruptBuff = new byte[options.Increment];
                    var startBuff   = new byte[options.Start];
                    var ns          = LumpNamespace.Global;

                    foreach (var lump in lumps)
                    {
                        reader.Goto(lump.Start);
                        writer.Goto(lump.Start);
                        CheckNamespaceMarker(lump, ref ns);
                        if (options.Filter.IsCorruptable(lump.Name, ns) && !(options.ZDOOM && IsZDOOMLump(lump.Name)))
                        {
                            ++lumpsCorrupted;
                            var i   = options.Start;
                            var end = options.End ?? lump.Length;
                            if (i > 0)
                            {
                                var count = (int)System.Math.Min(lump.Length, i);
                                reader.Read(startBuff, count);
                                writer.Write8s(startBuff, count);
                            }
                            while (i < lump.Length && i < end)
                            {
                                Status("Corrupting '{0}'... (0x{1:X8} / 0x{2:X8})", lump.Name, i, lump.Length);
                                var count = (int)System.Math.Min(lump.Length - i, options.Increment);
                                reader.Read(corruptBuff, count);
                                CorruptByte(ref corruptBuff[0], options.CorruptMode, options.CorruptValue);
                                writer.Write8s(corruptBuff, count);
                                ++bytesCorrupted;
                                i += count;
                            }
                        }
                        else
                        {
                            ++lumpsSkipped;
                            writer.Write8s(reader.Read8s(lump.Length));
                        }
                    }

                    // directory
                    writer.Goto(directoryOffset);
                    foreach (var lump in lumps)
                    {
                        Status("Writing lump directory for '{0}'...", lump.Name);
                        lump.ToStream(writer);
                    }
                }
            }

            timeTaken.Stop();
            Status("Finished corrupting.");
            Message();
            Separator();
            Message("                       Files : {0}", lumpCount);
            Message("             Files corrupted : {0}", lumpsCorrupted);
            Message("               Files skipped : {0}", lumpsSkipped);
            Message("Bytes mercilessly sacrificed : {0}", bytesCorrupted);
            Message("                  Time taken : {0}", timeTaken.Elapsed.ToString("g"));
            Message("                 Finished at : {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Pause();
        }
Example #10
0
        static void doCommandLine(aCommandLine cmd)
        {
            bool      inputSet = false;
            string    input    = null;
            bloFormat format   = bloFormat.Blo1;

            var searchPaths = new List <string>(5);

            bool sizeSet = false;
            int  width = 0, height = 0;

            foreach (var param in cmd)
            {
                switch (param.Name.ToLowerInvariant())
                {
                case "-input": {
                    if (param.Count < 1)
                    {
                        break;
                    }
                    inputSet = true;
                    input    = param[0];
                    format   = (param.Count >= 2 ? parseFormat(param[1]) : bloFormat.Blo1);
                    break;
                }

                case "-search-paths": {
                    foreach (var arg in param)
                    {
                        searchPaths.Add(arg);
                    }
                    break;
                }

                case "-display-size": {
                    if (param.Count != 2)
                    {
                        break;
                    }
                    if (Int32.TryParse(param[0], out width) && Int32.TryParse(param[1], out height))
                    {
                        sizeSet = true;
                    }
                    break;
                }
                }
            }

            if (!inputSet)
            {
                doUsage();
                return;
            }

            if (!File.Exists(input))
            {
                Console.WriteLine("Could not find input file '{0}'", input);
                return;
            }

            var path = Path.GetDirectoryName(Path.GetFullPath(input));
            var file = Path.GetFileName(input);

            createFinder(path, searchPaths);
            var screen = loadScreen(input, format);

            if (screen == null)
            {
                Console.WriteLine("Failed to load input file '{0}'", input);
                return;
            }

            if (sizeSet)
            {
                openViewer(screen, file, width, height);
            }
            else
            {
                openViewer(screen, file);
            }
        }
Example #11
0
        static int doCommandLine(aCommandLine cmd)
        {
            bool      inputSet    = false;
            string    input       = null;
            bloFormat inputFormat = bloFormat.Blo1;

            bool      outputSet    = false;
            string    output       = null;
            bloFormat outputFormat = bloFormat.Blo1;

            var searchPaths = new List <string>(5);

            foreach (var param in cmd)
            {
                switch (param.Name.ToLowerInvariant())
                {
                case "-input": {
                    if (param.Count < 1)
                    {
                        break;
                    }
                    inputSet    = true;
                    input       = param[0];
                    inputFormat = (param.Count >= 2 ? parseFormat(param[1]) : bloFormat.Blo1);
                    break;
                }

                case "-output": {
                    if (param.Count < 1)
                    {
                        break;
                    }
                    outputSet    = true;
                    output       = param[0];
                    outputFormat = (param.Count >= 2 ? parseFormat(param[1]) : bloFormat.Blo1);
                    break;
                }

                case "-search-paths": {
                    foreach (var arg in param)
                    {
                        searchPaths.Add(arg);
                    }
                    break;
                }
                }
            }

            if (!inputSet || !outputSet)
            {
                return(doUsage());
            }

            var inputFile  = Path.GetFullPath(input);
            var outputFile = Path.GetFullPath(output);

            var inputPath  = Path.GetDirectoryName(inputFile);
            var outputPath = Path.GetDirectoryName(outputFile);

            var finder = new bloResourceFinder(inputPath);

            foreach (var searchPath in searchPaths)
            {
                finder.addGlobalPath(searchPath);
            }
            bloResourceFinder.setFinder(finder);

            if (!File.Exists(inputFile))
            {
                Console.WriteLine("Could not find input file '{0}'", inputFile);
                return(1);
            }

            if (inputFile == outputFile)
            {
                Console.WriteLine("Input and output files cannot be the same.");
                return(1);
            }

            if (inputFormat == outputFormat)
            {
                File.Copy(inputFile, outputFile);
                return(0);
            }

            bloScreen screen = null;

            using (var stream = File.OpenRead(inputFile)) {
                switch (inputFormat)
                {
                case bloFormat.Compact: screen = bloScreen.loadCompact(stream); break;

                case bloFormat.Blo1: screen = bloScreen.loadBlo1(stream); break;

                case bloFormat.Xml: screen = bloScreen.loadXml(stream); break;

                default: {
                    Console.WriteLine("Unimplemented input format {0}", inputFormat);
                    return(1);
                }
                }
            }

            if (screen == null)
            {
                Console.WriteLine("Failed to input file '{0}'", inputFile);
                return(1);
            }

            using (var stream = File.Create(outputFile)) {
                switch (outputFormat)
                {
                case bloFormat.Compact: screen.saveCompact(stream); break;

                case bloFormat.Blo1: screen.saveBlo1(stream); break;

                case bloFormat.Xml: screen.saveXml(stream); break;

                default: {
                    Console.WriteLine("Unimplemented output format {0}", outputFormat);
                    return(1);
                }
                }
            }

            return(0);
        }
Example #12
0
 public static aCommandLineParameter GetLastCmdParam(aCommandLine cmdline, string name)
 {
     return(cmdline.LastOrDefault(param => param.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)));
 }