// Awake() - flag this class as don't destroy on load and register delegates void Awake() { // Don't run if Kopernicus isn't compatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } // Make sure the runtime utility isn't killed DontDestroyOnLoad(this); // Init the runtime logging new Logger("Kopernicus.Runtime").SetAsActive(); // Add handlers GameEvents.onPartUnpack.Add(OnPartUnpack); GameEvents.OnMapEntered.Add(OnMapEntered); GameEvents.onLevelWasLoaded.Add(OnLevelWasLoaded); GameEvents.onProtoVesselLoad.Add(TransformBodyReferencesOnLoad); GameEvents.onProtoVesselSave.Add(TransformBodyReferencesOnSave); // Log Logger.Default.Log("[Kopernicus] RuntimeUtility Started"); Logger.Default.Flush(); }
// Awake() is the first function called in the lifecycle of a Unity3D MonoBehaviour. In the case of KSP, // it happens to be called right before the game's PSystem is instantiated from PSystemManager.Instance.systemPrefab public void Awake() { // Abort, if KSP isn't compatible if (!CompatibilityChecker.IsCompatible()) { string supported = CompatibilityChecker.version_major + "." + CompatibilityChecker.version_minor + "." + CompatibilityChecker.Revision; string current = Versioning.version_major + "." + Versioning.version_minor + "." + Versioning.Revision; Debug.LogWarning("[Kopernicus] Detected incompatible install.\nCurrent version of KSP: " + current + ".\nSupported version of KSP: " + supported + ".\nPlease wait, until Kopernicus gets updated to match your version of KSP."); Debug.Log("[Kopernicus] Aborting..."); // Abort Destroy(this); return; } // We're ALIVE Logger.Default.SetAsActive(); Logger.Default.Log("Injector.Awake(): Begin"); // Parser Config ParserOptions.Register("Kopernicus", new ParserOptions.Data { errorCallback = e => Logger.Active.LogException(e), logCallback = s => Logger.Active.Log(s) }); // Yo garbage collector - we have work to do man DontDestroyOnLoad(this); // If the planetary manager does not work, well, error out if (PSystemManager.Instance == null) { // Log the error Logger.Default.Log("Injector.Awake(): If PSystemManager.Instance is null, there is nothing to do"); return; } // Backup the old prefab StockSystemPrefab = PSystemManager.Instance.systemPrefab; // Get the current time DateTime start = DateTime.Now; // Get the configNode ConfigNode kopernicus = GameDatabase.Instance.GetConfigs(rootNodeName)[0].config; // THIS IS WHERE THE MAGIC HAPPENS - OVERWRITE THE SYSTEM PREFAB SO KSP ACCEPTS OUR CUSTOM SOLAR SYSTEM AS IF IT WERE FROM SQUAD PSystemManager.Instance.systemPrefab = Parser.CreateObjectFromConfigNode <Loader>(kopernicus, "Kopernicus").systemPrefab; // Clear space center instance so it will accept nouveau Kerbin SpaceCenter.Instance = null; // Add a handler so that we can do post spawn fixups. PSystemManager.Instance.OnPSystemReady.Add(PostSpawnFixups); // Done executing the awake function TimeSpan duration = (DateTime.Now - start); Logger.Default.Log("Injector.Awake(): Completed in: " + duration.TotalMilliseconds + " ms"); Logger.Default.Flush(); }
void Awake() { if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } }
// Kill the old spawner public override void OnAwake() { if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } base.OnAwake(); }
// On awake(), preserve the star void Awake() { // Don't run if Kopernicus is incompatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } Logger.Default.Log("StarLightSwitcher.Awake(): Begin"); Logger.Default.Flush(); DontDestroyOnLoad(this); }
void Awake() { if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { if (FlightGlobals.GetHomeBody()?.atmosphericAmbientColor != null) { RenderSettings.ambientLight = FlightGlobals.GetHomeBody().atmosphericAmbientColor; } } }
// Kill the old spawner public override void OnAwake() { if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } base.OnAwake(); if (HighLogic.CurrentGame.RemoveProtoScenarioModule(typeof(ScenarioDiscoverableObjects))) { // RemoveProtoScenarioModule doesn't remove the actual Scenario; workaround! foreach (ScenarioDiscoverableObjects scen in Resources.FindObjectsOfTypeAll(typeof(ScenarioDiscoverableObjects))) { scen.StopAllCoroutines(); Destroy(scen); } Debug.Log("[Kopernicus]: ScenarioDiscoverableObjects successfully removed."); } }
// Awake() - flag this class as don't destroy on load and register delegates void Awake() { // Don't run if Kopernicus isn't compatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } // Make sure the runtime utility isn't killed DontDestroyOnLoad(this); // Add handlers GameEvents.onPartUnpack.Add(OnPartUnpack); GameEvents.onLevelWasLoaded.Add(FixCameras); GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene) { if (HighLogic.LoadedSceneHasPlanetarium && MapView.fetch != null) { MapView.fetch.max3DlineDrawDist = 20000f; } if (scene == GameScenes.MAINMENU) { UpdateMenu(); } }); // Update Music Logic if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null) { MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth; } // Log Logger.Default.Log("[Kopernicus]: RuntimeUtility Started"); Logger.Default.Flush(); }
// Awake() - flag this class as don't destroy on load and register delegates void Awake() { // Don't run if Kopernicus isn't compatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } // Make sure the runtime utility isn't killed DontDestroyOnLoad(this); // Add handlers GameEvents.onPartUnpack.Add(OnPartUnpack); GameEvents.onLevelWasLoaded.Add(FixCameras); GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene) { if (HighLogic.LoadedSceneHasPlanetarium && MapView.fetch != null) { MapView.fetch.max3DlineDrawDist = 20000f; } if (scene == GameScenes.MAINMENU) { UpdateMenu(); } if (scene == GameScenes.SPACECENTER) { PatchFI(); } foreach (CelestialBody body in PSystemManager.Instance.localBodies) { GameObject star_ = KopernicusStar.GetNearest(body).gameObject; if (body.afg != null) { body.afg.sunLight = star_; } if (body.scaledBody.GetComponent <MaterialSetDirection>() != null) { body.scaledBody.GetComponent <MaterialSetDirection>().target = star_.transform; } foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true)) { msd.target = star_.transform; } } foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>()) { anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform; } }); // Update Music Logic if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null) { MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth; } // Log Logger.Default.Log("[Kopernicus] RuntimeUtility Started"); Logger.Default.Flush(); }
// Awake() - flag this class as don't destroy on load and register delegates void Awake() { // Don't run if Kopernicus isn't compatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } // Make sure the runtime utility isn't killed DontDestroyOnLoad(this); // Init the runtime logging new Logger("Kopernicus.Runtime").SetAsActive(); // Add handlers GameEvents.onPartUnpack.Add(OnPartUnpack); GameEvents.onLevelWasLoaded.Add(FixCameras); GameEvents.OnMapEntered.Add(delegate { _mapDirty = true; }); GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene) { //if (MapView.fetch != null) // MapView.fetch.max3DlineDrawDist = Single.MaxValue; if (scene == GameScenes.SPACECENTER) { PatchFI(); } foreach (CelestialBody body in PSystemManager.Instance.localBodies) { GameObject star = KopernicusStar.GetNearest(body).gameObject; if (body.afg != null) { body.afg.sunLight = star; } if (body.scaledBody.GetComponent <MaterialSetDirection>() != null) { body.scaledBody.GetComponent <MaterialSetDirection>().target = star.transform; } foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true)) { msd.target = star.transform; } // Contract Weight if (ContractSystem.ContractWeights != null) { if (body.Has("contractWeight")) { if (ContractSystem.ContractWeights.ContainsKey(body.name)) { ContractSystem.ContractWeights[body.name] = body.Get <Int32>("contractWeight"); } else { ContractSystem.ContractWeights.Add(body.name, body.Get <Int32>("contractWeight")); } } } } foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>()) { anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform; } #if FALSE foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>()) { anim.gameObject.AddOrGetComponent <KopernicusStarTimeOfDay>(); } foreach (GalaxyCubeControl control in Resources.FindObjectsOfTypeAll <GalaxyCubeControl>()) { control.gameObject.AddOrGetComponent <KopernicusStarGalaxyCubeControl>(); } foreach (SkySphereControl control in Resources.FindObjectsOfTypeAll <SkySphereControl>()) { control.gameObject.AddOrGetComponent <KopernicusStarSkySphereControl>(); } #endif }); GameEvents.onProtoVesselLoad.Add(TransformBodyReferencesOnLoad); GameEvents.onProtoVesselSave.Add(TransformBodyReferencesOnSave); // Update Music Logic if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null) { MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth; } // Log Logger.Default.Log("[Kopernicus] RuntimeUtility Started"); Logger.Default.Flush(); }
// Awake() is the first function called in the lifecycle of a Unity3D MonoBehaviour. In the case of KSP, // it happens to be called right before the game's PSystem is instantiated from PSystemManager.Instance.systemPrefab public void Awake() { // Abort, if KSP isn't compatible if (!CompatibilityChecker.IsCompatible()) { String supported = CompatibilityChecker.VERSION_MAJOR + "." + CompatibilityChecker.VERSION_MINOR + "." + CompatibilityChecker.REVISION; String current = Versioning.version_major + "." + Versioning.version_minor + "." + Versioning.Revision; Debug.LogWarning("[Kopernicus] Detected incompatible install.\nCurrent version of KSP: " + current + ".\nSupported version of KSP: " + supported + ".\nPlease wait, until Kopernicus gets updated to match your version of KSP."); Debug.Log("[Kopernicus] Aborting..."); // Abort Destroy(this); return; } // Log the current version to the log String kopernicusVersion = CompatibilityChecker.VERSION_MAJOR + "." + CompatibilityChecker.VERSION_MINOR + "." + CompatibilityChecker.REVISION + "-" + CompatibilityChecker.KOPERNICUS; String kspVersion = Versioning.version_major + "." + Versioning.version_minor + "." + Versioning.Revision; Debug.Log("[Kopernicus] Running Kopernicus " + kopernicusVersion + " on KSP " + kspVersion); // Wrap this in a try - catch block so we can display a warning if Kopernicus fails to load for some reason try { // We're ALIVE IsInPrefab = true; Logger.Default.SetAsActive(); Logger.Default.Log("Injector.Awake(): Begin"); //Utility.DumpBuiltinTextures(); // Parser Config ParserOptions.Register("Kopernicus", new ParserOptions.Data { ErrorCallback = e => Logger.Active.LogException(e), LogCallback = s => Logger.Active.Log(s) }); // Yo garbage collector - we have work to do man DontDestroyOnLoad(this); // If the planetary manager does not work, well, error out if (PSystemManager.Instance == null) { // Log the error Logger.Default.Log("Injector.Awake(): If PSystemManager.Instance is null, there is nothing to do"); DisplayWarning(); return; } // Was the system template modified? #if !DEBUG String systemCfgPath = KSPUtil.ApplicationRootPath + "GameData/Kopernicus/Config/System.cfg"; if (File.Exists(systemCfgPath)) { Byte[] data = File.ReadAllBytes(systemCfgPath); SHA256 sha256 = SHA256.Create(); String checksum = BitConverter.ToString(sha256.ComputeHash(data)); checksum = checksum.Replace("-", ""); checksum = checksum.ToLower(); if (checksum != CONFIG_CHECKSUM) { throw new Exception( "The file 'Kopernicus/Config/System.cfg' was modified directly without ModuleManager"); } } #endif // Backup the old prefab StockSystemPrefab = PSystemManager.Instance.systemPrefab; // Fire Pre-Load Event Events.OnPreLoad.Fire(); // Get the current time DateTime start = DateTime.Now; // Get the configNode ConfigNode kopernicus = GameDatabase.Instance.GetConfigs(ROOT_NODE_NAME)[0].config; // THIS IS WHERE THE MAGIC HAPPENS - OVERWRITE THE SYSTEM PREFAB SO KSP ACCEPTS OUR CUSTOM SOLAR SYSTEM AS IF IT WERE FROM SQUAD PSystemManager.Instance.systemPrefab = Parser.CreateObjectFromConfigNode <Loader>(kopernicus, "Kopernicus").SystemPrefab; // Clear space center instance so it will accept nouveau Kerbin SpaceCenter.Instance = null; // Add a handler so that we can do post spawn fixups. PSystemManager.Instance.OnPSystemReady.Add(PostSpawnFixups); // Fire Post-Load Event Events.OnPostLoad.Fire(PSystemManager.Instance.systemPrefab); // Done executing the awake function TimeSpan duration = DateTime.Now - start; Logger.Default.Log("Injector.Awake(): Completed in: " + duration.TotalMilliseconds + " ms"); Logger.Default.Flush(); IsInPrefab = false; } catch (Exception e) { // Log the exception Debug.LogException(e); // Open the Warning popup DisplayWarning(); } }
// Awake() - flag this class as don't destroy on load and register delegates void Awake() { // Don't run if Kopernicus isn't compatible if (!CompatibilityChecker.IsCompatible()) { Destroy(this); return; } // Make sure the runtime utility isn't killed DontDestroyOnLoad(this); // Add handlers GameEvents.onPartUnpack.Add(OnPartUnpack); GameEvents.onLevelWasLoaded.Add(FixCameras); GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene) { if (HighLogic.LoadedSceneHasPlanetarium && MapView.fetch != null) { MapView.fetch.max3DlineDrawDist = 20000f; } if (scene == GameScenes.MAINMENU) { UpdateMenu(); } if (scene == GameScenes.SPACECENTER) { PatchFI(); } foreach (CelestialBody body in PSystemManager.Instance.localBodies) { GameObject star_ = KopernicusStar.GetNearest(body).gameObject; if (body.afg != null) { body.afg.sunLight = star_; } if (body.scaledBody.GetComponent <MaterialSetDirection>() != null) { body.scaledBody.GetComponent <MaterialSetDirection>().target = star_.transform; } foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true)) { msd.target = star_.transform; } } foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>()) { anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform; } }); // Update Music Logic if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null) { MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth; } // Stars GameObject gob = Sun.Instance.gameObject; KopernicusStar star = gob.AddComponent <KopernicusStar>(); Utility.CopyObjectFields(Sun.Instance, star, false); DestroyImmediate(Sun.Instance); Sun.Instance = star; // More stars foreach (CelestialBody body in PSystemManager.Instance.localBodies.Where(b => b.flightGlobalsIndex != 0 && b.scaledBody.GetComponentsInChildren <SunShaderController>(true).Length > 0)) { GameObject starObj = Instantiate(Sun.Instance.gameObject); KopernicusStar star_ = starObj.GetComponent <KopernicusStar>(); star_.sun = body; starObj.transform.parent = Sun.Instance.transform.parent; starObj.name = body.name; starObj.transform.localPosition = Vector3.zero; starObj.transform.localRotation = Quaternion.identity; starObj.transform.localScale = Vector3.one; starObj.transform.position = body.position; starObj.transform.rotation = body.rotation; } // Log Logger.Default.Log("[Kopernicus]: RuntimeUtility Started"); Logger.Default.Flush(); }