Exemplo n.º 1
0
        public bool Start()
        {
            if (!ChromaController.IsChromaSdkAvailable())
            {
                MessageBox.Show(
                    Resources.MsgBox_RazerChromaSdkNotFound,
                    new AssemblyInfo().Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                return(false);
            }

            var settings = AppSettings.Load(_appSettingsPath);

            if (!settings.IsValid())
            {
                MessageBox.Show(
                    Resources.MsgBox_UnableToIdentifyFolders,
                    new AssemblyInfo().Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                if (!EditSettingsDialog(settings))
                {
                    return(false);
                }
            }

            settings.Save(_appSettingsPath);
            CycleChromaController(settings);
            return(true);
        }
Exemplo n.º 2
0
        private static void Prefix(IDifficultyBeatmap difficultyBeatmap, ref OverrideEnvironmentSettings overrideEnvironmentSettings)
        {
            if (difficultyBeatmap.beatmapData is CustomBeatmapData customBeatmapData)
            {
                IEnumerable <string> requirements = ((List <object>)Trees.at(customBeatmapData.beatmapCustomData, "_requirements"))?.Cast <string>();
                IEnumerable <string> suggestions  = ((List <object>)Trees.at(customBeatmapData.beatmapCustomData, "_suggestions"))?.Cast <string>();
                bool chromaRequirement            = (requirements?.Contains(Chroma.Plugin.REQUIREMENTNAME) ?? false) || (suggestions?.Contains(Chroma.Plugin.REQUIREMENTNAME) ?? false);

                // please let me remove this shit
                bool legacyOverride = difficultyBeatmap.beatmapData.beatmapEventsData.Any(n => n.value >= LegacyLightHelper.RGB_INT_OFFSET);
                if (legacyOverride)
                {
                    ChromaLogger.Log("Legacy Chroma Detected...", IPA.Logging.Logger.Level.Warning);
                    ChromaLogger.Log("Please do not use Legacy Chroma for new maps as it is deprecated and its functionality in future versions of Chroma cannot be guaranteed", IPA.Logging.Logger.Level.Warning);
                }

                ChromaController.ToggleChromaPatches((chromaRequirement || legacyOverride) && ChromaConfig.Instance.CustomColorEventsEnabled);
                ChromaController.DoColorizerSabers = chromaRequirement && ChromaConfig.Instance.CustomColorEventsEnabled;

                if (chromaRequirement && ChromaConfig.Instance.EnvironmentEnhancementsEnabled && Trees.at(customBeatmapData.beatmapCustomData, "_environmentRemoval") != null)
                {
                    overrideEnvironmentSettings = null;
                }
            }
        }
Exemplo n.º 3
0
        public void ChecksIfChromaSdkIsAvailable(bool sdkAvailable)
        {
            var nm = new NativeMethodsMock(sdkAvailable);

            var available = ChromaController.IsChromaSdkAvailable(nm);

            Assert.Equal(sdkAvailable, available);
        }
Exemplo n.º 4
0
        public void DoesNotThrowWhenDisposingTwice()
        {
            var watcher = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder);

#pragma warning disable IDISP016, IDISP017
            watcher.Dispose();
            watcher.Dispose();
#pragma warning restore IDISP016, IDISP017
        }
Exemplo n.º 5
0
 private void CycleChromaController(AppSettings settings)
 {
     _cc?.Dispose();
     _cc = new ChromaController(settings.GameInstallFolder, settings.GameOptionsFolder, settings.JournalFolder)
     {
         ChromaFactory = _chromaFactory,
     };
     _cc.Start();
 }
Exemplo n.º 6
0
        public void EnUSOverrideIsAppliedInTheGameState()
        {
            using var cc = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder);
            var watcher = cc.GetPrivateField <GameStateWatcher>("_watcher");

            Assert.False(cc.ForceEnUSKeyboardLayout);
            Assert.False(watcher.GetGameStateSnapshot().ForceEnUSKeyboardLayout);

            cc.ForceEnUSKeyboardLayout = true;
            Assert.True(cc.ForceEnUSKeyboardLayout);
            Assert.True(watcher.GetGameStateSnapshot().ForceEnUSKeyboardLayout);
        }
Exemplo n.º 7
0
        public void RenderEffectIsNotReentrant()
        {
            using var cc = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder)
                  {
                      ChromaFactory = new ChromaFactory
                      {
                          ChromaApi     = new Mock <IChromaApi>().Object,
                          ChromaAppInfo = null,
                      },
                  };

            var game = cc.GetPrivateField <GameStateWatcher>("_watcher")
                       .GetPrivateField <GameState>("_gameState");

            var effect = cc.GetPrivateField <LayeredEffect>("_effect");

            var nRenderCalls = 0;

            using var mre = new ManualResetEventSlim();

            var layer = new Mock <EffectLayer>();

            layer.Protected()
            .Setup("OnRender", ItExpr.IsAny <ChromaCanvas>(), ItExpr.IsAny <object>())
            .Callback(() =>
            {
                Interlocked.Increment(ref nRenderCalls);
                mre.Wait();
            });

            effect.Clear();
            effect.Add(layer.Object);

            game.ProcessState = GameProcessState.InForeground;

            async Task RenderEffect()
            {
                await cc.InvokePrivateMethod <Task>("RenderEffect").ConfigureAwait(false);

                mre.Set();
            }

            Task.WaitAll(new[]
            {
                Task.Run(RenderEffect),
                Task.Run(RenderEffect),
            });

            Assert.Equal(1, nRenderCalls);
        }
Exemplo n.º 8
0
        public void StartAndStopAreNotReentrant()
        {
            using var watcher = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder);

            bool IsRunning() => watcher.GetPrivateField <bool>("_running");

            Assert.False(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());
        }
Exemplo n.º 9
0
        public AppContext()
        {
            if (!ValidateFolders())
            {
                return;
            }

            var settings = AppSettings.Default;

            _cc = new ChromaController(settings.GameInstallFolder, settings.GameOptionsFolder, settings.JournalFolder);
            _cc.Start();

            this.TrayIcon.Icon = Resources.EliteChromaIcon;

            ContextMenu.Items.Add("&Settings...", null, Settings_Click);
            ContextMenu.Items.Add("-");
            ContextMenu.Items.Add("&About...", null, About_Click);
            ContextMenu.Items.Add("-");
            ContextMenu.Items.Add("E&xit", null, Exit_Click);
        }
Exemplo n.º 10
0
        private void CycleChromaController(AppSettings settings)
        {
            if (CanSoftCycle(settings))
            {
                _cc.ForceEnUSKeyboardLayout = settings.ForceEnUSKeyboardLayout;
                _cc.Colors = settings.Colors;
                _cc.Refresh();
                _currentSettings = settings;
                return;
            }

            _cc?.Dispose();
            _cc = new ChromaController(settings.GameInstallFolder, settings.GameOptionsFolder, settings.JournalFolder)
            {
                ChromaFactory           = _chromaFactory,
                ForceEnUSKeyboardLayout = settings.ForceEnUSKeyboardLayout,
                Colors = settings.Colors,
            };
            _cc.Start();
            _currentSettings = settings;
        }
        public async Task RazerChromaApiGetsCalledOnGameEvents()
        {
            const string statusFile  = "Status.json";
            const string journalFile = "Journal.190101020000.01.log";

            var chromaApi = new ChromaApiMock();
            var evs       = new EventCollector <ChromaApiMock.MockCall>(h => chromaApi.Called += h, h => chromaApi.Called -= h);

            using TestFolder
                  dirRoot    = new TestFolder(_gameRootFolder),
                  dirOpts    = new TestFolder(_gameOptionsFolder),
                  dirJournal = new TestFolder();

            dirJournal.WriteText(statusFile, EventSequence.BuildEvent("Status", new { Flags = 0 }));
            dirJournal.WriteText(journalFile, EventSequence.BuildEvent("Fileheader", new { part = 1, language = @"English\UK", gameversion = "3.5.0.200 EDH", build = "r210198/r0 " }));

            using var cc = new ChromaController(dirRoot.Name, dirOpts.Name, dirJournal.Name)
                  {
                      ChromaApi              = chromaApi,
                      AnimationFrameRate     = 0,
                      DetectGameInForeground = false,
                  };

            var mcs = await evs.WaitAsync(5, cc.Start, 1000).ConfigureAwait(false);

            Assert.Equal("InitializeAsync", mcs[0].Method);
            Assert.Equal("CreateKeyboardEffectAsync", mcs[1].Method);

            var seq = BuildEventSequence();

            mcs = await evs.WaitAsync(seq.Count, () => seq.Play(dirJournal, journalFile, statusFile), 200 *seq.Count).ConfigureAwait(false);

            Assert.Equal(seq.Count, mcs.Count);

            var mc = await evs.WaitAsync(cc.Stop, 1000).ConfigureAwait(false);

            Assert.Equal("UninitializeAsync", mc.Method);
        }
Exemplo n.º 12
0
        private void Settings_Click(object sender, EventArgs eventArgs)
        {
            using var frm = new FrmAppSettings();

            var settings = AppSettings.Default;

            frm.txtGameInstall.Text = settings.GameInstallFolder;
            frm.txtGameOptions.Text = settings.GameOptionsFolder;
            frm.txtJournal.Text     = settings.JournalFolder;

            if (frm.ShowDialog(ContextMenu) == DialogResult.OK)
            {
                _cc.Dispose();

                settings.GameInstallFolder = frm.txtGameInstall.Text;
                settings.GameOptionsFolder = frm.txtGameOptions.Text;
                settings.JournalFolder     = frm.txtJournal.Text;

                settings.Save();

                _cc = new ChromaController(settings.GameInstallFolder, settings.GameOptionsFolder, settings.JournalFolder);
                _cc.Start();
            }
        }
Exemplo n.º 13
0
 private static void Prefix()
 {
     ChromaController.ToggleChromaPatches(false);
     ChromaController.DoColorizerSabers = false;
 }
Exemplo n.º 14
0
        public void RazerChromaApiGetsCalledOnGameEvents()
        {
            const string statusFile  = "Status.json";
            const string journalFile = "Journal.190101020000.01.log";

            using var cpl = ColoreProviderLock.GetLock();

            var chromaApi = new Mock <IChromaApi> {
                DefaultValue = DefaultValue.Mock
            };
            var mockIA   = chromaApi.Setup(x => x.InitializeAsync(It.IsAny <AppInfo>()));
            var mockCKEA = chromaApi.Setup(x => x.CreateKeyboardEffectAsync(It.IsAny <KeyboardEffectType>(), It.IsAny <It.IsValueType>()));
            var mockUA   = chromaApi.Setup(x => x.UninitializeAsync());

            using TestFolder
                  dirRoot    = new TestFolder(_gameRootFolder),
                  dirOpts    = new TestFolder(_gameOptionsFolder),
                  dirJournal = new TestFolder();

            dirJournal.WriteText(statusFile, EventSequence.BuildEvent("Status", new { Flags = 0 }));
            dirJournal.WriteText(journalFile, EventSequence.BuildEvent("Fileheader", new { part = 1, language = @"English\UK", gameversion = "3.5.0.200 EDH", build = "r210198/r0 " }));

            using var cc = new ChromaController(dirRoot.Name, dirOpts.Name, dirJournal.Name)
                  {
                      ChromaFactory = new ChromaFactory
                      {
                          ChromaApi     = chromaApi.Object,
                          ChromaAppInfo = null,
                      },
                      AnimationFrameRate     = 0,
                      DetectGameInForeground = false,
                  };

            Assert.False(cc.DetectGameInForeground);

            using var ceIA = new CountdownEvent(1);
            mockIA.Callback(() => ceIA.Signal());

            using var ceCKEA = new CountdownEvent(1);
            mockCKEA.Callback(() => ceCKEA.Signal());

            using var ceUA = new CountdownEvent(1);
            mockUA.Callback(() => ceUA.Signal());

            cc.Start();

            Assert.True(ceIA.Wait(1000));
            Assert.True(ceCKEA.Wait(1000));

            var seq = BuildEventSequence();

            ceCKEA.Reset(seq.Count(x => x.ChangesGameState));

            seq.Play(dirJournal, journalFile, statusFile);

            Assert.True(ceCKEA.Wait(200 * seq.Count));

            cc.Stop();

            Assert.True(ceUA.Wait(1000));
        }
        public void ChecksIfChromaSdkIsAvailable()
        {
            var available = ChromaController.IsChromaSdkAvailable();

            Assert.True(available);
        }
Exemplo n.º 16
0
 public void CannotSetANegativeAnimationFrameRate()
 {
     using var cc = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder);
     Assert.Throws <ArgumentOutOfRangeException>("AnimationFrameRate", () => cc.AnimationFrameRate = -1);
 }
Exemplo n.º 17
0
 public void DefaultAnimationFrameRateIsSetTo30Fps()
 {
     using var cc = new ChromaController(_gameRootFolder, _gameOptionsFolder, _journalFolder);
     Assert.Equal(30, cc.AnimationFrameRate);
 }
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static void Postfix(BeatmapObjectCallbackController __instance)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            __instance.StartCoroutine(ChromaController.DelayedStart());
        }
 private static void Postfix(BeatmapObjectSpawnController __instance)
 {
     __instance.StartCoroutine(ChromaController.DelayedStart(__instance));
 }