Skip to content

Commit

Permalink
Merge pull request #19 from surepy/fmt8.1.0
Browse files Browse the repository at this point in the history
bump fmt to version 8.1.1 (see also surepy/tf2bd_mh_stuff@5b7534c)
  • Loading branch information
surepy authored Oct 27, 2023
2 parents 483aca8 + f27ca3d commit 0a2a9f5
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url = https://github.com/PazerOP/imgui_desktop.git
[submodule "submodules/mh_stuff"]
path = submodules/mh_stuff
url = https://github.com/PazerOP/stuff.git
url = https://github.com/surepy/tf2bd_mh_stuff.git
[submodule "submodules/vcpkg"]
path = submodules/vcpkg
url = https://github.com/microsoft/vcpkg.git
2 changes: 1 addition & 1 deletion tf2_bot_detector/DB/TempDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace
Connect();

// Delete and recreate the DB if its an old version
if (const auto currentUserVersion = m_Connection->execAndGet(mh::format("PRAGMA user_version")).getInt();
if (const auto currentUserVersion = m_Connection->execAndGet("PRAGMA user_version").getInt();
currentUserVersion != DB_VERSION)
{
LogWarning("Current {} version = {}. Deleting and recreating...", CreateDBPath(), currentUserVersion);
Expand Down
4 changes: 2 additions & 2 deletions tf2_bot_detector/DiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static auto DiscordDebugLog(const std::string_view& fmtStr, const TArgs&... args
if (!s_DiscordDebugLogEnabled)
return;

DebugLog(DISCORD_LOG_COLOR, "DRP: {}", mh::format(fmtStr, args...));
DebugLog(DISCORD_LOG_COLOR, "DRP: {}", mh::format(mh::runtime(fmtStr), args...));
}

template<typename... TArgs>
Expand All @@ -114,7 +114,7 @@ static auto DiscordDebugLog(const mh::source_location& location,
if (fmtStr.empty())
DebugLog(DISCORD_LOG_COLOR, location);
else
DebugLog(DISCORD_LOG_COLOR, location, "DRP: {}", mh::format(fmtStr, args...));
DebugLog(DISCORD_LOG_COLOR, location, "DRP: {}", mh::format(mh::runtime(fmtStr), args...));
}

static void DiscordLogHookFunc(discord::LogLevel level, const char* logMsg)
Expand Down
14 changes: 11 additions & 3 deletions tf2_bot_detector/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,16 @@ void tf2_bot_detector::LogException(const mh::source_location& location, const s
if (visibility == LogVisibility::Debug)
color = color.WithAlpha(LogColors::DEBUG_ALPHA);

detail::log_h::LogImpl(LogColors::ERROR, severity, visibility, location,
msg.empty() ? "{1}: {2}"sv : "{0}: {1}: {2}"sv, msg, details.type_name(), details.m_Message);
detail::log_h::LogImpl(
LogColors::ERROR,
severity,
visibility,
location,
msg.empty() ? "{1}: {2}"sv : "{0}: {1}: {2}"sv,
msg,
details.type_name(),
details.m_Message
);

if (severity == LogSeverity::Fatal)
{
Expand Down Expand Up @@ -317,7 +325,7 @@ void detail::log_h::LogImpl(const LogMessageColor& color, LogSeverity severity,
ILogManager::GetInstance().Log(std::move(str), color, severity, visibility);
}

void tf2_bot_detector::detail::log_h::LogImpl(const LogMessageColor& color, LogSeverity severity, LogVisibility visibility,
void detail::log_h::LogImpl(const LogMessageColor& color, LogSeverity severity, LogVisibility visibility,
const mh::source_location& location, const std::string_view& str)
{
LogImpl(color, severity, visibility, mh::format(MH_FMT_STRING("{}: {}"sv), location, str));
Expand Down
15 changes: 9 additions & 6 deletions tf2_bot_detector/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ namespace tf2_bot_detector

template<typename... TArgs>
NOINLINE inline auto LogImpl(const LogMessageColor& color, LogSeverity severity, LogVisibility visibility,
const std::string_view& fmtStr, const TArgs&... args) ->
decltype(mh::try_format(fmtStr, args...), void())
const std::string_view& fmtStr, const TArgs&... args)
-> decltype(mh::try_format(mh::runtime(fmtStr), mh::make_format_args(args...)), void())
{
LogImplBase(color, severity, visibility, fmtStr, mh::make_format_args(args...));
}

template<typename... TArgs>
NOINLINE inline auto LogImpl(const LogMessageColor& color, LogSeverity severity, LogVisibility visibility,
const mh::source_location& location, const std::string_view& fmtStr, const TArgs&... args) ->
decltype(mh::try_format(fmtStr, args...), void())
const mh::source_location& location, const std::string_view& fmtStr, const TArgs&... args)
-> decltype(mh::try_format(mh::runtime(fmtStr), mh::make_format_args(args...)), void())
{
LogImplBase(color, severity, visibility, location, fmtStr, mh::make_format_args(args...));
}
Expand All @@ -147,6 +148,7 @@ namespace tf2_bot_detector
}

#undef LOG_DEFINITION_HELPER

#define LOG_DEFINITION_HELPER(name, defaultColor, severity, visibility) \
template<typename... TArgs> \
inline auto name(const LogMessageColor& color, const mh::source_location& location, const std::string_view& fmtStr, const TArgs&... args) \
Expand Down Expand Up @@ -189,7 +191,7 @@ namespace tf2_bot_detector
attr void name(const mh::source_location& location, const std::exception_ptr& e, \
const std::string_view& fmtStr = {}, const TArgs&... args) \
{ \
LogException(location, e, severity, visibility, mh::try_format(fmtStr, args...)); \
LogException(location, e, severity, visibility, mh::format(mh::runtime(fmtStr), args...)); /* NOTE: we're losing compile-time evaluation on fmtStr, but I can't be arsed to bother. */ \
} \
template<typename... TArgs> \
attr void name(const std::exception_ptr& e, const detail::log_h::src_location_wrapper& fmtStr = {}, const TArgs&... args) \
Expand Down Expand Up @@ -236,7 +238,8 @@ namespace tf2_bot_detector
[[noreturn]] void LogFatalError(const mh::source_location& location,
const std::string_view& fmtStr, const TArgs&... args)
{
LogFatalError(location, mh::try_format(fmtStr, args...));
/* NOTE: we're losing compile-time evaluation on fmtStr, but I can't be arsed to bother. */
LogFatalError(location, mh::try_format(mh::runtime(fmtStr), args...));
}
template<typename... TArgs>
[[noreturn]] void LogFatalError(const detail::log_h::src_location_wrapper& fmtStr, const TArgs&... args)
Expand Down
6 changes: 3 additions & 3 deletions tf2_bot_detector/ModeratorLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ std::string ModeratorLogic::GenerateCheaterWarnMessage(const std::vector<std::st
// check if they're empty for whatever reason
if (!m_Settings->m_OneCheaterWarningMessage.empty()) {
try {
fmt::format(m_Settings->m_OneCheaterWarningMessage, 1);
std::string discard = fmt::format(fmt::runtime(m_Settings->m_OneCheaterWarningMessage), 1);
one_cheater_warning = m_Settings->m_OneCheaterWarningMessage;
}
catch (fmt::format_error err) {
Expand All @@ -645,7 +645,7 @@ std::string ModeratorLogic::GenerateCheaterWarnMessage(const std::vector<std::st

if (!m_Settings->m_MultipleCheaterWarningMessage.empty()) {
try {
fmt::format(m_Settings->m_MultipleCheaterWarningMessage, fmt::arg("count", 2), fmt::arg("names", "a, b"));
std::string discard = fmt::format(fmt::runtime(m_Settings->m_MultipleCheaterWarningMessage), fmt::arg("count", 2), fmt::arg("names", "a, b"));
multiple_cheater_warning = m_Settings->m_MultipleCheaterWarningMessage;
}
catch (fmt::format_error err) {
Expand Down Expand Up @@ -770,7 +770,7 @@ void ModeratorLogic::HandleConnectingEnemyCheaters(const std::vector<Cheater>& c

if (m_Settings->m_UseCustomChatWarnings && !m_Settings->m_MultipleCheaterConnectingMessage.empty()) {
try {
fmt::format(m_Settings->m_MultipleCheaterConnectingMessage, 1);
std::string discard = fmt::format(fmt::runtime(m_Settings->m_MultipleCheaterConnectingMessage), 1);
mutli_cheater_connecting = m_Settings->m_MultipleCheaterConnectingMessage;
}
catch (fmt::format_error err) {
Expand Down
2 changes: 1 addition & 1 deletion tf2_bot_detector/UI/ImGui_TF2BotDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ImGui
{
template<typename... TArgs>
inline auto TextFmt(const std::string_view& fmtStr, const TArgs&... args) ->
decltype(mh::format(fmtStr, args...), void())
decltype(mh::format(fmt::runtime(fmtStr), args...), void())
{
if constexpr (sizeof...(TArgs) > 0)
return TextFmt(mh::fmtstr<3073>(fmtStr, args...));
Expand Down
10 changes: 6 additions & 4 deletions tf2_bot_detector/UI/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void SettingsWindow::OnDrawModerationSettings()
ImGui::InputText("Cheater Joining", &m_Settings.m_OneCheaterConnectingMessage);
ImGui::InputText("Multiple Cheater Joining", &m_Settings.m_MultipleCheaterConnectingMessage);
try {
fmt::format(m_Settings.m_MultipleCheaterConnectingMessage, 1);
ImGui::Text(fmt::format(fmt::runtime(m_Settings.m_MultipleCheaterConnectingMessage), "3").c_str());
}
catch (fmt::format_error err) {
ImGui::TextFmt({ 1, 0, 0, 1 }, "Invalid string format! this takes 1 arguments maximum! (player count)");
Expand All @@ -189,14 +189,16 @@ void SettingsWindow::OnDrawModerationSettings()

ImGui::InputText("Cheater Warning", &m_Settings.m_OneCheaterWarningMessage);
try {
fmt::format(m_Settings.m_OneCheaterWarningMessage, 1);

ImGui::Text(fmt::format(fmt::runtime(m_Settings.m_OneCheaterWarningMessage), 1).c_str());
}
catch (fmt::format_error err) {
ImGui::TextFmt( { 1, 0, 0, 1 }, "Invalid string format! this takes 1 arguments maximum! (player count)");
ImGui::TextFmt( { 1, 0, 0, 1 }, "Invalid string format! this takes 1 arguments maximum! (player name)");
}

ImGui::InputText("Multiple Cheater Warning", &m_Settings.m_MultipleCheaterWarningMessage);
try {
fmt::format(m_Settings.m_MultipleCheaterWarningMessage, fmt::arg("count", 2), fmt::arg("names", "a, b"));
ImGui::Text(fmt::format(fmt::runtime(m_Settings.m_MultipleCheaterWarningMessage), fmt::arg("count", 2), fmt::arg("names", "a, b")).c_str());
}
catch (fmt::format_error err) {
ImGui::TextFmt({ 1, 0, 0, 1 }, "Invalid string format! this takes 2 arguments maximum! ({count}, {names})");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Platform/PlatformCommon.h"

#include <mh/text/format.hpp>

#include <stdexcept>

#include <Windows.h>
Expand All @@ -22,7 +21,8 @@ void* tf2_bot_detector::Platform::GetProcAddressHelper(const char* moduleName, c
if (!moduleHandle)
{
auto err = GetLastError();
throw std::system_error(err, std::system_category(), mh::format(MH_FMT_STRING("Failed to GetModuleHandle({})"), moduleName));

throw std::system_error(err, std::system_category(), mh::format(FMT_STRING("Failed to GetModuleHandle({})"), moduleName));
}

auto address = GetProcAddress(moduleHandle, symbolName);
Expand All @@ -33,7 +33,7 @@ void* tf2_bot_detector::Platform::GetProcAddressHelper(const char* moduleName, c

if (isCritical)
{
throw std::system_error(ec, mh::format(MH_FMT_STRING("{}: Failed to find function {} in {}"), location, symbolName, moduleName));
throw std::system_error(ec, mh::format(FMT_STRING("{}: Failed to find function {} in {}"), location, symbolName, moduleName));
}
}

Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"overrides": [
{
"name": "fmt",
"version": "8.0.1"
"version": "8.1.1"
}
],
"builtin-baseline": "253704407ae68efa37bf8f5b59b3e06dd40d3d3f"
Expand Down

0 comments on commit 0a2a9f5

Please sign in to comment.