Exemple #1
0
        public static HidNpadIdType GetNpadIdTypeFromIndex(HidControllerID index)
        {
            switch (index)
            {
            case HidControllerID.Player1:  return(HidNpadIdType.Player1);

            case HidControllerID.Player2:  return(HidNpadIdType.Player2);

            case HidControllerID.Player3:  return(HidNpadIdType.Player3);

            case HidControllerID.Player4:  return(HidNpadIdType.Player4);

            case HidControllerID.Player5:  return(HidNpadIdType.Player5);

            case HidControllerID.Player6:  return(HidNpadIdType.Player6);

            case HidControllerID.Player7:  return(HidNpadIdType.Player7);

            case HidControllerID.Player8:  return(HidNpadIdType.Player8);

            case HidControllerID.Handheld: return(HidNpadIdType.Handheld);

            case HidControllerID.Unknown:  return(HidNpadIdType.Unknown);

            default: throw new ArgumentOutOfRangeException(nameof(index));
            }
        }
Exemple #2
0
 public void SendControllerButtons(HidControllerID ControllerId,
                                   HidControllerLayouts Layout,
                                   HidControllerKeys Buttons,
                                   JoystickPosition LeftJoystick,
                                   JoystickPosition RightJoystick)
 {
     Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick);
 }
Exemple #3
0
        public void SendControllerButtons(HidControllerID ControllerId,
                                          HidControllerLayouts Layout,
                                          HidControllerKeys Buttons,
                                          JoystickPosition LeftJoystick,
                                          JoystickPosition RightJoystick)
        {
            uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader)) +
                               (uint)Marshal.SizeOf(typeof(HidTouchScreen)) +
                               (uint)Marshal.SizeOf(typeof(HidMouse)) +
                               (uint)Marshal.SizeOf(typeof(HidKeyboard)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection1)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection2)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection3)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection4)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection5)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection6)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection7)) +
                               (uint)Marshal.SizeOf(typeof(HidUnknownSection8)) +
                               (uint)Marshal.SizeOf(typeof(HidControllerSerials)) +
                               ((uint)(Marshal.SizeOf(typeof(HidController)) * (int)ControllerId)) +
                               (uint)Marshal.SizeOf(typeof(HidControllerHeader)) +
                               (uint)Layout * (uint)Marshal.SizeOf(typeof(HidControllerLayout));

            IntPtr HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);

            HidControllerLayoutHeader OldControllerHeaderLayout = (HidControllerLayoutHeader)Marshal.PtrToStructure(HidPtr, typeof(HidControllerLayoutHeader));

            HidControllerLayoutHeader ControllerLayoutHeader = new HidControllerLayoutHeader
            {
                TimestampTicks = (ulong)Environment.TickCount,
                NumEntries     = (ulong)Hid_Num_Entries,
                MaxEntryIndex  = (ulong)Hid_Num_Entries - 1,
                LatestEntry    = (OldControllerHeaderLayout.LatestEntry < (ulong)Hid_Num_Entries ? OldControllerHeaderLayout.LatestEntry + 1 : 0)
            };

            Marshal.StructureToPtr(ControllerLayoutHeader, HidPtr, false);

            InnerOffset += (uint)Marshal.SizeOf(typeof(HidControllerLayoutHeader)) + (uint)((uint)(ControllerLayoutHeader.LatestEntry) * Marshal.SizeOf(typeof(HidControllerInputEntry)));
            HidPtr       = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);

            HidControllerInputEntry ControllerInputEntry = new HidControllerInputEntry
            {
                Timestamp   = (ulong)Environment.TickCount,
                Timestamp_2 = (ulong)Environment.TickCount,
                Buttons     = (ulong)Buttons,
                Joysticks   = new JoystickPosition[(int)HidControllerJoystick.Joystick_Num_Sticks]
            };

            ControllerInputEntry.Joysticks[(int)HidControllerJoystick.Joystick_Left]  = LeftJoystick;
            ControllerInputEntry.Joysticks[(int)HidControllerJoystick.Joystick_Right] = RightJoystick;
            ControllerInputEntry.ConnectionState = (ulong)(HidControllerConnectionState.Controller_State_Connected | HidControllerConnectionState.Controller_State_Wired);

            Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false);
        }
Exemple #4
0
        // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
        public ResultCode GetNpadIrCameraHandle(ServiceCtx context)
        {
            HidNpadIdType npadIdType = (HidNpadIdType)context.RequestData.ReadUInt32();

            if (npadIdType > HidNpadIdType.Player8 &&
                npadIdType != HidNpadIdType.Unknown &&
                npadIdType != HidNpadIdType.Handheld)
            {
                return(ResultCode.NpadIdOutOfRange);
            }

            HidControllerID irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);

            context.ResponseData.Write((int)irCameraHandle);

            // NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
            //       return ResultCode.HandlePointerIsNull;

            return(ResultCode.Success);
        }
Exemple #5
0
        private void MatchControllers()
        {
            PrimaryControllerId = HidControllerID.Unknown;

            for (int i = 0; i < _configuredNpads.Length; ++i)
            {
                ref NpadConfig p = ref _configuredNpads[i];

                if (p.State == FilterState.Unconfigured)
                {
                    continue;                                       // Ignore unconfigured
                }
                if ((p.ConfiguredType & _supportedStyleSets) == 0)
                {
                    Logger.PrintWarning(LogClass.Hid, $"ControllerType {p.ConfiguredType} (connected to {(HidControllerID)i}) not supported by game. Removing...");
                    p.State = FilterState.Configured;
                    _device.Hid.SharedMemory.Controllers[i] = new HidController();  // Zero it
                    continue;
                }

                InitController((HidControllerID)i, p.ConfiguredType);
            }
Exemple #6
0
        public void AddControllers(params ControllerConfig[] configs)
        {
            for (int i = 0; i < configs.Length; ++i)
            {
                HidControllerID playerId = configs[i].PlayerId;
                ControllerType  type     = configs[i].Type;
                if (playerId > HidControllerID.Handheld)
                {
                    throw new ArgumentOutOfRangeException("playerId must be Player1-8 or Handheld");
                }

                if (type == ControllerType.Handheld)
                {
                    playerId = HidControllerID.Handheld;
                }

                _configuredNpads[(int)playerId] = new NpadConfig {
                    ConfiguredType = type, State = FilterState.Configured
                };
            }

            MatchControllers();
        }