From 06735d13694a0460e69aa6b2465f0725cf853ae2 Mon Sep 17 00:00:00 2001 From: TakaRikka Date: Wed, 19 Aug 2026 19:14:07 -0700 Subject: [PATCH] c++ wrappers --- sdk/include/mods/svc/ui.hpp | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 sdk/include/mods/svc/ui.hpp diff --git a/sdk/include/mods/svc/ui.hpp b/sdk/include/mods/svc/ui.hpp new file mode 100644 index 0000000000..7994cad1dc --- /dev/null +++ b/sdk/include/mods/svc/ui.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include + +#include +#include + +namespace mods::ui { + +inline ModResult get_clipboard_text(std::string& outText) { + outText.clear(); + + size_t textLength = 0; + auto result = svc_ui->get_clipboard_text(mod_ctx, nullptr, 0, &textLength); + if (result != MOD_OK) { + return result; + } + + for (int attempt = 0; attempt < 3; ++attempt) { + std::string buffer(textLength + 1, '\0'); + size_t actualLength = 0; + + result = svc_ui->get_clipboard_text( + mod_ctx, buffer.data(), buffer.size(), &actualLength); + + if (result == MOD_OK) { + buffer.resize(actualLength); + outText = std::move(buffer); + return MOD_OK; + } + + // Retry if the clipboard grew between the two calls. + if (result != MOD_INVALID_ARGUMENT || actualLength <= textLength) { + return result; + } + + textLength = actualLength; + } + + return MOD_ERROR; +} + +inline ModResult set_clipboard_text(const std::string& text) { + return svc_ui->set_clipboard_text(mod_ctx, text.c_str()); +} + +} // namespace mods::ui \ No newline at end of file