ITimeZoneService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Core.OsHle.Services.Time
  5. {
  6. class ITimeZoneService : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. private static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
  11. public ITimeZoneService()
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 101, ToCalendarTimeWithMyRule }
  16. };
  17. }
  18. //(nn::time::PosixTime)-> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo)
  19. public long ToCalendarTimeWithMyRule(ServiceCtx Context)
  20. {
  21. long PosixTime = Context.RequestData.ReadInt64();
  22. Epoch = Epoch.AddSeconds(PosixTime).ToLocalTime();
  23. /*
  24. struct CalendarTime {
  25. u16_le year;
  26. u8 month; // Starts at 1
  27. u8 day; // Starts at 1
  28. u8 hour;
  29. u8 minute;
  30. u8 second;
  31. INSERT_PADDING_BYTES(1);
  32. };
  33. */
  34. Context.ResponseData.Write((short)Epoch.Year);
  35. Context.ResponseData.Write((byte)Epoch.Month);
  36. Context.ResponseData.Write((byte)Epoch.Day);
  37. Context.ResponseData.Write((byte)Epoch.Hour);
  38. Context.ResponseData.Write((byte)Epoch.Minute);
  39. Context.ResponseData.Write((byte)Epoch.Second);
  40. Context.ResponseData.Write((byte)0);
  41. /* Thanks to TuxSH
  42. struct CalendarAdditionalInfo {
  43. u32 tm_wday; //day of week [0,6] (Sunday = 0)
  44. s32 tm_yday; //day of year [0,365]
  45. struct timezone {
  46. char[8] tz_name;
  47. bool isDaylightSavingTime;
  48. s32 utcOffsetSeconds;
  49. };
  50. };
  51. */
  52. Context.ResponseData.Write((int)Epoch.DayOfWeek);
  53. Context.ResponseData.Write(Epoch.DayOfYear);
  54. Context.ResponseData.Write(new byte[8]);
  55. Context.ResponseData.Write(Convert.ToByte(Epoch.IsDaylightSavingTime()));
  56. Context.ResponseData.Write(0);
  57. return 0;
  58. }
  59. }
  60. }