diff --git a/ExampleMods/Mods/6ReplaceMethod/ReplaceMethod.cs b/ExampleMods/Mods/6ReplaceMethod/ReplaceMethod.cs index bacc6dc3..0ad6fdbe 100644 --- a/ExampleMods/Mods/6ReplaceMethod/ReplaceMethod.cs +++ b/ExampleMods/Mods/6ReplaceMethod/ReplaceMethod.cs @@ -10,17 +10,12 @@ namespace ExampleMods.Mods._6ReplaceMethod public class ReplaceMethod: Watermark { public ReplaceMethod( - ISptLogger logger, + ISptLogger logger, // The logger needs to use the same type as the overriden type (in this case, Watermark) ConfigServer configServer, LocalisationService localisationService, WatermarkLocale watermarkLocale) - : base(logger, configServer, localisationService, watermarkLocale) - { - _configServer = configServer; - _localisationService = localisationService; - _watermarkLocale = watermarkLocale; - _logger = logger; - } + : base(logger, configServer, localisationService, watermarkLocale) // You must provide the parameters the overridden type requires + { } public override void Initialize() { diff --git a/ExampleMods/Mods/7UseMultipleClasses/UseMultipleClasses.cs b/ExampleMods/Mods/7UseMultipleClasses/UseMultipleClasses.cs index 40419e34..845863c1 100644 --- a/ExampleMods/Mods/7UseMultipleClasses/UseMultipleClasses.cs +++ b/ExampleMods/Mods/7UseMultipleClasses/UseMultipleClasses.cs @@ -11,9 +11,9 @@ namespace ExampleMods.Mods._7UseMultipleClasses private readonly ISptLogger _logger; public UseMultipleClasses( - ISptLogger _logger) + ISptLogger logger) { - this._logger = _logger; + this._logger = logger; } public void PostDBLoad() diff --git a/ExampleMods/Mods/8AddOnLoad/AddOnLoad.cs b/ExampleMods/Mods/8AddOnLoad/AddOnLoad.cs new file mode 100644 index 00000000..3c858acc --- /dev/null +++ b/ExampleMods/Mods/8AddOnLoad/AddOnLoad.cs @@ -0,0 +1,33 @@ +using Core.DI; +using Core.Models.Utils; +using SptCommon.Annotations; + +namespace ExampleMods.Mods._8AddOnLoad +{ + // Flag class as being OnLoad and give it a load priority, check `OnLoadOrder` for list of possible choices + [Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.PostSptDatabase)] + [Injectable(InjectableTypeOverride = typeof(AddOnLoad))] + public class AddOnLoad : IOnLoad // Must implement the IOnLoad interface + { + private readonly ISptLogger _logger; + + public AddOnLoad( + ISptLogger logger) + { + _logger = logger; + } + + public Task OnLoad() + { + // Can do work here + _logger.Success($"Mod loaded after database!"); + + return Task.CompletedTask; + } + + public string GetRoute() + { + return "mod-load-example"; + } + } +} diff --git a/ExampleMods/Mods/8AddOnLoad/package.json b/ExampleMods/Mods/8AddOnLoad/package.json new file mode 100644 index 00000000..224d24f8 --- /dev/null +++ b/ExampleMods/Mods/8AddOnLoad/package.json @@ -0,0 +1,13 @@ +{ + "Name": "8AddOnLoad", + "Version": "1.0.0", + "SptVersion": "~4.0", + "LoadBefore": [], + "LoadAfter": [], + "IncompatibileMods": [], + "Url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "IsBundleMod": false, + "Author": "SPT", + "Contributors": [], + "Licence": "MIT" +} diff --git a/Libraries/Core/Callbacks/GameCallbacks.cs b/Libraries/Core/Callbacks/GameCallbacks.cs index 0150d466..e0cf4f2e 100644 --- a/Libraries/Core/Callbacks/GameCallbacks.cs +++ b/Libraries/Core/Callbacks/GameCallbacks.cs @@ -9,7 +9,7 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.GameCallbacks)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.GameCallbacks)] [Injectable(InjectableTypeOverride = typeof(GameCallbacks))] public class GameCallbacks( HttpResponseUtil _httpResponseUtil, @@ -17,7 +17,7 @@ public class GameCallbacks( SaveServer _saveServer, GameController _gameController, TimeUtil _timeUtil -) : OnLoad +) : IOnLoad { public Task OnLoad() { diff --git a/Libraries/Core/Callbacks/HandbookCallbacks.cs b/Libraries/Core/Callbacks/HandbookCallbacks.cs index bcabda1a..68204989 100644 --- a/Libraries/Core/Callbacks/HandbookCallbacks.cs +++ b/Libraries/Core/Callbacks/HandbookCallbacks.cs @@ -4,8 +4,8 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.HandbookCallbacks)] -public class HandbookCallbacks(HandBookController _handBookController) : OnLoad +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.HandbookCallbacks)] +public class HandbookCallbacks(HandBookController _handBookController) : IOnLoad { public Task OnLoad() { diff --git a/Libraries/Core/Callbacks/HttpCallbacks.cs b/Libraries/Core/Callbacks/HttpCallbacks.cs index 43e1f7be..21571fab 100644 --- a/Libraries/Core/Callbacks/HttpCallbacks.cs +++ b/Libraries/Core/Callbacks/HttpCallbacks.cs @@ -5,8 +5,8 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectionType.Singleton, InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.HttpCallbacks)] -public class HttpCallbacks(HttpServer _httpServer, ApplicationContext _applicationContext) : OnLoad +[Injectable(InjectionType.Singleton, InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.HttpCallbacks)] +public class HttpCallbacks(HttpServer _httpServer, ApplicationContext _applicationContext) : IOnLoad { public Task OnLoad() { diff --git a/Libraries/Core/Callbacks/PresetCallbacks.cs b/Libraries/Core/Callbacks/PresetCallbacks.cs index 641d122a..282ad117 100644 --- a/Libraries/Core/Callbacks/PresetCallbacks.cs +++ b/Libraries/Core/Callbacks/PresetCallbacks.cs @@ -4,8 +4,8 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.PresetCallbacks)] -public class PresetCallbacks(PresetController _presetController) : OnLoad +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.PresetCallbacks)] +public class PresetCallbacks(PresetController _presetController) : IOnLoad { public Task OnLoad() { diff --git a/Libraries/Core/Callbacks/RagfairCallbacks.cs b/Libraries/Core/Callbacks/RagfairCallbacks.cs index 7e0532e2..8311c924 100644 --- a/Libraries/Core/Callbacks/RagfairCallbacks.cs +++ b/Libraries/Core/Callbacks/RagfairCallbacks.cs @@ -11,7 +11,7 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.RagfairCallbacks)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.RagfairCallbacks)] [Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.RagfairCallbacks)] [Injectable(InjectableTypeOverride = typeof(RagfairCallbacks))] public class RagfairCallbacks( @@ -21,7 +21,7 @@ public class RagfairCallbacks( RagfairTaxService _ragfairTaxService, RagfairPriceService _ragfairPriceService, ConfigServer _configServer -) : OnLoad, OnUpdate +) : IOnLoad, OnUpdate { private readonly RagfairConfig _ragfairConfig = _configServer.GetConfig(); diff --git a/Libraries/Core/Callbacks/SaveCallbacks.cs b/Libraries/Core/Callbacks/SaveCallbacks.cs index 346d4693..31d4c5c4 100644 --- a/Libraries/Core/Callbacks/SaveCallbacks.cs +++ b/Libraries/Core/Callbacks/SaveCallbacks.cs @@ -6,14 +6,14 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.SaveCallbacks)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.SaveCallbacks)] [Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.SaveCallbacks)] public class SaveCallbacks( SaveServer _saveServer, ConfigServer _configServer, BackupService _backupService ) - : OnLoad, OnUpdate + : IOnLoad, OnUpdate { private readonly CoreConfig _coreConfig = _configServer.GetConfig(); diff --git a/Libraries/Core/Callbacks/TraderCallbacks.cs b/Libraries/Core/Callbacks/TraderCallbacks.cs index 14a4a72b..ebec1186 100644 --- a/Libraries/Core/Callbacks/TraderCallbacks.cs +++ b/Libraries/Core/Callbacks/TraderCallbacks.cs @@ -8,14 +8,14 @@ using SptCommon.Annotations; namespace Core.Callbacks; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.TraderCallbacks)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.TraderCallbacks)] [Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.TraderCallbacks)] [Injectable(InjectableTypeOverride = typeof(TraderCallbacks))] public class TraderCallbacks( HttpResponseUtil _httpResponseUtil, TraderController _traderController, ConfigServer _configServer -) : OnLoad, OnUpdate +) : IOnLoad, OnUpdate { private readonly TraderConfig _traderConfig = _configServer.GetConfig(); diff --git a/Libraries/Core/DI/OnLoad.cs b/Libraries/Core/DI/IOnLoad.cs similarity index 72% rename from Libraries/Core/DI/OnLoad.cs rename to Libraries/Core/DI/IOnLoad.cs index 60ada15a..91ed2543 100644 --- a/Libraries/Core/DI/OnLoad.cs +++ b/Libraries/Core/DI/IOnLoad.cs @@ -1,6 +1,6 @@ namespace Core.DI; -public interface OnLoad +public interface IOnLoad { Task OnLoad(); string GetRoute(); diff --git a/Libraries/Core/DI/OnLoadOrder.cs b/Libraries/Core/DI/OnLoadOrder.cs index 6c5c88ff..ddd6f73a 100644 --- a/Libraries/Core/DI/OnLoadOrder.cs +++ b/Libraries/Core/DI/OnLoadOrder.cs @@ -2,7 +2,9 @@ namespace Core.DI; public static class OnLoadOrder { - public const int Database = 0; + public const int PreSPTDatabase = 0; + public const int Database = 1; + public const int PostSptDatabase = 2; public const int GameCallbacks = 100; public const int PostDBModLoader = 200; public const int HandbookCallbacks = 300; @@ -13,4 +15,5 @@ public static class OnLoadOrder public const int PresetCallbacks = 800; public const int RagfairPriceService = 900; public const int RagfairCallbacks = 1000; + public const int PostServerLoad = 9999; } diff --git a/Libraries/Core/Loaders/PostDBModLoader.cs b/Libraries/Core/Loaders/PostDBModLoader.cs index 273431a9..d7954050 100644 --- a/Libraries/Core/Loaders/PostDBModLoader.cs +++ b/Libraries/Core/Loaders/PostDBModLoader.cs @@ -5,11 +5,11 @@ using SptCommon.Annotations; namespace Core.Loaders; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.PostDBModLoader)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.PostDBModLoader)] public class PostDBModLoader( ISptLogger _logger, IEnumerable _postDbLoadMods -) : OnLoad +) : IOnLoad { public async Task OnLoad() { diff --git a/Libraries/Core/Loaders/PostSptModLoader.cs b/Libraries/Core/Loaders/PostSptModLoader.cs index a1fb1b79..6c105296 100644 --- a/Libraries/Core/Loaders/PostSptModLoader.cs +++ b/Libraries/Core/Loaders/PostSptModLoader.cs @@ -6,11 +6,11 @@ using SptCommon.Annotations; namespace Core.Loaders; -[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.PostSptModLoader)] +[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.PostSptModLoader)] public class PostSptModLoader( ISptLogger _logger, IEnumerable _postSptLoadMods -) : OnLoad +) : IOnLoad { public async Task OnLoad() { diff --git a/Libraries/Core/Utils/App.cs b/Libraries/Core/Utils/App.cs index c5f7fb47..fa0062f8 100644 --- a/Libraries/Core/Utils/App.cs +++ b/Libraries/Core/Utils/App.cs @@ -21,7 +21,7 @@ public class App protected LocalisationService _localisationService; protected ISptLogger _logger; - protected IEnumerable _onLoad; + protected IEnumerable _onLoad; protected IEnumerable _onUpdate; protected Dictionary _onUpdateLastRun = new(); protected Timer _timer; @@ -36,7 +36,7 @@ public class App EncodingUtil encodingUtil, HttpServer httpServer, DatabaseService databaseService, - IEnumerable onLoadComponents, + IEnumerable onLoadComponents, IEnumerable onUpdateComponents ) { diff --git a/Libraries/Core/Utils/DatabaseImporter.cs b/Libraries/Core/Utils/DatabaseImporter.cs index 9261538f..00f776cf 100644 --- a/Libraries/Core/Utils/DatabaseImporter.cs +++ b/Libraries/Core/Utils/DatabaseImporter.cs @@ -11,8 +11,8 @@ using LogLevel = Core.Models.Spt.Logging.LogLevel; namespace Core.Utils; -[Injectable(InjectionType.Singleton, InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.Database)] -public class DatabaseImporter : OnLoad +[Injectable(InjectionType.Singleton, InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.Database)] +public class DatabaseImporter : IOnLoad { private const string _sptDataPath = "./Assets/"; private readonly HttpConfig httpConfig; diff --git a/Tools/HideoutCraftQuestIdGenerator/HideoutCraftQuestIdGenerator.cs b/Tools/HideoutCraftQuestIdGenerator/HideoutCraftQuestIdGenerator.cs index 33bf3bae..8f035f73 100644 --- a/Tools/HideoutCraftQuestIdGenerator/HideoutCraftQuestIdGenerator.cs +++ b/Tools/HideoutCraftQuestIdGenerator/HideoutCraftQuestIdGenerator.cs @@ -20,7 +20,7 @@ public class HideoutCraftQuestIdGenerator( DatabaseServer _databaseServer, LocaleService _localeService, ItemHelper _itemHelper, - IEnumerable _onLoadComponents + IEnumerable _onLoadComponents ) { private readonly HashSet _blacklistedProductions = diff --git a/Tools/ItemTplGenerator/ItemTplGenerator.cs b/Tools/ItemTplGenerator/ItemTplGenerator.cs index 4626578f..20c3fec5 100644 --- a/Tools/ItemTplGenerator/ItemTplGenerator.cs +++ b/Tools/ItemTplGenerator/ItemTplGenerator.cs @@ -20,7 +20,7 @@ public class ItemTplGenerator( LocaleService _localeService, ItemHelper _itemHelper, FileUtil _fileUtil, - IEnumerable _onLoadComponents + IEnumerable _onLoadComponents ) { private readonly HashSet collidedEnumKeys = [];