Compare commits

...

5 Commits

Author SHA1 Message Date
Duncan Ogilvie bdc3175fee Merge branch 'lobby_connect_fix' into 'master'
remember the last executable selected in lobby_connect

See merge request Mr_Goldberg/goldberg_emulator!30
2022-09-08 05:18:24 +00:00
Mr_Goldberg 802d8bcc8f
More accurate SetLobbyData. 2022-09-06 13:30:20 -04:00
Mr_Goldberg 7e1824290a
disable_lan_only.txt can now be put inside the steam_settings folder. 2022-09-06 13:29:39 -04:00
Mr_Goldberg 647e894d62
Add prints for debugging. 2022-09-06 13:29:02 -04:00
Duncan Ogilvie a76a1d48ae
remember the last executable selected in lobby_connect 2020-04-27 00:52:16 +02:00
5 changed files with 79 additions and 34 deletions

View File

@ -6,7 +6,7 @@ Then use my emu like you normally would. (Don't forget to put a steam_appid.txt)
For the LAN only connections feature:
If for some reason you want to disable this feature create a file named: disable_lan_only.txt beside the steam_api dll.
If for some reason you want to disable this feature create a file named: disable_lan_only.txt beside the steam_api dll or inside the steam_settings folder beside the steam api dll.
I noticed a lot of games seem to connect to analytics services and other crap that I hate.

View File

@ -824,7 +824,7 @@ static bool network_functions_attached = false;
BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
if (!file_exists(get_full_program_path() + "disable_lan_only.txt")) {
if (!file_exists(get_full_program_path() + "disable_lan_only.txt") && !file_exists(get_full_program_path() + "\\steam_settings\\disable_lan_only.txt")) {
PRINT_DEBUG("Hooking lan only functions\n");
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );

View File

@ -809,17 +809,20 @@ bool SetLobbyData( CSteamID steamIDLobby, const char *pchKey, const char *pchVal
std::lock_guard<std::recursive_mutex> lock(global_mutex);
Lobby *lobby = get_lobby(steamIDLobby);
if (!lobby || lobby->owner() != settings->get_local_steam_id().ConvertToUint64() || lobby->deleted()) {
if (!lobby || lobby->deleted()) {
return false;
}
auto result = caseinsensitive_find(lobby->values(), pchKey);
bool changed = true;
if (result == lobby->values().end()) {
(*lobby->mutable_values())[pchKey] = pchValue;
} else {
if (result->second == std::string(pchValue)) changed = false;
(*lobby->mutable_values())[result->first] = pchValue;
//callback is always triggered when setlobbydata is called from non owner however no data is actually changed.
if (lobby->owner() == settings->get_local_steam_id().ConvertToUint64()) {
auto result = caseinsensitive_find(lobby->values(), pchKey);
if (result == lobby->values().end()) {
(*lobby->mutable_values())[pchKey] = pchValue;
} else {
if (result->second == std::string(pchValue)) changed = false;
(*lobby->mutable_values())[result->first] = pchValue;
}
}
if (changed)

View File

@ -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 %u\n", hConn, size);
PRINT_DEBUG("get_steam_message_connection %u %u, %u\n", hConn, size, pMsg->m_nMessageNumber);
return pMsg;
}
@ -913,6 +913,7 @@ int ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessa
++messages;
}
PRINT_DEBUG("messages %u\n", messages);
return messages;
}
@ -2085,13 +2086,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 %u on connection %u\n", msg->networking_sockets().data().size(), connect_socket->first);
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u, num %u 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 %u on not accepted connection %u\n", msg->networking_sockets().data().size(), connect_socket->first);
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u, num %u 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());
}
}

View File

@ -26,6 +26,7 @@
#include <thread>
#include <string>
#include <vector>
#include <fstream>
#ifdef _WIN32
#include <windows.h>
@ -58,22 +59,23 @@ top:
std::cout << std::endl << "--------------Menu-------------" << std::endl << "\tappid\tname\tcommand line" << std::endl;
std::vector<std::string> arguments;
std::vector<std::pair<std::string, uint32>> arguments;
for (int i = 0; i < friend_count; ++i) {
CSteamID id = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagAll);
const char *name = SteamFriends()->GetFriendPersonaName(id);
const char *connect = SteamFriends()->GetFriendRichPresence( id, "connect");
FriendGameInfo_t friend_info = {};
SteamFriends()->GetFriendGamePlayed(id, &friend_info);
auto appid = friend_info.m_gameID.AppID();
if (strlen(connect) > 0) {
std::cout << arguments.size() << "\t" << friend_info.m_gameID.AppID() << "\t" << name << "\t" << connect << std::endl;
arguments.push_back(connect);
std::cout << arguments.size() << "\t" << appid << "\t" << name << "\t" << connect << std::endl;
arguments.emplace_back(connect, appid);
} else {
if (friend_info.m_steamIDLobby != k_steamIDNil) {
std::string connect = "+connect_lobby " + std::to_string(friend_info.m_steamIDLobby.ConvertToUint64());
std::cout << arguments.size() << "\t" << friend_info.m_gameID.AppID() << "\t" << name << "\t" << connect << std::endl;
arguments.push_back(connect);
std::cout << arguments.size() << "\t" << appid << "\t" << name << "\t" << connect << std::endl;
arguments.emplace_back(connect, appid);
}
}
}
@ -85,24 +87,40 @@ top:
if (choice >= arguments.size()) goto top;
auto connect = arguments[choice].first;
#ifdef _WIN32
std::cout << "starting the game with: " << arguments[choice] << std::endl << "Please select the game exe" << std::endl;
auto appid = arguments[choice].second;
std::cout << "starting the game with: " << connect << std::endl;
OPENFILENAMEA ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = 0;
ofn.lpstrFilter = "Exe Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetOpenFileNameA(&ofn))
{
std::string filename = szFileName;
filename = "\"" + filename + "\" " + arguments[choice];
char szBaseDirectory[MAX_PATH] = "";
GetModuleFileNameA(0, szBaseDirectory, MAX_PATH);
if (auto bs = strrchr(szBaseDirectory, '\\')) {
*bs = '\0';
}
auto lobbyFile = std::string(szBaseDirectory) + "\\lobby_connect_" + std::to_string(appid) + ".txt";
auto readLobbyFile = [&lobbyFile]() {
std::string data;
std::ifstream ifs(lobbyFile);
if (ifs.is_open())
std::getline(ifs, data);
return data;
};
auto writeLobbyFile = [&lobbyFile](const std::string& data) {
std::ofstream ofs(lobbyFile);
ofs << data << std::endl;
};
auto fileExists = [](const std::string& filename) {
std::ifstream ifs(filename);
return ifs.is_open();
};
auto joinLobby = [&connect](std::string filename) {
filename = "\"" + filename + "\" " + connect;
std::cout << filename << std::endl;
STARTUPINFOA lpStartupInfo;
PROCESS_INFORMATION lpProcessInfo;
@ -110,15 +128,38 @@ top:
lpStartupInfo.cb = sizeof( lpStartupInfo );
ZeroMemory( &lpProcessInfo, sizeof( lpProcessInfo ) );
CreateProcessA( NULL,
auto success = !!CreateProcessA( NULL,
const_cast<char *>(filename.c_str()), NULL, NULL,
NULL, NULL, NULL, NULL,
&lpStartupInfo,
&lpProcessInfo
);
CloseHandle(lpProcessInfo.hThread);
CloseHandle(lpProcessInfo.hProcess);
return success;
};
std::string filename = readLobbyFile();
if (filename.empty() || !fileExists(filename) || !joinLobby(filename)) {
std::cout << "Please select the game exe" << std::endl;
OPENFILENAMEA ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = 0;
ofn.lpstrFilter = "Exe Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "exe";
if(GetOpenFileNameA(&ofn) && joinLobby(szFileName)) {
writeLobbyFile(szFileName);
}
}
#else
std::cout << "Please launch the game with these arguments: " << arguments[choice] << std::endl;
std::cout << "Please launch the game with these arguments: " << connect << std::endl;
#endif
}
}