Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a safeguard to map command #529

Merged
merged 9 commits into from
Oct 2, 2023
24 changes: 24 additions & 0 deletions NorthstarDLL/util/printmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct MapVPKInfo
// our current list of maps in the game
std::vector<MapVPKInfo> vMapList;

FnCommandCallback_t OriginalMapCommand = NULL;

void RefreshMapList()
{
// Only update the maps list every 10 seconds max to we avoid constantly reading fs
Expand Down Expand Up @@ -182,10 +184,32 @@ void ConCommand_maps(const CCommand& args)
spdlog::info("({}) {}", PrintMapSource.at(map.source), map.name);
}

void ConCommand_map(const CCommand& args)
{
RefreshMapList();

if (args.ArgC() > 1 &&
std::find_if(vMapList.begin(), vMapList.end(), [&](MapVPKInfo map) -> bool { return map.name == args.Arg(1); }) == vMapList.end())
{
spdlog::warn("Map load failed: {} not found or invalid", args.Arg(1));
return;
}
else
{
spdlog::warn("Map load failed: no map name provided");
}

OriginalMapCommand(args);
}

void InitialiseMapsPrint()
{
AUTOHOOK_DISPATCH()

ConCommand* mapsCommand = R2::g_pCVar->FindCommand("maps");
mapsCommand->m_pCommandCallback = ConCommand_maps;

ConCommand* mapCommand = R2::g_pCVar->FindCommand("map");
OriginalMapCommand = mapCommand->m_pCommandCallback;
mapCommand->m_pCommandCallback = ConCommand_map;
}