public virtual void Execute(IDictionary <string, object> context) { var delegParams = TargetDelegate.Method.GetParameters(); if (delegParams.Length != Arguments.Count) { throw new TargetParameterCountException( String.Format("Delegate {0} requires {1} parameter(s)", TargetDelegate.GetType(), delegParams.Length)); } var argValues = new object[Arguments.Count]; var i = 0; foreach (var argFunc in Arguments) { var argValue = argFunc(context); argValues[i] = ConvertManager.ChangeType(argValue, delegParams[i].ParameterType); i++; } var invokeResult = TargetDelegate.DynamicInvoke(argValues); if (ResultKey != null) { context[ResultKey] = invokeResult; } }
/// <summary> /// Calls the original function, and returns a return value. /// </summary> /// <param name="args"> /// The arguments to pass. If it is a 'void' argument list, /// you MUST pass 'null'. /// </param> /// <returns>An object containing the original functions return value.</returns> public object CallOriginal(params object[] args) { Disable(); var ret = TargetDelegate.DynamicInvoke(args); Enable(); return(ret); }
/// <summary> /// Creates a new instance of an OrbwalkerMode using a new Keybind /// </summary> public OrbwalkerMode( string name, KeyCode key, TargetDelegate targetDelegate, OrbwalkModeDelegate orbwalkBehaviour) { this.Name = name ?? throw new Exception("There was an error creating the Orbwalker Mode"); this.ModeBehaviour = orbwalkBehaviour; this.GetTargetImplementation = targetDelegate; this.MenuItem = new MenuKeyBind(name, name, key, KeybindType.Press); }
/// <summary> /// Creates a new instance of an OrbwalkerMode using a Global Key /// </summary> public OrbwalkerMode(string name, GlobalKey key, TargetDelegate targetDelegate, OrbwalkModeDelegate orbwalkBehaviour) { if (name == null || key == null) { throw new Exception("There was an error creating the Orbwalker Mode"); } this.Name = name; this.ModeBehaviour = orbwalkBehaviour; this.GetTargetImplementation = targetDelegate; this.MenuItem = key.KeyBindItem; key.Activate(); this.UsingGlobalKey = true; }
/// <summary> /// Creates a new instance of an OrbwalkerMode using a new Keybind /// </summary> public OrbwalkerMode( string name, KeyCode key, TargetDelegate targetDelegate, OrbwalkModeDelegate orbwalkBehaviour) { this.Name = name ?? throw new Exception("There was an error creating the Orbwalker Mode"); this.ModeBehaviour = orbwalkBehaviour; this.GetTargetImplementation = targetDelegate; this.MenuItem = new MenuKeyBind(name, name, key, KeybindType.Press); this.ModeMenu = new Menu($"orbmode.{name}", name) { new MenuBool($"orbmode.{name}.move", "Movement"), new MenuBool($"orbmode.{name}.attack", "Attacking") }; }
public List <EventResponse> FireEvent(String EventName, Event Event) { List <EventResponse> ResponseList = new List <EventResponse>(); Type LocalType = this.GetType(); Type TargetType = null; if ((TargetType = this.FindEventType(LocalType, EventName)) == null) { return(ResponseList); } else { FieldInfo TargetField = TargetType.GetField(EventName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); MulticastDelegate EventDelegates = (MulticastDelegate)TargetField.GetValue(this); if (EventDelegates == null) { return(ResponseList); } else { foreach (Delegate TargetDelegate in EventDelegates.GetInvocationList()) { try { Object DelegateResponse = TargetDelegate.DynamicInvoke(new Object[] { Event }); EventResponse Response = (EventResponse)DelegateResponse; ResponseList.Add(Response); } catch (Exception e) { } } return(ResponseList); } } }
/// <summary> /// Creates a new instance of an OrbwalkerMode using a Global Key /// </summary> public OrbwalkerMode( string name, GlobalKey key, TargetDelegate targetDelegate, OrbwalkModeDelegate orbwalkBehaviour) { if (name == null || key == null) { throw new Exception("There was an error creating the Orbwalker Mode"); } this.Name = name; this.ModeBehaviour = orbwalkBehaviour; this.GetTargetImplementation = targetDelegate; this.MenuItem = key.KeyBindItem; key.Activate(); this.UsingGlobalKey = true; this.ModeMenu = new Menu($"orbmode.{name}", name) { new MenuBool($"orbmode.{name}.move", "Movement"), new MenuBool($"orbmode.{name}.attack", "Attacking") }; }