From 1b04526d9d98cfcf21afb1b785c4d0f5f91c5a63 Mon Sep 17 00:00:00 2001 From: otavepto Date: Thu, 21 Dec 2023 03:20:32 +0200 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFfixed=20all=20printf=20warnings=20for?= =?UTF-8?q?=20Linux=20&=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dll/common_includes.h | 3 +++ dll/flat.cpp | 3 ++- dll/network.cpp | 11 ++++++----- dll/steam_friends.h | 4 ++-- dll/steam_matchmaking.h | 14 +++++++------- dll/steam_matchmaking_servers.cpp | 14 +++++++------- dll/steam_networking.h | 6 +++--- dll/steam_networking_sockets.h | 8 ++++---- dll/steam_networking_utils.h | 2 +- dll/steam_utils.h | 2 +- 10 files changed, 36 insertions(+), 31 deletions(-) diff --git a/dll/common_includes.h b/dll/common_includes.h index 31ffccf1..59c51fbd 100644 --- a/dll/common_includes.h +++ b/dll/common_includes.h @@ -168,6 +168,9 @@ static inline void reset_LastError() // PRINT_DEBUG definition // notice the extra call to WSASetLastError(0) in Windows def #ifndef EMU_RELEASE_BUILD + // we need this for printf specifiers for intptr_t such as PRIdPTR + #include + //#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__) extern const std::string dbg_log_file; extern const std::chrono::time_point startup_counter; diff --git a/dll/flat.cpp b/dll/flat.cpp index 568a0540..d317cf89 100644 --- a/dll/flat.cpp +++ b/dll/flat.cpp @@ -6697,7 +6697,8 @@ STEAMAPI_API void *SteamAPI_ISteamGameServer_GetPublicIP( intptr_t instancePtr, get_steam_client()->steam_gameserver->GetPublicIP_fix((SteamIPAddress_t *)instancePtr); return (void *)instancePtr; } else { - return (void *)((ISteamGameServer012 *)instancePtr)->GetPublicIP_old(); + // (char*)0 will silence the compiler warning + return (void *)( (char*)0 + ((ISteamGameServer012 *)instancePtr)->GetPublicIP_old() ); } } diff --git a/dll/network.cpp b/dll/network.cpp index 7c681283..520422e7 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -459,7 +459,7 @@ static bool unbuffer_tcp(struct TCP_Socket &socket, Common_Message *msg) socket.recv_buffer.erase(socket.recv_buffer.begin(), socket.recv_buffer.begin() + sizeof(l) + l); return true; } else { - PRINT_DEBUG("BAD TCP DATA %lu %zu %zu %hhu\n", l, socket.recv_buffer.size(), sizeof(uint32), *((char *)&(socket.recv_buffer[sizeof(uint32)]))); + PRINT_DEBUG("BAD TCP DATA %u %zu %zu %hhu\n", l, socket.recv_buffer.size(), sizeof(uint32), *((char *)&(socket.recv_buffer[sizeof(uint32)]))); kill_tcp_socket(socket); } @@ -514,7 +514,8 @@ std::set Networking::resolve_ip(std::string dns) if (getaddrinfo(dns.c_str(), NULL, NULL, &result) == 0) { for (struct addrinfo *res = result; res != NULL; res = res->ai_next) { - PRINT_DEBUG("%zu %u\n", res->ai_addrlen, res->ai_family); + // cast to size_t because on Linux 'ai_addrlen' is defined as unsigned int and clang complains + PRINT_DEBUG("%zu %u\n", (size_t)res->ai_addrlen, res->ai_family); if (res->ai_family == AF_INET) { struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr; uint32 ip; @@ -675,7 +676,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port) PRINT_DEBUG("New Connection Created\n"); } - PRINT_DEBUG("Handle Announce: %lu, %llu, %lu, %u\n", conn->appid, msg->source_id(), msg->announce().appid(), msg->announce().type()); + PRINT_DEBUG("Handle Announce: %u, " "%" PRIu64 ", %u, %u\n", conn->appid, msg->source_id(), msg->announce().appid(), msg->announce().type()); conn->tcp_ip_port = ip_port; conn->tcp_ip_port.port = htons(msg->announce().tcp_port()); conn->appid = msg->announce().appid(); @@ -692,7 +693,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port) } Connection *conn = find_connection((uint64)msg->announce().peers(i).id(), msg->announce().peers(i).appid()); - PRINT_DEBUG("%p %lu %lu %llu\n", conn, conn ? conn->appid : 0, msg->announce().peers(i).appid(), msg->announce().peers(i).id()); + PRINT_DEBUG("%p %u %u " "%" PRIu64 "\n", conn, conn ? conn->appid : (uint32)0, msg->announce().peers(i).appid(), msg->announce().peers(i).id()); if (!conn || conn->appid != msg->announce().peers(i).appid()) { Common_Message msg_ = create_announce(true); @@ -882,7 +883,7 @@ Common_Message Networking::create_announce(bool request) } else { announce->set_type(Announce::PONG); for (auto &conn: connections) { - PRINT_DEBUG("Connection %u %llu %lu\n", conn.udp_pinged, conn.ids[0].ConvertToUint64(), conn.appid); + PRINT_DEBUG("Connection %u %llu %u\n", conn.udp_pinged, conn.ids[0].ConvertToUint64(), conn.appid); if (conn.udp_pinged) { Announce_Other_Peers *peer = announce->add_peers(); peer->set_id(conn.ids[0].ConvertToUint64()); diff --git a/dll/steam_friends.h b/dll/steam_friends.h index 1f7ed2ee..6313f3cc 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -412,7 +412,7 @@ bool GetFriendGamePlayed( CSteamID steamIDFriend, STEAM_OUT_STRUCT() FriendGameI pFriendGameInfo->m_usGamePort = 0; pFriendGameInfo->m_usQueryPort = 0; pFriendGameInfo->m_steamIDLobby = CSteamID((uint64)f->lobby_id()); - PRINT_DEBUG("%u %llu\n", f->appid(), f->lobby_id()); + PRINT_DEBUG("%u " "%" PRIu64 "\n", f->appid(), f->lobby_id()); } ret = true; @@ -1206,7 +1206,7 @@ void Callback(Common_Message *msg) } if (msg->has_friend_()) { - PRINT_DEBUG("Steam_Friends Friend %llu %llu\n", msg->friend_().id(), msg->friend_().lobby_id()); + PRINT_DEBUG("Steam_Friends Friend " "%" PRIu64 " " "%" PRIu64 "\n", msg->friend_().id(), msg->friend_().lobby_id()); Friend *f = find_friend((uint64)msg->friend_().id()); if (!f) { if (msg->friend_().id() != settings->get_local_steam_id().ConvertToUint64()) { diff --git a/dll/steam_matchmaking.h b/dll/steam_matchmaking.h index 4b4e811e..6f98f2bd 100644 --- a/dll/steam_matchmaking.h +++ b/dll/steam_matchmaking.h @@ -127,7 +127,7 @@ void send_lobby_data() for(auto & l: lobbies) { if (get_lobby_member(&l, settings->get_local_steam_id()) && l.owner() == settings->get_local_steam_id().ConvertToUint64() && !l.deleted()) { - PRINT_DEBUG("Sending lobby %llu\n", l.room_id()); + PRINT_DEBUG("Sending lobby " "%" PRIu64 "\n", l.room_id()); Common_Message msg = Common_Message(); msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); msg.set_allocated_lobby(new Lobby(l)); @@ -264,7 +264,7 @@ void remove_lobbies() auto g = std::begin(lobbies); while (g != std::end(lobbies)) { if (g->members().size() == 0 || (g->deleted() && (g->time_deleted() + LOBBY_DELETED_TIMEOUT < current_time))) { - PRINT_DEBUG("REMOVING LOBBY %llu\n", g->room_id()); + PRINT_DEBUG("REMOVING LOBBY " "%" PRIu64 "\n", g->room_id()); self_lobby_member_data.erase(g->room_id()); g = lobbies.erase(g); } else { @@ -372,7 +372,7 @@ bool GetFavoriteGame( int iGame, AppId_t *pnAppID, uint32 *pnIP, uint16 *pnConnP // adds the game server to the local list; updates the time played of the server if it already exists in the list int AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConnPort, uint16 nQueryPort, uint32 unFlags, uint32 rTime32LastPlayedOnServer ) { - PRINT_DEBUG("AddFavoriteGame %lu %lu %hu %hu %lu %lu\n", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer); + PRINT_DEBUG("AddFavoriteGame %u %u %hu %hu %u %u\n", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer); std::string file_path; unsigned long long file_size; @@ -1406,7 +1406,7 @@ void RunCallbacks() } } - PRINT_DEBUG("Lobby %llu use %u\n", l.room_id(), use); + PRINT_DEBUG("Lobby " "%" PRIu64 " use %u\n", l.room_id(), use); if (use) PUSH_BACK_IF_NOT_IN(filtered_lobbies, (uint64)l.room_id()); if (filtered_lobbies.size() >= filter_max_results_copy) { searching = false; @@ -1501,7 +1501,7 @@ void RunCallbacks() void Callback(Common_Message *msg) { if (msg->has_lobby()) { - PRINT_DEBUG("GOT A LOBBY appid: %lu\n", msg->lobby().appid()); + PRINT_DEBUG("GOT A LOBBY appid: %u\n", msg->lobby().appid()); if (msg->lobby().owner() != settings->get_local_steam_id().ConvertToUint64() && msg->lobby().appid() == settings->get_local_game_id().AppID()) { Lobby *lobby = get_lobby((uint64)msg->lobby().room_id()); if (!lobby) { @@ -1588,7 +1588,7 @@ void Callback(Common_Message *msg) if (msg->has_lobby_messages()) { - PRINT_DEBUG("LOBBY MESSAGE %u %llu\n", msg->lobby_messages().type(), msg->lobby_messages().id()); + PRINT_DEBUG("LOBBY MESSAGE %u " "%" PRIu64 "\n", msg->lobby_messages().type(), msg->lobby_messages().id()); Lobby *lobby = get_lobby((uint64)msg->lobby_messages().id()); if (lobby && !lobby->deleted()) { bool we_are_in_lobby = !!get_lobby_member(lobby, settings->get_local_steam_id()); @@ -1620,7 +1620,7 @@ void Callback(Common_Message *msg) } if (msg->lobby_messages().type() == Lobby_Messages::LEAVE) { - PRINT_DEBUG("LOBBY MESSAGE: LEAVE %llu\n", msg->source_id()); + PRINT_DEBUG("LOBBY MESSAGE: LEAVE " "%" PRIu64 "\n", msg->source_id()); leave_lobby(lobby, (uint64)msg->source_id()); if (we_are_in_lobby) trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)msg->source_id(), true, true, 0.2); } diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 12e52acc..944b8667 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -48,7 +48,7 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS request.type = type; requests.push_back(request); ++server_list_request; - requests[requests.size() - 1].id = (void *)server_list_request; + requests[requests.size() - 1].id = (char *)0 + server_list_request; // (char *)0 silences the compiler warning HServerListRequest id = requests[requests.size() - 1].id; PRINT_DEBUG("request id: %p\n", id); @@ -420,7 +420,7 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t * server->m_nServerVersion = g->version(); server->SetName(g->server_name().c_str()); server->m_steamID = CSteamID((uint64)g->id()); - PRINT_DEBUG("server_details %llu\n", g->id()); + PRINT_DEBUG("server_details " "%" PRIu64 "\n", g->id()); strncpy(server->m_szGameTags, g->tags().c_str(), k_cbMaxGameServerTags - 1); server->m_szGameTags[k_cbMaxGameServerTags - 1] = 0; @@ -457,7 +457,7 @@ void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matc if (ssq != NULL) ssq_server_free(ssq); } - PRINT_DEBUG("server_details_players %llu\n", g->id()); + PRINT_DEBUG("server_details_players " "%" PRIu64 "\n", g->id()); } void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r) @@ -491,7 +491,7 @@ void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchm if (ssq != NULL) ssq_server_free(ssq); } - PRINT_DEBUG("server_details_rules %llu\n", g->id()); + PRINT_DEBUG("server_details_rules " "%" PRIu64 "\n", g->id()); } // Get details on a given server in the list, you can get the valid range of index @@ -746,9 +746,9 @@ void Steam_Matchmaking_Servers::RunCallbacks() } for (auto &r : direct_ip_requests_temp) { - PRINT_DEBUG("dip request: %lu:%hu\n", r.ip, r.port); + PRINT_DEBUG("dip request: %u:%hu\n", r.ip, r.port); for (auto &g : gameservers) { - PRINT_DEBUG("server: %lu:%hu\n", g.server.ip(), g.server.query_port()); + PRINT_DEBUG("server: %u:%u\n", g.server.ip(), g.server.query_port()); uint16 query_port = g.server.query_port(); if (query_port == 0xFFFF) { query_port = g.server.port(); @@ -785,7 +785,7 @@ void Steam_Matchmaking_Servers::RunCallbacks() void Steam_Matchmaking_Servers::Callback(Common_Message *msg) { if (msg->has_gameserver() && msg->gameserver().type() != eFriendsServer) { - PRINT_DEBUG("got SERVER %llu, offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); + PRINT_DEBUG("got SERVER " "%" PRIu64 ", offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); if (msg->gameserver().offline()) { for (auto &g : gameservers) { if (g.server.id() == msg->gameserver().id()) { diff --git a/dll/steam_networking.h b/dll/steam_networking.h index 4a19845e..3fae0f12 100644 --- a/dll/steam_networking.h +++ b/dll/steam_networking.h @@ -317,7 +317,7 @@ bool IsP2PPacketAvailable( uint32 *pcubMsgSize, int nChannel) if (connection_exists((uint64)msg.source_id()) && msg.mutable_network()->channel() == nChannel && msg.network().processed()) { uint32 size = msg.mutable_network()->data().size(); if (pcubMsgSize) *pcubMsgSize = size; - PRINT_DEBUG("available with size: %lu\n", size); + PRINT_DEBUG("available with size: %u\n", size); return true; } } @@ -362,7 +362,7 @@ bool ReadP2PPacket( void *pubDest, uint32 cubDest, uint32 *pcubMsgSize, CSteamID }PRINT_DEBUG("\n"); #endif *psteamIDRemote = CSteamID((uint64)msg->source_id()); - PRINT_DEBUG("Steam_Networking::ReadP2PPacket len %u channel: %u from: %llu\n", msg_size, nChannel, msg->source_id()); + PRINT_DEBUG("Steam_Networking::ReadP2PPacket len %u channel: %u from: " "%" PRIu64 "\n", msg_size, nChannel, msg->source_id()); msg = messages.erase(msg); return true; } @@ -907,7 +907,7 @@ void Callback(Common_Message *msg) { if (msg->has_network()) { #ifndef EMU_RELEASE_BUILD - PRINT_DEBUG("Steam_Networking: got msg from: %llu to: %llu size %zu type %u | messages %p: %zu\n", msg->source_id(), msg->dest_id(), msg->network().data().size(), msg->network().type(), &messages, messages.size()); + PRINT_DEBUG("Steam_Networking: got msg from: " "%" PRIu64 " to: " "%" PRIu64 " size %zu type %u | messages %p: %zu\n", msg->source_id(), msg->dest_id(), msg->network().data().size(), msg->network().type(), &messages, messages.size()); for (int i = 0; i < msg->network().data().size(); ++i) { PRINT_DEBUG("%02hhX", msg->network().data().data()[i]); }PRINT_DEBUG("\n"); diff --git a/dll/steam_networking_sockets.h b/dll/steam_networking_sockets.h index fb60b099..3b035507 100644 --- a/dll/steam_networking_sockets.h +++ b/dll/steam_networking_sockets.h @@ -881,7 +881,7 @@ SteamNetworkingMessage_t *get_steam_message_connection(HSteamNetConnection hConn pMsg->m_pfnRelease = &delete_steam_message; pMsg->m_nChannel = 0; connect_socket->second.data.pop(); - PRINT_DEBUG("get_steam_message_connection %u %lu, %I64\n", hConn, size, pMsg->m_nMessageNumber); + PRINT_DEBUG("get_steam_message_connection %u %lu, %llu\n", hConn, size, pMsg->m_nMessageNumber); return pMsg; } @@ -2054,7 +2054,7 @@ void Callback(Common_Message *msg) } if (msg->has_networking_sockets()) { - PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u %llu\n", msg->networking_sockets().type(), msg->source_id()); + PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u " "%" PRIu64 "\n", msg->networking_sockets().type(), msg->source_id()); if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_REQUEST) { int virtual_port = msg->networking_sockets().virtual_port(); int real_port = msg->networking_sockets().real_port(); @@ -2093,13 +2093,13 @@ void Callback(Common_Message *msg) auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id()); if (connect_socket != s->connect_sockets.end()) { if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && (connect_socket->second.status == CONNECT_SOCKET_CONNECTED)) { - PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first); + PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num " "%" PRIu64 " on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first); connect_socket->second.data.push(msg->networking_sockets()); } } else { connect_socket = std::find_if(s->connect_sockets.begin(), s->connect_sockets.end(), [msg](const auto &in) {return in.second.remote_identity.GetSteamID64() == msg->source_id() && (in.second.status == CONNECT_SOCKET_NOT_ACCEPTED || in.second.status == CONNECT_SOCKET_CONNECTED) && in.second.remote_id == msg->networking_sockets().connection_id_from();}); if (connect_socket != s->connect_sockets.end()) { - PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first); + PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num " "%" PRIu64 " on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first); connect_socket->second.data.push(msg->networking_sockets()); } } diff --git a/dll/steam_networking_utils.h b/dll/steam_networking_utils.h index 4a0aa814..782690fb 100644 --- a/dll/steam_networking_utils.h +++ b/dll/steam_networking_utils.h @@ -358,7 +358,7 @@ bool SetConnectionConfigValueString( HSteamNetConnection hConn, ESteamNetworking bool SetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj, ESteamNetworkingConfigDataType eDataType, const void *pArg ) { - PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i %tf %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg); + PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i " "%" PRIdPTR " %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg); return true; } diff --git a/dll/steam_utils.h b/dll/steam_utils.h index feb8d2cd..ca15d523 100644 --- a/dll/steam_utils.h +++ b/dll/steam_utils.h @@ -72,7 +72,7 @@ uint32 GetServerRealTime() { PRINT_DEBUG("GetServerRealTime\n"); uint32 server_time = std::chrono::duration_cast>(std::chrono::system_clock::now().time_since_epoch()).count(); - PRINT_DEBUG("Time %lu\n", server_time); + PRINT_DEBUG("Time %u\n", server_time); return server_time; }