1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Services.Arp;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.HLE.Utilities;
using System;
using System.Collections.Generic;
using static Ryujinx.HLE.HOS.ErrorCode;
namespace Ryujinx.HLE.HOS.Services.Acc
{
[Service("acc:u0")]
[Service("acc:u1")]
class IAccountService : IpcService
{
private bool _userRegistrationRequestPermitted = false;
private ApplicationLaunchProperty _applicationLaunchProperty;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IAccountService(ServiceCtx context)
{
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 0, GetUserCount },
{ 1, GetUserExistence },
{ 2, ListAllUsers },
{ 3, ListOpenUsers },
{ 4, GetLastOpenedUser },
{ 5, GetProfile },
//{ 6, GetProfileDigest }, // 3.0.0+
{ 50, IsUserRegistrationRequestPermitted },
{ 51, TrySelectUserWithoutInteraction },
//{ 60, ListOpenContextStoredUsers }, // 5.0.0-5.1.0
//{ 99, DebugActivateOpenContextRetention }, // 6.0.0+
{ 100, InitializeApplicationInfo },
{ 101, GetBaasAccountManagerForApplication },
//{ 102, AuthenticateApplicationAsync },
//{ 103, CheckNetworkServiceAvailabilityAsync }, // 4.0.0+
{ 110, StoreSaveDataThumbnail },
{ 111, ClearSaveDataThumbnail },
//{ 120, CreateGuestLoginRequest },
//{ 130, LoadOpenContext }, // 6.0.0+
//{ 131, ListOpenContextStoredUsers }, // 6.0.0+
{ 140, InitializeApplicationInfo }, // 6.0.0+
//{ 141, ListQualifiedUsers }, // 6.0.0+
{ 150, IsUserAccountSwitchLocked }, // 6.0.0+
};
}
// GetUserCount() -> i32
public long GetUserCount(ServiceCtx context)
{
context.ResponseData.Write(context.Device.System.State.Account.GetUserCount());
return 0;
}
// GetUserExistence(nn::account::Uid) -> bool
public long GetUserExistence(ServiceCtx context)
{
UInt128 userId = new UInt128(context.RequestData.ReadBytes(0x10));
if (userId.IsNull)
{
return MakeError(ErrorModule.Account, AccErr.NullArgument);
}
context.ResponseData.Write(context.Device.System.State.Account.TryGetUser(userId, out _));
return 0;
}
// ListAllUsers() -> array<nn::account::Uid, 0xa>
public long ListAllUsers(ServiceCtx context)
{
return WriteUserList(context, context.Device.System.State.Account.GetAllUsers());
}
// ListOpenUsers() -> array<nn::account::Uid, 0xa>
public long ListOpenUsers(ServiceCtx context)
{
return WriteUserList(context, context.Device.System.State.Account.GetOpenedUsers());
}
private long WriteUserList(ServiceCtx context, IEnumerable<UserProfile> profiles)
{
if (context.Request.RecvListBuff.Count == 0)
{
return MakeError(ErrorModule.Account, AccErr.InvalidInputBuffer);
}
long outputPosition = context.Request.RecvListBuff[0].Position;
long outputSize = context.Request.RecvListBuff[0].Size;
ulong offset = 0;
foreach (UserProfile userProfile in profiles)
{
if (offset + 0x10 > (ulong)outputSize)
{
break;
}
context.Memory.WriteInt64(outputPosition + (long)offset, userProfile.UserId.Low);
context.Memory.WriteInt64(outputPosition + (long)offset + 8, userProfile.UserId.High);
offset += 0x10;
}
return 0;
}
// GetLastOpenedUser() -> nn::account::Uid
public long GetLastOpenedUser(ServiceCtx context)
{
context.Device.System.State.Account.LastOpenedUser.UserId.Write(context.ResponseData);
return 0;
}
// GetProfile(nn::account::Uid) -> object<nn::account::profile::IProfile>
public long GetProfile(ServiceCtx context)
{
UInt128 userId = new UInt128(context.RequestData.ReadBytes(0x10));
if (!context.Device.System.State.Account.TryGetUser(userId, out UserProfile userProfile))
{
Logger.PrintWarning(LogClass.ServiceAcc, $"User 0x{userId} not found!");
return MakeError(ErrorModule.Account, AccErr.UserNotFound);
}
MakeObject(context, new IProfile(userProfile));
// Doesn't occur in our case.
// return MakeError(ErrorModule.Account, AccErr.NullObject);
return 0;
}
// IsUserRegistrationRequestPermitted(u64, pid) -> bool
public long IsUserRegistrationRequestPermitted(ServiceCtx context)
{
// The u64 argument seems to be unused by account.
context.ResponseData.Write(_userRegistrationRequestPermitted);
return 0;
}
// TrySelectUserWithoutInteraction(bool) -> nn::account::Uid
public long TrySelectUserWithoutInteraction(ServiceCtx context)
{
if (context.Device.System.State.Account.GetUserCount() != 1)
{
// Invalid UserId.
new UInt128(0, 0).Write(context.ResponseData);
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.
Logger.PrintStub(LogClass.ServiceAcc, new { baasCheck });
}
// 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);
return 0;
}
// InitializeApplicationInfo(u64, pid)
// Both calls (100, 140) use the same submethod, maybe there's something different further along when arp:r is called?
public long InitializeApplicationInfo(ServiceCtx context)
{
if (_applicationLaunchProperty != null)
{
return MakeError(ErrorModule.Account, AccErr.ApplicationLaunchPropertyAlreadyInit);
}
// The u64 argument seems to be unused by account.
long unknown = context.RequestData.ReadInt64();
// 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
{
_applicationLaunchProperty = new ApplicationLaunchProperty
{
TitleId = 0x00;
Version = 0x00;
BaseGameStorageId = 0x03;
UpdateGameStorageId = 0x00;
}
return MakeError(ErrorModule.Account, AccErr.InvalidArgument);
}
else
*/
{
_applicationLaunchProperty = new ApplicationLaunchProperty
{
TitleId = BitConverter.ToInt64(StringUtils.HexToBytes(context.Device.System.TitleID), 0),
Version = 0x00,
BaseGameStorageId = (byte)StorageId.NandSystem,
UpdateGameStorageId = (byte)StorageId.None
};
}
Logger.PrintStub(LogClass.ServiceAcc, new { unknown });
return 0;
}
// GetBaasAccountManagerForApplication(nn::account::Uid) -> object<nn::account::baas::IManagerForApplication>
public long GetBaasAccountManagerForApplication(ServiceCtx context)
{
UInt128 userId = new UInt128(context.RequestData.ReadBytes(0x10));
if (userId.IsNull)
{
return MakeError(ErrorModule.Account, AccErr.NullArgument);
}
if (_applicationLaunchProperty == null)
{
return MakeError(ErrorModule.Account, AccErr.InvalidArgument);
}
MakeObject(context, new IManagerForApplication(userId, _applicationLaunchProperty));
// Doesn't occur in our case.
// return MakeError(ErrorModule.Account, AccErr.NullObject);
return 0;
}
// StoreSaveDataThumbnail(nn::account::Uid, buffer<bytes, 5>)
public long StoreSaveDataThumbnail(ServiceCtx context)
{
if (_applicationLaunchProperty == null)
{
return MakeError(ErrorModule.Account, AccErr.InvalidArgument);
}
UInt128 userId = new UInt128(context.RequestData.ReadBytes(0x10));
if (userId.IsNull)
{
return MakeError(ErrorModule.Account, AccErr.NullArgument);
}
if (context.Request.SendBuff.Count == 0)
{
return MakeError(ErrorModule.Account, AccErr.InvalidInputBuffer);
}
long inputPosition = context.Request.SendBuff[0].Position;
long inputSize = context.Request.SendBuff[0].Size;
if (inputSize != 0x24000)
{
return MakeError(ErrorModule.Account, AccErr.InvalidInputBufferSize);
}
byte[] thumbnailBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?
Logger.PrintStub(LogClass.ServiceAcc);
return 0;
}
// ClearSaveDataThumbnail(nn::account::Uid)
public long ClearSaveDataThumbnail(ServiceCtx context)
{
if (_applicationLaunchProperty == null)
{
return MakeError(ErrorModule.Account, AccErr.InvalidArgument);
}
UInt128 userId = new UInt128(context.RequestData.ReadBytes(0x10));
if (userId.IsNull)
{
return MakeError(ErrorModule.Account, AccErr.NullArgument);
}
// TODO: Clear the Thumbnail somewhere, in save data 0x8000000000000010 ?
Logger.PrintStub(LogClass.ServiceAcc);
return 0;
}
// IsUserAccountSwitchLocked() -> bool
public long IsUserAccountSwitchLocked(ServiceCtx context)
{
// TODO : Validate the following check.
/*
if (_applicationLaunchProperty != null)
{
return MakeError(ErrorModule.Account, AccErr.ApplicationLaunchPropertyAlreadyInit);
}
*/
// 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.
context.ResponseData.Write(context.Device.System.ControlData.UserAccountSwitchLock);
Logger.PrintStub(LogClass.ServiceAcc);
return 0;
}
}
}
|