2020-01-05 11:49:44 +00:00
using LibHac.Account ;
using LibHac.Common ;
2020-02-02 03:24:17 +00:00
using LibHac.Fs ;
2022-05-05 19:23:30 +01:00
using LibHac.Ncm ;
2020-01-05 11:49:44 +00:00
using LibHac.Ns ;
2023-03-02 02:42:27 +00:00
using LibHac.Tools.FsSystem.NcaUtils ;
2020-01-05 11:49:44 +00:00
using Ryujinx.Common ;
2018-10-17 18:15:50 +01:00
using Ryujinx.Common.Logging ;
2022-05-05 19:23:30 +01:00
using Ryujinx.HLE.Exceptions ;
2019-09-20 05:42:32 +01:00
using Ryujinx.HLE.HOS.Ipc ;
2020-02-11 23:07:13 +00:00
using Ryujinx.HLE.HOS.Kernel.Memory ;
2019-09-20 05:42:32 +01:00
using Ryujinx.HLE.HOS.Kernel.Threading ;
2019-09-19 01:45:11 +01:00
using Ryujinx.HLE.HOS.Services.Am.AppletAE.Storage ;
2020-09-21 04:45:30 +01:00
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types ;
2019-11-15 00:25:22 +00:00
using Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService ;
2020-05-27 09:40:23 +01:00
using Ryujinx.HLE.HOS.SystemState ;
2023-01-04 22:15:45 +00:00
using Ryujinx.Horizon.Common ;
2019-09-20 05:42:32 +01:00
using System ;
2020-05-27 09:40:23 +01:00
using System.Numerics ;
2022-05-05 19:23:30 +01:00
using System.Threading ;
2020-11-21 22:38:34 +00:00
using AccountUid = Ryujinx . HLE . HOS . Services . Account . Acc . UserId ;
2020-09-01 21:08:59 +01:00
using ApplicationId = LibHac . Ncm . ApplicationId ;
2020-01-05 11:49:44 +00:00
2019-09-19 01:45:11 +01:00
namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy
2018-02-04 23:08:20 +00:00
{
2018-03-19 18:58:46 +00:00
class IApplicationFunctions : IpcService
2018-02-04 23:08:20 +00:00
{
2022-11-18 03:29:01 +00:00
private long _defaultSaveDataSize = 200000000 ;
private long _defaultJournalSaveDataSize = 200000000 ;
2021-04-14 13:55:11 +01:00
2019-09-20 05:42:32 +01:00
private KEvent _gpuErrorDetectedSystemEvent ;
2020-05-12 15:52:27 +01:00
private KEvent _friendInvitationStorageChannelEvent ;
private KEvent _notificationStorageChannelEvent ;
2020-12-08 23:08:36 +00:00
private KEvent _healthWarningDisappearedSystemEvent ;
2019-09-20 05:42:32 +01:00
2020-12-01 23:23:43 +00:00
private int _gpuErrorDetectedSystemEventHandle ;
private int _friendInvitationStorageChannelEventHandle ;
private int _notificationStorageChannelEventHandle ;
2020-12-08 23:08:36 +00:00
private int _healthWarningDisappearedSystemEventHandle ;
2020-12-01 23:23:43 +00:00
2022-05-07 23:28:54 +01:00
private bool _gamePlayRecordingState ;
2022-05-05 19:23:30 +01:00
private int _jitLoaded ;
2023-01-04 22:15:45 +00:00
private LibHac . HorizonClient _horizon ;
2021-08-12 22:56:24 +01:00
2019-09-20 05:42:32 +01:00
public IApplicationFunctions ( Horizon system )
{
2020-12-08 23:08:36 +00:00
// TODO: Find where they are signaled.
2020-11-21 22:38:34 +00:00
_gpuErrorDetectedSystemEvent = new KEvent ( system . KernelContext ) ;
2020-05-12 15:52:27 +01:00
_friendInvitationStorageChannelEvent = new KEvent ( system . KernelContext ) ;
2020-11-21 22:38:34 +00:00
_notificationStorageChannelEvent = new KEvent ( system . KernelContext ) ;
2020-12-08 23:08:36 +00:00
_healthWarningDisappearedSystemEvent = new KEvent ( system . KernelContext ) ;
2021-08-12 22:56:24 +01:00
_horizon = system . LibHacHorizonManager . AmClient ;
2019-09-20 05:42:32 +01:00
}
2018-02-10 00:14:55 +00:00
2021-04-13 23:01:24 +01:00
[CommandHipc(1)]
2020-09-21 04:45:30 +01:00
// PopLaunchParameter(LaunchParameterKind kind) -> object<nn::am::service::IStorage>
2019-07-14 20:04:38 +01:00
public ResultCode PopLaunchParameter ( ServiceCtx context )
2018-02-04 23:08:20 +00:00
{
2020-09-21 04:45:30 +01:00
LaunchParameterKind kind = ( LaunchParameterKind ) context . RequestData . ReadUInt32 ( ) ;
byte [ ] storageData ;
switch ( kind )
{
case LaunchParameterKind . UserChannel :
2021-05-16 16:12:14 +01:00
storageData = context . Device . Configuration . UserChannelPersistence . Pop ( ) ;
2020-09-21 04:45:30 +01:00
break ;
case LaunchParameterKind . PreselectedUser :
// Only the first 0x18 bytes of the Data seems to be actually used.
2021-04-13 02:16:43 +01:00
storageData = StorageHelper . MakeLaunchParams ( context . Device . System . AccountManager . LastOpenedUser ) ;
2020-09-21 04:45:30 +01:00
break ;
2020-09-23 22:57:18 +01:00
case LaunchParameterKind . Unknown :
throw new NotImplementedException ( "Unknown LaunchParameterKind." ) ;
2020-09-21 04:45:30 +01:00
default :
2020-09-23 22:57:18 +01:00
return ResultCode . ObjectInvalid ;
}
if ( storageData = = null )
{
return ResultCode . NotAvailable ;
2020-09-21 04:45:30 +01:00
}
MakeObject ( context , new AppletAE . IStorage ( storageData ) ) ;
2018-02-04 23:08:20 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-02-04 23:08:20 +00:00
}
2021-07-10 22:37:29 +01:00
[CommandHipc(12)] // 4.0.0+
// CreateApplicationAndRequestToStart(u64 title_id)
public ResultCode CreateApplicationAndRequestToStart ( ServiceCtx context )
{
ulong titleId = context . RequestData . ReadUInt64 ( ) ;
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { titleId } ) ;
if ( titleId = = 0 )
{
context . Device . UiHandler . ExecuteProgram ( context . Device , ProgramSpecifyKind . RestartProgram , titleId ) ;
}
else
{
throw new NotImplementedException ( ) ;
}
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(20)]
2019-07-12 02:13:43 +01:00
// EnsureSaveData(nn::account::Uid) -> u64
2019-07-14 20:04:38 +01:00
public ResultCode EnsureSaveData ( ServiceCtx context )
2018-02-04 23:08:20 +00:00
{
2021-08-12 22:56:24 +01:00
Uid userId = context . RequestData . ReadStruct < AccountUid > ( ) . ToLibHacUid ( ) ;
// Mask out the low nibble of the program ID to get the application ID
2023-03-31 20:16:46 +01:00
ApplicationId applicationId = new ApplicationId ( context . Device . Processes . ActiveApplication . ProgramId & ~ 0xF ul ) ;
2018-04-17 01:24:42 +01:00
2023-03-31 20:16:46 +01:00
ApplicationControlProperty nacp = context . Device . Processes . ActiveApplication . ApplicationControlProperties ;
2020-01-05 11:49:44 +00:00
2023-01-04 22:15:45 +00:00
LibHac . HorizonClient hos = context . Device . System . LibHacHorizonManager . AmClient ;
2023-03-31 20:16:46 +01:00
LibHac . Result result = hos . Fs . EnsureApplicationSaveData ( out long requiredSize , applicationId , in nacp , in userId ) ;
2020-01-05 11:49:44 +00:00
context . ResponseData . Write ( requiredSize ) ;
return ( ResultCode ) result . Value ;
2018-02-04 23:08:20 +00:00
}
2021-04-13 23:01:24 +01:00
[CommandHipc(21)]
2019-07-12 02:13:43 +01:00
// GetDesiredLanguage() -> nn::settings::LanguageCode
2019-07-14 20:04:38 +01:00
public ResultCode GetDesiredLanguage ( ServiceCtx context )
2018-02-04 23:08:20 +00:00
{
2020-05-27 09:40:23 +01:00
// This seems to be calling ns:am GetApplicationDesiredLanguage followed by ConvertApplicationLanguageToLanguageCode
// Calls are from a IReadOnlyApplicationControlDataInterface object
// ConvertApplicationLanguageToLanguageCode compares language code strings and returns the index
// TODO: When above calls are implemented, switch to using ns:am
long desiredLanguageCode = context . Device . System . State . DesiredLanguageCode ;
2023-03-31 20:16:46 +01:00
int supportedLanguages = ( int ) context . Device . Processes . ActiveApplication . ApplicationControlProperties . SupportedLanguageFlag ;
2020-11-21 22:38:34 +00:00
int firstSupported = BitOperations . TrailingZeroCount ( supportedLanguages ) ;
2020-05-27 09:40:23 +01:00
2022-12-10 20:21:13 +00:00
if ( firstSupported > ( int ) TitleLanguage . BrazilianPortuguese )
2020-05-27 09:40:23 +01:00
{
2020-08-04 00:32:53 +01:00
Logger . Warning ? . Print ( LogClass . ServiceAm , "Application has zero supported languages" ) ;
2020-05-27 09:40:23 +01:00
context . ResponseData . Write ( desiredLanguageCode ) ;
return ResultCode . Success ;
}
2020-12-01 23:23:43 +00:00
// If desired language is not supported by application, use first supported language from TitleLanguage.
2020-05-27 09:40:23 +01:00
// TODO: In the future, a GUI could enable user-specified search priority
if ( ( ( 1 < < ( int ) context . Device . System . State . DesiredTitleLanguage ) & supportedLanguages ) = = 0 )
{
2022-12-10 20:21:13 +00:00
SystemLanguage newLanguage = Enum . Parse < SystemLanguage > ( Enum . GetName ( typeof ( TitleLanguage ) , firstSupported ) ) ;
2020-05-27 09:40:23 +01:00
desiredLanguageCode = SystemStateMgr . GetLanguageCode ( ( int ) newLanguage ) ;
2020-08-04 00:32:53 +01:00
Logger . Info ? . Print ( LogClass . ServiceAm , $"Application doesn't support configured language. Using {newLanguage}" ) ;
2020-05-27 09:40:23 +01:00
}
context . ResponseData . Write ( desiredLanguageCode ) ;
2018-02-04 23:08:20 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-02-04 23:08:20 +00:00
}
2021-04-13 23:01:24 +01:00
[CommandHipc(22)]
2019-07-12 02:13:43 +01:00
// SetTerminateResult(u32)
2019-07-14 20:04:38 +01:00
public ResultCode SetTerminateResult ( ServiceCtx context )
2018-02-25 18:58:16 +00:00
{
2023-01-04 22:15:45 +00:00
LibHac . Result result = new LibHac . Result ( context . RequestData . ReadUInt32 ( ) ) ;
2018-02-25 18:58:16 +00:00
2020-08-04 00:32:53 +01:00
Logger . Info ? . Print ( LogClass . ServiceAm , $"Result = 0x{result.Value:x8} ({result.ToStringWithName()})." ) ;
2018-02-25 18:58:16 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-02-25 18:58:16 +00:00
}
2021-04-13 23:01:24 +01:00
[CommandHipc(23)]
2019-07-12 02:13:43 +01:00
// GetDisplayVersion() -> nn::oe::DisplayVersion
2019-07-14 20:04:38 +01:00
public ResultCode GetDisplayVersion ( ServiceCtx context )
2018-04-22 05:21:49 +01:00
{
2020-05-27 09:22:50 +01:00
// If an NACP isn't found, the buffer will be all '\0' which seems to be the correct implementation.
2023-03-31 20:16:46 +01:00
context . ResponseData . Write ( context . Device . Processes . ActiveApplication . ApplicationControlProperties . DisplayVersion ) ;
2018-04-22 05:21:49 +01:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-04-22 05:21:49 +01:00
}
2021-04-14 13:55:11 +01:00
[CommandHipc(25)] // 3.0.0+
2022-11-18 03:29:01 +00:00
// ExtendSaveData(u8 save_data_type, nn::account::Uid, s64 save_size, s64 journal_size) -> u64 result_code
2021-04-14 13:55:11 +01:00
public ResultCode ExtendSaveData ( ServiceCtx context )
{
SaveDataType saveDataType = ( SaveDataType ) context . RequestData . ReadUInt64 ( ) ;
2021-08-12 22:56:24 +01:00
Uid userId = context . RequestData . ReadStruct < Uid > ( ) ;
2022-11-18 03:29:01 +00:00
long saveDataSize = context . RequestData . ReadInt64 ( ) ;
long journalSize = context . RequestData . ReadInt64 ( ) ;
2021-04-14 13:55:11 +01:00
// NOTE: Service calls nn::fs::ExtendApplicationSaveData.
// Since LibHac currently doesn't support this method, we can stub it for now.
_defaultSaveDataSize = saveDataSize ;
_defaultJournalSaveDataSize = journalSize ;
context . ResponseData . Write ( ( uint ) ResultCode . Success ) ;
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { saveDataType , userId , saveDataSize , journalSize } ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(26)] // 3.0.0+
2022-11-18 03:29:01 +00:00
// GetSaveDataSize(u8 save_data_type, nn::account::Uid) -> (s64 save_size, s64 journal_size)
2020-02-02 03:24:17 +00:00
public ResultCode GetSaveDataSize ( ServiceCtx context )
{
2020-11-24 19:45:23 +00:00
SaveDataType saveDataType = ( SaveDataType ) context . RequestData . ReadUInt64 ( ) ;
2021-08-12 22:56:24 +01:00
Uid userId = context . RequestData . ReadStruct < Uid > ( ) ;
2020-11-21 22:38:34 +00:00
2020-11-24 19:45:23 +00:00
// NOTE: Service calls nn::fs::FindSaveDataWithFilter with SaveDataType = 1 hardcoded.
// Then it calls nn::fs::GetSaveDataAvailableSize and nn::fs::GetSaveDataJournalSize to get the sizes.
// Since LibHac currently doesn't support the 2 last methods, we can hardcode the values to 200mb.
2020-02-02 03:24:17 +00:00
2021-04-14 13:55:11 +01:00
context . ResponseData . Write ( _defaultSaveDataSize ) ;
context . ResponseData . Write ( _defaultJournalSaveDataSize ) ;
2020-02-02 03:24:17 +00:00
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { saveDataType , userId } ) ;
2020-02-02 03:24:17 +00:00
return ResultCode . Success ;
}
2021-08-12 22:56:24 +01:00
[CommandHipc(27)] // 5.0.0+
// CreateCacheStorage(u16 index, s64 save_size, s64 journal_size) -> (u32 storageTarget, u64 requiredSize)
public ResultCode CreateCacheStorage ( ServiceCtx context )
{
ushort index = ( ushort ) context . RequestData . ReadUInt64 ( ) ;
long saveSize = context . RequestData . ReadInt64 ( ) ;
long journalSize = context . RequestData . ReadInt64 ( ) ;
// Mask out the low nibble of the program ID to get the application ID
2023-03-31 20:16:46 +01:00
ApplicationId applicationId = new ApplicationId ( context . Device . Processes . ActiveApplication . ProgramId & ~ 0xF ul ) ;
2021-08-12 22:56:24 +01:00
2023-03-31 20:16:46 +01:00
ApplicationControlProperty nacp = context . Device . Processes . ActiveApplication . ApplicationControlProperties ;
2021-08-12 22:56:24 +01:00
2023-01-04 22:15:45 +00:00
LibHac . Result result = _horizon . Fs . CreateApplicationCacheStorage ( out long requiredSize ,
2023-03-31 20:16:46 +01:00
out CacheStorageTargetMedia storageTarget , applicationId , in nacp , index , saveSize , journalSize ) ;
2021-08-12 22:56:24 +01:00
if ( result . IsFailure ( ) ) return ( ResultCode ) result . Value ;
context . ResponseData . Write ( ( ulong ) storageTarget ) ;
context . ResponseData . Write ( requiredSize ) ;
return ResultCode . Success ;
}
2022-11-18 03:29:01 +00:00
[CommandHipc(28)] // 11.0.0+
// GetSaveDataSizeMax() -> (s64 save_size_max, s64 journal_size_max)
public ResultCode GetSaveDataSizeMax ( ServiceCtx context )
{
// NOTE: We are currently using a stub for GetSaveDataSize() which returns the default values.
// For this method we shouldn't return anything lower than that, but since we aren't interacting
// with fs to get the actual sizes, we return the default values here as well.
// This also helps in case ExtendSaveData() has been executed and the default values were modified.
context . ResponseData . Write ( _defaultSaveDataSize ) ;
context . ResponseData . Write ( _defaultJournalSaveDataSize ) ;
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(30)]
2020-09-20 04:40:10 +01:00
// BeginBlockingHomeButtonShortAndLongPressed()
public ResultCode BeginBlockingHomeButtonShortAndLongPressed ( ServiceCtx context )
{
// NOTE: This set two internal fields at offsets 0x89 and 0x8B to value 1 then it signals an internal event.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(31)]
2020-09-20 04:40:10 +01:00
// EndBlockingHomeButtonShortAndLongPressed()
public ResultCode EndBlockingHomeButtonShortAndLongPressed ( ServiceCtx context )
{
// NOTE: This set two internal fields at offsets 0x89 and 0x8B to value 0 then it signals an internal event.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(32)] // 2.0.0+
2020-09-20 04:40:10 +01:00
// BeginBlockingHomeButton(u64 nano_second)
public ResultCode BeginBlockingHomeButton ( ServiceCtx context )
{
ulong nanoSeconds = context . RequestData . ReadUInt64 ( ) ;
// NOTE: This set two internal fields at offsets 0x89 to value 1 and 0x90 to value of "nanoSeconds" then it signals an internal event.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { nanoSeconds } ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(33)] // 2.0.0+
2020-09-20 04:40:10 +01:00
// EndBlockingHomeButton()
public ResultCode EndBlockingHomeButton ( ServiceCtx context )
{
// NOTE: This set two internal fields at offsets 0x89 and 0x90 to value 0 then it signals an internal event.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(40)]
2019-07-12 02:13:43 +01:00
// NotifyRunning() -> b8
2019-07-14 20:04:38 +01:00
public ResultCode NotifyRunning ( ServiceCtx context )
2018-02-06 23:28:32 +00:00
{
2020-07-22 05:56:00 +01:00
context . ResponseData . Write ( true ) ;
2018-02-06 23:28:32 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-02-06 23:28:32 +00:00
}
2021-04-13 23:01:24 +01:00
[CommandHipc(50)] // 2.0.0+
2019-07-12 02:13:43 +01:00
// GetPseudoDeviceId() -> nn::util::Uuid
2019-07-14 20:04:38 +01:00
public ResultCode GetPseudoDeviceId ( ServiceCtx context )
2018-05-25 22:33:09 +01:00
{
2018-12-06 11:16:24 +00:00
context . ResponseData . Write ( 0L ) ;
context . ResponseData . Write ( 0L ) ;
2018-05-25 22:33:09 +01:00
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
2019-11-15 00:25:22 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-05-25 22:33:09 +01:00
}
2021-12-30 10:25:46 +00:00
[CommandHipc(60)] // 2.0.0+
// SetMediaPlaybackStateForApplication(bool enabled)
public ResultCode SetMediaPlaybackStateForApplication ( ServiceCtx context )
{
bool enabled = context . RequestData . ReadBoolean ( ) ;
// NOTE: Service stores the "enabled" value in a private field, when enabled is false, it stores nn::os::GetSystemTick() too.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { enabled } ) ;
return ResultCode . Success ;
}
2022-05-07 23:28:54 +01:00
[CommandHipc(65)] // 3.0.0+
// IsGamePlayRecordingSupported() -> u8
public ResultCode IsGamePlayRecordingSupported ( ServiceCtx context )
{
context . ResponseData . Write ( _gamePlayRecordingState ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(66)] // 3.0.0+
2019-07-12 02:13:43 +01:00
// InitializeGamePlayRecording(u64, handle<copy>)
2019-07-14 20:04:38 +01:00
public ResultCode InitializeGamePlayRecording ( ServiceCtx context )
2018-02-04 23:08:20 +00:00
{
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
2018-02-04 23:08:20 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-06-02 23:46:09 +01:00
}
2018-02-04 23:08:20 +00:00
2021-04-13 23:01:24 +01:00
[CommandHipc(67)] // 3.0.0+
2019-07-12 02:13:43 +01:00
// SetGamePlayRecordingState(u32)
2019-07-14 20:04:38 +01:00
public ResultCode SetGamePlayRecordingState ( ServiceCtx context )
2018-06-02 23:46:09 +01:00
{
2022-05-07 23:28:54 +01:00
_gamePlayRecordingState = context . RequestData . ReadInt32 ( ) ! = 0 ;
2018-06-02 23:46:09 +01:00
2022-05-07 23:28:54 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { _gamePlayRecordingState } ) ;
2018-02-04 23:08:20 +00:00
2019-07-14 20:04:38 +01:00
return ResultCode . Success ;
2018-02-04 23:08:20 +00:00
}
2019-09-20 05:42:32 +01:00
2021-04-13 23:01:24 +01:00
[CommandHipc(90)] // 4.0.0+
2020-07-22 05:56:00 +01:00
// EnableApplicationCrashReport(u8)
public ResultCode EnableApplicationCrashReport ( ServiceCtx context )
{
bool applicationCrashReportEnabled = context . RequestData . ReadBoolean ( ) ;
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { applicationCrashReportEnabled } ) ;
2020-07-22 05:56:00 +01:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(100)] // 5.0.0+
2020-02-11 23:07:13 +00:00
// InitializeApplicationCopyrightFrameBuffer(s32 width, s32 height, handle<copy, transfer_memory> transfer_memory, u64 transfer_memory_size)
public ResultCode InitializeApplicationCopyrightFrameBuffer ( ServiceCtx context )
{
2020-11-21 22:38:34 +00:00
int width = context . RequestData . ReadInt32 ( ) ;
int height = context . RequestData . ReadInt32 ( ) ;
ulong transferMemorySize = context . RequestData . ReadUInt64 ( ) ;
int transferMemoryHandle = context . Request . HandleDesc . ToCopy [ 0 ] ;
2020-02-11 23:07:13 +00:00
ulong transferMemoryAddress = context . Process . HandleTable . GetObject < KTransferMemory > ( transferMemoryHandle ) . Address ;
ResultCode resultCode = ResultCode . InvalidParameters ;
if ( ( ( transferMemorySize & 0x3FFFF ) = = 0 ) & & width < = 1280 & & height < = 720 )
{
resultCode = InitializeApplicationCopyrightFrameBufferImpl ( transferMemoryAddress , transferMemorySize , width , height ) ;
}
2020-12-01 23:23:43 +00:00
if ( transferMemoryHandle ! = 0 )
2020-02-11 23:07:13 +00:00
{
2020-12-01 23:23:43 +00:00
context . Device . System . KernelContext . Syscall . CloseHandle ( transferMemoryHandle ) ;
2020-02-11 23:07:13 +00:00
}
return resultCode ;
}
private ResultCode InitializeApplicationCopyrightFrameBufferImpl ( ulong transferMemoryAddress , ulong transferMemorySize , int width , int height )
{
if ( ( transferMemorySize & 0x3FFFF ) ! = 0 )
{
return ResultCode . InvalidParameters ;
}
2020-11-21 22:38:34 +00:00
ResultCode resultCode ;
2020-02-11 23:07:13 +00:00
// if (_copyrightBuffer == null)
{
// TODO: Initialize buffer and object.
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { transferMemoryAddress , transferMemorySize , width , height } ) ;
2020-02-11 23:07:13 +00:00
resultCode = ResultCode . Success ;
}
return resultCode ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(101)] // 5.0.0+
2020-02-11 23:07:13 +00:00
// SetApplicationCopyrightImage(buffer<bytes, 0x45> frame_buffer, s32 x, s32 y, s32 width, s32 height, s32 window_origin_mode)
public ResultCode SetApplicationCopyrightImage ( ServiceCtx context )
{
2021-04-24 11:16:01 +01:00
ulong frameBufferPos = context . Request . SendBuff [ 0 ] . Position ;
ulong frameBufferSize = context . Request . SendBuff [ 0 ] . Size ;
int x = context . RequestData . ReadInt32 ( ) ;
int y = context . RequestData . ReadInt32 ( ) ;
int width = context . RequestData . ReadInt32 ( ) ;
int height = context . RequestData . ReadInt32 ( ) ;
uint windowOriginMode = context . RequestData . ReadUInt32 ( ) ;
2020-02-11 23:07:13 +00:00
ResultCode resultCode = ResultCode . InvalidParameters ;
if ( ( ( y | x ) > = 0 ) & & width > = 1 & & height > = 1 )
{
ResultCode result = SetApplicationCopyrightImageImpl ( x , y , width , height , frameBufferPos , frameBufferSize , windowOriginMode ) ;
2020-09-01 21:08:59 +01:00
if ( result ! = ResultCode . Success )
2020-02-11 23:07:13 +00:00
{
resultCode = result ;
}
else
{
resultCode = ResultCode . Success ;
}
}
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { frameBufferPos , frameBufferSize , x , y , width , height , windowOriginMode } ) ;
2020-02-11 23:07:13 +00:00
return resultCode ;
}
2021-04-24 11:16:01 +01:00
private ResultCode SetApplicationCopyrightImageImpl ( int x , int y , int width , int height , ulong frameBufferPos , ulong frameBufferSize , uint windowOriginMode )
2020-02-11 23:07:13 +00:00
{
/ *
if ( _copyrightBuffer = = null )
{
return ResultCode . NullCopyrightObject ;
}
* /
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { x , y , width , height , frameBufferPos , frameBufferSize , windowOriginMode } ) ;
2020-02-11 23:07:13 +00:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(102)] // 5.0.0+
2020-02-11 23:07:13 +00:00
// SetApplicationCopyrightVisibility(bool visible)
public ResultCode SetApplicationCopyrightVisibility ( ServiceCtx context )
{
bool visible = context . RequestData . ReadBoolean ( ) ;
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { visible } ) ;
2020-02-11 23:07:13 +00:00
// NOTE: It sets an internal field and return ResultCode.Success in all case.
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(110)] // 5.0.0+
2019-11-15 00:25:22 +00:00
// QueryApplicationPlayStatistics(buffer<bytes, 5> title_id_list) -> (buffer<bytes, 6> entries, s32 entries_count)
public ResultCode QueryApplicationPlayStatistics ( ServiceCtx context )
{
// TODO: Call pdm:qry cmd 13 when IPC call between services will be implemented.
return ( ResultCode ) QueryPlayStatisticsManager . GetPlayStatistics ( context ) ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(111)] // 6.0.0+
2019-11-15 00:25:22 +00:00
// QueryApplicationPlayStatisticsByUid(nn::account::Uid, buffer<bytes, 5> title_id_list) -> (buffer<bytes, 6> entries, s32 entries_count)
public ResultCode QueryApplicationPlayStatisticsByUid ( ServiceCtx context )
{
// TODO: Call pdm:qry cmd 16 when IPC call between services will be implemented.
return ( ResultCode ) QueryPlayStatisticsManager . GetPlayStatistics ( context , true ) ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(120)] // 5.0.0+
2020-09-21 04:45:30 +01:00
// ExecuteProgram(ProgramSpecifyKind kind, u64 value)
public ResultCode ExecuteProgram ( ServiceCtx context )
{
ProgramSpecifyKind kind = ( ProgramSpecifyKind ) context . RequestData . ReadUInt32 ( ) ;
// padding
context . RequestData . ReadUInt32 ( ) ;
ulong value = context . RequestData . ReadUInt64 ( ) ;
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { kind , value } ) ;
context . Device . UiHandler . ExecuteProgram ( context . Device , kind , value ) ;
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(121)] // 5.0.0+
2020-09-21 04:45:30 +01:00
// ClearUserChannel()
public ResultCode ClearUserChannel ( ServiceCtx context )
{
2021-05-16 16:12:14 +01:00
context . Device . Configuration . UserChannelPersistence . Clear ( ) ;
2020-09-21 04:45:30 +01:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(122)] // 5.0.0+
2020-09-21 04:45:30 +01:00
// UnpopToUserChannel(object<nn::am::service::IStorage> input_storage)
public ResultCode UnpopToUserChannel ( ServiceCtx context )
{
AppletAE . IStorage data = GetObject < AppletAE . IStorage > ( context , 0 ) ;
2021-05-16 16:12:14 +01:00
context . Device . Configuration . UserChannelPersistence . Push ( data . Data ) ;
2020-09-21 04:45:30 +01:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(123)] // 5.0.0+
2020-07-22 05:56:00 +01:00
// GetPreviousProgramIndex() -> s32 program_index
public ResultCode GetPreviousProgramIndex ( ServiceCtx context )
{
2021-05-16 16:12:14 +01:00
int previousProgramIndex = context . Device . Configuration . UserChannelPersistence . PreviousIndex ;
2020-07-22 05:56:00 +01:00
context . ResponseData . Write ( previousProgramIndex ) ;
2020-08-04 00:32:53 +01:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAm , new { previousProgramIndex } ) ;
2020-07-22 05:56:00 +01:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(130)] // 8.0.0+
2019-09-20 05:42:32 +01:00
// GetGpuErrorDetectedSystemEvent() -> handle<copy>
public ResultCode GetGpuErrorDetectedSystemEvent ( ServiceCtx context )
{
2020-12-01 23:23:43 +00:00
if ( _gpuErrorDetectedSystemEventHandle = = 0 )
2019-09-20 05:42:32 +01:00
{
2023-01-04 22:15:45 +00:00
if ( context . Process . HandleTable . GenerateHandle ( _gpuErrorDetectedSystemEvent . ReadableEvent , out _gpuErrorDetectedSystemEventHandle ) ! = Result . Success )
2020-12-01 23:23:43 +00:00
{
throw new InvalidOperationException ( "Out of handles!" ) ;
}
2019-09-20 05:42:32 +01:00
}
2020-12-01 23:23:43 +00:00
context . Response . HandleDesc = IpcHandleDesc . MakeCopy ( _gpuErrorDetectedSystemEventHandle ) ;
2019-09-20 05:42:32 +01:00
2020-12-01 23:23:43 +00:00
// NOTE: This is used by "sdk" NSO during applet-application initialization.
2021-08-12 22:56:24 +01:00
// A separate thread is setup where event-waiting is handled.
2019-09-20 05:42:32 +01:00
// When the Event is signaled, official sw will assert.
return ResultCode . Success ;
}
2020-05-12 15:52:27 +01:00
2021-04-13 23:01:24 +01:00
[CommandHipc(140)] // 9.0.0+
2020-05-12 15:52:27 +01:00
// GetFriendInvitationStorageChannelEvent() -> handle<copy>
public ResultCode GetFriendInvitationStorageChannelEvent ( ServiceCtx context )
{
2020-12-01 23:23:43 +00:00
if ( _friendInvitationStorageChannelEventHandle = = 0 )
2020-05-12 15:52:27 +01:00
{
2023-01-04 22:15:45 +00:00
if ( context . Process . HandleTable . GenerateHandle ( _friendInvitationStorageChannelEvent . ReadableEvent , out _friendInvitationStorageChannelEventHandle ) ! = Result . Success )
2020-12-01 23:23:43 +00:00
{
throw new InvalidOperationException ( "Out of handles!" ) ;
}
2020-05-12 15:52:27 +01:00
}
2020-12-01 23:23:43 +00:00
context . Response . HandleDesc = IpcHandleDesc . MakeCopy ( _friendInvitationStorageChannelEventHandle ) ;
2020-05-12 15:52:27 +01:00
return ResultCode . Success ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(141)] // 9.0.0+
2020-11-21 22:38:34 +00:00
// TryPopFromFriendInvitationStorageChannel() -> object<nn::am::service::IStorage>
public ResultCode TryPopFromFriendInvitationStorageChannel ( ServiceCtx context )
{
// NOTE: IStorage are pushed in the channel with IApplicationAccessor PushToFriendInvitationStorageChannel
// If _friendInvitationStorageChannelEvent is signaled, the event is cleared.
2021-10-28 22:06:45 +01:00
// If an IStorage is available, returns it with ResultCode.Success.
2020-11-21 22:38:34 +00:00
// If not, just returns ResultCode.NotAvailable. Since we don't support friend feature for now, it's fine to do the same.
Logger . Stub ? . PrintStub ( LogClass . ServiceAm ) ;
return ResultCode . NotAvailable ;
}
2021-04-13 23:01:24 +01:00
[CommandHipc(150)] // 9.0.0+
2020-05-12 15:52:27 +01:00
// GetNotificationStorageChannelEvent() -> handle<copy>
public ResultCode GetNotificationStorageChannelEvent ( ServiceCtx context )
{
2020-12-01 23:23:43 +00:00
if ( _notificationStorageChannelEventHandle = = 0 )
2020-05-12 15:52:27 +01:00
{
2023-01-04 22:15:45 +00:00
if ( context . Process . HandleTable . GenerateHandle ( _notificationStorageChannelEvent . ReadableEvent , out _notificationStorageChannelEventHandle ) ! = Result . Success )
2020-12-01 23:23:43 +00:00
{
throw new InvalidOperationException ( "Out of handles!" ) ;
}
2020-05-12 15:52:27 +01:00
}
2020-12-01 23:23:43 +00:00
context . Response . HandleDesc = IpcHandleDesc . MakeCopy ( _notificationStorageChannelEventHandle ) ;
2020-05-12 15:52:27 +01:00
return ResultCode . Success ;
}
2020-12-08 23:08:36 +00:00
2021-04-13 23:01:24 +01:00
[CommandHipc(160)] // 9.0.0+
2020-12-08 23:08:36 +00:00
// GetHealthWarningDisappearedSystemEvent() -> handle<copy>
public ResultCode GetHealthWarningDisappearedSystemEvent ( ServiceCtx context )
{
if ( _healthWarningDisappearedSystemEventHandle = = 0 )
{
2023-01-04 22:15:45 +00:00
if ( context . Process . HandleTable . GenerateHandle ( _healthWarningDisappearedSystemEvent . ReadableEvent , out _healthWarningDisappearedSystemEventHandle ) ! = Result . Success )
2020-12-08 23:08:36 +00:00
{
throw new InvalidOperationException ( "Out of handles!" ) ;
}
}
context . Response . HandleDesc = IpcHandleDesc . MakeCopy ( _healthWarningDisappearedSystemEventHandle ) ;
return ResultCode . Success ;
}
2022-05-05 19:23:30 +01:00
[CommandHipc(1001)] // 10.0.0+
// PrepareForJit()
public ResultCode PrepareForJit ( ServiceCtx context )
{
if ( Interlocked . Exchange ( ref _jitLoaded , 1 ) = = 0 )
{
string jitPath = context . Device . System . ContentManager . GetInstalledContentPath ( 0x010000000000003B , StorageId . BuiltInSystem , NcaContentType . Program ) ;
string filePath = context . Device . FileSystem . SwitchPathToSystemPath ( jitPath ) ;
if ( string . IsNullOrWhiteSpace ( filePath ) )
{
throw new InvalidSystemResourceException ( $"JIT (010000000000003B) system title not found! The JIT will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx#requirements for more information)" ) ;
}
2023-03-31 20:16:46 +01:00
context . Device . LoadNca ( filePath ) ;
2022-05-05 19:23:30 +01:00
// FIXME: Most likely not how this should be done?
while ( ! context . Device . System . SmRegistry . IsServiceRegistered ( "jit:u" ) )
{
context . Device . System . SmRegistry . WaitForServiceRegistration ( ) ;
}
}
return ResultCode . Success ;
}
2018-02-04 23:08:20 +00:00
}
2019-07-12 02:13:43 +01:00
}