private void TickTwitch() { if (!Config.Instance().Enabled) { return; } if (Config.Instance().TwitchVotingMode == 1) { if (progressBarTwitch.Maximum != Config.Instance().TwitchVotingTime) { progressBarTwitch.Maximum = Config.Instance().TwitchVotingTime; } // Hack to fix Windows' broken-ass progress bar handling int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds); progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value, 0); progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value - 1, 0); if (stopwatch.ElapsedMilliseconds - elapsedCount > 100) { long remaining = Math.Max(0, Config.Instance().TwitchVotingTime - stopwatch.ElapsedMilliseconds); ProcessHooker.SendEffectToGame("time", $"{remaining},{Config.Instance().TwitchVotingTime}"); twitch?.SendEffectVotingToGame(); elapsedCount = (int)stopwatch.ElapsedMilliseconds; } if (stopwatch.ElapsedMilliseconds >= Config.Instance().TwitchVotingTime) { ProcessHooker.SendEffectToGame("time", "0"); elapsedCount = 0; progressBarTwitch.Value = 0; progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown; stopwatch.Restart(); Config.Instance().TwitchVotingMode = 0; labelTwitchCurrentMode.Text = "Current Mode: Cooldown"; if (twitch != null) { TwitchConnection.VotingElement element = twitch.GetRandomVotedEffect(out string username); twitch.SetVoting(0, timesUntilRapidFire, element, username); CallEffect(element.Effect); } } } else if (Config.Instance().TwitchVotingMode == 2) { if (progressBarTwitch.Maximum != 1000 * 10) { progressBarTwitch.Maximum = 1000 * 10; } // Hack to fix Windows' broken-ass progress bar handling int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds); progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value, 0); progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value - 1, 0); if (stopwatch.ElapsedMilliseconds - elapsedCount > 100) { long remaining = Math.Max(0, (1000 * 10) - stopwatch.ElapsedMilliseconds); ProcessHooker.SendEffectToGame("time", $"{remaining},10000"); elapsedCount = (int)stopwatch.ElapsedMilliseconds; } if (stopwatch.ElapsedMilliseconds >= 1000 * 10) // Set 10 seconds { ProcessHooker.SendEffectToGame("time", "0"); elapsedCount = 0; progressBarTwitch.Value = 0; progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown; stopwatch.Restart(); Config.Instance().TwitchVotingMode = 0; labelTwitchCurrentMode.Text = "Current Mode: Cooldown"; twitch?.SetVoting(0, timesUntilRapidFire); } } else if (Config.Instance().TwitchVotingMode == 0) { if (progressBarTwitch.Maximum != Config.Instance().TwitchVotingCooldown) { progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown; } // Hack to fix Windows' broken-ass progress bar handling int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds); progressBarTwitch.Value = Math.Min(value + 1, progressBarTwitch.Maximum); progressBarTwitch.Value = Math.Min(value, progressBarTwitch.Maximum); if (stopwatch.ElapsedMilliseconds - elapsedCount > 100) { long remaining = Math.Max(0, Config.Instance().TwitchVotingCooldown - stopwatch.ElapsedMilliseconds); ProcessHooker.SendEffectToGame("time", $"{remaining},{Config.Instance().TwitchVotingCooldown}"); elapsedCount = (int)stopwatch.ElapsedMilliseconds; } if (stopwatch.ElapsedMilliseconds >= Config.Instance().TwitchVotingCooldown) { elapsedCount = 0; if (--timesUntilRapidFire == 0) { progressBarTwitch.Value = progressBarTwitch.Maximum = 1000 * 10; timesUntilRapidFire = new Random().Next(10, 15); Config.Instance().TwitchVotingMode = 2; labelTwitchCurrentMode.Text = "Current Mode: Rapid-Fire"; twitch?.SetVoting(2, timesUntilRapidFire); } else { progressBarTwitch.Value = progressBarTwitch.Maximum = Config.Instance().TwitchVotingTime; Config.Instance().TwitchVotingMode = 1; labelTwitchCurrentMode.Text = "Current Mode: Voting"; twitch?.SetVoting(1, timesUntilRapidFire); } stopwatch.Restart(); } } }