5#ifndef WIN32_LEAN_AND_MEAN
6#define WIN32_LEAN_AND_MEAN
14#define DISCORDPP_IMPLEMENTATION
15#define DISCORD_API __declspec(dllimport)
22 std::optional<std::string> Nonempty(
const std::string& value)
24 return value.empty() ? std::nullopt : std::optional<std::string>(value);
38 const char* detailsUrl = vehicleUrl;
47 steamButton.
SetLabel(
"View on Steam");
48 steamButton.
SetUrl(
"https://store.steampowered.com/app/795990/");
51 discordButton.
SetLabel(
"Join our Discord");
52 discordButton.
SetUrl(
"https://discord.gg/BH6zvaw");
82 std::unique_ptr<discordpp::Client> client;
84 explicit DesktopSocialSdk(HMODULE loaded,
const RiseDiscord::Log& log) : module(loaded)
86 client = std::make_unique<discordpp::Client>();
91 log(
"Could not register the Steam launch command",
true);
93 ~DesktopSocialSdk()
override
99 void Clear()
override { client->ClearRichPresence(); }
100 void Update(
const RiseDiscord::Activity& fields, Completion completion)
override
102 client->UpdateRichPresence(BuildSocialActivity(fields),
103 [completion = std::move(completion)](
const discordpp::ClientResult& result) {
104 completion(ConvertResult(result));
107 void QueryUser(UserCompletion completion)
override
110 [completion = std::move(completion)](
const discordpp::ClientResult& result,
111 std::optional<discordpp::UserHandle> user) {
112 completion(ConvertResult(result), user ? user->Id() : 0);
125 const auto length = GetModuleFileNameW(
nullptr, path,
static_cast<DWORD>(std::size(path)));
126 if (!length || length >= std::size(path))
return {};
127 auto separator = wcsrchr(path, L
'\\');
128 if (!separator)
return {};
129 *(separator + 1) = L
'\0';
130 wcscat_s(path, L
"discord_partner_sdk.dll");
131 HMODULE module = LoadLibraryExW(path,
nullptr,
132 LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
135 if (log) log(
"Social SDK DLL unavailable; continuing without Discord",
true);
138 using Version = std::int32_t (*)();
139 const auto major =
reinterpret_cast<Version
>(GetProcAddress(module,
"Discord_Client_GetVersionMajor"));
140 const auto minor =
reinterpret_cast<Version
>(GetProcAddress(module,
"Discord_Client_GetVersionMinor"));
141 const auto patch =
reinterpret_cast<Version
>(GetProcAddress(module,
"Discord_Client_GetVersionPatch"));
144 if (!major || !minor || !patch || major() != 1 || minor() != 10 || patch() != 19337)
146 if (log) log(
"Social SDK DLL version mismatch; expected 1.10.19337",
true);
150 auto sdk = std::make_unique<DesktopSocialSdk>(module, log);
151 if (log) log(
"Optional Social SDK 1.10.19337 initialized",
false);
154 if (log) log(
"Discord Social SDK requires a 64-bit client; continuing without Discord",
false);
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
Struct which controls what your rich presence looks like in the Discord client. If you don't specify ...
void SetLargeImage(std::optional< std::string > LargeImage)
Setter for ActivityAssets::LargeImage.
void SetLargeText(std::optional< std::string > LargeText)
Setter for ActivityAssets::LargeText.
void SetLargeUrl(std::optional< std::string > LargeUrl)
Setter for ActivityAssets::LargeUrl.
void SetSmallImage(std::optional< std::string > SmallImage)
Setter for ActivityAssets::SmallImage.
void SetSmallText(std::optional< std::string > SmallText)
Setter for ActivityAssets::SmallText.
void SetSmallUrl(std::optional< std::string > SmallUrl)
Setter for ActivityAssets::SmallUrl.
An Activity represents one "thing" a user is doing on Discord and is part of their rich presence.
void SetDetailsUrl(std::optional< std::string > DetailsUrl)
Setter for Activity::DetailsUrl.
void SetStateUrl(std::optional< std::string > StateUrl)
Setter for Activity::StateUrl.
void SetDetails(std::optional< std::string > Details)
Setter for Activity::Details.
void SetType(discordpp::ActivityTypes Type)
Setter for Activity::Type.
void SetTimestamps(std::optional< discordpp::ActivityTimestamps > Timestamps)
Setter for Activity::Timestamps.
void SetAssets(std::optional< discordpp::ActivityAssets > Assets)
Setter for Activity::Assets.
void AddButton(discordpp::ActivityButton button)
Adds a custom button to the rich presence.
void SetState(std::optional< std::string > State)
Setter for Activity::State.
void SetStart(uint64_t Start)
Setter for ActivityTimestamps::Start.
Struct that stores information about the result of an SDK function call.
discordpp::ErrorType Type() const
The type of error that occurred. See ErrorType for more information.
int32_t ErrorCode() const
A more detailed error code for this failure. Currently the only use of this is when an API request is...
bool Successful() const
Equivalent to type == ErrorType::None.
float Update(Component *components, std::size_t count, bool viewerInside)
const char * VehicleWikiUrl(std::string_view imageKey)
const char * LocationWikiUrl(std::string_view imageKey)
constexpr std::uint64_t ApplicationId
constexpr std::uint32_t SteamApplicationId
std::unique_ptr< SocialSdk > CreateSocialSdk(const Log &log)
std::function< void(const char *, bool warning)> Log
std::string largeImageKey
std::uint64_t startMilliseconds
std::string smallImageKey
std::string smallImageText
std::string largeImageText