Beispiel #1
0
        private string RunPattern(string pattern, string includeHidden)
        {
            var statusType = "success";
            var statusMessage = "Success";
            RantOutput output = null;
            if (String.IsNullOrWhiteSpace(pattern)) goto skip;

            var rant = new RantEngine();
            rant.LoadPackage(Resources.Package);
            if (!String.IsNullOrWhiteSpace(includeHidden))
                rant.Dictionary.IncludeHiddenClass(includeHidden);

            try
            {
                output = rant.Do(pattern, Config.Current.MaxChars, Config.Current.PatternTimeout);
            }
            catch (RantRuntimeException ex)
            {
                statusType = "runtime-error";
                statusMessage = ex.Message;
            }
            catch (RantCompilerException ex)
            {
                statusType = "compiler-error";
                statusMessage = ex.Message;
            }
            catch (Exception ex)
            {
                statusType = "unknown-error";
                statusMessage = "Unknown error";
                C.WriteLine(ConsoleColor.Red, $"An exception was thrown while running a pattern: {ex}");
            }

            skip:

            var json = new
            {
                statusType,
                statusMessage,
                seed = output?.Seed.ToString() ?? "0",
                output = output?.ToDictionary(oe => oe.Name, oe => oe.Value)
            };
            return JObject.FromObject(json).ToString();
        }
Beispiel #2
0
        static void PrintOutput(RantEngine engine, string source, bool isFile = false)
        {
            try
            {
                var sw = new Stopwatch();

                sw.Start();
                var pattern = isFile
                    ? RantPattern.FromFile(source)
                    : RantPattern.FromString(source);
                sw.Stop();
                var compileTime = sw.Elapsed;

                sw.Restart();
                var output = USE_SEED
                    ? engine.Do(pattern, SEED, 0, PATTERN_TIMEOUT)
                    : engine.Do(pattern, 0, PATTERN_TIMEOUT);
                sw.Stop();

                var runTime = sw.Elapsed;

                bool writeToFile = !String.IsNullOrEmpty(Property("out"));
                foreach (var chan in output)
                {
                    if (chan.Name != "main")
                    {
                        if (Flag("main")) continue;
                        if (!writeToFile)
                        {
                            ForegroundColor = ConsoleColor.DarkCyan;
                            WriteLine($"{chan.Name}:");
                            ResetColor();
                        }
                    }
                    ForegroundColor = ConsoleColor.Green;
                    if (chan.Value.Length > 0)
                    {
                        if (pattern.Type == RantPatternSource.File && writeToFile)
                        {
                            var path = Property("out");
                            File.WriteAllText(
                                Path.Combine(Path.GetDirectoryName(path),
                                Path.GetFileNameWithoutExtension(path) +
                                (chan.Name != "main"
                                    ? $".{chan.Name}"
                                    : "" + "." + Path.GetExtension(path))),
                                chan.Value);
                        }
                        else
                        {
                            WriteLine(chan.Value);
                        }
                    }
                    else if (!writeToFile)
                    {
                        ForegroundColor = ConsoleColor.DarkGray;
                        if (pattern.Type != RantPatternSource.File) WriteLine("[Empty]");
                    }
                    ResetColor();
                    WriteLine();
                }

                if ((pattern.Type != RantPatternSource.File || Flag("wait")) && !Flag("nostats"))
                {
                    PrintStats(
                        new Stat("Seed",
                            $"{output.Seed:X16}{(output.BaseGeneration != 0 ? ":" + output.BaseGeneration : String.Empty)}"),
                        new Stat("Compile Time", compileTime.ToString("c")),
                        new Stat("Run Time", runTime.ToString("c"))
                        );
                    WriteLine();
                }
            }
#if !DEBUG
            catch (RantRuntimeException e)
            {
                ForegroundColor = ConsoleColor.Red;
                WriteLine($"Runtime error: {e.Message}");
            }
            catch (RantCompilerException e)
            {
                ForegroundColor = ConsoleColor.Yellow;
                WriteLine($"Compiler error: {e.Message}");
            }
            catch (Exception e)
            {
                WriteLine(e.ToString()); // Print the whole stack trace if it isn't a Rant error
            }
#endif
            finally
            {
                ResetColor();
            }
        }
Beispiel #3
0
        static void StartIrrgen()
        {
            var rand = new Random(0);
            Thread.Sleep(400);
            C.WriteLine("#YIRRGEN Simulation Constant Calculator v1.4.53.3967495a");
            C.WriteLine("Copyright (c) 1993 Eugene Glass, Jason Fisch");
            C.WriteLine();
            Thread.Sleep(600);
            Loading("INIT: #Y[libhypermathlib2000 v5.7.8453]", 24, 30, true);
            Loading("INIT: #Y[lib-libsagan84 v1.4.9b]", 24, 30, true);
            Loading("INIT: #Y[libcalculalgebra v6.7.69]", 24, 30, true);
            Loading("INIT: #Y[libfuccboiGDX (Professional Edition)]", 24, 30, true);
            Loading("INIT: #Y[libMEGAphp-vm v8.6.0]", 24, 30, true);
            Loading("INIT: #Y[lib-interdimensional-grasse v1.2.1]", 24, 30, true);
            Loading("INIT: #Y[libfischingrod v0.2.0]", 24, 30, true);
            Loading("INIT: #Y[librant4unix v3.0.0]", 24, 30, true);
            Loading("INIT: #Y[libMirrorScript v5.6.Eyes-Real?]", 24, 30, true);
            Loading("INIT: #Y[libtimespacepapaya v3.0.2]", 24, 30, true);
            C.WriteLine("\n#GSubmodules initialized!\n");
            C.WriteLine("#YAllocating output buffers 0-255");
            Count(0, 255);
            C.WriteLine("\nPartitioning math cache\n");
            Thread.Sleep(500);
            for (int i = 0; i < 8; i++)
            {
                C.WriteLine(new string('=', 48));
                C.WriteLine($"#MPARTITION CREATED @ 0x{rand.Next():X8} ({rand.Next(500, 1001)}K)");
                C.WriteLine(new string('=', 48));
                C.WriteLine();
                Thread.Sleep(200);
            }
            C.WriteLine("#GAll systems ready.");
            C.WriteLine("#YProceed? (Y/n)");
            Console.ReadLine();
            Console.CursorVisible = false;
            Thread.Sleep(350);
            C.Write("#RLET'S DO THIS SHIT");
            for (int i = 0; i < 35; i++)
            {
                C.Write("#R>");
                Thread.Sleep(20);
            }
            C.WriteLine();
            Console.Clear();

            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("........................\n");
                Thread.Sleep(300);
            }

            C.Write("#YCALCULATION START ");
            Spinner();
            C.WriteLine('\n');

            int delayBase = 1;
            float delayOffset = 1000f;
            C.Write("5.");
            var colors = new[] { 'W', 'R', 'G', 'B', 'Y', 'C', 'M' };
            var bcolors = new[]
            {
                ConsoleColor.DarkBlue, ConsoleColor.DarkCyan, ConsoleColor.DarkGreen, ConsoleColor.DarkRed, ConsoleColor.DarkYellow, ConsoleColor.DarkBlue,
                ConsoleColor.DarkMagenta, ConsoleColor.DarkGray, ConsoleColor.Black
            };
            var rant = new RantEngine();
            rant.LoadPackage("Rantionary");
            rant.Dictionary.IncludeHiddenClass("nsfw");
            var rngRant = new RNG(0);
            var pattern = RantPattern.FromString(@"
            [rs:[n:1;8];{\s|:|--|\(|\);|\;|*|@|?!|...|_|::|\#|$|%|^|&\~|\u2591|\u2592|\u2593|\}|\{|\""|'|,|/|\\|\`|\|*|+|\< |\> |__|++|--|\<\< |\>\> |!!}]
            [before:[case:{upper|lower|none|word}]]
            {{<adj>\s|}<noun>|<place>|<verb.nom>|<name>|<adv>|<state>|<element>|<unit>|<country>|the|entity|
            pointer|object|int|void|reference|bool|boolean|byte|char|protected|private|public|internal|static|
            unsigned|operator|delete|const|float|double|dword|return|namespace|nullptr|class|template|exec|auto|
            \#include \<[`[^\w\d]`i:{<noun>|<verb.nom>};_].h\>|
            \#define __[case:upper]<noun>[case:none] [rs:[n:1;4];\s]{<noun>|<adj>|and|or|the|<verb>}
            [n:1;1k]|\#{W|R|G|Y|C|M|B}|[r:[n:1;16]]{\w}|0x\8,X|{<noun>|<verb>}\(\)|[numfmt:verbal-en;[n:1;1M]]}"
            );
            int l = 13000;
            int corruptPoint = 7500;
            int unstablePoint = 6000;
            for (int i = 0; i < l; i++)
            {
                if (i < corruptPoint)
                {
                    for (int j = 0; j < i / 100 + 1; j++)
                    {
                        if (i > unstablePoint && rand.Next(0, (corruptPoint - i) / 10 + 2) == 0)
                        {
                            C.Write(' ');
                        }
                        else
                        {
                            C.Write(rand.Next(0, 10));
                        }
                    }
                }
                else if (i == corruptPoint)
                {
                    SpinnerActive = false;
                    for (int k = 0; k < 75; k++)
                    {
                        C.WriteLine($"#R==== FATAL ERROR ==== @ 0x{rngRant.NextRaw():X16}, 0x{rngRant.NextRaw():X16}");
                        Thread.Sleep(5);
                    }
                }
                else
                {
                    switch (rand.Next(0, 2))
                    {
                        case 0:
                            C.Write($"#{colors[rand.Next(colors.Length)]}{rand.Next(0, 10)}", false);
                            break;
                        case 1:
                            if (i > 9000)
                            {
                                Console.BackgroundColor = bcolors[rand.Next(bcolors.Length)];
                            }
                            C.Write(rant.Do(pattern, rngRant), false);
                            break;
                    }

                    switch (rand.Next(700))
                    {
                        case 0:
                            Thread.Sleep(125);
                            break;
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                            Console.MoveBufferArea(0, 0, 6, 8, rand.Next(Console.BufferWidth - 6), Console.CursorTop - 8, '\u2592', ConsoleColor.Black, ConsoleColor.Black);
                            break;
                    }
                }

                Thread.Sleep(delayBase + (int)delayOffset);
                delayOffset *= 0.845f;
            }
            Console.BackgroundColor = ConsoleColor.Green;
            Console.Clear();
            for (int i = 0; i < Console.BufferWidth; i++)
            {
                if (i % 3 == 2) continue;
                Console.MoveBufferArea(Console.WindowHeight, 0, 1, Console.WindowHeight, i, 0, '\u2592', ConsoleColor.Blue, ConsoleColor.Magenta);
                for(int j = 0; j < 4; j++)
                    Console.MoveBufferArea(0, 0, 1, 1, rand.Next(Console.WindowWidth), rand.Next(Console.WindowHeight), '\u2591', ConsoleColor.Yellow, ConsoleColor.Black);
            }
        }