mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-12-26 07:59:55 +00:00
560ccbeb2d
* Refactoring commands handling - Use Reflection to handle commands ID. - Add all symbols (from SwIPC so not all time accurate). - Re-sort some services commands methods. - Some cleanup. - Keep some empty constructor for consistency. * Fix order in IProfile
97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using System;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time
|
|
{
|
|
class ISystemClock : IpcService
|
|
{
|
|
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
private SystemClockType _clockType;
|
|
private DateTime _systemClockContextEpoch;
|
|
private long _systemClockTimePoint;
|
|
private byte[] _systemClockContextEnding;
|
|
private long _timeOffset;
|
|
|
|
public ISystemClock(SystemClockType clockType)
|
|
{
|
|
_clockType = clockType;
|
|
_systemClockContextEpoch = System.Diagnostics.Process.GetCurrentProcess().StartTime;
|
|
_systemClockContextEnding = new byte[0x10];
|
|
_timeOffset = 0;
|
|
|
|
if (clockType == SystemClockType.User ||
|
|
clockType == SystemClockType.Network)
|
|
{
|
|
_systemClockContextEpoch = _systemClockContextEpoch.ToUniversalTime();
|
|
}
|
|
|
|
_systemClockTimePoint = (long)(_systemClockContextEpoch - Epoch).TotalSeconds;
|
|
}
|
|
|
|
[Command(0)]
|
|
// GetCurrentTime() -> nn::time::PosixTime
|
|
public long GetCurrentTime(ServiceCtx context)
|
|
{
|
|
DateTime currentTime = DateTime.Now;
|
|
|
|
if (_clockType == SystemClockType.User ||
|
|
_clockType == SystemClockType.Network)
|
|
{
|
|
currentTime = currentTime.ToUniversalTime();
|
|
}
|
|
|
|
context.ResponseData.Write((long)((currentTime - Epoch).TotalSeconds) + _timeOffset);
|
|
|
|
return 0;
|
|
}
|
|
|
|
[Command(1)]
|
|
// SetCurrentTime(nn::time::PosixTime)
|
|
public long SetCurrentTime(ServiceCtx context)
|
|
{
|
|
DateTime currentTime = DateTime.Now;
|
|
|
|
if (_clockType == SystemClockType.User ||
|
|
_clockType == SystemClockType.Network)
|
|
{
|
|
currentTime = currentTime.ToUniversalTime();
|
|
}
|
|
|
|
_timeOffset = (context.RequestData.ReadInt64() - (long)(currentTime - Epoch).TotalSeconds);
|
|
|
|
return 0;
|
|
}
|
|
|
|
[Command(2)]
|
|
// GetSystemClockContext() -> nn::time::SystemClockContext
|
|
public long GetSystemClockContext(ServiceCtx context)
|
|
{
|
|
context.ResponseData.Write((long)(_systemClockContextEpoch - Epoch).TotalSeconds);
|
|
|
|
// The point in time, TODO: is there a link between epoch and this?
|
|
context.ResponseData.Write(_systemClockTimePoint);
|
|
|
|
// This seems to be some kind of identifier?
|
|
for (int i = 0; i < 0x10; i++)
|
|
{
|
|
context.ResponseData.Write(_systemClockContextEnding[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
[Command(3)]
|
|
// SetSystemClockContext(nn::time::SystemClockContext)
|
|
public long SetSystemClockContext(ServiceCtx context)
|
|
{
|
|
long newSystemClockEpoch = context.RequestData.ReadInt64();
|
|
long newSystemClockTimePoint = context.RequestData.ReadInt64();
|
|
|
|
_systemClockContextEpoch = Epoch.Add(TimeSpan.FromSeconds(newSystemClockEpoch));
|
|
_systemClockTimePoint = newSystemClockTimePoint;
|
|
_systemClockContextEnding = context.RequestData.ReadBytes(0x10);
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
} |