diff --git a/Readme_release.txt b/Readme_release.txt index b1332f8..2abd87c 100644 --- a/Readme_release.txt +++ b/Readme_release.txt @@ -52,8 +52,9 @@ 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. Custom Broadcast ips: -If you want to set custom ips 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 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. +An example is provided in steam_settings.EXAMPLE\custom_broadcasts.EXAMPLE.txt Support for CPY steam_api(64).dll cracks: See the build in the experimental folder. diff --git a/dll/network.cpp b/dll/network.cpp index 83a8211..94b0c7c 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #endif #define MAX_BROADCASTS 16 @@ -467,6 +468,26 @@ static void socket_timeouts(struct TCP_Socket &socket, double extra_time) } } +std::set Networking::resolve_ip(std::string dns) +{ + std::set ips; + struct addrinfo* result; + + if (getaddrinfo(dns.c_str(), NULL, NULL, &result) == 0) { + for (struct addrinfo *res = result; res != NULL; res = res->ai_next) { + PRINT_DEBUG("%u %u\n", res->ai_addrlen, res->ai_family); + if (res->ai_family == AF_INET) { + struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr; + uint32 ip; + memcpy(&ip, &ipv4->sin_addr, sizeof(ip)); + ips.insert(ntohl(ip)); + } + } + } + + return ips; +} + void Networking::do_callbacks_message(Common_Message *msg) { if (msg->has_network() || msg->has_network_old()) { @@ -682,7 +703,7 @@ 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::vector *custom_broadcasts) +Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts) { run_at_startup(); tcp_port = udp_port = port; @@ -690,8 +711,9 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::vectorappid = appid; - if (custom_broadcasts) - this->custom_broadcasts = *custom_broadcasts; + if (custom_broadcasts) { + std::transform(custom_broadcasts->begin(), custom_broadcasts->end(), std::back_inserter(this->custom_broadcasts), [](uint32 ip) {return htonl(ip);}); + } sock_t sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); PRINT_DEBUG("UDP socket: %u\n", sock); diff --git a/dll/network.h b/dll/network.h index be97049..bc0ce91 100644 --- a/dll/network.h +++ b/dll/network.h @@ -121,7 +121,10 @@ class Networking { Common_Message create_announce(bool request); public: - Networking(CSteamID id, uint32 appid, uint16 port, std::vector *custom_broadcasts); + //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); void addListenId(CSteamID id); void setAppID(uint32 appid); void Run(); diff --git a/dll/steam_client.cpp b/dll/steam_client.cpp index fb4d21f..0602432 100644 --- a/dll/steam_client.cpp +++ b/dll/steam_client.cpp @@ -38,6 +38,19 @@ static void network_thread(Networking *network) } } +static void load_custom_broadcasts(std::string broadcasts_filepath, std::set &custom_broadcasts) +{ + std::ifstream broadcasts_file(broadcasts_filepath); + PRINT_DEBUG("Broadcasts file path: %s\n", broadcasts_filepath.c_str()); + if (broadcasts_file.is_open()) { + std::string line; + while (std::getline(broadcasts_file, line)) { + std::set ips = Networking::resolve_ip(line); + custom_broadcasts.insert(ips.begin(), ips.end()); + } + } +} + Steam_Client::Steam_Client() { std::string program_path = Local_Storage::get_program_path(), save_path = Local_Storage::get_user_appdata_path();; @@ -124,47 +137,9 @@ Steam_Client::Steam_Client() } // Custom broadcasts - std::vector custom_broadcasts; - std::string broadcasts_filepath = local_storage->get_global_settings_path() + "custom_broadcasts.txt"; - - std::ifstream broadcasts_file(broadcasts_filepath); - PRINT_DEBUG("Broadcasts file path: %s\n", broadcasts_filepath.c_str()); - if (broadcasts_file.is_open()) { - std::string line; - while (std::getline(broadcasts_file, line)) { - int offset = 0; - size_t pos = 0; - std::string tok; - uint32_t current_ip = 0; - while((pos = line.find(".")) != std::string::npos && offset < 32) - { - tok = line.substr(0, pos); - try - { - current_ip += (std::stoi(tok) << offset); - } - catch(std::invalid_argument ex) - { - offset = -1; - break; - } - line.erase(0, pos+1); - offset += 8; - } - if(pos == std::string::npos && offset != -1) - { - try - { - current_ip += (std::stoi(line) << offset); - custom_broadcasts.push_back(current_ip); - } - catch(std::invalid_argument ex) - { - - } - } - } - } + std::set custom_broadcasts; + 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); // Acount name char name[32] = {}; diff --git a/files_example/steam_settings.EXAMPLE/custom_broadcasts.EXAMPLE.txt b/files_example/steam_settings.EXAMPLE/custom_broadcasts.EXAMPLE.txt new file mode 100644 index 0000000..9793a97 --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/custom_broadcasts.EXAMPLE.txt @@ -0,0 +1,5 @@ +192.168.3.255 +127.8.9.10 +192.168.66.99 +192.168.7.99 +removethis.test.domain.com