diff --git a/include/crlib/cr-files.h b/include/crlib/cr-files.h index e54b79c..3eb8732 100644 --- a/include/crlib/cr-files.h +++ b/include/crlib/cr-files.h @@ -85,14 +85,14 @@ public: template size_t puts (const char *fmt, Args ...args) { if (!*this) { - return false; + return 0; } return fprintf (m_handle, fmt, cr::forward (args)...); } bool puts (const String &buffer) { if (!*this) { - return false; + return 0; } if (fputs (buffer.chars (), m_handle) < 0) { return false; diff --git a/include/crlib/cr-platform.h b/include/crlib/cr-platform.h index 9128b57..e10364b 100644 --- a/include/crlib/cr-platform.h +++ b/include/crlib/cr-platform.h @@ -57,11 +57,9 @@ CR_NAMESPACE_END #if defined(CR_WINDOWS) # include -# define stricmp _stricmp #else # include # include -# define stricmp strcasecmp #endif #include @@ -147,6 +145,14 @@ struct Platform : public Singleton { #endif } + bool caseStrMatch (const char *str1, const char *str2) { +#if defined(CR_WINDOWS) + return _stricmp (str1, str2) == 0; +#else + return strcasecmp (str1, str2) == 0; +#endif + } + void abort (const char *msg = "OUT OF MEMORY!") noexcept { fprintf (stderr, "%s\n", msg); diff --git a/source/control.cpp b/source/control.cpp index 85138f4..70c13c6 100644 --- a/source/control.cpp +++ b/source/control.cpp @@ -1653,7 +1653,7 @@ void BotControl::showMenu (int id) { for (auto &display : m_menus) { if (display.ident == id) { - const char *text = (game.is (GameFlags::Xash3D | GameFlags::Mobility) && !yb_display_menu_text.bool_ ()) ? " " : display.text.chars (); + auto text = (game.is (GameFlags::Xash3D | GameFlags::Mobility) && !yb_display_menu_text.bool_ ()) ? " " : display.text.chars (); MessageWriter msg; while (strlen (text) >= 64) { diff --git a/source/graph.cpp b/source/graph.cpp index 3d22d7b..195ed05 100644 --- a/source/graph.cpp +++ b/source/graph.cpp @@ -1310,7 +1310,7 @@ bool BotGraph::convertOldFormat () { if (header.fileVersion != StorageVersion::Podbot) { return false; } - else if (!!stricmp (header.mapName, map)) { + else if (!plat.caseStrMatch (header.mapName, map)) { return false; } else { diff --git a/source/manager.cpp b/source/manager.cpp index 1a2480c..23b577e 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -363,10 +363,10 @@ void BotManager::maintainQuota () { int desiredBotCount = yb_quota.int_ (); int botsInGame = getBotCount (); - if (stricmp (yb_quota_mode.str (), "fill") == 0) { + if (plat.caseStrMatch (yb_quota_mode.str (), "fill")) { botsInGame += humanPlayersInGame; } - else if (stricmp (yb_quota_mode.str (), "match") == 0) { + else if (plat.caseStrMatch (yb_quota_mode.str (), "match")) { int detectQuotaMatch = yb_quota_match.int_ () == 0 ? yb_quota.int_ () : yb_quota_match.int_ (); desiredBotCount = cr::max (0, detectQuotaMatch * humanPlayersInGame); @@ -1269,7 +1269,7 @@ void BotManager::captureChatRadio (const char *cmd, const char *arg, edict_t *en return; } - if (stricmp (cmd, "say") == 0 || stricmp (cmd, "say_team") == 0) { + if (plat.caseStrMatch (cmd, "say") || plat.caseStrMatch (cmd, "say_team")) { if (strcmp (arg, "dropme") == 0 || strcmp (arg, "dropc4") == 0) { Bot *bot = nullptr; @@ -1605,7 +1605,7 @@ void BotConfig::loadMainConfig () { if (cvar != nullptr) { auto value = const_cast (keyval[1].trim ().trim ("\"").trim ().chars ()); - if (needsToIgnoreVar (ignore, key) && !!stricmp (value, cvar->string)) { + if (needsToIgnoreVar (ignore, key) && !plat.caseStrMatch (value, cvar->string)) { game.print ("Bot CVAR '%s' differs from the stored in the config (%s/%s). Ignoring.", cvar->name, cvar->string, value); // ensure cvar will have old value @@ -2112,7 +2112,7 @@ void BotConfig::initWeapons () { // fill array with available weapons m_weapons.emplace (Weapon::Knife, "weapon_knife", "knife.mdl", 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, true ); m_weapons.emplace (Weapon::USP, "weapon_usp", "usp.mdl", 500, 1, -1, -1, 1, 1, 2, 2, 0, 12, false ); - m_weapons.emplace (Weapon::Glock18, "weapon_glock18", "glock18.mdl", 400, 1, -1, -1, 1, 2, 1, 1, 0, 20, false ); + m_weapons.emplace (Weapon::Glock18, "weapon_glock18", "glock18.mdl", 400, 1, -1, -1, 1, 2, 1, 1, 0, 20, false ); m_weapons.emplace (Weapon::Deagle, "weapon_deagle", "deagle.mdl", 650, 1, 2, 2, 1, 3, 4, 4, 2, 7, false ); m_weapons.emplace (Weapon::P228, "weapon_p228", "p228.mdl", 600, 1, 2, 2, 1, 4, 3, 3, 0, 13, false ); m_weapons.emplace (Weapon::Elite, "weapon_elite", "elite.mdl", 800, 1, 0, 0, 1, 5, 5, 5, 0, 30, false );