Skip to content

Commit

Permalink
remove duplicate helper
Browse files Browse the repository at this point in the history
  • Loading branch information
a committed Dec 6, 2024
1 parent 648faa9 commit 49a9cfa
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dll/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const std::map<std::string, Stat_config>& Settings::getStats() const

std::map<std::string, Stat_config>::const_iterator Settings::setStatDefiniton(const std::string &name, const struct Stat_config &stat_config)
{
auto ins_it = stats.insert_or_assign(common_helpers::ascii_to_lowercase(name), stat_config);
auto ins_it = stats.insert_or_assign(common_helpers::to_lower(name), stat_config);
return ins_it.first;
}

Expand Down
2 changes: 1 addition & 1 deletion dll/steam_user_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Steam_User_Stats::Steam_User_Stats(Settings *settings, class Networking *network
try {
trig.name = name;
trig.value_operation = static_cast<std::string const&>(it["progress"]["value"]["operation"]);
std::string stat_name = common_helpers::ascii_to_lowercase(static_cast<std::string const&>(it["progress"]["value"]["operand1"]));
std::string stat_name = common_helpers::to_lower(static_cast<std::string const&>(it["progress"]["value"]["operand1"]));
trig.min_value = static_cast<std::string const&>(it["progress"]["min_val"]);
trig.max_value = static_cast<std::string const&>(it["progress"]["max_val"]);
achievement_stat_trigger[stat_name].push_back(trig);
Expand Down
5 changes: 3 additions & 2 deletions dll/steam_user_stats_leaderboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ std::vector<Steam_Leaderboard_Entry> Steam_User_Stats::load_leaderboard_entries(

std::vector<Steam_Leaderboard_Entry> out{};

std::string leaderboard_name(common_helpers::ascii_to_lowercase(name));
std::string leaderboard_name(common_helpers::to_lower(name));
unsigned read_bytes = local_storage->file_size(Local_Storage::leaderboard_storage_folder, leaderboard_name);
if ((read_bytes == 0) ||
(read_bytes < (ELEMENT_SIZE * MAIN_HEADER_ELEMENTS_COUNT)) ||
Expand Down Expand Up @@ -138,7 +138,7 @@ void Steam_User_Stats::save_my_leaderboard_entry(const Steam_Leaderboard &leader
output.push_back(detail);
}

std::string leaderboard_name(common_helpers::ascii_to_lowercase(leaderboard.name));
std::string leaderboard_name(common_helpers::to_lower(leaderboard.name));
unsigned int buffer_size = static_cast<unsigned int>(output.size() * sizeof(output[0])); // in bytes
local_storage->store_data(Local_Storage::leaderboard_storage_folder, leaderboard_name, (char* )&output[0], buffer_size);
}
Expand Down Expand Up @@ -186,6 +186,7 @@ unsigned int Steam_User_Stats::cache_leaderboard_ifneeded(const std::string &nam

// create a new entry in-memory and try reading the entries from disk
struct Steam_Leaderboard new_board{};
// don't make this lower/upper case, appid 1372280 later calls GetLeaderboardName() and hangs if the name wasn't the same as the original
new_board.name = name;
new_board.sort_method = eLeaderboardSortMethod;
new_board.display_type = eLeaderboardDisplayType;
Expand Down
14 changes: 7 additions & 7 deletions dll/steam_user_stats_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool Steam_User_Stats::clear_stats_internal()
bool notify_server = false;

for (const auto &stat : settings->getStats()) {
std::string stat_name(common_helpers::ascii_to_lowercase(stat.first));
std::string stat_name(common_helpers::to_lower(stat.first));

switch (stat.second.type)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ Steam_User_Stats::InternalSetResult<int32> Steam_User_Stats::set_stat_internal(
Steam_User_Stats::InternalSetResult<int32> result{};

if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));

const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
Expand Down Expand Up @@ -152,7 +152,7 @@ Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> result{};

if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));

const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
Expand Down Expand Up @@ -226,7 +226,7 @@ Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> result{};

if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));

const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
Expand Down Expand Up @@ -305,7 +305,7 @@ bool Steam_User_Stats::GetStat( const char *pchName, int32 *pData )
std::lock_guard<std::recursive_mutex> lock(global_mutex);

if (!pchName) return false;
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
std::string stat_name = common_helpers::to_lower(pchName);

const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
Expand Down Expand Up @@ -344,7 +344,7 @@ bool Steam_User_Stats::GetStat( const char *pchName, float *pData )
std::lock_guard<std::recursive_mutex> lock(global_mutex);

if (!pchName) return false;
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
std::string stat_name = common_helpers::to_lower(pchName);

const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
Expand Down Expand Up @@ -531,7 +531,7 @@ bool Steam_User_Stats::ResetAllStats( bool bAchievementsToo )
clear_stats_internal(); // this will save stats to disk if necessary
if (!settings->disable_sharing_stats_with_gameserver) {
for (const auto &stat : settings->getStats()) {
std::string stat_name(common_helpers::ascii_to_lowercase(stat.first));
std::string stat_name(common_helpers::to_lower(stat.first));

auto &new_stat = (*pending_server_updates.mutable_user_stats())[stat_name];
new_stat.set_stat_type(stat.second.type);
Expand Down
6 changes: 0 additions & 6 deletions helpers/common_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,6 @@ bool common_helpers::str_cmp_insensitive(std::wstring_view str1, std::wstring_vi
});
}

std::string common_helpers::ascii_to_lowercase(std::string data) {
std::transform(data.begin(), data.end(), data.begin(),
[](char c){ return std::tolower(c); });
return data;
}

void common_helpers::thisThreadYieldFor(std::chrono::microseconds u)
{
const auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 0 additions & 2 deletions helpers/common_helpers/common_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ std::string uint8_vector_to_hex_string(const std::vector<uint8_t> &v);
bool str_cmp_insensitive(std::string_view str1, std::string_view str2);
bool str_cmp_insensitive(std::wstring_view str1, std::wstring_view str2);

std::string ascii_to_lowercase(std::string data);

void thisThreadYieldFor(std::chrono::microseconds u);

void consume_bom(std::ifstream &input);
Expand Down

0 comments on commit 49a9cfa

Please sign in to comment.