2019-10-08 04:48:49 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-03 23:54:50 +01:00
|
|
|
using Ryujinx.Cpu;
|
2019-10-08 04:48:49 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
2021-10-24 23:13:20 +01:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2022-06-24 18:04:57 +01:00
|
|
|
using Ryujinx.Memory;
|
2019-10-08 04:48:49 +01:00
|
|
|
using System;
|
2022-06-24 18:04:57 +01:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Runtime.InteropServices;
|
2019-10-08 04:48:49 +01:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
|
|
|
|
{
|
|
|
|
class ITimeZoneServiceForGlue : IpcService
|
|
|
|
{
|
|
|
|
private TimeZoneContentManager _timeZoneContentManager;
|
|
|
|
private ITimeZoneServiceForPsc _inner;
|
|
|
|
private bool _writePermission;
|
|
|
|
|
|
|
|
public ITimeZoneServiceForGlue(TimeZoneContentManager timeZoneContentManager, bool writePermission)
|
|
|
|
{
|
|
|
|
_timeZoneContentManager = timeZoneContentManager;
|
|
|
|
_writePermission = writePermission;
|
|
|
|
_inner = new ITimeZoneServiceForPsc(timeZoneContentManager.Manager, writePermission);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(0)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// GetDeviceLocationName() -> nn::time::LocationName
|
|
|
|
public ResultCode GetDeviceLocationName(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.GetDeviceLocationName(context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(1)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// SetDeviceLocationName(nn::time::LocationName)
|
|
|
|
public ResultCode SetDeviceLocationName(ServiceCtx context)
|
|
|
|
{
|
|
|
|
if (!_writePermission)
|
|
|
|
{
|
|
|
|
return ResultCode.PermissionDenied;
|
|
|
|
}
|
|
|
|
|
2021-10-24 23:13:20 +01:00
|
|
|
string locationName = StringUtils.ReadInlinedAsciiString(context.RequestData, 0x24);
|
2019-10-08 04:48:49 +01:00
|
|
|
|
|
|
|
return _timeZoneContentManager.SetDeviceLocationName(locationName);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(2)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// GetTotalLocationNameCount() -> u32
|
|
|
|
public ResultCode GetTotalLocationNameCount(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.GetTotalLocationNameCount(context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(3)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// LoadLocationNameList(u32 index) -> (u32 outCount, buffer<nn::time::LocationName, 6>)
|
|
|
|
public ResultCode LoadLocationNameList(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 11:16:01 +01:00
|
|
|
uint index = context.RequestData.ReadUInt32();
|
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2019-10-08 04:48:49 +01:00
|
|
|
|
|
|
|
ResultCode errorCode = _timeZoneContentManager.LoadLocationNameList(index, out string[] locationNameArray, (uint)bufferSize / 0x24);
|
|
|
|
|
|
|
|
if (errorCode == 0)
|
|
|
|
{
|
|
|
|
uint offset = 0;
|
|
|
|
|
|
|
|
foreach (string locationName in locationNameArray)
|
|
|
|
{
|
|
|
|
int padding = 0x24 - locationName.Length;
|
|
|
|
|
|
|
|
if (padding < 0)
|
|
|
|
{
|
|
|
|
return ResultCode.LocationNameTooLong;
|
|
|
|
}
|
|
|
|
|
2021-04-24 11:16:01 +01:00
|
|
|
context.Memory.Write(bufferPosition + offset, Encoding.ASCII.GetBytes(locationName));
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, bufferPosition + offset + (ulong)locationName.Length, padding);
|
2019-10-08 04:48:49 +01:00
|
|
|
|
|
|
|
offset += 0x24;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.ResponseData.Write((uint)locationNameArray.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorCode;
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(4)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// LoadTimeZoneRule(nn::time::LocationName locationName) -> buffer<nn::time::TimeZoneRule, 0x16>
|
|
|
|
public ResultCode LoadTimeZoneRule(ServiceCtx context)
|
|
|
|
{
|
2021-04-24 11:16:01 +01:00
|
|
|
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
2019-10-08 04:48:49 +01:00
|
|
|
|
|
|
|
if (bufferSize != 0x4000)
|
|
|
|
{
|
|
|
|
// TODO: find error code here
|
2020-08-04 00:32:53 +01:00
|
|
|
Logger.Error?.Print(LogClass.ServiceTime, $"TimeZoneRule buffer size is 0x{bufferSize:x} (expected 0x4000)");
|
2019-10-08 04:48:49 +01:00
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2021-10-24 23:13:20 +01:00
|
|
|
string locationName = StringUtils.ReadInlinedAsciiString(context.RequestData, 0x24);
|
2019-10-08 04:48:49 +01:00
|
|
|
|
2022-06-24 18:04:57 +01:00
|
|
|
using (WritableRegion region = context.Memory.GetWritableRegion(bufferPosition, Unsafe.SizeOf<TimeZoneRule>()))
|
2019-10-08 04:48:49 +01:00
|
|
|
{
|
2022-06-24 18:04:57 +01:00
|
|
|
ref TimeZoneRule rules = ref MemoryMarshal.Cast<byte, TimeZoneRule>(region.Memory.Span)[0];
|
2019-10-08 04:48:49 +01:00
|
|
|
|
2022-06-24 18:04:57 +01:00
|
|
|
return _timeZoneContentManager.LoadTimeZoneRule(ref rules, locationName);
|
|
|
|
}
|
2019-10-08 04:48:49 +01:00
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(100)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// ToCalendarTime(nn::time::PosixTime time, buffer<nn::time::TimeZoneRule, 0x15> rules) -> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo)
|
|
|
|
public ResultCode ToCalendarTime(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.ToCalendarTime(context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(101)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// ToCalendarTimeWithMyRule(nn::time::PosixTime) -> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo)
|
|
|
|
public ResultCode ToCalendarTimeWithMyRule(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.ToCalendarTimeWithMyRule(context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(201)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// ToPosixTime(nn::time::CalendarTime calendarTime, buffer<nn::time::TimeZoneRule, 0x15> rules) -> (u32 outCount, buffer<nn::time::PosixTime, 0xa>)
|
|
|
|
public ResultCode ToPosixTime(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.ToPosixTime(context);
|
|
|
|
}
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
[CommandCmif(202)]
|
2019-10-08 04:48:49 +01:00
|
|
|
// ToPosixTimeWithMyRule(nn::time::CalendarTime calendarTime) -> (u32 outCount, buffer<nn::time::PosixTime, 0xa>)
|
|
|
|
public ResultCode ToPosixTimeWithMyRule(ServiceCtx context)
|
|
|
|
{
|
|
|
|
return _inner.ToPosixTimeWithMyRule(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|