chore: applets: Cleanup redundant ReadStruct implementations & provide a default implementation for IApplet#GetResult.

This commit is contained in:
Evan Husted 2024-12-04 02:24:40 -06:00
parent 08b7257be5
commit 07690e4527
10 changed files with 7 additions and 53 deletions

View File

@ -24,11 +24,9 @@ namespace Ryujinx.HLE.HOS.Applets
case AppletId.SoftwareKeyboard: case AppletId.SoftwareKeyboard:
return new SoftwareKeyboardApplet(system); return new SoftwareKeyboardApplet(system);
case AppletId.LibAppletWeb: case AppletId.LibAppletWeb:
return new BrowserApplet(system);
case AppletId.LibAppletShop: case AppletId.LibAppletShop:
return new BrowserApplet(system);
case AppletId.LibAppletOff: case AppletId.LibAppletOff:
return new BrowserApplet(system); return new BrowserApplet();
case AppletId.MiiEdit: case AppletId.MiiEdit:
Logger.Warning?.Print(LogClass.Application, $"Please use the MiiEdit inside File/Open Applet"); Logger.Warning?.Print(LogClass.Application, $"Please use the MiiEdit inside File/Open Applet");
return new DummyApplet(system); return new DummyApplet(system);

View File

@ -18,13 +18,6 @@ namespace Ryujinx.HLE.HOS.Applets.Browser
private List<BrowserArgument> _arguments; private List<BrowserArgument> _arguments;
private ShimKind _shimKind; private ShimKind _shimKind;
public BrowserApplet(Horizon system) { }
public ResultCode GetResult()
{
return ResultCode.Success;
}
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
{ {
_normalSession = normalSession; _normalSession = normalSession;

View File

@ -125,19 +125,6 @@ namespace Ryujinx.HLE.HOS.Applets.Cabinet
return bytes; return bytes;
} }
public static T ReadStruct<T>(byte[] data) where T : unmanaged
{
if (data.Length < Unsafe.SizeOf<T>())
{
throw new ArgumentException("Not enough data to read the struct");
}
fixed (byte* dataPtr = data)
{
return Unsafe.Read<T>(dataPtr);
}
}
#region Structs #region Structs
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]

View File

@ -117,11 +117,6 @@ namespace Ryujinx.HLE.HOS.Applets
return ResultCode.Success; return ResultCode.Success;
} }
public ResultCode GetResult()
{
return ResultCode.Success;
}
private static byte[] BuildResponse(ControllerSupportResultInfo result) private static byte[] BuildResponse(ControllerSupportResultInfo result)
{ {
using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); using MemoryStream stream = MemoryStreamManager.Shared.GetStream();

View File

@ -11,11 +11,14 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
{ {
private readonly Horizon _system; private readonly Horizon _system;
private AppletSession _normalSession; private AppletSession _normalSession;
public event EventHandler AppletStateChanged; public event EventHandler AppletStateChanged;
public DummyApplet(Horizon system) public DummyApplet(Horizon system)
{ {
_system = system; _system = system;
} }
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
{ {
_normalSession = normalSession; _normalSession = normalSession;
@ -24,10 +27,7 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
_system.ReturnFocus(); _system.ReturnFocus();
return ResultCode.Success; return ResultCode.Success;
} }
private static T ReadStruct<T>(byte[] data) where T : struct
{
return MemoryMarshal.Read<T>(data.AsSpan());
}
private static byte[] BuildResponse() private static byte[] BuildResponse()
{ {
using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
@ -35,9 +35,5 @@ namespace Ryujinx.HLE.HOS.Applets.Dummy
writer.Write((ulong)ResultCode.Success); writer.Write((ulong)ResultCode.Success);
return stream.ToArray(); return stream.ToArray();
} }
public ResultCode GetResult()
{
return ResultCode.Success;
}
} }
} }

View File

@ -203,10 +203,5 @@ namespace Ryujinx.HLE.HOS.Applets.Error
_horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber} (Details)", "\n" + detailsText, buttons.ToArray()); _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber} (Details)", "\n" + detailsText, buttons.ToArray());
} }
} }
public ResultCode GetResult()
{
return ResultCode.Success;
}
} }
} }

View File

@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Applets
ResultCode Start(AppletSession normalSession, ResultCode Start(AppletSession normalSession,
AppletSession interactiveSession); AppletSession interactiveSession);
ResultCode GetResult(); ResultCode GetResult() => ResultCode.Success;
bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false; bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false;

View File

@ -37,11 +37,6 @@ namespace Ryujinx.HLE.HOS.Applets
return ResultCode.Success; return ResultCode.Success;
} }
public ResultCode GetResult()
{
return ResultCode.Success;
}
private byte[] BuildResponse() private byte[] BuildResponse()
{ {
UserProfile currentUser = _system.AccountManager.LastOpenedUser; UserProfile currentUser = _system.AccountManager.LastOpenedUser;

View File

@ -144,11 +144,6 @@ namespace Ryujinx.HLE.HOS.Applets
} }
} }
public ResultCode GetResult()
{
return ResultCode.Success;
}
private bool IsKeyboardActive() private bool IsKeyboardActive()
{ {
return _backgroundState >= InlineKeyboardState.Appearing && _backgroundState < InlineKeyboardState.Disappearing; return _backgroundState >= InlineKeyboardState.Appearing && _backgroundState < InlineKeyboardState.Disappearing;

View File

@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
{ {
/// <summary> /// <summary>
/// Wraps a type in a class so it gets stored in the GC managed heap. This is used as communication mechanism /// Wraps a type in a class so it gets stored in the GC managed heap. This is used as communication mechanism
/// between classed that need to be disposed and, thus, can't share their references. /// between classes that need to be disposed and, thus, can't share their references.
/// </summary> /// </summary>
/// <typeparam name="T">The internal type.</typeparam> /// <typeparam name="T">The internal type.</typeparam>
class TRef<T> class TRef<T>