diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9021357 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +# Set the default behavior. +* text=auto + +# Unix shell files should always be LF. +*.sh text eol=lf + +# Windows shell files should always be CRLF. +*.bat text eol=crlf + +# Binary files. +*.jpg binary +*.png binary + diff --git a/.gitignore b/.gitignore index 47acc83..788c645 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,18 @@ -.vs/* -.vscode/* -*.bin -*.o -net.pb.* -*steam_api* -release/* -/build*/ -*.obj -/dll/net.pb.cc -/dll/net.pb.h -base.exp -base.lib -rtlgenrandom* -steamclient.exp -steamclient.lib -out/* +.vs/* +.vscode/* +*.bin +*.o +net.pb.* +*steam_api* +release/* +debug/* +/build*/ +*.obj +/dll/net.pb.cc +/dll/net.pb.h +base.exp +base.lib +rtlgenrandom* +steamclient.exp +steamclient.lib +out/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c158841..98989b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,15 +69,21 @@ build_windows: - 7za x protobuf_x86-windows-static.7z -oprotobuf_x86-windows-static - 7za x protobuf_x64-windows-static.7z -oprotobuf_x64-windows-static - 7za x sdk_standalone.7z -osdk_standalone - - DLL_FILES="$(ls dll/*.cpp | tr "\n" " ")"; sed "s|dll/\*.cpp|$DLL_FILES|g" -i *.bat - - DLL_FILES="$(ls dll/*.proto | tr "\n" " " | sed "s/.proto/.pb.cc/g")"; sed "s|dll/\*.cc|$DLL_FILES|g" -i *.bat + - DLL_FILES="$(ls dll/*.cpp | tr "\n" " " | tr "/" "\\\\")"; sed "s|dll/\*.cpp|$DLL_FILES|g" -i *.bat + - DLL_FILES="$(ls dll/*.proto | tr "\n" " " | tr "/" "\\\\" | sed "s/.proto/.pb.cc/g")"; sed "s|dll/\*.cc|$DLL_FILES|g" -i *.bat - sed "s| /MP12 | /MP4 |g" -i *.bat + # CI can't produce PDBs. Throws a bunch of errors, and skips building the PEs. + - sed "s| /DDEBUG\:FULL | |g" -i *.bat + # Turn on echo. + - sed "s|echo off|echo on|g" -i *.bat - python generate_build_win_bat.py - export WINEDEBUG=-all - wine cmd /c build_win_release_test.bat + - cp build_win_release_test.bat release/build_win_release_test.bat artifacts: paths: - release/ + - debug/ expire_in: 1 day build_cmake_linux: diff --git a/build_env_x64.bat b/build_env_x64.bat index 35b701b..21c181d 100755 --- a/build_env_x64.bat +++ b/build_env_x64.bat @@ -12,6 +12,8 @@ if exist "%VS_Base_Path%\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Bu if exist "%VS_Base_Path%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" goto vs2022 if exist "%VS_Base_Path%\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" goto vs2022_bt if exist ".\sdk_standalone\set_vars64.bat" goto gitlabci +if exist "vsinstallloc.txt" goto readloc +if exist "%VS_Base_Path%\Microsoft Visual Studio\Installer\vswhere.exe" goto wherevs :vs2022 call "%VS_Base_Path%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" @@ -44,4 +46,14 @@ goto batend :gitlabci call ".\sdk_standalone\set_vars64.bat" goto batend + +:wherevs +call "%VS_Base_Path%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath > vsinstallloc.txt +goto readloc + +:readloc +set /p VS_LOCAL= vsinstallloc.txt +goto readloc + +:readloc +set /p VS_LOCAL= #include #include - #include #include #include @@ -205,4 +204,4 @@ inline std::string ascii_to_lowercase(std::string data) { #define LOBBY_CONNECT_APPID ((uint32)-2) -#endif//__INCLUDED_COMMON_INCLUDES__ \ No newline at end of file +#endif//__INCLUDED_COMMON_INCLUDES__ diff --git a/dll/settings.h b/dll/settings.h index a7b2aa9..aeb8b49 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -132,6 +132,9 @@ public: //custom broadcasts std::set custom_broadcasts; + //custom master server + std::set custom_master_server; + //stats std::map getStats() { return stats; } void setStatDefiniton(std::string name, struct Stat_config stat_config) {stats[ascii_to_lowercase(name)] = stat_config; } diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 22dad2e..ef34316 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -211,6 +211,11 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s load_custom_broadcasts(local_storage->get_global_settings_path() + "custom_broadcasts.txt", custom_broadcasts); load_custom_broadcasts(Local_Storage::get_game_settings_path() + "custom_broadcasts.txt", custom_broadcasts); + // Custom master server + std::set custom_master_server; + load_custom_broadcasts(local_storage->get_global_settings_path() + "custom_master_server.txt", custom_master_server); + load_custom_broadcasts(Local_Storage::get_game_settings_path() + "custom_master_server.txt", custom_master_server); + // Acount name char name[32] = {}; if (local_storage->get_data_settings("account_name.txt", name, sizeof(name) - 1) <= 0) { @@ -359,6 +364,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->set_port(port); settings_client->custom_broadcasts = custom_broadcasts; settings_server->custom_broadcasts = custom_broadcasts; + settings_client->custom_master_server = custom_master_server; + settings_server->custom_master_server = custom_master_server; settings_client->disable_networking = disable_networking; settings_server->disable_networking = disable_networking; settings_client->disable_overlay = disable_overlay; diff --git a/dll/steam_client.cpp b/dll/steam_client.cpp index 17af33e..101d089 100644 --- a/dll/steam_client.cpp +++ b/dll/steam_client.cpp @@ -81,6 +81,7 @@ Steam_Client::Steam_Client() steam_remote_storage = new Steam_Remote_Storage(settings_client, local_storage, callback_results_client); steam_screenshots = new Steam_Screenshots(local_storage, callbacks_client); steam_http = new Steam_HTTP(settings_client, network, callback_results_client, callbacks_client); + steam_unified_messages = new Steam_Unified_Messages(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_controller = new Steam_Controller(settings_client, callback_results_client, callbacks_client, run_every_runcb); steam_ugc = new Steam_UGC(settings_client, callback_results_client, callbacks_client); steam_applist = new Steam_Applist(); @@ -95,7 +96,6 @@ Steam_Client::Steam_Client() steam_networking_messages = new Steam_Networking_Messages(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_game_coordinator = new Steam_Game_Coordinator(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_networking_utils = new Steam_Networking_Utils(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); - steam_unified_messages = new Steam_Unified_Messages(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_game_search = new Steam_Game_Search(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_parties = new Steam_Parties(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); steam_remoteplay = new Steam_RemotePlay(settings_client, network, callback_results_client, callbacks_client, run_every_runcb); diff --git a/dll/steam_client.h b/dll/steam_client.h index d00cb6a..37c4a85 100644 --- a/dll/steam_client.h +++ b/dll/steam_client.h @@ -75,6 +75,7 @@ public ISteamClient018, public ISteamClient019, public ISteamClient { +// Some games (SAO:FB) use pointer math to access the class so member order is important. public: Networking *network; SteamCallResults *callback_results_server, *callback_results_client; @@ -94,6 +95,7 @@ public: Steam_Remote_Storage *steam_remote_storage; Steam_Screenshots *steam_screenshots; Steam_HTTP *steam_http; + Steam_Unified_Messages *steam_unified_messages; Steam_Controller *steam_controller; Steam_UGC *steam_ugc; Steam_Applist *steam_applist; @@ -108,7 +110,6 @@ public: Steam_Networking_Messages *steam_networking_messages; Steam_Game_Coordinator *steam_game_coordinator; Steam_Networking_Utils *steam_networking_utils; - Steam_Unified_Messages *steam_unified_messages; Steam_Game_Search *steam_game_search; Steam_Parties *steam_parties; Steam_RemotePlay *steam_remoteplay; diff --git a/dll/steam_masterserver_updater.h b/dll/steam_masterserver_updater.h index d55e63e..d17ccd8 100644 --- a/dll/steam_masterserver_updater.h +++ b/dll/steam_masterserver_updater.h @@ -173,12 +173,64 @@ void ForceHeartbeat() bool AddMasterServer( const char *pServerAddress ) { PRINT_DEBUG("Steam_Masterserver_Updater::AddMasterServer\n"); + + IP_PORT addr; + + if (pServerAddress) + { + addr.ip = (uint32)*pServerAddress; + if (pServerAddress[(sizeof(uint32))] != 0) + { + addr.port = (uint16)*(pServerAddress + sizeof(uint32)); + } + else + { + addr.port = 27016; + } + PRINT_DEBUG("Steam_Masterserver_Updater::AddMasterServer pServerAddress IP: %d, PORT: %d", addr.ip, addr.port); + this->settings->custom_master_server.insert(addr); + } + return true; } bool RemoveMasterServer( const char *pServerAddress ) { PRINT_DEBUG("Steam_Masterserver_Updater::RemoveMasterServer\n"); + + std::set::iterator iter; + IP_PORT addr; + IP_PORT list; + + if (pServerAddress) + { + addr.ip = (uint32)*pServerAddress; + if (pServerAddress[(sizeof(uint32))] != 0) + { + addr.port = (uint16)*(pServerAddress + sizeof(uint32)); + } + else + { + addr.port = 27016; + } + PRINT_DEBUG("Steam_Masterserver_Updater::RemoveMasterServer pServerAddress IP: %d, PORT: %d", addr.ip, addr.port); + + iter = this->settings->custom_master_server.begin(); + while (iter != this->settings->custom_master_server.end()) + { + list = (*iter); + if (addr.ip == list.ip && + (addr.port == list.port || (list.port == 0 && addr.port == 27016))) + { + iter = this->settings->custom_master_server.erase(iter); + } + else + { + iter++; + } + } + } + return true; } @@ -186,7 +238,7 @@ bool RemoveMasterServer( const char *pServerAddress ) int GetNumMasterServers() { PRINT_DEBUG("Steam_Masterserver_Updater::GetNumMasterServers\n"); - return 0; + return this->settings->custom_master_server.size(); } @@ -194,7 +246,38 @@ int GetNumMasterServers() int GetMasterServerAddress( int iServer, char *pOut, int outBufferSize ) { PRINT_DEBUG("Steam_Masterserver_Updater::GetMasterServerAddress\n"); - return 0; + + size_t written_bytes = 0; + char * byte_cpy = NULL; + std::set::iterator iter; + IP_PORT addr; + + if (pOut && outBufferSize >= sizeof(uint32) && this->settings->custom_master_server.size() > 0) + { + iter = this->settings->custom_master_server.begin(); + while (written_bytes < outBufferSize && iter != this->settings->custom_master_server.end()) + { + addr = (*iter); + byte_cpy = (char*)&(addr.ip); + for (size_t x = 0; x < sizeof(addr.ip) && written_bytes < outBufferSize; x++) + { + memcpy(pOut + x, byte_cpy + x, 1); + written_bytes++; + } + if (addr.port != 0 && addr.port != 27016) // Default updater port. + { + byte_cpy = (char*)&(addr.port); + for (size_t x = 0; x < sizeof(addr.port) && written_bytes < outBufferSize; x++) + { + memcpy(pOut + x, byte_cpy + x, 1); + written_bytes++; + } + } + iter++; + } + } + + return written_bytes; } diff --git a/dll/steam_remoteplay.cpp b/dll/steam_remoteplay.cpp new file mode 100644 index 0000000..c182b76 --- /dev/null +++ b/dll/steam_remoteplay.cpp @@ -0,0 +1,202 @@ +/* Copyright (C) 2019 Mr Goldberg + This file is part of the Goldberg Emulator + + The Goldberg Emulator is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The Goldberg Emulator is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Goldberg Emulator; if not, see + . */ + +#include "steam_remoteplay.h" +#include +#include + +typedef struct remote_play_session_info_T { + RemotePlaySessionID_t session_id; + CSteamID connected_user; + const char * client_name; + ESteamDeviceFormFactor client_form_factor; + int client_resolution_x; + int client_resolution_y; +} remote_play_session_info; +//TODO: NOT thread safe!!! +static std::vector remote_play_sessions; + +int create_remote_play_session_info( RemotePlaySessionID_t session_id, CSteamID connected_user, const char * client_name, ESteamDeviceFormFactor client_form_factor, int client_resolution_x, int client_resolution_y ) { + remote_play_session_info session_info; + size_t buffer_length = 0; + char * buffer = NULL; + + if ((remote_play_sessions.size() < UINT_MAX) && (client_name != NULL)) { + session_info.session_id = session_id; + session_info.connected_user = connected_user; + session_info.client_form_factor = client_form_factor; + session_info.client_resolution_x = client_resolution_x; + session_info.client_resolution_y = client_resolution_y; + + buffer_length = strlen( client_name ); + if (buffer_length > 0) { + buffer = new char[buffer_length + 1]; + if (buffer != NULL) { + memcpy(buffer, client_name, buffer_length); + session_info.client_name = buffer; + remote_play_sessions.push_back( (const remote_play_session_info)session_info ); + return 0; + } + } + } + return -1; +} + +int destroy_remote_play_session_info( size_t index ) { + if (remote_play_sessions.size() < index) { + delete remote_play_sessions[index].client_name; + remote_play_sessions.erase(remote_play_sessions.begin() + index); + return 0; + } + return -1; +} + +uint32 get_number_of_remote_play_sessions() { + return (uint32)remote_play_sessions.size(); +} + +int get_remote_play_session_id( size_t index, RemotePlaySessionID_t * session_id ) { + if ((session_id != NULL) && (index >= 0) && (remote_play_sessions.size() < index)) { + *session_id = remote_play_sessions[index].session_id; + return 0; + } + return -1; +} + +int get_remote_play_session_index( RemotePlaySessionID_t session_id, size_t * index ) { + size_t count = 0; + + if ((index != NULL) && (remote_play_sessions.size() > 0)) { + for (std::vector::iterator iter = remote_play_sessions.begin(); iter != remote_play_sessions.end(); iter++) { + if (iter->session_id == session_id) { + *index = count; + return 0; + } + count++; + } + } + return -1; +} + +int get_remote_play_session_connected_user( size_t index, CSteamID * connected_user ) { + if ((connected_user != NULL) && (index >= 0) && (remote_play_sessions.size() < index)) { + *connected_user = remote_play_sessions[index].connected_user; + return 0; + } + return -1; +} + +int get_remote_play_session_client_name( size_t index, const char ** client_name ) { + if ((client_name != NULL) && (index >= 0) && (remote_play_sessions.size() < index)) { + *client_name = remote_play_sessions[index].client_name; + return 0; + } + return -1; +} + +int get_remote_play_session_client_form_factor( size_t index, ESteamDeviceFormFactor * client_form_factor ) { + if ((client_form_factor != NULL) && (index >= 0) && (remote_play_sessions.size() < index)) { + *client_form_factor = remote_play_sessions[index].client_form_factor; + return 0; + } + return -1; +} + +int get_remote_play_session_client_resolutions( size_t index, int * client_resolution_x, int * client_resolution_y ) { + if ((client_resolution_x != NULL) && (client_resolution_y != NULL) && (index >= 0) && (remote_play_sessions.size() < index)) { + *client_resolution_x = remote_play_sessions[index].client_resolution_x; + *client_resolution_y = remote_play_sessions[index].client_resolution_y; + return 0; + } + return -1; +} + +uint32 Steam_RemotePlay::GetSessionCount() +{ + PRINT_DEBUG("Steam_RemotePlay::GetSessionCount\n"); + return get_number_of_remote_play_sessions(); +} + +uint32 Steam_RemotePlay::GetSessionID( int iSessionIndex ) +{ + RemotePlaySessionID_t session_id; + + PRINT_DEBUG("Steam_RemotePlay::GetSessionID\n"); + return ((get_remote_play_session_id( iSessionIndex, &session_id ) == 0) ? (session_id) : (0)); +} + +CSteamID Steam_RemotePlay::GetSessionSteamID( uint32 unSessionID ) +{ + CSteamID steam_id = k_steamIDNil; + size_t index = 0; + + PRINT_DEBUG("Steam_RemotePlay::GetSessionSteamID\n"); + if (get_remote_play_session_index( unSessionID, &index ) == 0) { + if (get_remote_play_session_connected_user( index, &steam_id ) == 0) { + return steam_id; + } + } + return k_steamIDNil; +} + +const char * Steam_RemotePlay::GetSessionClientName( uint32 unSessionID ) +{ + const char * client_name = NULL; + size_t index = 0; + + PRINT_DEBUG("Steam_RemotePlay::GetSessionClientName\n"); + if (get_remote_play_session_index( unSessionID, &index ) == 0) { + if (get_remote_play_session_client_name( index, &client_name ) == 0) { + return client_name; + } + } + return NULL; +} + +ESteamDeviceFormFactor Steam_RemotePlay::GetSessionClientFormFactor( uint32 unSessionID ) +{ + ESteamDeviceFormFactor form_factor = k_ESteamDeviceFormFactorUnknown; + size_t index = 0; + + PRINT_DEBUG("Steam_RemotePlay::GetSessionClientFormFactor\n"); + if (get_remote_play_session_index( unSessionID, &index ) == 0) { + if (get_remote_play_session_client_form_factor( index, &form_factor ) == 0) { + return form_factor; + } + } + return k_ESteamDeviceFormFactorUnknown; +} + +bool Steam_RemotePlay::BGetSessionClientResolution( uint32 unSessionID, int *pnResolutionX, int *pnResolutionY ) +{ + int x = 0; + int y = 0; + size_t index = 0; + + PRINT_DEBUG("Steam_RemotePlay::BGetSessionClientResolution\n"); + if ((pnResolutionX != NULL) && (pnResolutionY != NULL)) { + if (get_remote_play_session_index( unSessionID, &index ) == 0) { + if (get_remote_play_session_client_resolutions( index, &x, &y ) == 0) { + *pnResolutionX = x; + *pnResolutionY = y; + return true; + } + } + } + return false; +} + diff --git a/dll/steam_remoteplay.h b/dll/steam_remoteplay.h index 7bd97ff..56e2965 100644 --- a/dll/steam_remoteplay.h +++ b/dll/steam_remoteplay.h @@ -62,48 +62,24 @@ Steam_RemotePlay(class Settings *settings, class Networking *network, class Stea } // Get the number of currently connected Steam Remote Play sessions -uint32 GetSessionCount() -{ - PRINT_DEBUG("Steam_RemotePlay::GetSessionCount\n"); - return 0; -} +uint32 GetSessionCount(); // Get the currently connected Steam Remote Play session ID at the specified index. Returns zero if index is out of bounds. -uint32 GetSessionID( int iSessionIndex ) -{ - PRINT_DEBUG("Steam_RemotePlay::GetSessionID\n"); - return 0; -} +uint32 GetSessionID( int iSessionIndex ); // Get the SteamID of the connected user -CSteamID GetSessionSteamID( uint32 unSessionID ) -{ - PRINT_DEBUG("Steam_RemotePlay::GetSessionSteamID\n"); - return k_steamIDNil; -} +CSteamID GetSessionSteamID( uint32 unSessionID ); // Get the name of the session client device // This returns NULL if the sessionID is not valid -const char *GetSessionClientName( uint32 unSessionID ) -{ - PRINT_DEBUG("Steam_RemotePlay::GetSessionClientName\n"); - return NULL; -} +const char *GetSessionClientName( uint32 unSessionID ); // Get the form factor of the session client device -ESteamDeviceFormFactor GetSessionClientFormFactor( uint32 unSessionID ) -{ - PRINT_DEBUG("Steam_RemotePlay::GetSessionClientFormFactor\n"); - return k_ESteamDeviceFormFactorUnknown; -} +ESteamDeviceFormFactor GetSessionClientFormFactor( uint32 unSessionID ); // Get the resolution, in pixels, of the session client device // This is set to 0x0 if the resolution is not available -bool BGetSessionClientResolution( uint32 unSessionID, int *pnResolutionX, int *pnResolutionY ) -{ - PRINT_DEBUG("Steam_RemotePlay::BGetSessionClientResolution\n"); - return false; -} +bool BGetSessionClientResolution( uint32 unSessionID, int *pnResolutionX, int *pnResolutionY ); // Invite a friend to Remote Play Together // This returns false if the invite can't be sent diff --git a/dll/steam_ugc.h b/dll/steam_ugc.h index b1ada44..77658b2 100644 --- a/dll/steam_ugc.h +++ b/dll/steam_ugc.h @@ -600,13 +600,13 @@ bool RemoveItemPreview( UGCUpdateHandle_t handle, uint32 index ) bool AddContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) { - PRINT_DEBUG("Steam_UGC::AddContentDescriptor %llu %u\n", handle, index); + PRINT_DEBUG("Steam_UGC::AddContentDescriptor %llu %u\n", handle, descid); return false; } bool RemoveContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) { - PRINT_DEBUG("Steam_UGC::RemoveContentDescriptor %llu %u\n", handle, index); + PRINT_DEBUG("Steam_UGC::RemoveContentDescriptor %llu %u\n", handle, descid); return false; } diff --git a/dll/wrap.cpp b/dll/wrap.cpp index 50defc7..7cabf7c 100644 --- a/dll/wrap.cpp +++ b/dll/wrap.cpp @@ -25,6 +25,7 @@ // Nothing to be done here #else #define STEAM_API_FUNCTIONS_IMPL + #include "base.h" #include "dll.h" @@ -34,6 +35,26 @@ const char *STEAM_PATH; size_t STEAM_PATH_SIZE; +#ifndef __x86_64__ +# define _STAT_VER_LINUX_OLD 1 +# define _STAT_VER_KERNEL 1 +# define _STAT_VER_SVR4 2 +# define _STAT_VER_LINUX 3 +# define _MKNOD_VER_LINUX 1 +# define _MKNOD_VER_SVR4 2 +#else +# define _STAT_VER_KERNEL 0 +# define _STAT_VER_LINUX 1 +# define _MKNOD_VER_LINUX 0 +#endif +#define _STAT_VER _STAT_VER_LINUX +#define _MKNOD_VER _MKNOD_VER_LINUX + +/* From kernel_stat.h It help me save some condition */ +#define XSTAT_IS_XSTAT64 1 +#define STATFS_IS_STATFS64 __STATFS_MATCHES_STATFS64 +#define STAT_IS_KERNEL_STAT 1 + // Returns a '/' terminated absolute path to the steam folder in user's home, // root is returned if env home is not set const char *get_steam_path() @@ -290,7 +311,16 @@ STEAMAPI_API int __wrap_access(const char *path, int mode) STEAMAPI_API int __wrap___xstat(int ver, const char * path, struct stat * stat_buf) { const char *path_lowercased = lowercase_path(path, false, false); - int result = __xstat(ver, path_lowercased, stat_buf); + int result; + + switch (ver) { + case _STAT_VER_KERNEL: + result = stat(path_lowercased, stat_buf); + break; + default: + result = EINVAL; + } + if (path_lowercased != path) { free((void *)path_lowercased); } @@ -305,7 +335,16 @@ STEAMAPI_API int __wrap_stat(const char * path, struct stat * stat_buf) STEAMAPI_API int __wrap___lxstat(int ver, const char * path, struct stat * stat_buf) { const char *path_lowercased = lowercase_path(path, false, false); - int result = __lxstat(ver, path_lowercased, stat_buf); + int result; + + switch (ver) { + case _STAT_VER_KERNEL: + result = lstat(path_lowercased, stat_buf); + break; + default: + result = EINVAL; + } + if (path_lowercased != path) { free((void *)path_lowercased); } @@ -350,7 +389,16 @@ STEAMAPI_API DIR *__wrap_opendir(const char *path) STEAMAPI_API int __wrap___xstat64(int ver, const char *path, struct stat64 *stat_buf) { const char *path_lowercased = lowercase_path(path, false, false); - int result = __xstat64(ver, path_lowercased, stat_buf); + int result; + + switch (ver) { + case _STAT_VER_KERNEL: + result = stat64(path_lowercased, stat_buf); + break; + default: + result = EINVAL; + } + if (path_lowercased != path) { free((void *)path_lowercased); } @@ -360,7 +408,16 @@ STEAMAPI_API int __wrap___xstat64(int ver, const char *path, struct stat64 *stat STEAMAPI_API int __wrap___lxstat64(int ver, const char *path, struct stat64 *stat_buf) { const char *path_lowercased = lowercase_path(path, false, false); - int result = __lxstat64(ver, path_lowercased, stat_buf); + int result; + + switch (ver) { + case _STAT_VER_KERNEL: + result = lstat64(path_lowercased, stat_buf); + break; + default: + result = EINVAL; + } + if (path_lowercased != path) { free((void *)path_lowercased); } @@ -448,7 +505,7 @@ STEAMAPI_API int __wrap_link(const char *path1, const char *path2) STEAMAPI_API int __wrap_mknod(const char *path, mode_t mode, dev_t dev) { const char *path_lowercased = lowercase_path(path, true, true); - int result = __xmknod(1, path_lowercased, mode, &dev); + int result = mknod(path_lowercased, mode, dev); if (path_lowercased != path) { free((void *)path_lowercased); } diff --git a/files_example/steam_settings.EXAMPLE/custom_master_server.EXAMPLE.txt b/files_example/steam_settings.EXAMPLE/custom_master_server.EXAMPLE.txt new file mode 100644 index 0000000..2837580 --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/custom_master_server.EXAMPLE.txt @@ -0,0 +1,2 @@ +192.168.7.99 +removethis.test.domain.com diff --git a/generate_build_win_bat.py b/generate_build_win_bat.py index f24b6bc..9e3ef47 100644 --- a/generate_build_win_bat.py +++ b/generate_build_win_bat.py @@ -32,6 +32,7 @@ includes_64 = list(map(lambda a: '/I{}'.format(a), ["%PROTOBUF_X64_DIRECTORY%\\i debug_build_args = [] release_build_args = ["/DEMU_RELEASE_BUILD", "/DNDEBUG"] steamclient_build_args = ["/DSTEAMCLIENT_DLL"] +lobby_connect_args = ["/DNO_DISK_WRITES", "/DLOBBY_CONNECT"] experimental_build_args = ["/DEMU_EXPERIMENTAL_BUILD", "/DCONTROLLER_SUPPORT", "/DEMU_OVERLAY"] steamclient_experimental_build_args = experimental_build_args + steamclient_build_args @@ -62,6 +63,7 @@ mkdir release\experimental mkdir release\experimental_steamclient mkdir release\debug_experimental mkdir release\debug_experimental_steamclient +mkdir release\lobby_connect call build_set_protobuf_directories.bat """ @@ -81,7 +83,8 @@ xcopy /s files_example\* release\\ copy Readme_experimental.txt release\experimental\Readme.txt copy Readme_debug.txt release\debug_experimental\Readme.txt copy steamclient_loader\ColdClientLoader.ini release\experimental_steamclient\\ -call build_win_lobby_connect.bat +REM call build_win_lobby_connect.bat +copy Readme_lobby_connect.txt release\lobby_connect\Readme.txt call build_win_find_interfaces.bat """ @@ -114,6 +117,8 @@ def generate_common(include_arch, linker_arch, steam_api_name, steamclient_name) out += generate_common(includes_32, linker_32, "steam_api.dll", "steamclient.dll") +out += cl_line_exe(files_from_dir("./", "lobby_connect.cpp") + files_from_dir("dll", "flat.cpp") + files_from_dir("dll", "dll.cpp") + lobby_connect_args + normal_build_args + release_build_args + includes_32 + proto_deps + steam_deps + normal_linker_libs + ["Comdlg32.lib", "user32.lib"], linker_32 + ["/debug:none", "/OUT:release\lobby_connect\lobby_connect.exe"]) + out += cl_line_exe(files_from_dir("steamclient_loader", ".cpp") + ["advapi32.lib", "user32.lib"] + normal_build_args, ["/debug:none", "/OUT:release\experimental_steamclient\steamclient_loader.exe"]) out += head_64bit diff --git a/lobby_connect.cpp b/lobby_connect.cpp index 36f3327..3af6dad 100644 --- a/lobby_connect.cpp +++ b/lobby_connect.cpp @@ -32,93 +32,113 @@ #else #endif -int main() { +int main(int argc, char ** argv) { + bool broadcast_relay_daemon = false; + + if (argc > 1) { + for (int x = 1; x < argc; x++) { + if (strcmp(argv[x], "-d") == 0) { + broadcast_relay_daemon = true; + } + } + } + if (SteamAPI_Init()) { //Set appid to: LOBBY_CONNECT_APPID SteamAPI_RestartAppIfNecessary(LOBBY_CONNECT_APPID); - std::cout << "This is a program to find lobbies and run the game with lobby connect parameters" << std::endl; - std::cout << "Api initialized, "; + if (broadcast_relay_daemon) { + std::cout << "Running in relay daemon mode. Press Ctrl+C to exit...." << std::endl; + std::cout.flush(); + + while (1) { + SteamAPI_RunCallbacks(); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + } + } else { + std::cout << "This is a program to find lobbies and run the game with lobby connect parameters" << std::endl; + std::cout << "Api initialized, "; top: - std::cout << "waiting a few seconds for connections:" << std::endl; - for (int i = 0; i < 10; ++i) { - SteamAPI_RunCallbacks(); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } + std::cout << "waiting a few seconds for connections:" << std::endl; + for (int i = 0; i < 10; ++i) { + SteamAPI_RunCallbacks(); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + } - int friend_count = SteamFriends()->GetFriendCount(k_EFriendFlagAll); - std::cout << "People on the network: " << friend_count << std::endl; - for (int i = 0; i < friend_count; ++i) { - CSteamID id = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagAll); - const char *name = SteamFriends()->GetFriendPersonaName(id); + int friend_count = SteamFriends()->GetFriendCount(k_EFriendFlagAll); + std::cout << "People on the network: " << friend_count << std::endl; + for (int i = 0; i < friend_count; ++i) { + CSteamID id = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagAll); + const char *name = SteamFriends()->GetFriendPersonaName(id); - FriendGameInfo_t friend_info = {}; - SteamFriends()->GetFriendGamePlayed(id, &friend_info); - std::cout << name << " is playing: " << friend_info.m_gameID.AppID() << std::endl; - } + FriendGameInfo_t friend_info = {}; + SteamFriends()->GetFriendGamePlayed(id, &friend_info); + std::cout << name << " is playing: " << friend_info.m_gameID.AppID() << std::endl; + } - std::cout << std::endl << "--------------Menu-------------" << std::endl << "\tappid\tname\tcommand line" << std::endl; + std::cout << std::endl << "--------------Menu-------------" << std::endl << "\tappid\tname\tcommand line" << std::endl; - std::vector 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); + std::vector 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); - if (strlen(connect) > 0) { - std::cout << arguments.size() << "\t" << friend_info.m_gameID.AppID() << "\t" << name << "\t" << connect << std::endl; - arguments.push_back(connect); - } else { - if (friend_info.m_steamIDLobby != k_steamIDNil) { - std::string connect = "+connect_lobby " + std::to_string(friend_info.m_steamIDLobby.ConvertToUint64()); + if (strlen(connect) > 0) { std::cout << arguments.size() << "\t" << friend_info.m_gameID.AppID() << "\t" << name << "\t" << connect << std::endl; arguments.push_back(connect); + } 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() << ": Retry." << std::endl; - std::cout << std::endl << "Enter the number corresponding to your choice then press Enter." << std::endl; - unsigned int choice; - std::cin >> choice; + std::cout << arguments.size() << ": Retry." << std::endl; + std::cout << std::endl << "Enter the number corresponding to your choice then press Enter." << std::endl; + unsigned int choice; + std::cin >> choice; - if (choice >= arguments.size()) goto top; + if (choice >= arguments.size()) goto top; #ifdef _WIN32 - std::cout << "starting the game with: " << arguments[choice] << std::endl << "Please select the game exe" << std::endl; + std::cout << "starting the game with: " << arguments[choice] << std::endl << "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 = "txt"; - if(GetOpenFileNameA(&ofn)) - { - std::string filename = szFileName; - filename = "\"" + filename + "\" " + arguments[choice]; - std::cout << filename << std::endl; - STARTUPINFOA lpStartupInfo; - PROCESS_INFORMATION lpProcessInfo; + 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]; + std::cout << filename << std::endl; + STARTUPINFOA lpStartupInfo; + PROCESS_INFORMATION lpProcessInfo; - ZeroMemory( &lpStartupInfo, sizeof( lpStartupInfo ) ); - lpStartupInfo.cb = sizeof( lpStartupInfo ); - ZeroMemory( &lpProcessInfo, sizeof( lpProcessInfo ) ); + ZeroMemory( &lpStartupInfo, sizeof( lpStartupInfo ) ); + lpStartupInfo.cb = sizeof( lpStartupInfo ); + ZeroMemory( &lpProcessInfo, sizeof( lpProcessInfo ) ); - CreateProcessA( NULL, - const_cast(filename.c_str()), NULL, NULL, - NULL, NULL, NULL, NULL, - &lpStartupInfo, - &lpProcessInfo - ); - } + CreateProcessA( NULL, + const_cast(filename.c_str()), NULL, NULL, + NULL, NULL, NULL, NULL, + &lpStartupInfo, + &lpProcessInfo + ); + } #else - std::cout << "Please launch the game with these arguments: " << arguments[choice] << std::endl; + std::cout << "Please launch the game with these arguments: " << arguments[choice] << std::endl; #endif + } } } diff --git a/steamclient_loader/ColdClientLoader.cpp b/steamclient_loader/ColdClientLoader.cpp index 6e790ab..ed59f24 100644 --- a/steamclient_loader/ColdClientLoader.cpp +++ b/steamclient_loader/ColdClientLoader.cpp @@ -32,6 +32,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance WCHAR ExeRunDir[MAX_PATH] = { 0 }; WCHAR ExeCommandLine[4096] = { 0 }; WCHAR AppId[128] = { 0 }; + HANDLE SharedMemFileMap = 0; + HANDLE SharedMemFileView = 0; + HANDLE SharedMemFileLock = 0; STARTUPINFOW info = { sizeof(info) }; PROCESS_INFORMATION processInfo; @@ -100,11 +103,38 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance return 0; } + // Create shared mem map. + SharedMemFileMap = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024, L"Local\\SteamStart_SharedMemFile"); + if (!SharedMemFileMap) + { + MessageBoxA(NULL, "Unable to create shared memory mapping.", "ColdClientLoader", MB_ICONERROR); + return 0; + } + SharedMemFileView = MapViewOfFile(SharedMemFileMap, SECTION_ALL_ACCESS, 0, 0, 0); + if (!SharedMemFileView) + { + MessageBoxA(NULL, "Unable to create view of shared memory mapping.", "ColdClientLoader", MB_ICONERROR); + CloseHandle(SharedMemFileMap); + return 0; + } + SharedMemFileLock = CreateEventW(NULL, FALSE, FALSE, L"Local\\SteamStart_SharedMemLock"); + if (!SharedMemFileLock) + { + MessageBoxA(NULL, "Unable to create lock for shared memory mapping.", "ColdClientLoader", MB_ICONERROR); + CloseHandle(SharedMemFileView); + CloseHandle(SharedMemFileMap); + return 0; + } + SetEvent(SharedMemFileLock); + WCHAR CommandLine[8192]; _snwprintf(CommandLine, _countof(CommandLine), L"\"%ls\" %ls", ExeFile, ExeCommandLine); if (!ExeFile[0] || !CreateProcessW(ExeFile, CommandLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ExeRunDir, &info, &processInfo)) { MessageBoxA(NULL, "Unable to load the requested EXE file.", "ColdClientLoader", MB_ICONERROR); + CloseHandle(SharedMemFileLock); + CloseHandle(SharedMemFileView); + CloseHandle(SharedMemFileMap); return 0; } HKEY Registrykey; @@ -130,6 +160,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance { MessageBoxA(NULL, "Unable to patch Steam process informations on the Windows registry.", "ColdClientLoader", MB_ICONERROR); TerminateProcess(processInfo.hProcess, NULL); + CloseHandle(SharedMemFileLock); + CloseHandle(SharedMemFileView); + CloseHandle(SharedMemFileMap); return 0; } } @@ -175,5 +208,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance } } + // Close the SharedMem handles. + CloseHandle(SharedMemFileLock); + CloseHandle(SharedMemFileView); + CloseHandle(SharedMemFileMap); + return 0; }