Skip to content

Commit

Permalink
Changed to NET 5.0, versioning, better information in commands, small…
Browse files Browse the repository at this point in the history
… refactor (#7)

- Fixed a bug where it did not click on the given coordinates.
- Changed to NET 5.0
- Pause/Resume commands now have a console message showing that it was successfully executed.
- Small refactoring work was done to ensure the user gets better warnings/error messages.
  • Loading branch information
versaceLORD authored Aug 6, 2021
1 parent e736a03 commit 9d8a9e3
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 106 deletions.
46 changes: 23 additions & 23 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: .NET Core 3.1 build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
name: .NET 5.0

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
25 changes: 9 additions & 16 deletions src/AutoClicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace VirtualAutoClicker
public class AutoClicker
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam);

private static extern int SendMessage(IntPtr hWnd, uint message, int wParam, int lParam);
/// <summary>
/// Name of instance
/// </summary>
Expand Down Expand Up @@ -124,15 +124,6 @@ public void Resume()
StartClicker();
}

/// <summary>
/// Creates parameters which will be sent to simulate coordinates to the SendMessage message.
/// The coordinate is relative to the upper-left corner of the client area.
/// </summary>
private static IntPtr CreateLParam(int loWord, int hiWord)
{
return (IntPtr)((hiWord << 16) | (loWord & 0xffff));
}

/// <summary>
/// If all neccsary AutoClicker properties are set, send click message to the set process
/// </summary>
Expand All @@ -143,18 +134,20 @@ private void Click()
return;
}

var lParam = (Coordinates.Y << 16) + Coordinates.X;

SendMessage(
CurrentProcess.MainWindowHandle,
Buttons.WmLbuttondown,
new IntPtr(Buttons.MkLbutton),
CreateLParam(Coordinates.X, Coordinates.Y)
0,
lParam
);

SendMessage(
CurrentProcess.MainWindowHandle,
Buttons.WmLbuttonup,
new IntPtr(Buttons.MkLbutton),
CreateLParam(Coordinates.X, Coordinates.Y)
0,
lParam
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Pause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public void Execute(string[] arguments)

var acWorker = VacEnvironment.GetAcWorker();
acWorker?.GetAutoclicker(acName)?.Pause();

ConsoleHelper.WriteMessage($"autoclicker {acName} paused!");
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Picnic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public void Execute(string[] arguments)
var acWorker = VacEnvironment.GetAcWorker();
acWorker?.Picnic();

ConsoleHelper.WriteMessage("Autoclickers stopped!");
ConsoleHelper.WriteMessage("All autoclickers stopped!");
}
}
}
2 changes: 2 additions & 0 deletions src/Commands/Resume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public void Execute(string[] arguments)

var acWorker = VacEnvironment.GetAcWorker();
acWorker?.GetAutoclicker(acName)?.Resume();

ConsoleHelper.WriteMessage($"autoclicker {acName} resumed!");
}
}
}
32 changes: 17 additions & 15 deletions src/Commands/StartAutoClicker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Text.RegularExpressions;

using VirtualAutoClicker.Models;

namespace VirtualAutoClicker.Commands
Expand All @@ -22,30 +20,34 @@ public void Execute(string[] arguments)
}

var processName = arguments[0];

// If the process name is put between double quotation marks
if (arguments[0].StartsWith('"') && arguments[0].EndsWith('"'))

var xConversion = int.TryParse(arguments[1].Split(',')[0], out var x);
var yConversion = int.TryParse(arguments[1].Split(',')[1], out var y);
if (!xConversion || !yConversion)
{
var pattern = new Regex("\"(.*?)\"");
var matches = pattern.Matches(processName);
if (matches.Count > 0)
{
processName = matches[0].Groups[1].Value.Replace("\"", "");
}
ConsoleHelper.WriteWarning("Command usage: 'startautoclicker \"P\" X,Y I N' please refer to the readme.md file for further assistance.");
return;
}

var coordinates = new Coordinates
{
X = int.Parse(arguments[1].Split(',')[0]),
Y = int.Parse(arguments[1].Split(',')[1]),
X = x,
Y = y,
};

var intervalConversion = int.TryParse(arguments[2], out var interval);
if (!intervalConversion)
{
ConsoleHelper.WriteWarning("Command usage: 'startautoclicker \"P\" X,Y I N' please refer to the readme.md file for further assistance.");
return;
}

// Instantiate the new autoclicker
Start(
proposedAcName,
processName,
coordinates,
int.Parse(arguments[2])
interval
);
}

Expand Down
49 changes: 49 additions & 0 deletions src/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualAutoClicker
{
Expand Down Expand Up @@ -43,5 +46,51 @@ public static void WriteError(Exception e)
Console.WriteLine(e);
Console.ForegroundColor = ConsoleColor.White;
}

public static void WriteStartingMessage()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("- - - - - - - - - - - - - - - - - -");
Console.WriteLine($"virtual-auto-clicker - Your idle success [version {VacEnvironment.VersionNumber}]");
Console.WriteLine("by @versaceLORD - https://github.com/versaceLORD/virtual-auto-clicker");
Console.WriteLine("- - - - - - - - - - - - - - - - - -\n\r");
}

public static string[] GetInputArguments(List<string> arguments)
{
var processName = new StringBuilder();

if (arguments.Count(arg => arg.Contains("\"", StringComparison.InvariantCultureIgnoreCase)) != 2)
{
return arguments.ToArray();
}

var doubleQuoteIndex = arguments.FindIndex(arg => arg.StartsWith('"'));
var endingIndex = 0;
for (var i = 0; i < arguments.Count; i++)
{
if (arguments[i].EndsWith('"'))
{
endingIndex = i;
}
}

if (endingIndex == 0)
{
return arguments.ToArray();
}

for (var i = doubleQuoteIndex; i <= endingIndex; i++)
{
processName.Append($"{arguments[i]} ");
}

arguments.RemoveRange(doubleQuoteIndex, endingIndex + 1);
arguments = arguments
.Prepend(processName.ToString().Remove(processName.Length - 1, 1))
.ToList();

return arguments.ToArray();
}
}
}
9 changes: 9 additions & 0 deletions src/Constants/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
{
public static class Buttons
{
/// <summary>
/// Left mouse button down
/// </summary>
public const uint WmLbuttondown = 0x201;
/// <summary>
/// Left mouse button up
/// </summary>
public const uint WmLbuttonup = 0x202;
/// <summary>
/// Left mouse button
/// </summary>
public const uint MkLbutton = 0x0001;
}
}
9 changes: 0 additions & 9 deletions src/Enums/Button.cs

This file was deleted.

18 changes: 11 additions & 7 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ internal static class Program
{
private static void Main()
{
ConsoleHelper.WriteMessage("Virtual Autoclicker Console is starting!");
Console.Title = $"Virtual Autoclicker [{VacEnvironment.VersionNumber}]";

ConsoleHelper.WriteStartingMessage();

VacEnvironment.Initialize();

StartClosingHandlers();
Console.Title = "Virtual Autoclicker";

ConsoleHelper.WriteMessage("Virtual Autoclicker Console has started!\n\r");
ConsoleHelper.WriteMessage("Virtual Autoclicker is ready for use - press the enter key to input a command!\n\r");

while (VacEnvironment.Active)
{
Expand All @@ -30,15 +31,18 @@ private static void Main()
{
continue;
}

var command = VacEnvironment.GetCommand(input.Split(' ')[0]);

var inputCommand = input.Split(' ')[0];
var arguments = ConsoleHelper.GetInputArguments(input.Split(' ').Skip(1).ToList());

var command = VacEnvironment.GetCommand(inputCommand);
if (command is null)
{
ConsoleHelper.WriteWarning($"No command found named '{command}'");
ConsoleHelper.WriteWarning($"No command found named '{inputCommand}'");
continue;
}

command.Execute(input.Split(' ').Skip(1).ToArray());
command.Execute(arguments);
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/Properties/PublishProfiles/Selfcontained windows x64.pubxml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
34 changes: 17 additions & 17 deletions src/Properties/PublishProfiles/Selfcontained windows x86.pubxml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
Loading

0 comments on commit 9d8a9e3

Please sign in to comment.