diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-05-28 09:11:31 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-05-28 09:11:31 +0800 |
| commit | c0244a9d6f657934313e03f67a4b9fa9d93d34b7 (patch) | |
| tree | 2da30c3984f5182e1bd3369de148abaa05afcbf8 | |
| parent | adc42fdf2050e77de50952bc8629684f1b3cf0ce (diff) | |
.
| -rw-r--r-- | .cargo/config.toml | 3 | ||||
| -rw-r--r-- | .cargo/scripts/release_files_win | 6 | ||||
| -rw-r--r-- | Cargo.lock | 158 | ||||
| -rw-r--r-- | Cargo.toml | 5 | ||||
| -rw-r--r-- | Release.toml | 9 | ||||
| -rw-r--r-- | console/Cargo.toml | 1 | ||||
| -rw-r--r-- | console/src/bin/nogpadc.rs | 6 | ||||
| -rw-r--r-- | console/src/bin/nogpads.rs | 6 | ||||
| -rw-r--r-- | console/src/lib.rs | 0 | ||||
| -rw-r--r-- | core/Cargo.toml | 7 | ||||
| -rw-r--r-- | core/src/lib.rs | 3 | ||||
| -rw-r--r-- | core/src/pad_data/game_profile.rs | 1 | ||||
| -rw-r--r-- | core/src/pad_data/pad_player_info.rs | 1 | ||||
| -rw-r--r-- | core/src/pad_service/client.rs | 2 | ||||
| -rw-r--r-- | core/src/pad_service/server.rs | 9 | ||||
| -rw-r--r-- | core_c/src/lib.rs | 41 | ||||
| -rw-r--r-- | release/0.1.0/bin/nogpadc.exe | bin | 0 -> 2237440 bytes | |||
| -rw-r--r-- | release/Cargo.toml | 8 | ||||
| -rw-r--r-- | release/src/bin/release_project.rs | 70 |
19 files changed, 314 insertions, 22 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml index fde969b..f605948 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ [build] target-dir = "./.cargo/shared/target" + +[env] +PROJECT_VERSION = { value = "0.1.0" }
\ No newline at end of file diff --git a/.cargo/scripts/release_files_win b/.cargo/scripts/release_files_win index bfc7841..b82e833 100644 --- a/.cargo/scripts/release_files_win +++ b/.cargo/scripts/release_files_win @@ -3,4 +3,8 @@ nogpadc.exe : .\bin\nogpadc.exe nogpads.exe : .\bin\nogpads.exe // Dll部分 -nogamepads_c.dll : .\bridge\libs\nogamepads_c.dll
\ No newline at end of file +nogamepads_c.dll : .\bridge\nogamepads.dll + +// Header部分 +nogamepads.h : .\bridge\nogamepads.h +nogamepads_cpp.h : .\bridge\nogamepads_cpp.h
\ No newline at end of file @@ -160,6 +160,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] +name = "cbindgen" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684" +dependencies = [ + "clap", + "heck", + "indexmap", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn", + "tempfile", + "toml 0.8.22", +] + +[[package]] name = "cc" version = "1.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -378,6 +397,12 @@ dependencies = [ ] [[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -621,7 +646,7 @@ dependencies = [ [[package]] name = "nogamepads-console" -version = "0.1.0" +version = "0.0.0" dependencies = [ "clap", "nogamepads-core", @@ -634,7 +659,7 @@ dependencies = [ [[package]] name = "nogamepads-core" -version = "0.1.0" +version = "0.0.0" dependencies = [ "bincode", "clap", @@ -649,8 +674,9 @@ dependencies = [ [[package]] name = "nogamepads_c" -version = "0.1.0" +version = "0.0.0" dependencies = [ + "cbindgen", "nogamepads-core", ] @@ -902,6 +928,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] +name = "release" +version = "0.0.0" +dependencies = [ + "serde", + "toml 0.7.8", +] + +[[package]] name = "rpassword" version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -980,6 +1014,27 @@ dependencies = [ ] [[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + +[[package]] name = "serde_yaml" version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1064,6 +1119,19 @@ dependencies = [ ] [[package]] +name = "tempfile" +version = "3.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +dependencies = [ + "fastrand", + "getrandom 0.3.3", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] name = "term" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1165,6 +1233,72 @@ dependencies = [ ] [[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", +] + +[[package]] +name = "toml" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.26", +] + +[[package]] +name = "toml_datetime" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow 0.7.10", +] + +[[package]] +name = "toml_write" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" + +[[package]] name = "typenum" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1470,6 +1604,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +dependencies = [ + "memchr", +] + +[[package]] name = "winsafe" version = "0.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -15,7 +15,8 @@ edition = "2024" members = [ "core", "console", - "core_c" + "core_c", + "release" ] [dependencies] @@ -32,4 +33,4 @@ debug = false [profile.dev] strip = false -debug = true +debug = true
\ No newline at end of file diff --git a/Release.toml b/Release.toml new file mode 100644 index 0000000..8718e70 --- /dev/null +++ b/Release.toml @@ -0,0 +1,9 @@ +[release.root] +#./ +license = { raw = "./", target = "./", files = ["LICENSE-LGPL-2", "LICENSE-THIRD-PARTY"] } + +[release.deps] +#./.cargo/shared/target/release/deps +header = { raw = "./", target = "./bridge", files = ["nogamepads_cpp.h", "nogamepads.h"] } +dll = { raw = "./", target = "./bridge", files = ["nogamepads_lib_c.dll"] } +binaries = { raw = "./", target = "./bin", files = ["nogpadc.exe", "nogpads.exe"] }
\ No newline at end of file diff --git a/console/Cargo.toml b/console/Cargo.toml index 03ec382..f48f21d 100644 --- a/console/Cargo.toml +++ b/console/Cargo.toml @@ -5,7 +5,6 @@ description = "This crate provides a set of tools for simulating and deploying t homepage = "https://github.com/CatilGrass/NoGamepads" repository = "https://github.com/CatilGrass/NoGamepads" -version = "0.1.0" edition = "2024" [dependencies] diff --git a/console/src/bin/nogpadc.rs b/console/src/bin/nogpadc.rs index 656c2a0..a8c4e8d 100644 --- a/console/src/bin/nogpadc.rs +++ b/console/src/bin/nogpadc.rs @@ -1,9 +1,6 @@ use crate::AccountCommands::{Add, Customize, List, Remove}; use crate::Commands::{Account, Connect}; use clap::{Args, Parser, Subcommand}; -use nogamepads_core::pad_service::client::nogamepads_client::PadClient; -use nogamepads_core::pad_data::pad_player_info::nogamepads_player_info::PlayerInfo; -use nogamepads_core::DEFAULT_PORT; use prettytable::{row, Table}; use rand::Rng; use std::env::current_dir; @@ -13,6 +10,9 @@ use std::net::{IpAddr, Ipv4Addr}; use std::path::PathBuf; use std::process::exit; use std::str::FromStr; +use nogamepads_lib_rs::DEFAULT_PORT; +use nogamepads_lib_rs::pad_data::pad_player_info::nogamepads_player_info::PlayerInfo; +use nogamepads_lib_rs::pad_service::client::nogamepads_client::PadClient; /// NoGamePads Console - Client Cli #[derive(Parser, Debug)] diff --git a/console/src/bin/nogpads.rs b/console/src/bin/nogpads.rs index f42495a..51390b0 100644 --- a/console/src/bin/nogpads.rs +++ b/console/src/bin/nogpads.rs @@ -1,13 +1,13 @@ use clap::{arg, Args, Parser, Subcommand}; -use nogamepads_core::pad_service::server::nogamepads_server::{PadServer}; -use nogamepads_core::DEFAULT_PORT; use serde::{Deserialize, Serialize}; use std::env::current_dir; use std::fs::{create_dir, File}; use std::io::{BufReader, Write}; use std::net::{IpAddr, Ipv4Addr}; use std::path::PathBuf; -use nogamepads_core::pad_data::game_profile::game_profile::GameProfile; +use nogamepads_lib_rs::DEFAULT_PORT; +use nogamepads_lib_rs::pad_data::game_profile::game_profile::GameProfile; +use nogamepads_lib_rs::pad_service::server::nogamepads_server::PadServer; /// NoGamePads Console - Server Cli #[derive(Parser, Debug)] diff --git a/console/src/lib.rs b/console/src/lib.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/console/src/lib.rs diff --git a/core/Cargo.toml b/core/Cargo.toml index fade27a..e41697e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -5,7 +5,6 @@ homepage = "https://github.com/CatilGrass/NoGamepads" repository = "https://github.com/CatilGrass/NoGamepads" readme = "../README.md" -version = "0.1.0" edition = "2024" [dependencies] @@ -17,4 +16,8 @@ tokio = { version = "1.45.0", features = ["full"] } serde = { version = "1.0.219", features = ["derive"] } clap = { version = "4.5.38", features = ["derive"] } sha1 = "0.10.6" -log = "0.4.27"
\ No newline at end of file +log = "0.4.27" + +[lib] +name = "nogamepads_lib_rs" +crate-type = [ "rlib"]
\ No newline at end of file diff --git a/core/src/lib.rs b/core/src/lib.rs index 1abb191..0c8cf83 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -6,5 +6,4 @@ pub mod pad_data; pub const DEFAULT_PORT : u16 = 5989; pub const BINCODE_CONVERT_FAILED : Vec<u8> = Vec::new(); -pub const BINCODE_CONFIG : Configuration = config::standard(); - +pub const BINCODE_CONFIG : Configuration = config::standard();
\ No newline at end of file diff --git a/core/src/pad_data/game_profile.rs b/core/src/pad_data/game_profile.rs index 8d6e279..cd2a175 100644 --- a/core/src/pad_data/game_profile.rs +++ b/core/src/pad_data/game_profile.rs @@ -3,6 +3,7 @@ pub mod game_profile { use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; + #[repr(C)] #[derive(Encode, Decode, Serialize, Deserialize, PartialEq, Debug)] pub struct GameProfile { diff --git a/core/src/pad_data/pad_player_info.rs b/core/src/pad_data/pad_player_info.rs index ab0f6fd..1c8b7e0 100644 --- a/core/src/pad_data/pad_player_info.rs +++ b/core/src/pad_data/pad_player_info.rs @@ -7,6 +7,7 @@ pub mod nogamepads_player_info { pub const ACCOUNT_HASH_SALT : &str = "Mr.Weicao"; + #[repr(C)] #[derive(Encode, Decode, Serialize, Deserialize, PartialEq, Debug)] diff --git a/core/src/pad_service/client.rs b/core/src/pad_service/client.rs index 3114330..be7784d 100644 --- a/core/src/pad_service/client.rs +++ b/core/src/pad_service/client.rs @@ -25,6 +25,7 @@ pub mod nogamepads_client { type WriteList = Arc<Mutex<VecDeque<ControlMessage>>>; type ReadList = Arc<Mutex<VecDeque<GameMessage>>>; + #[repr(C)] pub struct PadClient { // --- 主要参数 --- @@ -108,7 +109,6 @@ pub mod nogamepads_client { // 客户端消息管理 impl PadClient { - pub fn put_msg(&self, msg: ControlMessage) { let mut guard = self.write_list.lock().unwrap(); guard.push_back(msg); diff --git a/core/src/pad_service/server.rs b/core/src/pad_service/server.rs index 3c60864..66ab56d 100644 --- a/core/src/pad_service/server.rs +++ b/core/src/pad_service/server.rs @@ -30,6 +30,7 @@ pub mod nogamepads_server { type WriteList = Arc<Mutex<HashMap<String, VecDeque<GameMessage>>>>; type ReadList = Arc<Mutex<HashMap<String, VecDeque<ControlMessage>>>>; + #[repr(C)] pub struct PadServer { // --- 主要参数 --- @@ -237,7 +238,7 @@ pub mod nogamepads_server { guard.contains_key(&player.account.player_hash) } - pub fn set_player_online (&self, player: &PlayerInfo, online: bool) { + fn set_player_online (&self, player: &PlayerInfo, online: bool) { let online_current = self.is_player_online(player); if online_current && !online { let mut guard = self.online_players.lock().unwrap(); @@ -374,15 +375,15 @@ pub mod nogamepads_server { } } - fn lock_game(&self) { + pub fn lock_game(&self) { self.game_locked.store(true, SeqCst); } - fn unlock_game(&self) { + pub fn unlock_game(&self) { self.game_locked.store(false, SeqCst); } - fn is_game_locked(&self) -> bool { + pub fn is_game_locked(&self) -> bool { self.game_locked.load(SeqCst) } diff --git a/core_c/src/lib.rs b/core_c/src/lib.rs index e69de29..bdeb7ef 100644 --- a/core_c/src/lib.rs +++ b/core_c/src/lib.rs @@ -0,0 +1,41 @@ +use std::ffi::{c_char, CStr, CString}; + +pub mod data_c; +pub mod service_c; + +pub fn string_to_c_char_safe(s: String) -> (CString, *const c_char) { + let c_string = CString::new(s).expect(""); + let ptr = c_string.as_ptr(); + (c_string, ptr) +} + +pub fn c_char_to_string_safe(ptr: *const c_char) -> Option<String> { + if ptr.is_null() { + return None; + } + unsafe { + CStr::from_ptr(ptr) + .to_str() + .ok() + .map(|s| s.to_owned()) + } +} + +#[macro_export] +macro_rules! box_into_raw { + ($expr:expr) => { + $crate::box_into_raw!(@inner $expr) + }; + + ($expr:expr => $t:ty) => { + $crate::box_into_raw!(@inner ($expr) as $t) + }; + + (@inner $expr:expr) => { + ::std::boxed::Box::into_raw(::std::boxed::Box::new($expr)) + }; + + (@inner ($expr:expr) as $t:ty) => { + ::std::boxed::Box::into_raw(::std::boxed::Box::new($expr) as ::std::boxed::Box<$t>) + }; +}
\ No newline at end of file diff --git a/release/0.1.0/bin/nogpadc.exe b/release/0.1.0/bin/nogpadc.exe Binary files differnew file mode 100644 index 0000000..5cf21ea --- /dev/null +++ b/release/0.1.0/bin/nogpadc.exe diff --git a/release/Cargo.toml b/release/Cargo.toml new file mode 100644 index 0000000..e43d5fb --- /dev/null +++ b/release/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "release" +authors = [ "CatilGrass" ] +edition = "2024" + +[dependencies] +serde = { version = "1.0.219", features = ["derive"] } +toml = "0.7.8"
\ No newline at end of file diff --git a/release/src/bin/release_project.rs b/release/src/bin/release_project.rs new file mode 100644 index 0000000..c608ff8 --- /dev/null +++ b/release/src/bin/release_project.rs @@ -0,0 +1,70 @@ +use std::fs::{copy, create_dir_all, remove_dir_all}; +use std::path::PathBuf; + +use serde::Deserialize; +use std::collections::HashMap; +use std::fs; + +#[derive(Debug, Deserialize)] +pub struct Config { + pub release: Release, +} + +#[derive(Debug, Deserialize)] +pub struct Release { + pub root: HashMap<String, ReleaseItem>, + pub deps: HashMap<String, ReleaseItem>, +} + +#[derive(Debug, Deserialize)] +pub struct ReleaseItem { + pub raw: String, + pub target: String, + pub files: Vec<String>, +} + +pub fn main() { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_path_buf(); + + let toml_config = root.join("Release.toml"); + let config: Config = toml::from_str(fs::read_to_string(toml_config).unwrap().as_str()) + .expect("Failed to parse TOML"); + + let release_root = + root.join("release"); + + let release_dir_current_version = + release_root.join(env!("PROJECT_VERSION")); + + let target_dir = + root.join(".cargo").join("shared").join("target").join("release").join("deps"); + + // 清理目录 + let _ = remove_dir_all(&release_dir_current_version); + + for data in config.release.root { + println!("Releasing \"{}\" files", data.0); + let raw_path = root.join(data.1.raw); + let target_path = release_dir_current_version.join(data.1.target); + copy_files(&raw_path, &target_path, data.1.files); + } + + for data in config.release.deps { + println!("Releasing \"{}\" files", data.0); + let raw_path = target_dir.join(data.1.raw); + let target_path = release_dir_current_version.join(data.1.target); + copy_files(&raw_path, &target_path, data.1.files); + } +} + +fn copy_files (raw: &PathBuf, target: &PathBuf, file_names: Vec<String>) { + create_dir_all(target).unwrap(); + + for file in file_names.iter() { + let file_path_raw = raw.join(file); + let file_path_target = target.join(file); + if file_path_raw.exists() { + let _ = copy(&file_path_raw, &file_path_target); + } + } +}
\ No newline at end of file |
