├── Host
├── YTDPwin
│ ├── YTDPsetup
│ │ └── desktop.ini
│ ├── YTDPwin
│ │ ├── YTDPwin.vcxproj.user
│ │ ├── YTDPwin.vcxproj.filters
│ │ └── YTDPwin.vcxproj
│ └── YTDPwin.sln
├── YTDPlogo.ico
├── Discord
│ ├── Lib
│ │ ├── discord_game_sdk.dll
│ │ └── discord_game_sdk.dll.lib
│ └── API
│ │ ├── discord.h
│ │ ├── image_manager.h
│ │ ├── user_manager.h
│ │ ├── application_manager.h
│ │ ├── relationship_manager.h
│ │ ├── overlay_manager.h
│ │ ├── voice_manager.h
│ │ ├── achievement_manager.h
│ │ ├── store_manager.h
│ │ ├── event.h
│ │ ├── activity_manager.h
│ │ ├── storage_manager.h
│ │ ├── network_manager.h
│ │ ├── image_manager.cpp
│ │ ├── core.h
│ │ ├── user_manager.cpp
│ │ ├── relationship_manager.cpp
│ │ ├── application_manager.cpp
│ │ ├── network_manager.cpp
│ │ ├── achievement_manager.cpp
│ │ ├── voice_manager.cpp
│ │ ├── overlay_manager.cpp
│ │ ├── lobby_manager.h
│ │ ├── store_manager.cpp
│ │ ├── core.cpp
│ │ ├── storage_manager.cpp
│ │ ├── activity_manager.cpp
│ │ ├── types.h
│ │ └── types.cpp
├── main.json
└── main.cpp
├── Extension
├── Images
│ ├── icon16.png
│ ├── icon48.png
│ ├── icon128.png
│ └── ytdpSettings.png
├── manifest.json
├── content_loader.js
├── content.js
├── popup.css
├── popup.html
└── background.js
├── Screenshots
├── newUiExample.png
├── ytdpScreenshot1.png
├── ytdpScreenshot2.png
├── ytdpScreenshot3.png
└── ytdpScreenshot4.png
├── NodeHost
├── package.json
├── src
│ └── app.js
└── package-lock.json
├── .gitignore
├── LICENSE.txt
└── README.md
/Host/YTDPwin/YTDPsetup/desktop.ini:
--------------------------------------------------------------------------------
1 | [ViewState]
2 | Mode=
3 | Vid=
4 | FolderType=Generic
5 |
--------------------------------------------------------------------------------
/Host/YTDPlogo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Host/YTDPlogo.ico
--------------------------------------------------------------------------------
/Extension/Images/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Extension/Images/icon16.png
--------------------------------------------------------------------------------
/Extension/Images/icon48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Extension/Images/icon48.png
--------------------------------------------------------------------------------
/Extension/Images/icon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Extension/Images/icon128.png
--------------------------------------------------------------------------------
/Screenshots/newUiExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Screenshots/newUiExample.png
--------------------------------------------------------------------------------
/Screenshots/ytdpScreenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Screenshots/ytdpScreenshot1.png
--------------------------------------------------------------------------------
/Screenshots/ytdpScreenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Screenshots/ytdpScreenshot2.png
--------------------------------------------------------------------------------
/Screenshots/ytdpScreenshot3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Screenshots/ytdpScreenshot3.png
--------------------------------------------------------------------------------
/Screenshots/ytdpScreenshot4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Screenshots/ytdpScreenshot4.png
--------------------------------------------------------------------------------
/Extension/Images/ytdpSettings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Extension/Images/ytdpSettings.png
--------------------------------------------------------------------------------
/Host/Discord/Lib/discord_game_sdk.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Host/Discord/Lib/discord_game_sdk.dll
--------------------------------------------------------------------------------
/Host/Discord/Lib/discord_game_sdk.dll.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XFG16/YouTubeDiscordPresence/HEAD/Host/Discord/Lib/discord_game_sdk.dll.lib
--------------------------------------------------------------------------------
/Host/YTDPwin/YTDPwin/YTDPwin.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Host/main.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.ytdp.discord.presence",
3 | "description": "Component of the YouTubeDiscordPresence extension that allows the usage of native messaging.",
4 | "path": "YTDPwin.exe",
5 | "type": "stdio",
6 | "allowed_origins": [
7 | "chrome-extension://hnmeidgkfcbpjjjpmjmpehjdljlaeaaa/"
8 | ]
9 | }
--------------------------------------------------------------------------------
/NodeHost/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "youtube-discord-presence",
3 | "version": "1.0.0",
4 | "description": "NodeJS version of the YouTubeDiscordPresence desktop component",
5 | "main": "app.js",
6 | "scripts": {
7 | "test": "node ./src/app.js"
8 | },
9 | "author": "Michael Ren",
10 | "license": "MIT",
11 | "dependencies": {
12 | "discord-rpc": "^4.0.1"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Host/Discord/API/discord.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 | #include "core.h"
5 | #include "application_manager.h"
6 | #include "user_manager.h"
7 | #include "image_manager.h"
8 | #include "activity_manager.h"
9 | #include "relationship_manager.h"
10 | #include "lobby_manager.h"
11 | #include "network_manager.h"
12 | #include "overlay_manager.h"
13 | #include "storage_manager.h"
14 | #include "store_manager.h"
15 | #include "voice_manager.h"
16 | #include "achievement_manager.h"
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Host/main.dSYM
2 | Host/log.txt
3 | Extension.zip
4 | Extension/.DS_Store
5 | .DS_Store
6 | Host/YTDPwin/x64
7 | Host/YTDPwin/YTDPwin/log.txt
8 | Host/YTDPwin/YTDPwin/x64
9 | Host/YTDPwin/UpgradeLog.htm
10 | Host/YTDPwin/UpgradeLog2.htm
11 | Host/YTDPwin/YTDPsetup/Debug
12 | Host/YTDPwin/YTDPsetup/Release
13 | .vscode
14 | .vs
15 | *.o
16 | *.msi
17 | *.exe
18 | *.out
19 | *.zip
20 | NodeHost/node_modules
21 | NodeHost/src/app-linux
22 | NodeHost/src/app-macos
23 | NodeHost/src/bundle.js
24 | test.js
25 | config.json
26 | test.bat
27 | .env
28 |
--------------------------------------------------------------------------------
/Host/Discord/API/image_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class ImageManager final {
8 | public:
9 | ~ImageManager() = default;
10 |
11 | void Fetch(ImageHandle handle, bool refresh, std::function callback);
12 | Result GetDimensions(ImageHandle handle, ImageDimensions* dimensions);
13 | Result GetData(ImageHandle handle, std::uint8_t* data, std::uint32_t dataLength);
14 |
15 | private:
16 | friend class Core;
17 |
18 | ImageManager() = default;
19 | ImageManager(ImageManager const& rhs) = delete;
20 | ImageManager& operator=(ImageManager const& rhs) = delete;
21 | ImageManager(ImageManager&& rhs) = delete;
22 | ImageManager& operator=(ImageManager&& rhs) = delete;
23 |
24 | IDiscordImageManager* internal_;
25 | static IDiscordImageEvents events_;
26 | };
27 |
28 | } // namespace discord
29 |
--------------------------------------------------------------------------------
/Host/Discord/API/user_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class UserManager final {
8 | public:
9 | ~UserManager() = default;
10 |
11 | Result GetCurrentUser(User* currentUser);
12 | void GetUser(UserId userId, std::function callback);
13 | Result GetCurrentUserPremiumType(PremiumType* premiumType);
14 | Result CurrentUserHasFlag(UserFlag flag, bool* hasFlag);
15 |
16 | Event<> OnCurrentUserUpdate;
17 |
18 | private:
19 | friend class Core;
20 |
21 | UserManager() = default;
22 | UserManager(UserManager const& rhs) = delete;
23 | UserManager& operator=(UserManager const& rhs) = delete;
24 | UserManager(UserManager&& rhs) = delete;
25 | UserManager& operator=(UserManager&& rhs) = delete;
26 |
27 | IDiscordUserManager* internal_;
28 | static IDiscordUserEvents events_;
29 | };
30 |
31 | } // namespace discord
32 |
--------------------------------------------------------------------------------
/Host/Discord/API/application_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class ApplicationManager final {
8 | public:
9 | ~ApplicationManager() = default;
10 |
11 | void ValidateOrExit(std::function callback);
12 | void GetCurrentLocale(char locale[128]);
13 | void GetCurrentBranch(char branch[4096]);
14 | void GetOAuth2Token(std::function callback);
15 | void GetTicket(std::function callback);
16 |
17 | private:
18 | friend class Core;
19 |
20 | ApplicationManager() = default;
21 | ApplicationManager(ApplicationManager const& rhs) = delete;
22 | ApplicationManager& operator=(ApplicationManager const& rhs) = delete;
23 | ApplicationManager(ApplicationManager&& rhs) = delete;
24 | ApplicationManager& operator=(ApplicationManager&& rhs) = delete;
25 |
26 | IDiscordApplicationManager* internal_;
27 | static IDiscordApplicationEvents events_;
28 | };
29 |
30 | } // namespace discord
31 |
--------------------------------------------------------------------------------
/Host/Discord/API/relationship_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class RelationshipManager final {
8 | public:
9 | ~RelationshipManager() = default;
10 |
11 | void Filter(std::function filter);
12 | Result Count(std::int32_t* count);
13 | Result Get(UserId userId, Relationship* relationship);
14 | Result GetAt(std::uint32_t index, Relationship* relationship);
15 |
16 | Event<> OnRefresh;
17 | Event OnRelationshipUpdate;
18 |
19 | private:
20 | friend class Core;
21 |
22 | RelationshipManager() = default;
23 | RelationshipManager(RelationshipManager const& rhs) = delete;
24 | RelationshipManager& operator=(RelationshipManager const& rhs) = delete;
25 | RelationshipManager(RelationshipManager&& rhs) = delete;
26 | RelationshipManager& operator=(RelationshipManager&& rhs) = delete;
27 |
28 | IDiscordRelationshipManager* internal_;
29 | static IDiscordRelationshipEvents events_;
30 | };
31 |
32 | } // namespace discord
33 |
--------------------------------------------------------------------------------
/Host/Discord/API/overlay_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class OverlayManager final {
8 | public:
9 | ~OverlayManager() = default;
10 |
11 | void IsEnabled(bool* enabled);
12 | void IsLocked(bool* locked);
13 | void SetLocked(bool locked, std::function callback);
14 | void OpenActivityInvite(ActivityActionType type, std::function callback);
15 | void OpenGuildInvite(char const* code, std::function callback);
16 | void OpenVoiceSettings(std::function callback);
17 |
18 | Event OnToggle;
19 |
20 | private:
21 | friend class Core;
22 |
23 | OverlayManager() = default;
24 | OverlayManager(OverlayManager const& rhs) = delete;
25 | OverlayManager& operator=(OverlayManager const& rhs) = delete;
26 | OverlayManager(OverlayManager&& rhs) = delete;
27 | OverlayManager& operator=(OverlayManager&& rhs) = delete;
28 |
29 | IDiscordOverlayManager* internal_;
30 | static IDiscordOverlayEvents events_;
31 | };
32 |
33 | } // namespace discord
34 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2022–Present Michael Ren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/Host/Discord/API/voice_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class VoiceManager final {
8 | public:
9 | ~VoiceManager() = default;
10 |
11 | Result GetInputMode(InputMode* inputMode);
12 | void SetInputMode(InputMode inputMode, std::function callback);
13 | Result IsSelfMute(bool* mute);
14 | Result SetSelfMute(bool mute);
15 | Result IsSelfDeaf(bool* deaf);
16 | Result SetSelfDeaf(bool deaf);
17 | Result IsLocalMute(Snowflake userId, bool* mute);
18 | Result SetLocalMute(Snowflake userId, bool mute);
19 | Result GetLocalVolume(Snowflake userId, std::uint8_t* volume);
20 | Result SetLocalVolume(Snowflake userId, std::uint8_t volume);
21 |
22 | Event<> OnSettingsUpdate;
23 |
24 | private:
25 | friend class Core;
26 |
27 | VoiceManager() = default;
28 | VoiceManager(VoiceManager const& rhs) = delete;
29 | VoiceManager& operator=(VoiceManager const& rhs) = delete;
30 | VoiceManager(VoiceManager&& rhs) = delete;
31 | VoiceManager& operator=(VoiceManager&& rhs) = delete;
32 |
33 | IDiscordVoiceManager* internal_;
34 | static IDiscordVoiceEvents events_;
35 | };
36 |
37 | } // namespace discord
38 |
--------------------------------------------------------------------------------
/Host/Discord/API/achievement_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class AchievementManager final {
8 | public:
9 | ~AchievementManager() = default;
10 |
11 | void SetUserAchievement(Snowflake achievementId,
12 | std::uint8_t percentComplete,
13 | std::function callback);
14 | void FetchUserAchievements(std::function callback);
15 | void CountUserAchievements(std::int32_t* count);
16 | Result GetUserAchievement(Snowflake userAchievementId, UserAchievement* userAchievement);
17 | Result GetUserAchievementAt(std::int32_t index, UserAchievement* userAchievement);
18 |
19 | Event OnUserAchievementUpdate;
20 |
21 | private:
22 | friend class Core;
23 |
24 | AchievementManager() = default;
25 | AchievementManager(AchievementManager const& rhs) = delete;
26 | AchievementManager& operator=(AchievementManager const& rhs) = delete;
27 | AchievementManager(AchievementManager&& rhs) = delete;
28 | AchievementManager& operator=(AchievementManager&& rhs) = delete;
29 |
30 | IDiscordAchievementManager* internal_;
31 | static IDiscordAchievementEvents events_;
32 | };
33 |
34 | } // namespace discord
35 |
--------------------------------------------------------------------------------
/Extension/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "YouTubeDiscordPresence",
3 | "author": "Michael Ren",
4 | "description": "An extension used to create a detailed rich presence for YouTube videos on Discord.",
5 | "version": "1.5.8",
6 | "manifest_version": 3,
7 | "content_scripts": [
8 | {
9 | "matches": [
10 | "https://www.youtube.com/*",
11 | "https://music.youtube.com/*"
12 | ],
13 | "js": [
14 | "content_loader.js"
15 | ]
16 | }
17 | ],
18 | "background": {
19 | "service_worker": "background.js"
20 | },
21 | "action": {
22 | "default_icon": "/Images/icon16.png",
23 | "default_popup": "popup.html"
24 | },
25 | "web_accessible_resources": [
26 | {
27 | "resources": [
28 | "content.js",
29 | "warning.html"
30 | ],
31 | "matches": [
32 | "https://www.youtube.com/*",
33 | "https://music.youtube.com/*"
34 | ]
35 | }
36 | ],
37 | "permissions": [
38 | "nativeMessaging",
39 | "background",
40 | "storage",
41 | "tabs"
42 | ],
43 | "icons": {
44 | "16": "/Images/icon16.png",
45 | "48": "/Images/icon48.png",
46 | "128": "/Images/icon128.png"
47 | }
48 | }
--------------------------------------------------------------------------------
/Host/Discord/API/store_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class StoreManager final {
8 | public:
9 | ~StoreManager() = default;
10 |
11 | void FetchSkus(std::function callback);
12 | void CountSkus(std::int32_t* count);
13 | Result GetSku(Snowflake skuId, Sku* sku);
14 | Result GetSkuAt(std::int32_t index, Sku* sku);
15 | void FetchEntitlements(std::function callback);
16 | void CountEntitlements(std::int32_t* count);
17 | Result GetEntitlement(Snowflake entitlementId, Entitlement* entitlement);
18 | Result GetEntitlementAt(std::int32_t index, Entitlement* entitlement);
19 | Result HasSkuEntitlement(Snowflake skuId, bool* hasEntitlement);
20 | void StartPurchase(Snowflake skuId, std::function callback);
21 |
22 | Event OnEntitlementCreate;
23 | Event OnEntitlementDelete;
24 |
25 | private:
26 | friend class Core;
27 |
28 | StoreManager() = default;
29 | StoreManager(StoreManager const& rhs) = delete;
30 | StoreManager& operator=(StoreManager const& rhs) = delete;
31 | StoreManager(StoreManager&& rhs) = delete;
32 | StoreManager& operator=(StoreManager&& rhs) = delete;
33 |
34 | IDiscordStoreManager* internal_;
35 | static IDiscordStoreEvents events_;
36 | };
37 |
38 | } // namespace discord
39 |
--------------------------------------------------------------------------------
/Host/Discord/API/event.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace discord {
7 |
8 | template
9 | class Event final {
10 | public:
11 | using Token = int;
12 |
13 | Event() { slots_.reserve(4); }
14 |
15 | Event(Event const&) = default;
16 | Event(Event&&) = default;
17 | ~Event() = default;
18 |
19 | Event& operator=(Event const&) = default;
20 | Event& operator=(Event&&) = default;
21 |
22 | template
23 | Token Connect(EventHandler slot)
24 | {
25 | slots_.emplace_back(Slot{nextToken_, std::move(slot)});
26 | return nextToken_++;
27 | }
28 |
29 | void Disconnect(Token token)
30 | {
31 | for (auto& slot : slots_) {
32 | if (slot.token == token) {
33 | slot = slots_.back();
34 | slots_.pop_back();
35 | break;
36 | }
37 | }
38 | }
39 |
40 | void DisconnectAll() { slots_ = {}; }
41 |
42 | void operator()(Args... args)
43 | {
44 | for (auto const& slot : slots_) {
45 | slot.fn(std::forward(args)...);
46 | }
47 | }
48 |
49 | private:
50 | struct Slot {
51 | Token token;
52 | std::function fn;
53 | };
54 |
55 | Token nextToken_{};
56 | std::vector slots_{};
57 | };
58 |
59 | } // namespace discord
60 |
--------------------------------------------------------------------------------
/Host/Discord/API/activity_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class ActivityManager final {
8 | public:
9 | ~ActivityManager() = default;
10 |
11 | Result RegisterCommand(char const* command);
12 | Result RegisterSteam(std::uint32_t steamId);
13 | void UpdateActivity(Activity const& activity, std::function callback);
14 | void ClearActivity(std::function callback);
15 | void SendRequestReply(UserId userId,
16 | ActivityJoinRequestReply reply,
17 | std::function callback);
18 | void SendInvite(UserId userId,
19 | ActivityActionType type,
20 | char const* content,
21 | std::function callback);
22 | void AcceptInvite(UserId userId, std::function callback);
23 |
24 | Event OnActivityJoin;
25 | Event OnActivitySpectate;
26 | Event OnActivityJoinRequest;
27 | Event OnActivityInvite;
28 |
29 | private:
30 | friend class Core;
31 |
32 | ActivityManager() = default;
33 | ActivityManager(ActivityManager const& rhs) = delete;
34 | ActivityManager& operator=(ActivityManager const& rhs) = delete;
35 | ActivityManager(ActivityManager&& rhs) = delete;
36 | ActivityManager& operator=(ActivityManager&& rhs) = delete;
37 |
38 | IDiscordActivityManager* internal_;
39 | static IDiscordActivityEvents events_;
40 | };
41 |
42 | } // namespace discord
43 |
--------------------------------------------------------------------------------
/Host/Discord/API/storage_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class StorageManager final {
8 | public:
9 | ~StorageManager() = default;
10 |
11 | Result Read(char const* name,
12 | std::uint8_t* data,
13 | std::uint32_t dataLength,
14 | std::uint32_t* read);
15 | void ReadAsync(char const* name,
16 | std::function callback);
17 | void ReadAsyncPartial(char const* name,
18 | std::uint64_t offset,
19 | std::uint64_t length,
20 | std::function callback);
21 | Result Write(char const* name, std::uint8_t* data, std::uint32_t dataLength);
22 | void WriteAsync(char const* name,
23 | std::uint8_t* data,
24 | std::uint32_t dataLength,
25 | std::function callback);
26 | Result Delete(char const* name);
27 | Result Exists(char const* name, bool* exists);
28 | void Count(std::int32_t* count);
29 | Result Stat(char const* name, FileStat* stat);
30 | Result StatAt(std::int32_t index, FileStat* stat);
31 | Result GetPath(char path[4096]);
32 |
33 | private:
34 | friend class Core;
35 |
36 | StorageManager() = default;
37 | StorageManager(StorageManager const& rhs) = delete;
38 | StorageManager& operator=(StorageManager const& rhs) = delete;
39 | StorageManager(StorageManager&& rhs) = delete;
40 | StorageManager& operator=(StorageManager&& rhs) = delete;
41 |
42 | IDiscordStorageManager* internal_;
43 | static IDiscordStorageEvents events_;
44 | };
45 |
46 | } // namespace discord
47 |
--------------------------------------------------------------------------------
/Host/Discord/API/network_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class NetworkManager final {
8 | public:
9 | ~NetworkManager() = default;
10 |
11 | /**
12 | * Get the local peer ID for this process.
13 | */
14 | void GetPeerId(NetworkPeerId* peerId);
15 | /**
16 | * Send pending network messages.
17 | */
18 | Result Flush();
19 | /**
20 | * Open a connection to a remote peer.
21 | */
22 | Result OpenPeer(NetworkPeerId peerId, char const* routeData);
23 | /**
24 | * Update the route data for a connected peer.
25 | */
26 | Result UpdatePeer(NetworkPeerId peerId, char const* routeData);
27 | /**
28 | * Close the connection to a remote peer.
29 | */
30 | Result ClosePeer(NetworkPeerId peerId);
31 | /**
32 | * Open a message channel to a connected peer.
33 | */
34 | Result OpenChannel(NetworkPeerId peerId, NetworkChannelId channelId, bool reliable);
35 | /**
36 | * Close a message channel to a connected peer.
37 | */
38 | Result CloseChannel(NetworkPeerId peerId, NetworkChannelId channelId);
39 | /**
40 | * Send a message to a connected peer over an opened message channel.
41 | */
42 | Result SendMessage(NetworkPeerId peerId,
43 | NetworkChannelId channelId,
44 | std::uint8_t* data,
45 | std::uint32_t dataLength);
46 |
47 | Event OnMessage;
48 | Event OnRouteUpdate;
49 |
50 | private:
51 | friend class Core;
52 |
53 | NetworkManager() = default;
54 | NetworkManager(NetworkManager const& rhs) = delete;
55 | NetworkManager& operator=(NetworkManager const& rhs) = delete;
56 | NetworkManager(NetworkManager&& rhs) = delete;
57 | NetworkManager& operator=(NetworkManager&& rhs) = delete;
58 |
59 | IDiscordNetworkManager* internal_;
60 | static IDiscordNetworkEvents events_;
61 | };
62 |
63 | } // namespace discord
64 |
--------------------------------------------------------------------------------
/Host/YTDPwin/YTDPwin.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.2.32519.379
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YTDPwin", "YTDPwin\YTDPwin.vcxproj", "{FE7AD499-27B7-4135-AF92-20E7E3984FC3}"
7 | EndProject
8 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "YTDPsetup", "YTDPsetup\YTDPsetup.vdproj", "{22527C5D-CC35-471C-8505-B7688C5E8490}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Debug|x64.ActiveCfg = Debug|x64
19 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Debug|x64.Build.0 = Debug|x64
20 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Debug|x86.ActiveCfg = Debug|Win32
21 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Debug|x86.Build.0 = Debug|Win32
22 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Release|x64.ActiveCfg = Release|x64
23 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Release|x64.Build.0 = Release|x64
24 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Release|x86.ActiveCfg = Release|Win32
25 | {FE7AD499-27B7-4135-AF92-20E7E3984FC3}.Release|x86.Build.0 = Release|Win32
26 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Debug|x64.ActiveCfg = Debug
27 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Debug|x64.Build.0 = Debug
28 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Debug|x86.ActiveCfg = Debug
29 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Release|x64.ActiveCfg = Release
30 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Release|x64.Build.0 = Release
31 | {22527C5D-CC35-471C-8505-B7688C5E8490}.Release|x86.ActiveCfg = Release
32 | EndGlobalSection
33 | GlobalSection(SolutionProperties) = preSolution
34 | HideSolutionNode = FALSE
35 | EndGlobalSection
36 | GlobalSection(ExtensibilityGlobals) = postSolution
37 | SolutionGuid = {21E7BB46-2E06-4678-BF07-032F67BEFAC7}
38 | EndGlobalSection
39 | EndGlobal
40 |
--------------------------------------------------------------------------------
/Extension/content_loader.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2022–Present Michael Ren
3 | Licensing and distribution info can be found at the GitHub repository
4 | https://github.com/XFG16/YouTubeDiscordPresence
5 | */
6 |
7 | // MAIN VARIABLE INITIALIZATION
8 |
9 | const LOGGING = false;
10 |
11 | const UPDATE_PRESENCE_MESSAGE = "UPDATE_PRESENCE_DATA";
12 |
13 | // REDIRECTION OF DATA FROM INJECTED CONTENT.JS TO BACKGROUND.JS
14 |
15 | window.addEventListener("SendToLoader", function (message) {
16 | chrome.runtime.sendMessage({
17 | messageType: UPDATE_PRESENCE_MESSAGE,
18 | title: message.detail.title,
19 | author: message.detail.author,
20 | timeLeft: message.detail.timeLeft,
21 | duration: message.detail.duration,
22 | videoId: message.detail.videoId,
23 | channelUrl: message.detail.channelUrl,
24 | applicationType: message.detail.applicationType,
25 | thumbnailUrl: message.detail.thumbnailUrl,
26 | }, (response) => {
27 | if (LOGGING) {
28 | console.log(`Data was sent by content_loader.js and received by background.js: ${message.detail}`);
29 | }
30 | });
31 | }, false);
32 |
33 | // INJECTION OF CONTENT.JS INTO MAIN DOM
34 |
35 | var mainScript = document.createElement("script");
36 | mainScript.src = chrome.runtime.getURL("/content.js");
37 | (document.head || document.documentElement).appendChild(mainScript);
38 | mainScript.onload = function () {
39 | this.remove();
40 | };
41 |
42 | // NATIVE APP NOT CONNECTED WARNING
43 |
44 | // chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
45 | // if (message.removeWarning) {
46 | // let warning = document.getElementById("ytdpClientErrorContainer");
47 | // if (warning) {
48 | // warning.remove();
49 | // }
50 | // }
51 | // sendResponse(null);
52 | // });
53 |
54 | // chrome.storage.sync.get("isNativeConnected", function (result) {
55 | // if (result.isNativeConnected == false) {
56 | // fetch(chrome.runtime.getURL('/warning.html')).then(r => r.text()).then(html => {
57 | // document.body.insertAdjacentHTML('beforeend', html);
58 | // });
59 | // }
60 | // });
--------------------------------------------------------------------------------
/Host/Discord/API/image_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "image_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | void ImageManager::Fetch(ImageHandle handle,
15 | bool refresh,
16 | std::function callback)
17 | {
18 | static auto wrapper =
19 | [](void* callbackData, EDiscordResult result, DiscordImageHandle handleResult) -> void {
20 | std::unique_ptr> cb(
21 | reinterpret_cast*>(callbackData));
22 | if (!cb || !(*cb)) {
23 | return;
24 | }
25 | (*cb)(static_cast(result), *reinterpret_cast(&handleResult));
26 | };
27 | std::unique_ptr> cb{};
28 | cb.reset(new std::function(std::move(callback)));
29 | internal_->fetch(internal_,
30 | *reinterpret_cast(&handle),
31 | (refresh ? 1 : 0),
32 | cb.release(),
33 | wrapper);
34 | }
35 |
36 | Result ImageManager::GetDimensions(ImageHandle handle, ImageDimensions* dimensions)
37 | {
38 | if (!dimensions) {
39 | return Result::InternalError;
40 | }
41 |
42 | auto result = internal_->get_dimensions(internal_,
43 | *reinterpret_cast(&handle),
44 | reinterpret_cast(dimensions));
45 | return static_cast(result);
46 | }
47 |
48 | Result ImageManager::GetData(ImageHandle handle, std::uint8_t* data, std::uint32_t dataLength)
49 | {
50 | auto result = internal_->get_data(internal_,
51 | *reinterpret_cast(&handle),
52 | reinterpret_cast(data),
53 | dataLength);
54 | return static_cast(result);
55 | }
56 |
57 | } // namespace discord
58 |
--------------------------------------------------------------------------------
/Host/Discord/API/core.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 | #include "application_manager.h"
5 | #include "user_manager.h"
6 | #include "image_manager.h"
7 | #include "activity_manager.h"
8 | #include "relationship_manager.h"
9 | #include "lobby_manager.h"
10 | #include "network_manager.h"
11 | #include "overlay_manager.h"
12 | #include "storage_manager.h"
13 | #include "store_manager.h"
14 | #include "voice_manager.h"
15 | #include "achievement_manager.h"
16 |
17 | namespace discord {
18 |
19 | class Core final {
20 | public:
21 | static Result Create(ClientId clientId, std::uint64_t flags, Core** instance);
22 |
23 | ~Core();
24 |
25 | Result RunCallbacks();
26 | void SetLogHook(LogLevel minLevel, std::function hook);
27 |
28 | discord::ApplicationManager& ApplicationManager();
29 | discord::UserManager& UserManager();
30 | discord::ImageManager& ImageManager();
31 | discord::ActivityManager& ActivityManager();
32 | discord::RelationshipManager& RelationshipManager();
33 | discord::LobbyManager& LobbyManager();
34 | discord::NetworkManager& NetworkManager();
35 | discord::OverlayManager& OverlayManager();
36 | discord::StorageManager& StorageManager();
37 | discord::StoreManager& StoreManager();
38 | discord::VoiceManager& VoiceManager();
39 | discord::AchievementManager& AchievementManager();
40 |
41 | private:
42 | Core() = default;
43 | Core(Core const& rhs) = delete;
44 | Core& operator=(Core const& rhs) = delete;
45 | Core(Core&& rhs) = delete;
46 | Core& operator=(Core&& rhs) = delete;
47 |
48 | IDiscordCore* internal_;
49 | Event setLogHook_;
50 | discord::ApplicationManager applicationManager_;
51 | discord::UserManager userManager_;
52 | discord::ImageManager imageManager_;
53 | discord::ActivityManager activityManager_;
54 | discord::RelationshipManager relationshipManager_;
55 | discord::LobbyManager lobbyManager_;
56 | discord::NetworkManager networkManager_;
57 | discord::OverlayManager overlayManager_;
58 | discord::StorageManager storageManager_;
59 | discord::StoreManager storeManager_;
60 | discord::VoiceManager voiceManager_;
61 | discord::AchievementManager achievementManager_;
62 | };
63 |
64 | } // namespace discord
65 |
--------------------------------------------------------------------------------
/Host/Discord/API/user_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "user_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class UserEvents final {
15 | public:
16 | static void OnCurrentUserUpdate(void* callbackData)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->UserManager();
24 | module.OnCurrentUserUpdate();
25 | }
26 | };
27 |
28 | IDiscordUserEvents UserManager::events_{
29 | &UserEvents::OnCurrentUserUpdate,
30 | };
31 |
32 | Result UserManager::GetCurrentUser(User* currentUser)
33 | {
34 | if (!currentUser) {
35 | return Result::InternalError;
36 | }
37 |
38 | auto result =
39 | internal_->get_current_user(internal_, reinterpret_cast(currentUser));
40 | return static_cast(result);
41 | }
42 |
43 | void UserManager::GetUser(UserId userId, std::function callback)
44 | {
45 | static auto wrapper = [](void* callbackData, EDiscordResult result, DiscordUser* user) -> void {
46 | std::unique_ptr> cb(
47 | reinterpret_cast*>(callbackData));
48 | if (!cb || !(*cb)) {
49 | return;
50 | }
51 | (*cb)(static_cast(result), *reinterpret_cast(user));
52 | };
53 | std::unique_ptr> cb{};
54 | cb.reset(new std::function(std::move(callback)));
55 | internal_->get_user(internal_, userId, cb.release(), wrapper);
56 | }
57 |
58 | Result UserManager::GetCurrentUserPremiumType(PremiumType* premiumType)
59 | {
60 | if (!premiumType) {
61 | return Result::InternalError;
62 | }
63 |
64 | auto result = internal_->get_current_user_premium_type(
65 | internal_, reinterpret_cast(premiumType));
66 | return static_cast(result);
67 | }
68 |
69 | Result UserManager::CurrentUserHasFlag(UserFlag flag, bool* hasFlag)
70 | {
71 | if (!hasFlag) {
72 | return Result::InternalError;
73 | }
74 |
75 | auto result = internal_->current_user_has_flag(
76 | internal_, static_cast(flag), reinterpret_cast(hasFlag));
77 | return static_cast(result);
78 | }
79 |
80 | } // namespace discord
81 |
--------------------------------------------------------------------------------
/Host/Discord/API/relationship_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "relationship_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class RelationshipEvents final {
15 | public:
16 | static void OnRefresh(void* callbackData)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->RelationshipManager();
24 | module.OnRefresh();
25 | }
26 |
27 | static void OnRelationshipUpdate(void* callbackData, DiscordRelationship* relationship)
28 | {
29 | auto* core = reinterpret_cast(callbackData);
30 | if (!core) {
31 | return;
32 | }
33 |
34 | auto& module = core->RelationshipManager();
35 | module.OnRelationshipUpdate(*reinterpret_cast(relationship));
36 | }
37 | };
38 |
39 | IDiscordRelationshipEvents RelationshipManager::events_{
40 | &RelationshipEvents::OnRefresh,
41 | &RelationshipEvents::OnRelationshipUpdate,
42 | };
43 |
44 | void RelationshipManager::Filter(std::function filter)
45 | {
46 | static auto wrapper = [](void* callbackData, DiscordRelationship* relationship) -> bool {
47 | auto cb(reinterpret_cast*>(callbackData));
48 | if (!cb || !(*cb)) {
49 | return {};
50 | }
51 | return (*cb)(*reinterpret_cast(relationship));
52 | };
53 | std::unique_ptr> cb{};
54 | cb.reset(new std::function(std::move(filter)));
55 | internal_->filter(internal_, cb.get(), wrapper);
56 | }
57 |
58 | Result RelationshipManager::Count(std::int32_t* count)
59 | {
60 | if (!count) {
61 | return Result::InternalError;
62 | }
63 |
64 | auto result = internal_->count(internal_, reinterpret_cast(count));
65 | return static_cast(result);
66 | }
67 |
68 | Result RelationshipManager::Get(UserId userId, Relationship* relationship)
69 | {
70 | if (!relationship) {
71 | return Result::InternalError;
72 | }
73 |
74 | auto result =
75 | internal_->get(internal_, userId, reinterpret_cast(relationship));
76 | return static_cast(result);
77 | }
78 |
79 | Result RelationshipManager::GetAt(std::uint32_t index, Relationship* relationship)
80 | {
81 | if (!relationship) {
82 | return Result::InternalError;
83 | }
84 |
85 | auto result =
86 | internal_->get_at(internal_, index, reinterpret_cast(relationship));
87 | return static_cast(result);
88 | }
89 |
90 | } // namespace discord
91 |
--------------------------------------------------------------------------------
/Host/Discord/API/application_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "application_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | void ApplicationManager::ValidateOrExit(std::function callback)
15 | {
16 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
17 | std::unique_ptr> cb(
18 | reinterpret_cast*>(callbackData));
19 | if (!cb || !(*cb)) {
20 | return;
21 | }
22 | (*cb)(static_cast(result));
23 | };
24 | std::unique_ptr> cb{};
25 | cb.reset(new std::function(std::move(callback)));
26 | internal_->validate_or_exit(internal_, cb.release(), wrapper);
27 | }
28 |
29 | void ApplicationManager::GetCurrentLocale(char locale[128])
30 | {
31 | if (!locale) {
32 | return;
33 | }
34 |
35 | internal_->get_current_locale(internal_, reinterpret_cast(locale));
36 | }
37 |
38 | void ApplicationManager::GetCurrentBranch(char branch[4096])
39 | {
40 | if (!branch) {
41 | return;
42 | }
43 |
44 | internal_->get_current_branch(internal_, reinterpret_cast(branch));
45 | }
46 |
47 | void ApplicationManager::GetOAuth2Token(std::function callback)
48 | {
49 | static auto wrapper =
50 | [](void* callbackData, EDiscordResult result, DiscordOAuth2Token* oauth2Token) -> void {
51 | std::unique_ptr> cb(
52 | reinterpret_cast*>(callbackData));
53 | if (!cb || !(*cb)) {
54 | return;
55 | }
56 | (*cb)(static_cast(result), *reinterpret_cast(oauth2Token));
57 | };
58 | std::unique_ptr> cb{};
59 | cb.reset(new std::function(std::move(callback)));
60 | internal_->get_oauth2_token(internal_, cb.release(), wrapper);
61 | }
62 |
63 | void ApplicationManager::GetTicket(std::function callback)
64 | {
65 | static auto wrapper = [](void* callbackData, EDiscordResult result, char const* data) -> void {
66 | std::unique_ptr> cb(
67 | reinterpret_cast*>(callbackData));
68 | if (!cb || !(*cb)) {
69 | return;
70 | }
71 | (*cb)(static_cast(result), static_cast(data));
72 | };
73 | std::unique_ptr> cb{};
74 | cb.reset(new std::function(std::move(callback)));
75 | internal_->get_ticket(internal_, cb.release(), wrapper);
76 | }
77 |
78 | } // namespace discord
79 |
--------------------------------------------------------------------------------
/Host/Discord/API/network_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "network_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class NetworkEvents final {
15 | public:
16 | static void OnMessage(void* callbackData,
17 | DiscordNetworkPeerId peerId,
18 | DiscordNetworkChannelId channelId,
19 | uint8_t* data,
20 | uint32_t dataLength)
21 | {
22 | auto* core = reinterpret_cast(callbackData);
23 | if (!core) {
24 | return;
25 | }
26 |
27 | auto& module = core->NetworkManager();
28 | module.OnMessage(peerId, channelId, data, dataLength);
29 | }
30 |
31 | static void OnRouteUpdate(void* callbackData, char const* routeData)
32 | {
33 | auto* core = reinterpret_cast(callbackData);
34 | if (!core) {
35 | return;
36 | }
37 |
38 | auto& module = core->NetworkManager();
39 | module.OnRouteUpdate(static_cast(routeData));
40 | }
41 | };
42 |
43 | IDiscordNetworkEvents NetworkManager::events_{
44 | &NetworkEvents::OnMessage,
45 | &NetworkEvents::OnRouteUpdate,
46 | };
47 |
48 | void NetworkManager::GetPeerId(NetworkPeerId* peerId)
49 | {
50 | if (!peerId) {
51 | return;
52 | }
53 |
54 | internal_->get_peer_id(internal_, reinterpret_cast(peerId));
55 | }
56 |
57 | Result NetworkManager::Flush()
58 | {
59 | auto result = internal_->flush(internal_);
60 | return static_cast(result);
61 | }
62 |
63 | Result NetworkManager::OpenPeer(NetworkPeerId peerId, char const* routeData)
64 | {
65 | auto result = internal_->open_peer(internal_, peerId, const_cast(routeData));
66 | return static_cast(result);
67 | }
68 |
69 | Result NetworkManager::UpdatePeer(NetworkPeerId peerId, char const* routeData)
70 | {
71 | auto result = internal_->update_peer(internal_, peerId, const_cast(routeData));
72 | return static_cast(result);
73 | }
74 |
75 | Result NetworkManager::ClosePeer(NetworkPeerId peerId)
76 | {
77 | auto result = internal_->close_peer(internal_, peerId);
78 | return static_cast(result);
79 | }
80 |
81 | Result NetworkManager::OpenChannel(NetworkPeerId peerId, NetworkChannelId channelId, bool reliable)
82 | {
83 | auto result = internal_->open_channel(internal_, peerId, channelId, (reliable ? 1 : 0));
84 | return static_cast(result);
85 | }
86 |
87 | Result NetworkManager::CloseChannel(NetworkPeerId peerId, NetworkChannelId channelId)
88 | {
89 | auto result = internal_->close_channel(internal_, peerId, channelId);
90 | return static_cast(result);
91 | }
92 |
93 | Result NetworkManager::SendMessage(NetworkPeerId peerId,
94 | NetworkChannelId channelId,
95 | std::uint8_t* data,
96 | std::uint32_t dataLength)
97 | {
98 | auto result = internal_->send_message(
99 | internal_, peerId, channelId, reinterpret_cast(data), dataLength);
100 | return static_cast(result);
101 | }
102 |
103 | } // namespace discord
104 |
--------------------------------------------------------------------------------
/Host/Discord/API/achievement_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "achievement_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class AchievementEvents final {
15 | public:
16 | static void OnUserAchievementUpdate(void* callbackData, DiscordUserAchievement* userAchievement)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->AchievementManager();
24 | module.OnUserAchievementUpdate(*reinterpret_cast(userAchievement));
25 | }
26 | };
27 |
28 | IDiscordAchievementEvents AchievementManager::events_{
29 | &AchievementEvents::OnUserAchievementUpdate,
30 | };
31 |
32 | void AchievementManager::SetUserAchievement(Snowflake achievementId,
33 | std::uint8_t percentComplete,
34 | std::function callback)
35 | {
36 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
37 | std::unique_ptr> cb(
38 | reinterpret_cast*>(callbackData));
39 | if (!cb || !(*cb)) {
40 | return;
41 | }
42 | (*cb)(static_cast(result));
43 | };
44 | std::unique_ptr> cb{};
45 | cb.reset(new std::function(std::move(callback)));
46 | internal_->set_user_achievement(
47 | internal_, achievementId, percentComplete, cb.release(), wrapper);
48 | }
49 |
50 | void AchievementManager::FetchUserAchievements(std::function callback)
51 | {
52 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
53 | std::unique_ptr> cb(
54 | reinterpret_cast*>(callbackData));
55 | if (!cb || !(*cb)) {
56 | return;
57 | }
58 | (*cb)(static_cast(result));
59 | };
60 | std::unique_ptr> cb{};
61 | cb.reset(new std::function(std::move(callback)));
62 | internal_->fetch_user_achievements(internal_, cb.release(), wrapper);
63 | }
64 |
65 | void AchievementManager::CountUserAchievements(std::int32_t* count)
66 | {
67 | if (!count) {
68 | return;
69 | }
70 |
71 | internal_->count_user_achievements(internal_, reinterpret_cast(count));
72 | }
73 |
74 | Result AchievementManager::GetUserAchievement(Snowflake userAchievementId,
75 | UserAchievement* userAchievement)
76 | {
77 | if (!userAchievement) {
78 | return Result::InternalError;
79 | }
80 |
81 | auto result = internal_->get_user_achievement(
82 | internal_, userAchievementId, reinterpret_cast(userAchievement));
83 | return static_cast(result);
84 | }
85 |
86 | Result AchievementManager::GetUserAchievementAt(std::int32_t index,
87 | UserAchievement* userAchievement)
88 | {
89 | if (!userAchievement) {
90 | return Result::InternalError;
91 | }
92 |
93 | auto result = internal_->get_user_achievement_at(
94 | internal_, index, reinterpret_cast(userAchievement));
95 | return static_cast(result);
96 | }
97 |
98 | } // namespace discord
99 |
--------------------------------------------------------------------------------
/Host/Discord/API/voice_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "voice_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class VoiceEvents final {
15 | public:
16 | static void OnSettingsUpdate(void* callbackData)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->VoiceManager();
24 | module.OnSettingsUpdate();
25 | }
26 | };
27 |
28 | IDiscordVoiceEvents VoiceManager::events_{
29 | &VoiceEvents::OnSettingsUpdate,
30 | };
31 |
32 | Result VoiceManager::GetInputMode(InputMode* inputMode)
33 | {
34 | if (!inputMode) {
35 | return Result::InternalError;
36 | }
37 |
38 | auto result =
39 | internal_->get_input_mode(internal_, reinterpret_cast(inputMode));
40 | return static_cast(result);
41 | }
42 |
43 | void VoiceManager::SetInputMode(InputMode inputMode, std::function callback)
44 | {
45 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
46 | std::unique_ptr> cb(
47 | reinterpret_cast*>(callbackData));
48 | if (!cb || !(*cb)) {
49 | return;
50 | }
51 | (*cb)(static_cast(result));
52 | };
53 | std::unique_ptr> cb{};
54 | cb.reset(new std::function(std::move(callback)));
55 | internal_->set_input_mode(
56 | internal_, *reinterpret_cast(&inputMode), cb.release(), wrapper);
57 | }
58 |
59 | Result VoiceManager::IsSelfMute(bool* mute)
60 | {
61 | if (!mute) {
62 | return Result::InternalError;
63 | }
64 |
65 | auto result = internal_->is_self_mute(internal_, reinterpret_cast(mute));
66 | return static_cast(result);
67 | }
68 |
69 | Result VoiceManager::SetSelfMute(bool mute)
70 | {
71 | auto result = internal_->set_self_mute(internal_, (mute ? 1 : 0));
72 | return static_cast(result);
73 | }
74 |
75 | Result VoiceManager::IsSelfDeaf(bool* deaf)
76 | {
77 | if (!deaf) {
78 | return Result::InternalError;
79 | }
80 |
81 | auto result = internal_->is_self_deaf(internal_, reinterpret_cast(deaf));
82 | return static_cast(result);
83 | }
84 |
85 | Result VoiceManager::SetSelfDeaf(bool deaf)
86 | {
87 | auto result = internal_->set_self_deaf(internal_, (deaf ? 1 : 0));
88 | return static_cast(result);
89 | }
90 |
91 | Result VoiceManager::IsLocalMute(Snowflake userId, bool* mute)
92 | {
93 | if (!mute) {
94 | return Result::InternalError;
95 | }
96 |
97 | auto result = internal_->is_local_mute(internal_, userId, reinterpret_cast(mute));
98 | return static_cast(result);
99 | }
100 |
101 | Result VoiceManager::SetLocalMute(Snowflake userId, bool mute)
102 | {
103 | auto result = internal_->set_local_mute(internal_, userId, (mute ? 1 : 0));
104 | return static_cast(result);
105 | }
106 |
107 | Result VoiceManager::GetLocalVolume(Snowflake userId, std::uint8_t* volume)
108 | {
109 | if (!volume) {
110 | return Result::InternalError;
111 | }
112 |
113 | auto result =
114 | internal_->get_local_volume(internal_, userId, reinterpret_cast(volume));
115 | return static_cast(result);
116 | }
117 |
118 | Result VoiceManager::SetLocalVolume(Snowflake userId, std::uint8_t volume)
119 | {
120 | auto result = internal_->set_local_volume(internal_, userId, volume);
121 | return static_cast(result);
122 | }
123 |
124 | } // namespace discord
125 |
--------------------------------------------------------------------------------
/Host/Discord/API/overlay_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "overlay_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class OverlayEvents final {
15 | public:
16 | static void OnToggle(void* callbackData, bool locked)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->OverlayManager();
24 | module.OnToggle((locked != 0));
25 | }
26 | };
27 |
28 | IDiscordOverlayEvents OverlayManager::events_{
29 | &OverlayEvents::OnToggle,
30 | };
31 |
32 | void OverlayManager::IsEnabled(bool* enabled)
33 | {
34 | if (!enabled) {
35 | return;
36 | }
37 |
38 | internal_->is_enabled(internal_, reinterpret_cast(enabled));
39 | }
40 |
41 | void OverlayManager::IsLocked(bool* locked)
42 | {
43 | if (!locked) {
44 | return;
45 | }
46 |
47 | internal_->is_locked(internal_, reinterpret_cast(locked));
48 | }
49 |
50 | void OverlayManager::SetLocked(bool locked, std::function callback)
51 | {
52 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
53 | std::unique_ptr> cb(
54 | reinterpret_cast*>(callbackData));
55 | if (!cb || !(*cb)) {
56 | return;
57 | }
58 | (*cb)(static_cast(result));
59 | };
60 | std::unique_ptr> cb{};
61 | cb.reset(new std::function(std::move(callback)));
62 | internal_->set_locked(internal_, (locked ? 1 : 0), cb.release(), wrapper);
63 | }
64 |
65 | void OverlayManager::OpenActivityInvite(ActivityActionType type,
66 | std::function callback)
67 | {
68 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
69 | std::unique_ptr> cb(
70 | reinterpret_cast*>(callbackData));
71 | if (!cb || !(*cb)) {
72 | return;
73 | }
74 | (*cb)(static_cast(result));
75 | };
76 | std::unique_ptr> cb{};
77 | cb.reset(new std::function(std::move(callback)));
78 | internal_->open_activity_invite(
79 | internal_, static_cast(type), cb.release(), wrapper);
80 | }
81 |
82 | void OverlayManager::OpenGuildInvite(char const* code, std::function callback)
83 | {
84 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
85 | std::unique_ptr> cb(
86 | reinterpret_cast*>(callbackData));
87 | if (!cb || !(*cb)) {
88 | return;
89 | }
90 | (*cb)(static_cast(result));
91 | };
92 | std::unique_ptr> cb{};
93 | cb.reset(new std::function(std::move(callback)));
94 | internal_->open_guild_invite(internal_, const_cast(code), cb.release(), wrapper);
95 | }
96 |
97 | void OverlayManager::OpenVoiceSettings(std::function callback)
98 | {
99 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
100 | std::unique_ptr> cb(
101 | reinterpret_cast*>(callbackData));
102 | if (!cb || !(*cb)) {
103 | return;
104 | }
105 | (*cb)(static_cast(result));
106 | };
107 | std::unique_ptr> cb{};
108 | cb.reset(new std::function(std::move(callback)));
109 | internal_->open_voice_settings(internal_, cb.release(), wrapper);
110 | }
111 |
112 | } // namespace discord
113 |
--------------------------------------------------------------------------------
/Host/Discord/API/lobby_manager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "types.h"
4 |
5 | namespace discord {
6 |
7 | class LobbyManager final {
8 | public:
9 | ~LobbyManager() = default;
10 |
11 | Result GetLobbyCreateTransaction(LobbyTransaction* transaction);
12 | Result GetLobbyUpdateTransaction(LobbyId lobbyId, LobbyTransaction* transaction);
13 | Result GetMemberUpdateTransaction(LobbyId lobbyId,
14 | UserId userId,
15 | LobbyMemberTransaction* transaction);
16 | void CreateLobby(LobbyTransaction const& transaction,
17 | std::function callback);
18 | void UpdateLobby(LobbyId lobbyId,
19 | LobbyTransaction const& transaction,
20 | std::function callback);
21 | void DeleteLobby(LobbyId lobbyId, std::function callback);
22 | void ConnectLobby(LobbyId lobbyId,
23 | LobbySecret secret,
24 | std::function callback);
25 | void ConnectLobbyWithActivitySecret(LobbySecret activitySecret,
26 | std::function callback);
27 | void DisconnectLobby(LobbyId lobbyId, std::function callback);
28 | Result GetLobby(LobbyId lobbyId, Lobby* lobby);
29 | Result GetLobbyActivitySecret(LobbyId lobbyId, char secret[128]);
30 | Result GetLobbyMetadataValue(LobbyId lobbyId, MetadataKey key, char value[4096]);
31 | Result GetLobbyMetadataKey(LobbyId lobbyId, std::int32_t index, char key[256]);
32 | Result LobbyMetadataCount(LobbyId lobbyId, std::int32_t* count);
33 | Result MemberCount(LobbyId lobbyId, std::int32_t* count);
34 | Result GetMemberUserId(LobbyId lobbyId, std::int32_t index, UserId* userId);
35 | Result GetMemberUser(LobbyId lobbyId, UserId userId, User* user);
36 | Result GetMemberMetadataValue(LobbyId lobbyId,
37 | UserId userId,
38 | MetadataKey key,
39 | char value[4096]);
40 | Result GetMemberMetadataKey(LobbyId lobbyId, UserId userId, std::int32_t index, char key[256]);
41 | Result MemberMetadataCount(LobbyId lobbyId, UserId userId, std::int32_t* count);
42 | void UpdateMember(LobbyId lobbyId,
43 | UserId userId,
44 | LobbyMemberTransaction const& transaction,
45 | std::function callback);
46 | void SendLobbyMessage(LobbyId lobbyId,
47 | std::uint8_t* data,
48 | std::uint32_t dataLength,
49 | std::function callback);
50 | Result GetSearchQuery(LobbySearchQuery* query);
51 | void Search(LobbySearchQuery const& query, std::function callback);
52 | void LobbyCount(std::int32_t* count);
53 | Result GetLobbyId(std::int32_t index, LobbyId* lobbyId);
54 | void ConnectVoice(LobbyId lobbyId, std::function callback);
55 | void DisconnectVoice(LobbyId lobbyId, std::function callback);
56 | Result ConnectNetwork(LobbyId lobbyId);
57 | Result DisconnectNetwork(LobbyId lobbyId);
58 | Result FlushNetwork();
59 | Result OpenNetworkChannel(LobbyId lobbyId, std::uint8_t channelId, bool reliable);
60 | Result SendNetworkMessage(LobbyId lobbyId,
61 | UserId userId,
62 | std::uint8_t channelId,
63 | std::uint8_t* data,
64 | std::uint32_t dataLength);
65 |
66 | Event OnLobbyUpdate;
67 | Event OnLobbyDelete;
68 | Event OnMemberConnect;
69 | Event OnMemberUpdate;
70 | Event OnMemberDisconnect;
71 | Event OnLobbyMessage;
72 | Event OnSpeaking;
73 | Event OnNetworkMessage;
74 |
75 | private:
76 | friend class Core;
77 |
78 | LobbyManager() = default;
79 | LobbyManager(LobbyManager const& rhs) = delete;
80 | LobbyManager& operator=(LobbyManager const& rhs) = delete;
81 | LobbyManager(LobbyManager&& rhs) = delete;
82 | LobbyManager& operator=(LobbyManager&& rhs) = delete;
83 |
84 | IDiscordLobbyManager* internal_;
85 | static IDiscordLobbyEvents events_;
86 | };
87 |
88 | } // namespace discord
89 |
--------------------------------------------------------------------------------
/Host/YTDPwin/YTDPwin/YTDPwin.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 |
65 |
66 | Header Files
67 |
68 |
69 | Header Files
70 |
71 |
72 | Header Files
73 |
74 |
75 | Header Files
76 |
77 |
78 | Header Files
79 |
80 |
81 | Header Files
82 |
83 |
84 | Header Files
85 |
86 |
87 | Header Files
88 |
89 |
90 | Header Files
91 |
92 |
93 | Header Files
94 |
95 |
96 | Header Files
97 |
98 |
99 | Header Files
100 |
101 |
102 | Header Files
103 |
104 |
105 | Header Files
106 |
107 |
108 | Header Files
109 |
110 |
111 | Header Files
112 |
113 |
114 |
--------------------------------------------------------------------------------
/Host/Discord/API/store_manager.cpp:
--------------------------------------------------------------------------------
1 | #if !defined(_CRT_SECURE_NO_WARNINGS)
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #endif
4 |
5 | #include "store_manager.h"
6 |
7 | #include "core.h"
8 |
9 | #include
10 | #include
11 |
12 | namespace discord {
13 |
14 | class StoreEvents final {
15 | public:
16 | static void OnEntitlementCreate(void* callbackData, DiscordEntitlement* entitlement)
17 | {
18 | auto* core = reinterpret_cast(callbackData);
19 | if (!core) {
20 | return;
21 | }
22 |
23 | auto& module = core->StoreManager();
24 | module.OnEntitlementCreate(*reinterpret_cast(entitlement));
25 | }
26 |
27 | static void OnEntitlementDelete(void* callbackData, DiscordEntitlement* entitlement)
28 | {
29 | auto* core = reinterpret_cast(callbackData);
30 | if (!core) {
31 | return;
32 | }
33 |
34 | auto& module = core->StoreManager();
35 | module.OnEntitlementDelete(*reinterpret_cast(entitlement));
36 | }
37 | };
38 |
39 | IDiscordStoreEvents StoreManager::events_{
40 | &StoreEvents::OnEntitlementCreate,
41 | &StoreEvents::OnEntitlementDelete,
42 | };
43 |
44 | void StoreManager::FetchSkus(std::function callback)
45 | {
46 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
47 | std::unique_ptr> cb(
48 | reinterpret_cast*>(callbackData));
49 | if (!cb || !(*cb)) {
50 | return;
51 | }
52 | (*cb)(static_cast(result));
53 | };
54 | std::unique_ptr> cb{};
55 | cb.reset(new std::function(std::move(callback)));
56 | internal_->fetch_skus(internal_, cb.release(), wrapper);
57 | }
58 |
59 | void StoreManager::CountSkus(std::int32_t* count)
60 | {
61 | if (!count) {
62 | return;
63 | }
64 |
65 | internal_->count_skus(internal_, reinterpret_cast(count));
66 | }
67 |
68 | Result StoreManager::GetSku(Snowflake skuId, Sku* sku)
69 | {
70 | if (!sku) {
71 | return Result::InternalError;
72 | }
73 |
74 | auto result = internal_->get_sku(internal_, skuId, reinterpret_cast(sku));
75 | return static_cast(result);
76 | }
77 |
78 | Result StoreManager::GetSkuAt(std::int32_t index, Sku* sku)
79 | {
80 | if (!sku) {
81 | return Result::InternalError;
82 | }
83 |
84 | auto result = internal_->get_sku_at(internal_, index, reinterpret_cast(sku));
85 | return static_cast(result);
86 | }
87 |
88 | void StoreManager::FetchEntitlements(std::function callback)
89 | {
90 | static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
91 | std::unique_ptr> cb(
92 | reinterpret_cast*>(callbackData));
93 | if (!cb || !(*cb)) {
94 | return;
95 | }
96 | (*cb)(static_cast(result));
97 | };
98 | std::unique_ptr> cb{};
99 | cb.reset(new std::function(std::move(callback)));
100 | internal_->fetch_entitlements(internal_, cb.release(), wrapper);
101 | }
102 |
103 | void StoreManager::CountEntitlements(std::int32_t* count)
104 | {
105 | if (!count) {
106 | return;
107 | }
108 |
109 | internal_->count_entitlements(internal_, reinterpret_cast(count));
110 | }
111 |
112 | Result StoreManager::GetEntitlement(Snowflake entitlementId, Entitlement* entitlement)
113 | {
114 | if (!entitlement) {
115 | return Result::InternalError;
116 | }
117 |
118 | auto result = internal_->get_entitlement(
119 | internal_, entitlementId, reinterpret_cast(entitlement));
120 | return static_cast(result);
121 | }
122 |
123 | Result StoreManager::GetEntitlementAt(std::int32_t index, Entitlement* entitlement)
124 | {
125 | if (!entitlement) {
126 | return Result::InternalError;
127 | }
128 |
129 | auto result = internal_->get_entitlement_at(
130 | internal_, index, reinterpret_cast