Skip to content

Commit 4114d1e

Browse files
committed
v1.1.10
1 parent 9260472 commit 4114d1e

File tree

6 files changed

+76
-26
lines changed

6 files changed

+76
-26
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# 1.1.9
1+
# 1.1.10
2+
3+
- Can define a custom game name if required in the `UPPatcherSettings`
4+
- Older Unity version support for various code blocks
5+
6+
# 1.1.9
27

38
- Fixed Project to Project migration not doing the full process
49
- Removed many warnings related to nullables

Editor/PatcherUtility.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Nomnom.UnityProjectPatcher.AssetRipper;
1616
using Nomnom.UnityProjectPatcher.Editor.Steps;
1717
using UnityEditor;
18+
using UnityEditor.Build;
1819
using UnityEditor.PackageManager;
1920
using UnityEditor.SceneManagement;
2021
using UnityEditorInternal;
@@ -148,17 +149,41 @@ public static (string version, string gameWrapperVersion) GetVersions(PackageCol
148149
}
149150
}
150151

152+
public static string GetScriptingDefineSymbols() {
153+
#if UNITY_2020_3_OR_NEWER
154+
return PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone);
155+
#else
156+
return PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
157+
#endif
158+
}
159+
160+
public static void SetScriptingDefineSymbols(string symbols) {
161+
#if UNITY_2020_3_OR_NEWER
162+
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, symbols);
163+
#else
164+
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols);
165+
#endif
166+
}
167+
151168
public static bool TryFetchGitVersion(string gitUrl, out string version) {
152169
try {
153170
// https://raw.githubusercontent.com/nomnomab/unity-lc-project-patcher/master/package.json
154171
var packageUrl = $"{gitUrl.Replace("github.com", "raw.githubusercontent.com")}/master/package.json";
155172
var request = UnityWebRequest.Get(packageUrl);
156-
request.SendWebRequest();
157-
while (!request.isDone) { }
173+
var r = request.SendWebRequest();
174+
while (!r.isDone) { }
175+
176+
#if UNITY_2020_3_OR_NEWER
158177
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError) {
159178
version = null;
160179
return false;
161180
}
181+
#else
182+
if (request.isHttpError || request.isNetworkError) {
183+
version = null;
184+
return false;
185+
}
186+
#endif
162187

163188
var json = request.downloadHandler.text;
164189
var packageContents = JObject.Parse(json);

Editor/PatcherWindow.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ private static void OnLoad() {
3030
// check tool version
3131
var packages = PatcherUtility.GetPackages();
3232
var toolGit = "https://github.com/nomnomab/unity-project-patcher";
33-
var bepinexGit = "https://github.com/nomnomab/unity-project-patcher-bepinex";
3433
var gameWrapper = PatcherUtility.GetGameWrapperAttribute();
3534

3635
var currentToolVersion = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher")?.version;
37-
var currentBepInExVersion = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher-bepinex")?.version;
3836

3937
try {
4038
if (!string.IsNullOrEmpty(currentToolVersion) && PatcherUtility.TryFetchGitVersion(toolGit, out var toolVersion)) {
@@ -50,6 +48,9 @@ private static void OnLoad() {
5048
Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher] version from \"{toolGit}\". Exception: {e}");
5149
}
5250

51+
#if UNITY_2020_3_OR_NEWER
52+
var currentBepInExVersion = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher-bepinex")?.version;
53+
var bepinexGit = "https://github.com/nomnomab/unity-project-patcher-bepinex";
5354
try {
5455
if (!string.IsNullOrEmpty(currentBepInExVersion) && PatcherUtility.TryFetchGitVersion(bepinexGit, out var bepinexVersion)) {
5556
if (currentBepInExVersion != bepinexVersion) {
@@ -63,6 +64,7 @@ private static void OnLoad() {
6364
} catch (Exception e) {
6465
Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher-bepinex] version from \"{bepinexGit}\". Exception: {e}");
6566
}
67+
#endif
6668

6769
if (gameWrapper != null) {
6870
try {
@@ -93,6 +95,11 @@ private static void OnLoad() {
9395
Debug.LogWarning($"Failed to fetch [{gameWrapper.PackageName}] version. Exception: {e}");
9496
}
9597
}
98+
99+
var window = Resources.FindObjectsOfTypeAll<PatcherWindow>().FirstOrDefault() as PatcherWindow;
100+
if (window) {
101+
window.CheckPackages();
102+
}
96103
}
97104

98105
[MenuItem("Tools/Unity Project Patcher/Open Window")]
@@ -130,21 +137,27 @@ private void OnEnable() {
130137
_gameWrapperGuiFunction = gameWrapperOnGUIFunction;
131138
}
132139

133-
private void OnFocus() {
134-
Nomnom.UnityProjectPatcher.PatcherUtility.GetUserSettings();
135-
CheckPackages();
136-
}
140+
// private void OnFocus() {
141+
// Nomnom.UnityProjectPatcher.PatcherUtility.GetUserSettings();
142+
// try {
143+
// CheckPackages();
144+
// } catch (Exception e) {
145+
// Debug.LogWarning(e);
146+
// }
147+
// }
137148

138149
private void CheckPackages() {
139-
_packageCollection ??= PatcherUtility.GetPackages();
140-
150+
if (_packageCollection is null) {
151+
_packageCollection = PatcherUtility.GetPackages();
152+
}
153+
141154
var (version, gameVersion) = PatcherUtility.GetVersions(_packageCollection);
142155
_patcherVersion = version;
143156
_gameWrapperVersion = gameVersion;
144157

145158
// check packages
146159
_hasBepInExPackage = _packageCollection.Any(x => x.name == "com.nomnom.unity-project-patcher-bepinex");
147-
_hasBepInExFlag = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Contains("ENABLE_BEPINEX");
160+
_hasBepInExFlag = PatcherUtility.GetScriptingDefineSymbols().Contains("ENABLE_BEPINEX");
148161
_foundPackageAttribute = PatcherUtility.GetGameWrapperAttribute();
149162
// _hasGameWrapperPackage = false;
150163
// if (!string.IsNullOrEmpty(_foundPackageAttribute?.PackageName)) {
@@ -190,6 +203,7 @@ private void OnGUI() {
190203
GUI.enabled = false;
191204
}
192205

206+
#if UNITY_2020_3_OR_NEWER
193207
if (!_hasBepInExPackage) {
194208
if (GUILayout.Button("Install BepInEx")) {
195209
EditorApplication.delayCall += () => {
@@ -206,10 +220,10 @@ private void OnGUI() {
206220
}
207221

208222
// enable ENABLE_BEPINEX
209-
var existingSymbols = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone);
223+
var existingSymbols = PatcherUtility.GetScriptingDefineSymbols();
210224
if (!existingSymbols.Contains("ENABLE_BEPINEX")) {
211225
existingSymbols += ";ENABLE_BEPINEX";
212-
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, existingSymbols);
226+
PatcherUtility.SetScriptingDefineSymbols(existingSymbols);
213227
}
214228

215229
EditorUtility.ClearProgressBar();
@@ -218,21 +232,24 @@ private void OnGUI() {
218232
} else {
219233
if (_hasBepInExFlag && GUILayout.Button("Disable BepInEx")) {
220234
EditorApplication.delayCall += () => {
221-
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Replace("ENABLE_BEPINEX", ""));
235+
PatcherUtility.SetScriptingDefineSymbols(PatcherUtility.GetScriptingDefineSymbols().Replace("ENABLE_BEPINEX", ""));
222236
};
223237
} else if (!_hasBepInExFlag && GUILayout.Button("Enable BepInEx")) {
224238
EditorApplication.delayCall += () => {
225-
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.Standalone, PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone) + ";ENABLE_BEPINEX");
239+
PatcherUtility.SetScriptingDefineSymbols(PatcherUtility.GetScriptingDefineSymbols() + ";ENABLE_BEPINEX");
226240
};
227241
}
228242
}
229243

230-
if (!_hasBepInExPackage && _foundPackageAttribute is not null && _foundPackageAttribute.RequiresBepInEx) {
244+
if (!_hasBepInExPackage && !(_foundPackageAttribute is null) && _foundPackageAttribute.RequiresBepInEx) {
231245
EditorGUILayout.LabelField("Please install all packages!", EditorStyles.centeredGreyMiniLabel);
232246
EditorGUILayout.LabelField($"bepinex: {(_hasBepInExPackage ? "good!" : "missing!")}");
233247
// EditorGUILayout.LabelField($"{_gameWrapperType.Name}: {(_hasGameWrapperPackage ? "good!" : "missing!")}");
234248
return;
235249
}
250+
#else
251+
EditorGUILayout.LabelField("BepInEx is not supported for older versions of Unity atm", EditorStyles.centeredGreyMiniLabel);
252+
#endif
236253

237254
if (GUILayout.Button("Run Patcher")) {
238255
// if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) {

Runtime/UPPatcherSettings.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace Nomnom.UnityProjectPatcher {
1616
public partial class UPPatcherSettings : ScriptableObject {
1717
#if UNITY_EDITOR
1818
public string GameFolderPath => PatcherUtility.GetUserSettings().GameFolderPath ?? throw new NullReferenceException(nameof(GameFolderPath));
19-
public string GameExePath => Path.Combine(GameFolderPath, $"{GameName}.exe");
20-
public string GameDataPath => Path.Combine(GameFolderPath, $"{GameName}_Data");
19+
public string GameExePath => Path.Combine(GameFolderPath, $"{(string.IsNullOrEmpty(_customGameName) ? GameName : _customGameName)}.exe");
20+
public string GameDataPath => Path.Combine(GameFolderPath, $"{(string.IsNullOrEmpty(_customGameName) ? GameName : _customGameName)}_Data");
2121
public string GameManagedPath => Path.Combine(GameDataPath, "Managed");
2222
#endif
2323

@@ -50,6 +50,9 @@ public partial class UPPatcherSettings : ScriptableObject {
5050
[SerializeField, InlineButton(nameof(GetGameName), "Get", buttonWidth: 30)]
5151
private string? _gameName = null;
5252

53+
[SerializeField]
54+
private string? _customGameName = null;
55+
5356
[SerializeField, InlineButton(nameof(GetGameVersion), "Get", buttonWidth: 30)]
5457
private string? _gameVersion = null;
5558

@@ -59,6 +62,9 @@ public partial class UPPatcherSettings : ScriptableObject {
5962
[SerializeField]
6063
private string _gameName = null;
6164

65+
[SerializeField]
66+
private string _customGameName = null;
67+
6268
[SerializeField]
6369
private string _gameVersion = null;
6470

Runtime/UPPatcherUserSettings.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,15 @@ public sealed class UPPatcherUserSettings: ScriptableObject {
3232
private string? _assetRipperExportFolderPath = "AssetRipperOutput";
3333
#else
3434
[SerializeField]
35-
[Header("Where the game is installed")]
36-
[HelpBox(@"This path is absolute to your game folder. Such as: ""C:\Program Files (x86)\Steam\steamapps\common\Lethal Company""")]
35+
[Header(@"Where the game is installed. This path is absolute to your game folder. Such as: ""C:\Program Files (x86)\Steam\steamapps\common\Lethal Company""")]
3736
private string _gameFolderPath;
3837

3938
[SerializeField]
40-
[Header("Where AssetRipper will be downloaded to")]
41-
[HelpBox(@"This path is relative to your project folder. It defaults to ""[Project Name]\AssetRipper""")]
39+
[Header(@"Where AssetRipper will be downloaded to. This path is relative to your project folder. It defaults to ""[Project Name]\AssetRipper""")]
4240
private string _assetRipperDownloadFolderPath = "AssetRipper";
4341

4442
[SerializeField]
45-
[Header("Where AssetRipper will store exported files")]
46-
[HelpBox(@"This path is relative to your project folder. It defaults to ""[Project Name]\AssetRipperOutput""")]
43+
[Header(@"Where AssetRipper will store exported files. This path is relative to your project folder. It defaults to ""[Project Name]\AssetRipperOutput""")]
4744
private string _assetRipperExportFolderPath = "AssetRipperOutput";
4845
#endif
4946
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.nomnom.unity-project-patcher",
3-
"version": "1.1.9",
3+
"version": "1.1.10",
44
"displayName": "Unity Project Patcher",
55
"description": "A tool that generates a Unity project from a game build that can be playable in-editor",
66
"unity": "2022.3",

0 commit comments

Comments
 (0)