2021-01-02 17:34:28 -05:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.Cpu;
|
|
|
|
|
using Ryujinx.HLE.Utilities;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
|
|
|
|
|
{
|
|
|
|
|
class ProfileServer
|
|
|
|
|
{
|
|
|
|
|
private UserProfile _profile;
|
|
|
|
|
|
|
|
|
|
public ProfileServer(UserProfile profile)
|
|
|
|
|
{
|
2021-04-12 21:16:43 -04:00
|
|
|
|
_profile = profile;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode Get(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80UL);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
ulong bufferPosition = context.Request.RecvListBuff[0].Position;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80);
|
|
|
|
|
|
|
|
|
|
// TODO: Determine the struct.
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Write(bufferPosition, 0); // Unknown
|
|
|
|
|
context.Memory.Write(bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs.
|
|
|
|
|
context.Memory.Write(bufferPosition + 8, (byte)1); // Profile icon background color ID
|
2021-01-02 17:34:28 -05:00
|
|
|
|
// 0x07 bytes - Unknown
|
|
|
|
|
// 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used.
|
|
|
|
|
// 0x60 bytes - Usually zeros?
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
|
|
|
|
|
|
return GetBase(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetBase(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
_profile.UserId.Write(context.ResponseData);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(_profile.LastModifiedTimestamp);
|
|
|
|
|
|
|
|
|
|
byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(username);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetImageSize(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-12 21:16:43 -04:00
|
|
|
|
context.ResponseData.Write(_profile.Image.Length);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode LoadImage(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 06:16:01 -04:00
|
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
ulong bufferLen = context.Request.ReceiveBuff[0].Size;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
if ((ulong)_profile.Image.Length > bufferLen)
|
2021-04-12 21:16:43 -04:00
|
|
|
|
{
|
|
|
|
|
return ResultCode.InvalidBufferSize;
|
|
|
|
|
}
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Write(bufferPosition, _profile.Image);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-12 21:16:43 -04:00
|
|
|
|
context.ResponseData.Write(_profile.Image.Length);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode Store(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 06:16:01 -04:00
|
|
|
|
ulong userDataPosition = context.Request.PtrBuff[0].Position;
|
|
|
|
|
ulong userDataSize = context.Request.PtrBuff[0].Size;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
byte[] userData = new byte[userDataSize];
|
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Read(userDataPosition, userData);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
// TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize });
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode StoreWithImage(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-24 06:16:01 -04:00
|
|
|
|
ulong userDataPosition = context.Request.PtrBuff[0].Position;
|
|
|
|
|
ulong userDataSize = context.Request.PtrBuff[0].Size;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
byte[] userData = new byte[userDataSize];
|
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Read(userDataPosition, userData);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
ulong profileImagePosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
ulong profileImageSize = context.Request.SendBuff[0].Size;
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-12 21:16:43 -04:00
|
|
|
|
byte[] profileImageData = new byte[profileImageSize];
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Read(profileImagePosition, profileImageData);
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
// TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
|
|
|
|
|
|
2021-04-12 21:16:43 -04:00
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profileImageSize });
|
2021-01-02 17:34:28 -05:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|