コード例 #1
0
ファイル: CoreBase.cs プロジェクト: WhitePhoera/SEModTemplate
 protected void ChangeUpdateOrder(MyUpdateOrder value)
 {
     if (value != UpdateOrder)
     {
         MyAPIGateway.Utilities.InvokeOnGameThread(() => SetUpdateOrder(value));
     }
 }
コード例 #2
0
 public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     // TODO: Better handling of component overrides
     //if(m_sessionComponents.ContainsKey(component.ComponentType))
     m_sessionComponents[component.ComponentType] = component;
     component.Session = this;
     AddComponentForUpdate(updateOrder, component);
 }
コード例 #3
0
        public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
        {
            m_sessionComponents.Add(component.ComponentType, component);

            AddComponentForUpdate(updateOrder, MyUpdateOrder.BeforeSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.Simulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.AfterSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.NoUpdate, component);
        }
コード例 #4
0
        public MySessionComponentBase()
        {
            var type = GetType();
            var attr = (MySessionComponentDescriptor)Attribute.GetCustomAttribute(type, typeof(MySessionComponentDescriptor), false);

            DebugName = type.Name;
            Priority = attr.Priority;
            UpdateOrder = attr.UpdateOrder;
            ObjectBuilderType = attr.ObjectBuilderType;

            if (ObjectBuilderType != MyObjectBuilderType.Invalid)
                MySessionComponentMapping.Map(GetType(), ObjectBuilderType);
        }
コード例 #5
0
        private void AddComponentForUpdate(MyUpdateOrder updateOrder, MyUpdateOrder insertIfOrder, MySessionComponentBase component)
        {
            if ((updateOrder & insertIfOrder) != insertIfOrder)
            {
                return;
            }
            SortedSet <MySessionComponentBase> componentList = null;

            if (!m_sessionComponentsForUpdate.TryGetValue((int)insertIfOrder, out componentList))
            {
                m_sessionComponentsForUpdate.Add((int)insertIfOrder, componentList = new SortedSet <MySessionComponentBase>(SessionComparer));
            }

            componentList.Add(component);
        }
コード例 #6
0
        public MySessionComponentBase()
        {
            var type = GetType();
            var attr = (MySessionComponentDescriptor)Attribute.GetCustomAttribute(type, typeof(MySessionComponentDescriptor), false);

            DebugName         = type.Name;
            Priority          = attr.Priority;
            UpdateOrder       = attr.UpdateOrder;
            ObjectBuilderType = attr.ObjectBuilderType;

            if (ObjectBuilderType != MyObjectBuilderType.Invalid)
            {
                MySessionComponentMapping.Map(GetType(), ObjectBuilderType);
            }
        }
コード例 #7
0
        public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type obType)
        {
            UpdateOrder = updateOrder;
            Priority = priority;
            ObjectBuilderType = obType;

            if (obType != null)
            {
                Debug.Assert(typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType), obType.FullName);

                if (!typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType))
                {
                    ObjectBuilderType = MyObjectBuilderType.Invalid;
                }
            }
        }
コード例 #8
0
        public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type obType, Type registrationType = null)
        {
            UpdateOrder       = updateOrder;
            Priority          = priority;
            ObjectBuilderType = obType;

            if (obType != null)
            {
                Debug.Assert(typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType), obType.FullName);

                if (!typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType))
                {
                    ObjectBuilderType = MyObjectBuilderType.Invalid;
                }
            }

            ComponentType = registrationType;
        }
コード例 #9
0
        public void AddComponentForUpdate(MyUpdateOrder updateOrder, MySessionComponentBase component)
        {
            for (int i = 0; i <= 2; ++i)
            {
                if (((int)updateOrder & (1 << i)) == 0)
                {
                    continue;
                }

                SortedSet <MySessionComponentBase> componentList = null;

                if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
                {
                    m_sessionComponentsForUpdate.Add(1 << i, componentList = new SortedSet <MySessionComponentBase>(SessionComparer));
                }

                componentList.Add(component);
            }
        }
コード例 #10
0
 public void SetComponentUpdateOrder(MySessionComponentBase component, MyUpdateOrder order)
 {
     for (int i = 0; i <= 2; ++i)
     {
         SortedSet <MySessionComponentBase> componentList = null;
         if ((order & (MyUpdateOrder)(1 << i)) != 0)
         {
             if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
             {
                 componentList = new SortedSet <MySessionComponentBase>();
                 m_sessionComponentsForUpdate.Add(i, componentList);
             }
             componentList.Add(component);
         }
         else
         {
             if (m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
             {
                 componentList.Remove(component);
             }
         }
     }
 }
コード例 #11
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type type)
 {
     UpdateOrder = updateOrder;
     Priority = priority;
     ObjectBuilderType = type;
 }
コード例 #12
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority)
     : this(updateOrder, priority, null)
 {
 }
コード例 #13
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder)
     : this(updateOrder, 1000)
 {
 }
コード例 #14
0
 public void SetUpdateOrder(MyUpdateOrder order)
 {
     Session.SetComponentUpdateOrder(this, order);
     UpdateOrder = order;
 }
コード例 #15
0
        public override bool Initialize(out MyUpdateOrder order)
        {
            order = MyUpdateOrder.NoUpdate;
            if (NetworkHandlerSystem.IsClient)
            {
                if (MyAPIGateway.Session.Player == null)
                {
                    return(false);
                }
            }
            /* Handle Server side */
            if (NetworkHandlerSystem.IsServer)
            {
                /* LOAD World Settings */
                try
                {
                    using (var sw = MyAPIGateway.Utilities.ReadFileInWorldStorage(Settings.configFile, typeof(Core)))
                        settings.Load(MyAPIGateway.Utilities.SerializeFromXML <SettingsFile>(sw.ReadToEnd()));
                }
                catch (Exception e)
                {
                    if (e.HResult == -2147024894)  // Unable to find the specified file.
                    {
                        settings = settings.CreateDefaults();
                    }
                    else
                    {
                        MyLog.Default.WriteLine($"Possible Old Settings: {e.Message}");
                        MyLog.Default.WriteLine($"Possible Old SettingsStack: {e.StackTrace}");
                        MyLog.Default.Flush();

                        SettingsFile possibleOldSettings = new SettingsFile();
                        try
                        {
                            using (var sw = MyAPIGateway.Utilities.ReadFileInWorldStorage(Settings.configFile, typeof(Core)))
                                possibleOldSettings = (SettingsFile)MyAPIGateway.Utilities.SerializeFromXML <Settings>(sw.ReadToEnd());

                            using (var sw = MyAPIGateway.Utilities.WriteFileInWorldStorage("config.xml.old", typeof(Core)))
                                sw.Write(MyAPIGateway.Utilities.SerializeToXML(possibleOldSettings));
                            /* Create Defaults then Load and Save Old Settings file */
                            settings = settings.CreateDefaults();
                            settings.Load(possibleOldSettings);
                            MyLog.Default.WriteLine("Successfully Loaded Old World Settings:");
                        }
                        catch (Exception e1)
                        {
                            MyLog.Default.WriteLine($"ERROR Get World Settings: {e1.Message}");
                            MyLog.Default.WriteLine($"ERROR Get World SettingsStack: {e1.StackTrace}");
                            MyLog.Default.Flush();
                            settings = settings.CreateDefaults();
                        }
                    }
                }

                /* Save after loading to add new default settings just incase we added more */
                settings.SaveSettings(true);

                try
                {
                    var cfg = MyAPIGateway.Utilities.ConfigDedicated;
                    cfg.Load();
                    ulong steamId;
                    foreach (string id in cfg.Administrators)
                    {
                        if (ulong.TryParse(id, out steamId))
                        {
                            unlockAllPlayers.Add(steamId, true);
                            MyLog.Default.WriteLine($"Admin Found {steamId}");
                        }
                    }
                    if (unlockAllPlayers.Count() == 0)
                    {
                        MyLog.Default.WriteLine($"No Admins");
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine($"Failed to load Server cfg file: {e.Message}");
                    MyLog.Default.Flush();
                }
                if (settings.AlwaysUnlocked == null)
                {
                    settings.AlwaysUnlocked = new HashSet <SerializableDefinitionId>();
                }
                MyAPIGateway.Session.DamageSystem.RegisterDestroyHandler(0, DestroyHandler);
                MyVisualScriptLogicProvider.PlayerResearchClearAll();
                PrepareCache();
            }
            /* Setup Client and Server wide communication*/
            try
            {
                PlayerInit             = nhs.Create <long>(null, PlayerJoined, EventOptions.OnlyToServer);
                SendUnlockNotification = nhs.Create <MyDefinitionId, string, string>(LearnedById, null, EventOptions.OnlyToTarget);
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine($"Network Notifications ERROR: {e.StackTrace}");
                MyLog.Default.Flush();
            }
            if (NetworkHandlerSystem.IsClient)
            {
                try
                {
                    MyVisualScriptLogicProvider.ResearchListWhitelist(true);
                    MyVisualScriptLogicProvider.PlayerResearchClear();
                    MyLog.Default.WriteLine($"Check ControlledEntity");
                    if (MyAPIGateway.Session.Player.Controller.ControlledEntity != null &&
                        MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity is IMyCharacter)
                    {
                        MyLog.Default.WriteLine($"InvokeOnGameThread Start");
                        MyLog.Default.Flush();
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            try
                            {
                                MyLog.Default.WriteLine($"Start InitPlayer");
                                MyLog.Default.Flush();
                                PlayerInit(MyAPIGateway.Session.Player.PlayerID);
                            }
                            catch (Exception e)
                            {
                                MyLog.Default.WriteLine($"PlayerInit: {e.Message}");
                                MyLog.Default.Flush();
                            }
                        });
                    }
                    else
                    {
                        MyLog.Default.WriteLine($"ControlledEntityChanged");
                        MyLog.Default.Flush();
                        MyAPIGateway.Session.Player.Controller.ControlledEntityChanged += Controller_ControlledEntityChanged;
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine($"NetworkHandlerSystem INIT: {e.Message}");
                    MyLog.Default.Flush();
                }
            }
            GetAllBlocks();
            MyLog.Default.WriteLine($"SUCCESSFUL INIT!");
            MyLog.Default.Flush();
            return(true);
        }
コード例 #16
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type type)
 {
     UpdateOrder       = updateOrder;
     Priority          = priority;
     ObjectBuilderType = type;
 }
コード例 #17
0
 void IMySession.RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     RegisterComponent(component, updateOrder, priority);
 }
コード例 #18
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority)
     : this(updateOrder, priority, null)
 {
 }
コード例 #19
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder)
     : this(updateOrder, 1000)
 {
 }
コード例 #20
0
 public void SetUpdateOrder(MyUpdateOrder order)
 {
     Session.SetComponentUpdateOrder(this, order);
     UpdateOrder = order;
 }
コード例 #21
0
 void IMySession.RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     RegisterComponent(component, updateOrder, priority);
 }
コード例 #22
0
 public abstract bool Initialize(out MyUpdateOrder order);