LuaCs CSharp Enabled Rework
- New UI for the prompt - Third time's the charm. - Fixed TOCTOU for cs prompt on main menu. - Fixed SubEditor not running lua when don't run is selected for cs. - LuaCs CSharp Enabled Rework
This commit is contained in:
committed by
Evil Factory
parent
d440ccbce2
commit
ebe8ec455f
@@ -2,7 +2,14 @@
|
||||
<Configuration>
|
||||
<Settings>
|
||||
<Setting Name="HideUserNamesInLogs" Type="bool" Value="true"/>
|
||||
<Setting Name="IsCsEnabled" Type="bool" Value="false" AllowChangesWhileExecuting="false"/>
|
||||
<Setting Name="CsRunPolicy" Type="listString" Value="Prompt" AllowChangesWhileExecuting="false">
|
||||
<Values>
|
||||
<Value Value="Disabled"/>
|
||||
<Value Value="Prompt"/>
|
||||
<Value Value="Enabled"/>
|
||||
</Values>
|
||||
</Setting>
|
||||
<Setting Name="UseCaching" Type="bool" Value="true" AllowChangesWhileExecuting="false"/>
|
||||
<Setting Name="CsRunPolicySession" Type="bool" AllowChangesWhileExecuting="false" ShowInMenus="false"/>
|
||||
</Settings>
|
||||
</Configuration>
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
<LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>Mod Gameplay Settings</LuaCsForBarotrauma.SettingsMenu.ModGameplayButton>
|
||||
<!-- Settings -->
|
||||
<!-- Is Cs Enabled-->
|
||||
<LuaCsForBarotrauma.IsCsEnabled.DisplayName>Are C# Mods Allowed</LuaCsForBarotrauma.IsCsEnabled.DisplayName>
|
||||
<LuaCsForBarotrauma.IsCsEnabled.Tooltip>Should unsandboxed scripts and dlls be allowed to run.</LuaCsForBarotrauma.IsCsEnabled.Tooltip>
|
||||
<LuaCsForBarotrauma.IsCsEnabled.DisplayCategory>General</LuaCsForBarotrauma.IsCsEnabled.DisplayCategory>
|
||||
<LuaCsForBarotrauma.CsRunPolicy.DisplayName>Are C# Mods Allowed</LuaCsForBarotrauma.CsRunPolicy.DisplayName>
|
||||
<LuaCsForBarotrauma.CsRunPolicy.Tooltip>Should unsandboxed scripts and dlls be allowed to run.</LuaCsForBarotrauma.CsRunPolicy.Tooltip>
|
||||
<LuaCsForBarotrauma.CsRunPolicy.DisplayCategory>General</LuaCsForBarotrauma.CsRunPolicy.DisplayCategory>
|
||||
<!-- Use Caching -->
|
||||
<LuaCsForBarotrauma.UseCaching.DisplayName>Use Pre-Caching</LuaCsForBarotrauma.UseCaching.DisplayName>
|
||||
<LuaCsForBarotrauma.UseCaching.Tooltip>Should mod files be preloaded to speed up loading. Should only be turned off if you have mods that have issues with this.</LuaCsForBarotrauma.UseCaching.Tooltip>
|
||||
|
||||
@@ -84,18 +84,22 @@ namespace Barotrauma
|
||||
private LuaGame _game;
|
||||
public LuaGame Game => _game ??= _servicesProvider.GetService<LuaGame>();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether C# plugin code is enabled.
|
||||
/// </summary>
|
||||
public bool IsCsEnabled
|
||||
{
|
||||
get => _isCsEnabled?.Value ?? false;
|
||||
internal set => _isCsEnabled?.TrySetValue(value);
|
||||
#if CLIENT
|
||||
get => _csRunPolicy?.Value == "Enabled" || _isCsEnabledForSession;
|
||||
#elif SERVER
|
||||
// cs settings cannot be changed on the server after launch
|
||||
get => _csRunPolicy?.Value is "Enabled" or "Prompt";
|
||||
#endif
|
||||
}
|
||||
|
||||
private ISettingBase<bool> _isCsEnabled;
|
||||
|
||||
private ISettingList<string> _csRunPolicy;
|
||||
private bool ShouldPromptForCs => _csRunPolicy?.Value is "Prompt";
|
||||
|
||||
/// <summary>
|
||||
/// Whether usernames are anonymized or show in logs.
|
||||
/// </summary>
|
||||
@@ -123,8 +127,8 @@ namespace Barotrauma
|
||||
{
|
||||
var luaCsPackage = GetLuaCsPackage();
|
||||
|
||||
_isCsEnabled =
|
||||
ConfigService.TryGetConfig<ISettingBase<bool>>(luaCsPackage, "IsCsEnabled", out var val1)
|
||||
_csRunPolicy =
|
||||
ConfigService.TryGetConfig<ISettingList<string>>(luaCsPackage, "CsRunPolicy", out var val1)
|
||||
? val1
|
||||
: null;
|
||||
_hideUserNamesInLogs =
|
||||
@@ -380,16 +384,27 @@ namespace Barotrauma
|
||||
void RunStateRunning_OnExit(State<RunState> currentState)
|
||||
{
|
||||
EventService.Call("stop");
|
||||
|
||||
#if CLIENT
|
||||
_isCsEnabledForSession = false;
|
||||
#endif
|
||||
Logger.LogResults(PackageManagementService.StopRunningPackages());
|
||||
|
||||
Logger.LogMessage("LuaCs running state exited");
|
||||
}
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Checks for Cs Execution Policy (ie. prompting the user) and then calls the delegate once completed.
|
||||
/// </summary>
|
||||
/// <param name="onReadyToRun"></param>
|
||||
partial void CheckReadyToRun(Action onReadyToRun);
|
||||
|
||||
#region LegacyRedirects
|
||||
|
||||
// --- Compatibility
|
||||
@@ -457,7 +472,7 @@ namespace Barotrauma
|
||||
|
||||
void DisposeLuaCsConfig()
|
||||
{
|
||||
_isCsEnabled = null;
|
||||
_csRunPolicy = null;
|
||||
_hideUserNamesInLogs = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user