Example #1
0
        private void ProcessDefinitionValue(ulong sender, IMsg msg)
        {
            var value = msg as ResearchDefinitionValueMessage;

            if (value == null)
            {
                return;
            }
            SetUiHidden(true);
            Definitions.BeginLoading();
            foreach (var o in value.Definitions)
            {
                Definitions.Load(o);
            }
            Definitions.FinishLoading();
            if (value.ResearchStates != null && value.ResearchIds != null &&
                MyAPIGateway.Session.LocalHumanPlayer != null)
            {
                var owner = GetOrCreatePlayer(MyAPIGateway.Session.LocalHumanPlayer);
                for (var i = 0; i < value.ResearchIds.Length; i++)
                {
                    owner.PlayerResearchState(value.ResearchIds[i], true).State = value.ResearchStates[i];
                }
            }

            SetUiHidden(false);
        }
Example #2
0
        private void LoadResearchData()
        {
            Definitions.BeginLoading();
            foreach (var kv in MyDefinitionManager.Static.GetPrefabDefinitions())
            {
                if (!kv.Key.StartsWith("EqResearch_"))
                {
                    continue;
                }
                foreach (var grid in kv.Value.CubeGrids)
                {
                    foreach (var block in grid.CubeBlocks.OfType <MyObjectBuilder_MyProgrammableBlock>())
                    {
                        try
                        {
                            Ob_ResearchDefinition[] defs;
                            try
                            {
                                try
                                {
                                    defs = MyAPIGateway.Utilities.SerializeFromXML <Ob_ResearchDefinition[]>(block.Program);
                                }
                                catch
                                {
                                    defs = new[] { MyAPIGateway.Utilities.SerializeFromXML <Ob_ResearchDefinition>(block.Program) };
                                }
                            }
                            catch
                            {
                                var raw = Encoding.UTF8.GetString(Convert.FromBase64String(block.Program));
                                try
                                {
                                    defs = MyAPIGateway.Utilities.SerializeFromXML <Ob_ResearchDefinition[]>(raw);
                                }
                                catch
                                {
                                    defs = new[] { MyAPIGateway.Utilities.SerializeFromXML <Ob_ResearchDefinition>(raw) };
                                }
                            }

                            foreach (var k in defs)
                            {
                                Definitions.Load(k);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error(
                                $"Load definition in {kv.Key}/{grid.DisplayName}/{block.CustomName} error: \n{e}");
                        }
                    }
                }
            }

            {
                var aux = Core.ReadXml <Ob_ResearchDefinition[]>(AUX_RESEARCH_STORAGE);
                if (aux != null)
                {
                    foreach (var k in aux)
                    {
                        Definitions.Load(k);
                    }
                }
            }
            Definitions.FinishLoading();
        }