public static void Console_Eval_CS(IConsole console, string[] param) { var code = string.Join(" ", param ?? Array.Empty <string>()).Trim(); if (string.IsNullOrEmpty(code)) { ConsoleShell.OnCommand = EvalToConsole; ConsoleShell.EnterEvalMode(console); } else { EvalToConsole(console, code); } }
internal static void EnterEvalMode(IConsole console) { if (EvalPatch != null) { return; } var me = new ConsoleShell(); ReadPatch = me.TryPatch(GameAssembly.GetType("Base.Utils.GameConsole.CommandLineParser"), "ReadCommandLine", nameof(BeforeReadCommandLine_Eval)); EvalPatch = me.TryPatch(GameAssembly.GetType("Base.Utils.GameConsole.EmptyCommand"), "Execute", postfix: nameof(AfterExecute_Eval)); if (ReadPatch == null || EvalPatch == null) { Unpatch(ref ReadPatch); Unpatch(ref EvalPatch); return; } ShowLinePatch = me.TryPatch(typeof(GameConsoleWindow).GetMethod("ExecuteCommandLine", new Type[] { typeof(string), typeof(bool), typeof(bool) }), prefix: nameof(BeforeExecuteCommandLine_ShowLine)); SetConsoleInputPlaceholder("Enter C# expression...", Color.blue); console.Write("Entering C# Shell. Type 'Exit' to return."); }