Skip to content

Commit

Permalink
chore: applets: Cleanup redundant ReadStruct implementations & provid…
Browse files Browse the repository at this point in the history
…e a default implementation for IApplet#GetResult.
  • Loading branch information
GreemDev committed Dec 4, 2024
1 parent 08b7257 commit 07690e4
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 53 deletions.
4 changes: 1 addition & 3 deletions src/Ryujinx.HLE/HOS/Applets/AppletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ public static IApplet Create(AppletId applet, Horizon system)
case AppletId.SoftwareKeyboard:
return new SoftwareKeyboardApplet(system);
case AppletId.LibAppletWeb:
return new BrowserApplet(system);
case AppletId.LibAppletShop:
return new BrowserApplet(system);
case AppletId.LibAppletOff:
return new BrowserApplet(system);
return new BrowserApplet();
case AppletId.MiiEdit:
Logger.Warning?.Print(LogClass.Application, $"Please use the MiiEdit inside File/Open Applet");
return new DummyApplet(system);
Expand Down
7 changes: 0 additions & 7 deletions src/Ryujinx.HLE/HOS/Applets/Browser/BrowserApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ internal class BrowserApplet : IApplet
private List<BrowserArgument> _arguments;
private ShimKind _shimKind;

public BrowserApplet(Horizon system) { }

public ResultCode GetResult()
{
return ResultCode.Success;
}

public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
{
_normalSession = normalSession;
Expand Down
13 changes: 0 additions & 13 deletions src/Ryujinx.HLE/HOS/Applets/Cabinet/CabinetApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,6 @@ private static byte[] BuildResponse(ReturnValueForAmiiboSettings returnValue)
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

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down
5 changes: 0 additions & 5 deletions src/Ryujinx.HLE/HOS/Applets/Controller/ControllerApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ public ResultCode Start(AppletSession normalSession, AppletSession interactiveSe
return ResultCode.Success;
}

public ResultCode GetResult()
{
return ResultCode.Success;
}

private static byte[] BuildResponse(ControllerSupportResultInfo result)
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
Expand Down
12 changes: 4 additions & 8 deletions src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ internal class DummyApplet : IApplet
{
private readonly Horizon _system;
private AppletSession _normalSession;

public event EventHandler AppletStateChanged;

public DummyApplet(Horizon system)
{
_system = system;
}

public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
{
_normalSession = normalSession;
Expand All @@ -24,20 +27,13 @@ public ResultCode Start(AppletSession normalSession, AppletSession interactiveSe
_system.ReturnFocus();
return ResultCode.Success;
}
private static T ReadStruct<T>(byte[] data) where T : struct
{
return MemoryMarshal.Read<T>(data.AsSpan());
}

private static byte[] BuildResponse()
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
using BinaryWriter writer = new(stream);
writer.Write((ulong)ResultCode.Success);
return stream.ToArray();
}
public ResultCode GetResult()
{
return ResultCode.Success;
}
}
}
5 changes: 0 additions & 5 deletions src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,5 @@ private void ParseApplicationErrorArg()
_horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber} (Details)", "\n" + detailsText, buttons.ToArray());
}
}

public ResultCode GetResult()
{
return ResultCode.Success;
}
}
}
2 changes: 1 addition & 1 deletion src/Ryujinx.HLE/HOS/Applets/IApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IApplet
ResultCode Start(AppletSession normalSession,
AppletSession interactiveSession);

ResultCode GetResult();
ResultCode GetResult() => ResultCode.Success;

bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public ResultCode Start(AppletSession normalSession, AppletSession interactiveSe
return ResultCode.Success;
}

public ResultCode GetResult()
{
return ResultCode.Success;
}

private byte[] BuildResponse()
{
UserProfile currentUser = _system.AccountManager.LastOpenedUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public ResultCode Start(AppletSession normalSession, AppletSession interactiveSe
}
}

public ResultCode GetResult()
{
return ResultCode.Success;
}

private bool IsKeyboardActive()
{
return _backgroundState >= InlineKeyboardState.Appearing && _backgroundState < InlineKeyboardState.Disappearing;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/TRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
{
/// <summary>
/// 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>
/// <typeparam name="T">The internal type.</typeparam>
class TRef<T>
Expand Down

0 comments on commit 07690e4

Please sign in to comment.