Exemple #1
0
 /// <summary>
 /// Do not call this constructor. Use SxLib.InitializeOffscreen instead.
 /// </summary>
 /// <param name="_Current"></param>
 /// <param name="_SynapseDir"></param>
 protected internal SxLibOffscreen(string _SynapseDir) : base(_SynapseDir)
 {
     LoadEventInternal   += delegate(SynLoadEvents LEvent, object Param) { LoadEvent?.Invoke(LEvent, Param); };
     AttachEventInternal += delegate(SynAttachEvents AEvent, object Param) { AttachEvent?.Invoke(AEvent, Param); };
     HubEventInternal    += delegate(List <SynHubEntry> Entries)
     {
         ScriptHubMarkAsClosedInternal();
         ScriptHubEvent?.Invoke(Entries);
     };
 }
Exemple #2
0
        void Notify(AttachEvent evt, string message, AttachEventType eventType)
        {
            AttachEventInfo info = new AttachEventInfo(eventType, this);

            seedObject.SendMessage(message, info, SendMessageOptions.DontRequireReceiver);
            if (evt != null)
            {
                evt.Invoke(info);
            }
        }
Exemple #3
0
        void HandleEvent(AttachEventInfo info)
        {
            AttachEvent evt = events.GetOrCreateEvent(info.eventType);

            if (evt == null)
            {
                return;
            }
            AttachEventInfo newInfo = new AttachEventInfo(info.eventType, info.attachment, info.attachObject,
                                                          sender: this);

            evt.Invoke(newInfo);
        }
Exemple #4
0
        void HandleEvent(AttachEventInfo info)
        {
            AttachEventInfo newInfo = new AttachEventInfo(info.eventType, info.attachObject, sender: this);

            if (!attachObjects.Contains(info.attachObject))
            {
                return;
            }
            AttachEvent evt = events.GetOrCreateEvent(newInfo.eventType);

            if (evt != null)
            {
                evt.Invoke(newInfo);
            }
        }
        // Handles Attaching Hardpoint-Mountpoint pairs
        void Handle(AttachEvent e)
        {
            Hardpoint  hardpoint;
            Mountpoint mountpoint;

            if (e.Parent != e.Child && e.Parent.TryGetComponents(out hardpoint) && e.Child.TryGetComponents(out mountpoint))
            {
                e.Child.transform.SetParent(e.Parent.transform);
                Ego.SetParent(e.Parent, e.Child);
                e.Child.transform.localRotation = Quaternion.AngleAxis(mountpoint.LocalRotation, Vector3.forward);
                e.Child.transform.localPosition = hardpoint.LocalVector2D + mountpoint.LocalVector2D;

                // Makes sure attached body doesn't change parent's center of gravity or mass, and doesn't collide with the parent
                Rigidbody2D rigidbody2D;
                if (e.Child.TryGetComponents(out rigidbody2D))
                {
                    rigidbody2D.isKinematic = true;
                    rigidbody2D.simulated   = false;
                }

                hardpoint.Attached = mountpoint.GetComponent <EgoComponent>();
            }
        }
Exemple #6
0
        void HandleMessage(string msg, dynamic args, Request request)
        {
            LogDebug("(in)  " + request.type + " " + msg);
            LogVerbose("... " + JsonConvert.SerializeObject(request));

            args = args ?? new { };

            try
            {
                switch (msg)
                {
                case "initialize":
                    var cap = new Capabilities();
                    InitializeEvent?.Invoke(request, cap);
                    Send(request, cap);
                    Initialized();
                    break;

                case "configurationDone":
                    ConfigurationDoneEvent?.Invoke(request);
                    break;

                case "launch":
                    LaunchEvent?.Invoke(request, JsonConvert.SerializeObject(args));
                    break;

                case "attach":
                    AttachEvent?.Invoke(request, JsonConvert.SerializeObject(args));
                    break;

                case "disconnect":
                    DisconnectEvent?.Invoke(request);
                    break;

                case "next":
                    StepOverEvent?.Invoke(request);
                    break;

                case "continue":
                    ContinueEvent?.Invoke(request);
                    break;

                case "stepIn":
                    StepInEvent?.Invoke(request);
                    break;

                case "stepOut":
                    StepOutEvent?.Invoke(request);
                    break;

                case "pause":
                    PauseEvent?.Invoke(request);
                    break;

                case "threads":
                    GetThreadsEvent?.Invoke(request);
                    break;

                case "scopes":
                    GetScopesEvent?.Invoke(request, (int)args.frameId);
                    break;

                case "stackTrace":
                    GetStackTraceEvent?.Invoke(request);
                    break;

                case "variables":
                    _tempVariables.Clear();
                    GetVariablesEvent?.Invoke(request, (int)args.variablesReference, _tempVariables);
                    Send(request, new VariablesResponseBody(_tempVariables));
                    break;

                case "setVariable":

                    var variable = new Variable((string)args.name, (string)args.value, "", (int)args.variablesReference);

                    SetVariableEvent?.Invoke(
                        request, variable
                        );

                    Send(
                        request,
                        new SetVariableResponseBody(variable.value, variable.variablesReference)
                        );

                    break;

                case "loadedSources":
                    GetLoadedSourcesEvent?.Invoke(request);
                    break;

                case "source":
                    GetSourceEvent?.Invoke(request);
                    break;

                case "evaluate":

                    string resultEval = "";
                    EvaluateEvent?.Invoke(
                        request, (int)args.frameId, (string)args.context, (string)args.expression, (bool)(args.format?.hex ?? false),
                        ref resultEval
                        );

                    Send(
                        request,
                        new EvaluateResponseBody(
                            resultEval
                            )
                        );

                    break;

                case "completions":
                    GetCompletionsEvent?.Invoke(
                        request, (int)args.frameId, (int)args.line, (int)args.column, (string )args.text
                        );
                    break;


                case "setBreakpoints":
                    SetBreakpointsEvent?.Invoke(request);
                    break;


//                    case "runInTerminal":
//                        OnRunInTerminal?.Invoke( pRequest );
//                        break;


//                    case "setFunctionBreakpoints":
//                        SetFunctionBreakpoints( pResponse, pArgs );
//                        break;

//                    case "setExceptionBreakpoints":
//                        SetExceptionBreakpoints( pResponse, pArgs );
//                        break;

                default:

                    CustomRequestEvent?.Invoke(request);

                    if (!request.responded)
                    {
                        Log(
                            Logging.Severity.Error,
                            string.Format("Request not handled: '{0}' [{1}]", msg, Convert.Encode(request.arguments.ToString()))
                            );
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                Log(
                    Logging.Severity.Error,
                    $"Error during request '{Convert.Encode( request.arguments.ToString() )}' [{msg}] (exception: {e.Message})\n{e}"
                    );

                Send(new Response(request, errorMsg: e.Message));
            }
        }
Exemple #7
0
 /// <summary>
 /// Do not call this constructor. Use SxLib.InitializeWinForms instead.
 /// </summary>
 /// <param name="_Current"></param>
 /// <param name="_SynapseDir"></param>
 protected internal SxLibWinForms(Form _Current, string _SynapseDir) : base(_SynapseDir)
 {
     Current              = _Current;
     LoadEventInternal   += delegate(SynLoadEvents LEvent, object Param) { Current.Invoke(new Action(() => { LoadEvent?.Invoke(LEvent, Param); })); };
     AttachEventInternal += delegate(SynAttachEvents AEvent, object Param) { Current.Invoke(new Action(() => { AttachEvent?.Invoke(AEvent, Param); })); };
     HubEventInternal    += delegate(List <SynHubEntry> Entries) { Current.Invoke(new Action(() => { ScriptHubEvent?.Invoke(Entries); })); };
 }
        internal override void _window_PreDrawGraphics(object sender, DrawGraphicsEventArgs e)
        {
            if (!Loaded)
            {
                return;
            }
            if (!_windowLoaded)
            {
                return;
            }

            #region Attach

            try
            {
                if (_attachTargetName != "")
                {
                    if (_attachTargetType == AttachTargetEnum.Process)
                    {
                        var foregroundWindowHandle = User32.GetForegroundWindow();

                        if (foregroundWindowHandle != _foregroundWindowHandle)
                        {
                            _foregroundWindowHandle = foregroundWindowHandle;
                            User32.GetWindowThreadProcessId(_foregroundWindowHandle, ref _foregroundProcessId);
                            var processes = Process.GetProcessesByName(_attachTargetName);

                            if (processes.Length != 0)
                            {
                                _targetProcessId = processes.First().Id;
                                if (_targetProcessId == _foregroundProcessId || _foregroundProcessId == _currentProcessId)
                                {
                                    _targetWindowHandle = processes.First().MainWindowHandle;

                                    if (AttachToTargetMode == AttachToTargetModeEnum.Manual)
                                    {
                                        if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.Foreground)
                                        {
                                            AttachEvent?.Invoke(TargetStateEnum.Foreground);
                                        }
                                        else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always)
                                        {
                                            AttachEvent?.Invoke(TargetStateEnum.Foreground);
                                        }
                                    }

                                    _targetState = TargetStateEnum.Foreground;

                                    if (AttachToTargetMode == AttachToTargetModeEnum.Automatic)
                                    {
                                        if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Exit)
                                        {
                                            Process.GetCurrentProcess().Kill(); //Поменять
                                        }
                                        if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Show)
                                        {
                                            Window.Show();
                                            Window.PlaceAbove(_targetWindowHandle);
                                            Window.FitTo(_targetWindowHandle, true);
                                        }

                                        if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Hide)
                                        {
                                            Window.Hide();
                                        }

                                        if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.OpacityChange)
                                        {
                                            Window.Show();
                                            CurrentOpacity = OpacityWhenTargetStateForeground;
                                            Window.PlaceAbove(_targetWindowHandle);
                                            Window.FitTo(_targetWindowHandle, true);
                                        }
                                        else
                                        {
                                            CurrentOpacity = 1f;
                                        }
                                    }
                                }
                                else
                                {
                                    if (AttachToTargetMode == AttachToTargetModeEnum.Manual)
                                    {
                                        if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.Background)
                                        {
                                            AttachEvent?.Invoke(TargetStateEnum.Background);
                                        }
                                        else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always)
                                        {
                                            AttachEvent?.Invoke(TargetStateEnum.Background);
                                        }
                                    }

                                    _targetState = TargetStateEnum.Background;

                                    if (AttachToTargetMode == AttachToTargetModeEnum.Automatic)
                                    {
                                        if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Exit)
                                        {
                                            Process.GetCurrentProcess().Kill(); //Поменять
                                        }
                                        if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Show)
                                        {
                                            Window.Show();
                                            Window.PlaceAbove(_targetWindowHandle);
                                            Window.FitTo(_targetWindowHandle, true);
                                        }

                                        if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Hide)
                                        {
                                            Window.Hide();
                                        }

                                        if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.OpacityChange)
                                        {
                                            Window.Show();
                                            CurrentOpacity = OpacityWhenTargetStateBackground;
                                            Window.PlaceAbove(_targetWindowHandle);
                                            Window.FitTo(_targetWindowHandle, true);
                                        }
                                        else
                                        {
                                            CurrentOpacity = 1f;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (AttachToTargetMode == AttachToTargetModeEnum.Manual)
                                {
                                    if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.None)
                                    {
                                        AttachEvent?.Invoke(TargetStateEnum.None);
                                    }
                                    else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always)
                                    {
                                        AttachEvent?.Invoke(TargetStateEnum.None);
                                    }
                                }

                                _targetState = TargetStateEnum.None;

                                if (AttachToTargetMode == AttachToTargetModeEnum.Manual)
                                {
                                    if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Exit)
                                    {
                                        Process.GetCurrentProcess().Kill(); //Поменять
                                    }
                                    if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Show)
                                    {
                                        Window.Show();
                                        Window.PlaceAbove(_targetWindowHandle);
                                        Window.FitTo(_targetWindowHandle, true);
                                    }

                                    if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Hide)
                                    {
                                        Window.Hide();
                                    }

                                    if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.OpacityChange)
                                    {
                                        Window.Show();
                                        CurrentOpacity = OpacityWhenTargetStateNone;
                                        Window.PlaceAbove(_targetWindowHandle);
                                        Window.FitTo(_targetWindowHandle, true);
                                    }
                                    else
                                    {
                                        CurrentOpacity = 1f;
                                    }
                                } //none
                            }
                        }
                        else
                        {
                            //not change
                            if (AttachToTargetMode == AttachToTargetModeEnum.Manual)
                            {
                                if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always)
                                {
                                    AttachEvent?.Invoke(TargetStateEnum.None);
                                }
                            }

                            if (AttachToTargetMode == AttachToTargetModeEnum.Automatic)
                            {
                                if (Window.IsVisible)
                                {
                                    if (_targetWindowHandle != IntPtr.Zero)
                                    {
                                        Window.PlaceAbove(_targetWindowHandle);

                                        Window.FitTo(_targetWindowHandle, true);
                                    }
                                }
                            }
                        }
                    }

                    if (_attachTargetType == AttachTargetEnum.Window)
                    {
                    }
                }
            }
            catch (Exception exception) { }
            //if (_attachTargetName != "")
            //{
            //    if (_attachTargetMode == AttachTarget.Process)
            //    {
            //        _foregroundWindowHandle = User32.GetForegroundWindow();
            //        User32.GetWindowThreadProcessId(_foregroundWindowHandle, out _foregroundProcessId);
            //        var processes = Process.GetProcessesByName(_attachTargetName);

            //        if (processes.Length != 0)
            //        {
            //            _targetProcessId = processes.First().Id;

            //            if (_targetProcessId == _foregroundProcessId || _foregroundProcessId == _currentProcessId)
            //            {
            //                //if (HideOverlayWhenTargetWindowNoForeground)
            //                //{
            //                    if (!g.Window.IsVisible)
            //                        g.Window.Show();
            //                //}
            //                //else
            //                //{
            //                    if (!g.Window.IsTopmost)
            //                        g.Window.MakeTopmost();
            //                //}

            //                var targetProcessMainWindowHandle = processes.First().MainWindowHandle;
            //                g.Window.PlaceAboveWindow(targetProcessMainWindowHandle);

            //                if (_aspectRatio.CloseTo(0))
            //                    g.Window.FitToWindow(targetProcessMainWindowHandle);
            //                else
            //                    g.Window.FitToWindow(targetProcessMainWindowHandle, _aspectRatio);
            //            }
            //            else
            //            {
            //                if (HideOverlayWhenTargetWindowNoForeground)
            //                {
            //                    if (g.Window.IsVisible)
            //                        g.Window.Hide();
            //                }
            //                else
            //                {
            //                    if (g.Window.IsTopmost)
            //                        g.Window.RemoveTopmost();
            //                }
            //            }
            //        }
            //        else
            //        {
            //            _targetProcessId = -1;

            //            if (WorkWithoutProcess)
            //            {
            //                if (g.Window.IsVisible)
            //                    g.Window.Hide();
            //            }
            //            else
            //            {
            //                OnAppExit();
            //                g.Overlay.StopHook();
            //                g.Overlay.Window.Graphics.Dispose();
            //                Process.GetCurrentProcess().Kill();
            //            }
            //        }
            //    }
            //    else if(_attachTargetMode == AttachTarget.ActiveWindowTitle)
            //    {
            //        _foregroundWindowTitle = User32.GetActiveWindowTitle();

            //        if (_foregroundWindowTitle != null)
            //        {
            //            if (_foregroundWindowTitle.Contains(_attachTargetName))
            //            {
            //                if (!g.Window.IsVisible)
            //                    g.Window.Show();

            //                var targetProcessMainWindowHandle = User32.GetForegroundWindow();
            //                g.Window.PlaceAboveWindow(targetProcessMainWindowHandle);

            //                g.Window.FitToWindow(targetProcessMainWindowHandle, _aspectRatio);
            //            }
            //            else
            //            {
            //                if (g.Window.IsVisible)
            //                    g.Window.Hide();
            //            }
            //        }
            //    }
            //}

            #endregion

            OnPreDraw?.Invoke(sender, e);
        }
Exemple #9
0
 /// <summary>
 /// Do not call this constructor. Use SxLib.InitializeWPF instead.
 /// </summary>
 /// <param name="_Current"></param>
 /// <param name="_SynapseDir"></param>
 protected internal SxLibWPF(Window _Current, string _SynapseDir) : base(_SynapseDir)
 {
     Current              = _Current;
     LoadEventInternal   += delegate(SynLoadEvents LEvent, object Param) { Current.Dispatcher.Invoke(() => { LoadEvent?.Invoke(LEvent, Param); }); };
     AttachEventInternal += delegate(SynAttachEvents AEvent, object Param) { Current.Dispatcher.Invoke(() => { AttachEvent?.Invoke(AEvent, Param); }); };
     HubEventInternal    += delegate(List <SynHubEntry> Entries) { Current.Dispatcher.Invoke(() => { ScriptHubEvent?.Invoke(Entries); }); };
 }