D4Automator is a Windows Forms desktop application (.NET Framework 4.8, C#) that automates Diablo IV PC actions including skills 1-4, primary/secondary attacks, potions, dodge, and mouse movement for Infernal Hordes. It uses global hotkeys and supports Xbox controller detection to auto-pause/resume automation.
- Solution:
D4Automator.sln(single-project solution) - Framework: .NET Framework 4.8 (WinForms)
- Build: Open in Visual Studio or run
msbuild D4Automator.sln /p:Configuration=Release - Output:
bin\Debug\orbin\Release\ - Dependencies: SharpDX 4.2.0 and SharpDX.XInput 4.2.0 (NuGet via
packages.config) - Restore packages:
nuget restore D4Automator.sln
D4Automator/
Program.cs - Entry point (DPI-aware, launches MainForm)
MainForm.cs - Main application logic (automation loops, key simulation,
mouse movement, controller detection, overlay, settings
persistence, file save/load, recent files)
MainForm.Designer.cs - WinForms designer (auto-generated, do NOT edit manually)
MainForm.resx - Form resources (auto-generated)
KeyConfigForm.cs - Key/mouse binding configuration dialog
KeyConfigForm.Designer.cs - Designer (auto-generated)
HordesConfigForm.cs - Infernal Hordes movement settings dialog
HordesConfigForm.Designer.cs - Designer (auto-generated)
Properties/
AssemblyInfo.cs - Assembly version and metadata
Builds/ - Sample build configuration JSON files
App.config - .NET runtime configuration
packages.config - NuGet package references
- MainForm.cs contains nearly all logic:
Settingsclass (serializable config model),OverlayFormclass (transparent always-on-top status display), andMainForm(the main form). - Settings persistence: Internal settings stored as XML (
D4AutomatorSettings.xml). User configurations saved/loaded as JSON files. Custom JSON serializer/deserializer (no external JSON library). - Automation: Runs async loops per action (
RunActionLoop), each pressing a key/mouse button at configured intervals. Delay of0= disabled, delay of1= hold key pressed. - Input simulation: Win32
keybd_eventandmouse_eventvia P/Invoke. Supports keyboard keys, left/right/middle/X1/X2 mouse buttons. - Global hotkeys: Win32
RegisterHotKey/UnregisterHotKeyfor toggle automation (default F5) and toggle hordes automation (default F6). - Controller support: SharpDX.XInput polls Xbox controller every 50ms; pauses automation when sticks/D-pad are moved, resumes when released.
- Hordes mouse movement: Elliptical cursor path (16:9 aspect ratio), alternates clockwise/counter-clockwise every 1.5 revolutions.
- Overlay:
OverlayFormis a click-through transparent window showing current automation status (usesWS_EX_LAYERED | WS_EX_TRANSPARENTwindow styles). - Dark mode: Applied programmatically to all forms.
IMPORTANT: When making code changes, always increment the assembly version in Properties/AssemblyInfo.cs. Update both AssemblyVersion and AssemblyFileVersion attributes. The version is displayed in the form title bar via SetFormTitle().
Current version format: Major.Minor.Build.0 (e.g., 2.7.0.0). Increment the minor version for feature changes or the build number for bug fixes.
Commit messages should follow the pattern: {version} - {description} (e.g., 2.7 - Fix issues with controller).
MainForm(MainForm.cs) - Main form with all automation logicSettings(MainForm.cs:1456) - Configuration model with delay/action properties and defaultsOverlayForm(MainForm.cs:1515) - Transparent overlay showing automation statusKeyConfigForm(KeyConfigForm.cs) - Key binding configuration dialogHordesConfigForm(HordesConfigForm.cs) - Hordes movement parameter dialog
- Designer files: Never manually edit
*.Designer.csor*.resxfiles - these are auto-generated by the WinForms designer. - Dark mode: All new forms/controls must have dark mode styling applied (background
Color.FromArgb(30, 30, 30)or(45, 45, 48), foregroundColor.White). - Key actions: Stored as strings - either
System.Windows.Forms.Keysenum names (e.g.,"D1","F5","Space") or mouse action strings ("LeftClick","RightClick","MiddleClick","MouseBack","MouseForward"). - P/Invoke: All Win32 interop is done in
MainForm.csusingDllImportattributes. - No external JSON library: Settings serialization uses custom
StringBuilder-based JSON writer and manual line-by-line parser. - UI thread safety: Input simulation methods check
InvokeRequiredand marshal to UI thread viaInvoke. - Restricted keys: Modifier keys (Alt, Shift, Ctrl, Win), Tab, CapsLock, NumLock, Enter, etc. cannot be bound as actions (see
KeyConfigForm.RestrictedKeys).
D4AutomatorSettings.xml- Auto-saved XML with all current settings (created next to the executable)RecentFiles.txt- List of recently opened JSON config files (up to 5)Builds/*.json- Sample user build configurations with skill delays and key bindings