Skip to content

Commit d7b6c8b

Browse files
committed
fix: Updated function declarations to use newer ones and added destructor
1 parent 8b99304 commit d7b6c8b

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

src/p2sm.cpp

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@
1414
#include "globals.hpp"
1515
#include "patch-hook.hpp"
1616

17-
//---------------------------------------------------------------------------------
18-
// The plugin is a static singleton that is exported as an interface
19-
//---------------------------------------------------------------------------------
20-
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CP2SMPlusPlusPlugin, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_P2SMPlusPlusPlugin);
21-
22-
//---------------------------------------------------------------------------------
23-
// Purpose: constructor
24-
//---------------------------------------------------------------------------------
17+
/**
18+
* @brief The plugin is a static singleton that is exported as an interface. Max plugin interface version Portal 2 uses is 3.
19+
*/
20+
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CP2SMPlusPlusPlugin, IServerPluginCallbacks, "ISERVERPLUGINCALLBACKS003", g_P2SMPlusPlusPlugin);
21+
22+
/**
23+
* @brief Constructor
24+
*/
2525
CP2SMPlusPlusPlugin::CP2SMPlusPlusPlugin()
2626
{
27-
this->m_bPluginLoaded = false;
28-
this->m_bNoUnload = false; // If we fail to load, we don't want to run anything on Unload() to get what the error was.
27+
this->pluginLoaded = false;
28+
this->noUnload = false; // If we fail to load, we don't want to run anything on Unload() to get what the error was.
29+
30+
this->clientCommandIndex = 0;
31+
this->debugID = EVENT_DEBUG_ID_INIT;
32+
}
33+
34+
/**
35+
* @brief Destructor
36+
*/
37+
CP2SMPlusPlusPlugin::~CP2SMPlusPlusPlugin()
38+
{
39+
this->debugID = EVENT_DEBUG_ID_SHUTDOWN;
2940
}
3041

3142
//---------------------------------------------------------------------------------
3243
// Purpose: Description of plugin outputted when the "plugin_print" console command is executed.
3344
//---------------------------------------------------------------------------------
34-
const char* CP2SMPlusPlusPlugin::GetPluginDescription(void)
45+
const char* CP2SMPlusPlusPlugin::GetPluginDescription()
3546
{
3647
return "P2SourceModPlusPlus Plugin | Plugin Version: " P2SMPLUSPLUS_PLUGIN_VERSION;
3748
}
@@ -40,12 +51,12 @@ const char* CP2SMPlusPlusPlugin::GetPluginDescription(void)
4051
// Purpose: Called when the plugin is loaded, initialization process.
4152
// Loads the interfaces we need from the engine and applies our patches.
4253
//---------------------------------------------------------------------------------
43-
bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInterfaceFn gameServerFactory)
54+
bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
4455
{
45-
if (m_bPluginLoaded)
56+
if (pluginLoaded)
4657
{
4758
Log(WARNING, false, "Already loaded!");
48-
m_bNoUnload = true;
59+
noUnload = true;
4960
return false;
5061
}
5162

@@ -85,7 +96,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
8596
{
8697
assert(false && "Unable to load engineServer!");
8798
Log(WARNING, false, "Unable to load engineServer!");
88-
this->m_bNoUnload = true;
99+
this->noUnload = true;
89100
return false;
90101
}
91102

@@ -95,7 +106,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
95106
{
96107
assert(false && "Unable to load engineClient!");
97108
Log(WARNING, false, "Unable to load engineClient!");
98-
this->m_bNoUnload = true;
109+
this->noUnload = true;
99110
return false;
100111
}
101112

@@ -105,7 +116,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
105116
{
106117
assert(false && "Unable to load g_pPlayerInfoManager!");
107118
Log(WARNING, false, "Unable to load g_pPlayerInfoManager!");
108-
this->m_bNoUnload = true;
119+
this->noUnload = true;
109120
return false;
110121
}
111122

@@ -115,7 +126,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
115126
{
116127
assert(false && "Unable to load g_pGlobals!");
117128
Log(WARNING, false, "Unable to load g_pGlobals!");
118-
this->m_bNoUnload = true;
129+
this->noUnload = true;
119130
return false;
120131
}
121132

@@ -127,7 +138,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
127138

128139
if (!Patches::EnablePatches())
129140
{
130-
this->m_bNoUnload = true;
141+
this->noUnload = true;
131142
throw std::runtime_error("Failed to enable patches!");
132143
}
133144

@@ -142,7 +153,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
142153
} catch (const std::exception& ex) {
143154
Log(INFO, false, "Failed to perform patch and hook operations! :( Exception: \"%s\"", ex.what());
144155
assert(false && "Patch and hook failure!");
145-
this->m_bNoUnload = true;
156+
this->noUnload = true;
146157
return false;
147158
}
148159

@@ -169,20 +180,20 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateI
169180
ifuCVar->RemoveFlags(FCVAR_CHEAT);
170181

171182
Log(INFO, false, "Loaded plugin! Yay! :D");
172-
m_bPluginLoaded = true;
183+
pluginLoaded = true;
173184

174185
return true;
175186
}
176187

177188
//---------------------------------------------------------------------------------
178189
// Purpose: Called when the plugin is turning off/unloading.
179190
//---------------------------------------------------------------------------------
180-
void CP2SMPlusPlusPlugin::Unload(void)
191+
void CP2SMPlusPlusPlugin::Unload()
181192
{
182193
// If the plugin errors for some reason, prevent it from unloading.
183-
if (m_bNoUnload)
194+
if (noUnload)
184195
{
185-
m_bNoUnload = false;
196+
noUnload = false;
186197
Log(WARNING, true, "Failed to load plugin!");
187198
MessageBox(GeneralGUI::GetWindowHandle(), "P2SM++ ran into a error when starting!\nPlease check the console for more info!", "P2SM++ Startup Error", MB_OK | MB_ICONERROR);
188199
return;
@@ -241,14 +252,14 @@ void CP2SMPlusPlusPlugin::Unload(void)
241252
DisconnectTier2Libraries();
242253
DisconnectTier1Libraries();
243254

244-
m_bPluginLoaded = false;
255+
pluginLoaded = false;
245256
Log(INFO, false, "Plugin unloaded! Goodbye!");
246257
}
247258

248-
void CP2SMPlusPlusPlugin::ClientFullyConnect(Edict* pEntity)
259+
void CP2SMPlusPlusPlugin::ClientFullyConnect(Edict* edict)
249260
{
250261
// Make sure the r_drawscreenoverlay ConVar is enabled for connecting clients.
251-
engineServer->ClientCommand(pEntity, "r_drawscreenoverlay 1");
262+
engineServer->ClientCommand(edict, "r_drawscreenoverlay 1");
252263
Log(WARNING, true, "r_drawscreenoverlay enabled for client.");
253264
}
254265

src/p2sm.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CP2SMPlusPlusPlugin : public IServerPluginCallbacks, public IGameEventList
2323
{
2424
public:
2525
CP2SMPlusPlusPlugin();
26-
virtual ~CP2SMPlusPlusPlugin() = default;
26+
~CP2SMPlusPlusPlugin() override;
2727

2828
bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) override;
2929
void Unload() override;
@@ -49,17 +49,17 @@ class CP2SMPlusPlusPlugin : public IServerPluginCallbacks, public IGameEventList
4949

5050
// IGameEventListener2 methods
5151
virtual void FireGameEvent(IGameEvent* event);
52-
virtual int GetEventDebugID(void) { return m_nDebugID; }
52+
virtual int GetEventDebugID(void) { return debugID; }
5353

54-
virtual int GetCommandIndex() { return m_iClientCommandIndex; }
54+
virtual int GetCommandIndex() { return clientCommandIndex; }
5555

5656
private:
5757
// Plugin state member variables.
58-
bool m_bPluginLoaded;
59-
bool m_bNoUnload;
58+
bool pluginLoaded;
59+
bool noUnload;
6060

61-
int m_nDebugID;
62-
int m_iClientCommandIndex;
61+
int debugID;
62+
int clientCommandIndex;
6363
};
6464

6565
static CP2SMPlusPlusPlugin g_P2SMPlusPlusPlugin;

0 commit comments

Comments
 (0)