IUserInterface.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Ryujinx.HLE.OsHle.Handles;
  2. using Ryujinx.HLE.OsHle.Ipc;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.HLE.OsHle.Services.Sm
  5. {
  6. class IUserInterface : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. private bool IsInitialized;
  11. public IUserInterface()
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 0, Initialize },
  16. { 1, GetService }
  17. };
  18. }
  19. private const int SmNotInitialized = 0x415;
  20. public long Initialize(ServiceCtx Context)
  21. {
  22. IsInitialized = true;
  23. return 0;
  24. }
  25. public long GetService(ServiceCtx Context)
  26. {
  27. //Only for kernel version > 3.0.0.
  28. if (!IsInitialized)
  29. {
  30. //return SmNotInitialized;
  31. }
  32. string Name = string.Empty;
  33. for (int Index = 0; Index < 8 &&
  34. Context.RequestData.BaseStream.Position <
  35. Context.RequestData.BaseStream.Length; Index++)
  36. {
  37. byte Chr = Context.RequestData.ReadByte();
  38. if (Chr >= 0x20 && Chr < 0x7f)
  39. {
  40. Name += (char)Chr;
  41. }
  42. }
  43. if (Name == string.Empty)
  44. {
  45. return 0;
  46. }
  47. KSession Session = new KSession(ServiceFactory.MakeService(Name), Name);
  48. int Handle = Context.Process.HandleTable.OpenHandle(Session);
  49. Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
  50. return 0;
  51. }
  52. }
  53. }