Skip to content

Commit

Permalink
Read Discord UI from config file if Discord SDK is unresponsive
Browse files Browse the repository at this point in the history
Discord SDK has been malfunctioning for (seemingly random) selection of users since mid-September, and unfortunately that malfunction stops that (seemingly random) selection of users from being able to receive their Discord UID by ShareDiva. This change forces the mod to read the config file instead, should Discord be unresponsive after a short amount of time.
  • Loading branch information
RocketRacer committed Oct 18, 2022
1 parent 59a4b51 commit 8dc97c5
Show file tree
Hide file tree
Showing 43 changed files with 12,030 additions and 479 deletions.
3 changes: 2 additions & 1 deletion Dependencies/discord/achievement_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace discord {

class AchievementEvents final {
public:
static void OnUserAchievementUpdate(void* callbackData, DiscordUserAchievement* userAchievement)
static void DISCORD_CALLBACK OnUserAchievementUpdate(void* callbackData,
DiscordUserAchievement* userAchievement)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
14 changes: 7 additions & 7 deletions Dependencies/discord/activity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace discord {

class ActivityEvents final {
public:
static void OnActivityJoin(void* callbackData, char const* secret)
static void DISCORD_CALLBACK OnActivityJoin(void* callbackData, char const* secret)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -24,7 +24,7 @@ class ActivityEvents final {
module.OnActivityJoin(static_cast<const char*>(secret));
}

static void OnActivitySpectate(void* callbackData, char const* secret)
static void DISCORD_CALLBACK OnActivitySpectate(void* callbackData, char const* secret)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -35,7 +35,7 @@ class ActivityEvents final {
module.OnActivitySpectate(static_cast<const char*>(secret));
}

static void OnActivityJoinRequest(void* callbackData, DiscordUser* user)
static void DISCORD_CALLBACK OnActivityJoinRequest(void* callbackData, DiscordUser* user)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -46,10 +46,10 @@ class ActivityEvents final {
module.OnActivityJoinRequest(*reinterpret_cast<User const*>(user));
}

static void OnActivityInvite(void* callbackData,
EDiscordActivityActionType type,
DiscordUser* user,
DiscordActivity* activity)
static void DISCORD_CALLBACK OnActivityInvite(void* callbackData,
EDiscordActivityActionType type,
DiscordUser* user,
DiscordActivity* activity)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
1,037 changes: 604 additions & 433 deletions Dependencies/discord/ffi.h

Large diffs are not rendered by default.

Binary file modified Dependencies/discord/lib/discord_game_sdk.bundle
Binary file not shown.
41 changes: 24 additions & 17 deletions Dependencies/discord/lobby_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace discord {

class LobbyEvents final {
public:
static void OnLobbyUpdate(void* callbackData, int64_t lobbyId)
static void DISCORD_CALLBACK OnLobbyUpdate(void* callbackData, int64_t lobbyId)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -24,7 +24,7 @@ class LobbyEvents final {
module.OnLobbyUpdate(lobbyId);
}

static void OnLobbyDelete(void* callbackData, int64_t lobbyId, uint32_t reason)
static void DISCORD_CALLBACK OnLobbyDelete(void* callbackData, int64_t lobbyId, uint32_t reason)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -35,7 +35,9 @@ class LobbyEvents final {
module.OnLobbyDelete(lobbyId, reason);
}

static void OnMemberConnect(void* callbackData, int64_t lobbyId, int64_t userId)
static void DISCORD_CALLBACK OnMemberConnect(void* callbackData,
int64_t lobbyId,
int64_t userId)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -46,7 +48,7 @@ class LobbyEvents final {
module.OnMemberConnect(lobbyId, userId);
}

static void OnMemberUpdate(void* callbackData, int64_t lobbyId, int64_t userId)
static void DISCORD_CALLBACK OnMemberUpdate(void* callbackData, int64_t lobbyId, int64_t userId)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -57,7 +59,9 @@ class LobbyEvents final {
module.OnMemberUpdate(lobbyId, userId);
}

static void OnMemberDisconnect(void* callbackData, int64_t lobbyId, int64_t userId)
static void DISCORD_CALLBACK OnMemberDisconnect(void* callbackData,
int64_t lobbyId,
int64_t userId)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -68,11 +72,11 @@ class LobbyEvents final {
module.OnMemberDisconnect(lobbyId, userId);
}

static void OnLobbyMessage(void* callbackData,
int64_t lobbyId,
int64_t userId,
uint8_t* data,
uint32_t dataLength)
static void DISCORD_CALLBACK OnLobbyMessage(void* callbackData,
int64_t lobbyId,
int64_t userId,
uint8_t* data,
uint32_t dataLength)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -83,7 +87,10 @@ class LobbyEvents final {
module.OnLobbyMessage(lobbyId, userId, data, dataLength);
}

static void OnSpeaking(void* callbackData, int64_t lobbyId, int64_t userId, bool speaking)
static void DISCORD_CALLBACK OnSpeaking(void* callbackData,
int64_t lobbyId,
int64_t userId,
bool speaking)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -94,12 +101,12 @@ class LobbyEvents final {
module.OnSpeaking(lobbyId, userId, (speaking != 0));
}

static void OnNetworkMessage(void* callbackData,
int64_t lobbyId,
int64_t userId,
uint8_t channelId,
uint8_t* data,
uint32_t dataLength)
static void DISCORD_CALLBACK OnNetworkMessage(void* callbackData,
int64_t lobbyId,
int64_t userId,
uint8_t channelId,
uint8_t* data,
uint32_t dataLength)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
12 changes: 6 additions & 6 deletions Dependencies/discord/network_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace discord {

class NetworkEvents final {
public:
static void OnMessage(void* callbackData,
DiscordNetworkPeerId peerId,
DiscordNetworkChannelId channelId,
uint8_t* data,
uint32_t dataLength)
static void DISCORD_CALLBACK OnMessage(void* callbackData,
DiscordNetworkPeerId peerId,
DiscordNetworkChannelId channelId,
uint8_t* data,
uint32_t dataLength)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -28,7 +28,7 @@ class NetworkEvents final {
module.OnMessage(peerId, channelId, data, dataLength);
}

static void OnRouteUpdate(void* callbackData, char const* routeData)
static void DISCORD_CALLBACK OnRouteUpdate(void* callbackData, char const* routeData)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
119 changes: 118 additions & 1 deletion Dependencies/discord/overlay_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace discord {

class OverlayEvents final {
public:
static void OnToggle(void* callbackData, bool locked)
static void DISCORD_CALLBACK OnToggle(void* callbackData, bool locked)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down Expand Up @@ -109,4 +109,121 @@ void OverlayManager::OpenVoiceSettings(std::function<void(Result)> callback)
internal_->open_voice_settings(internal_, cb.release(), wrapper);
}

Result OverlayManager::InitDrawingDxgi(IDXGISwapChain* swapchain, bool useMessageForwarding)
{
auto result =
internal_->init_drawing_dxgi(internal_, swapchain, (useMessageForwarding ? 1 : 0));
return static_cast<Result>(result);
}

void OverlayManager::OnPresent()
{
internal_->on_present(internal_);
}

void OverlayManager::ForwardMessage(MSG* message)
{
internal_->forward_message(internal_, message);
}

void OverlayManager::KeyEvent(bool down, char const* keyCode, KeyVariant variant)
{
internal_->key_event(internal_,
(down ? 1 : 0),
const_cast<char*>(keyCode),
static_cast<EDiscordKeyVariant>(variant));
}

void OverlayManager::CharEvent(char const* character)
{
internal_->char_event(internal_, const_cast<char*>(character));
}

void OverlayManager::MouseButtonEvent(std::uint8_t down,
std::int32_t clickCount,
MouseButton which,
std::int32_t x,
std::int32_t y)
{
internal_->mouse_button_event(
internal_, down, clickCount, static_cast<EDiscordMouseButton>(which), x, y);
}

void OverlayManager::MouseMotionEvent(std::int32_t x, std::int32_t y)
{
internal_->mouse_motion_event(internal_, x, y);
}

void OverlayManager::ImeCommitText(char const* text)
{
internal_->ime_commit_text(internal_, const_cast<char*>(text));
}

void OverlayManager::ImeSetComposition(char const* text,
ImeUnderline* underlines,
std::uint32_t underlinesLength,
std::int32_t from,
std::int32_t to)
{
internal_->ime_set_composition(internal_,
const_cast<char*>(text),
reinterpret_cast<DiscordImeUnderline*>(underlines),
underlinesLength,
from,
to);
}

void OverlayManager::ImeCancelComposition()
{
internal_->ime_cancel_composition(internal_);
}

void OverlayManager::SetImeCompositionRangeCallback(
std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>
onImeCompositionRangeChanged)
{
static auto wrapper = [](void* callbackData,
int32_t from,
int32_t to,
DiscordRect* bounds,
uint32_t boundsLength) -> void {
std::unique_ptr<std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>> cb(
reinterpret_cast<std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>*>(
callbackData));
if (!cb || !(*cb)) {
return;
}
(*cb)(from, to, reinterpret_cast<Rect*>(bounds), boundsLength);
};
std::unique_ptr<std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>> cb{};
cb.reset(new std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>(
std::move(onImeCompositionRangeChanged)));
internal_->set_ime_composition_range_callback(internal_, cb.release(), wrapper);
}

void OverlayManager::SetImeSelectionBoundsCallback(
std::function<void(Rect, Rect, bool)> onImeSelectionBoundsChanged)
{
static auto wrapper =
[](void* callbackData, DiscordRect anchor, DiscordRect focus, bool isAnchorFirst) -> void {
std::unique_ptr<std::function<void(Rect, Rect, bool)>> cb(
reinterpret_cast<std::function<void(Rect, Rect, bool)>*>(callbackData));
if (!cb || !(*cb)) {
return;
}
(*cb)(*reinterpret_cast<Rect const*>(&anchor),
*reinterpret_cast<Rect const*>(&focus),
(isAnchorFirst != 0));
};
std::unique_ptr<std::function<void(Rect, Rect, bool)>> cb{};
cb.reset(new std::function<void(Rect, Rect, bool)>(std::move(onImeSelectionBoundsChanged)));
internal_->set_ime_selection_bounds_callback(internal_, cb.release(), wrapper);
}

bool OverlayManager::IsPointInsideClickZone(std::int32_t x, std::int32_t y)
{
auto result = internal_->is_point_inside_click_zone(internal_, x, y);
return (result != 0);
}

} // namespace discord
24 changes: 24 additions & 0 deletions Dependencies/discord/overlay_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ class OverlayManager final {
void OpenActivityInvite(ActivityActionType type, std::function<void(Result)> callback);
void OpenGuildInvite(char const* code, std::function<void(Result)> callback);
void OpenVoiceSettings(std::function<void(Result)> callback);
Result InitDrawingDxgi(IDXGISwapChain* swapchain, bool useMessageForwarding);
void OnPresent();
void ForwardMessage(MSG* message);
void KeyEvent(bool down, char const* keyCode, KeyVariant variant);
void CharEvent(char const* character);
void MouseButtonEvent(std::uint8_t down,
std::int32_t clickCount,
MouseButton which,
std::int32_t x,
std::int32_t y);
void MouseMotionEvent(std::int32_t x, std::int32_t y);
void ImeCommitText(char const* text);
void ImeSetComposition(char const* text,
ImeUnderline* underlines,
std::uint32_t underlinesLength,
std::int32_t from,
std::int32_t to);
void ImeCancelComposition();
void SetImeCompositionRangeCallback(
std::function<void(std::int32_t, std::int32_t, Rect*, std::uint32_t)>
onImeCompositionRangeChanged);
void SetImeSelectionBoundsCallback(
std::function<void(Rect, Rect, bool)> onImeSelectionBoundsChanged);
bool IsPointInsideClickZone(std::int32_t x, std::int32_t y);

Event<bool> OnToggle;

Expand Down
5 changes: 3 additions & 2 deletions Dependencies/discord/relationship_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace discord {

class RelationshipEvents final {
public:
static void OnRefresh(void* callbackData)
static void DISCORD_CALLBACK OnRefresh(void* callbackData)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -24,7 +24,8 @@ class RelationshipEvents final {
module.OnRefresh();
}

static void OnRelationshipUpdate(void* callbackData, DiscordRelationship* relationship)
static void DISCORD_CALLBACK OnRelationshipUpdate(void* callbackData,
DiscordRelationship* relationship)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
6 changes: 4 additions & 2 deletions Dependencies/discord/store_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace discord {

class StoreEvents final {
public:
static void OnEntitlementCreate(void* callbackData, DiscordEntitlement* entitlement)
static void DISCORD_CALLBACK OnEntitlementCreate(void* callbackData,
DiscordEntitlement* entitlement)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand All @@ -24,7 +25,8 @@ class StoreEvents final {
module.OnEntitlementCreate(*reinterpret_cast<Entitlement const*>(entitlement));
}

static void OnEntitlementDelete(void* callbackData, DiscordEntitlement* entitlement)
static void DISCORD_CALLBACK OnEntitlementDelete(void* callbackData,
DiscordEntitlement* entitlement)
{
auto* core = reinterpret_cast<Core*>(callbackData);
if (!core) {
Expand Down
Loading

0 comments on commit 8dc97c5

Please sign in to comment.