2020-02-01 22:24:17 -05:00
using Ryujinx.Common ;
2018-10-17 13:15:50 -04:00
using Ryujinx.Common.Logging ;
2020-05-03 18:54:50 -04:00
using Ryujinx.Cpu ;
2019-09-18 20:45:11 -04:00
using Ryujinx.HLE.HOS.Services.Arp ;
2018-02-24 23:34:16 -05:00
using System.Collections.Generic ;
2019-09-18 20:45:11 -04:00
namespace Ryujinx.HLE.HOS.Services.Account.Acc
2018-02-24 23:34:16 -05:00
{
2019-07-10 11:59:54 -04:00
[Service("acc:u0")]
2019-09-18 20:45:11 -04:00
class IAccountServiceForApplication : IpcService
2018-02-24 23:34:16 -05:00
{
2019-06-15 18:35:38 -04:00
private bool _userRegistrationRequestPermitted = false ;
private ApplicationLaunchProperty _applicationLaunchProperty ;
2019-09-18 20:45:11 -04:00
public IAccountServiceForApplication ( ServiceCtx context ) { }
2018-02-24 23:34:16 -05:00
2019-07-11 21:13:43 -04:00
[Command(0)]
2018-10-13 19:16:02 -04:00
// GetUserCount() -> i32
2019-07-14 15:04:38 -04:00
public ResultCode GetUserCount ( ServiceCtx context )
2018-04-17 12:41:14 -04:00
{
2019-06-15 18:35:38 -04:00
context . ResponseData . Write ( context . Device . System . State . Account . GetUserCount ( ) ) ;
2018-04-17 12:41:14 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-04-17 12:41:14 -04:00
}
2018-06-10 20:46:42 -04:00
2019-07-11 21:13:43 -04:00
[Command(1)]
2018-10-13 19:16:02 -04:00
// GetUserExistence(nn::account::Uid) -> bool
2019-07-14 15:04:38 -04:00
public ResultCode GetUserExistence ( ServiceCtx context )
2018-06-10 00:36:07 -04:00
{
2020-02-01 22:24:17 -05:00
UserId userId = context . RequestData . ReadStruct < UserId > ( ) ;
2019-06-15 18:35:38 -04:00
if ( userId . IsNull )
{
2019-07-14 15:04:38 -04:00
return ResultCode . NullArgument ;
2019-06-15 18:35:38 -04:00
}
2018-06-10 00:36:07 -04:00
2019-06-15 18:35:38 -04:00
context . ResponseData . Write ( context . Device . System . State . Account . TryGetUser ( userId , out _ ) ) ;
2018-06-10 00:36:07 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-06-10 00:36:07 -04:00
}
2018-04-17 12:41:14 -04:00
2019-07-11 21:13:43 -04:00
[Command(2)]
2018-10-13 19:16:02 -04:00
// ListAllUsers() -> array<nn::account::Uid, 0xa>
2019-07-14 15:04:38 -04:00
public ResultCode ListAllUsers ( ServiceCtx context )
2018-06-10 00:36:07 -04:00
{
2019-06-15 18:35:38 -04:00
return WriteUserList ( context , context . Device . System . State . Account . GetAllUsers ( ) ) ;
2018-06-10 00:36:07 -04:00
}
2018-06-10 20:46:42 -04:00
2019-07-11 21:13:43 -04:00
[Command(3)]
2018-10-13 19:16:02 -04:00
// ListOpenUsers() -> array<nn::account::Uid, 0xa>
2019-07-14 15:04:38 -04:00
public ResultCode ListOpenUsers ( ServiceCtx context )
2018-02-24 23:34:16 -05:00
{
2019-06-15 18:35:38 -04:00
return WriteUserList ( context , context . Device . System . State . Account . GetOpenedUsers ( ) ) ;
2018-08-14 18:02:42 -04:00
}
2019-07-14 15:04:38 -04:00
private ResultCode WriteUserList ( ServiceCtx context , IEnumerable < UserProfile > profiles )
2018-08-14 18:02:42 -04:00
{
2019-06-15 18:35:38 -04:00
if ( context . Request . RecvListBuff . Count = = 0 )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidInputBuffer ;
2019-06-15 18:35:38 -04:00
}
2018-12-06 06:16:24 -05:00
long outputPosition = context . Request . RecvListBuff [ 0 ] . Position ;
long outputSize = context . Request . RecvListBuff [ 0 ] . Size ;
2018-08-14 18:02:42 -04:00
2019-10-27 20:50:50 -04:00
MemoryHelper . FillWithZeros ( context . Memory , outputPosition , ( int ) outputSize ) ;
2019-06-15 18:35:38 -04:00
ulong offset = 0 ;
2018-08-14 18:02:42 -04:00
2019-06-15 18:35:38 -04:00
foreach ( UserProfile userProfile in profiles )
2018-08-14 18:02:42 -04:00
{
2019-06-15 18:35:38 -04:00
if ( offset + 0x10 > ( ulong ) outputSize )
2018-08-14 18:02:42 -04:00
{
break ;
}
2020-05-03 18:54:50 -04:00
context . Memory . Write ( ( ulong ) outputPosition + offset , userProfile . UserId . High ) ;
context . Memory . Write ( ( ulong ) outputPosition + offset + 8 , userProfile . UserId . Low ) ;
2019-06-15 18:35:38 -04:00
offset + = 0x10 ;
2018-08-14 18:02:42 -04:00
}
2018-04-16 20:24:42 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-02-24 23:34:16 -05:00
}
2019-07-11 21:13:43 -04:00
[Command(4)]
2018-10-13 19:16:02 -04:00
// GetLastOpenedUser() -> nn::account::Uid
2019-07-14 15:04:38 -04:00
public ResultCode GetLastOpenedUser ( ServiceCtx context )
2018-06-02 18:46:09 -04:00
{
2019-06-15 18:35:38 -04:00
context . Device . System . State . Account . LastOpenedUser . UserId . Write ( context . ResponseData ) ;
2018-06-02 18:46:09 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-06-02 18:46:09 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(5)]
2018-10-13 19:16:02 -04:00
// GetProfile(nn::account::Uid) -> object<nn::account::profile::IProfile>
2019-07-14 15:04:38 -04:00
public ResultCode GetProfile ( ServiceCtx context )
2018-02-24 23:34:16 -05:00
{
2020-02-01 22:24:17 -05:00
UserId userId = context . RequestData . ReadStruct < UserId > ( ) ;
2018-08-14 18:02:42 -04:00
2019-06-15 18:35:38 -04:00
if ( ! context . Device . System . State . Account . TryGetUser ( userId , out UserProfile userProfile ) )
2018-08-14 18:02:42 -04:00
{
2020-08-03 19:32:53 -04:00
Logger . Warning ? . Print ( LogClass . ServiceAcc , $"User 0x{userId} not found!" ) ;
2018-08-14 18:02:42 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . UserNotFound ;
2018-08-14 18:02:42 -04:00
}
2019-06-15 18:35:38 -04:00
MakeObject ( context , new IProfile ( userProfile ) ) ;
// Doesn't occur in our case.
2019-09-04 12:09:20 -04:00
// return ResultCode.NullObject;
2018-02-24 23:34:16 -05:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-02-24 23:34:16 -05:00
}
2019-07-11 21:13:43 -04:00
[Command(50)]
2018-10-13 19:16:02 -04:00
// IsUserRegistrationRequestPermitted(u64, pid) -> bool
2019-07-14 15:04:38 -04:00
public ResultCode IsUserRegistrationRequestPermitted ( ServiceCtx context )
2018-10-13 19:16:02 -04:00
{
2019-06-15 18:35:38 -04:00
// The u64 argument seems to be unused by account.
context . ResponseData . Write ( _userRegistrationRequestPermitted ) ;
2018-10-13 19:16:02 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-10-13 19:16:02 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(51)]
2018-10-13 19:16:02 -04:00
// TrySelectUserWithoutInteraction(bool) -> nn::account::Uid
2019-07-14 15:04:38 -04:00
public ResultCode TrySelectUserWithoutInteraction ( ServiceCtx context )
2018-10-13 19:16:02 -04:00
{
2019-06-15 18:35:38 -04:00
if ( context . Device . System . State . Account . GetUserCount ( ) ! = 1 )
{
// Invalid UserId.
2020-02-01 22:24:17 -05:00
new UserId ( 0 , 0 ) . Write ( context . ResponseData ) ;
2018-10-13 19:16:02 -04:00
2019-06-15 18:35:38 -04:00
return 0 ;
}
bool baasCheck = context . RequestData . ReadBoolean ( ) ;
if ( baasCheck )
{
// This checks something related to baas (online), and then return an invalid UserId if the check in baas returns an error code.
// In our case, we can just log it for now.
2018-10-13 19:16:02 -04:00
2020-08-03 19:32:53 -04:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { baasCheck } ) ;
2019-06-15 18:35:38 -04:00
}
2018-10-13 19:16:02 -04:00
2019-06-15 18:35:38 -04:00
// As we returned an invalid UserId if there is more than one user earlier, now we can return only the first one.
context . Device . System . State . Account . GetFirst ( ) . UserId . Write ( context . ResponseData ) ;
2018-10-13 19:16:02 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-10-13 19:16:02 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(100)]
[Command(140)] // 6.0.0+
2018-10-13 19:16:02 -04:00
// InitializeApplicationInfo(u64, pid)
2019-06-15 18:35:38 -04:00
// Both calls (100, 140) use the same submethod, maybe there's something different further along when arp:r is called?
2019-07-14 15:04:38 -04:00
public ResultCode InitializeApplicationInfo ( ServiceCtx context )
2018-02-24 23:34:16 -05:00
{
2019-06-15 18:35:38 -04:00
if ( _applicationLaunchProperty ! = null )
{
2019-07-14 15:04:38 -04:00
return ResultCode . ApplicationLaunchPropertyAlreadyInit ;
2019-06-15 18:35:38 -04:00
}
// The u64 argument seems to be unused by account.
2018-12-06 06:16:24 -05:00
long unknown = context . RequestData . ReadInt64 ( ) ;
2018-10-13 19:16:02 -04:00
2019-06-15 18:35:38 -04:00
// TODO: Account actually calls nn::arp::detail::IReader::GetApplicationLaunchProperty() with the current PID and store the result (ApplicationLaunchProperty) internally.
// For now we can hardcode values, and fix it after GetApplicationLaunchProperty is implemented.
/ *
if ( nn : : arp : : detail : : IReader : : GetApplicationLaunchProperty ( ) = = 0xCC9D ) // InvalidProcessId
{
2019-09-10 05:55:28 -04:00
_applicationLaunchProperty = ApplicationLaunchProperty . Default ;
2019-06-15 18:35:38 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidArgument ;
2019-06-15 18:35:38 -04:00
}
else
* /
{
2019-09-10 05:55:28 -04:00
_applicationLaunchProperty = ApplicationLaunchProperty . GetByPid ( context ) ;
2019-06-15 18:35:38 -04:00
}
2020-08-03 19:32:53 -04:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { unknown } ) ;
2018-04-16 20:24:42 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-02-24 23:34:16 -05:00
}
2019-07-11 21:13:43 -04:00
[Command(101)]
2019-06-15 18:35:38 -04:00
// GetBaasAccountManagerForApplication(nn::account::Uid) -> object<nn::account::baas::IManagerForApplication>
2019-07-14 15:04:38 -04:00
public ResultCode GetBaasAccountManagerForApplication ( ServiceCtx context )
2018-02-24 23:34:16 -05:00
{
2020-02-01 22:24:17 -05:00
UserId userId = context . RequestData . ReadStruct < UserId > ( ) ;
2019-06-15 18:35:38 -04:00
if ( userId . IsNull )
{
2019-07-14 15:04:38 -04:00
return ResultCode . NullArgument ;
2019-06-15 18:35:38 -04:00
}
if ( _applicationLaunchProperty = = null )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidArgument ;
2019-06-15 18:35:38 -04:00
}
MakeObject ( context , new IManagerForApplication ( userId , _applicationLaunchProperty ) ) ;
// Doesn't occur in our case.
2019-07-14 15:04:38 -04:00
// return ResultCode.NullObject;
2019-06-15 18:35:38 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2019-06-15 18:35:38 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(110)]
2019-06-15 18:35:38 -04:00
// StoreSaveDataThumbnail(nn::account::Uid, buffer<bytes, 5>)
2019-07-14 15:04:38 -04:00
public ResultCode StoreSaveDataThumbnail ( ServiceCtx context )
2019-06-15 18:35:38 -04:00
{
if ( _applicationLaunchProperty = = null )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidArgument ;
2019-06-15 18:35:38 -04:00
}
2020-02-01 22:24:17 -05:00
UserId userId = context . RequestData . ReadStruct < UserId > ( ) ;
2019-06-15 18:35:38 -04:00
if ( userId . IsNull )
{
2019-07-14 15:04:38 -04:00
return ResultCode . NullArgument ;
2019-06-15 18:35:38 -04:00
}
if ( context . Request . SendBuff . Count = = 0 )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidInputBuffer ;
2019-06-15 18:35:38 -04:00
}
long inputPosition = context . Request . SendBuff [ 0 ] . Position ;
long inputSize = context . Request . SendBuff [ 0 ] . Size ;
if ( inputSize ! = 0x24000 )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidInputBufferSize ;
2019-06-15 18:35:38 -04:00
}
2020-05-03 18:54:50 -04:00
byte [ ] thumbnailBuffer = new byte [ inputSize ] ;
context . Memory . Read ( ( ulong ) inputPosition , thumbnailBuffer ) ;
2019-06-15 18:35:38 -04:00
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?
2020-08-03 19:32:53 -04:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
2019-06-15 18:35:38 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2019-06-15 18:35:38 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(111)]
2019-06-15 18:35:38 -04:00
// ClearSaveDataThumbnail(nn::account::Uid)
2019-07-14 15:04:38 -04:00
public ResultCode ClearSaveDataThumbnail ( ServiceCtx context )
2019-06-15 18:35:38 -04:00
{
if ( _applicationLaunchProperty = = null )
{
2019-07-14 15:04:38 -04:00
return ResultCode . InvalidArgument ;
2019-06-15 18:35:38 -04:00
}
2020-02-01 22:24:17 -05:00
UserId userId = context . RequestData . ReadStruct < UserId > ( ) ;
2019-06-15 18:35:38 -04:00
if ( userId . IsNull )
{
2019-07-14 15:04:38 -04:00
return ResultCode . NullArgument ;
2019-06-15 18:35:38 -04:00
}
// TODO: Clear the Thumbnail somewhere, in save data 0x8000000000000010 ?
2020-08-03 19:32:53 -04:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
2019-06-15 18:35:38 -04:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2019-06-15 18:35:38 -04:00
}
2019-07-11 21:13:43 -04:00
[Command(150)] // 6.0.0+
2019-06-15 18:35:38 -04:00
// IsUserAccountSwitchLocked() -> bool
2019-07-14 15:04:38 -04:00
public ResultCode IsUserAccountSwitchLocked ( ServiceCtx context )
2019-06-15 18:35:38 -04:00
{
// TODO : Validate the following check.
/ *
if ( _applicationLaunchProperty ! = null )
{
2019-07-14 15:04:38 -04:00
return ResultCode . ApplicationLaunchPropertyAlreadyInit ;
2019-06-15 18:35:38 -04:00
}
* /
// Account actually calls nn::arp::detail::IReader::GetApplicationControlProperty() with the current PID and store the result (NACP File) internally.
// But since we use LibHac and we load one Application at a time, it's not necessary.
2020-05-15 02:16:46 -04:00
context . ResponseData . Write ( context . Device . Application . ControlData . Value . UserAccountSwitchLock ) ;
2018-10-13 19:16:02 -04:00
2020-08-03 19:32:53 -04:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
2018-02-24 23:34:16 -05:00
2019-07-14 15:04:38 -04:00
return ResultCode . Success ;
2018-02-24 23:34:16 -05:00
}
}
2018-04-17 12:41:14 -04:00
}