NgctServer.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Ryujinx.Common.Logging;
  2. using System.Text;
  3. namespace Ryujinx.HLE.HOS.Services.Ngct
  4. {
  5. static class NgctServer
  6. {
  7. public static ResultCode Match(ServiceCtx context)
  8. {
  9. // NOTE: Service load the values of sys:set ngc.t!functionality_override_enabled and ngc.t!auto_reload_enabled in internal fields.
  10. // Then it checks if ngc.t!functionality_override_enabled is enabled and if sys:set GetT is == 2.
  11. // If both conditions are true, it does this following code. Since we currently stub it, it's fine to don't check settings service values.
  12. ulong bufferPosition = context.Request.PtrBuff[0].Position;
  13. ulong bufferSize = context.Request.PtrBuff[0].Size;
  14. bool isMatch = false;
  15. string text = "";
  16. if (bufferSize != 0)
  17. {
  18. if (bufferSize > 1024)
  19. {
  20. isMatch = true;
  21. }
  22. else
  23. {
  24. byte[] buffer = new byte[bufferSize];
  25. context.Memory.Read(bufferPosition, buffer);
  26. text = Encoding.ASCII.GetString(buffer);
  27. // NOTE: Ngct use the archive 0100000000001034 which contains a words table. This is pushed on Chinese Switchs using Bcat service.
  28. // This call check if the string match with entries in the table and return the result if there is one (or more).
  29. // Since we don't want to hide bad words. It's fine to returns false here.
  30. isMatch = false;
  31. }
  32. }
  33. Logger.Stub?.PrintStub(LogClass.ServiceNgct, new { isMatch, text });
  34. context.ResponseData.Write(isMatch);
  35. return ResultCode.Success;
  36. }
  37. public static ResultCode Filter(ServiceCtx context)
  38. {
  39. // NOTE: Service load the values of sys:set ngc.t!functionality_override_enabled and ngc.t!auto_reload_enabled in internal fields.
  40. // Then it checks if ngc.t!functionality_override_enabled is enabled and if sys:set GetT is == 2.
  41. // If both conditions are true, it does this following code. Since we currently stub it, it's fine to don't check settings service values.
  42. ulong bufferPosition = context.Request.PtrBuff[0].Position;
  43. ulong bufferSize = context.Request.PtrBuff[0].Size;
  44. ulong bufferFilteredPosition = context.Request.RecvListBuff[0].Position;
  45. string text = "";
  46. string textFiltered = "";
  47. if (bufferSize != 0)
  48. {
  49. if (bufferSize > 1024)
  50. {
  51. textFiltered = new string('*', text.Length);
  52. context.Memory.Write(bufferFilteredPosition, Encoding.ASCII.GetBytes(textFiltered));
  53. }
  54. else
  55. {
  56. byte[] buffer = new byte[bufferSize];
  57. context.Memory.Read(bufferPosition, buffer);
  58. // NOTE: Ngct use the archive 0100000000001034 which contains a words table. This is pushed on Chinese Switchs using Bcat service.
  59. // This call check if the string contains words which are in the table then returns the same string with each matched words replaced by '*'.
  60. // Since we don't want to hide bad words. It's fine to returns the same string.
  61. textFiltered = text = Encoding.ASCII.GetString(buffer);
  62. context.Memory.Write(bufferFilteredPosition, buffer);
  63. }
  64. }
  65. Logger.Stub?.PrintStub(LogClass.ServiceNgct, new { text, textFiltered });
  66. return ResultCode.Success;
  67. }
  68. }
  69. }