Exemplo n.º 1
0
        protected override void OnAttachToProcess(long processId)
        {
            if (connectorRegistry.Connectors.ContainsKey((uint)processId))
            {
                currentConnector = connectorRegistry.Connectors[(uint)processId];
                StartConnecting(currentConnector.SetupConnection(), 3, 1000);
                return;
            }
            else if (UnitySoftDebuggerEngine.UnityPlayers.ContainsKey((uint)processId))
            {
                PlayerConnection.PlayerInfo player = UnitySoftDebuggerEngine.UnityPlayers[(uint)processId];
                int port = (0 == player.m_DebuggerPort
                                        ? (int)(56000 + (processId % 1000))
                                        : (int)player.m_DebuggerPort);
                try {
                    StartConnecting(new SoftDebuggerStartInfo(new SoftDebuggerConnectArgs(player.m_Id, player.m_IPEndPoint.Address, (int)port)), 3, 1000);
                } catch (Exception ex) {
                    throw new Exception(string.Format("Unable to attach to {0}:{1}", player.m_IPEndPoint.Address, port), ex);
                }
                return;
            }

            long defaultPort = 56000 + (processId % 1000);

            StartConnecting(new SoftDebuggerStartInfo(new SoftDebuggerConnectArgs(null, IPAddress.Loopback, (int)defaultPort)), 3, 1000);
        }
        public static UnityAttachInfo GetUnityAttachInfo(long processId, ref IUnityDbgConnector connector)
        {
            if (ConnectorRegistry.Connectors.ContainsKey((uint)processId))
            {
                connector = ConnectorRegistry.Connectors[(uint)processId];
                return(connector.SetupConnection());
            }
            else if (UnityPlayers.ContainsKey((uint)processId))
            {
                PlayerConnection.PlayerInfo player = UnityPlayers[(uint)processId];
                int port = 0 == player.m_DebuggerPort
                    ? (int)(56000 + processId % 1000)
                    : (int)player.m_DebuggerPort;
                try
                {
                    return(new UnityAttachInfo(player.m_Id, player.m_IPEndPoint.Address, port));
                }
                catch (Exception ex)
                {
                    throw new Exception($"Unable to attach to {player.m_IPEndPoint.Address}:{port}", ex);
                }
            }

            long defaultPort = 56000 + (processId % 1000);

            return(new UnityAttachInfo(null, IPAddress.Loopback, (int)defaultPort));
        }
Exemplo n.º 3
0
        public ProcessInfo[] GetAttachableProcesses()
        {
            int index = 1;
            List <ProcessInfo> processes = new List <ProcessInfo> ();

            Process[]        systemProcesses = Process.GetProcesses();
            StringComparison comparison      = StringComparison.OrdinalIgnoreCase;

            if (null != unityPlayerConnection)
            {
                lock (unityPlayerConnection) {
                    foreach (string player in unityPlayerConnection.AvailablePlayers)
                    {
                        try {
                            PlayerConnection.PlayerInfo info = PlayerConnection.PlayerInfo.Parse(player);
                            if (info.m_AllowDebugging)
                            {
                                UnityPlayers[info.m_Guid] = info;
                                processes.Add(new ProcessInfo(info.m_Guid, info.m_Id));
                                ++index;
                            }
                        } catch {
                            // Don't care; continue
                        }
                    }
                }
            }
            if (null != systemProcesses)
            {
                foreach (Process p in systemProcesses)
                {
                    try {
                        if ((p.ProcessName.StartsWith("unity", comparison) ||
                             p.ProcessName.Contains("Unity.app")) &&
                            !p.ProcessName.Contains("UnityShader"))
                        {
                            processes.Add(new ProcessInfo(p.Id, string.Format("{0} ({1})", "Unity Editor", p.ProcessName)));
                        }
                    } catch {
                        // Don't care; continue
                    }
                }
            }

            // Direct USB devices
            iOSDevices.GetUSBDevices(ConnectorRegistry, processes);

            return(processes.ToArray());
        }
 protected override void OnAttachToProcess(long processId)
 {
     if (UnitySoftDebuggerEngine.UnityPlayers.ContainsKey((uint)processId))
     {
         int port = (int)(56000 + (processId % 1000));
         PlayerConnection.PlayerInfo player = UnitySoftDebuggerEngine.UnityPlayers[(uint)processId];
         try {
             StartConnecting(new SoftDebuggerStartInfo(new SoftDebuggerConnectArgs(player.m_Id, player.m_IPEndPoint.Address, (int)port)), 3, 1000);
         } catch (Exception ex) {
             throw new Exception(string.Format("Unable to attach to {0}:{1}", player.m_IPEndPoint.Address, port), ex);
         }
         return;
     }
     base.OnAttachToProcess(processId);
 }
        public static List <UnityProcessInfo> GetUnityPlayerProcesses(bool block)
        {
            int index = 1;
            List <UnityProcessInfo> processes = new List <UnityProcessInfo>();

            if (null == unityPlayerConnection)
            {
                return(processes);
            }

            UnityDebug.Log.Write("UnityPlayerConnection is constructed");
            if (block)
            {
                Monitor.Enter(unityPlayerConnection);

                UnityDebug.Log.Write("Known size of available Players: " + unityPlayerConnection.AvailablePlayers.Count());
                for (int i = 0; i < 12 && !unityPlayerConnection.AvailablePlayers.Any(); ++i)
                {
                    unityPlayerConnection.Poll();
                    Thread.Sleep(250);
                }
            }
            else if (!Monitor.TryEnter(unityPlayerConnection))
            {
                return(processes);
            }

            UnityDebug.Log.Write("New size of available Players: " + unityPlayerConnection.AvailablePlayers.Count());
            foreach (var availablePlayer in unityPlayerConnection.AvailablePlayers)
            {
                UnityDebug.Log.Write($"Available player: {availablePlayer}");
            }

            try
            {
                foreach (string player in unityPlayerConnection.AvailablePlayers)
                {
                    try
                    {
                        PlayerConnection.PlayerInfo info = PlayerConnection.PlayerInfo.Parse(player);
                        if (info.m_AllowDebugging)
                        {
                            UnityPlayers[info.m_Guid] = info;
                            processes.Add(new UnityProcessInfo(info.m_Guid, info.m_Id, info.m_ProjectName));
                            ++index;
                        }
                    }
                    catch (Exception e)
                    {
                        UnityDebug.Log.Write($"{player}: could not be parsed: {e.Message}");
                        // Don't care; continue
                    }
                }
            }
            finally
            {
                Monitor.Exit(unityPlayerConnection);
            }

            return(processes);
        }
        public override ProcessInfo[] GetAttachableProcesses()
        {
            int index = 1;
            List <ProcessInfo> processes = new List <ProcessInfo> ();

            StringComparison comparison = StringComparison.OrdinalIgnoreCase;

            if (null != unityPlayerConnection)
            {
                if (Monitor.TryEnter(unityPlayerConnection))
                {
                    try {
                        foreach (string player in unityPlayerConnection.AvailablePlayers)
                        {
                            try {
                                PlayerConnection.PlayerInfo info = PlayerConnection.PlayerInfo.Parse(player);
                                if (info.m_AllowDebugging)
                                {
                                    UnityPlayers[info.m_Guid] = info;
                                    processes.Add(new ProcessInfo(info.m_Guid, info.m_Id));
                                    ++index;
                                }
                            } catch {
                                // Don't care; continue
                            }
                        }
                    }
                    finally {
                        Monitor.Exit(unityPlayerConnection);
                    }
                }
            }

            if (unityProcessesFinished)
            {
                unityProcessesFinished = false;

                ThreadPool.QueueUserWorkItem(delegate {
                    Process[] systemProcesses = Process.GetProcesses();
                    var unityThreadProcesses  = new List <ProcessInfo>();

                    if (systemProcesses != null)
                    {
                        foreach (Process p in systemProcesses)
                        {
                            try {
                                if ((p.ProcessName.StartsWith("unity", comparison) ||
                                     p.ProcessName.Contains("Unity.app")) &&
                                    !p.ProcessName.Contains("UnityShader") &&
                                    !p.ProcessName.Contains("UnityHelper") &&
                                    !p.ProcessName.Contains("Unity Helper"))
                                {
                                    unityThreadProcesses.Add(new ProcessInfo(p.Id, string.Format("{0} ({1})", "Unity Editor", p.ProcessName)));
                                }
                            } catch {
                                // Don't care; continue
                            }
                        }

                        unityProcesses         = unityThreadProcesses;
                        unityProcessesFinished = true;
                    }
                });
            }

            processes.AddRange(unityProcesses);

            if (usbProcessesFinished)
            {
                usbProcessesFinished = false;

                ThreadPool.QueueUserWorkItem(delegate {
                    // Direct USB devices
                    lock (usbLock)
                    {
                        var usbThreadProcesses = new List <ProcessInfo>();

                        try
                        {
                            iOSDevices.GetUSBDevices(ConnectorRegistry, usbThreadProcesses);
                        }
                        catch (NotSupportedException)
                        {
                            LoggingService.LogInfo("iOS over USB not supported on this platform");
                        }
                        catch (Exception e)
                        {
                            LoggingService.LogError("iOS USB Error: " + e);
                        }
                        usbProcesses         = usbThreadProcesses;
                        usbProcessesFinished = true;
                    }
                });
            }

            processes.AddRange(usbProcesses);

            return(processes.ToArray());
        }