Skip to content

Commit da3eb4a

Browse files
committed
Changed all NULL's in place of pointer returns with nullptr, plus few other fixes.
1 parent 3650375 commit da3eb4a

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

discordrpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ unsigned SendWebHook(void* webhookParams)
138138
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonPayload);
139139

140140
// Set the Content-Type header
141-
struct curl_slist* headers = NULL;
141+
struct curl_slist* headers = nullptr;
142142
headers = curl_slist_append(headers, "Content-Type: application/json");
143143
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
144144

globals.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void P2MMLog(int level, bool dev, const char* pMsgFormat, ...)
4141
Warning(completeMsg);
4242
return;
4343
case 2:
44-
Warning("(P2:MM PLUGIN):\n!!!ERROR ERROR ERROR!!!:\nA ERROR OCCURED WITH THE ENGINE:\n%s", completeMsg);
44+
Warning("(P2:MM PLUGIN):\n!!!ERROR ERROR ERROR!!!:\nA FATAL ERROR OCCURED WITH THE ENGINE:\n%s", completeMsg);
4545
Error(completeMsg);
4646
return;
4747
default:
@@ -58,14 +58,14 @@ int UserIDToPlayerIndex(int userid)
5858
{
5959
for (int i = 1; i <= MAX_PLAYERS; i++)
6060
{
61-
edict_t* pEdict = NULL;
61+
edict_t* pEdict = nullptr;
6262
if (i >= 0 && i < g_pGlobals->maxEntities)
6363
pEdict = (edict_t*)(g_pGlobals->pEdicts + i);
6464

6565
if (engineServer->GetPlayerUserId(pEdict) == userid)
6666
return i;
6767
}
68-
return NULL; // Return NULL if the index can't be found
68+
return 0; // Return 0 if the index can't be found
6969
}
7070

7171
//---------------------------------------------------------------------------------
@@ -94,7 +94,7 @@ const char* GetPlayerName(int playerIndex)
9494
//---------------------------------------------------------------------------------
9595
int GetSteamID(int playerIndex)
9696
{
97-
edict_t* pEdict = NULL;
97+
edict_t* pEdict = nullptr;
9898
if (playerIndex >= 0 && playerIndex < MAX_PLAYERS)
9999
pEdict = (edict_t*)(g_pGlobals->pEdicts + playerIndex);
100100

@@ -221,10 +221,10 @@ HSCRIPT INDEXHANDLE(int iEdictNum)
221221
{
222222
edict_t* pEdict = INDEXENT(iEdictNum);
223223
if (!pEdict->GetUnknown())
224-
return NULL;
224+
return nullptr;
225225
CBaseEntity* pBaseEntity = pEdict->GetUnknown()->GetBaseEntity();
226226
if (!pBaseEntity)
227-
return NULL;
227+
return nullptr;
228228
HSCRIPT entityHandle = CBaseEntity__GetScriptInstance(pBaseEntity);
229229
return entityHandle;
230230
}

globals.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ class CBaseClient;
4444
#define COMMAND_COMPLETION_MAXITEMS 64
4545
#define COMMAND_COMPLETION_ITEM_LENGTH 64
4646

47-
// ClientPrint msg_dest macros.
48-
#define HUD_PRINTNOTIFY 1 // Works same as HUD_PRINTCONSOLE
49-
#define HUD_PRINTCONSOLE 2
50-
#define HUD_PRINTTALK 3
51-
#define HUD_PRINTCENTER 4
52-
5347
// A macro to iterate through all ConVars and ConCommand in the game.
5448
// Thanks to Nanoman2525 for this.
5549
#define FOR_ALL_CONSOLE_COMMANDS(pCommandVarName) \
@@ -82,6 +76,16 @@ enum
8276
DIVINITY
8377
};
8478

79+
// ClientPrint msg_dest macros.
80+
enum
81+
{
82+
HUD_PRINTNOTIFY = 1, // Works same as HUD_PRINTCONSOLE
83+
HUD_PRINTCONSOLE,
84+
HUD_PRINTTALK,
85+
HUD_PRINTCENTER
86+
};
87+
88+
8589
// Struct for map arrays.
8690
typedef struct
8791
{
@@ -109,9 +113,6 @@ extern IGameEventManager2* g_pGameEventManager_;
109113
extern IServerPluginHelpers* g_pPluginHelpers;
110114
extern IFileSystem* g_pFileSystem;
111115

112-
// Logging function.
113-
void P2MMLog(int level, bool dev, const char* pMsgFormat, ...);
114-
115116
//---------------------------------------------------------------------------------
116117
// UTIL functions.
117118
//---------------------------------------------------------------------------------
@@ -127,6 +128,9 @@ int GetBotCount();
127128
int CURPLAYERCOUNT();
128129
HSCRIPT INDEXHANDLE(int iEdictNum);
129130

131+
// Logging function.
132+
void P2MMLog(int level, bool dev, const char* pMsgFormat, ...);
133+
130134
//---------------------------------------------------------------------------------
131135
// Player recipient filter.
132136
//---------------------------------------------------------------------------------
@@ -201,10 +205,10 @@ inline edict_t* INDEXENT(int iEdictNum)
201205
{
202206
edict_t* pEdict = g_pGlobals->pEdicts + iEdictNum;
203207
if (pEdict->IsFree())
204-
return NULL;
208+
return nullptr;
205209
return pEdict;
206210
}
207-
return NULL;
211+
return nullptr;
208212
}
209213

210214
//---------------------------------------------------------------------------------

p2mm.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ extern ConVar p2mm_discord_webhooks;
2323
//---------------------------------------------------------------------------------
2424
// Interfaces from the engine
2525
//---------------------------------------------------------------------------------
26-
IVEngineServer* engineServer = NULL; // Access engine server functions (messaging clients, loading content, making entities, running commands, etc).
27-
IVEngineClient* engineClient = NULL; // Access engine client functions.
28-
CGlobalVars* g_pGlobals = NULL; // Access global variables shared between the engine and games dlls.
29-
IPlayerInfoManager* g_pPlayerInfoManager = NULL; // Access interface functions for players.
30-
IScriptVM* g_pScriptVM = NULL; // Access VScript interface.
31-
IServerTools* g_pServerTools = NULL; // Access to interface from engine to tools for manipulating entities.
32-
IGameEventManager2* g_pGameEventManager_ = NULL; // Access game events interface.
33-
IServerPluginHelpers* g_pPluginHelpers = NULL; // Access interface for plugin helper functions.
34-
IFileSystem* g_pFileSystem = NULL; // Access interface for Valve's file system interface.
26+
IVEngineServer* engineServer = nullptr; // Access engine server functions (messaging clients, loading content, making entities, running commands, etc).
27+
IVEngineClient* engineClient = nullptr; // Access engine client functions.
28+
CGlobalVars* g_pGlobals = nullptr; // Access global variables shared between the engine and games dlls.
29+
IPlayerInfoManager* g_pPlayerInfoManager = nullptr; // Access interface functions for players.
30+
IScriptVM* g_pScriptVM = nullptr; // Access VScript interface.
31+
IServerTools* g_pServerTools = nullptr; // Access to interface from engine to tools for manipulating entities.
32+
IGameEventManager2* g_pGameEventManager_ = nullptr; // Access game events interface.
33+
IServerPluginHelpers* g_pPluginHelpers = nullptr; // Access interface for plugin helper functions.
34+
IFileSystem* g_pFileSystem = nullptr; // Access interface for Valve's file system interface.
3535
#ifndef GAME_DLL
3636
#define g_pGameEventManager g_pGameEventManager_
3737
#endif
@@ -524,7 +524,7 @@ void CP2MMServerPlugin::LevelInit(char const* pMapName)
524524
#ifdef _WIN32
525525
reinterpret_cast<void(__cdecl*)(bool bDXChange)>(Memory::Scanner::Scan<void*>(ENGINEDLL, "55 8B EC 83 EC 14 53 33 DB 89"));
526526
#else
527-
NULL; // TODO: Linux & MacOS
527+
nullptr; // TODO: Linux
528528
#endif // _WIN32
529529
if (R_LoadWorldGeometry)
530530
{
@@ -570,15 +570,15 @@ PLUGIN_RESULT CP2MMServerPlugin::ClientCommand(edict_t* pEntity, const CCommand&
570570
P2MMLog(0, true, "userid: %i", userid);
571571
P2MMLog(0, true, "entindex: %i", entindex);
572572
P2MMLog(0, true, "playername: %s", playername);
573-
P2MMLog(0, true, "VScript VM Working?: %s", (g_pScriptVM != NULL) ? "Working" : "Not Working!");
573+
P2MMLog(0, true, "VScript VM Working?: %s", (g_pScriptVM) ? "Working" : "Not Working!");
574574
}
575575

576576
// Call the "GEClientCommand" VScript function
577577
if (g_pScriptVM)
578578
{
579579
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEClientCommand");
580580
if (ge_func)
581-
g_pScriptVM->Call<const char*, const char*, int, int, const char*>(ge_func, NULL, false, NULL, pCmd, fArgs, userid, entindex, playername);
581+
g_pScriptVM->Call<const char*, const char*, int, int, const char*>(ge_func, nullptr, false, nullptr, pCmd, fArgs, userid, entindex, playername);
582582
}
583583

584584
// signify is the client command used to make on screen icons appear
@@ -623,7 +623,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
623623
if (spewinfo)
624624
{
625625
P2MMLog(0, true, "Game Event Fired: %s", event->GetName());
626-
P2MMLog(0, true, "VScript VM Working?: %s", (g_pScriptVM != NULL) ? "Working" : "Not Working!");
626+
P2MMLog(0, true, "VScript VM Working?: %s", (g_pScriptVM) ? "Working" : "Not Working!");
627627
}
628628

629629
// Event called when a player pings, "portal_player_ping" returns:
@@ -646,7 +646,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
646646
// Handle VScript game event function
647647
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerPing");
648648
if (ge_func)
649-
g_pScriptVM->Call<short, float, float, float, int>(ge_func, NULL, false, NULL, userid, ping_x, ping_y, ping_z, entindex);
649+
g_pScriptVM->Call<short, float, float, float, int>(ge_func, nullptr, false, nullptr, userid, ping_x, ping_y, ping_z, entindex);
650650
}
651651

652652
if (spewinfo)
@@ -676,7 +676,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
676676
// Handle VScript game event function
677677
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerPortaled");
678678
if (ge_func)
679-
g_pScriptVM->Call<short, bool, int>(ge_func, NULL, false, NULL, userid, portal2, entindex);
679+
g_pScriptVM->Call<short, bool, int>(ge_func, nullptr, false, nullptr, userid, portal2, entindex);
680680
}
681681

682682
if (spewinfo)
@@ -696,7 +696,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
696696
// Handle VScript game event function
697697
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GETurretHitTurret");
698698
if (ge_func)
699-
g_pScriptVM->Call(ge_func, NULL, false, NULL);
699+
g_pScriptVM->Call(ge_func, nullptr, false, nullptr);
700700
}
701701

702702
return;
@@ -709,7 +709,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
709709
// Handle VScript game event function
710710
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GECamDetach");
711711
if (ge_func)
712-
g_pScriptVM->Call(ge_func, NULL, false, NULL);
712+
g_pScriptVM->Call(ge_func, nullptr, false, nullptr);
713713
}
714714

715715
return;
@@ -728,7 +728,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
728728
// Handle VScript game event function
729729
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerLanded");
730730
if (ge_func)
731-
g_pScriptVM->Call<short, int>(ge_func, NULL, false, NULL, userid, entindex);
731+
g_pScriptVM->Call<short, int>(ge_func, nullptr, false, nullptr, userid, entindex);
732732
}
733733

734734
return;
@@ -741,7 +741,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
741741
// Handle VScript game event function
742742
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSpawnBlue");
743743
if (ge_func)
744-
g_pScriptVM->Call(ge_func, NULL, false, NULL);
744+
g_pScriptVM->Call(ge_func, nullptr, false, nullptr);
745745
}
746746

747747
return;
@@ -754,7 +754,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
754754
// Handle VScript game event function
755755
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSpawnOrange");
756756
if (ge_func)
757-
g_pScriptVM->Call(ge_func, NULL, false, NULL);
757+
g_pScriptVM->Call(ge_func, nullptr, false, nullptr);
758758
}
759759

760760
return;
@@ -779,15 +779,15 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
779779
HSCRIPT playerHandle = INDEXHANDLE(entindex);
780780
if (playerHandle)
781781
{
782-
g_pScriptVM->Call<HSCRIPT>(od_func, NULL, false, NULL, playerHandle);
782+
g_pScriptVM->Call<HSCRIPT>(od_func, nullptr, false, nullptr, playerHandle);
783783
g_pDiscordIntegration->SendWebHookEmbed(std::string(GetPlayerName(entindex) + std::string(" Died!")), "", EMBEDCOLOR_PLAYERDEATH);
784784
}
785785
}
786786

787787
// Handle VScript game event function
788788
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerDeath");
789789
if (ge_func)
790-
g_pScriptVM->Call<short, short, int>(ge_func, NULL, false, NULL, userid, attacker, entindex);
790+
g_pScriptVM->Call<short, short, int>(ge_func, nullptr, false, nullptr, userid, attacker, entindex);
791791
}
792792

793793
if (spewinfo)
@@ -813,7 +813,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
813813
// Handle VScript game event function
814814
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSpawn");
815815
if (ge_func)
816-
g_pScriptVM->Call<short, int>(ge_func, NULL, false, NULL, userid, entindex);
816+
g_pScriptVM->Call<short, int>(ge_func, nullptr, false, nullptr, userid, entindex);
817817
}
818818

819819
if (spewinfo)
@@ -855,7 +855,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
855855
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerConnect");
856856
if (ge_func)
857857
{
858-
g_pScriptVM->Call<const char*, int, short, const char*, const char*, const char*, bool, int>(ge_func, NULL, false, NULL, name, index, userid, xuid, networkid, address, bot, entindex);
858+
g_pScriptVM->Call<const char*, int, short, const char*, const char*, const char*, bool, int>(ge_func, nullptr, false, nullptr, name, index, userid, xuid, networkid, address, bot, entindex);
859859
g_pDiscordIntegration->SendWebHookEmbed(std::string(name + std::string(" Joined!")), std::string(name + std::string(" joined the server!")));
860860
}
861861
}
@@ -898,7 +898,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
898898
// Handle VScript game event function
899899
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerInfo");
900900
if (ge_func)
901-
g_pScriptVM->Call<const char*, int, short, const char*, const char*, bool, int>(ge_func, NULL, false, NULL, name, index, userid, networkid, address, bot, entindex);
901+
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);
902902
}
903903

904904
if (spewinfo)
@@ -927,13 +927,13 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
927927

928928
if (g_pScriptVM)
929929
{
930-
if (entindex != NULL)
930+
if (entindex)
931931
{
932932
// Handling chat commands
933933
HSCRIPT cc_func = g_pScriptVM->LookupFunction("ChatCommands");
934934
if (cc_func)
935935
{
936-
g_pScriptVM->Call<const char*, int>(cc_func, NULL, false, NULL, text, entindex);
936+
g_pScriptVM->Call<const char*, int>(cc_func, nullptr, false, nullptr, text, entindex);
937937

938938
std::string playerName = GetPlayerName(entindex);
939939
std::string chatMsg = text;
@@ -960,7 +960,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
960960
// Handle VScript game event function
961961
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSay");
962962
if (ge_func)
963-
g_pScriptVM->Call<short, const char*, int>(ge_func, NULL, false, NULL, userid, text, entindex);
963+
g_pScriptVM->Call<short, const char*, int>(ge_func, nullptr, false, nullptr, userid, text, entindex);
964964
}
965965

966966
if (spewinfo)
@@ -1011,13 +1011,13 @@ void CP2MMServerPlugin::ClientActive(edict_t* pEntity)
10111011
{
10121012
HSCRIPT playerHandle = INDEXHANDLE(entindex);
10131013
if (playerHandle)
1014-
g_pScriptVM->Call<HSCRIPT>(opj_func, NULL, false, NULL, playerHandle);
1014+
g_pScriptVM->Call<HSCRIPT>(opj_func, nullptr, false, nullptr, playerHandle);
10151015
}
10161016

10171017
// Handle VScript game event function
10181018
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEClientActive");
10191019
if (ge_func)
1020-
g_pScriptVM->Call<short, int>(ge_func, NULL, false, NULL, userid, entindex);
1020+
g_pScriptVM->Call<short, int>(ge_func, nullptr, false, nullptr, userid, entindex);
10211021
}
10221022

10231023
// Update Discord RPC to update player count.
@@ -1032,12 +1032,12 @@ void CP2MMServerPlugin::GameFrame(bool simulating)
10321032
{
10331033
HSCRIPT loop_func = g_pScriptVM->LookupFunction("P2MMLoop");
10341034
if (loop_func && p2mm_loop.GetBool())
1035-
g_pScriptVM->Call(loop_func, NULL, false, NULL);
1035+
g_pScriptVM->Call(loop_func, nullptr, false, nullptr);
10361036

10371037
// Handle VScript game event function
10381038
HSCRIPT gf_func = g_pScriptVM->LookupFunction("GEGameFrame");
10391039
if (gf_func)
1040-
g_pScriptVM->Call<bool>(gf_func, NULL, false, NULL, simulating);
1040+
g_pScriptVM->Call<bool>(gf_func, nullptr, false, nullptr, simulating);
10411041
}
10421042

10431043
extern void updateMapsList();

sdk.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ void __cdecl respawn_hook(CBaseEntity* pEdict, bool fCopyCorpse)
9090
// Handling OnRespawn VScript event
9191
HSCRIPT or_func = g_pScriptVM->LookupFunction("OnRespawn");
9292
if (or_func)
93-
g_pScriptVM->Call<HSCRIPT>(or_func, NULL, false, NULL, INDEXHANDLE(ENTINDEX(pEdict)));
93+
g_pScriptVM->Call<HSCRIPT>(or_func, nullptr, false, nullptr, INDEXHANDLE(ENTINDEX(pEdict)));
9494

9595
// Handle VScript game event function
9696
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerRespawn");
9797
if (ge_func)
98-
g_pScriptVM->Call<HSCRIPT>(ge_func, NULL, false, NULL, INDEXHANDLE(ENTINDEX(pEdict)));
98+
g_pScriptVM->Call<HSCRIPT>(ge_func, nullptr, false, nullptr, INDEXHANDLE(ENTINDEX(pEdict)));
9999
}
100100
}
101101

@@ -104,7 +104,7 @@ CBasePlayer* (__cdecl* UTIL_GetLocalPlayer_orig)();
104104
CBasePlayer* __cdecl UTIL_GetLocalPlayer()
105105
{
106106
if (engineServer->IsDedicatedServer())
107-
return NULL;
107+
return nullptr;
108108
return UTIL_GetLocalPlayer_orig();
109109
}
110110

@@ -120,7 +120,7 @@ CBasePlayer* UTIL_PlayerByIndex(int playerIndex)
120120
static auto _PlayerByIndex = reinterpret_cast<CBasePlayer* (__cdecl*)(int)>(Memory::Scanner::Scan<void*>(SERVERDLL, "55 8B EC 8B 4D 08 33 C0 85 C9 7E 30"));
121121
return _PlayerByIndex(playerIndex);
122122
#else // Linux support TODO
123-
return NULL;
123+
return nullptr;
124124
#endif
125125
}
126126

@@ -185,8 +185,8 @@ int CBaseEntity__GetTeamNumber(CBasePlayer* pPlayer)
185185
//---------------------------------------------------------------------------------
186186
HSCRIPT CBaseEntity__GetScriptScope(CBaseEntity* entity)
187187
{
188-
if (entity == NULL)
189-
return NULL;
188+
if (!entity)
189+
return nullptr;
190190

191191
return *reinterpret_cast<HSCRIPT*>(reinterpret_cast<uintptr_t>(entity) + 0x33c);
192192
}

0 commit comments

Comments
 (0)