@@ -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()) {
0 commit comments