Skip to content

Latest commit

 

History

History
79 lines (61 loc) · 5.41 KB

File metadata and controls

79 lines (61 loc) · 5.41 KB

D4Automator - Project Guide

Project Overview

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.

Build & Run

  • 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\ or bin\Release\
  • Dependencies: SharpDX 4.2.0 and SharpDX.XInput 4.2.0 (NuGet via packages.config)
  • Restore packages: nuget restore D4Automator.sln

Project Structure

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

Key Architecture

  • MainForm.cs contains nearly all logic: Settings class (serializable config model), OverlayForm class (transparent always-on-top status display), and MainForm (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 of 0 = disabled, delay of 1 = hold key pressed.
  • Input simulation: Win32 keybd_event and mouse_event via P/Invoke. Supports keyboard keys, left/right/middle/X1/X2 mouse buttons.
  • Global hotkeys: Win32 RegisterHotKey/UnregisterHotKey for 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: OverlayForm is a click-through transparent window showing current automation status (uses WS_EX_LAYERED | WS_EX_TRANSPARENT window styles).
  • Dark mode: Applied programmatically to all forms.

Versioning

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).

Key Classes & Types

  • MainForm (MainForm.cs) - Main form with all automation logic
  • Settings (MainForm.cs:1456) - Configuration model with delay/action properties and defaults
  • OverlayForm (MainForm.cs:1515) - Transparent overlay showing automation status
  • KeyConfigForm (KeyConfigForm.cs) - Key binding configuration dialog
  • HordesConfigForm (HordesConfigForm.cs) - Hordes movement parameter dialog

Important Conventions

  • Designer files: Never manually edit *.Designer.cs or *.resx files - 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), foreground Color.White).
  • Key actions: Stored as strings - either System.Windows.Forms.Keys enum names (e.g., "D1", "F5", "Space") or mouse action strings ("LeftClick", "RightClick", "MiddleClick", "MouseBack", "MouseForward").
  • P/Invoke: All Win32 interop is done in MainForm.cs using DllImport attributes.
  • 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 InvokeRequired and marshal to UI thread via Invoke.
  • Restricted keys: Modifier keys (Alt, Shift, Ctrl, Win), Tab, CapsLock, NumLock, Enter, etc. cannot be bound as actions (see KeyConfigForm.RestrictedKeys).

Configuration Files

  • 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