!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / VisualStudioExtensions / CryEngineMonoDebugger / source / CryEngine.Debugger.Mono / CryEngineDebuggerSession.cs
blobe8a9758e6ec75155bcde4a71a9653dfc651ecc9e
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Diagnostics;
5 using System.IO;
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
16 GameLauncher,
17 Sandbox,
18 Server
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);
29 switch (launcher)
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;
79 _process.Start();
81 StartRemoteConsole(remoteConsolePort);
84 private void StartRemoteConsole(int port)
86 StopRemoteConsole();
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)
105 StopRemoteConsole();
106 Exit();
109 protected override void OnExit()
111 StopRemoteConsole();
112 if (_process != null && !_process.HasExited)
114 _process.Kill();