Skip to content

Commit

Permalink
Some more game support things, supported mod checking, changing some …
Browse files Browse the repository at this point in the history
…if statements to switch statements, and fixed Discord RPC bug

Added in some more support things for Divinity like Discord RPC and a place for the largeImageKey when that is completed.

Reworked the part which originally just printed a dev message of which Portal 2 branch based game is being played to checking if it is currently a supported game. If it isn't the game will be closed because half of the time the game will close anyway because of crashing due to wrong byte patches or hooks, or some other inconvenience we haven't fully figured out. If you want to load in anyway just use `-forcep2mmload` as a launch option in whatever you use to launch the game.

Because the m_iCurGameIndex has a enum to go with it, switched out some if statement checks with switch case statements.

Fixed Discord RPC bug where it wouldnt report on discord that the user was actually on the menu when exiting out of a game session.
  • Loading branch information
OrsellGaming committed Jan 10, 2025
1 parent 8e1449b commit 19217ed
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 60 deletions.
49 changes: 33 additions & 16 deletions discordrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,15 @@ bool CDiscordIntegration::StartDiscordRPC()
V_snprintf(appid, 255, "%d", engineServer->GetAppID());
Discord_Initialize("1201562647880015954", handlers, 1, appid);

if (g_P2MMServerPlugin.m_iCurGameIndex == PORTAL_STORIES_MEL)
switch (g_P2MMServerPlugin.m_iCurGameIndex)
{
case (PORTAL_STORIES_MEL):
RPC.largeImageKey = "p2mmmellogo";
RPC.largeImageText = "Portal Stories: Mel";
break;
case (DIVINITY):
RPC.largeImageKey = "p2mmdivinitylogo";
RPC.largeImageText = "Portal: Divinity";
}
UpdateDiscordRPC();

Expand All @@ -321,30 +326,36 @@ void CDiscordIntegration::ShutdownDiscordRPC()

void CDiscordIntegration::UpdateDiscordRPC()
{
bool bActiveGame = IsGameActive();
bool bGameShutdown = IsGameShutdown();

DiscordLog(0, true, "Updating Discord RPC!");
DiscordLog(0, true, "Unloading Plugin: %i", g_P2MMServerPlugin.m_bPluginUnloading);
DiscordLog(0, true, "IsGameActive: %i", bActiveGame);
DiscordLog(0, true, "IsGameShutdown: %i", bGameShutdown);

RPC.state = "";
RPC.details = "";
RPC.smallImageKey = "wave";
RPC.smallImageText = "Welcome to P2:MM!";
RPC.partyId = "";
RPC.partySize = 0;
RPC.partyMax = MAX_PLAYERS;
RPC.matchSecret = "";
RPC.joinSecret = "";
RPC.spectateSecret = "";
RPC.instance = 0;

if (g_P2MMServerPlugin.m_bPluginUnloading)
{
RPC.state = "See you around!";
RPC.details = "Shutting down...";
RPC.smallImageKey = "wave";
RPC.smallImageText = "Welcome to P2:MM!";
RPC.partySize = 0;
RPC.partyMax = 0;
RPC.instance = 0;
}

if (!IsGameActive() || IsGameShutdown())
{
if (!bActiveGame || bGameShutdown)
RPC.details = "Main Menu";
RPC.smallImageKey = "wave";
RPC.smallImageText = "Welcome to P2:MM!";
RPC.partySize = 0;
RPC.partyMax = 0;
RPC.instance = 0;
}

if (IsGameActive() && (!g_P2MMServerPlugin.m_bPluginUnloading || !IsGameShutdown()))
if (bActiveGame && !(g_P2MMServerPlugin.m_bPluginUnloading || bGameShutdown))
{
MapParams* map = NULL;
char state[128] = { 0 };
Expand Down Expand Up @@ -415,6 +426,13 @@ void CDiscordIntegration::UpdateDiscordRPC()
V_snprintf(smallImageKey, 32, "melchapter%i", map->chapter);
V_strcat(smallImageText, map->chaptername, 128);
break;
case (DIVINITY):
map = InDivinityCampaignMap();
if (!map) break;
V_strcat(details, map->mapname, 128);
V_snprintf(smallImageKey, 32, "divinitychapter%i", map->chapter);
V_strcat(smallImageText, map->chaptername, 128);
break;
default:
break;
}
Expand All @@ -431,7 +449,6 @@ void CDiscordIntegration::UpdateDiscordRPC()
RPC.smallImageKey = smallImageKey;
RPC.smallImageText = smallImageText;
RPC.partySize = CURPLAYERCOUNT();
RPC.partyMax = MAX_PLAYERS;
RPC.instance = 1;
}

Expand Down
43 changes: 33 additions & 10 deletions globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ std::vector<MapParams> gelocityMaps =
MapParams* InGelocityMap()
{
for (size_t i = 0; i < gelocityMaps.size(); i++)
{
if (FStrEq(CURMAPFILENAME, gelocityMaps[i].mapfile)) return &gelocityMaps[i];
}
return NULL;
}

Expand Down Expand Up @@ -385,16 +383,12 @@ MapParams* InP2CampaignMap(bool mpMaps)
if (mpMaps)
{
for (size_t i = 0; i < mpCampaignMaps.size(); i++)
{
if (FStrEq(CURMAPFILENAME, mpCampaignMaps[i].mapfile)) return &mpCampaignMaps[i];
}
}
else
{
for (size_t i = 0; i < spCampaignMaps.size(); i++)
{
if (FStrEq(CURMAPFILENAME, spCampaignMaps[i].mapfile)) return &spCampaignMaps[i];
}
}
return NULL;
}
Expand Down Expand Up @@ -460,16 +454,45 @@ MapParams* InMelCampaignMap(bool advanced)
if (advanced)
{
for (size_t i = 0; i < melAdvancedCampaignMaps.size(); i++)
{
if (FStrEq(CURMAPFILENAME, melAdvancedCampaignMaps[i].mapfile)) return &melAdvancedCampaignMaps[i];
}
}
else
{
for (size_t i = 0; i < melStoryCampaignMaps.size(); i++)
{
if (FStrEq(CURMAPFILENAME, melStoryCampaignMaps[i].mapfile)) return &melStoryCampaignMaps[i];
}
}
return NULL;
}

// Array of maps for Portal: Divinity
std::vector<MapParams> divinityCampaignMaps =
{
{"sp_a1_divinity_intro", "Intro", 1, "House of Leaves"},
{"sp_a1_divinity_bts1", "BTS 1", 1, "House of Leaves"},
{"sp_a1_divinity_field_intro", "Field Intro", 1, "House of Leaves"},
{"sp_a1_divinity_wall_blocks_wall", "Wall Blocks Wall", 1, "House of Leaves"},
{"sp_a1_divinity_traversal", "Traversal", 1, "House of Leaves"},
{"sp_a1_divinity_funnel_tower", "Funnel Tower", 1, "House of Leaves"},
{"sp_a1_divinity_pink_plate", "Pink Plate", 1, "House of Leaves"},
{"sp_a1_divinity_core01", "Core 01", 1, "House of Leaves"}
};

// Check to see which Divinity map is being played.
MapParams* InDivinityCampaignMap(bool advanced)
{
if (advanced)
{
// No Divinity Advanced Chambers have been implemented yet.

//for (size_t i = 0; i < melAdvancedCampaignMaps.size(); i++)
//{
// if (FStrEq(CURMAPFILENAME, melAdvancedCampaignMaps[i].mapfile)) return &melAdvancedCampaignMaps[i];
//}
}
else
{
for (size_t i = 0; i < divinityCampaignMaps.size(); i++)
if (FStrEq(CURMAPFILENAME, divinityCampaignMaps[i].mapfile)) return &divinityCampaignMaps[i];
}
return NULL;
}
2 changes: 2 additions & 0 deletions globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum
APERTURE_TAG,
PORTAL_RELOADED,
INFRA,
STANLEY_PARABLE,
DIVINITY
};

Expand All @@ -93,6 +94,7 @@ typedef struct
MapParams* InGelocityMap();
MapParams* InP2CampaignMap(bool mpMaps = false);
MapParams* InMelCampaignMap(bool advanced = false);
MapParams* InDivinityCampaignMap(bool advanced = false);

//---------------------------------------------------------------------------------
// Interfaces from the engine.
Expand Down
79 changes: 48 additions & 31 deletions p2mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,52 +160,69 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterface

P2MMLog(0, false, "Loading plugin...");

// Determine which Portal 2 branch game we are running.
// Determine which Portal 2 branch game we are running and if its supported.
bool unsupportedGame = false;
P2MMLog(0, true, "Determining which Portal 2 branch game is being run...");
if ((FStrEq(GetGameMainDir(), "portal2")))
{
this->m_iCurGameIndex = PORTAL_2;
P2MMLog(0, false, "Currently running Portal 2.");
}
else if ((FStrEq(GetGameMainDir(), "portal_stories")))
{
this->m_iCurGameIndex = PORTAL_STORIES_MEL;
P2MMLog(0, false, "Currently running Portal Stories: Mel.");
}
else if ((FStrEq(GetGameMainDir(), "aperturetag")))
{
this->m_iCurGameIndex = APERTURE_TAG;
P2MMLog(0, false, "Currently running Aperture Tag.");
// Unsupported...for now...
unsupportedGame = true;
}
else if ((FStrEq(GetGameMainDir(), "portalreloaded")))
{
this->m_iCurGameIndex = PORTAL_RELOADED;
P2MMLog(0, false, "Currently running Portal Reloaded.");
// Unsupported...for now...
unsupportedGame = true;
}
else if ((FStrEq(GetGameMainDir(), "infra")))
{
this->m_iCurGameIndex = INFRA;
P2MMLog(0, false, "Currently running Infra.");
// Unsupported...for now...
unsupportedGame = true;
}
else if ((FStrEq(GetGameMainDir(), "thestanleyparable")))
{
this->m_iCurGameIndex = STANLEY_PARABLE;
P2MMLog(0, false, "Currently running The Stanley Parable.");
// Unsupported...for now...
unsupportedGame = true;
}
else if ((FStrEq(GetGameMainDir(), "divinity")))
{
this->m_iCurGameIndex = DIVINITY;
P2MMLog(0, false, "Currently running Portal: Divinity.");
}
else if (!CommandLine()->FindParm("-forcep2mmload"))
{
P2MMLog(2, false, "\nAn unsupported Source Engine/Portal 2 branch game has been started with P2:MM! Please check the FAQ to see which Portal 2 engine based games are supported!");
return false;
}
else
{
unsupportedGame = true;
}


if (p2mm_developer.GetBool())
if (unsupportedGame && !CommandLine()->FindParm("-forcep2mmload"))
{
switch (this->m_iCurGameIndex)
{
case PORTAL_2:
P2MMLog(0, true, "Currently running Portal 2.");
break;
case PORTAL_STORIES_MEL:
P2MMLog(0, true, "Currently running Portal Stories: Mel.");
break;
case APERTURE_TAG:
P2MMLog(0, true, "Currently running Aperture Tag.");
break;
case PORTAL_RELOADED:
P2MMLog(0, true, "Currently running Portal Reloaded.");
break;
case INFRA:
P2MMLog(0, true, "Currently running Infra.");
break;
case DIVINITY:
P2MMLog(0, true, "Currently running Portal: Divinity.");
break;
default:
//! TODO: Need to add more checks for this down the line if a unsupported game is run.
P2MMLog(1, true, "INVALID m_iCurGameIndex SPECIFIED! DEFAULTING TO PORTAL 2!");
this->m_iCurGameIndex = PORTAL_2;
P2MMLog(0, true, "Currently running Portal 2.");
break;
}
P2MMLog(2, false, "\nThe current Source Engine/Portal 2 branch game is not **yet** supported by P2:MM! Please check the FAQ to see which games are supported!");
return false;
}
else if (unsupportedGame && CommandLine()->FindParm("-forcep2mmload"))
P2MMLog(1, false, "P2:MM is being run with a unsupported Source Engine/Portal 2 branch game! Proceed with caution as crashes and bugs could occur!");

P2MMLog(0, true, "Connecting tier libraries...");
ConnectTier1Libraries(&interfaceFactory, 1);
Expand Down Expand Up @@ -1029,7 +1046,7 @@ extern void updateMapsList();
//---------------------------------------------------------------------------------
void CP2MMServerPlugin::LevelShutdown(void)
{
P2MMLog(0, true, "Level Shutdown!");
P2MMLog(0, true, "Level Shutdown! Map: %s", CURMAPFILENAME);
p2mm_loop.SetValue("0"); // REMOVE THIS at some point...
updateMapsList(); // Update the maps list for p2mm_map.
// Update Discord RPC to update the level information or to say the host is on the main menu.
Expand Down
Loading

0 comments on commit 19217ed

Please sign in to comment.