forked from MeloNX/MeloNX
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2208 warnings * Address or silence dotnet format CA1806 and a few CA1854 warnings * Address dotnet format CA2211 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Make dotnet format succeed in style mode * Address or silence dotnet format CA2211 warnings * Address review comments * Address dotnet format CA2208 warnings properly * Make ProcessResult readonly * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix a few disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Run dotnet format after rebase * Use using declaration instead of block syntax * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Fix typo * Add trailing commas, use targeted new and use array initializer * Fix build issues * Fix remaining build issues * Remove SuppressMessage for CA1069 where possible * Address dotnet format issues * Address formatting issues Co-authored-by: Ac_K <acoustik666@gmail.com> * Add GetHashCode implementation for RenderingSurfaceInfo * Explicitly silence CA1822 for every affected method in Syscall * Address formatting issues in Demangler.cs * Address review feedback Co-authored-by: Ac_K <acoustik666@gmail.com> * Revert marking service methods as static * Next dotnet format pass * Address review feedback --------- Co-authored-by: Ac_K <acoustik666@gmail.com>
146 lines
5.5 KiB
C#
146 lines
5.5 KiB
C#
using Ryujinx.Common.Logging;
|
|
using Ryujinx.Common.Memory;
|
|
using Ryujinx.HLE.HOS.Services.Am.AppletAE;
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using static Ryujinx.HLE.HOS.Services.Hid.HidServer.HidUtils;
|
|
|
|
namespace Ryujinx.HLE.HOS.Applets
|
|
{
|
|
internal class ControllerApplet : IApplet
|
|
{
|
|
private readonly Horizon _system;
|
|
|
|
private AppletSession _normalSession;
|
|
|
|
public event EventHandler AppletStateChanged;
|
|
|
|
public ControllerApplet(Horizon system)
|
|
{
|
|
_system = system;
|
|
}
|
|
|
|
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
|
|
{
|
|
_normalSession = normalSession;
|
|
|
|
byte[] launchParams = _normalSession.Pop();
|
|
byte[] controllerSupportArgPrivate = _normalSession.Pop();
|
|
ControllerSupportArgPrivate privateArg = IApplet.ReadStruct<ControllerSupportArgPrivate>(controllerSupportArgPrivate);
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerApplet ArgPriv {privateArg.PrivateSize} {privateArg.ArgSize} {privateArg.Mode} " +
|
|
$"HoldType:{(NpadJoyHoldType)privateArg.NpadJoyHoldType} StyleSets:{(ControllerType)privateArg.NpadStyleSet}");
|
|
|
|
if (privateArg.Mode != ControllerSupportMode.ShowControllerSupport)
|
|
{
|
|
_normalSession.Push(BuildResponse()); // Dummy response for other modes
|
|
AppletStateChanged?.Invoke(this, null);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
byte[] controllerSupportArg = _normalSession.Pop();
|
|
|
|
ControllerSupportArgHeader argHeader;
|
|
|
|
if (privateArg.ArgSize == Marshal.SizeOf<ControllerSupportArgV7>())
|
|
{
|
|
ControllerSupportArgV7 arg = IApplet.ReadStruct<ControllerSupportArgV7>(controllerSupportArg);
|
|
argHeader = arg.Header;
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerSupportArg Version 7 EnableExplainText={arg.EnableExplainText != 0}");
|
|
// Read enable text here?
|
|
}
|
|
else if (privateArg.ArgSize == Marshal.SizeOf<ControllerSupportArgVPre7>())
|
|
{
|
|
ControllerSupportArgVPre7 arg = IApplet.ReadStruct<ControllerSupportArgVPre7>(controllerSupportArg);
|
|
argHeader = arg.Header;
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerSupportArg Version Pre-7 EnableExplainText={arg.EnableExplainText != 0}");
|
|
// Read enable text here?
|
|
}
|
|
else
|
|
{
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, "ControllerSupportArg Version Unknown");
|
|
|
|
argHeader = IApplet.ReadStruct<ControllerSupportArgHeader>(controllerSupportArg); // Read just the header
|
|
}
|
|
|
|
int playerMin = argHeader.PlayerCountMin;
|
|
int playerMax = argHeader.PlayerCountMax;
|
|
bool singleMode = argHeader.EnableSingleMode != 0;
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerApplet Arg {playerMin} {playerMax} {argHeader.EnableTakeOverConnection} {argHeader.EnableSingleMode}");
|
|
|
|
if (singleMode)
|
|
{
|
|
// Applications can set an arbitrary player range even with SingleMode, so clamp it
|
|
playerMin = playerMax = 1;
|
|
}
|
|
|
|
int configuredCount;
|
|
PlayerIndex primaryIndex;
|
|
while (!_system.Device.Hid.Npads.Validate(playerMin, playerMax, (ControllerType)privateArg.NpadStyleSet, out configuredCount, out primaryIndex))
|
|
{
|
|
ControllerAppletUiArgs uiArgs = new()
|
|
{
|
|
PlayerCountMin = playerMin,
|
|
PlayerCountMax = playerMax,
|
|
SupportedStyles = (ControllerType)privateArg.NpadStyleSet,
|
|
SupportedPlayers = _system.Device.Hid.Npads.GetSupportedPlayers(),
|
|
IsDocked = _system.State.DockedMode,
|
|
};
|
|
|
|
if (!_system.Device.UiHandler.DisplayMessageDialog(uiArgs))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
ControllerSupportResultInfo result = new()
|
|
{
|
|
PlayerCount = (sbyte)configuredCount,
|
|
SelectedId = (uint)GetNpadIdTypeFromIndex(primaryIndex),
|
|
};
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceHid, $"ControllerApplet ReturnResult {result.PlayerCount} {result.SelectedId}");
|
|
|
|
_normalSession.Push(BuildResponse(result));
|
|
AppletStateChanged?.Invoke(this, null);
|
|
|
|
_system.ReturnFocus();
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
public ResultCode GetResult()
|
|
{
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
private static byte[] BuildResponse(ControllerSupportResultInfo result)
|
|
{
|
|
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
|
using BinaryWriter writer = new(stream);
|
|
|
|
writer.Write(MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref result, Unsafe.SizeOf<ControllerSupportResultInfo>())));
|
|
|
|
return stream.ToArray();
|
|
}
|
|
|
|
private static byte[] BuildResponse()
|
|
{
|
|
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
|
using BinaryWriter writer = new(stream);
|
|
|
|
writer.Write((ulong)ResultCode.Success);
|
|
|
|
return stream.ToArray();
|
|
}
|
|
}
|
|
}
|