2021-06-29 12:57:06 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 17:15:45 -05:00
|
|
|
using Ryujinx.Horizon.Common;
|
2021-06-29 12:57:06 -04:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
|
|
|
|
{
|
|
|
|
[Service("aoc:u")]
|
|
|
|
class IAddOnContentManager : IpcService
|
|
|
|
{
|
|
|
|
private readonly KEvent _addOnContentListChangedEvent;
|
2021-07-06 14:17:06 -04:00
|
|
|
private int _addOnContentListChangedEventHandle;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
private ulong _addOnContentBaseId;
|
|
|
|
|
2021-11-24 16:11:50 -05:00
|
|
|
private List<ulong> _mountedAocTitleIds = new List<ulong>();
|
|
|
|
|
2021-06-29 12:57:06 -04:00
|
|
|
public IAddOnContentManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
_addOnContentListChangedEvent = new KEvent(context.Device.System.KernelContext);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(0)] // 1.0.0-6.2.0
|
2021-06-29 12:57:06 -04:00
|
|
|
// CountAddOnContentByApplicationId(u64 title_id) -> u32
|
|
|
|
public ResultCode CountAddOnContentByApplicationId(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong titleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
return CountAddOnContentImpl(context, titleId);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(1)] // 1.0.0-6.2.0
|
2021-06-29 12:57:06 -04:00
|
|
|
// ListAddOnContentByApplicationId(u64 title_id, u32 start_index, u32 buffer_size) -> (u32 count, buffer<u32>)
|
|
|
|
public ResultCode ListAddOnContentByApplicationId(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong titleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
return ListAddContentImpl(context, titleId);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(2)]
|
2021-06-29 12:57:06 -04:00
|
|
|
// CountAddOnContent(pid) -> u32
|
|
|
|
public ResultCode CountAddOnContent(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
return CountAddOnContentImpl(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(3)]
|
2021-06-29 12:57:06 -04:00
|
|
|
// ListAddOnContent(u32 start_index, u32 buffer_size, pid) -> (u32 count, buffer<u32>)
|
|
|
|
public ResultCode ListAddOnContent(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
return ListAddContentImpl(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(4)] // 1.0.0-6.2.0
|
2021-06-29 12:57:06 -04:00
|
|
|
// GetAddOnContentBaseIdByApplicationId(u64 title_id) -> u64
|
|
|
|
public ResultCode GetAddOnContentBaseIdByApplicationId(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong titleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
return GetAddOnContentBaseIdImpl(context, titleId);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(5)]
|
2021-06-29 12:57:06 -04:00
|
|
|
// GetAddOnContentBaseId(pid) -> u64
|
|
|
|
public ResultCode GetAddOnContentBaseId(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
return GetAddOnContentBaseIdImpl(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(6)] // 1.0.0-6.2.0
|
2021-06-29 12:57:06 -04:00
|
|
|
// PrepareAddOnContentByApplicationId(u64 title_id, u32 index)
|
|
|
|
public ResultCode PrepareAddOnContentByApplicationId(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong titleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
return PrepareAddOnContentImpl(context, titleId);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(7)]
|
2021-06-29 12:57:06 -04:00
|
|
|
// PrepareAddOnContent(u32 index, pid)
|
|
|
|
public ResultCode PrepareAddOnContent(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
return PrepareAddOnContentImpl(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(8)] // 4.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// GetAddOnContentListChangedEvent() -> handle<copy>
|
|
|
|
public ResultCode GetAddOnContentListChangedEvent(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return GetAddOnContentListChangedEventImpl(context);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(9)] // 10.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// GetAddOnContentLostErrorCode() -> u64
|
|
|
|
public ResultCode GetAddOnContentLostErrorCode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// NOTE: 0x7D0A4 -> 2164-1000
|
|
|
|
context.ResponseData.Write(GetAddOnContentLostErrorCodeImpl(0x7D0A4));
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(10)] // 11.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// GetAddOnContentListChangedEventWithProcessId(pid) -> handle<copy>
|
|
|
|
public ResultCode GetAddOnContentListChangedEventWithProcessId(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
|
|
|
// TODO: Found where stored value is used.
|
2023-03-31 15:16:46 -04:00
|
|
|
ResultCode resultCode = GetAddOnContentBaseIdFromTitleId(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2023-01-04 17:15:45 -05:00
|
|
|
|
2021-06-29 12:57:06 -04:00
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
{
|
|
|
|
return resultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetAddOnContentListChangedEventImpl(context);
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(11)] // 13.0.0+
|
2021-11-24 16:11:50 -05:00
|
|
|
// NotifyMountAddOnContent(pid, u64 title_id)
|
|
|
|
public ResultCode NotifyMountAddOnContent(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-11-24 16:11:50 -05:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
|
|
|
ulong aocTitleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
if (_mountedAocTitleIds.Count <= 0x7F)
|
|
|
|
{
|
|
|
|
_mountedAocTitleIds.Add(aocTitleId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(12)] // 13.0.0+
|
2021-11-24 16:11:50 -05:00
|
|
|
// NotifyUnmountAddOnContent(pid, u64 title_id)
|
|
|
|
public ResultCode NotifyUnmountAddOnContent(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-11-24 16:11:50 -05:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
|
|
|
|
ulong aocTitleId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
_mountedAocTitleIds.Remove(aocTitleId);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(50)] // 13.0.0+
|
2021-11-24 16:11:50 -05:00
|
|
|
// CheckAddOnContentMountStatus(pid)
|
|
|
|
public ResultCode CheckAddOnContentMountStatus(ServiceCtx context)
|
|
|
|
{
|
2022-02-09 15:18:07 -05:00
|
|
|
ulong pid = context.Request.HandleDesc.PId;
|
2021-11-24 16:11:50 -05:00
|
|
|
|
|
|
|
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
|
|
|
|
// Then it does some internal checks and returns InvalidBufferSize if they fail.
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(100)] // 7.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// CreateEcPurchasedEventManager() -> object<nn::ec::IPurchaseEventManager>
|
|
|
|
public ResultCode CreateEcPurchasedEventManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
MakeObject(context, new IPurchaseEventManager(context.Device.System));
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(101)] // 9.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// CreatePermanentEcPurchasedEventManager() -> object<nn::ec::IPurchaseEventManager>
|
|
|
|
public ResultCode CreatePermanentEcPurchasedEventManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// NOTE: Service call arp:r to get the TitleId, do some extra checks and pass it to returned interface.
|
|
|
|
|
|
|
|
MakeObject(context, new IPurchaseEventManager(context.Device.System));
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(110)] // 12.0.0+
|
2021-06-29 12:57:06 -04:00
|
|
|
// CreateContentsServiceManager() -> object<nn::ec::IContentsServiceManager>
|
|
|
|
public ResultCode CreateContentsServiceManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
MakeObject(context, new IContentsServiceManager());
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode CountAddOnContentImpl(ServiceCtx context, ulong titleId)
|
|
|
|
{
|
|
|
|
// NOTE: Service call sys:set GetQuestFlag and store it internally.
|
|
|
|
// If QuestFlag is true, counts some extra titles.
|
|
|
|
|
|
|
|
ResultCode resultCode = GetAddOnContentBaseIdFromTitleId(context, titleId);
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
{
|
|
|
|
return resultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This should use _addOnContentBaseId;
|
|
|
|
uint aocCount = (uint)context.Device.System.ContentManager.GetAocCount();
|
|
|
|
|
|
|
|
context.ResponseData.Write(aocCount);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode ListAddContentImpl(ServiceCtx context, ulong titleId)
|
|
|
|
{
|
|
|
|
// NOTE: Service call sys:set GetQuestFlag and store it internally.
|
|
|
|
// If QuestFlag is true, counts some extra titles.
|
|
|
|
|
|
|
|
uint startIndex = context.RequestData.ReadUInt32();
|
2021-07-06 14:17:06 -04:00
|
|
|
uint indexNumber = context.RequestData.ReadUInt32();
|
2021-06-29 12:57:06 -04:00
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
2021-06-29 16:52:17 -04:00
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
// TODO: This should use _addOnContentBaseId;
|
2021-07-06 14:17:06 -04:00
|
|
|
uint aocTotalCount = (uint)context.Device.System.ContentManager.GetAocCount();
|
2021-06-29 12:57:06 -04:00
|
|
|
|
2021-07-06 14:17:06 -04:00
|
|
|
if (indexNumber > bufferSize / sizeof(uint))
|
2021-06-29 12:57:06 -04:00
|
|
|
{
|
|
|
|
return ResultCode.InvalidBufferSize;
|
|
|
|
}
|
|
|
|
|
2021-07-06 14:17:06 -04:00
|
|
|
if (aocTotalCount <= startIndex)
|
2021-06-29 12:57:06 -04:00
|
|
|
{
|
|
|
|
context.ResponseData.Write(0);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
IList<ulong> aocTitleIds = context.Device.System.ContentManager.GetAocTitleIds();
|
|
|
|
|
|
|
|
GetAddOnContentBaseIdFromTitleId(context, titleId);
|
|
|
|
|
2021-07-06 14:17:06 -04:00
|
|
|
uint indexCounter = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < indexNumber; i++)
|
2021-06-29 12:57:06 -04:00
|
|
|
{
|
2021-07-06 14:17:06 -04:00
|
|
|
if (i + (int)startIndex < aocTitleIds.Count)
|
|
|
|
{
|
|
|
|
context.Memory.Write(bufferPosition + (ulong)i * sizeof(uint), (uint)(aocTitleIds[i + (int)startIndex] - _addOnContentBaseId));
|
|
|
|
|
|
|
|
indexCounter++;
|
|
|
|
}
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2021-07-06 14:17:06 -04:00
|
|
|
context.ResponseData.Write(indexCounter);
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode GetAddOnContentBaseIdImpl(ServiceCtx context, ulong titleId)
|
|
|
|
{
|
|
|
|
ResultCode resultCode = GetAddOnContentBaseIdFromTitleId(context, titleId);
|
|
|
|
|
|
|
|
context.ResponseData.Write(_addOnContentBaseId);
|
|
|
|
|
|
|
|
return resultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode GetAddOnContentBaseIdFromTitleId(ServiceCtx context, ulong titleId)
|
|
|
|
{
|
|
|
|
// NOTE: Service calls arp:r GetApplicationControlProperty to get AddOnContentBaseId using TitleId,
|
|
|
|
// If the call fails, it returns ResultCode.InvalidPid.
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
_addOnContentBaseId = context.Device.Processes.ActiveApplication.ApplicationControlProperties.AddOnContentBaseId;
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
if (_addOnContentBaseId == 0)
|
|
|
|
{
|
|
|
|
_addOnContentBaseId = titleId + 0x1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode PrepareAddOnContentImpl(ServiceCtx context, ulong titleId)
|
|
|
|
{
|
|
|
|
uint index = context.RequestData.ReadUInt32();
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
ResultCode resultCode = GetAddOnContentBaseIdFromTitleId(context, context.Device.Processes.ActiveApplication.ProgramId);
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
{
|
|
|
|
return resultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Service calls ns:am RegisterContentsExternalKey?, GetOwnedApplicationContentMetaStatus? etc...
|
|
|
|
// Ideally, this should probably initialize the AocData values for the specified index
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs, new { index });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResultCode GetAddOnContentListChangedEventImpl(ServiceCtx context)
|
|
|
|
{
|
2021-07-06 14:17:06 -04:00
|
|
|
if (_addOnContentListChangedEventHandle == 0)
|
2021-06-29 12:57:06 -04:00
|
|
|
{
|
2023-01-04 17:15:45 -05:00
|
|
|
if (context.Process.HandleTable.GenerateHandle(_addOnContentListChangedEvent.ReadableEvent, out _addOnContentListChangedEventHandle) != Result.Success)
|
2021-07-06 14:17:06 -04:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2021-06-29 12:57:06 -04:00
|
|
|
}
|
|
|
|
|
2021-07-06 14:17:06 -04:00
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_addOnContentListChangedEventHandle);
|
2021-06-29 12:57:06 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ulong GetAddOnContentLostErrorCodeImpl(int errorCode)
|
|
|
|
{
|
|
|
|
return ((ulong)errorCode & 0x1FF | ((((ulong)errorCode >> 9) & 0x1FFF) << 32)) + 2000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|