diff --git a/Readme_release.txt b/Readme_release.txt index c0d11e0..a136aeb 100644 --- a/Readme_release.txt +++ b/Readme_release.txt @@ -60,6 +60,10 @@ The steam appid can also be set using the SteamAppId or SteamGameId env variable Offline mode: Some games that connect to online servers might only work if the steam emu behaves like steam is in offline mode. If you need this create a offline.txt file in the steam_settings folder. +Disable networking: +If for some reason you want to disable all the networking functionality of the emu you can create a disable_networking.txt file in the steam_settings folder. This will of course break all the +networking functionality so games that use networking related functionality like lobbies or those that launch a server in the background will not work. + Custom Broadcast ips: If you want to set custom ips (or domains) which the emulator will send broadcast packets to, make a list of them, one on each line in: Goldberg SteamEmu Saves\settings\custom_broadcasts.txt If the custom ips/domains are specific for one game only you can put the custom_broadcasts.txt in the steam_settings\ folder. diff --git a/dll/network.cpp b/dll/network.cpp index 7b2628a..e726a5c 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -706,18 +706,26 @@ bool Networking::handle_low_level_udp(Common_Message *msg, IP_PORT ip_port) #define NUM_TCP_WAITING 128 -Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts) +Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts, bool disable_sockets) { - run_at_startup(); tcp_port = udp_port = port; own_ip = 0x7F000001; alive = true; last_run = std::chrono::high_resolution_clock::now(); this->appid = appid; + + if (disable_sockets) { + enabled = false; + udp_socket = -1; + tcp_socket = -1; + return; + } + if (custom_broadcasts) { std::transform(custom_broadcasts->begin(), custom_broadcasts->end(), std::back_inserter(this->custom_broadcasts), [](uint32 ip) {return htonl(ip);}); } + run_at_startup(); sock_t sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); PRINT_DEBUG("UDP socket: %u\n", sock); if (is_socket_valid(sock) && set_socket_nonblocking(sock)) { @@ -1054,6 +1062,7 @@ void Networking::Run() void Networking::addListenId(CSteamID id) { + if (!enabled) return; auto i = std::find(ids.begin(), ids.end(), id); if (i != ids.end()) { return; @@ -1087,6 +1096,8 @@ bool Networking::sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool bool Networking::sendTo(Common_Message *msg, bool reliable, Connection *conn) { + if (!enabled) return false; + bool ret = false; CSteamID dest_id((uint64)msg->dest_id()); if (std::find(ids.begin(), ids.end(), dest_id) != ids.end()) { diff --git a/dll/network.h b/dll/network.h index bc0ce91..1a8c064 100644 --- a/dll/network.h +++ b/dll/network.h @@ -124,7 +124,7 @@ public: //NOTE: for all functions ips/ports are passed/returned in host byte order //ex: 127.0.0.1 should be passed as 0x7F000001 static std::set resolve_ip(std::string dns); - Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts); + Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts, bool disable_sockets); void addListenId(CSteamID id); void setAppID(uint32 appid); void Run(); diff --git a/dll/settings.h b/dll/settings.h index a5efb5b..cfb06b0 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -135,6 +135,9 @@ public: //controller struct Controller_Settings controller_settings; + + //networking + bool disable_networking = false; }; #endif diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 42849d3..ca12e85 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -247,6 +247,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } bool steam_offline_mode = false; + bool disable_networking = false; { std::string steam_settings_path = Local_Storage::get_game_settings_path(); @@ -255,6 +256,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s PRINT_DEBUG("steam settings path %s\n", p.c_str()); if (p == "offline.txt") { steam_offline_mode = true; + } else if (p == "disable_networking.txt") { + disable_networking = true; } } } @@ -265,6 +268,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->disable_networking = disable_networking; + settings_server->disable_networking = disable_networking; { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; diff --git a/dll/steam_client.cpp b/dll/steam_client.cpp index d81f90c..f7b5fe7 100644 --- a/dll/steam_client.cpp +++ b/dll/steam_client.cpp @@ -45,7 +45,7 @@ Steam_Client::Steam_Client() uint32 appid = create_localstorage_settings(&settings_client, &settings_server, &local_storage); std::string items_db_file_path = (Local_Storage::get_game_settings_path() + "items.json"); - network = new Networking(settings_server->get_local_steam_id(), appid, settings_server->get_port(), &(settings_server->custom_broadcasts)); + network = new Networking(settings_server->get_local_steam_id(), appid, settings_server->get_port(), &(settings_server->custom_broadcasts), settings_server->disable_networking); callback_results_client = new SteamCallResults(); callback_results_server = new SteamCallResults();