2018-10-17 13:15:50 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-06-20 13:38:14 -04:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
|
|
|
using System;
|
2018-02-09 19:14:55 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Ns
|
2018-02-09 19:14:55 -05:00
|
|
|
{
|
2019-07-10 11:59:54 -04:00
|
|
|
[Service("aoc:u")]
|
2018-04-06 00:01:52 -04:00
|
|
|
class IAddOnContentManager : IpcService
|
2018-02-09 19:14:55 -05:00
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
private readonly KEvent _addOnContentListChangedEvent;
|
|
|
|
|
|
|
|
private int _addOnContentListChangedEventHandle;
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
public IAddOnContentManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
_addOnContentListChangedEvent = new KEvent(context.Device.System.KernelContext);
|
|
|
|
}
|
2018-04-04 18:16:59 -04:00
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(2)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// CountAddOnContent(pid) -> u32
|
|
|
|
public ResultCode CountAddOnContent(ServiceCtx context)
|
2018-04-04 18:16:59 -04:00
|
|
|
{
|
2020-06-20 13:38:14 -04:00
|
|
|
long pid = context.Process.Pid;
|
2018-04-04 18:16:59 -04:00
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
// Official code checks ApplicationControlProperty.RuntimeAddOnContentInstall
|
2020-06-20 13:38:14 -04:00
|
|
|
// if true calls ns:am ListAvailableAddOnContent again to get updated count
|
|
|
|
|
|
|
|
byte runtimeAddOnContentInstall = context.Device.Application.ControlData.Value.RuntimeAddOnContentInstall;
|
|
|
|
if (runtimeAddOnContentInstall != 0)
|
|
|
|
{
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Warning?.Print(LogClass.ServiceNs, $"RuntimeAddOnContentInstall is true. Some DLC may be missing");
|
2020-06-20 13:38:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint aocCount = CountAddOnContentImpl(context);
|
|
|
|
|
|
|
|
context.ResponseData.Write(aocCount);
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs, new { aocCount, runtimeAddOnContentInstall });
|
2018-04-16 20:24:42 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-04-04 18:16:59 -04:00
|
|
|
}
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2020-06-20 13:38:14 -04:00
|
|
|
private static uint CountAddOnContentImpl(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return (uint)context.Device.System.ContentManager.GetAocCount();
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(3)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// ListAddOnContent(u32, u32, pid) -> (u32, buffer<u32>)
|
|
|
|
public ResultCode ListAddOnContent(ServiceCtx context)
|
|
|
|
{
|
|
|
|
uint startIndex = context.RequestData.ReadUInt32();
|
|
|
|
uint bufferSize = context.RequestData.ReadUInt32();
|
|
|
|
long pid = context.Process.Pid;
|
|
|
|
|
|
|
|
var aocTitleIds = context.Device.System.ContentManager.GetAocTitleIds();
|
|
|
|
|
|
|
|
uint aocCount = CountAddOnContentImpl(context);
|
|
|
|
|
|
|
|
if (aocCount <= startIndex)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write((uint)0);
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
aocCount = Math.Min(aocCount - startIndex, bufferSize);
|
|
|
|
|
|
|
|
context.ResponseData.Write(aocCount);
|
|
|
|
|
|
|
|
ulong bufAddr = (ulong)context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
ulong aocBaseId = GetAddOnContentBaseIdImpl(context);
|
|
|
|
|
|
|
|
for (int i = 0; i < aocCount; ++i)
|
|
|
|
{
|
|
|
|
context.Memory.Write(bufAddr + (ulong)i * 4, (int)(aocTitleIds[i + (int)startIndex] - aocBaseId));
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs, new { bufferSize, startIndex, aocCount });
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(5)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// GetAddOnContentBaseId(pid) -> u64
|
|
|
|
public ResultCode GetAddonContentBaseId(ServiceCtx context)
|
|
|
|
{
|
|
|
|
long pid = context.Process.Pid;
|
|
|
|
|
|
|
|
// Official code calls arp:r GetApplicationControlProperty to get AddOnContentBaseId
|
|
|
|
// If the call fails, calls arp:r GetApplicationLaunchProperty to get App TitleId
|
|
|
|
ulong aocBaseId = GetAddOnContentBaseIdImpl(context);
|
|
|
|
|
|
|
|
context.ResponseData.Write(aocBaseId);
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs, $"aocBaseId={aocBaseId:X16}");
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
// ResultCode will be error code of GetApplicationLaunchProperty if it fails
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ulong GetAddOnContentBaseIdImpl(ServiceCtx context)
|
|
|
|
{
|
|
|
|
ulong aocBaseId = context.Device.Application.ControlData.Value.AddOnContentBaseId;
|
|
|
|
|
|
|
|
if (aocBaseId == 0)
|
|
|
|
{
|
|
|
|
aocBaseId = context.Device.Application.TitleId + 0x1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aocBaseId;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(7)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// PrepareAddOnContent(u32, pid)
|
|
|
|
public ResultCode PrepareAddOnContent(ServiceCtx context)
|
|
|
|
{
|
|
|
|
uint aocIndex = context.RequestData.ReadUInt32();
|
|
|
|
long pid = context.Process.Pid;
|
|
|
|
|
|
|
|
// Official Code calls a bunch of functions from arp:r for aocBaseId
|
|
|
|
// and ns:am RegisterContentsExternalKey?, GetOwnedApplicationContentMetaStatus? etc...
|
|
|
|
|
|
|
|
// Ideally, this should probably initialize the AocData values for the specified index
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs, new { aocIndex });
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(8)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// GetAddOnContentListChangedEvent() -> handle<copy>
|
|
|
|
public ResultCode GetAddOnContentListChangedEvent(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// Official code seems to make an internal call to ns:am Cmd 84 GetDynamicCommitEvent()
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
if (_addOnContentListChangedEventHandle == 0)
|
2020-06-20 13:38:14 -04:00
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
if (context.Process.HandleTable.GenerateHandle(_addOnContentListChangedEvent.ReadableEvent, out _addOnContentListChangedEventHandle) != KernelResult.Success)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2020-06-20 13:38:14 -04:00
|
|
|
}
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_addOnContentListChangedEventHandle);
|
2020-06-20 13:38:14 -04:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs);
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(9)] // [10.0.0+]
|
2020-06-20 13:38:14 -04:00
|
|
|
// GetAddOnContentLostErrorCode() -> u64
|
|
|
|
public ResultCode GetAddOnContentLostErrorCode(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// Seems to calculate ((value & 0x1ff)) + 2000 on 0x7d0a4
|
|
|
|
// which gives 0x874 (2000+164). 164 being Module ID of `EC (Shop)`
|
|
|
|
context.ResponseData.Write(2164L);
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs);
|
2020-06-20 13:38:14 -04:00
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(100)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// CreateEcPurchasedEventManager() -> object<nn::ec::IPurchaseEventManager>
|
|
|
|
public ResultCode CreateEcPurchasedEventManager(ServiceCtx context)
|
2018-04-04 20:01:36 -04:00
|
|
|
{
|
2020-07-26 19:04:08 -04:00
|
|
|
MakeObject(context, new IPurchaseEventManager(context.Device.System));
|
2020-06-20 13:38:14 -04:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs);
|
2018-04-16 20:24:42 -04:00
|
|
|
|
2020-06-20 13:38:14 -04:00
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
[CommandHipc(101)]
|
2020-06-20 13:38:14 -04:00
|
|
|
// CreatePermanentEcPurchasedEventManager() -> object<nn::ec::IPurchaseEventManager>
|
|
|
|
public ResultCode CreatePermanentEcPurchasedEventManager(ServiceCtx context)
|
|
|
|
{
|
|
|
|
// Very similar to CreateEcPurchasedEventManager but with some extra code
|
|
|
|
|
2020-07-26 19:04:08 -04:00
|
|
|
MakeObject(context, new IPurchaseEventManager(context.Device.System));
|
2020-06-20 13:38:14 -04:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceNs);
|
2018-04-04 20:01:36 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-04-04 20:01:36 -04:00
|
|
|
}
|
2018-02-09 19:14:55 -05:00
|
|
|
}
|
|
|
|
}
|