From 9c4b307dcbac1de1e1b02dbc707deaae03115d41 Mon Sep 17 00:00:00 2001 From: radius Date: Tue, 16 Oct 2018 18:16:01 -0500 Subject: [PATCH] Update Discord RPC Squashed 'deps/discord-rpc/' changes from ba9fe00c4d..7716eadca3 7716eadca3 Update D binding link (#234) e32d001809 readme nits 2cb9813eb6 Unity specific DLL setup af380116a0 Check C# strings against UTF8 bytes instead of clamping (#221) 3d3ae7129d Fix mismatched signs in comparison after b44defe (#209) b44defe60a [Linux] Null-terminate output from readlink in Discord_Register. (#208) dfad394be0 Added enum for response codes (#207) a3ad6afee2 Added Discord RPC C# implementation to list. (#205) 7c41a8ec19 Fixed issue with Discord RPC not updating presence during shutdown (#189) 5df1c5ae6d copy the whole folder UE4 c05c7148dd Updated README with UE plugin instructions (#183) git-subtree-dir: deps/discord-rpc git-subtree-split: 7716eadca31a0d556f9d71fb610943b203470533 --- .../button-clicker/Assets/DiscordRpc.cs | 58 ++++++------------- .../DiscordRpc/Public/DiscordRpcBlueprint.h | 10 ++++ .../src/discord_register_linux.cpp | 4 +- deps/discord-rpc/src/discord_rpc.cpp | 3 +- 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/deps/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs b/deps/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs index dec1ade0f5..af82c1c231 100644 --- a/deps/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs +++ b/deps/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs @@ -129,20 +129,20 @@ public class DiscordRpc FreeMem(); } - _presence.state = StrToPtr(state, 128); - _presence.details = StrToPtr(details, 128); + _presence.state = StrToPtr(state); + _presence.details = StrToPtr(details); _presence.startTimestamp = startTimestamp; _presence.endTimestamp = endTimestamp; - _presence.largeImageKey = StrToPtr(largeImageKey, 32); - _presence.largeImageText = StrToPtr(largeImageText, 128); - _presence.smallImageKey = StrToPtr(smallImageKey, 32); - _presence.smallImageText = StrToPtr(smallImageText, 128); - _presence.partyId = StrToPtr(partyId, 128); + _presence.largeImageKey = StrToPtr(largeImageKey); + _presence.largeImageText = StrToPtr(largeImageText); + _presence.smallImageKey = StrToPtr(smallImageKey); + _presence.smallImageText = StrToPtr(smallImageText); + _presence.partyId = StrToPtr(partyId); _presence.partySize = partySize; _presence.partyMax = partyMax; - _presence.matchSecret = StrToPtr(matchSecret, 128); - _presence.joinSecret = StrToPtr(joinSecret, 128); - _presence.spectateSecret = StrToPtr(spectateSecret, 128); + _presence.matchSecret = StrToPtr(matchSecret); + _presence.joinSecret = StrToPtr(joinSecret); + _presence.spectateSecret = StrToPtr(spectateSecret); _presence.instance = instance; return _presence; @@ -152,16 +152,18 @@ public class DiscordRpc /// Returns a pointer to a representation of the given string with a size of maxbytes /// /// String to convert - /// Max number of bytes to use /// Pointer to the UTF-8 representation of - private IntPtr StrToPtr(string input, int maxbytes) + private IntPtr StrToPtr(string input) { if (string.IsNullOrEmpty(input)) return IntPtr.Zero; - var convstr = StrClampBytes(input, maxbytes); - var convbytecnt = Encoding.UTF8.GetByteCount(convstr); - var buffer = Marshal.AllocHGlobal(convbytecnt); + var convbytecnt = Encoding.UTF8.GetByteCount(input); + var buffer = Marshal.AllocHGlobal(convbytecnt + 1); + for (int i = 0; i < convbytecnt + 1; i++) + { + Marshal.WriteByte(buffer, i , 0); + } _buffers.Add(buffer); - Marshal.Copy(Encoding.UTF8.GetBytes(convstr), 0, buffer, convbytecnt); + Marshal.Copy(Encoding.UTF8.GetBytes(input), 0, buffer, convbytecnt); return buffer; } @@ -181,30 +183,6 @@ public class DiscordRpc return Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(str)); } - /// - /// Clamp the string to the given byte length preserving null termination - /// - /// string to clamp - /// max bytes the resulting string should have (including null termination) - /// null terminated string with a byte length less or equal to - private static string StrClampBytes(string toclamp, int maxbytes) - { - var str = StrToUtf8NullTerm(toclamp); - var strbytes = Encoding.UTF8.GetBytes(str); - - if (strbytes.Length <= maxbytes) - { - return str; - } - - var newstrbytes = new byte[] { }; - Array.Copy(strbytes, 0, newstrbytes, 0, maxbytes - 1); - newstrbytes[newstrbytes.Length - 1] = 0; - newstrbytes[newstrbytes.Length - 2] = 0; - - return Encoding.UTF8.GetString(newstrbytes); - } - /// /// Free the allocated memory for conversion to /// diff --git a/deps/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h b/deps/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h index 2d6521124b..17e2f9b29e 100644 --- a/deps/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h +++ b/deps/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h @@ -24,6 +24,16 @@ struct FDiscordUserData { FString avatar; }; +/** +* Valid response codes for Respond function +*/ +UENUM(BlueprintType) +enum class EDiscordJoinResponseCodes : uint8 +{ + DISCORD_REPLY_NO UMETA(DisplayName="No"), + DISCORD_REPLY_YES UMETA(DisplayName="Yes"), + DISCORD_REPLY_IGNORE UMETA(DisplayName="Ignore") +}; DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All); diff --git a/deps/discord-rpc/src/discord_register_linux.cpp b/deps/discord-rpc/src/discord_register_linux.cpp index b10f96db66..09911dcc6c 100644 --- a/deps/discord-rpc/src/discord_register_linux.cpp +++ b/deps/discord-rpc/src/discord_register_linux.cpp @@ -33,9 +33,11 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char exePath[1024]; if (!command || !command[0]) { - if (readlink("/proc/self/exe", exePath, sizeof(exePath)) <= 0) { + ssize_t size = readlink("/proc/self/exe", exePath, sizeof(exePath)); + if (size <= 0 || size >= (ssize_t)sizeof(exePath)) { return; } + exePath[size] = '\0'; command = exePath; } diff --git a/deps/discord-rpc/src/discord_rpc.cpp b/deps/discord-rpc/src/discord_rpc.cpp index dedb3f1539..2e44c939ce 100644 --- a/deps/discord-rpc/src/discord_rpc.cpp +++ b/deps/discord-rpc/src/discord_rpc.cpp @@ -89,10 +89,11 @@ public: keepRunning.store(true); ioThread = std::thread([&]() { const std::chrono::duration maxWait{500LL}; + Discord_UpdateConnection(); while (keepRunning.load()) { - Discord_UpdateConnection(); std::unique_lock lock(waitForIOMutex); waitForIOActivity.wait_for(lock, maxWait); + Discord_UpdateConnection(); } }); }