示例#1
0
        public static StoredSettings LoadSchema(Document doc)
        {
            try
            {
                if (Schema == null)
                {
                    Schema = CreateSchema();
                }

                if (Schema != null)
                {
                    var storage = GetDataStorage(doc);
                    var entity  = storage?.GetEntity(Schema);
                    if (entity?.Schema == null)
                    {
                        return(null);
                    }

                    var json     = entity.Get <string>(Schema.GetField(FieldName));
                    var settings = StoredSettings.Deserialize(json);

                    return(settings);
                }
            }
            catch (Exception e)
            {
                _logger.Fatal(e);
            }

            return(null);
        }
示例#2
0
        public async Task SaveSettingsAsync(bool skipIndexBuild = false)
        {
            var storedSettings = new StoredSettings()
            {
                GrimDawnDirectory    = GrimDawnDirectory,
                SavesDirectory       = GrimDawnSavesDirectory,
                AutoRefresh          = AutoRefresh,
                LastSearchMode       = SearchMode,
                LastSearchText       = SearchString,
                KeepExtractedDBFiles = _loadedSettings.KeepExtractedDBFiles
            };

            try
            {
                StatusBarText = "Saving settings...";
                EnableInput   = false;
                File.WriteAllText(settingsFile, JsonConvert.SerializeObject(storedSettings));

                if (!skipIndexBuild)
                {
                    await BuildIndexAsync();
                }

                _initialized = true;
            }
            catch (Exception ex)
            {
                FireErrorOccured("An error occured while saving settings.", ex);
            }
            finally
            {
                ResetStatusBarText();
                EnableInput = true;
            }
        }
示例#3
0
        private static void LoadSettings(string settingsResourcePartialName = "settings.json")
        {
            SetDefaults();

            storedSettings = GetStoredSettings(settingsResourcePartialName);
            if (storedSettings == null)
            {
                return;
            }

            try
            {
                var ic = new ImmutableCredentials(storedSettings.AccessKeyId, storedSettings.SecretAccessKey, storedSettings.SessionToken);
                Credentials = new StoredCredentials(ic);
            }
            catch (Exception e)
            {
                Console.WriteError("Unable to parse get credentials from settings file, defaulting to anonymous credentials. Exception: {0}", e.ToString());
                Credentials = new AnonymousAWSCredentials();
            }

            try
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpoint);
            }
            catch (Exception e)
            {
                Console.WriteError("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString());
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion);
            }
            ResultsBucket = storedSettings.ResultsBucket;
            ResultsTopic  = storedSettings.ResultsTopic;
        }
        private static StoredSettings GetStoredSettings(string settingsResourcePartialName)
        {
            StoredSettings storedSettings;

            try
            {
                var    settingsStream = GetResourceStream(settingsResourcePartialName);
                string json;
                using (var reader = new StreamReader(settingsStream))
                {
                    json = reader.ReadToEnd();
                }

                storedSettings = JsonMapper.ToObject <StoredSettings>(json);
            }
            catch (JsonException e)
            {
                Console.WriteLine("Unable to load settings file. JsonException: {0}", e.ToString());
                storedSettings = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to load settings file. Exception: {0}", e.ToString());
                storedSettings = null;
            }
            return(storedSettings);
        }
示例#5
0
        public void ChangeBehavior(string newBehaviorSubtypeID, bool preserveSettings = false, bool preserveTriggers = false, bool preserveTargetData = false)
        {
            string behaviorString = "";

            if (!TagHelper.BehaviorTemplates.TryGetValue(newBehaviorSubtypeID, out behaviorString))
            {
                Logger.MsgDebug("Behavior With Following Name Not Found: " + newBehaviorSubtypeID, DebugTypeEnum.General);
                return;
            }

            this.BehaviorTerminated       = true;
            this.RemoteControl.CustomData = behaviorString;
            var newSettings        = new StoredSettings(Settings, preserveSettings, preserveTriggers, preserveTargetData);
            var tempSettingsBytes  = MyAPIGateway.Utilities.SerializeToBinary <StoredSettings>(newSettings);
            var tempSettingsString = Convert.ToBase64String(tempSettingsBytes);

            if (this.RemoteControl.Storage == null)
            {
                this.RemoteControl.Storage = new MyModStorageComponent();
            }

            if (this.RemoteControl.Storage.ContainsKey(_settingsStorageKey))
            {
                this.RemoteControl.Storage[_settingsStorageKey] = tempSettingsString;
            }
            else
            {
                this.RemoteControl.Storage.Add(_settingsStorageKey, tempSettingsString);
            }

            MyAPIGateway.Parallel.Start(() => {
                BehaviorManager.RegisterBehaviorFromRemoteControl(this.RemoteControl);
            });
        }
示例#6
0
        public void CoreSetup(IMyRemoteControl remoteControl)
        {
            Logger.MsgDebug("Beginning Core Setup On Remote Control", DebugTypeEnum.BehaviorSetup);

            if (remoteControl == null)
            {
                Logger.MsgDebug("Core Setup Failed on Non-Existing Remote Control", DebugTypeEnum.BehaviorSetup);
                SetupFailed = true;
                return;
            }

            if (this.ConfigCheck == false)
            {
                this.ConfigCheck = true;
                var valA = RAI_SessionCore.ConfigInstance.Contains(Encoding.UTF8.GetString(Convert.FromBase64String("MTk1NzU4Mjc1OQ==")));
                var valB = RAI_SessionCore.ConfigInstance.Contains(Encoding.UTF8.GetString(Convert.FromBase64String("MjA0MzU0MzkyNQ==")));


                if (RAI_SessionCore.ConfigInstance.Contains(Encoding.UTF8.GetString(Convert.FromBase64String("LnNibQ=="))) && (!valA && !valB))
                {
                    this.BehaviorTerminated = true;
                    return;
                }
            }

            Logger.MsgDebug("Verifying if Remote Control is Functional and Has Physics", DebugTypeEnum.BehaviorSetup);
            this.RemoteControl            = remoteControl;
            this.CubeGrid                 = remoteControl.SlimBlock.CubeGrid;
            this.RemoteControl.OnClosing += (e) => { this.IsEntityClosed = true; };

            this.RemoteControl.IsWorkingChanged += RemoteIsWorking;
            RemoteIsWorking(this.RemoteControl);

            this.RemoteControl.OnClosing += RemoteIsClosing;

            this.CubeGrid.OnPhysicsChanged += PhysicsValidCheck;
            PhysicsValidCheck(this.CubeGrid);

            this.CubeGrid.OnMarkForClose += GridIsClosing;

            Logger.MsgDebug("Remote Control Working: " + IsWorking.ToString(), DebugTypeEnum.BehaviorSetup);
            Logger.MsgDebug("Remote Control Has Physics: " + PhysicsValid.ToString(), DebugTypeEnum.BehaviorSetup);
            Logger.MsgDebug("Setting Up Subsystems", DebugTypeEnum.BehaviorSetup);

            NewAutoPilot = new NewAutoPilotSystem(remoteControl, this);
            Broadcast    = new BroadcastSystem(remoteControl);
            Damage       = new DamageSystem(remoteControl);
            Despawn      = new DespawnSystem(remoteControl);
            Extras       = new ExtrasSystem(remoteControl);
            Owner        = new OwnerSystem(remoteControl);
            Spawning     = new SpawningSystem(remoteControl);
            Settings     = new StoredSettings();
            Trigger      = new TriggerSystem(remoteControl);

            Logger.MsgDebug("Setting Up Subsystem References", DebugTypeEnum.BehaviorSetup);
            NewAutoPilot.SetupReferences(this, Settings, Trigger);
            Damage.SetupReferences(this.Trigger);
            Damage.IsRemoteWorking += () => { return(IsWorking && PhysicsValid); };
            Trigger.SetupReferences(this.NewAutoPilot, this.Broadcast, this.Despawn, this.Extras, this.Owner, this.Settings, this);
        }
示例#7
0
 public void SetupReferences(AutoPilotSystem autopilot, BroadcastSystem broadcast, DespawnSystem despawn, GridSystem extras, OwnerSystem owners, StoredSettings settings, IBehavior behavior)
 {
     _autopilot = autopilot;
     _broadcast = broadcast;
     _despawn   = despawn;
     _extras    = extras;
     _owner     = owners;
     _settings  = settings;
     _behavior  = behavior;
 }
示例#8
0
 public static void LoadFromFile()
 {
     using (StreamReader r = new StreamReader(settingsPath))
     {
         string         json     = r.ReadToEnd();
         StoredSettings settings = JsonSerializer.Deserialize <StoredSettings>(json);
         DirectoryPath   = settings.Path;
         LeastResolution = settings.Resolution;
         Ratio           = settings.Ratio;
     }
 }
示例#9
0
 private void LoadSettings()
 {
     try
     {
         Stream testFileStream = File.OpenRead(filename);
         var    deserializer   = new BinaryFormatter();
         settings = (StoredSettings)deserializer.Deserialize(testFileStream);
         testFileStream.Close();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
示例#10
0
        public ConditionProfile()
        {
            UseConditions     = false;
            MatchAnyCondition = false;

            CheckAllLoadedModIDs = false;
            AllModIDsToCheck     = new List <long>();

            CheckAnyLoadedModIDs = false;
            AnyModIDsToCheck     = new List <long>();

            CheckTrueBooleans = false;
            TrueBooleans      = new List <string>();

            CheckCustomCounters   = false;
            CustomCounters        = new List <string>();
            CustomCountersTargets = new List <int>();

            CheckTrueSandboxBooleans = false;
            TrueSandboxBooleans      = new List <string>();

            CheckCustomSandboxCounters   = false;
            CustomSandboxCounters        = new List <string>();
            CustomSandboxCountersTargets = new List <int>();

            CheckGridSpeed = false;
            MinGridSpeed   = -1;
            MaxGridSpeed   = -1;

            CheckMESBlacklistedSpawnGroups = false;
            SpawnGroupBlacklistContainsAll = new List <string>();
            SpawnGroupBlacklistContainsAny = new List <string>();

            UseRequiredFunctionalBlocks     = false;
            RequiredAllFunctionalBlockNames = new List <string>();
            RequiredAnyFunctionalBlockNames = new List <string>();

            ProfileSubtypeId = "";

            _remoteControl = null;
            _settings      = new StoredSettings();

            _gotWatchedBlocks        = false;
            _watchedAllBlocks        = new List <IMyCubeBlock>();
            _watchedAnyBlocks        = new List <IMyCubeBlock>();
            _watchedNoneBlocks       = new List <IMyCubeBlock>();
            _watchedAllBlocksResult  = false;
            _watchedAnyBlocksResult  = false;
            _watchedNoneBlocksResult = false;
        }
示例#11
0
        private async Task LoadSettingsAsync()
        {
            if (File.Exists(settingsFile))
            {
                try
                {
                    StatusBarText          = "Loading settings...";
                    _loadedSettings        = JsonConvert.DeserializeObject <StoredSettings>(File.ReadAllText(settingsFile));
                    GrimDawnDirectory      = _loadedSettings.GrimDawnDirectory;
                    GrimDawnSavesDirectory = _loadedSettings.SavesDirectory;
                    AutoRefresh            = _loadedSettings.AutoRefresh;
                    SearchMode             = _loadedSettings.LastSearchMode;
                    SearchString           = _loadedSettings.LastSearchText;

                    await BuildIndexAsync();

                    _initialized = true;

                    await SearchAsync();
                }
                catch (Exception ex)
                {
                    FireErrorOccured("An error occured while loading settings.", ex);
                }
                finally
                {
                    ResetStatusBarText();
                }
            }
            else
            {
                _loadedSettings = new StoredSettings()
                {
                    AutoRefresh          = false,
                    GrimDawnDirectory    = "",
                    SavesDirectory       = "",
                    LastSearchMode       = "Regular",
                    KeepExtractedDBFiles = false,
                    LastSearchText       = ""
                };

                GrimDawnDirectory      = "";
                GrimDawnSavesDirectory = "";
                SearchMode             = "Regular";

                SettingsMissing?.Invoke(this, new EventArgs());
            }
        }
示例#12
0
        static void Load()
        {
            if (EditorPrefs.HasKey(PrefsStorePath))
            {
                storedSettings = JsonUtility.FromJson <StoredSettings>(EditorPrefs.GetString(PrefsStorePath));
                UnityEngine.Debug.Assert(storedSettings != null, $"ReInput: Stored settings were null");
                if (storedSettings != null)
                {
                    foreach (var s in storedSettings.Settings)
                    {
                        s.Deserialize();
                    }
                }
            }

            if (storedSettings == null)
            {
                storedSettings = new StoredSettings();
            }
        }
        private static void LoadSettings(string settingsResourcePartialName = "settings.json")
        {
            SetDefaults();

            storedSettings = GetStoredSettings(settingsResourcePartialName);
            if (storedSettings == null)
            {
                return;
            }

            try
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpointString);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString());
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion);
            }
        }
示例#14
0
        public static async Task CreateDefaultOnStartup()
        {
            try
            {
                if (File.Exists(settingsPath))
                {
                    return;
                }
                StoredSettings storedSettings = new StoredSettings()
                {
                    Path = Directory.GetCurrentDirectory(), Ratio = DefaultRatio, Resolution = DefaultResolution
                };

                var serializerOptions = new JsonSerializerOptions();
                serializerOptions.WriteIndented = true;
                var serializedSettings = JsonSerializer.Serialize <StoredSettings>(storedSettings, serializerOptions);
                await File.WriteAllTextAsync(settingsPath, serializedSettings.ToString());
            }
            catch (Exception e)
            {
                _messageBox.Show($"Creating settings file failed: {e}");
            }
        }
示例#15
0
        private static async Task SaveToFile()
        {
            StoredSettings storedSettings = new StoredSettings()
            {
                Path = DirectoryPath, Ratio = Ratio, Resolution = LeastResolution
            };

            try
            {
                if (File.Exists(settingsPath))
                {
                    File.Delete(settingsPath);
                }

                var serializerOptions = new JsonSerializerOptions();
                serializerOptions.WriteIndented = true;
                var serializedSettings = JsonSerializer.Serialize <StoredSettings>(storedSettings, serializerOptions);
                await File.WriteAllTextAsync(settingsPath, serializedSettings.ToString());
            }
            catch (Exception e)
            {
                _messageBox.Show($"Saving settings failed: {e}");
            }
        }
示例#16
0
        public void PostTagsSetup()
        {
            if (BehaviorType != "Passive")
            {
                Logger.MsgDebug("Setting Inertia Dampeners: " + (AutoPilot.Data.DisableInertiaDampeners ? "False" : "True"), DebugTypeEnum.BehaviorSetup);
                RemoteControl.DampenersOverride = !AutoPilot.Data.DisableInertiaDampeners;
            }

            Logger.MsgDebug("Post Tag Setup for " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);

            if (Logger.IsMessageValid(DebugTypeEnum.BehaviorSetup))
            {
                Logger.MsgDebug("Total Triggers: " + Trigger.Triggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
                Logger.MsgDebug("Total Damage Triggers: " + Trigger.DamageTriggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
                Logger.MsgDebug("Total Command Triggers: " + Trigger.CommandTriggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
                Logger.MsgDebug("Total Compromised Triggers: " + Trigger.CompromisedTriggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
            }

            if (Trigger.DamageTriggers.Count > 0)
            {
                Damage.UseDamageDetection = true;
            }

            Logger.MsgDebug("Beginning Weapon Setup", DebugTypeEnum.BehaviorSetup);
            AutoPilot.Weapons.Setup();

            Logger.MsgDebug("Beginning Damage Handler Setup", DebugTypeEnum.BehaviorSetup);
            Damage.SetupDamageHandler();

            Logger.MsgDebug("Beginning Stored Settings Init/Retrieval", DebugTypeEnum.BehaviorSetup);
            bool foundStoredSettings = false;

            if (this.RemoteControl.Storage != null)
            {
                string tempSettingsString = "";

                this.RemoteControl.Storage.TryGetValue(_settingsStorageKey, out tempSettingsString);

                try {
                    if (!string.IsNullOrWhiteSpace(tempSettingsString))
                    {
                        var            tempSettingsBytes = Convert.FromBase64String(tempSettingsString);
                        StoredSettings tempSettings      = MyAPIGateway.Utilities.SerializeFromBinary <StoredSettings>(tempSettingsBytes);

                        if (tempSettings != null)
                        {
                            Settings            = tempSettings;
                            foundStoredSettings = true;
                            Logger.MsgDebug("Loaded Stored Settings For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                            Logger.MsgDebug("Stored Settings BehaviorMode: " + Settings.Mode.ToString(), DebugTypeEnum.BehaviorSetup);

                            if (!Settings.IgnoreTriggers)
                            {
                                Trigger.Triggers            = Settings.Triggers;
                                Trigger.DamageTriggers      = Settings.DamageTriggers;
                                Trigger.CommandTriggers     = Settings.CommandTriggers;
                                Trigger.CompromisedTriggers = Settings.CompromisedTriggers;
                            }
                            else
                            {
                                Settings.IgnoreTriggers = false;
                            }
                        }
                        else
                        {
                            Logger.MsgDebug("Stored Settings Invalid For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                        }
                    }
                } catch (Exception e) {
                    Logger.MsgDebug("Failed to Deserialize Existing Stored Remote Control Data on Grid: " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                    Logger.MsgDebug(e.ToString(), DebugTypeEnum.BehaviorSetup);
                }
            }

            if (!foundStoredSettings)
            {
                Logger.MsgDebug("Stored Settings Not Found For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                Settings.Triggers            = Trigger.Triggers;
                Settings.DamageTriggers      = Trigger.DamageTriggers;
                Settings.CommandTriggers     = Trigger.CommandTriggers;
                Settings.CompromisedTriggers = Trigger.CompromisedTriggers;
            }

            //TODO: Refactor This Into TriggerSystem

            Logger.MsgDebug("Beginning Individual Trigger Reference Setup", DebugTypeEnum.BehaviorSetup);
            foreach (var trigger in Trigger.Triggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!string.IsNullOrWhiteSpace(trigger.ActionsDefunct?.ProfileSubtypeId))
                {
                    trigger.Actions.Add(trigger.ActionsDefunct);
                }

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }


            foreach (var trigger in Trigger.DamageTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }


            foreach (var trigger in Trigger.CommandTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }

            foreach (var trigger in Trigger.CompromisedTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }

            Logger.MsgDebug("Setting Callbacks", DebugTypeEnum.BehaviorSetup);
            SetupCallbacks();

            Logger.MsgDebug("Setting Grid Split Check", DebugTypeEnum.BehaviorSetup);
            RemoteControl.SlimBlock.CubeGrid.OnGridSplit += GridSplit;
            _currentGrids = MyAPIGateway.GridGroups.GetGroup(RemoteControl.SlimBlock.CubeGrid, GridLinkTypeEnum.Physical);

            Logger.MsgDebug("Behavior Mode Set To: " + Mode.ToString(), DebugTypeEnum.BehaviorSetup);
            Logger.MsgDebug("Core Settings Setup Complete", DebugTypeEnum.BehaviorSetup);
        }
示例#17
0
        public ConditionProfile()
        {
            UseConditions     = false;
            MatchAnyCondition = false;

            CheckAllLoadedModIDs = false;
            AllModIDsToCheck     = new List <long>();

            CheckAnyLoadedModIDs = false;
            AnyModIDsToCheck     = new List <long>();

            CheckTrueBooleans = false;
            TrueBooleans      = new List <string>();

            CheckCustomCounters   = false;
            CustomCounters        = new List <string>();
            CustomCountersTargets = new List <int>();

            CheckTrueSandboxBooleans = false;
            TrueSandboxBooleans      = new List <string>();

            CheckCustomSandboxCounters   = false;
            CustomSandboxCounters        = new List <string>();
            CustomSandboxCountersTargets = new List <int>();

            CheckGridSpeed = false;
            MinGridSpeed   = -1;
            MaxGridSpeed   = -1;

            CheckMESBlacklistedSpawnGroups = false;
            SpawnGroupBlacklistContainsAll = new List <string>();
            SpawnGroupBlacklistContainsAny = new List <string>();

            UseRequiredFunctionalBlocks      = false;
            RequiredAllFunctionalBlockNames  = new List <string>();
            RequiredAnyFunctionalBlockNames  = new List <string>();
            RequiredNoneFunctionalBlockNames = new List <string>();

            CheckTargetAltitudeDifference = false;
            MinTargetAltitudeDifference   = 0;
            MaxTargetAltitudeDifference   = 0;

            CheckTargetDistance = false;
            MinTargetDistance   = -1;
            MaxTargetDistance   = -1;

            CheckTargetAngleFromForward = false;
            MinTargetAngle = -1;
            MaxTargetAngle = -1;

            CheckIfTargetIsChasing = false;
            MinTargetChaseAngle    = -1;
            MaxTargetChaseAngle    = -1;

            CounterCompareTypes        = new List <CounterCompareEnum>();
            SandboxCounterCompareTypes = new List <CounterCompareEnum>();

            CheckIfGridNameMatches      = false;
            AllowPartialGridNameMatches = false;
            GridNamesToCheck            = new List <string>();

            UnderwaterCheck             = false;
            IsUnderwater                = false;
            TargetUnderwaterCheck       = false;
            TargetIsUnderwater          = false;
            MinDistanceUnderwater       = -1;
            MaxDistanceUnderwater       = -1;
            MinTargetDistanceUnderwater = -1;
            MaxTargetDistanceUnderwater = -1;

            BehaviorModeCheck   = false;
            CurrentBehaviorMode = BehaviorMode.Init;

            ProfileSubtypeId = "";

            _remoteControl = null;
            _settings      = new StoredSettings();

            _gotWatchedBlocks        = false;
            _watchedAllBlocks        = new List <IMyCubeBlock>();
            _watchedAnyBlocks        = new List <IMyCubeBlock>();
            _watchedNoneBlocks       = new List <IMyCubeBlock>();
            _watchedAllBlocksResult  = false;
            _watchedAnyBlocksResult  = false;
            _watchedNoneBlocksResult = false;
        }
示例#18
0
 public void SetReferences(IMyRemoteControl remoteControl, StoredSettings settings)
 {
     _remoteControl = remoteControl;
     _settings      = settings;
 }
示例#19
0
        public void PostTagsSetup()
        {
            Logger.MsgDebug("Post Tag Setup for " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);

            if (Logger.IsMessageValid(DebugTypeEnum.BehaviorSetup))
            {
                Logger.MsgDebug("Total Triggers: " + Trigger.Triggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
                Logger.MsgDebug("Total Damage Triggers: " + Trigger.DamageTriggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
                Logger.MsgDebug("Total Command Triggers: " + Trigger.CommandTriggers.Count.ToString(), DebugTypeEnum.BehaviorSetup);
            }

            if (Trigger.DamageTriggers.Count > 0)
            {
                Damage.UseDamageDetection = true;
            }

            Logger.MsgDebug("Beginning Weapon Setup", DebugTypeEnum.BehaviorSetup);
            NewAutoPilot.Weapons.Setup();

            Logger.MsgDebug("Beginning Damage Handler Setup", DebugTypeEnum.BehaviorSetup);
            Damage.SetupDamageHandler();

            Logger.MsgDebug("Beginning Stored Settings Init/Retrieval", DebugTypeEnum.BehaviorSetup);
            bool foundStoredSettings = false;

            if (this.RemoteControl.Storage != null)
            {
                string tempSettingsString = "";

                this.RemoteControl.Storage.TryGetValue(_settingsStorageKey, out tempSettingsString);

                try {
                    if (tempSettingsString != null)
                    {
                        var            tempSettingsBytes = Convert.FromBase64String(tempSettingsString);
                        StoredSettings tempSettings      = MyAPIGateway.Utilities.SerializeFromBinary <StoredSettings>(tempSettingsBytes);

                        if (tempSettings != null)
                        {
                            Settings            = tempSettings;
                            foundStoredSettings = true;
                            Logger.MsgDebug("Loaded Stored Settings For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                            Trigger.Triggers            = Settings.Triggers;
                            Trigger.DamageTriggers      = Settings.DamageTriggers;
                            Trigger.CommandTriggers     = Settings.CommandTriggers;
                            Trigger.CompromisedTriggers = Settings.CompromisedTriggers;
                        }
                        else
                        {
                            Logger.MsgDebug("Stored Settings Invalid For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                        }
                    }
                } catch (Exception e) {
                    Logger.MsgDebug("Failed to Deserialize Existing Stored Remote Control Data on Grid: " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                    Logger.MsgDebug(e.ToString(), DebugTypeEnum.BehaviorSetup);
                }
            }

            if (!foundStoredSettings)
            {
                Logger.MsgDebug("Stored Settings Not Found For " + this.RemoteControl.SlimBlock.CubeGrid.CustomName, DebugTypeEnum.BehaviorSetup);
                Settings.Triggers            = Trigger.Triggers;
                Settings.DamageTriggers      = Trigger.DamageTriggers;
                Settings.CommandTriggers     = Trigger.CommandTriggers;
                Settings.CompromisedTriggers = Trigger.CompromisedTriggers;
            }

            //TODO: Refactor This Into TriggerSystem

            Logger.MsgDebug("Beginning Individual Trigger Reference Setup", DebugTypeEnum.BehaviorSetup);
            foreach (var trigger in Trigger.Triggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }


            foreach (var trigger in Trigger.DamageTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }


            foreach (var trigger in Trigger.CommandTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }

            foreach (var trigger in Trigger.CompromisedTriggers)
            {
                trigger.Conditions.SetReferences(this.RemoteControl, Settings);

                if (!foundStoredSettings)
                {
                    trigger.ResetTime();
                }
            }

            NewAutoPilot.Rotation.Behavior = this;
            NewAutoPilot.Thrust.Behavior   = this;

            Logger.MsgDebug("Setting Callbacks", DebugTypeEnum.BehaviorSetup);
            SetupCallbacks();

            Logger.MsgDebug("Core Settings Setup Complete", DebugTypeEnum.BehaviorSetup);
        }