Merge branch 'feature/lua-debugging' into develop
This commit is contained in:
@@ -3380,6 +3380,18 @@ namespace Barotrauma
|
||||
{
|
||||
GameMain.LuaCs.Initialize();
|
||||
}));
|
||||
|
||||
commands.Add(new Command("cl_toggleluadebug", "Toggles the MoonSharp Debug Server.", (string[] args) =>
|
||||
{
|
||||
int port = 41912;
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int.TryParse(args[0], out port);
|
||||
}
|
||||
|
||||
GameMain.LuaCs.ToggleDebugger(port);
|
||||
}));
|
||||
}
|
||||
|
||||
private static void ReloadWearables(Character character, int variant = 0)
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Barotrauma
|
||||
"Sigil.dll",
|
||||
"Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll",
|
||||
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
|
||||
"MoonSharp.Interpreter.dll",
|
||||
"MoonSharp.Interpreter.dll", "MoonSharp.VsCodeDebugger.dll",
|
||||
|
||||
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
|
||||
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
|
||||
|
||||
@@ -1260,6 +1260,18 @@ namespace Barotrauma
|
||||
GameMain.LuaCs.Initialize();
|
||||
}));
|
||||
|
||||
commands.Add(new Command("toggleluadebug", "Toggles the MoonSharp Debug Server.", (string[] args) =>
|
||||
{
|
||||
int port = 41912;
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int.TryParse(args[0], out port);
|
||||
}
|
||||
|
||||
GameMain.LuaCs.ToggleDebugger(port);
|
||||
}));
|
||||
|
||||
#if WINDOWS
|
||||
commands.Add(new Command("install_cl_lua|install_cl|install_cl_cs|install_cl_luacs", "Installs Client-Side LuaCs into your client.", (string[] args) =>
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Barotrauma
|
||||
"Sigil.dll",
|
||||
"Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll",
|
||||
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
|
||||
"MoonSharp.Interpreter.dll",
|
||||
"MoonSharp.Interpreter.dll", "MoonSharp.VsCodeDebugger.dll",
|
||||
|
||||
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
|
||||
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
|
||||
<PackageReference Include="Sigil" Version="5.0.0" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.Interpreter\MoonSharp.Interpreter.csproj" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -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