From b093ca90d3e32aae681cb6bf720d6b2778402f7d Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Sun, 16 Jun 2019 15:12:22 +0200 Subject: [PATCH 1/8] Fix issue #14 This commit fixes game crash in ETS2. The parameter order is wrong, 1st param is what to replace and 2nd param is with what to replace. --- dll/local_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 80f815c..fbc543e 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -636,7 +636,7 @@ bool Local_Storage::iterate_file(std::string folder, int index, char *output_fil std::string name = desanitize_file_name(files[index].name); if (output_size) *output_size = file_size(folder, name); #if defined(STEAM_WIN32) - name = replace_with(name, PATH_SEPARATOR, "/"); + name = replace_with(name, "/", PATH_SEPARATOR); #endif strcpy(output_filename, name.c_str()); return true; From e54072918ff3a2d3cfd8618b3acb9afa1120bed2 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Mon, 17 Jun 2019 23:08:23 +0200 Subject: [PATCH 2/8] Added check on directory in Local_Storage::file_exists Added check on directory in Local_Storage::file_exists. Added check in get_filenames_recursive if last char is the path separator (some use cases were adding a path separator even if there were already one). In base.h, added check on s and r, that will avoid an out-of-range vector exception on Visual Studio, same for network.cpp. --- dll/base.h | 3 ++- dll/local_storage.cpp | 11 +++++++++-- dll/network.cpp | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dll/base.h b/dll/base.h index 7e08258..5999799 100644 --- a/dll/base.h +++ b/dll/base.h @@ -93,7 +93,8 @@ struct Steam_Call_Result { Steam_Call_Result(SteamAPICall_t a, int icb, void *r, unsigned int s, double r_in, bool run_cc_cb) { api_call = a; result.resize(s); - memcpy(&(result[0]), r, s); + if (s > 0 && r != NULL) + memcpy(&(result[0]), r, s); created = std::chrono::high_resolution_clock::now(); run_in = r_in; run_call_completed_cb = run_cc_cb; diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index fbc543e..c68979f 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -192,6 +192,8 @@ static std::vector get_filenames(std::string strPath) static std::vector get_filenames_recursive(std::string base_path) { + if (base_path.back() == *PATH_SEPARATOR) + base_path.pop_back(); std::vector output; std::string strPath = base_path; strPath = strPath.append("\\*"); @@ -211,10 +213,11 @@ static std::vector get_filenames_recursive(std::string base_pa std::string dir_name = ffd.cFileName; std::string path = base_path; - path += "\\"; + path += PATH_SEPARATOR; path += dir_name; std::vector lower = get_filenames_recursive(path); + // output.push_back(File_Data{ dir_name }); Is this needed ? Add folder name to the list of files ? std::transform(lower.begin(), lower.end(), std::back_inserter(output), [dir_name](File_Data f) {f.name = dir_name + "\\" + f.name; return f;}); } else { File_Data f; @@ -584,6 +587,10 @@ bool Local_Storage::file_exists(std::string folder, std::string file) std::string full_path = save_directory + appid + folder + file; struct stat buffer; + + if (GetFileAttributes(full_path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) + return false; + return (stat (full_path.c_str(), &buffer) == 0); } @@ -636,7 +643,7 @@ bool Local_Storage::iterate_file(std::string folder, int index, char *output_fil std::string name = desanitize_file_name(files[index].name); if (output_size) *output_size = file_size(folder, name); #if defined(STEAM_WIN32) - name = replace_with(name, "/", PATH_SEPARATOR); + name = replace_with(name, PATH_SEPARATOR, "/"); #endif strcpy(output_filename, name.c_str()); return true; diff --git a/dll/network.cpp b/dll/network.cpp index db87adc..b85ce3f 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -379,7 +379,10 @@ unsigned int receive_buffer_amount(sock_t sock) static void send_tcp_pending(struct TCP_Socket &socket) { - int len = send(socket.sock, &(socket.send_buffer[0]), socket.send_buffer.size(), MSG_NOSIGNAL); + size_t buf_size = socket.send_buffer.size(); + if (buf_size == 0) return; + + int len = send(socket.sock, &(socket.send_buffer[0]), buf_size, MSG_NOSIGNAL); if (len <= 0) return; socket.send_buffer.erase(socket.send_buffer.begin(), socket.send_buffer.begin() + len); From b034ee878166f92848d414eda3afc94a77a6ad93 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Tue, 18 Jun 2019 00:25:56 +0200 Subject: [PATCH 3/8] Changed param source in strncpy In strncpy its the destination size that should be in the 3rd parameter. --- dll/net.proto | 6 +++++- dll/steam_friends.h | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dll/net.proto b/dll/net.proto index a6d6414..9808822 100644 --- a/dll/net.proto +++ b/dll/net.proto @@ -176,10 +176,14 @@ message Auth_Ticket { message Friend_Messages { enum Types { LOBBY_INVITE = 0; + GAME_INVITE = 1; } Types type = 1; - uint64 lobby_id = 2; + oneof invite_data { + uint64 lobby_id = 2; + bytes connect_str = 3; + } } message Common_Message { diff --git a/dll/steam_friends.h b/dll/steam_friends.h index 039b5a1..105186d 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -545,6 +545,7 @@ void SetPlayedWith( CSteamID steamIDUserPlayedWith ) void ActivateGameOverlayInviteDialog( CSteamID steamIDLobby ) { PRINT_DEBUG("Steam_Friends::ActivateGameOverlayInviteDialog\n"); + // TODO: Here open the overlay } // gets the small (32x32) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set @@ -775,8 +776,14 @@ void RequestFriendRichPresence( CSteamID steamIDFriend ) bool InviteUserToGame( CSteamID steamIDFriend, const char *pchConnectString ) { PRINT_DEBUG("Steam_Friends::InviteUserToGame\n"); - //TODO - return true; + Common_Message msg; + Friend_Messages *friend_messages = new Friend_Messages(); + friend_messages->set_type(Friend_Messages::GAME_INVITE); + friend_messages->set_connect_str(pchConnectString); + msg.set_allocated_friend_messages(friend_messages); + msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); + msg.set_dest_id(steamIDFriend.ConvertToUint64()); + return network->sendTo(&msg, true); } @@ -1021,6 +1028,15 @@ void Callback(Common_Message *msg) data.m_steamIDFriend = CSteamID((uint64)msg->source_id()); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } + + if (msg->friend_messages().type() == Friend_Messages::GAME_INVITE) { + PRINT_DEBUG("Steam_Friends Got Game Invite\n"); + std::string const& connect_str = msg->friend_messages().connect_str(); + GameRichPresenceJoinRequested_t data; + data.m_steamIDFriend = CSteamID((uint64)msg->source_id()); + strncpy(data.m_rgchConnect, connect_str.c_str(), k_cchMaxRichPresenceValueLength); + callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); + } } } From 717808e7965f9a3e3fad85713a9e49dc115a35b2 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Tue, 18 Jun 2019 10:55:17 +0200 Subject: [PATCH 4/8] Updated for the linux case. --- dll/local_storage.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index c68979f..b701b26 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -217,7 +217,7 @@ static std::vector get_filenames_recursive(std::string base_pa path += dir_name; std::vector lower = get_filenames_recursive(path); - // output.push_back(File_Data{ dir_name }); Is this needed ? Add folder name to the list of files ? + output.push_back(File_Data{ dir_name });// Is this needed ? Add folder name to the list of files ? std::transform(lower.begin(), lower.end(), std::back_inserter(output), [dir_name](File_Data f) {f.name = dir_name + "\\" + f.name; return f;}); } else { File_Data f; @@ -587,11 +587,19 @@ bool Local_Storage::file_exists(std::string folder, std::string file) std::string full_path = save_directory + appid + folder + file; struct stat buffer; - - if (GetFileAttributes(full_path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) + + if (stat(full_path.c_str(), &buffer) != 0) return false; - return (stat (full_path.c_str(), &buffer) == 0); +#if defined(STEAM_WIN32) + if ( buffer.st_mode & _S_IFDIR) + return false; +#else + if (S_ISDIR(buffer.st_mode)) + return false; +#endif + + return true; } unsigned int Local_Storage::file_size(std::string folder, std::string file) From a1d336bf567c6b7d85a7d565f9db358c25f89cd9 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Wed, 19 Jun 2019 18:39:14 +0200 Subject: [PATCH 5/8] Pass dir_name by reference Passing dir_name by reference will save a copy constructor. --- dll/local_storage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index b701b26..78d3060 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -218,7 +218,7 @@ static std::vector get_filenames_recursive(std::string base_pa std::vector lower = get_filenames_recursive(path); output.push_back(File_Data{ dir_name });// Is this needed ? Add folder name to the list of files ? - std::transform(lower.begin(), lower.end(), std::back_inserter(output), [dir_name](File_Data f) {f.name = dir_name + "\\" + f.name; return f;}); + std::transform(lower.begin(), lower.end(), std::back_inserter(output), [&dir_name](File_Data f) {f.name = dir_name + "\\" + f.name; return f;}); } else { File_Data f; f.name = ffd.cFileName; @@ -357,7 +357,7 @@ static std::vector get_filenames_recursive(std::string base_pa path += dir_name; std::vector lower = get_filenames_recursive(path); - std::transform(lower.begin(), lower.end(), std::back_inserter(output), [dir_name](File_Data f) {f.name = dir_name + "/" + f.name; return f;}); + std::transform(lower.begin(), lower.end(), std::back_inserter(output), [&dir_name](File_Data f) {f.name = dir_name + "/" + f.name; return f;}); } } } From 72d7d15adc32ee6d401f532a7d06ae6449a424f1 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Wed, 19 Jun 2019 18:43:14 +0200 Subject: [PATCH 6/8] Added the line to push dir name on linux --- dll/local_storage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 78d3060..3f0e5b2 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -357,6 +357,7 @@ static std::vector get_filenames_recursive(std::string base_pa path += dir_name; std::vector lower = get_filenames_recursive(path); + output.push_back(File_Data{ dir_name });// Is this needed ? Add folder name to the list of files ? std::transform(lower.begin(), lower.end(), std::back_inserter(output), [&dir_name](File_Data f) {f.name = dir_name + "/" + f.name; return f;}); } } From aa9e3c0c46e00efba870ab901a4d64d39eef29d8 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Wed, 10 Jul 2019 08:03:40 -0400 Subject: [PATCH 7/8] Small improvements to last commit. --- dll/steam_friends.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dll/steam_friends.h b/dll/steam_friends.h index 105186d..145a1d5 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -776,6 +776,10 @@ void RequestFriendRichPresence( CSteamID steamIDFriend ) bool InviteUserToGame( CSteamID steamIDFriend, const char *pchConnectString ) { PRINT_DEBUG("Steam_Friends::InviteUserToGame\n"); + std::lock_guard lock(global_mutex); + Friend *f = find_friend(steamIDFriend); + if (!f) return false; + Common_Message msg; Friend_Messages *friend_messages = new Friend_Messages(); friend_messages->set_type(Friend_Messages::GAME_INVITE); @@ -1028,13 +1032,14 @@ void Callback(Common_Message *msg) data.m_steamIDFriend = CSteamID((uint64)msg->source_id()); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } - + if (msg->friend_messages().type() == Friend_Messages::GAME_INVITE) { PRINT_DEBUG("Steam_Friends Got Game Invite\n"); + //TODO: I'm pretty sure that the user should accept the invite before this is posted but we do like above std::string const& connect_str = msg->friend_messages().connect_str(); - GameRichPresenceJoinRequested_t data; + GameRichPresenceJoinRequested_t data = {}; data.m_steamIDFriend = CSteamID((uint64)msg->source_id()); - strncpy(data.m_rgchConnect, connect_str.c_str(), k_cchMaxRichPresenceValueLength); + strncpy(data.m_rgchConnect, connect_str.c_str(), k_cchMaxRichPresenceValueLength - 1); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } } From 6dd7f517e64bc58f5dbf9d50c692e348be08d579 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Fri, 12 Jul 2019 11:26:07 -0400 Subject: [PATCH 8/8] Fix last pull request. --- dll/local_storage.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 3f0e5b2..774d0fc 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -217,7 +217,6 @@ static std::vector get_filenames_recursive(std::string base_pa path += dir_name; std::vector lower = get_filenames_recursive(path); - output.push_back(File_Data{ dir_name });// Is this needed ? Add folder name to the list of files ? std::transform(lower.begin(), lower.end(), std::back_inserter(output), [&dir_name](File_Data f) {f.name = dir_name + "\\" + f.name; return f;}); } else { File_Data f; @@ -357,7 +356,6 @@ static std::vector get_filenames_recursive(std::string base_pa path += dir_name; std::vector lower = get_filenames_recursive(path); - output.push_back(File_Data{ dir_name });// Is this needed ? Add folder name to the list of files ? std::transform(lower.begin(), lower.end(), std::back_inserter(output), [&dir_name](File_Data f) {f.name = dir_name + "/" + f.name; return f;}); } }