From cde626b041e72d749c54d0be8119fe3604bbf4f0 Mon Sep 17 00:00:00 2001 From: cat_or_not <41955154+catornot@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:17:22 -0400 Subject: [PATCH 1/7] Add a safeguard to map command (#529) Adds safeguard to the `map` command that prevents it from executing if the requested map is invalid or no map argument is given. --- NorthstarDLL/util/printmaps.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/NorthstarDLL/util/printmaps.cpp b/NorthstarDLL/util/printmaps.cpp index dd825bff3..abd4e1ea6 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 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 @@ -182,6 +188,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() @@ -189,3 +219,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_Changelevel_f = module.Offset(0x15AAD0).RCast(); +} From d6f0cd508dfb81a9af7afa5ac70b8b2496665037 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 2 Oct 2023 22:44:27 +0100 Subject: [PATCH 2/7] Fix crash when running `disconnect %%s` (#554) Co-authored-by: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> --- NorthstarDLL/client/rejectconnectionfixes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NorthstarDLL/client/rejectconnectionfixes.cpp b/NorthstarDLL/client/rejectconnectionfixes.cpp index 5daeb3eeb..6adde8b6c 100644 --- a/NorthstarDLL/client/rejectconnectionfixes.cpp +++ b/NorthstarDLL/client/rejectconnectionfixes.cpp @@ -25,7 +25,7 @@ void,, (bool a1, const char* fmt, ...)) R2::Cbuf_AddText(R2::Cbuf_GetCurrentPlayer(), "disconnect", R2::cmd_source_t::kCommandSrcCode); } - return COM_ExplainDisconnection(a1, buf); + return COM_ExplainDisconnection(a1, "%s", buf); } ON_DLL_LOAD_CLIENT("engine.dll", RejectConnectionFixes, (CModule module)) From 2a3be90915b547f21c1dc574a83b24c988cf6b72 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:32:14 +0200 Subject: [PATCH 3/7] Revert "Add a safeguard to map command" (#561) Revert "Add a safeguard to map command (#529)" This reverts commit cde626b041e72d749c54d0be8119fe3604bbf4f0. --- NorthstarDLL/util/printmaps.cpp | 36 --------------------------------- 1 file changed, 36 deletions(-) diff --git a/NorthstarDLL/util/printmaps.cpp b/NorthstarDLL/util/printmaps.cpp index abd4e1ea6..dd825bff3 100644 --- a/NorthstarDLL/util/printmaps.cpp +++ b/NorthstarDLL/util/printmaps.cpp @@ -31,12 +31,6 @@ struct MapVPKInfo // our current list of maps in the game std::vector 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,30 +182,6 @@ 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() @@ -219,9 +189,3 @@ 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_Changelevel_f = module.Offset(0x15AAD0).RCast(); -} From 1d30b2d5eeecb1b0bddf75c665939f9532ee235e Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:04:32 +0100 Subject: [PATCH 4/7] Always allow the local player through the banlist (#540) Adds a check to always allow local player through banlist to aid with players accidentally banning themselves. --- NorthstarDLL/server/auth/bansystem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NorthstarDLL/server/auth/bansystem.cpp b/NorthstarDLL/server/auth/bansystem.cpp index 845a1bff1..9b9d24c43 100644 --- a/NorthstarDLL/server/auth/bansystem.cpp +++ b/NorthstarDLL/server/auth/bansystem.cpp @@ -3,6 +3,7 @@ #include "core/convar/concommand.h" #include "server/r2server.h" #include "engine/r2engine.h" +#include "client/r2client.h" #include "config/profile.h" #include @@ -172,6 +173,10 @@ void ServerBanSystem::UnbanUID(uint64_t uid) bool ServerBanSystem::IsUIDAllowed(uint64_t uid) { + uint64_t localPlayerUserID = strtoull(R2::g_pLocalPlayerUserID, nullptr, 10); + if (localPlayerUserID == uid) + return true; + ReloadBanlist(); // Reload to have up to date list on join return std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid) == m_vBannedUids.end(); } From 5798c6369c9c093ddd170397177ea75f674a7b4c Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 4 Oct 2023 13:56:48 +0200 Subject: [PATCH 5/7] Give `g_pMemAllocSingleton` a default value (#563) Give default value as standard does not define value if uninitialised. --- NorthstarDLL/core/tier0.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NorthstarDLL/core/tier0.cpp b/NorthstarDLL/core/tier0.cpp index 3b9996a13..167093842 100644 --- a/NorthstarDLL/core/tier0.cpp +++ b/NorthstarDLL/core/tier0.cpp @@ -3,7 +3,7 @@ // use the Tier0 namespace for tier0 funcs namespace Tier0 { - IMemAlloc* g_pMemAllocSingleton; + IMemAlloc* g_pMemAllocSingleton = nullptr; ErrorType Error; CommandLineType CommandLine; From b269c4df616be0ff3f669021726072edf1214c88 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:57:34 +0200 Subject: [PATCH 6/7] Define indent size in editorconfig (#550) Setting indent size in `.editorconfig` means that things like GitHub web preview will default to showing tab indent size as 4 spaces. --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index bc423183f..59f4af9f5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,4 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true indent_style = tab +indent_size = 4 From 9d8bedf580184313f419cdb60351e712712832e3 Mon Sep 17 00:00:00 2001 From: H0L0 Date: Fri, 6 Oct 2023 08:50:53 +1000 Subject: [PATCH 7/7] Write date to logs (#565) Next to time also write date to log files. --- NorthstarDLL/logging/logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NorthstarDLL/logging/logging.cpp b/NorthstarDLL/logging/logging.cpp index 2e8605d67..a68fe7046 100644 --- a/NorthstarDLL/logging/logging.cpp +++ b/NorthstarDLL/logging/logging.cpp @@ -52,7 +52,7 @@ void CreateLogFiles() stream << std::put_time(¤tTime, (GetNorthstarPrefix() + "/logs/nslog%Y-%m-%d %H-%M-%S.txt").c_str()); auto sink = std::make_shared(stream.str(), false); - sink->set_pattern("[%H:%M:%S] [%n] [%l] %v"); + sink->set_pattern("[%Y-%m-%d] [%H:%M:%S] [%n] [%l] %v"); for (auto& logger : loggers) { logger->sinks().push_back(sink);