Skip to content

Commit

Permalink
actually do a null-terminated array cause it's nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
p0358 committed Nov 2, 2023
1 parent 36b372a commit 57bf005
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/send-presence/send-presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ static void updateDiscordPresence()
DiscordButton buttons[] = {
{.label = "Test", .url = "https://example.com"},
{.label = "Test 2", .url = "https://discord.gg/fortnite"},
{0, 0},
};

if (SendButtons) {
discordPresence.buttons = buttons;
discordPresence.numButtons = sizeof(buttons) / sizeof(DiscordButton);
}

Discord_UpdatePresence(&discordPresence);
Expand Down
1 change: 0 additions & 1 deletion include/discord_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ typedef struct DiscordRichPresence {
const char* joinSecret; /* max 128 bytes */
const char* spectateSecret; /* max 128 bytes */
int8_t instance;
uint8_t numButtons;
const DiscordButton* buttons;
} DiscordRichPresence;

Expand Down
8 changes: 3 additions & 5 deletions src/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ size_t JsonWriteRichPresenceObj(char* dest,
writer.Key("instance");
writer.Bool(presence->instance != 0);

if (presence->buttons && presence->numButtons > 0) {
const auto btns = presence->buttons;
if (presence->buttons) {
WriteArray buttons(writer, "buttons");

for (uint8_t i = 0; i < presence->numButtons; i++) {

for (uint8_t i = 0; true; i++) {
const DiscordButton& btn = presence->buttons[i];

if (!btn.label || !btn.label[0])
continue;
break;

WriteObject button(writer);
WriteKey(writer, "url");
Expand Down

0 comments on commit 57bf005

Please sign in to comment.