internal static int LoadAndRun(LemonFunc <int> functionToWaitForAsync) { if (!MelonLaunchOptions.Core.StartScreen) { return(functionToWaitForAsync()); } // Doesn't support Unity versions lower than 2017.2.0 (yet?) // Doesn't support Unity versions lower than 2018 (Crashing Issue) UnityVersion unityVersion = UnityInformationHandler.EngineVersion; UnityVersion minimumVersion = new UnityVersion(2018); if (unityVersion < minimumVersion) { return(functionToWaitForAsync()); } // Doesn't support Unity versions higher than to 2020.3.21 (Crashing Issue) UnityVersion maximumVersion = new UnityVersion(2020, 3, 21); if (unityVersion > maximumVersion) { return(functionToWaitForAsync()); } if (!Load()) { return(functionToWaitForAsync()); } if (LoadAndRunMethod != null) { return((int)LoadAndRunMethod.Invoke(null, new object[] { functionToWaitForAsync })); } return(-1); }
private static void ReadGameInfo(AssetsManager assetsManager) { string gameDataPath = MelonUtils.GetGameDataDirectory(); AssetsFileInstance instance = null; try { string bundlePath = Path.Combine(gameDataPath, "globalgamemanagers"); if (!File.Exists(bundlePath)) { bundlePath = Path.Combine(gameDataPath, "mainData"); } if (!File.Exists(bundlePath)) { return; } instance = assetsManager.LoadAssetsFile(bundlePath, true); if (instance == null) { return; } assetsManager.LoadIncludedClassPackage(); assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); EngineVersion = UnityVersion.Parse(instance.file.typeTree.unityVersion); List <AssetFileInfoEx> assetFiles = instance.table.GetAssetsOfType(129); if (assetFiles.Count > 0) { AssetFileInfoEx playerSettings = assetFiles.First(); AssetTypeInstance assetTypeInstance = null; try { assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } catch (Exception ex) { MelonLogger.Error(ex); MelonLogger.Warning("Attempting to use Large Class Package..."); assetsManager.LoadIncludedLargeClassPackage(); assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } if (assetTypeInstance != null) { AssetTypeValueField playerSettings_baseField = assetTypeInstance.GetBaseField(); AssetTypeValueField bundleVersion = playerSettings_baseField.Get("bundleVersion"); if (bundleVersion != null) { GameVersion = bundleVersion.GetValue().AsString(); } AssetTypeValueField companyName = playerSettings_baseField.Get("companyName"); if (companyName != null) { GameDeveloper = companyName.GetValue().AsString(); } AssetTypeValueField productName = playerSettings_baseField.Get("productName"); if (productName != null) { GameName = productName.GetValue().AsString(); } } } } catch (Exception ex) { MelonLogger.Error(ex); } if (instance != null) { instance.file.Close(); } }