Skip to content

Commit e6fb681

Browse files
authored
Merge pull request #18 from KSP2Community/dev
Dev
2 parents de7ec93 + b1cbde4 commit e6fb681

77 files changed

Lines changed: 4634 additions & 2290 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ plugin_template/patches/*.json
5151
# OS-specific
5252
Thumbs.db
5353
Desktop.ini
54-
.DS_Store
54+
.DS_Store
55+
56+
# ModuleAutoDocumenter
57+
GeneratedDocumentation

PatchManager.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Resources", "s
2222
EndProject
2323
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Planets", "src\PatchManager.Planets\PatchManager.Planets.csproj", "{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Science", "src\PatchManager.Science\PatchManager.Science.csproj", "{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -118,5 +120,13 @@ Global
118120
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.Deploy|Any CPU.Build.0 = Deploy|Any CPU
119121
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.DeployAndRun|Any CPU.ActiveCfg = DeployAndRun|Any CPU
120122
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.DeployAndRun|Any CPU.Build.0 = DeployAndRun|Any CPU
123+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Debug|Any CPU.Build.0 = Debug|Any CPU
125+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Release|Any CPU.ActiveCfg = Release|Any CPU
126+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Release|Any CPU.Build.0 = Release|Any CPU
127+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU
128+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Deploy|Any CPU.Build.0 = Deploy|Any CPU
129+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.DeployAndRun|Any CPU.ActiveCfg = DeployAndRun|Any CPU
130+
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.DeployAndRun|Any CPU.Build.0 = DeployAndRun|Any CPU
121131
EndGlobalSection
122132
EndGlobal

plugin_template/swinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Patch Manager",
66
"description": "A mod for generic patching needs similar to KSP 1's Module Manager.",
77
"source": "https://github.com/KSP2Community/PatchManager",
8-
"version": "0.4.0",
8+
"version": "0.5.0",
99
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
1010
"ksp2_version": {
1111
"min": "0.1.5",

src/PatchManager.Core/Assets/PatchingManager.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.Reflection;
44
using System.Text.RegularExpressions;
5+
using BepInEx.Logging;
56
using KSP.Game;
67
using KSP.Game.Flow;
78
using PatchManager.Core.Cache;
@@ -36,9 +37,21 @@ internal static class PatchingManager
3637
public static void GenerateUniverse()
3738
{
3839
var loadedPlugins = PluginList.AllEnabledAndActivePlugins.Select(x => x.Guid).ToList();
39-
Universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo, RegisterGenerator,
40+
UniverseLogMessage($"{string.Join(", ", loadedPlugins)}");
41+
Universe = new(RegisterPatcher, UniverseLogError, UniverseLogMessage, RegisterGenerator,
4042
loadedPlugins);
4143
_initialLibraryCount = Universe.AllLibraries.Count;
44+
45+
void UniverseLogError(string error)
46+
{
47+
Debug.Log($"[PatchManager.Universe] [ERR]: {error}");
48+
}
49+
50+
void UniverseLogMessage(string message)
51+
{
52+
53+
Debug.Log($"[PatchManager.Universe] [MSG]: {message}");
54+
}
4255
}
4356

4457
private static void RegisterPatcher(ITextPatcher patcher)
@@ -133,6 +146,7 @@ public static void ImportModPatches(string modName, string modFolder)
133146

134147
public static void RegisterPatches()
135148
{
149+
Logging.LogInfo($"Registering all patches!");
136150
Universe.RegisterAllPatches();
137151
Logging.LogInfo($"{Patchers.Count} patchers registered!");
138152
Logging.LogInfo($"{Generators.Count} generators registered!");

src/PatchManager.Core/CoreModule.cs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using PatchManager.Core.Assets;
77
using PatchManager.Core.Cache;
88
using PatchManager.Core.Flow;
9+
using PatchManager.SassyPatching.Execution;
910
using PatchManager.Shared;
1011
using PatchManager.Shared.Modules;
1112
using SpaceWarp.API.Configuration;
@@ -42,24 +43,8 @@ private static bool ShouldLoad(string[] disabled, string modInfoLocation)
4243
/// <summary>
4344
/// Reads all patch files.
4445
/// </summary>
45-
public override void Preload()
46+
public override void Init()
4647
{
47-
// Go here instead so that the static constructor recognizes everything
48-
PatchingManager.GenerateUniverse();
49-
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
50-
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
51-
52-
var modFolders = Directory.GetDirectories(Paths.PluginPath, "*",SearchOption.AllDirectories)
53-
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x => (Folder: x, Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))));
54-
55-
foreach (var modFolder in modFolders)
56-
{
57-
Logging.LogInfo($"Loading patchers from {modFolder.Folder}");
58-
// var modName = Path.GetDirectoryName(modFolder);
59-
PatchingManager.ImportModPatches(modFolder.Info.ModID, modFolder.Folder);
60-
}
61-
62-
PatchingManager.RegisterPatches();
6348

6449
if (_shouldAlwaysInvalidate.Value || SpaceWarp.API.Mods.PluginList.ModListChangedSinceLastRun)
6550
{
@@ -75,16 +60,33 @@ public override void Preload()
7560
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0,() => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
7661
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(1,() => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
7762
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(2, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
78-
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
79-
// () => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
80-
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
81-
// () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
8263
}
8364
else
8465
{
8566
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
8667
}
8768
}
69+
70+
/// <inheritdoc />
71+
public override void PreLoad()
72+
{
73+
// Go here instead so that the static constructor recognizes everything
74+
PatchingManager.GenerateUniverse();
75+
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
76+
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
77+
78+
var modFolders = Directory.GetDirectories(Paths.PluginPath, "*",SearchOption.AllDirectories)
79+
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x => (Folder: x, Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))));
80+
81+
foreach (var modFolder in modFolders)
82+
{
83+
Logging.LogInfo($"Loading patchers from {modFolder.Folder}");
84+
// var modName = Path.GetDirectoryName(modFolder);
85+
PatchingManager.ImportModPatches(modFolder.Info.ModID, modFolder.Folder);
86+
}
87+
PatchingManager.RegisterPatches();
88+
}
89+
8890
/// <summary>
8991
/// Registers the provider and locator for cached assets.
9092
/// </summary>
@@ -138,4 +140,9 @@ public override void BindConfiguration(IConfigFile modConfiguration)
138140
_shouldAlwaysInvalidate = new (modConfiguration.Bind("Core", "Always Invalidate Cache", false,
139141
"Should patch manager always invalidate its cache upon load"));
140142
}
143+
144+
/// <summary>
145+
/// This is the current universe that patch manager is using (used for interop reasons)
146+
/// </summary>
147+
[PublicAPI] public Universe CurrentUniverse => PatchingManager.Universe;
141148
}

0 commit comments

Comments
 (0)