Renamed interface to IOnLoad

Added OnLoad mod
Expanded `OnLoadOrder` options
This commit is contained in:
Chomp
2025-02-08 12:18:57 +00:00
parent 212dfd0d65
commit ac7b2daeba
19 changed files with 80 additions and 36 deletions
@@ -10,17 +10,12 @@ namespace ExampleMods.Mods._6ReplaceMethod
public class ReplaceMethod: Watermark
{
public ReplaceMethod(
ISptLogger<Watermark> logger,
ISptLogger<Watermark> 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()
{
@@ -11,9 +11,9 @@ namespace ExampleMods.Mods._7UseMultipleClasses
private readonly ISptLogger<UseMultipleClasses> _logger;
public UseMultipleClasses(
ISptLogger<UseMultipleClasses> _logger)
ISptLogger<UseMultipleClasses> logger)
{
this._logger = _logger;
this._logger = logger;
}
public void PostDBLoad()
+33
View File
@@ -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<AddOnLoad> _logger;
public AddOnLoad(
ISptLogger<AddOnLoad> 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";
}
}
}
+13
View File
@@ -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"
}
+2 -2
View File
@@ -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()
{
@@ -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()
{
+2 -2
View File
@@ -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()
{
+2 -2
View File
@@ -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()
{
+2 -2
View File
@@ -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<RagfairConfig>();
+2 -2
View File
@@ -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<CoreConfig>();
+2 -2
View File
@@ -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<TraderConfig>();
@@ -1,6 +1,6 @@
namespace Core.DI;
public interface OnLoad
public interface IOnLoad
{
Task OnLoad();
string GetRoute();
+4 -1
View File
@@ -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;
}
+2 -2
View File
@@ -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<PostDBModLoader> _logger,
IEnumerable<IPostDBLoadMod> _postDbLoadMods
) : OnLoad
) : IOnLoad
{
public async Task OnLoad()
{
+2 -2
View File
@@ -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<PostSptModLoader> _logger,
IEnumerable<IPostSptLoadMod> _postSptLoadMods
) : OnLoad
) : IOnLoad
{
public async Task OnLoad()
{
+2 -2
View File
@@ -21,7 +21,7 @@ public class App
protected LocalisationService _localisationService;
protected ISptLogger<App> _logger;
protected IEnumerable<OnLoad> _onLoad;
protected IEnumerable<IOnLoad> _onLoad;
protected IEnumerable<OnUpdate> _onUpdate;
protected Dictionary<string, long> _onUpdateLastRun = new();
protected Timer _timer;
@@ -36,7 +36,7 @@ public class App
EncodingUtil encodingUtil,
HttpServer httpServer,
DatabaseService databaseService,
IEnumerable<OnLoad> onLoadComponents,
IEnumerable<IOnLoad> onLoadComponents,
IEnumerable<OnUpdate> onUpdateComponents
)
{
+2 -2
View File
@@ -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;
@@ -20,7 +20,7 @@ public class HideoutCraftQuestIdGenerator(
DatabaseServer _databaseServer,
LocaleService _localeService,
ItemHelper _itemHelper,
IEnumerable<OnLoad> _onLoadComponents
IEnumerable<IOnLoad> _onLoadComponents
)
{
private readonly HashSet<string> _blacklistedProductions =
+1 -1
View File
@@ -20,7 +20,7 @@ public class ItemTplGenerator(
LocaleService _localeService,
ItemHelper _itemHelper,
FileUtil _fileUtil,
IEnumerable<OnLoad> _onLoadComponents
IEnumerable<IOnLoad> _onLoadComponents
)
{
private readonly HashSet<string> collidedEnumKeys = [];