From e9072c1cb13c9009b0e87202736d8482f946eef6 Mon Sep 17 00:00:00 2001 From: CWX Date: Thu, 6 Feb 2025 00:06:11 +0000 Subject: [PATCH] make it so each mod example loads and does some logging. removed unused project --- ExampleMods/Mods/EditConfigs.cs | 19 +++++++++++++------ ExampleMods/Mods/EditDatabaseValues.cs | 18 +++++++++++------- ExampleMods/Mods/Logging.cs | 13 ++++++------- .../Mods/Override/ExampleOverrideMod.csproj | 13 ------------- .../Mods/{Override => }/WatermarkOverride.cs | 0 Server/ModDllLoader.cs | 4 ++++ 6 files changed, 34 insertions(+), 33 deletions(-) delete mode 100644 ExampleMods/Mods/Override/ExampleOverrideMod.csproj rename ExampleMods/Mods/{Override => }/WatermarkOverride.cs (100%) diff --git a/ExampleMods/Mods/EditConfigs.cs b/ExampleMods/Mods/EditConfigs.cs index 0dea17d9..df52229b 100644 --- a/ExampleMods/Mods/EditConfigs.cs +++ b/ExampleMods/Mods/EditConfigs.cs @@ -1,12 +1,14 @@ using SptCommon.Annotations; using Core.Models.Enums; +using Core.Models.External; using Core.Models.Spt.Config; +using Core.Models.Utils; using Core.Servers; namespace ExampleMods.Mods; [Injectable] -public class EditConfigs +public class EditConfigs : IPostDBLoadMod { private readonly ConfigServer _configServer; private readonly BotConfig _botConfig; @@ -17,11 +19,16 @@ public class EditConfigs private readonly QuestConfig _questConfig; private readonly PmcConfig _pmcConfig; + private readonly ISptLogger _logger; + // We access configs via ConfigServer public EditConfigs( - ConfigServer configServer) + ConfigServer configServer, + ISptLogger logger + ) { _configServer = configServer; + _logger = logger; // We get the bot config by calling GetConfig and passing the configs 'type' within the diamond brackets _botConfig = _configServer.GetConfig(); @@ -31,11 +38,9 @@ public class EditConfigs _pmcChatResponseConfig = _configServer.GetConfig(); _questConfig = _configServer.GetConfig(); _pmcConfig = _configServer.GetConfig(); - - Run(); } - - public void Run() + + public void PostDBLoad() { // Let's edit the weather config to make the season winter _weatherConfig.OverrideSeason = Season.WINTER; @@ -71,5 +76,7 @@ public class EditConfigs var assaultConversionSettings = factory4DayConversionSettings["assault"]; assaultConversionSettings.Min = 100; assaultConversionSettings.Max = 100; + + _logger.Success("Finished Editing Configs"); } } diff --git a/ExampleMods/Mods/EditDatabaseValues.cs b/ExampleMods/Mods/EditDatabaseValues.cs index 7acc8c12..40a6a732 100644 --- a/ExampleMods/Mods/EditDatabaseValues.cs +++ b/ExampleMods/Mods/EditDatabaseValues.cs @@ -1,25 +1,28 @@ using SptCommon.Annotations; using Core.Models.Eft.Hideout; using Core.Models.Enums; +using Core.Models.External; using Core.Models.Utils; using Core.Services; namespace ExampleMods.Mods; [Injectable] -public class EditDatabaseValues +public class EditDatabaseValues : IPostDBLoadMod { private readonly DatabaseService _databaseService; - + private readonly ISptLogger _logger; + public EditDatabaseValues( - DatabaseService databaseService) + DatabaseService databaseService, + ISptLogger logger + ) { _databaseService = databaseService; - - Run(); + _logger = logger; } - public void Run() + public void PostDBLoad() { // When SPT starts, it stores all the data found in (SPT_Data\Server\database) in memory // We can use the '_databaseService' we injected to access this data, this includes files from EFT and SPT @@ -38,6 +41,8 @@ public class EditDatabaseValues // Lets edit Customs EditCustoms(); + + _logger.Success("Finished Editing Database"); } private void EditGlobals() @@ -48,7 +53,6 @@ public class EditDatabaseValues // Let's edit the scav cooldown to be 1 second globals.Configuration.SavagePlayCooldown = 1; - // Now lets try editing the ragfair unlock level, lets get the ragfair settings first var ragfairSettings = globals.Configuration.RagFair; diff --git a/ExampleMods/Mods/Logging.cs b/ExampleMods/Mods/Logging.cs index 8f784473..4875d277 100644 --- a/ExampleMods/Mods/Logging.cs +++ b/ExampleMods/Mods/Logging.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Core.Models.External; using SptCommon.Annotations; using Core.Models.Logging; using Core.Models.Utils; @@ -10,22 +11,20 @@ using Core.Models.Utils; namespace ExampleMods.Mods; [Injectable] -public class Logging +public class Logging : IPostSptLoadMod { private readonly ISptLogger _logger; // Constructor - Inject a 'ISptLogger' with your mods Class in the diamond brackets public Logging( - ISptLogger logger) + ISptLogger logger + ) { // Save the logger we're injecting into a private variable that is scoped to this class (only this class has access to it) _logger = logger; - - // Not 100% necessary but let's split our code out into a method to make it easier to read - Run(); } - - public void Run() + + public void PostSptLoad() { // We can access the logger to assigned in the constructor here _logger.Success("This is a success message"); diff --git a/ExampleMods/Mods/Override/ExampleOverrideMod.csproj b/ExampleMods/Mods/Override/ExampleOverrideMod.csproj deleted file mode 100644 index 3cebe147..00000000 --- a/ExampleMods/Mods/Override/ExampleOverrideMod.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net9.0 - enable - enable - - - - - - - diff --git a/ExampleMods/Mods/Override/WatermarkOverride.cs b/ExampleMods/Mods/WatermarkOverride.cs similarity index 100% rename from ExampleMods/Mods/Override/WatermarkOverride.cs rename to ExampleMods/Mods/WatermarkOverride.cs diff --git a/Server/ModDllLoader.cs b/Server/ModDllLoader.cs index 52874643..b7f3e7fb 100644 --- a/Server/ModDllLoader.cs +++ b/Server/ModDllLoader.cs @@ -12,14 +12,18 @@ public class ModDllLoader Directory.CreateDirectory(ModPath); var mods = new List(); foreach (var file in Directory.GetFiles(ModPath, "*.dll", SearchOption.AllDirectories)) + { try { mods.Add(Assembly.LoadFile(Path.GetFullPath(file))); + var name = file.Split(Path.DirectorySeparatorChar); + Console.WriteLine($"Loaded {name[^1]}"); } catch (Exception e) { Console.WriteLine(e); } + } return mods; }