Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Features/ChallengeMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

ChallengeMode *cm;

bool ChallengeMode::EnsureStatsController() {
if (entityList->GetEntityInfoByClassName("portal_stats_controller")) {
return true;
}

return server->Create && server->Create("portal_stats_controller", {0, 0, 0}, {0, 0, 0}, nullptr);
}

void ChallengeMode::CreateNode() {
if (!sv_bonus_challenge.GetBool() || engine->demoplayer->IsPlaying()) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/Features/ChallengeMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ChallengeMode : public Feature {

public:
void CreateNode();
bool EnsureStatsController();
void LoadNodes(SourceGameVersion version);
};

Expand Down
20 changes: 20 additions & 0 deletions src/Modules/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,26 @@ static void __cdecl AcceptInput_Hook(void *thisptr, const char *inputName, void
console->Print("%.4d %s.%s(%s)\n", session->GetTick(), entName, inputName, parameter.ToString());
}

if (sar.game->Is(SourceGame_PortalStoriesMel)
&& client->GetChallengeStatus() == CMStatus::CHALLENGE
&& !engine->demoplayer->IsPlaying()
&& (!strcasecmp(className, "point_clientcommand") || !strcasecmp(className, "point_servercommand"))
&& !strcasecmp(inputName, "Command")) {
const char *command = parameter.ToString();
command += strspn(command, " \t\r\n");
if (!strncasecmp(command, "changelevel", 11) && strspn(command + 11, " \t\r\n") > 0) {
if (cm->EnsureStatsController()) {
// Complete after the map's fade, replacing the changelevel command entirely.
// RunScriptCode is a base entity input; queue OnLevelEnd so it reaches our hook.
inputName = "RunScriptCode";
parameter.fieldType = FIELD_STRING;
parameter.iszVal = "EntFire(\"portal_stats_controller\", \"OnLevelEnd\", 5.0, 0);";
} else {
console->Print("Could not obtain portal_stats_controller; keeping Mel's original elevator transition.\n");
}
}
}

// HACKHACK
// Deals with maps where you hit a normal transition trigger
if (!strcmp(className, "portal_stats_controller") && !strcmp(inputName, "OnLevelEnd") && client->GetChallengeStatus() == CMStatus::CHALLENGE) {
Expand Down
1 change: 1 addition & 0 deletions src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# include <Windows.h>
# define strdup _strdup
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
#else
# include <unistd.h>
#endif
Expand Down
Loading