コード例 #1
0
ファイル: UpdateManager.cs プロジェクト: zrisher/ARMS
        public void Init()
        {
            //Log.DebugLog("entered Init", "Init()");
            try
            {
                if (MyAPIGateway.CubeBuilder == null || MyAPIGateway.Entities == null || MyAPIGateway.Multiplayer == null || MyAPIGateway.Parallel == null ||
                    MyAPIGateway.Players == null || MyAPIGateway.Session == null || MyAPIGateway.TerminalActionsHelper == null || MyAPIGateway.Utilities == null)
                {
                    return;
                }

                if (!MyAPIGateway.Multiplayer.IsServer && MyAPIGateway.Session.Player == null)
                {
                    return;
                }

                Globals.WorldClosed = false;
                Log.DebugLog("World: " + MyAPIGateway.Session.Name + ", Path: " + MyAPIGateway.Session.CurrentPath, Logger.severity.INFO);
                AttributeFinder.InvokeMethodsWithAttribute <OnWorldLoad>();
                MyAPIGateway.Entities.OnCloseAll += UnloadData;

                if (!MyAPIGateway.Multiplayer.MultiplayerActive)
                {
                    Log.AlwaysLog("Single player, running server scripts", Logger.severity.INFO);
                    RegisterScripts_Server();
                }
                else if (MyAPIGateway.Multiplayer.IsServer)
                {
                    Log.AlwaysLog("This is the server, running server scripts", Logger.severity.INFO);
                    RegisterScripts_Server();
                }
                else
                {
                    Log.AlwaysLog("Client, running client scripts only", Logger.severity.INFO);
                }

                if (!CheckFinalBuildConstant("IS_OFFICIAL"))
                {
                    Log.AlwaysLog("Space Engineers build is UNOFFICIAL; this build is not supported. Version: " + MyFinalBuildConstants.APP_VERSION_STRING, Logger.severity.WARNING);
                }
                else if (CheckFinalBuildConstant("IS_DEBUG"))
                {
                    Log.AlwaysLog("Space Engineers build is DEBUG; this build is not supported. Version: " + MyFinalBuildConstants.APP_VERSION_STRING, Logger.severity.WARNING);
                }
                else
                {
                    Log.AlwaysLog("Space Engineers version: " + MyFinalBuildConstants.APP_VERSION_STRING, Logger.severity.INFO);
                }

                Logger.DebugNotify("ARMS DEBUG build loaded", 10000, Logger.severity.INFO);

                ManagerStatus = Status.Initialized;
            }
            catch (Exception ex)
            {
                Log.AlwaysLog("Failed to Init(): " + ex, Logger.severity.FATAL);
                ManagerStatus = Status.Terminated;
            }
        }
コード例 #2
0
ファイル: UpdateManager.cs プロジェクト: zrisher/ARMS
        private void Start()
        {
            RegisterScripts_ClientAndServer();

            // create script for each entity
            HashSet <IMyEntity> allEntities = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(allEntities);

            //Log.DebugLog("Adding all entities", "Init()");
            foreach (IMyEntity entity in allEntities)
            {
                AddEntity(entity);
            }

            MyAPIGateway.Entities.OnEntityAdd += Entities_OnEntityAdd;
            ManagerStatus = Status.Started;

            if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowAutopilot))
            {
                Log.AlwaysLog("Disabling autopilot blocks", Logger.severity.INFO);
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Cockpit), "Autopilot-Block_Large")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Cockpit), "Autopilot-Block_Small")).Enabled = false;
            }
            if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile))
            {
                Log.AlwaysLog("Disabling guided missile blocks", Logger.severity.INFO);
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_SmallMissileLauncher), "Souper_R12VP_Launcher")).Enabled       = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_SmallMissileLauncher), "Souper_R8EA_Launcher")).Enabled        = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_SmallMissileLauncher), "Souper_B3MP_Launcher")).Enabled        = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_LargeMissileTurret), "Souper_Missile_Defense_Turret")).Enabled = false;
            }
            if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowHacker))
            {
                Log.AlwaysLog("Disabling hacker blocks", Logger.severity.INFO);
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_LandingGear), "ARMS_SmallHackerBlock")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_LandingGear), "ARMS_LargeHackerBlock")).Enabled = false;
            }
            if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar))
            {
                Log.AlwaysLog("Disabling radar blocks", Logger.severity.INFO);
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "LargeBlockRadarRynAR")).Enabled   = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "SmallBlockRadarRynAR")).Enabled   = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "Radar_A_Large_Souper07")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "Radar_A_Small_Souper07")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "PhasedArrayRadar_Large_Souper07")).Enabled       = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "PhasedArrayRadar_Small_Souper07")).Enabled       = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "PhasedArrayRadarOffset_Large_Souper07")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "PhasedArrayRadarOffset_Small_Souper07")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "AWACSRadarLarge_JnSm")).Enabled        = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_Beacon), "AWACSRadarSmall_JnSm")).Enabled        = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "AP_Radar_Jammer_Large")).Enabled = false;
                MyDefinitionManager.Static.GetCubeBlockDefinition(new SerializableDefinitionId(typeof(MyObjectBuilder_RadioAntenna), "AP_Radar_Jammer_Small")).Enabled = false;
            }

            AttributeFinder.InvokeMethodsWithAttribute <AfterArmsInit>();
        }
コード例 #3
0
ファイル: UpdateManager.cs プロジェクト: zrisher/ARMS
        protected override void UnloadData()
        {
            base.UnloadData();
            if (MyAPIGateway.Entities != null)
            {
                MyAPIGateway.Entities.OnEntityAdd -= Entities_OnEntityAdd;
                MyAPIGateway.Entities.OnCloseAll  -= UnloadData;
            }

            if (!Globals.WorldClosed)
            {
                MainLock.MainThread_ReleaseExclusive();
                try
                {
                    AttributeFinder.InvokeMethodsWithAttribute <OnWorldClose>();
                }
                catch (Exception ex)
                {
                    // if world is closed by X button, expect an exception
                    Log.AlwaysLog("Exception while unloading: " + ex, Logger.severity.ERROR);
                }
                Globals.WorldClosed = true;
                Profiler.Write();
            }

            // in case SE doesn't clean up properly, clear all fields
            foreach (FieldInfo field in GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!field.IsLiteral && !field.IsInitOnly)
                {
                    field.SetValue(this, null);
                }
            }

            ManagerStatus = Status.Terminated;
        }
コード例 #4
0
ファイル: UpdateManager.cs プロジェクト: zrisher/ARMS
 public override void SaveData()
 {
     AttributeFinder.InvokeMethodsWithAttribute <OnWorldSave>();
 }