JibbSmart / JoyShockLibrary

Read DualSense, DualShock 4, JoyCon, and Pro Controller input on PC -- compiled for Windows, but code should work on other platforms.
Other
233 stars 47 forks source link

TOUCH_STATE returning methods yield incorrect sequence of values [C#] #37

Open salty-sweet opened 3 years ago

salty-sweet commented 3 years ago

VERSION: Release v2.2.0

ISSUE

The TOUCH_STATE struct I used and added into JoyShockLibrary.cs was in a wrong form despite the fact that I directly copied it from JoyShockLibrary.h @ Line 111. Here's TOUCH_STATE struct declared on that said file:

typedef struct TOUCH_STATE {
    int t0Id;
    int t1Id;
    bool t0Down;
    bool t1Down;
    float t0X;
    float t0Y;
    float t1X;
    float t1Y;
} TOUCH_STATE;

...and here's that same struct I converted to C# initially:

    [StructLayout(LayoutKind.Sequential)]
    public struct TOUCH_STATE {
        public int t0Id;
        public int t1Id;
        public bool t0Down;
        public bool t1Down;
        public float t0X;
        public float t0Y;
        public float t1X;
        public float t1Y;
    }

It is already identical, and yet it yields data in a different sequence. I found out later on that the methods that return TOUCH_STATE structs do not contain any values that should be for t1Down.

WORKAROUND SOLUTION

Putting the public bool t1Down; or public float t1Down; at the very bottom of the struct returns proper values for both touches. This is how the C# struct looks now:

    [StructLayout(LayoutKind.Sequential)]
    public struct MODIFIED_TOUCH_STATE
    {
        public int t0Id;
        public int t1Id;
        public bool t0Down;
        public float t0X;
        public float t0Y;
        public float t1X;
        public float t1Y;
        public float t1Down;   // still nothing
    }

My tests still don't show any change in value on t1Down after moving it downwards, so I'm thinking there's no value for checking if there's a second touch? I wish to help look into your source code to pinpoint where this problem stems from, but I don't know much about C++. I'm just going to bet that it's within the InputHelpers.cpp of yours.

I'm willing to answer further questions that may help you!