From 866a0fcbf43336f5d6a3632a30fe4302031fe8ac Mon Sep 17 00:00:00 2001 From: raymondtri Date: Mon, 24 Feb 2025 12:00:12 -0500 Subject: [PATCH 1/4] I really don't like having to use a non-official base rust package for this --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- client.d.ts | 3 +++ src/api/networking.rs | 27 ++++++++++++++++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd7252f..b614758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -320,7 +320,7 @@ dependencies = [ [[package]] name = "steamworks" version = "0.11.0" -source = "git+https://github.com/Noxime/steamworks-rs/?rev=fbb79635b06b4feea8261e5ca3e8ea3ef42facf9#fbb79635b06b4feea8261e5ca3e8ea3ef42facf9" +source = "git+https://github.com/yobson1/steamworks-rs/?rev=4128ec7695abb5333190712c0a9afce7a150e74d#4128ec7695abb5333190712c0a9afce7a150e74d" dependencies = [ "bitflags 1.3.2", "lazy_static", @@ -333,7 +333,7 @@ dependencies = [ [[package]] name = "steamworks-sys" version = "0.11.0" -source = "git+https://github.com/Noxime/steamworks-rs/?rev=fbb79635b06b4feea8261e5ca3e8ea3ef42facf9#fbb79635b06b4feea8261e5ca3e8ea3ef42facf9" +source = "git+https://github.com/yobson1/steamworks-rs/?rev=4128ec7695abb5333190712c0a9afce7a150e74d#4128ec7695abb5333190712c0a9afce7a150e74d" [[package]] name = "steamworksjs" diff --git a/Cargo.toml b/Cargo.toml index c6d4428..f182b37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ napi = { version = "2.16.8", features = ["tokio_rt", "napi6", "serde-json"] } napi-derive = "2.16.9" lazy_static = "1" tokio = { version = "1", features = ["sync", "time"] } -steamworks = { git = "https://github.com/Noxime/steamworks-rs/", rev = "fbb79635b06b4feea8261e5ca3e8ea3ef42facf9", features = ["serde"] } +steamworks = { git = "https://github.com/yobson1/steamworks-rs/", rev = "4128ec7695abb5333190712c0a9afce7a150e74d", features = ["serde"] } serde = "1" serde_json = "1" diff --git a/client.d.ts b/client.d.ts index c2fbb50..cbfdf8b 100644 --- a/client.d.ts +++ b/client.d.ts @@ -184,8 +184,11 @@ export declare namespace networking { ReliableWithBuffering = 3 } export function sendP2PPacket(steamId64: bigint, sendType: SendType, data: Buffer): boolean + export function sendP2PPacketOnChannel(steamId64: bigint, sendType: SendType, data: Buffer, channel: number): boolean export function isP2PPacketAvailable(): number + export function isP2PPacketAvailableOnChannel(channel: number): number export function readP2PPacket(size: number): P2PPacket + export function readP2PPacketFromChannel(size: number, channel: number): P2PPacket export function acceptP2PSession(steamId64: bigint): void } export declare namespace overlay { diff --git a/src/api/networking.rs b/src/api/networking.rs index 321162f..6b95571 100644 --- a/src/api/networking.rs +++ b/src/api/networking.rs @@ -41,9 +41,19 @@ pub mod networking { steam_id64: BigInt, send_type: SendType, data: Buffer, + ) -> Result { + self::send_p2p_packet_on_channel(steam_id64, send_type, data, 0) + } + + #[napi] + pub fn send_p2p_packet_on_channel( + steam_id64: BigInt, + send_type: SendType, + data: Buffer, + channel: i32, ) -> Result { let client = crate::client::get_client(); - let result = client.networking().send_p2p_packet( + let result = client.networking().send_p2p_packet_on_channel( SteamId::from_raw(steam_id64.get_u64().1), match send_type { SendType::Unreliable => steamworks::SendType::Unreliable, @@ -52,27 +62,38 @@ pub mod networking { SendType::ReliableWithBuffering => steamworks::SendType::ReliableWithBuffering, }, &data, + channel ); Ok(result) } #[napi] pub fn is_p2p_packet_available() -> i32 { + self::is_p2p_packet_available_on_channel(0) + } + + #[napi] + pub fn is_p2p_packet_available_on_channel(channel: i32) -> i32 { let client = crate::client::get_client(); client .networking() - .is_p2p_packet_available() + .is_p2p_packet_available_on_channel(channel) .unwrap_or_default() as i32 } #[napi] pub fn read_p2p_packet(size: i32) -> Result { + self::read_p2p_packet_from_channel(size, 0) + } + + #[napi] + pub fn read_p2p_packet_from_channel(size: i32, channel: i32) -> Result { let client = crate::client::get_client(); let mut buffer = vec![0; size as usize]; client .networking() - .read_p2p_packet(&mut buffer) + .read_p2p_packet_from_channel(&mut buffer, channel) .map(|(steam_id, read_size)| P2PPacket { data: buffer.into(), size: read_size as i32, From e41776665022963579e3ef31b1ba55a035ddb86c Mon Sep 17 00:00:00 2001 From: raymondtri Date: Mon, 24 Feb 2025 14:00:49 -0500 Subject: [PATCH 2/4] better support for auto-bundlers by not using require with a relative path --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index bc9e54d..a3f6917 100644 --- a/index.js +++ b/index.js @@ -5,14 +5,14 @@ const { platform, arch } = process let nativeBinding = undefined if (platform === 'win32' && arch === 'x64') { - nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node') + nativeBinding = require('steamworks.js/dist/win64/steamworksjs.win32-x64-msvc.node') } else if (platform === 'linux' && arch === 'x64') { - nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node') + nativeBinding = require('steamworks.js/dist/linux64/steamworksjs.linux-x64-gnu.node') } else if (platform === 'darwin') { if (arch === 'x64') { - nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node') + nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-x64.node') } else if (arch === 'arm64') { - nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node') + nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-arm64.node') } } else { throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) From c8d52b73815fc9805c8ca99abcf2ae959fb4a2ed Mon Sep 17 00:00:00 2001 From: raymondtri Date: Wed, 26 Feb 2025 08:50:08 -0500 Subject: [PATCH 3/4] reverted changes to the index.js regarding require since that can be handled in another pr --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a3f6917..bc9e54d 100644 --- a/index.js +++ b/index.js @@ -5,14 +5,14 @@ const { platform, arch } = process let nativeBinding = undefined if (platform === 'win32' && arch === 'x64') { - nativeBinding = require('steamworks.js/dist/win64/steamworksjs.win32-x64-msvc.node') + nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node') } else if (platform === 'linux' && arch === 'x64') { - nativeBinding = require('steamworks.js/dist/linux64/steamworksjs.linux-x64-gnu.node') + nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node') } else if (platform === 'darwin') { if (arch === 'x64') { - nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-x64.node') + nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node') } else if (arch === 'arm64') { - nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-arm64.node') + nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node') } } else { throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) From 3457614345522038c448a7962b46b0bfabb9d774 Mon Sep 17 00:00:00 2001 From: raymondtri Date: Wed, 26 Feb 2025 08:53:16 -0500 Subject: [PATCH 4/4] updated cargo back to non-fork repo --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b614758..f2f2358 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,7 +320,7 @@ dependencies = [ [[package]] name = "steamworks" version = "0.11.0" -source = "git+https://github.com/yobson1/steamworks-rs/?rev=4128ec7695abb5333190712c0a9afce7a150e74d#4128ec7695abb5333190712c0a9afce7a150e74d" +source = "git+https://github.com/Noxime/steamworks-rs/?rev=5fc8ef13d52e82068f031535446d786cf0bd60a8#5fc8ef13d52e82068f031535446d786cf0bd60a8" dependencies = [ "bitflags 1.3.2", "lazy_static", @@ -333,7 +333,7 @@ dependencies = [ [[package]] name = "steamworks-sys" version = "0.11.0" -source = "git+https://github.com/yobson1/steamworks-rs/?rev=4128ec7695abb5333190712c0a9afce7a150e74d#4128ec7695abb5333190712c0a9afce7a150e74d" +source = "git+https://github.com/Noxime/steamworks-rs/?rev=5fc8ef13d52e82068f031535446d786cf0bd60a8#5fc8ef13d52e82068f031535446d786cf0bd60a8" [[package]] name = "steamworksjs" diff --git a/Cargo.toml b/Cargo.toml index f182b37..0857e58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ napi = { version = "2.16.8", features = ["tokio_rt", "napi6", "serde-json"] } napi-derive = "2.16.9" lazy_static = "1" tokio = { version = "1", features = ["sync", "time"] } -steamworks = { git = "https://github.com/yobson1/steamworks-rs/", rev = "4128ec7695abb5333190712c0a9afce7a150e74d", features = ["serde"] } +steamworks = { git = "https://github.com/Noxime/steamworks-rs/", rev = "5fc8ef13d52e82068f031535446d786cf0bd60a8", features = ["serde"] } serde = "1" serde_json = "1"