diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/LazyLoad.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/LazyLoad.cs index 162d6d7c..effd9d53 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/LazyLoad.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/LazyLoad.cs @@ -8,6 +8,12 @@ public class LazyLoad(Func deserialize) private Timer? autoCleanerTimeout; + /// + /// can be subscribed to for mods to modify. It is fired right after lazy loading is complete + /// and any modification passed to will stay for the duration of this 's lifecycle + /// + public event EventHandler>? OnLazyLoad; + public T? Value { get @@ -16,6 +22,12 @@ public class LazyLoad(Func deserialize) { _result = deserialize(); _isLoaded = true; + + OnLazyLoadEventArgs args = new(_result); + OnLazyLoad?.Invoke(this, args); + + _result = args.Value; + autoCleanerTimeout = new Timer( _ => { @@ -33,9 +45,10 @@ public class LazyLoad(Func deserialize) autoCleanerTimeout?.Change(_autoCleanerTimeout, Timeout.InfiniteTimeSpan); return _result; } - set - { - _result = value; - } } } + +public class OnLazyLoadEventArgs(T value) : EventArgs +{ + public T Value { get; set; } = value; +}