mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-07-22 14:47:10 +02:00
Merge Latest Ryujinx (Unstable)
This commit is contained in:
parent
aaefc0a9e5
commit
12ab8bc3e2
1237 changed files with 48656 additions and 21399 deletions
|
@ -86,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
PlayerIndex primaryIndex;
|
||||
while (!_system.Device.Hid.Npads.Validate(playerMin, playerMax, (ControllerType)privateArg.NpadStyleSet, out configuredCount, out primaryIndex))
|
||||
{
|
||||
ControllerAppletUiArgs uiArgs = new()
|
||||
ControllerAppletUIArgs uiArgs = new()
|
||||
{
|
||||
PlayerCountMin = playerMin,
|
||||
PlayerCountMax = playerMax,
|
||||
|
@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
IsDocked = _system.State.DockedMode,
|
||||
};
|
||||
|
||||
if (!_system.Device.UiHandler.DisplayMessageDialog(uiArgs))
|
||||
if (!_system.Device.UIHandler.DisplayMessageDialog(uiArgs))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Ryujinx.HLE.HOS.Applets
|
||||
{
|
||||
public struct ControllerAppletUiArgs
|
||||
public struct ControllerAppletUIArgs
|
||||
{
|
||||
public int PlayerCountMin;
|
||||
public int PlayerCountMax;
|
|
@ -166,13 +166,13 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
|||
|
||||
string[] buttons = GetButtonsText(module, description, "DlgBtn");
|
||||
|
||||
bool showDetails = _horizon.Device.UiHandler.DisplayErrorAppletDialog($"Error Code: {module}-{description:0000}", "\n" + message, buttons);
|
||||
bool showDetails = _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Code: {module}-{description:0000}", "\n" + message, buttons);
|
||||
if (showDetails)
|
||||
{
|
||||
message = GetMessageText(module, description, "FlvMsg");
|
||||
buttons = GetButtonsText(module, description, "FlvBtn");
|
||||
|
||||
_horizon.Device.UiHandler.DisplayErrorAppletDialog($"Details: {module}-{description:0000}", "\n" + message, buttons);
|
||||
_horizon.Device.UIHandler.DisplayErrorAppletDialog($"Details: {module}-{description:0000}", "\n" + message, buttons);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,12 +200,12 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
|||
|
||||
buttons.Add("OK");
|
||||
|
||||
bool showDetails = _horizon.Device.UiHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber}", "\n" + messageText, buttons.ToArray());
|
||||
bool showDetails = _horizon.Device.UIHandler.DisplayErrorAppletDialog($"Error Number: {applicationErrorArg.ErrorNumber}", "\n" + messageText, buttons.ToArray());
|
||||
if (showDetails)
|
||||
{
|
||||
buttons.RemoveAt(0);
|
||||
|
||||
_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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Ryujinx.HLE.HOS.Services.Am.AppletAE;
|
||||
using Ryujinx.HLE.Ui;
|
||||
using Ryujinx.HLE.UI;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
|
@ -4,8 +4,8 @@ using Ryujinx.Common.Logging;
|
|||
using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard;
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletAE;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad;
|
||||
using Ryujinx.HLE.Ui;
|
||||
using Ryujinx.HLE.Ui.Input;
|
||||
using Ryujinx.HLE.UI;
|
||||
using Ryujinx.HLE.UI.Input;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
@ -94,14 +94,14 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
_keyboardBackgroundInitialize = MemoryMarshal.Read<SoftwareKeyboardInitialize>(keyboardConfig);
|
||||
_backgroundState = InlineKeyboardState.Uninitialized;
|
||||
|
||||
if (_device.UiHandler == null)
|
||||
if (_device.UIHandler == null)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAm, "GUI Handler is not set, software keyboard applet will not work properly");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a text handler that converts keyboard strokes to strings.
|
||||
_dynamicTextInputHandler = _device.UiHandler.CreateDynamicTextInputHandler();
|
||||
_dynamicTextInputHandler = _device.UIHandler.CreateDynamicTextInputHandler();
|
||||
_dynamicTextInputHandler.TextChangedEvent += HandleTextChangedEvent;
|
||||
_dynamicTextInputHandler.KeyPressedEvent += HandleKeyPressedEvent;
|
||||
|
||||
|
@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
_npads.NpadButtonDownEvent += HandleNpadButtonDownEvent;
|
||||
_npads.NpadButtonUpEvent += HandleNpadButtonUpEvent;
|
||||
|
||||
_keyboardRenderer = new SoftwareKeyboardRenderer(_device.UiHandler.HostUiTheme);
|
||||
_keyboardRenderer = new SoftwareKeyboardRenderer(_device.UIHandler.HostUITheme);
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
|
@ -203,13 +203,12 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
_keyboardForegroundConfig.StringLengthMax = 100;
|
||||
}
|
||||
|
||||
// If no GUI handler is set, fallback to default behavior.
|
||||
if (_device.UiHandler == null)
|
||||
if (_device.UIHandler == null)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, "GUI Handler is not set. Falling back to default");
|
||||
|
||||
// Prepare the SoftwareKeyboardUiArgs struct
|
||||
var args = new SoftwareKeyboardUiArgs
|
||||
// Prepare the SoftwareKeyboardUIArgs struct
|
||||
var args = new SoftwareKeyboardUIArgs
|
||||
{
|
||||
KeyboardMode = _keyboardForegroundConfig.Mode,
|
||||
HeaderText = StripUnicodeControlCodes(_keyboardForegroundConfig.HeaderText),
|
||||
|
@ -228,7 +227,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
else
|
||||
{
|
||||
// Call the configured GUI handler to get user's input.
|
||||
var args = new SoftwareKeyboardUiArgs
|
||||
var args = new SoftwareKeyboardUIArgs
|
||||
{
|
||||
KeyboardMode = _keyboardForegroundConfig.Mode,
|
||||
HeaderText = StripUnicodeControlCodes(_keyboardForegroundConfig.HeaderText),
|
||||
|
@ -240,7 +239,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
|||
StringLengthMax = _keyboardForegroundConfig.StringLengthMax,
|
||||
InitialText = initialText,
|
||||
};
|
||||
_device.UiHandler.DisplayInputDialog(args, inputText =>
|
||||
_device.UIHandler.DisplayInputDialog(args, inputText =>
|
||||
{
|
||||
Console.WriteLine($"User entered: {inputText}");
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Ryujinx.HLE.Ui;
|
||||
using Ryujinx.HLE.UI;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
@ -15,13 +15,13 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
|
||||
private readonly object _stateLock = new();
|
||||
|
||||
private readonly SoftwareKeyboardUiState _state = new();
|
||||
private readonly SoftwareKeyboardUIState _state = new();
|
||||
private readonly SoftwareKeyboardRendererBase _renderer;
|
||||
|
||||
private readonly TimedAction _textBoxBlinkTimedAction = new();
|
||||
private readonly TimedAction _renderAction = new();
|
||||
|
||||
public SoftwareKeyboardRenderer(IHostUiTheme uiTheme)
|
||||
public SoftwareKeyboardRenderer(IHostUITheme uiTheme)
|
||||
{
|
||||
_renderer = new SoftwareKeyboardRendererBase(uiTheme);
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
StartRenderer(_renderAction, _renderer, _state, _stateLock);
|
||||
}
|
||||
|
||||
private static void StartTextBoxBlinker(TimedAction timedAction, SoftwareKeyboardUiState state, object stateLock)
|
||||
private static void StartTextBoxBlinker(TimedAction timedAction, SoftwareKeyboardUIState state, object stateLock)
|
||||
{
|
||||
timedAction.Reset(() =>
|
||||
{
|
||||
|
@ -45,9 +45,9 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
}, TextBoxBlinkSleepMilliseconds);
|
||||
}
|
||||
|
||||
private static void StartRenderer(TimedAction timedAction, SoftwareKeyboardRendererBase renderer, SoftwareKeyboardUiState state, object stateLock)
|
||||
private static void StartRenderer(TimedAction timedAction, SoftwareKeyboardRendererBase renderer, SoftwareKeyboardUIState state, object stateLock)
|
||||
{
|
||||
SoftwareKeyboardUiState internalState = new();
|
||||
SoftwareKeyboardUIState internalState = new();
|
||||
|
||||
bool canCreateSurface = false;
|
||||
bool needsUpdate = true;
|
||||
|
@ -112,11 +112,16 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
{
|
||||
// Update the parameters that were provided.
|
||||
_state.InputText = inputText ?? _state.InputText;
|
||||
_state.CursorBegin = cursorBegin.GetValueOrDefault(_state.CursorBegin);
|
||||
_state.CursorEnd = cursorEnd.GetValueOrDefault(_state.CursorEnd);
|
||||
_state.CursorBegin = Math.Max(0, cursorBegin.GetValueOrDefault(_state.CursorBegin));
|
||||
_state.CursorEnd = Math.Min(cursorEnd.GetValueOrDefault(_state.CursorEnd), _state.InputText.Length);
|
||||
_state.OverwriteMode = overwriteMode.GetValueOrDefault(_state.OverwriteMode);
|
||||
_state.TypingEnabled = typingEnabled.GetValueOrDefault(_state.TypingEnabled);
|
||||
|
||||
var begin = _state.CursorBegin;
|
||||
var end = _state.CursorEnd;
|
||||
_state.CursorBegin = Math.Min(begin, end);
|
||||
_state.CursorEnd = Math.Max(begin, end);
|
||||
|
||||
// Reset the cursor blink.
|
||||
_state.TextBoxBlinkCounter = 0;
|
||||
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
using Ryujinx.HLE.Ui;
|
||||
using Ryujinx.HLE.UI;
|
||||
using Ryujinx.Memory;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SkiaSharp;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -29,41 +24,42 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
private readonly object _bufferLock = new();
|
||||
|
||||
private RenderingSurfaceInfo _surfaceInfo = null;
|
||||
private Image<Argb32> _surface = null;
|
||||
private SKImageInfo _imageInfo;
|
||||
private SKSurface _surface = null;
|
||||
private byte[] _bufferData = null;
|
||||
|
||||
private readonly Image _ryujinxLogo = null;
|
||||
private readonly Image _padAcceptIcon = null;
|
||||
private readonly Image _padCancelIcon = null;
|
||||
private readonly Image _keyModeIcon = null;
|
||||
private readonly SKBitmap _ryujinxLogo = null;
|
||||
private readonly SKBitmap _padAcceptIcon = null;
|
||||
private readonly SKBitmap _padCancelIcon = null;
|
||||
private readonly SKBitmap _keyModeIcon = null;
|
||||
|
||||
private readonly float _textBoxOutlineWidth;
|
||||
private readonly float _padPressedPenWidth;
|
||||
|
||||
private readonly Color _textNormalColor;
|
||||
private readonly Color _textSelectedColor;
|
||||
private readonly Color _textOverCursorColor;
|
||||
private readonly SKColor _textNormalColor;
|
||||
private readonly SKColor _textSelectedColor;
|
||||
private readonly SKColor _textOverCursorColor;
|
||||
|
||||
private readonly IBrush _panelBrush;
|
||||
private readonly IBrush _disabledBrush;
|
||||
private readonly IBrush _cursorBrush;
|
||||
private readonly IBrush _selectionBoxBrush;
|
||||
private readonly SKPaint _panelBrush;
|
||||
private readonly SKPaint _disabledBrush;
|
||||
private readonly SKPaint _cursorBrush;
|
||||
private readonly SKPaint _selectionBoxBrush;
|
||||
|
||||
private readonly Pen _textBoxOutlinePen;
|
||||
private readonly Pen _cursorPen;
|
||||
private readonly Pen _selectionBoxPen;
|
||||
private readonly Pen _padPressedPen;
|
||||
private readonly SKPaint _textBoxOutlinePen;
|
||||
private readonly SKPaint _cursorPen;
|
||||
private readonly SKPaint _selectionBoxPen;
|
||||
private readonly SKPaint _padPressedPen;
|
||||
|
||||
private readonly int _inputTextFontSize;
|
||||
private Font _messageFont;
|
||||
private Font _inputTextFont;
|
||||
private Font _labelsTextFont;
|
||||
private SKFont _messageFont;
|
||||
private SKFont _inputTextFont;
|
||||
private SKFont _labelsTextFont;
|
||||
|
||||
private RectangleF _panelRectangle;
|
||||
private Point _logoPosition;
|
||||
private SKRect _panelRectangle;
|
||||
private SKPoint _logoPosition;
|
||||
private float _messagePositionY;
|
||||
|
||||
public SoftwareKeyboardRendererBase(IHostUiTheme uiTheme)
|
||||
public SoftwareKeyboardRendererBase(IHostUITheme uiTheme)
|
||||
{
|
||||
int ryujinxLogoSize = 32;
|
||||
|
||||
|
@ -78,10 +74,10 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
_padCancelIcon = LoadResource(typeof(SoftwareKeyboardRendererBase).Assembly, padCancelIconPath, 0, 0);
|
||||
_keyModeIcon = LoadResource(typeof(SoftwareKeyboardRendererBase).Assembly, keyModeIconPath, 0, 0);
|
||||
|
||||
Color panelColor = ToColor(uiTheme.DefaultBackgroundColor, 255);
|
||||
Color panelTransparentColor = ToColor(uiTheme.DefaultBackgroundColor, 150);
|
||||
Color borderColor = ToColor(uiTheme.DefaultBorderColor);
|
||||
Color selectionBackgroundColor = ToColor(uiTheme.SelectionBackgroundColor);
|
||||
var panelColor = ToColor(uiTheme.DefaultBackgroundColor, 255);
|
||||
var panelTransparentColor = ToColor(uiTheme.DefaultBackgroundColor, 150);
|
||||
var borderColor = ToColor(uiTheme.DefaultBorderColor);
|
||||
var selectionBackgroundColor = ToColor(uiTheme.SelectionBackgroundColor);
|
||||
|
||||
_textNormalColor = ToColor(uiTheme.DefaultForegroundColor);
|
||||
_textSelectedColor = ToColor(uiTheme.SelectionForegroundColor);
|
||||
|
@ -92,70 +88,36 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
|||
_textBoxOutlineWidth = 2;
|
||||
_padPressedPenWidth = 2;
|
||||
|
||||
_panelBrush = new SolidBrush(panelColor);
|
||||
_disabledBrush = new SolidBrush(panelTransparentColor);
|
||||
_cursorBrush = new SolidBrush(_textNormalColor);
|
||||
_selectionBoxBrush = new SolidBrush(selectionBackgroundColor);
|
||||
_panelBrush = new SKPaint()
|
||||
{
|
||||
Color = panelColor,
|
||||
IsAntialias = true
|
||||
};
|
||||
_disabledBrush = new SKPaint()
|
||||
{
|
||||
Color = panelTransparentColor,
|
||||
IsAntialias = true
|
||||
};
|
||||
_cursorBrush = new SKPaint() { Color = _textNormalColor, IsAntialias = true };
|
||||
_selectionBoxBrush = new SKPaint() { Color = selectionBackgroundColor, IsAntialias = true };
|
||||
|
||||
_textBoxOutlinePen = new Pen(borderColor, _textBoxOutlineWidth);
|
||||
_cursorPen = new Pen(_textNormalColor, cursorWidth);
|
||||
_selectionBoxPen = new Pen(selectionBackgroundColor, cursorWidth);
|
||||
_padPressedPen = new Pen(borderColor, _padPressedPenWidth);
|
||||
_textBoxOutlinePen = new SKPaint()
|
||||
{
|
||||
Color = borderColor,
|
||||
StrokeWidth = _textBoxOutlineWidth,
|
||||
IsStroke = true,
|
||||
IsAntialias = true
|
||||
};
|
||||
_cursorPen = new SKPaint() { Color = _textNormalColor, StrokeWidth = cursorWidth, IsStroke = true, IsAntialias = true };
|
||||
_selectionBoxPen = new SKPaint() { Color = selectionBackgroundColor, StrokeWidth = cursorWidth, IsStroke = true, IsAntialias = true };
|
||||
_padPressedPen = new SKPaint() { Color = borderColor, StrokeWidth = _padPressedPenWidth, IsStroke = true, IsAntialias = true };
|
||||
|
||||
_inputTextFontSize = 20;
|
||||
|
||||
CreateFonts(uiTheme.FontFamily);
|
||||
// CreateFonts(uiTheme.FontFamily);
|
||||
}
|
||||
|
||||
private void CreateFonts(string uiThemeFontFamily)
|
||||
{
|
||||
// Try a list of fonts in case any of them is not available in the system.
|
||||
string[] availableFonts = { uiThemeFontFamily };
|
||||
|
||||
// If it's iOS, we'll want to use a more appropriate set of fonts.
|
||||
if (OperatingSystem.IsIOS())
|
||||
{
|
||||
availableFonts = new string[] {
|
||||
"SF Pro",
|
||||
"New York",
|
||||
"Helvetica Neue",
|
||||
"Avenir"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback for other platforms (e.g., Android, Windows, etc.)
|
||||
availableFonts = new string[] {
|
||||
uiThemeFontFamily,
|
||||
"Liberation Sans",
|
||||
"FreeSans",
|
||||
"DejaVu Sans",
|
||||
"Lucida Grande"
|
||||
};
|
||||
}
|
||||
|
||||
// Try to create the fonts with the selected font families
|
||||
foreach (string fontFamily in availableFonts)
|
||||
{
|
||||
try
|
||||
{
|
||||
_messageFont = SystemFonts.CreateFont(fontFamily, 26, FontStyle.Regular);
|
||||
_inputTextFont = SystemFonts.CreateFont(fontFamily, _inputTextFontSize, FontStyle.Regular);
|
||||
_labelsTextFont = SystemFonts.CreateFont(fontFamily, 24, FontStyle.Regular);
|
||||
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If the font creation fails, try the next font family
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"None of these fonts were found in the system: {String.Join(", ", availableFonts)}!");
|
||||
}
|
||||
|
||||
|
||||
private static Color ToColor(ThemeColor color, byte? overrideAlpha = null, bool flipRgb = false)
|
||||
private static SKColor ToColor(ThemeColor color, byte? overrideAlpha = null, bool flipRgb = false)
|
||||
{
|
||||
var a = (byte)(color.A * 255);
|
||||
var r = (byte)(color.R * 255);
|
||||
|
@ -169,34 +131,33 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
b = (byte)(255 - b);
|
||||
}
|
||||
|
||||
return Color.FromRgba(r, g, b, overrideAlpha.GetValueOrDefault(a));
|
||||
return new SKColor(r, g, b, overrideAlpha.GetValueOrDefault(a));
|
||||
}
|
||||
|
||||
private static Image LoadResource(Assembly assembly, string resourcePath, int newWidth, int newHeight)
|
||||
private static SKBitmap LoadResource(Assembly assembly, string resourcePath, int newWidth, int newHeight)
|
||||
{
|
||||
Stream resourceStream = assembly.GetManifestResourceStream(resourcePath);
|
||||
|
||||
return LoadResource(resourceStream, newWidth, newHeight);
|
||||
}
|
||||
|
||||
private static Image LoadResource(Stream resourceStream, int newWidth, int newHeight)
|
||||
private static SKBitmap LoadResource(Stream resourceStream, int newWidth, int newHeight)
|
||||
{
|
||||
Debug.Assert(resourceStream != null);
|
||||
|
||||
var image = Image.Load(resourceStream);
|
||||
var bitmap = SKBitmap.Decode(resourceStream);
|
||||
|
||||
if (newHeight != 0 && newWidth != 0)
|
||||
{
|
||||
image.Mutate(x => x.Resize(newWidth, newHeight, KnownResamplers.Lanczos3));
|
||||
var resized = bitmap.Resize(new SKImageInfo(newWidth, newHeight), SKFilterQuality.High);
|
||||
if (resized != null)
|
||||
{
|
||||
bitmap.Dispose();
|
||||
bitmap = resized;
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private static void SetGraphicsOptions(IImageProcessingContext context)
|
||||
{
|
||||
context.GetGraphicsOptions().Antialias = true;
|
||||
context.GetShapeGraphicsOptions().GraphicsOptions.Antialias = true;
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void DrawImmutableElements()
|
||||
|
@ -205,65 +166,64 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
{
|
||||
return;
|
||||
}
|
||||
var canvas = _surface.Canvas;
|
||||
|
||||
_surface.Mutate(context =>
|
||||
{
|
||||
SetGraphicsOptions(context);
|
||||
canvas.Clear(SKColors.Transparent);
|
||||
canvas.DrawRect(_panelRectangle, _panelBrush);
|
||||
canvas.DrawBitmap(_ryujinxLogo, _logoPosition);
|
||||
|
||||
context.Clear(Color.Transparent);
|
||||
context.Fill(_panelBrush, _panelRectangle);
|
||||
context.DrawImage(_ryujinxLogo, _logoPosition, 1);
|
||||
float halfWidth = _panelRectangle.Width / 2;
|
||||
float buttonsY = _panelRectangle.Top + 185;
|
||||
|
||||
float halfWidth = _panelRectangle.Width / 2;
|
||||
float buttonsY = _panelRectangle.Y + 185;
|
||||
SKPoint disableButtonPosition = new(halfWidth + 180, buttonsY);
|
||||
|
||||
PointF disableButtonPosition = new(halfWidth + 180, buttonsY);
|
||||
|
||||
DrawControllerToggle(context, disableButtonPosition);
|
||||
});
|
||||
DrawControllerToggle(canvas, disableButtonPosition);
|
||||
}
|
||||
|
||||
public void DrawMutableElements(SoftwareKeyboardUiState state)
|
||||
public void DrawMutableElements(SoftwareKeyboardUIState state)
|
||||
{
|
||||
if (_surface == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_surface.Mutate(context =>
|
||||
using var paint = new SKPaint(_messageFont)
|
||||
{
|
||||
var messageRectangle = MeasureString(MessageText, _messageFont);
|
||||
float messagePositionX = (_panelRectangle.Width - messageRectangle.Width) / 2 - messageRectangle.X;
|
||||
float messagePositionY = _messagePositionY - messageRectangle.Y;
|
||||
var messagePosition = new PointF(messagePositionX, messagePositionY);
|
||||
var messageBoundRectangle = new RectangleF(messagePositionX, messagePositionY, messageRectangle.Width, messageRectangle.Height);
|
||||
Color = _textNormalColor,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
SetGraphicsOptions(context);
|
||||
var canvas = _surface.Canvas;
|
||||
var messageRectangle = MeasureString(MessageText, paint);
|
||||
float messagePositionX = (_panelRectangle.Width - messageRectangle.Width) / 2 - messageRectangle.Left;
|
||||
float messagePositionY = _messagePositionY - messageRectangle.Top;
|
||||
var messagePosition = new SKPoint(messagePositionX, messagePositionY);
|
||||
var messageBoundRectangle = SKRect.Create(messagePositionX, messagePositionY, messageRectangle.Width, messageRectangle.Height);
|
||||
|
||||
context.Fill(_panelBrush, messageBoundRectangle);
|
||||
canvas.DrawRect(messageBoundRectangle, _panelBrush);
|
||||
|
||||
context.DrawText(MessageText, _messageFont, _textNormalColor, messagePosition);
|
||||
canvas.DrawText(MessageText, messagePosition.X, messagePosition.Y + _messageFont.Metrics.XHeight + _messageFont.Metrics.Descent, paint);
|
||||
|
||||
if (!state.TypingEnabled)
|
||||
{
|
||||
// Just draw a semi-transparent rectangle on top to fade the component with the background.
|
||||
// TODO (caian): This will not work if one decides to add make background semi-transparent as well.
|
||||
if (!state.TypingEnabled)
|
||||
{
|
||||
// Just draw a semi-transparent rectangle on top to fade the component with the background.
|
||||
// TODO (caian): This will not work if one decides to add make background semi-transparent as well.
|
||||
|
||||
context.Fill(_disabledBrush, messageBoundRectangle);
|
||||
}
|
||||
canvas.DrawRect(messageBoundRectangle, _disabledBrush);
|
||||
}
|
||||
|
||||
DrawTextBox(context, state);
|
||||
DrawTextBox(canvas, state);
|
||||
|
||||
float halfWidth = _panelRectangle.Width / 2;
|
||||
float buttonsY = _panelRectangle.Y + 185;
|
||||
float halfWidth = _panelRectangle.Width / 2;
|
||||
float buttonsY = _panelRectangle.Top + 185;
|
||||
|
||||
PointF acceptButtonPosition = new(halfWidth - 180, buttonsY);
|
||||
PointF cancelButtonPosition = new(halfWidth, buttonsY);
|
||||
PointF disableButtonPosition = new(halfWidth + 180, buttonsY);
|
||||
SKPoint acceptButtonPosition = new(halfWidth - 180, buttonsY);
|
||||
SKPoint cancelButtonPosition = new(halfWidth, buttonsY);
|
||||
SKPoint disableButtonPosition = new(halfWidth + 180, buttonsY);
|
||||
|
||||
DrawPadButton(canvas, acceptButtonPosition, _padAcceptIcon, AcceptText, state.AcceptPressed, state.ControllerEnabled);
|
||||
DrawPadButton(canvas, cancelButtonPosition, _padCancelIcon, CancelText, state.CancelPressed, state.ControllerEnabled);
|
||||
|
||||
DrawPadButton(context, acceptButtonPosition, _padAcceptIcon, AcceptText, state.AcceptPressed, state.ControllerEnabled);
|
||||
DrawPadButton(context, cancelButtonPosition, _padCancelIcon, CancelText, state.CancelPressed, state.ControllerEnabled);
|
||||
});
|
||||
}
|
||||
|
||||
public void CreateSurface(RenderingSurfaceInfo surfaceInfo)
|
||||
|
@ -286,7 +246,8 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
Debug.Assert(_surfaceInfo.Height <= totalHeight);
|
||||
Debug.Assert(_surfaceInfo.Pitch * _surfaceInfo.Height <= _surfaceInfo.Size);
|
||||
|
||||
_surface = new Image<Argb32>((int)totalWidth, (int)totalHeight);
|
||||
_imageInfo = new SKImageInfo((int)totalWidth, (int)totalHeight, SKColorType.Rgba8888);
|
||||
_surface = SKSurface.Create(_imageInfo);
|
||||
|
||||
ComputeConstants();
|
||||
DrawImmutableElements();
|
||||
|
@ -300,76 +261,81 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
int panelHeight = 240;
|
||||
int panelPositionY = totalHeight - panelHeight;
|
||||
|
||||
_panelRectangle = new RectangleF(0, panelPositionY, totalWidth, panelHeight);
|
||||
_panelRectangle = SKRect.Create(0, panelPositionY, totalWidth, panelHeight);
|
||||
|
||||
_messagePositionY = panelPositionY + 60;
|
||||
|
||||
int logoPositionX = (totalWidth - _ryujinxLogo.Width) / 2;
|
||||
int logoPositionY = panelPositionY + 18;
|
||||
|
||||
_logoPosition = new Point(logoPositionX, logoPositionY);
|
||||
_logoPosition = new SKPoint(logoPositionX, logoPositionY);
|
||||
}
|
||||
private static RectangleF MeasureString(string text, Font font)
|
||||
private static SKRect MeasureString(string text, SKPaint paint)
|
||||
{
|
||||
RendererOptions options = new(font);
|
||||
SKRect bounds = SKRect.Empty;
|
||||
|
||||
if (text == "")
|
||||
{
|
||||
FontRectangle emptyRectangle = TextMeasurer.Measure(" ", options);
|
||||
|
||||
return new RectangleF(0, emptyRectangle.Y, 0, emptyRectangle.Height);
|
||||
paint.MeasureText(" ", ref bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
paint.MeasureText(text, ref bounds);
|
||||
}
|
||||
|
||||
FontRectangle rectangle = TextMeasurer.Measure(text, options);
|
||||
|
||||
return new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private static RectangleF MeasureString(ReadOnlySpan<char> text, Font font)
|
||||
private static SKRect MeasureString(ReadOnlySpan<char> text, SKPaint paint)
|
||||
{
|
||||
RendererOptions options = new(font);
|
||||
SKRect bounds = SKRect.Empty;
|
||||
|
||||
if (text == "")
|
||||
{
|
||||
FontRectangle emptyRectangle = TextMeasurer.Measure(" ", options);
|
||||
return new RectangleF(0, emptyRectangle.Y, 0, emptyRectangle.Height);
|
||||
paint.MeasureText(" ", ref bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
paint.MeasureText(text, ref bounds);
|
||||
}
|
||||
|
||||
FontRectangle rectangle = TextMeasurer.Measure(text, options);
|
||||
|
||||
return new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private void DrawTextBox(IImageProcessingContext context, SoftwareKeyboardUiState state)
|
||||
private void DrawTextBox(SKCanvas canvas, SoftwareKeyboardUIState state)
|
||||
{
|
||||
var inputTextRectangle = MeasureString(state.InputText, _inputTextFont);
|
||||
using var textPaint = new SKPaint(_labelsTextFont)
|
||||
{
|
||||
IsAntialias = true,
|
||||
Color = _textNormalColor
|
||||
};
|
||||
var inputTextRectangle = MeasureString(state.InputText, textPaint);
|
||||
|
||||
float boxWidth = (int)(Math.Max(300, inputTextRectangle.Width + inputTextRectangle.X + 8));
|
||||
float boxWidth = (int)(Math.Max(300, inputTextRectangle.Width + inputTextRectangle.Left + 8));
|
||||
float boxHeight = 32;
|
||||
float boxY = _panelRectangle.Y + 110;
|
||||
float boxY = _panelRectangle.Top + 110;
|
||||
float boxX = (int)((_panelRectangle.Width - boxWidth) / 2);
|
||||
|
||||
RectangleF boxRectangle = new(boxX, boxY, boxWidth, boxHeight);
|
||||
SKRect boxRectangle = SKRect.Create(boxX, boxY, boxWidth, boxHeight);
|
||||
|
||||
RectangleF boundRectangle = new(_panelRectangle.X, boxY - _textBoxOutlineWidth,
|
||||
SKRect boundRectangle = SKRect.Create(_panelRectangle.Left, boxY - _textBoxOutlineWidth,
|
||||
_panelRectangle.Width, boxHeight + 2 * _textBoxOutlineWidth);
|
||||
|
||||
context.Fill(_panelBrush, boundRectangle);
|
||||
canvas.DrawRect(boundRectangle, _panelBrush);
|
||||
|
||||
context.Draw(_textBoxOutlinePen, boxRectangle);
|
||||
canvas.DrawRect(boxRectangle, _textBoxOutlinePen);
|
||||
|
||||
float inputTextX = (_panelRectangle.Width - inputTextRectangle.Width) / 2 - inputTextRectangle.X;
|
||||
float inputTextX = (_panelRectangle.Width - inputTextRectangle.Width) / 2 - inputTextRectangle.Left;
|
||||
float inputTextY = boxY + 5;
|
||||
|
||||
var inputTextPosition = new PointF(inputTextX, inputTextY);
|
||||
|
||||
context.DrawText(state.InputText, _inputTextFont, _textNormalColor, inputTextPosition);
|
||||
var inputTextPosition = new SKPoint(inputTextX, inputTextY);
|
||||
canvas.DrawText(state.InputText, inputTextPosition.X, inputTextPosition.Y + (_labelsTextFont.Metrics.XHeight + _labelsTextFont.Metrics.Descent), textPaint);
|
||||
|
||||
// Draw the cursor on top of the text and redraw the text with a different color if necessary.
|
||||
|
||||
Color cursorTextColor;
|
||||
IBrush cursorBrush;
|
||||
Pen cursorPen;
|
||||
SKColor cursorTextColor;
|
||||
SKPaint cursorBrush;
|
||||
SKPaint cursorPen;
|
||||
|
||||
float cursorPositionYTop = inputTextY + 1;
|
||||
float cursorPositionYBottom = cursorPositionYTop + _inputTextFontSize + 1;
|
||||
|
@ -389,12 +355,12 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
ReadOnlySpan<char> textUntilBegin = state.InputText.AsSpan(0, state.CursorBegin);
|
||||
ReadOnlySpan<char> textUntilEnd = state.InputText.AsSpan(0, state.CursorEnd);
|
||||
|
||||
var selectionBeginRectangle = MeasureString(textUntilBegin, _inputTextFont);
|
||||
var selectionEndRectangle = MeasureString(textUntilEnd, _inputTextFont);
|
||||
var selectionBeginRectangle = MeasureString(textUntilBegin, textPaint);
|
||||
var selectionEndRectangle = MeasureString(textUntilEnd, textPaint);
|
||||
|
||||
cursorVisible = true;
|
||||
cursorPositionXLeft = inputTextX + selectionBeginRectangle.Width + selectionBeginRectangle.X;
|
||||
cursorPositionXRight = inputTextX + selectionEndRectangle.Width + selectionEndRectangle.X;
|
||||
cursorPositionXLeft = inputTextX + selectionBeginRectangle.Width + selectionBeginRectangle.Left;
|
||||
cursorPositionXRight = inputTextX + selectionEndRectangle.Width + selectionEndRectangle.Left;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -408,10 +374,10 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
|
||||
int cursorBegin = Math.Min(state.InputText.Length, state.CursorBegin);
|
||||
ReadOnlySpan<char> textUntilCursor = state.InputText.AsSpan(0, cursorBegin);
|
||||
var cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont);
|
||||
var cursorTextRectangle = MeasureString(textUntilCursor, textPaint);
|
||||
|
||||
cursorVisible = true;
|
||||
cursorPositionXLeft = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.X;
|
||||
cursorPositionXLeft = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.Left;
|
||||
|
||||
if (state.OverwriteMode)
|
||||
{
|
||||
|
@ -420,8 +386,8 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
if (state.CursorBegin < state.InputText.Length)
|
||||
{
|
||||
textUntilCursor = state.InputText.AsSpan(0, cursorBegin + 1);
|
||||
cursorTextRectangle = MeasureString(textUntilCursor, _inputTextFont);
|
||||
cursorPositionXRight = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.X;
|
||||
cursorTextRectangle = MeasureString(textUntilCursor, textPaint);
|
||||
cursorPositionXRight = inputTextX + cursorTextRectangle.Width + cursorTextRectangle.Left;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -448,29 +414,32 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
|
||||
if (cursorWidth == 0)
|
||||
{
|
||||
PointF[] points = {
|
||||
new PointF(cursorPositionXLeft, cursorPositionYTop),
|
||||
new PointF(cursorPositionXLeft, cursorPositionYBottom),
|
||||
};
|
||||
|
||||
context.DrawLines(cursorPen, points);
|
||||
canvas.DrawLine(new SKPoint(cursorPositionXLeft, cursorPositionYTop),
|
||||
new SKPoint(cursorPositionXLeft, cursorPositionYBottom),
|
||||
cursorPen);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cursorRectangle = new RectangleF(cursorPositionXLeft, cursorPositionYTop, cursorWidth, cursorHeight);
|
||||
var cursorRectangle = SKRect.Create(cursorPositionXLeft, cursorPositionYTop, cursorWidth, cursorHeight);
|
||||
|
||||
context.Draw(cursorPen, cursorRectangle);
|
||||
context.Fill(cursorBrush, cursorRectangle);
|
||||
canvas.DrawRect(cursorRectangle, cursorPen);
|
||||
canvas.DrawRect(cursorRectangle, cursorBrush);
|
||||
|
||||
Image<Argb32> textOverCursor = new((int)cursorRectangle.Width, (int)cursorRectangle.Height);
|
||||
textOverCursor.Mutate(context =>
|
||||
using var textOverCursor = SKSurface.Create(new SKImageInfo((int)cursorRectangle.Width, (int)cursorRectangle.Height, SKColorType.Rgba8888));
|
||||
var textOverCanvas = textOverCursor.Canvas;
|
||||
var textRelativePosition = new SKPoint(inputTextPosition.X - cursorRectangle.Left, inputTextPosition.Y - cursorRectangle.Top);
|
||||
|
||||
using var cursorPaint = new SKPaint(_inputTextFont)
|
||||
{
|
||||
var textRelativePosition = new PointF(inputTextPosition.X - cursorRectangle.X, inputTextPosition.Y - cursorRectangle.Y);
|
||||
context.DrawText(state.InputText, _inputTextFont, cursorTextColor, textRelativePosition);
|
||||
});
|
||||
Color = cursorTextColor,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
var cursorPosition = new Point((int)cursorRectangle.X, (int)cursorRectangle.Y);
|
||||
context.DrawImage(textOverCursor, cursorPosition, 1);
|
||||
textOverCanvas.DrawText(state.InputText, textRelativePosition.X, textRelativePosition.Y + _inputTextFont.Metrics.XHeight + _inputTextFont.Metrics.Descent, cursorPaint);
|
||||
|
||||
var cursorPosition = new SKPoint((int)cursorRectangle.Left, (int)cursorRectangle.Top);
|
||||
textOverCursor.Flush();
|
||||
canvas.DrawSurface(textOverCursor, cursorPosition);
|
||||
}
|
||||
}
|
||||
else if (!state.TypingEnabled)
|
||||
|
@ -478,25 +447,31 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
// Just draw a semi-transparent rectangle on top to fade the component with the background.
|
||||
// TODO (caian): This will not work if one decides to add make background semi-transparent as well.
|
||||
|
||||
context.Fill(_disabledBrush, boundRectangle);
|
||||
canvas.DrawRect(boundRectangle, _disabledBrush);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPadButton(IImageProcessingContext context, PointF point, Image icon, string label, bool pressed, bool enabled)
|
||||
private void DrawPadButton(SKCanvas canvas, SKPoint point, SKBitmap icon, string label, bool pressed, bool enabled)
|
||||
{
|
||||
// Use relative positions so we can center the the entire drawing later.
|
||||
// Use relative positions so we can center the entire drawing later.
|
||||
|
||||
float iconX = 0;
|
||||
float iconY = 0;
|
||||
float iconWidth = icon.Width;
|
||||
float iconHeight = icon.Height;
|
||||
|
||||
var labelRectangle = MeasureString(label, _labelsTextFont);
|
||||
using var paint = new SKPaint(_labelsTextFont)
|
||||
{
|
||||
Color = _textNormalColor,
|
||||
IsAntialias = true
|
||||
};
|
||||
|
||||
float labelPositionX = iconWidth + 8 - labelRectangle.X;
|
||||
var labelRectangle = MeasureString(label, paint);
|
||||
|
||||
float labelPositionX = iconWidth + 8 - labelRectangle.Left;
|
||||
float labelPositionY = 3;
|
||||
|
||||
float fullWidth = labelPositionX + labelRectangle.Width + labelRectangle.X;
|
||||
float fullWidth = labelPositionX + labelRectangle.Width + labelRectangle.Left;
|
||||
float fullHeight = iconHeight;
|
||||
|
||||
// Convert all relative positions into absolute.
|
||||
|
@ -507,24 +482,24 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
iconX += originX;
|
||||
iconY += originY;
|
||||
|
||||
var iconPosition = new Point((int)iconX, (int)iconY);
|
||||
var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY);
|
||||
var iconPosition = new SKPoint((int)iconX, (int)iconY);
|
||||
var labelPosition = new SKPoint(labelPositionX + originX, labelPositionY + originY);
|
||||
|
||||
var selectedRectangle = new RectangleF(originX - 2 * _padPressedPenWidth, originY - 2 * _padPressedPenWidth,
|
||||
var selectedRectangle = SKRect.Create(originX - 2 * _padPressedPenWidth, originY - 2 * _padPressedPenWidth,
|
||||
fullWidth + 4 * _padPressedPenWidth, fullHeight + 4 * _padPressedPenWidth);
|
||||
|
||||
var boundRectangle = new RectangleF(originX, originY, fullWidth, fullHeight);
|
||||
var boundRectangle = SKRect.Create(originX, originY, fullWidth, fullHeight);
|
||||
boundRectangle.Inflate(4 * _padPressedPenWidth, 4 * _padPressedPenWidth);
|
||||
|
||||
context.Fill(_panelBrush, boundRectangle);
|
||||
context.DrawImage(icon, iconPosition, 1);
|
||||
context.DrawText(label, _labelsTextFont, _textNormalColor, labelPosition);
|
||||
canvas.DrawRect(boundRectangle, _panelBrush);
|
||||
canvas.DrawBitmap(icon, iconPosition);
|
||||
canvas.DrawText(label, labelPosition.X, labelPosition.Y + _labelsTextFont.Metrics.XHeight + _labelsTextFont.Metrics.Descent, paint);
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
if (pressed)
|
||||
{
|
||||
context.Draw(_padPressedPen, selectedRectangle);
|
||||
canvas.DrawRect(selectedRectangle, _padPressedPen);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -532,21 +507,26 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
// Just draw a semi-transparent rectangle on top to fade the component with the background.
|
||||
// TODO (caian): This will not work if one decides to add make background semi-transparent as well.
|
||||
|
||||
context.Fill(_disabledBrush, boundRectangle);
|
||||
canvas.DrawRect(boundRectangle, _disabledBrush);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawControllerToggle(IImageProcessingContext context, PointF point)
|
||||
private void DrawControllerToggle(SKCanvas canvas, SKPoint point)
|
||||
{
|
||||
var labelRectangle = MeasureString(ControllerToggleText, _labelsTextFont);
|
||||
using var paint = new SKPaint(_labelsTextFont)
|
||||
{
|
||||
IsAntialias = true,
|
||||
Color = _textNormalColor
|
||||
};
|
||||
var labelRectangle = MeasureString(ControllerToggleText, paint);
|
||||
|
||||
// Use relative positions so we can center the the entire drawing later.
|
||||
// Use relative positions so we can center the entire drawing later.
|
||||
|
||||
float keyWidth = _keyModeIcon.Width;
|
||||
float keyHeight = _keyModeIcon.Height;
|
||||
|
||||
float labelPositionX = keyWidth + 8 - labelRectangle.X;
|
||||
float labelPositionY = -labelRectangle.Y - 1;
|
||||
float labelPositionX = keyWidth + 8 - labelRectangle.Left;
|
||||
float labelPositionY = -labelRectangle.Top - 1;
|
||||
|
||||
float keyX = 0;
|
||||
float keyY = (int)((labelPositionY + labelRectangle.Height - keyHeight) / 2);
|
||||
|
@ -562,14 +542,14 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
keyX += originX;
|
||||
keyY += originY;
|
||||
|
||||
var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY);
|
||||
var overlayPosition = new Point((int)keyX, (int)keyY);
|
||||
var labelPosition = new SKPoint(labelPositionX + originX, labelPositionY + originY);
|
||||
var overlayPosition = new SKPoint((int)keyX, (int)keyY);
|
||||
|
||||
context.DrawImage(_keyModeIcon, overlayPosition, 1);
|
||||
context.DrawText(ControllerToggleText, _labelsTextFont, _textNormalColor, labelPosition);
|
||||
canvas.DrawBitmap(_keyModeIcon, overlayPosition);
|
||||
canvas.DrawText(ControllerToggleText, labelPosition.X, labelPosition.Y + _labelsTextFont.Metrics.XHeight, paint);
|
||||
}
|
||||
|
||||
public void CopyImageToBuffer()
|
||||
public unsafe void CopyImageToBuffer()
|
||||
{
|
||||
lock (_bufferLock)
|
||||
{
|
||||
|
@ -579,21 +559,20 @@ private void CreateFonts(string uiThemeFontFamily)
|
|||
}
|
||||
|
||||
// Convert the pixel format used in the image to the one used in the Switch surface.
|
||||
_surface.Flush();
|
||||
|
||||
if (!_surface.TryGetSinglePixelSpan(out Span<Argb32> pixels))
|
||||
var buffer = new byte[_imageInfo.BytesSize];
|
||||
fixed (byte* bufferPtr = buffer)
|
||||
{
|
||||
return;
|
||||
if (!_surface.ReadPixels(_imageInfo, (nint)bufferPtr, _imageInfo.RowBytes, 0, 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_bufferData = MemoryMarshal.AsBytes(pixels).ToArray();
|
||||
Span<uint> dataConvert = MemoryMarshal.Cast<byte, uint>(_bufferData);
|
||||
_bufferData = buffer;
|
||||
|
||||
Debug.Assert(_bufferData.Length == _surfaceInfo.Size);
|
||||
|
||||
for (int i = 0; i < dataConvert.Length; i++)
|
||||
{
|
||||
dataConvert[i] = BitOperations.RotateRight(dataConvert[i], 8);
|
||||
}
|
||||
Debug.Assert(buffer.Length == _surfaceInfo.Size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard;
|
|||
|
||||
namespace Ryujinx.HLE.HOS.Applets
|
||||
{
|
||||
public struct SoftwareKeyboardUiArgs
|
||||
public struct SoftwareKeyboardUIArgs
|
||||
{
|
||||
public KeyboardMode KeyboardMode;
|
||||
public string HeaderText;
|
|
@ -1,11 +1,11 @@
|
|||
using Ryujinx.HLE.Ui;
|
||||
using Ryujinx.HLE.UI;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO
|
||||
/// </summary>
|
||||
internal class SoftwareKeyboardUiState
|
||||
internal class SoftwareKeyboardUIState
|
||||
{
|
||||
public string InputText = "";
|
||||
public int CursorBegin = 0;
|
|
@ -57,6 +57,8 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
public void Execute(IExecutionContext context, ulong codeAddress)
|
||||
{
|
||||
// We must wait until shader cache is loaded, among other things, before executing CPU code.
|
||||
_gpuContext.WaitUntilGpuReady();
|
||||
_cpuContext.Execute(context, codeAddress);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,9 +72,10 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
AddressSpace addressSpace = null;
|
||||
|
||||
if ((mode == MemoryManagerMode.HostMapped || mode == MemoryManagerMode.HostMappedUnsafe) && (MemoryBlock.GetPageSize() <= 0x1000))
|
||||
// We want to use host tracked mode if the host page size is > 4KB.
|
||||
if ((mode == MemoryManagerMode.HostMapped || mode == MemoryManagerMode.HostMappedUnsafe) && MemoryBlock.GetPageSize() <= 0x1000)
|
||||
{
|
||||
if (!AddressSpace.TryCreate(context.Memory, addressSpaceSize, MemoryBlock.GetPageSize() == MemoryManagerHostMapped.PageSize, out addressSpace))
|
||||
if (!AddressSpace.TryCreate(context.Memory, addressSpaceSize, out addressSpace))
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Cpu, "Address space creation failed, falling back to software page table");
|
||||
|
||||
|
@ -93,7 +94,7 @@ namespace Ryujinx.HLE.HOS
|
|||
case MemoryManagerMode.HostMappedUnsafe:
|
||||
if (addressSpace == null)
|
||||
{
|
||||
var memoryManagerHostTracked = new MemoryManagerHostTracked(context.Memory, addressSpaceSize, invalidAccessHandler);
|
||||
var memoryManagerHostTracked = new MemoryManagerHostTracked(context.Memory, addressSpaceSize, mode == MemoryManagerMode.HostMappedUnsafe, invalidAccessHandler);
|
||||
processContext = new ArmProcessContext<MemoryManagerHostTracked>(pid, cpuEngine, _gpu, memoryManagerHostTracked, addressSpaceSize, for64Bit);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -4,12 +4,6 @@ using LibHac.Fs;
|
|||
using LibHac.Fs.Shim;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using Ryujinx.Audio;
|
||||
using Ryujinx.Audio.Input;
|
||||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.Audio.Output;
|
||||
using Ryujinx.Audio.Renderer.Device;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
|
@ -20,7 +14,6 @@ using Ryujinx.HLE.HOS.Services;
|
|||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy;
|
||||
using Ryujinx.HLE.HOS.Services.Apm;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
using Ryujinx.HLE.HOS.Services.Caps;
|
||||
using Ryujinx.HLE.HOS.Services.Mii;
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
|
@ -61,11 +54,6 @@ namespace Ryujinx.HLE.HOS
|
|||
internal ITickSource TickSource { get; }
|
||||
|
||||
internal SurfaceFlinger SurfaceFlinger { get; private set; }
|
||||
internal AudioManager AudioManager { get; private set; }
|
||||
internal AudioOutputManager AudioOutputManager { get; private set; }
|
||||
internal AudioInputManager AudioInputManager { get; private set; }
|
||||
internal AudioRendererManager AudioRendererManager { get; private set; }
|
||||
internal VirtualDeviceSessionRegistry AudioDeviceSessionRegistry { get; private set; }
|
||||
|
||||
public SystemStateMgr State { get; private set; }
|
||||
|
||||
|
@ -79,8 +67,6 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
internal ServerBase SmServer { get; private set; }
|
||||
internal ServerBase BsdServer { get; private set; }
|
||||
internal ServerBase AudRenServer { get; private set; }
|
||||
internal ServerBase AudOutServer { get; private set; }
|
||||
internal ServerBase FsServer { get; private set; }
|
||||
internal ServerBase HidServer { get; private set; }
|
||||
internal ServerBase NvDrvServer { get; private set; }
|
||||
|
@ -248,60 +234,9 @@ namespace Ryujinx.HLE.HOS
|
|||
HostSyncpoint = new NvHostSyncpt(device);
|
||||
|
||||
SurfaceFlinger = new SurfaceFlinger(device);
|
||||
|
||||
InitializeAudioRenderer(TickSource);
|
||||
InitializeServices();
|
||||
}
|
||||
|
||||
private void InitializeAudioRenderer(ITickSource tickSource)
|
||||
{
|
||||
AudioManager = new AudioManager();
|
||||
AudioOutputManager = new AudioOutputManager();
|
||||
AudioInputManager = new AudioInputManager();
|
||||
AudioRendererManager = new AudioRendererManager(tickSource);
|
||||
AudioRendererManager.SetVolume(Device.Configuration.AudioVolume);
|
||||
AudioDeviceSessionRegistry = new VirtualDeviceSessionRegistry(Device.AudioDeviceDriver);
|
||||
|
||||
IWritableEvent[] audioOutputRegisterBufferEvents = new IWritableEvent[Constants.AudioOutSessionCountMax];
|
||||
|
||||
for (int i = 0; i < audioOutputRegisterBufferEvents.Length; i++)
|
||||
{
|
||||
KEvent registerBufferEvent = new(KernelContext);
|
||||
|
||||
audioOutputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent);
|
||||
}
|
||||
|
||||
AudioOutputManager.Initialize(Device.AudioDeviceDriver, audioOutputRegisterBufferEvents);
|
||||
AudioOutputManager.SetVolume(Device.Configuration.AudioVolume);
|
||||
|
||||
IWritableEvent[] audioInputRegisterBufferEvents = new IWritableEvent[Constants.AudioInSessionCountMax];
|
||||
|
||||
for (int i = 0; i < audioInputRegisterBufferEvents.Length; i++)
|
||||
{
|
||||
KEvent registerBufferEvent = new(KernelContext);
|
||||
|
||||
audioInputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent);
|
||||
}
|
||||
|
||||
AudioInputManager.Initialize(Device.AudioDeviceDriver, audioInputRegisterBufferEvents);
|
||||
|
||||
IWritableEvent[] systemEvents = new IWritableEvent[Constants.AudioRendererSessionCountMax];
|
||||
|
||||
for (int i = 0; i < systemEvents.Length; i++)
|
||||
{
|
||||
KEvent systemEvent = new(KernelContext);
|
||||
|
||||
systemEvents[i] = new AudioKernelEvent(systemEvent);
|
||||
}
|
||||
|
||||
AudioManager.Initialize(Device.AudioDeviceDriver.GetUpdateRequiredEvent(), AudioOutputManager.Update, AudioInputManager.Update);
|
||||
|
||||
AudioRendererManager.Initialize(systemEvents, Device.AudioDeviceDriver);
|
||||
|
||||
AudioManager.Start();
|
||||
}
|
||||
|
||||
private void InitializeServices()
|
||||
public void InitializeServices()
|
||||
{
|
||||
SmRegistry = new SmRegistry();
|
||||
SmServer = new ServerBase(KernelContext, "SmServer", () => new IUserInterface(KernelContext, SmRegistry));
|
||||
|
@ -311,8 +246,6 @@ namespace Ryujinx.HLE.HOS
|
|||
SmServer.InitDone.WaitOne();
|
||||
|
||||
BsdServer = new ServerBase(KernelContext, "BsdServer");
|
||||
AudRenServer = new ServerBase(KernelContext, "AudioRendererServer");
|
||||
AudOutServer = new ServerBase(KernelContext, "AudioOutServer");
|
||||
FsServer = new ServerBase(KernelContext, "FsServer");
|
||||
HidServer = new ServerBase(KernelContext, "HidServer");
|
||||
NvDrvServer = new ServerBase(KernelContext, "NvservicesServer");
|
||||
|
@ -330,7 +263,13 @@ namespace Ryujinx.HLE.HOS
|
|||
HorizonFsClient fsClient = new(this);
|
||||
|
||||
ServiceTable = new ServiceTable();
|
||||
var services = ServiceTable.GetServices(new HorizonOptions(Device.Configuration.IgnoreMissingServices, LibHacHorizonManager.BcatClient, fsClient));
|
||||
var services = ServiceTable.GetServices(new HorizonOptions
|
||||
(Device.Configuration.IgnoreMissingServices,
|
||||
LibHacHorizonManager.BcatClient,
|
||||
fsClient,
|
||||
AccountManager,
|
||||
Device.AudioDeviceDriver,
|
||||
TickSource));
|
||||
|
||||
foreach (var service in services)
|
||||
{
|
||||
|
@ -385,17 +324,6 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
AudioOutputManager.SetVolume(volume);
|
||||
AudioRendererManager.SetVolume(volume);
|
||||
}
|
||||
|
||||
public float GetVolume()
|
||||
{
|
||||
return AudioOutputManager.GetVolume() == 0 ? AudioRendererManager.GetVolume() : AudioOutputManager.GetVolume();
|
||||
}
|
||||
|
||||
public void ReturnFocus()
|
||||
{
|
||||
AppletState.SetFocus(true);
|
||||
|
@ -459,11 +387,7 @@ namespace Ryujinx.HLE.HOS
|
|||
// "Soft" stops AudioRenderer and AudioManager to avoid some sound between resume and stop.
|
||||
if (IsPaused)
|
||||
{
|
||||
AudioManager.StopUpdates();
|
||||
|
||||
TogglePauseEmulation(false);
|
||||
|
||||
AudioRendererManager.StopSendingCommands();
|
||||
}
|
||||
|
||||
KProcess terminationProcess = new(KernelContext);
|
||||
|
@ -514,12 +438,6 @@ namespace Ryujinx.HLE.HOS
|
|||
// This is safe as KThread that are likely to call ioctls are going to be terminated by the post handler hook on the SVC facade.
|
||||
INvDrvServices.Destroy();
|
||||
|
||||
AudioManager.Dispose();
|
||||
AudioOutputManager.Dispose();
|
||||
AudioInputManager.Dispose();
|
||||
|
||||
AudioRendererManager.Dispose();
|
||||
|
||||
if (LibHacHorizonManager.ApplicationClient != null)
|
||||
{
|
||||
LibHacHorizonManager.PmClient.Fs.UnregisterProgram(LibHacHorizonManager.ApplicationClient.Os.GetCurrentProcessId().Value).ThrowIfFailure();
|
||||
|
|
|
@ -28,8 +28,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
|
|||
MemoryArrange.MemoryArrange4GiBSystemDev or
|
||||
MemoryArrange.MemoryArrange6GiBAppletDev => 3285 * MiB,
|
||||
MemoryArrange.MemoryArrange4GiBAppletDev => 2048 * MiB,
|
||||
MemoryArrange.MemoryArrange6GiB or
|
||||
MemoryArrange.MemoryArrange8GiB => 4916 * MiB,
|
||||
MemoryArrange.MemoryArrange6GiB => 4916 * MiB,
|
||||
MemoryArrange.MemoryArrange8GiB => 6964 * MiB,
|
||||
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."),
|
||||
};
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
|
|||
MemoryArrange.MemoryArrange4GiBAppletDev => 1554 * MiB,
|
||||
MemoryArrange.MemoryArrange4GiBSystemDev => 448 * MiB,
|
||||
MemoryArrange.MemoryArrange6GiB => 562 * MiB,
|
||||
MemoryArrange.MemoryArrange6GiBAppletDev or
|
||||
MemoryArrange.MemoryArrange8GiB => 2193 * MiB,
|
||||
MemoryArrange.MemoryArrange6GiBAppletDev => 2193 * MiB,
|
||||
MemoryArrange.MemoryArrange8GiB => 562 * MiB,
|
||||
_ => throw new ArgumentException($"Invalid memory arrange \"{arrange}\"."),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -570,7 +570,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
|||
}
|
||||
else
|
||||
{
|
||||
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
||||
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetReadOnlySequence(copySrc, (int)copySize));
|
||||
}
|
||||
|
||||
if (clientResult != Result.Success)
|
||||
|
@ -858,7 +858,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
|||
}
|
||||
else
|
||||
{
|
||||
clientProcess.CpuMemory.Write(copyDst, serverProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
||||
clientProcess.CpuMemory.Write(copyDst, serverProcess.CpuMemory.GetReadOnlySequence(copySrc, (int)copySize));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
{
|
||||
enum AddressSpaceType
|
||||
{
|
||||
Addr32Bits = 0,
|
||||
Addr36Bits = 1,
|
||||
Addr32BitsNoMap = 2,
|
||||
Addr39Bits = 3,
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using Ryujinx.Horizon.Common;
|
|||
using Ryujinx.Memory;
|
||||
using Ryujinx.Memory.Range;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
@ -11,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
{
|
||||
private readonly IVirtualMemoryManager _cpuMemory;
|
||||
|
||||
protected override bool Supports4KBPages => _cpuMemory.Supports4KBPages;
|
||||
protected override bool UsesPrivateAllocations => _cpuMemory.UsesPrivateAllocations;
|
||||
|
||||
public KPageTable(KernelContext context, IVirtualMemoryManager cpuMemory, ulong reservedAddressSpaceSize) : base(context, reservedAddressSpaceSize)
|
||||
{
|
||||
|
@ -34,6 +35,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ReadOnlySequence<byte> GetReadOnlySequence(ulong va, int size)
|
||||
{
|
||||
return _cpuMemory.GetReadOnlySequence(va, size);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ReadOnlySpan<byte> GetSpan(ulong va, int size)
|
||||
{
|
||||
|
@ -119,7 +126,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
Context.MemoryManager.IncrementPagesReferenceCount(srcPa, pagesCount);
|
||||
}
|
||||
|
||||
if (shouldFillPages && (Supports4KBPages || !flags.HasFlag(MemoryMapFlags.Private) || fillValue != 0))
|
||||
if (shouldFillPages && (!OperatingSystem.IsIOS() || !flags.HasFlag(MemoryMapFlags.Private) || fillValue != 0))
|
||||
{
|
||||
_cpuMemory.Fill(dstVa, size, fillValue);
|
||||
}
|
||||
|
@ -149,7 +156,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
_cpuMemory.Map(currentVa, addr, size, flags);
|
||||
|
||||
if (shouldFillPages && (Supports4KBPages || !flags.HasFlag(MemoryMapFlags.Private) || fillValue != 0))
|
||||
if (shouldFillPages && (!OperatingSystem.IsIOS() || !flags.HasFlag(MemoryMapFlags.Private) || fillValue != 0))
|
||||
{
|
||||
_cpuMemory.Fill(currentVa, size, fillValue);
|
||||
}
|
||||
|
@ -247,6 +254,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
_cpuMemory.SignalMemoryTracking(va, size, write);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Write(ulong va, ReadOnlySequence<byte> data)
|
||||
{
|
||||
_cpuMemory.Write(va, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Write(ulong va, ReadOnlySpan<byte> data)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ using Ryujinx.Horizon.Common;
|
|||
using Ryujinx.Memory;
|
||||
using Ryujinx.Memory.Range;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
@ -32,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
private const int MaxBlocksNeededForInsertion = 2;
|
||||
|
||||
protected readonly KernelContext Context;
|
||||
protected virtual bool Supports4KBPages => true;
|
||||
protected virtual bool UsesPrivateAllocations => false;
|
||||
|
||||
public ulong AddrSpaceStart { get; private set; }
|
||||
public ulong AddrSpaceEnd { get; private set; }
|
||||
|
@ -57,11 +58,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
public ulong AslrRegionStart { get; private set; }
|
||||
public ulong AslrRegionEnd { get; private set; }
|
||||
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private ulong _heapCapacity;
|
||||
#pragma warning restore IDE0052
|
||||
|
||||
public ulong PhysicalMemoryUsage { get; private set; }
|
||||
public ulong AliasRegionExtraSize { get; private set; }
|
||||
|
||||
private readonly KMemoryBlockManager _blockManager;
|
||||
|
||||
|
@ -97,30 +97,21 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
_reservedAddressSpaceSize = reservedAddressSpaceSize;
|
||||
}
|
||||
|
||||
private static readonly int[] _addrSpaceSizes = { 32, 36, 32, 39 };
|
||||
|
||||
public Result InitializeForProcess(
|
||||
AddressSpaceType addrSpaceType,
|
||||
bool aslrEnabled,
|
||||
ProcessCreationFlags flags,
|
||||
bool fromBack,
|
||||
MemoryRegion memRegion,
|
||||
ulong address,
|
||||
ulong size,
|
||||
KMemoryBlockSlabManager slabManager)
|
||||
{
|
||||
if ((uint)addrSpaceType > (uint)AddressSpaceType.Addr39Bits)
|
||||
{
|
||||
throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType));
|
||||
}
|
||||
|
||||
_contextId = Context.ContextIdManager.GetId();
|
||||
|
||||
ulong addrSpaceBase = 0;
|
||||
ulong addrSpaceSize = 1UL << _addrSpaceSizes[(int)addrSpaceType];
|
||||
ulong addrSpaceSize = 1UL << GetAddressSpaceWidth(flags);
|
||||
|
||||
Result result = CreateUserAddressSpace(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
flags,
|
||||
fromBack,
|
||||
addrSpaceBase,
|
||||
addrSpaceSize,
|
||||
|
@ -137,6 +128,22 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
return result;
|
||||
}
|
||||
|
||||
private static int GetAddressSpaceWidth(ProcessCreationFlags flags)
|
||||
{
|
||||
switch (flags & ProcessCreationFlags.AddressSpaceMask)
|
||||
{
|
||||
case ProcessCreationFlags.AddressSpace32Bit:
|
||||
case ProcessCreationFlags.AddressSpace32BitWithoutAlias:
|
||||
return 32;
|
||||
case ProcessCreationFlags.AddressSpace64BitDeprecated:
|
||||
return 36;
|
||||
case ProcessCreationFlags.AddressSpace64Bit:
|
||||
return 39;
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Invalid process flags {flags}", nameof(flags));
|
||||
}
|
||||
|
||||
private struct Region
|
||||
{
|
||||
public ulong Start;
|
||||
|
@ -146,8 +153,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
}
|
||||
|
||||
private Result CreateUserAddressSpace(
|
||||
AddressSpaceType addrSpaceType,
|
||||
bool aslrEnabled,
|
||||
ProcessCreationFlags flags,
|
||||
bool fromBack,
|
||||
ulong addrSpaceStart,
|
||||
ulong addrSpaceEnd,
|
||||
|
@ -167,9 +173,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
ulong stackAndTlsIoStart;
|
||||
ulong stackAndTlsIoEnd;
|
||||
|
||||
switch (addrSpaceType)
|
||||
AliasRegionExtraSize = 0;
|
||||
|
||||
switch (flags & ProcessCreationFlags.AddressSpaceMask)
|
||||
{
|
||||
case AddressSpaceType.Addr32Bits:
|
||||
case ProcessCreationFlags.AddressSpace32Bit:
|
||||
aliasRegion.Size = 0x40000000;
|
||||
heapRegion.Size = 0x40000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -182,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x40000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr36Bits:
|
||||
case ProcessCreationFlags.AddressSpace64BitDeprecated:
|
||||
aliasRegion.Size = 0x180000000;
|
||||
heapRegion.Size = 0x180000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -195,7 +203,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x80000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr32BitsNoMap:
|
||||
case ProcessCreationFlags.AddressSpace32BitWithoutAlias:
|
||||
aliasRegion.Size = 0;
|
||||
heapRegion.Size = 0x80000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -208,7 +216,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x40000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr39Bits:
|
||||
case ProcessCreationFlags.AddressSpace64Bit:
|
||||
if (_reservedAddressSpaceSize < addrSpaceEnd)
|
||||
{
|
||||
int addressSpaceWidth = (int)ulong.Log2(_reservedAddressSpaceSize);
|
||||
|
@ -217,8 +225,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
heapRegion.Size = 0x180000000;
|
||||
stackRegion.Size = 1UL << (addressSpaceWidth - 8);
|
||||
tlsIoRegion.Size = 1UL << (addressSpaceWidth - 3);
|
||||
CodeRegionStart = BitUtils.AlignDown<ulong>(address, RegionAlignment);
|
||||
codeRegionSize = BitUtils.AlignUp<ulong>(endAddr, RegionAlignment) - CodeRegionStart;
|
||||
CodeRegionStart = BitUtils.AlignDown(address, RegionAlignment);
|
||||
codeRegionSize = BitUtils.AlignUp(endAddr, RegionAlignment) - CodeRegionStart;
|
||||
stackAndTlsIoStart = 0;
|
||||
stackAndTlsIoEnd = 0;
|
||||
AslrRegionStart = 0x8000000;
|
||||
|
@ -238,9 +246,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoStart = 0;
|
||||
stackAndTlsIoEnd = 0;
|
||||
}
|
||||
|
||||
if (flags.HasFlag(ProcessCreationFlags.EnableAliasRegionExtraSize))
|
||||
{
|
||||
AliasRegionExtraSize = addrSpaceEnd / 8;
|
||||
aliasRegion.Size += AliasRegionExtraSize;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType));
|
||||
throw new ArgumentException($"Invalid process flags {flags}", nameof(flags));
|
||||
}
|
||||
|
||||
CodeRegionEnd = CodeRegionStart + codeRegionSize;
|
||||
|
@ -265,6 +280,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
ulong aslrMaxOffset = mapAvailableSize - mapTotalSize;
|
||||
|
||||
bool aslrEnabled = flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
_aslrEnabled = aslrEnabled;
|
||||
|
||||
AddrSpaceStart = addrSpaceStart;
|
||||
|
@ -673,9 +690,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
MemoryState.UnmapProcessCodeMemoryAllowed,
|
||||
KMemoryPermission.None,
|
||||
KMemoryPermission.None,
|
||||
MemoryAttribute.Mask,
|
||||
MemoryAttribute.Mask & ~MemoryAttribute.PermissionLocked,
|
||||
MemoryAttribute.None,
|
||||
MemoryAttribute.IpcAndDeviceMapped | MemoryAttribute.PermissionLocked,
|
||||
MemoryAttribute.IpcAndDeviceMapped,
|
||||
out MemoryState state,
|
||||
out _,
|
||||
out _);
|
||||
|
@ -724,7 +741,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
{
|
||||
address = 0;
|
||||
|
||||
if (size > HeapRegionEnd - HeapRegionStart)
|
||||
if (size > HeapRegionEnd - HeapRegionStart || size > _heapCapacity)
|
||||
{
|
||||
return KernelResult.OutOfMemory;
|
||||
}
|
||||
|
@ -1568,7 +1585,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
while (size > 0)
|
||||
{
|
||||
ulong copySize = 0x100000; // Copy chunck size. Any value will do, moderate sizes are recommended.
|
||||
ulong copySize = int.MaxValue;
|
||||
|
||||
if (copySize > size)
|
||||
{
|
||||
|
@ -1577,11 +1594,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
if (toServer)
|
||||
{
|
||||
currentProcess.CpuMemory.Write(serverAddress, GetSpan(clientAddress, (int)copySize));
|
||||
currentProcess.CpuMemory.Write(serverAddress, GetReadOnlySequence(clientAddress, (int)copySize));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write(clientAddress, currentProcess.CpuMemory.GetSpan(serverAddress, (int)copySize));
|
||||
Write(clientAddress, currentProcess.CpuMemory.GetReadOnlySequence(serverAddress, (int)copySize));
|
||||
}
|
||||
|
||||
serverAddress += copySize;
|
||||
|
@ -1911,9 +1928,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
Context.Memory.Fill(GetDramAddressFromPa(dstFirstPagePa), unusedSizeBefore, (byte)_ipcFillValue);
|
||||
|
||||
ulong copySize = addressRounded <= endAddr ? addressRounded - address : size;
|
||||
var data = srcPageTable.GetSpan(addressTruncated + unusedSizeBefore, (int)copySize);
|
||||
var data = srcPageTable.GetReadOnlySequence(addressTruncated + unusedSizeBefore, (int)copySize);
|
||||
|
||||
Context.Memory.Write(GetDramAddressFromPa(dstFirstPagePa + unusedSizeBefore), data);
|
||||
((IWritableBlock)Context.Memory).Write(GetDramAddressFromPa(dstFirstPagePa + unusedSizeBefore), data);
|
||||
|
||||
firstPageFillAddress += unusedSizeBefore + copySize;
|
||||
|
||||
|
@ -1947,17 +1964,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
Result result;
|
||||
|
||||
if (srcPageTable.Supports4KBPages)
|
||||
if (srcPageTable.UsesPrivateAllocations)
|
||||
{
|
||||
result = MapForeign(srcPageTable.GetHostRegions(addressRounded, alignedSize), currentVa, alignedSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
KPageList pageList = new();
|
||||
srcPageTable.GetPhysicalRegions(addressRounded, alignedSize, pageList);
|
||||
|
||||
result = MapPages(currentVa, pageList, permission, MemoryMapFlags.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = MapForeign(srcPageTable.GetHostRegions(addressRounded, alignedSize), currentVa, alignedSize);
|
||||
}
|
||||
|
||||
if (result != Result.Success)
|
||||
{
|
||||
|
@ -1977,9 +1994,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
if (send)
|
||||
{
|
||||
ulong copySize = endAddr - endAddrTruncated;
|
||||
var data = srcPageTable.GetSpan(endAddrTruncated, (int)copySize);
|
||||
var data = srcPageTable.GetReadOnlySequence(endAddrTruncated, (int)copySize);
|
||||
|
||||
Context.Memory.Write(GetDramAddressFromPa(dstLastPagePa), data);
|
||||
((IWritableBlock)Context.Memory).Write(GetDramAddressFromPa(dstLastPagePa), data);
|
||||
|
||||
lastPageFillAddr += copySize;
|
||||
|
||||
|
@ -2943,6 +2960,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
/// <param name="pageList">Page list where the ranges will be added</param>
|
||||
protected abstract void GetPhysicalRegions(ulong va, ulong size, KPageList pageList);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only sequence of data from CPU mapped memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Allows reading non-contiguous memory without first copying it to a newly allocated single contiguous block.
|
||||
/// </remarks>
|
||||
/// <param name="va">Virtual address of the data</param>
|
||||
/// <param name="size">Size of the data</param>
|
||||
/// <returns>A read-only sequence of the data</returns>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract ReadOnlySequence<byte> GetReadOnlySequence(ulong va, int size);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only span of data from CPU mapped memory.
|
||||
/// </summary>
|
||||
|
@ -2952,7 +2981,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
/// </remarks>
|
||||
/// <param name="va">Virtual address of the data</param>
|
||||
/// <param name="size">Size of the data</param>
|
||||
/// <param name="tracked">True if read tracking is triggered on the span</param>
|
||||
/// <returns>A read-only span of the data</returns>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract ReadOnlySpan<byte> GetSpan(ulong va, int size);
|
||||
|
@ -3060,6 +3088,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
/// <param name="size">Size of the region</param>
|
||||
protected abstract void SignalMemoryTracking(ulong va, ulong size, bool write);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to CPU mapped memory, with write tracking.
|
||||
/// </summary>
|
||||
/// <param name="va">Virtual address to write the data into</param>
|
||||
/// <param name="data">Data to be written</param>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract void Write(ulong va, ReadOnlySequence<byte> data);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to CPU mapped memory, with write tracking.
|
||||
/// </summary>
|
||||
|
|
|
@ -2,7 +2,6 @@ using Ryujinx.Common;
|
|||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
{
|
||||
|
@ -49,17 +48,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
return KernelResult.InvalidPermission;
|
||||
}
|
||||
|
||||
// On platforms with page size > 4 KB, this can fail due to the address not being page aligned,
|
||||
// we can return an error to force the application to retry with a different address.
|
||||
|
||||
try
|
||||
{
|
||||
return memoryManager.MapPages(address, _pageList, MemoryState.SharedMemory, permission);
|
||||
}
|
||||
catch (InvalidMemoryRegionException)
|
||||
{
|
||||
return KernelResult.InvalidMemState;
|
||||
}
|
||||
return memoryManager.MapPages(address, _pageList, MemoryState.SharedMemory, permission);
|
||||
}
|
||||
|
||||
public Result UnmapFromProcess(KPageTableBase memoryManager, ulong address, ulong size, KProcess process)
|
||||
|
|
|
@ -126,8 +126,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
_contextFactory = contextFactory ?? new ProcessContextFactory();
|
||||
_customThreadStart = customThreadStart;
|
||||
|
||||
AddressSpaceType addrSpaceType = (AddressSpaceType)((int)(creationInfo.Flags & ProcessCreationFlags.AddressSpaceMask) >> (int)ProcessCreationFlags.AddressSpaceShift);
|
||||
|
||||
Pid = KernelContext.NewKipId();
|
||||
|
||||
if (Pid == 0 || Pid >= KernelConstants.InitialProcessId)
|
||||
|
@ -137,8 +135,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
InitializeMemoryManager(creationInfo.Flags);
|
||||
|
||||
bool aslrEnabled = creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
ulong codeAddress = creationInfo.CodeAddress;
|
||||
|
||||
ulong codeSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize;
|
||||
|
@ -148,9 +144,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
: KernelContext.SmallMemoryBlockSlabManager;
|
||||
|
||||
Result result = MemoryManager.InitializeForProcess(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
!aslrEnabled,
|
||||
creationInfo.Flags,
|
||||
!creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr),
|
||||
memRegion,
|
||||
codeAddress,
|
||||
codeSize,
|
||||
|
@ -234,8 +229,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
: KernelContext.SmallMemoryBlockSlabManager;
|
||||
}
|
||||
|
||||
AddressSpaceType addrSpaceType = (AddressSpaceType)((int)(creationInfo.Flags & ProcessCreationFlags.AddressSpaceMask) >> (int)ProcessCreationFlags.AddressSpaceShift);
|
||||
|
||||
Pid = KernelContext.NewProcessId();
|
||||
|
||||
if (Pid == ulong.MaxValue || Pid < KernelConstants.InitialProcessId)
|
||||
|
@ -245,16 +238,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
InitializeMemoryManager(creationInfo.Flags);
|
||||
|
||||
bool aslrEnabled = creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
ulong codeAddress = creationInfo.CodeAddress;
|
||||
|
||||
ulong codeSize = codePagesCount * KPageTableBase.PageSize;
|
||||
|
||||
Result result = MemoryManager.InitializeForProcess(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
!aslrEnabled,
|
||||
creationInfo.Flags,
|
||||
!creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr),
|
||||
memRegion,
|
||||
codeAddress,
|
||||
codeSize,
|
||||
|
@ -309,8 +299,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
private Result ParseProcessInfo(ProcessCreationInfo creationInfo)
|
||||
{
|
||||
// Ensure that the current kernel version is equal or above to the minimum required.
|
||||
uint requiredKernelVersionMajor = (uint)Capabilities.KernelReleaseVersion >> 19;
|
||||
uint requiredKernelVersionMinor = ((uint)Capabilities.KernelReleaseVersion >> 15) & 0xf;
|
||||
uint requiredKernelVersionMajor = Capabilities.KernelReleaseVersion >> 19;
|
||||
uint requiredKernelVersionMinor = (Capabilities.KernelReleaseVersion >> 15) & 0xf;
|
||||
|
||||
if (KernelContext.EnableVersionChecks)
|
||||
{
|
||||
|
@ -519,12 +509,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
private void GenerateRandomEntropy()
|
||||
{
|
||||
// TODO.
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
public Result Start(int mainThreadPriority, ulong stackSize)
|
||||
{
|
||||
|
@ -1182,5 +1170,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsSvcPermitted(int svcId)
|
||||
{
|
||||
return Capabilities.IsSvcPermitted(svcId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
{
|
||||
class KProcessCapabilities
|
||||
{
|
||||
private const int SvcMaskElementBits = 8;
|
||||
|
||||
public byte[] SvcAccessMask { get; }
|
||||
public byte[] IrqAccessMask { get; }
|
||||
|
||||
|
@ -22,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
public KProcessCapabilities()
|
||||
{
|
||||
// length / number of bits of the underlying type
|
||||
SvcAccessMask = new byte[KernelConstants.SupervisorCallCount / 8];
|
||||
SvcAccessMask = new byte[KernelConstants.SupervisorCallCount / SvcMaskElementBits];
|
||||
IrqAccessMask = new byte[0x80];
|
||||
}
|
||||
|
||||
|
@ -208,7 +210,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
return KernelResult.MaximumExceeded;
|
||||
}
|
||||
|
||||
SvcAccessMask[svcId / 8] |= (byte)(1 << (svcId & 7));
|
||||
SvcAccessMask[svcId / SvcMaskElementBits] |= (byte)(1 << (svcId % SvcMaskElementBits));
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -324,5 +326,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
return mask << (int)min;
|
||||
}
|
||||
|
||||
public bool IsSvcPermitted(int svcId)
|
||||
{
|
||||
int index = svcId / SvcMaskElementBits;
|
||||
int mask = 1 << (svcId % SvcMaskElementBits);
|
||||
|
||||
return (uint)svcId < KernelConstants.SupervisorCallCount && (SvcAccessMask[index] & mask) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
PoolPartitionMask = 0xf << PoolPartitionShift,
|
||||
|
||||
OptimizeMemoryAllocation = 1 << 11,
|
||||
DisableDeviceAddressSpaceMerge = 1 << 12,
|
||||
EnableAliasRegionExtraSize = 1 << 13,
|
||||
|
||||
All =
|
||||
Is64Bit |
|
||||
|
@ -38,6 +40,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
IsApplication |
|
||||
DeprecatedUseSecureMemory |
|
||||
PoolPartitionMask |
|
||||
OptimizeMemoryAllocation,
|
||||
OptimizeMemoryAllocation |
|
||||
DisableDeviceAddressSpaceMerge |
|
||||
EnableAliasRegionExtraSize,
|
||||
}
|
||||
}
|
||||
|
|
25
src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ExternalEvent.cs
Normal file
25
src/Ryujinx.HLE/HOS/Kernel/SupervisorCall/ExternalEvent.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
||||
{
|
||||
readonly struct ExternalEvent : IExternalEvent
|
||||
{
|
||||
private readonly KWritableEvent _writableEvent;
|
||||
|
||||
public ExternalEvent(KWritableEvent writableEvent)
|
||||
{
|
||||
_writableEvent = writableEvent;
|
||||
}
|
||||
|
||||
public readonly void Signal()
|
||||
{
|
||||
_writableEvent.Signal();
|
||||
}
|
||||
|
||||
public readonly void Clear()
|
||||
{
|
||||
_writableEvent.Clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,14 +21,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
SystemResourceSizeTotal,
|
||||
SystemResourceSizeUsed,
|
||||
ProgramId,
|
||||
// NOTE: Added in 4.0.0, removed in 5.0.0.
|
||||
InitialProcessIdRange,
|
||||
InitialProcessIdRange, // NOTE: Added in 4.0.0, removed in 5.0.0.
|
||||
UserExceptionContextAddress,
|
||||
TotalNonSystemMemorySize,
|
||||
UsedNonSystemMemorySize,
|
||||
IsApplication,
|
||||
FreeThreadCount,
|
||||
ThreadTickCount,
|
||||
IsSvcPermitted,
|
||||
IoRegionHint,
|
||||
AliasRegionExtraSize,
|
||||
|
||||
MesosphereCurrentProcess = 65001,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using Ryujinx.HLE.HOS.Kernel.Memory;
|
|||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Threading;
|
||||
|
@ -83,6 +84,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidSize;
|
||||
}
|
||||
|
||||
if (info.Flags.HasFlag(ProcessCreationFlags.EnableAliasRegionExtraSize))
|
||||
{
|
||||
if ((info.Flags & ProcessCreationFlags.AddressSpaceMask) != ProcessCreationFlags.AddressSpace64Bit ||
|
||||
info.SystemResourcePagesCount <= 0)
|
||||
{
|
||||
return KernelResult.InvalidState;
|
||||
}
|
||||
|
||||
// TODO: Check that we are in debug mode.
|
||||
}
|
||||
|
||||
if (info.Flags.HasFlag(ProcessCreationFlags.OptimizeMemoryAllocation) &&
|
||||
!info.Flags.HasFlag(ProcessCreationFlags.IsApplication))
|
||||
{
|
||||
|
@ -138,7 +150,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return handleTable.GenerateHandle(process, out handle);
|
||||
}
|
||||
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result StartProcess(int handle, int priority, int cpuCore, ulong mainThreadStackSize)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess().HandleTable.GetObject<KProcess>(handle);
|
||||
|
@ -171,17 +182,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x5f)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result FlushProcessDataCache(int processHandle, ulong address, ulong size)
|
||||
{
|
||||
// FIXME: This needs to be implemented as ARMv7 doesn't have any way to do cache maintenance operations on EL0.
|
||||
// As we don't support (and don't actually need) to flush the cache, this is stubbed.
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
// IPC
|
||||
|
||||
|
@ -255,7 +263,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x22)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SendSyncRequestWithUserBuffer(
|
||||
[PointerSized] ulong messagePtr,
|
||||
[PointerSized] ulong messageSize,
|
||||
|
@ -305,7 +312,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return result;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x23)]
|
||||
public Result SendAsyncRequestWithUserBuffer(
|
||||
|
@ -615,7 +621,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
}
|
||||
|
||||
ArrayPool<KSynchronizationObject>.Shared.Return(syncObjsArray);
|
||||
ArrayPool<KSynchronizationObject>.Shared.Return(syncObjsArray, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -895,7 +901,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(2)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetMemoryPermission([PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -927,10 +932,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return currentProcess.MemoryManager.SetMemoryPermission(address, size, permission);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(3)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetMemoryAttribute(
|
||||
[PointerSized] ulong address,
|
||||
[PointerSized] ulong size,
|
||||
|
@ -978,10 +981,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return result;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(4)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(src | dst))
|
||||
|
@ -1017,10 +1018,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return process.MemoryManager.Map(dst, src, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(5)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(src | dst))
|
||||
|
@ -1056,7 +1055,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return process.MemoryManager.Unmap(dst, src, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(6)]
|
||||
public Result QueryMemory([PointerSized] ulong infoPtr, [PointerSized] out ulong pageInfo, [PointerSized] ulong address)
|
||||
|
@ -1073,7 +1071,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return result;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result QueryMemory(out MemoryInfo info, out ulong pageInfo, ulong address)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -1093,10 +1090,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x13)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1142,10 +1137,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
currentProcess,
|
||||
permission);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x14)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1185,7 +1178,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
size,
|
||||
currentProcess);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x15)]
|
||||
public Result CreateTransferMemory(out int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
|
||||
|
@ -1252,7 +1244,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x51)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1298,10 +1289,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
currentProcess,
|
||||
permission);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x52)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1341,10 +1330,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
size,
|
||||
currentProcess);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x2c)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1379,10 +1366,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return process.MemoryManager.MapPhysicalMemory(address, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x2d)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
|
||||
{
|
||||
if (!PageAligned(address))
|
||||
|
@ -1417,7 +1402,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return process.MemoryManager.UnmapPhysicalMemory(address, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x4b)]
|
||||
public Result CreateCodeMemory(out int handle, [PointerSized] ulong address, [PointerSized] ulong size)
|
||||
|
@ -1461,7 +1445,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x4c)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result ControlCodeMemory(
|
||||
int handle,
|
||||
CodeMemoryOperation op,
|
||||
|
@ -1539,14 +1522,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidEnumValue;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x73)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetProcessMemoryPermission(
|
||||
int handle,
|
||||
[PointerSized] ulong src,
|
||||
[PointerSized] ulong size,
|
||||
ulong src,
|
||||
ulong size,
|
||||
KMemoryPermission permission)
|
||||
{
|
||||
if (!PageAligned(src))
|
||||
|
@ -1583,10 +1564,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return targetProcess.MemoryManager.SetProcessMemoryPermission(src, size, permission);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x74)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapProcessMemory(
|
||||
[PointerSized] ulong dst,
|
||||
int handle,
|
||||
|
@ -1642,10 +1621,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return dstProcess.MemoryManager.MapPages(dst, pageList, MemoryState.ProcessMemory, KMemoryPermission.ReadAndWrite);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x75)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapProcessMemory(
|
||||
[PointerSized] ulong dst,
|
||||
int handle,
|
||||
|
@ -1690,10 +1667,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x77)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result MapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
|
||||
{
|
||||
if (!PageAligned(dst) || !PageAligned(src))
|
||||
|
@ -1730,10 +1705,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return targetProcess.MemoryManager.MapProcessCodeMemory(dst, src, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x78)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result UnmapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
|
||||
{
|
||||
if (!PageAligned(dst) || !PageAligned(src))
|
||||
|
@ -1770,7 +1743,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return targetProcess.MemoryManager.UnmapProcessCodeMemory(dst, src, size);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
private static bool PageAligned(ulong address)
|
||||
{
|
||||
|
@ -1780,7 +1752,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
// System
|
||||
|
||||
[Svc(0x7b)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result TerminateProcess(int handle)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -1809,15 +1780,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return result;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(7)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public void ExitProcess()
|
||||
{
|
||||
KernelStatic.GetCurrentProcess().TerminateCurrentProcess();
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x11)]
|
||||
public Result SignalEvent(int handle)
|
||||
|
@ -1910,7 +1878,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x26)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public void Break(ulong reason)
|
||||
{
|
||||
KThread currentThread = KernelStatic.GetCurrentThread();
|
||||
|
@ -1936,10 +1903,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
Logger.Debug?.Print(LogClass.KernelSvc, "Debugger triggered.");
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x27)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public void OutputDebugString([PointerSized] ulong strPtr, [PointerSized] ulong size)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -1948,7 +1913,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
Logger.Warning?.Print(LogClass.KernelSvc, str);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x29)]
|
||||
public Result GetInfo(out ulong value, InfoType id, int handle, long subId)
|
||||
|
@ -1977,6 +1941,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.UsedNonSystemMemorySize:
|
||||
case InfoType.IsApplication:
|
||||
case InfoType.FreeThreadCount:
|
||||
case InfoType.AliasRegionExtraSize:
|
||||
{
|
||||
if (subId != 0)
|
||||
{
|
||||
|
@ -2005,22 +1970,19 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
value = process.MemoryManager.AliasRegionStart;
|
||||
break;
|
||||
case InfoType.AliasRegionSize:
|
||||
value = (process.MemoryManager.AliasRegionEnd -
|
||||
process.MemoryManager.AliasRegionStart);
|
||||
value = process.MemoryManager.AliasRegionEnd - process.MemoryManager.AliasRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.HeapRegionAddress:
|
||||
value = process.MemoryManager.HeapRegionStart;
|
||||
break;
|
||||
case InfoType.HeapRegionSize:
|
||||
value = (process.MemoryManager.HeapRegionEnd -
|
||||
process.MemoryManager.HeapRegionStart);
|
||||
value = process.MemoryManager.HeapRegionEnd - process.MemoryManager.HeapRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.TotalMemorySize:
|
||||
value = process.GetMemoryCapacity();
|
||||
break;
|
||||
|
||||
case InfoType.UsedMemorySize:
|
||||
value = process.GetMemoryUsage();
|
||||
break;
|
||||
|
@ -2028,7 +1990,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.AslrRegionAddress:
|
||||
value = process.MemoryManager.GetAddrSpaceBaseAddr();
|
||||
break;
|
||||
|
||||
case InfoType.AslrRegionSize:
|
||||
value = process.MemoryManager.GetAddrSpaceSize();
|
||||
break;
|
||||
|
@ -2037,20 +1998,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
value = process.MemoryManager.StackRegionStart;
|
||||
break;
|
||||
case InfoType.StackRegionSize:
|
||||
value = (process.MemoryManager.StackRegionEnd -
|
||||
process.MemoryManager.StackRegionStart);
|
||||
value = process.MemoryManager.StackRegionEnd - process.MemoryManager.StackRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.SystemResourceSizeTotal:
|
||||
value = process.PersonalMmHeapPagesCount * KPageTableBase.PageSize;
|
||||
break;
|
||||
|
||||
case InfoType.SystemResourceSizeUsed:
|
||||
if (process.PersonalMmHeapPagesCount != 0)
|
||||
{
|
||||
value = process.MemoryManager.GetMmUsedPages() * KPageTableBase.PageSize;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case InfoType.ProgramId:
|
||||
|
@ -2064,7 +2022,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.TotalNonSystemMemorySize:
|
||||
value = process.GetMemoryCapacityWithoutPersonalMmHeap();
|
||||
break;
|
||||
|
||||
case InfoType.UsedNonSystemMemorySize:
|
||||
value = process.GetMemoryUsageWithoutPersonalMmHeap();
|
||||
break;
|
||||
|
@ -2083,10 +2040,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
{
|
||||
value = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case InfoType.AliasRegionExtraSize:
|
||||
value = process.MemoryManager.AliasRegionExtraSize;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2103,7 +2062,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
value = KernelStatic.GetCurrentProcess().Debug ? 1UL : 0UL;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2135,7 +2093,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
value = (uint)resLimHandle;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2154,7 +2111,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
value = (ulong)KTimeManager.ConvertHostTicksToTicks(_context.Schedulers[currentCore].TotalIdleTimeTicks);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2173,7 +2129,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
|
||||
value = currentProcess.RandomEntropy[subId];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2219,7 +2174,22 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
value = (ulong)KTimeManager.ConvertHostTicksToTicks(totalTimeRunning);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case InfoType.IsSvcPermitted:
|
||||
{
|
||||
if (handle != 0)
|
||||
{
|
||||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
|
||||
if (subId != 0x36)
|
||||
{
|
||||
return KernelResult.InvalidCombination;
|
||||
}
|
||||
|
||||
value = KernelStatic.GetCurrentProcess().IsSvcPermitted((int)subId) ? 1UL : 0UL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2230,7 +2200,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
|
||||
if ((ulong)subId != 0)
|
||||
if (subId != 0)
|
||||
{
|
||||
return KernelResult.InvalidCombination;
|
||||
}
|
||||
|
@ -2245,8 +2215,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return result;
|
||||
}
|
||||
|
||||
value = (ulong)outHandle;
|
||||
|
||||
value = (uint)outHandle;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2397,7 +2366,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x30)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetResourceLimitLimitValue(out long limitValue, int handle, LimitableResource resource)
|
||||
{
|
||||
limitValue = 0;
|
||||
|
@ -2418,10 +2386,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x31)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetResourceLimitCurrentValue(out long limitValue, int handle, LimitableResource resource)
|
||||
{
|
||||
limitValue = 0;
|
||||
|
@ -2442,10 +2408,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x37)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetResourceLimitPeakValue(out long peak, int handle, LimitableResource resource)
|
||||
{
|
||||
peak = 0;
|
||||
|
@ -2466,7 +2430,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x7d)]
|
||||
public Result CreateResourceLimit(out int handle)
|
||||
|
@ -2479,7 +2442,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x7e)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetResourceLimitLimitValue(int handle, LimitableResource resource, long limitValue)
|
||||
{
|
||||
if (resource >= LimitableResource.Count)
|
||||
|
@ -2496,7 +2458,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return resourceLimit.SetLimitValue(resource, limitValue);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
// Thread
|
||||
|
||||
|
@ -2576,7 +2537,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(9)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result StartThread(int handle)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2603,17 +2563,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0xa)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public void ExitThread()
|
||||
{
|
||||
KThread currentThread = KernelStatic.GetCurrentThread();
|
||||
|
||||
currentThread.Exit();
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0xb)]
|
||||
public void SleepThread(long timeout)
|
||||
|
@ -2640,7 +2597,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0xc)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetThreadPriority(out int priority, int handle)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2660,10 +2616,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0xd)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetThreadPriority(int handle, int priority)
|
||||
{
|
||||
// TODO: NPDM check.
|
||||
|
@ -2681,10 +2635,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0xe)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetThreadCoreMask(out int preferredCore, out ulong affinityMask, int handle)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2706,10 +2658,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0xf)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetThreadCoreMask(int handle, int preferredCore, ulong affinityMask)
|
||||
{
|
||||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2757,18 +2707,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return thread.SetCoreAndAffinityMask(preferredCore, affinityMask);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x10)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public int GetCurrentProcessorNumber()
|
||||
{
|
||||
return KernelStatic.GetCurrentThread().CurrentCore;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x25)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetThreadId(out ulong threadUid, int handle)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2788,10 +2734,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidHandle;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x32)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SetThreadActivity(int handle, bool pause)
|
||||
{
|
||||
KProcess process = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2815,10 +2759,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return thread.SetActivity(pause);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x33)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result GetThreadContext3([PointerSized] ulong address, int handle)
|
||||
{
|
||||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
|
@ -2852,7 +2794,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return result;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
// Thread synchronization
|
||||
|
||||
|
@ -2985,7 +2926,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
[Svc(0x1a)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result ArbitrateLock(int ownerHandle, [PointerSized] ulong mutexAddress, int requesterHandle)
|
||||
{
|
||||
if (IsPointingInsideKernel(mutexAddress))
|
||||
|
@ -3002,10 +2942,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return currentProcess.AddressArbiter.ArbitrateLock(ownerHandle, mutexAddress, requesterHandle);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x1b)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result ArbitrateUnlock([PointerSized] ulong mutexAddress)
|
||||
{
|
||||
if (IsPointingInsideKernel(mutexAddress))
|
||||
|
@ -3022,10 +2960,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return currentProcess.AddressArbiter.ArbitrateUnlock(mutexAddress);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x1c)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result WaitProcessWideKeyAtomic(
|
||||
[PointerSized] ulong mutexAddress,
|
||||
[PointerSized] ulong condVarAddress,
|
||||
|
@ -3055,10 +2991,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
handle,
|
||||
timeout);
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x1d)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SignalProcessWideKey([PointerSized] ulong address, int count)
|
||||
{
|
||||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
|
@ -3067,10 +3001,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x34)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result WaitForAddress([PointerSized] ulong address, ArbitrationType type, int value, long timeout)
|
||||
{
|
||||
if (IsPointingInsideKernel(address))
|
||||
|
@ -3101,10 +3033,8 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
_ => KernelResult.InvalidEnumValue,
|
||||
};
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x35)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SignalToAddress([PointerSized] ulong address, SignalType type, int value, int count)
|
||||
{
|
||||
if (IsPointingInsideKernel(address))
|
||||
|
@ -3130,17 +3060,45 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
_ => KernelResult.InvalidEnumValue,
|
||||
};
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
[Svc(0x36)]
|
||||
#pragma warning disable CA1822 // Mark member as static
|
||||
public Result SynchronizePreemptionState()
|
||||
{
|
||||
KernelStatic.GetCurrentThread().SynchronizePreemptionState();
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
#pragma warning restore CA1822
|
||||
|
||||
// Not actual syscalls, used by HLE services and such.
|
||||
|
||||
public IExternalEvent GetExternalEvent(int handle)
|
||||
{
|
||||
KWritableEvent writableEvent = KernelStatic.GetCurrentProcess().HandleTable.GetObject<KWritableEvent>(handle);
|
||||
|
||||
if (writableEvent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ExternalEvent(writableEvent);
|
||||
}
|
||||
|
||||
public IVirtualMemoryManager GetMemoryManagerByProcessHandle(int handle)
|
||||
{
|
||||
return KernelStatic.GetCurrentProcess().HandleTable.GetKProcess(handle).CpuMemory;
|
||||
}
|
||||
|
||||
public ulong GetTransferMemoryAddress(int handle)
|
||||
{
|
||||
KTransferMemory transferMemory = KernelStatic.GetCurrentProcess().HandleTable.GetObject<KTransferMemory>(handle);
|
||||
|
||||
if (transferMemory == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return transferMemory.Address;
|
||||
}
|
||||
|
||||
private static bool IsPointingInsideKernel(ulong address)
|
||||
{
|
||||
|
|
|
@ -28,42 +28,25 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
|
||||
private SchedulingState _state;
|
||||
|
||||
private AutoResetEvent _idleInterruptEvent;
|
||||
private readonly object _idleInterruptEventLock;
|
||||
|
||||
private KThread _previousThread;
|
||||
private KThread _currentThread;
|
||||
private readonly KThread _idleThread;
|
||||
|
||||
private int _coreIdleLock;
|
||||
private bool _idleSignalled = true;
|
||||
private bool _idleActive = true;
|
||||
private long _idleTimeRunning;
|
||||
|
||||
public KThread PreviousThread => _previousThread;
|
||||
public KThread CurrentThread => _currentThread;
|
||||
public long LastContextSwitchTime { get; private set; }
|
||||
public long TotalIdleTimeTicks => _idleThread.TotalTimeRunning;
|
||||
public long TotalIdleTimeTicks => _idleTimeRunning;
|
||||
|
||||
public KScheduler(KernelContext context, int coreId)
|
||||
{
|
||||
_context = context;
|
||||
_coreId = coreId;
|
||||
|
||||
_idleInterruptEvent = new AutoResetEvent(false);
|
||||
_idleInterruptEventLock = new object();
|
||||
|
||||
KThread idleThread = CreateIdleThread(context, coreId);
|
||||
|
||||
_currentThread = idleThread;
|
||||
_idleThread = idleThread;
|
||||
|
||||
idleThread.StartHostThread();
|
||||
idleThread.SchedulerWaitEvent.Set();
|
||||
}
|
||||
|
||||
private KThread CreateIdleThread(KernelContext context, int cpuCore)
|
||||
{
|
||||
KThread idleThread = new(context);
|
||||
|
||||
idleThread.Initialize(0UL, 0UL, 0UL, PrioritiesCount, cpuCore, null, ThreadType.Dummy, IdleThreadLoop);
|
||||
|
||||
return idleThread;
|
||||
_currentThread = null;
|
||||
}
|
||||
|
||||
public static ulong SelectThreads(KernelContext context)
|
||||
|
@ -237,39 +220,64 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
KThread threadToSignal = context.Schedulers[coreToSignal]._currentThread;
|
||||
|
||||
// Request the thread running on that core to stop and reschedule, if we have one.
|
||||
if (threadToSignal != context.Schedulers[coreToSignal]._idleThread)
|
||||
{
|
||||
threadToSignal.Context.RequestInterrupt();
|
||||
}
|
||||
threadToSignal?.Context.RequestInterrupt();
|
||||
|
||||
// If the core is idle, ensure that the idle thread is awaken.
|
||||
context.Schedulers[coreToSignal]._idleInterruptEvent.Set();
|
||||
context.Schedulers[coreToSignal].NotifyIdleThread();
|
||||
|
||||
scheduledCoresMask &= ~(1UL << coreToSignal);
|
||||
}
|
||||
}
|
||||
|
||||
private void IdleThreadLoop()
|
||||
private void ActivateIdleThread()
|
||||
{
|
||||
while (_context.Running)
|
||||
while (Interlocked.CompareExchange(ref _coreIdleLock, 1, 0) != 0)
|
||||
{
|
||||
Thread.SpinWait(1);
|
||||
}
|
||||
|
||||
Thread.MemoryBarrier();
|
||||
|
||||
// Signals that idle thread is now active on this core.
|
||||
_idleActive = true;
|
||||
|
||||
TryLeaveIdle();
|
||||
|
||||
Interlocked.Exchange(ref _coreIdleLock, 0);
|
||||
}
|
||||
|
||||
private void NotifyIdleThread()
|
||||
{
|
||||
while (Interlocked.CompareExchange(ref _coreIdleLock, 1, 0) != 0)
|
||||
{
|
||||
Thread.SpinWait(1);
|
||||
}
|
||||
|
||||
Thread.MemoryBarrier();
|
||||
|
||||
// Signals that the idle core may be able to exit idle.
|
||||
_idleSignalled = true;
|
||||
|
||||
TryLeaveIdle();
|
||||
|
||||
Interlocked.Exchange(ref _coreIdleLock, 0);
|
||||
}
|
||||
|
||||
public void TryLeaveIdle()
|
||||
{
|
||||
if (_idleSignalled && _idleActive)
|
||||
{
|
||||
_state.NeedsScheduling = false;
|
||||
Thread.MemoryBarrier();
|
||||
KThread nextThread = PickNextThread(_state.SelectedThread);
|
||||
KThread nextThread = PickNextThread(null, _state.SelectedThread);
|
||||
|
||||
if (_idleThread != nextThread)
|
||||
if (nextThread != null)
|
||||
{
|
||||
_idleThread.SchedulerWaitEvent.Reset();
|
||||
WaitHandle.SignalAndWait(nextThread.SchedulerWaitEvent, _idleThread.SchedulerWaitEvent);
|
||||
_idleActive = false;
|
||||
nextThread.SchedulerWaitEvent.Set();
|
||||
}
|
||||
|
||||
_idleInterruptEvent.WaitOne();
|
||||
}
|
||||
|
||||
lock (_idleInterruptEventLock)
|
||||
{
|
||||
_idleInterruptEvent.Dispose();
|
||||
_idleInterruptEvent = null;
|
||||
_idleSignalled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,20 +300,37 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
// Wake all the threads that might be waiting until this thread context is unlocked.
|
||||
for (int core = 0; core < CpuCoresCount; core++)
|
||||
{
|
||||
_context.Schedulers[core]._idleInterruptEvent.Set();
|
||||
_context.Schedulers[core].NotifyIdleThread();
|
||||
}
|
||||
|
||||
KThread nextThread = PickNextThread(selectedThread);
|
||||
KThread nextThread = PickNextThread(KernelStatic.GetCurrentThread(), selectedThread);
|
||||
|
||||
if (currentThread.Context.Running)
|
||||
{
|
||||
// Wait until this thread is scheduled again, and allow the next thread to run.
|
||||
WaitHandle.SignalAndWait(nextThread.SchedulerWaitEvent, currentThread.SchedulerWaitEvent);
|
||||
|
||||
if (nextThread == null)
|
||||
{
|
||||
ActivateIdleThread();
|
||||
currentThread.SchedulerWaitEvent.WaitOne();
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitHandle.SignalAndWait(nextThread.SchedulerWaitEvent, currentThread.SchedulerWaitEvent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Allow the next thread to run.
|
||||
nextThread.SchedulerWaitEvent.Set();
|
||||
|
||||
if (nextThread == null)
|
||||
{
|
||||
ActivateIdleThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
nextThread.SchedulerWaitEvent.Set();
|
||||
}
|
||||
|
||||
// We don't need to wait since the thread is exiting, however we need to
|
||||
// make sure this thread will never call the scheduler again, since it is
|
||||
|
@ -319,7 +344,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
}
|
||||
}
|
||||
|
||||
private KThread PickNextThread(KThread selectedThread)
|
||||
private KThread PickNextThread(KThread currentThread, KThread selectedThread)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
@ -335,7 +360,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
// on the core, as the scheduled thread will handle the next switch.
|
||||
if (selectedThread.ThreadContext.Lock())
|
||||
{
|
||||
SwitchTo(selectedThread);
|
||||
SwitchTo(currentThread, selectedThread);
|
||||
|
||||
if (!_state.NeedsScheduling)
|
||||
{
|
||||
|
@ -346,15 +371,15 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
}
|
||||
else
|
||||
{
|
||||
return _idleThread;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The core is idle now, make sure that the idle thread can run
|
||||
// and switch the core when a thread is available.
|
||||
SwitchTo(null);
|
||||
return _idleThread;
|
||||
SwitchTo(currentThread, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
_state.NeedsScheduling = false;
|
||||
|
@ -363,12 +388,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
}
|
||||
}
|
||||
|
||||
private void SwitchTo(KThread nextThread)
|
||||
private void SwitchTo(KThread currentThread, KThread nextThread)
|
||||
{
|
||||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
KThread currentThread = KernelStatic.GetCurrentThread();
|
||||
|
||||
nextThread ??= _idleThread;
|
||||
KProcess currentProcess = currentThread?.Owner;
|
||||
|
||||
if (currentThread != nextThread)
|
||||
{
|
||||
|
@ -376,7 +398,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
long currentTicks = PerformanceCounter.ElapsedTicks;
|
||||
long ticksDelta = currentTicks - previousTicks;
|
||||
|
||||
currentThread.AddCpuTime(ticksDelta);
|
||||
if (currentThread == null)
|
||||
{
|
||||
Interlocked.Add(ref _idleTimeRunning, ticksDelta);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentThread.AddCpuTime(ticksDelta);
|
||||
}
|
||||
|
||||
currentProcess?.AddCpuTime(ticksDelta);
|
||||
|
||||
|
@ -386,13 +415,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
{
|
||||
_previousThread = !currentThread.TerminationRequested && currentThread.ActiveCore == _coreId ? currentThread : null;
|
||||
}
|
||||
else if (currentThread == _idleThread)
|
||||
else if (currentThread == null)
|
||||
{
|
||||
_previousThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextThread.CurrentCore != _coreId)
|
||||
if (nextThread != null && nextThread.CurrentCore != _coreId)
|
||||
{
|
||||
nextThread.CurrentCore = _coreId;
|
||||
}
|
||||
|
@ -645,11 +674,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
// Ensure that the idle thread is not blocked and can exit.
|
||||
lock (_idleInterruptEventLock)
|
||||
{
|
||||
_idleInterruptEvent?.Set();
|
||||
}
|
||||
// No resources to dispose for now.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
}
|
||||
}
|
||||
|
||||
ArrayPool<LinkedListNode<KThread>>.Shared.Return(syncNodesArray);
|
||||
ArrayPool<LinkedListNode<KThread>>.Shared.Return(syncNodesArray, true);
|
||||
}
|
||||
|
||||
_context.CriticalSection.Leave();
|
||||
|
|
|
@ -143,9 +143,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
PreferredCore = cpuCore;
|
||||
AffinityMask |= 1UL << cpuCore;
|
||||
|
||||
SchedFlags = type == ThreadType.Dummy
|
||||
? ThreadSchedState.Running
|
||||
: ThreadSchedState.None;
|
||||
SchedFlags = ThreadSchedState.None;
|
||||
|
||||
ActiveCore = cpuCore;
|
||||
ObjSyncResult = KernelResult.ThreadNotStarted;
|
||||
|
@ -1055,6 +1053,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
// If the thread is not schedulable, we want to just run or pause
|
||||
// it directly as we don't care about priority or the core it is
|
||||
// running on in this case.
|
||||
|
||||
if (SchedFlags == ThreadSchedState.Running)
|
||||
{
|
||||
_schedulerWaitEvent.Set();
|
||||
|
|
|
@ -2,7 +2,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
|||
{
|
||||
enum ThreadType
|
||||
{
|
||||
Dummy,
|
||||
Kernel,
|
||||
Kernel2,
|
||||
User,
|
||||
|
|
|
@ -7,6 +7,7 @@ using LibHac.Tools.FsSystem;
|
|||
using LibHac.Tools.FsSystem.RomFs;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||
using Ryujinx.HLE.Loaders.Executables;
|
||||
using Ryujinx.HLE.Loaders.Mods;
|
||||
|
@ -17,6 +18,7 @@ using System.Collections.Specialized;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LazyFile = Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy.LazyFile;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Ryujinx.HLE.HOS
|
||||
|
@ -37,15 +39,19 @@ namespace Ryujinx.HLE.HOS
|
|||
private const string AmsNroPatchDir = "nro_patches";
|
||||
private const string AmsKipPatchDir = "kip_patches";
|
||||
|
||||
private static readonly ModMetadataJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
public readonly struct Mod<T> where T : FileSystemInfo
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly T Path;
|
||||
public readonly bool Enabled;
|
||||
|
||||
public Mod(string name, T path)
|
||||
public Mod(string name, T path, bool enabled)
|
||||
{
|
||||
Name = name;
|
||||
Path = path;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +73,7 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
// Title dependent mods
|
||||
// Application dependent mods
|
||||
public class ModCache
|
||||
{
|
||||
public List<Mod<FileInfo>> RomfsContainers { get; }
|
||||
|
@ -88,7 +94,7 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
// Title independent mods
|
||||
// Application independent mods
|
||||
private class PatchCache
|
||||
{
|
||||
public List<Mod<DirectoryInfo>> NsoPatches { get; }
|
||||
|
@ -107,7 +113,7 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<ulong, ModCache> _appMods; // key is TitleId
|
||||
private readonly Dictionary<ulong, ModCache> _appMods; // key is ApplicationId
|
||||
private PatchCache _patches;
|
||||
|
||||
private static readonly EnumerationOptions _dirEnumOptions;
|
||||
|
@ -153,26 +159,32 @@ namespace Ryujinx.HLE.HOS
|
|||
return modsDir.FullName;
|
||||
}
|
||||
|
||||
private static DirectoryInfo FindTitleDir(DirectoryInfo contentsDir, string titleId)
|
||||
=> contentsDir.EnumerateDirectories(titleId, _dirEnumOptions).FirstOrDefault();
|
||||
private static DirectoryInfo FindApplicationDir(DirectoryInfo contentsDir, string applicationId)
|
||||
=> contentsDir.EnumerateDirectories(applicationId, _dirEnumOptions).FirstOrDefault();
|
||||
|
||||
private static void AddModsFromDirectory(ModCache mods, DirectoryInfo dir, string titleId)
|
||||
private static void AddModsFromDirectory(ModCache mods, DirectoryInfo dir, ModMetadata modMetadata)
|
||||
{
|
||||
System.Text.StringBuilder types = new();
|
||||
|
||||
foreach (var modDir in dir.EnumerateDirectories())
|
||||
{
|
||||
types.Clear();
|
||||
Mod<DirectoryInfo> mod = new("", null);
|
||||
Mod<DirectoryInfo> mod = new("", null, true);
|
||||
|
||||
if (StrEquals(RomfsDir, modDir.Name))
|
||||
{
|
||||
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir));
|
||||
var modData = modMetadata.Mods.Find(x => modDir.FullName.Contains(x.Path));
|
||||
var enabled = modData?.Enabled ?? true;
|
||||
|
||||
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
|
||||
types.Append('R');
|
||||
}
|
||||
else if (StrEquals(ExefsDir, modDir.Name))
|
||||
{
|
||||
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir));
|
||||
var modData = modMetadata.Mods.Find(x => modDir.FullName.Contains(x.Path));
|
||||
var enabled = modData?.Enabled ?? true;
|
||||
|
||||
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
|
||||
types.Append('E');
|
||||
}
|
||||
else if (StrEquals(CheatDir, modDir.Name))
|
||||
|
@ -181,28 +193,28 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
else
|
||||
{
|
||||
AddModsFromDirectory(mods, modDir, titleId);
|
||||
AddModsFromDirectory(mods, modDir, modMetadata);
|
||||
}
|
||||
|
||||
if (types.Length > 0)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found mod '{mod.Name}' [{types}]");
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found {(mod.Enabled ? "enabled" : "disabled")} mod '{mod.Name}' [{types}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTitleDir(string modsBasePath, string titleId)
|
||||
public static string GetApplicationDir(string modsBasePath, string applicationId)
|
||||
{
|
||||
var contentsDir = new DirectoryInfo(Path.Combine(modsBasePath, AmsContentsDir));
|
||||
var titleModsPath = FindTitleDir(contentsDir, titleId);
|
||||
var applicationModsPath = FindApplicationDir(contentsDir, applicationId);
|
||||
|
||||
if (titleModsPath == null)
|
||||
if (applicationModsPath == null)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Creating mods directory for Title {titleId.ToUpper()}");
|
||||
titleModsPath = contentsDir.CreateSubdirectory(titleId);
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Creating mods directory for Application {applicationId.ToUpper()}");
|
||||
applicationModsPath = contentsDir.CreateSubdirectory(applicationId);
|
||||
}
|
||||
|
||||
return titleModsPath.FullName;
|
||||
return applicationModsPath.FullName;
|
||||
}
|
||||
|
||||
// Static Query Methods
|
||||
|
@ -238,47 +250,68 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
foreach (var modDir in patchDir.EnumerateDirectories())
|
||||
{
|
||||
patches.Add(new Mod<DirectoryInfo>(modDir.Name, modDir));
|
||||
patches.Add(new Mod<DirectoryInfo>(modDir.Name, modDir, true));
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found {type} patch '{modDir.Name}'");
|
||||
}
|
||||
}
|
||||
|
||||
private static void QueryTitleDir(ModCache mods, DirectoryInfo titleDir)
|
||||
private static void QueryApplicationDir(ModCache mods, DirectoryInfo applicationDir, ulong applicationId)
|
||||
{
|
||||
if (!titleDir.Exists)
|
||||
if (!applicationDir.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fsFile = new FileInfo(Path.Combine(titleDir.FullName, RomfsContainer));
|
||||
if (fsFile.Exists)
|
||||
string modJsonPath = Path.Combine(AppDataManager.GamesDirPath, applicationId.ToString("x16"), "mods.json");
|
||||
ModMetadata modMetadata = new();
|
||||
|
||||
if (File.Exists(modJsonPath))
|
||||
{
|
||||
mods.RomfsContainers.Add(new Mod<FileInfo>($"<{titleDir.Name} RomFs>", fsFile));
|
||||
try
|
||||
{
|
||||
modMetadata = JsonHelper.DeserializeFromFile(modJsonPath, _serializerContext.ModMetadata);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ModLoader, $"Failed to deserialize mod data for {applicationId:X16} at {modJsonPath}");
|
||||
}
|
||||
}
|
||||
|
||||
fsFile = new FileInfo(Path.Combine(titleDir.FullName, ExefsContainer));
|
||||
var fsFile = new FileInfo(Path.Combine(applicationDir.FullName, RomfsContainer));
|
||||
if (fsFile.Exists)
|
||||
{
|
||||
mods.ExefsContainers.Add(new Mod<FileInfo>($"<{titleDir.Name} ExeFs>", fsFile));
|
||||
var modData = modMetadata.Mods.Find(x => fsFile.FullName.Contains(x.Path));
|
||||
var enabled = modData == null || modData.Enabled;
|
||||
|
||||
mods.RomfsContainers.Add(new Mod<FileInfo>($"<{applicationDir.Name} RomFs>", fsFile, enabled));
|
||||
}
|
||||
|
||||
AddModsFromDirectory(mods, titleDir, titleDir.Name);
|
||||
fsFile = new FileInfo(Path.Combine(applicationDir.FullName, ExefsContainer));
|
||||
if (fsFile.Exists)
|
||||
{
|
||||
var modData = modMetadata.Mods.Find(x => fsFile.FullName.Contains(x.Path));
|
||||
var enabled = modData == null || modData.Enabled;
|
||||
|
||||
mods.ExefsContainers.Add(new Mod<FileInfo>($"<{applicationDir.Name} ExeFs>", fsFile, enabled));
|
||||
}
|
||||
|
||||
AddModsFromDirectory(mods, applicationDir, modMetadata);
|
||||
}
|
||||
|
||||
public static void QueryContentsDir(ModCache mods, DirectoryInfo contentsDir, ulong titleId)
|
||||
public static void QueryContentsDir(ModCache mods, DirectoryInfo contentsDir, ulong applicationId)
|
||||
{
|
||||
if (!contentsDir.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Searching mods for {((titleId & 0x1000) != 0 ? "DLC" : "Title")} {titleId:X16}");
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Searching mods for {((applicationId & 0x1000) != 0 ? "DLC" : "Application")} {applicationId:X16} in \"{contentsDir.FullName}\"");
|
||||
|
||||
var titleDir = FindTitleDir(contentsDir, $"{titleId:x16}");
|
||||
var applicationDir = FindApplicationDir(contentsDir, $"{applicationId:x16}");
|
||||
|
||||
if (titleDir != null)
|
||||
if (applicationDir != null)
|
||||
{
|
||||
QueryTitleDir(mods, titleDir);
|
||||
QueryApplicationDir(mods, applicationDir, applicationId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,9 +420,9 @@ namespace Ryujinx.HLE.HOS
|
|||
{
|
||||
if (IsContentsDir(searchDir.Name))
|
||||
{
|
||||
foreach ((ulong titleId, ModCache cache) in modCaches)
|
||||
foreach ((ulong applicationId, ModCache cache) in modCaches)
|
||||
{
|
||||
QueryContentsDir(cache, searchDir, titleId);
|
||||
QueryContentsDir(cache, searchDir, applicationId);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -410,7 +443,7 @@ namespace Ryujinx.HLE.HOS
|
|||
if (!searchDir.Exists)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ModLoader, $"Mod Search Dir '{searchDir.FullName}' doesn't exist");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryQuery(searchDir, patches, modCaches))
|
||||
|
@ -425,21 +458,21 @@ namespace Ryujinx.HLE.HOS
|
|||
patches.Initialized = true;
|
||||
}
|
||||
|
||||
public void CollectMods(IEnumerable<ulong> titles, params string[] searchDirPaths)
|
||||
public void CollectMods(IEnumerable<ulong> applications, params string[] searchDirPaths)
|
||||
{
|
||||
Clear();
|
||||
|
||||
foreach (ulong titleId in titles)
|
||||
foreach (ulong applicationId in applications)
|
||||
{
|
||||
_appMods[titleId] = new ModCache();
|
||||
_appMods[applicationId] = new ModCache();
|
||||
}
|
||||
|
||||
CollectMods(_appMods, _patches, searchDirPaths);
|
||||
}
|
||||
|
||||
internal IStorage ApplyRomFsMods(ulong titleId, IStorage baseStorage)
|
||||
internal IStorage ApplyRomFsMods(ulong applicationId, IStorage baseStorage)
|
||||
{
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.RomfsDirs.Count + mods.RomfsContainers.Count == 0)
|
||||
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.RomfsDirs.Count + mods.RomfsContainers.Count == 0)
|
||||
{
|
||||
return baseStorage;
|
||||
}
|
||||
|
@ -448,14 +481,19 @@ namespace Ryujinx.HLE.HOS
|
|||
var builder = new RomFsBuilder();
|
||||
int count = 0;
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Applying RomFS mods for Title {titleId:X16}");
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Applying RomFS mods for Application {applicationId:X16}");
|
||||
|
||||
// Prioritize loose files first
|
||||
foreach (var mod in mods.RomfsDirs)
|
||||
{
|
||||
if (!mod.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using (IFileSystem fs = new LocalFileSystem(mod.Path.FullName))
|
||||
{
|
||||
AddFiles(fs, mod.Name, fileSet, builder);
|
||||
AddFiles(fs, mod.Name, mod.Path.FullName, fileSet, builder);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
@ -463,10 +501,15 @@ namespace Ryujinx.HLE.HOS
|
|||
// Then files inside images
|
||||
foreach (var mod in mods.RomfsContainers)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found 'romfs.bin' for Title {titleId:X16}");
|
||||
if (!mod.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found 'romfs.bin' for Application {applicationId:X16}");
|
||||
using (IFileSystem fs = new RomFsFileSystem(mod.Path.OpenRead().AsStorage()))
|
||||
{
|
||||
AddFiles(fs, mod.Name, fileSet, builder);
|
||||
AddFiles(fs, mod.Name, mod.Path.FullName, fileSet, builder);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
@ -499,18 +542,18 @@ namespace Ryujinx.HLE.HOS
|
|||
return newStorage;
|
||||
}
|
||||
|
||||
private static void AddFiles(IFileSystem fs, string modName, ISet<string> fileSet, RomFsBuilder builder)
|
||||
private static void AddFiles(IFileSystem fs, string modName, string rootPath, ISet<string> fileSet, RomFsBuilder builder)
|
||||
{
|
||||
foreach (var entry in fs.EnumerateEntries()
|
||||
.AsParallel()
|
||||
.Where(f => f.Type == DirectoryEntryType.File)
|
||||
.OrderBy(f => f.FullPath, StringComparer.Ordinal))
|
||||
{
|
||||
using var file = new UniqueRef<IFile>();
|
||||
var file = new LazyFile(entry.FullPath, rootPath, fs);
|
||||
|
||||
fs.OpenFile(ref file.Ref, entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
|
||||
if (fileSet.Add(entry.FullPath))
|
||||
{
|
||||
builder.AddFile(entry.FullPath, file.Release());
|
||||
builder.AddFile(entry.FullPath, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -519,9 +562,9 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
internal bool ReplaceExefsPartition(ulong titleId, ref IFileSystem exefs)
|
||||
internal bool ReplaceExefsPartition(ulong applicationId, ref IFileSystem exefs)
|
||||
{
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsContainers.Count == 0)
|
||||
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.ExefsContainers.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -549,7 +592,7 @@ namespace Ryujinx.HLE.HOS
|
|||
public bool Modified => (Stubs.Data | Replaces.Data) != 0;
|
||||
}
|
||||
|
||||
internal ModLoadResult ApplyExefsMods(ulong titleId, NsoExecutable[] nsos)
|
||||
internal ModLoadResult ApplyExefsMods(ulong applicationId, NsoExecutable[] nsos)
|
||||
{
|
||||
ModLoadResult modLoadResult = new()
|
||||
{
|
||||
|
@ -557,7 +600,7 @@ namespace Ryujinx.HLE.HOS
|
|||
Replaces = new BitVector32(),
|
||||
};
|
||||
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsDirs.Count == 0)
|
||||
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.ExefsDirs.Count == 0)
|
||||
{
|
||||
return modLoadResult;
|
||||
}
|
||||
|
@ -571,6 +614,11 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
foreach (var mod in exeMods)
|
||||
{
|
||||
if (!mod.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ProcessConst.ExeFsPrefixes.Length; ++i)
|
||||
{
|
||||
var nsoName = ProcessConst.ExeFsPrefixes[i];
|
||||
|
@ -637,11 +685,11 @@ namespace Ryujinx.HLE.HOS
|
|||
ApplyProgramPatches(nroPatches, 0, nro);
|
||||
}
|
||||
|
||||
internal bool ApplyNsoPatches(ulong titleId, params IExecutable[] programs)
|
||||
internal bool ApplyNsoPatches(ulong applicationId, params IExecutable[] programs)
|
||||
{
|
||||
IEnumerable<Mod<DirectoryInfo>> nsoMods = _patches.NsoPatches;
|
||||
|
||||
if (_appMods.TryGetValue(titleId, out ModCache mods))
|
||||
if (_appMods.TryGetValue(applicationId, out ModCache mods))
|
||||
{
|
||||
nsoMods = nsoMods.Concat(mods.ExefsDirs);
|
||||
}
|
||||
|
@ -651,7 +699,7 @@ namespace Ryujinx.HLE.HOS
|
|||
return ApplyProgramPatches(nsoMods, 0x100, programs);
|
||||
}
|
||||
|
||||
internal void LoadCheats(ulong titleId, ProcessTamperInfo tamperInfo, TamperMachine tamperMachine)
|
||||
internal void LoadCheats(ulong applicationId, ProcessTamperInfo tamperInfo, TamperMachine tamperMachine)
|
||||
{
|
||||
if (tamperInfo?.BuildIds == null || tamperInfo.CodeAddresses == null)
|
||||
{
|
||||
|
@ -660,9 +708,9 @@ namespace Ryujinx.HLE.HOS
|
|||
return;
|
||||
}
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Build ids found for title {titleId:X16}:\n {String.Join("\n ", tamperInfo.BuildIds)}");
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Build ids found for application {applicationId:X16}:\n {String.Join("\n ", tamperInfo.BuildIds)}");
|
||||
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.Cheats.Count == 0)
|
||||
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.Cheats.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -687,12 +735,12 @@ namespace Ryujinx.HLE.HOS
|
|||
tamperMachine.InstallAtmosphereCheat(cheat.Name, cheatId, cheat.Instructions, tamperInfo, exeAddress);
|
||||
}
|
||||
|
||||
EnableCheats(titleId, tamperMachine);
|
||||
EnableCheats(applicationId, tamperMachine);
|
||||
}
|
||||
|
||||
internal static void EnableCheats(ulong titleId, TamperMachine tamperMachine)
|
||||
internal static void EnableCheats(ulong applicationId, TamperMachine tamperMachine)
|
||||
{
|
||||
var contentDirectory = FindTitleDir(new DirectoryInfo(Path.Combine(GetModsBasePath(), AmsContentsDir)), $"{titleId:x16}");
|
||||
var contentDirectory = FindApplicationDir(new DirectoryInfo(Path.Combine(GetModsBasePath(), AmsContentsDir)), $"{applicationId:x16}");
|
||||
string enabledCheatsPath = Path.Combine(contentDirectory.FullName, CheatDir, "enabled.txt");
|
||||
|
||||
if (File.Exists(enabledCheatsPath))
|
||||
|
@ -724,6 +772,11 @@ namespace Ryujinx.HLE.HOS
|
|||
// Collect patches
|
||||
foreach (var mod in mods)
|
||||
{
|
||||
if (!mod.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var patchDir = mod.Path;
|
||||
foreach (var patchFile in patchDir.EnumerateFiles())
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ using LibHac.Fs;
|
|||
using LibHac.Fs.Shim;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Horizon.Sdk.Account;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
@ -11,7 +12,7 @@ using System.Linq;
|
|||
|
||||
namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
||||
{
|
||||
public class AccountManager
|
||||
public class AccountManager : IEmulatorAccountManager
|
||||
{
|
||||
public static readonly UserId DefaultUserId = new("00000000000000010000000000000000");
|
||||
|
||||
|
@ -106,6 +107,11 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
_accountSaveDataManager.Save(_profiles);
|
||||
}
|
||||
|
||||
public void OpenUserOnlinePlay(Uid userId)
|
||||
{
|
||||
OpenUserOnlinePlay(new UserId((long)userId.Low, (long)userId.High));
|
||||
}
|
||||
|
||||
public void OpenUserOnlinePlay(UserId userId)
|
||||
{
|
||||
if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
|
||||
|
@ -127,6 +133,11 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|||
_accountSaveDataManager.Save(_profiles);
|
||||
}
|
||||
|
||||
public void CloseUserOnlinePlay(Uid userId)
|
||||
{
|
||||
CloseUserOnlinePlay(new UserId((long)userId.Low, (long)userId.High));
|
||||
}
|
||||
|
||||
public void CloseUserOnlinePlay(UserId userId)
|
||||
{
|
||||
if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
using Microsoft.IdentityModel.JsonWebTokens;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -20,6 +22,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
|
|||
private readonly UserId _userId;
|
||||
#pragma warning restore IDE0052
|
||||
|
||||
private byte[] _cachedTokenData;
|
||||
private DateTime _cachedTokenExpiry;
|
||||
|
||||
public ManagerServer(UserId userId)
|
||||
{
|
||||
_userId = userId;
|
||||
|
@ -37,11 +42,6 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
|
|||
|
||||
credentials.Key.KeyId = parameters.ToString();
|
||||
|
||||
var header = new JwtHeader(credentials)
|
||||
{
|
||||
{ "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" },
|
||||
};
|
||||
|
||||
byte[] rawUserId = new byte[0x10];
|
||||
RandomNumberGenerator.Fill(rawUserId);
|
||||
|
||||
|
@ -51,23 +51,25 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
|
|||
byte[] deviceAccountId = new byte[0x10];
|
||||
RandomNumberGenerator.Fill(deviceId);
|
||||
|
||||
var payload = new JwtPayload
|
||||
var descriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
{ "sub", Convert.ToHexString(rawUserId).ToLower() },
|
||||
{ "aud", "ed9e2f05d286f7b8" },
|
||||
{ "di", Convert.ToHexString(deviceId).ToLower() },
|
||||
{ "sn", "XAW10000000000" },
|
||||
{ "bs:did", Convert.ToHexString(deviceAccountId).ToLower() },
|
||||
{ "iss", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com" },
|
||||
{ "typ", "id_token" },
|
||||
{ "iat", DateTimeOffset.UtcNow.ToUnixTimeSeconds() },
|
||||
{ "jti", Guid.NewGuid().ToString() },
|
||||
{ "exp", (DateTimeOffset.UtcNow + TimeSpan.FromHours(3)).ToUnixTimeSeconds() },
|
||||
Subject = new GenericIdentity(Convert.ToHexString(rawUserId).ToLower()),
|
||||
SigningCredentials = credentials,
|
||||
Audience = "ed9e2f05d286f7b8",
|
||||
Issuer = "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com",
|
||||
TokenType = "id_token",
|
||||
IssuedAt = DateTime.UtcNow,
|
||||
Expires = DateTime.UtcNow + TimeSpan.FromHours(3),
|
||||
Claims = new Dictionary<string, object>
|
||||
{
|
||||
{ "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" },
|
||||
{ "di", Convert.ToHexString(deviceId).ToLower() },
|
||||
{ "sn", "XAW10000000000" },
|
||||
{ "bs:did", Convert.ToHexString(deviceAccountId).ToLower() }
|
||||
}
|
||||
};
|
||||
|
||||
JwtSecurityToken securityToken = new(header, payload);
|
||||
|
||||
return new JwtSecurityTokenHandler().WriteToken(securityToken);
|
||||
return new JsonWebTokenHandler().CreateToken(descriptor);
|
||||
}
|
||||
|
||||
public ResultCode CheckAvailability(ServiceCtx context)
|
||||
|
@ -145,7 +147,13 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
|
|||
}
|
||||
*/
|
||||
|
||||
byte[] tokenData = Encoding.ASCII.GetBytes(GenerateIdToken());
|
||||
if (_cachedTokenData == null || DateTime.UtcNow > _cachedTokenExpiry)
|
||||
{
|
||||
_cachedTokenExpiry = DateTime.UtcNow + TimeSpan.FromHours(3);
|
||||
_cachedTokenData = Encoding.ASCII.GetBytes(GenerateIdToken());
|
||||
}
|
||||
|
||||
byte[] tokenData = _cachedTokenData;
|
||||
|
||||
context.Memory.Write(bufferPosition, tokenData);
|
||||
context.ResponseData.Write(tokenData.Length);
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
|
|||
|
||||
if (titleId == 0)
|
||||
{
|
||||
context.Device.UiHandler.ExecuteProgram(context.Device, ProgramSpecifyKind.RestartProgram, titleId);
|
||||
context.Device.UIHandler.ExecuteProgram(context.Device, ProgramSpecifyKind.RestartProgram, titleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -524,7 +524,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati
|
|||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAm, new { kind, value });
|
||||
|
||||
context.Device.UiHandler.ExecuteProgram(context.Device, kind, value);
|
||||
context.Device.UIHandler.ExecuteProgram(context.Device, kind, value);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Arp
|
||||
{
|
||||
[Service("arp:r")]
|
||||
class IReader : IpcService
|
||||
{
|
||||
public IReader(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Arp
|
||||
{
|
||||
[Service("arp:w")]
|
||||
class IWriter : IpcService
|
||||
{
|
||||
public IWriter(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Audio.Input;
|
||||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn
|
||||
{
|
||||
class AudioIn : IAudioIn
|
||||
{
|
||||
private readonly AudioInputSystem _system;
|
||||
private readonly uint _processHandle;
|
||||
private readonly KernelContext _kernelContext;
|
||||
|
||||
public AudioIn(AudioInputSystem system, KernelContext kernelContext, uint processHandle)
|
||||
{
|
||||
_system = system;
|
||||
_kernelContext = kernelContext;
|
||||
_processHandle = processHandle;
|
||||
}
|
||||
|
||||
public ResultCode AppendBuffer(ulong bufferTag, ref AudioUserBuffer buffer)
|
||||
{
|
||||
return (ResultCode)_system.AppendBuffer(bufferTag, ref buffer);
|
||||
}
|
||||
|
||||
public ResultCode AppendUacBuffer(ulong bufferTag, ref AudioUserBuffer buffer, uint handle)
|
||||
{
|
||||
return (ResultCode)_system.AppendUacBuffer(bufferTag, ref buffer, handle);
|
||||
}
|
||||
|
||||
public bool ContainsBuffer(ulong bufferTag)
|
||||
{
|
||||
return _system.ContainsBuffer(bufferTag);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_system.Dispose();
|
||||
|
||||
_kernelContext.Syscall.CloseHandle((int)_processHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlushBuffers()
|
||||
{
|
||||
return _system.FlushBuffers();
|
||||
}
|
||||
|
||||
public uint GetBufferCount()
|
||||
{
|
||||
return _system.GetBufferCount();
|
||||
}
|
||||
|
||||
public ResultCode GetReleasedBuffers(Span<ulong> releasedBuffers, out uint releasedCount)
|
||||
{
|
||||
return (ResultCode)_system.GetReleasedBuffers(releasedBuffers, out releasedCount);
|
||||
}
|
||||
|
||||
public AudioDeviceState GetState()
|
||||
{
|
||||
return _system.GetState();
|
||||
}
|
||||
|
||||
public float GetVolume()
|
||||
{
|
||||
return _system.GetVolume();
|
||||
}
|
||||
|
||||
public KEvent RegisterBufferEvent()
|
||||
{
|
||||
IWritableEvent outEvent = _system.RegisterBufferEvent();
|
||||
|
||||
if (outEvent is AudioKernelEvent kernelEvent)
|
||||
{
|
||||
return kernelEvent.Event;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
_system.SetVolume(volume);
|
||||
}
|
||||
|
||||
public ResultCode Start()
|
||||
{
|
||||
return (ResultCode)_system.Start();
|
||||
}
|
||||
|
||||
public ResultCode Stop()
|
||||
{
|
||||
return (ResultCode)_system.Stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn
|
||||
{
|
||||
class AudioInServer : DisposableIpcService
|
||||
{
|
||||
private readonly IAudioIn _impl;
|
||||
|
||||
public AudioInServer(IAudioIn impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// GetAudioInState() -> u32 state
|
||||
public ResultCode GetAudioInState(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write((uint)_impl.GetState());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// Start()
|
||||
public ResultCode Start(ServiceCtx context)
|
||||
{
|
||||
return _impl.Start();
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// Stop()
|
||||
public ResultCode StopAudioIn(ServiceCtx context)
|
||||
{
|
||||
return _impl.Stop();
|
||||
}
|
||||
|
||||
[CommandCmif(3)]
|
||||
// AppendAudioInBuffer(u64 tag, buffer<nn::audio::AudioInBuffer, 5>)
|
||||
public ResultCode AppendAudioInBuffer(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.SendBuff[0].Position;
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendBuffer(bufferTag, ref data);
|
||||
}
|
||||
|
||||
[CommandCmif(4)]
|
||||
// RegisterBufferEvent() -> handle<copy>
|
||||
public ResultCode RegisterBufferEvent(ServiceCtx context)
|
||||
{
|
||||
KEvent bufferEvent = _impl.RegisterBufferEvent();
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(5)]
|
||||
// GetReleasedAudioInBuffers() -> (u32 count, buffer<u64, 6> tags)
|
||||
public ResultCode GetReleasedAudioInBuffers(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
using WritableRegion outputRegion = context.Memory.GetWritableRegion((ulong)position, (int)size);
|
||||
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
||||
|
||||
context.ResponseData.Write(releasedCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(6)]
|
||||
// ContainsAudioInBuffer(u64 tag) -> b8
|
||||
public ResultCode ContainsAudioInBuffer(ServiceCtx context)
|
||||
{
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
context.ResponseData.Write(_impl.ContainsBuffer(bufferTag));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(7)] // 3.0.0+
|
||||
// AppendUacInBuffer(u64 tag, handle<copy, unknown>, buffer<nn::audio::AudioInBuffer, 5>)
|
||||
public ResultCode AppendUacInBuffer(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.SendBuff[0].Position;
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
uint handle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendUacBuffer(bufferTag, ref data, handle);
|
||||
}
|
||||
|
||||
[CommandCmif(8)] // 3.0.0+
|
||||
// AppendAudioInBufferAuto(u64 tag, buffer<nn::audio::AudioInBuffer, 0x21>)
|
||||
public ResultCode AppendAudioInBufferAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, _) = context.Request.GetBufferType0x21();
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendBuffer(bufferTag, ref data);
|
||||
}
|
||||
|
||||
[CommandCmif(9)] // 3.0.0+
|
||||
// GetReleasedAudioInBuffersAuto() -> (u32 count, buffer<u64, 0x22> tags)
|
||||
public ResultCode GetReleasedAudioInBuffersAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size);
|
||||
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
||||
|
||||
context.ResponseData.Write(releasedCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(10)] // 3.0.0+
|
||||
// AppendUacInBufferAuto(u64 tag, handle<copy, event>, buffer<nn::audio::AudioInBuffer, 0x21>)
|
||||
public ResultCode AppendUacInBufferAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, _) = context.Request.GetBufferType0x21();
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
uint handle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendUacBuffer(bufferTag, ref data, handle);
|
||||
}
|
||||
|
||||
[CommandCmif(11)] // 4.0.0+
|
||||
// GetAudioInBufferCount() -> u32
|
||||
public ResultCode GetAudioInBufferCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetBufferCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(12)] // 4.0.0+
|
||||
// SetAudioInVolume(s32)
|
||||
public ResultCode SetAudioInVolume(ServiceCtx context)
|
||||
{
|
||||
float volume = context.RequestData.ReadSingle();
|
||||
|
||||
_impl.SetVolume(volume);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(13)] // 4.0.0+
|
||||
// GetAudioInVolume() -> s32
|
||||
public ResultCode GetAudioInVolume(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetVolume());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(14)] // 6.0.0+
|
||||
// FlushAudioInBuffers() -> b8
|
||||
public ResultCode FlushAudioInBuffers(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.FlushBuffers());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
_impl.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioIn
|
||||
{
|
||||
interface IAudioIn : IDisposable
|
||||
{
|
||||
AudioDeviceState GetState();
|
||||
|
||||
ResultCode Start();
|
||||
|
||||
ResultCode Stop();
|
||||
|
||||
ResultCode AppendBuffer(ulong bufferTag, ref AudioUserBuffer buffer);
|
||||
|
||||
// NOTE: This is broken by design... not quite sure what it's used for (if anything in production).
|
||||
ResultCode AppendUacBuffer(ulong bufferTag, ref AudioUserBuffer buffer, uint handle);
|
||||
|
||||
KEvent RegisterBufferEvent();
|
||||
|
||||
ResultCode GetReleasedBuffers(Span<ulong> releasedBuffers, out uint releasedCount);
|
||||
|
||||
bool ContainsBuffer(ulong bufferTag);
|
||||
|
||||
uint GetBufferCount();
|
||||
|
||||
bool FlushBuffers();
|
||||
|
||||
void SetVolume(float volume);
|
||||
|
||||
float GetVolume();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Audio.Input;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioIn;
|
||||
using AudioInManagerImpl = Ryujinx.Audio.Input.AudioInputManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
class AudioInManager : IAudioInManager
|
||||
{
|
||||
private readonly AudioInManagerImpl _impl;
|
||||
|
||||
public AudioInManager(AudioInManagerImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public string[] ListAudioIns(bool filtered)
|
||||
{
|
||||
return _impl.ListAudioIns(filtered);
|
||||
}
|
||||
|
||||
public ResultCode OpenAudioIn(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle)
|
||||
{
|
||||
var memoryManager = context.Process.HandleTable.GetKProcess((int)processHandle).CpuMemory;
|
||||
|
||||
ResultCode result = (ResultCode)_impl.OpenAudioIn(out outputDeviceName, out outputConfiguration, out AudioInputSystem inSystem, memoryManager, inputDeviceName, SampleFormat.PcmInt16, ref parameter, appletResourceUserId, processHandle);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
obj = new AudioIn.AudioIn(inSystem, context.Device.System.KernelContext, processHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,243 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioIn;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audin:u")]
|
||||
class AudioInManagerServer : IpcService
|
||||
{
|
||||
private const int AudioInNameSize = 0x100;
|
||||
|
||||
private readonly IAudioInManager _impl;
|
||||
|
||||
public AudioInManagerServer(ServiceCtx context) : this(context, new AudioInManager(context.Device.System.AudioInputManager)) { }
|
||||
|
||||
public AudioInManagerServer(ServiceCtx context, IAudioInManager impl) : base(context.Device.System.AudOutServer)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// ListAudioIns() -> (u32, buffer<bytes, 6>)
|
||||
public ResultCode ListAudioIns(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioIns(false);
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioInNameSize - buffer.Length);
|
||||
|
||||
position += AudioInNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// OpenAudioIn(AudioInInputConfiguration input_config, nn::applet::AppletResourceUserId, pid, handle<copy, process>, buffer<bytes, 5> name)
|
||||
// -> (u32 sample_rate, u32 channel_count, u32 pcm_format, u32, object<nn::audio::detail::IAudioIn>, buffer<bytes, 6> name)
|
||||
public ResultCode OpenAudioIn(ServiceCtx context)
|
||||
{
|
||||
AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct<AudioInputConfiguration>();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
ulong deviceNameInputPosition = context.Request.SendBuff[0].Position;
|
||||
ulong deviceNameInputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size;
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
string inputDeviceName = MemoryHelper.ReadAsciiString(context.Memory, deviceNameInputPosition, (long)deviceNameInputSize);
|
||||
|
||||
ResultCode resultCode = _impl.OpenAudioIn(context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, inputDeviceName, ref inputConfiguration, appletResourceUserId, processHandle);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.WriteStruct(outputConfiguration);
|
||||
|
||||
byte[] outputDeviceNameRaw = Encoding.ASCII.GetBytes(outputDeviceName);
|
||||
|
||||
context.Memory.Write(deviceNameOutputPosition, outputDeviceNameRaw);
|
||||
MemoryHelper.FillWithZeros(context.Memory, deviceNameOutputPosition + (ulong)outputDeviceNameRaw.Length, AudioInNameSize - outputDeviceNameRaw.Length);
|
||||
|
||||
MakeObject(context, new AudioInServer(obj));
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
[CommandCmif(2)] // 3.0.0+
|
||||
// ListAudioInsAuto() -> (u32, buffer<bytes, 0x22>)
|
||||
public ResultCode ListAudioInsAuto(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioIns(false);
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioInNameSize - buffer.Length);
|
||||
|
||||
position += AudioInNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(3)] // 3.0.0+
|
||||
// OpenAudioInAuto(AudioInInputConfiguration input_config, nn::applet::AppletResourceUserId, pid, handle<copy, process>, buffer<bytes, 0x21>)
|
||||
// -> (u32 sample_rate, u32 channel_count, u32 pcm_format, u32, object<nn::audio::detail::IAudioIn>, buffer<bytes, 0x22> name)
|
||||
public ResultCode OpenAudioInAuto(ServiceCtx context)
|
||||
{
|
||||
AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct<AudioInputConfiguration>();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
(ulong deviceNameInputPosition, ulong deviceNameInputSize) = context.Request.GetBufferType0x21();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong deviceNameOutputPosition, ulong deviceNameOutputSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
string inputDeviceName = MemoryHelper.ReadAsciiString(context.Memory, deviceNameInputPosition, (long)deviceNameInputSize);
|
||||
|
||||
ResultCode resultCode = _impl.OpenAudioIn(context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, inputDeviceName, ref inputConfiguration, appletResourceUserId, processHandle);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.WriteStruct(outputConfiguration);
|
||||
|
||||
byte[] outputDeviceNameRaw = Encoding.ASCII.GetBytes(outputDeviceName);
|
||||
|
||||
context.Memory.Write(deviceNameOutputPosition, outputDeviceNameRaw);
|
||||
MemoryHelper.FillWithZeros(context.Memory, deviceNameOutputPosition + (ulong)outputDeviceNameRaw.Length, AudioInNameSize - outputDeviceNameRaw.Length);
|
||||
|
||||
MakeObject(context, new AudioInServer(obj));
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
[CommandCmif(4)] // 3.0.0+
|
||||
// ListAudioInsAutoFiltered() -> (u32, buffer<bytes, 0x22>)
|
||||
public ResultCode ListAudioInsAutoFiltered(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioIns(true);
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioInNameSize - buffer.Length);
|
||||
|
||||
position += AudioInNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(5)] // 5.0.0+
|
||||
// OpenAudioInProtocolSpecified(b64 protocol_specified_related, AudioInInputConfiguration input_config, nn::applet::AppletResourceUserId, pid, handle<copy, process>, buffer<bytes, 5> name)
|
||||
// -> (u32 sample_rate, u32 channel_count, u32 pcm_format, u32, object<nn::audio::detail::IAudioIn>, buffer<bytes, 6> name)
|
||||
public ResultCode OpenAudioInProtocolSpecified(ServiceCtx context)
|
||||
{
|
||||
// NOTE: We always assume that only the default device will be plugged (we never report any USB Audio Class type devices).
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
bool protocolSpecifiedRelated = context.RequestData.ReadUInt64() == 1;
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct<AudioInputConfiguration>();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
ulong deviceNameInputPosition = context.Request.SendBuff[0].Position;
|
||||
ulong deviceNameInputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
#pragma warning disable IDE0051, IDE0059 // Remove unused private member
|
||||
ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size;
|
||||
#pragma warning restore IDE0051, IDE0059
|
||||
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
string inputDeviceName = MemoryHelper.ReadAsciiString(context.Memory, deviceNameInputPosition, (long)deviceNameInputSize);
|
||||
|
||||
ResultCode resultCode = _impl.OpenAudioIn(context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, inputDeviceName, ref inputConfiguration, appletResourceUserId, processHandle);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.WriteStruct(outputConfiguration);
|
||||
|
||||
byte[] outputDeviceNameRaw = Encoding.ASCII.GetBytes(outputDeviceName);
|
||||
|
||||
context.Memory.Write(deviceNameOutputPosition, outputDeviceNameRaw);
|
||||
MemoryHelper.FillWithZeros(context.Memory, deviceNameOutputPosition + (ulong)outputDeviceNameRaw.Length, AudioInNameSize - outputDeviceNameRaw.Length);
|
||||
|
||||
MakeObject(context, new AudioInServer(obj));
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.Audio.Output;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut
|
||||
{
|
||||
class AudioOut : IAudioOut
|
||||
{
|
||||
private readonly AudioOutputSystem _system;
|
||||
private readonly uint _processHandle;
|
||||
private readonly KernelContext _kernelContext;
|
||||
|
||||
public AudioOut(AudioOutputSystem system, KernelContext kernelContext, uint processHandle)
|
||||
{
|
||||
_system = system;
|
||||
_kernelContext = kernelContext;
|
||||
_processHandle = processHandle;
|
||||
}
|
||||
|
||||
public ResultCode AppendBuffer(ulong bufferTag, ref AudioUserBuffer buffer)
|
||||
{
|
||||
return (ResultCode)_system.AppendBuffer(bufferTag, ref buffer);
|
||||
}
|
||||
|
||||
public bool ContainsBuffer(ulong bufferTag)
|
||||
{
|
||||
return _system.ContainsBuffer(bufferTag);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_system.Dispose();
|
||||
|
||||
_kernelContext.Syscall.CloseHandle((int)_processHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlushBuffers()
|
||||
{
|
||||
return _system.FlushBuffers();
|
||||
}
|
||||
|
||||
public uint GetBufferCount()
|
||||
{
|
||||
return _system.GetBufferCount();
|
||||
}
|
||||
|
||||
public ulong GetPlayedSampleCount()
|
||||
{
|
||||
return _system.GetPlayedSampleCount();
|
||||
}
|
||||
|
||||
public ResultCode GetReleasedBuffers(Span<ulong> releasedBuffers, out uint releasedCount)
|
||||
{
|
||||
return (ResultCode)_system.GetReleasedBuffer(releasedBuffers, out releasedCount);
|
||||
}
|
||||
|
||||
public AudioDeviceState GetState()
|
||||
{
|
||||
return _system.GetState();
|
||||
}
|
||||
|
||||
public float GetVolume()
|
||||
{
|
||||
return _system.GetVolume();
|
||||
}
|
||||
|
||||
public KEvent RegisterBufferEvent()
|
||||
{
|
||||
IWritableEvent outEvent = _system.RegisterBufferEvent();
|
||||
|
||||
if (outEvent is AudioKernelEvent kernelEvent)
|
||||
{
|
||||
return kernelEvent.Event;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
_system.SetVolume(volume);
|
||||
}
|
||||
|
||||
public ResultCode Start()
|
||||
{
|
||||
return (ResultCode)_system.Start();
|
||||
}
|
||||
|
||||
public ResultCode Stop()
|
||||
{
|
||||
return (ResultCode)_system.Stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,181 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut
|
||||
{
|
||||
class AudioOutServer : DisposableIpcService
|
||||
{
|
||||
private readonly IAudioOut _impl;
|
||||
|
||||
public AudioOutServer(IAudioOut impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// GetAudioOutState() -> u32 state
|
||||
public ResultCode GetAudioOutState(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write((uint)_impl.GetState());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// Start()
|
||||
public ResultCode Start(ServiceCtx context)
|
||||
{
|
||||
return _impl.Start();
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// Stop()
|
||||
public ResultCode Stop(ServiceCtx context)
|
||||
{
|
||||
return _impl.Stop();
|
||||
}
|
||||
|
||||
[CommandCmif(3)]
|
||||
// AppendAudioOutBuffer(u64 bufferTag, buffer<nn::audio::AudioOutBuffer, 5> buffer)
|
||||
public ResultCode AppendAudioOutBuffer(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.SendBuff[0].Position;
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendBuffer(bufferTag, ref data);
|
||||
}
|
||||
|
||||
[CommandCmif(4)]
|
||||
// RegisterBufferEvent() -> handle<copy>
|
||||
public ResultCode RegisterBufferEvent(ServiceCtx context)
|
||||
{
|
||||
KEvent bufferEvent = _impl.RegisterBufferEvent();
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(bufferEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(5)]
|
||||
// GetReleasedAudioOutBuffers() -> (u32 count, buffer<u64, 6> tags)
|
||||
public ResultCode GetReleasedAudioOutBuffers(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size);
|
||||
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
||||
|
||||
context.ResponseData.Write(releasedCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(6)]
|
||||
// ContainsAudioOutBuffer(u64 tag) -> b8
|
||||
public ResultCode ContainsAudioOutBuffer(ServiceCtx context)
|
||||
{
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
context.ResponseData.Write(_impl.ContainsBuffer(bufferTag));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(7)] // 3.0.0+
|
||||
// AppendAudioOutBufferAuto(u64 tag, buffer<nn::audio::AudioOutBuffer, 0x21>)
|
||||
public ResultCode AppendAudioOutBufferAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, _) = context.Request.GetBufferType0x21();
|
||||
|
||||
ulong bufferTag = context.RequestData.ReadUInt64();
|
||||
|
||||
AudioUserBuffer data = MemoryHelper.Read<AudioUserBuffer>(context.Memory, position);
|
||||
|
||||
return _impl.AppendBuffer(bufferTag, ref data);
|
||||
}
|
||||
|
||||
[CommandCmif(8)] // 3.0.0+
|
||||
// GetReleasedAudioOutBuffersAuto() -> (u32 count, buffer<u64, 0x22> tags)
|
||||
public ResultCode GetReleasedAudioOutBuffersAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
using WritableRegion outputRegion = context.Memory.GetWritableRegion(position, (int)size);
|
||||
ResultCode result = _impl.GetReleasedBuffers(MemoryMarshal.Cast<byte, ulong>(outputRegion.Memory.Span), out uint releasedCount);
|
||||
|
||||
context.ResponseData.Write(releasedCount);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(9)] // 4.0.0+
|
||||
// GetAudioOutBufferCount() -> u32
|
||||
public ResultCode GetAudioOutBufferCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetBufferCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10)] // 4.0.0+
|
||||
// GetAudioOutPlayedSampleCount() -> u64
|
||||
public ResultCode GetAudioOutPlayedSampleCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetPlayedSampleCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(11)] // 4.0.0+
|
||||
// FlushAudioOutBuffers() -> b8
|
||||
public ResultCode FlushAudioOutBuffers(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.FlushBuffers());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(12)] // 6.0.0+
|
||||
// SetAudioOutVolume(s32)
|
||||
public ResultCode SetAudioOutVolume(ServiceCtx context)
|
||||
{
|
||||
float volume = context.RequestData.ReadSingle();
|
||||
|
||||
_impl.SetVolume(volume);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(13)] // 6.0.0+
|
||||
// GetAudioOutVolume() -> s32
|
||||
public ResultCode GetAudioOutVolume(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetVolume());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
_impl.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioOut
|
||||
{
|
||||
interface IAudioOut : IDisposable
|
||||
{
|
||||
AudioDeviceState GetState();
|
||||
|
||||
ResultCode Start();
|
||||
|
||||
ResultCode Stop();
|
||||
|
||||
ResultCode AppendBuffer(ulong bufferTag, ref AudioUserBuffer buffer);
|
||||
|
||||
KEvent RegisterBufferEvent();
|
||||
|
||||
ResultCode GetReleasedBuffers(Span<ulong> releasedBuffers, out uint releasedCount);
|
||||
|
||||
bool ContainsBuffer(ulong bufferTag);
|
||||
|
||||
uint GetBufferCount();
|
||||
|
||||
ulong GetPlayedSampleCount();
|
||||
|
||||
bool FlushBuffers();
|
||||
|
||||
void SetVolume(float volume);
|
||||
|
||||
float GetVolume();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Audio.Output;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioOut;
|
||||
using AudioOutManagerImpl = Ryujinx.Audio.Output.AudioOutputManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
class AudioOutManager : IAudioOutManager
|
||||
{
|
||||
private readonly AudioOutManagerImpl _impl;
|
||||
|
||||
public AudioOutManager(AudioOutManagerImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public string[] ListAudioOuts()
|
||||
{
|
||||
return _impl.ListAudioOuts();
|
||||
}
|
||||
|
||||
public ResultCode OpenAudioOut(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioOut obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle, float volume)
|
||||
{
|
||||
var memoryManager = context.Process.HandleTable.GetKProcess((int)processHandle).CpuMemory;
|
||||
|
||||
ResultCode result = (ResultCode)_impl.OpenAudioOut(out outputDeviceName, out outputConfiguration, out AudioOutputSystem outSystem, memoryManager, inputDeviceName, SampleFormat.PcmInt16, ref parameter, appletResourceUserId, processHandle, volume);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
obj = new AudioOut.AudioOut(outSystem, context.Device.System.KernelContext, processHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioOut;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audout:u")]
|
||||
class AudioOutManagerServer : IpcService
|
||||
{
|
||||
private const int AudioOutNameSize = 0x100;
|
||||
|
||||
private readonly IAudioOutManager _impl;
|
||||
|
||||
public AudioOutManagerServer(ServiceCtx context) : this(context, new AudioOutManager(context.Device.System.AudioOutputManager)) { }
|
||||
|
||||
public AudioOutManagerServer(ServiceCtx context, IAudioOutManager impl) : base(context.Device.System.AudOutServer)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// ListAudioOuts() -> (u32, buffer<bytes, 6>)
|
||||
public ResultCode ListAudioOuts(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioOuts();
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioOutNameSize - buffer.Length);
|
||||
|
||||
position += AudioOutNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// OpenAudioOut(AudioOutInputConfiguration input_config, nn::applet::AppletResourceUserId, pid, handle<copy, process> process_handle, buffer<bytes, 5> name_in)
|
||||
// -> (AudioOutInputConfiguration output_config, object<nn::audio::detail::IAudioOut>, buffer<bytes, 6> name_out)
|
||||
public ResultCode OpenAudioOut(ServiceCtx context)
|
||||
{
|
||||
AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct<AudioInputConfiguration>();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
ulong deviceNameInputPosition = context.Request.SendBuff[0].Position;
|
||||
ulong deviceNameInputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
ulong deviceNameOutputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong deviceNameOutputSize = context.Request.ReceiveBuff[0].Size;
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
string inputDeviceName = MemoryHelper.ReadAsciiString(context.Memory, deviceNameInputPosition, (long)deviceNameInputSize);
|
||||
|
||||
ResultCode resultCode = _impl.OpenAudioOut(context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioOut obj, inputDeviceName, ref inputConfiguration, appletResourceUserId, processHandle, context.Device.Configuration.AudioVolume);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.WriteStruct(outputConfiguration);
|
||||
|
||||
byte[] outputDeviceNameRaw = Encoding.ASCII.GetBytes(outputDeviceName);
|
||||
|
||||
context.Memory.Write(deviceNameOutputPosition, outputDeviceNameRaw);
|
||||
MemoryHelper.FillWithZeros(context.Memory, deviceNameOutputPosition + (ulong)outputDeviceNameRaw.Length, AudioOutNameSize - outputDeviceNameRaw.Length);
|
||||
|
||||
MakeObject(context, new AudioOutServer(obj));
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
[CommandCmif(2)] // 3.0.0+
|
||||
// ListAudioOutsAuto() -> (u32, buffer<bytes, 0x22>)
|
||||
public ResultCode ListAudioOutsAuto(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioOuts();
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioOutNameSize - buffer.Length);
|
||||
|
||||
position += AudioOutNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(3)] // 3.0.0+
|
||||
// OpenAudioOut(AudioOutInputConfiguration input_config, nn::applet::AppletResourceUserId, pid, handle<copy, process> process_handle, buffer<bytes, 0x21> name_in)
|
||||
// -> (AudioOutInputConfiguration output_config, object<nn::audio::detail::IAudioOut>, buffer<bytes, 0x22> name_out)
|
||||
public ResultCode OpenAudioOutAuto(ServiceCtx context)
|
||||
{
|
||||
AudioInputConfiguration inputConfiguration = context.RequestData.ReadStruct<AudioInputConfiguration>();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
(ulong deviceNameInputPosition, ulong deviceNameInputSize) = context.Request.GetBufferType0x21();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong deviceNameOutputPosition, ulong deviceNameOutputSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[0];
|
||||
|
||||
string inputDeviceName = MemoryHelper.ReadAsciiString(context.Memory, deviceNameInputPosition, (long)deviceNameInputSize);
|
||||
|
||||
ResultCode resultCode = _impl.OpenAudioOut(context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioOut obj, inputDeviceName, ref inputConfiguration, appletResourceUserId, processHandle, context.Device.Configuration.AudioVolume);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.WriteStruct(outputConfiguration);
|
||||
|
||||
byte[] outputDeviceNameRaw = Encoding.ASCII.GetBytes(outputDeviceName);
|
||||
|
||||
context.Memory.Write(deviceNameOutputPosition, outputDeviceNameRaw);
|
||||
MemoryHelper.FillWithZeros(context.Memory, deviceNameOutputPosition + (ulong)outputDeviceNameRaw.Length, AudioOutNameSize - outputDeviceNameRaw.Length);
|
||||
|
||||
MakeObject(context, new AudioOutServer(obj));
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
using Ryujinx.Audio.Renderer.Device;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
class AudioDevice : IAudioDevice
|
||||
{
|
||||
private readonly VirtualDeviceSession[] _sessions;
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private readonly ulong _appletResourceId;
|
||||
private readonly int _revision;
|
||||
#pragma warning restore IDE0052
|
||||
private readonly bool _isUsbDeviceSupported;
|
||||
|
||||
private readonly VirtualDeviceSessionRegistry _registry;
|
||||
private readonly KEvent _systemEvent;
|
||||
|
||||
public AudioDevice(VirtualDeviceSessionRegistry registry, KernelContext context, ulong appletResourceId, int revision)
|
||||
{
|
||||
_registry = registry;
|
||||
_appletResourceId = appletResourceId;
|
||||
_revision = revision;
|
||||
|
||||
BehaviourContext behaviourContext = new();
|
||||
behaviourContext.SetUserRevision(revision);
|
||||
|
||||
_isUsbDeviceSupported = behaviourContext.IsAudioUsbDeviceOutputSupported();
|
||||
_sessions = _registry.GetSessionByAppletResourceId(appletResourceId);
|
||||
|
||||
// TODO: support the 3 different events correctly when we will have hot plugable audio devices.
|
||||
_systemEvent = new KEvent(context);
|
||||
_systemEvent.ReadableEvent.Signal();
|
||||
}
|
||||
|
||||
private bool TryGetDeviceByName(out VirtualDeviceSession result, string name, bool ignoreRevLimitation = false)
|
||||
{
|
||||
result = null;
|
||||
|
||||
foreach (VirtualDeviceSession session in _sessions)
|
||||
{
|
||||
if (session.Device.Name.Equals(name))
|
||||
{
|
||||
if (!ignoreRevLimitation && !_isUsbDeviceSupported && session.Device.IsUsbDevice())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = session;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public string GetActiveAudioDeviceName()
|
||||
{
|
||||
VirtualDevice device = _registry.ActiveDevice;
|
||||
|
||||
if (!_isUsbDeviceSupported && device.IsUsbDevice())
|
||||
{
|
||||
device = _registry.DefaultDevice;
|
||||
}
|
||||
|
||||
return device.Name;
|
||||
}
|
||||
|
||||
public uint GetActiveChannelCount()
|
||||
{
|
||||
VirtualDevice device = _registry.ActiveDevice;
|
||||
|
||||
if (!_isUsbDeviceSupported && device.IsUsbDevice())
|
||||
{
|
||||
device = _registry.DefaultDevice;
|
||||
}
|
||||
|
||||
return device.ChannelCount;
|
||||
}
|
||||
|
||||
public ResultCode GetAudioDeviceOutputVolume(string name, out float volume)
|
||||
{
|
||||
if (TryGetDeviceByName(out VirtualDeviceSession result, name))
|
||||
{
|
||||
volume = result.Volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = 0.0f;
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public ResultCode SetAudioDeviceOutputVolume(string name, float volume)
|
||||
{
|
||||
if (TryGetDeviceByName(out VirtualDeviceSession result, name, true))
|
||||
{
|
||||
if (!_isUsbDeviceSupported && result.Device.IsUsbDevice())
|
||||
{
|
||||
result = _sessions[0];
|
||||
}
|
||||
|
||||
result.Volume = volume;
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public string GetActiveAudioOutputDeviceName()
|
||||
{
|
||||
return _registry.ActiveDevice.GetOutputDeviceName();
|
||||
}
|
||||
|
||||
public string[] ListAudioDeviceName()
|
||||
{
|
||||
int deviceCount = _sessions.Length;
|
||||
|
||||
if (!_isUsbDeviceSupported)
|
||||
{
|
||||
deviceCount--;
|
||||
}
|
||||
|
||||
string[] result = new string[deviceCount];
|
||||
|
||||
int i = 0;
|
||||
|
||||
foreach (VirtualDeviceSession session in _sessions)
|
||||
{
|
||||
if (!_isUsbDeviceSupported && session.Device.IsUsbDevice())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[i] = session.Device.Name;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public string[] ListAudioOutputDeviceName()
|
||||
{
|
||||
int deviceCount = _sessions.Length;
|
||||
|
||||
string[] result = new string[deviceCount];
|
||||
|
||||
for (int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
result[i] = _sessions[i].Device.GetOutputDeviceName();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public KEvent QueryAudioDeviceInputEvent()
|
||||
{
|
||||
return _systemEvent;
|
||||
}
|
||||
|
||||
public KEvent QueryAudioDeviceOutputEvent()
|
||||
{
|
||||
return _systemEvent;
|
||||
}
|
||||
|
||||
public KEvent QueryAudioDeviceSystemEvent()
|
||||
{
|
||||
return _systemEvent;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,320 +0,0 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
class AudioDeviceServer : IpcService
|
||||
{
|
||||
private const int AudioDeviceNameSize = 0x100;
|
||||
|
||||
private readonly IAudioDevice _impl;
|
||||
|
||||
public AudioDeviceServer(IAudioDevice impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// ListAudioDeviceName() -> (u32, buffer<bytes, 6>)
|
||||
public ResultCode ListAudioDeviceName(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioDeviceName();
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioDeviceNameSize - buffer.Length);
|
||||
|
||||
position += AudioDeviceNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// SetAudioDeviceOutputVolume(f32 volume, buffer<bytes, 5> name)
|
||||
public ResultCode SetAudioDeviceOutputVolume(ServiceCtx context)
|
||||
{
|
||||
float volume = context.RequestData.ReadSingle();
|
||||
|
||||
ulong position = context.Request.SendBuff[0].Position;
|
||||
ulong size = context.Request.SendBuff[0].Size;
|
||||
|
||||
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, (long)size);
|
||||
|
||||
return _impl.SetAudioDeviceOutputVolume(deviceName, volume);
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// GetAudioDeviceOutputVolume(buffer<bytes, 5> name) -> f32 volume
|
||||
public ResultCode GetAudioDeviceOutputVolume(ServiceCtx context)
|
||||
{
|
||||
ulong position = context.Request.SendBuff[0].Position;
|
||||
ulong size = context.Request.SendBuff[0].Size;
|
||||
|
||||
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, (long)size);
|
||||
|
||||
ResultCode result = _impl.GetAudioDeviceOutputVolume(deviceName, out float volume);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.Write(volume);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(3)]
|
||||
// GetActiveAudioDeviceName() -> buffer<bytes, 6>
|
||||
public ResultCode GetActiveAudioDeviceName(ServiceCtx context)
|
||||
{
|
||||
string name = _impl.GetActiveAudioDeviceName();
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(name + "\0");
|
||||
|
||||
if ((ulong)deviceNameBuffer.Length <= size)
|
||||
{
|
||||
context.Memory.Write(position, deviceNameBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(4)]
|
||||
// QueryAudioDeviceSystemEvent() -> handle<copy, event>
|
||||
public ResultCode QueryAudioDeviceSystemEvent(ServiceCtx context)
|
||||
{
|
||||
KEvent deviceSystemEvent = _impl.QueryAudioDeviceSystemEvent();
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(deviceSystemEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(5)]
|
||||
// GetActiveChannelCount() -> u32
|
||||
public ResultCode GetActiveChannelCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetActiveChannelCount());
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(6)] // 3.0.0+
|
||||
// ListAudioDeviceNameAuto() -> (u32, buffer<bytes, 0x22>)
|
||||
public ResultCode ListAudioDeviceNameAuto(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioDeviceName();
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioDeviceNameSize - buffer.Length);
|
||||
|
||||
position += AudioDeviceNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(7)] // 3.0.0+
|
||||
// SetAudioDeviceOutputVolumeAuto(f32 volume, buffer<bytes, 0x21> name)
|
||||
public ResultCode SetAudioDeviceOutputVolumeAuto(ServiceCtx context)
|
||||
{
|
||||
float volume = context.RequestData.ReadSingle();
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x21();
|
||||
|
||||
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, (long)size);
|
||||
|
||||
return _impl.SetAudioDeviceOutputVolume(deviceName, volume);
|
||||
}
|
||||
|
||||
[CommandCmif(8)] // 3.0.0+
|
||||
// GetAudioDeviceOutputVolumeAuto(buffer<bytes, 0x21> name) -> f32
|
||||
public ResultCode GetAudioDeviceOutputVolumeAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x21();
|
||||
|
||||
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, position, (long)size);
|
||||
|
||||
ResultCode result = _impl.GetAudioDeviceOutputVolume(deviceName, out float volume);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
context.ResponseData.Write(volume);
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10)] // 3.0.0+
|
||||
// GetActiveAudioDeviceNameAuto() -> buffer<bytes, 0x22>
|
||||
public ResultCode GetActiveAudioDeviceNameAuto(ServiceCtx context)
|
||||
{
|
||||
string name = _impl.GetActiveAudioDeviceName();
|
||||
|
||||
(ulong position, ulong size) = context.Request.GetBufferType0x22();
|
||||
|
||||
byte[] deviceNameBuffer = Encoding.UTF8.GetBytes(name + '\0');
|
||||
|
||||
if ((ulong)deviceNameBuffer.Length <= size)
|
||||
{
|
||||
context.Memory.Write(position, deviceNameBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(11)] // 3.0.0+
|
||||
// QueryAudioDeviceInputEvent() -> handle<copy, event>
|
||||
public ResultCode QueryAudioDeviceInputEvent(ServiceCtx context)
|
||||
{
|
||||
KEvent deviceInputEvent = _impl.QueryAudioDeviceInputEvent();
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(deviceInputEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(12)] // 3.0.0+
|
||||
// QueryAudioDeviceOutputEvent() -> handle<copy, event>
|
||||
public ResultCode QueryAudioDeviceOutputEvent(ServiceCtx context)
|
||||
{
|
||||
KEvent deviceOutputEvent = _impl.QueryAudioDeviceOutputEvent();
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(deviceOutputEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceAudio);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(13)] // 13.0.0+
|
||||
// GetActiveAudioOutputDeviceName() -> buffer<bytes, 6>
|
||||
public ResultCode GetActiveAudioOutputDeviceName(ServiceCtx context)
|
||||
{
|
||||
string name = _impl.GetActiveAudioOutputDeviceName();
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(name + "\0");
|
||||
|
||||
if ((ulong)deviceNameBuffer.Length <= size)
|
||||
{
|
||||
context.Memory.Write(position, deviceNameBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(14)] // 13.0.0+
|
||||
// ListAudioOutputDeviceName() -> (u32, buffer<bytes, 6>)
|
||||
public ResultCode ListAudioOutputDeviceName(ServiceCtx context)
|
||||
{
|
||||
string[] deviceNames = _impl.ListAudioOutputDeviceName();
|
||||
|
||||
ulong position = context.Request.ReceiveBuff[0].Position;
|
||||
ulong size = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ulong basePosition = position;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (string name in deviceNames)
|
||||
{
|
||||
byte[] buffer = Encoding.ASCII.GetBytes(name);
|
||||
|
||||
if ((position - basePosition) + (ulong)buffer.Length > size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
context.Memory.Write(position, buffer);
|
||||
MemoryHelper.FillWithZeros(context.Memory, position + (ulong)buffer.Length, AudioDeviceNameSize - buffer.Length);
|
||||
|
||||
position += AudioDeviceNameSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
context.ResponseData.Write(count);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
class AudioKernelEvent : IWritableEvent
|
||||
{
|
||||
public KEvent Event { get; }
|
||||
|
||||
public AudioKernelEvent(KEvent evnt)
|
||||
{
|
||||
Event = evnt;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Event.WritableEvent.Clear();
|
||||
}
|
||||
|
||||
public void Signal()
|
||||
{
|
||||
Event.WritableEvent.Signal();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
class AudioRenderer : IAudioRenderer
|
||||
{
|
||||
private readonly AudioRenderSystem _impl;
|
||||
|
||||
public AudioRenderer(AudioRenderSystem impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public ResultCode ExecuteAudioRendererRendering()
|
||||
{
|
||||
return (ResultCode)_impl.ExecuteAudioRendererRendering();
|
||||
}
|
||||
|
||||
public uint GetMixBufferCount()
|
||||
{
|
||||
return _impl.GetMixBufferCount();
|
||||
}
|
||||
|
||||
public uint GetRenderingTimeLimit()
|
||||
{
|
||||
return _impl.GetRenderingTimeLimit();
|
||||
}
|
||||
|
||||
public uint GetSampleCount()
|
||||
{
|
||||
return _impl.GetSampleCount();
|
||||
}
|
||||
|
||||
public uint GetSampleRate()
|
||||
{
|
||||
return _impl.GetSampleRate();
|
||||
}
|
||||
|
||||
public int GetState()
|
||||
{
|
||||
if (_impl.IsActive())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public ResultCode QuerySystemEvent(out KEvent systemEvent)
|
||||
{
|
||||
ResultCode resultCode = (ResultCode)_impl.QuerySystemEvent(out IWritableEvent outEvent);
|
||||
|
||||
if (resultCode == ResultCode.Success)
|
||||
{
|
||||
if (outEvent is AudioKernelEvent kernelEvent)
|
||||
{
|
||||
systemEvent = kernelEvent.Event;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
systemEvent = null;
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
public ResultCode RequestUpdate(Memory<byte> output, Memory<byte> performanceOutput, ReadOnlyMemory<byte> input)
|
||||
{
|
||||
return (ResultCode)_impl.Update(output, performanceOutput, input);
|
||||
}
|
||||
|
||||
public void SetRenderingTimeLimit(uint percent)
|
||||
{
|
||||
_impl.SetRenderingTimeLimitPercent(percent);
|
||||
}
|
||||
|
||||
public ResultCode Start()
|
||||
{
|
||||
_impl.Start();
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public ResultCode Stop()
|
||||
{
|
||||
_impl.Stop();
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_impl.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVoiceDropParameter(float voiceDropParameter)
|
||||
{
|
||||
_impl.SetVoiceDropParameter(voiceDropParameter);
|
||||
}
|
||||
|
||||
public float GetVoiceDropParameter()
|
||||
{
|
||||
return _impl.GetVoiceDropParameter();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
class AudioRendererServer : DisposableIpcService
|
||||
{
|
||||
private readonly IAudioRenderer _impl;
|
||||
|
||||
public AudioRendererServer(IAudioRenderer impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// GetSampleRate() -> u32
|
||||
public ResultCode GetSampleRate(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetSampleRate());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// GetSampleCount() -> u32
|
||||
public ResultCode GetSampleCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetSampleCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// GetMixBufferCount() -> u32
|
||||
public ResultCode GetMixBufferCount(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetMixBufferCount());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(3)]
|
||||
// GetState() -> u32
|
||||
public ResultCode GetState(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write(_impl.GetState());
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(4)]
|
||||
// RequestUpdate(buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 5> input)
|
||||
// -> (buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 6> output, buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 6> performanceOutput)
|
||||
public ResultCode RequestUpdate(ServiceCtx context)
|
||||
{
|
||||
ulong inputPosition = context.Request.SendBuff[0].Position;
|
||||
ulong inputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ulong performanceOutputPosition = context.Request.ReceiveBuff[1].Position;
|
||||
ulong performanceOutputSize = context.Request.ReceiveBuff[1].Size;
|
||||
|
||||
ReadOnlyMemory<byte> input = context.Memory.GetSpan(inputPosition, (int)inputSize).ToArray();
|
||||
|
||||
using IMemoryOwner<byte> outputOwner = ByteMemoryPool.RentCleared(outputSize);
|
||||
using IMemoryOwner<byte> performanceOutputOwner = ByteMemoryPool.RentCleared(performanceOutputSize);
|
||||
Memory<byte> output = outputOwner.Memory;
|
||||
Memory<byte> performanceOutput = performanceOutputOwner.Memory;
|
||||
|
||||
using MemoryHandle outputHandle = output.Pin();
|
||||
using MemoryHandle performanceOutputHandle = performanceOutput.Pin();
|
||||
|
||||
ResultCode result = _impl.RequestUpdate(output, performanceOutput, input);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
context.Memory.Write(outputPosition, output.Span);
|
||||
context.Memory.Write(performanceOutputPosition, performanceOutput.Span);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Error while processing renderer update: 0x{(int)result:X}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(5)]
|
||||
// Start()
|
||||
public ResultCode Start(ServiceCtx context)
|
||||
{
|
||||
return _impl.Start();
|
||||
}
|
||||
|
||||
[CommandCmif(6)]
|
||||
// Stop()
|
||||
public ResultCode Stop(ServiceCtx context)
|
||||
{
|
||||
return _impl.Stop();
|
||||
}
|
||||
|
||||
[CommandCmif(7)]
|
||||
// QuerySystemEvent() -> handle<copy, event>
|
||||
public ResultCode QuerySystemEvent(ServiceCtx context)
|
||||
{
|
||||
ResultCode result = _impl.QuerySystemEvent(out KEvent systemEvent);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
if (context.Process.HandleTable.GenerateHandle(systemEvent.ReadableEvent, out int handle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(8)]
|
||||
// SetAudioRendererRenderingTimeLimit(u32 limit)
|
||||
public ResultCode SetAudioRendererRenderingTimeLimit(ServiceCtx context)
|
||||
{
|
||||
uint limit = context.RequestData.ReadUInt32();
|
||||
|
||||
_impl.SetRenderingTimeLimit(limit);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(9)]
|
||||
// GetAudioRendererRenderingTimeLimit() -> u32 limit
|
||||
public ResultCode GetAudioRendererRenderingTimeLimit(ServiceCtx context)
|
||||
{
|
||||
uint limit = _impl.GetRenderingTimeLimit();
|
||||
|
||||
context.ResponseData.Write(limit);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10)] // 3.0.0+
|
||||
// RequestUpdateAuto(buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x21> input)
|
||||
// -> (buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x22> output, buffer<nn::audio::detail::AudioRendererUpdateDataHeader, 0x22> performanceOutput)
|
||||
public ResultCode RequestUpdateAuto(ServiceCtx context)
|
||||
{
|
||||
(ulong inputPosition, ulong inputSize) = context.Request.GetBufferType0x21();
|
||||
(ulong outputPosition, ulong outputSize) = context.Request.GetBufferType0x22(0);
|
||||
(ulong performanceOutputPosition, ulong performanceOutputSize) = context.Request.GetBufferType0x22(1);
|
||||
|
||||
ReadOnlyMemory<byte> input = context.Memory.GetSpan(inputPosition, (int)inputSize).ToArray();
|
||||
|
||||
Memory<byte> output = new byte[outputSize];
|
||||
Memory<byte> performanceOutput = new byte[performanceOutputSize];
|
||||
|
||||
using MemoryHandle outputHandle = output.Pin();
|
||||
using MemoryHandle performanceOutputHandle = performanceOutput.Pin();
|
||||
|
||||
ResultCode result = _impl.RequestUpdate(output, performanceOutput, input);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
context.Memory.Write(outputPosition, output.Span);
|
||||
context.Memory.Write(performanceOutputPosition, performanceOutput.Span);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(11)] // 3.0.0+
|
||||
// ExecuteAudioRendererRendering()
|
||||
public ResultCode ExecuteAudioRendererRendering(ServiceCtx context)
|
||||
{
|
||||
return _impl.ExecuteAudioRendererRendering();
|
||||
}
|
||||
|
||||
[CommandCmif(12)] // 15.0.0+
|
||||
// SetVoiceDropParameter(f32 voiceDropParameter)
|
||||
public ResultCode SetVoiceDropParameter(ServiceCtx context)
|
||||
{
|
||||
float voiceDropParameter = context.RequestData.ReadSingle();
|
||||
|
||||
_impl.SetVoiceDropParameter(voiceDropParameter);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(13)] // 15.0.0+
|
||||
// GetVoiceDropParameter() -> f32 voiceDropParameter
|
||||
public ResultCode GetVoiceDropParameter(ServiceCtx context)
|
||||
{
|
||||
float voiceDropParameter = _impl.GetVoiceDropParameter();
|
||||
|
||||
context.ResponseData.Write(voiceDropParameter);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
_impl.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
interface IAudioDevice
|
||||
{
|
||||
string[] ListAudioDeviceName();
|
||||
ResultCode SetAudioDeviceOutputVolume(string name, float volume);
|
||||
ResultCode GetAudioDeviceOutputVolume(string name, out float volume);
|
||||
string GetActiveAudioDeviceName();
|
||||
KEvent QueryAudioDeviceSystemEvent();
|
||||
uint GetActiveChannelCount();
|
||||
KEvent QueryAudioDeviceInputEvent();
|
||||
KEvent QueryAudioDeviceOutputEvent();
|
||||
string GetActiveAudioOutputDeviceName();
|
||||
string[] ListAudioOutputDeviceName();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRenderer
|
||||
{
|
||||
interface IAudioRenderer : IDisposable
|
||||
{
|
||||
uint GetSampleRate();
|
||||
uint GetSampleCount();
|
||||
uint GetMixBufferCount();
|
||||
int GetState();
|
||||
ResultCode RequestUpdate(Memory<byte> output, Memory<byte> performanceOutput, ReadOnlyMemory<byte> input);
|
||||
ResultCode Start();
|
||||
ResultCode Stop();
|
||||
ResultCode QuerySystemEvent(out KEvent systemEvent);
|
||||
void SetRenderingTimeLimit(uint percent);
|
||||
uint GetRenderingTimeLimit();
|
||||
ResultCode ExecuteAudioRendererRendering();
|
||||
void SetVoiceDropParameter(float voiceDropParameter);
|
||||
float GetVoiceDropParameter();
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
using Ryujinx.Audio.Renderer.Device;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
|
||||
using AudioRendererManagerImpl = Ryujinx.Audio.Renderer.Server.AudioRendererManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
class AudioRendererManager : IAudioRendererManager
|
||||
{
|
||||
private readonly AudioRendererManagerImpl _impl;
|
||||
private readonly VirtualDeviceSessionRegistry _registry;
|
||||
|
||||
public AudioRendererManager(AudioRendererManagerImpl impl, VirtualDeviceSessionRegistry registry)
|
||||
{
|
||||
_impl = impl;
|
||||
_registry = registry;
|
||||
}
|
||||
|
||||
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context, out IAudioDevice outObject, int revision, ulong appletResourceUserId)
|
||||
{
|
||||
outObject = new AudioDevice(_registry, context.Device.System.KernelContext, appletResourceUserId, revision);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public ulong GetWorkBufferSize(ref AudioRendererConfiguration parameter)
|
||||
{
|
||||
return AudioRendererManagerImpl.GetWorkBufferSize(ref parameter);
|
||||
}
|
||||
|
||||
public ResultCode OpenAudioRenderer(
|
||||
ServiceCtx context,
|
||||
out IAudioRenderer obj,
|
||||
ref AudioRendererConfiguration parameter,
|
||||
ulong workBufferSize,
|
||||
ulong appletResourceUserId,
|
||||
KTransferMemory workBufferTransferMemory,
|
||||
uint processHandle)
|
||||
{
|
||||
var memoryManager = context.Process.HandleTable.GetKProcess((int)processHandle).CpuMemory;
|
||||
|
||||
ResultCode result = (ResultCode)_impl.OpenAudioRenderer(
|
||||
out AudioRenderSystem renderer,
|
||||
memoryManager,
|
||||
ref parameter,
|
||||
appletResourceUserId,
|
||||
workBufferTransferMemory.Address,
|
||||
workBufferTransferMemory.Size,
|
||||
processHandle,
|
||||
context.Device.Configuration.AudioVolume);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
obj = new AudioRenderer.AudioRenderer(renderer);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Server;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audren:u")]
|
||||
class AudioRendererManagerServer : IpcService
|
||||
{
|
||||
private const int InitialRevision = ('R' << 0) | ('E' << 8) | ('V' << 16) | ('1' << 24);
|
||||
|
||||
private readonly IAudioRendererManager _impl;
|
||||
|
||||
public AudioRendererManagerServer(ServiceCtx context) : this(context, new AudioRendererManager(context.Device.System.AudioRendererManager, context.Device.System.AudioDeviceSessionRegistry)) { }
|
||||
|
||||
public AudioRendererManagerServer(ServiceCtx context, IAudioRendererManager impl) : base(context.Device.System.AudRenServer)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal parameter, u64 workBufferSize, nn::applet::AppletResourceUserId appletResourceId, pid, handle<copy> workBuffer, handle<copy> processHandle)
|
||||
// -> object<nn::audio::detail::IAudioRenderer>
|
||||
public ResultCode OpenAudioRenderer(ServiceCtx context)
|
||||
{
|
||||
AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
|
||||
ulong workBufferSize = context.RequestData.ReadUInt64();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
int transferMemoryHandle = context.Request.HandleDesc.ToCopy[0];
|
||||
KTransferMemory workBufferTransferMemory = context.Process.HandleTable.GetObject<KTransferMemory>(transferMemoryHandle);
|
||||
uint processHandle = (uint)context.Request.HandleDesc.ToCopy[1];
|
||||
|
||||
ResultCode result = _impl.OpenAudioRenderer(
|
||||
context,
|
||||
out IAudioRenderer renderer,
|
||||
ref parameter,
|
||||
workBufferSize,
|
||||
appletResourceUserId,
|
||||
workBufferTransferMemory,
|
||||
processHandle);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
MakeObject(context, new AudioRendererServer(renderer));
|
||||
}
|
||||
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle(transferMemoryHandle);
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle((int)processHandle);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal parameter) -> u64 workBufferSize
|
||||
public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
|
||||
{
|
||||
AudioRendererConfiguration parameter = context.RequestData.ReadStruct<AudioRendererConfiguration>();
|
||||
|
||||
if (BehaviourContext.CheckValidRevision(parameter.Revision))
|
||||
{
|
||||
ulong size = _impl.GetWorkBufferSize(ref parameter);
|
||||
|
||||
context.ResponseData.Write(size);
|
||||
|
||||
Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.ResponseData.Write(0L);
|
||||
|
||||
Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{BehaviourContext.GetRevisionNumber(parameter.Revision)} is not supported!");
|
||||
|
||||
return ResultCode.UnsupportedRevision;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
|
||||
public ResultCode GetAudioDeviceService(ServiceCtx context)
|
||||
{
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, InitialRevision, appletResourceUserId);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
MakeObject(context, new AudioDeviceServer(device));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandCmif(4)] // 4.0.0+
|
||||
// GetAudioDeviceServiceWithRevisionInfo(s32 revision, nn::applet::AppletResourceUserId appletResourceId) -> object<nn::audio::detail::IAudioDevice>
|
||||
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
|
||||
{
|
||||
int revision = context.RequestData.ReadInt32();
|
||||
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
||||
|
||||
ResultCode result = _impl.GetAudioDeviceServiceWithRevisionInfo(context, out IAudioDevice device, revision, appletResourceUserId);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
MakeObject(context, new AudioDeviceServer(device));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
using Concentus.Structs;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
||||
{
|
||||
class Decoder : IDecoder
|
||||
{
|
||||
private readonly OpusDecoder _decoder;
|
||||
|
||||
public int SampleRate => _decoder.SampleRate;
|
||||
public int ChannelsCount => _decoder.NumChannels;
|
||||
|
||||
public Decoder(int sampleRate, int channelsCount)
|
||||
{
|
||||
_decoder = new OpusDecoder(sampleRate, channelsCount);
|
||||
}
|
||||
|
||||
public int Decode(byte[] inData, int inDataOffset, int len, short[] outPcm, int outPcmOffset, int frameSize)
|
||||
{
|
||||
return _decoder.Decode(inData, inDataOffset, len, outPcm, outPcmOffset, frameSize);
|
||||
}
|
||||
|
||||
public void ResetState()
|
||||
{
|
||||
_decoder.ResetState();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
using Concentus;
|
||||
using Concentus.Enums;
|
||||
using Concentus.Structs;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.Types;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
||||
{
|
||||
static class DecoderCommon
|
||||
{
|
||||
private static ResultCode GetPacketNumSamples(this IDecoder decoder, out int numSamples, byte[] packet)
|
||||
{
|
||||
int result = OpusPacketInfo.GetNumSamples(packet, 0, packet.Length, decoder.SampleRate);
|
||||
|
||||
numSamples = result;
|
||||
|
||||
if (result == OpusError.OPUS_INVALID_PACKET)
|
||||
{
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
else if (result == OpusError.OPUS_BAD_ARG)
|
||||
{
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public static ResultCode DecodeInterleaved(
|
||||
this IDecoder decoder,
|
||||
bool reset,
|
||||
ReadOnlySpan<byte> input,
|
||||
out short[] outPcmData,
|
||||
ulong outputSize,
|
||||
out uint outConsumed,
|
||||
out int outSamples)
|
||||
{
|
||||
outPcmData = null;
|
||||
outConsumed = 0;
|
||||
outSamples = 0;
|
||||
|
||||
int streamSize = input.Length;
|
||||
|
||||
if (streamSize < Unsafe.SizeOf<OpusPacketHeader>())
|
||||
{
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
|
||||
OpusPacketHeader header = OpusPacketHeader.FromSpan(input);
|
||||
int headerSize = Unsafe.SizeOf<OpusPacketHeader>();
|
||||
uint totalSize = header.length + (uint)headerSize;
|
||||
|
||||
if (totalSize > streamSize)
|
||||
{
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
|
||||
byte[] opusData = input.Slice(headerSize, (int)header.length).ToArray();
|
||||
|
||||
ResultCode result = decoder.GetPacketNumSamples(out int numSamples, opusData);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
if ((uint)numSamples * (uint)decoder.ChannelsCount * sizeof(short) > outputSize)
|
||||
{
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
|
||||
outPcmData = new short[numSamples * decoder.ChannelsCount];
|
||||
|
||||
if (reset)
|
||||
{
|
||||
decoder.ResetState();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
outSamples = decoder.Decode(opusData, 0, opusData.Length, outPcmData, 0, outPcmData.Length / decoder.ChannelsCount);
|
||||
outConsumed = totalSize;
|
||||
}
|
||||
catch (OpusException)
|
||||
{
|
||||
// TODO: as OpusException doesn't provide us the exact error code, this is kind of inaccurate in some cases...
|
||||
return ResultCode.OpusInvalidInput;
|
||||
}
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
||||
{
|
||||
interface IDecoder
|
||||
{
|
||||
int SampleRate { get; }
|
||||
int ChannelsCount { get; }
|
||||
|
||||
int Decode(byte[] inData, int inDataOffset, int len, short[] outPcm, int outPcmOffset, int frameSize);
|
||||
void ResetState();
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
using Ryujinx.HLE.HOS.Services.Audio.Types;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
||||
{
|
||||
class IHardwareOpusDecoder : IpcService
|
||||
{
|
||||
private readonly IDecoder _decoder;
|
||||
private readonly OpusDecoderFlags _flags;
|
||||
|
||||
public IHardwareOpusDecoder(int sampleRate, int channelsCount, OpusDecoderFlags flags)
|
||||
{
|
||||
_decoder = new Decoder(sampleRate, channelsCount);
|
||||
_flags = flags;
|
||||
}
|
||||
|
||||
public IHardwareOpusDecoder(int sampleRate, int channelsCount, int streams, int coupledStreams, OpusDecoderFlags flags, byte[] mapping)
|
||||
{
|
||||
_decoder = new MultiSampleDecoder(sampleRate, channelsCount, streams, coupledStreams, mapping);
|
||||
_flags = flags;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// DecodeInterleavedOld(buffer<unknown, 5>) -> (u32, u32, buffer<unknown, 6>)
|
||||
public ResultCode DecodeInterleavedOld(ServiceCtx context)
|
||||
{
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: false);
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
// DecodeInterleavedForMultiStreamOld(buffer<unknown, 5>) -> (u32, u32, buffer<unknown, 6>)
|
||||
public ResultCode DecodeInterleavedForMultiStreamOld(ServiceCtx context)
|
||||
{
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: false);
|
||||
}
|
||||
|
||||
[CommandCmif(4)] // 6.0.0+
|
||||
// DecodeInterleavedWithPerfOld(buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleavedWithPerfOld(ServiceCtx context)
|
||||
{
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: true);
|
||||
}
|
||||
|
||||
[CommandCmif(5)] // 6.0.0+
|
||||
// DecodeInterleavedForMultiStreamWithPerfOld(buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleavedForMultiStreamWithPerfOld(ServiceCtx context)
|
||||
{
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset: false, withPerf: true);
|
||||
}
|
||||
|
||||
[CommandCmif(6)] // 6.0.0+
|
||||
// DecodeInterleavedWithPerfAndResetOld(bool reset, buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleavedWithPerfAndResetOld(ServiceCtx context)
|
||||
{
|
||||
bool reset = context.RequestData.ReadBoolean();
|
||||
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset, withPerf: true);
|
||||
}
|
||||
|
||||
[CommandCmif(7)] // 6.0.0+
|
||||
// DecodeInterleavedForMultiStreamWithPerfAndResetOld(bool reset, buffer<unknown, 5>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleavedForMultiStreamWithPerfAndResetOld(ServiceCtx context)
|
||||
{
|
||||
bool reset = context.RequestData.ReadBoolean();
|
||||
|
||||
return DecodeInterleavedInternal(context, OpusDecoderFlags.None, reset, withPerf: true);
|
||||
}
|
||||
|
||||
[CommandCmif(8)] // 7.0.0+
|
||||
// DecodeInterleaved(bool reset, buffer<unknown, 0x45>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleaved(ServiceCtx context)
|
||||
{
|
||||
bool reset = context.RequestData.ReadBoolean();
|
||||
|
||||
return DecodeInterleavedInternal(context, _flags, reset, withPerf: true);
|
||||
}
|
||||
|
||||
[CommandCmif(9)] // 7.0.0+
|
||||
// DecodeInterleavedForMultiStream(bool reset, buffer<unknown, 0x45>) -> (u32, u32, u64, buffer<unknown, 0x46>)
|
||||
public ResultCode DecodeInterleavedForMultiStream(ServiceCtx context)
|
||||
{
|
||||
bool reset = context.RequestData.ReadBoolean();
|
||||
|
||||
return DecodeInterleavedInternal(context, _flags, reset, withPerf: true);
|
||||
}
|
||||
|
||||
private ResultCode DecodeInterleavedInternal(ServiceCtx context, OpusDecoderFlags flags, bool reset, bool withPerf)
|
||||
{
|
||||
ulong inPosition = context.Request.SendBuff[0].Position;
|
||||
ulong inSize = context.Request.SendBuff[0].Size;
|
||||
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ReadOnlySpan<byte> input = context.Memory.GetSpan(inPosition, (int)inSize);
|
||||
|
||||
ResultCode result = _decoder.DecodeInterleaved(reset, input, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
|
||||
|
||||
if (result == ResultCode.Success)
|
||||
{
|
||||
context.Memory.Write(outputPosition, MemoryMarshal.Cast<short, byte>(outPcmData.AsSpan()));
|
||||
|
||||
context.ResponseData.Write(outConsumed);
|
||||
context.ResponseData.Write(outSamples);
|
||||
|
||||
if (withPerf)
|
||||
{
|
||||
// This is the time the DSP took to process the request, TODO: fill this.
|
||||
context.ResponseData.Write(0UL);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
using Concentus.Structs;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
|
||||
{
|
||||
class MultiSampleDecoder : IDecoder
|
||||
{
|
||||
private readonly OpusMSDecoder _decoder;
|
||||
|
||||
public int SampleRate => _decoder.SampleRate;
|
||||
public int ChannelsCount { get; }
|
||||
|
||||
public MultiSampleDecoder(int sampleRate, int channelsCount, int streams, int coupledStreams, byte[] mapping)
|
||||
{
|
||||
ChannelsCount = channelsCount;
|
||||
_decoder = new OpusMSDecoder(sampleRate, channelsCount, streams, coupledStreams, mapping);
|
||||
}
|
||||
|
||||
public int Decode(byte[] inData, int inDataOffset, int len, short[] outPcm, int outPcmOffset, int frameSize)
|
||||
{
|
||||
return _decoder.DecodeMultistream(inData, inDataOffset, len, outPcm, outPcmOffset, frameSize, 0);
|
||||
}
|
||||
|
||||
public void ResetState()
|
||||
{
|
||||
_decoder.ResetState();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audctl")]
|
||||
class IAudioController : IpcService
|
||||
{
|
||||
public IAudioController(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioIn;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
interface IAudioInManager
|
||||
{
|
||||
public string[] ListAudioIns(bool filtered);
|
||||
|
||||
public ResultCode OpenAudioIn(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioIn obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audin:a")]
|
||||
class IAudioInManagerForApplet : IpcService
|
||||
{
|
||||
public IAudioInManagerForApplet(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audin:d")]
|
||||
class IAudioInManagerForDebugger : IpcService
|
||||
{
|
||||
public IAudioInManagerForDebugger(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioOut;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
interface IAudioOutManager
|
||||
{
|
||||
public string[] ListAudioOuts();
|
||||
|
||||
public ResultCode OpenAudioOut(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioOut obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle, float volume);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audout:a")]
|
||||
class IAudioOutManagerForApplet : IpcService
|
||||
{
|
||||
public IAudioOutManagerForApplet(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audout:d")]
|
||||
class IAudioOutManagerForDebugger : IpcService
|
||||
{
|
||||
public IAudioOutManagerForDebugger(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
interface IAudioRendererManager
|
||||
{
|
||||
// TODO: Remove ServiceCtx argument
|
||||
// BODY: This is only needed by the legacy backend. Refactor this when removing the legacy backend.
|
||||
ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context, out IAudioDevice outObject, int revision, ulong appletResourceUserId);
|
||||
|
||||
// TODO: Remove ServiceCtx argument
|
||||
// BODY: This is only needed by the legacy backend. Refactor this when removing the legacy backend.
|
||||
ResultCode OpenAudioRenderer(ServiceCtx context, out IAudioRenderer obj, ref AudioRendererConfiguration parameter, ulong workBufferSize, ulong appletResourceUserId, KTransferMemory workBufferTransferMemory, uint processHandle);
|
||||
|
||||
ulong GetWorkBufferSize(ref AudioRendererConfiguration parameter);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audren:a")]
|
||||
class IAudioRendererManagerForApplet : IpcService
|
||||
{
|
||||
public IAudioRendererManagerForApplet(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audren:d")]
|
||||
class IAudioRendererManagerForDebugger : IpcService
|
||||
{
|
||||
public IAudioRendererManagerForDebugger(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("auddev")] // 6.0.0+
|
||||
class IAudioSnoopManager : IpcService
|
||||
{
|
||||
public IAudioSnoopManager(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audrec:u")]
|
||||
class IFinalOutputRecorderManager : IpcService
|
||||
{
|
||||
public IFinalOutputRecorderManager(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audrec:a")]
|
||||
class IFinalOutputRecorderManagerForApplet : IpcService
|
||||
{
|
||||
public IFinalOutputRecorderManagerForApplet(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audrec:d")]
|
||||
class IFinalOutputRecorderManagerForDebugger : IpcService
|
||||
{
|
||||
public IFinalOutputRecorderManagerForDebugger(ServiceCtx context) { }
|
||||
}
|
||||
}
|
|
@ -1,227 +0,0 @@
|
|||
using Ryujinx.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.Types;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("hwopus")]
|
||||
class IHardwareOpusDecoderManager : IpcService
|
||||
{
|
||||
public IHardwareOpusDecoderManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
||||
public ResultCode Initialize(ServiceCtx context)
|
||||
{
|
||||
int sampleRate = context.RequestData.ReadInt32();
|
||||
int channelsCount = context.RequestData.ReadInt32();
|
||||
|
||||
MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount, OpusDecoderFlags.None));
|
||||
|
||||
// Close transfer memory immediately as we don't use it.
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// GetWorkBufferSize(bytes<8, 4>) -> u32
|
||||
public ResultCode GetWorkBufferSize(ServiceCtx context)
|
||||
{
|
||||
int sampleRate = context.RequestData.ReadInt32();
|
||||
int channelsCount = context.RequestData.ReadInt32();
|
||||
|
||||
int opusDecoderSize = GetOpusDecoderSize(channelsCount);
|
||||
|
||||
int frameSize = BitUtils.AlignUp(channelsCount * 1920 / (48000 / sampleRate), 64);
|
||||
int totalSize = opusDecoderSize + 1536 + frameSize;
|
||||
|
||||
context.ResponseData.Write(totalSize);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(2)] // 3.0.0+
|
||||
// InitializeForMultiStream(u32, handle<copy>, buffer<unknown<0x110>, 0x19>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
||||
public ResultCode InitializeForMultiStream(ServiceCtx context)
|
||||
{
|
||||
ulong parametersAddress = context.Request.PtrBuff[0].Position;
|
||||
|
||||
OpusMultiStreamParameters parameters = context.Memory.Read<OpusMultiStreamParameters>(parametersAddress);
|
||||
|
||||
MakeObject(context, new IHardwareOpusDecoder(parameters.SampleRate, parameters.ChannelsCount, OpusDecoderFlags.None));
|
||||
|
||||
// Close transfer memory immediately as we don't use it.
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(3)] // 3.0.0+
|
||||
// GetWorkBufferSizeForMultiStream(buffer<unknown<0x110>, 0x19>) -> u32
|
||||
public ResultCode GetWorkBufferSizeForMultiStream(ServiceCtx context)
|
||||
{
|
||||
ulong parametersAddress = context.Request.PtrBuff[0].Position;
|
||||
|
||||
OpusMultiStreamParameters parameters = context.Memory.Read<OpusMultiStreamParameters>(parametersAddress);
|
||||
|
||||
int opusDecoderSize = GetOpusMultistreamDecoderSize(parameters.NumberOfStreams, parameters.NumberOfStereoStreams);
|
||||
|
||||
int streamSize = BitUtils.AlignUp(parameters.NumberOfStreams * 1500, 64);
|
||||
int frameSize = BitUtils.AlignUp(parameters.ChannelsCount * 1920 / (48000 / parameters.SampleRate), 64);
|
||||
int totalSize = opusDecoderSize + streamSize + frameSize;
|
||||
|
||||
context.ResponseData.Write(totalSize);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(4)] // 12.0.0+
|
||||
// InitializeEx(OpusParametersEx, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
||||
public ResultCode InitializeEx(ServiceCtx context)
|
||||
{
|
||||
OpusParametersEx parameters = context.RequestData.ReadStruct<OpusParametersEx>();
|
||||
|
||||
// UseLargeFrameSize can be ignored due to not relying on fixed size buffers for storing the decoded result.
|
||||
MakeObject(context, new IHardwareOpusDecoder(parameters.SampleRate, parameters.ChannelsCount, parameters.Flags));
|
||||
|
||||
// Close transfer memory immediately as we don't use it.
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(5)] // 12.0.0+
|
||||
// GetWorkBufferSizeEx(OpusParametersEx) -> u32
|
||||
public ResultCode GetWorkBufferSizeEx(ServiceCtx context)
|
||||
{
|
||||
OpusParametersEx parameters = context.RequestData.ReadStruct<OpusParametersEx>();
|
||||
|
||||
int opusDecoderSize = GetOpusDecoderSize(parameters.ChannelsCount);
|
||||
|
||||
int frameSizeMono48KHz = parameters.Flags.HasFlag(OpusDecoderFlags.LargeFrameSize) ? 5760 : 1920;
|
||||
int frameSize = BitUtils.AlignUp(parameters.ChannelsCount * frameSizeMono48KHz / (48000 / parameters.SampleRate), 64);
|
||||
int totalSize = opusDecoderSize + 1536 + frameSize;
|
||||
|
||||
context.ResponseData.Write(totalSize);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(6)] // 12.0.0+
|
||||
// InitializeForMultiStreamEx(u32, handle<copy>, buffer<unknown<0x118>, 0x19>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
||||
public ResultCode InitializeForMultiStreamEx(ServiceCtx context)
|
||||
{
|
||||
ulong parametersAddress = context.Request.PtrBuff[0].Position;
|
||||
|
||||
OpusMultiStreamParametersEx parameters = context.Memory.Read<OpusMultiStreamParametersEx>(parametersAddress);
|
||||
|
||||
byte[] mappings = MemoryMarshal.Cast<uint, byte>(parameters.ChannelMappings.AsSpan()).ToArray();
|
||||
|
||||
// UseLargeFrameSize can be ignored due to not relying on fixed size buffers for storing the decoded result.
|
||||
MakeObject(context, new IHardwareOpusDecoder(
|
||||
parameters.SampleRate,
|
||||
parameters.ChannelsCount,
|
||||
parameters.NumberOfStreams,
|
||||
parameters.NumberOfStereoStreams,
|
||||
parameters.Flags,
|
||||
mappings));
|
||||
|
||||
// Close transfer memory immediately as we don't use it.
|
||||
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(7)] // 12.0.0+
|
||||
// GetWorkBufferSizeForMultiStreamEx(buffer<unknown<0x118>, 0x19>) -> u32
|
||||
public ResultCode GetWorkBufferSizeForMultiStreamEx(ServiceCtx context)
|
||||
{
|
||||
ulong parametersAddress = context.Request.PtrBuff[0].Position;
|
||||
|
||||
OpusMultiStreamParametersEx parameters = context.Memory.Read<OpusMultiStreamParametersEx>(parametersAddress);
|
||||
|
||||
int opusDecoderSize = GetOpusMultistreamDecoderSize(parameters.NumberOfStreams, parameters.NumberOfStereoStreams);
|
||||
|
||||
int frameSizeMono48KHz = parameters.Flags.HasFlag(OpusDecoderFlags.LargeFrameSize) ? 5760 : 1920;
|
||||
int streamSize = BitUtils.AlignUp(parameters.NumberOfStreams * 1500, 64);
|
||||
int frameSize = BitUtils.AlignUp(parameters.ChannelsCount * frameSizeMono48KHz / (48000 / parameters.SampleRate), 64);
|
||||
int totalSize = opusDecoderSize + streamSize + frameSize;
|
||||
|
||||
context.ResponseData.Write(totalSize);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(8)] // 16.0.0+
|
||||
// GetWorkBufferSizeExEx(OpusParametersEx) -> u32
|
||||
public ResultCode GetWorkBufferSizeExEx(ServiceCtx context)
|
||||
{
|
||||
// NOTE: GetWorkBufferSizeEx use hardcoded values to compute the returned size.
|
||||
// GetWorkBufferSizeExEx fixes that by using dynamic values.
|
||||
// Since we're already doing that, it's fine to call it directly.
|
||||
|
||||
return GetWorkBufferSizeEx(context);
|
||||
}
|
||||
|
||||
[CommandCmif(9)] // 16.0.0+
|
||||
// GetWorkBufferSizeForMultiStreamExEx(buffer<unknown<0x118>, 0x19>) -> u32
|
||||
public ResultCode GetWorkBufferSizeForMultiStreamExEx(ServiceCtx context)
|
||||
{
|
||||
// NOTE: GetWorkBufferSizeForMultiStreamEx use hardcoded values to compute the returned size.
|
||||
// GetWorkBufferSizeForMultiStreamExEx fixes that by using dynamic values.
|
||||
// Since we're already doing that, it's fine to call it directly.
|
||||
|
||||
return GetWorkBufferSizeForMultiStreamEx(context);
|
||||
}
|
||||
|
||||
private static int GetOpusMultistreamDecoderSize(int streams, int coupledStreams)
|
||||
{
|
||||
if (streams < 1 || coupledStreams > streams || coupledStreams < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int coupledSize = GetOpusDecoderSize(2);
|
||||
int monoSize = GetOpusDecoderSize(1);
|
||||
|
||||
return Align4(monoSize - GetOpusDecoderAllocSize(1)) * (streams - coupledStreams) +
|
||||
Align4(coupledSize - GetOpusDecoderAllocSize(2)) * coupledStreams + 0xb90c;
|
||||
}
|
||||
|
||||
private static int Align4(int value)
|
||||
{
|
||||
return BitUtils.AlignUp(value, 4);
|
||||
}
|
||||
|
||||
private static int GetOpusDecoderSize(int channelsCount)
|
||||
{
|
||||
const int SilkDecoderSize = 0x2160;
|
||||
|
||||
if (channelsCount < 1 || channelsCount > 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int celtDecoderSize = GetCeltDecoderSize(channelsCount);
|
||||
int opusDecoderSize = GetOpusDecoderAllocSize(channelsCount) | 0x4c;
|
||||
|
||||
return opusDecoderSize + SilkDecoderSize + celtDecoderSize;
|
||||
}
|
||||
|
||||
private static int GetOpusDecoderAllocSize(int channelsCount)
|
||||
{
|
||||
return (channelsCount * 0x800 + 0x4803) & -0x800;
|
||||
}
|
||||
|
||||
private static int GetCeltDecoderSize(int channelsCount)
|
||||
{
|
||||
const int DecodeBufferSize = 0x2030;
|
||||
const int Overlap = 120;
|
||||
const int EBandsCount = 21;
|
||||
|
||||
return (DecodeBufferSize + Overlap * 4) * channelsCount + EBandsCount * 16 + 0x50;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
enum ResultCode
|
||||
{
|
||||
ModuleId = 153,
|
||||
ErrorCodeShift = 9,
|
||||
|
||||
Success = 0,
|
||||
|
||||
DeviceNotFound = (1 << ErrorCodeShift) | ModuleId,
|
||||
UnsupportedRevision = (2 << ErrorCodeShift) | ModuleId,
|
||||
UnsupportedSampleRate = (3 << ErrorCodeShift) | ModuleId,
|
||||
BufferSizeTooSmall = (4 << ErrorCodeShift) | ModuleId,
|
||||
OpusInvalidInput = (6 << ErrorCodeShift) | ModuleId,
|
||||
TooManyBuffersInUse = (8 << ErrorCodeShift) | ModuleId,
|
||||
InvalidChannelCount = (10 << ErrorCodeShift) | ModuleId,
|
||||
InvalidOperation = (513 << ErrorCodeShift) | ModuleId,
|
||||
InvalidHandle = (1536 << ErrorCodeShift) | ModuleId,
|
||||
OutputAlreadyStarted = (1540 << ErrorCodeShift) | ModuleId,
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.Types
|
||||
{
|
||||
[Flags]
|
||||
enum OpusDecoderFlags : uint
|
||||
{
|
||||
None,
|
||||
LargeFrameSize = 1 << 0,
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x110)]
|
||||
struct OpusMultiStreamParameters
|
||||
{
|
||||
public int SampleRate;
|
||||
public int ChannelsCount;
|
||||
public int NumberOfStreams;
|
||||
public int NumberOfStereoStreams;
|
||||
public Array64<uint> ChannelMappings;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x118)]
|
||||
struct OpusMultiStreamParametersEx
|
||||
{
|
||||
public int SampleRate;
|
||||
public int ChannelsCount;
|
||||
public int NumberOfStreams;
|
||||
public int NumberOfStereoStreams;
|
||||
public OpusDecoderFlags Flags;
|
||||
|
||||
Array4<byte> Padding1;
|
||||
|
||||
public Array64<uint> ChannelMappings;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct OpusPacketHeader
|
||||
{
|
||||
public uint length;
|
||||
public uint finalRange;
|
||||
|
||||
public static OpusPacketHeader FromSpan(ReadOnlySpan<byte> data)
|
||||
{
|
||||
OpusPacketHeader header = MemoryMarshal.Cast<byte, OpusPacketHeader>(data)[0];
|
||||
|
||||
header.length = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.length) : header.length;
|
||||
header.finalRange = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.finalRange) : header.finalRange;
|
||||
|
||||
return header;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
|
||||
struct OpusParametersEx
|
||||
{
|
||||
public int SampleRate;
|
||||
public int ChannelsCount;
|
||||
public OpusDecoderFlags Flags;
|
||||
|
||||
Array4<byte> Padding1;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Caps.Types;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SkiaSharp;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Caps
|
||||
|
@ -118,7 +118,11 @@ namespace Ryujinx.HLE.HOS.Services.Caps
|
|||
}
|
||||
|
||||
// NOTE: The saved JPEG file doesn't have the limitation in the extra EXIF data.
|
||||
Image.LoadPixelData<Rgba32>(screenshotData, 1280, 720).SaveAsJpegAsync(filePath);
|
||||
using var bitmap = new SKBitmap(new SKImageInfo(1280, 720, SKColorType.Rgba8888));
|
||||
Marshal.Copy(screenshotData, 0, bitmap.GetPixels(), screenshotData.Length);
|
||||
using var data = bitmap.Encode(SKEncodedImageFormat.Jpeg, 80);
|
||||
using var file = File.OpenWrite(filePath);
|
||||
data.SaveTo(file);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Services.Fatal
|
|||
errorReport.AppendLine($"\tResultCode: {((int)resultCode & 0x1FF) + 2000}-{((int)resultCode >> 9) & 0x3FFF:d4}");
|
||||
errorReport.AppendLine($"\tFatalPolicy: {fatalPolicy}");
|
||||
|
||||
if (cpuContext != null)
|
||||
if (!cpuContext.IsEmpty)
|
||||
{
|
||||
errorReport.AppendLine("CPU Context:");
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
using Ryujinx.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend
|
||||
{
|
||||
[Service("friend:a", FriendServicePermissionLevel.Administrator)]
|
||||
[Service("friend:m", FriendServicePermissionLevel.Manager)]
|
||||
[Service("friend:s", FriendServicePermissionLevel.System)]
|
||||
[Service("friend:u", FriendServicePermissionLevel.User)]
|
||||
[Service("friend:v", FriendServicePermissionLevel.Viewer)]
|
||||
class IServiceCreator : IpcService
|
||||
{
|
||||
private readonly FriendServicePermissionLevel _permissionLevel;
|
||||
|
||||
public IServiceCreator(ServiceCtx context, FriendServicePermissionLevel permissionLevel)
|
||||
{
|
||||
_permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateFriendService() -> object<nn::friends::detail::ipc::IFriendService>
|
||||
public ResultCode CreateFriendService(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new IFriendService(_permissionLevel));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)] // 2.0.0+
|
||||
// CreateNotificationService(nn::account::Uid userId) -> object<nn::friends::detail::ipc::INotificationService>
|
||||
public ResultCode CreateNotificationService(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
MakeObject(context, new INotificationService(context, userId, _permissionLevel));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(2)] // 4.0.0+
|
||||
// CreateDaemonSuspendSessionService() -> object<nn::friends::detail::ipc::IDaemonSuspendSessionService>
|
||||
public ResultCode CreateDaemonSuspendSessionService(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new IDaemonSuspendSessionService(_permissionLevel));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Friend
|
||||
{
|
||||
enum ResultCode
|
||||
{
|
||||
ModuleId = 121,
|
||||
ErrorCodeShift = 9,
|
||||
|
||||
Success = 0,
|
||||
|
||||
InvalidArgument = (2 << ErrorCodeShift) | ModuleId,
|
||||
InternetRequestDenied = (6 << ErrorCodeShift) | ModuleId,
|
||||
NotificationQueueEmpty = (15 << ErrorCodeShift) | ModuleId,
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0x8, Size = 0x200, CharSet = CharSet.Ansi)]
|
||||
struct Friend
|
||||
{
|
||||
public UserId UserId;
|
||||
public long NetworkUserId;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x21)]
|
||||
public string Nickname;
|
||||
|
||||
public UserPresence presence;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsFavourite;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsNew;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x6)]
|
||||
readonly char[] Unknown;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsValid;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct FriendFilter
|
||||
{
|
||||
public PresenceStatusFilter PresenceStatus;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsFavoriteOnly;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsSameAppPresenceOnly;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsSameAppPlayedOnly;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsArbitraryAppPlayedOnly;
|
||||
|
||||
public long PresenceGroupId;
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService
|
||||
{
|
||||
enum PresenceStatus : uint
|
||||
{
|
||||
Offline,
|
||||
Online,
|
||||
OnlinePlay,
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService
|
||||
{
|
||||
enum PresenceStatusFilter : uint
|
||||
{
|
||||
None,
|
||||
Online,
|
||||
OnlinePlay,
|
||||
OnlineOrOnlinePlay,
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0x8)]
|
||||
struct UserPresence
|
||||
{
|
||||
public UserId UserId;
|
||||
public long LastTimeOnlineTimestamp;
|
||||
public PresenceStatus Status;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool SamePresenceGroupApplication;
|
||||
|
||||
public Array3<byte> Unknown;
|
||||
private AppKeyValueStorageHolder _appKeyValueStorage;
|
||||
|
||||
public Span<byte> AppKeyValueStorage => MemoryMarshal.Cast<AppKeyValueStorageHolder, byte>(MemoryMarshal.CreateSpan(ref _appKeyValueStorage, AppKeyValueStorageHolder.Size));
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0x1, Size = Size)]
|
||||
private struct AppKeyValueStorageHolder
|
||||
{
|
||||
public const int Size = 0xC0;
|
||||
}
|
||||
|
||||
public readonly override string ToString()
|
||||
{
|
||||
return $"UserPresence {{ UserId: {UserId}, LastTimeOnlineTimestamp: {LastTimeOnlineTimestamp}, Status: {Status} }}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
|
||||
{
|
||||
class IDaemonSuspendSessionService : IpcService
|
||||
{
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private readonly FriendServicePermissionLevel _permissionLevel;
|
||||
#pragma warning restore IDE0052
|
||||
|
||||
public IDaemonSuspendSessionService(FriendServicePermissionLevel permissionLevel)
|
||||
{
|
||||
_permissionLevel = permissionLevel;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,374 +0,0 @@
|
|||
using LibHac.Ns;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
|
||||
{
|
||||
class IFriendService : IpcService
|
||||
{
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private readonly FriendServicePermissionLevel _permissionLevel;
|
||||
#pragma warning restore IDE0052
|
||||
private KEvent _completionEvent;
|
||||
|
||||
public IFriendService(FriendServicePermissionLevel permissionLevel)
|
||||
{
|
||||
_permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
// GetCompletionEvent() -> handle<copy>
|
||||
public ResultCode GetCompletionEvent(ServiceCtx context)
|
||||
{
|
||||
_completionEvent ??= new KEvent(context.Device.System.KernelContext);
|
||||
|
||||
if (context.Process.HandleTable.GenerateHandle(_completionEvent.ReadableEvent, out int completionEventHandle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
_completionEvent.WritableEvent.Signal();
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(completionEventHandle);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
// nn::friends::Cancel()
|
||||
public ResultCode Cancel(ServiceCtx context)
|
||||
{
|
||||
// TODO: Original service sets an internal field to 1 here. Determine usage.
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10100)]
|
||||
// nn::friends::GetFriendListIds(int offset, nn::account::Uid userId, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid)
|
||||
// -> int outCount, array<nn::account::NetworkServiceAccountId, 0xa>
|
||||
public ResultCode GetFriendListIds(ServiceCtx context)
|
||||
{
|
||||
int offset = context.RequestData.ReadInt32();
|
||||
|
||||
// Padding
|
||||
context.RequestData.ReadInt32();
|
||||
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
|
||||
|
||||
// Pid placeholder
|
||||
context.RequestData.ReadInt64();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
|
||||
context.ResponseData.Write(0);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new
|
||||
{
|
||||
UserId = userId.ToString(),
|
||||
offset,
|
||||
filter.PresenceStatus,
|
||||
filter.IsFavoriteOnly,
|
||||
filter.IsSameAppPresenceOnly,
|
||||
filter.IsSameAppPlayedOnly,
|
||||
filter.IsArbitraryAppPlayedOnly,
|
||||
filter.PresenceGroupId,
|
||||
});
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10101)]
|
||||
// nn::friends::GetFriendList(int offset, nn::account::Uid userId, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid)
|
||||
// -> int outCount, array<nn::friends::detail::FriendImpl, 0x6>
|
||||
public ResultCode GetFriendList(ServiceCtx context)
|
||||
{
|
||||
int offset = context.RequestData.ReadInt32();
|
||||
|
||||
// Padding
|
||||
context.RequestData.ReadInt32();
|
||||
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
|
||||
|
||||
// Pid placeholder
|
||||
context.RequestData.ReadInt64();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
|
||||
context.ResponseData.Write(0);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new
|
||||
{
|
||||
UserId = userId.ToString(),
|
||||
offset,
|
||||
filter.PresenceStatus,
|
||||
filter.IsFavoriteOnly,
|
||||
filter.IsSameAppPresenceOnly,
|
||||
filter.IsSameAppPlayedOnly,
|
||||
filter.IsArbitraryAppPlayedOnly,
|
||||
filter.PresenceGroupId,
|
||||
});
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10120)] // 10.0.0+
|
||||
// nn::friends::IsFriendListCacheAvailable(nn::account::Uid userId) -> bool
|
||||
public ResultCode IsFriendListCacheAvailable(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// TODO: Service mount the friends:/ system savedata and try to load friend.cache file, returns true if exists, false otherwise.
|
||||
// NOTE: If no cache is available, guest then calls nn::friends::EnsureFriendListAvailable, we can avoid that by faking the cache check.
|
||||
context.ResponseData.Write(true);
|
||||
|
||||
// TODO: Since we don't support friend features, it's fine to stub it for now.
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10121)] // 10.0.0+
|
||||
// nn::friends::EnsureFriendListAvailable(nn::account::Uid userId)
|
||||
public ResultCode EnsureFriendListAvailable(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// TODO: Service mount the friends:/ system savedata and create a friend.cache file for the given user id.
|
||||
// Since we don't support friend features, it's fine to stub it for now.
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10400)]
|
||||
// nn::friends::GetBlockedUserListIds(int offset, nn::account::Uid userId) -> (u32, buffer<nn::account::NetworkServiceAccountId, 0xa>)
|
||||
public ResultCode GetBlockedUserListIds(ServiceCtx context)
|
||||
{
|
||||
int offset = context.RequestData.ReadInt32();
|
||||
|
||||
// Padding
|
||||
context.RequestData.ReadInt32();
|
||||
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
// There are no friends blocked, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
|
||||
context.ResponseData.Write(0);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { offset, UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10420)]
|
||||
// nn::friends::CheckBlockedUserListAvailability(nn::account::Uid userId) -> bool
|
||||
public ResultCode CheckBlockedUserListAvailability(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
// Yes, it is available.
|
||||
context.ResponseData.Write(true);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10600)]
|
||||
// nn::friends::DeclareOpenOnlinePlaySession(nn::account::Uid userId)
|
||||
public ResultCode DeclareOpenOnlinePlaySession(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
context.Device.System.AccountManager.OpenUserOnlinePlay(userId);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10601)]
|
||||
// nn::friends::DeclareCloseOnlinePlaySession(nn::account::Uid userId)
|
||||
public ResultCode DeclareCloseOnlinePlaySession(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
context.Device.System.AccountManager.CloseUserOnlinePlay(userId);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10610)]
|
||||
// nn::friends::UpdateUserPresence(nn::account::Uid, u64, pid, buffer<nn::friends::detail::UserPresenceImpl, 0x19>)
|
||||
public ResultCode UpdateUserPresence(ServiceCtx context)
|
||||
{
|
||||
UserId uuid = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
// Pid placeholder
|
||||
context.RequestData.ReadInt64();
|
||||
|
||||
ulong position = context.Request.PtrBuff[0].Position;
|
||||
ulong size = context.Request.PtrBuff[0].Size;
|
||||
|
||||
ReadOnlySpan<UserPresence> userPresenceInputArray = MemoryMarshal.Cast<byte, UserPresence>(context.Memory.GetSpan(position, (int)size));
|
||||
|
||||
if (uuid.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), userPresenceInputArray = userPresenceInputArray.ToArray() });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10700)]
|
||||
// nn::friends::GetPlayHistoryRegistrationKey(b8 unknown, nn::account::Uid) -> buffer<nn::friends::PlayHistoryRegistrationKey, 0x1a>
|
||||
public ResultCode GetPlayHistoryRegistrationKey(ServiceCtx context)
|
||||
{
|
||||
bool unknownBool = context.RequestData.ReadBoolean();
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x40UL);
|
||||
|
||||
ulong bufferPosition = context.Request.RecvListBuff[0].Position;
|
||||
|
||||
if (userId.IsNull)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// NOTE: Calls nn::friends::detail::service::core::PlayHistoryManager::GetInstance and stores the instance.
|
||||
|
||||
byte[] randomBytes = new byte[8];
|
||||
|
||||
Random.Shared.NextBytes(randomBytes);
|
||||
|
||||
// NOTE: Calls nn::friends::detail::service::core::UuidManager::GetInstance and stores the instance.
|
||||
// Then call nn::friends::detail::service::core::AccountStorageManager::GetInstance and store the instance.
|
||||
// Then it checks if an Uuid is already stored for the UserId, if not it generates a random Uuid.
|
||||
// And store it in the savedata 8000000000000080 in the friends:/uid.bin file.
|
||||
|
||||
Array16<byte> randomGuid = new();
|
||||
|
||||
Guid.NewGuid().ToByteArray().AsSpan().CopyTo(randomGuid.AsSpan());
|
||||
|
||||
PlayHistoryRegistrationKey playHistoryRegistrationKey = new()
|
||||
{
|
||||
Type = 0x101,
|
||||
KeyIndex = (byte)(randomBytes[0] & 7),
|
||||
UserIdBool = 0, // TODO: Find it.
|
||||
UnknownBool = (byte)(unknownBool ? 1 : 0), // TODO: Find it.
|
||||
Reserved = new Array11<byte>(),
|
||||
Uuid = randomGuid,
|
||||
};
|
||||
|
||||
ReadOnlySpan<byte> playHistoryRegistrationKeyBuffer = SpanHelpers.AsByteSpan(ref playHistoryRegistrationKey);
|
||||
|
||||
/*
|
||||
|
||||
NOTE: The service uses the KeyIndex to get a random key from a keys buffer (since the key index is stored in the returned buffer).
|
||||
We currently don't support play history and online services so we can use a blank key for now.
|
||||
Code for reference:
|
||||
|
||||
byte[] hmacKey = new byte[0x20];
|
||||
|
||||
HMACSHA256 hmacSha256 = new HMACSHA256(hmacKey);
|
||||
byte[] hmacHash = hmacSha256.ComputeHash(playHistoryRegistrationKeyBuffer);
|
||||
|
||||
*/
|
||||
|
||||
context.Memory.Write(bufferPosition, playHistoryRegistrationKeyBuffer);
|
||||
context.Memory.Write(bufferPosition + 0x20, new byte[0x20]); // HmacHash
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(10702)]
|
||||
// nn::friends::AddPlayHistory(nn::account::Uid, u64, pid, buffer<nn::friends::PlayHistoryRegistrationKey, 0x19>, buffer<nn::friends::InAppScreenName, 0x19>, buffer<nn::friends::InAppScreenName, 0x19>)
|
||||
public ResultCode AddPlayHistory(ServiceCtx context)
|
||||
{
|
||||
UserId userId = context.RequestData.ReadStruct<UserId>();
|
||||
|
||||
// Pid placeholder
|
||||
context.RequestData.ReadInt64();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong pid = context.Request.HandleDesc.PId;
|
||||
|
||||
ulong playHistoryRegistrationKeyPosition = context.Request.PtrBuff[0].Position;
|
||||
ulong playHistoryRegistrationKeySize = context.Request.PtrBuff[0].Size;
|
||||
|
||||
ulong inAppScreenName1Position = context.Request.PtrBuff[1].Position;
|
||||
#pragma warning restore IDE0059
|
||||
ulong inAppScreenName1Size = context.Request.PtrBuff[1].Size;
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong inAppScreenName2Position = context.Request.PtrBuff[2].Position;
|
||||
#pragma warning restore IDE0059
|
||||
ulong inAppScreenName2Size = context.Request.PtrBuff[2].Size;
|
||||
|
||||
if (userId.IsNull || inAppScreenName1Size > 0x48 || inAppScreenName2Size > 0x48)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
||||
// TODO: Call nn::arp::GetApplicationControlProperty here when implemented.
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ApplicationControlProperty controlProperty = context.Device.Processes.ActiveApplication.ApplicationControlProperties;
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
/*
|
||||
|
||||
NOTE: The service calls nn::friends::detail::service::core::PlayHistoryManager to store informations using the registration key computed in GetPlayHistoryRegistrationKey.
|
||||
Then calls nn::friends::detail::service::core::FriendListManager to update informations on the friend list.
|
||||
We currently don't support play history and online services so it's fine to do nothing.
|
||||
|
||||
*/
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceFriend);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
using Ryujinx.Common;
|
||||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
|
||||
{
|
||||
class INotificationService : DisposableIpcService
|
||||
{
|
||||
private readonly UserId _userId;
|
||||
private readonly FriendServicePermissionLevel _permissionLevel;
|
||||
|
||||
private readonly object _lock = new();
|
||||
|
||||
private readonly KEvent _notificationEvent;
|
||||
private int _notificationEventHandle = 0;
|
||||
|
||||
private readonly LinkedList<NotificationInfo> _notifications;
|
||||
|
||||
private bool _hasNewFriendRequest;
|
||||
private bool _hasFriendListUpdate;
|
||||
|
||||
public INotificationService(ServiceCtx context, UserId userId, FriendServicePermissionLevel permissionLevel)
|
||||
{
|
||||
_userId = userId;
|
||||
_permissionLevel = permissionLevel;
|
||||
_notifications = new LinkedList<NotificationInfo>();
|
||||
_notificationEvent = new KEvent(context.Device.System.KernelContext);
|
||||
|
||||
_hasNewFriendRequest = false;
|
||||
_hasFriendListUpdate = false;
|
||||
|
||||
NotificationEventHandler.Instance.RegisterNotificationService(this);
|
||||
}
|
||||
|
||||
[CommandCmif(0)] //2.0.0+
|
||||
// nn::friends::detail::ipc::INotificationService::GetEvent() -> handle<copy>
|
||||
public ResultCode GetEvent(ServiceCtx context)
|
||||
{
|
||||
if (_notificationEventHandle == 0)
|
||||
{
|
||||
if (context.Process.HandleTable.GenerateHandle(_notificationEvent.ReadableEvent, out _notificationEventHandle) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
}
|
||||
|
||||
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_notificationEventHandle);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)] //2.0.0+
|
||||
// nn::friends::detail::ipc::INotificationService::Clear()
|
||||
public ResultCode Clear(ServiceCtx context)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_hasNewFriendRequest = false;
|
||||
_hasFriendListUpdate = false;
|
||||
|
||||
_notifications.Clear();
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(2)] // 2.0.0+
|
||||
// nn::friends::detail::ipc::INotificationService::Pop() -> nn::friends::detail::ipc::SizedNotificationInfo
|
||||
public ResultCode Pop(ServiceCtx context)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_notifications.Count >= 1)
|
||||
{
|
||||
NotificationInfo notificationInfo = _notifications.First.Value;
|
||||
_notifications.RemoveFirst();
|
||||
|
||||
if (notificationInfo.Type == NotificationEventType.FriendListUpdate)
|
||||
{
|
||||
_hasFriendListUpdate = false;
|
||||
}
|
||||
else if (notificationInfo.Type == NotificationEventType.NewFriendRequest)
|
||||
{
|
||||
_hasNewFriendRequest = false;
|
||||
}
|
||||
|
||||
context.ResponseData.WriteStruct(notificationInfo);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
|
||||
return ResultCode.NotificationQueueEmpty;
|
||||
}
|
||||
|
||||
public void SignalFriendListUpdate(UserId targetId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_userId == targetId)
|
||||
{
|
||||
if (!_hasFriendListUpdate)
|
||||
{
|
||||
NotificationInfo friendListNotification = new();
|
||||
|
||||
if (_notifications.Count != 0)
|
||||
{
|
||||
friendListNotification = _notifications.First.Value;
|
||||
_notifications.RemoveFirst();
|
||||
}
|
||||
|
||||
friendListNotification.Type = NotificationEventType.FriendListUpdate;
|
||||
_hasFriendListUpdate = true;
|
||||
|
||||
if (_hasNewFriendRequest)
|
||||
{
|
||||
NotificationInfo newFriendRequestNotification = new();
|
||||
|
||||
if (_notifications.Count != 0)
|
||||
{
|
||||
newFriendRequestNotification = _notifications.First.Value;
|
||||
_notifications.RemoveFirst();
|
||||
}
|
||||
|
||||
newFriendRequestNotification.Type = NotificationEventType.NewFriendRequest;
|
||||
_notifications.AddFirst(newFriendRequestNotification);
|
||||
}
|
||||
|
||||
// We defer this to make sure we are on top of the queue.
|
||||
_notifications.AddFirst(friendListNotification);
|
||||
}
|
||||
|
||||
_notificationEvent.ReadableEvent.Signal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SignalNewFriendRequest(UserId targetId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if ((_permissionLevel & FriendServicePermissionLevel.ViewerMask) != 0 && _userId == targetId)
|
||||
{
|
||||
if (!_hasNewFriendRequest)
|
||||
{
|
||||
if (_notifications.Count == 100)
|
||||
{
|
||||
SignalFriendListUpdate(targetId);
|
||||
}
|
||||
|
||||
NotificationInfo newFriendRequestNotification = new()
|
||||
{
|
||||
Type = NotificationEventType.NewFriendRequest,
|
||||
};
|
||||
|
||||
_notifications.AddLast(newFriendRequestNotification);
|
||||
_hasNewFriendRequest = true;
|
||||
}
|
||||
|
||||
_notificationEvent.ReadableEvent.Signal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
NotificationEventHandler.Instance.UnregisterNotificationService(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService
|
||||
{
|
||||
public sealed class NotificationEventHandler
|
||||
{
|
||||
private static NotificationEventHandler _instance;
|
||||
private static readonly object _instanceLock = new();
|
||||
|
||||
private readonly INotificationService[] _registry;
|
||||
|
||||
public static NotificationEventHandler Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_instanceLock)
|
||||
{
|
||||
_instance ??= new NotificationEventHandler();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationEventHandler()
|
||||
{
|
||||
_registry = new INotificationService[0x20];
|
||||
}
|
||||
|
||||
internal void RegisterNotificationService(INotificationService service)
|
||||
{
|
||||
// NOTE: in case there isn't space anymore in the registry array, Nintendo doesn't return any errors.
|
||||
for (int i = 0; i < _registry.Length; i++)
|
||||
{
|
||||
if (_registry[i] == null)
|
||||
{
|
||||
_registry[i] = service;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void UnregisterNotificationService(INotificationService service)
|
||||
{
|
||||
// NOTE: in case there isn't the entry in the registry array, Nintendo doesn't return any errors.
|
||||
for (int i = 0; i < _registry.Length; i++)
|
||||
{
|
||||
if (_registry[i] == service)
|
||||
{
|
||||
_registry[i] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use this when we will have enough things to go online.
|
||||
public void SignalFriendListUpdate(UserId targetId)
|
||||
{
|
||||
for (int i = 0; i < _registry.Length; i++)
|
||||
{
|
||||
_registry[i]?.SignalFriendListUpdate(targetId);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use this when we will have enough things to go online.
|
||||
public void SignalNewFriendRequest(UserId targetId)
|
||||
{
|
||||
for (int i = 0; i < _registry.Length; i++)
|
||||
{
|
||||
_registry[i]?.SignalNewFriendRequest(targetId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService
|
||||
{
|
||||
enum NotificationEventType : uint
|
||||
{
|
||||
Invalid = 0x0,
|
||||
FriendListUpdate = 0x1,
|
||||
NewFriendRequest = 0x65,
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
|
||||
struct NotificationInfo
|
||||
{
|
||||
public NotificationEventType Type;
|
||||
private Array4<byte> _padding;
|
||||
public long NetworkUserIdPlaceholder;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
|
||||
{
|
||||
[Flags]
|
||||
enum FriendServicePermissionLevel
|
||||
{
|
||||
UserMask = 1,
|
||||
ViewerMask = 2,
|
||||
ManagerMask = 4,
|
||||
SystemMask = 8,
|
||||
|
||||
Administrator = -1,
|
||||
User = UserMask,
|
||||
Viewer = UserMask | ViewerMask,
|
||||
Manager = UserMask | ViewerMask | ManagerMask,
|
||||
System = UserMask | SystemMask,
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x20)]
|
||||
struct PlayHistoryRegistrationKey
|
||||
{
|
||||
public ushort Type;
|
||||
public byte KeyIndex;
|
||||
public byte UserIdBool;
|
||||
public byte UnknownBool;
|
||||
public Array11<byte> Reserved;
|
||||
public Array16<byte> Uuid;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using LibHac;
|
|||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Path = LibHac.FsSrv.Sf.Path;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
||||
|
@ -149,7 +150,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// Commit()
|
||||
public ResultCode Commit(ServiceCtx context)
|
||||
{
|
||||
return (ResultCode)_fileSystem.Get.Commit().Value;
|
||||
ResultCode resultCode = (ResultCode)_fileSystem.Get.Commit().Value;
|
||||
if (resultCode == ResultCode.PathAlreadyInUse)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceFs, "The file system is already in use by another process.");
|
||||
}
|
||||
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
[CommandCmif(11)]
|
||||
|
|
65
src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/LazyFile.cs
Normal file
65
src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/LazyFile.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using LibHac;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
||||
{
|
||||
class LazyFile : LibHac.Fs.Fsa.IFile
|
||||
{
|
||||
private readonly LibHac.Fs.Fsa.IFileSystem _fs;
|
||||
private readonly string _filePath;
|
||||
private readonly UniqueRef<LibHac.Fs.Fsa.IFile> _fileReference = new();
|
||||
private readonly FileInfo _fileInfo;
|
||||
|
||||
public LazyFile(string filePath, string prefix, LibHac.Fs.Fsa.IFileSystem fs)
|
||||
{
|
||||
_fs = fs;
|
||||
_filePath = filePath;
|
||||
_fileInfo = new FileInfo(prefix + "/" + filePath);
|
||||
}
|
||||
|
||||
private void PrepareFile()
|
||||
{
|
||||
if (_fileReference.Get == null)
|
||||
{
|
||||
_fs.OpenFile(ref _fileReference.Ref, _filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
PrepareFile();
|
||||
|
||||
return _fileReference.Get!.Read(out bytesRead, offset, destination);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override Result DoFlush()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override Result DoGetSize(out long size)
|
||||
{
|
||||
size = _fileInfo.Length;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
|||
newState.Buttons = (MouseButton)buttons;
|
||||
newState.X = mouseX;
|
||||
newState.Y = mouseY;
|
||||
newState.DeltaX = mouseX - previousEntry.DeltaX;
|
||||
newState.DeltaY = mouseY - previousEntry.DeltaY;
|
||||
newState.DeltaX = mouseX - previousEntry.X;
|
||||
newState.DeltaY = mouseY - previousEntry.Y;
|
||||
newState.WheelDeltaX = scrollX;
|
||||
newState.WheelDeltaY = scrollY;
|
||||
newState.Attributes = connected ? MouseAttribute.IsConnected : MouseAttribute.None;
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
|||
|
||||
private bool _sixAxisSensorFusionEnabled;
|
||||
private bool _unintendedHomeButtonInputProtectionEnabled;
|
||||
private bool _npadAnalogStickCenterClampEnabled;
|
||||
private bool _vibrationPermitted;
|
||||
private bool _usbFullKeyControllerEnabled;
|
||||
private readonly bool _isFirmwareUpdateAvailableForSixAxisSensor;
|
||||
|
@ -1107,6 +1108,19 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
|||
// If not, it returns nothing.
|
||||
}
|
||||
|
||||
[CommandCmif(134)] // 6.1.0+
|
||||
// SetNpadUseAnalogStickUseCenterClamp(bool Enable, nn::applet::AppletResourceUserId)
|
||||
public ResultCode SetNpadUseAnalogStickUseCenterClamp(ServiceCtx context)
|
||||
{
|
||||
ulong pid = context.RequestData.ReadUInt64();
|
||||
_npadAnalogStickCenterClampEnabled = context.RequestData.ReadUInt32() != 0;
|
||||
long appletResourceUserId = context.RequestData.ReadInt64();
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { pid, appletResourceUserId, _npadAnalogStickCenterClampEnabled });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(200)]
|
||||
// GetVibrationDeviceInfo(nn::hid::VibrationDeviceHandle) -> nn::hid::VibrationDeviceInfo
|
||||
public ResultCode GetVibrationDeviceInfo(ServiceCtx context)
|
||||
|
@ -1821,5 +1835,18 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
|||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1004)] // 17.0.0+
|
||||
// SetTouchScreenResolution(int width, int height, nn::applet::AppletResourceUserId)
|
||||
public ResultCode SetTouchScreenResolution(ServiceCtx context)
|
||||
{
|
||||
int width = context.RequestData.ReadInt32();
|
||||
int height = context.RequestData.ReadInt32();
|
||||
long appletResourceUserId = context.RequestData.ReadInt64();
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { width, height, appletResourceUserId });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue