Skip to content

Commit 0348de4

Browse files
committed
Moved where g_pScriptVM is loaded and removed FirstRunState
1 parent e7f7074 commit 0348de4

File tree

4 files changed

+21
-36
lines changed

4 files changed

+21
-36
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ void SendToChat(const char* msg, int playerIndex); | "Sends
2727
const char* GetGameMainDir(); | "Returns the current game directory. Ex. portal2"
2828
const char* GetGameRootDir(); | "Returns the current root game directory. Ex. Portal 2"
2929
const char* GetLastMap(); | "Returns the last map recorded by the Last Map system."
30-
bool FirstRunState(); | "Get or set the state of whether the first map was run or not. Set false/true = 0/1 | -1 to get state."
3130
void CallFirstRunPrompt(); | "Shows the first run prompt if enabled in config.nut."
3231
int GetConVarInt(const char* cvName); | "Get the integer value of a ConVar."
3332
const char* GetConVarString(const char* cvName); | "Get the string value of a ConVar."

p2mm.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,6 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
269269
return false;
270270
}
271271

272-
Log(INFO, true, "Loading g_pScriptVM...");
273-
g_pScriptVM = static_cast<IScriptVM*>(interfaceFactory(VSCRIPT_INTERFACE_VERSION, 0));
274-
if (!g_pScriptVM)
275-
{
276-
assert(0 && "Unable to load g_pScriptVM!");
277-
Log(WARNING, false, "Unable to load g_pScriptVM!");
278-
this->m_bNoUnload = true;
279-
return false;
280-
}
281-
282272
Log(INFO, true, "Loading g_pServerTools...");
283273
g_pServerTools = static_cast<IServerTools*>(gameServerFactory(VSERVERTOOLS_INTERFACE_VERSION, 0));
284274
if (!g_pServerTools)
@@ -603,6 +593,8 @@ void CP2MMServerPlugin::SetCommandClient(const int index)
603593
void RegisterFuncsAndRun();
604594
void CP2MMServerPlugin::ServerActivate(edict_t* pEdictList, int edictCount, int clientMax)
605595
{
596+
Log(INFO, true, "edictCount: %i", edictCount);
597+
Log(INFO, true, "clientMax: %i", clientMax);
606598
RegisterFuncsAndRun();
607599
}
608600

@@ -1063,38 +1055,38 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
10631055
//---------------------------------------------------------------------------------
10641056
void CP2MMServerPlugin::ClientActive(edict_t* pEntity)
10651057
{
1066-
int userid = engineServer->GetPlayerUserId(pEntity);
1067-
int entindex = UserIDToPlayerIndex(userid);
1058+
const int userID = engineServer->GetPlayerUserId(pEntity);
1059+
const int entIndex = UserIDToPlayerIndex(userID);
10681060

10691061
if (p2mm_spew_gameevent_info.GetBool())
10701062
{
10711063
Log(INFO, true, "ClientActive Called!");
1072-
Log(INFO, true, "userid: %i", userid);
1073-
Log(INFO, true, "entindex: %i", entindex);
1064+
Log(INFO, true, "userid: %i", userID);
1065+
Log(INFO, true, "entindex: %i", entIndex);
10741066
}
10751067

10761068
// Make sure people know that the chat is being recorded if webhook is set
10771069
if (p2mm_discord_webhooks.GetBool())
10781070
{
1079-
if (CBasePlayer* pPlayer = UTIL_PlayerByIndex(entindex))
1071+
if (CBasePlayer* pPlayer = UTIL_PlayerByIndex(entIndex))
10801072
{
1081-
Log(INFO, true, "Warning for enabled webhooks sent to player index %i.", entindex);
1073+
Log(INFO, true, "Warning for enabled webhooks sent to player index %i.", entIndex);
10821074
UTIL_ClientPrint(pPlayer, HUD_PRINTTALK, "This lobby has Discord Webhook Integration enabled. All of your in-game messages may be sent to a Discord channel.");
10831075
}
10841076
}
10851077

10861078
if (g_pScriptVM)
10871079
{
10881080
// Handling OnPlayerJoin VScript event
1089-
if (HSCRIPT opj_func = g_pScriptVM->LookupFunction("OnPlayerJoin"))
1081+
if (const HSCRIPT opjFunc = g_pScriptVM->LookupFunction("OnPlayerJoin"))
10901082
{
1091-
if (HSCRIPT playerHandle = INDEXHANDLE(entindex))
1092-
g_pScriptVM->Call<HSCRIPT>(opj_func, nullptr, false, nullptr, playerHandle);
1083+
if (const HSCRIPT playerHandle = INDEXHANDLE(entIndex))
1084+
g_pScriptVM->Call<HSCRIPT>(opjFunc, nullptr, false, nullptr, playerHandle);
10931085
}
10941086

10951087
// Handle VScript game event function
1096-
if (HSCRIPT geFunc = g_pScriptVM->LookupFunction("GEClientActive"))
1097-
g_pScriptVM->Call<int, int>(geFunc, nullptr, false, nullptr, userid, entindex);
1088+
if (const HSCRIPT geFunc = g_pScriptVM->LookupFunction("GEClientActive"))
1089+
g_pScriptVM->Call<int, int>(geFunc, nullptr, false, nullptr, userID, entIndex);
10981090
}
10991091

11001092
// Update Discord RPC to update player count.
@@ -1175,6 +1167,7 @@ PLUGIN_RESULT CP2MMServerPlugin::ClientConnect(bool* bAllowConnect, edict_t* pEn
11751167
void CP2MMServerPlugin::ClientFullyConnect(edict_t* pEntity)
11761168
{
11771169
Log(INFO, true, "Player Joined (ClientFullyConnect)!");
1170+
p2mm_lastmap.SetValue(CUR_MAPFILE_NAME);
11781171
}
11791172

11801173
//---------------------------------------------------------------------------------

p2mm.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@
440440
<ClInclude Include="scanner.hpp" />
441441
<ClInclude Include="sdk.hpp" />
442442
</ItemGroup>
443+
<ItemGroup>
444+
<Content Include="README.md" />
445+
</ItemGroup>
443446
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
444447
<ImportGroup Label="ExtensionTargets">
445448
</ImportGroup>

vscript.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ static const char* GetLastMap()
126126
return p2mm_lastmap.GetString();
127127
}
128128

129-
//---------------------------------------------------------------------------------
130-
// Purpose: Get or set the state of whether the first map was run or not.
131-
// Set false/true = 0/1 | -1 to get state.
132-
//---------------------------------------------------------------------------------
133-
static bool FirstRunState(const int state)
134-
{
135-
if (state == 0 || state == 1)
136-
return g_P2MMServerPlugin.m_bFirstMapRan = !!state;
137-
138-
return g_P2MMServerPlugin.m_bFirstMapRan;
139-
}
140-
141129
//---------------------------------------------------------------------------------
142130
// Purpose: Shows the first run prompt if enabled in config.nut.
143131
//---------------------------------------------------------------------------------
@@ -309,10 +297,13 @@ static void ShowScoreboard(const int playerIndex, const bool bEnable)
309297

310298
void RegisterFuncsAndRun()
311299
{
300+
// The IScriptVM interface has to be retrieved later than when starting the plugin as it isn't available yet in memory until map is loading.
301+
Log(INFO, true, "Loading g_pScriptVM...");
312302
g_pScriptVM = **Memory::Scanner::Scan<IScriptVM***>(SERVERDLL, "8B 1D ?? ?? ?? ?? 57 85 DB", 2);
313303
if (!g_pScriptVM)
314304
{
315-
Log(WARNING, false, "Could not register or run our VScript functions!");
305+
assert(0 && "Unable to load g_pScriptVM!");
306+
Log(ERRORR, false, "P2:MM was unable to load g_pScriptVM!\nThis is required for P2:MM to run!\nPlease report!");
316307
return;
317308
}
318309

@@ -328,7 +319,6 @@ void RegisterFuncsAndRun()
328319
ScriptRegisterFunction (g_pScriptVM, GetGameMainDir, "Returns the current game directory. Ex. portal2");
329320
ScriptRegisterFunction (g_pScriptVM, GetGameRootDir, "Returns the current root game directory. Ex. Portal 2");
330321
ScriptRegisterFunction (g_pScriptVM, GetLastMap, "Returns the last map recorded by the Last Map system.");
331-
ScriptRegisterFunction (g_pScriptVM, FirstRunState, "Get or set the state of whether the first map was run or not. Set false/true = 0/1 | -1 to get state.");
332322
ScriptRegisterFunction (g_pScriptVM, CallFirstRunPrompt, "Shows the first run prompt if enabled in config.nut.");
333323
ScriptRegisterFunctionNamed(g_pScriptVM, GetConVarInt, "GetConVarInt", "Get the integer value of a ConVar.");
334324
ScriptRegisterFunctionNamed(g_pScriptVM, GetConVarString, "GetConVarString", "Get the string value of a ConVar.");

0 commit comments

Comments
 (0)