Skip to content

Commit 376a1e5

Browse files
authored
Merge pull request #22 from KSP2Community/dev
Dev -> Main for 0.7.0
2 parents 7783653 + 3a664e6 commit 376a1e5

96 files changed

Lines changed: 5617 additions & 3056 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.

.github/workflows/build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Download NuGet
15+
id: download-nuget
16+
run: |
17+
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
18+
19+
- name: Build the solution
20+
run: dotnet build "PatchManager.sln" -c Release
21+
22+
- name: Find zip
23+
id: find-zip
24+
run: |
25+
echo "zip=$(ls -1 dist/PatchManager-*.zip | head -n 1)" >> $GITHUB_ENV
26+
echo "artifact_name=PatchManagerRelease" >> $GITHUB_ENV
27+
28+
- name: Upload zip artifact
29+
uses: actions/upload-artifact@v3
30+
with:
31+
name: ${{ env.artifact_name }}
32+
path: ${{ env.zip }}
33+
34+
- name: Find NuGet package
35+
id: find-nupkg
36+
run: |
37+
echo "nupkg=$(ls -1 nuget/PatchManager.*.nupkg | head -n 1)" >> $GITHUB_ENV
38+
echo "artifact_name=PatchManagerNuGet" >> $GITHUB_ENV
39+
40+
- name: Upload NuGet package
41+
uses: actions/upload-artifact@v3
42+
with:
43+
name: ${{ env.artifact_name }}
44+
path: ${{ env.nupkg }}

.github/workflows/on-release.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Publish NuGet and upload release
2+
3+
on:
4+
release:
5+
types: [ "published" ]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions: write-all
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v3
14+
15+
- name: Install jq
16+
uses: dcarbone/install-jq-action@v2.1.0
17+
18+
- name: Download NuGet
19+
id: download-nuget
20+
run: |
21+
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
22+
23+
- name: Build the solution
24+
run: dotnet build "PatchManager.sln" -c Release
25+
26+
- name: Extract current version
27+
id: get-version
28+
run: |
29+
version=$(jq -r '.version' plugin_template/BepInEx/plugins/PatchManager/swinfo.json)
30+
echo "Version is $version"
31+
echo "version=$version" >> $GITHUB_ENV
32+
echo "artifact_name=PatchManager-$version.zip" >> $GITHUB_ENV
33+
echo "zip=$(ls -1 dist/PatchManager-*.zip | head -n 1)" >> $GITHUB_ENV
34+
echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV
35+
36+
- name: Check if version exists
37+
id: check-version
38+
run: |
39+
version=${{ env.version }}
40+
response=$(curl -s "https://nuget.spacewarp.org/v3/search?q=PatchManager")
41+
exists=$(echo "$response" | jq -r --arg id "PatchManager" --arg version "$version" '.data[] | select(.id == $id) | .versions[] | select(.version == $version) | .version')
42+
if [ "$exists" == "$version" ]; then
43+
echo "Version $version already exists in the NuGet repository"
44+
exit 1
45+
else
46+
echo "Version $version does not exist in the NuGet repository"
47+
echo "should_publish=true" >> $GITHUB_ENV
48+
fi
49+
50+
- name: Publish NuGet package
51+
if: env.should_publish == 'true'
52+
run: |
53+
nupkg_path=$(ls -1 nuget/PatchManager.*.nupkg | head -n 1)
54+
dotnet nuget push "$nupkg_path" -s https://nuget.spacewarp.org/v3/index.json -k ${{ secrets.NUGET_SERVER_KEY }}
55+
56+
- name: Upload Zip
57+
uses: actions/upload-release-asset@v1.0.1
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
upload_url: ${{ env.upload_url }}
62+
asset_path: ${{ env.zip }}
63+
asset_name: ${{ env.artifact_name }}
64+
asset_content_type: application/zip
65+

.github/workflows/verify.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Verify swinfo.json
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
verify:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
14+
15+
- name: Verify KSP2 Mod
16+
uses: Rexicon226/VerifierAction@V0.5
File renamed without changes.

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.6.1",
8+
"version": "0.7.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: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System.Collections;
2-
using System.Globalization;
3-
using System.Reflection;
4-
using System.Text.RegularExpressions;
5-
using BepInEx.Logging;
62
using KSP.Game;
73
using KSP.Game.Flow;
84
using PatchManager.Core.Cache;
@@ -12,9 +8,7 @@
128
using PatchManager.SassyPatching.Execution;
139
using PatchManager.Shared;
1410
using PatchManager.Shared.Interfaces;
15-
using SpaceWarp;
1611
using SpaceWarp.API.Mods;
17-
using SpaceWarp.API.Versions;
1812
using UnityEngine;
1913
using UnityEngine.AddressableAssets;
2014
using UnityEngine.ResourceManagement.AsyncOperations;
@@ -33,25 +27,13 @@ internal static class PatchingManager
3327
private static Dictionary<string, List<(string name, string text)>> _createdAssets = new();
3428

3529
internal static int TotalPatchCount;
36-
private static readonly Regex VersionPreprocessRegex = new Regex(@"[^0-9.]");
37-
public static void GenerateUniverse()
30+
public static void GenerateUniverse(HashSet<string> singleFileModIds)
3831
{
3932
var loadedPlugins = PluginList.AllEnabledAndActivePlugins.Select(x => x.Guid).ToList();
40-
UniverseLogMessage($"{string.Join(", ", loadedPlugins)}");
41-
Universe = new(RegisterPatcher, UniverseLogError, UniverseLogMessage, RegisterGenerator,
33+
loadedPlugins.AddRange(singleFileModIds);
34+
Universe = new(RegisterPatcher, Logging.LogError, Logging.LogMessage, RegisterGenerator,
4235
loadedPlugins);
4336
_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-
}
5537
}
5638

5739
private static void RegisterPatcher(ITextPatcher patcher)
@@ -69,6 +51,7 @@ private static void RegisterPatcher(ITextPatcher patcher)
6951

7052
Patchers.Add(patcher);
7153
}
54+
7255
private static void RegisterGenerator(ITextAssetGenerator generator)
7356
{
7457
for (var index = 0; index < Generators.Count; index++)
@@ -144,6 +127,9 @@ public static void ImportModPatches(string modName, string modFolder)
144127
}
145128
}
146129

130+
public static void ImportSinglePatch(FileInfo fileInfo)
131+
=> Universe.LoadSinglePatchFile(fileInfo,new DirectoryInfo(BepInEx.Paths.GameRootPath));
132+
147133
public static void RegisterPatches()
148134
{
149135
Logging.LogInfo($"Registering all patches!");
@@ -207,6 +193,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
207193
Assets = new List<string> { name }
208194
});
209195
}
196+
210197
createdAsset.Clear();
211198
_createdAssets.Remove(label);
212199
}
@@ -226,6 +213,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
226213
{
227214
return;
228215
}
216+
229217
archiveFiles[asset.name] = patchedText;
230218
labelCacheEntry.Assets.Add(asset.name);
231219
assetsCacheEntries.Add(asset.name, new CacheEntry
@@ -259,6 +247,7 @@ void SaveArchive()
259247

260248
Console.WriteLine($"Cache for label '{label}' rebuilt.");
261249
}
250+
262251
if (handle.Status == AsyncOperationStatus.Failed && !unchanged)
263252
{
264253
SaveArchive();
@@ -278,21 +267,6 @@ void SaveArchive()
278267
return handle;
279268
}
280269

281-
private static bool IsUsefulKey(string key)
282-
{
283-
key = key.Replace(".bundle", "").Replace(".json", "");
284-
if (int.TryParse(key, NumberStyles.Number, CultureInfo.InvariantCulture, out _))
285-
{
286-
return false;
287-
}
288-
if (key.Length == 32)
289-
{
290-
return !key.All(x => "0123456789abcdef".Contains(x));
291-
}
292-
293-
return !key.EndsWith(".prefab") && !key.EndsWith(".png");
294-
}
295-
296270
public static void CreateNewAssets(Action resolve, Action<string> reject)
297271
{
298272
foreach (var generator in Generators)
@@ -317,34 +291,40 @@ public static void CreateNewAssets(Action resolve, Action<string> reject)
317291

318292
public static void RebuildAllCache(Action resolve, Action<string> reject)
319293
{
320-
321-
322294
var distinctKeys = Universe.LoadedLabels.Concat(_createdAssets.Keys).Distinct().ToList();
323295

324296
LoadingBarPatch.InjectPatchManagerTips = true;
297+
325298
GenericFlowAction CreateIndexedFlowAction(int idx)
326299
{
327300
return new GenericFlowAction(
328301
$"Patch Manager: {distinctKeys[idx]}",
329-
(resolve2, reject2) =>
302+
(resolve2, _) =>
330303
{
331304
var handle = RebuildCache(distinctKeys[idx]);
332305
var killTips = false;
333306
if (idx + 1 < distinctKeys.Count)
334-
GameManager.Instance.LoadingFlow._flowActions.Insert(GameManager.Instance.LoadingFlow._flowIndex + 1,
335-
CreateIndexedFlowAction(idx+1));
307+
{
308+
GameManager.Instance.LoadingFlow._flowActions.Insert(
309+
GameManager.Instance.LoadingFlow._flowIndex + 1,
310+
CreateIndexedFlowAction(idx + 1)
311+
);
312+
}
336313
else
337314
{
338315
killTips = true;
339316
}
340-
CoroutineUtil.Instance.DoCoroutine(WaitForCacheRebuildSingleHandle(handle, resolve2,killTips));
317+
318+
CoroutineUtil.Instance.DoCoroutine(WaitForCacheRebuildSingleHandle(handle, resolve2, killTips));
341319
});
342320
}
343321

344322
if (distinctKeys.Count > 0)
345323
{
346-
GameManager.Instance.LoadingFlow._flowActions.Insert(GameManager.Instance.LoadingFlow._flowIndex + 1,
347-
CreateIndexedFlowAction(0));
324+
GameManager.Instance.LoadingFlow._flowActions.Insert(
325+
GameManager.Instance.LoadingFlow._flowIndex + 1,
326+
CreateIndexedFlowAction(0)
327+
);
348328
}
349329

350330
resolve();

src/PatchManager.Core/Cache/Archive.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.IO.Compression;
2-
using UnityEngine;
32

43
namespace PatchManager.Core.Cache;
54

0 commit comments

Comments
 (0)