Skip to content

Commit

Permalink
1.6 - Mouse move for Infernal Hordes
Browse files Browse the repository at this point in the history
  • Loading branch information
dliedke committed Jan 5, 2025
1 parent 2dd3b7e commit d88862d
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 8 deletions.
18 changes: 16 additions & 2 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 144 additions & 3 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public partial class MainForm : Form
private const float DEAD_ZONE = 0.1f; // Adjust as needed
private bool wasAutomationRunning = false;

private bool isMouseMoveEnabled = false;
private bool isMoving = false;
private System.Windows.Forms.Timer moveTimer;
private const int PAUSE_DURATION = 5000; // 5 second pause at each corner
private const int RECT_WIDTH = 700; // Width of rectangle
private const int RECT_HEIGHT = 400; // Height of rectangle
private const int MOVE_STEPS = 30; // Steps for smooth movement
private Point initialPosition;
private Point targetPosition;
private Point startPosition;
private int currentStep = 0;
private bool isMovingToTarget = false;
private int currentCorner = 0; // 0: top-right, 1: bottom-right, 2: bottom-left, 3: top-left

public MainForm()
{
InitializeComponent();
Expand Down Expand Up @@ -264,13 +278,136 @@ private string GetDisplayTextForKey(string keyString)

protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312 && m.WParam.ToInt32() == HOTKEY_ID)
if (m.Msg == 0x0312) // WM_HOTKEY
{
ToggleAutomation();
// Original automation hotkey
if (m.WParam.ToInt32() == HOTKEY_ID)
{
ToggleAutomation();

if (isMouseMoveEnabled)
{
ToggleMovement();
}
}
}

base.WndProc(ref m);
}


private void chkMouseMove_CheckedChanged(object sender, EventArgs e)
{
isMouseMoveEnabled = chkMouseMove.Checked;

if (chkMouseMove.Checked)
{
InitializeMouseMovement();
}
else
{
moveTimer.Stop();
}
}

private void InitializeMouseMovement()
{
moveTimer = new System.Windows.Forms.Timer();
moveTimer.Interval = 50;
moveTimer.Tick += MoveTimer_Tick;
}

private void ToggleMovement()
{
isMoving = !isMoving;
if (isMoving)
{
initialPosition = System.Windows.Forms.Cursor.Position;
currentCorner = 0;
StartNextMove();
moveTimer.Start();
}
else
{
moveTimer.Stop();
}
}

private Point GetCornerPosition(int corner)
{
switch (corner)
{
case 0: // Top-right
return new Point(initialPosition.X + RECT_WIDTH / 2, initialPosition.Y - RECT_HEIGHT / 2);
case 1: // Bottom-right
return new Point(initialPosition.X + RECT_WIDTH / 2, initialPosition.Y + RECT_HEIGHT / 2);
case 2: // Bottom-left
return new Point(initialPosition.X - RECT_WIDTH / 2, initialPosition.Y + RECT_HEIGHT / 2);
case 3: // Top-left
return new Point(initialPosition.X - RECT_WIDTH / 2, initialPosition.Y - RECT_HEIGHT / 2);
default:
return initialPosition;
}
}

private void StartNextMove()
{
startPosition = System.Windows.Forms.Cursor.Position;
targetPosition = GetCornerPosition(currentCorner);
currentStep = 0;
isMovingToTarget = true;
}

private async Task PauseBetweenMoves()
{
isMovingToTarget = false;
await Task.Delay(PAUSE_DURATION);
if (isMoving)
{
// Move to next corner
currentCorner = (currentCorner + 1) % 4;
StartNextMove();
}
}

private void MoveTimer_Tick(object sender, EventArgs e)
{
if (!isMoving) return;

if (!isMovingToTarget)
{
return; // We're in a pause
}

// Calculate progress (0.0 to 1.0)
float progress = (float)currentStep / MOVE_STEPS;

// Use easing function to make movement more natural
progress = EaseInOutQuad(progress);

// Calculate new position
int newX = (int)(startPosition.X + (targetPosition.X - startPosition.X) * progress);
int newY = (int)(startPosition.Y + (targetPosition.Y - startPosition.Y) * progress);

// Move cursor
System.Windows.Forms.Cursor.Position = new Point(newX, newY);

// Increment step
currentStep++;

// If we've reached the target, start a pause
if (currentStep >= MOVE_STEPS)
{
_ = PauseBetweenMoves();
}
}

// Easing function to make movement more natural
private float EaseInOutQuad(float t)
{
return t < 0.5f ? 2 * t * t : 1 - (float)Math.Pow(-2 * t + 2, 2) / 2;
}

private void ToggleAutomation()
{
if (!isRunning)
Expand Down Expand Up @@ -368,7 +505,7 @@ private void SimulateKeyPress(Keys key)
keybd_event(vk, 0, 0, UIntPtr.Zero);
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
}

private void SimulateMouseClick(MouseButtons button)
{
if (InvokeRequired)
Expand Down Expand Up @@ -496,9 +633,11 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
SaveSettings();
UnregisterGlobalHotkey();
UnregisterHotKey(this.Handle, 9001); // Unregister F4 hotkey

controllerCheckTimer?.Stop();
controllerCheckTimer?.Dispose();
moveTimer?.Dispose();
controller = null;
}

Expand Down Expand Up @@ -562,6 +701,8 @@ private void SimulateAction(string action)
break;
}
}


}

public class Settings
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("D4Automator")]
[assembly: AssemblyCopyright("Daniel Liedke - Copyright © 2024")]
[assembly: AssemblyCopyright("Daniel Liedke - Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]

0 comments on commit d88862d

Please sign in to comment.