Renamed "OnUpdate" interface

Added OnUpdate example mod

Expanded `OnUpdateOrder` options
This commit is contained in:
Chomp
2025-02-08 12:29:56 +00:00
parent ac7b2daeba
commit c9c1af653b
12 changed files with 70 additions and 22 deletions
@@ -2,17 +2,17 @@
using Core.Models.Utils;
using SptCommon.Annotations;
namespace ExampleMods.Mods._8AddOnLoad
namespace ExampleMods.Mods._8OnLoad
{
// 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
[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.PostSptDatabase)] // Can also give an int value for fine-grained control
[Injectable(InjectableTypeOverride = typeof(OnLoadExample))]
public class OnLoadExample : IOnLoad // Must implement the IOnLoad interface
{
private readonly ISptLogger<AddOnLoad> _logger;
private readonly ISptLogger<OnLoadExample> _logger;
public AddOnLoad(
ISptLogger<AddOnLoad> logger)
public OnLoadExample(
ISptLogger<OnLoadExample> logger)
{
_logger = logger;
}
@@ -1,5 +1,5 @@
{
"Name": "8AddOnLoad",
"Name": "8OnLoadExample",
"Version": "1.0.0",
"SptVersion": "~4.0",
"LoadBefore": [],
@@ -0,0 +1,33 @@
using Core.DI;
using Core.Models.Utils;
using SptCommon.Annotations;
namespace ExampleMods.Mods._9OnUpdate
{
// Flag class as being OnLoad and give it a load priority, check `OnLoadOrder` for list of possible choices
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.PostSptUpdate)] // Can also give it an int value for more fine-grained control
[Injectable(InjectableTypeOverride = typeof(OnUpdateExample))]
public class OnUpdateExample : IOnUpdate // Must implement the IOnUpdate interface
{
private readonly ISptLogger<OnUpdateExample> _logger;
public OnUpdateExample(
ISptLogger<OnUpdateExample> logger)
{
_logger = logger;
}
public bool OnUpdate(long timeSinceLastRun)
{
// Can do work here
_logger.Success($"Mod running update after SPT updates have run!");
return true; // Return true for a success, false for failure
}
public string GetRoute()
{
return "mod-update-example";
}
}
}
+13
View File
@@ -0,0 +1,13 @@
{
"Name": "9OnUpdateExample",
"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"
}
@@ -8,7 +8,7 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.DialogueCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.DialogueCallbacks)]
[Injectable(InjectableTypeOverride = typeof(DialogueCallbacks))]
public class DialogueCallbacks(
HashUtil _hashUtil,
@@ -16,7 +16,7 @@ public class DialogueCallbacks(
HttpResponseUtil _httpResponseUtil,
DialogueController _dialogueController
)
: OnUpdate
: IOnUpdate
{
public bool OnUpdate(long timeSinceLastRun)
{
+2 -2
View File
@@ -9,12 +9,12 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.HideoutCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.HideoutCallbacks)]
[Injectable(InjectableTypeOverride = typeof(HideoutCallbacks))]
public class HideoutCallbacks(
HideoutController _hideoutController,
ConfigServer _configServer
) : OnUpdate
) : IOnUpdate
{
private readonly HideoutConfig _hideoutConfig = _configServer.GetConfig<HideoutConfig>();
@@ -11,7 +11,7 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.InsuranceCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.InsuranceCallbacks)]
[Injectable(InjectableTypeOverride = typeof(InsuranceCallbacks))]
public class InsuranceCallbacks(
InsuranceController _insuranceController,
@@ -19,7 +19,7 @@ public class InsuranceCallbacks(
HttpResponseUtil _httpResponseUtil,
ConfigServer _configServer
)
: OnUpdate
: IOnUpdate
{
private readonly InsuranceConfig _insuranceConfig = _configServer.GetConfig<InsuranceConfig>();
+2 -2
View File
@@ -12,7 +12,7 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.RagfairCallbacks)]
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.RagfairCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.RagfairCallbacks)]
[Injectable(InjectableTypeOverride = typeof(RagfairCallbacks))]
public class RagfairCallbacks(
HttpResponseUtil _httpResponseUtil,
@@ -21,7 +21,7 @@ public class RagfairCallbacks(
RagfairTaxService _ragfairTaxService,
RagfairPriceService _ragfairPriceService,
ConfigServer _configServer
) : IOnLoad, OnUpdate
) : IOnLoad, IOnUpdate
{
private readonly RagfairConfig _ragfairConfig = _configServer.GetConfig<RagfairConfig>();
+2 -2
View File
@@ -7,13 +7,13 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.SaveCallbacks)]
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.SaveCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.SaveCallbacks)]
public class SaveCallbacks(
SaveServer _saveServer,
ConfigServer _configServer,
BackupService _backupService
)
: IOnLoad, OnUpdate
: IOnLoad, IOnUpdate
{
private readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
+2 -2
View File
@@ -9,13 +9,13 @@ using SptCommon.Annotations;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(IOnLoad), TypePriority = OnLoadOrder.TraderCallbacks)]
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.TraderCallbacks)]
[Injectable(InjectableTypeOverride = typeof(IOnUpdate), TypePriority = OnUpdateOrder.TraderCallbacks)]
[Injectable(InjectableTypeOverride = typeof(TraderCallbacks))]
public class TraderCallbacks(
HttpResponseUtil _httpResponseUtil,
TraderController _traderController,
ConfigServer _configServer
) : IOnLoad, OnUpdate
) : IOnLoad, IOnUpdate
{
private readonly TraderConfig _traderConfig = _configServer.GetConfig<TraderConfig>();
@@ -1,6 +1,6 @@
namespace Core.DI;
public interface OnUpdate
public interface IOnUpdate
{
bool OnUpdate(long timeSinceLastRun);
string GetRoute();
+3 -1
View File
@@ -2,10 +2,12 @@ namespace Core.DI;
public static class OnUpdateOrder
{
public const int DialogueCallbacks = 0;
public const int PreSptUpdate = 0;
public const int DialogueCallbacks = 1;
public const int HideoutCallbacks = 100;
public const int TraderCallbacks = 200;
public const int RagfairCallbacks = 300;
public const int InsuranceCallbacks = 400;
public const int SaveCallbacks = 500;
public const int PostSptUpdate = 9999;
}