Skip to content

Commit

Permalink
Added player_spawn_blue and player_spawn_orange game event interf…
Browse files Browse the repository at this point in the history
…aces.
  • Loading branch information
OrsellGaming committed Nov 5, 2024
1 parent 95471e9 commit dbdb102
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void GEPlayerPortaled(short userid, bool portal2, int entindex);
void GETurretHitTurret(); | "Called whenever a turret hits another turret. Game event: 'turret_hit_turret'"
void GECamDetach(); | "Called whenever a camera is detached from a surface. Game event: 'security_camera_detached'"
void GEPlayerLanded(short userid, int entindex); | "Called whenever a player lands on the ground. Game event: 'player_landed'"
void GEPlayerSpawnBlue(); | "Called whenever a Blue/Atlas player spawns. Game event: 'player_spawn_blue'"
void GEPlayerSpawnOrange(); | "Called whenever a Red/Orange/PBody player spawns. Game event: 'player_spawn_orange'"
void GEPlayerDeath(short userid, short attacker, int entindex); | "Called whenever a player dies. Game event: 'player_death'"
void GEPlayerConnect(const char* name, int index, short userid, const char* xuid,
const char* networkid, const char* address, bool bot, int entindex); | "Called where a player connects to the server. 'index' is the entity index minus 1. Game event: 'player_connect'"
Expand Down
79 changes: 55 additions & 24 deletions p2mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static const char* gameevents[] =
"turret_hit_turret",
"security_camera_detached",
"player_landed",
"player_spawn_blue",
"player_spawn_orange",
"player_death",
"player_connect",
"player_say",
Expand Down Expand Up @@ -170,22 +172,6 @@ static int p2mm_startsession_CompletionFunc(const char* partial, char commands[C
return numMatchedMaps;
}

CON_COMMAND(p2mm_updatemaplist, "Manually updates the list of avaliable maps that can be loaded with \"p2mm_startsession\"")
{
updateMapsList();
}

CON_COMMAND(p2mm_maplist, "Lists avaliable maps that can be loaded with \"p2mm_startsession\"")
{
P2MMLog(0, false, "AVALIABLE MAPS:");
P2MMLog(0, false, "----------------------------------------");
for (const std::string map : mapList)
{
P2MMLog(0, false, map.c_str());
}
P2MMLog(0, false, "----------------------------------------");
}

CON_COMMAND_F_COMPLETION(p2mm_startsession, "Starts up a P2:MM session with a requested map.", 0, p2mm_startsession_CompletionFunc)
{
// Make sure the CON_COMMAND was executed correctly.
Expand Down Expand Up @@ -269,6 +255,22 @@ CON_COMMAND_F_COMPLETION(p2mm_startsession, "Starts up a P2:MM session with a re
}
}

CON_COMMAND(p2mm_updatemaplist, "Manually updates the list of avaliable maps that can be loaded with \"p2mm_startsession\"")
{
updateMapsList();
}

CON_COMMAND(p2mm_maplist, "Lists avaliable maps that can be loaded with \"p2mm_startsession\"")
{
P2MMLog(0, false, "AVALIABLE MAPS:");
P2MMLog(0, false, "----------------------------------------");
for (const std::string map : mapList)
{
P2MMLog(0, false, map.c_str());
}
P2MMLog(0, false, "----------------------------------------");
}

CON_COMMAND(p2mm_respawnall, "Respawns all players.")
{
for (int i = 1; i < g_pGlobals->maxClients; i++)
Expand Down Expand Up @@ -321,7 +323,6 @@ const char* CP2MMServerPlugin::GetPluginDescription(void)
// disconnect_orig(thisptr, edx, cl, eDenyReason, pchOptionalText);
//}


// Bottom three hooks are for being able to change the starting models to something different.
// First two are for changing what model is returned when precaching however...
// Last one is for actually specifying the right model as the MSVC compiler inlined the returns
Expand Down Expand Up @@ -510,14 +511,15 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterface
// Hook onto the function which defines what Atlas's and PBody's models are.
MH_CreateHook(
Memory::Rel32(Memory::Scanner::Scan(SERVERDLL, "E8 ?? ?? ?? ?? 83 C4 40 50", 1)),
&GetBallBotModel_hook, (void**)&GetBallBotModel_orig);
&GetBallBotModel_hook, (void**)&GetBallBotModel_orig
);
MH_CreateHook(
Memory::Rel32(Memory::Scanner::Scan(SERVERDLL, "E8 ?? ?? ?? ?? 83 C4 04 50 8B 45 10 8B 10", 1)),
&GetEggBotModel_hook, (void**)&GetEggBotModel_orig);
&GetEggBotModel_hook, (void**)&GetEggBotModel_orig
);
MH_CreateHook(
Memory::Scanner::Scan(SERVERDLL, "55 8B EC 81 EC 10 01 00 00 53 8B 1D"),
&CPortal_Player__GetPlayerModelName_hook,
(void**)&CPortal_Player__GetPlayerModelName_orig
&CPortal_Player__GetPlayerModelName_hook, (void**)&CPortal_Player__GetPlayerModelName_orig
);

MH_EnableHook(MH_ALL_HOOKS);
Expand Down Expand Up @@ -778,7 +780,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)

return;
}
// Event called when a player goes through a portal, "turret_hit_turret" returns nothing.
// Event called when a turret hits another turret, "turret_hit_turret" returns nothing.
else if (FStrEq(event->GetName(), "turret_hit_turret"))
{
if (g_pScriptVM)
Expand All @@ -793,7 +795,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)

return;
}
// Event called when a player goes through a portal, "security_camera_detached" returns nothing.
// Event called when a camera is detached from a wall, "security_camera_detached" returns nothing.
else if (FStrEq(event->GetName(), "security_camera_detached"))
{
if (g_pScriptVM)
Expand Down Expand Up @@ -828,6 +830,36 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)

return;
}
// Event called when a Blue/Atlas spawns, "player_spawn_blue" returns nothing.
else if (FStrEq(event->GetName(), "player_spawn_blue"))
{
if (g_pScriptVM)
{
// Handle VScript game event function
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSpawnBlue");
if (ge_func)
{
g_pScriptVM->Call(ge_func, NULL, true, NULL);
}
}

return;
}
// Event called when a Red/Orange/PBody spawns, "player_spawn_orange" returns nothing.
else if (FStrEq(event->GetName(), "player_spawn_orange"))
{
if (g_pScriptVM)
{
// Handle VScript game event function
HSCRIPT ge_func = g_pScriptVM->LookupFunction("GEPlayerSpawnOrange");
if (ge_func)
{
g_pScriptVM->Call(ge_func, NULL, true, NULL);
}
}

return;
}
// Event called when a player dies, "player_death" returns:
/*
"userid" "short" // user ID who died
Expand All @@ -848,7 +880,6 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
HSCRIPT playerHandle = INDEXHANDLE(entindex);
if (playerHandle)
{
// player does not have a script scope yet, fire OnPlayerJoin
g_pScriptVM->Call<HSCRIPT>(od_func, NULL, true, NULL, playerHandle);
}
}
Expand Down

0 comments on commit dbdb102

Please sign in to comment.