Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Added hotkey for saving unchecked combos
Browse files Browse the repository at this point in the history
  • Loading branch information
Laiteux committed Dec 27, 2020
1 parent 356d58d commit b735f9d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/Club_Cooee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Program
{
public static async Task Main()
{
var checkerSettings = new CheckerSettings(100, true);
var checkerSettings = new CheckerSettings(maxThreads: 100, useProxies: true);

var checker = new CheckerBuilder(checkerSettings, CheckAsync)
.WithCombos(File.ReadAllLines("Combos.txt"))
Expand All @@ -22,7 +22,7 @@ public static async Task Main()

var consoleManager = new ConsoleManager(checker);
_ = consoleManager.StartUpdatingTitleAsync(TimeSpan.FromMilliseconds(25), prefix: "Club Cooee Checker — ");
_ = consoleManager.StartListeningKeysAsync(ConsoleKey.P, ConsoleKey.R);
_ = consoleManager.StartListeningKeysAsync(ConsoleKey.P, ConsoleKey.R, saveUnchecked: ConsoleKey.S);

await checker.StartAsync();

Expand Down
20 changes: 17 additions & 3 deletions src/Milky/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ await _combos.ForEachAsync(_checkerSettings.MaxThreads, async combo =>

lock (Info.Locker)
{
Info.Checked++;
Info.Checked.Add(combo);

if (checkResult.ComboResult == ComboResult.Hit)
{
Expand Down Expand Up @@ -171,13 +171,27 @@ public TimeSpan Resume()
}
}

public int SaveUnchecked()
{
lock (Info.Locker)
{
string outputPath = Path.Combine(_outputSettings.OutputDirectory ?? string.Empty, "Unchecked.txt");

var @unchecked = _combos.Except(Info.Checked);

File.WriteAllLines(outputPath, @unchecked.Select(c => c.ToString()));

return @unchecked.Count();
}
}

private async Task StartCpmCounterAsync()
{
while (Info.Status != CheckerStatus.Done)
{
int checkedBefore = Info.Checked;
int checkedBefore = Info.Checked.Count;
await Task.Delay(6000).ConfigureAwait(false);
int checkedAfter = Info.Checked;
int checkedAfter = Info.Checked.Count;

Info.Cpm = (checkedAfter - checkedBefore) * 10;
}
Expand Down
48 changes: 36 additions & 12 deletions src/Milky/ConsoleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task StartUpdatingTitleAsync(TimeSpan updateInterval, bool showFree
{
var checkStats = new List<string>()
{
"Checked: " + ((double)_checker.Info.Checked).ToString("N0"),
"Checked: " + ((double)_checker.Info.Checked.Count).ToString("N0"),
"Hits: " + ((double)_checker.Info.Hits).ToString("N0")
};

Expand All @@ -46,14 +46,14 @@ public async Task StartUpdatingTitleAsync(TimeSpan updateInterval, bool showFree
{
if (_checker.Info.Status != CheckerStatus.Done)
{
checkStats[0] += $" ({(double)_checker.Info.Checked / _checker.Info.Combos:P2})";
checkStats[0] += $" ({(double)_checker.Info.Checked.Count / _checker.Info.Combos:P2})";
}

checkStats[1] += $" ({(double)_checker.Info.Hits / _checker.Info.Checked:P2})";
checkStats[1] += $" ({(double)_checker.Info.Hits / _checker.Info.Checked.Count:P2})";

if (showFree)
{
checkStats[2] += $" ({(double)_checker.Info.Free / _checker.Info.Checked:P2})";
checkStats[2] += $" ({(double)_checker.Info.Free / _checker.Info.Checked.Count:P2})";
}
}

Expand All @@ -64,7 +64,7 @@ public async Task StartUpdatingTitleAsync(TimeSpan updateInterval, bool showFree

if (_checker.Info.Status != CheckerStatus.Done)
{
checkStats.Insert(1, "Left: " + ((double)(_checker.Info.Combos - _checker.Info.Checked)).ToString("N0"));
checkStats.Insert(1, "Left: " + ((double)(_checker.Info.Combos - _checker.Info.Checked.Count)).ToString("N0"));

if (_checker.Info.Hits != 0)
{
Expand Down Expand Up @@ -97,10 +97,11 @@ public async Task StartUpdatingTitleAsync(TimeSpan updateInterval, bool showFree
/// <summary>
/// Will start listening to user keys and do actions associated with them when pressed
/// </summary>
/// <param name="pauseKey"><see cref="ConsoleKey"/> for <see cref="Checker.Pause"/>, <see cref="null"/> to disable</param>
/// <param name="resumeKey"><see cref="ConsoleKey"/> for <see cref="Checker.Resume"/>, <see cref="null"/> to disable</param>
/// <param name="abortKey"><see cref="ConsoleKey"/> for <see cref="Checker.Abort"/>, <see cref="null"/> to disable</param>
public async Task StartListeningKeysAsync(ConsoleKey? pauseKey = ConsoleKey.P, ConsoleKey? resumeKey = ConsoleKey.R, ConsoleKey? abortKey = null)
/// <param name="pause"><see cref="ConsoleKey"/> for <see cref="Checker.Pause"/>, <see cref="null"/> to disable</param>
/// <param name="resume"><see cref="ConsoleKey"/> for <see cref="Checker.Resume"/>, <see cref="null"/> to disable</param>
/// /// <param name="saveUnchecked"><see cref="ConsoleKey"/> for saving unchecked combos, <see cref="null"/> to disable</param>
/// <param name="abort"><see cref="ConsoleKey"/> for <see cref="Checker.Abort"/>, <see cref="null"/> to disable</param>
public async Task StartListeningKeysAsync(ConsoleKey? pause = ConsoleKey.P, ConsoleKey? resume = ConsoleKey.R, ConsoleKey? saveUnchecked = ConsoleKey.S, ConsoleKey? abort = null)
{
while (_checker.Info.Status != CheckerStatus.Done)
{
Expand All @@ -118,7 +119,7 @@ public async Task StartListeningKeysAsync(ConsoleKey? pauseKey = ConsoleKey.P, C

ConsoleKey key = Console.ReadKey(true).Key;

if ((pauseKey != null && key == pauseKey) || (resumeKey != null && key == resumeKey))
if ((pause != null && key == pause) || (resume != null && key == resume))
{
if (_checker.Info.Status == CheckerStatus.Running)
{
Expand All @@ -127,7 +128,7 @@ public async Task StartListeningKeysAsync(ConsoleKey? pauseKey = ConsoleKey.P, C
lock (_checker.Info.Locker)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"{Environment.NewLine}Checker paused, press \"{resumeKey}\" to resume...{Environment.NewLine}");
Console.WriteLine($"{Environment.NewLine}Checker paused, press \"{resume}\" to resume...{Environment.NewLine}");
}
}
else if (_checker.Info.Status == CheckerStatus.Paused)
Expand All @@ -144,7 +145,30 @@ public async Task StartListeningKeysAsync(ConsoleKey? pauseKey = ConsoleKey.P, C
}
}
}
else if (abortKey != null && key == abortKey)
else if (saveUnchecked != null && key == saveUnchecked)
{
lock (_checker.Info.Locker)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"{Environment.NewLine}Saving unchecked combos, please wait...{Environment.NewLine}");
}

var saveStart = DateTime.Now;

int @unchecked = _checker.SaveUnchecked();

lock (_checker.Info.Locker)
{
if (_checker.Info.LastHit > saveStart)
{
Console.WriteLine();
}

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"Saved {@unchecked:N0} unchecked combos!{Environment.NewLine}");
}
}
else if (abort != null && key == abort)
{
_checker.Abort();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Milky/Models/CheckerInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Milky.Enums;
using System;
using System.Collections.Generic;
using System.Threading;

namespace Milky.Models
{
// MIGHT not seem so good at the first look but perfectly does the job
public class CheckerInfo
{
internal CheckerInfo(int combos)
Expand All @@ -18,9 +18,9 @@ internal CheckerInfo(int combos)

public CheckerStatus Status { get; internal set; }

public int Combos { get; private set; }
public int Combos { get; }

public int Checked { get; internal set; }
public List<Combo> Checked { get; } = new List<Combo>();

public int Cpm { get; internal set; }

Expand All @@ -34,12 +34,12 @@ public int EstimatedHits
{
get
{
if (Checked == 0 || Hits == 0)
if (Checked.Count == 0 || Hits == 0)
{
return 0;
}

return (int)((double)Combos / Checked * Hits);
return (int)((double)Combos / Checked.Count * Hits);
}
}

Expand All @@ -61,7 +61,7 @@ public TimeSpan? Remaining
{
try
{
return TimeSpan.FromSeconds((Combos - Checked) / (Cpm / 60));
return TimeSpan.FromSeconds((Combos - Checked.Count) / (Cpm / 60));
}
catch
{
Expand Down

0 comments on commit b735f9d

Please sign in to comment.