Skip to content

Commit 88a5532

Browse files
committed
Added g_pGlobals and IPlayerInfoManager as available interfaces to load for the plugin
1 parent 0aaea2d commit 88a5532

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
IVEngineServer* engineServer = nullptr;
1919
IVEngineClient* engineClient = nullptr;
2020
CGlobalVars* g_pGlobals = nullptr;
21-
//IPlayerInfoManager* g_pPlayerInfoManager = nullptr;
21+
IPlayerInfoManager* g_pPlayerInfoManager = nullptr;
2222
// IScriptVM* g_pScriptVM;
2323
//IServerTools* g_pServerTools = nullptr;
2424
// IGameEventManager2* g_pGameEventManager_;

globals.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "cdll_int.h"
1212
#include "vscript/ivscript.h"
1313
#include "engine/iserverplugin.h"
14+
#include "game/server/iplayerinfo.h"
1415
#include "public/steam/steamclientpublic.h"
1516
#include "irecipientfilter.h"
1617

@@ -85,7 +86,7 @@ static HWND hWnd;
8586
extern IVEngineServer* engineServer;
8687
extern IVEngineClient* engineClient;
8788
extern CGlobalVars* g_pGlobals;
88-
// extern IPlayerInfoManager* g_pPlayerInfoManager;
89+
extern IPlayerInfoManager* g_pPlayerInfoManager;
8990
// extern IScriptVM* g_pScriptVM;
9091
// extern IServerTools* g_pServerTools;
9192
// extern IGameEventManager2* g_pGameEventManager_;

p2sm.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,41 +81,74 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
8181
Log(WARNING, false, "Failed to find game window!");
8282

8383
Log(INFO, true, "Connecting tier libraries...");
84+
MathLib_Init(2.2f, 2.2f, 0.0f, 2.0f);
8485
ConnectTier1Libraries(&interfaceFactory, 1);
8586
ConnectTier2Libraries(&interfaceFactory, 1);
87+
88+
Log(INFO, true, "Registering plugin ConVars and ConCommands...");
8689
ConVar_Register(0);
8790

91+
// Make sure that all the interfaces needed are loaded and usable.
8892
Log(INFO, true, "Loading interfaces...");
93+
Log(INFO, true, "Loading engineServer...");
8994
engineServer = static_cast<IVEngineServer*>(interfaceFactory(INTERFACEVERSION_VENGINESERVER, 0));
9095
if (!engineServer)
9196
{
97+
assert(0 && "Unable to load engineServer!");
9298
Log(WARNING, false, "Unable to load engineServer!");
9399
this->m_bNoUnload = true;
94100
return false;
95101
}
96102

103+
Log(INFO, true, "Loading engineClient...");
97104
engineClient = static_cast<IVEngineClient*>(interfaceFactory(VENGINE_CLIENT_INTERFACE_VERSION, 0));
98105
if (!engineClient)
99106
{
107+
assert(0 && "Unable to load engineClient!");
100108
Log(WARNING, false, "Unable to load engineClient!");
101109
this->m_bNoUnload = true;
102110
return false;
103111
}
104112

113+
Log(INFO, true, "Loading g_pPlayerInfoManager...");
114+
g_pPlayerInfoManager = static_cast<IPlayerInfoManager*>(gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, 0));
115+
if (!g_pPlayerInfoManager)
116+
{
117+
assert(0 && "Unable to load g_pPlayerInfoManager!");
118+
Log(WARNING, false, "Unable to load g_pPlayerInfoManager!");
119+
this->m_bNoUnload = true;
120+
return false;
121+
}
122+
123+
Log(INFO, true, "Loading g_pGlobals...");
124+
g_pGlobals = g_pPlayerInfoManager->GetGlobalVars();
125+
if (!g_pGlobals)
126+
{
127+
assert(0 && "Unable to load g_pGlobals!");
128+
Log(WARNING, false, "Unable to load g_pGlobals!");
129+
this->m_bNoUnload = true;
130+
return false;
131+
}
132+
133+
Log(INFO, true, "Updating/Fixing game ConVars and ConCommands...");
134+
105135
// cl_localnetworkbackdoor is causing NPCs to not move correctly thanks to Valve networking "optimizations".
106136
// Turn it off, nothing else should turn it back automatically while in game.
137+
Log(INFO, true, "cl_localnetworkbackdoor...");
107138
if (ConVar* lnbCVar = g_pCVar->FindVar("cl_localnetworkbackdoor"))
108139
lnbCVar->SetValue(0);
109-
140+
110141
// Remove the cheat flag on r_drawscreenoverlay and enable it by default to allow maps to easily display screen overlays.
142+
Log(INFO, true, "r_drawscreenoverlay...");
111143
if (ConVar* screenCVar = g_pCVar->FindVar("r_drawscreenoverlay"))
112144
{
113145
screenCVar->RemoveFlags(FCVAR_CHEAT);
114146
screenCVar->SetValue(1);
115147
}
116-
148+
117149
// Make switching between players in splitscreen when testing easier by removing
118150
// the need for cheats to change the current player under control.
151+
Log(INFO, true, "in_forceuser...");
119152
if (ConVar* ifuCVar = g_pCVar->FindVar("in_forceuser"))
120153
ifuCVar->RemoveFlags(FCVAR_CHEAT);
121154

@@ -163,9 +196,9 @@ void CP2SMPlusPlusPlugin::Unload(void)
163196

164197
Log(INFO, false, "Unloading Plugin...");
165198

166-
Log(INFO, true, "Disconnecting hooked functions and un-initializing MinHook...");
167-
MH_DisableHook(MH_ALL_HOOKS);
168-
MH_Uninitialize();
199+
Log(INFO, true, "Disconnecting tier libraries...");
200+
DisconnectTier2Libraries();
201+
DisconnectTier1Libraries();
169202

170203
m_bPluginLoaded = false;
171204
Log(INFO, false, "Plugin unloaded! Goodbye!");

0 commit comments

Comments
 (0)