GameMain.LuaCs is no more
This commit is contained in:
+2
-2
@@ -1306,11 +1306,11 @@ namespace Barotrauma
|
||||
//increase oxygen and clamp it above zero
|
||||
// -> the character should be revived if there are no major afflictions in addition to lack of oxygen
|
||||
target.Oxygen = Math.Max(target.Oxygen + 10.0f, 10.0f);
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventHumanCPRSuccess>(x => x.OnCharacterCPRSuccess(this));
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventHumanCPRSuccess>(x => x.OnCharacterCPRSuccess(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventHumanCPRFailed>(x => x.OnCharacterCPRFailed(this));
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventHumanCPRFailed>(x => x.OnCharacterCPRFailed(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -859,7 +859,7 @@ namespace Barotrauma
|
||||
float impactDamage = GetImpactDamage(impact, impactTolerance);
|
||||
|
||||
float? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventChangeFallDamage>(x => should = x.OnChangeFallDamage(impactDamage, character, impactPos, velocity) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventChangeFallDamage>(x => should = x.OnChangeFallDamage(impactDamage, character, impactPos, velocity) ?? should);
|
||||
|
||||
if (should != null)
|
||||
{
|
||||
|
||||
@@ -3388,13 +3388,13 @@ namespace Barotrauma
|
||||
{
|
||||
for (int i = 0; i < CharacterList.Count; i++)
|
||||
{
|
||||
if (GameMain.LuaCs.Game.UpdatePriorityCharacters.Contains(CharacterList[i])) continue;
|
||||
if (LuaCsSetup.Instance.Game.UpdatePriorityCharacters.Contains(CharacterList[i])) continue;
|
||||
|
||||
CharacterList[i].Update(deltaTime * CharacterUpdateInterval, cam);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Character character in GameMain.LuaCs.Game.UpdatePriorityCharacters)
|
||||
foreach (Character character in LuaCsSetup.Instance.Game.UpdatePriorityCharacters)
|
||||
{
|
||||
if (character.Removed) { continue; }
|
||||
Debug.Assert(character is { Removed: false });
|
||||
|
||||
+2
-2
@@ -338,13 +338,13 @@ namespace Barotrauma
|
||||
|
||||
if (Prefab is AfflictionPrefabHusk huskPrefab)
|
||||
{
|
||||
if (huskPrefab.ControlHusk || GameMain.LuaCs.Game.enableControlHusk)
|
||||
if (huskPrefab.ControlHusk || LuaCsSetup.Instance.Game.enableControlHusk)
|
||||
{
|
||||
#if SERVER
|
||||
if (client != null)
|
||||
{
|
||||
GameMain.Server.SetClientCharacter(client, husk);
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventClientControlHusk>(x => x.OnClientControlHusk(client, husk));
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventClientControlHusk>(x => x.OnClientControlHusk(client, husk));
|
||||
}
|
||||
#else
|
||||
if (!character.IsRemotelyControlled && character == Character.Controlled)
|
||||
|
||||
@@ -658,7 +658,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventCharacterApplyDamage>(x => should = x.OnCharacterApplyDamage(this, attackResult, hitLimb, allowStacking) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventCharacterApplyDamage>(x => should = x.OnCharacterApplyDamage(this, attackResult, hitLimb, allowStacking) ?? should);
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
foreach (Affliction newAffliction in attackResult.Afflictions)
|
||||
@@ -830,7 +830,7 @@ namespace Barotrauma
|
||||
if (Character.Params.Health.ImmunityIdentifiers.Contains(newAffliction.Identifier)) { return; }
|
||||
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventCharacterApplyAffliction>(x => should = x.OnCharacterApplyAffliction(this, limbHealth, newAffliction, allowStacking) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventCharacterApplyAffliction>(x => should = x.OnCharacterApplyAffliction(this, limbHealth, newAffliction, allowStacking) ?? should);
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
Affliction existingAffliction = null;
|
||||
|
||||
@@ -436,7 +436,7 @@ namespace Barotrauma.Items.Components
|
||||
Structure targetStructure = target.UserData as Structure ?? targetFixture.UserData as Structure;
|
||||
Item targetItem = target.UserData is Holdable h ? h.Item : target.UserData as Item ?? targetFixture.UserData as Item;
|
||||
Entity targetEntity = targetCharacter ?? targetStructure ?? targetItem ?? target.UserData as Entity;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventMeleeWeaponHandleImpact>(x => x.OnMeleeWeaponHandleImpact(this, target));
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventMeleeWeaponHandleImpact>(x => x.OnMeleeWeaponHandleImpact(this, target));
|
||||
|
||||
if (Attack != null)
|
||||
{
|
||||
|
||||
@@ -335,7 +335,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventItemDeconstructed>(x => should = x.OnItemDeconstructed(targetItem, this, user, allowRemove) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventItemDeconstructed>(x => should = x.OnItemDeconstructed(targetItem, this, user, allowRemove) ?? should);
|
||||
if (should == true) { return; }
|
||||
|
||||
if (targetItem.AllowDeconstruct && allowRemove)
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace Barotrauma.Items.Components
|
||||
public void TransmitSignal(Signal signal, bool sentFromChat)
|
||||
{
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventWifiSignalTransmitted>(x => should = x.OnWifiSignalTransmitted(this, signal, sentFromChat) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventWifiSignalTransmitted>(x => should = x.OnWifiSignalTransmitted(this, signal, sentFromChat) ?? should);
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
bool chatMsgSent = false;
|
||||
|
||||
@@ -3895,7 +3895,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventItemReadPropertyChange>(x => should = x.OnItemReadPropertyChange(this, property, parentObject, allowEditing, sender) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventItemReadPropertyChange>(x => should = x.OnItemReadPropertyChange(this, property, parentObject, allowEditing, sender) ?? should);
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
Type type = property.PropertyType;
|
||||
|
||||
@@ -22,8 +22,16 @@ namespace Barotrauma
|
||||
partial class LuaCsSetup : IDisposable, IEventScreenSelected, IEventEnabledPackageListChanged,
|
||||
IEventReloadAllPackages
|
||||
{
|
||||
public LuaCsSetup()
|
||||
private static LuaCsSetup _luaCsSetup;
|
||||
public static LuaCsSetup Instance => _luaCsSetup ??= new LuaCsSetup();
|
||||
|
||||
private LuaCsSetup()
|
||||
{
|
||||
if (_luaCsSetup != null)
|
||||
{
|
||||
throw new Exception("Tried to create another LuaCsSetup instance");
|
||||
}
|
||||
|
||||
// == startup
|
||||
_servicesProvider = SetupServicesProvider();
|
||||
_runStateMachine = SetupStateMachine();
|
||||
@@ -432,6 +440,8 @@ namespace Barotrauma
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
_luaCsSetup = null;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
@@ -74,27 +74,27 @@ namespace Barotrauma.LuaCs
|
||||
public static void PrintMessage(string s)
|
||||
{
|
||||
#if SERVER
|
||||
GameMain.LuaCs.Logger.LogMessage($"{s}");
|
||||
LuaCsSetup.Instance.Logger.LogMessage($"{s}");
|
||||
#else
|
||||
GameMain.LuaCs.Logger.LogMessage($"{s}");
|
||||
LuaCsSetup.Instance.Logger.LogMessage($"{s}");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void PrintWarning(string s)
|
||||
{
|
||||
#if SERVER
|
||||
GameMain.LuaCs.Logger.Log($"{s}", Color.Yellow);
|
||||
LuaCsSetup.Instance.Logger.Log($"{s}", Color.Yellow);
|
||||
#else
|
||||
GameMain.LuaCs.Logger.Log($"{s}", Color.Yellow);
|
||||
LuaCsSetup.Instance.Logger.Log($"{s}", Color.Yellow);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void PrintError(string s)
|
||||
{
|
||||
#if SERVER
|
||||
GameMain.LuaCs.Logger.LogError($"{s}");
|
||||
LuaCsSetup.Instance.Logger.LogError($"{s}");
|
||||
#else
|
||||
GameMain.LuaCs.Logger.LogError($"{s}");
|
||||
LuaCsSetup.Instance.Logger.LogError($"{s}");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Barotrauma
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GameMain.LuaCs.Logger.HandleException(e);
|
||||
LuaCsSetup.Instance.Logger.HandleException(e);
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public partial class LoggerService : ILoggerService
|
||||
if (!_isInsideLogCall)
|
||||
{
|
||||
_isInsideLogCall = true;
|
||||
GameMain.LuaCs?.EventService.PublishEvent<IEventServerLog>(x => x.OnServerLog(logMessage, log.MessageType));
|
||||
LuaCsSetup.Instance?.EventService.PublishEvent<IEventServerLog>(x => x.OnServerLog(logMessage, log.MessageType));
|
||||
_isInsideLogCall = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ public sealed class LuaCsInfoProvider : ILuaCsInfoProvider
|
||||
}
|
||||
|
||||
public bool IsDisposed => false;
|
||||
public bool IsCsEnabled => GameMain.LuaCs.IsCsEnabled;
|
||||
public bool DisableErrorGUIOverlay => GameMain.LuaCs.DisableErrorGUIOverlay;
|
||||
public bool HideUserNamesInLogs => GameMain.LuaCs.HideUserNamesInLogs;
|
||||
public ulong LuaForBarotraumaSteamId => GameMain.LuaCs.LuaForBarotraumaSteamId;
|
||||
public bool RestrictMessageSize => GameMain.LuaCs.RestrictMessageSize;
|
||||
public string LocalDataSavePath => GameMain.LuaCs.LocalDataSavePath;
|
||||
public RunState CurrentRunState => GameMain.LuaCs.CurrentRunState;
|
||||
public bool IsCsEnabled => LuaCsSetup.Instance.IsCsEnabled;
|
||||
public bool DisableErrorGUIOverlay => LuaCsSetup.Instance.DisableErrorGUIOverlay;
|
||||
public bool HideUserNamesInLogs => LuaCsSetup.Instance.HideUserNamesInLogs;
|
||||
public ulong LuaForBarotraumaSteamId => LuaCsSetup.Instance.LuaForBarotraumaSteamId;
|
||||
public bool RestrictMessageSize => LuaCsSetup.Instance.RestrictMessageSize;
|
||||
public string LocalDataSavePath => LuaCsSetup.Instance.LocalDataSavePath;
|
||||
public RunState CurrentRunState => LuaCsSetup.Instance.CurrentRunState;
|
||||
public ContentPackage LuaCsForBarotraumaPackage
|
||||
{
|
||||
get
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
{
|
||||
commands.RegisterCommand("cl_reloadlua|cl_reloadcs|cl_reloadluacs", "Re-initializes the LuaCs environment.", (string[] args) =>
|
||||
{
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventReloadAllPackages>(sub => sub.OnReloadAllPackages());
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventReloadAllPackages>(sub => sub.OnReloadAllPackages());
|
||||
});
|
||||
|
||||
commands.RegisterCommand("cl_toggleluadebug", "Toggles the MoonSharp Debug Server.", (string[] args) =>
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ namespace Barotrauma
|
||||
{
|
||||
public object GetComponentString(string component)
|
||||
{
|
||||
Type type = GameMain.LuaCs.PluginManagementService.GetType("Barotrauma.Items.Components." + component);
|
||||
Type type = LuaCsSetup.Instance.PluginManagementService.GetType("Barotrauma.Items.Components." + component);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
|
||||
+11
-11
@@ -17,41 +17,41 @@ namespace Barotrauma
|
||||
{
|
||||
public static void HandleException(Exception ex, LuaCsMessageOrigin origin)
|
||||
{
|
||||
GameMain.LuaCs.Logger.HandleException(ex);
|
||||
LuaCsSetup.Instance.Logger.HandleException(ex);
|
||||
}
|
||||
|
||||
public static void LogError(string message, LuaCsMessageOrigin origin)
|
||||
{
|
||||
GameMain.LuaCs.Logger.LogError(message);
|
||||
LuaCsSetup.Instance.Logger.LogError(message);
|
||||
}
|
||||
|
||||
public static void LogError(string message)
|
||||
{
|
||||
GameMain.LuaCs.Logger.LogError(message);
|
||||
LuaCsSetup.Instance.Logger.LogError(message);
|
||||
}
|
||||
|
||||
public static void LogMessage(string message, Color? serverColor = null, Color? clientColor = null)
|
||||
{
|
||||
GameMain.LuaCs.Logger.LogMessage(message, serverColor, clientColor);
|
||||
LuaCsSetup.Instance.Logger.LogMessage(message, serverColor, clientColor);
|
||||
}
|
||||
|
||||
public static void Log(string message, Color? color = null, ServerLog.MessageType messageType = ServerLog.MessageType.ServerMessage)
|
||||
{
|
||||
GameMain.LuaCs.Logger.Log(message, color, messageType);
|
||||
LuaCsSetup.Instance.Logger.Log(message, color, messageType);
|
||||
}
|
||||
}
|
||||
|
||||
partial class LuaCsSetup
|
||||
{
|
||||
// Compatibility with cs mods that use this method.
|
||||
public static void PrintLuaError(object message) => GameMain.LuaCs.Logger.LogError($"{message}");
|
||||
public static void PrintCsError(object message) => GameMain.LuaCs.Logger.LogError($"{message}");
|
||||
public static void PrintGenericError(object message) => GameMain.LuaCs.Logger.LogError($"{message}");
|
||||
public static void PrintLuaError(object message) => LuaCsSetup.Instance.Logger.LogError($"{message}");
|
||||
public static void PrintCsError(object message) => LuaCsSetup.Instance.Logger.LogError($"{message}");
|
||||
public static void PrintGenericError(object message) => LuaCsSetup.Instance.Logger.LogError($"{message}");
|
||||
|
||||
internal void PrintMessage(object message) => GameMain.LuaCs.Logger.LogMessage($"{message}");
|
||||
internal void PrintMessage(object message) => LuaCsSetup.Instance.Logger.LogMessage($"{message}");
|
||||
|
||||
public static void PrintCsMessage(object message) => GameMain.LuaCs.Logger.LogMessage($"{message}");
|
||||
public static void PrintCsMessage(object message) => LuaCsSetup.Instance.Logger.LogMessage($"{message}");
|
||||
|
||||
internal void HandleException(Exception ex, LuaCsMessageOrigin origin) => GameMain.LuaCs.Logger.HandleException(ex);
|
||||
internal void HandleException(Exception ex, LuaCsMessageOrigin origin) => LuaCsSetup.Instance.Logger.HandleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (var package in ContentPackageManager.AllPackages)
|
||||
{
|
||||
if (package.UgcId.ValueEquals(new SteamWorkshopId(GameMain.LuaCs.LuaForBarotraumaSteamId))
|
||||
if (package.UgcId.ValueEquals(new SteamWorkshopId(LuaCsSetup.Instance.LuaForBarotraumaSteamId))
|
||||
&& pathStartsWith(getFullPath(package.Path)))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -294,7 +294,7 @@ namespace Barotrauma.LuaCs
|
||||
|
||||
private static MethodBase ResolveMethod(string className, string methodName, string[] parameters)
|
||||
{
|
||||
var classType = GameMain.LuaCs.PluginManagementService.GetType(className);
|
||||
var classType = LuaCsSetup.Instance.PluginManagementService.GetType(className);
|
||||
if (classType == null) throw new ScriptRuntimeException($"invalid class name '{className}'");
|
||||
|
||||
const BindingFlags BINDING_FLAGS = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
@@ -309,7 +309,7 @@ namespace Barotrauma.LuaCs
|
||||
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
Type type = GameMain.LuaCs.PluginManagementService.GetType(parameters[i]);
|
||||
Type type = LuaCsSetup.Instance.PluginManagementService.GetType(parameters[i]);
|
||||
if (type == null)
|
||||
{
|
||||
throw new ScriptRuntimeException($"invalid parameter type '{parameters[i]}'");
|
||||
@@ -670,7 +670,7 @@ namespace Barotrauma.LuaCs
|
||||
}
|
||||
|
||||
var type = typeBuilder.CreateType();
|
||||
type.GetField(FIELD_LUACS, BindingFlags.Public | BindingFlags.Static).SetValue(null, GameMain.LuaCs);
|
||||
type.GetField(FIELD_LUACS, BindingFlags.Public | BindingFlags.Static).SetValue(null, LuaCsSetup.Instance);
|
||||
return type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
|
||||
}
|
||||
|
||||
|
||||
@@ -886,7 +886,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
bool? should = null;
|
||||
GameMain.LuaCs.EventService.PublishEvent<IEventGapOxygenUpdate>(x => should = x.OnGapOxygenUpdate(this, hull1, hull2) ?? should);
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventGapOxygenUpdate>(x => should = x.OnGapOxygenUpdate(this, hull1, hull2) ?? should);
|
||||
if (should != null && should.Value) return;
|
||||
|
||||
float totalOxygen = hull1.Oxygen + hull2.Oxygen;
|
||||
|
||||
@@ -697,7 +697,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
if (GameMain.LuaCs.Game.UpdatePriorityItems.Contains(item)) { continue; }
|
||||
if (LuaCsSetup.Instance.Game.UpdatePriorityItems.Contains(item)) { continue; }
|
||||
lastUpdatedItem = item;
|
||||
item.Update(deltaTime * MapEntityUpdateInterval, cam);
|
||||
}
|
||||
@@ -712,7 +712,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in GameMain.LuaCs.Game.UpdatePriorityItems)
|
||||
foreach (var item in LuaCsSetup.Instance.Game.UpdatePriorityItems)
|
||||
{
|
||||
if (item.Removed) continue;
|
||||
|
||||
|
||||
@@ -1787,14 +1787,14 @@ namespace Barotrauma
|
||||
{
|
||||
if (entity is Item item)
|
||||
{
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>("statusEffect.apply." + item.Prefab.Identifier, this, deltaTime, entity, targets, worldPosition);
|
||||
var result = LuaCsSetup.Instance.Hook.Call<bool?>("statusEffect.apply." + item.Prefab.Identifier, this, deltaTime, entity, targets, worldPosition);
|
||||
|
||||
if (result != null && result.Value) { return; }
|
||||
}
|
||||
|
||||
if (entity is Character character)
|
||||
{
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>("statusEffect.apply." + character.SpeciesName, this, deltaTime, entity, targets, worldPosition);
|
||||
var result = LuaCsSetup.Instance.Hook.Call<bool?>("statusEffect.apply." + character.SpeciesName, this, deltaTime, entity, targets, worldPosition);
|
||||
|
||||
if (result != null && result.Value) { return; }
|
||||
}
|
||||
@@ -1804,7 +1804,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach ((string hookName, ContentXElement element) in luaHook)
|
||||
{
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>(hookName, this, deltaTime, entity, targets, worldPosition, element);
|
||||
var result = LuaCsSetup.Instance.Hook.Call<bool?>(hookName, this, deltaTime, entity, targets, worldPosition, element);
|
||||
|
||||
if (result != null && result.Value) { return; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user