Skip to content

Commit

Permalink
Merge pull request #18 from KSP2Community/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cheese3660 authored Dec 19, 2023
2 parents de7ec93 + b1cbde4 commit e6fb681
Show file tree
Hide file tree
Showing 77 changed files with 4,634 additions and 2,290 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ plugin_template/patches/*.json
# OS-specific
Thumbs.db
Desktop.ini
.DS_Store
.DS_Store

# ModuleAutoDocumenter
GeneratedDocumentation
10 changes: 10 additions & 0 deletions PatchManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Resources", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Planets", "src\PatchManager.Planets\PatchManager.Planets.csproj", "{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchManager.Science", "src\PatchManager.Science\PatchManager.Science.csproj", "{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,5 +120,13 @@ Global
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.Deploy|Any CPU.Build.0 = Deploy|Any CPU
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.DeployAndRun|Any CPU.ActiveCfg = DeployAndRun|Any CPU
{CDD0B166-F1E1-4EE1-8D1B-D47E269DA981}.DeployAndRun|Any CPU.Build.0 = DeployAndRun|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Release|Any CPU.Build.0 = Release|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.Deploy|Any CPU.Build.0 = Deploy|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.DeployAndRun|Any CPU.ActiveCfg = DeployAndRun|Any CPU
{E6AD9C2A-D53E-47DD-B48F-7A9AF6ACDC55}.DeployAndRun|Any CPU.Build.0 = DeployAndRun|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Patch Manager",
"description": "A mod for generic patching needs similar to KSP 1's Module Manager.",
"source": "https://github.com/KSP2Community/PatchManager",
"version": "0.4.0",
"version": "0.5.0",
"version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.1.5",
Expand Down
16 changes: 15 additions & 1 deletion src/PatchManager.Core/Assets/PatchingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Reflection;
using System.Text.RegularExpressions;
using BepInEx.Logging;
using KSP.Game;
using KSP.Game.Flow;
using PatchManager.Core.Cache;
Expand Down Expand Up @@ -36,9 +37,21 @@ internal static class PatchingManager
public static void GenerateUniverse()
{
var loadedPlugins = PluginList.AllEnabledAndActivePlugins.Select(x => x.Guid).ToList();
Universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo, RegisterGenerator,
UniverseLogMessage($"{string.Join(", ", loadedPlugins)}");
Universe = new(RegisterPatcher, UniverseLogError, UniverseLogMessage, RegisterGenerator,
loadedPlugins);
_initialLibraryCount = Universe.AllLibraries.Count;

void UniverseLogError(string error)
{
Debug.Log($"[PatchManager.Universe] [ERR]: {error}");
}

void UniverseLogMessage(string message)
{

Debug.Log($"[PatchManager.Universe] [MSG]: {message}");
}
}

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

public static void RegisterPatches()
{
Logging.LogInfo($"Registering all patches!");
Universe.RegisterAllPatches();
Logging.LogInfo($"{Patchers.Count} patchers registered!");
Logging.LogInfo($"{Generators.Count} generators registered!");
Expand Down
49 changes: 28 additions & 21 deletions src/PatchManager.Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using PatchManager.Core.Assets;
using PatchManager.Core.Cache;
using PatchManager.Core.Flow;
using PatchManager.SassyPatching.Execution;
using PatchManager.Shared;
using PatchManager.Shared.Modules;
using SpaceWarp.API.Configuration;
Expand Down Expand Up @@ -42,24 +43,8 @@ private static bool ShouldLoad(string[] disabled, string modInfoLocation)
/// <summary>
/// Reads all patch files.
/// </summary>
public override void Preload()
public override void Init()
{
// Go here instead so that the static constructor recognizes everything
PatchingManager.GenerateUniverse();
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

var modFolders = Directory.GetDirectories(Paths.PluginPath, "*",SearchOption.AllDirectories)
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x => (Folder: x, Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))));

foreach (var modFolder in modFolders)
{
Logging.LogInfo($"Loading patchers from {modFolder.Folder}");
// var modName = Path.GetDirectoryName(modFolder);
PatchingManager.ImportModPatches(modFolder.Info.ModID, modFolder.Folder);
}

PatchingManager.RegisterPatches();

if (_shouldAlwaysInvalidate.Value || SpaceWarp.API.Mods.PluginList.ModListChangedSinceLastRun)
{
Expand All @@ -75,16 +60,33 @@ public override void Preload()
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0,() => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(1,() => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(2, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
// () => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets));
// SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction(
// () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache));
}
else
{
SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator));
}
}

/// <inheritdoc />
public override void PreLoad()
{
// Go here instead so that the static constructor recognizes everything
PatchingManager.GenerateUniverse();
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

var modFolders = Directory.GetDirectories(Paths.PluginPath, "*",SearchOption.AllDirectories)
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x => (Folder: x, Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))));

foreach (var modFolder in modFolders)
{
Logging.LogInfo($"Loading patchers from {modFolder.Folder}");
// var modName = Path.GetDirectoryName(modFolder);
PatchingManager.ImportModPatches(modFolder.Info.ModID, modFolder.Folder);
}
PatchingManager.RegisterPatches();
}

/// <summary>
/// Registers the provider and locator for cached assets.
/// </summary>
Expand Down Expand Up @@ -138,4 +140,9 @@ public override void BindConfiguration(IConfigFile modConfiguration)
_shouldAlwaysInvalidate = new (modConfiguration.Bind("Core", "Always Invalidate Cache", false,
"Should patch manager always invalidate its cache upon load"));
}

/// <summary>
/// This is the current universe that patch manager is using (used for interop reasons)
/// </summary>
[PublicAPI] public Universe CurrentUniverse => PatchingManager.Universe;
}
Loading

0 comments on commit e6fb681

Please sign in to comment.