Exemplo n.º 1
0
        public void Start()
        {
            this.AdvantageousWarningCanvas.SetActive(false);

            this.KMGameInfo    = this.GetComponent <KMGameInfo>();
            this.KMModSettings = this.GetComponent <KMModSettings>();
            this.KMGamepad     = this.GetComponent <KMGamepad>();

            if (Application.isEditor)
            {
                this.config = new Config {
                    ShowModuleNames = true
                };
                this.StartCoroutine(this.CheckForBombsTest());
            }
            else
            {
                this.RefreshConfig();
                this.KMGameInfo.OnStateChange = this.KMGameInfo_OnStateChange;
                UnityEngine.SceneManagement.SceneManager.sceneLoaded += this.SceneManager_sceneLoaded;
            }

            if (KTInputManager.Instance.IsMotionControlMode())
            {
                this.StartCoroutine(this.SearchForVrControllersCoroutine());
            }
        }
Exemplo n.º 2
0
 void ReplaceBombInfo()
 {
     MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();
     foreach (MonoBehaviour s in scripts)
     {
         IEnumerable <FieldInfo> fields = s.GetType().GetFields();
         foreach (FieldInfo f in fields)
         {
             //if (f.FieldType.Equals(typeof(KMBombInfo)))
             //{
             //Handlers((KMBombInfo)f.GetValue(s));
             //continue;
             //}
             if (f.FieldType.Equals(typeof(KMGameInfo)))
             {
                 KMGameInfo component = (KMGameInfo)f.GetValue(s);
                 component.OnLightsChange += new KMGameInfo.KMLightsChangeDelegate(fakeInfo.OnLights);
                 //component.OnAlarmClockChange += new KMGameInfo.KMAlarmClockChangeDelegate(fakeInfo.OnAlarm);
                 continue;
             }
             if (f.FieldType.Equals(typeof(KMGameCommands)))
             {
                 KMGameCommands component = (KMGameCommands)f.GetValue(s);
                 component.OnCauseStrike += new KMGameCommands.KMCauseStrikeDelegate(fakeInfo.HandleStrike);
                 continue;
             }
         }
     }
 }
Exemplo n.º 3
0
    // Use this for initialization
    private void Start()
    {
        AlarmClockHandler.DebugLog("Starting service");
        _alarmClockHandler = new AlarmClockHandler(_modSettings);
        var failure = false;

        try
        {
            if (CommonReflectedTypeInfo.AlarmClockType == null)
            {
                failure = true;
            }
        }
        catch (Exception ex)
        {
            AlarmClockHandler.DebugLog("Failed due to Exception: {0} - Stack Trace: {1}", ex.Message, ex.StackTrace);
            failure = true;
        }
        if (failure)
        {
            AlarmClockHandler.DebugLog("The reflection component of Alarm Clock Extender failed. Aborting the load");
            return;
        }
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;
        _modSettings.ReadSettings();
        StartCoroutine(_alarmClockHandler.KeepTrackQueueFull());
    }
 private void OnEnable()
 {
     _enabled = true;
     GameInfo = GetComponent <KMGameInfo>();
     GameInfo.OnStateChange += delegate(KMGameInfo.State state) {
         StateChange(state);
     };
 }
Exemplo n.º 5
0
 private void Start()
 {
     Instance = this;
     gameInfo = GetComponent <KMGameInfo>();
     gameInfo.OnStateChange += OnStateChange;
     modConfig = new ModConfig <InternationalSettings>("InternationalSettings");
     ReadSettings();
 }
 private void Start()
 {
     GameCommands            = GetComponent <KMGameCommands>();
     GameInfo                = GetComponent <KMGameInfo>();
     GameInfo.OnStateChange += delegate(KMGameInfo.State state)
     {
         CurrentState = state;
     };
 }
 private void Start()
 {
     GameCommands = GetComponent <KMGameCommands>();
     GameInfo     = GetComponent <KMGameInfo>();
     BombInfo     = GetComponent <KMBombInfo>();
     Service      = GetComponent <KMService>();
     Console      = GetComponent <CommandLineWindow>();
     SetUpCommands();
 }
Exemplo n.º 8
0
 void Start()
 {
     gameInfo = this.GetComponent <KMGameInfo>();
     gameInfo.OnStateChange += OnStateChange;
     bombInfo = this.GetComponent <KMBombInfo>();
     bombInfo.OnBombExploded += OnBombExplodes;
     bombInfo.OnBombSolved   += OnBombDefused;
     setPins();
     //StartCoroutine(checkBombState());
 }
Exemplo n.º 9
0
        private void Awake()
        {
            _gameInfo = GetComponent <KMGameInfo>();

            _properties = GetComponentInChildren <APIProperties>();
            _properties.Add("SupportedModes", () => FactoryGameModePicker.GetModeNames, null);
            _properties.Add("EnabledModes", () => FactoryGameModePicker.GetModeSupport, null);

            _binderConverter = GetComponentInChildren <ResultBinderConverter>(true);
        }
Exemplo n.º 10
0
    private void Start()
    {
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        _modSettings = GetComponent <KMModSettings>();

        ModSettingsJSON settings = JsonConvert.DeserializeObject <ModSettingsJSON>(_modSettings.Settings);

        if (settings == null)
        {
            DebugHelper.LogError("Failed to read connection settings from mod settings.");
            return;
        }

        DebugMode = (settings.debug == true);

        _ircConnection = new IRCConnection(settings.authToken, settings.userName, settings.channelName, settings.serverName, settings.serverPort);
        _ircConnection.Connect();

        _coroutineCanceller = new CoroutineCanceller();

        _coroutineQueue = GetComponent <CoroutineQueue>();
        _coroutineQueue.coroutineCanceller = _coroutineCanceller;

        logUploader = GetComponent <LogUploader>();
        logUploader.ircConnection = _ircConnection;

        urlHelper = GetComponent <UrlHelper>();
        urlHelper.ChangeMode(settings.shortUrls == true);

        _leaderboard = new Leaderboard();
        _leaderboard.LoadDataFromFile();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        TwitchPlaySettings.LoadDataFromFile();

        UserAccess.AddUser(settings.userName, AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.AddUser(settings.channelName.Replace("#", ""), AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.WriteAccessList();

        SetupResponder(bombMessageResponder);
        SetupResponder(postGameMessageResponder);
        SetupResponder(missionMessageResponder);
        SetupResponder(miscellaneousMessageResponder);

        bombMessageResponder.leaderboard          = _leaderboard;
        postGameMessageResponder.leaderboard      = _leaderboard;
        miscellaneousMessageResponder.leaderboard = _leaderboard;

        bombMessageResponder.parentService = this;
    }
 private void OnEnable()
 {
     handlers = new DiscordRpc.EventHandlers();
     DiscordRpc.Initialize("523242657040826400", ref handlers, true, "341800");
     presence.largeImageKey = "ktane";
     presence.details       = "Loading KTaNE";
     DiscordRpc.UpdatePresence(presence);
     _gameInfo = GetComponent <KMGameInfo>();
     _bombInfo = GetComponent <KMBombInfo>();
     _gameInfo.OnStateChange  += StateChange;
     _bombInfo.OnBombExploded += BombExploded;
 }
Exemplo n.º 12
0
 internal static void Assign(this KMGameInfo kmGameInfo,
                             Func <bool, Action> onAlarmClockChange = null,
                             Func <bool, Action> onLightsChange     = null)
 {
     if (onAlarmClockChange != null)
     {
         kmGameInfo.OnAlarmClockChange += on => onAlarmClockChange(on);
     }
     if (onLightsChange != null)
     {
         kmGameInfo.OnLightsChange += on => onLightsChange(on);
     }
 }
Exemplo n.º 13
0
    private void Start()
    {
        Instance = this;

        transform.Find("Prefabs").gameObject.SetActive(false);
        twitchGame = GetComponentInChildren <TwitchGame>(true);

        twitchGame.twitchBombPrefab    = GetComponentInChildren <TwitchBomb>(true);
        twitchGame.twitchModulePrefab  = GetComponentInChildren <TwitchModule>(true);
        twitchGame.moduleCamerasPrefab = GetComponentInChildren <ModuleCameras>(true);

        TwitchGame.Instance = twitchGame;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        CoroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();
        LeaderboardController.Install();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        AuditLog.SetupLog();
        MainThreadQueue.Initialize();

        TwitchPlaySettings.LoadDataFromFile();

        MusicPlayer.LoadMusic();

        IRCConnection.Instance.OnMessageReceived.AddListener(OnMessageReceived);

        twitchGame.ParentService = this;

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;         // TODO: Useless variable?
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }

        UpdateUiHue();
        SetupChatSimulator();
    }
Exemplo n.º 14
0
        private void Awake()
        {
            Debug.Log("[Extended Mission Settings] Awakening");
            DestroyImmediate(GetComponent <KMService>());            //Hide from Mod Selector
            _gameInfo     = GetComponent <KMGameInfo>();
            _gameCommands = GetComponent <KMGameCommands>();

            GameObject infoObject = new GameObject("ExtendedMissionSettingsProperties");

            infoObject.transform.parent      = gameObject.transform;
            PublicProperties                 = infoObject.AddComponent <ExtendedMissionSettingsProperties>();
            PublicProperties.MissionExtender = this;
            LoadMod();
            _started = true;
            Debug.Log("[Extended Mission Settings] Awoken");
        }
Exemplo n.º 15
0
 internal static void Unassign(this KMGameInfo kmGameInfo,
                               Func <bool, Action> onAlarmClockChange = null,
                               Func <bool, Action> onLightsChange     = null)
 {
     if (kmGameInfo == null)
     {
         throw new ArgumentNullException("The KMGameInfo is null. You cannot assign events to a KMGameInfo without a reference to a KMGameInfo.");
     }
     if (onAlarmClockChange != null)
     {
         kmGameInfo.OnAlarmClockChange -= on => onAlarmClockChange(on);
     }
     if (onLightsChange != null)
     {
         kmGameInfo.OnLightsChange -= on => onLightsChange(on);
     }
 }
Exemplo n.º 16
0
    void Awake()
    {
        Debug.Log("[CompetitiveLogger] Initializing...");

        // Register bomb info listeners as a just-in-case
        bombInfo = GetComponent <KMBombInfo>();
        bombInfo.OnBombExploded += OnBombExplodes;
        bombInfo.OnBombSolved   += OnBombDefused;

        // Register game state listener
        gameInfo = GetComponent <KMGameInfo>();
        gameInfo.OnStateChange += OnStateChange;

        // Replace the default logger
        replaceLogger();

        Debug.Log("[CompetitiveLogger] Done initializing.");
    }
    private void Start()
    {
        transform.Find("Prefabs").gameObject.SetActive(false);
        bombMessageResponder          = GetComponentInChildren <BombMessageResponder>(true);
        postGameMessageResponder      = GetComponentInChildren <PostGameMessageResponder>(true);
        missionMessageResponder       = GetComponentInChildren <MissionMessageResponder>(true);
        miscellaneousMessageResponder = GetComponentInChildren <MiscellaneousMessageResponder>(true);

        bombMessageResponder.twitchBombHandlePrefab      = GetComponentInChildren <TwitchBombHandle>(true);
        bombMessageResponder.twitchComponentHandlePrefab = GetComponentInChildren <TwitchComponentHandle>(true);
        bombMessageResponder.moduleCamerasPrefab         = GetComponentInChildren <ModuleCameras>(true);

        BombMessageResponder.Instance = bombMessageResponder;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        _coroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        TwitchPlaySettings.LoadDataFromFile();

        SetupResponder(bombMessageResponder);
        SetupResponder(postGameMessageResponder);
        SetupResponder(missionMessageResponder);
        SetupResponder(miscellaneousMessageResponder);

        bombMessageResponder.parentService = this;

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }
    }
Exemplo n.º 18
0
    private void Start()
    {
        _started = true;
        DebugLog("Service prefab Instantiated.");
        _modSettings = new Settings(GetComponent <KMModSettings>());

        if (!_modSettings.ReadSettings())
        {
            DebugLog("Failed to initialize Mod settings. Aborting load");
            return;
        }
        Settings = _modSettings;

        _gameInfo = GetComponent <KMGameInfo>();
        LoadMod();


        DebugLog("Service started");
    }
    private void Start()
    {
        _widgetGeneratorType = ReflectionHelper.FindType("WidgetGenerator");
        _widgetCountField    = _widgetGeneratorType.GetField("NumberToGenerate", BindingFlags.Instance | BindingFlags.Public);

        _indicatorWidgetType  = ReflectionHelper.FindType("IndicatorWidget");
        _indicatorLabelsField = _indicatorWidgetType.GetField("Labels", BindingFlags.Public | BindingFlags.Static);
        _knownIndicators      = (List <string>)_indicatorLabelsField.GetValue(null);
        InitCustomIndicators();

        _serialNumberType       = ReflectionHelper.FindType("SerialNumber");
        _serialStringField      = _serialNumberType.GetField("serialString", BindingFlags.NonPublic | BindingFlags.Instance);
        _serialNumberArrayField = _serialNumberType.GetField("possibleCharArray", BindingFlags.NonPublic | BindingFlags.Instance);

        KMGameInfo gameInfoComponent = GetComponent <KMGameInfo>();

        gameInfoComponent.OnStateChange  += OnStateChange;
        gameInfoComponent.OnLightsChange += OnLightsChange;
    }
Exemplo n.º 20
0
    private void Start()
    {
        _started = true;
        DebugLog("Service prefab Instantiated.");
        ApplyBugFixes();
        //DestroyImmediate(GetComponent<KMService>()); //Hide from Mod Selector
        _modSettings = new Settings(GetComponent <KMModSettings>());

        if (!Initialize())
        {
            DebugLog("Failed to initialize the reflection component of Vanilla Rule Modifier. Aborting load");
            return;
        }
        if (!_modSettings.ReadSettings())
        {
            DebugLog("Failed to initialize Mod settings. Aborting load");
            return;
        }

        GameObject infoObject = new GameObject("VanillaRuleModifierProperties");

        infoObject.transform.parent            = gameObject.transform;
        PublicProperties[0]                    = infoObject.AddComponent <RuleSeedModifierProperties>();
        PublicProperties[0].VanillaRuleModifer = this;

        GameObject infoObject2 = new GameObject("RuleSeedModifierProperties");

        infoObject2.transform.parent           = gameObject.transform;
        PublicProperties[1]                    = infoObject2.AddComponent <RuleSeedModifierProperties>();
        PublicProperties[1].VanillaRuleModifer = this;

        foreach (string mod in ModsThatSupportRuleSeedModifier)
        {
            RuleSeedModifierProperties.AddSupportedModule(mod);
        }

        _gameInfo = GetComponent <KMGameInfo>();
        LoadMod();

        DebugLog("Service started");
    }
    private void Awake()
    {
        _properties = GetComponentInChildren <APIProperties>();
        _properties.Add("AddPageMethod", () => (Action <KMSelectable>)PageManager.AddPagePrefab, null);
        _properties.Add("AddPagesMethod", () => (Action <KMSelectable[]>)PageManager.AddPagePrefabs, null);
        _properties.Add("AddHomePageMethod", () => (Action <string, KMSelectable, Texture2D>)PageManager.AddHomePageEntry, null);
        _properties.Add("GoToPageMethod", () => (Action <string>)FindObjectOfType <PageNavigation>().GoToPage, null);
        _properties.Add("GoBackMethod", () => (Action)FindObjectOfType <PageNavigation>().GoBack, null);

        _properties.Add("AllMods", () => GetAllModNames(), null);
        _properties.Add("AllSolvableModules", () => GetModNames(ModType.SolvableModule), null);
        _properties.Add("AllNeedyModules", () => GetModNames(ModType.NeedyModule), null);
        _properties.Add("AllBombs", () => GetModNames(ModType.Bomb), null);
        _properties.Add("AllWidgets", () => GetModNames(ModType.Widget), null);
        _properties.Add("AllGameplayRooms", () => GetModNames(ModType.GameplayRoom), null);
        _properties.Add("AllServices", () => GetModNames(ModType.Service), null);

        _properties.Add("GetModuleDisplayNameMethod", () => (Func <string, string>)GetModuleDisplayName, null);

        _properties.Add("DisabledMods", () => ProfileManager.ActiveDisableSet, null);
        _properties.Add("DisabledSolvableModules", () => ProfileManager.GetActiveDisableList(ModType.SolvableModule), null);
        _properties.Add("DisabledNeedyModules", () => ProfileManager.GetActiveDisableList(ModType.NeedyModule), null);
        _properties.Add("DisabledBombs", () => ProfileManager.GetActiveDisableList(ModType.Bomb), null);
        _properties.Add("DisabledWidgets", () => ProfileManager.GetActiveDisableList(ModType.Widget), null);
        _properties.Add("DisabledGameplayRooms", () => ProfileManager.GetActiveDisableList(ModType.GameplayRoom), null);
        _properties.Add("DisabledServices", () => ProfileManager.GetActiveDisableList(ModType.Service), null);

        //TOOD: The above is a little nasty, but not too bad yet. If there's more methods to expose, improve this!

        PageManager.AddPagePrefabs(PagePrefabs);

        PageManager.AddHomePageEntry("Profiles", ProfilesMainPrefab, ProfilesMainIcon);
        PageManager.AddHomePageEntry("Mods Info", ModsMainPrefab, ModsMainIcon);

        KMGameInfo gameInfo = GetComponent <KMGameInfo>();

        gameInfo.OnStateChange += OnStateChange;
    }
Exemplo n.º 22
0
 void ReplaceBombInfo()
 {
     MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();
     foreach (MonoBehaviour s in scripts)
     {
         IEnumerable <FieldInfo> fields = s.GetType().GetFields();
         foreach (FieldInfo f in fields)
         {
             if (f.FieldType.Equals(typeof(KMBombInfo)))
             {
                 KMBombInfo component = (KMBombInfo)f.GetValue(s);
                 component.TimeHandler                 += new KMBombInfo.GetTimeHandler(fakeInfo.GetTime);
                 component.FormattedTimeHandler        += new KMBombInfo.GetFormattedTimeHandler(fakeInfo.GetFormattedTime);
                 component.StrikesHandler              += new KMBombInfo.GetStrikesHandler(fakeInfo.GetStrikes);
                 component.ModuleNamesHandler          += new KMBombInfo.GetModuleNamesHandler(fakeInfo.GetModuleNames);
                 component.SolvableModuleNamesHandler  += new KMBombInfo.GetSolvableModuleNamesHandler(fakeInfo.GetSolvableModuleNames);
                 component.SolvedModuleNamesHandler    += new KMBombInfo.GetSolvedModuleNamesHandler(fakeInfo.GetSolvedModuleNames);
                 component.WidgetQueryResponsesHandler += new KMBombInfo.GetWidgetQueryResponsesHandler(fakeInfo.GetWidgetQueryResponses);
                 component.IsBombPresentHandler        += new KMBombInfo.KMIsBombPresent(fakeInfo.IsBombPresent);
                 continue;
             }
             if (f.FieldType.Equals(typeof(KMGameInfo)))
             {
                 KMGameInfo component = (KMGameInfo)f.GetValue(s);
                 component.OnLightsChange += new KMGameInfo.KMLightsChangeDelegate(fakeInfo.OnLights);
                 //component.OnAlarmClockChange += new KMGameInfo.KMAlarmClockChangeDelegate(fakeInfo.OnAlarm);
                 continue;
             }
             if (f.FieldType.Equals(typeof(KMGameCommands)))
             {
                 KMGameCommands component = (KMGameCommands)f.GetValue(s);
                 component.OnCauseStrike += new KMGameCommands.KMCauseStrikeDelegate(fakeInfo.HandleStrike);
                 continue;
             }
         }
     }
 }
Exemplo n.º 23
0
    private void Start()
    {
        KMGameInfo gameInfo = GetComponent <KMGameInfo>();

        gameInfo.OnStateChange += OnStateChange;

        _instance = this;

        DontDestroyOnLoad(gameObject);

        //For modules
        GetSolvableModules();
        GetNeedyModules();
        GetActiveModules();

        //For services
        GetModServices();

        //For all other mod types
        GetModList();

        //Reload the active configuration
        Profile.ReloadActiveConfiguration();
    }
    public override void Start()
    {
        base.Start();
        string name = string.Format("{0} #{1}", Connector.KMBombModule.ModuleDisplayName, Connector.ModuleID);

        _gameInfo = GetComponent <KMGameInfo>();
        _bombInfo = GetComponent <KMBombInfo>();

        _translation = GetComponent <TranslatedTheButton> ();
        _translation.GenerateLanguage(name);
        LanguageTheButton language = _translation.Language;

        // Sets the appearance of the button
        Connector.SetColour(_color = (ButtonColour)Random.Range(0, 4));

        _label = (ButtonLabel)Random.Range(0, 4);
        if (_translation.Language.DisplayMethod == LanguageTheButton.DisplayMethods.CustomTextMesh)
        {
            Connector.SetLabel(language.GetLabelFromEnglishName(_label.ToString()), language.Font, language.FontMaterial, language.GetSizeFromEnglishName(_label.ToString()));
        }
        else
        {
            Connector.SetLabel(language.GetLabelFromEnglishName(_label.ToString()));
        }

        LogFormat(language.RuleColorIs, language.GetLogFromEnglishName(_color.ToString()));
        LogFormat(language.RuleLabelIs, language.GetLogFromEnglishName(_label.ToString()));
        LogFormat(language.RuleButtonShouldBe, (ShouldBeHeld() ? language.RuleHeld : language.RulePressed));

        // Register button hold and released events
        Connector.Held     += Button_In;
        Connector.Released += Button_Out;

        // todo: this seems not needed anymore. Maybe for sprites.
        // Hide our custom text mesh/sprite in the dark.
        //if (_translation.Language.DisplayMethod != LanguageTheButton.DisplayMethods.Default) {
        //	if (_color == ButtonColour.Blue || _color == ButtonColour.Red) {
        //		_gameInfo.OnLightsChange += Connector.ToggleLabel;
        //		Connector.ToggleLabel(false);
        //	}
        //}

        TwitchHelpMessage = string.Format("{1}, {2} - !{0} tap | !{0} hold | !{0} release 7 (releases when there's a 7 in the timer)", "{0}", _translation.Language.NativeName, _translation.Language.Name);

        // Stuff regarding the cover
        var moduleSelectable = GetComponent <KMSelectable>();

        _buttonSelectable            = moduleSelectable.Children[0];
        moduleSelectable.OnHighlight = () => { if (OpenCoverOnSelection)
                                               {
                                                   Connector.OpenCover();
                                               }
        };
        _buttonSelectable.OnHighlight = () => { if (OpenCoverOnSelection)
                                                {
                                                    Connector.OpenCover();
                                                }
        };
        moduleSelectable.OnHighlightEnded = () => { if (OpenCoverOnSelection)
                                                    {
                                                        Connector.CloseCover();
                                                    }
        };
        _buttonSelectable.OnHighlightEnded = () => { if (OpenCoverOnSelection)
                                                     {
                                                         Connector.CloseCover();
                                                     }
        };
        moduleSelectable.OnCancel = () => { Connector.CloseCover(); return(true); };         // Twitch Plays
        if (Application.isEditor)
        {
            // Things work a bit differently in the test harness from the actual game.
            // TODO: There is currently an issue whereby going from one module to another does not call any event.
            moduleSelectable.OnInteract = () => { if (!OpenCoverOnSelection)
                                                  {
                                                      Connector.OpenCover();
                                                  }
                                                  return(true); };
        }
        else
        {
            OpenCoverOnSelection     = Connector.ShouldOpenCoverOnSelection;
            moduleSelectable.OnFocus = () => { if (!OpenCoverOnSelection)
                                               {
                                                   Connector.OpenCover();
                                               }
            };
            moduleSelectable.OnDefocus = () => Connector.CloseCover();
        }
    }
Exemplo n.º 25
0
    public void Awake()
    {
        MainThreadQueue.Initialize();

        GameInfo       = GetComponent <KMGameInfo>();
        SettingWarning = transform.Find("UI").Find("SettingWarning").gameObject;
        BetterCasePicker.BombCaseGenerator = GetComponentInChildren <BombCaseGenerator>();

        modConfig = new ModConfig <TweakSettings>("TweakSettings");
        UpdateSettings();

        bool changeFadeTime = settings.FadeTime >= 0;

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = float.MaxValue;
        FreeplayDevice.MIN_MODULE_COUNT     = 1;

        if (settings.EnableModsOnlyKey)
        {
            var lastFreeplaySettings = FreeplaySettings.CreateDefaultFreeplaySettings();
            lastFreeplaySettings.OnlyMods = true;
            ProgressionManager.Instance.RecordLastFreeplaySettings(lastFreeplaySettings);
        }

        UpdateSettingWarning();

        // Setup API/properties other mods to interact with
        GameObject infoObject = new GameObject("Tweaks_Info", typeof(TweaksProperties));

        infoObject.transform.parent = gameObject.transform;

        // Watch the TweakSettings file for Time Mode state being changed in the office.
        FileSystemWatcher watcher = new FileSystemWatcher(Path.Combine(Application.persistentDataPath, "Modsettings"), "TweakSettings.json")
        {
            NotifyFilter = NotifyFilters.LastWrite
        };

        watcher.Changed += (object source, FileSystemEventArgs e) =>
        {
            if (modConfig.SerializeSettings(settings) == modConfig.SerializeSettings(modConfig.Settings))
            {
                return;
            }

            UpdateSettings();
            UpdateSettingWarning();

            MainThreadQueue.Enqueue(() => StartCoroutine(ModifyFreeplayDevice(false)));
        };

        // Setup our "service" to block the leaderboard submission requests
        ReflectedTypes.InstanceField.SetValue(null, new SteamFilterService());

        // Create a fake case with a bunch of anchors to trick the game when using CaseGenerator.
        TweaksCaseGeneratorCase = new GameObject("TweaksCaseGenerator");
        TweaksCaseGeneratorCase.transform.SetParent(transform);
        var kmBomb = TweaksCaseGeneratorCase.AddComponent <KMBomb>();

        kmBomb.IsHoldable      = false;
        kmBomb.WidgetAreas     = new List <GameObject>();
        kmBomb.visualTransform = transform;
        kmBomb.Faces           = new List <KMBombFace>();

        TweaksCaseGeneratorCase.AddComponent <ModBomb>();

        var kmBombFace = TweaksCaseGeneratorCase.AddComponent <KMBombFace>();

        kmBombFace.Anchors = new List <Transform>();
        kmBomb.Faces.Add(kmBombFace);

        for (int i = 0; i <= 9001; i++)
        {
            kmBombFace.Anchors.Add(transform);
        }

        // Handle scene changes
        UnityEngine.SceneManagement.SceneManager.sceneLoaded += (Scene scene, LoadSceneMode _) =>
        {
            UpdateSettings();
            UpdateSettingWarning();

            Modes.settings           = Modes.modConfig.Settings;
            Modes.modConfig.Settings = Modes.settings;

            if ((scene.name == "mainScene" || scene.name == "gameplayScene") && changeFadeTime)
            {
                SceneManager.Instance.RapidFadeInTime = settings.FadeTime;
            }

            switch (scene.name)
            {
            case "mainScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.SetupState.FadeInTime          =
                        SceneManager.Instance.SetupState.FadeOutTime     =
                            SceneManager.Instance.UnlockState.FadeInTime = settings.FadeTime;
                }

                break;

            case "gameplayLoadingScene":
                var gameplayLoadingManager = FindObjectOfType <GameplayLoadingManager>();
                if (settings.InstantSkip)
                {
                    gameplayLoadingManager.MinTotalLoadTime = 0;
                }
                if (changeFadeTime)
                {
                    gameplayLoadingManager.FadeInTime      =
                        gameplayLoadingManager.FadeOutTime = settings.FadeTime;
                }

                ReflectedTypes.UpdateTypes();

                ReflectedTypes.CurrencyAPIEndpointField?.SetValue(null, settings.FixFER ? "http://api.exchangeratesapi.io" : "http://api.fixer.io");

                break;

            case "gameplayScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.GameplayState.FadeInTime      =
                        SceneManager.Instance.GameplayState.FadeOutTime = settings.FadeTime;
                }

                break;
            }
        };

        // Handle state changes
        GameInfo.OnStateChange += (KMGameInfo.State state) =>
        {
            CurrentState = state;
            watcher.EnableRaisingEvents = state == KMGameInfo.State.Setup;

            if (state == KMGameInfo.State.Gameplay)
            {
                bool disableRecords = settings.BombHUD || settings.ShowEdgework || CurrentMode != Mode.Normal || settings.MissionSeed != -1;

                Assets.Scripts.Stats.StatsManager.Instance.DisableStatChanges        =
                    Assets.Scripts.Records.RecordManager.Instance.DisableBestRecords = disableRecords;
                if (disableRecords)
                {
                    SteamFilterService.TargetMissionID = GameplayState.MissionToLoad;
                }

                BetterCasePicker.HandleCaseGeneration();

                BombStatus.Instance.widgetsActivated = false;
                BombStatus.Instance.HUD.SetActive(settings.BombHUD);
                BombStatus.Instance.Edgework.SetActive(settings.ShowEdgework);
                BombStatus.Instance.ConfidencePrefab.gameObject.SetActive(CurrentMode != Mode.Zen);
                BombStatus.Instance.StrikesPrefab.color = CurrentMode == Mode.Time ? Color.yellow : Color.red;

                Modes.Multiplier = Modes.settings.TimeModeStartingMultiplier;
                BombStatus.Instance.UpdateMultiplier();
                bombWrappers = new BombWrapper[] { };
                StartCoroutine(CheckForBombs());
                if (settings.SkipGameplayDelay)
                {
                    StartCoroutine(SkipGameplayDelay());
                }

                if (GameplayState.BombSeedToUse == -1)
                {
                    GameplayState.BombSeedToUse = settings.MissionSeed;
                }
            }
            else if (state == KMGameInfo.State.Setup)
            {
                if (ReflectedTypes.LoadedModsField.GetValue(ModManager.Instance) is Dictionary <string, Mod> loadedMods)
                {
                    Mod tweaksMod = loadedMods.Values.FirstOrDefault(mod => mod.ModID == "Tweaks");
                    if (tweaksMod != null)
                    {
                        if (CaseGeneratorSettingCache != settings.CaseGenerator)
                        {
                            if (settings.CaseGenerator)
                            {
                                tweaksMod.ModObjects.Add(TweaksCaseGeneratorCase);
                            }
                            else
                            {
                                tweaksMod.ModObjects.Remove(TweaksCaseGeneratorCase);
                            }

                            CaseGeneratorSettingCache = settings.CaseGenerator;
                            UpdateSettingWarning();
                        }
                    }
                }

                StartCoroutine(ModifyFreeplayDevice(true));
                GetComponentInChildren <ModSelectorExtension>().FindAPI();

                GameplayState.BombSeedToUse = -1;
            }
            else if (state == KMGameInfo.State.Transitioning)
            {
                // Because the settings are checked on a scene change and there is no scene change from exiting the gameplay room,
                // we need to update the settings here in case the user changed their HideTOC settings.
                UpdateSettings();

                bool modified       = false;
                var  ModMissionToCs = ModManager.Instance.ModMissionToCs;
                foreach (var metaData in ModMissionToCs)
                {
                    modified |= ModToCMetaData.Add(metaData);
                }

                var unloadedMods = (Dictionary <string, Mod>)ReflectedTypes.UnloadedModsField.GetValue(ModManager.Instance);
                if (unloadedMods != null)
                {
                    foreach (var unloadedMod in unloadedMods.Values)
                    {
                        var tocs = (List <ModTableOfContentsMetaData>)ReflectedTypes.TocsField.GetValue(unloadedMod);
                        if (tocs != null)
                        {
                            foreach (var metaData in tocs)
                            {
                                modified |= ModToCMetaData.Remove(metaData);
                            }
                        }
                    }
                }

                var newToCs = ModToCMetaData.Where(metaData => !settings.HideTOC.Any(pattern => Localization.GetLocalizedString(metaData.DisplayNameTerm).Like(pattern)));
                modified |= (newToCs.Count() != ModMissionToCs.Count || !newToCs.All(ModMissionToCs.Contains));
                ModMissionToCs.Clear();
                ModMissionToCs.AddRange(newToCs);

                if (modified)
                {
                    SetupState.LastBombBinderTOCIndex = 0;
                    SetupState.LastBombBinderTOCPage  = 0;
                }
            }
        };
    }
Exemplo n.º 26
0
 private void Awake()
 {
     _gameInfo = GetComponentInParent <KMGameInfo>();
     _gameInfo.OnLightsChange += OnLightsChange;
     OnLightsChange(_lightState);
 }
    private void Start()
    {
        Instance = this;

        transform.Find("Prefabs").gameObject.SetActive(false);
        twitchGame = GetComponentInChildren <TwitchGame>(true);

        twitchGame.twitchBombPrefab    = GetComponentInChildren <TwitchBomb>(true);
        twitchGame.twitchModulePrefab  = GetComponentInChildren <TwitchModule>(true);
        twitchGame.moduleCamerasPrefab = GetComponentInChildren <ModuleCameras>(true);

        TwitchGame.Instance = twitchGame;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        CoroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();
        LeaderboardController.Install();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        AuditLog.SetupLog();
        MainThreadQueue.Initialize();

        TwitchPlaySettings.LoadDataFromFile();

        MusicPlayer.LoadMusic();

        IRCConnection.Instance.OnMessageReceived.AddListener(OnMessageReceived);

        twitchGame.ParentService = this;

        TwitchPlaysAPI.Setup();

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;         // TODO: Useless variable?
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }

        UpdateUiHue();

        if (TwitchPlaySettings.data.DarkMode)
        {
            HeaderBackground.color   = new Color32(0x0E, 0x0E, 0x10, 0xFF);
            HeaderText.color         = new Color32(0xEF, 0xEF, 0xEC, 0xFF);
            MessagesBackground.color = new Color32(0x3A, 0x3A, 0x3D, 0xFF);
        }
        else
        {
            HeaderBackground.color   = new Color32(0xEE, 0xEE, 0xEE, 0xFF);
            HeaderText.color         = new Color32(0x4F, 0x4F, 0x4F, 0xFF);
            MessagesBackground.color = new Color32(0xD8, 0xD8, 0xD8, 0xFF);
        }

        SetupChatSimulator();

        // Delete the steam_appid.txt since it was created for a one-time steam boot.
        // Steam will have initialized before this.
        if (File.Exists("steam_appid.txt"))
        {
            File.Delete("steam_appid.txt");
        }
    }
Exemplo n.º 28
0
 // Use this for initialization
 void Start()
 {
     DebugLog("Starting service");
     _gameInfo = GetComponent <KMGameInfo>();
     _gameInfo.OnStateChange += OnStateChange;
 }
Exemplo n.º 29
0
    public void Awake()
    {
        Instance = this;

        MainThreadQueue.Initialize();

        GameInfo            = GetComponent <KMGameInfo>();
        SettingWarning      = gameObject.Traverse("UI", "SettingWarning");
        AdvantageousWarning = gameObject.Traverse("UI", "AdvantageousWarning");
        Tips.TipMessage     = gameObject.Traverse("UI", "TipMessage");
        BetterCasePicker.BombCaseGenerator = GetComponentInChildren <BombCaseGenerator>();
        DemandBasedLoading.LoadingScreen   = gameObject.Traverse <CanvasGroup>("UI", "LoadingModules");

        CaseGeneratorWarning = MakeSettingWarning("CaseGenerator");
        DBMLWarning          = MakeSettingWarning("DemandBasedModLoading");
        HoldablesWarning     = MakeSettingWarning("Holdables");

        modConfig = new ModConfig <TweakSettings>("TweakSettings", OnReadError);
        UpdateSettings();
        StartCoroutine(Modes.LoadDefaultSettings());

        DemandBasedLoading.EverLoadedModules = !settings.DemandBasedModLoading;
        DemandBasedSettingCache = settings.DemandBasedModLoading;

        HoldablesSettingCache = settings.Holdables;

        bool changeFadeTime = settings.FadeTime >= 0;

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = float.MaxValue;
        FreeplayDevice.MIN_MODULE_COUNT     = 1;

        if (settings.EnableModsOnlyKey)
        {
            var lastFreeplaySettings = FreeplaySettings.CreateDefaultFreeplaySettings();
            lastFreeplaySettings.OnlyMods = true;
            ProgressionManager.Instance.RecordLastFreeplaySettings(lastFreeplaySettings);
        }

        UpdateSettingWarnings();
        AdvantageousWarning.SetActive(false);

        // Setup API/properties other mods to interact with
        GameObject infoObject = new GameObject("Tweaks_Info", typeof(TweaksProperties));

        infoObject.transform.parent = gameObject.transform;

        TweaksAPI.Setup();

        // Watch the TweakSettings file for Time Mode state being changed in the office.
        FileSystemWatcher watcher = new FileSystemWatcher(Path.Combine(Application.persistentDataPath, "Modsettings"), "TweakSettings.json")
        {
            NotifyFilter = NotifyFilters.LastWrite
        };

        watcher.Changed += (object source, FileSystemEventArgs e) =>
        {
            if (ModConfig <TweakSettings> .SerializeSettings(userSettings) == ModConfig <TweakSettings> .SerializeSettings(modConfig.Read()))
            {
                return;
            }

            UpdateSettings();
            UpdateSettingWarnings();

            MainThreadQueue.Enqueue(() => StartCoroutine(ModifyFreeplayDevice(false)));
        };

        // Setup the leaderboard controller to block the leaderboard submission requests.
        LeaderboardController.Install();

        GetTweaks();

        // Create a fake case with a bunch of anchors to trick the game when using CaseGenerator.
        TweaksCaseGeneratorCase = new GameObject("TweaksCaseGenerator");
        TweaksCaseGeneratorCase.transform.SetParent(transform);
        var kmBomb = TweaksCaseGeneratorCase.AddComponent <KMBomb>();

        kmBomb.IsHoldable      = false;
        kmBomb.WidgetAreas     = new List <GameObject>();
        kmBomb.visualTransform = transform;
        kmBomb.Faces           = new List <KMBombFace>();

        TweaksCaseGeneratorCase.AddComponent <ModBomb>();

        var kmBombFace = TweaksCaseGeneratorCase.AddComponent <KMBombFace>();

        kmBombFace.Anchors = new List <Transform>();
        kmBomb.Faces.Add(kmBombFace);

        for (int i = 0; i <= 9001; i++)
        {
            kmBombFace.Anchors.Add(transform);
        }

        // Handle scene changes
        UnityEngine.SceneManagement.SceneManager.sceneLoaded += (Scene scene, LoadSceneMode _) =>
        {
            UpdateSettings();
            UpdateSettingWarnings();

            Modes.settings = Modes.modConfig.Read();
            Modes.modConfig.Write(Modes.settings);

            if ((scene.name == "mainScene" || scene.name == "gameplayScene") && changeFadeTime)
            {
                SceneManager.Instance.RapidFadeInTime = settings.FadeTime;
            }

            switch (scene.name)
            {
            case "mainScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.SetupState.FadeInTime          =
                        SceneManager.Instance.SetupState.FadeOutTime     =
                            SceneManager.Instance.UnlockState.FadeInTime = settings.FadeTime;
                }

                break;

            case "gameplayLoadingScene":
                var gameplayLoadingManager = FindObjectOfType <GameplayLoadingManager>();
                if (settings.InstantSkip)
                {
                    gameplayLoadingManager.MinTotalLoadTime = 0;
                }
                if (changeFadeTime)
                {
                    gameplayLoadingManager.FadeInTime      =
                        gameplayLoadingManager.FadeOutTime = settings.FadeTime;
                }

                ReflectedTypes.UpdateTypes();

                ReflectedTypes.CurrencyAPIEndpointField?.SetValue(null, settings.FixFER ? "http://api.exchangeratesapi.io" : "http://api.fixer.io");

                if (
                    AdvantageousFeaturesEnabled &&
                    GameplayState.MissionToLoad != Assets.Scripts.Missions.FreeplayMissionGenerator.FREEPLAY_MISSION_ID &&
                    GameplayState.MissionToLoad != ModMission.CUSTOM_MISSION_ID
                    )
                {
                    StartCoroutine(ShowAdvantageousWarning());
                }

                break;

            case "gameplayScene":
                if (changeFadeTime)
                {
                    SceneManager.Instance.GameplayState.FadeInTime      =
                        SceneManager.Instance.GameplayState.FadeOutTime = settings.FadeTime;
                }

                break;
            }
        };

        // Handle state changes
        GameInfo.OnStateChange += (KMGameInfo.State state) =>
        {
            OnStateChanged(CurrentState, state);

            // Transitioning away from another state
            if (state == KMGameInfo.State.Transitioning)
            {
                if (CurrentState == KMGameInfo.State.Setup)
                {
                    DemandBasedLoading.DisabledModsCount = 0;
                }

                if (CurrentState != KMGameInfo.State.Gameplay)
                {
                    DemandBasedLoading.HandleTransitioning();
                }
            }

            CurrentState = state;
            watcher.EnableRaisingEvents = state == KMGameInfo.State.Setup;

            if (state == KMGameInfo.State.Gameplay)
            {
                if (AdvantageousFeaturesEnabled)
                {
                    LeaderboardController.DisableLeaderboards();
                }

                TwitchPlaysActiveCache = TwitchPlaysActive;
                CurrentModeCache       = CurrentMode;

                BombStatus.Instance.widgetsActivated = false;
                BombStatus.Instance.HUD.SetActive(settings.BombHUD);
                BombStatus.Instance.ConfidencePrefab.gameObject.SetActive(CurrentMode != Mode.Zen);
                BombStatus.Instance.StrikesPrefab.color = CurrentMode == Mode.Time ? Color.yellow : Color.red;

                Modes.Multiplier = Modes.settings.TimeModeStartingMultiplier;
                BombStatus.Instance.UpdateMultiplier();
                bombWrappers.Clear();
                StartCoroutine(CheckForBombs());

                if (GameplayState.BombSeedToUse == -1)
                {
                    GameplayState.BombSeedToUse = settings.MissionSeed;
                }
            }
            else if (state == KMGameInfo.State.Setup)
            {
                if (ReflectedTypes.LoadedModsField.GetValue(ModManager.Instance) is Dictionary <string, Mod> loadedMods)
                {
                    Mod tweaksMod = loadedMods.Values.FirstOrDefault(mod => mod.ModID == "Tweaks");
                    if (tweaksMod != null && CaseGeneratorSettingCache != settings.CaseGenerator)
                    {
                        if (settings.CaseGenerator)
                        {
                            tweaksMod.ModObjects.Add(TweaksCaseGeneratorCase);
                        }
                        else
                        {
                            tweaksMod.ModObjects.Remove(TweaksCaseGeneratorCase);
                        }

                        CaseGeneratorSettingCache = settings.CaseGenerator;
                    }
                }

                StartCoroutine(Tips.ShowTip());
                StartCoroutine(ModifyFreeplayDevice(true));
                StartCoroutine(ModifyHoldables());
                GetComponentInChildren <ModSelectorExtension>().FindAPI();
                TweaksAPI.SetTPProperties(!TwitchPlaysActive);

                Patching.EnsurePatch("LogfileViewerHotkey", typeof(LogfileUploaderPatch));

                GameplayState.BombSeedToUse = -1;

                UpdateSettingWarnings();

                UpdateBombCreator();
            }
            else if (state == KMGameInfo.State.Transitioning)
            {
                // Because the settings are checked on a scene change and there is no scene change from exiting the gameplay room,
                // we need to update the settings here in case the user changed their HideTOC settings.
                UpdateSettings();

                bool modified       = false;
                var  ModMissionToCs = ModManager.Instance.ModMissionToCs;
                foreach (var metaData in ModMissionToCs)
                {
                    modified |= ModToCMetaData.Add(metaData);
                }

                var unloadedMods = (Dictionary <string, Mod>)ReflectedTypes.UnloadedModsField.GetValue(ModManager.Instance);
                if (unloadedMods != null)
                {
                    foreach (var unloadedMod in unloadedMods.Values)
                    {
                        var tocs = (List <ModTableOfContentsMetaData>)ReflectedTypes.TocsField.GetValue(unloadedMod);
                        if (tocs != null)
                        {
                            foreach (var metaData in tocs)
                            {
                                modified |= ModToCMetaData.Remove(metaData);
                            }
                        }
                    }
                }

                var newToCs = ModToCMetaData.Where(metaData => !settings.HideTOC.Any(pattern => Localization.GetLocalizedString(metaData.DisplayNameTerm).Like(pattern)));
                modified |= newToCs.Count() != ModMissionToCs.Count || !newToCs.All(ModMissionToCs.Contains);
                ModMissionToCs.Clear();
                ModMissionToCs.AddRange(newToCs);

                if (modified)
                {
                    SetupState.LastBombBinderTOCIndex = 0;
                    SetupState.LastBombBinderTOCPage  = 0;
                }
            }
        };
    }