From 774758796df50a6f8ed54f9f01291ca61867e04d Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Jan 2025 18:03:12 +0000 Subject: [PATCH] smol stuff --- Core/Annotations/Injectable.cs | 4 ++-- Core/Callbacks/DialogCallbacks.cs | 6 ++++-- Core/Callbacks/GameCallbacks.cs | 6 ++++-- Core/Callbacks/HandbookCallbacks.cs | 6 ++++-- Core/Callbacks/HttpCallbacks.cs | 4 ++-- Core/Callbacks/ModCallbacks.cs | 6 ++++-- Core/Callbacks/PresetCallbacks.cs | 6 ++++-- Core/Callbacks/RagfairCallbacks.cs | 6 ++++-- Core/Callbacks/SaveCallbacks.cs | 2 +- Core/Callbacks/TraderCallbacks.cs | 6 ++++-- Core/Context/ContextVariableType.cs | 5 +++-- Core/DI/OnLoadOrder.cs | 16 ++++++++++++++++ Core/DI/OnUpdateOrder.cs | 11 +++++++++++ Core/Models/External/IPostDBLoadMod.cs | 6 ++++++ Core/Models/External/IPostSptLoadMod.cs | 6 ++++++ Core/Models/External/IPreSptLoadMod.cs | 6 ++++++ Core/Utils/DatabaseImporter.cs | 2 +- Server/Program.cs | 2 +- 18 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 Core/DI/OnLoadOrder.cs create mode 100644 Core/DI/OnUpdateOrder.cs create mode 100644 Core/Models/External/IPostDBLoadMod.cs create mode 100644 Core/Models/External/IPostSptLoadMod.cs create mode 100644 Core/Models/External/IPreSptLoadMod.cs diff --git a/Core/Annotations/Injectable.cs b/Core/Annotations/Injectable.cs index b29b7af0..8bb82dc5 100644 --- a/Core/Annotations/Injectable.cs +++ b/Core/Annotations/Injectable.cs @@ -1,6 +1,6 @@ namespace Core.Annotations; -[AttributeUsage(AttributeTargets.Class)] +[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] public class Injectable(InjectionType injectionType = InjectionType.Scoped, Type? type = null, int typePriority = int.MaxValue) : Attribute { public InjectionType InjectionType { get; set; } = injectionType; @@ -13,4 +13,4 @@ public enum InjectionType Singleton, Transient, Scoped -} \ No newline at end of file +} diff --git a/Core/Callbacks/DialogCallbacks.cs b/Core/Callbacks/DialogCallbacks.cs index 8a1f507b..5d7af987 100644 --- a/Core/Callbacks/DialogCallbacks.cs +++ b/Core/Callbacks/DialogCallbacks.cs @@ -1,4 +1,5 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; using Core.Models.Eft.Common; using Core.Models.Eft.Common.Request; using Core.Models.Eft.Dialog; @@ -7,6 +8,7 @@ using Core.Models.Eft.Profile; namespace Core.Callbacks; +[Injectable(TypePriority = OnUpdateOrder.DialogCallbacks)] public class DialogCallbacks : OnUpdate { public DialogCallbacks() @@ -304,4 +306,4 @@ public class DialogCallbacks : OnUpdate { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/GameCallbacks.cs b/Core/Callbacks/GameCallbacks.cs index d6309616..dd262195 100644 --- a/Core/Callbacks/GameCallbacks.cs +++ b/Core/Callbacks/GameCallbacks.cs @@ -1,4 +1,5 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; using Core.Models.Eft.Common; using Core.Models.Eft.Common.Request; using Core.Models.Eft.Game; @@ -6,6 +7,7 @@ using Core.Models.Eft.HttpResponse; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.GameCallbacks)] public class GameCallbacks : OnLoad { public GameCallbacks() @@ -202,4 +204,4 @@ public class GameCallbacks : OnLoad { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/HandbookCallbacks.cs b/Core/Callbacks/HandbookCallbacks.cs index 2d72e78b..4fe5e97c 100644 --- a/Core/Callbacks/HandbookCallbacks.cs +++ b/Core/Callbacks/HandbookCallbacks.cs @@ -1,7 +1,9 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.HandbookCallbacks)] public class HandbookCallbacks : OnLoad { public HandbookCallbacks() @@ -17,4 +19,4 @@ public class HandbookCallbacks : OnLoad { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/HttpCallbacks.cs b/Core/Callbacks/HttpCallbacks.cs index 7aa6f9dc..ca07ada3 100644 --- a/Core/Callbacks/HttpCallbacks.cs +++ b/Core/Callbacks/HttpCallbacks.cs @@ -5,7 +5,7 @@ using Core.Servers; namespace Core.Callbacks; -[Injectable(InjectionType.Singleton, typePriority: 1)] +[Injectable(InjectionType.Singleton, typePriority: OnLoadOrder.HttpCallbacks)] public class HttpCallbacks : OnLoad { private readonly HttpServer _httpServer; @@ -31,4 +31,4 @@ public class HttpCallbacks : OnLoad { return ""; } -} \ No newline at end of file +} diff --git a/Core/Callbacks/ModCallbacks.cs b/Core/Callbacks/ModCallbacks.cs index 258b4a6f..6ed46c8d 100644 --- a/Core/Callbacks/ModCallbacks.cs +++ b/Core/Callbacks/ModCallbacks.cs @@ -1,7 +1,9 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.ModCallbacks)] public class ModCallbacks : OnLoad { public ModCallbacks() @@ -17,4 +19,4 @@ public class ModCallbacks : OnLoad { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/PresetCallbacks.cs b/Core/Callbacks/PresetCallbacks.cs index a19feb1c..d67286ae 100644 --- a/Core/Callbacks/PresetCallbacks.cs +++ b/Core/Callbacks/PresetCallbacks.cs @@ -1,7 +1,9 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.PresetCallbacks)] public class PresetCallbacks : OnLoad { public PresetCallbacks() @@ -17,4 +19,4 @@ public class PresetCallbacks : OnLoad { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/RagfairCallbacks.cs b/Core/Callbacks/RagfairCallbacks.cs index 9d7762be..bd3cd41a 100644 --- a/Core/Callbacks/RagfairCallbacks.cs +++ b/Core/Callbacks/RagfairCallbacks.cs @@ -1,4 +1,5 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; using Core.Models.Eft.Common; using Core.Models.Eft.HttpResponse; using Core.Models.Eft.ItemEvent; @@ -7,6 +8,7 @@ using Core.Models.Spt.Config; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.RagfairCallbacks)] public class RagfairCallbacks : OnLoad, OnUpdate { private RagfairConfig _ragfairConfig; @@ -140,4 +142,4 @@ public class RagfairCallbacks : OnLoad, OnUpdate { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Callbacks/SaveCallbacks.cs b/Core/Callbacks/SaveCallbacks.cs index 28d881b0..4d9d962a 100644 --- a/Core/Callbacks/SaveCallbacks.cs +++ b/Core/Callbacks/SaveCallbacks.cs @@ -7,7 +7,7 @@ using Core.Services; namespace Core.Callbacks; -[Injectable] +[Injectable(TypePriority = OnLoadOrder.SaveCallbacks)] public class SaveCallbacks : OnLoad, OnUpdate { protected SaveServer _saveServer; diff --git a/Core/Callbacks/TraderCallbacks.cs b/Core/Callbacks/TraderCallbacks.cs index 93c489c1..2e13b2ec 100644 --- a/Core/Callbacks/TraderCallbacks.cs +++ b/Core/Callbacks/TraderCallbacks.cs @@ -1,4 +1,5 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; using Core.Models.Eft.Common; using Core.Models.Eft.Common.Tables; using Core.Models.Eft.HttpResponse; @@ -6,6 +7,7 @@ using Core.Models.Spt.Config; namespace Core.Callbacks; +[Injectable(TypePriority = OnLoadOrder.TraderCallbacks)] public class TraderCallbacks : OnLoad, OnUpdate { public TraderCallbacks() @@ -78,4 +80,4 @@ public class TraderCallbacks : OnLoad, OnUpdate { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/Core/Context/ContextVariableType.cs b/Core/Context/ContextVariableType.cs index c6334931..878a0b3b 100644 --- a/Core/Context/ContextVariableType.cs +++ b/Core/Context/ContextVariableType.cs @@ -17,5 +17,6 @@ public enum ContextVariableType /** Data returned from client request object from endLocalRaid() */ TRANSIT_INFO = 5, - APP_BUILDER = 6 -} \ No newline at end of file + APP_BUILDER = 6, + LOADED_MOD_ASSEMBLIES = 6 +} diff --git a/Core/DI/OnLoadOrder.cs b/Core/DI/OnLoadOrder.cs new file mode 100644 index 00000000..9e9b75d7 --- /dev/null +++ b/Core/DI/OnLoadOrder.cs @@ -0,0 +1,16 @@ +namespace Core.DI; + +public static class OnLoadOrder +{ + public const int Database = 0; + public const int PostDBModLoader = 1; + public const int HandbookCallbacks = 2; + public const int HttpCallbacks = 3; + public const int PresetCallbacks = 4; + public const int SaveCallbacks = 5; + public const int TraderCallbacks = 6; + public const int RagfairPriceService = 7; + public const int RagfairCallbacks = 8; + public const int ModCallbacks = 9; + public const int GameCallbacks = 10; +} diff --git a/Core/DI/OnUpdateOrder.cs b/Core/DI/OnUpdateOrder.cs new file mode 100644 index 00000000..961b7aec --- /dev/null +++ b/Core/DI/OnUpdateOrder.cs @@ -0,0 +1,11 @@ +namespace Core.DI; + +public static class OnUpdateOrder +{ + public const int DialogCallbacks = 0; + public const int PostDBModLoader = 1; + public const int HandbookCallbacks = 2; + public const int HttpCallbacks = 3; + public const int PresetCallbacks = 4; + public const int SaveCallbacks = 5; +} diff --git a/Core/Models/External/IPostDBLoadMod.cs b/Core/Models/External/IPostDBLoadMod.cs new file mode 100644 index 00000000..c0c2adfc --- /dev/null +++ b/Core/Models/External/IPostDBLoadMod.cs @@ -0,0 +1,6 @@ +namespace Core.Models.External; + +public interface IPostDBLoadMod +{ + void PostDBLoad(); +} diff --git a/Core/Models/External/IPostSptLoadMod.cs b/Core/Models/External/IPostSptLoadMod.cs new file mode 100644 index 00000000..dbd05e7f --- /dev/null +++ b/Core/Models/External/IPostSptLoadMod.cs @@ -0,0 +1,6 @@ +namespace Core.Models.External; + +public interface IPostSptLoadMod +{ + void PostSptLoad(); +} diff --git a/Core/Models/External/IPreSptLoadMod.cs b/Core/Models/External/IPreSptLoadMod.cs new file mode 100644 index 00000000..f237299a --- /dev/null +++ b/Core/Models/External/IPreSptLoadMod.cs @@ -0,0 +1,6 @@ +namespace Core.Models.External; + +public interface IPreSptLoadMod +{ + void PreSptLoad(); +} diff --git a/Core/Utils/DatabaseImporter.cs b/Core/Utils/DatabaseImporter.cs index 9e4cd55b..a146b08d 100644 --- a/Core/Utils/DatabaseImporter.cs +++ b/Core/Utils/DatabaseImporter.cs @@ -10,7 +10,7 @@ using ILogger = Core.Models.Utils.ILogger; namespace Core.Utils; -[Injectable(InjectionType.Singleton, typePriority: 0)] +[Injectable(InjectionType.Singleton, TypePriority = OnLoadOrder.Database)] public class DatabaseImporter : OnLoad { private object hashedFile; diff --git a/Server/Program.cs b/Server/Program.cs index a74760ec..b0c2839c 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -18,13 +18,13 @@ public static class Program try { - var serviceProvider = builder.Services.BuildServiceProvider(); var watermark = serviceProvider.GetService(); watermark.Initialize(); // TODO: var preSptModLoader = serviceProvider.GetService(); var app = serviceProvider.GetService(); var appContext = serviceProvider.GetService(); + appContext.AddValue(ContextVariableType.LOADED_MOD_ASSEMBLIES, assemblies); appContext.AddValue(ContextVariableType.APP_BUILDER, builder); app.Load().Wait(); }