Exemple #1
0
        /// <summary>
        /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed.
        /// </summary>
        /// <param name="scenario">Your instance of CommNetScenario.</param>
        /// <param name="CustomCommNetNetwork">The handle of the CommNetNetwork object that is being implemented.</param>
        /// <returns>True if CommNetManager or the supplied Net was instantiated, False if not.</returns>
        public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario, out CommNetNetwork CustomCommNetNetwork)
        {
            CustomCommNetNetwork = null;
            //Replace the CommNet network
            CommNetNetwork stockNet = UnityEngine.Object.FindObjectOfType <CommNetNetwork>();

            if (CommNetManagerInstalled)
            {
                if (stockNet.GetType() == CommNetManager)
                {
                    CustomCommNetNetwork = stockNet;
                    return(true);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(CommNetManager);
            }
            else
            {
                return(false);
            }

            if (!(CustomCommNetNetwork == null))
            {
                UnityEngine.Object.Destroy(stockNet);
                _commNetwork = CustomCommNetNetwork;
                //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work
                return(true);
            }
            else
            {
                CustomCommNetNetwork = stockNet;
                _commNetwork         = stockNet;
                return(false);
            }
        }
Exemple #2
0
        public void Start()
        {
            if (!varLoaded)
            {
                customGameVariables = GameVariables.Instance.gameObject.AddComponent <CustomGameVariables>();
                customGameVariables.Load(GameVariables.Instance);
                GameVariables.Instance = customGameVariables;
                // Make sure the network uses the new config. I could not find an event that only update the TrackingStation
                // But I guess something exist for when you update it....
                if (CommNetNetwork.Instance != null)
                {
                    CommNetNetwork.Reset();
                }

                log(customGameVariables.ToString());

                // We have to reload everything at each scene changes because the game mess up some of the values...
                GameEvents.onLevelWasLoaded.Add(LoadUpgradesPricesSceneChange);

                // The "Switch Editor" button also reset everything
                GameEvents.onEditorRestart.Add(LoadUpgradesPrices);

                BreakStuff();
            }
        }
Exemple #3
0
 protected override void OnStart()
 {
     if (this.vessel != null)
     {
         //if this connection is stock, replace it with this custom connection
         if (this.vessel.connection != null && this.vessel.connection is CommNetVessel && CommNetNetwork.Initialized)
         {
             CommNetNetwork.Remove(this.vessel.connection.Comm); //delete stock node from commnet network
             //UnityEngine.Object.DestroyObject(this.vessel.connection); // don't do this. there are still action-call leftovers of stock CommNetVessel
             this.vessel.connection = this;
         }
     }
     base.OnStart();
 }
Exemple #4
0
        public void Start()
        {
            if (!varLoaded)
            {
                customGameVariables = GameVariables.Instance.gameObject.AddComponent <CustomGameVariables>();
                customGameVariables.Load(GameVariables.Instance);
                GameVariables.Instance = customGameVariables;
                // Make sure the network uses the new config. I could not find an event that only update the TrackingStation
                // But I guess something exist for when you update it....
                CommNetNetwork.Reset();
                varLoaded = true;

                log(customGameVariables.ToString());

                GameEvents.onLevelWasLoaded.Add(LoadUpgradesPrices);
            }
        }
Exemple #5
0
        protected override void Start()
        {
            if (Features.KCommNet)
            {
                Instance = this;
                Cache.InitGroundStation();
                Cache.refreshCommNode = true;

                Lib.Debug("KCommNet Scenario loading ...");
                //Replace the CommNet user interface
                CommNetUI ui = FindObjectOfType <CommNetUI>();
                CustomCommNetUI = gameObject.AddComponent <KCommNetUI>();
                Destroy(ui);

                //Replace the CommNet network
                CommNetNetwork net = FindObjectOfType <CommNetNetwork>();
                CustomCommNetNetwork = gameObject.AddComponent <KCommNetNetwork>();
                Destroy(net);

                //Replace the CommNet ground stations
                CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
                for (int i = 0; i < homes.Length; i++)
                {
                    KCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(KCommNetHome)) as KCommNetHome;
                    customHome.CopyOf(homes[i]);
                    Destroy(homes[i]);
                    //DB.Station(customHome.nodeName);
                    Cache.LoadGroundStation(customHome);
                }

                //Replace the CommNet celestial bodies
                CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
                for (int i = 0; i < bodies.Length; i++)
                {
                    KCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(KCommNetBody)) as KCommNetBody;
                    customBody.CopyOf(bodies[i]);
                    Destroy(bodies[i]);
                }
                Lib.Verbose("CommNet Scenario loading done!");
            }
        }
Exemple #6
0
        /// <summary>
        /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed or a supplied type if it is not.
        /// </summary>
        /// <param name="scenario">Your instance of CommNetScenario.</param>
        /// <param name="derivativeOfCommNetNetwork">Type of your network to instantiate if CommNetManager is not installed.</param>
        /// <param name="CustomCommNetNetwork">The handle of the CommNetNetwork object that is being implemented.</param>
        /// <returns>True if CommNetManager or the supplied Net was instantiated, false if not.</returns>
        public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario, Type derivativeOfCommNetNetwork, out CommNetNetwork CustomCommNetNetwork)
        {
            CustomCommNetNetwork = null;
            //Replace the CommNet network
            CommNetNetwork stockNet = CommNetScenario.FindObjectOfType <CommNetNetwork>();

            if (CommNetManagerInstalled)
            {
                if (stockNet.GetType() == CommNetManager)
                {
                    CustomCommNetNetwork = stockNet;
                    return(true);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(CommNetManager);
            }
            else
            {
                if (!typeof(CommNetNetwork).IsAssignableFrom(derivativeOfCommNetNetwork))
                {
                    UnityEngine.Debug.LogError("The supplied Type in SetCommNetManagerIfAvailable is not a derivative of CommNetNetwork.");
                    return(false);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(derivativeOfCommNetNetwork);
            }

            if (CustomCommNetNetwork != null)
            {
                UnityEngine.Object.Destroy(stockNet);
                _commNetwork = CustomCommNetNetwork;
                //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work
                return(true);
            }
            else
            {
                CustomCommNetNetwork = stockNet;
                _commNetwork         = stockNet;
                return(false);
            }
        }
        protected override void Start()
        {
            CNCCommNetScenario.Instance = this;
            this.commVessels            = new List <CNCCommNetVessel>();
            this.dirtyCommNetVesselList = true;

            CNCLog.Verbose("CommNet Scenario loading ...");

            //Issue #13: Commnet behaves like vanilla when joining a DMP server for the second time.
            //if stock CommNet logic somehow runs (such as the order of CNCCommNetScenario and CommNetScenario in persisten.sfs)
            if (CommNetScenario.Instance != null)
            {
                UnityEngine.Object.DestroyImmediate(CommNetScenario.Instance);
                CNCCommNetScenario.Instance = this;
            }

            //Replace the CommNet user interface
            CommNetUI ui = FindObjectOfType <CommNetUI>();              // the order of the three lines is important

            CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class
            UnityEngine.Object.Destroy(ui);

            //Replace the CommNet network
            CommNetNetwork net = FindObjectOfType <CommNetNetwork>();

            CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>();
            UnityEngine.Object.Destroy(net);
            //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work

            //Replace the TelemetryUpdate
            TelemetryUpdate     tel      = TelemetryUpdate.Instance;                 //only appear in flight
            CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight

            if (tel != null && HighLogic.LoadedSceneIsFlight)
            {
                TelemetryUpdateData tempData = new TelemetryUpdateData(tel);
                UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance
                CustomCommNetTelemetry = gameObject.AddComponent <CNCTelemetryUpdate>();
                CustomCommNetTelemetry.copyOf(tempData);
            }
            else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>();
                CustomCommNetModeButton.copyOf(cnmodeUI);
                UnityEngine.Object.DestroyImmediate(cnmodeUI);
            }

            //Replace the CommNet ground stations
            groundStations.Clear();
            CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
            for (int i = 0; i < homes.Length; i++)
            {
                CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome;
                customHome.copyOf(homes[i]);
                UnityEngine.Object.Destroy(homes[i]);
                groundStations.Add(customHome);
            }
            groundStations.Sort();

            //Apply the ground-station changes from persistent.sfs
            for (int i = 0; i < persistentGroundStations.Count; i++)
            {
                if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID)))
                {
                    groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]);
                }
            }
            persistentGroundStations.Clear();//dont need anymore

            //Replace the CommNet celestial bodies
            CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
            for (int i = 0; i < bodies.Length; i++)
            {
                CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody;
                customBody.copyOf(bodies[i]);
                UnityEngine.Object.Destroy(bodies[i]);
            }

            //Imitate stock CommNetScenario.Instance in order to run certain stock functionalities
            //Comment: Vessel.GetControlLevel() has the check on CommNetScenario.Instance != null before calling vessel.connection.GetControlLevel()
            PropertyInfo property = typeof(CommNetScenario).GetProperty("Instance");

            property.DeclaringType.GetProperty("Instance");
            property.SetValue(CommNetScenario.Instance, this, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);

            CNCLog.Verbose("CommNet Scenario loading done!");
        }
        protected override void Start()
        {
            CNCCommNetScenario.Instance = this;
            this.commVessels            = new List <CNCCommNetVessel>();
            this.dirtyCommNetVesselList = true;

            CNCLog.Verbose("CommNet Scenario loading ...");

            //Replace the CommNet user interface
            CommNetUI ui = FindObjectOfType <CommNetUI>();              // the order of the three lines is important

            CustomCommNetUI = gameObject.AddComponent <CNCCommNetUI>(); // gameObject.AddComponent<>() is "new" keyword for Monohebaviour class
            UnityEngine.Object.Destroy(ui);

            //Replace the CommNet network
            CommNetNetwork net = FindObjectOfType <CommNetNetwork>();

            CustomCommNetNetwork = gameObject.AddComponent <CNCCommNetNetwork>();
            UnityEngine.Object.Destroy(net);
            //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work

            //Replace the TelemetryUpdate
            TelemetryUpdate     tel      = TelemetryUpdate.Instance;                 //only appear in flight
            CommNetUIModeButton cnmodeUI = FindObjectOfType <CommNetUIModeButton>(); //only appear in tracking station; initialised separately by TelemetryUpdate in flight

            if (tel != null && HighLogic.LoadedSceneIsFlight)
            {
                TelemetryUpdateData tempData = new TelemetryUpdateData(tel);
                UnityEngine.Object.DestroyImmediate(tel); //seem like UE won't initialise CNCTelemetryUpdate instance in presence of TelemetryUpdate instance
                CustomCommNetTelemetry = gameObject.AddComponent <CNCTelemetryUpdate>();
                CustomCommNetTelemetry.copyOf(tempData);
            }
            else if (cnmodeUI != null && HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                CustomCommNetModeButton = cnmodeUI.gameObject.AddComponent <CNCCommNetUIModeButton>();
                CustomCommNetModeButton.copyOf(cnmodeUI);
                UnityEngine.Object.DestroyImmediate(cnmodeUI);
            }

            //Replace the CommNet ground stations
            groundStations.Clear();
            CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
            for (int i = 0; i < homes.Length; i++)
            {
                CNCCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(CNCCommNetHome)) as CNCCommNetHome;
                customHome.copyOf(homes[i]);
                UnityEngine.Object.Destroy(homes[i]);
                groundStations.Add(customHome);
            }
            groundStations.Sort();

            //Apply the ground-station changes from persistent.sfs
            for (int i = 0; i < persistentGroundStations.Count; i++)
            {
                if (groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID)))
                {
                    groundStations.Find(x => x.ID.Equals(persistentGroundStations[i].ID)).applySavedChanges(persistentGroundStations[i]);
                }
            }
            persistentGroundStations.Clear();//dont need anymore

            //Replace the CommNet celestial bodies
            CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
            for (int i = 0; i < bodies.Length; i++)
            {
                CNCCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(CNCCommNetBody)) as CNCCommNetBody;
                customBody.copyOf(bodies[i]);
                UnityEngine.Object.Destroy(bodies[i]);
            }

            CNCLog.Verbose("CommNet Scenario loading done!");
        }