Skip to content

Commit

Permalink
Working Version
Browse files Browse the repository at this point in the history
  • Loading branch information
NAinfini committed Sep 2, 2023
1 parent 465accf commit d2a9c5f
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 162 deletions.
283 changes: 153 additions & 130 deletions GameZBDAlchemyStoneTapper/Detection.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions GameZBDAlchemyStoneTapper/GameZBDAlchemyStoneTapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
<OutputPath>bin\x64\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PackageReference Include="Costura.Fody" Version="5.8.0-alpha0098">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="InputSimulator" Version="1.0.4" />
<PackageReference Include="GregsStack.InputSimulatorStandard" Version="1.3.5" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers">
<Version>0.4.421302</Version>
</PackageReference>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.15.1" />
<PackageReference Include="Microsoft.AspNetCore.SystemWebAdapters" Version="1.2.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.15.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.15.1" />
<PackageReference Include="NumSharp" Version="0.30.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="7.0.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0-preview.7.23375.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
Expand Down
7 changes: 7 additions & 0 deletions GameZBDAlchemyStoneTapper/GlobalHotkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ public GlobalHotkey(ModifierKeys modifier, Key key, Action callbackMethod, bool
this.Callback = callbackMethod;
this.CanExecute = canExecute;
}

public GlobalHotkey(Key key, Action callbackMethod, bool canExecute = true)
{
this.Key = key;
this.Callback = callbackMethod;
this.CanExecute = canExecute;
}
}
}
250 changes: 250 additions & 0 deletions GameZBDAlchemyStoneTapper/InputSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
using System;
using System.Runtime.InteropServices;

namespace GameZBDAlchemyStoneTapper
{
public class InputSender
{
#region Imports/Structs/Enums

[StructLayout(LayoutKind.Sequential)]
public struct KeyboardInput
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct MouseInput
{
public int dx;
public int dy;
public uint mouseData;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct HardwareInput
{
public uint uMsg;
public ushort wParamL;
public ushort wParamH;
}

[StructLayout(LayoutKind.Explicit)]
public struct InputUnion
{
[FieldOffset(0)] public MouseInput mi;
[FieldOffset(0)] public KeyboardInput ki;
[FieldOffset(0)] public HardwareInput hi;
}

public struct Input
{
public int type;
public InputUnion u;
}

[Flags]
public enum InputType
{
Mouse = 0,
Keyboard = 1,
Hardware = 2
}

[Flags]
public enum KeyEventF
{
KeyDown = 0x0000,
ExtendedKey = 0x0001,
KeyUp = 0x0002,
Unicode = 0x0004,
Scancode = 0x0008
}

[Flags]
public enum MouseEventF
{
Absolute = 0x8000,
HWheel = 0x01000,
Move = 0x0001,
MoveNoCoalesce = 0x2000,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
VirtualDesk = 0x4000,
Wheel = 0x0800,
XDown = 0x0080,
XUp = 0x0100
}

[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint nInputs, Input[] pInputs, int cbSize);

[DllImport("user32.dll")]
private static extern IntPtr GetMessageExtraInfo();

[DllImport("user32.dll")]
private static extern bool GetCursorPos(out POINT lpPoint);

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}

[DllImport("User32.dll")]
private static extern bool SetCursorPos(int x, int y);

#endregion Imports/Structs/Enums

#region Wrapper Methods

public static POINT GetCursorPosition()
{
GetCursorPos(out POINT point);
return point;
}

public static void SetCursorPosition(int x, int y)
{
SetCursorPos(x, y);
}

public static void SendKeyboardInput(KeyboardInput[] kbInputs)
{
Input[] inputs = new Input[kbInputs.Length];

for (int i = 0; i < kbInputs.Length; i++)
{
inputs[i] = new Input
{
type = (int)InputType.Keyboard,
u = new InputUnion
{
ki = kbInputs[i]
}
};
}

SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
}

public static void ClickKey(ushort scanCode)
{
var inputs = new KeyboardInput[]
{
new KeyboardInput
{
wScan = scanCode,
dwFlags = (uint)(KeyEventF.KeyDown | KeyEventF.Scancode),
dwExtraInfo = GetMessageExtraInfo()
},
new KeyboardInput
{
wScan = scanCode,
dwFlags = (uint)(KeyEventF.KeyUp | KeyEventF.Scancode),
dwExtraInfo = GetMessageExtraInfo()
}
};
SendKeyboardInput(inputs);
}

public static void SendMouseInput(MouseInput[] mInputs)
{
Input[] inputs = new Input[mInputs.Length];

for (int i = 0; i < mInputs.Length; i++)
{
inputs[i] = new Input
{
type = (int)InputType.Mouse,
u = new InputUnion
{
mi = mInputs[i]
}
};
}

SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
}

#endregion Wrapper Methods

public static void LeftClick()
{
Input[] inputs = new Input[]
{
new Input
{
type = (int) InputType.Mouse,
u = new InputUnion
{
mi = new MouseInput
{
dwFlags = (uint)( MouseEventF.LeftDown),
dwExtraInfo = GetMessageExtraInfo()
}
}
},
new Input
{
type = (int) InputType.Mouse,
u = new InputUnion
{
mi = new MouseInput
{
dwFlags = (uint)MouseEventF.LeftUp,
dwExtraInfo = GetMessageExtraInfo()
}
}
}
};

SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
}

public static void RightClick()
{
Input[] inputs = new Input[]
{
new Input
{
type = (int) InputType.Mouse,
u = new InputUnion
{
mi = new MouseInput
{
dwFlags = (uint)( MouseEventF.RightDown),
dwExtraInfo = GetMessageExtraInfo()
}
}
},
new Input
{
type = (int) InputType.Mouse,
u = new InputUnion
{
mi = new MouseInput
{
dwFlags = (uint)MouseEventF.RightUp,
dwExtraInfo = GetMessageExtraInfo()
}
}
}
};

SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
}
}
}
85 changes: 85 additions & 0 deletions GameZBDAlchemyStoneTapper/MouseClickerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using GregsStack.InputSimulatorStandard;
using NumSharp.Utilities;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static GameZBDAlchemyStoneTapper.InputSender;

namespace GameZBDAlchemyStoneTapper
{
internal class MouseClickHelper
{
private static InputSimulator Ins = new InputSimulator();

[DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy,
int dwData, int dwExtraInfo);

[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
private static extern void SetCursorPos(int X, int Y);

[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}

public static void LeftClick(int x, int y)
{
SetCursorPos(x, y);
Thread.Sleep(50);
Ins.Mouse.LeftButtonDown();
Thread.Sleep(50);
Ins.Mouse.LeftButtonUp();
}

public static void LeftClick(Point pt)
{
SetCursorPos(pt.X, pt.Y);
Thread.Sleep(50);
Ins.Mouse.LeftButtonDown();
Thread.Sleep(50);
Ins.Mouse.LeftButtonUp();
}

public static void RightClick(int x, int y)
{
SetCursorPos(x, y);
Thread.Sleep(50);
Ins.Mouse.RightButtonDown();
Thread.Sleep(50);
Ins.Mouse.RightButtonUp();
}

public static void RightClick(Point pt)
{
SetCursorPos(pt.X, pt.Y);
Thread.Sleep(50);
Ins.Mouse.RightButtonDown();
Thread.Sleep(50);
Ins.Mouse.RightButtonUp();
}

public static void PressSpace()
{
Ins.Keyboard.KeyPress(GregsStack.InputSimulatorStandard.Native.VirtualKeyCode.SPACE);
}

public static void PressEnter()
{
Ins.Keyboard.KeyPress(GregsStack.InputSimulatorStandard.Native.VirtualKeyCode.EXECUTE);
}
}
}
Loading

0 comments on commit d2a9c5f

Please sign in to comment.