コード例 #1
0
 public void LoadScenarioDataIntoGame()
 {
     while (scenarioQueue.Count > 0)
     {
         ScenarioEntry scenarioEntry = scenarioQueue.Dequeue();
         if (scenarioEntry.scenarioName == "ProgressTracking")
         {
             CreateMissingKerbalsInProgressTrackingSoTheGameDoesntBugOut(scenarioEntry.scenarioNode);
         }
         CheckForBlankSceneSoTheGameDoesntBugOut(scenarioEntry);
         ProtoScenarioModule psm = new ProtoScenarioModule(scenarioEntry.scenarioNode);
         if (psm != null)
         {
             if (IsScenarioModuleAllowed(psm.moduleName))
             {
                 DarkLog.Debug("Loading " + psm.moduleName + " scenario data");
                 HighLogic.CurrentGame.scenarios.Add(psm);
             }
             else
             {
                 DarkLog.Debug("Skipping " + psm.moduleName + " scenario data in " + dmpGame.gameMode + " mode");
             }
         }
     }
 }
コード例 #2
0
 private void Update()
 {
     if (workerEnabled)
     {
         if (!registered)
         {
             RegisterGameHooks();
         }
         if (!blockScenarioDataSends)
         {
             if ((Client.realtimeSinceStartup - lastScenarioSendTime) > SEND_SCENARIO_DATA_INTERVAL)
             {
                 SendScenarioModules(false);
             }
             lock (scenarioQueue)
             {
                 while (scenarioQueue.Count > 0)
                 {
                     ScenarioEntry se = scenarioQueue.Dequeue();
                     LoadScenarioData(se);
                 }
             }
         }
     }
     else
     {
         if (registered)
         {
             UnregisterGameHooks();
         }
     }
 }
コード例 #3
0
 public void LoadScenarioDataIntoGame()
 {
     lock (scenarioQueue)
     {
         while (scenarioQueue.Count > 0)
         {
             ScenarioEntry scenarioEntry = scenarioQueue.Dequeue();
             if (scenarioEntry.scenarioName == "ProgressTracking")
             {
                 CreateMissingKerbalsInProgressTrackingSoTheGameDoesntBugOut(scenarioEntry.scenarioNode);
             }
             CheckForBlankSceneSoTheGameDoesntBugOut(scenarioEntry);
             ProtoScenarioModule psm = new ProtoScenarioModule(scenarioEntry.scenarioNode);
             if (psm != null)
             {
                 if (IsScenarioModuleAllowed(psm.moduleName))
                 {
                     DarkLog.Debug("Loading " + psm.moduleName + " scenario data");
                     HighLogic.CurrentGame.scenarios.Add(psm);
                     ByteArray scenarioHashBytes = configNodeSerializer.Serialize(scenarioEntry.scenarioNode);
                     checkData[scenarioEntry.scenarioName] = Common.CalculateSHA256Hash(scenarioHashBytes);
                     ByteRecycler.ReleaseObject(scenarioHashBytes);
                 }
                 else
                 {
                     DarkLog.Debug("Skipping " + psm.moduleName + " scenario data in " + dmpGame.gameMode + " mode");
                 }
             }
         }
     }
 }
コード例 #4
0
 public void LoadScenarioDataIntoGame()
 {
     while (scenarioQueue.Count > 0)
     {
         ScenarioEntry scenarioEntry = scenarioQueue.Dequeue();
         if (scenarioEntry.scenarioName == "ContractSystem")
         {
             RemoveKerbalRescueMissionsSoTheGameDoesntBugOut(scenarioEntry.scenarioNode);
         }
         if (scenarioEntry.scenarioName == "ProgressTracking")
         {
             CreateMissingKerbalsInProgressTrackingSoTheGameDoesntBugOut(scenarioEntry.scenarioNode);
         }
         ProtoScenarioModule psm = new ProtoScenarioModule(scenarioEntry.scenarioNode);
         if (psm != null)
         {
             if (IsScenarioModuleAllowed(psm.moduleName))
             {
                 DarkLog.Debug("Loading " + psm.moduleName + " scenario data");
                 HighLogic.CurrentGame.scenarios.Add(psm);
             }
             else
             {
                 DarkLog.Debug("Skipping " + psm.moduleName + " scenario data in " + Client.fetch.gameMode + " mode");
             }
         }
     }
 }
コード例 #5
0
        public void QueueScenarioData(string scenarioName, ConfigNode scenarioData)
        {
            ScenarioEntry entry = new ScenarioEntry();

            entry.scenarioName = scenarioName;
            entry.scenarioNode = scenarioData;
            scenarioQueue.Enqueue(entry);
        }
コード例 #6
0
 //If the scene field is blank, KSP will throw an error while starting the game, meaning players will be unable to join the server.
 private void CheckForBlankSceneSoTheGameDoesntBugOut(ScenarioEntry scenarioEntry)
 {
     if (scenarioEntry.scenarioNode.GetValue("scene") == string.Empty)
     {
         string nodeName = scenarioEntry.scenarioName;
         ScreenMessages.PostScreenMessage(nodeName + " is badly behaved!");
         DarkLog.Debug(nodeName + " is badly behaved!");
         scenarioEntry.scenarioNode.SetValue("scene", "7, 8, 5, 6, 9");
     }
 }
コード例 #7
0
        private bool DidScenarioChange(ScenarioEntry scenarioEntry)
        {
            string previousScenarioHash = null;
            string currentScenarioHash  = Common.CalculateSHA256Hash(ConfigNodeSerializer.fetch.Serialize(scenarioEntry.scenarioNode));

            if (checkData.TryGetValue(scenarioEntry.scenarioName, out previousScenarioHash))
            {
                return(previousScenarioHash != currentScenarioHash);
            }
            return(true);
        }
コード例 #8
0
        private bool DidScenarioChange(ScenarioEntry scenarioEntry)
        {
            string    previousScenarioHash = null;
            ByteArray scenarioBytes        = configNodeSerializer.Serialize(scenarioEntry.scenarioNode);
            string    currentScenarioHash  = Common.CalculateSHA256Hash(scenarioBytes);

            ByteRecycler.ReleaseObject(scenarioBytes);
            if (checkData.TryGetValue(scenarioEntry.scenarioName, out previousScenarioHash))
            {
                return(previousScenarioHash != currentScenarioHash);
            }
            return(true);
        }
コード例 #9
0
        public void LoadScenarioData(ScenarioEntry entry)
        {
            if (!IsScenarioModuleAllowed(entry.scenarioName))
            {
                DarkLog.Debug("Skipped '" + entry.scenarioName + "' scenario data  in " + dmpGame.gameMode + " mode");
                return;
            }
            //Load data from DMP
            if (entry.scenarioNode == null)
            {
                DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!");
                blockScenarioDataSends = true;
                return;
            }

            //Load data into game
            if (DidScenarioChange(entry))
            {
                bool loaded = false;
                foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
                {
                    if (psm.moduleName == entry.scenarioName)
                    {
                        DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module");
                        try
                        {
                            if (psm.moduleRef == null)
                            {
                                DarkLog.Debug("Fixing null scenario module!");
                                psm.moduleRef = new ScenarioModule();
                            }
                            psm.moduleRef.Load(entry.scenarioNode);
                        }
                        catch (Exception e)
                        {
                            DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                            blockScenarioDataSends = true;
                        }
                        loaded = true;
                    }
                }
                if (!loaded)
                {
                    DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module");
                    LoadNewScenarioData(entry.scenarioNode);
                }
            }
        }
コード例 #10
0
        public void LoadScenarioData(ScenarioEntry entry)
        {
            if (!IsScenarioModuleAllowed(entry.scenarioName))
            {
                DarkLog.Debug("Skipped '" + entry.scenarioName + "' scenario data  in " + Client.fetch.gameMode + " mode");
                return;
            }

            //Load data from DMP
            if (entry.scenarioNode == null)
            {
                DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!");
                blockScenarioDataSends = true;
                return;
            }

            //Load data into game
            bool loaded = false;
            foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
            {
                if (psm.moduleName == entry.scenarioName)
                {
                    DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module");
                    try
                    {
                        if (psm.moduleRef == null)
                        {
                            DarkLog.Debug("Fixing null scenario module!");
                            psm.moduleRef = new ScenarioModule();
                        }
                        psm.moduleRef.Load(entry.scenarioNode);
                    }
                    catch (Exception e)
                    {
                        DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                        blockScenarioDataSends = true;
                    }
                    loaded = true;
                }
            }
            if (!loaded)
            {
                DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module");
                LoadNewScenarioData(entry.scenarioNode);
            }
        }
コード例 #11
0
 public void QueueScenarioData(string scenarioName, ConfigNode scenarioData)
 {
     ScenarioEntry entry = new ScenarioEntry();
     entry.scenarioName = scenarioName;
     entry.scenarioNode = scenarioData;
     scenarioQueue.Enqueue(entry);
 }
コード例 #12
0
        public void LoadScenarioData(ScenarioEntry entry)
        {
            if (!IsScenarioModuleAllowed(entry.scenarioName))
            {
                DarkLog.Debug("Skipped '" + entry.scenarioName + "' scenario data  in " + dmpGame.gameMode + " mode");
                return;
            }
            //Load data from DMP
            if (entry.scenarioNode == null)
            {
                DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!");
                ScreenMessages.PostScreenMessage("Scenario " + entry.scenarioName + " failed to load, blocking scenario uploads.", 10f, ScreenMessageStyle.UPPER_CENTER);
                blockScenarioDataSends = true;
                return;
            }

            //Load data into game
            if (DidScenarioChange(entry))
            {
                bool      loaded        = false;
                ByteArray scenarioBytes = configNodeSerializer.Serialize(entry.scenarioNode);
                checkData[entry.scenarioName] = Common.CalculateSHA256Hash(scenarioBytes);
                ByteRecycler.ReleaseObject(scenarioBytes);
                foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
                {
                    if (psm.moduleName == entry.scenarioName)
                    {
                        DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module");
                        try
                        {
                            if (psm.moduleRef == null)
                            {
                                DarkLog.Debug("Fixing null scenario module!");
                                psm.moduleRef = new ScenarioModule();
                            }
                            bool skipLoad = false;
                            if (beforeCallback.ContainsKey(psm.moduleName))
                            {
                                skipLoad = beforeCallback[psm.moduleName](entry.scenarioNode);
                            }
                            if (!skipLoad)
                            {
                                psm.moduleRef.Load(entry.scenarioNode);
                            }
                            if (afterCallback.ContainsKey(psm.moduleName))
                            {
                                afterCallback[psm.moduleName](entry.scenarioNode);
                            }
                        }
                        catch (Exception e)
                        {
                            DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                            blockScenarioDataSends = true;
                        }
                        loaded = true;
                    }
                }
                if (!loaded)
                {
                    DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module");
                    LoadNewScenarioData(entry.scenarioNode);
                }
            }
        }
コード例 #13
0
 public void LoadScenarioData(ScenarioEntry entry)
 {
     if (entry.scenarioName == "ScenarioDiscoverableObjects")
     {
         DarkLog.Debug("Skipping loading asteroid data - It is created locally");
         return;
     }
     if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode != GameMode.CAREER)
     {
         DarkLog.Debug("Skipping loading career mode data in sandbox");
         return;
     }
     if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode == GameMode.CAREER)
     {
         loadedScience = true;
     }
     //Don't stare directly at the next 7 lines - It's bad for your eyes.
     string tempFile = Path.GetTempFileName();
     using (StreamWriter sw = new StreamWriter(tempFile))
     {
         sw.Write(entry.scenarioData);
     }
     ConfigNode scenarioNode = ConfigNode.Load(tempFile);
     File.Delete(tempFile);
     if (scenarioNode == null)
     {
         DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!");
         blockScenarioDataSends = true;
         return;
     }
     bool loaded = false;
     foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
     {
         if (psm.moduleName == entry.scenarioName)
         {
             DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module");
             try
             {
                 if (psm.moduleRef == null)
                 {
                     DarkLog.Debug("Fixing null scenario module!");
                     psm.moduleRef = new ScenarioModule();
                 }
                 psm.moduleRef.Load(scenarioNode);
             }
             catch (Exception e)
             {
                 DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                 blockScenarioDataSends = true;
             }
             loaded = true;
         }
     }
     if (!loaded)
     {
         DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module");
         ProtoScenarioModule scenarioModule = new ProtoScenarioModule(scenarioNode);
         try
         {
             HighLogic.CurrentGame.scenarios.Add(scenarioModule);
             scenarioModule.Load(ScenarioRunner.fetch);
         }
         catch (Exception e)
         {
             DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
             blockScenarioDataSends = true;
         }
     }
 }
コード例 #14
0
 //If the scene field is blank, KSP will throw an error while starting the game, meaning players will be unable to join the server.
 private void CheckForBlankSceneSoTheGameDoesntBugOut(ScenarioEntry scenarioEntry)
 {
     if (scenarioEntry.scenarioNode.GetValue("scene") == string.Empty)
     {
         string nodeName = scenarioEntry.scenarioName;
         ScreenMessages.PostScreenMessage(nodeName + " is badly behaved!");
         DarkLog.Debug(nodeName + " is badly behaved!");
         scenarioEntry.scenarioNode.SetValue("scene", "7, 8, 5, 6, 9");
     }
 }
コード例 #15
0
        public void LoadScenarioData(ScenarioEntry entry)
        {
            if (entry.scenarioName == "ScenarioDiscoverableObjects")
            {
                DarkLog.Debug("Skipping loading asteroid data - It is created locally");
                return;
            }
            if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode != GameMode.CAREER)
            {
                DarkLog.Debug("Skipping loading career mode data in sandbox");
                return;
            }
            if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode == GameMode.CAREER)
            {
                loadedScience = true;
            }
            //Don't stare directly at the next 7 lines - It's bad for your eyes.
            string tempFile = Path.GetTempFileName();

            using (StreamWriter sw = new StreamWriter(tempFile))
            {
                sw.Write(entry.scenarioData);
            }
            ConfigNode scenarioNode = ConfigNode.Load(tempFile);

            File.Delete(tempFile);
            if (scenarioNode == null)
            {
                DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!");
                blockScenarioDataSends = true;
                return;
            }
            bool loaded = false;

            foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
            {
                if (psm.moduleName == entry.scenarioName)
                {
                    DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module");
                    try
                    {
                        if (psm.moduleRef == null)
                        {
                            DarkLog.Debug("Fixing null scenario module!");
                            psm.moduleRef = new ScenarioModule();
                        }
                        psm.moduleRef.Load(scenarioNode);
                    }
                    catch (Exception e)
                    {
                        DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                        blockScenarioDataSends = true;
                    }
                    loaded = true;
                }
            }
            if (!loaded)
            {
                DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module");
                ProtoScenarioModule scenarioModule = new ProtoScenarioModule(scenarioNode);
                try
                {
                    HighLogic.CurrentGame.scenarios.Add(scenarioModule);
                    scenarioModule.Load(ScenarioRunner.fetch);
                }
                catch (Exception e)
                {
                    DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e);
                    blockScenarioDataSends = true;
                }
            }
        }