Seconb / Aimmy-Arduino-Edition

Aimmy... but with Arduino support!
Other
32 stars 7 forks source link

Code to communicate to USB Host Shield. #14

Closed AimmyHS closed 3 months ago

AimmyHS commented 4 months ago

Code to communicate to USB Host Shield. Working great on my computer.

Arduino side: https://github.com/SunOner/HID_Arduino (Default baud rate: 9600, change that or change the baud rate in the following code)

using System;
using System.IO.Ports;
using System.Text;

namespace MouseMovementLibraries.HostShieldSupport
{
    public class ArduinoHostShield
    {
        public ArduinoHostShield() { }

        private SerialPort serialPort = new SerialPort();
        private bool Open = false;

        public void StartArduinoMouse()
        {
            string[] ports = System.IO.Ports.SerialPort.GetPortNames();

            // Select the COM port with the minimum number (Normally there is just one, so I'll just leave it as it is)
            serialPort.PortName = ports[0];

            serialPort.BaudRate = 115200; // Please match the baud rate with arduino side
            serialPort.DataBits = 8;
            serialPort.StopBits = StopBits.One;
            serialPort.Parity = Parity.None;
            serialPort.Open();
            Open = true;
        }

        public void SendMouseCoordinates(int x, int y)
        {
            if (!Open) StartArduinoMouse();
            if (x != 0 || y != 0)
            {
                string message = $"m{x},{y}\n";
                byte[] encodedBytes = Encoding.UTF8.GetBytes(message);
                serialPort.Write(Encoding.UTF8.GetString(encodedBytes));
            }
        }

        public void SendMouseClick(int press)
        {
            if (!Open) StartArduinoMouse();
            string message = "r\n";
            if(press == 1)
            {
                message = "p\n";
            }
            else
            {
                message = "r\n";
            }
            byte[] encodedBytes = Encoding.UTF8.GetBytes(message);
            serialPort.Write(Encoding.UTF8.GetString(encodedBytes));
        }
    }
}
Seconb commented 3 months ago

this defeats the purpose of using hid communication

the reason i communicate over hid rather than com ports is because it’s harder for anti cheats to detect, in fact with a host shield this would even be undetected on valorant

Seconb commented 3 months ago

also get out with this bullshit ass chatgpt solution, if it was this easy i would’ve added it already

AimmyHS commented 3 months ago

OK how about this? I took your HID communication code and put it in 'HID_Arduino', and removed the COM communication part. I tried it out on my computer it worked. Since my mouse is 8-bit, I only utilized the lower bits of x and y. HID_Communication_HS.zip