rdiscord_sdk 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/.vscode/c_cpp_properties.json +24 -0
- data/.vscode/settings.json +102 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +46 -0
- data/INTERNALS.md +0 -0
- data/LICENSE +674 -0
- data/README.md +187 -0
- data/Rakefile +17 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/rdiscord_sdk/activity.cpp +297 -0
- data/ext/rdiscord_sdk/activity.h +17 -0
- data/ext/rdiscord_sdk/common.cpp +65 -0
- data/ext/rdiscord_sdk/common.h +88 -0
- data/ext/rdiscord_sdk/extconf.rb +54 -0
- data/ext/rdiscord_sdk/gem_activity_manager.cpp +273 -0
- data/ext/rdiscord_sdk/gem_activity_manager.h +8 -0
- data/ext/rdiscord_sdk/gem_user_manager.cpp +114 -0
- data/ext/rdiscord_sdk/gem_user_manager.h +8 -0
- data/ext/rdiscord_sdk/rdiscord_sdk.cpp +77 -0
- data/ext/rdiscord_sdk/rdiscord_sdk.h +17 -0
- data/ext/rdiscord_sdk/user.cpp +98 -0
- data/ext/rdiscord_sdk/user.h +19 -0
- data/lib/rdiscord_sdk/enums.rb +162 -0
- data/lib/rdiscord_sdk/rdiscord_sdk.so +0 -0
- data/lib/rdiscord_sdk/version.rb +16 -0
- data/lib/rdiscord_sdk.rb +3 -0
- data/rdiscord_sdk.gemspec +34 -0
- data/third-party/include/achievement_manager.cpp +98 -0
- data/third-party/include/achievement_manager.h +34 -0
- data/third-party/include/activity_manager.cpp +177 -0
- data/third-party/include/activity_manager.h +42 -0
- data/third-party/include/application_manager.cpp +78 -0
- data/third-party/include/application_manager.h +30 -0
- data/third-party/include/core.cpp +182 -0
- data/third-party/include/core.h +64 -0
- data/third-party/include/discord.h +16 -0
- data/third-party/include/event.h +59 -0
- data/third-party/include/ffi.h +942 -0
- data/third-party/include/image_manager.cpp +57 -0
- data/third-party/include/image_manager.h +28 -0
- data/third-party/include/lobby_manager.cpp +547 -0
- data/third-party/include/lobby_manager.h +88 -0
- data/third-party/include/network_manager.cpp +103 -0
- data/third-party/include/network_manager.h +63 -0
- data/third-party/include/overlay_manager.cpp +112 -0
- data/third-party/include/overlay_manager.h +33 -0
- data/third-party/include/relationship_manager.cpp +90 -0
- data/third-party/include/relationship_manager.h +32 -0
- data/third-party/include/storage_manager.cpp +158 -0
- data/third-party/include/storage_manager.h +46 -0
- data/third-party/include/store_manager.cpp +160 -0
- data/third-party/include/store_manager.h +38 -0
- data/third-party/include/types.cpp +769 -0
- data/third-party/include/types.h +492 -0
- data/third-party/include/user_manager.cpp +80 -0
- data/third-party/include/user_manager.h +31 -0
- data/third-party/include/voice_manager.cpp +124 -0
- data/third-party/include/voice_manager.h +37 -0
- data/third-party/lib/x86/discord_game_sdk.dll +0 -0
- data/third-party/lib/x86/discord_game_sdk.dll.lib +0 -0
- data/third-party/lib/x86_64/discord_game_sdk.bundle +0 -0
- data/third-party/lib/x86_64/discord_game_sdk.dll +0 -0
- data/third-party/lib/x86_64/discord_game_sdk.dll.lib +0 -0
- data/third-party/lib/x86_64/discord_game_sdk.dylib +0 -0
- data/third-party/lib/x86_64/discord_game_sdk.so +0 -0
- metadata +114 -0
@@ -0,0 +1,88 @@
|
|
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<void(Result, Lobby const&)> callback);
|
18
|
+
void UpdateLobby(LobbyId lobbyId,
|
19
|
+
LobbyTransaction const& transaction,
|
20
|
+
std::function<void(Result)> callback);
|
21
|
+
void DeleteLobby(LobbyId lobbyId, std::function<void(Result)> callback);
|
22
|
+
void ConnectLobby(LobbyId lobbyId,
|
23
|
+
LobbySecret secret,
|
24
|
+
std::function<void(Result, Lobby const&)> callback);
|
25
|
+
void ConnectLobbyWithActivitySecret(LobbySecret activitySecret,
|
26
|
+
std::function<void(Result, Lobby const&)> callback);
|
27
|
+
void DisconnectLobby(LobbyId lobbyId, std::function<void(Result)> 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<void(Result)> callback);
|
46
|
+
void SendLobbyMessage(LobbyId lobbyId,
|
47
|
+
std::uint8_t* data,
|
48
|
+
std::uint32_t dataLength,
|
49
|
+
std::function<void(Result)> callback);
|
50
|
+
Result GetSearchQuery(LobbySearchQuery* query);
|
51
|
+
void Search(LobbySearchQuery const& query, std::function<void(Result)> callback);
|
52
|
+
void LobbyCount(std::int32_t* count);
|
53
|
+
Result GetLobbyId(std::int32_t index, LobbyId* lobbyId);
|
54
|
+
void ConnectVoice(LobbyId lobbyId, std::function<void(Result)> callback);
|
55
|
+
void DisconnectVoice(LobbyId lobbyId, std::function<void(Result)> 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<std::int64_t> OnLobbyUpdate;
|
67
|
+
Event<std::int64_t, std::uint32_t> OnLobbyDelete;
|
68
|
+
Event<std::int64_t, std::int64_t> OnMemberConnect;
|
69
|
+
Event<std::int64_t, std::int64_t> OnMemberUpdate;
|
70
|
+
Event<std::int64_t, std::int64_t> OnMemberDisconnect;
|
71
|
+
Event<std::int64_t, std::int64_t, std::uint8_t*, std::uint32_t> OnLobbyMessage;
|
72
|
+
Event<std::int64_t, std::int64_t, bool> OnSpeaking;
|
73
|
+
Event<std::int64_t, std::int64_t, std::uint8_t, std::uint8_t*, std::uint32_t> 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
|
@@ -0,0 +1,103 @@
|
|
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 <cstring>
|
10
|
+
#include <memory>
|
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<Core*>(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<Core*>(callbackData);
|
34
|
+
if (!core) {
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
|
38
|
+
auto& module = core->NetworkManager();
|
39
|
+
module.OnRouteUpdate(static_cast<const char*>(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<uint64_t*>(peerId));
|
55
|
+
}
|
56
|
+
|
57
|
+
Result NetworkManager::Flush()
|
58
|
+
{
|
59
|
+
auto result = internal_->flush(internal_);
|
60
|
+
return static_cast<Result>(result);
|
61
|
+
}
|
62
|
+
|
63
|
+
Result NetworkManager::OpenPeer(NetworkPeerId peerId, char const* routeData)
|
64
|
+
{
|
65
|
+
auto result = internal_->open_peer(internal_, peerId, const_cast<char*>(routeData));
|
66
|
+
return static_cast<Result>(result);
|
67
|
+
}
|
68
|
+
|
69
|
+
Result NetworkManager::UpdatePeer(NetworkPeerId peerId, char const* routeData)
|
70
|
+
{
|
71
|
+
auto result = internal_->update_peer(internal_, peerId, const_cast<char*>(routeData));
|
72
|
+
return static_cast<Result>(result);
|
73
|
+
}
|
74
|
+
|
75
|
+
Result NetworkManager::ClosePeer(NetworkPeerId peerId)
|
76
|
+
{
|
77
|
+
auto result = internal_->close_peer(internal_, peerId);
|
78
|
+
return static_cast<Result>(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>(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>(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<uint8_t*>(data), dataLength);
|
100
|
+
return static_cast<Result>(result);
|
101
|
+
}
|
102
|
+
|
103
|
+
} // namespace discord
|
@@ -0,0 +1,63 @@
|
|
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<NetworkPeerId, NetworkChannelId, std::uint8_t*, std::uint32_t> OnMessage;
|
48
|
+
Event<char const*> 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
|
@@ -0,0 +1,112 @@
|
|
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 <cstring>
|
10
|
+
#include <memory>
|
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<Core*>(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<bool*>(enabled));
|
39
|
+
}
|
40
|
+
|
41
|
+
void OverlayManager::IsLocked(bool* locked)
|
42
|
+
{
|
43
|
+
if (!locked) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
internal_->is_locked(internal_, reinterpret_cast<bool*>(locked));
|
48
|
+
}
|
49
|
+
|
50
|
+
void OverlayManager::SetLocked(bool locked, std::function<void(Result)> callback)
|
51
|
+
{
|
52
|
+
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
53
|
+
std::unique_ptr<std::function<void(Result)>> cb(
|
54
|
+
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
55
|
+
if (!cb || !(*cb)) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
(*cb)(static_cast<Result>(result));
|
59
|
+
};
|
60
|
+
std::unique_ptr<std::function<void(Result)>> cb{};
|
61
|
+
cb.reset(new std::function<void(Result)>(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<void(Result)> callback)
|
67
|
+
{
|
68
|
+
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
69
|
+
std::unique_ptr<std::function<void(Result)>> cb(
|
70
|
+
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
71
|
+
if (!cb || !(*cb)) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
(*cb)(static_cast<Result>(result));
|
75
|
+
};
|
76
|
+
std::unique_ptr<std::function<void(Result)>> cb{};
|
77
|
+
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
78
|
+
internal_->open_activity_invite(
|
79
|
+
internal_, static_cast<EDiscordActivityActionType>(type), cb.release(), wrapper);
|
80
|
+
}
|
81
|
+
|
82
|
+
void OverlayManager::OpenGuildInvite(char const* code, std::function<void(Result)> callback)
|
83
|
+
{
|
84
|
+
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
85
|
+
std::unique_ptr<std::function<void(Result)>> cb(
|
86
|
+
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
87
|
+
if (!cb || !(*cb)) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
(*cb)(static_cast<Result>(result));
|
91
|
+
};
|
92
|
+
std::unique_ptr<std::function<void(Result)>> cb{};
|
93
|
+
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
94
|
+
internal_->open_guild_invite(internal_, const_cast<char*>(code), cb.release(), wrapper);
|
95
|
+
}
|
96
|
+
|
97
|
+
void OverlayManager::OpenVoiceSettings(std::function<void(Result)> callback)
|
98
|
+
{
|
99
|
+
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
100
|
+
std::unique_ptr<std::function<void(Result)>> cb(
|
101
|
+
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
102
|
+
if (!cb || !(*cb)) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
(*cb)(static_cast<Result>(result));
|
106
|
+
};
|
107
|
+
std::unique_ptr<std::function<void(Result)>> cb{};
|
108
|
+
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
109
|
+
internal_->open_voice_settings(internal_, cb.release(), wrapper);
|
110
|
+
}
|
111
|
+
|
112
|
+
} // namespace discord
|
@@ -0,0 +1,33 @@
|
|
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<void(Result)> callback);
|
14
|
+
void OpenActivityInvite(ActivityActionType type, std::function<void(Result)> callback);
|
15
|
+
void OpenGuildInvite(char const* code, std::function<void(Result)> callback);
|
16
|
+
void OpenVoiceSettings(std::function<void(Result)> callback);
|
17
|
+
|
18
|
+
Event<bool> 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
|
@@ -0,0 +1,90 @@
|
|
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 <cstring>
|
10
|
+
#include <memory>
|
11
|
+
|
12
|
+
namespace discord {
|
13
|
+
|
14
|
+
class RelationshipEvents final {
|
15
|
+
public:
|
16
|
+
static void OnRefresh(void* callbackData)
|
17
|
+
{
|
18
|
+
auto* core = reinterpret_cast<Core*>(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<Core*>(callbackData);
|
30
|
+
if (!core) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
auto& module = core->RelationshipManager();
|
35
|
+
module.OnRelationshipUpdate(*reinterpret_cast<Relationship const*>(relationship));
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
IDiscordRelationshipEvents RelationshipManager::events_{
|
40
|
+
&RelationshipEvents::OnRefresh,
|
41
|
+
&RelationshipEvents::OnRelationshipUpdate,
|
42
|
+
};
|
43
|
+
|
44
|
+
void RelationshipManager::Filter(std::function<bool(Relationship const&)> filter)
|
45
|
+
{
|
46
|
+
static auto wrapper = [](void* callbackData, DiscordRelationship* relationship) -> bool {
|
47
|
+
auto cb(reinterpret_cast<std::function<bool(Relationship const&)>*>(callbackData));
|
48
|
+
if (!cb || !(*cb)) {
|
49
|
+
return {};
|
50
|
+
}
|
51
|
+
return (*cb)(*reinterpret_cast<Relationship const*>(relationship));
|
52
|
+
};
|
53
|
+
std::unique_ptr<std::function<bool(Relationship const&)>> cb{};
|
54
|
+
cb.reset(new std::function<bool(Relationship const&)>(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<int32_t*>(count));
|
65
|
+
return static_cast<Result>(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<DiscordRelationship*>(relationship));
|
76
|
+
return static_cast<Result>(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<DiscordRelationship*>(relationship));
|
87
|
+
return static_cast<Result>(result);
|
88
|
+
}
|
89
|
+
|
90
|
+
} // namespace discord
|
@@ -0,0 +1,32 @@
|
|
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<bool(Relationship const&)> 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<Relationship const&> 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
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
2
|
+
#define _CRT_SECURE_NO_WARNINGS
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#include "storage_manager.h"
|
6
|
+
|
7
|
+
#include "core.h"
|
8
|
+
|
9
|
+
#include <cstring>
|
10
|
+
#include <memory>
|
11
|
+
|
12
|
+
namespace discord {
|
13
|
+
|
14
|
+
Result StorageManager::Read(char const* name,
|
15
|
+
std::uint8_t* data,
|
16
|
+
std::uint32_t dataLength,
|
17
|
+
std::uint32_t* read)
|
18
|
+
{
|
19
|
+
if (!read) {
|
20
|
+
return Result::InternalError;
|
21
|
+
}
|
22
|
+
|
23
|
+
auto result = internal_->read(internal_,
|
24
|
+
const_cast<char*>(name),
|
25
|
+
reinterpret_cast<uint8_t*>(data),
|
26
|
+
dataLength,
|
27
|
+
reinterpret_cast<uint32_t*>(read));
|
28
|
+
return static_cast<Result>(result);
|
29
|
+
}
|
30
|
+
|
31
|
+
void StorageManager::ReadAsync(char const* name,
|
32
|
+
std::function<void(Result, std::uint8_t*, std::uint32_t)> callback)
|
33
|
+
{
|
34
|
+
static auto wrapper =
|
35
|
+
[](void* callbackData, EDiscordResult result, uint8_t* data, uint32_t dataLength) -> void {
|
36
|
+
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb(
|
37
|
+
reinterpret_cast<std::function<void(Result, std::uint8_t*, std::uint32_t)>*>(
|
38
|
+
callbackData));
|
39
|
+
if (!cb || !(*cb)) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
(*cb)(static_cast<Result>(result), data, dataLength);
|
43
|
+
};
|
44
|
+
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb{};
|
45
|
+
cb.reset(new std::function<void(Result, std::uint8_t*, std::uint32_t)>(std::move(callback)));
|
46
|
+
internal_->read_async(internal_, const_cast<char*>(name), cb.release(), wrapper);
|
47
|
+
}
|
48
|
+
|
49
|
+
void StorageManager::ReadAsyncPartial(
|
50
|
+
char const* name,
|
51
|
+
std::uint64_t offset,
|
52
|
+
std::uint64_t length,
|
53
|
+
std::function<void(Result, std::uint8_t*, std::uint32_t)> callback)
|
54
|
+
{
|
55
|
+
static auto wrapper =
|
56
|
+
[](void* callbackData, EDiscordResult result, uint8_t* data, uint32_t dataLength) -> void {
|
57
|
+
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb(
|
58
|
+
reinterpret_cast<std::function<void(Result, std::uint8_t*, std::uint32_t)>*>(
|
59
|
+
callbackData));
|
60
|
+
if (!cb || !(*cb)) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
(*cb)(static_cast<Result>(result), data, dataLength);
|
64
|
+
};
|
65
|
+
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb{};
|
66
|
+
cb.reset(new std::function<void(Result, std::uint8_t*, std::uint32_t)>(std::move(callback)));
|
67
|
+
internal_->read_async_partial(
|
68
|
+
internal_, const_cast<char*>(name), offset, length, cb.release(), wrapper);
|
69
|
+
}
|
70
|
+
|
71
|
+
Result StorageManager::Write(char const* name, std::uint8_t* data, std::uint32_t dataLength)
|
72
|
+
{
|
73
|
+
auto result = internal_->write(
|
74
|
+
internal_, const_cast<char*>(name), reinterpret_cast<uint8_t*>(data), dataLength);
|
75
|
+
return static_cast<Result>(result);
|
76
|
+
}
|
77
|
+
|
78
|
+
void StorageManager::WriteAsync(char const* name,
|
79
|
+
std::uint8_t* data,
|
80
|
+
std::uint32_t dataLength,
|
81
|
+
std::function<void(Result)> callback)
|
82
|
+
{
|
83
|
+
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
84
|
+
std::unique_ptr<std::function<void(Result)>> cb(
|
85
|
+
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
86
|
+
if (!cb || !(*cb)) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
(*cb)(static_cast<Result>(result));
|
90
|
+
};
|
91
|
+
std::unique_ptr<std::function<void(Result)>> cb{};
|
92
|
+
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
93
|
+
internal_->write_async(internal_,
|
94
|
+
const_cast<char*>(name),
|
95
|
+
reinterpret_cast<uint8_t*>(data),
|
96
|
+
dataLength,
|
97
|
+
cb.release(),
|
98
|
+
wrapper);
|
99
|
+
}
|
100
|
+
|
101
|
+
Result StorageManager::Delete(char const* name)
|
102
|
+
{
|
103
|
+
auto result = internal_->delete_(internal_, const_cast<char*>(name));
|
104
|
+
return static_cast<Result>(result);
|
105
|
+
}
|
106
|
+
|
107
|
+
Result StorageManager::Exists(char const* name, bool* exists)
|
108
|
+
{
|
109
|
+
if (!exists) {
|
110
|
+
return Result::InternalError;
|
111
|
+
}
|
112
|
+
|
113
|
+
auto result =
|
114
|
+
internal_->exists(internal_, const_cast<char*>(name), reinterpret_cast<bool*>(exists));
|
115
|
+
return static_cast<Result>(result);
|
116
|
+
}
|
117
|
+
|
118
|
+
void StorageManager::Count(std::int32_t* count)
|
119
|
+
{
|
120
|
+
if (!count) {
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
|
124
|
+
internal_->count(internal_, reinterpret_cast<int32_t*>(count));
|
125
|
+
}
|
126
|
+
|
127
|
+
Result StorageManager::Stat(char const* name, FileStat* stat)
|
128
|
+
{
|
129
|
+
if (!stat) {
|
130
|
+
return Result::InternalError;
|
131
|
+
}
|
132
|
+
|
133
|
+
auto result =
|
134
|
+
internal_->stat(internal_, const_cast<char*>(name), reinterpret_cast<DiscordFileStat*>(stat));
|
135
|
+
return static_cast<Result>(result);
|
136
|
+
}
|
137
|
+
|
138
|
+
Result StorageManager::StatAt(std::int32_t index, FileStat* stat)
|
139
|
+
{
|
140
|
+
if (!stat) {
|
141
|
+
return Result::InternalError;
|
142
|
+
}
|
143
|
+
|
144
|
+
auto result = internal_->stat_at(internal_, index, reinterpret_cast<DiscordFileStat*>(stat));
|
145
|
+
return static_cast<Result>(result);
|
146
|
+
}
|
147
|
+
|
148
|
+
Result StorageManager::GetPath(char path[4096])
|
149
|
+
{
|
150
|
+
if (!path) {
|
151
|
+
return Result::InternalError;
|
152
|
+
}
|
153
|
+
|
154
|
+
auto result = internal_->get_path(internal_, reinterpret_cast<DiscordPath*>(path));
|
155
|
+
return static_cast<Result>(result);
|
156
|
+
}
|
157
|
+
|
158
|
+
} // namespace discord
|