Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AutoClicker/AutoClicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<Reference Include="CommonServiceLocator, Version=2.0.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>packages\CommonServiceLocator.2.0.6\lib\net48\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\MathNet.Numerics.5.0.0\lib\net48\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
Expand Down
23 changes: 19 additions & 4 deletions AutoClicker/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using AutoClicker.Models;
using AutoClicker.Utils;
using Serilog;
using MathNet.Numerics.Distributions;
using CheckBox = System.Windows.Controls.CheckBox;
using MouseAction = AutoClicker.Enums.MouseAction;
using MouseButton = AutoClicker.Enums.MouseButton;
Expand All @@ -32,7 +33,11 @@ public AutoClickerSettings AutoClickerSettings
new UIPropertyMetadata(SettingsUtils.CurrentSettings.AutoClickerSettings));

private int timesRepeated = 0;
private readonly Timer clickTimer;
private Timer clickTimer;
private double cpsMean = 1.0;
private double cpsSDev = 0.25;
private MathNet.Numerics.Distributions.Normal cpsDistribution;

private readonly Uri runningIconUri =
new Uri(Constants.RUNNING_ICON_RESOURCE_PATH, UriKind.Relative);

Expand Down Expand Up @@ -118,10 +123,12 @@ protected override void OnClosed(EventArgs e)
private void StartCommand_Execute(object sender, ExecutedRoutedEventArgs e)
{
int interval = CalculateInterval();
Log.Information("Starting operation, interval={Interval}ms", interval);

cpsMean = (interval <= 0) ? 0.5 : 1000 / (double)interval;
cpsDistribution = new Normal(cpsMean, cpsSDev);
clickTimer.Interval = (int)Math.Round(1000 / cpsDistribution.Sample());
timesRepeated = 0;
clickTimer.Interval = interval;

Log.Information("Starting operation, cps_avg={cps}, cps_std_dev={dev}, interval={interval}ms", cpsMean, cpsSDev, clickTimer.Interval);
clickTimer.Start();

Icon = new BitmapImage(runningIconUri);
Expand Down Expand Up @@ -236,6 +243,13 @@ private bool IsIntervalValid()
return CalculateInterval() > 0;
}

private int DistributedInterval()
{
/* Instead of constant if/else checking to avoid zero division, just always skew my 1 ms.
* Shouldn't affect CPS meaningfully in practice. */
return 1 + (int)Math.Round(1000 / cpsDistribution.Sample());
}

private bool CanStartOperation()
{
return !clickTimer.Enabled && IsRepeatModeValid() && IsIntervalValid();
Expand Down Expand Up @@ -326,6 +340,7 @@ private void OnClickTimerElapsed(object sender, ElapsedEventArgs e)
{
InitMouseClick();
timesRepeated++;
clickTimer.Interval = DistributedInterval();

if (timesRepeated == GetTimesToRepeat())
{
Expand Down
1 change: 1 addition & 0 deletions AutoClicker/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="2.0.6" targetFramework="net48" />
<package id="MathNet.Numerics" version="5.0.0" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" />
<package id="Prism" version="4.1.0.0" targetFramework="net452" />
<package id="Serilog" version="2.10.0" targetFramework="net48" />
Expand Down