improved tools\generate_interfaces\generate_interfaces.cpp + fixed finding of "STEAMCONTROLLER_INTERFACE_VERSION" interface

This commit is contained in:
Sak32009 2024-08-24 20:02:04 +02:00
parent 935d3405a9
commit 63857ceb4e

View File

@ -1,16 +1,14 @@
#include <regex> #include <regex>
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <streambuf>
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
// these are defined in dll.cpp at the top like this: // these are defined in dll.cpp at the top like this:
// static char old_xxx[128] = ... // static char old_xxx[128] = ...
const static std::vector<std::string> interface_patterns = { const static std::vector<std::string> interface_patterns = {
R"(SteamClient\d+)", R"(SteamClient\d+)",
R"(SteamGameServerStats\d+)", R"(SteamGameServerStats\d+)",
R"(SteamGameServer\d+)", R"(SteamGameServer\d+)",
@ -27,10 +25,10 @@ const static std::vector<std::string> interface_patterns = {
R"(STEAMSCREENSHOTS_INTERFACE_VERSION\d+)", R"(STEAMSCREENSHOTS_INTERFACE_VERSION\d+)",
R"(STEAMHTTP_INTERFACE_VERSION\d+)", R"(STEAMHTTP_INTERFACE_VERSION\d+)",
R"(STEAMUNIFIEDMESSAGES_INTERFACE_VERSION\d+)", R"(STEAMUNIFIEDMESSAGES_INTERFACE_VERSION\d+)",
R"(STEAMCONTROLLER_INTERFACE_VERSION\d+)", R"(STEAMCONTROLLER_INTERFACE_VERSION)",
R"(SteamController\d+)", R"(SteamController\d+)",
R"(STEAMUGC_INTERFACE_VERSION\d+)", R"(STEAMUGC_INTERFACE_VERSION\d+)",
R"(STEAMAPPLIST_INTERFACE_VERSION\d+)", R"(STEAMAPPLIST_INTERFACE_VERSION\d+)",
R"(STEAMMUSIC_INTERFACE_VERSION\d+)", R"(STEAMMUSIC_INTERFACE_VERSION\d+)",
@ -47,56 +45,64 @@ unsigned int findinterface(
const std::string &interface_patt) const std::string &interface_patt)
{ {
std::regex interface_regex(interface_patt); std::regex interface_regex(interface_patt);
auto begin = std::sregex_iterator(file_contents.begin(), file_contents.end(), interface_regex);
auto begin = std::sregex_iterator(file_contents.cbegin(), file_contents.cend(), interface_regex);
auto end = std::sregex_iterator(); auto end = std::sregex_iterator();
unsigned int matches = 0; unsigned int matches = 0;
for (std::sregex_iterator i = begin; i != end; ++i) {
std::smatch match = *i; for (std::sregex_iterator i = begin; i != end; ++i)
std::string match_str = match.str(); {
out_file << match_str << std::endl; out_file << i->str() << std::endl;
++matches; ++matches;
} }
return matches; return matches;
} }
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 2) { if (argc < 2)
{
std::cerr << "usage: " << argv[0] << " <path to steam_api .dll or .so>" << std::endl; std::cerr << "usage: " << argv[0] << " <path to steam_api .dll or .so>" << std::endl;
return 1; return 1;
} }
std::ifstream steam_api_file(std::filesystem::u8path(argv[1]), std::ios::binary); std::ifstream steam_api_file(std::filesystem::u8path(argv[1]), std::ios::binary);
if (!steam_api_file.is_open()) { if (!steam_api_file)
std::cerr << "Error opening file" << std::endl; {
std::cerr << "Error opening file: " << argv[1] << std::endl;
return 1; return 1;
} }
std::string steam_api_contents( std::string steam_api_contents((std::istreambuf_iterator<char>(steam_api_file)), std::istreambuf_iterator<char>());
(std::istreambuf_iterator<char>(steam_api_file)),
std::istreambuf_iterator<char>());
steam_api_file.close(); steam_api_file.close();
if (steam_api_contents.size() == 0) { if (steam_api_contents.empty())
{
std::cerr << "Error loading data" << std::endl; std::cerr << "Error loading data" << std::endl;
return 1; return 1;
} }
unsigned int total_matches = 0; std::ofstream out_file("steam_interfaces.txt");
std::ofstream out_file(std::filesystem::u8path("steam_interfaces.txt")); if (!out_file)
if (!out_file.is_open()) { {
std::cerr << "Error opening output file" << std::endl; std::cerr << "Error opening output file" << std::endl;
return 1; return 1;
} }
for (const auto &patt : interface_patterns) { unsigned int total_matches = 0;
for (const auto &patt : interface_patterns)
{
total_matches += findinterface(out_file, steam_api_contents, patt); total_matches += findinterface(out_file, steam_api_contents, patt);
} }
out_file.close(); out_file.close();
if (total_matches == 0) { if (total_matches == 0)
{
std::cerr << "No interfaces were found" << std::endl; std::cerr << "No interfaces were found" << std::endl;
return 1; return 1;
} }