Skip to content

Commit ff549aa

Browse files
committed
Added MessageBox call for when running -forcep2mmload and its a unsupported game.
1 parent f888892 commit ff549aa

2 files changed

Lines changed: 53 additions & 42 deletions

File tree

p2mm.cpp

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "minhook/include/MinHook.h"
1616

17+
#include <Windows.h>
18+
1719
// memdbgon must be the last include file in a .cpp file!!!
1820
#include "tier0/memdbgon.h"
1921

@@ -111,6 +113,8 @@ static const char* forbiddenClientCommands[] =
111113
//---------------------------------------------------------------------------------
112114
CP2MMServerPlugin::CP2MMServerPlugin()
113115
{
116+
this->m_hWnd = nullptr; // Game window handle
117+
114118
// Store game vars
115119
this->m_bSeenFirstRunPrompt = false; // Flag is set true after CallFirstRunPrompt() is called in VScript.
116120
this->m_bFirstMapRan = true; // Checks if the game ran for the first time.
@@ -160,6 +164,10 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterface
160164

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

167+
this->m_hWnd = FindWindow("Valve001", nullptr);
168+
if (!this->m_hWnd)
169+
P2MMLog(1, false, "Failed to find game window Valve001!");
170+
163171
// Determine which Portal 2 branch game we are running and if its supported.
164172
bool unsupportedGame = false;
165173
const char* gameMainDir = GetGameMainDir();
@@ -221,71 +229,74 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterface
221229
return false;
222230
}
223231
if (unsupportedGame && CommandLine()->FindParm("-forcep2mmload"))
232+
{
233+
MessageBox(this->m_hWnd, "P2:MM is being run with a unsupported Source Engine/Portal 2 branch game! Proceed with caution as crashes and bugs could occur!", "Unsupported P2:MM Game", MB_OK | MB_ICONEXCLAMATION);
224234
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!");
235+
}
225236

226237
P2MMLog(0, true, "Connecting tier libraries...");
227238
ConnectTier1Libraries(&interfaceFactory, 1);
228239
ConnectTier2Libraries(&interfaceFactory, 1);
229240

230241
// Make sure that all the interfaces needed are loaded and useable
231242
P2MMLog(0, true, "Loading interfaces...");
232-
engineServer = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, 0);
243+
engineServer = static_cast<IVEngineServer*>(interfaceFactory(INTERFACEVERSION_VENGINESERVER, 0));
233244
if (!engineServer)
234245
{
235246
P2MMLog(1, false, "Unable to load engineServer!");
236247
this->m_bNoUnload = true;
237248
return false;
238249
}
239250

240-
engineClient = (IVEngineClient*)interfaceFactory(VENGINE_CLIENT_INTERFACE_VERSION, 0);
251+
engineClient = static_cast<IVEngineClient*>(interfaceFactory(VENGINE_CLIENT_INTERFACE_VERSION, 0));
241252
if (!engineClient)
242253
{
243254
P2MMLog(1, false, "Unable to load engineClient!");
244255
this->m_bNoUnload = true;
245256
return false;
246257
}
247258

248-
g_pPlayerInfoManager = (IPlayerInfoManager*)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, 0);
259+
g_pPlayerInfoManager = static_cast<IPlayerInfoManager*>(gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, 0));
249260
if (!g_pPlayerInfoManager)
250261
{
251262
P2MMLog(1, false, "Unable to load g_pPlayerInfoManager!");
252263
this->m_bNoUnload = true;
253264
return false;
254265
}
255266

256-
g_pScriptVM = (IScriptVM*)interfaceFactory(VSCRIPT_INTERFACE_VERSION, 0);
267+
g_pScriptVM = static_cast<IScriptVM*>(interfaceFactory(VSCRIPT_INTERFACE_VERSION, 0));
257268
if (!g_pScriptVM)
258269
{
259270
P2MMLog(1, false, "Unable to load g_pScriptVM!");
260271
this->m_bNoUnload = true;
261272
return false;
262273
}
263274

264-
g_pServerTools = (IServerTools*)gameServerFactory(VSERVERTOOLS_INTERFACE_VERSION, 0);
275+
g_pServerTools = static_cast<IServerTools*>(gameServerFactory(VSERVERTOOLS_INTERFACE_VERSION, 0));
265276
if (!g_pServerTools)
266277
{
267278
P2MMLog(1, false, "Unable to load g_pServerTools!");
268279
this->m_bNoUnload = true;
269280
return false;
270281
}
271282

272-
g_pGameEventManager = (IGameEventManager2*)interfaceFactory(INTERFACEVERSION_GAMEEVENTSMANAGER2, 0);
283+
g_pGameEventManager = static_cast<IGameEventManager2*>(interfaceFactory(INTERFACEVERSION_GAMEEVENTSMANAGER2, 0));
273284
if (!g_pGameEventManager)
274285
{
275286
P2MMLog(1, false, "Unable to load g_pGameEventManager!");
276287
this->m_bNoUnload = true;
277288
return false;
278289
}
279290

280-
g_pPluginHelpers = (IServerPluginHelpers*)interfaceFactory(INTERFACEVERSION_ISERVERPLUGINHELPERS, 0);
291+
g_pPluginHelpers = static_cast<IServerPluginHelpers*>(interfaceFactory(INTERFACEVERSION_ISERVERPLUGINHELPERS, 0));
281292
if (!g_pPluginHelpers)
282293
{
283294
P2MMLog(1, false, "Unable to load g_pPluginHelpers!");
284295
this->m_bNoUnload = true;
285296
return false;
286297
}
287298

288-
g_pFileSystem = (IFileSystem*)interfaceFactory(FILESYSTEM_INTERFACE_VERSION, 0);
299+
g_pFileSystem = static_cast<IFileSystem*>(interfaceFactory(FILESYSTEM_INTERFACE_VERSION, 0));
289300
if (!g_pFileSystem)
290301
{
291302
P2MMLog(1, false, "Unable to load g_pFileSystem!");
@@ -540,8 +551,8 @@ void CP2MMServerPlugin::LevelInit(char const* pMapName)
540551

541552
if (!g_P2MMServerPlugin.m_bSeenFirstRunPrompt) return;
542553

543-
std::string changemapstr = std::string("The server has changed the map to: `" + std::string(CURMAPFILENAME) + "`");
544-
g_pDiscordIntegration->SendWebHookEmbed("Server", changemapstr, EMBED_COLOR_SERVER, false);
554+
std::string changeMapStr = std::string("The server has changed the map to: `" + std::string(CURMAPFILENAME) + "`");
555+
g_pDiscordIntegration->SendWebHookEmbed("Server", changeMapStr, EMBED_COLOR_SERVER, false);
545556

546557
// Update Discord RPC to update current map information.
547558
g_pDiscordIntegration->UpdateDiscordRPC();
@@ -552,7 +563,7 @@ void CP2MMServerPlugin::LevelInit(char const* pMapName)
552563
//---------------------------------------------------------------------------------
553564
PLUGIN_RESULT CP2MMServerPlugin::ClientCommand(edict_t* pEntity, const CCommand& args)
554565
{
555-
// Check if its a valid player edict.
566+
// Check if it's a valid player edict.
556567
if (!pEntity || pEntity->IsFree())
557568
return PLUGIN_CONTINUE;
558569

@@ -619,8 +630,8 @@ PLUGIN_RESULT CP2MMServerPlugin::ClientCommand(edict_t* pEntity, const CCommand&
619630
//---------------------------------------------------------------------------------
620631
void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
621632
{
622-
bool spewinfo = p2mm_spewgameeventinfo.GetBool();
623-
if (spewinfo)
633+
bool spewInfo = p2mm_spewgameeventinfo.GetBool();
634+
if (spewInfo)
624635
{
625636
P2MMLog(0, true, "Game Event Fired: %s", event->GetName());
626637
P2MMLog(0, true, "VScript VM Working?: %s", (g_pScriptVM) ? "Working" : "Not Working!");
@@ -635,7 +646,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
635646
*/
636647
if (FStrEq(event->GetName(), "portal_player_ping"))
637648
{
638-
short userid = event->GetInt("userid");
649+
int userid = event->GetInt("userid");
639650
float ping_x = event->GetFloat("ping_x");
640651
float ping_y = event->GetFloat("ping_y");
641652
float ping_z = event->GetFloat("ping_z");
@@ -649,7 +660,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
649660
g_pScriptVM->Call<short, float, float, float, int>(ge_func, nullptr, false, nullptr, userid, ping_x, ping_y, ping_z, entindex);
650661
}
651662

652-
if (spewinfo)
663+
if (spewInfo)
653664
{
654665
P2MMLog(0, true, "userid: %i", userid);
655666
P2MMLog(0, true, "ping_x: %f", ping_x);
@@ -665,9 +676,9 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
665676
"userid" "short" // user ID on server
666677
"portal2" "bool" // false for portal1 (blue)
667678
*/
668-
else if (FStrEq(event->GetName(), "portal_player_portaled"))
679+
if (FStrEq(event->GetName(), "portal_player_portaled"))
669680
{
670-
short userid = event->GetInt("userid");
681+
int userid = event->GetInt("userid");
671682
bool portal2 = event->GetString("text");
672683
int entindex = UserIDToPlayerIndex(userid);
673684

@@ -679,7 +690,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
679690
g_pScriptVM->Call<short, bool, int>(ge_func, nullptr, false, nullptr, userid, portal2, entindex);
680691
}
681692

682-
if (spewinfo)
693+
if (spewInfo)
683694
{
684695
P2MMLog(0, true, "userid: %i", userid);
685696
P2MMLog(0, true, "portal2: %s", portal2 ? "true" : "false");
@@ -689,7 +700,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
689700
return;
690701
}
691702
// Event called when a turret hits another turret, "turret_hit_turret" returns nothing.
692-
else if (FStrEq(event->GetName(), "turret_hit_turret"))
703+
if (FStrEq(event->GetName(), "turret_hit_turret"))
693704
{
694705
if (g_pScriptVM)
695706
{
@@ -702,7 +713,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
702713
return;
703714
}
704715
// Event called when a camera is detached from a wall, "security_camera_detached" returns nothing.
705-
else if (FStrEq(event->GetName(), "security_camera_detached"))
716+
if (FStrEq(event->GetName(), "security_camera_detached"))
706717
{
707718
if (g_pScriptVM)
708719
{
@@ -718,9 +729,9 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
718729
/*
719730
"userid" "short" // user ID on server
720731
*/
721-
else if (FStrEq(event->GetName(), "player_landed"))
732+
if (FStrEq(event->GetName(), "player_landed"))
722733
{
723-
short userid = event->GetInt("userid");
734+
int userid = event->GetInt("userid");
724735
int entindex = UserIDToPlayerIndex(userid);
725736

726737
if (g_pScriptVM)
@@ -734,7 +745,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
734745
return;
735746
}
736747
// Event called when a Blue/Atlas spawns, "player_spawn_blue" returns nothing.
737-
else if (FStrEq(event->GetName(), "player_spawn_blue"))
748+
if (FStrEq(event->GetName(), "player_spawn_blue"))
738749
{
739750
if (g_pScriptVM)
740751
{
@@ -747,7 +758,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
747758
return;
748759
}
749760
// Event called when a Red/Orange/PBody spawns, "player_spawn_orange" returns nothing.
750-
else if (FStrEq(event->GetName(), "player_spawn_orange"))
761+
if (FStrEq(event->GetName(), "player_spawn_orange"))
751762
{
752763
if (g_pScriptVM)
753764
{
@@ -764,9 +775,9 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
764775
"userid" "short" // user ID who died
765776
"attacker" "short" // user ID who killed
766777
*/
767-
else if (FStrEq(event->GetName(), "player_death"))
778+
if (FStrEq(event->GetName(), "player_death"))
768779
{
769-
short userid = event->GetInt("userid");
780+
int userid = event->GetInt("userid");
770781
short attacker = event->GetInt("attacker");
771782
int entindex = UserIDToPlayerIndex(userid);
772783

@@ -790,7 +801,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
790801
g_pScriptVM->Call<short, short, int>(ge_func, nullptr, false, nullptr, userid, attacker, entindex);
791802
}
792803

793-
if (spewinfo)
804+
if (spewInfo)
794805
{
795806
P2MMLog(0, true, "userid: %i", userid);
796807
P2MMLog(0, true, "attacker: %i", attacker);
@@ -803,9 +814,9 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
803814
/*
804815
"userid" "short" // user ID on server
805816
*/
806-
else if (FStrEq(event->GetName(), "player_spawn"))
817+
if (FStrEq(event->GetName(), "player_spawn"))
807818
{
808-
short userid = event->GetInt("userid");
819+
int userid = event->GetInt("userid");
809820
int entindex = UserIDToPlayerIndex(userid);
810821

811822
if (g_pScriptVM)
@@ -816,7 +827,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
816827
g_pScriptVM->Call<short, int>(ge_func, nullptr, false, nullptr, userid, entindex);
817828
}
818829

819-
if (spewinfo)
830+
if (spewInfo)
820831
{
821832
P2MMLog(0, true, "userid: %i", userid);
822833
P2MMLog(0, true, "entindex: %i", entindex);
@@ -838,11 +849,11 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
838849
"bot" "bool" // player is a bot
839850
}
840851
*/
841-
else if (FStrEq(event->GetName(), "player_connect"))
852+
if (FStrEq(event->GetName(), "player_connect"))
842853
{
843854
const char* name = event->GetString("name");
844855
int index = event->GetInt("index");
845-
short userid = event->GetInt("userid");
856+
int userid = event->GetInt("userid");
846857
const char* xuid = std::to_string(event->GetUint64("xuid")).c_str();
847858
const char* networkid = event->GetString("networkid");
848859
const char* address = event->GetString("address");
@@ -860,7 +871,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
860871
}
861872
}
862873

863-
if (spewinfo)
874+
if (spewInfo)
864875
{
865876
P2MMLog(0, true, "name: %s", name);
866877
P2MMLog(0, true, "index: %i", index);
@@ -883,11 +894,11 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
883894
"networkid" "string" // player network (i.e steam) id
884895
"bot" "bool" // true if player is a AI bot
885896
*/
886-
else if (FStrEq(event->GetName(), "player_info"))
897+
if (FStrEq(event->GetName(), "player_info"))
887898
{
888899
const char* name = event->GetString("name");
889900
int index = event->GetInt("index");
890-
short userid = event->GetInt("userid");
901+
int userid = event->GetInt("userid");
891902
const char* networkid = event->GetString("networkid");
892903
const char* address = event->GetString("address");
893904
bool bot = event->GetBool("bot");
@@ -901,7 +912,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
901912
g_pScriptVM->Call<const char*, int, short, const char*, const char*, bool, int>(ge_func, nullptr, false, nullptr, name, index, userid, networkid, address, bot, entindex);
902913
}
903914

904-
if (spewinfo)
915+
if (spewInfo)
905916
{
906917
P2MMLog(0, true, "name: %s", name);
907918
P2MMLog(0, true, "index: %i", index);
@@ -919,9 +930,9 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
919930
"userid" "short" // user ID on server
920931
"text" "string" // the say text
921932
*/
922-
else if (FStrEq(event->GetName(), "player_say"))
933+
if (FStrEq(event->GetName(), "player_say"))
923934
{
924-
short userid = event->GetInt("userid");
935+
int userid = event->GetInt("userid");
925936
const char* text = event->GetString("text");
926937
int entindex = UserIDToPlayerIndex(userid);
927938

@@ -963,7 +974,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
963974
g_pScriptVM->Call<short, const char*, int>(ge_func, nullptr, false, nullptr, userid, text, entindex);
964975
}
965976

966-
if (spewinfo)
977+
if (spewInfo)
967978
{
968979
P2MMLog(0, true, "userid: %i", userid);
969980
P2MMLog(0, true, "text: %s", text);
@@ -972,8 +983,6 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
972983

973984
return;
974985
}
975-
976-
return;
977986
}
978987

979988
//---------------------------------------------------------------------------------
@@ -982,7 +991,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
982991
//---------------------------------------------------------------------------------
983992
void CP2MMServerPlugin::ClientActive(edict_t* pEntity)
984993
{
985-
short userid = engineServer->GetPlayerUserId(pEntity);
994+
int userid = engineServer->GetPlayerUserId(pEntity);
986995
int entindex = UserIDToPlayerIndex(userid);
987996

988997
if (p2mm_spewgameeventinfo.GetBool())

p2mm.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class CP2MMServerPlugin : public IServerPluginCallbacks, public IGameEventListen
5353

5454
virtual int GetCommandIndex() { return m_iClientCommandIndex; }
5555

56+
HWND m_hWnd;
57+
5658
bool m_bPluginLoaded;
5759
bool m_bPluginUnloading;
5860
int m_iCurGameIndex;

0 commit comments

Comments
 (0)