From 635de11af2e6b3540b7dbf1a6d42b145fb14ca1b Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Fri, 18 Jun 2021 22:05:25 +0200 Subject: [PATCH] early-access version 1795 --- README.md | 2 +- externals/discord-rpc/.travis.yml | 2 +- externals/discord-rpc/README.md | 66 +++++++++-------- .../Assets/DiscordController.cs | 16 ++-- .../button-clicker/Assets/DiscordRpc.cs | 73 ++++++++++++++----- .../examples/send-presence/send-presence.c | 1 + .../Private/DiscordRpcBlueprint.cpp | 1 + .../DiscordRpc/Public/DiscordRpcBlueprint.h | 12 +++ externals/discord-rpc/include/discord_rpc.h | 3 + externals/discord-rpc/src/CMakeLists.txt | 5 ++ externals/discord-rpc/src/connection_unix.cpp | 3 + .../src/discord_register_linux.cpp | 4 +- .../discord-rpc/src/discord_register_win.cpp | 3 +- externals/discord-rpc/src/discord_rpc.cpp | 16 ++-- externals/discord-rpc/src/rpc_connection.cpp | 8 +- externals/discord-rpc/src/serialization.cpp | 7 +- 16 files changed, 144 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 637d5be75..ecc5010b4 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1794. +This is the source code for early-access 1795. ## Legal Notice diff --git a/externals/discord-rpc/.travis.yml b/externals/discord-rpc/.travis.yml index 5d091317c..42cc09d5b 100755 --- a/externals/discord-rpc/.travis.yml +++ b/externals/discord-rpc/.travis.yml @@ -43,5 +43,5 @@ before_install: script: - mkdir build - cd build - - cmake -DCLANG_FORMAT_SUFFIX=$CLANG_FORMAT_SUFFIX --config Release .. + - cmake -DCLANG_FORMAT_SUFFIX=$CLANG_FORMAT_SUFFIX -DWARNINGS_AS_ERRORS=On --config Release .. - cmake --build . -- -j2 diff --git a/externals/discord-rpc/README.md b/externals/discord-rpc/README.md index 48e15506c..1285fb844 100755 --- a/externals/discord-rpc/README.md +++ b/externals/discord-rpc/README.md @@ -1,5 +1,11 @@ # Discord RPC +## Deprecation Notice + +This library has been deprecated in favor of Discord's GameSDK. [Learn more here](https://discordapp.com/developers/docs/game-sdk/sdk-starter-guide) + +--- + This is a library for interfacing your game with a locally running Discord desktop client. It's known to work on Windows, macOS, and Linux. You can use the lib directly if you like, or use it as a guide to writing your own if it doesn't suit your game as is. PRs/feedback welcome if you have an improvement everyone might want, or can describe how this doesn't meet your needs. Included here are some quick demos that implement the very minimal subset to show current status, and @@ -15,6 +21,33 @@ Zeroith, you should be set up to build things because you are a game developer, First, head on over to the [Discord developers site](https://discordapp.com/developers/applications/me) and make yourself an app. Keep track of `Client ID` -- you'll need it here to pass to the init function. +### Unreal Engine 4 Setup + +To use the Rich Presense plugin with Unreal Engine Projects: + +1. Download the latest [release](https://github.com/discordapp/discord-rpc/releases) for each operating system you are targeting and the zipped source code +2. In the source code zip, copy the UE plugin—`examples/unrealstatus/Plugins/discordrpc`—to your project's plugin directory +3. At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create an `Include` folder and copy `discord_rpc.h` and `discord_register.h` to it from the zip +4. Follow the steps below for each OS +5. Build your UE4 project +6. Launch the editor, and enable the Discord plugin. + +#### Windows + +- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Win64` folder +- Copy `lib/discord-rpc.lib` and `bin/discord-rpc.dll` from `[RELEASE_ZIP]/win64-dynamic` to the `Win64` folder + +#### Mac + +- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Mac` folder +- Copy `libdiscord-rpc.dylib` from `[RELEASE_ZIP]/osx-dynamic/lib` to the `Mac` folder + +#### Linux + +- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Linux` folder +- Inside, create another folder `x86_64-unknown-linux-gnu` +- Copy `libdiscord-rpc.so` from `[RELEASE_ZIP]/linux-dynamic/lib` to `Linux/x86_64-unknown-linux-gnu` + ### Unity Setup If you're a Unity developer looking to integrate Rich Presence into your game, follow this simple guide to get started towards success: @@ -29,14 +62,14 @@ We've got our `Plugins` folder ready, so let's get platform-specific! 4. Create `x86` and `x86_64` folders inside `Assets/Plugins/` 5. Copy `discord-rpc-win/win64-dynamic/bin/discord-rpc.dll` to `Assets/Plugins/x86_64/` -6. Copy `discord-rpc-win/win32-dynamic/bin/discord-rpc.dll` to `Assets/Plguins/x86/` +6. Copy `discord-rpc-win/win32-dynamic/bin/discord-rpc.dll` to `Assets/Plugins/x86/` 7. Click on both DLLs and make sure they are targetting the correct architectures in the Unity editor properties pane 8. Done! #### MacOS 4. Copy `discord-rpc-osx/osx-dynamic/lib/libdiscord-rpc.dylib` to `Assets/Plugins/` -5. Rename `libdiscord-rpc.dylib` to `libdiscord-rpc.bundle` +5. Rename `libdiscord-rpc.dylib` to `discord-rpc.bundle` 6. Done! #### Linux @@ -101,33 +134,6 @@ This is a sample [Unity](https://unity3d.com/) project that wraps a DLL version This is a sample [Unreal](https://www.unrealengine.com) project that wraps the DLL version of the library with an Unreal plugin, exposes a blueprint class for interacting with it, and uses that to make a very simple UI. Run `python build.py unreal` in the root directory to build the correct library files and place them in their respective folders. -### Using the Unreal Engine plugin with your own project - -To use the Rich Presense plugin with Unreal Engine Projects: - -1. Download the latest [release](https://github.com/discordapp/discord-rpc/releases) for each operating system you are targeting and the zipped source code -2. In the source code zip, copy the UE plugin—`examples/unrealstatus/Plugins/discordrpc`—to your project's plugin directory -3. At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create an `Include` folder and copy `discord_rpc.h` and `discord_register.h` to it from the zip -4. Follow the steps below for each OS -5. Build your UE4 project -6. Launch the editor, and enable the Discord plugin. - -#### Windows - -- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Win64` folder -- Copy `lib/discord-rpc.lib` and `bin/discord-rpc.dll` from `[RELEASE_ZIP]/win64-dynamic` to the `Win64` folder - -#### Mac - -- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Mac` folder -- Copy `libdiscord-rpc.dylib` from `[RELEASE_ZIP]/osx-dynamic/lib` to the `Mac` folder - -#### Linux - -- At `[YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/`, create a `Linux` folder -- Inside, create another folder `x86_64-unknown-linux-gnu` -- Copy `libdiscord-rpc.so` from `[RELEASE_ZIP]/linux-dynamic/lib` to `Linux/x86_64-unknown-linux-gnu` - ## Wrappers and Implementations Below is a table of unofficial, community-developed wrappers for and implementations of Rich Presence in various languages. If you would like to have yours added, please make a pull request adding your repository to the table. The repository should include: @@ -141,7 +147,7 @@ Below is a table of unofficial, community-developed wrappers for and implementat | Name | Language | | ------------------------------------------------------------------------- | --------------------------------- | | [Discord RPC C#](https://github.com/Lachee/discord-rpc-csharp) | C# | -| [DerelictDiscordRPC](https://github.com/voidblaster/DerelictDiscordRPC) | [D](https://dlang.org/) | +| [Discord RPC D](https://github.com/voidblaster/discord-rpc-d) | [D](https://dlang.org/) | | [discord-rpc.jar](https://github.com/Vatuu/discord-rpc 'Discord-RPC.jar') | Java | | [java-discord-rpc](https://github.com/MinnDevelopment/java-discord-rpc) | Java | | [Discord-IPC](https://github.com/jagrosh/DiscordIPC) | Java | diff --git a/externals/discord-rpc/examples/button-clicker/Assets/DiscordController.cs b/externals/discord-rpc/examples/button-clicker/Assets/DiscordController.cs index 182d31d8a..7319d5fa3 100755 --- a/externals/discord-rpc/examples/button-clicker/Assets/DiscordController.cs +++ b/externals/discord-rpc/examples/button-clicker/Assets/DiscordController.cs @@ -14,7 +14,6 @@ public class DiscordController : MonoBehaviour public DiscordRpc.RichPresence presence = new DiscordRpc.RichPresence(); public string applicationId; public string optionalSteamId; - public int callbackCalls; public int clickCounter; public DiscordRpc.DiscordUser joinRequest; public UnityEngine.Events.UnityEvent onConnect; @@ -32,6 +31,11 @@ public class DiscordController : MonoBehaviour clickCounter++; presence.details = string.Format("Button clicked {0} times", clickCounter); + presence.joinSecret = "aSecret"; + presence.partyId = "aPartyId"; + presence.partySize = 1; + presence.partyMax = 3; + presence.partyPrivacy = DiscordRpc.PartyPrivacy.Public; DiscordRpc.UpdatePresence(presence); } @@ -52,41 +56,35 @@ public class DiscordController : MonoBehaviour public void ReadyCallback(ref DiscordRpc.DiscordUser connectedUser) { - ++callbackCalls; Debug.Log(string.Format("Discord: connected to {0}#{1}: {2}", connectedUser.username, connectedUser.discriminator, connectedUser.userId)); onConnect.Invoke(); } public void DisconnectedCallback(int errorCode, string message) { - ++callbackCalls; Debug.Log(string.Format("Discord: disconnect {0}: {1}", errorCode, message)); onDisconnect.Invoke(); } public void ErrorCallback(int errorCode, string message) { - ++callbackCalls; Debug.Log(string.Format("Discord: error {0}: {1}", errorCode, message)); } public void JoinCallback(string secret) { - ++callbackCalls; Debug.Log(string.Format("Discord: join ({0})", secret)); onJoin.Invoke(secret); } public void SpectateCallback(string secret) { - ++callbackCalls; Debug.Log(string.Format("Discord: spectate ({0})", secret)); onSpectate.Invoke(secret); } public void RequestCallback(ref DiscordRpc.DiscordUser request) { - ++callbackCalls; Debug.Log(string.Format("Discord: join request {0}#{1}: {2}", request.username, request.discriminator, request.userId)); joinRequest = request; onJoinRequest.Invoke(request); @@ -104,10 +102,8 @@ public class DiscordController : MonoBehaviour void OnEnable() { Debug.Log("Discord: init"); - callbackCalls = 0; - handlers = new DiscordRpc.EventHandlers(); - handlers.readyCallback = ReadyCallback; + handlers.readyCallback += ReadyCallback; handlers.disconnectedCallback += DisconnectedCallback; handlers.errorCallback += ErrorCallback; handlers.joinCallback += JoinCallback; diff --git a/externals/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs b/externals/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs index af82c1c23..f3b1ee597 100755 --- a/externals/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs +++ b/externals/discord-rpc/examples/button-clicker/Assets/DiscordRpc.cs @@ -2,35 +2,44 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; +using AOT; public class DiscordRpc { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ReadyCallback(ref DiscordUser connectedUser); + [MonoPInvokeCallback(typeof(OnReadyInfo))] + public static void ReadyCallback(ref DiscordUser connectedUser) { Callbacks.readyCallback(ref connectedUser); } + public delegate void OnReadyInfo(ref DiscordUser connectedUser); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void DisconnectedCallback(int errorCode, string message); + [MonoPInvokeCallback(typeof(OnDisconnectedInfo))] + public static void DisconnectedCallback(int errorCode, string message) { Callbacks.disconnectedCallback(errorCode, message); } + public delegate void OnDisconnectedInfo(int errorCode, string message); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ErrorCallback(int errorCode, string message); + [MonoPInvokeCallback(typeof(OnErrorInfo))] + public static void ErrorCallback(int errorCode, string message) { Callbacks.errorCallback(errorCode, message); } + public delegate void OnErrorInfo(int errorCode, string message); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void JoinCallback(string secret); + [MonoPInvokeCallback(typeof(OnJoinInfo))] + public static void JoinCallback(string secret) { Callbacks.joinCallback(secret); } + public delegate void OnJoinInfo(string secret); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void SpectateCallback(string secret); + [MonoPInvokeCallback(typeof(OnSpectateInfo))] + public static void SpectateCallback(string secret) { Callbacks.spectateCallback(secret); } + public delegate void OnSpectateInfo(string secret); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void RequestCallback(ref DiscordUser request); + [MonoPInvokeCallback(typeof(OnRequestInfo))] + public static void RequestCallback(ref DiscordUser request) { Callbacks.requestCallback(ref request); } + public delegate void OnRequestInfo(ref DiscordUser request); + + static EventHandlers Callbacks { get; set; } public struct EventHandlers { - public ReadyCallback readyCallback; - public DisconnectedCallback disconnectedCallback; - public ErrorCallback errorCallback; - public JoinCallback joinCallback; - public SpectateCallback spectateCallback; - public RequestCallback requestCallback; + public OnReadyInfo readyCallback; + public OnDisconnectedInfo disconnectedCallback; + public OnErrorInfo errorCallback; + public OnJoinInfo joinCallback; + public OnSpectateInfo spectateCallback; + public OnRequestInfo requestCallback; } [Serializable, StructLayout(LayoutKind.Sequential)] @@ -47,6 +56,7 @@ public class DiscordRpc public IntPtr partyId; /* max 128 bytes */ public int partySize; public int partyMax; + public int partyPrivacy; public IntPtr matchSecret; /* max 128 bytes */ public IntPtr joinSecret; /* max 128 bytes */ public IntPtr spectateSecret; /* max 128 bytes */ @@ -69,8 +79,29 @@ public class DiscordRpc Ignore = 2 } + public enum PartyPrivacy + { + Private = 0, + Public = 1 + } + + public static void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId) + { + Callbacks = handlers; + + EventHandlers staticEventHandlers = new EventHandlers(); + staticEventHandlers.readyCallback += DiscordRpc.ReadyCallback; + staticEventHandlers.disconnectedCallback += DiscordRpc.DisconnectedCallback; + staticEventHandlers.errorCallback += DiscordRpc.ErrorCallback; + staticEventHandlers.joinCallback += DiscordRpc.JoinCallback; + staticEventHandlers.spectateCallback += DiscordRpc.SpectateCallback; + staticEventHandlers.requestCallback += DiscordRpc.RequestCallback; + + InitializeInternal(applicationId, ref staticEventHandlers, autoRegister, optionalSteamId); + } + [DllImport("discord-rpc", EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)] - public static extern void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId); + static extern void InitializeInternal(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId); [DllImport("discord-rpc", EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)] public static extern void Shutdown(); @@ -113,6 +144,7 @@ public class DiscordRpc public string partyId; /* max 128 bytes */ public int partySize; public int partyMax; + public PartyPrivacy partyPrivacy; public string matchSecret; /* max 128 bytes */ public string joinSecret; /* max 128 bytes */ public string spectateSecret; /* max 128 bytes */ @@ -140,6 +172,7 @@ public class DiscordRpc _presence.partyId = StrToPtr(partyId); _presence.partySize = partySize; _presence.partyMax = partyMax; + _presence.partyPrivacy = (int)partyPrivacy; _presence.matchSecret = StrToPtr(matchSecret); _presence.joinSecret = StrToPtr(joinSecret); _presence.spectateSecret = StrToPtr(spectateSecret); @@ -160,7 +193,7 @@ public class DiscordRpc var buffer = Marshal.AllocHGlobal(convbytecnt + 1); for (int i = 0; i < convbytecnt + 1; i++) { - Marshal.WriteByte(buffer, i , 0); + Marshal.WriteByte(buffer, i, 0); } _buffers.Add(buffer); Marshal.Copy(Encoding.UTF8.GetBytes(input), 0, buffer, convbytecnt); diff --git a/externals/discord-rpc/examples/send-presence/send-presence.c b/externals/discord-rpc/examples/send-presence/send-presence.c index 5449cf86f..1b651f2c4 100755 --- a/externals/discord-rpc/examples/send-presence/send-presence.c +++ b/externals/discord-rpc/examples/send-presence/send-presence.c @@ -47,6 +47,7 @@ static void updateDiscordPresence() discordPresence.partyId = "party1234"; discordPresence.partySize = 1; discordPresence.partyMax = 6; + discordPresence.partyPrivacy = DISCORD_PARTY_PUBLIC; discordPresence.matchSecret = "xyzzy"; discordPresence.joinSecret = "join"; discordPresence.spectateSecret = "look"; diff --git a/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Private/DiscordRpcBlueprint.cpp b/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Private/DiscordRpcBlueprint.cpp index 95388df0b..8925d8e41 100755 --- a/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Private/DiscordRpcBlueprint.cpp +++ b/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Private/DiscordRpcBlueprint.cpp @@ -153,6 +153,7 @@ void UDiscordRpc::UpdatePresence() rp.endTimestamp = RichPresence.endTimestamp; rp.partySize = RichPresence.partySize; rp.partyMax = RichPresence.partyMax; + rp.partyPrivacy = (int)RichPresence.partyPrivacy; rp.instance = RichPresence.instance; Discord_UpdatePresence(&rp); diff --git a/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h b/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h index 17e2f9b29..409eee0d9 100755 --- a/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h +++ b/externals/discord-rpc/examples/unrealstatus/Plugins/discordrpc/Source/DiscordRpc/Public/DiscordRpcBlueprint.h @@ -35,6 +35,16 @@ enum class EDiscordJoinResponseCodes : uint8 DISCORD_REPLY_IGNORE UMETA(DisplayName="Ignore") }; +/** +* Valid party privacy values +*/ +UENUM(BlueprintType) +enum class EDiscordPartyPrivacy: uint8 +{ + DISCORD_PARTY_PRIVATE UMETA(DisplayName="Private"), + DISCORD_PARTY_PUBLIC UMETA(DisplayName="Public") +}; + DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordConnected, const FDiscordUserData&, joinRequest); @@ -77,6 +87,8 @@ struct FDiscordRichPresence { UPROPERTY(BlueprintReadWrite) int partyMax; UPROPERTY(BlueprintReadWrite) + EDiscordPartyPrivacy partyPrivacy; + UPROPERTY(BlueprintReadWrite) FString matchSecret; UPROPERTY(BlueprintReadWrite) FString joinSecret; diff --git a/externals/discord-rpc/include/discord_rpc.h b/externals/discord-rpc/include/discord_rpc.h index 3e1441e05..9470434a8 100755 --- a/externals/discord-rpc/include/discord_rpc.h +++ b/externals/discord-rpc/include/discord_rpc.h @@ -35,6 +35,7 @@ typedef struct DiscordRichPresence { const char* partyId; /* max 128 bytes */ int partySize; int partyMax; + int partyPrivacy; const char* matchSecret; /* max 128 bytes */ const char* joinSecret; /* max 128 bytes */ const char* spectateSecret; /* max 128 bytes */ @@ -60,6 +61,8 @@ typedef struct DiscordEventHandlers { #define DISCORD_REPLY_NO 0 #define DISCORD_REPLY_YES 1 #define DISCORD_REPLY_IGNORE 2 +#define DISCORD_PARTY_PRIVATE 0 +#define DISCORD_PARTY_PUBLIC 1 DISCORD_EXPORT void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers, diff --git a/externals/discord-rpc/src/CMakeLists.txt b/externals/discord-rpc/src/CMakeLists.txt index f9ec2503d..290d76115 100755 --- a/externals/discord-rpc/src/CMakeLists.txt +++ b/externals/discord-rpc/src/CMakeLists.txt @@ -72,6 +72,11 @@ if(UNIX) add_library(discord-rpc ${BASE_RPC_SRC}) target_link_libraries(discord-rpc PUBLIC pthread) + + if (APPLE) + target_link_libraries(discord-rpc PRIVATE "-framework AppKit, -mmacosx-version-min=10.10") + endif (APPLE) + target_compile_options(discord-rpc PRIVATE -g -Wall diff --git a/externals/discord-rpc/src/connection_unix.cpp b/externals/discord-rpc/src/connection_unix.cpp index 6fe359ea4..85dace3cc 100755 --- a/externals/discord-rpc/src/connection_unix.cpp +++ b/externals/discord-rpc/src/connection_unix.cpp @@ -118,5 +118,8 @@ bool BaseConnection::Read(void* data, size_t length) } Close(); } + else if (res == 0) { + Close(); + } return res == (int)length; } diff --git a/externals/discord-rpc/src/discord_register_linux.cpp b/externals/discord-rpc/src/discord_register_linux.cpp index 09911dcc6..dd92eea0d 100755 --- a/externals/discord-rpc/src/discord_register_linux.cpp +++ b/externals/discord-rpc/src/discord_register_linux.cpp @@ -41,7 +41,7 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const command = exePath; } - const char* destopFileFormat = "[Desktop Entry]\n" + const char* desktopFileFormat = "[Desktop Entry]\n" "Name=Game %s\n" "Exec=%s %%u\n" // note: it really wants that %u in there "Type=Application\n" @@ -50,7 +50,7 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const "MimeType=x-scheme-handler/discord-%s;\n"; char desktopFile[2048]; int fileLen = snprintf( - desktopFile, sizeof(desktopFile), destopFileFormat, applicationId, command, applicationId); + desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId); if (fileLen <= 0) { return; } diff --git a/externals/discord-rpc/src/discord_register_win.cpp b/externals/discord-rpc/src/discord_register_win.cpp index e441318dd..0b1c4a13d 100755 --- a/externals/discord-rpc/src/discord_register_win.cpp +++ b/externals/discord-rpc/src/discord_register_win.cpp @@ -7,7 +7,6 @@ #define NOIME #include #include -#include #include /** @@ -20,6 +19,7 @@ * The entire function is rewritten */ #ifdef __MINGW32__ +#include /// strsafe.h fixes static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat, ...) { @@ -34,6 +34,7 @@ static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat, return ret; } #else +#include #include #endif // __MINGW32__ diff --git a/externals/discord-rpc/src/discord_rpc.cpp b/externals/discord-rpc/src/discord_rpc.cpp index 2e44c939c..03924538c 100755 --- a/externals/discord-rpc/src/discord_rpc.cpp +++ b/externals/discord-rpc/src/discord_rpc.cpp @@ -54,6 +54,7 @@ static std::atomic_bool WasJustDisconnected{false}; static std::atomic_bool GotErrorMessage{false}; static std::atomic_bool WasJoinGame{false}; static std::atomic_bool WasSpectateGame{false}; +static std::atomic_bool UpdatePresence{false}; static char JoinGameSecret[256]; static char SpectateGameSecret[256]; static int LastErrorCode{0}; @@ -214,17 +215,17 @@ static void Discord_UpdateConnection(void) } // writes - if (QueuedPresence.length) { + if (UpdatePresence.exchange(false) && QueuedPresence.length) { QueuedMessage local; { std::lock_guard guard(PresenceMutex); local.Copy(QueuedPresence); - QueuedPresence.length = 0; } if (!Connection->Write(local.buffer, local.length)) { // if we fail to send, requeue std::lock_guard guard(PresenceMutex); QueuedPresence.Copy(local); + UpdatePresence.exchange(true); } } @@ -310,6 +311,10 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId, Connection = RpcConnection::Create(applicationId); Connection->onConnect = [](JsonDocument& readyMessage) { Discord_UpdateHandlers(&QueuedHandlers); + if (QueuedPresence.length > 0) { + UpdatePresence.exchange(true); + SignalIOActivity(); + } auto data = GetObjMember(&readyMessage, "data"); auto user = GetObjMember(data, "user"); auto userId = GetStrMember(user, "id"); @@ -335,10 +340,6 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId, Connection->onDisconnect = [](int err, const char* message) { LastDisconnectErrorCode = err; StringCopy(LastDisconnectErrorMessage, message); - { - std::lock_guard guard(HandlerMutex); - Handlers = {}; - } WasJustDisconnected.exchange(true); UpdateReconnectTime(); }; @@ -354,6 +355,8 @@ extern "C" DISCORD_EXPORT void Discord_Shutdown(void) Connection->onConnect = nullptr; Connection->onDisconnect = nullptr; Handlers = {}; + QueuedPresence.length = 0; + UpdatePresence.exchange(false); if (IoThread != nullptr) { IoThread->Stop(); delete IoThread; @@ -369,6 +372,7 @@ extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* std::lock_guard guard(PresenceMutex); QueuedPresence.length = JsonWriteRichPresenceObj( QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence); + UpdatePresence.exchange(true); } SignalIOActivity(); } diff --git a/externals/discord-rpc/src/rpc_connection.cpp b/externals/discord-rpc/src/rpc_connection.cpp index bf9e4cc7a..093316216 100755 --- a/externals/discord-rpc/src/rpc_connection.cpp +++ b/externals/discord-rpc/src/rpc_connection.cpp @@ -26,12 +26,8 @@ void RpcConnection::Open() return; } - if (state == State::Disconnected) { - if (connection->Open()) { - } - else { - return; - } + if (state == State::Disconnected && !connection->Open()) { + return; } if (state == State::SentHandshake) { diff --git a/externals/discord-rpc/src/serialization.cpp b/externals/discord-rpc/src/serialization.cpp index 6cc1e9013..70efa637f 100755 --- a/externals/discord-rpc/src/serialization.cpp +++ b/externals/discord-rpc/src/serialization.cpp @@ -134,7 +134,7 @@ size_t JsonWriteRichPresenceObj(char* dest, } if ((presence->partyId && presence->partyId[0]) || presence->partySize || - presence->partyMax) { + presence->partyMax || presence->partyPrivacy) { WriteObject party(writer, "party"); WriteOptionalString(writer, "id", presence->partyId); if (presence->partySize && presence->partyMax) { @@ -142,6 +142,11 @@ size_t JsonWriteRichPresenceObj(char* dest, writer.Int(presence->partySize); writer.Int(presence->partyMax); } + + if (presence->partyPrivacy) { + WriteKey(writer, "privacy"); + writer.Int(presence->partyPrivacy); + } } if ((presence->matchSecret && presence->matchSecret[0]) ||