Skip to content

Commit

Permalink
Fix SpaceWarp 1.4 plugin list integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-bures committed Sep 2, 2023
1 parent 8ccad44 commit ab2ca7d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/PatchManager.Core/Assets/PatchingManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections;
using System.Reflection;
using HarmonyLib;
using KSP.Game;
using KSP.Game.Flow;
using PatchManager.Core.Cache;
Expand All @@ -14,7 +13,6 @@
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Coroutine = MoonSharp.Interpreter.Coroutine;

namespace PatchManager.Core.Assets;

Expand All @@ -24,8 +22,6 @@ internal static class PatchingManager
private static readonly List<ITextAssetGenerator> Generators = new();
private static Universe _universe;



private static readonly PatchHashes CurrentPatchHashes = PatchHashes.CreateDefault();

private static int _initialLibraryCount;
Expand All @@ -37,7 +33,8 @@ public static void GenerateUniverse()
// 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).FirstOrDefault(x => x.Name == "AllPlugins")!;
var field = manager.GetFields(BindingFlags.Static|BindingFlags.NonPublic)
.FirstOrDefault(x => x.Name == "AllPlugins")!;
var plugins = (List<SpaceWarpPluginDescriptor>)field.GetValue(null);
_universe = new(RegisterPatcher, Logging.LogError, Logging.LogInfo, RegisterGenerator,
plugins.Select(x => x.Guid).ToList());
Expand Down Expand Up @@ -192,7 +189,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
{
Label = name,
ArchiveFilename = archiveFilename,
Assets = new List<string> { name }
Assets = new List<string> { name }
});
}
createdAsset.Clear();
Expand Down Expand Up @@ -277,7 +274,7 @@ public static void CreateNewAssets(Action resolve, Action<string> 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));
Expand All @@ -293,8 +290,8 @@ public static void CreateNewAssets(Action resolve, Action<string> reject)

public static void RebuildAllCache(Action resolve, Action<string> reject)
{


var distinctKeys = _universe.LoadedLabels.Concat(_createdAssets.Keys).Distinct().ToList();

LoadingBarPatch.InjectPatchManagerTips = true;
Expand Down Expand Up @@ -334,7 +331,7 @@ bool killLoadingBarTips
{
while (!handle.IsDone)
{
// "Shuffle" it
// "Shuffle" it
GameManager.Instance.Game.UI.LoadingBar.ShuffleLoadingTip();
yield return null;
}
Expand Down

0 comments on commit ab2ca7d

Please sign in to comment.