diff --git a/Directory.Build.props b/Directory.Build.props index 9957a57..fffee4e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,14 +36,10 @@ - - - - @@ -56,4 +52,10 @@ @(Swinfo -> '%(source)') + + + + + + \ No newline at end of file diff --git a/PatchManager.nuspec b/PatchManager.nuspec new file mode 100644 index 0000000..1571220 --- /dev/null +++ b/PatchManager.nuspec @@ -0,0 +1,24 @@ + + + + $id$ + $version$ + $authors$ + false + https://raw.githubusercontent.com/KSP2Community/PatchManager/main/LICENSE + $description$ + ksp ksp2 mod patching library + https://github.com/KSP2Community/PatchManager/wiki + + README.md + + + + + + + + + + + \ No newline at end of file diff --git a/StandalonePatchTester/Program.cs b/StandalonePatchTester/Program.cs index 23f82e0..f760b89 100644 --- a/StandalonePatchTester/Program.cs +++ b/StandalonePatchTester/Program.cs @@ -42,7 +42,7 @@ void AddGenerator(ITextAssetGenerator generator) } - var universe = new Universe(Add, Console.WriteLine, Console.WriteLine, AddGenerator); + var universe = new Universe(Add, Console.WriteLine, Console.WriteLine, AddGenerator, new()); universe.LoadPatchesInDirectory(new DirectoryInfo("patches"), "test"); Console.WriteLine($"{universe.AllLibraries.Count} libraries loaded!"); diff --git a/StandalonePatchTester/StandalonePatchTester.csproj b/StandalonePatchTester/StandalonePatchTester.csproj index a302f04..c61cf9f 100644 --- a/StandalonePatchTester/StandalonePatchTester.csproj +++ b/StandalonePatchTester/StandalonePatchTester.csproj @@ -8,6 +8,7 @@ enable $(SolutionDir)/build/bin/testing/$(MSBuildProjectName) $(SolutionDir)build/obj/testing/$(MSBuildProjectName) + $(NoWarn);MSB3539 diff --git a/plugin_template/swinfo.json b/plugin_template/swinfo.json index a1e354c..3840bdf 100644 --- a/plugin_template/swinfo.json +++ b/plugin_template/swinfo.json @@ -1,21 +1,21 @@ { "spec": "1.3", "mod_id": "PatchManager", - "author": "munix", + "author": "KSP2 Community", "name": "Patch Manager", "description": "A mod for generic patching needs similar to KSP 1's Module Manager.", - "source": "https://github.com/jan-bures/PatchManager", - "version": "0.1.0", - "version_check": "https://raw.githubusercontent.com/jan-bures/PatchManager/main/plugin_template/swinfo.json", + "source": "https://github.com/KSP2Community/PatchManager", + "version": "0.1.1", + "version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json", "ksp2_version": { - "min": "0.1.3", + "min": "0.1.4", "max": "*" }, "dependencies": [ { "id": "com.github.x606.spacewarp", "version": { - "min": "1.3.0", + "min": "1.4.2", "max": "*" } } diff --git a/src/PatchManager.Core/Assets/PatchingManager.cs b/src/PatchManager.Core/Assets/PatchingManager.cs index 717c14f..4611551 100644 --- a/src/PatchManager.Core/Assets/PatchingManager.cs +++ b/src/PatchManager.Core/Assets/PatchingManager.cs @@ -1,5 +1,5 @@ using System.Collections; -using HarmonyLib; +using System.Reflection; using KSP.Game; using KSP.Game.Flow; using PatchManager.Core.Cache; @@ -9,10 +9,10 @@ using PatchManager.SassyPatching.Execution; using PatchManager.Shared; using PatchManager.Shared.Interfaces; +using SpaceWarp.API.Mods; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; -using Coroutine = MoonSharp.Interpreter.Coroutine; namespace PatchManager.Core.Assets; @@ -22,8 +22,6 @@ internal static class PatchingManager private static readonly List Generators = new(); private static Universe _universe; - - private static readonly PatchHashes CurrentPatchHashes = PatchHashes.CreateDefault(); private static int _initialLibraryCount; @@ -32,7 +30,14 @@ internal static class PatchingManager internal static int TotalPatchCount; public static void GenerateUniverse() { - _universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo,RegisterGenerator); + // Need to do some reflection here as I forgot to make something public :3 + var manager = typeof(BaseSpaceWarpPlugin).Assembly.GetTypes() + .FirstOrDefault(type => type.Name == "SpaceWarpManager")!; + var field = manager.GetFields(BindingFlags.Static|BindingFlags.NonPublic) + .FirstOrDefault(x => x.Name == "AllPlugins")!; + var plugins = (List)field.GetValue(null); + _universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo, RegisterGenerator, + plugins.Select(x => x.Guid).ToList()); _initialLibraryCount = _universe.AllLibraries.Count; } @@ -184,7 +189,7 @@ private static AsyncOperationHandle> RebuildCache(string label) { Label = name, ArchiveFilename = archiveFilename, - Assets = new List { name } + Assets = new List { name } }); } createdAsset.Clear(); @@ -269,7 +274,7 @@ public static void CreateNewAssets(Action resolve, Action reject) { var text = generator.Create(out var label, out var name); Logging.LogInfo($"Generated an asset with the label {label}, and name {name}:\n{text}"); - + if (!_createdAssets.ContainsKey(label)) _createdAssets[label] = new List<(string name, string text)>(); _createdAssets[label].Add((name, text)); @@ -285,8 +290,8 @@ public static void CreateNewAssets(Action resolve, Action reject) public static void RebuildAllCache(Action resolve, Action reject) { - - + + var distinctKeys = _universe.LoadedLabels.Concat(_createdAssets.Keys).Distinct().ToList(); LoadingBarPatch.InjectPatchManagerTips = true; @@ -326,7 +331,7 @@ bool killLoadingBarTips { while (!handle.IsDone) { - // "Shuffle" it + // "Shuffle" it GameManager.Instance.Game.UI.LoadingBar.ShuffleLoadingTip(); yield return null; } diff --git a/src/PatchManager.Core/GlobalUsings.cs b/src/PatchManager.Core/GlobalUsings.cs deleted file mode 100644 index 8148803..0000000 --- a/src/PatchManager.Core/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using static PatchManager.Shared.Extensions; \ No newline at end of file diff --git a/src/PatchManager.Core/PatchManager.Core.csproj b/src/PatchManager.Core/PatchManager.Core.csproj index 2b0ea9a..4799e5f 100644 --- a/src/PatchManager.Core/PatchManager.Core.csproj +++ b/src/PatchManager.Core/PatchManager.Core.csproj @@ -3,7 +3,7 @@ - + diff --git a/src/PatchManager.Generic/SassyPatching/Rulesets/JsonRuleset.cs b/src/PatchManager.Generic/SassyPatching/Rulesets/JsonRuleset.cs index c8f68f4..7f8af96 100644 --- a/src/PatchManager.Generic/SassyPatching/Rulesets/JsonRuleset.cs +++ b/src/PatchManager.Generic/SassyPatching/Rulesets/JsonRuleset.cs @@ -26,6 +26,7 @@ public ISelectable ConvertToSelectable(string type, string name, string jsonData return new JTokenSelectable(() => { }, JToken.Parse(jsonData), name, type); } + /// public INewAsset CreateNew(List dataValues) { var label = dataValues[0].String; diff --git a/src/PatchManager.Parts/PartsModule.cs b/src/PatchManager.Parts/PartsModule.cs index 5f696fa..1f8d933 100644 --- a/src/PatchManager.Parts/PartsModule.cs +++ b/src/PatchManager.Parts/PartsModule.cs @@ -1,7 +1,12 @@ -using PatchManager.Shared.Modules; +using JetBrains.Annotations; +using PatchManager.Shared.Modules; namespace PatchManager.Parts; +/// +/// Part patching module. +/// +[UsedImplicitly] public class PartsModule : BaseModule { } \ No newline at end of file diff --git a/src/PatchManager.Parts/PartsUtilities.cs b/src/PatchManager.Parts/PartsUtilities.cs index 860e9e7..e8ab3e8 100644 --- a/src/PatchManager.Parts/PartsUtilities.cs +++ b/src/PatchManager.Parts/PartsUtilities.cs @@ -3,9 +3,11 @@ namespace PatchManager.Parts; +/// +/// Utilities for parts patching. +/// public static class PartsUtilities { - private static Dictionary _componentModules; private static void BuildComponentModuleDictionary() @@ -35,7 +37,7 @@ private static void BuildComponentModuleDictionary() } } } - + internal static IReadOnlyDictionary ComponentModules { get @@ -70,7 +72,7 @@ private static void BuildDataModuleDictionary() } } } - + internal static IReadOnlyDictionary DataModules { get diff --git a/src/PatchManager.Parts/Rulesets/PartsRuleset.cs b/src/PatchManager.Parts/Rulesets/PartsRuleset.cs index 195c92b..e30d1d6 100644 --- a/src/PatchManager.Parts/Rulesets/PartsRuleset.cs +++ b/src/PatchManager.Parts/Rulesets/PartsRuleset.cs @@ -26,5 +26,6 @@ public ISelectable ConvertToSelectable(string type, string name, string jsonData return new PartSelectable(jsonData); } + /// public INewAsset CreateNew(List dataValues) => throw new NotImplementedException(); } \ No newline at end of file diff --git a/src/PatchManager.Parts/Selectables/ModuleSelectable.cs b/src/PatchManager.Parts/Selectables/ModuleSelectable.cs index 54c332b..97f3423 100644 --- a/src/PatchManager.Parts/Selectables/ModuleSelectable.cs +++ b/src/PatchManager.Parts/Selectables/ModuleSelectable.cs @@ -96,5 +96,6 @@ public override ISelectable AddElement(string elementType) /// public override string Serialize() => _jToken.ToString(); + /// public override DataValue GetValue() => DataValue.FromJToken(_jToken); } \ No newline at end of file diff --git a/src/PatchManager.Parts/Selectables/PartSelectable.cs b/src/PatchManager.Parts/Selectables/PartSelectable.cs index 043c1ab..23e2322 100644 --- a/src/PatchManager.Parts/Selectables/PartSelectable.cs +++ b/src/PatchManager.Parts/Selectables/PartSelectable.cs @@ -119,5 +119,6 @@ public override ISelectable AddElement(string elementType) /// public override string Serialize() => _modified ? _deleted ? "" : JObject.ToString() : _originalData; + /// public override DataValue GetValue() => OpenModification().Get(); } \ No newline at end of file diff --git a/src/PatchManager.Parts/Selectables/ResourceContainersSelectable.cs b/src/PatchManager.Parts/Selectables/ResourceContainersSelectable.cs index 4cb649f..3cebab9 100644 --- a/src/PatchManager.Parts/Selectables/ResourceContainersSelectable.cs +++ b/src/PatchManager.Parts/Selectables/ResourceContainersSelectable.cs @@ -11,7 +11,7 @@ public sealed class ResourceContainersSelectable : BaseSelectable { private readonly JArray _containers; private PartSelectable _selectable; - + internal ResourceContainersSelectable(JArray containers, PartSelectable selectable) { _containers = containers; @@ -67,5 +67,6 @@ public override ISelectable AddElement(string elementType) /// public override string Serialize() => _containers.ToString(); + /// public override DataValue GetValue() => DataValue.FromJToken(_containers); } \ No newline at end of file diff --git a/src/PatchManager.Resources/ResourcesModule.cs b/src/PatchManager.Resources/ResourcesModule.cs index d037cbe..c778623 100644 --- a/src/PatchManager.Resources/ResourcesModule.cs +++ b/src/PatchManager.Resources/ResourcesModule.cs @@ -1,7 +1,12 @@ -using PatchManager.Shared.Modules; +using JetBrains.Annotations; +using PatchManager.Shared.Modules; namespace PatchManager.Resources; +/// +/// Resource patching module. +/// +[UsedImplicitly] public class ResourcesModule : BaseModule { } \ No newline at end of file diff --git a/src/PatchManager.Resources/Selectables/RecipeSelectable.cs b/src/PatchManager.Resources/Selectables/RecipeSelectable.cs index 8041a6a..fbb9b46 100644 --- a/src/PatchManager.Resources/Selectables/RecipeSelectable.cs +++ b/src/PatchManager.Resources/Selectables/RecipeSelectable.cs @@ -11,13 +11,13 @@ namespace PatchManager.Resources.Selectables; /// public sealed class RecipeSelectable : BaseSelectable { - - private bool _modified = false; - private bool _deleted = false; + + private bool _modified; + private bool _deleted; private readonly string _originalData; internal readonly JObject JObject; internal readonly JArray Ingredients; - + /// /// Marks this resource selectable as having been modified any level down /// diff --git a/src/PatchManager.SassyPatching.Tests/PatchManager.SassyPatching.Tests.csproj b/src/PatchManager.SassyPatching.Tests/PatchManager.SassyPatching.Tests.csproj index dcaede7..aa462c1 100644 --- a/src/PatchManager.SassyPatching.Tests/PatchManager.SassyPatching.Tests.csproj +++ b/src/PatchManager.SassyPatching.Tests/PatchManager.SassyPatching.Tests.csproj @@ -5,6 +5,7 @@ false true PatchManager.SassyPatching.Tests + $(NoWarn);NU1701 diff --git a/src/PatchManager.SassyPatching.Tests/Validators/ArgumentValidator.cs b/src/PatchManager.SassyPatching.Tests/Validators/ArgumentValidator.cs index 522b170..ceb7c0c 100644 --- a/src/PatchManager.SassyPatching.Tests/Validators/ArgumentValidator.cs +++ b/src/PatchManager.SassyPatching.Tests/Validators/ArgumentValidator.cs @@ -9,12 +9,12 @@ public class ArgumentValidator : ParseValidator /// A field that is used to match against the corresponding field in a node of type /// public string Name = ""; - + /// /// A validator that is used to match against the corresponding node in a node of type /// - public ParseValidator? Value = null; - + public ParseValidator Value = null; + /// /// Determines if a node matches the tree defined by this validator /// diff --git a/src/PatchManager.SassyPatching.Tests/Validators/CallArgumentValidator.cs b/src/PatchManager.SassyPatching.Tests/Validators/CallArgumentValidator.cs index ea76495..e3c4e34 100644 --- a/src/PatchManager.SassyPatching.Tests/Validators/CallArgumentValidator.cs +++ b/src/PatchManager.SassyPatching.Tests/Validators/CallArgumentValidator.cs @@ -8,7 +8,7 @@ public class CallArgumentValidator : ParseValidator /// /// A field that is used to match against the corresponding field in a node of type /// - public string? ArgumentName = null; + public string ArgumentName = null; /// /// A validator that is used to match against the corresponding node in a node of type /// diff --git a/src/PatchManager.SassyPatching.Tests/Validators/Statements/ConditionalValidator.cs b/src/PatchManager.SassyPatching.Tests/Validators/Statements/ConditionalValidator.cs index 3cd60c6..d0d298a 100644 --- a/src/PatchManager.SassyPatching.Tests/Validators/Statements/ConditionalValidator.cs +++ b/src/PatchManager.SassyPatching.Tests/Validators/Statements/ConditionalValidator.cs @@ -9,13 +9,13 @@ public class ConditionalValidator : ParseValidator /// public ParseValidator Condition = new FalseValidator(); /// - /// A list of validators used to match against the corresponding list of nodes in a value of type + /// A list of validators used to match against the corresponding list of nodes in a value of type /// public List Body = new(); /// /// A validator that is used to match against the corresponding node in a node of type /// - public ParseValidator? Else = null; + public ParseValidator Else = null; /// /// Determines if a node matches the tree defined by this validator /// diff --git a/src/PatchManager.SassyPatching.Tests/Validators/Statements/SelectionLevel/FieldValidator.cs b/src/PatchManager.SassyPatching.Tests/Validators/Statements/SelectionLevel/FieldValidator.cs index 767267a..33dbccc 100644 --- a/src/PatchManager.SassyPatching.Tests/Validators/Statements/SelectionLevel/FieldValidator.cs +++ b/src/PatchManager.SassyPatching.Tests/Validators/Statements/SelectionLevel/FieldValidator.cs @@ -11,7 +11,7 @@ public class FieldValidator : ParseValidator /// /// A validator that is used to match against the corresponding node in a node of type /// - public ParseValidator? Indexer = null; + public ParseValidator Indexer = null; /// /// A validator that is used to match against the corresponding node in a node of type /// diff --git a/src/PatchManager.SassyPatching/Execution/Universe.cs b/src/PatchManager.SassyPatching/Execution/Universe.cs index dd5d656..9c12842 100644 --- a/src/PatchManager.SassyPatching/Execution/Universe.cs +++ b/src/PatchManager.SassyPatching/Execution/Universe.cs @@ -100,13 +100,14 @@ static Universe() /// This action receives patchers and registers them for later execution /// The action to be taken to log an error /// The action to be taken to log a message - public Universe(Action registerPatcher, Action errorLogger, Action messageLogger, Action registerGenerator) + public Universe(Action registerPatcher, Action errorLogger, Action messageLogger, Action registerGenerator, List allMods) { RegisterPatcher = registerPatcher; _errorLogger = errorLogger; MessageLogger = messageLogger; RegisterGenerator = registerGenerator; LoadedLabels = new List(_preloadedLabels); + AllMods = allMods; } // TODO: Fix this so that other mods stages get their guids working diff --git a/src/PatchManager.SassyPatching/PatchManager.SassyPatching.csproj b/src/PatchManager.SassyPatching/PatchManager.SassyPatching.csproj index 4002f8e..7a38c37 100644 --- a/src/PatchManager.SassyPatching/PatchManager.SassyPatching.csproj +++ b/src/PatchManager.SassyPatching/PatchManager.SassyPatching.csproj @@ -3,4 +3,8 @@ + + + $(NoWarn);CS3021;CS1591;CS0168;CS1571;CS1573 + diff --git a/src/PatchManager.Shared/Interfaces/ITextAssetGenerator.cs b/src/PatchManager.Shared/Interfaces/ITextAssetGenerator.cs index 2102df7..28edccd 100644 --- a/src/PatchManager.Shared/Interfaces/ITextAssetGenerator.cs +++ b/src/PatchManager.Shared/Interfaces/ITextAssetGenerator.cs @@ -1,12 +1,15 @@ namespace PatchManager.Shared.Interfaces; +/// +/// Describes a patcher that can generate text assets +/// public interface ITextAssetGenerator { /// /// The priority of this patcher compared to other patchers, so it can order the way they get executed /// public ulong Priority { get; } - + /// /// Creates a new text asset /// diff --git a/src/PatchManager/Directory.Build.targets b/src/PatchManager/Directory.Build.targets index 7420bb2..7d611b1 100644 --- a/src/PatchManager/Directory.Build.targets +++ b/src/PatchManager/Directory.Build.targets @@ -1,9 +1,5 @@  - - true - - @@ -31,7 +27,7 @@ - + @@ -74,6 +70,30 @@ + + + + + + + + + + + + + + + + + - - + diff --git a/src/PatchManager/PatchManager.csproj b/src/PatchManager/PatchManager.csproj index 7b08392..7267c50 100644 --- a/src/PatchManager/PatchManager.csproj +++ b/src/PatchManager/PatchManager.csproj @@ -1,37 +1,19 @@ - - - icon.png - $(ProjectName) - https://raw.githubusercontent.com/jan-bures/PatchManager/main/LICENSE - ../../nuget - $(RepositoryUrl) - README.md - ksp2;mod;library - - - - - - - - - - - + - + + \ No newline at end of file