public void SendControllerButtons(HidControllerID ControllerId, HidControllerLayouts Layout, HidControllerKeys Buttons, JoystickPosition LeftJoystick, JoystickPosition RightJoystick) { Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick); }
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); }
public void SetJoyconButton( HidControllerId ControllerId, HidControllerLayouts ControllerLayout, HidControllerButtons Buttons, HidJoystickPosition LeftStick, HidJoystickPosition RightStick) { Buttons |= UpdateStickButtons(LeftStick, RightStick); long ControllerOffset = HidPosition + HidControllersOffset; ControllerOffset += (int)ControllerId * HidControllerSize; ControllerOffset += HidControllerHeaderSize; ControllerOffset += (int)ControllerLayout * HidControllerLayoutsSize; long LastEntry = Device.Memory.ReadInt64(ControllerOffset + 0x10); long CurrEntry = (LastEntry + 1) % HidEntryCount; long Timestamp = GetTimestamp(); Device.Memory.WriteInt64(ControllerOffset + 0x0, Timestamp); Device.Memory.WriteInt64(ControllerOffset + 0x8, HidEntryCount); Device.Memory.WriteInt64(ControllerOffset + 0x10, CurrEntry); Device.Memory.WriteInt64(ControllerOffset + 0x18, HidEntryCount - 1); ControllerOffset += HidControllersLayoutHeaderSize; long LastEntryOffset = ControllerOffset + LastEntry * HidControllersInputEntrySize; ControllerOffset += CurrEntry * HidControllersInputEntrySize; long SampleCounter = Device.Memory.ReadInt64(LastEntryOffset) + 1; Device.Memory.WriteInt64(ControllerOffset + 0x0, SampleCounter); Device.Memory.WriteInt64(ControllerOffset + 0x8, SampleCounter); Device.Memory.WriteInt64(ControllerOffset + 0x10, (uint)Buttons); Device.Memory.WriteInt32(ControllerOffset + 0x18, LeftStick.DX); Device.Memory.WriteInt32(ControllerOffset + 0x1c, LeftStick.DY); Device.Memory.WriteInt32(ControllerOffset + 0x20, RightStick.DX); Device.Memory.WriteInt32(ControllerOffset + 0x24, RightStick.DY); Device.Memory.WriteInt64(ControllerOffset + 0x28, (uint)HidControllerConnState.Controller_State_Connected | (uint)HidControllerConnState.Controller_State_Wired); }
protected long WriteInput( HidControllerButtons buttons, HidJoystickPosition leftStick, HidJoystickPosition rightStick, HidControllerLayouts controllerLayout) { long controllerOffset = Offset + HidControllerHeaderSize; controllerOffset += (int)controllerLayout * HidControllerLayoutsSize; long lastEntry = Device.Memory.ReadInt64(controllerOffset + 0x10); long currEntry = (lastEntry + 1) % HidEntryCount; long timestamp = GetTimestamp(); Device.Memory.WriteInt64(controllerOffset + 0x00, timestamp); Device.Memory.WriteInt64(controllerOffset + 0x08, HidEntryCount); Device.Memory.WriteInt64(controllerOffset + 0x10, currEntry); Device.Memory.WriteInt64(controllerOffset + 0x18, HidEntryCount - 1); controllerOffset += HidControllersLayoutHeaderSize; long lastEntryOffset = controllerOffset + lastEntry * HidControllersInputEntrySize; controllerOffset += currEntry * HidControllersInputEntrySize; long sampleCounter = Device.Memory.ReadInt64(lastEntryOffset) + 1; Device.Memory.WriteInt64(controllerOffset + 0x00, sampleCounter); Device.Memory.WriteInt64(controllerOffset + 0x08, sampleCounter); Device.Memory.WriteInt64(controllerOffset + 0x10, (uint)buttons); Device.Memory.WriteInt32(controllerOffset + 0x18, leftStick.Dx); Device.Memory.WriteInt32(controllerOffset + 0x1c, leftStick.Dy); Device.Memory.WriteInt32(controllerOffset + 0x20, rightStick.Dx); Device.Memory.WriteInt32(controllerOffset + 0x24, rightStick.Dy); return(controllerOffset); }
protected long WriteInput( HidControllerButtons Buttons, HidJoystickPosition LeftStick, HidJoystickPosition RightStick, HidControllerLayouts ControllerLayout) { long ControllerOffset = Offset + HidControllerHeaderSize; ControllerOffset += (int)ControllerLayout * HidControllerLayoutsSize; long LastEntry = Device.Memory.ReadInt64(ControllerOffset + 0x10); long CurrEntry = (LastEntry + 1) % HidEntryCount; long Timestamp = GetTimestamp(); Device.Memory.WriteInt64(ControllerOffset + 0x00, Timestamp); Device.Memory.WriteInt64(ControllerOffset + 0x08, HidEntryCount); Device.Memory.WriteInt64(ControllerOffset + 0x10, CurrEntry); Device.Memory.WriteInt64(ControllerOffset + 0x18, HidEntryCount - 1); ControllerOffset += HidControllersLayoutHeaderSize; long LastEntryOffset = ControllerOffset + LastEntry * HidControllersInputEntrySize; ControllerOffset += CurrEntry * HidControllersInputEntrySize; long SampleCounter = Device.Memory.ReadInt64(LastEntryOffset) + 1; Device.Memory.WriteInt64(ControllerOffset + 0x00, SampleCounter); Device.Memory.WriteInt64(ControllerOffset + 0x08, SampleCounter); Device.Memory.WriteInt64(ControllerOffset + 0x10, (uint)Buttons); Device.Memory.WriteInt32(ControllerOffset + 0x18, LeftStick.DX); Device.Memory.WriteInt32(ControllerOffset + 0x1c, LeftStick.DY); Device.Memory.WriteInt32(ControllerOffset + 0x20, RightStick.DX); Device.Memory.WriteInt32(ControllerOffset + 0x24, RightStick.DY); return(ControllerOffset); }