Skip to content

Commit

Permalink
Update dependencies and add new forward manager interface
Browse files Browse the repository at this point in the history
  • Loading branch information
QtKaii committed Jan 23, 2024
1 parent 5b71d46 commit 14a33cc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 51 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,45 @@
clippy::complexity,
clippy::perf,
clippy::style,
clippy::suspicious
clippy::suspicious,
clippy::restriction
)]

use axum::{
routing::get,
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!"
}
10 changes: 3 additions & 7 deletions shrimpstats_tf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
52 changes: 16 additions & 36 deletions shrimpstats_tf2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
fn on_extension_load(&mut self, me: IExtension, sys: IShareSys, late: bool) -> Result<(), Box<dyn std::error::Error>> {
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(())
}
Expand Down

0 comments on commit 14a33cc

Please sign in to comment.