protected static void PrintHelp(AugmentrexContext context, Command command, bool details) { context.SuccessLine(" {0} {1}", string.Join("|", command.Names), command.Syntax); context.InfoLine(" {0}", command.Description); if (details && command.Details.Count != 0) { foreach (var detail in command.Details) { context.Line(); context.InfoLine(" {0}", detail); } } }
public override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <HelpOptions>(context, args); if (opts == null) { return(null); } if (opts.Commands.Any()) { var cmds = opts.Commands.Select(x => (x, CommandInterpreter.GetCommand(x))); var unknown = false; foreach (var(name, cmd) in cmds) { if (cmd == null) { unknown = true; context.ErrorLine("Unknown command '{0}'.", name); } } if (unknown) { return(null); } context.Line(); foreach (var(_, cmd) in cmds) { PrintHelp(context, cmd, true); context.Line(); } } else { context.Line(); context.InfoLine("Available commands:"); context.Line(); foreach (var cmd in CommandInterpreter.Commands) { PrintHelp(context, cmd, false); context.Line(); } } return(null); }
public override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <KeyOptions>(context, args); if (opts == null) { return(null); } if (!opts.Add && !opts.Delete) { foreach (var kvp in _bindings) { context.InfoLine("{0} = {1}", kvp.Key, kvp.Value); } return(null); } var info = new HotKeyInfo(opts.Key, opts.Alt, opts.Control, opts.Shift); if (_handler == null) { void KeyHandler(HotKeyInfo info) { var freq = context.Configuration.HotKeyBeepFrequency; if (freq != 0) { context.Ipc.Channel.Beep(freq, context.Configuration.HotKeyBeepDuration); } if (_bindings.TryGetValue(info, out var command)) { context.Interpreter.RunCommand(command, true); } } _handler = new HotKeyHandler(KeyHandler); } if (opts.Add) { var command = string.Join(" ", opts.Fragments); if (string.IsNullOrWhiteSpace(command)) { context.ErrorLine("No command given."); return(null); } if (_bindings.TryAdd(info, command)) { context.HotKeys.Add(info, _handler); context.InfoLine("Added key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding already exists: {0} = {1}", info, _bindings[info]); } } if (opts.Delete) { if (_bindings.Remove(info, out var command)) { context.InfoLine("Deleted key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding not found: {0}", info); } } return(null); }
public override void Stop(AugmentrexContext context) { context.InfoLine("Simple test plugin stopped."); }
public unsafe override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <ReadOptions>(context, args); if (opts == null) { return(null); } var parsed = (int)TypeDescriptor.GetConverter(typeof(int)).ConvertFromString(opts.Offset); var memory = context.Memory; var offset = opts.Absolute ? memory.ToOffset((MemoryAddress)parsed) : (MemoryOffset)parsed; switch (opts.Type) { case ReadType.I8: var i8 = memory.Read <sbyte>(offset); context.InfoLine("{0} (0x{0:X})", i8); break; case ReadType.U8: var u8 = memory.Read <byte>(offset); context.InfoLine("{0} (0x{0:X})", u8); break; case ReadType.I16: var i16 = memory.Read <short>(offset); context.InfoLine("{0} (0x{0:X})", i16); break; case ReadType.U16: var u16 = memory.Read <ushort>(offset); context.InfoLine("{0} (0x{0:X})", u16); break; case ReadType.I32: var i32 = memory.Read <int>(offset); context.InfoLine("{0} (0x{0:X})", i32); break; case ReadType.U32: var u32 = memory.Read <uint>(offset); context.InfoLine("{0} (0x{0:X})", u32); break; case ReadType.I64: var i64 = memory.Read <long>(offset); context.InfoLine("{0} (0x{0:X})", i64); break; case ReadType.U64: var u64 = memory.Read <ulong>(offset); context.InfoLine("{0} (0x{0:X})", u64); break; case ReadType.F32: var f32 = memory.Read <float>(offset); context.InfoLine("{0} (0x{0:X})", f32, Unsafe.Read <uint>(&f32)); break; case ReadType.F64: var f64 = memory.Read <double>(offset); context.InfoLine("{0} (0x{0:X})", f64, Unsafe.Read <uint>(&f64)); break; case ReadType.Ptr: var ptr = memory.ReadOffset(offset); context.InfoLine("{0}{1}={2}", memory.Address, ptr, memory.Address + ptr); break; } return(null); }
public override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <EvaluateOptions>(context, args); if (opts == null) { return(null); } if (_script == null || opts.Clear) { _script = CSharpScript.Create(string.Empty, ScriptOptions.Default.WithFilePath("<hgl>") .WithImports(ScriptOptions.Default.Imports.AddRange( Assembly.GetExecutingAssembly().DefinedTypes.Select(x => x.Namespace).Where(x => x != null).Distinct())) .WithLanguageVersion(LanguageVersion.CSharp8) .WithReferences(Assembly.GetExecutingAssembly()), typeof(Globals)); } var code = string.Join(" ", opts.Fragments); if (string.IsNullOrWhiteSpace(code)) { return(null); } Script script = _script.ContinueWith(code); Task <ScriptState> task; try { task = script.RunAsync(new Globals(context)); } catch (CompilationErrorException ex) { foreach (var diag in ex.Diagnostics) { context.ErrorLine("{0}", diag.ToString()); } return(null); } try { task.Wait(); } catch (AggregateException ex) { context.ErrorLine("{0}", ex.InnerException); return(null); } _script = script; var result = task.Result.ReturnValue; context.InfoLine("{0} it = {1}", result?.GetType() ?? typeof(object), result ?? "null"); return(null); }