make it so each mod example loads and does some logging. removed unused project

This commit is contained in:
CWX
2025-02-06 00:06:11 +00:00
parent fee7dc1b89
commit e9072c1cb1
6 changed files with 34 additions and 33 deletions
+13 -6
View File
@@ -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<EditConfigs> _logger;
// We access configs via ConfigServer
public EditConfigs(
ConfigServer configServer)
ConfigServer configServer,
ISptLogger<EditConfigs> 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<BotConfig>();
@@ -31,11 +38,9 @@ public class EditConfigs
_pmcChatResponseConfig = _configServer.GetConfig<PmcChatResponse>();
_questConfig = _configServer.GetConfig<QuestConfig>();
_pmcConfig = _configServer.GetConfig<PmcConfig>();
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");
}
}
+11 -7
View File
@@ -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<EditDatabaseValues> _logger;
public EditDatabaseValues(
DatabaseService databaseService)
DatabaseService databaseService,
ISptLogger<EditDatabaseValues> 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;
+6 -7
View File
@@ -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<Logging> _logger;
// Constructor - Inject a 'ISptLogger' with your mods Class in the diamond brackets
public Logging(
ISptLogger<Logging> logger)
ISptLogger<Logging> 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");
@@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
</Project>
+4
View File
@@ -12,14 +12,18 @@ public class ModDllLoader
Directory.CreateDirectory(ModPath);
var mods = new List<Assembly>();
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;
}