static void InitConsole() { Engine.GamePath = ConVar.Register("game", "basegame", ConVarType.Replicated | ConVarType.Init); //Engine.GamePath = ConVar.Register("game", "legprocessor", ConVarType.Replicated | ConVarType.Init); Engine.MaxFPS = ConVar.Register("maxfps", 60, ConVarType.Archive); Engine.WindowWidth = ConVar.Register("width", 1366, ConVarType.Archive); Engine.WindowHeight = ConVar.Register("height", 768, ConVarType.Archive); //Engine.WindowWidth = CVar.Register("width", 800, CVarType.Archive); //Engine.WindowHeight = CVar.Register("height", 600, CVarType.Archive); Engine.WindowBorderless = ConVar.Register("borderless", false, ConVarType.Archive); Engine.WindowResizable = ConVar.Register("resizable", false, ConVarType.Archive); Engine.ShowFPS = ConVar.Register("showfps", true, ConVarType.Archive); Engine.MSAA = ConVar.Register("msaa", 32, ConVarType.Archive); Engine.SourceGameDirs = ConVar.Register("source_game_dirs", "C:/Program Files (x86)/Steam/steamapps/common/GarrysMod", ConVarType.Archive); Engine.DebugDraw = ConVar.Register("debugdraw", true, ConVarType.Cheat); // Parse all arguments and set CVars foreach (var Arg in ArgumentParser.All) { switch (Arg.Key) { case "console": GConsole.Open = true; break; case "game": Engine.GamePath.Value = Arg.Value.Last(); break; default: GConsole.Error("Invalid switch '{0}' with value '{1}'", Arg.Key, Arg.Value); break; } } foreach (var CVar in ConVar.GetAll()) { GConsole.WriteLine(CVar); } ConCmd.Register("exit", (Argv) => Environment.Exit(0)); GConsole.RegisterAlias("quit", "exit"); }
static void InitConsole() { Engine.GamePath = ConVar.Register("game", "basegame", ConVarType.Replicated | ConVarType.Init); //Engine.GamePath = ConVar.Register("game", "legprocessor", ConVarType.Replicated | ConVarType.Init); Engine.WindowWidth = ConVar.Register("width", 1366, ConVarType.Archive); Engine.WindowHeight = ConVar.Register("height", 768, ConVarType.Archive); //Engine.WindowWidth = CVar.Register("width", 800, CVarType.Archive); //Engine.WindowHeight = CVar.Register("height", 600, CVarType.Archive); Engine.WindowBorderless = ConVar.Register("borderless", false, ConVarType.Archive); Engine.WindowResizable = ConVar.Register("resizable", false, ConVarType.Archive); // Parse all arguments and set CVars foreach (var Arg in ArgumentParser.All) { switch (Arg.Key) { case "console": GConsole.Open = true; break; case "game": Engine.GamePath.Value = Arg.Value.Last(); break; default: GConsole.Error("Invalid switch '{0}' with value '{1}'", Arg.Key, Arg.Value); break; } } foreach (var CVar in ConVar.GetAll()) { GConsole.WriteLine(CVar); } ConCmd.Register("exit", (Argv) => Environment.Exit(0)); GConsole.RegisterAlias("quit", "exit"); }
internal static void Init() { /*ConsoleWindow = new Window(); * ConsoleWindow.ResizableHorizontal = false; * ConsoleWindow.Movable = false; * ConsoleWindow.Color = new Color(255, 255, 255, 200); * ConsoleWindow.MinimumSize = new Vector2(0, 100); * * Input = ConsoleWindow.AddChild(new InputBox(DefaultFonts.ConsoleFont)); * Input.OnTextEntered += (In, Txt) => { * In.String = ""; * SendInput(Txt); * }; * * Output = ConsoleWindow.AddChild(new Label(DefaultFonts.ConsoleFont)); * Output.Multiline = true; * ConsoleWindow.OnResize += (Wnd, Sz) => { * float SpacingOffset = 1.5f; * Output.Position = new Vector2(0, DefaultFonts.ConsoleFont.LineSpacing * SpacingOffset); * Output.DrawRegion = new AABB(new Vector2(Sz.X, Sz.Y - DefaultFonts.ConsoleFont.LineSpacing * SpacingOffset)); * * Input.DrawRegion = new AABB(new Vector2(Sz.X, DefaultFonts.ConsoleFont.LineSpacing)); * }; * * if (TempBuffer.Length > 0) { * Output.AppendString(TempBuffer.ToString()); * TempBuffer.Clear(); * }//*/ ConVar <float> ConHeight = ConVar.Register("con_height", 0.4f, ConVarType.Archive); //const float Padding = 10; //ConsoleWindow.Position = new Vector2(Padding, (int)(Engine.WindowHeight * ConHeight) + Padding); //ConsoleWindow.Size = new Vector2(Engine.WindowWidth - Padding * 2, (int)(Engine.WindowHeight * (1.0f - ConHeight)) - Padding * 2); ConCmd.Register("clear", (Argv) => { Clear(); }); ConCmd.Register("rainbow", (Argv) => { string Rnd = Utils.RandomString(40, 60); Color Clr = Color; foreach (var Char in Rnd) { Color = Utils.RandomColor(); Write(Char.ToString()); } Write("\n"); Color = Clr; }); ConCmd.Register("echo", (Argv) => { for (int i = 1; i < Argv.Length; i++) { string Arg = Argv[i]; /*if (Arg.StartsWith("$")) { * if (ConVar.TryFind(Arg.Substring(1), out ConVar Var)) * Write(Var.ObjectValue); * else * Write("null"); * } else*/ Write(Arg); } Write("\n"); }); ConCmd.Register("alias", (Argv) => { if (Argv.Length == 1) { foreach (var Alias in GetAliases()) { WriteLine("{0} -> {1}", Alias.Item1, Alias.Item2); } } else if (Argv.Length == 2) { foreach (var Alias in GetAliases()) { if (Alias.Item1.StartsWith(Argv[1])) { WriteLine("{0} -> {1}", Alias.Item1, Alias.Item2); } } } else if (Argv.Length == 3) { WriteLine("{0} -> {1}", Argv[1], Argv[2]); RegisterAlias(Argv[1], Argv[2]); } else { Error("alias\nalias <command_alias>\nalias <command_alias> <command>"); } }); ConCmd.Register("var", (Argv) => { if (Argv.Length != 2) { Error("var <variable_name>"); return; } ConVar.Register(Argv[1], 0); }); ConCmd.Register("inc", (Argv) => { if (Argv.Length != 2) { Error("inc <variable_name>"); return; } if (ConVar.TryFind(Argv[1], out ConVar Var)) { ((ConVar <int>)Var).Value++; } }); ConCmd.Register("dec", (Argv) => { if (Argv.Length != 2) { Error("dec <variable_name>"); return; } if (ConVar.TryFind(Argv[1], out ConVar Var)) { ((ConVar <int>)Var).Value--; } }); ConCmd.Register("toggle", (Argv) => { if (Argv.Length != 2) { Error("toggle <variable_name>"); return; } if (ConVar.TryFind(Argv[1], out ConVar Var)) { ConVar <int> IntVar = (ConVar <int>)Var; if (IntVar.Value == 0) { IntVar.Value = 1; } else { IntVar.Value = 0; } } }); ConCmd.Register("cvarlist", (Argv) => { foreach (var CVar in ConVar.GetAll()) { WriteLine(CVar); } }); ConCmd.Register("cmdlist", (Argv) => { foreach (var Cmd in ConCmd.GetAll()) { WriteLine(Cmd); } }); ConCmd.Register("eval", (Argv) => { SendInputQuiet(string.Join("", Argv.Skip(1))); }); ConCmd.Register("mousepos", (Argv) => { GConsole.WriteLine((Engine.Window.WindowSize.GetHeight() - Engine.Window.MousePos).Abs()); }); ConCmd.Register("crash", (Argv) => { throw new InvalidOperationException("Crashing the program!"); }); }