Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2026-01-22 02:05:16 +00:00
5 changed files with 249 additions and 157 deletions
+38 -26
View File
@@ -75,11 +75,11 @@ std::string read_vr_manifest(const std::filesystem::path & root)
return read_file(root / "config/steamapps.vrmanifest"); return read_file(root / "config/steamapps.vrmanifest");
} }
steam_app_info read_steam_app_info(const std::filesystem::path & root) std::unordered_map<uint32_t, wivrn::steam_icon> safe_read_steam_icons(const std::filesystem::path & root)
{ {
try try
{ {
return steam_app_info{root / "appcache/appinfo.vdf"}; return read_steam_icons(root / "appcache/appinfo.vdf");
} }
catch (...) catch (...)
{} {}
@@ -87,14 +87,15 @@ steam_app_info read_steam_app_info(const std::filesystem::path & root)
return {}; return {};
} }
std::optional<std::filesystem::path> find_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info) std::optional<std::filesystem::path> find_steam_icon(const std::filesystem::path & root, int app_id, const std::unordered_map<uint32_t, wivrn::steam_icon> & info)
{ {
const auto & app_info = info.get(app_id); auto icon = info.find(app_id);
if (icon == info.end())
return std::nullopt;
try try
{ {
std::string icon{std::get<std::string_view>(app_info.at("common.clienticon"))}; auto icon_path = root / "steam/games" / (icon->second.clienticon + ".ico");
auto icon_path = root / "steam/games" / (icon + ".ico");
if (std::filesystem::exists(icon_path)) if (std::filesystem::exists(icon_path))
return icon_path; return icon_path;
@@ -105,10 +106,7 @@ std::optional<std::filesystem::path> find_steam_icon(const std::filesystem::path
try try
{ {
std::string icon{std::get<std::string_view>(app_info.at("common.linuxclienticon"))}; auto icon_path = root / "steam/games" / (icon->second.linuxclienticon + ".zip");
auto icon_path = root / "steam/games" / (icon + ".zip");
if (std::filesystem::exists(icon_path)) if (std::filesystem::exists(icon_path))
return icon_path; return icon_path;
} }
@@ -126,7 +124,7 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
return; return;
auto manifest = read_vr_manifest(*root); auto manifest = read_vr_manifest(*root);
auto info = read_steam_app_info(*root); auto info = safe_read_steam_icons(*root);
if (manifest.empty()) if (manifest.empty())
return; return;
@@ -138,6 +136,11 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
{ {
application app; application app;
if (i["launch_type"] == "url")
app.exec = command + " " + (std::string)i["url"];
else
continue;
std::string app_key = i["app_key"]; std::string app_key = i["app_key"];
for (auto [locale, items]: i["strings"].items()) for (auto [locale, items]: i["strings"].items())
{ {
@@ -154,21 +157,6 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
app.name[""] = it->second; app.name[""] = it->second;
} }
if (i["launch_type"] == "url")
{
app.exec = command + " " + (std::string)i["url"];
}
else if (i["launch_type"] == "binary")
{
const char prefix[] = "steam.app.";
if (app_key.starts_with(prefix))
{
// ¯\_(ツ)_/¯
uint64_t appkey = stoll(app_key.substr(strlen(prefix)));
app.exec = command + " steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000);
}
}
try try
{ {
const char prefix[] = "steam.app."; const char prefix[] = "steam.app.";
@@ -190,6 +178,30 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
std::cerr << "Failed to parse Steam VR manifest: " << e.what() << std::endl; std::cerr << "Failed to parse Steam VR manifest: " << e.what() << std::endl;
} }
} }
for (auto const & entry: std::filesystem::directory_iterator{*root / "userdata"})
{
auto shortcuts_vdf = entry.path() / "config/shortcuts.vdf";
if (std::filesystem::exists(shortcuts_vdf))
{
try
{
for (auto && item: read_steam_shortcuts(shortcuts_vdf))
{
res[std::to_string(item.appid)] = {
.name = {{"", std::move(item.name)}},
// ¯\_(ツ)_/¯
.exec = command + " steam://rungameid/" + std::to_string((uint64_t(item.appid) << 32) + 0x2000000),
.icon_path = std::move(item.icon),
};
}
}
catch (std::exception & e)
{
std::cerr << "Failed to parse Steam shortcuts file " << shortcuts_vdf << ": " << e.what() << std::endl;
}
}
}
} }
std::string unescape(std::string_view in) std::string unescape(std::string_view in)
+190 -102
View File
@@ -18,169 +18,257 @@
#include "steam_app_info.h" #include "steam_app_info.h"
#include <bit> #include <bit>
#include <cctype>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <span> #include <iostream>
#include <string_view>
namespace namespace
{ {
template <typename T>
T read(std::span<char> & buffer);
template <typename T> class binary_reader
requires std::is_integral_v<T>
T read(std::span<char> & buffer)
{ {
if (sizeof(T) > buffer.size()) std::ifstream in;
throw std::runtime_error{"File truncated"};
T value; public:
memcpy(&value, buffer.data(), sizeof(T)); binary_reader(std::ifstream && in) : in{std::move(in)} {}
buffer = buffer.subspan(sizeof(T));
static_assert(std::endian::native == std::endian::big or std::endian::native == std::endian::little); void discard(size_t bytes)
{
in.seekg(bytes, std::ios_base::cur);
}
if constexpr (std::endian::native == std::endian::big) template <typename T>
return std::byteswap(value); T read();
else
return value; template <typename T>
} requires std::is_integral_v<T>
T read()
{
T res;
in.read((char *)&res, sizeof(T));
if (not in)
throw std::runtime_error{"File truncated"};
static_assert(std::endian::native == std::endian::big or std::endian::native == std::endian::little);
if constexpr (std::endian::native == std::endian::big)
return std::byteswap(res);
else
return res;
}
std::vector<std::string> string_table();
auto tellg()
{
return in.tellg();
}
void seekg(size_t pos)
{
in.seekg(pos);
}
};
template <> template <>
std::string_view read<std::string_view>(std::span<char> & buffer) std::string binary_reader::read()
{ {
size_t size = strnlen((char *)buffer.data(), buffer.size()); std::string res;
if (size == buffer.size()) std::getline(in, res, '\0');
if (not in)
throw std::runtime_error{"File truncated"}; throw std::runtime_error{"File truncated"};
return res;
char * str = buffer.data();
buffer = buffer.subspan(size + 1);
return {str, size};
} }
std::span<char> read(std::span<char> & buffer, size_t size) std::vector<std::string> binary_reader::string_table()
{ {
if (size > buffer.size()) std::vector<std::string> res;
throw std::runtime_error{"File truncated"}; size_t string_offset = read<uint64_t>();
auto pos = in.tellg();
std::span<char> value{buffer.data(), size}; in.seekg(string_offset);
buffer = buffer.subspan(size); auto count = read<uint32_t>();
return value; res.reserve(count);
for (size_t i = 0; i < count; ++i)
res.emplace_back(read<std::string>());
in.seekg(pos);
return res;
} }
std::vector<std::string_view> read_string_table(std::span<char> buffer) template <typename T>
void read_dict(binary_reader & in, T & visitor, const std::vector<std::string> * string_table = nullptr)
{ {
std::vector<std::string_view> string_table; while (true)
uint32_t count = read<uint32_t>(buffer);
string_table.reserve(count);
for (size_t i = 0; i < count; i++)
string_table.emplace_back(read<std::string_view>(buffer));
return string_table;
}
void read_vdf(wivrn::steam_app_info::info & info, const std::string & prefix, std::span<char> & bindata, const std::vector<std::string_view> & string_table)
{
int type = read<uint8_t>(bindata);
while (type != 8)
{ {
std::string name{string_table.at(read<uint32_t>(bindata))}; auto type = in.read<uint8_t>();
for (char & c: name) if (type == 8)
c = std::tolower(c); {
visitor.end_dict();
return;
}
// https://github.com/ValveResourceFormat/ValveKeyValue/blob/master/ValveKeyValue/ValveKeyValue/KeyValues1/KV1BinaryNodeType.cs // Key
const std::string & key = string_table ? string_table->at(in.read<uint32_t>()) : in.read<std::string>();
// Value
switch (type) switch (type)
{ {
case 0: // Dictionary case 0: // Dictionary
read_vdf(info, prefix + name + ".", bindata, string_table); visitor.begin_dict(key);
read_dict(in, visitor, string_table);
break; break;
case 1: // UTF-8 string case 1: // UTF-8 string
info.emplace(prefix + name, read<std::string_view>(bindata)); visitor.on_string(key, in.read<std::string>());
break; break;
case 2: // uint32_t case 2: // uint32_t
info.emplace(prefix + name, read<uint32_t>(bindata)); visitor.on_uint32_t(key, in.read<uint32_t>());
break; break;
// case 3: // float // case 3: // float
// break;
default: default:
throw std::runtime_error{"Unknown object type " + std::to_string(type)}; throw std::runtime_error{"Unknown object type " + std::to_string(type)};
} }
type = read<uint8_t>(bindata);
} }
} }
} // namespace } // namespace
wivrn::steam_app_info::steam_app_info(std::filesystem::path path) std::unordered_map<uint32_t, wivrn::steam_icon> wivrn::read_steam_icons(std::filesystem::path path)
{ {
std::vector<std::string_view> string_table; binary_reader in{std::ifstream{path}};
{ uint32_t magic = in.read<uint32_t>();
std::ifstream f{path};
data = std::vector<char>{std::istreambuf_iterator{f}, {}};
}
std::span<char> buffer = data;
// See https://github.com/SteamDatabase/SteamAppInfo/blob/master/README.md#file-header
uint32_t magic = read<uint32_t>(buffer);
if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00) if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00)
throw std::runtime_error{"Wrong magic number"}; throw std::runtime_error{"Wrong magic number"};
auto universe = in.read<uint32_t>();
int version = magic & 0xff; int version = magic & 0xff;
if (version < 41) std::vector<std::string> string_table;
throw std::runtime_error{"Unsupported version"}; std::vector<std::string> * string_table_ptr = nullptr;
int universe = read<uint32_t>(buffer);
if (version >= 41) if (version >= 41)
{ {
size_t string_offset = read<uint64_t>(buffer); string_table = in.string_table();
string_table = read_string_table(std::span<char>{data}.subspan(string_offset)); string_table_ptr = &string_table;
} }
else
throw std::runtime_error{"Unsupported version"}; std::unordered_map<uint32_t, wivrn::steam_icon> res;
struct V
{
wivrn::steam_icon current{};
void begin_dict(const std::string & key)
{
}
void end_dict()
{
}
void on_string(const std::string & key, std::string && val)
{
if (key == "clienticon")
current.clienticon = std::move(val);
else if (key == "linuxclienticon")
current.linuxclienticon = std::move(val);
}
void on_uint32_t(const std::string & key, uint32_t val)
{
}
};
while (true) while (true)
{ {
// See https://github.com/SteamDatabase/SteamAppInfo/blob/master/README.md#app-entry-repeated // See https://github.com/SteamDatabase/SteamAppInfo/blob/master/README.md#app-entry-repeated
auto app_id = in.read<uint32_t>();
auto app_id = read<uint32_t>(buffer);
if (app_id == 0) if (app_id == 0)
break; break;
auto size_data = read<uint32_t>(buffer); size_t size_data = in.read<uint32_t>();
char * current_offset = buffer.data(); size_t pos = in.tellg();
in.discard(
read<uint32_t>(buffer); // info_state 4 // info_state
read<uint32_t>(buffer); // last_updated + 4 // last_updated
read<uint64_t>(buffer); // pics_token + 8 // pics_token
read(buffer, 20); // SHA1 of the app info + 20 // SHA1 of the app info
read<uint32_t>(buffer); // change number + 4 // change number
// if (version < 38) + 20 // SHA1 of the bin data
// read<uint8_t>(buffer); // section type + 4 // checksum
read(buffer, 20); // SHA1 of the bin data + 1 // type
auto bindata = read(buffer, size_data - (buffer.data() - current_offset)); );
try try
{ {
bindata = bindata.subspan(4 + 1); // Skip the checksum + type (must be 0) V v;
read_dict(in, v, string_table_ptr);
info app_info; if (not(v.current.clienticon.empty() and v.current.linuxclienticon.empty()))
read_vdf(app_info, "", bindata, string_table); res.emplace(app_id, std::move(v.current));
app_data.emplace(app_id, app_info);
} }
catch (...) catch (...)
{ {
// Ignore errors // Ignore errors
} }
in.seekg(pos + size_data);
} }
return res;
}
std::vector<wivrn::steam_shortcut> wivrn::read_steam_shortcuts(std::filesystem::path path)
{
binary_reader in{std::ifstream{path}};
auto type = in.read<uint8_t>();
auto name = in.read<std::string>();
if (type != 0 or name != "shortcuts")
throw std::runtime_error{"Invalid type for shortcuts file"};
std::vector<wivrn::steam_shortcut> res;
struct V
{
std::vector<wivrn::steam_shortcut> & items;
int depth = 0;
wivrn::steam_shortcut current{};
bool VR = false;
void begin_dict(const std::string & key)
{
++depth;
if (depth == 1)
{
current = decltype(current){};
VR = false;
}
}
void end_dict()
{
--depth;
if (depth == 0)
{
if (VR)
items.push_back(std::move(current));
}
}
void on_string(const std::string & key, std::string && val)
{
if (depth == 1)
{
if (key == "AppName")
current.name = std::move(val);
else if (key == "icon")
current.icon = std::move(val);
}
}
void on_uint32_t(const std::string & key, uint32_t val)
{
if (depth == 1)
{
if (key == "appid")
current.appid = val;
if (key == "OpenVR")
VR = val;
}
}
} v{res};
read_dict(in, v);
return res;
} }
+16 -22
View File
@@ -19,33 +19,27 @@
#pragma once #pragma once
#include <filesystem> #include <filesystem>
#include <optional>
#include <unordered_map> #include <unordered_map>
#include <variant>
#include <vector> #include <vector>
namespace wivrn namespace wivrn
{ {
class steam_app_info
struct steam_icon
{ {
public: std::string clienticon;
using info = std::unordered_map<std::string, std::variant<uint32_t, std::string_view>>; std::string linuxclienticon;
private:
std::vector<char> data;
std::unordered_map<int, info> app_data;
public:
steam_app_info(std::filesystem::path path);
steam_app_info() = default;
steam_app_info(const steam_app_info &) = delete;
steam_app_info(steam_app_info &&) = default;
steam_app_info & operator=(const steam_app_info &) = delete;
steam_app_info & operator=(steam_app_info &&) = default;
const auto & get(int appid) const
{
return app_data.at(appid);
}
}; };
struct steam_shortcut
{
uint32_t appid;
std::string name;
std::optional<std::filesystem::path> icon;
};
std::unordered_map<uint32_t, steam_icon> read_steam_icons(std::filesystem::path path);
std::vector<steam_shortcut> read_steam_shortcuts(std::filesystem::path path);
} // namespace wivrn } // namespace wivrn
-7
View File
@@ -137,10 +137,6 @@ struct pipewire_device : public audio_device
// Declare target latency to help PipeWire optimize buffering // Declare target latency to help PipeWire optimize buffering
PW_KEY_NODE_LATENCY, PW_KEY_NODE_LATENCY,
latency_str.c_str(), latency_str.c_str(),
// Force constant quantum size to prevent dynamic buffer size changes
// Variable buffer sizes cause crackling in effect processors (EasyEffects)
PW_KEY_NODE_FORCE_QUANTUM,
latency_str.c_str(),
NULL), NULL),
&speaker_events, &speaker_events,
this)); this));
@@ -210,9 +206,6 @@ struct pipewire_device : public audio_device
// Declare target latency to help PipeWire optimize buffering // Declare target latency to help PipeWire optimize buffering
PW_KEY_NODE_LATENCY, PW_KEY_NODE_LATENCY,
latency_str.c_str(), latency_str.c_str(),
// Force constant quantum size to prevent dynamic buffer size changes
PW_KEY_NODE_FORCE_QUANTUM,
latency_str.c_str(),
NULL), NULL),
&mic_events, &mic_events,
this)); this));
+5
View File
@@ -201,6 +201,11 @@ void systemd_units_manager::start_application(const std::vector<std::string> & a
if (args.empty()) if (args.empty())
return; return;
std::cerr << "Launching";
for (const auto & i: args)
std::cerr << " " << std::quoted(i);
std::cerr << std::endl;
std::string service_name = std::format("wivrn-application-{}.service", std::chrono::steady_clock::now().time_since_epoch().count()); std::string service_name = std::format("wivrn-application-{}.service", std::chrono::steady_clock::now().time_since_epoch().count());
variant_builder b(G_VARIANT_TYPE("a(sv)")); variant_builder b(G_VARIANT_TYPE("a(sv)"));