Skip to content

Commit d1dc0f3

Browse files
committed
v1.1.6
1 parent 2bf2876 commit d1dc0f3

16 files changed

+195
-45
lines changed

CHANGELOG.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
# 1.1.5
1+
# 1.1.6
2+
3+
- Added extra help text to `UPPatcherSettings`
4+
- Added `RestartEditorStep` to end of default steps
5+
- Added `Install BepInEx` button to tool window
6+
- `UPPatcher` attribute can require BepInEx now
7+
- Will automatically add the `ENABLE_BEPINEX` compile flag
8+
- Added an Enable/Disable button for BepInEx after installation
9+
- Fixed `RenameAnimatorParamatersStep` not renaming `m_ConditionEvent`
10+
- Fixed various building issues when building asset bundles
11+
- Updated `README_TEMPLATE.md`
12+
13+
# 1.1.5
214

315
- Added scene saving dialogue when pressing the patch button
416
- Fixed New Input System enabling not restarting if enabled via package step
@@ -7,8 +19,8 @@
719

820
- Project to project migration tool
921
- Rename animator paramaters step
10-
- Updated README.md
11-
- Updated README_TEMPLATE.md
22+
- Updated `README.md`
23+
- Updated `README_TEMPLATE.md`
1224

1325
# 1.1.3
1426

Editor/AssetScrubber.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public static void TestScrubCompareProjectToProject() {
345345

346346
[MenuItem("Tools/Unity Project Patcher/Other/Import Assets From Another Project")]
347347
public static void ImportAssetsFromAnotherProject() {
348-
var disk = EditorUtility.OpenFilePanel("Select Project's .json file", "Assets", "");
348+
var disk = EditorUtility.OpenFilePanel("Select Project's .json file", "Assets", "json");
349349
if (string.IsNullOrEmpty(disk)) return;
350350

351351
var modDisk = EditorUtility.OpenFolderPanel("Mod Root Folder", "Assets", "");
@@ -355,7 +355,7 @@ public static void ImportAssetsFromAnotherProject() {
355355
// if (string.IsNullOrEmpty(output)) return;
356356

357357
var settings = UnityProjectPatcher.PatcherUtility.GetSettings();
358-
var outputFolder = Path.Combine(settings.ProjectGamePluginsFullPath, "plugins", Path.GetFileNameWithoutExtension(modDisk));
358+
var outputFolder = Path.Combine(settings.ProjectGameModsFullPath, "plugins", Path.GetFileNameWithoutExtension(modDisk));
359359
if (Directory.Exists(outputFolder)) {
360360
Directory.Delete(outputFolder, true);
361361
}
@@ -460,15 +460,15 @@ public static void ImportAssetsFromAnotherProject() {
460460
EditorUtility.ClearProgressBar();
461461
}
462462

463-
[MenuItem("Tools/Unity Project Patcher/Other/Fix FileIds")]
464-
public static async void FixFileIDs() {
465-
try {
466-
var step = new FixProjectFileIdsStep();
467-
await step.Run();
468-
} catch (Exception e) {
469-
EditorUtility.ClearProgressBar();
470-
}
471-
}
463+
// [MenuItem("Tools/Unity Project Patcher/Other/Fix FileIds")]
464+
// public static async void FixFileIDs() {
465+
// try {
466+
// var step = new FixProjectFileIdsStep();
467+
// await step.Run();
468+
// } catch (Exception e) {
469+
// EditorUtility.ClearProgressBar();
470+
// }
471+
// }
472472

473473
public static AssetCatalogue ScrubProjectAssets() {
474474
return ScrubProject(string.Empty, _assetsRootSearchFolder);

Editor/PatcherUtility.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public static Type GetGameWrapperType() {
6363

6464
return null;
6565
}
66+
67+
public static UPPatcherAttribute GetGameWrapperAttribute() {
68+
var type = GetGameWrapperType();
69+
if (type is null) return null;
70+
return type.GetCustomAttribute<UPPatcherAttribute>();
71+
}
6672

6773
// public static MethodInfo GetGameWrapperRunFunction(Type wrapperType) {
6874
// var runFunction = wrapperType.GetMethod("Run", BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
@@ -93,32 +99,44 @@ public static MethodInfo GetGameWrapperOnGUIFunction(Type wrapperType) {
9399
return guiFunction;
94100
}
95101

96-
public static (string version, string gameWrapperVersion) GetVersions() {
97-
EditorUtility.DisplayProgressBar("Fetching...", "Fetching versions...", 0.5f);
102+
public static PackageCollection GetPackages() {
98103
try {
99104
var list = Client.List();
100105
while (!list.IsCompleted) { }
106+
return list.Result;
107+
} catch (Exception e) {
108+
Debug.LogError(e);
109+
return null;
110+
}
111+
}
101112

102-
var patcher = list.Result.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher");
113+
public static (string version, string gameWrapperVersion) GetVersions(PackageCollection packages) {
114+
EditorUtility.DisplayProgressBar("Fetching...", "Fetching versions...", 0.5f);
115+
try {
116+
var patcher = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher");
103117
(string, string) results = (null, null);
104118
if (patcher != null) {
105119
results.Item1 = patcher.version;
106120
}
107121

108122
var gameWrapperType = GetGameWrapperType();
123+
if (gameWrapperType is null) {
124+
results.Item2 = null;
125+
return results;
126+
}
109127
var assembly = gameWrapperType.Assembly;
110128
var packageName = assembly.GetName().Name.ToLower();
111129
if (packageName.EndsWith(".editor")) {
112130
packageName = packageName.Replace(".editor", string.Empty);
113131
}
114-
patcher = list.Result.FirstOrDefault(x => x.name == packageName);
132+
patcher = packages.FirstOrDefault(x => x.name == packageName);
115133
if (patcher != null) {
116134
results.Item2 = patcher.version;
117135
}
118136

119137
return results;
120138
} catch (Exception e) {
121-
Debug.LogError(e);
139+
Debug.LogWarning(e);
122140
return (null, null);
123141
}
124142
finally {

Editor/PatcherWindow.cs

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Reflection;
45
using Nomnom.UnityProjectPatcher.Editor.Steps;
56
using UnityEditor;
7+
using UnityEditor.Build;
8+
using UnityEditor.PackageManager;
69
using UnityEditor.SceneManagement;
710
using UnityEngine;
811

@@ -15,6 +18,12 @@ public class PatcherWindow: EditorWindow {
1518

1619
private GUIStyle _leftAlignedGreyLabel;
1720
private GUIStyle _rightAlignedGreyLabel;
21+
22+
private bool _hasBepInExPackage;
23+
private bool _hasBepInExFlag;
24+
// private bool _hasGameWrapperPackage;
25+
private UPPatcherAttribute _foundPackageAttribute;
26+
private PackageCollection _packageCollection;
1827

1928
[MenuItem("Tools/Unity Project Patcher/Open Window")]
2029
private static void Open() {
@@ -33,9 +42,8 @@ private void OnEnable() {
3342
Nomnom.UnityProjectPatcher.PatcherUtility.GetUserSettings();
3443

3544
EditorApplication.delayCall += () => {
36-
var (version, gameVersion) = PatcherUtility.GetVersions();
37-
_patcherVersion = version;
38-
_gameWrapperVersion = gameVersion;
45+
_packageCollection = null;
46+
CheckPackages();
3947
Repaint();
4048
};
4149
_gameWrapperVersion = null;
@@ -52,6 +60,29 @@ private void OnEnable() {
5260
_gameWrapperGuiFunction = gameWrapperOnGUIFunction;
5361
}
5462

63+
private void OnFocus() {
64+
Nomnom.UnityProjectPatcher.PatcherUtility.GetUserSettings();
65+
CheckPackages();
66+
}
67+
68+
private void CheckPackages() {
69+
_packageCollection ??= PatcherUtility.GetPackages();
70+
71+
var (version, gameVersion) = PatcherUtility.GetVersions(_packageCollection);
72+
_patcherVersion = version;
73+
_gameWrapperVersion = gameVersion;
74+
75+
// check packages
76+
_hasBepInExPackage = _packageCollection.Any(x => x.name == "com.nomnom.unity-project-patcher-bepinex");
77+
_hasBepInExFlag = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Contains("ENABLE_BEPINEX");
78+
_packageCollection = _packageCollection;
79+
_foundPackageAttribute = PatcherUtility.GetGameWrapperAttribute();
80+
// _hasGameWrapperPackage = false;
81+
// if (!string.IsNullOrEmpty(_foundPackageAttribute?.PackageName)) {
82+
// _hasGameWrapperPackage = _packageCollection.Any(x => x.name == _foundPackageAttribute.PackageName);
83+
// }
84+
}
85+
5586
private void OnGUI() {
5687
if (_leftAlignedGreyLabel == null) {
5788
_leftAlignedGreyLabel = new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleLeft };
@@ -87,6 +118,51 @@ private void OnGUI() {
87118

88119
if (EditorApplication.isCompiling) {
89120
EditorGUILayout.LabelField("Compiling...", EditorStyles.centeredGreyMiniLabel);
121+
GUI.enabled = false;
122+
}
123+
124+
if (!_hasBepInExPackage) {
125+
if (GUILayout.Button("Install BepInEx")) {
126+
EditorApplication.delayCall += () => {
127+
_packageCollection = null;
128+
129+
EditorUtility.DisplayProgressBar("Installing...", "Installing BepInEx...", 0.5f);
130+
131+
var request = Client.Add("https://github.com/nomnomab/unity-project-patcher-bepinex.git");
132+
while (!request.IsCompleted) { }
133+
if (request.Status == StatusCode.Success) {
134+
EditorUtility.DisplayDialog("Success!", "BepInEx was installed successfully!", "OK");
135+
} else {
136+
EditorUtility.DisplayDialog("Error", $"Failed to install BepInEx! [{request.Error.errorCode}] {request.Error.message}", "OK");
137+
}
138+
139+
// enable ENABLE_BEPINEX
140+
var existingSymbols = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone);
141+
if (!existingSymbols.Contains("ENABLE_BEPINEX")) {
142+
existingSymbols += ";ENABLE_BEPINEX";
143+
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, existingSymbols);
144+
}
145+
146+
EditorUtility.ClearProgressBar();
147+
};
148+
}
149+
} else {
150+
if (_hasBepInExFlag && GUILayout.Button("Disable BepInEx")) {
151+
EditorApplication.delayCall += () => {
152+
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Replace("ENABLE_BEPINEX", ""));
153+
};
154+
} else if (!_hasBepInExFlag && GUILayout.Button("Enable BepInEx")) {
155+
EditorApplication.delayCall += () => {
156+
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone) + ";ENABLE_BEPINEX");
157+
};
158+
}
159+
}
160+
161+
if (!_hasBepInExPackage && _foundPackageAttribute is not null && _foundPackageAttribute.RequiresBepInEx) {
162+
EditorGUILayout.LabelField("Please install all packages!", EditorStyles.centeredGreyMiniLabel);
163+
EditorGUILayout.LabelField($"bepinex: {(_hasBepInExPackage ? "good!" : "missing!")}");
164+
// EditorGUILayout.LabelField($"{_gameWrapperType.Name}: {(_hasGameWrapperPackage ? "good!" : "missing!")}");
165+
return;
90166
}
91167

92168
if (GUILayout.Button("Run Patcher")) {
@@ -100,21 +176,30 @@ private void OnGUI() {
100176

101177
try {
102178
if (string.IsNullOrEmpty(userSettings.GameFolderPath) || !Directory.Exists(Path.GetFullPath(userSettings.GameFolderPath))) {
103-
EditorUtility.DisplayDialog("Error", "Please select a valid game folder!", "Ok");
179+
EditorUtility.DisplayDialog("Error", "Please select a valid game folder!\n\nPlease fix this in your UPPatcherUserSettings asset!", "Focus UPPatcherUserSettings");
180+
EditorUtility.FocusProjectWindow();
181+
Selection.activeObject = userSettings;
182+
EditorGUIUtility.PingObject(userSettings);
104183
return;
105184
}
106185

107186
if (string.IsNullOrEmpty(userSettings.AssetRipperDownloadFolderPath)) {
108-
EditorUtility.DisplayDialog("Error", "Please select a valid asset ripper download location!", "Ok");
187+
EditorUtility.DisplayDialog("Error", "Please select a valid asset ripper download location!\n\nPlease fix this in your UPPatcherUserSettings asset!", "Focus UPPatcherUserSettings");
188+
EditorUtility.FocusProjectWindow();
189+
Selection.activeObject = userSettings;
190+
EditorGUIUtility.PingObject(userSettings);
109191
return;
110192
}
111193

112194
if (string.IsNullOrEmpty(userSettings.AssetRipperExportFolderPath)) {
113-
EditorUtility.DisplayDialog("Error", "Please select a valid asset ripper export location!", "Ok");
195+
EditorUtility.DisplayDialog("Error", "Please select a valid asset ripper export location!\n\nPlease fix this in your UPPatcherUserSettings asset!", "Focus UPPatcherUserSettings");
196+
EditorUtility.FocusProjectWindow();
197+
Selection.activeObject = userSettings;
198+
EditorGUIUtility.PingObject(userSettings);
114199
return;
115200
}
116201
} catch {
117-
EditorUtility.DisplayDialog("Error", "There is a bad path in the user settings!", "Ok");
202+
EditorUtility.DisplayDialog("Error", "There is a bad path in the user settings!\n\nPlease fix this in your UPPatcherUserSettings asset!", "Focus UPPatcherUserSettings");
118203
EditorUtility.FocusProjectWindow();
119204
Selection.activeObject = userSettings;
120205
EditorGUIUtility.PingObject(userSettings);

Editor/Steps/Processing/AssetRipperStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Nomnom.UnityProjectPatcher.Editor.Steps {
1717
public readonly struct AssetRipperStep: IPatcherStep {
1818
private static bool _noDeletion;
1919

20-
[MenuItem("Tools/Unity Project Patcher/Run AssetRipper")]
20+
[MenuItem("Tools/Unity Project Patcher/Other/Run AssetRipper")]
2121
private static void Foo() {
2222
if (!EditorUtility.DisplayDialog("AssetRipper", "Are you sure you want to run AssetRipper?", "Yes", "No")) {
2323
return;

Editor/Steps/Processing/GenerateReadmeStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Nomnom.UnityProjectPatcher.Editor.Steps {
77
public readonly struct GenerateReadmeStep: IPatcherStep {
8-
[MenuItem("Tools/Unity Project Patcher/Generate README.md")]
8+
[MenuItem("Tools/Unity Project Patcher/Other/Generate README.md")]
99
private static void Foo() {
1010
try {
1111
new GenerateReadmeStep().Run().Forget();

Editor/Steps/Processing/RenameAnimatorParametersStep.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public UniTask<StepResult> Run() {
3030

3131
foreach (var pair in rename.replace) {
3232
contents = contents.Replace($"m_Name: {pair.from}", $"m_Name: {pair.to}");
33+
contents = contents.Replace($"m_ConditionEvent: {pair.from}", $"m_ConditionEvent: {pair.to}");
3334
}
3435

3536
File.WriteAllText(path, contents);
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// using Cysharp.Threading.Tasks;
2-
//
3-
// namespace Nomnom.UnityProjectPatcher.Editor.Steps {
4-
// /// <summary>
5-
// /// This simply restarts the editor.
6-
// /// </summary>
7-
// public readonly struct RestartEditorStep: IPatcherStep {
8-
// public UniTask<StepResult> Run() {
9-
// return UniTask.FromResult(StepResult.RestartEditor);
10-
// }
11-
//
12-
// public void OnComplete(bool failed) { }
13-
// }
14-
// }
1+
using Cysharp.Threading.Tasks;
2+
3+
namespace Nomnom.UnityProjectPatcher.Editor.Steps {
4+
/// <summary>
5+
/// This simply restarts the editor.
6+
/// </summary>
7+
public readonly struct RestartEditorStep: IPatcherStep {
8+
public UniTask<StepResult> Run() {
9+
return UniTask.FromResult(StepResult.RestartEditor);
10+
}
11+
12+
public void OnComplete(bool failed) { }
13+
}
14+
}

Editor/Steps/StepPipeline.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public sealed class StepPipeline {
2323
new GuidRemapperStep(),
2424
new CopyAssetRipperExportToProjectStep(), // restarts
2525
new FixProjectFileIdsStep(),
26-
new SortAssetTypesSteps()
26+
new SortAssetTypesSteps(),
27+
new RestartEditorStep()
2728
};
2829

2930
public StepPipeline() {

Editor/UPPatcherAttribute.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace Nomnom.UnityProjectPatcher.Editor {
44
[AttributeUsage(AttributeTargets.Class)]
55
public sealed class UPPatcherAttribute: Attribute {
6+
public readonly bool RequiresBepInEx;
67

8+
public UPPatcherAttribute(bool requiresBepInEx = false) {
9+
RequiresBepInEx = requiresBepInEx;
10+
}
711
}
812
}

0 commit comments

Comments
 (0)