diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-11-28 00:05:42 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-12-01 00:57:19 +0100 |
commit | 67b005eca43fd3e4ae5df91d245e8864dd53339c (patch) | |
tree | ad2da3c610f0fba93d8ccf83741baa8de8a2a1e4 /NorthstarDLL | |
parent | cfc53081ff38a7a0e29cc0b89644760a7ade33a1 (diff) | |
download | NorthstarLauncher-1.20.2.tar.gz NorthstarLauncher-1.20.2.zip |
Add a safeguard to map command (#564)v1.20.2-rc1v1.20.2
Adds safeguard to the `map` command that prevents it from executing if the requested map is invalid or no map argument is given.
Retry of #529
Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com>
(cherry picked from commit da7061a846759cd63dd1907a9df163f4c5b17cf6)
Diffstat (limited to 'NorthstarDLL')
-rw-r--r-- | NorthstarDLL/util/printmaps.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/NorthstarDLL/util/printmaps.cpp b/NorthstarDLL/util/printmaps.cpp index 5b406c4c..bf9f1dec 100644 --- a/NorthstarDLL/util/printmaps.cpp +++ b/NorthstarDLL/util/printmaps.cpp @@ -31,6 +31,12 @@ struct MapVPKInfo // our current list of maps in the game std::vector<MapVPKInfo> vMapList; +typedef void (*Host_Map_helperType)(const CCommand&, void*); +typedef void (*Host_Changelevel_fType)(const CCommand&); + +Host_Map_helperType Host_Map_helper; +Host_Changelevel_fType Host_Changelevel_f; + void RefreshMapList() { // Only update the maps list every 10 seconds max to we avoid constantly reading fs @@ -188,6 +194,30 @@ void ConCommand_maps(const CCommand& args) spdlog::info("({}) {}", PrintMapSource.at(map.source), map.name); } +// clang-format off +AUTOHOOK(Host_Map_f, engine.dll + 0x15B340, void, __fastcall, (const CCommand& args)) +// clang-format on +{ + 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 if (args.ArgC() == 1) + { + spdlog::warn("Map load failed: no map name provided"); + return; + } + + if (*R2::g_pServerState >= R2::server_state_t::ss_active) + return Host_Changelevel_f(args); + else + return Host_Map_helper(args, nullptr); +} + void InitialiseMapsPrint() { AUTOHOOK_DISPATCH() @@ -195,3 +225,9 @@ void InitialiseMapsPrint() ConCommand* mapsCommand = R2::g_pCVar->FindCommand("maps"); mapsCommand->m_pCommandCallback = ConCommand_maps; } + +ON_DLL_LOAD("engine.dll", Host_Map_f, (CModule module)) +{ + Host_Map_helper = module.Offset(0x15AEF0).RCast<Host_Map_helperType>(); + Host_Changelevel_f = module.Offset(0x15AAD0).RCast<Host_Changelevel_fType>(); +} |