From 5b71d4623dcb591a1a3a3245b647b50116de127a Mon Sep 17 00:00:00 2001 From: QtKai <15091327+QtKaii@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:36:45 +0000 Subject: [PATCH 1/3] Started with extension. Lgtm so far. --- Cargo.lock | 34 ++++++++++++++++ Cargo.toml | 1 + shrimpstats_tf2/.cargo/config.toml | 16 ++++++++ shrimpstats_tf2/Cargo.toml | 16 ++++++++ shrimpstats_tf2/src/lib.rs | 65 ++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 shrimpstats_tf2/.cargo/config.toml create mode 100644 shrimpstats_tf2/Cargo.toml create mode 100644 shrimpstats_tf2/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3a7c9af..a0f455f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "c_str_macro" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d44951c469019e225e7667d799052f67fb8ea358d086878f3582b39f0de5e5" + [[package]] name = "cc" version = "1.0.83" @@ -1288,6 +1294,13 @@ dependencies = [ "digest", ] +[[package]] +name = "shrimpstats_tf2" +version = "0.1.0" +dependencies = [ + "sm-ext", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1306,6 +1319,26 @@ dependencies = [ "autocfg", ] +[[package]] +name = "sm-ext" +version = "0.3.0" +source = "git+https://github.com/asherkin/sm-ext-rs.git?rev=8e8d87b#8e8d87bdd234ce6acdcd84907e319fe4b73aa8d5" +dependencies = [ + "c_str_macro", + "libc", + "sm-ext-derive", +] + +[[package]] +name = "sm-ext-derive" +version = "0.3.0" +source = "git+https://github.com/asherkin/sm-ext-rs.git?rev=8e8d87b#8e8d87bdd234ce6acdcd84907e319fe4b73aa8d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "smallvec" version = "1.13.1" @@ -1329,6 +1362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", + "quote", "unicode-ident", ] diff --git a/Cargo.toml b/Cargo.toml index 946945c..12d6a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ members = [ "webapp/axum_htmx", "webapp/yew_csr", "api", + "shrimpstats_tf2", ] diff --git a/shrimpstats_tf2/.cargo/config.toml b/shrimpstats_tf2/.cargo/config.toml new file mode 100644 index 0000000..2737728 --- /dev/null +++ b/shrimpstats_tf2/.cargo/config.toml @@ -0,0 +1,16 @@ +# windows target +[target.x86_64-pc-windows-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.i686-pc-windows-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.i686-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.x86_64-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] + +# linux target +[target.x86_64-unknown-linux-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] \ No newline at end of file diff --git a/shrimpstats_tf2/Cargo.toml b/shrimpstats_tf2/Cargo.toml new file mode 100644 index 0000000..71b40d7 --- /dev/null +++ b/shrimpstats_tf2/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "shrimpstats_tf2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +# -C target-feature=+crt-static + +# windows target +[target.'cfg(all(target_arch="x86_64", target_os="windows"))'] +rustfl = ["-Ctarget-feature=+crt-static"] + + +[dependencies] +sm-ext = { git = "https://github.com/asherkin/sm-ext-rs.git", rev = "8e8d87b"} diff --git a/shrimpstats_tf2/src/lib.rs b/shrimpstats_tf2/src/lib.rs new file mode 100644 index 0000000..7e839ac --- /dev/null +++ b/shrimpstats_tf2/src/lib.rs @@ -0,0 +1,65 @@ +#![deny( + unsafe_code, + clippy::correctness, + clippy::nursery, + clippy::pedantic, + clippy::complexity, + clippy::perf, + clippy::style, + clippy::suspicious +)] + + +use sm_ext::{forwards, native, ExecType, ICallableApi, IExtension, IExtensionInterface, IShareSys, SMExtension}; + +#[derive(Default, SMExtension)] +#[extension(name = "shrimpstats_tf2", description = "ShrimpStats TF2 Extension")] +pub struct ShrimpStatsTF2Extension; + + +// Name: player_death +// Structure: +// short userid user ID who died +// long victim_entindex +// long inflictor_entindex ent index of inflictor (a sentry, for example) +// short attacker user ID who killed +// string weapon weapon name killer used +// short weaponid ID of weapon killed used +// long damagebits bits of type of damage +// short customkill type of custom kill +// short assister user ID of assister +// string weapon_logclassname weapon name that should be printed on the log +// short stun_flags victim's stun flags at the moment of death +// short death_flags death flags. +// bool silent_kill +// short playerpenetratecount +// string assister_fallback contains a string to use if "assister" is -1 +// short kill_streak_total Kill streak count (level) +// short kill_streak_wep Kill streak for killing weapon +// short kill_streak_assist Kill streak for assister count +// short kill_streak_victim Victims kill streak +// short ducks_streaked Duck streak increment from this kill +// short duck_streak_total Duck streak count for attacker +// short duck_streak_assist Duck streak count for assister +// short duck_streak_victim (former) duck streak count for victim +// bool rocket_jump was the victim rocket jumping +// short weapon_def_index item def index of weapon killer used +// short crit_type Crit type of kill. (0: None, 1: Mini, 2: Full) + +// #[forwards] +// pub struct ShrimpStatsTF2ExtensionForward{ +// #[global_forward("player_death", ExecType::Hook)] +// pub player_death: fn(userid: i32, victim_entindex: i32, inflictor_entindex: i32, attacker: i32, weapon: , weaponid: i32, damagebits: i32, customkill: i32, assister: i32, weapon_logclassname: String, stun_flags: i32, death_flags: u8, silent_kill: bool, playerpenetratecount: u8, assister_fallback: String, kill_streak_total: u8, kill_streak_wep: u8, kill_streak_assist: u8, kill_streak_victim: u8, ducks_streaked: u8, duck_streak_total: u8, duck_streak_assist: u8, duck_streak_victim: u8, rocket_jump: bool, weapon_def_index: i32, crit_type: u8) +// } + +impl IExtensionInterface for ShrimpStatsTF2Extension { + fn on_extension_load(&mut self, _me: IExtension, _sys: IShareSys, _late: bool) -> Result<(), Box> { + + Ok(()) + } + + fn on_extension_unload(&mut self) {} + + fn on_extensions_all_loaded(&mut self) { + } +} \ No newline at end of file From 14a33cc1d87a8416c3ca96a380c6bf9a6a97f104 Mon Sep 17 00:00:00 2001 From: QtKai <15091327+QtKaii@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:59:22 +0000 Subject: [PATCH 2/3] Update dependencies and add new forward manager interface --- Cargo.lock | 10 +++++--- api/src/main.rs | 29 ++++++++++++++++++--- shrimpstats_tf2/Cargo.toml | 10 +++----- shrimpstats_tf2/src/lib.rs | 52 ++++++++++++-------------------------- 4 files changed, 50 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0f455f..0f10072 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1322,7 +1322,8 @@ dependencies = [ [[package]] name = "sm-ext" version = "0.3.0" -source = "git+https://github.com/asherkin/sm-ext-rs.git?rev=8e8d87b#8e8d87bdd234ce6acdcd84907e319fe4b73aa8d5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcdcd9d45b7f6d92ab1fa4dc1a9090d59ccdceab4f94aa51991c3ef0d73c8fda" dependencies = [ "c_str_macro", "libc", @@ -1332,7 +1333,8 @@ dependencies = [ [[package]] name = "sm-ext-derive" version = "0.3.0" -source = "git+https://github.com/asherkin/sm-ext-rs.git?rev=8e8d87b#8e8d87bdd234ce6acdcd84907e319fe4b73aa8d5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75e96380b9fa81d50460fa1240990754e7f5766a74ffa5791f0cf43f50e56fc2" dependencies = [ "proc-macro2", "quote", @@ -1589,9 +1591,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" diff --git a/api/src/main.rs b/api/src/main.rs index cf69430..daa855f 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -6,7 +6,8 @@ clippy::complexity, clippy::perf, clippy::style, - clippy::suspicious + clippy::suspicious, + clippy::restriction )] use axum::{ @@ -14,16 +15,36 @@ use axum::{ Router, }; +use tokio::net::TcpListener; + #[tokio::main] async fn main() { + + let x = 5_i32; + let app = Router::new().route("/", get(root)); - let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + let listener = match TcpListener::bind("0.0.0.0:3000").await { + Ok(x) => x, + Err(e) => { + println!("Error: {}", e); + return; + } + + }; - axum::serve(listener, app).await.unwrap(); + + + match axum::serve(listener, app).await { + Ok(x) => x, + Err(e) => { + println!("Error: {}", e); + return; + } + }; } -// basic handler that responds with a static string + async fn root() -> &'static str { "Hello, World!" } \ No newline at end of file diff --git a/shrimpstats_tf2/Cargo.toml b/shrimpstats_tf2/Cargo.toml index 71b40d7..d4d2fc9 100644 --- a/shrimpstats_tf2/Cargo.toml +++ b/shrimpstats_tf2/Cargo.toml @@ -4,13 +4,9 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -# -C target-feature=+crt-static - -# windows target -[target.'cfg(all(target_arch="x86_64", target_os="windows"))'] -rustfl = ["-Ctarget-feature=+crt-static"] +[lib] +crate-type = ["cdylib"] [dependencies] -sm-ext = { git = "https://github.com/asherkin/sm-ext-rs.git", rev = "8e8d87b"} +sm-ext = "0.3.0" \ No newline at end of file diff --git a/shrimpstats_tf2/src/lib.rs b/shrimpstats_tf2/src/lib.rs index 7e839ac..dcc5cd4 100644 --- a/shrimpstats_tf2/src/lib.rs +++ b/shrimpstats_tf2/src/lib.rs @@ -10,50 +10,30 @@ )] -use sm_ext::{forwards, native, ExecType, ICallableApi, IExtension, IExtensionInterface, IShareSys, SMExtension}; +use std::ffi::CStr; + +use sm_ext::{forwards, native, ExecType, ICallableApi, IExtension, IExtensionInterface, IForwardManager, IShareSys, SMExtension, SMInterfaceApi}; #[derive(Default, SMExtension)] #[extension(name = "shrimpstats_tf2", description = "ShrimpStats TF2 Extension")] pub struct ShrimpStatsTF2Extension; +#[forwards] +struct MyForwards { + /// ```sourcepawn + /// forward int OnRustCall(int a, int b, const char[] c); + /// ``` + #[global_forward("OnRustCall", ExecType::Hook)] + on_rust_call: fn(a: i32, b: i32, c: &CStr) -> i32, +} -// Name: player_death -// Structure: -// short userid user ID who died -// long victim_entindex -// long inflictor_entindex ent index of inflictor (a sentry, for example) -// short attacker user ID who killed -// string weapon weapon name killer used -// short weaponid ID of weapon killed used -// long damagebits bits of type of damage -// short customkill type of custom kill -// short assister user ID of assister -// string weapon_logclassname weapon name that should be printed on the log -// short stun_flags victim's stun flags at the moment of death -// short death_flags death flags. -// bool silent_kill -// short playerpenetratecount -// string assister_fallback contains a string to use if "assister" is -1 -// short kill_streak_total Kill streak count (level) -// short kill_streak_wep Kill streak for killing weapon -// short kill_streak_assist Kill streak for assister count -// short kill_streak_victim Victims kill streak -// short ducks_streaked Duck streak increment from this kill -// short duck_streak_total Duck streak count for attacker -// short duck_streak_assist Duck streak count for assister -// short duck_streak_victim (former) duck streak count for victim -// bool rocket_jump was the victim rocket jumping -// short weapon_def_index item def index of weapon killer used -// short crit_type Crit type of kill. (0: None, 1: Mini, 2: Full) - -// #[forwards] -// pub struct ShrimpStatsTF2ExtensionForward{ -// #[global_forward("player_death", ExecType::Hook)] -// pub player_death: fn(userid: i32, victim_entindex: i32, inflictor_entindex: i32, attacker: i32, weapon: , weaponid: i32, damagebits: i32, customkill: i32, assister: i32, weapon_logclassname: String, stun_flags: i32, death_flags: u8, silent_kill: bool, playerpenetratecount: u8, assister_fallback: String, kill_streak_total: u8, kill_streak_wep: u8, kill_streak_assist: u8, kill_streak_victim: u8, ducks_streaked: u8, duck_streak_total: u8, duck_streak_assist: u8, duck_streak_victim: u8, rocket_jump: bool, weapon_def_index: i32, crit_type: u8) -// } impl IExtensionInterface for ShrimpStatsTF2Extension { - fn on_extension_load(&mut self, _me: IExtension, _sys: IShareSys, _late: bool) -> Result<(), Box> { + fn on_extension_load(&mut self, me: IExtension, sys: IShareSys, late: bool) -> Result<(), Box> { + println!(">>> Rusty extension loaded! me = {:?}, sys = {:?}, late = {:?}", me, sys, late); + + let forward_manager: IForwardManager = sys.request_interface(&me)?; + println!(">>> Got interface: {:?} v{:?}", forward_manager.get_interface_name(), forward_manager.get_interface_version()); Ok(()) } From fde0350565ef7539bdf2bff597f9e67bd04d04ff Mon Sep 17 00:00:00 2001 From: QtKai <15091327+QtKaii@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:57:14 +0000 Subject: [PATCH 3/3] Remove unnecessary clippy::restriction from main.rs --- api/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/src/main.rs b/api/src/main.rs index daa855f..ada225d 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -6,8 +6,7 @@ clippy::complexity, clippy::perf, clippy::style, - clippy::suspicious, - clippy::restriction + clippy::suspicious )] use axum::{ @@ -27,7 +26,7 @@ async fn main() { let listener = match TcpListener::bind("0.0.0.0:3000").await { Ok(x) => x, Err(e) => { - println!("Error: {}", e); + println!("Error: {e}"); return; } @@ -38,7 +37,7 @@ async fn main() { match axum::serve(listener, app).await { Ok(x) => x, Err(e) => { - println!("Error: {}", e); + println!("Error: {e}"); return; } };