IUserInterface.cs 1.9 KB

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