diff --git a/Libraries/Core/Helpers/ModHelper.cs b/Libraries/Core/Helpers/ModHelper.cs index 76f13aa4..d7cd78c4 100644 --- a/Libraries/Core/Helpers/ModHelper.cs +++ b/Libraries/Core/Helpers/ModHelper.cs @@ -24,13 +24,19 @@ namespace Core.Helpers return Path.GetDirectoryName(modAssembly.Location); } - public T GetFileFromModFolder(string pathToFile, string fileName) + public string GetRawFileData(string pathToFile, string fileName) + { + // Read the content of the config file as a string + return _fileUtil.ReadFile(Path.Combine(pathToFile, fileName)); + } + + public T GetJsonDataFromFile(string pathToFile, string fileName) { // Read the content of the config file as a string var rawContent = _fileUtil.ReadFile(Path.Combine(pathToFile, fileName)); // Take the string above and deserialise it into a file with a type (defined between the diamond brackets) - return _jsonUtil.DeserializeFromFile(rawContent); + return _jsonUtil.Deserialize(rawContent); } } } diff --git a/Libraries/Core/Models/Spt/Mod/SptMod.cs b/Libraries/Core/Models/Spt/Mod/SptMod.cs index ce471de2..cd82da89 100644 --- a/Libraries/Core/Models/Spt/Mod/SptMod.cs +++ b/Libraries/Core/Models/Spt/Mod/SptMod.cs @@ -5,15 +5,22 @@ namespace Core.Models.Spt.Mod; public class SptMod { - [JsonPropertyName("PackageJson")] + [JsonPropertyName("directory")] + public string Directory + { + get; + set; + } + + [JsonPropertyName("packageJson")] public PackageJsonData? PackageJson { get; set; } - [JsonPropertyName("Assembly")] - public Assembly? Assembly + [JsonPropertyName("assemblies")] + public List? Assemblies { get; set; diff --git a/Libraries/SptCommon/Semver/Implementations/SemanticVersioningSemVer.cs b/Libraries/SptCommon/Semver/Implementations/SemanticVersioningSemVer.cs index 908602a3..beb6f4dc 100644 --- a/Libraries/SptCommon/Semver/Implementations/SemanticVersioningSemVer.cs +++ b/Libraries/SptCommon/Semver/Implementations/SemanticVersioningSemVer.cs @@ -27,7 +27,7 @@ public class SemanticVersioningSemVer : ISemVer public bool Satisfies(string version, string testVersion) { - return Range.IsSatisfied(version, testVersion, true); + return Range.IsSatisfied(testVersion, version, true); } public bool AnySatisfies(string version, List testVersions) diff --git a/ModExamples/10CustomRoute/package.json b/ModExamples/10CustomRoute/package.json index caaf9248..92408068 100644 --- a/ModExamples/10CustomRoute/package.json +++ b/ModExamples/10CustomRoute/package.json @@ -1,13 +1,13 @@ { - "Name": "10CustomStaticRouter", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "10CustomStaticRouter", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/11RegisterClassesInDI/package.json b/ModExamples/11RegisterClassesInDI/package.json index 140fa45f..8c61a565 100644 --- a/ModExamples/11RegisterClassesInDI/package.json +++ b/ModExamples/11RegisterClassesInDI/package.json @@ -1,13 +1,13 @@ { - "Name": "11RegisterClassesInDI", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "11RegisterClassesInDI", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/12Bundle/package.json b/ModExamples/12Bundle/package.json index e48932f6..1244cf43 100644 --- a/ModExamples/12Bundle/package.json +++ b/ModExamples/12Bundle/package.json @@ -1,13 +1,13 @@ { - "Name": "12Bundle", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "12Bundle", + "version": "1.0.0", + "sptVersion": "~4.0", + "loadBefore": [], + "loadAfter": [], "IncompatibileMods": [], - "Url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", - "IsBundleMod": true, - "Author": "SPT", - "Contributors": [], - "Licence": "MIT" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": true, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/13.1AddTraderWithDynamicAssorts/AddTraderWithDynamicAssorts.cs b/ModExamples/13.1AddTraderWithDynamicAssorts/AddTraderWithDynamicAssorts.cs index 35dcd9e9..bc054e09 100644 --- a/ModExamples/13.1AddTraderWithDynamicAssorts/AddTraderWithDynamicAssorts.cs +++ b/ModExamples/13.1AddTraderWithDynamicAssorts/AddTraderWithDynamicAssorts.cs @@ -63,7 +63,7 @@ public class AddTraderWithDynamicAssorts : IPostDBLoadMod var pathToMod = _modHelper.GetAbsolutePathToModFolder(Assembly.GetExecutingAssembly()); var traderImagePath = Path.Combine(pathToMod, "db/cat.jpg"); - var traderBase = _modHelper.GetFileFromModFolder(pathToMod, "db/base.json"); + var traderBase = _modHelper.GetJsonDataFromFile(pathToMod, "db/base.json"); // Create helper class and use it to register our traders image/icon + set its stock refresh time var addTraderHelper = new AddTraderHelper(); @@ -112,7 +112,7 @@ public class AddTraderWithDynamicAssorts : IPostDBLoadMod .AddLoyaltyLevel(1) .Export(tables.Traders[traderBase.Id]); - // Add mp133 preset as a barter for mayonase + // Add mp133 preset as a barter for mayonase fluentAssortCreator .CreateComplexAssortItem(tables.Globals.ItemPresets["584148f2245977598f1ad387"].Items) // Weapon preset id comes from globals.json .AddStackCount(200) diff --git a/ModExamples/13.1AddTraderWithDynamicAssorts/package.json b/ModExamples/13.1AddTraderWithDynamicAssorts/package.json index b49687fa..e057ccda 100644 --- a/ModExamples/13.1AddTraderWithDynamicAssorts/package.json +++ b/ModExamples/13.1AddTraderWithDynamicAssorts/package.json @@ -1,13 +1,13 @@ { - "Name": "13.1AddTraderWithDynamicAssorts", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "13.1AddTraderWithDynamicAssorts", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/13AddTraderWithAssortJson/AddTraderWithAssortJson.cs b/ModExamples/13AddTraderWithAssortJson/AddTraderWithAssortJson.cs index 2f611957..a4765d32 100644 --- a/ModExamples/13AddTraderWithAssortJson/AddTraderWithAssortJson.cs +++ b/ModExamples/13AddTraderWithAssortJson/AddTraderWithAssortJson.cs @@ -49,9 +49,9 @@ public class AddTraderWithAssortJson : IPostDBLoadMod var pathToMod = _modHelper.GetAbsolutePathToModFolder(Assembly.GetExecutingAssembly()); var traderImagePath = Path.Combine(pathToMod, "db/cat.jpg"); - var traderBase = _modHelper.GetFileFromModFolder(pathToMod, "db/base.json"); + var traderBase = _modHelper.GetJsonDataFromFile(pathToMod, "db/base.json"); - var assort = _modHelper.GetFileFromModFolder(pathToMod, "db/assort.json"); + var assort = _modHelper.GetJsonDataFromFile(pathToMod, "db/assort.json"); // Create helper class and use it to register our traders image/icon + set its stock refresh time var addTraderHelper = new AddTraderHelper(); diff --git a/ModExamples/13AddTraderWithAssortJson/package.json b/ModExamples/13AddTraderWithAssortJson/package.json index 5adc350e..0d56d2d1 100644 --- a/ModExamples/13AddTraderWithAssortJson/package.json +++ b/ModExamples/13AddTraderWithAssortJson/package.json @@ -1,13 +1,13 @@ { - "Name": "1313AddTraderWithAssortJson", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "1313AddTraderWithAssortJson", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/14AfterDBLoadHook/package.json b/ModExamples/14AfterDBLoadHook/package.json index 9347e985..3d21524e 100644 --- a/ModExamples/14AfterDBLoadHook/package.json +++ b/ModExamples/14AfterDBLoadHook/package.json @@ -1,13 +1,13 @@ { - "Name": "14AfterDBLoadHook", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "14AfterDBLoadHook", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/15HttpListenerExample/package.json b/ModExamples/15HttpListenerExample/package.json index c71daffa..63c79d21 100644 --- a/ModExamples/15HttpListenerExample/package.json +++ b/ModExamples/15HttpListenerExample/package.json @@ -1,13 +1,13 @@ { - "Name": "15HttpListenerExample", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "15HttpListenerExample", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/18.1CustomItemServiceLootBox/package.json b/ModExamples/18.1CustomItemServiceLootBox/package.json index 64c28a96..7c475e6d 100644 --- a/ModExamples/18.1CustomItemServiceLootBox/package.json +++ b/ModExamples/18.1CustomItemServiceLootBox/package.json @@ -1,13 +1,13 @@ { - "Name": "18.1CustomItemServiceLootBox", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "18.1CustomItemServiceLootBox", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/18CustomItemService/package.json b/ModExamples/18CustomItemService/package.json index 01265135..c539bb7e 100644 --- a/ModExamples/18CustomItemService/package.json +++ b/ModExamples/18CustomItemService/package.json @@ -1,13 +1,13 @@ { - "Name": "18CustomItemService", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "18CustomItemService", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/1Logging/package.json b/ModExamples/1Logging/package.json index 1dd61d15..bb8023fe 100644 --- a/ModExamples/1Logging/package.json +++ b/ModExamples/1Logging/package.json @@ -1,14 +1,14 @@ { - "Name": "1Logging", - "Author": "SPT", - "Contributors": [], - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], - "IncompatibleMods": [], - "Dependencies": [], - "Url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", - "IsBundleMod": false, - "Licence": "MIT" + "name": "1Logging", + "author": "SPT", + "contributors": [], + "version": "1.0.0", + "sptVersion": "~4.0", + "loadBefore": [], + "loadAfter": [], + "incompatibilities": [], + "dependencies": [], + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "licence": "MIT" } diff --git a/ModExamples/20CustomChatBot/package.json b/ModExamples/20CustomChatBot/package.json index 22bfbf97..f76d93f5 100644 --- a/ModExamples/20CustomChatBot/package.json +++ b/ModExamples/20CustomChatBot/package.json @@ -1,13 +1,13 @@ { - "Name": "20CustomChatBot", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "20CustomChatBot", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/21CustomCommandoCommand/package.json b/ModExamples/21CustomCommandoCommand/package.json index d2034199..45dbe823 100644 --- a/ModExamples/21CustomCommandoCommand/package.json +++ b/ModExamples/21CustomCommandoCommand/package.json @@ -1,13 +1,13 @@ { - "Name": "21CustomCommandoCommand", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "21CustomCommandoCommand", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/22CustomSptCommand/package.json b/ModExamples/22CustomSptCommand/package.json index 28d9f492..2469dae6 100644 --- a/ModExamples/22CustomSptCommand/package.json +++ b/ModExamples/22CustomSptCommand/package.json @@ -1,13 +1,13 @@ { - "Name": "22CustomSptCommand", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "22CustomSptCommand", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/23CustomAbstractChatBot/package.json b/ModExamples/23CustomAbstractChatBot/package.json index c1441df3..28d95078 100644 --- a/ModExamples/23CustomAbstractChatBot/package.json +++ b/ModExamples/23CustomAbstractChatBot/package.json @@ -1,13 +1,13 @@ { - "Name": "23CustomAbstractChatBot", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "23CustomAbstractChatBot", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/24Websocket/package.json b/ModExamples/24Websocket/package.json index 8fb13a94..cd57a504 100644 --- a/ModExamples/24Websocket/package.json +++ b/ModExamples/24Websocket/package.json @@ -1,13 +1,13 @@ { - "Name": "24Websocket", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "24Websocket", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/2EditDatabase/package.json b/ModExamples/2EditDatabase/package.json index af514afd..e448782b 100644 --- a/ModExamples/2EditDatabase/package.json +++ b/ModExamples/2EditDatabase/package.json @@ -1,13 +1,13 @@ { - "Name": "2EditDatabase", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "2EditDatabase", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/3EditSptConfig/EditConfigs.cs b/ModExamples/3EditSptConfig/EditConfigs.cs index b92d079f..4b09834d 100644 --- a/ModExamples/3EditSptConfig/EditConfigs.cs +++ b/ModExamples/3EditSptConfig/EditConfigs.cs @@ -71,16 +71,6 @@ public class EditConfigs : IPostDBLoadMod // Let's disable loot on scavs _botConfig.DisableLootOnBotTypes.Add("assault"); - // Let's make the conversion rate of scavs to pmcs 100% on factory day - var factory4DayConversionSettings = _pmcConfig.ConvertIntoPmcChance["factory4_day"]; - - // We get assault bot settings for factory day - var assaultConversionSettings = factory4DayConversionSettings["assault"]; - - // Set min and max to 100% - assaultConversionSettings.Min = 100; - assaultConversionSettings.Max = 100; - _logger.Success("Finished Editing Configs"); } } diff --git a/ModExamples/3EditSptConfig/package.json b/ModExamples/3EditSptConfig/package.json index b59d90bb..f355c9ac 100644 --- a/ModExamples/3EditSptConfig/package.json +++ b/ModExamples/3EditSptConfig/package.json @@ -1,13 +1,13 @@ { - "Name": "3EditSptConfig", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "3EditSptConfig", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/4ReadCustomJson5Config/4ReadCustomJson5Config.csproj b/ModExamples/4ReadCustomJson5Config/4ReadCustomJson5Config.csproj index e570ba66..bdeaf779 100644 --- a/ModExamples/4ReadCustomJson5Config/4ReadCustomJson5Config.csproj +++ b/ModExamples/4ReadCustomJson5Config/4ReadCustomJson5Config.csproj @@ -10,8 +10,17 @@ bin\$(Configuration)\$(ProjectName)\$(AssemblyName)-$(Version)\ false + true + true + + + true + true + true + + @@ -33,4 +42,10 @@ false + + + + Always + + diff --git a/ModExamples/4ReadCustomJson5Config/ReadJson5Config.cs b/ModExamples/4ReadCustomJson5Config/ReadJson5Config.cs index fb5a5e0e..b5523d5a 100644 --- a/ModExamples/4ReadCustomJson5Config/ReadJson5Config.cs +++ b/ModExamples/4ReadCustomJson5Config/ReadJson5Config.cs @@ -2,6 +2,7 @@ using System.Reflection; using Core.Models.External; using Core.Models.Utils; +using fastJSON5; using SptCommon.Annotations; namespace _4ReadCustomJson5Config @@ -24,8 +25,8 @@ namespace _4ReadCustomJson5Config { var pathToMod = _modHelper.GetAbsolutePathToModFolder(Assembly.GetExecutingAssembly()); - // TODO - fix/implement - var json5Config = _modHelper.GetFileFromModFolder(pathToMod, "config.json5"); + // To use JSON5, you will have to find and provide your own JSON5 library to decode it + var json5Config = JSON5.ToObject(_modHelper.GetRawFileData(pathToMod, "config.json5")); _logger.Success($"Read property: 'ExampleProperty' from config with value: {json5Config.ExampleProperty}"); } diff --git a/ModExamples/4ReadCustomJson5Config/package.json b/ModExamples/4ReadCustomJson5Config/package.json index 59eafcd4..4277e6ef 100644 --- a/ModExamples/4ReadCustomJson5Config/package.json +++ b/ModExamples/4ReadCustomJson5Config/package.json @@ -1,13 +1,19 @@ { - "Name": "4ReadCustomJson5Config", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "4ReadCustomJson5Config", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT", + "dependencies": [ + { + "name": "fastJSON5", + "version": "1.0.4" + } + ] } diff --git a/ModExamples/5ReadCustomJsonConfig/ReadJsonConfig.cs b/ModExamples/5ReadCustomJsonConfig/ReadJsonConfig.cs index 746e3834..d10b4110 100644 --- a/ModExamples/5ReadCustomJsonConfig/ReadJsonConfig.cs +++ b/ModExamples/5ReadCustomJsonConfig/ReadJsonConfig.cs @@ -27,7 +27,7 @@ namespace _5ReadCustomJsonConfig var pathToMod = _modHelper.GetAbsolutePathToModFolder(Assembly.GetExecutingAssembly()); // We give the path to the mod folder and the file we want to get, giving us the config, supply the files 'type' between the diamond brackets - var config = _modHelper.GetFileFromModFolder(pathToMod, "config.json"); + var config = _modHelper.GetJsonDataFromFile(pathToMod, "config.json"); _logger.Success($"Read property: 'ExampleProperty' from config with value: {config.ExampleProperty}"); } diff --git a/ModExamples/5ReadCustomJsonConfig/package.json b/ModExamples/5ReadCustomJsonConfig/package.json index cb56b6b3..7e825910 100644 --- a/ModExamples/5ReadCustomJsonConfig/package.json +++ b/ModExamples/5ReadCustomJsonConfig/package.json @@ -1,13 +1,13 @@ { - "Name": "5ReadCustomConfig", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "5ReadCustomConfig", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/6OverrideMethod/package.json b/ModExamples/6OverrideMethod/package.json index f1de0234..64086d4d 100644 --- a/ModExamples/6OverrideMethod/package.json +++ b/ModExamples/6OverrideMethod/package.json @@ -1,13 +1,13 @@ { - "Name": "6OverrideMethod", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "6OverrideMethod", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/7UseMultipleClasses/package.json b/ModExamples/7UseMultipleClasses/package.json index 51711196..70924f53 100644 --- a/ModExamples/7UseMultipleClasses/package.json +++ b/ModExamples/7UseMultipleClasses/package.json @@ -1,13 +1,13 @@ { - "Name": "7UseMultipleClasses", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "7UseMultipleClasses", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/8OnLoad/package.json b/ModExamples/8OnLoad/package.json index 8394e361..f7a96e21 100644 --- a/ModExamples/8OnLoad/package.json +++ b/ModExamples/8OnLoad/package.json @@ -1,13 +1,13 @@ { - "Name": "8OnLoadExample", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "name": "8OnLoadExample", + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/9OnUpdate/package.json b/ModExamples/9OnUpdate/package.json index 1b1aa46f..2b7afe81 100644 --- a/ModExamples/9OnUpdate/package.json +++ b/ModExamples/9OnUpdate/package.json @@ -1,13 +1,13 @@ { - "Name": "9OnUpdateExample", - "Version": "1.0.0", - "SptVersion": "~4.0", - "LoadBefore": [], - "LoadAfter": [], + "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" + "url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "isBundleMod": false, + "author": "SPT", + "contributors": [], + "licence": "MIT" } diff --git a/ModExamples/TempReferences/Core.dll b/ModExamples/TempReferences/Core.dll index 9c5b0954..ed872f3e 100644 Binary files a/ModExamples/TempReferences/Core.dll and b/ModExamples/TempReferences/Core.dll differ diff --git a/ModExamples/TempReferences/SptCommon.dll b/ModExamples/TempReferences/SptCommon.dll index f5d35fee..10ce74b7 100644 Binary files a/ModExamples/TempReferences/SptCommon.dll and b/ModExamples/TempReferences/SptCommon.dll differ diff --git a/ModExamples/TempReferences/SptDependencyInjection.dll b/ModExamples/TempReferences/SptDependencyInjection.dll index d5b647fe..ce2fee3b 100644 Binary files a/ModExamples/TempReferences/SptDependencyInjection.dll and b/ModExamples/TempReferences/SptDependencyInjection.dll differ diff --git a/Server/Modding/ModDllLoader.cs b/Server/Modding/ModDllLoader.cs index a5eeeb85..1423eaa1 100644 --- a/Server/Modding/ModDllLoader.cs +++ b/Server/Modding/ModDllLoader.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.Loader; using System.Text.Json; using Core.Models.Spt.Mod; @@ -48,7 +49,11 @@ public class ModDllLoader /// SptMod private static SptMod LoadMod(string path) { - var result = new SptMod(); + var result = new SptMod + { + Directory = path, + Assemblies = [] + }; var asmCount = 0; var packCount = 0; foreach (var file in new DirectoryInfo(path).GetFiles()) // only search top level @@ -69,12 +74,7 @@ public class ModDllLoader if (file.Extension.ToLower() == ".dll") { asmCount++; - - result.Assembly = Assembly.LoadFile(Path.GetFullPath(file.FullName)); - if (asmCount > 1) - { - throw new Exception($"More than one Assembly found in: {path}"); - } + result.Assemblies.Add(AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(file.FullName))); } } @@ -100,7 +100,7 @@ public class ModDllLoader throw new Exception($"The package.json file for {path} is missing one of these properties: name, author, licence, version or sptVersion"); } - if (result.Assembly is not null && result.PackageJson is not null) + if (result.Assemblies is not null && result.PackageJson is not null) { Console.WriteLine($"Loaded: {result.PackageJson.Name} Version: {result.PackageJson.Version} by: {result.PackageJson.Author}"); } diff --git a/Server/Modding/ModValidator.cs b/Server/Modding/ModValidator.cs index 59c59f41..de38d798 100644 --- a/Server/Modding/ModValidator.cs +++ b/Server/Modding/ModValidator.cs @@ -377,9 +377,9 @@ public class ModValidator( var modIsCalledUser = modName.ToLower() == "user"; var modIsCalledSrc = modName.ToLower() == "src"; var modIsCalledDb = modName.ToLower() == "db"; - var hasBepinExFolderStructure = fileUtil.DirectoryExists($"{modPath}/plugins"); - var containsJs = fileUtil.GetFiles(modPath, true, "*.js").Count > 0; - var containsTs = fileUtil.GetFiles(modPath, true, "*.ts").Count > 0; + var hasBepinExFolderStructure = fileUtil.DirectoryExists($"{mod.Directory}/plugins"); + var containsJs = fileUtil.GetFiles(mod.Directory, true, "*.js").Count > 0; + var containsTs = fileUtil.GetFiles(mod.Directory, true, "*.ts").Count > 0; if (modIsCalledSrc || modIsCalledDb || modIsCalledUser) { diff --git a/Server/Program.cs b/Server/Program.cs index 01638bb0..25516ecb 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -31,12 +31,12 @@ public static class Program // validate and sort mods, this will also discard any mods that are invalid var sortedLoadedMods = ValidateMods(mods); // for harmony we use the original list, as some mods may only be bepinex patches only - HarmonyBootstrapper.LoadAllPatches(mods.Select(asm => asm.Assembly).ToList()); + HarmonyBootstrapper.LoadAllPatches(mods.SelectMany(asm => asm.Assemblies).ToList()); // register SPT components DependencyInjectionRegistrator.RegisterSptComponents(typeof(Program).Assembly, typeof(App).Assembly, builder.Services); // register mod components from the filtered list - DependencyInjectionRegistrator.RegisterModOverrideComponents(builder.Services, sortedLoadedMods.Select(a => a.Assembly).ToList()); + DependencyInjectionRegistrator.RegisterModOverrideComponents(builder.Services, sortedLoadedMods.SelectMany(a => a.Assemblies).ToList()); var logger = new SerilogLoggerProvider(registeredLogger).CreateLogger("Server"); try { diff --git a/Server/Server.csproj b/Server/Server.csproj index 40536f93..9e24d99a 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -7,6 +7,7 @@ enable enable Exe + 4.0.0