ITimeZoneService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Ryujinx.Core.Logging;
  2. using Ryujinx.Core.OsHle.Ipc;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Core.OsHle.Services.Time
  6. {
  7. class ITimeZoneService : IpcService
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  12. public ITimeZoneService()
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, GetDeviceLocationName },
  17. { 101, ToCalendarTimeWithMyRule }
  18. };
  19. }
  20. public long GetDeviceLocationName(ServiceCtx Context)
  21. {
  22. Context.Ns.Log.PrintStub(LogClass.ServiceTime, "Stubbed.");
  23. for (int Index = 0; Index < 0x24; Index++)
  24. {
  25. Context.ResponseData.Write((byte)0);
  26. }
  27. return 0;
  28. }
  29. public long ToCalendarTimeWithMyRule(ServiceCtx Context)
  30. {
  31. long PosixTime = Context.RequestData.ReadInt64();
  32. DateTime CurrentTime = Epoch.AddSeconds(PosixTime).ToLocalTime();
  33. Context.ResponseData.Write((ushort)CurrentTime.Year);
  34. Context.ResponseData.Write((byte)CurrentTime.Month);
  35. Context.ResponseData.Write((byte)CurrentTime.Day);
  36. Context.ResponseData.Write((byte)CurrentTime.Hour);
  37. Context.ResponseData.Write((byte)CurrentTime.Minute);
  38. Context.ResponseData.Write((byte)CurrentTime.Second);
  39. Context.ResponseData.Write((byte)0);
  40. /* Thanks to TuxSH
  41. struct CalendarAdditionalInfo {
  42. u32 tm_wday; //day of week [0,6] (Sunday = 0)
  43. s32 tm_yday; //day of year [0,365]
  44. struct timezone {
  45. char[8] tz_name;
  46. bool isDaylightSavingTime;
  47. s32 utcOffsetSeconds;
  48. };
  49. };
  50. */
  51. Context.ResponseData.Write((int)CurrentTime.DayOfWeek);
  52. Context.ResponseData.Write(CurrentTime.DayOfYear - 1);
  53. //TODO: Find out the names used.
  54. Context.ResponseData.Write(new byte[8]);
  55. Context.ResponseData.Write((byte)(CurrentTime.IsDaylightSavingTime() ? 1 : 0));
  56. Context.ResponseData.Write((int)TimeZoneInfo.Local.GetUtcOffset(CurrentTime).TotalSeconds);
  57. return 0;
  58. }
  59. }
  60. }