Merge branch 'feature/lua-debugging' into develop
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||
using System.Diagnostics;
|
||||
using MoonSharp.VsCodeDebugger;
|
||||
|
||||
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsScriptAssembly, AllInternalsVisible = true)]
|
||||
namespace Barotrauma
|
||||
@@ -62,6 +63,7 @@ namespace Barotrauma
|
||||
|
||||
public CsScriptLoader CsScriptLoader { get; private set; }
|
||||
public LuaCsSetupConfig Config { get; private set; }
|
||||
public MoonSharpVsCodeDebugServer DebugServer { get; private set; }
|
||||
|
||||
private bool ShouldRunCs
|
||||
{
|
||||
@@ -79,6 +81,8 @@ namespace Barotrauma
|
||||
Game = new LuaGame();
|
||||
Networking = new LuaCsNetworking();
|
||||
|
||||
DebugServer = new MoonSharpVsCodeDebugServer();
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
using (var file = File.Open(configFileName, FileMode.Open, FileAccess.Read))
|
||||
@@ -92,6 +96,38 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleDebugger(int port = 41912)
|
||||
{
|
||||
if (!GameMain.LuaCs.DebugServer.IsStarted)
|
||||
{
|
||||
DebugServer.Start();
|
||||
AttachDebugger();
|
||||
|
||||
LuaCsLogger.Log($"Lua Debug Server started on port {port}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
DetachDebugger();
|
||||
DebugServer.Stop();
|
||||
|
||||
LuaCsLogger.Log($"Lua Debug Server stopped.");
|
||||
}
|
||||
}
|
||||
|
||||
public void AttachDebugger()
|
||||
{
|
||||
DebugServer.AttachToScript(Lua, "Script", s =>
|
||||
{
|
||||
if (s.Name.StartsWith("LocalMods") || s.Name.StartsWith("Lua"))
|
||||
{
|
||||
return Environment.CurrentDirectory + "/" + s.Name;
|
||||
}
|
||||
return s.Name;
|
||||
});
|
||||
}
|
||||
|
||||
public void DetachDebugger() => DebugServer.Detach(Lua);
|
||||
|
||||
public void UpdateConfig()
|
||||
{
|
||||
FileStream file;
|
||||
@@ -234,6 +270,11 @@ namespace Barotrauma
|
||||
Hook?.Call("stop");
|
||||
}
|
||||
|
||||
if (Lua != null && DebugServer.IsStarted)
|
||||
{
|
||||
DebugServer.Detach(Lua);
|
||||
}
|
||||
|
||||
Game?.Stop();
|
||||
|
||||
Hook.Clear();
|
||||
@@ -329,6 +370,11 @@ namespace Barotrauma
|
||||
Lua.Globals["SERVER"] = IsServer;
|
||||
Lua.Globals["CLIENT"] = IsClient;
|
||||
|
||||
if (DebugServer.IsStarted)
|
||||
{
|
||||
AttachDebugger();
|
||||
}
|
||||
|
||||
if (csActive)
|
||||
{
|
||||
LuaCsLogger.LogMessage("Cs! Version " + AssemblyInfo.GitRevision);
|
||||
|
||||
Reference in New Issue
Block a user