Initialize hid inputs on activation (#2246)

This commit is contained in:
Caian Benedicto 2021-04-26 05:44:20 -03:00 committed by GitHub
parent cac4f31dfa
commit ec97a8a1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Hid
@ -70,6 +71,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
long appletResourceUserId = context.RequestData.ReadInt64();
// Initialize entries to avoid issues with some games.
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.DebugPad.Update();
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
return ResultCode.Success;
@ -83,6 +91,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid
context.Device.Hid.Touchscreen.Active = true;
// Initialize entries to avoid issues with some games.
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.Touchscreen.Update();
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
return ResultCode.Success;
@ -96,6 +111,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid
context.Device.Hid.Mouse.Active = true;
// Initialize entries to avoid issues with some games.
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.Mouse.Update(0, 0);
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
return ResultCode.Success;
@ -109,6 +131,16 @@ namespace Ryujinx.HLE.HOS.Services.Hid
context.Device.Hid.Keyboard.Active = true;
// Initialize entries to avoid issues with some games.
KeyboardInput emptyInput = new KeyboardInput();
emptyInput.Keys = new int[8];
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.Keyboard.Update(emptyInput);
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
return ResultCode.Success;
@ -618,6 +650,32 @@ namespace Ryujinx.HLE.HOS.Services.Hid
long appletResourceUserId = context.RequestData.ReadInt64();
context.Device.Hid.Npads.Active = true;
// Initialize entries to avoid issues with some games.
List<GamepadInput> emptyGamepadInputs = new List<GamepadInput>();
List<SixAxisInput> emptySixAxisInputs = new List<SixAxisInput>();
for (int player = 0; player < NpadDevices.MaxControllers; player++)
{
GamepadInput gamepadInput = new GamepadInput();
SixAxisInput sixaxisInput = new SixAxisInput();
gamepadInput.PlayerId = (PlayerIndex)player;
sixaxisInput.PlayerId = (PlayerIndex)player;
sixaxisInput.Orientation = new float[9];
emptyGamepadInputs.Add(gamepadInput);
emptySixAxisInputs.Add(sixaxisInput);
}
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.Npads.Update(emptyGamepadInputs);
context.Device.Hid.Npads.UpdateSixAxis(emptySixAxisInputs);
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
return ResultCode.Success;
@ -690,6 +748,31 @@ namespace Ryujinx.HLE.HOS.Services.Hid
int revision = context.RequestData.ReadInt32();
long appletResourceUserId = context.RequestData.ReadInt64();
// Initialize entries to avoid issues with some games.
List<GamepadInput> emptyGamepadInputs = new List<GamepadInput>();
List<SixAxisInput> emptySixAxisInputs = new List<SixAxisInput>();
for (int player = 0; player < NpadDevices.MaxControllers; player++)
{
GamepadInput gamepadInput = new GamepadInput();
SixAxisInput sixaxisInput = new SixAxisInput();
gamepadInput.PlayerId = (PlayerIndex)player;
sixaxisInput.PlayerId = (PlayerIndex)player;
sixaxisInput.Orientation = new float[9];
emptyGamepadInputs.Add(gamepadInput);
emptySixAxisInputs.Add(sixaxisInput);
}
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
{
context.Device.Hid.Npads.Update(emptyGamepadInputs);
context.Device.Hid.Npads.UpdateSixAxis(emptySixAxisInputs);
}
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, revision });
return ResultCode.Success;