static void HandleCaseGeneration() { Tweaks.FixRNGSeed(); BombGenerator bombGenerator = Object.FindObjectOfType <BombGenerator>(); if (bombGenerator.BombPrefabOverride == null) // No point in doing anything if they aren't even going to use the ObjectPool. { ObjectPool prefabPool = bombGenerator.BombPrefabPool; // Generate a case parent if (CaseParent != null) { Object.Destroy(CaseParent); } // We have to parent the case to a GameObject that isn't active so it doesn't appear in the scene but itself is still active. CaseParent = new GameObject(); CaseParent.SetActive(false); // Override any KMGameCommands foreach (KMGameCommands gameCommands in Object.FindObjectsOfType <KMGameCommands>()) { var previousDelegate = gameCommands.OnCreateBomb; gameCommands.OnCreateBomb = (string missionId, KMGeneratorSetting generatorSettings, GameObject spawnTarget, string seed) => { HandleGeneratorSetting(ModMission.CreateGeneratorSettingsFromMod(generatorSettings), prefabPool); return(previousDelegate(missionId, generatorSettings, spawnTarget, seed)); }; } // This must happen regardless of even BetterCasePicker is enabled so that the game can't try to spawn the fake case. prefabPool.Objects = prefabPool.Objects.Where(gameobject => gameobject.name != "TweaksCaseGenerator").ToList(); if (!Tweaks.settings.BetterCasePicker && !Tweaks.CaseGeneratorSettingCache) { return; } // Try to figure out what mission we are going into Mission mission = null; if (!string.IsNullOrEmpty(GameplayState.MissionToLoad)) { if (GameplayState.MissionToLoad.Equals(FreeplayMissionGenerator.FREEPLAY_MISSION_ID)) { mission = FreeplayMissionGenerator.Generate(GameplayState.FreeplaySettings); } else if (GameplayState.MissionToLoad.Equals(ModMission.CUSTOM_MISSION_ID)) { mission = GameplayState.CustomMission; } else { mission = MissionManager.Instance.GetMission(GameplayState.MissionToLoad); } } if (mission == null) { Debug.LogError("[BetterCasePicker] Unable to find the current mission"); return; } HandleGeneratorSetting(mission.GeneratorSetting, prefabPool); } }