Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Minecraft.Client/ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,6 @@ void ClientConnection::handleRespawn(shared_ptr<RespawnPacket> packet)
gameMode->getTutorial()->showTutorialPopup(false);
}

// 4J-JEV: Fix for Durango #156334 - Content: UI: Rich Presence 'In the Nether' message is updating with a 3 to 10 minute delay.
minecraft->localplayers[m_userIndex]->updateRichPresence();

ConnectionProgressParams *param = new ConnectionProgressParams();
param->iPad = m_userIndex;
if( packet->dimension == -1)
Expand Down
106 changes: 103 additions & 3 deletions Minecraft.Client/Extrax64Stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "Orbis\Sentient\DynamicConfigurations.h"
#include <perf.h>
#endif
#ifdef _WINDOWS64
#include "Windows64/RichPresence/discord_rpc.h"
#endif

#if !defined(__PS3__) && !defined(__ORBIS__) && !defined(__PSVITA__)
#ifdef _WINDOWS64
Expand Down Expand Up @@ -729,9 +732,106 @@
bool C_4JProfile::CanBeAwarded(int iQuadrant, int iAwardNumber) { return false; }
void C_4JProfile::Award(int iQuadrant, int iAwardNumber, bool bForce) {}
bool C_4JProfile::IsAwardsFlagSet(int iQuadrant, int iAward) { return false; }
void C_4JProfile::RichPresenceInit(int iPresenceCount, int iContextCount) {}
void C_4JProfile::RegisterRichPresenceContext(int iGameConfigContextID) {}
void C_4JProfile::SetRichPresenceContextValue(int iPad, int iContextID, int iVal) {}
void C_4JProfile::RichPresenceInit(int iPresenceCount, int iContextCount)
{
#ifdef _WINDOWS64
DiscordEventHandlers discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));

// 1480245069947732159 is on my discord account (acth2)
Discord_Initialize("1480245069947732159", &discordPresence, 1, NULL);
#endif
}
void C_4JProfile::RegisterRichPresenceContext(int iGameConfigContextID)
{
}

#ifdef _WINDOWS64
std::string WStringToUtf8(LPCWSTR wstr)
{
int size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
std::string result(size - 1, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result.data(), size, NULL, NULL);
return result;
}
#endif

void C_4JProfile::SetRichPresenceContextValue(int iPad, int iContextID, int iVal)
{
#ifdef _WINDOWS64
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));

// std::string = UTF8
// LPCWSTR = UTF16

static std::string s_detailsUtf8;
static std::string s_stateUtf8;

// i cannot instantly do = because app.getString
s_detailsUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_BLANK));

if (iContextID == CONTEXT_GAME_STATE)
{
discordPresence.details = "Playing Minecraft: Legacy Console Edition";

discordPresence.largeImageKey = "main_icon";
discordPresence.largeImageText = "Minecraft: LCE";

switch (iVal)
{
case CONTEXT_GAME_STATE_NETHER:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_NETHER));
discordPresence.smallImageKey = "nether_icon";
break;

case CONTEXT_GAME_STATE_FORGING:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_FORGING));
discordPresence.smallImageKey = "anvil_icon";
break;

case CONTEXT_GAME_STATE_BOATING:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_BOATING));
discordPresence.smallImageKey = "boat_icon";
break;

case CONTEXT_GAME_STATE_CRAFTING:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_CRAFTING));
discordPresence.smallImageKey = "crafting_icon";
break;

case CONTEXT_GAME_STATE_RIDING_MINECART:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_RIDING_MINECART));
discordPresence.smallImageKey = "minecart_icon";
break;

case CONTEXT_GAME_STATE_RIDING_PIG:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_RIDING_PIG));
discordPresence.smallImageKey = "pig_icon";
break;

case CONTEXT_GAME_STATE_BREWING:

Check failure on line 813 in Minecraft.Client/Extrax64Stubs.cpp

View workflow job for this annotation

GitHub Actions / build

case value '5' already used
s_stateUtf8 = "Brewing a potion";
discordPresence.smallImageKey = "brewing_icon";
break;

case CONTEXT_GAME_STATE_ENCHANTING:

Check failure on line 818 in Minecraft.Client/Extrax64Stubs.cpp

View workflow job for this annotation

GitHub Actions / build

case value '5' already used
s_stateUtf8 = "Enchanting";
discordPresence.smallImageKey = "enchanting_icon";
break;

case CONTEXT_GAME_STATE_BLANK:
default:
s_stateUtf8 = WStringToUtf8(app.GetString(IDS_RICHPRESENCESTATE_BLANK));
discordPresence.smallImageKey = nullptr;
break;
}

discordPresence.state = s_stateUtf8.c_str();
Discord_UpdatePresence(&discordPresence);
}
#endif
}
void C_4JProfile::SetCurrentGameActivity(int iPad, int iNewPresence, bool bSetOthersToIdle) {}
void C_4JProfile::DisplayFullVersionPurchase(bool bRequired, int iQuadrant, int iUpsellParam) {}
void C_4JProfile::SetUpsellCallback(void (*Func)(LPVOID lpParam, eUpsellType type, eUpsellResponse response, int iUserData), LPVOID lpParam) {}
Expand Down
1 change: 0 additions & 1 deletion Minecraft.Client/LevelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,6 @@ void LevelRenderer::levelEvent(shared_ptr<Player> source, int type, int x, int y
level[playerIndex]->playStreamingMusic(L"", x, y, z); // 4J - used to pass nullptr, but using empty string here now instead
}
}
mc->localplayers[playerIndex]->updateRichPresence();
}
break;
// 4J - new level event sounds brought forward from 1.2.3
Expand Down
137 changes: 66 additions & 71 deletions Minecraft.Client/LocalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
#include "..\Minecraft.World\Random.h"
#include "..\Minecraft.World\TileEntity.h"
#include "..\Minecraft.World\Mth.h"

#include "..\AnvilMenu.h"
#include "..\CraftingMenu.h"
#include "..\BrewingStandMenu.h"
#include "..\EnchantmentMenu.h"

#include "AchievementPopup.h"
#include "CritParticle.h"

Expand Down Expand Up @@ -470,42 +476,6 @@ void LocalPlayer::aiStep()
yd = 0.0f;
onGround = true;
}

// Check if the player is idle and the rich presence needs updated
if( !m_bIsIdle && InputManager.GetIdleSeconds( m_iPad ) > PLAYER_IDLE_TIME )
{
ProfileManager.SetCurrentGameActivity(m_iPad,CONTEXT_PRESENCE_IDLE,false);
m_bIsIdle = true;
}
else if ( m_bIsIdle && InputManager.GetIdleSeconds( m_iPad ) < PLAYER_IDLE_TIME )
{
// Are we offline or online, and how many players are there
if(g_NetworkManager.GetPlayerCount()>1)
{
// only do it for this player here - each player will run this code
if(g_NetworkManager.IsLocalGame())
{
ProfileManager.SetCurrentGameActivity(m_iPad,CONTEXT_PRESENCE_MULTIPLAYEROFFLINE,false);
}
else
{
ProfileManager.SetCurrentGameActivity(m_iPad,CONTEXT_PRESENCE_MULTIPLAYER,false);
}
}
else
{
if(g_NetworkManager.IsLocalGame())
{
ProfileManager.SetCurrentGameActivity(m_iPad,CONTEXT_PRESENCE_MULTIPLAYER_1POFFLINE,false);
}
else
{
ProfileManager.SetCurrentGameActivity(m_iPad,CONTEXT_PRESENCE_MULTIPLAYER_1P,false);
}
}
updateRichPresence();
m_bIsIdle = false;
}
}

void LocalPlayer::changeDimension(int i)
Expand Down Expand Up @@ -1600,42 +1570,67 @@ bool LocalPlayer::handleMouseClick(int button)

void LocalPlayer::updateRichPresence()
{
if((m_iPad!=-1)/* && !ui.GetMenuDisplayed(m_iPad)*/ )
{
shared_ptr<ItemInstance> selectedItem = inventory->getSelected();
if(selectedItem != nullptr && selectedItem->id == Item::fishingRod_Id)
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_FISHING);
}
else if(selectedItem != nullptr && selectedItem->id == Item::map_Id)
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_MAP);
}
else if ( (riding != nullptr) && riding->instanceof(eTYPE_MINECART) )
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_RIDING_MINECART);
if (m_iPad == -1)
{
return;
}

if (containerMenu != nullptr && containerMenu != inventoryMenu)
{
if (dynamic_cast<AnvilMenu *>(containerMenu) != nullptr)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_FORGING);
}
else if (dynamic_cast<CraftingMenu *>(containerMenu) != nullptr)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_CRAFTING);
}
else if (dynamic_cast<BrewingStandMenu*>(containerMenu) != nullptr)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_BREWING);
}
else if ( (riding != nullptr) && riding->instanceof(eTYPE_BOAT) )
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_BOATING);
}
else if ( (riding != nullptr) && riding->instanceof(eTYPE_PIG) )
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_RIDING_PIG);
}
else if( this->dimension == -1 )
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_NETHER);
}
else if( minecraft->soundEngine->GetIsPlayingStreamingCDMusic() )
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_CD);
}
else
{
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_BLANK);
}
}
else if (dynamic_cast<EnchantmentMenu *>(containerMenu) != nullptr)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_ENCHANTING);
}
return;
}

// INGAME ACTIVITY
shared_ptr<ItemInstance> selectedItem = inventory->getSelected();
if (selectedItem != NULL && selectedItem->id == Item::fishingRod_Id)
{
// TODO
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_FISHING);
}
else if (selectedItem != NULL && selectedItem->id == Item::map_Id)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_MAP);
}
else if ((riding != NULL) && riding->instanceof(eTYPE_MINECART))
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_RIDING_MINECART);
}
else if ((riding != NULL) && riding->instanceof(eTYPE_BOAT))
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_BOATING);
}
else if ((riding != NULL) && riding->instanceof(eTYPE_PIG))
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_RIDING_PIG);
}
else if (this->dimension == -1)
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_NETHER);
}
else if (minecraft->soundEngine->GetIsPlayingStreamingCDMusic())
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_CD);
}
else
{
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_BLANK);
}
}

// 4J Stu - Added for telemetry
Expand Down
17 changes: 14 additions & 3 deletions Minecraft.Client/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ void Minecraft::init()
progressRenderer = new ProgressRenderer(this);

RenderManager.CBuffLockStaticCreations();

// Setup discord rich presence
#ifdef _WINDOWS64
ProfileManager.RichPresenceInit(4, 1);
#endif
}

void Minecraft::renderLoadingScreen()
Expand Down Expand Up @@ -2299,6 +2304,15 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
// Tick the opacity timer (to display the interface at default opacity for a certain time if the user has been navigating it)
app.TickOpacityTimer(iPad);

#ifdef _WINDOWS64
static int tickRP = 0;
if (++tickRP >= 10)
{
player->updateRichPresence();
tickRP = 0;
}
#endif

// 4J added
if( bFirst ) levelRenderer->destroyedTileManager->tick();

Expand Down Expand Up @@ -3562,9 +3576,6 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
gameMode->getTutorial()->onSelectedItemChanged(player->inventory->getSelected());
}

// Update presence
player->updateRichPresence();

if (options->isFlying)
{
if (wheel > 0) wheel = 1;
Expand Down
2 changes: 0 additions & 2 deletions Minecraft.Client/MultiPlayerLocalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ void MultiplayerLocalPlayer::ride(shared_ptr<Entity> e)
TelemetryManager->RecordEnemyKilledOrOvercome(GetXboxPad(), 0, y, 0, 0, 0, 0, eventType);
}

updateRichPresence();

Minecraft *pMinecraft = Minecraft::GetInstance();

if( pMinecraft->localgameModes[m_iPad] != nullptr )
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Loading