Merge branch 'feature/lua-debugging' into develop

This commit is contained in:
EvilFactory
2023-04-12 11:40:16 -03:00
11 changed files with 150 additions and 19 deletions

View File

@@ -23,6 +23,7 @@ env:
0Harmony.dll
Sigil.dll
MoonSharp.Interpreter.dll
MoonSharp.VsCodeDebugger.dll
MonoMod.Common.dll
Mono.Cecil.dll
Mono.Cecil.Mdb.dll

View File

@@ -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)

View File

@@ -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",

View File

@@ -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) =>
{

View File

@@ -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",

View File

@@ -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>

View File

@@ -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);

View File

@@ -46,10 +46,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.Interpreter", "Li
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeployAll", "Deploy\DeployAll\DeployAll.csproj", "{60B82E13-2CDD-4C74-8373-FD7264D6C80B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.VsCodeDebugger", "Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj", "{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{95c4d59d-9be4-4278-b4f8-46c0ba1a3916}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
@@ -203,6 +202,18 @@ Global
{F1B80D94-8BD6-48CE-8D17-BB2A5C98BCA3}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{F1B80D94-8BD6-48CE-8D17-BB2A5C98BCA3}.Unstable|x64.ActiveCfg = Debug|Any CPU
{F1B80D94-8BD6-48CE-8D17-BB2A5C98BCA3}.Unstable|x64.Build.0 = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Debug|x64.Build.0 = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Release|Any CPU.Build.0 = Release|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Release|x64.ActiveCfg = Release|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Release|x64.Build.0 = Release|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Unstable|Any CPU.ActiveCfg = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Unstable|x64.ActiveCfg = Debug|Any CPU
{382DFA63-78FC-41AC-BA85-630960A56E5C}.Unstable|x64.Build.0 = Debug|Any CPU
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -215,6 +226,18 @@ Global
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Unstable|x64.ActiveCfg = Debug|Any CPU
{60B82E13-2CDD-4C74-8373-FD7264D6C80B}.Unstable|x64.Build.0 = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Debug|x64.Build.0 = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Release|Any CPU.Build.0 = Release|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Release|x64.ActiveCfg = Release|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Release|x64.Build.0 = Release|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Unstable|Any CPU.ActiveCfg = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Unstable|x64.ActiveCfg = Debug|Any CPU
{877AD4B3-9E28-4857-8832-AEBB2B2F7B5C}.Unstable|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -238,6 +261,9 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17032EAB-554B-4B44-A4F6-EFB177ACAB7A}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{95c4d59d-9be4-4278-b4f8-46c0ba1a3916}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 0.9.0.0
EndGlobalSection

View File

@@ -46,10 +46,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.Interpreter", "Li
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeployAll", "Deploy\DeployAll\DeployAll.csproj", "{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.VsCodeDebugger", "Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj", "{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{c54f0dfe-add3-4767-8cbc-101859218d66}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
@@ -203,6 +202,18 @@ Global
{20BC9336-B439-4BF1-8B65-D587DBF421D1}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{20BC9336-B439-4BF1-8B65-D587DBF421D1}.Unstable|x64.ActiveCfg = Debug|Any CPU
{20BC9336-B439-4BF1-8B65-D587DBF421D1}.Unstable|x64.Build.0 = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Debug|x64.ActiveCfg = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Debug|x64.Build.0 = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Release|Any CPU.Build.0 = Release|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Release|x64.ActiveCfg = Release|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Release|x64.Build.0 = Release|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Unstable|Any CPU.ActiveCfg = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Unstable|x64.ActiveCfg = Debug|Any CPU
{40BDE83D-61D5-481C-A53E-E0F5B23881E2}.Unstable|x64.Build.0 = Debug|Any CPU
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -215,6 +226,18 @@ Global
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Unstable|x64.ActiveCfg = Debug|Any CPU
{36B38D18-3574-4B67-A89C-FD3C2D39F1D6}.Unstable|x64.Build.0 = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Debug|x64.ActiveCfg = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Debug|x64.Build.0 = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Release|Any CPU.Build.0 = Release|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Release|x64.ActiveCfg = Release|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Release|x64.Build.0 = Release|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Unstable|Any CPU.ActiveCfg = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Unstable|x64.ActiveCfg = Debug|Any CPU
{B6EB29F7-6554-4ACC-8A0C-3D89AD7AF319}.Unstable|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -238,6 +261,9 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17032EAB-554B-4B44-A4F6-EFB177ACAB7A}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{c54f0dfe-add3-4767-8cbc-101859218d66}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 0.9.0.0
EndGlobalSection

View File

@@ -46,10 +46,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.Interpreter", "Li
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeployAll", "Deploy\DeployAll\DeployAll.csproj", "{C98FE0D0-BC7D-4806-B592-734B53016FD8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoonSharp.VsCodeDebugger", "Libraries\moonsharp\MoonSharp.VsCodeDebugger\MoonSharp.VsCodeDebugger.csproj", "{AF484604-D20F-4D87-B298-1A712052D0D9}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{95c4d59d-9be4-4278-b4f8-46c0ba1a3916}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
@@ -227,12 +226,18 @@ Global
{C98FE0D0-BC7D-4806-B592-734B53016FD8}.Unstable|Any CPU.Build.0 = Release|Any CPU
{C98FE0D0-BC7D-4806-B592-734B53016FD8}.Unstable|x64.ActiveCfg = Debug|Any CPU
{C98FE0D0-BC7D-4806-B592-734B53016FD8}.Unstable|x64.Build.0 = Debug|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Debug|x64.ActiveCfg = Debug|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Debug|x64.Build.0 = Debug|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Release|x64.ActiveCfg = Release|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Release|x64.Build.0 = Release|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Unstable|x64.ActiveCfg = Debug|Any CPU
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6}.Unstable|x64.Build.0 = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Debug|x64.ActiveCfg = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Debug|x64.Build.0 = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Release|Any CPU.Build.0 = Release|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Release|x64.ActiveCfg = Release|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Release|x64.Build.0 = Release|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Unstable|Any CPU.ActiveCfg = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Unstable|Any CPU.Build.0 = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Unstable|x64.ActiveCfg = Debug|Any CPU
{AF484604-D20F-4D87-B298-1A712052D0D9}.Unstable|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -252,11 +257,13 @@ Global
{6911872D-40EF-400C-B0A1-9985A19ED488} = {DE36F45F-F09E-4719-B953-00D148F7722A}
{C7212AE2-A925-4225-A639-AE0653EF65B0} = {78A9F0AA-5519-407A-9B72-2A09F5DF7068}
{C98FE0D0-BC7D-4806-B592-734B53016FD8} = {F35DF9BF-0BED-4FEF-A51C-DD83C531882F}
{D42D8E48-A687-445D-AAF1-9E7E6EBF1DE6} = {DE36F45F-F09E-4719-B953-00D148F7722A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17032EAB-554B-4B44-A4F6-EFB177ACAB7A}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Libraries\GameAnalytics\GA-SDK-MONO-SHARED\GA-SDK-MONO-SHARED.projitems*{95c4d59d-9be4-4278-b4f8-46c0ba1a3916}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 0.9.0.0
EndGlobalSection