From cf251451ed82aaa91ae85a867436f7c07ed8826d Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:06:13 -0300 Subject: [PATCH] Fix EventService.Call not implemented correctly --- .../LuaCs/Services/EventService.cs | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs index e8141201c..bf7a04271 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs @@ -5,6 +5,7 @@ using FluentResults; using FluentResults.LuaCs; using HarmonyLib; using Microsoft.Toolkit.Diagnostics; +using MoonSharp.Interpreter; using OneOf; using RestSharp; using System; @@ -132,6 +133,11 @@ public partial class EventService : IEventService } public object Call(string eventName, params object[] args) + { + return Call(eventName, args); + } + + public T Call(string eventName, params object[] args) { Guard.IsNotNullOrWhiteSpace(eventName, nameof(eventName)); using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult(); @@ -140,16 +146,36 @@ public partial class EventService : IEventService if (!_luaLegacyEventsSubscribers.TryGetValue(eventName, out var eventSubscribers) || eventSubscribers.IsEmpty) { - return null; + return default; } - object returnValue = null; + T returnValue = default; foreach (var subscriber in eventSubscribers) { try { - returnValue = subscriber.Value.Invoke(args); + object result = subscriber.Value.Invoke(args); + if (result is DynValue luaResult) + { + if (luaResult.Type == DataType.Tuple) + { + bool replaceNil = luaResult.Tuple.Length > 1 && luaResult.Tuple[1].CastToBool(); + + if (!luaResult.Tuple[0].IsNil() || replaceNil) + { + returnValue = luaResult.ToObject(); + } + } + else if (!luaResult.IsNil()) + { + returnValue = luaResult.ToObject(); + } + } + else + { + returnValue = (T)result; + } } catch (Exception e) { @@ -163,11 +189,6 @@ public partial class EventService : IEventService return returnValue; } - public T Call(string eventName, params object[] args) - { - return (T)Call(eventName, args); - } - public void Subscribe(string identifier, IDictionary callbacks) where T : IEvent { Guard.IsNotNullOrWhiteSpace(identifier, nameof(identifier));