- 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()
|
public void CheckCsEnabled()
|
||||||
{
|
{
|
||||||
var csharpMods = PackageManagementService.GetLoadedAssemblyPackages();
|
var csharpMods = PackageManagementService.GetLoadedAssemblyPackages();
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ internal interface IEventReloadAllPackages : IEvent<IEventReloadAllPackages>
|
|||||||
void OnReloadAllPackages();
|
void OnReloadAllPackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal interface IEventConfigVarInstanced : IEvent<IEventConfigVarInstanced>
|
|
||||||
{
|
|
||||||
void OnConfigCreated(IConfigBase config);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GameEvents
|
#region GameEvents
|
||||||
@@ -215,11 +210,6 @@ public interface IEventPluginPreInitialize : IEvent<IEventPluginPreInitialize>
|
|||||||
public interface IEventAssemblyLoaded : IEvent<IEventAssemblyLoaded>
|
public interface IEventAssemblyLoaded : IEvent<IEventAssemblyLoaded>
|
||||||
{
|
{
|
||||||
void OnAssemblyLoaded(Assembly assembly);
|
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>
|
/// <summary>
|
||||||
@@ -228,11 +218,6 @@ public interface IEventAssemblyLoaded : IEvent<IEventAssemblyLoaded>
|
|||||||
public interface IEventAssemblyContextCreated : IEvent<IEventAssemblyContextCreated>
|
public interface IEventAssemblyContextCreated : IEvent<IEventAssemblyContextCreated>
|
||||||
{
|
{
|
||||||
void OnAssemblyCreated(IAssemblyLoaderService loaderService);
|
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>
|
/// <summary>
|
||||||
@@ -241,11 +226,6 @@ public interface IEventAssemblyContextCreated : IEvent<IEventAssemblyContextCrea
|
|||||||
public interface IEventAssemblyContextUnloading : IEvent<IEventAssemblyContextUnloading>
|
public interface IEventAssemblyContextUnloading : IEvent<IEventAssemblyContextUnloading>
|
||||||
{
|
{
|
||||||
void OnAssemblyUnloading(WeakReference<IAssemblyLoaderService> loaderService);
|
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
|
#endregion
|
||||||
|
|||||||
@@ -120,5 +120,12 @@ namespace Barotrauma
|
|||||||
TimedAction timedAction = new TimedAction(action, 0);
|
TimedAction timedAction = new TimedAction(action, 0);
|
||||||
AddTimer(timedAction);
|
AddTimer(timedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDisposed => false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,10 @@ namespace Barotrauma.LuaCs.Services
|
|||||||
|
|
||||||
public LuaGame()
|
public LuaGame()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return; // startup testing
|
||||||
|
#endif
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
/*LuaUserData.MakeFieldAccessible(UserData.RegisterType(typeof(GameSettings)), "currentConfig");
|
/*LuaUserData.MakeFieldAccessible(UserData.RegisterType(typeof(GameSettings)), "currentConfig");
|
||||||
Settings = UserData.CreateStatic(typeof(GameSettings));*/
|
Settings = UserData.CreateStatic(typeof(GameSettings));*/
|
||||||
|
|||||||
@@ -269,9 +269,10 @@ namespace Barotrauma
|
|||||||
descriptor.RemoveMember(methodName);
|
descriptor.RemoveMember(methodName);
|
||||||
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
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 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 LuaCsErrorHandler(Exception ex, LuaCsMessageOrigin origin);
|
||||||
internal delegate void LuaCsExceptionHandler(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
|
IEventReloadAllPackages
|
||||||
{
|
{
|
||||||
public LuaCsSetup()
|
public LuaCsSetup()
|
||||||
{
|
{
|
||||||
// == startup
|
// == startup
|
||||||
_servicesProvider = new ServicesProvider();
|
_servicesProvider = SetupServicesProvider();
|
||||||
RegisterServices(_servicesProvider);
|
|
||||||
if (!ValidateLuaCsContent())
|
if (!ValidateLuaCsContent())
|
||||||
{
|
{
|
||||||
Logger.LogError($"{nameof(LuaCsSetup)}: ModConfigXml missing. Unable to continue.");
|
Logger.LogError($"{nameof(LuaCsSetup)}: ModConfigXml missing. Unable to continue.");
|
||||||
throw new ApplicationException($"{nameof(LuaCsSetup)}: Lua ModConfig.xml is missing. Unable to continue.");
|
throw new ApplicationException($"{nameof(LuaCsSetup)}: Lua ModConfig.xml is missing. Unable to continue.");
|
||||||
}
|
}
|
||||||
SubscribeToLuaCsEvents();
|
|
||||||
_runStateMachine = SetupStateMachine();
|
_runStateMachine = SetupStateMachine();
|
||||||
//LoadLuaCsConfig();
|
SubscribeToLuaCsEvents();
|
||||||
|
SetRunState(RunState.LoadedNoExec);
|
||||||
return;
|
LoadLuaCsConfig();
|
||||||
// == 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValidateLuaCsContent()
|
bool ValidateLuaCsContent()
|
||||||
@@ -88,44 +51,16 @@ namespace Barotrauma
|
|||||||
// TODO: we just wanna boot for now
|
// TODO: we just wanna boot for now
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
// check if /Content/Lua/ModConfig.xml exists
|
// check if /Content/ModConfig.xml exists
|
||||||
// if not, try to copy it from the Local Mods folder
|
// if not, try to copy missing files from the Local Mods folder
|
||||||
// if not, try to copy it from the Workshop Mods folder
|
// if not, try to copy missing files from the Workshop Mods folder
|
||||||
// if that fails, throw an error and exit.
|
// if that fails, throw an error and exit.
|
||||||
throw new NotImplementedException();
|
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()
|
void SubscribeToLuaCsEvents()
|
||||||
{
|
{
|
||||||
EventService.Subscribe<IEventScreenSelected>(this); // game state hook in
|
EventService.Subscribe<IEventScreenSelected>(this); // game state hook in
|
||||||
EventService.Subscribe<IEventAllPackageListChanged>(this);
|
|
||||||
EventService.Subscribe<IEventEnabledPackageListChanged>(this);
|
EventService.Subscribe<IEventEnabledPackageListChanged>(this);
|
||||||
EventService.Subscribe<IEventReloadAllPackages>(this);
|
EventService.Subscribe<IEventReloadAllPackages>(this);
|
||||||
}
|
}
|
||||||
@@ -141,14 +76,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Services_ConfigVars
|
#region Services_CVars
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* === Singleton Services
|
* === Singleton Services
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private readonly IServicesProvider _servicesProvider;
|
private readonly IServicesProvider _servicesProvider;
|
||||||
|
|
||||||
public PerformanceCounterService PerformanceCounter => _servicesProvider.GetService<PerformanceCounterService>();
|
public PerformanceCounterService PerformanceCounter => _servicesProvider.GetService<PerformanceCounterService>();
|
||||||
public ILoggerService Logger => _servicesProvider.GetService<ILoggerService>();
|
public ILoggerService Logger => _servicesProvider.GetService<ILoggerService>();
|
||||||
public IConfigService ConfigService => _servicesProvider.GetService<IConfigService>();
|
public IConfigService ConfigService => _servicesProvider.GetService<IConfigService>();
|
||||||
@@ -158,14 +93,8 @@ namespace Barotrauma
|
|||||||
public INetworkingService NetworkingService => _servicesProvider.GetService<INetworkingService>();
|
public INetworkingService NetworkingService => _servicesProvider.GetService<INetworkingService>();
|
||||||
public IEventService EventService => _servicesProvider.GetService<IEventService>();
|
public IEventService EventService => _servicesProvider.GetService<IEventService>();
|
||||||
public LuaGame Game => _servicesProvider.GetService<LuaGame>();
|
public LuaGame Game => _servicesProvider.GetService<LuaGame>();
|
||||||
|
|
||||||
|
|
||||||
#region LuaCsInternal
|
internal IStorageService StorageService => _servicesProvider.GetService<IStorageService>();
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* === Config Vars
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether C# plugin code is enabled.
|
/// Whether C# plugin code is enabled.
|
||||||
@@ -207,13 +136,58 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal IConfigEntry<string> LocalDataSavePath { get; private set; }
|
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
|
#endregion
|
||||||
|
|
||||||
/**
|
#region StateMachine
|
||||||
* == Ops Vars
|
|
||||||
*/
|
|
||||||
private RunState _runState;
|
private RunState _runState;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current run state of all services managed by LuaCs.
|
/// The current run state of all services managed by LuaCs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -222,14 +196,116 @@ namespace Barotrauma
|
|||||||
get => _runState;
|
get => _runState;
|
||||||
private set => _runState = value;
|
private set => _runState = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private readonly StateMachine<RunState> _runStateMachine;
|
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
|
#endregion
|
||||||
|
|
||||||
#region LegacyRedirects
|
#region LegacyRedirects
|
||||||
|
|
||||||
public ILuaCsHook Hook => this.EventService;
|
public ILuaCsHook Hook => this.EventService;
|
||||||
@@ -276,72 +352,7 @@ namespace Barotrauma
|
|||||||
/// <param name="screen">The new game screen.</param>
|
/// <param name="screen">The new game screen.</param>
|
||||||
public partial void OnScreenSelected(Screen screen);
|
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()
|
void DisposeLuaCsConfig()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Barotrauma.LuaCs.Services.Compatibility;
|
namespace Barotrauma.LuaCs.Services.Compatibility;
|
||||||
|
|
||||||
public interface ILuaCsShim
|
public interface ILuaCsShim : IService
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public partial class ConfigService : IConfigService
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region LuaInterface
|
||||||
|
|
||||||
public bool TryGetConfigBool(string packageName, string configName, out bool value)
|
public bool TryGetConfigBool(string packageName, string configName, out bool value)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -128,7 +130,10 @@ public partial class ConfigService : IConfigService
|
|||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void RegisterTypeInitializer<TData, TConfig>(Func<IConfigInfo, Result<TConfig>> initializer, bool replaceIfExists = false) where TData : IEquatable<TData> where TConfig : IConfigBase
|
public void RegisterTypeInitializer<TData, TConfig>(Func<IConfigInfo, Result<TConfig>> initializer, bool replaceIfExists = false) where TData : IEquatable<TData> where TConfig : IConfigBase
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -136,11 +141,17 @@ public partial class ConfigService : IConfigService
|
|||||||
|
|
||||||
public async Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources)
|
public async Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return FluentResults.Result.Ok(); // just for startup testing
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigResourceInfo> configProfileResources)
|
public async Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigResourceInfo> configProfileResources)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return FluentResults.Result.Ok(); // just for startup testing
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,11 +167,17 @@ public partial class ConfigService : IConfigService
|
|||||||
|
|
||||||
public FluentResults.Result DisposePackageData(ContentPackage package)
|
public FluentResults.Result DisposePackageData(ContentPackage package)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return FluentResults.Result.Ok(); // just for startup testing
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result DisposeAllPackageData()
|
public FluentResults.Result DisposeAllPackageData()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return FluentResults.Result.Ok(); // just for startup testing
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
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
|
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();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -43,19 +43,20 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
|||||||
private readonly ILoggerService _loggerService;
|
private readonly ILoggerService _loggerService;
|
||||||
private readonly LuaGame _luaGame;
|
private readonly LuaGame _luaGame;
|
||||||
private readonly ILuaCsHook _luaCsHook;
|
private readonly ILuaCsHook _luaCsHook;
|
||||||
private readonly ILuaCsNetworking _luaCsNetworking;
|
//private readonly ILuaCsNetworking _luaCsNetworking;
|
||||||
private readonly ILuaCsUtility _luaCsUtility;
|
//private readonly ILuaCsUtility _luaCsUtility;
|
||||||
private readonly ILuaCsTimer _luaCsTimer;
|
//private readonly ILuaCsTimer _luaCsTimer;
|
||||||
|
|
||||||
public LuaScriptManagementService(
|
public LuaScriptManagementService(
|
||||||
ILoggerService loggerService,
|
ILoggerService loggerService,
|
||||||
ILuaScriptLoader loader,
|
ILuaScriptLoader loader,
|
||||||
ILuaScriptServicesConfig luaScriptServicesConfig,
|
ILuaScriptServicesConfig luaScriptServicesConfig,
|
||||||
LuaGame luaGame,
|
LuaGame luaGame,
|
||||||
ILuaCsHook luaCsHook,
|
ILuaCsHook luaCsHook
|
||||||
ILuaCsNetworking luaCsNetworking,
|
//ILuaCsNetworking luaCsNetworking,
|
||||||
ILuaCsUtility luaCsUtility,
|
//ILuaCsUtility luaCsUtility,
|
||||||
ILuaCsTimer luaCsTimer)
|
//ILuaCsTimer luaCsTimer
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_luaScriptLoader = loader;
|
_luaScriptLoader = loader;
|
||||||
_luaScriptServicesConfig = luaScriptServicesConfig;
|
_luaScriptServicesConfig = luaScriptServicesConfig;
|
||||||
@@ -63,9 +64,9 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
|||||||
|
|
||||||
_luaGame = luaGame;
|
_luaGame = luaGame;
|
||||||
_luaCsHook = luaCsHook;
|
_luaCsHook = luaCsHook;
|
||||||
_luaCsNetworking = luaCsNetworking;
|
//_luaCsNetworking = luaCsNetworking;
|
||||||
_luaCsUtility = luaCsUtility;
|
//_luaCsUtility = luaCsUtility;
|
||||||
_luaCsTimer = luaCsTimer;
|
//_luaCsTimer = luaCsTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDisposed { get; private set; }
|
public bool IsDisposed { get; private set; }
|
||||||
@@ -124,9 +125,9 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
|||||||
|
|
||||||
_script.Globals["Game"] = _luaGame;
|
_script.Globals["Game"] = _luaGame;
|
||||||
_script.Globals["Hook"] = _luaCsHook;
|
_script.Globals["Hook"] = _luaCsHook;
|
||||||
_script.Globals["Timer"] = _luaCsTimer;
|
//_script.Globals["Timer"] = _luaCsTimer;
|
||||||
_script.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
_script.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||||
_script.Globals["Networking"] = _luaCsNetworking;
|
//_script.Globals["Networking"] = _luaCsNetworking;
|
||||||
//_script.Globals["Steam"] = Steam;
|
//_script.Globals["Steam"] = Steam;
|
||||||
|
|
||||||
_script.Globals["ExecutionNumber"] = 0;
|
_script.Globals["ExecutionNumber"] = 0;
|
||||||
|
|||||||
+38
-1
@@ -223,7 +223,30 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
|
|
||||||
return result;
|
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()
|
public FluentResults.Result StopRunningPackages()
|
||||||
{
|
{
|
||||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
@@ -308,6 +331,20 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
return _runningPackages.ContainsKey(package);
|
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()
|
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages()
|
||||||
{
|
{
|
||||||
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
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 LoadPackageInfo(ContentPackage package);
|
||||||
public FluentResults.Result LoadPackagesInfo(ImmutableArray<ContentPackage> packages);
|
public FluentResults.Result LoadPackagesInfo(ImmutableArray<ContentPackage> packages);
|
||||||
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder);
|
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder);
|
||||||
|
public FluentResults.Result SyncLoadedPackagesList(ImmutableArray<ContentPackage> packages);
|
||||||
public FluentResults.Result StopRunningPackages();
|
public FluentResults.Result StopRunningPackages();
|
||||||
public FluentResults.Result UnloadPackage(ContentPackage package);
|
public FluentResults.Result UnloadPackage(ContentPackage package);
|
||||||
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
public FluentResults.Result UnloadPackages(ImmutableArray<ContentPackage> packages);
|
||||||
public FluentResults.Result UnloadAllPackages();
|
public FluentResults.Result UnloadAllPackages();
|
||||||
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
public ImmutableArray<ContentPackage> GetAllLoadedPackages();
|
||||||
public bool IsPackageRunning(ContentPackage package);
|
|
||||||
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages();
|
public ImmutableArray<ContentPackage> GetLoadedAssemblyPackages();
|
||||||
|
public bool IsPackageRunning(ContentPackage package);
|
||||||
|
public bool IsAnyPackageLoaded();
|
||||||
|
public bool IsAnyPackageRunning();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user