ngc.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/string_util.h"
  4. #include "core/core.h"
  5. #include "core/hle/service/ipc_helpers.h"
  6. #include "core/hle/service/ngc/ngc.h"
  7. #include "core/hle/service/server_manager.h"
  8. #include "core/hle/service/service.h"
  9. namespace Service::NGC {
  10. class NgctServiceImpl final : public ServiceFramework<NgctServiceImpl> {
  11. public:
  12. explicit NgctServiceImpl(Core::System& system_) : ServiceFramework{system_, "ngct:u"} {
  13. // clang-format off
  14. static const FunctionInfo functions[] = {
  15. {0, &NgctServiceImpl::Match, "Match"},
  16. {1, &NgctServiceImpl::Filter, "Filter"},
  17. };
  18. // clang-format on
  19. RegisterHandlers(functions);
  20. }
  21. private:
  22. void Match(HLERequestContext& ctx) {
  23. const auto buffer = ctx.ReadBuffer();
  24. const auto text = Common::StringFromFixedZeroTerminatedBuffer(
  25. reinterpret_cast<const char*>(buffer.data()), buffer.size());
  26. LOG_WARNING(Service_NGC, "(STUBBED) called, text={}", text);
  27. IPC::ResponseBuilder rb{ctx, 3};
  28. rb.Push(ResultSuccess);
  29. // Return false since we don't censor anything
  30. rb.Push(false);
  31. }
  32. void Filter(HLERequestContext& ctx) {
  33. const auto buffer = ctx.ReadBuffer();
  34. const auto text = Common::StringFromFixedZeroTerminatedBuffer(
  35. reinterpret_cast<const char*>(buffer.data()), buffer.size());
  36. LOG_WARNING(Service_NGC, "(STUBBED) called, text={}", text);
  37. // Return the same string since we don't censor anything
  38. ctx.WriteBuffer(buffer);
  39. IPC::ResponseBuilder rb{ctx, 2};
  40. rb.Push(ResultSuccess);
  41. }
  42. };
  43. class NgcServiceImpl final : public ServiceFramework<NgcServiceImpl> {
  44. public:
  45. explicit NgcServiceImpl(Core::System& system_) : ServiceFramework(system_, "ngc:u") {
  46. // clang-format off
  47. static const FunctionInfo functions[] = {
  48. {0, &NgcServiceImpl::GetContentVersion, "GetContentVersion"},
  49. {1, &NgcServiceImpl::Check, "Check"},
  50. {2, &NgcServiceImpl::Mask, "Mask"},
  51. {3, &NgcServiceImpl::Reload, "Reload"},
  52. };
  53. // clang-format on
  54. RegisterHandlers(functions);
  55. }
  56. private:
  57. static constexpr u32 NgcContentVersion = 1;
  58. // This is nn::ngc::detail::ProfanityFilterOption
  59. struct ProfanityFilterOption {
  60. INSERT_PADDING_BYTES_NOINIT(0x20);
  61. };
  62. static_assert(sizeof(ProfanityFilterOption) == 0x20,
  63. "ProfanityFilterOption has incorrect size");
  64. void GetContentVersion(HLERequestContext& ctx) {
  65. LOG_INFO(Service_NGC, "(STUBBED) called");
  66. // This calls nn::ngc::ProfanityFilter::GetContentVersion
  67. const u32 version = NgcContentVersion;
  68. IPC::ResponseBuilder rb{ctx, 3};
  69. rb.Push(ResultSuccess);
  70. rb.Push(version);
  71. }
  72. void Check(HLERequestContext& ctx) {
  73. LOG_INFO(Service_NGC, "(STUBBED) called");
  74. struct InputParameters {
  75. u32 flags;
  76. ProfanityFilterOption option;
  77. };
  78. IPC::RequestParser rp{ctx};
  79. [[maybe_unused]] const auto params = rp.PopRaw<InputParameters>();
  80. [[maybe_unused]] const auto input = ctx.ReadBuffer(0);
  81. // This calls nn::ngc::ProfanityFilter::CheckProfanityWords
  82. const u32 out_flags = 0;
  83. IPC::ResponseBuilder rb{ctx, 3};
  84. rb.Push(ResultSuccess);
  85. rb.Push(out_flags);
  86. }
  87. void Mask(HLERequestContext& ctx) {
  88. LOG_INFO(Service_NGC, "(STUBBED) called");
  89. struct InputParameters {
  90. u32 flags;
  91. ProfanityFilterOption option;
  92. };
  93. IPC::RequestParser rp{ctx};
  94. [[maybe_unused]] const auto params = rp.PopRaw<InputParameters>();
  95. const auto input = ctx.ReadBuffer(0);
  96. // This calls nn::ngc::ProfanityFilter::MaskProfanityWordsInText
  97. const u32 out_flags = 0;
  98. ctx.WriteBuffer(input);
  99. IPC::ResponseBuilder rb{ctx, 3};
  100. rb.Push(ResultSuccess);
  101. rb.Push(out_flags);
  102. }
  103. void Reload(HLERequestContext& ctx) {
  104. LOG_INFO(Service_NGC, "(STUBBED) called");
  105. // This reloads the database.
  106. IPC::ResponseBuilder rb{ctx, 2};
  107. rb.Push(ResultSuccess);
  108. }
  109. };
  110. void LoopProcess(Core::System& system) {
  111. auto server_manager = std::make_unique<ServerManager>(system);
  112. server_manager->RegisterNamedService("ngct:u", std::make_shared<NgctServiceImpl>(system));
  113. server_manager->RegisterNamedService("ngc:u", std::make_shared<NgcServiceImpl>(system));
  114. ServerManager::RunServer(std::move(server_manager));
  115. }
  116. } // namespace Service::NGC