komefai / PS4Macro

Automation utility for PS4 Remote Play written in C#
http://blog.komefai.com
MIT License
378 stars 89 forks source link

Remap Gyro to Mouse #87

Open KITATUS opened 5 years ago

KITATUS commented 5 years ago

So I am looking at the code and can see that the macro recorder can take in and spit out GyroX and GyroY. I'm trying to judge the possibility of instead of sending left stick, right stick commands using the mouse sending Gyro X and Y instead.

The reason I feel this will be helpful is in titles such as Dreams, the inspiration for me picking up PS4Macro in the first place.

In Dreams, it seems the gyro values themselves don't matter as they can be "recentered" - so I assume it's possible to do a GyroX++ / GyroY++ with a clamp or something along those lines.

(As an example, I recorded a macro out of GyroX, GyroY and GyroZ and the values range from 2197 - 1830)

Does anybody know the ideal place to put this code? I assume introduce a chunk in the "IsLeftStick" or "IsRightStick" and send the gyro data there? I took a look at the remapper class and it's a little confusing in terms of how to send GyroX, GyroY based on the X and Y of the mouse due to the map of the button inputs being more abstract that I anticipated.

This is more of a soapbox to drop suggestions and whatnot as I try to work on this but if anybody else wanted to help, it would be greatly appreciated. The best way I could recieve help at the moment is a general idea of how I'd form the GyroX call in the remapper class to be treated like a PS4 controller input ala the left stick and right stick.

Cheers!

KITATUS commented 5 years ago

I have tried the approach of using a macro script (based on mouse position) but I can't seem to get the gyro working reliably. Attached is the current script as it stands.

using PS4MacroAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace KitGyro
{
    public class Script : ScriptBase
    {
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;
        } `

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

        public Script()
        {
            Config.Name = "KitGyro";
        }

        public override void Start()
        {
            base.Start();
        }

        public override void Update()
        {

            int X = Cursor.Position.X * 1000;
            int Y = Cursor.Position.Y * 1000;

            base.Update();

            Press(new DualShockState() { GyroX = (short)X });
            Press(new DualShockState() { GyroX = (short)Y });

        }
    }
}

After this, I tried giving just standard Gyro values, with:

            Press(new DualShockState() { GyroX = 0 });
            Press(new DualShockState() { GyroY = 0 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 1000 });
            Press(new DualShockState() { GyroY = 100 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 0 });
            Press(new DualShockState() { GyroY = 0 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 1000 });
            Press(new DualShockState() { GyroY = 1000 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 0 });
            Press(new DualShockState() { GyroY = 0 });
            Sleep(10);
            Press(new DualShockState() { GyroX = -500 });
            Press(new DualShockState() { GyroY = -500 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 0 });
            Press(new DualShockState() { GyroY = 0 });
            Sleep(10);
            Press(new DualShockState() { GyroX = 100 });
            Press(new DualShockState() { GyroY = -100 }); 

But even then the script was acting unreliably, which worries in terms of if the Gyro functionality is working correctly in the first place.