- IT BUILDS!!2:BARO BOOGALOO
This commit is contained in:
@@ -21,8 +21,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private partial bool ShouldRunCs() => IsCsEnabled.Value;
|
||||
|
||||
public void CheckCsEnabled()
|
||||
{
|
||||
var csharpMods = PackageManagementService.GetLoadedAssemblyPackages();
|
||||
|
||||
@@ -61,11 +61,6 @@ internal interface IEventReloadAllPackages : IEvent<IEventReloadAllPackages>
|
||||
void OnReloadAllPackages();
|
||||
}
|
||||
|
||||
internal interface IEventConfigVarInstanced : IEvent<IEventConfigVarInstanced>
|
||||
{
|
||||
void OnConfigCreated(IConfigBase config);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GameEvents
|
||||
@@ -215,11 +210,6 @@ public interface IEventPluginPreInitialize : IEvent<IEventPluginPreInitialize>
|
||||
public interface IEventAssemblyLoaded : IEvent<IEventAssemblyLoaded>
|
||||
{
|
||||
void OnAssemblyLoaded(Assembly assembly);
|
||||
static IEventAssemblyLoaded IEvent<IEventAssemblyLoaded>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
||||
{
|
||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
||||
OnAssemblyLoaded = ReturnVoid.Arguments<Assembly>((ass) => luaFunc[nameof(OnAssemblyLoaded)](ass))
|
||||
}.ActLike<IEventAssemblyLoaded>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -228,11 +218,6 @@ public interface IEventAssemblyLoaded : IEvent<IEventAssemblyLoaded>
|
||||
public interface IEventAssemblyContextCreated : IEvent<IEventAssemblyContextCreated>
|
||||
{
|
||||
void OnAssemblyCreated(IAssemblyLoaderService loaderService);
|
||||
static IEventAssemblyContextCreated IEvent<IEventAssemblyContextCreated>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
||||
{
|
||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
||||
OnAssemblyContextCreated = ReturnVoid.Arguments<IAssemblyLoaderService>((loader) => luaFunc[nameof(OnAssemblyCreated)](loader))
|
||||
}.ActLike<IEventAssemblyContextCreated>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -241,11 +226,6 @@ public interface IEventAssemblyContextCreated : IEvent<IEventAssemblyContextCrea
|
||||
public interface IEventAssemblyContextUnloading : IEvent<IEventAssemblyContextUnloading>
|
||||
{
|
||||
void OnAssemblyUnloading(WeakReference<IAssemblyLoaderService> loaderService);
|
||||
static IEventAssemblyContextUnloading IEvent<IEventAssemblyContextUnloading>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
|
||||
{
|
||||
IsLuaRunner = Return<bool>.Arguments(() => true),
|
||||
OnAssemblyUnloading = ReturnVoid.Arguments<WeakReference<IAssemblyLoaderService>>((loader) => luaFunc[nameof(OnAssemblyUnloading)](loader))
|
||||
}.ActLike<IEventAssemblyContextUnloading>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -120,5 +120,12 @@ namespace Barotrauma
|
||||
TimedAction timedAction = new TimedAction(action, 0);
|
||||
AddTimer(timedAction);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
public bool IsDisposed => false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +272,10 @@ namespace Barotrauma.LuaCs.Services
|
||||
|
||||
public LuaGame()
|
||||
{
|
||||
#if DEBUG
|
||||
return; // startup testing
|
||||
#endif
|
||||
|
||||
throw new NotImplementedException();
|
||||
/*LuaUserData.MakeFieldAccessible(UserData.RegisterType(typeof(GameSettings)), "currentConfig");
|
||||
Settings = UserData.CreateStatic(typeof(GameSettings));*/
|
||||
|
||||
@@ -269,9 +269,10 @@ namespace Barotrauma
|
||||
descriptor.RemoveMember(methodName);
|
||||
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
||||
{
|
||||
if (GameMain.LuaCs != null)
|
||||
/*if (GameMain.LuaCs != null)
|
||||
return GameMain.LuaCs.CallLuaFunction(function, arg3.GetArray());
|
||||
return null;
|
||||
return null;*/
|
||||
throw new NotImplementedException();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,59 +27,22 @@ namespace Barotrauma
|
||||
internal delegate void LuaCsErrorHandler(Exception ex, LuaCsMessageOrigin origin);
|
||||
internal delegate void LuaCsExceptionHandler(Exception ex, LuaCsMessageOrigin origin);
|
||||
|
||||
partial class LuaCsSetup : IDisposable, IEventScreenSelected, IEventAllPackageListChanged, IEventEnabledPackageListChanged,
|
||||
partial class LuaCsSetup : IDisposable, IEventScreenSelected, IEventEnabledPackageListChanged,
|
||||
IEventReloadAllPackages
|
||||
{
|
||||
public LuaCsSetup()
|
||||
{
|
||||
// == startup
|
||||
_servicesProvider = new ServicesProvider();
|
||||
RegisterServices(_servicesProvider);
|
||||
_servicesProvider = SetupServicesProvider();
|
||||
if (!ValidateLuaCsContent())
|
||||
{
|
||||
Logger.LogError($"{nameof(LuaCsSetup)}: ModConfigXml missing. Unable to continue.");
|
||||
throw new ApplicationException($"{nameof(LuaCsSetup)}: Lua ModConfig.xml is missing. Unable to continue.");
|
||||
}
|
||||
SubscribeToLuaCsEvents();
|
||||
_runStateMachine = SetupStateMachine();
|
||||
//LoadLuaCsConfig();
|
||||
|
||||
return;
|
||||
// == end
|
||||
|
||||
StateMachine<RunState> SetupStateMachine()
|
||||
{
|
||||
return new StateMachine<RunState>(false, RunState.Unloaded, RunStateUnloaded_OnEnter, null)
|
||||
.AddState(RunState.LoadedNoExec, RunStateLoadedNoExec_OnEnter, RunStateLoadedNoExec_OnExit)
|
||||
.AddState(RunState.Running, RunStateRunning_OnEnter, RunStateRunning_OnExit);
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
void RunStateUnloaded_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RunStateLoadedNoExec_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RunStateLoadedNoExec_OnExit(State<RunState> currentState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RunStateRunning_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RunStateRunning_OnExit(State<RunState> currentState)
|
||||
{
|
||||
|
||||
}
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
SubscribeToLuaCsEvents();
|
||||
SetRunState(RunState.LoadedNoExec);
|
||||
LoadLuaCsConfig();
|
||||
}
|
||||
|
||||
bool ValidateLuaCsContent()
|
||||
@@ -88,44 +51,16 @@ namespace Barotrauma
|
||||
// TODO: we just wanna boot for now
|
||||
return true;
|
||||
#endif
|
||||
// check if /Content/Lua/ModConfig.xml exists
|
||||
// if not, try to copy it from the Local Mods folder
|
||||
// if not, try to copy it from the Workshop Mods folder
|
||||
// check if /Content/ModConfig.xml exists
|
||||
// if not, try to copy missing files from the Local Mods folder
|
||||
// if not, try to copy missing files from the Workshop Mods folder
|
||||
// if that fails, throw an error and exit.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void RegisterServices(IServicesProvider servicesProvider)
|
||||
{
|
||||
servicesProvider.RegisterServiceType<ILoggerService, LoggerService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<PerformanceCounterService, PerformanceCounterService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IStorageService, StorageService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<IEventService, EventService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptLoader, LuaScriptLoader>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<LuaGame, LuaGame>(ServiceLifetime.Singleton);
|
||||
|
||||
// TODO: IConfigService
|
||||
// TODO: INetworkingService
|
||||
// TODO: [Resource Converter/Parser Services]
|
||||
|
||||
servicesProvider.RegisterServiceType<IModConfigService, ModConfigService>(ServiceLifetime.Transient);
|
||||
|
||||
// service config data
|
||||
servicesProvider.RegisterServiceType<IStorageServiceConfig, StorageServiceConfig>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptServicesConfig, LuaScriptServicesConfig>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IConfigServiceConfig, ConfigServiceConfig>(ServiceLifetime.Singleton);
|
||||
|
||||
// gen IL
|
||||
servicesProvider.Compile();
|
||||
}
|
||||
|
||||
void SubscribeToLuaCsEvents()
|
||||
{
|
||||
EventService.Subscribe<IEventScreenSelected>(this); // game state hook in
|
||||
EventService.Subscribe<IEventAllPackageListChanged>(this);
|
||||
EventService.Subscribe<IEventEnabledPackageListChanged>(this);
|
||||
EventService.Subscribe<IEventReloadAllPackages>(this);
|
||||
}
|
||||
@@ -141,14 +76,14 @@ namespace Barotrauma
|
||||
|
||||
#endregion
|
||||
|
||||
#region Services_ConfigVars
|
||||
#region Services_CVars
|
||||
|
||||
/*
|
||||
* === Singleton Services
|
||||
*/
|
||||
|
||||
private readonly IServicesProvider _servicesProvider;
|
||||
|
||||
|
||||
public PerformanceCounterService PerformanceCounter => _servicesProvider.GetService<PerformanceCounterService>();
|
||||
public ILoggerService Logger => _servicesProvider.GetService<ILoggerService>();
|
||||
public IConfigService ConfigService => _servicesProvider.GetService<IConfigService>();
|
||||
@@ -158,14 +93,8 @@ namespace Barotrauma
|
||||
public INetworkingService NetworkingService => _servicesProvider.GetService<INetworkingService>();
|
||||
public IEventService EventService => _servicesProvider.GetService<IEventService>();
|
||||
public LuaGame Game => _servicesProvider.GetService<LuaGame>();
|
||||
|
||||
|
||||
#region LuaCsInternal
|
||||
|
||||
|
||||
/*
|
||||
* === Config Vars
|
||||
*/
|
||||
internal IStorageService StorageService => _servicesProvider.GetService<IStorageService>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether C# plugin code is enabled.
|
||||
@@ -207,13 +136,58 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
internal IConfigEntry<string> LocalDataSavePath { get; private set; }
|
||||
|
||||
void LoadLuaCsConfig()
|
||||
{
|
||||
IsCsEnabled = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "IsCsEnabled", out var val1) ? val1
|
||||
: throw new NullReferenceException($"{nameof(IsCsEnabled)} cannot be loaded.");
|
||||
TreatForcedModsAsNormal = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "TreatForcedModsAsNormal", out var val2) ? val2
|
||||
: throw new NullReferenceException($"{nameof(TreatForcedModsAsNormal)} cannot be loaded.");
|
||||
DisableErrorGUIOverlay = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "DisableErrorGUIOverlay", out var val3) ? val3
|
||||
: throw new NullReferenceException($"{nameof(DisableErrorGUIOverlay)} cannot be loaded.");
|
||||
HideUserNamesInLogs = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "HideUserNamesInLogs", out var val4) ? val4
|
||||
: throw new NullReferenceException($"{nameof(HideUserNamesInLogs)} cannot be loaded.");
|
||||
LuaForBarotraumaSteamId = ConfigService.TryGetConfig<IConfigEntry<ulong>>(ContentPackageManager.VanillaCorePackage, "LuaForBarotraumaSteamId", out var val5) ? val5
|
||||
: throw new NullReferenceException($"{nameof(LuaForBarotraumaSteamId)} cannot be loaded.");
|
||||
RestrictMessageSize = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "RestrictMessageSize", out var val7) ? val7
|
||||
: throw new NullReferenceException($"{nameof(RestrictMessageSize)} cannot be loaded.");
|
||||
}
|
||||
|
||||
private IServicesProvider SetupServicesProvider()
|
||||
{
|
||||
var servicesProvider = new ServicesProvider();
|
||||
|
||||
servicesProvider.RegisterServiceType<ILoggerService, LoggerService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<PerformanceCounterService, PerformanceCounterService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IStorageService, StorageService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<ISafeStorageService, SafeStorageService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<IEventService, EventService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaCsHook, EventService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptLoader, LuaScriptLoader>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<LuaGame, LuaGame>(ServiceLifetime.Singleton);
|
||||
// TODO: INetworkingService
|
||||
servicesProvider.RegisterServiceType<IConfigService, ConfigService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IModConfigService, ModConfigService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<IParserServiceAsync<ResourceParserInfo, IAssemblyResourceInfo>, ConfigFileParserService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<IParserServiceAsync<ResourceParserInfo, ILuaScriptResourceInfo>, ConfigFileParserService>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<IParserServiceAsync<ResourceParserInfo, IConfigResourceInfo>, ConfigFileParserService>(ServiceLifetime.Transient);
|
||||
// service config data
|
||||
servicesProvider.RegisterServiceType<IStorageServiceConfig, StorageServiceConfig>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<ILuaScriptServicesConfig, LuaScriptServicesConfig>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IConfigServiceConfig, ConfigServiceConfig>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IPackageManagementServiceConfig, PackageManagementServiceConfig>(ServiceLifetime.Singleton);
|
||||
// gen IL
|
||||
servicesProvider.Compile();
|
||||
return servicesProvider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/**
|
||||
* == Ops Vars
|
||||
*/
|
||||
#region StateMachine
|
||||
|
||||
private RunState _runState;
|
||||
|
||||
/// <summary>
|
||||
/// The current run state of all services managed by LuaCs.
|
||||
/// </summary>
|
||||
@@ -222,14 +196,116 @@ namespace Barotrauma
|
||||
get => _runState;
|
||||
private set => _runState = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private readonly StateMachine<RunState> _runStateMachine;
|
||||
private readonly ConcurrentQueue<ContentPackage> _toLoad = new();
|
||||
private readonly ConcurrentQueue<ContentPackage> _toUnload = new();
|
||||
|
||||
public void OnEnabledPackageListChanged(CorePackage package, IEnumerable<RegularPackage> regularPackages)
|
||||
{
|
||||
ProcessEnabledPackageChanges(new []{ package }.Concat<ContentPackage>(regularPackages).ToImmutableArray());
|
||||
}
|
||||
|
||||
public void OnReloadAllPackages()
|
||||
{
|
||||
if (CurrentRunState <= RunState.Unloaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var state = CurrentRunState;
|
||||
SetRunState(RunState.Unloaded);
|
||||
SetRunState(state);
|
||||
}
|
||||
|
||||
private void ProcessEnabledPackageChanges(ImmutableArray<ContentPackage> packages)
|
||||
{
|
||||
if (CurrentRunState < RunState.LoadedNoExec)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var state = CurrentRunState;
|
||||
if (CurrentRunState > RunState.LoadedNoExec)
|
||||
{
|
||||
SetRunState(RunState.LoadedNoExec);
|
||||
}
|
||||
|
||||
PackageManagementService.SyncLoadedPackagesList(packages);
|
||||
SetRunState(state); // restore
|
||||
}
|
||||
|
||||
private void SetRunState(RunState targetRunState)
|
||||
{
|
||||
if (CurrentRunState == targetRunState)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_runStateMachine.GotoState(targetRunState);
|
||||
}
|
||||
|
||||
private StateMachine<RunState> SetupStateMachine()
|
||||
{
|
||||
return new StateMachine<RunState>(false, RunState.Unloaded, RunStateUnloaded_OnEnter, null)
|
||||
.AddState(RunState.LoadedNoExec, RunStateLoadedNoExec_OnEnter, null)
|
||||
.AddState(RunState.Running, RunStateRunning_OnEnter, RunStateRunning_OnExit);
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
void RunStateUnloaded_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
if (PackageManagementService.IsAnyPackageRunning())
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.StopRunningPackages());
|
||||
}
|
||||
|
||||
if (PackageManagementService.IsAnyPackageRunning())
|
||||
{
|
||||
DisposeLuaCsConfig();
|
||||
Logger.LogResults(PackageManagementService.UnloadAllPackages());
|
||||
}
|
||||
|
||||
CurrentRunState = RunState.Unloaded;
|
||||
}
|
||||
|
||||
void RunStateLoadedNoExec_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
if (PackageManagementService.IsAnyPackageRunning())
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.StopRunningPackages());
|
||||
}
|
||||
|
||||
if (!PackageManagementService.IsAnyPackageLoaded())
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.LoadPackagesInfo(ContentPackageManager.EnabledPackages.All.ToImmutableArray()));
|
||||
LoadLuaCsConfig();
|
||||
}
|
||||
|
||||
CurrentRunState = RunState.LoadedNoExec;
|
||||
}
|
||||
|
||||
void RunStateRunning_OnEnter(State<RunState> currentState)
|
||||
{
|
||||
if (!PackageManagementService.IsAnyPackageLoaded())
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.LoadPackagesInfo(ContentPackageManager.EnabledPackages.All.ToImmutableArray()));
|
||||
LoadLuaCsConfig();
|
||||
}
|
||||
|
||||
if (!PackageManagementService.IsAnyPackageRunning())
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.ExecuteLoadedPackages(ContentPackageManager.EnabledPackages.All.ToImmutableArray()));
|
||||
}
|
||||
|
||||
CurrentRunState = RunState.Running;
|
||||
}
|
||||
|
||||
void RunStateRunning_OnExit(State<RunState> currentState)
|
||||
{
|
||||
Logger.LogResults(PackageManagementService.StopRunningPackages());
|
||||
}
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region LegacyRedirects
|
||||
|
||||
public ILuaCsHook Hook => this.EventService;
|
||||
@@ -276,72 +352,7 @@ namespace Barotrauma
|
||||
/// <param name="screen">The new game screen.</param>
|
||||
public partial void OnScreenSelected(Screen screen);
|
||||
|
||||
public void OnAllPackageListChanged(IEnumerable<CorePackage> corePackages, IEnumerable<RegularPackage> regularPackages)
|
||||
{
|
||||
UpdateLoadedPackagesList();
|
||||
}
|
||||
|
||||
public void OnEnabledPackageListChanged(CorePackage corePackage, IEnumerable<RegularPackage> regularPackages)
|
||||
{
|
||||
UpdateLoadedPackagesList();
|
||||
}
|
||||
|
||||
public void OnReloadAllPackages()
|
||||
{
|
||||
if (CurrentRunState <= RunState.Unloaded)
|
||||
return;
|
||||
var state = CurrentRunState;
|
||||
SetRunState(RunState.Unloaded);
|
||||
SetRunState(CurrentRunState);
|
||||
}
|
||||
|
||||
public void ForceRunState(RunState newState)
|
||||
{
|
||||
if (CurrentRunState == newState)
|
||||
return;
|
||||
SetRunState(newState);
|
||||
}
|
||||
|
||||
private void UpdateLoadedPackagesList()
|
||||
{
|
||||
throw new NotImplementedException($"Rewrite the loading state system.");
|
||||
|
||||
var newPackSet = ContentPackageManager.AllPackages
|
||||
.Union(ContentPackageManager.EnabledPackages.All)
|
||||
.ToHashSet();
|
||||
var currPackSet = PackageManagementService.GetAllLoadedPackages().ToHashSet();
|
||||
var toAdd = newPackSet.Except(currPackSet);
|
||||
var toRemove = currPackSet.Except(newPackSet);
|
||||
foreach (var package in toAdd)
|
||||
_toLoad.Enqueue(package);
|
||||
foreach (var package in toRemove)
|
||||
_toUnload.Enqueue(package);
|
||||
|
||||
//ProcessPackagesListDifferences();
|
||||
}
|
||||
|
||||
void SetRunState(RunState newRunState)
|
||||
{
|
||||
if (CurrentRunState == newRunState)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void LoadLuaCsConfig()
|
||||
{
|
||||
IsCsEnabled = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "IsCsEnabled", out var val1) ? val1
|
||||
: throw new NullReferenceException($"{nameof(IsCsEnabled)} cannot be loaded.");
|
||||
TreatForcedModsAsNormal = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "TreatForcedModsAsNormal", out var val2) ? val2
|
||||
: throw new NullReferenceException($"{nameof(TreatForcedModsAsNormal)} cannot be loaded.");
|
||||
DisableErrorGUIOverlay = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "DisableErrorGUIOverlay", out var val3) ? val3
|
||||
: throw new NullReferenceException($"{nameof(DisableErrorGUIOverlay)} cannot be loaded.");
|
||||
HideUserNamesInLogs = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "HideUserNamesInLogs", out var val4) ? val4
|
||||
: throw new NullReferenceException($"{nameof(HideUserNamesInLogs)} cannot be loaded.");
|
||||
LuaForBarotraumaSteamId = ConfigService.TryGetConfig<IConfigEntry<ulong>>(ContentPackageManager.VanillaCorePackage, "LuaForBarotraumaSteamId", out var val5) ? val5
|
||||
: throw new NullReferenceException($"{nameof(LuaForBarotraumaSteamId)} cannot be loaded.");
|
||||
RestrictMessageSize = ConfigService.TryGetConfig<IConfigEntry<bool>>(ContentPackageManager.VanillaCorePackage, "RestrictMessageSize", out var val7) ? val7
|
||||
: throw new NullReferenceException($"{nameof(RestrictMessageSize)} cannot be loaded.");
|
||||
}
|
||||
|
||||
void DisposeLuaCsConfig()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Barotrauma.LuaCs.Services.Compatibility;
|
||||
|
||||
public interface ILuaCsShim
|
||||
public interface ILuaCsShim : IService
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ public partial class ConfigService : IConfigService
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#region LuaInterface
|
||||
|
||||
public bool TryGetConfigBool(string packageName, string configName, out bool value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -128,7 +130,10 @@ public partial class ConfigService : IConfigService
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
public void RegisterTypeInitializer<TData, TConfig>(Func<IConfigInfo, Result<TConfig>> initializer, bool replaceIfExists = false) where TData : IEquatable<TData> where TConfig : IConfigBase
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -136,11 +141,17 @@ public partial class ConfigService : IConfigService
|
||||
|
||||
public async Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources)
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Ok(); // just for startup testing
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigResourceInfo> configProfileResources)
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Ok(); // just for startup testing
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -156,11 +167,17 @@ public partial class ConfigService : IConfigService
|
||||
|
||||
public FluentResults.Result DisposePackageData(ContentPackage package)
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Ok(); // just for startup testing
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public FluentResults.Result DisposeAllPackageData()
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Ok(); // just for startup testing
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -181,6 +198,10 @@ public partial class ConfigService : IConfigService
|
||||
|
||||
public bool TryGetConfig<T>(ContentPackage package, string name, out T config) where T : IConfigBase
|
||||
{
|
||||
#if DEBUG
|
||||
config = default(T);
|
||||
return true; // just for startup testing
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
+13
-12
@@ -43,19 +43,20 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
private readonly ILoggerService _loggerService;
|
||||
private readonly LuaGame _luaGame;
|
||||
private readonly ILuaCsHook _luaCsHook;
|
||||
private readonly ILuaCsNetworking _luaCsNetworking;
|
||||
private readonly ILuaCsUtility _luaCsUtility;
|
||||
private readonly ILuaCsTimer _luaCsTimer;
|
||||
//private readonly ILuaCsNetworking _luaCsNetworking;
|
||||
//private readonly ILuaCsUtility _luaCsUtility;
|
||||
//private readonly ILuaCsTimer _luaCsTimer;
|
||||
|
||||
public LuaScriptManagementService(
|
||||
ILoggerService loggerService,
|
||||
ILuaScriptLoader loader,
|
||||
ILuaScriptServicesConfig luaScriptServicesConfig,
|
||||
LuaGame luaGame,
|
||||
ILuaCsHook luaCsHook,
|
||||
ILuaCsNetworking luaCsNetworking,
|
||||
ILuaCsUtility luaCsUtility,
|
||||
ILuaCsTimer luaCsTimer)
|
||||
ILuaCsHook luaCsHook
|
||||
//ILuaCsNetworking luaCsNetworking,
|
||||
//ILuaCsUtility luaCsUtility,
|
||||
//ILuaCsTimer luaCsTimer
|
||||
)
|
||||
{
|
||||
_luaScriptLoader = loader;
|
||||
_luaScriptServicesConfig = luaScriptServicesConfig;
|
||||
@@ -63,9 +64,9 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
|
||||
_luaGame = luaGame;
|
||||
_luaCsHook = luaCsHook;
|
||||
_luaCsNetworking = luaCsNetworking;
|
||||
_luaCsUtility = luaCsUtility;
|
||||
_luaCsTimer = luaCsTimer;
|
||||
//_luaCsNetworking = luaCsNetworking;
|
||||
//_luaCsUtility = luaCsUtility;
|
||||
//_luaCsTimer = luaCsTimer;
|
||||
}
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
@@ -124,9 +125,9 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
|
||||
_script.Globals["Game"] = _luaGame;
|
||||
_script.Globals["Hook"] = _luaCsHook;
|
||||
_script.Globals["Timer"] = _luaCsTimer;
|
||||
//_script.Globals["Timer"] = _luaCsTimer;
|
||||
_script.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||
_script.Globals["Networking"] = _luaCsNetworking;
|
||||
//_script.Globals["Networking"] = _luaCsNetworking;
|
||||
//_script.Globals["Steam"] = Steam;
|
||||
|
||||
_script.Globals["ExecutionNumber"] = 0;
|
||||
|
||||
+38
-1
@@ -223,7 +223,30 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public FluentResults.Result SyncLoadedPackagesList(ImmutableArray<ContentPackage> packages)
|
||||
{
|
||||
if (packages.IsDefaultOrEmpty)
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(packages));
|
||||
if (!_runningPackages.IsEmpty)
|
||||
ThrowHelper.ThrowInvalidOperationException($"{nameof(SyncLoadedPackagesList)}: There are packages running!");
|
||||
|
||||
var toRemove = _loadedPackages.Keys.Except(packages).ToImmutableArray();
|
||||
var toAdd = packages.Except(_loadedPackages.Keys)
|
||||
.OrderBy(pack => packages.IndexOf(pack)).ToImmutableArray();
|
||||
|
||||
var result = new FluentResults.Result();
|
||||
|
||||
result.WithReasons(UnloadPackages(toRemove).Reasons);
|
||||
|
||||
if (result.IsFailed)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result.WithReasons(LoadPackagesInfo(toAdd).Reasons);
|
||||
}
|
||||
|
||||
public FluentResults.Result StopRunningPackages()
|
||||
{
|
||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
@@ -308,6 +331,20 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
return _runningPackages.ContainsKey(package);
|
||||
}
|
||||
|
||||
public bool IsAnyPackageLoaded()
|
||||
{
|
||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
IService.CheckDisposed(this);
|
||||
return !_loadedPackages.IsEmpty;
|
||||
}
|
||||
|
||||
public bool IsAnyPackageRunning()
|
||||
{
|
||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
IService.CheckDisposed(this);
|
||||
return !_runningPackages.IsEmpty;
|
||||
}
|
||||
|
||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages()
|
||||
{
|
||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
+4
-1
@@ -15,11 +15,14 @@ public interface IPackageManagementService : IReusableService
|
||||
public FluentResults.Result LoadPackageInfo(ContentPackage package);
|
||||
public FluentResults.Result LoadPackagesInfo(ImmutableArray<ContentPackage> packages);
|
||||
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder);
|
||||
public FluentResults.Result SyncLoadedPackagesList(ImmutableArray<ContentPackage> packages);
|
||||
public FluentResults.Result StopRunningPackages();
|
||||
public FluentResults.Result UnloadPackage(ContentPackage package);
|
||||
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
||||
public FluentResults.Result UnloadAllPackages();
|
||||
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
||||
public bool IsPackageRunning(ContentPackage package);
|
||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages();
|
||||
public bool IsPackageRunning(ContentPackage package);
|
||||
public bool IsAnyPackageLoaded();
|
||||
public bool IsAnyPackageRunning();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user