Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/Noxime/steamworks-rs/", rev = "40a457a61f5ef714d93804e51e0c5e3d405145a3", features = ["serde"] }
serde = "1"
serde_json = "1"

Expand Down
2 changes: 1 addition & 1 deletion client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export declare namespace workshop {
* Get all subscribed workshop items.
* @returns an array of subscribed workshop item ids
*/
export function getSubscribedItems(): Array<bigint>
export function getSubscribedItems(includeLocallyDisabled: boolean): Array<bigint>
export const enum UGCQueryType {
RankedByVote = 0,
RankedByPublicationDate = 1,
Expand Down
Binary file modified sdk/redistributable_bin/linux32/libsteam_api.so
Binary file not shown.
Binary file modified sdk/redistributable_bin/linux64/libsteam_api.so
Binary file not shown.
Binary file modified sdk/redistributable_bin/osx/libsteam_api.dylib
Binary file not shown.
Binary file modified sdk/redistributable_bin/steam_api.dll
Binary file not shown.
Binary file modified sdk/redistributable_bin/steam_api.lib
Binary file not shown.
Binary file modified sdk/redistributable_bin/win64/steam_api64.dll
Binary file not shown.
Binary file modified sdk/redistributable_bin/win64/steam_api64.lib
Binary file not shown.
31 changes: 24 additions & 7 deletions src/api/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ use napi_derive::napi;

#[napi]
pub mod callback {
use std::{
collections::HashMap,
sync::{
atomic::{AtomicU32, Ordering},
Mutex, OnceLock,
},
};

use napi::{
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
JsFunction,
};

static HANDLE_ID_COUNTER: AtomicU32 = AtomicU32::new(1);
static CALLBACK_REGISTRY: OnceLock<Mutex<HashMap<u32, steamworks::CallbackHandle>>> =
OnceLock::new();

fn get_registry() -> &'static Mutex<HashMap<u32, steamworks::CallbackHandle>> {
CALLBACK_REGISTRY.get_or_init(|| Mutex::new(HashMap::new()))
}

#[napi]
pub struct Handle {
handle: Option<steamworks::CallbackHandle>,
id: u32,
}

#[napi]
impl Handle {
#[napi]
pub fn disconnect(&mut self) {
if let Some(handle) = self.handle.take() {
handle.disconnect();
}
get_registry().lock().unwrap().remove(&self.id);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these changes are basically here to re-fix #77.
Noxime/steamworks-rs#128 was reverted in Noxime/steamworks-rs#241, and it seems like the fix on steamworks-rs's side is not coming back. So instead I tried to fix this on the rust side of things in steamworks.js. Basically a reference to each handle is kept in the CALLBACK_REGISTRY, which is removed from the registry when the user calls disconnect()

I'll have to admit I used a fair bit of AI to get this part to work as I'm not too familiar with rust. So feel free to make changes if this is absolute garbage.

}
}

Expand Down Expand Up @@ -79,9 +93,12 @@ pub mod callback {
}
};

Handle {
handle: Some(handle),
}
let id = HANDLE_ID_COUNTER.fetch_add(1, Ordering::Relaxed);
let registry = get_registry();
let mut map = registry.lock().unwrap();
map.insert(id, handle);

Handle { id }
}

fn register_callback<C>(
Expand Down
10 changes: 5 additions & 5 deletions src/api/workshop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod workshop {
use napi::threadsafe_function::ThreadsafeFunction;
use napi::threadsafe_function::ThreadsafeFunctionCallMode;
use std::path::Path;
use steamworks::{ClientManager, FileType, PublishedFileId, UpdateHandle};
use steamworks::{FileType, PublishedFileId, UpdateHandle};
use tokio::sync::oneshot;

#[napi(object)]
Expand Down Expand Up @@ -61,11 +61,11 @@ pub mod workshop {
impl UgcUpdate {
pub fn submit(
self,
mut update: UpdateHandle<ClientManager>,
mut update: UpdateHandle,
callback: impl FnOnce(Result<(PublishedFileId, bool), steamworks::SteamError>)
+ Send
+ 'static,
) -> steamworks::UpdateWatchHandle<ClientManager> {
) -> steamworks::UpdateWatchHandle {
if let Some(title) = self.title {
update = update.title(title.as_str());
}
Expand Down Expand Up @@ -394,9 +394,9 @@ pub mod workshop {
/// Get all subscribed workshop items.
/// @returns an array of subscribed workshop item ids
#[napi]
pub fn get_subscribed_items() -> Vec<BigInt> {
pub fn get_subscribed_items(include_locally_disabled: bool) -> Vec<BigInt> {
let client = crate::client::get_client();
let result = client.ugc().subscribed_items();
let result = client.ugc().subscribed_items(include_locally_disabled);

result
.iter()
Expand Down
6 changes: 3 additions & 3 deletions src/api/workshop_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ pub mod workshop {
pub consumer: Option<u32>,
}

fn handle_query_config<Manager>(
mut query_handle: steamworks::QueryHandle<Manager>,
fn handle_query_config(
mut query_handle: steamworks::QueryHandle,
query_config: Option<WorkshopItemQueryConfig>,
) -> steamworks::QueryHandle<Manager> {
) -> steamworks::QueryHandle {
// Apply statistics query parameters if provided
if let Some(query_config) = query_config {
if let Some(cached_response_max_age) = query_config.cached_response_max_age {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pub fn init(app_id: Option<u32>) -> Result<(), Error> {
| SteamAPIInitError::VersionMismatch(msg) => Error::from_reason(msg),
})?;

steam_client.user_stats().request_current_stats();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was deprecated in version 1.61 of the steamworks sdk:

ISteamUserStats:

  • RequestCurrentStats is no longer necessary and has been removed. The Steam Client will synchronize this data before your game launches.


client::set_client(steam_client);
Ok(())
}
Expand Down
Loading