Skip to content

Commit e5c0c84

Browse files
committed
Minor clean up of some code. Small removals, small adds.
1 parent 977207a commit e5c0c84

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

commands.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ CON_COMMAND_F_COMPLETION(p2mm_map, "Starts up a P2:MM session with a requested m
129129

130130
// Get the current act so we can start the right main menu music.
131131
int iAct = ConVarRef("ui_lastact_played").GetInt();
132-
if (iAct > 5) iAct = 5;
133-
else if (iAct < 1) iAct = 1;
132+
if (iAct > 5)
133+
iAct = 5;
134+
else if (iAct < 1)
135+
iAct = 1;
134136

135137
// Put the command to start the music and the act number together.
136138
char completePvCmd[sizeof("playvol \"#music/mainmenu/portal2_background0%d\" 0.35") + sizeof(iAct)] = { 0 };
@@ -142,6 +144,7 @@ CON_COMMAND_F_COMPLETION(p2mm_map, "Starts up a P2:MM session with a requested m
142144
UpdateMapsList();
143145
return;
144146
}
147+
145148
V_strcpy(requestedMap, p2mm_lastmap.GetString());
146149
Log(INFO, true, "P2MM_LASTMAP called! Running Last Map: \"%s\"", requestedMap);
147150
}
@@ -204,13 +207,13 @@ CON_COMMAND(p2mm_respawnall, "Respawns all players.")
204207
}
205208
}
206209

207-
static bool m_ConVarConCommandsShown = false; // Bool to track if the hidden ConVars and ConCommands are showing.
210+
static bool cvccShown = false; // Bool to track if the hidden ConVars and ConCommands are showing.
208211
static std::vector<ConCommandBase*> toggledCVCCs; // List of toggled ConVars and ConCommands with the FCVAR_DEVELOPMENTONLY and FCVAR_HIDDEN ConVar flags removed.
209212
CON_COMMAND_F(p2mm_toggle_dev_cc_cvars, "Toggle showing any ConVars and ConCommands that have the FCVAR_DEVELOPMENTONLY and FCVAR_HIDDEN ConVar flags.", FCVAR_HIDDEN)
210213
{
211214
int iToggleCount = 0; // To tell the user how many ConVars and ConCommands where toggle to show or hide.
212215

213-
if (m_ConVarConCommandsShown)
216+
if (cvccShown)
214217
{
215218
// Hide the ConVars and ConCommands
216219
for (ConCommandBase* pCommandVarName : toggledCVCCs)
@@ -219,11 +222,11 @@ CON_COMMAND_F(p2mm_toggle_dev_cc_cvars, "Toggle showing any ConVars and ConComma
219222
iToggleCount++;
220223
}
221224
toggledCVCCs.clear();
222-
m_ConVarConCommandsShown = false;
225+
cvccShown = false;
223226
}
224227
else
225228
{
226-
// Unhide the ConVars and ConCommands
229+
// Remove development and hidden flags from the ConVars and ConCommands
227230
FOR_ALL_CONSOLE_COMMANDS(pCommandVarName)
228231
{
229232
if (pCommandVarName->IsFlagSet(FCVAR_DEVELOPMENTONLY) || pCommandVarName->IsFlagSet(FCVAR_HIDDEN))
@@ -233,10 +236,10 @@ CON_COMMAND_F(p2mm_toggle_dev_cc_cvars, "Toggle showing any ConVars and ConComma
233236
toggledCVCCs.push_back(pCommandVarName);
234237
}
235238
}
236-
m_ConVarConCommandsShown = true;
239+
cvccShown = true;
237240
}
238241

239-
Log(INFO, false, "%s %i ConVars/ConCommands!", m_ConVarConCommandsShown ? "Unhid" : "Hid", iToggleCount);
242+
Log(INFO, false, "%s %i ConVars/ConCommands!", cvccShown ? "Unhid" : "Hid", iToggleCount);
240243
}
241244

242245
//---------------------------------------------------------------------------------

globals.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum : std::uint8_t
7474
};
7575

7676
// iCurGameIndex enum.
77-
enum : std::uint8_t
77+
inline enum GameIndexes : std::uint8_t
7878
{
7979
PORTAL_2 = 0,
8080
PORTAL_STORIES_MEL,
@@ -83,7 +83,7 @@ enum : std::uint8_t
8383
INFRA,
8484
STANLEY_PARABLE,
8585
DIVINITY
86-
};
86+
} GameIndex;
8787

8888
// ClientPrint msg_dest macros.
8989
enum : std::uint8_t
@@ -224,7 +224,7 @@ inline edict_t* INDEXENT(const int iEdictNum)
224224
}
225225

226226
//---------------------------------------------------------------------------------
227-
// Purpose: VScript instance to void*. void* because we can not assume that the returned instance is a CBaseEntity* because VScript instances can be
227+
// Purpose: VScript instance to void*. void* because we can not assume that the returned instance is a CBaseEntity* because VScript instances can be a different class type.
228228
//---------------------------------------------------------------------------------
229229
inline void* HSCRIPTENT(const HSCRIPT ent)
230230
{

p2mm.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CP2MMServerPlugin::CP2MMServerPlugin()
138138
//---------------------------------------------------------------------------------
139139
CP2MMServerPlugin::~CP2MMServerPlugin()
140140
{
141-
m_nDebugID = EVENT_DEBUG_ID_SHUTDOWN;
141+
this->m_nDebugID = EVENT_DEBUG_ID_SHUTDOWN;
142142
}
143143

144144
//---------------------------------------------------------------------------------
@@ -164,9 +164,10 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
164164

165165
Log(INFO, false, "Loading plugin...");
166166

167+
Log(INFO, true, "Grabbing game window handle...");
167168
this->m_hWnd = FindWindow("Valve001", nullptr);
168169
if (!this->m_hWnd)
169-
Log(WARNING, false, "Failed to find game window Valve001!");
170+
Log(WARNING, false, "Failed to find game window!");
170171

171172
// Determine which Portal 2 branch game we are running and if its supported.
172173
// TODO: Rework this to be a switch case then if and else if statements.
@@ -209,6 +210,7 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
209210
// // Unsupported...
210211
// unsupportedGame = true;
211212
// }
213+
// Have to find "Divinity" in the gameMainDir string as it's a big folder path due to being a SourceMod.
212214
else if ((std::strstr(gameMainDir, "Divinity")))
213215
{
214216
this->m_iCurGameIndex = DIVINITY;
@@ -229,7 +231,8 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
229231
}
230232
if (unsupportedGame && CommandLine()->FindParm("-forcep2mmload"))
231233
{
232-
MessageBox(this->m_hWnd, "P2:MM is being run with a unsupported Source Engine/Portal 2 branch game!\n\"-forcep2mmload\" has been specified to stop the plugin shutting down the game.\nProceed with caution as crashes and bugs could occur!", "Unsupported P2:MM Game", MB_OK | MB_ICONEXCLAMATION);
234+
if (this->m_hWnd)
235+
MessageBox(this->m_hWnd, "P2:MM is being run with a unsupported Source Engine/Portal 2 branch game!\n\"-forcep2mmload\" has been specified to stop the plugin shutting down the game.\nProceed with caution as crashes and bugs could occur!", "Unsupported P2:MM Game", MB_OK | MB_ICONEXCLAMATION);
233236
Log(WARNING, false, R"(P2:MM is being run with a unsupported Source Engine/Portal 2 branch game! "-forcep2mmload" has been specified to stop the plugin shutting down the game. Proceed with caution as crashes and bugs could occur!)");
234237
}
235238

@@ -415,13 +418,14 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
415418
// NoSteamLogon disconnect hook patch.
416419
Log(INFO, true, "Hooking CSteam3Server::OnGSClientDenyHelper...");
417420
MH_CreateHook(
418-
(LPVOID)Memory::Scanner::Scan<void*>(ENGINEDLL, "55 8B EC 83 EC 08 53 56 57 8B F1 E8 ?? ?? ?? ?? 8B"),
421+
Memory::Scanner::Scan<void*>(ENGINEDLL, "55 8B EC 83 EC 08 53 56 57 8B F1 E8 ?? ?? ?? ?? 8B"),
419422
&CSteam3Server__OnGSClientDenyHelper_hook, reinterpret_cast<void**>(&CSteam3Server__OnGSClientDenyHelper_orig)
420423
);
421424

422-
// For p2mm_instantrespawn.
425+
423426
if (!this->m_bP2SMPluginLoaded)
424427
{
428+
// For p2mm_instantrespawn.
425429
Log(INFO, true, "Hooking CPortal_Player::PlayerDeathThink...");
426430
MH_CreateHook(
427431
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"),
@@ -474,10 +478,11 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
474478

475479
Log(INFO, true, "Enabling hooks...");
476480
MH_EnableHook(MH_ALL_HOOKS);
477-
} catch (const std::exception& ex)
481+
}
482+
catch (const std::exception& ex)
478483
{
479484
assert(0 && "Failed to implement patch or hook!");
480-
Log(INFO, false, R"(Failed to load plugin! :( Exception: "%s")", ex.what());
485+
Log(WARNING, false, R"(Failed to load plugin! :( Exception: "%s")", ex.what());
481486
this->m_bNoUnload = true;
482487
return false;
483488
}
@@ -524,7 +529,7 @@ void CP2MMServerPlugin::Unload(void)
524529
CommandLine()->RemoveParm("-allowspectators");
525530
}
526531

527-
Log(INFO, true, "Unregistering ConVars...");
532+
Log(INFO, true, "Unregistering ConVars/ConCommands...");
528533
ConVar_Unregister();
529534

530535
Log(INFO, true, "Disconnecting tier libraries...");
@@ -539,7 +544,7 @@ void CP2MMServerPlugin::Unload(void)
539544
// Linked portal doors event crash patch
540545
if (!this->m_bP2SMPluginLoaded)
541546
{
542-
Log(INFO, true, "Unfixing linked portal doors...");
547+
Log(INFO, true, "Un-patching linked portal doors...");
543548
Memory::ReplacePattern("server", "EB 14 87 04 05 00 00 8B 16", "0F B6 87 04 05 00 00 8B 16");
544549
}
545550

@@ -573,7 +578,7 @@ void CP2MMServerPlugin::Unload(void)
573578
catch (const std::exception& ex)
574579
{
575580
assert(0 && "Failed to fully unload!");
576-
Log(INFO, false, R"(Encountered error when unload plugin! :( Exception: "%s")", ex.what());
581+
Log(WARNING, false, R"(Encountered error when unload plugin! :( Exception: "%s")", ex.what());
577582
Log(ERRORR, false, "P2:MM failed to unload!\nGame has to be shutdown as possibly some other patches/hooks are still connected which can cause issues!");
578583
}
579584

0 commit comments

Comments
 (0)