2018-10-17 19:15:50 +02:00
using Ryujinx.Common.Logging ;
2020-08-18 21:24:54 +02:00
using Ryujinx.Cpu ;
using Ryujinx.HLE.HOS.Kernel.Threading ;
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext ;
2019-09-19 02:45:11 +02:00
using Ryujinx.HLE.HOS.Services.Arp ;
2020-08-18 21:24:54 +02:00
using System ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
2018-02-10 01:14:55 +01:00
2019-09-19 02:45:11 +02:00
namespace Ryujinx.HLE.HOS.Services.Account.Acc
2018-02-10 01:14:55 +01:00
{
2018-03-19 19:58:46 +01:00
class IManagerForApplication : IpcService
2018-02-10 01:14:55 +01:00
{
2020-08-18 21:24:54 +02:00
// TODO: Determine where and how NetworkServiceAccountId is set.
private const long NetworkServiceAccountId = 0xcafe ;
2020-02-02 04:24:17 +01:00
private UserId _userId ;
2019-06-16 00:35:38 +02:00
private ApplicationLaunchProperty _applicationLaunchProperty ;
2018-10-14 01:16:02 +02:00
2020-02-02 04:24:17 +01:00
public IManagerForApplication ( UserId userId , ApplicationLaunchProperty applicationLaunchProperty )
2018-02-10 01:14:55 +01:00
{
2019-06-16 00:35:38 +02:00
_userId = userId ;
_applicationLaunchProperty = applicationLaunchProperty ;
2018-02-10 01:14:55 +01:00
}
2019-07-12 03:13:43 +02:00
[Command(0)]
2018-10-14 01:16:02 +02:00
// CheckAvailability()
2019-07-14 21:04:38 +02:00
public ResultCode CheckAvailability ( ServiceCtx context )
2018-04-17 02:24:42 +02:00
{
2020-08-18 21:24:54 +02:00
// NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x".
// Then it searches the Availability of Online Services related to the UserId in this file and returns it.
2020-08-04 01:32:53 +02:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
2018-04-17 02:24:42 +02:00
2020-08-18 21:24:54 +02:00
// NOTE: Even if we try to return different error codes here, the guest still needs other calls.
2019-07-14 21:04:38 +02:00
return ResultCode . Success ;
2018-02-10 01:14:55 +01:00
}
2019-07-12 03:13:43 +02:00
[Command(1)]
2018-10-14 01:16:02 +02:00
// GetAccountId() -> nn::account::NetworkServiceAccountId
2019-07-14 21:04:38 +02:00
public ResultCode GetAccountId ( ServiceCtx context )
2018-02-10 01:14:55 +01:00
{
2020-12-12 04:06:20 +01:00
// NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
2020-08-18 21:24:54 +02:00
// as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
// Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
2020-08-04 01:32:53 +02:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { NetworkServiceAccountId } ) ;
2020-03-02 15:07:27 +01:00
context . ResponseData . Write ( NetworkServiceAccountId ) ;
return ResultCode . Success ;
}
2020-08-18 21:24:54 +02:00
[Command(2)]
// EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
public ResultCode EnsureIdTokenCacheAsync ( ServiceCtx context )
{
KEvent asyncEvent = new KEvent ( context . Device . System . KernelContext ) ;
AsyncExecution asyncExecution = new AsyncExecution ( asyncEvent ) ;
asyncExecution . Initialize ( 1000 , EnsureIdTokenCacheAsyncImpl ) ;
MakeObject ( context , new IAsyncContext ( asyncExecution ) ) ;
// return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
return ResultCode . Success ;
}
private async Task EnsureIdTokenCacheAsyncImpl ( CancellationToken token )
{
// NOTE: This open the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
// in the "account:/" savedata.
// Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
// in "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the "account:/" savedata.
// Since we don't support online services, we can stub it.
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
// TODO: Use a real function instead, with the CancellationToken.
await Task . CompletedTask ;
}
[Command(3)]
// LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
public ResultCode LoadIdTokenCache ( ServiceCtx context )
{
long bufferPosition = context . Request . ReceiveBuff [ 0 ] . Position ;
long bufferSize = context . Request . ReceiveBuff [ 0 ] . Size ;
// NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
// in the "account:/" savedata and writes some data in the buffer.
// Since we don't support online services, we can stub it.
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
/ *
if ( internal_object ! = null )
{
if ( bufferSize > 0xC00 )
{
return ResultCode . InvalidIdTokenCacheBufferSize ;
}
}
* /
int idTokenCacheSize = 0 ;
MemoryHelper . FillWithZeros ( context . Memory , bufferPosition , ( int ) bufferSize ) ;
context . ResponseData . Write ( idTokenCacheSize ) ;
return ResultCode . Success ;
}
2020-03-02 15:07:27 +01:00
[Command(130)]
2020-12-12 12:10:12 +01:00
// GetNintendoAccountUserResourceCacheForApplication() -> (nn::account::NintendoAccountId, nn::account::nas::NasUserBaseForApplication, buffer<bytes, 6>)
2020-03-02 15:07:27 +01:00
public ResultCode GetNintendoAccountUserResourceCacheForApplication ( ServiceCtx context )
{
2020-08-04 01:32:53 +02:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { NetworkServiceAccountId } ) ;
2018-10-14 01:16:02 +02:00
2020-03-02 15:07:27 +01:00
context . ResponseData . Write ( NetworkServiceAccountId ) ;
2018-04-17 02:24:42 +02:00
2020-12-12 12:10:12 +01:00
// TODO: determine and fill the output IPC buffer.
2018-02-10 01:14:55 +01:00
2019-07-14 21:04:38 +02:00
return ResultCode . Success ;
2018-02-10 01:14:55 +01:00
}
2020-09-21 05:45:30 +02:00
[Command(160)] // 5.0.0+
// StoreOpenContext()
public ResultCode StoreOpenContext ( ServiceCtx context )
{
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
return ResultCode . Success ;
}
2018-02-10 01:14:55 +01:00
}
}