protected override void OnDisabled() { base.OnDisabled(); CheckData.Clear(); ScenarioQueue = new ConcurrentQueue <ScenarioEntry>(); AllScenarioTypesInAssemblies.Clear(); }
private void LoadScenarioTypes() { AllScenarioTypesInAssemblies.Clear(); var scenarioTypes = AssemblyLoader.loadedAssemblies .SelectMany(a => a.assembly.GetTypes()) .Where(s => s.IsSubclassOf(typeof(ScenarioModule)) && !AllScenarioTypesInAssemblies.ContainsKey(s.Name)); foreach (var scenarioType in scenarioTypes) { AllScenarioTypesInAssemblies.TryAdd(scenarioType.Name, scenarioType); } }
private static bool IsScenarioModuleAllowed(string scenarioName) { if (string.IsNullOrEmpty(scenarioName)) { return(false); } if (scenarioName == "DeployedScience" && !ExpansionsLoader.IsExpansionInstalled("Serenity")) { return(false); } if (!IsDlcScenarioInstalled(scenarioName)) { return(false); } if (!AllScenarioTypesInAssemblies.ContainsKey(scenarioName)) { return(false); //Module missing } var scenarioType = AllScenarioTypesInAssemblies[scenarioName]; var scenarioAttributes = (KSPScenario[])scenarioType.GetCustomAttributes(typeof(KSPScenario), true); if (scenarioAttributes.Length > 0) { var attribute = scenarioAttributes[0]; var protoAllowed = false; if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { protoAllowed = attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingCareerGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewCareerGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingScienceSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewScienceSandboxGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewSandboxGames); } return(protoAllowed); } //Scenario is not marked with KSPScenario - let's load it anyway. return(true); }
private bool IsScenarioModuleAllowed(string scenarioName) { //Blacklist asteroid module from every game mode //We hijack this and enable / disable it if we need to. //Do not send kerbnet custom waypoints aswell. they f**k it up sometimes if (string.IsNullOrEmpty(scenarioName) || scenarioName == "ScenarioDiscoverableObjects" || scenarioName == "ScenarioCustomWaypoints") { return(false); } if (!AllScenarioTypesInAssemblies.Any()) { LoadScenarioTypes(); //Load type dictionary on first use } if (!AllScenarioTypesInAssemblies.ContainsKey(scenarioName)) { return(false); //Module missing } var scenarioType = AllScenarioTypesInAssemblies[scenarioName]; var scenarioAttributes = (KSPScenario[])scenarioType.GetCustomAttributes(typeof(KSPScenario), true); if (scenarioAttributes.Length > 0) { var attribute = scenarioAttributes[0]; var protoAllowed = false; if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { protoAllowed = attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingCareerGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewCareerGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingScienceSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewScienceSandboxGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewSandboxGames); } return(protoAllowed); } //Scenario is not marked with KSPScenario - let's load it anyway. return(true); }