Fix bullshit Lua issues

This commit is contained in:
Evil Factory
2026-02-12 21:50:13 -03:00
parent 07d838eee0
commit 5f38b4a43a
5 changed files with 22 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
namespace Barotrauma.LuaCs.Compatibility;
internal partial interface ILuaCsTimer : ILuaCsShim
internal partial interface ILuaCsTimer : IReusableService, ILuaCsShim
{
public static double Time => Timing.TotalTime;
public static double GetTime() => Time;

View File

@@ -25,10 +25,7 @@ internal class HarmonyEventPatchesService : IService
Harmony.PatchAll(typeof(HarmonyEventPatchesService));
}
// TODO: This causes like hell in Debug.
#if !DEBUG
[HarmonyPatch(typeof(CoroutineManager), nameof(CoroutineManager.Update)), HarmonyPostfix]
#endif
public static void CoroutineManager_Update_Post()
{
_eventService.PublishEvent<IEventUpdate>(x => x.OnUpdate(Timing.TotalTime));

View File

@@ -174,9 +174,8 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
_eventService.RegisterLuaEventAlias<IEventUpdate>("think", "OnUpdate");
_eventService.RegisterLuaEventAlias<IEventKeyUpdate>("keyUpdate", "OnKeyUpdate");
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("character.created", "OnCharacterCreated");
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("character.giveJobItems", "OnGiveCharacterJobItems");
_eventService.RegisterLuaEventAlias<IEventCharacterCreated>("afflictionUpdate", "OnAfflictionUpdate");
_eventService.RegisterLuaEventAlias<IEventGiveCharacterJobItems>("character.giveJobItems", "OnGiveCharacterJobItems");
_eventService.RegisterLuaEventAlias<IEventAfflictionUpdate>("afflictionUpdate", "OnAfflictionUpdate");
}
private void SetupEnvironment(bool enableSandbox)
@@ -357,6 +356,7 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
{
_luaScriptLoader.ClearCaches();
_userDataService.Reset();
_luaCsTimer.Reset();
RegisterLuaEvents();
return DisposeAllPackageResources();
}

View File

@@ -34,7 +34,7 @@ namespace Barotrauma
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(LuaCsAction), v => (LuaCsAction)(args =>
{
if (v.Function.OwnerScript == _luaScriptManagementService)
if (v.Function.OwnerScript == _luaScriptManagementService.InternalScript)
{
Call(v.Function, args);
}

View File

@@ -61,7 +61,7 @@ namespace Barotrauma
public LuaCsTimer(IEventService eventService)
{
_eventService = eventService;
_eventService.Subscribe<IEventUpdate>(this);
SubscribeToEvents();
}
private void AddTimer(TimedAction timedAction)
@@ -101,11 +101,6 @@ namespace Barotrauma
AddTimer(timedAction);
}
public void Dispose()
{
_eventService.Unsubscribe<IEventUpdate>(this);
}
public void OnUpdate(double fixedDeltaTime)
{
lock (timedActions)
@@ -135,6 +130,22 @@ namespace Barotrauma
}
}
private void SubscribeToEvents()
{
_eventService.Subscribe<IEventUpdate>(this);
}
public FluentResults.Result Reset()
{
SubscribeToEvents();
return FluentResults.Result.Ok();
}
public void Dispose()
{
_eventService.Unsubscribe<IEventUpdate>(this);
}
public bool IsDisposed => false;
}
}