Skip to content

Commit

Permalink
Unity ajt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
crmarsh committed Nov 2, 2017
1 parent aa79c70 commit 3bdb88d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 1 addition & 4 deletions examples/button-clicker/Assets/DiscordRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ public struct RichPresence
public bool instance;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.Serializable]
public struct JoinRequest
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)]
public string userId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
public string username;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string avatar;
}

Expand Down
Binary file modified examples/button-clicker/Assets/Resources/discord-rpc.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions include/discord-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ typedef struct DiscordRichPresence {
} DiscordRichPresence;

typedef struct DiscordJoinRequest {
char userId[24];
char username[48];
char avatar[128];
const char* userId;
const char* username;
const char* avatar;
} DiscordJoinRequest;

typedef struct DiscordEventHandlers {
Expand Down
11 changes: 9 additions & 2 deletions src/discord-rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ struct QueuedMessage {
}
};

struct JoinRequest {
char userId[24];
char username[48];
char avatar[128];
};

static RpcConnection* Connection{nullptr};
static DiscordEventHandlers Handlers{};
static std::atomic_bool WasJustConnected{false};
Expand All @@ -48,7 +54,7 @@ static char LastDisconnectErrorMessage[256];
static std::mutex PresenceMutex;
static QueuedMessage QueuedPresence{};
static MsgQueue<QueuedMessage, MessageQueueSize> SendQueue;
static MsgQueue<DiscordJoinRequest, JoinQueueSize> JoinAskQueue;
static MsgQueue<JoinRequest, JoinQueueSize> JoinAskQueue;

// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential
// backoff from 0.5 seconds to 1 minute
Expand Down Expand Up @@ -353,7 +359,8 @@ extern "C" DISCORD_EXPORT void Discord_RunCallbacks()
while (JoinAskQueue.HavePendingSends()) {
auto req = JoinAskQueue.GetNextSendMessage();
if (Handlers.joinRequest) {
Handlers.joinRequest(req);
DiscordJoinRequest djr{req->userId, req->username, req->avatar};
Handlers.joinRequest(&djr);
}
JoinAskQueue.CommitSend();
}
Expand Down

0 comments on commit 3bdb88d

Please sign in to comment.