Skip to content

Commit 565e187

Browse files
committed
Added checks for the Portal SourceMod++ plugin
1 parent 0d8c707 commit 565e187

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

p2mm.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ CP2MMServerPlugin::CP2MMServerPlugin()
123123
this->m_bPluginLoaded = false;
124124
this->m_bPluginUnloading = false; // For Discord RPC.
125125
this->m_bNoUnload = false; // If we fail to load, we don't want to run anything on Unload().
126+
this->m_bP2SMPluginLoaded = false; // Some functions that the Portal 2 SourceMod++ plugin does match some fixes
126127

127128
// Current Portal 2 branch based game being run.
128129
// Helps when checking for specific game related things instead of getting the game directory everytime.
@@ -331,6 +332,14 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
331332
MathLib_Init(2.2f, 2.2f, 0.0f, 2.0f);
332333
ConVar_Register(0);
333334

335+
// Check if Portal 2 SourceMod++ plugin is loaded. If it is, some functionality will not be enabled in P2:MM as P2SM++ will take priority.
336+
Log(INFO, true, "Checking if Portal 2 SourceMod++ is loaded...");
337+
if (g_pCVar->FindVar("p2sm_developer"))
338+
{
339+
this->m_bP2SMPluginLoaded = true;
340+
Log(WARNING, true, "Portal 2 SourceMod++ is loaded! Letting P2SM++ have priority over some patches!");
341+
}
342+
334343
// Enable Discord RPC if it is not disabled by the host.
335344
Log(INFO, true, "Checking if Discord RPC should be started...");
336345
if (p2mm_discord_rpc.GetBool() && !CDiscordIntegration::DiscordRPCRunning() /*&& !this->m_bP2SMPluginLoaded*/)
@@ -373,8 +382,12 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
373382
Memory::ReplacePattern("engine", "75 ?? 68 ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 83 C4 ?? 5F C3 56", "EB ?? 68 ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 83 C4 ?? 5F C3 56");
374383
Log(INFO, true, "Patching Portal 2...");
375384

376-
// Linked portal doors event crash patch
377-
Memory::ReplacePattern("server", "0F B6 87 04 05 00 00 8B 16", "EB 14 87 04 05 00 00 8B 16");
385+
// Linked portal doors event crash patch.
386+
if (!this->m_bP2SMPluginLoaded)
387+
{
388+
Log(INFO, true, "Fixing linked portal doors...");
389+
Memory::ReplacePattern("server", "0F B6 87 04 05 00 00 8B 16", "EB 14 87 04 05 00 00 8B 16");
390+
}
378391

379392
// Partner disconnects.
380393
Log(INFO, true, "Patching partner disconnect event...");
@@ -416,10 +429,14 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
416429
);
417430

418431
// For p2mm_instantrespawn.
419-
MH_CreateHook(
420-
Memory::Scanner::Scan(SERVERDLL, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B ?? 89 6C 24 ?? 8B EC A1 ?? ?? ?? ?? F3 0F 10 40 ?? F3 0F 58 05 ?? ?? ?? ?? 83 EC 28 56 57 6A 00 51 8B F1 F3 0F 11 04 24 E8 ?? ?? ?? ?? 6A 03"),
421-
&CPortal_Player__PlayerDeathThink_hook, reinterpret_cast<void**>(&CPortal_Player__PlayerDeathThink_orig)
422-
);
432+
if (!this->m_bP2SMPluginLoaded)
433+
{
434+
Log(INFO, true, "Hooking CPortal_Player::PlayerDeathThink...");
435+
MH_CreateHook(
436+
Memory::Scanner::Scan(SERVERDLL, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B ?? 89 6C 24 ?? 8B EC A1 ?? ?? ?? ?? F3 0F 10 40 ?? F3 0F 58 05 ?? ?? ?? ?? 83 EC 28 56 57 6A 00 51 8B F1 F3 0F 11 04 24 E8 ?? ?? ?? ?? 6A 03"),
437+
&CPortal_Player__PlayerDeathThink_hook, reinterpret_cast<void**>(&CPortal_Player__PlayerDeathThink_orig)
438+
);
439+
}
423440

424441
// "respawn" function hook for getting a VScript "game event" call out of it.
425442
Log(INFO, true, "Hooking respawn function call...");
@@ -429,10 +446,14 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
429446
);
430447

431448
// UTIL_GetLocalPlayer dedicated server hook crash fix.
432-
MH_CreateHook(
433-
Memory::Scanner::Scan(SERVERDLL, "8B 15 ?? ?? ?? ?? 8B 4A ?? 33 C0"),
434-
&UTIL_GetLocalPlayer, reinterpret_cast<void**>(&UTIL_GetLocalPlayer_orig)
435-
);
449+
if (!this->m_bP2SMPluginLoaded)
450+
{
451+
Log(INFO, true, "Hooking UTIL_GetLocalPlayer...");
452+
MH_CreateHook(
453+
Memory::Scanner::Scan(SERVERDLL, "8B 15 ?? ?? ?? ?? 8B 4A ?? 33 C0"),
454+
&UTIL_GetLocalPlayer, reinterpret_cast<void**>(&UTIL_GetLocalPlayer_orig)
455+
);
456+
}
436457

437458
// Game-specific hooks
438459
switch (g_P2MMServerPlugin.m_iCurGameIndex)
@@ -529,7 +550,11 @@ void CP2MMServerPlugin::Unload(void)
529550
Log(INFO, true, "Un-patching Portal 2...");
530551

531552
// Linked portal doors event crash patch
532-
Memory::ReplacePattern("server", "EB 14 87 04 05 00 00 8B 16", "0F B6 87 04 05 00 00 8B 16");
553+
if (!this->m_bP2SMPluginLoaded)
554+
{
555+
Log(INFO, true, "Unfixing linked portal doors...");
556+
Memory::ReplacePattern("server", "EB 14 87 04 05 00 00 8B 16", "0F B6 87 04 05 00 00 8B 16");
557+
}
533558

534559
// Partner disconnects
535560
Log(INFO, true, "Un-patching partner disconnect event...");

p2mm.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class CP2MMServerPlugin : public IServerPluginCallbacks, public IGameEventListen
6262
bool m_bSeenFirstRunPrompt;
6363
bool m_bFirstMapRan;
6464

65+
bool m_bP2SMPluginLoaded;
66+
6567
CBaseServer* sv; // Pointer to the server.
6668

6769
private:

0 commit comments

Comments
 (0)