1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Diagnostics
;
6 using Mono
.Debugging
.Client
;
7 using Mono
.Debugging
.Soft
;
9 // Process is ambigious between System.Diagnostics and EnvDTE, but we only need one.
10 using Process
= System
.Diagnostics
.Process
;
12 namespace CryEngine
.Debugger
.Mono
14 public enum LauncherType
21 public class CryEngineDebuggerSession
: SoftDebuggerSession
23 private Process _process
;
24 private RemoteConsole _remoteConsole
;
26 private string GetLauncherPath(string gameLauncherPath
, LauncherType launcher
)
28 var dir
= Path
.GetDirectoryName(gameLauncherPath
);
31 case LauncherType
.GameLauncher
:
32 return Path
.Combine(dir
, "GameLauncher.exe");
33 case LauncherType
.Sandbox
:
34 return Path
.Combine(dir
, "Sandbox.exe");
35 case LauncherType
.Server
:
36 return Path
.Combine(dir
, "Game_Server.exe");
38 return gameLauncherPath
;
41 protected override void OnRun(DebuggerStartInfo startInfo
)
43 base.OnRun(startInfo
);
44 UseOperationThread
= true;
46 var cryStartInfo
= startInfo
as CryEngineStartInfo
;
47 if (cryStartInfo
== null)
49 throw new ArgumentException(string.Format("The value of {0} is not a valid type of '{1}'.", nameof(startInfo
), typeof(CryEngineStartInfo
).Name
));
52 var listenArgs
= cryStartInfo
.StartArgs
as SoftDebuggerConnectArgs
;
53 var projectData
= cryStartInfo
.ProjectData
;
55 var launcherPath
= GetLauncherPath(projectData
.LauncherPath
, cryStartInfo
.LauncherType
);
57 if (!File
.Exists(launcherPath
))
59 throw new InvalidOperationException(string.Format("Did not find a valid launcher at expected location: {0}", launcherPath
));
62 var remoteConsolePort
= NetworkHelper
.GetAvailablePort(4600, 4610);
64 var arguments
= string.Format("-project {0} -monoDebuggerPort {1} {2} -monoSuspend 1 -remoteConsolePort {3}",
65 projectData
.ProjectPath
, listenArgs
.DebugPort
, projectData
.CommandArguments
, remoteConsolePort
);
67 var processStartInfo
= new ProcessStartInfo(launcherPath
, arguments
)
69 UseShellExecute
= true
72 _process
= new Process
74 StartInfo
= processStartInfo
77 _process
.Exited
+= OnProcessExitedExternally
;
81 StartRemoteConsole(remoteConsolePort
);
84 private void StartRemoteConsole(int port
)
88 _remoteConsole
= new RemoteConsole(port
);
89 _remoteConsole
.SetListener(new CryEngineConsoleListener());
90 _remoteConsole
.Start();
93 private void StopRemoteConsole()
95 if (_remoteConsole
!= null)
97 _remoteConsole
.Stop();
98 _remoteConsole
.Dispose();
99 _remoteConsole
= null;
103 private void OnProcessExitedExternally(object sender
, EventArgs e
)
109 protected override void OnExit()
112 if (_process
!= null && !_process
.HasExited
)