diff --git a/.gitmodules b/.gitmodules index c7c1a48..2cce4e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "proto/proto"] path = proto/proto url = https://github.com/SteamDatabase/Protobufs +[submodule "abigen/proton"] + path = abigen/proton + url = https://github.com/ValveSoftware/Proton diff --git a/Cargo.lock b/Cargo.lock index 4536fa8..fb7a39c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,6 +197,26 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c044c781163c001b913cd018fc95a628c50d0d2dfea8bca77dad71edb16e37" +dependencies = [ + "clang-sys", + "libc", +] + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", +] + [[package]] name = "color-eyre" version = "0.6.3" @@ -552,6 +572,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1955,6 +1981,17 @@ dependencies = [ "vapore-struct", ] +[[package]] +name = "vapore-abigen" +version = "0.1.0" +dependencies = [ + "clang", + "color-eyre", + "env_logger", + "log", + "regex", +] + [[package]] name = "vapore-client" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 298f355..0dcfbcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] resolver = "2" members = [ + "abigen", "client", "lib", "proto", diff --git a/abigen/Cargo.toml b/abigen/Cargo.toml new file mode 100644 index 0000000..81b8124 --- /dev/null +++ b/abigen/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "vapore-abigen" +edition = "2021" +version.workspace = true + +[dependencies] +clang = { version = "2.0.0", features = ["clang_10_0"] } +color-eyre.workspace = true +env_logger.workspace = true +log.workspace = true +regex = "1.10.6" diff --git a/abigen/proton b/abigen/proton new file mode 160000 index 0000000..962bbc4 --- /dev/null +++ b/abigen/proton @@ -0,0 +1 @@ +Subproject commit 962bbc4e74dde0643a6edab7c845bc628601f23f diff --git a/abigen/src/main.rs b/abigen/src/main.rs new file mode 100644 index 0000000..2a6c95c --- /dev/null +++ b/abigen/src/main.rs @@ -0,0 +1,56 @@ +use std::{collections::HashMap, env, path::PathBuf, vec}; + +use clang::{Entity, EntityKind}; +use color_eyre::eyre; +use regex::Regex; + +fn main() -> eyre::Result<()> { + env_logger::init(); + color_eyre::install()?; + + let re = Regex::new(r#"^#define\s*(STEAM[A-Z]*)_INTERFACE_VERSION\s*"([a-zA-Z0-9_]*)"$"#)?; + + let lsteamclient_path = + PathBuf::from(env::var_os("PROTON_SOURCE").unwrap_or_else(|| "proton".into())) + .join("lsteamclient"); + + let clang = clang::Clang::new().unwrap(); + + let index = clang::Index::new(&clang, false, false); + + let parsed = index + .parser( + lsteamclient_path + .join("steamworks_sdk_160") + .join("steam_api.h"), + ) + .arguments(&["-x", "c++"]) + .detailed_preprocessing_record(true) + .parse()?; + + let mut classes = Vec::new(); + // let mut interfaces = HashMap::new(); + + for child in parsed.get_entity().get_children() { + if child.get_kind() == EntityKind::ClassDecl { + let Some(class_name) = child.get_name() else { + continue; + }; + + if !class_name.starts_with("ISteam") { + continue; + }; + + if child.get_children().len() == 0 { + continue; + } + + log::info!("Found class `{}`", class_name); + classes.push(class_name); + } + } + + + + Ok(()) +} diff --git a/flake.nix b/flake.nix index 60cfff6..8bd7005 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ { devShells.default = with pkgs; - mkShell { + (mkShell.override { stdenv = llvmPackages.stdenv; }) { packages = [ rustPackages.cargo rustPackages.rustc @@ -27,6 +27,8 @@ protobuf ]; + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; + RUST_SRC_PATH = "${rustPackages.rustPlatform.rustLibSrc}"; RUST_LOG = "debug,vapore=trace,vapore-client=trace"; RUST_BACKTRACE = "1";