From c28a1f1f5280f8a63b728738d3d3f2537bb05773 Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:58:16 +0300 Subject: [PATCH] fix more VS2022 warnings --- dll/appticket.cpp | 2 +- dll/auth.cpp | 6 ++- dll/local_storage.cpp | 6 +-- dll/source_query.cpp | 4 +- dll/steam_apps.cpp | 3 +- dll/steam_friends.cpp | 8 +++- dll/steam_gameserver.cpp | 10 +++-- dll/steam_http.cpp | 4 +- dll/steam_matchmaking.cpp | 67 ++++++++++++++----------------- dll/steam_matchmaking_servers.cpp | 29 ++++++------- dll/steam_networking_utils.cpp | 2 +- dll/steam_remote_storage.cpp | 10 ++--- dll/steam_user.cpp | 12 +++--- dll/steam_user_stats.cpp | 26 ++++++------ dll/steam_utils.cpp | 14 +++---- 15 files changed, 103 insertions(+), 100 deletions(-) diff --git a/dll/appticket.cpp b/dll/appticket.cpp index db708c1b..cccbbbb5 100644 --- a/dll/appticket.cpp +++ b/dll/appticket.cpp @@ -177,7 +177,7 @@ bool AppTicketV4::Deserialize(const uint8_t* pBuffer, size_t size) return false; uint16_t appid_count = *reinterpret_cast(pBuffer); - if (size < (appid_count * 4 + 2) || appid_count >= 140) + if (size < static_cast(appid_count * 4 + 2) || appid_count >= 140u) return false; AppIDs.resize(appid_count); diff --git a/dll/auth.cpp b/dll/auth.cpp index 2c3ac361..b36d192d 100644 --- a/dll/auth.cpp +++ b/dll/auth.cpp @@ -697,8 +697,9 @@ Auth_Data Auth_Manager::getTicketData( void *pTicket, int cbMaxTicket, uint32 *p std::vector ser = ticket_data.Serialize(); uint32_t ser_size = static_cast(ser.size()); *pcbTicket = ser_size; - if (cbMaxTicket >= ser_size) + if (cbMaxTicket > 0 && static_cast(cbMaxTicket) >= ser_size) { memcpy(pTicket, ser.data(), ser_size); + } } else { @@ -736,8 +737,9 @@ HAuthTicket Auth_Manager::getTicket( void *pTicket, int cbMaxTicket, uint32 *pcb Auth_Data ticket_data = getTicketData(pTicket, cbMaxTicket, pcbTicket ); - if (*pcbTicket > cbMaxTicket) + if (*pcbTicket > static_cast(cbMaxTicket)) { return k_HAuthTicketInvalid; + } GetAuthSessionTicketResponse_t data{}; data.m_hAuthTicket = (HAuthTicket)ticket_data.number; diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 161d1496..49f2a6e5 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -229,7 +229,7 @@ static BOOL DirectoryExists(LPCWSTR szPath) static void createDirectoryRecursively(std::wstring path) { - unsigned long long pos = 0; + size_t pos = 0; do { pos = path.find_first_of(L"\\/", pos + 1); @@ -765,7 +765,7 @@ bool Local_Storage::iterate_file(std::string folder, int index, char *output_fil } std::vector files = get_filenames_recursive(save_directory + appid + folder); - if (index < 0 || index >= files.size()) return false; + if (index < 0 || static_cast(index) >= files.size()) return false; std::string name(desanitize_file_name(files[index].name)); if (output_size) *output_size = file_size(folder, name); @@ -807,7 +807,7 @@ bool Local_Storage::load_json(std::string full_path, nlohmann::json& json) // If there is a file and we opened it if (inventory_file) { inventory_file.seekg(0, std::ios::end); - size_t size = inventory_file.tellg(); + size_t size = static_cast(inventory_file.tellg()); std::string buffer(size, '\0'); inventory_file.seekg(0); // Read it entirely, if the .json file gets too big, diff --git a/dll/source_query.cpp b/dll/source_query.cpp index c8318090..300c4d5f 100644 --- a/dll/source_query.cpp +++ b/dll/source_query.cpp @@ -133,7 +133,7 @@ void get_challenge(std::vector &challenge_buff) std::vector Source_Query::handle_source_query(const void* buffer, size_t len, Gameserver const& gs) { - std::vector output_buffer; + std::vector output_buffer{}; if (len < source_query_header_size) // its not at least 5 bytes long (0xFF 0xFF 0xFF 0xFF 0x??) return output_buffer; @@ -206,7 +206,7 @@ std::vector Source_Query::handle_source_query(const void* buffer, size_ serialize_response(output_buffer, source_response_header::A2S_PLAYER); serialize_response(output_buffer, static_cast(players.size())); // num_players - for (int i = 0; i < players.size(); ++i) { + for (unsigned i = 0; i < players.size(); ++i) { serialize_response(output_buffer, static_cast(i)); // player index serialize_response(output_buffer, players[i].second.name); // player name serialize_response(output_buffer, players[i].second.score); // player score diff --git a/dll/steam_apps.cpp b/dll/steam_apps.cpp index 45515f38..94d39a5f 100644 --- a/dll/steam_apps.cpp +++ b/dll/steam_apps.cpp @@ -243,11 +243,12 @@ bool Steam_Apps::GetCurrentBetaName( char *pchName, int cchNameBufferSize ) { PRINT_DEBUG("%p [%i]", pchName, cchNameBufferSize); std::lock_guard lock(global_mutex); - if (pchName && cchNameBufferSize > settings->current_branch_name.size()) { + if (pchName && cchNameBufferSize > 0 && static_cast(cchNameBufferSize) > settings->current_branch_name.size()) { memset(pchName, 0, cchNameBufferSize); memcpy(pchName, settings->current_branch_name.c_str(), settings->current_branch_name.size()); } + PRINT_DEBUG("returned '%s'", pchName); return settings->is_beta_branch; } diff --git a/dll/steam_friends.cpp b/dll/steam_friends.cpp index ad823e18..efc564e6 100644 --- a/dll/steam_friends.cpp +++ b/dll/steam_friends.cpp @@ -272,7 +272,11 @@ CSteamID Steam_Friends::GetFriendByIndex( int iFriend, int iFriendFlags ) PRINT_DEBUG_ENTRY(); std::lock_guard lock(global_mutex); CSteamID id = k_steamIDNil; - if (ok_friend_flags(iFriendFlags)) if (iFriend < friends.size()) id = CSteamID((uint64)friends[iFriend].id()); + if (ok_friend_flags(iFriendFlags)) { + if (iFriend >= 0 && static_cast(iFriend) < friends.size()) { + id = CSteamID((uint64)friends[iFriend].id()); + } + } return id; } @@ -933,7 +937,7 @@ const char* Steam_Friends::GetFriendRichPresenceKeyByIndex( CSteamID steamIDFrie f = find_friend(steamIDFriend); } - if (f && is_appid_compatible(f) && f->rich_presence().size() > iKey && iKey >= 0) { + if (iKey >= 0 && f && is_appid_compatible(f) && f->rich_presence().size() > static_cast(iKey)) { auto friend_data = f->rich_presence().begin(); for (int i = 0; i < iKey; ++i) ++friend_data; key = friend_data->first.c_str(); diff --git a/dll/steam_gameserver.cpp b/dll/steam_gameserver.cpp index 7b7a3c28..78c8fe82 100644 --- a/dll/steam_gameserver.cpp +++ b/dll/steam_gameserver.cpp @@ -726,10 +726,14 @@ int Steam_GameServer::GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *p PRINT_DEBUG_ENTRY(); std::lock_guard lock(global_mutex); if (settings->disable_source_query) return 0; - if (outgoing_packets.size() == 0) return 0; + if (outgoing_packets.empty()) return 0; - if (outgoing_packets.back().data.size() < cbMaxOut) cbMaxOut = static_cast(outgoing_packets.back().data.size()); - if (pOut) memcpy(pOut, outgoing_packets.back().data.data(), cbMaxOut); + if (cbMaxOut > 0) { + if (outgoing_packets.back().data.size() < static_cast(cbMaxOut)) { + cbMaxOut = static_cast(outgoing_packets.back().data.size()); + } + if (pOut) memcpy(pOut, outgoing_packets.back().data.data(), cbMaxOut); + } if (pNetAdr) *pNetAdr = outgoing_packets.back().ip; if (pPort) *pPort = outgoing_packets.back().port; outgoing_packets.pop_back(); diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index 92fe920c..8f2adfc8 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -63,7 +63,7 @@ HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, request.response.resize(file_size); long long read = Local_Storage::get_file_data(file_path, (char *)&request.response[0], file_size, 0); if (read < 0) read = 0; - if (read != file_size) request.response.resize(read); + if (read != file_size) request.response.resize(static_cast(read)); } } @@ -318,7 +318,7 @@ void Steam_HTTP::online_http_request(Steam_Http_Request *request, SteamAPICall_t if (file_size) { long long read = Local_Storage::get_file_data(request->target_filepath, (char *)&request->response[0], file_size, 0); if (read < 0) read = 0; - request->response.resize(read); + request->response.resize(static_cast(read)); } send_callresult(); diff --git a/dll/steam_matchmaking.cpp b/dll/steam_matchmaking.cpp index 735c431b..ebbf8f16 100644 --- a/dll/steam_matchmaking.cpp +++ b/dll/steam_matchmaking.cpp @@ -291,7 +291,7 @@ int Steam_Matchmaking::GetFavoriteGameCount() { PRINT_DEBUG_ENTRY(); std::string file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser_favorites.txt"; - unsigned long long file_size = file_size_(file_path); + unsigned int file_size = file_size_(file_path); if (file_size) { std::string list{}; list.resize(file_size); @@ -321,35 +321,32 @@ int Steam_Matchmaking::AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConn { PRINT_DEBUG("%u %u %hu %hu %u %u", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer); - std::string file_path; - unsigned long long file_size; + std::string file_path{}; + unsigned int file_size{}; if (unFlags == 1) { file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser_favorites.txt"; file_size = file_size_(file_path); - } - else if (unFlags == 2) { + } else if (unFlags == 2) { file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser_history.txt"; file_size = file_size_(file_path); - } - else { + } else { return 0; } - unsigned char ip[4]; + unsigned char ip[4]{}; ip[0] = nIP & 0xFF; ip[1] = (nIP >> 8) & 0xFF; ip[2] = (nIP >> 16) & 0xFF; ip[3] = (nIP >> 24) & 0xFF; - char newip[24]; + char newip[24]{}; snprintf(newip, sizeof(newip), "%d.%d.%d.%d:%d\n", ip[3], ip[2], ip[1], ip[0], nConnPort); - std::string newip_string; - newip_string.append(newip); + std::string newip_string(newip); if (file_size) { std::string list{}; list.resize(file_size); - Local_Storage::get_file_data(file_path, (char *)&list[0], file_size, 0); + Local_Storage::get_file_data(file_path, (char*)&list[0], file_size, 0); auto list_lines = std::count(list.begin(), list.end(), '\n'); list_lines += (!list.empty() && list.back() != '\n'); @@ -358,7 +355,7 @@ int Steam_Matchmaking::AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConn list.append(newip_string); list.append("\n"); - std::size_t file_directory = file_path.rfind("/"); + std::size_t file_directory = file_path.find_last_of("/\\"); std::string directory_path; std::string file_name; if (file_directory != std::string::npos) { @@ -371,11 +368,10 @@ int Steam_Matchmaking::AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConn } return list_lines; - } - else { + } else { newip_string.append("\n"); - std::size_t file_directory = file_path.rfind("/"); + std::size_t file_directory = file_path.find_last_of("/\\"); std::string directory_path; std::string file_name; if (file_directory != std::string::npos) { @@ -394,43 +390,40 @@ bool Steam_Matchmaking::RemoveFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 n { PRINT_DEBUG_ENTRY(); - std::string file_path; - unsigned long long file_size; + std::string file_path{}; + unsigned int file_size{}; if (unFlags == 1) { file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + "serverbrowser_favorites.txt"; file_size = file_size_(file_path); - } - else if (unFlags == 2) { + } else if (unFlags == 2) { file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + "serverbrowser_history.txt"; file_size = file_size_(file_path); - } - else { + } else { return false; } if (file_size) { std::string list{}; list.resize(file_size); - Local_Storage::get_file_data(file_path, (char *)&list[0], file_size, 0); + Local_Storage::get_file_data(file_path, (char*)&list[0], file_size, 0); - unsigned char ip[4]; + unsigned char ip[4]{}; ip[0] = nIP & 0xFF; ip[1] = (nIP >> 8) & 0xFF; ip[2] = (nIP >> 16) & 0xFF; ip[3] = (nIP >> 24) & 0xFF; - char newip[24]; + char newip[24]{}; snprintf((char *)newip, sizeof(newip), "%d.%d.%d.%d:%d\n", ip[3], ip[2], ip[1], ip[0], nConnPort); - std::string newip_string; - newip_string.append(newip); + std::string newip_string(newip); std::size_t list_ip = list.find(newip_string); if (list_ip != std::string::npos) { list.erase(list_ip, newip_string.length()); - std::size_t file_directory = file_path.rfind("/"); - std::string directory_path; - std::string file_name; + std::size_t file_directory = file_path.find_last_of("/\\"); + std::string directory_path{}; + std::string file_name{}; if (file_directory != std::string::npos) { directory_path = file_path.substr(0, file_directory); file_name = file_path.substr(file_directory); @@ -600,7 +593,9 @@ CSteamID Steam_Matchmaking::GetLobbyByIndex( int iLobby ) PRINT_DEBUG("%i", iLobby); std::lock_guard lock(global_mutex); CSteamID id = k_steamIDNil; - if (0 <= iLobby && iLobby < filtered_lobbies.size()) id = filtered_lobbies[iLobby]; + if (iLobby >= 0 && static_cast(iLobby) < filtered_lobbies.size()) { + id = filtered_lobbies[iLobby]; + } PRINT_DEBUG("found lobby %llu", id.ConvertToUint64()); return id; } @@ -868,7 +863,7 @@ bool Steam_Matchmaking::GetLobbyDataByIndex( CSteamID steamIDLobby, int iLobbyDa Lobby *lobby = get_lobby(steamIDLobby); bool ret = false; - if (lobby && lobby->values().size() > iLobbyData && iLobbyData >= 0) { + if (iLobbyData >= 0 && lobby && lobby->values().size() > static_cast(iLobbyData)) { auto lobby_data = lobby->values().begin(); for (int i = 0; i < iLobbyData; ++i) ++lobby_data; if (pchKey && cchKeyBufferSize > 0) { @@ -914,7 +909,7 @@ const char* Steam_Matchmaking::GetLobbyMemberData( CSteamID steamIDLobby, CSteam std::lock_guard lock(global_mutex); if (!pchKey) return ""; - struct Lobby_Member *member = get_lobby_member(get_lobby(steamIDLobby), steamIDUser); + Lobby_Member *member = get_lobby_member(get_lobby(steamIDLobby), steamIDUser); const char *ret = ""; if (member) { if (steamIDUser == settings->get_local_steam_id()) { @@ -1009,12 +1004,12 @@ int Steam_Matchmaking::GetLobbyChatEntry( CSteamID steamIDLobby, int iChatID, ST { PRINT_DEBUG("%llu %i %p %p %i %p", steamIDLobby.ConvertToUint64(), iChatID, pSteamIDUser, pvData, cubData, peChatEntryType); std::lock_guard lock(global_mutex); - if (iChatID >= chat_entries.size() || iChatID < 0 || cubData < 0) return 0; + if (iChatID < 0 || cubData < 0 || static_cast(iChatID) >= chat_entries.size()) return 0; if (chat_entries[iChatID].lobby_id != steamIDLobby) return 0; if (pSteamIDUser) *pSteamIDUser = chat_entries[iChatID].user_id; if (peChatEntryType) *peChatEntryType = chat_entries[iChatID].type; if (pvData) { - if (chat_entries[iChatID].message.size() <= cubData) { + if (chat_entries[iChatID].message.size() <= static_cast(cubData)) { cubData = chat_entries[iChatID].message.size(); memcpy(pvData, chat_entries[iChatID].message.data(), cubData); PRINT_DEBUG(" Returned chat of len: %i", cubData); @@ -1357,7 +1352,7 @@ void Steam_Matchmaking::RunCallbacks() int compare_to = 0; //TODO: check if this is how real steam behaves if (value->second.size()) { - compare_to = std::stoll(value->second, 0, 0); + compare_to = static_cast(std::stoll(value->second, 0, 0)); } PRINT_DEBUG("Compare Values %i %i", compare_to, f.value_int); if (f.eComparisonType == k_ELobbyComparisonEqual) { diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 76b9933f..b2fab9d5 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -104,8 +104,8 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS return id; } - std::string file_path; - unsigned long long file_size; + std::string file_path{}; + unsigned int file_size{}; if (type == eInternetServer || type == eSpectatorServer) { file_path = local_storage->get_current_save_directory() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser.txt"; file_size = file_size_(file_path); @@ -117,29 +117,29 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS file_size = file_size_(file_path); } - PRINT_DEBUG("list file '%s' [%llu bytes]", file_path.c_str(), file_size); + PRINT_DEBUG("list file '%s' [%u bytes]", file_path.c_str(), file_size); std::string list{}; if (file_size) { list.resize(file_size); - Local_Storage::get_file_data(file_path, (char *)&list[0], static_cast(file_size), 0); + Local_Storage::get_file_data(file_path, (char *)&list[0], file_size, 0); } else { return id; } std::istringstream list_ss(list); - std::string list_ip; + std::string list_ip{}; while (std::getline(list_ss, list_ip)) { if (list_ip.length() <= 0) continue; - unsigned int byte4, byte3, byte2, byte1, byte0; - uint32 ip_int; - uint16 port_int; - char newip[24]; + unsigned int byte4{}, byte3{}, byte2{}, byte1{}, byte0{}; + uint32 ip_int{}; + uint16 port_int{}; + char newip[24]{}; if (sscanf(list_ip.c_str(), "%u.%u.%u.%u:%u", &byte3, &byte2, &byte1, &byte0, &byte4) == 5) { ip_int = (byte3 << 24) + (byte2 << 16) + (byte1 << 8) + byte0; port_int = byte4; - unsigned char ip_tmp[4]; + unsigned char ip_tmp[4]{}; ip_tmp[0] = ip_int & 0xFF; ip_tmp[1] = (ip_int >> 8) & 0xFF; ip_tmp[2] = (ip_int >> 16) & 0xFF; @@ -390,7 +390,7 @@ gameserveritem_t *Steam_Matchmaking_Servers::GetServerDetails( HServerListReques ++g; } - if (iServer >= gameservers_filtered.size() || iServer < 0) { + if (iServer < 0 || static_cast(iServer) >= gameservers_filtered.size()) { return NULL; } @@ -593,14 +593,14 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t * if (settings->matchmaking_server_details_via_source_query && !(g->ip() < 0) && !(g->query_port() < 0)) { unsigned char ip[4]{}; - char newip[24]; + char newip[24]{}; ip[0] = g->ip() & 0xFF; ip[1] = (g->ip() >> 8) & 0xFF; ip[2] = (g->ip() >> 16) & 0xFF; ip[3] = (g->ip() >> 24) & 0xFF; snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); - PRINT_DEBUG(" connecting to ssq server on %s:%u", newip, g->query_port()); + PRINT_DEBUG(" connecting to ssq server on %s:%u", newip, g->query_port()); SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); if (ssq != NULL && ssq_server_eok(ssq)) { PRINT_DEBUG(" ssq server connection ok"); @@ -733,7 +733,8 @@ void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matc const auto &players = get_steam_client()->steam_gameserver->get_players(); auto player = players->cbegin(); for (uint32_t i = 0; i < number_players && player != players->end(); ++i, ++player) { - float playtime = static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - player->second.join_time).count()); + auto duration = std::chrono::duration_cast(std::chrono::steady_clock::now() - player->second.join_time); + float playtime = static_cast(duration.count()); PRINT_DEBUG(" PLAYER [%u] '%s' %u %f", i, player->second.name.c_str(), player->second.score, playtime); r->players_response->AddPlayerToList(player->second.name.c_str(), player->second.score, playtime); } diff --git a/dll/steam_networking_utils.cpp b/dll/steam_networking_utils.cpp index c83814a3..ab50947d 100644 --- a/dll/steam_networking_utils.cpp +++ b/dll/steam_networking_utils.cpp @@ -514,7 +514,7 @@ bool Steam_Networking_Utils::SteamNetworkingIPAddr_ParseString( SteamNetworkingI size_t sep_pos = 0; std::string ip; int sep_count = 0; - for (int i = 0; i < str.length(); ++i) { + for (unsigned i = 0; i < str.length(); ++i) { if (str[i] == ':') { sep_pos = i; ++sep_count; diff --git a/dll/steam_remote_storage.cpp b/dll/steam_remote_storage.cpp index 2ec8d5d9..79b92f98 100644 --- a/dll/steam_remote_storage.cpp +++ b/dll/steam_remote_storage.cpp @@ -147,15 +147,13 @@ bool Steam_Remote_Storage::FileReadAsyncComplete( SteamAPICall_t hReadCall, void if (cubToRead < a_read->to_read) return false; - char *temp = new char[a_read->size]; - int read_data = local_storage->get_data(Local_Storage::remote_storage_folder, a_read->file_name, (char* )temp, a_read->size); - if (read_data < a_read->to_read + a_read->offset) { - delete[] temp; + std::vector temp(a_read->size); + int read_data = local_storage->get_data(Local_Storage::remote_storage_folder, a_read->file_name, (char* )&temp[0], a_read->size); + if (read_data < 0 || (static_cast(read_data) < (a_read->to_read + a_read->offset))) { return false; } - memcpy(pvBuffer, temp + a_read->offset, a_read->to_read); - delete[] temp; + memcpy(pvBuffer, &temp[0] + a_read->offset, a_read->to_read); async_reads.erase(a_read); return true; } diff --git a/dll/steam_user.cpp b/dll/steam_user.cpp index 98b9e9d0..d0437173 100644 --- a/dll/steam_user.cpp +++ b/dll/steam_user.cpp @@ -426,18 +426,18 @@ SteamAPICall_t Steam_User::RequestEncryptedAppTicket( void *pDataToInclude, int // retrieve a finished ticket bool Steam_User::GetEncryptedAppTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) { - PRINT_DEBUG("%i", cbMaxTicket); - unsigned int ticket_size = static_cast(encrypted_app_ticket.size()); - if (!cbMaxTicket) { + PRINT_DEBUG("%i %p %p", cbMaxTicket, pTicket, pcbTicket); + uint32 ticket_size = static_cast(encrypted_app_ticket.size()); + if (pcbTicket) *pcbTicket = ticket_size; + + if (cbMaxTicket <= 0) { if (!pcbTicket) return false; - *pcbTicket = ticket_size; return true; } if (!pTicket) return false; - if (ticket_size > cbMaxTicket) return false; + if (ticket_size > static_cast(cbMaxTicket)) return false; encrypted_app_ticket.copy((char *)pTicket, cbMaxTicket); - if (pcbTicket) *pcbTicket = ticket_size; return true; } diff --git a/dll/steam_user_stats.cpp b/dll/steam_user_stats.cpp index 3a85c567..dbafa907 100644 --- a/dll/steam_user_stats.cpp +++ b/dll/steam_user_stats.cpp @@ -539,7 +539,7 @@ Steam_User_Stats::InternalSetResult(oldcount / oldsessionlength); memcpy(data, &average, sizeof(average)); memcpy(data + sizeof(float), &oldcount, sizeof(oldcount)); memcpy(data + sizeof(float) * 2, &oldsessionlength, sizeof(oldsessionlength)); @@ -1421,7 +1421,7 @@ const char * Steam_User_Stats::GetLeaderboardName( SteamLeaderboard_t hSteamLead std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return ""; - return cached_leaderboards[hSteamLeaderboard - 1].name.c_str(); + return cached_leaderboards[static_cast(hSteamLeaderboard - 1)].name.c_str(); } @@ -1432,7 +1432,7 @@ int Steam_User_Stats::GetLeaderboardEntryCount( SteamLeaderboard_t hSteamLeaderb std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return 0; - return (int)cached_leaderboards[hSteamLeaderboard - 1].entries.size(); + return (int)cached_leaderboards[static_cast(hSteamLeaderboard - 1)].entries.size(); } @@ -1443,7 +1443,7 @@ ELeaderboardSortMethod Steam_User_Stats::GetLeaderboardSortMethod( SteamLeaderbo std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return k_ELeaderboardSortMethodNone; - return cached_leaderboards[hSteamLeaderboard - 1].sort_method; + return cached_leaderboards[static_cast(hSteamLeaderboard - 1)].sort_method; } @@ -1454,7 +1454,7 @@ ELeaderboardDisplayType Steam_User_Stats::GetLeaderboardDisplayType( SteamLeader std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return k_ELeaderboardDisplayTypeNone; - return cached_leaderboards[hSteamLeaderboard - 1].display_type; + return cached_leaderboards[static_cast(hSteamLeaderboard - 1)].display_type; } @@ -1473,7 +1473,7 @@ SteamAPICall_t Steam_User_Stats::DownloadLeaderboardEntries( SteamLeaderboard_t std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return k_uAPICallInvalid; //might return callresult even if hSteamLeaderboard is invalid - int entries_count = (int)cached_leaderboards[hSteamLeaderboard - 1].entries.size(); + int entries_count = (int)cached_leaderboards[static_cast(hSteamLeaderboard - 1)].entries.size(); // https://partner.steamgames.com/doc/api/ISteamUserStats#ELeaderboardDataRequest if (eLeaderboardDataRequest != k_ELeaderboardDataRequestFriends) { int required_count = nRangeEnd - nRangeStart + 1; @@ -1502,7 +1502,7 @@ SteamAPICall_t Steam_User_Stats::DownloadLeaderboardEntriesForUsers( SteamLeader std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return k_uAPICallInvalid; //might return callresult even if hSteamLeaderboard is invalid - auto &board = cached_leaderboards[hSteamLeaderboard - 1]; + auto& board = cached_leaderboards[static_cast(hSteamLeaderboard - 1)]; bool ok = true; int total_count = 0; if (prgUsers && cUsers > 0) { @@ -1553,8 +1553,8 @@ bool Steam_User_Stats::GetDownloadedLeaderboardEntry( SteamLeaderboardEntries_t std::lock_guard lock(global_mutex); if (hSteamLeaderboardEntries > cached_leaderboards.size() || hSteamLeaderboardEntries <= 0) return false; - const auto &board = cached_leaderboards[hSteamLeaderboardEntries - 1]; - if (index < 0 || index >= board.entries.size()) return false; + const auto &board = cached_leaderboards[static_cast(hSteamLeaderboardEntries - 1)]; + if (index < 0 || static_cast(index) >= board.entries.size()) return false; const auto &target_entry = board.entries[index]; @@ -1568,7 +1568,7 @@ bool Steam_User_Stats::GetDownloadedLeaderboardEntry( SteamLeaderboardEntries_t } if (pDetails && cDetailsMax > 0) { - for (int i = 0; i < target_entry.score_details.size() && i < cDetailsMax; ++i) { + for (unsigned i = 0; i < target_entry.score_details.size() && i < static_cast(cDetailsMax); ++i) { pDetails[i] = target_entry.score_details[i]; } } @@ -1588,7 +1588,7 @@ SteamAPICall_t Steam_User_Stats::UploadLeaderboardScore( SteamLeaderboard_t hSte std::lock_guard lock(global_mutex); if (hSteamLeaderboard > cached_leaderboards.size() || hSteamLeaderboard <= 0) return k_uAPICallInvalid; //TODO: might return callresult even if hSteamLeaderboard is invalid - auto &board = cached_leaderboards[hSteamLeaderboard - 1]; + auto &board = cached_leaderboards[static_cast(hSteamLeaderboard - 1)]; auto my_entry = board.find_recent_entry(settings->get_local_steam_id()); int current_rank = my_entry ? 1 + (int)(my_entry - &board.entries[0]) @@ -1756,7 +1756,7 @@ int Steam_User_Stats::GetNextMostAchievedAchievementInfo( int iIteratorPrevious, std::lock_guard lock(global_mutex); if (iIteratorPrevious < 0) return -1; - int iIteratorCurrent = iIteratorPrevious + 1; + unsigned iIteratorCurrent = static_cast(iIteratorPrevious + 1); if (iIteratorCurrent >= defined_achievements.size()) return -1; std::string name(GetAchievementName(iIteratorCurrent)); @@ -1776,7 +1776,7 @@ int Steam_User_Stats::GetNextMostAchievedAchievementInfo( int iIteratorPrevious, *pbAchieved = achieved; } - return iIteratorCurrent; + return static_cast(iIteratorCurrent); } diff --git a/dll/steam_utils.cpp b/dll/steam_utils.cpp index 20d904fb..050b2543 100644 --- a/dll/steam_utils.cpp +++ b/dll/steam_utils.cpp @@ -82,7 +82,7 @@ bool Steam_Utils::GetImageSize( int iImage, uint32 *pnWidth, uint32 *pnHeight ) if (!iImage || !pnWidth || !pnHeight) return false; auto image = settings->images.find(iImage); - if (image == settings->images.end()) return false; + if (settings->images.end() == image) return false; *pnWidth = image->second.width; *pnHeight = image->second.height; @@ -94,16 +94,14 @@ bool Steam_Utils::GetImageSize( int iImage, uint32 *pnWidth, uint32 *pnHeight ) // the destination buffer size should be 4 * height * width * sizeof(char) bool Steam_Utils::GetImageRGBA( int iImage, uint8 *pubDest, int nDestBufferSize ) { - PRINT_DEBUG("%i", iImage); + PRINT_DEBUG("%i %p %i", iImage, pubDest, nDestBufferSize); std::lock_guard lock(global_mutex); - if (!iImage || !pubDest || !nDestBufferSize) return false; + if (!iImage || !pubDest || nDestBufferSize <= 0) return false; auto image = settings->images.find(iImage); - if (image == settings->images.end()) return false; + if (settings->images.end() == image) return false; - unsigned size = static_cast(image->second.data.size()); - if (nDestBufferSize < size) size = nDestBufferSize; image->second.data.copy((char *)pubDest, nDestBufferSize); return true; } @@ -111,7 +109,7 @@ bool Steam_Utils::GetImageRGBA( int iImage, uint8 *pubDest, int nDestBufferSize // returns the IP of the reporting server for valve - currently only used in Source engine games bool Steam_Utils::GetCSERIPPort( uint32 *unIP, uint16 *usPort ) { - PRINT_DEBUG_ENTRY(); + PRINT_DEBUG_TODO(); std::lock_guard lock(global_mutex); return false; } @@ -122,7 +120,7 @@ uint8 Steam_Utils::GetCurrentBatteryPower() { PRINT_DEBUG_ENTRY(); std::lock_guard lock(global_mutex); - return 255; + return 255; // AC }