Skip to content

Commit

Permalink
set_game_tags conflicts resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ymo-4 committed Jul 23, 2024
2 parents 62ceafb + 23283f8 commit 821d4a9
Show file tree
Hide file tree
Showing 41 changed files with 772 additions and 1,883 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ steamworks = "0.11.0"

| Crate | SDK | MSRV |
|--------|-------|--------|
| git | 1.58a | 1.71.1 |
| git | 1.59 | 1.71.1 |
| 0.11.0 | 1.58a | 1.71.1 |
| 0.10.0 | 1.54 | 1.56.1 |
| 0.9.0 | 1.53a | 1.56.1 |
Expand Down
4 changes: 4 additions & 0 deletions src/friends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ impl<Manager> Friend<Manager> {
pub fn nick_name(&self) -> Option<String> {
unsafe {
let name = sys::SteamAPI_ISteamFriends_GetPlayerNickname(self.friends, self.id.0);
if name.is_null() {
return None;
}

let name = CStr::from_ptr(name);
if name.is_empty() {
None
Expand Down
23 changes: 19 additions & 4 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ impl<Manager> Input<Manager> {
/// Init must be called when starting use of this interface.
/// if explicitly_call_run_frame is called then you will need to manually call RunFrame
/// each frame, otherwise Steam Input will updated when SteamAPI_RunCallbacks() is called
pub fn init(&self, explicitly_call_run_frame: bool) {
unsafe {
sys::SteamAPI_ISteamInput_Init(self.input, explicitly_call_run_frame);
}
pub fn init(&self, explicitly_call_run_frame: bool) -> bool {
unsafe { sys::SteamAPI_ISteamInput_Init(self.input, explicitly_call_run_frame) }
}

/// Synchronize API state with the latest Steam Input action data available. This
Expand Down Expand Up @@ -73,6 +71,14 @@ impl<Manager> Input<Manager> {
}
}

/// Allows to load a specific Action Manifest File localy
pub fn set_input_action_manifest_file_path(&self, path: &str) -> bool {
let path = CString::new(path).unwrap();
unsafe {
sys::SteamAPI_ISteamInput_SetInputActionManifestFilePath(self.input, path.as_ptr())
}
}

/// Returns the associated ControllerActionSet handle for the specified controller,
pub fn get_action_set_handle(&self, action_set_name: &str) -> sys::InputActionSetHandle_t {
let name = CString::new(action_set_name).unwrap();
Expand Down Expand Up @@ -187,6 +193,15 @@ impl<Manager> Input<Manager> {
unsafe { sys::SteamAPI_ISteamInput_GetMotionData(self.input, input_handle) }
}

/// Invokes the Steam overlay and brings up the binding screen.
/// Returns true for success, false if overlay is disabled/unavailable.
/// If the player is using Big Picture Mode the configuration will open in
/// the overlay. In desktop mode a popup window version of Big Picture will
/// be created and open the configuration.
pub fn show_binding_panel(&self, input_handle: sys::InputHandle_t) -> bool {
unsafe { sys::SteamAPI_ISteamInput_ShowBindingPanel(self.input, input_handle) }
}

/// Shutdown must be called when ending use of this interface.
pub fn shutdown(&self) {
unsafe {
Expand Down
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate bitflags;
#[macro_use]
extern crate lazy_static;

use screenshots::Screenshots;
#[cfg(feature = "raw-bindings")]
pub use steamworks_sys as sys;
#[cfg(not(feature = "raw-bindings"))]
Expand Down Expand Up @@ -51,6 +52,7 @@ pub mod networking_types;
pub mod networking_utils;
mod remote_play;
mod remote_storage;
pub mod screenshots;
mod server;
mod ugc;
mod user;
Expand Down Expand Up @@ -141,7 +143,6 @@ impl Client<ClientManager> {
let versions: Vec<&[u8]> = vec![
sys::STEAMUTILS_INTERFACE_VERSION,
sys::STEAMNETWORKINGUTILS_INTERFACE_VERSION,
sys::STEAMAPPLIST_INTERFACE_VERSION,
sys::STEAMAPPS_INTERFACE_VERSION,
sys::STEAMCONTROLLER_INTERFACE_VERSION,
sys::STEAMFRIENDS_INTERFACE_VERSION,
Expand Down Expand Up @@ -436,6 +437,18 @@ impl<Manager> Client<Manager> {
}
}

/// Returns an accessor to the steam screenshots interface
pub fn screenshots(&self) -> Screenshots<Manager> {
unsafe {
let screenshots = sys::SteamAPI_SteamScreenshots_v003();
debug_assert!(!screenshots.is_null());
Screenshots {
screenshots,
_inner: self.inner.clone(),
}
}
}

/// Returns an accessor to the steam UGC interface (steam workshop)
pub fn ugc(&self) -> UGC<Manager> {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/networking_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl From<NetworkingConfigValue> for sys::ESteamNetworkingConfigValue {
NetworkingConfigValue::SDRClientMinPingsBeforePingAccurate => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_MinPingsBeforePingAccurate,
NetworkingConfigValue::SDRClientSingleSocket => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_SingleSocket,
NetworkingConfigValue::SDRClientForceRelayCluster => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_ForceRelayCluster,
NetworkingConfigValue::SDRClientDebugTicketAddress => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_DebugTicketAddress,
NetworkingConfigValue::SDRClientDebugTicketAddress => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_DevTicket,
NetworkingConfigValue::SDRClientForceProxyAddr => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_ForceProxyAddr,
NetworkingConfigValue::SDRClientFakeClusterPing => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_SDRClient_FakeClusterPing,
NetworkingConfigValue::LogLevelAckRTT => sys::ESteamNetworkingConfigValue::k_ESteamNetworkingConfig_LogLevel_AckRTT,
Expand Down
154 changes: 154 additions & 0 deletions src/screenshots.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
use std::path::Path;

pub use sys::ScreenshotHandle;

use super::*;

/// Access to the steam screenshots interface
pub struct Screenshots<Manager> {
pub(crate) screenshots: *mut sys::ISteamScreenshots,
pub(crate) _inner: Arc<Inner<Manager>>,
}

impl<Manager> Screenshots<Manager> {
/// Toggles whether the overlay handles screenshots when the user presses the screenshot hotkey, or if the game handles them.
///
/// Hooking is disabled by default, and only ever enabled if you do so with this function.
///
/// If the hooking is enabled, then the [`ScreenshotRequested`] callback will be sent if the user presses the hotkey or when [`Self::trigger_screenshot`] is called,
/// and then the game is expected to call `WriteScreenshot` or [`Self::add_screenshot_to_library`] in response.
///
/// You can check if hooking is enabled with [`Self::is_screenshots_hooked`].
pub fn hook_screenshots(&self, hook: bool) {
unsafe {
sys::SteamAPI_ISteamScreenshots_HookScreenshots(self.screenshots, hook);
}
}

/// Checks if the app is hooking screenshots, or if the Steam Overlay is handling them.
///
/// This can be toggled with [`Self::hook_screenshots`].
///
/// Returns
/// - `true` if the game is hooking screenshots and is expected to handle them; otherwise, `false`.
pub fn is_screenshots_hooked(&self) -> bool {
unsafe { sys::SteamAPI_ISteamScreenshots_IsScreenshotsHooked(self.screenshots) }
}

/// Either causes the Steam Overlay to take a screenshot, or tells your screenshot manager that a screenshot needs to be taken.
/// Depending on the value of [`Self::is_screenshots_hooked`].
///
/// - Triggers a [`ScreenshotRequested`] callback.
/// - Triggers a [`ScreenshotReady`] callback.
/// - Only causes [`ScreenshotRequested`] if hooking has been enabled with [`Self::hook_screenshots`].
/// - Otherwise [`ScreenshotReady`] will be called when the screenshot has been saved and added to the library.
pub fn trigger_screenshot(&self) {
unsafe {
sys::SteamAPI_ISteamScreenshots_TriggerScreenshot(self.screenshots);
}
}

/// Adds a screenshot to the user's Steam screenshot library from disk.
///
/// Triggers a [`ScreenshotReady`] callback.
/// The handle to this screenshot that is valid for the duration of the game process and can be used to apply tags.
///
/// This call is asynchronous, a [`ScreenshotReady`] callback will be sent when the screenshot has finished writing to disk.
pub fn add_screenshot_to_library(
&self,
filename: &Path,
thumbnail_filename: Option<&Path>,
width: i32,
height: i32,
) -> Result<ScreenshotHandle, ScreenshotLibraryAddError> {
let filename =
path_to_absolute_cstring(filename).ok_or(ScreenshotLibraryAddError::InvalidPath)?;

let thumbnail_filename = if let Some(thumbnail_filename) = thumbnail_filename {
Some(
path_to_absolute_cstring(thumbnail_filename)
.ok_or(ScreenshotLibraryAddError::InvalidPath)?,
)
} else {
None
};

unsafe {
let handle = sys::SteamAPI_ISteamScreenshots_AddScreenshotToLibrary(
self.screenshots,
filename.as_ptr(),
thumbnail_filename.map_or(std::ptr::null(), |s| s.as_ptr()),
width,
height,
);

if handle != sys::INVALID_SCREENSHOT_HANDLE {
Ok(handle)
} else {
Err(ScreenshotLibraryAddError::SavingFailed)
}
}
}
}

#[derive(Debug, Error)]
pub enum ScreenshotLibraryAddError {
/// Steam failed to save the file for an unspecified reason.
#[error("The screenshot file could not be saved")]
SavingFailed,
/// One of the paths provided was invalid.
#[error("Invalid path")]
InvalidPath,
}

/// A screenshot has been requested by the user from the Steam screenshot hotkey.
/// This will only be called if [`Screenshots::hook_screenshots`] has been enabled, in which case Steam will not take the screenshot itself.
#[derive(Clone, Debug)]
pub struct ScreenshotRequested;

unsafe impl Callback for ScreenshotRequested {
const ID: i32 = sys::ScreenshotRequested_t__bindgen_ty_1::k_iCallback as _;
const SIZE: i32 = std::mem::size_of::<sys::ScreenshotRequested_t>() as _;

unsafe fn from_raw(_: *mut c_void) -> Self {
Self
}
}

#[derive(Clone, Debug, Error)]
pub enum ScreenshotReadyError {
/// The screenshot could not be loaded or parsed.
#[error("The screenshot could not be loaded or parsed")]
Fail,
/// The screenshot could not be saved to the disk.
#[error("The screenshot could not be saved to the disk")]
IoFailure,
}

/// A screenshot successfully written or otherwise added to the library and can now be tagged.
#[derive(Clone, Debug)]
pub struct ScreenshotReady {
/// The screenshot handle that has been written.
pub local_handle: Result<ScreenshotHandle, ScreenshotReadyError>,
}

unsafe impl Callback for ScreenshotReady {
const ID: i32 = sys::ScreenshotReady_t__bindgen_ty_1::k_iCallback as _;
const SIZE: i32 = std::mem::size_of::<sys::ScreenshotReady_t>() as _;

unsafe fn from_raw(raw: *mut c_void) -> Self {
let status = *(raw as *mut sys::ScreenshotReady_t);
let local_handle = match status.m_eResult {
sys::EResult::k_EResultOK => Ok(status.m_hLocal),
sys::EResult::k_EResultIOFailure => Err(ScreenshotReadyError::Fail),
_ => Err(ScreenshotReadyError::Fail),
};

Self { local_handle }
}
}

fn path_to_absolute_cstring(filename: &Path) -> Option<CString> {
let filename = filename.canonicalize().ok()?;
Some(CString::new(filename.to_str()?).unwrap())
}
27 changes: 26 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ impl Server {
}
}

/// Login to a generic account by token
pub fn log_on(&self, token: &str) {
let token = CString::new(token).unwrap();
unsafe {
sys::SteamAPI_ISteamGameServer_LogOn(self.server, token.as_ptr());
}
}

/// If active, updates the master server with this server's presence so players can find it via
/// the steam matchmaking/server browser interfaces.
pub fn enable_heartbeats(&self, active: bool) {
Expand Down Expand Up @@ -340,7 +348,7 @@ impl Server {
pub fn set_server_name(&self, server_name: &str) {
let server_name = CString::new(server_name).unwrap();
unsafe {
sys::SteamAPI_ISteamGameServer_SetMapName(self.server, server_name.as_ptr());
sys::SteamAPI_ISteamGameServer_SetServerName(self.server, server_name.as_ptr());
}
}

Expand Down Expand Up @@ -373,6 +381,23 @@ impl Server {
}
}

/// Add/update a rules key/value pair.
pub fn set_key_value(&self, key: &str, value: &str) {
let key = CString::new(key).unwrap();
let value = CString::new(value).unwrap();

unsafe {
sys::SteamAPI_ISteamGameServer_SetKeyValue(self.server, key.as_ptr(), value.as_ptr());
}
}

/// Clears the whole list of key/values that are sent in rules queries.
pub fn clear_all_key_values(&self) {
unsafe {
sys::SteamAPI_ISteamGameServer_ClearAllKeyValues(self.server);
}
}

/// Returns an accessor to the steam UGC interface (steam workshop)
///
/// **For this to work properly, you need to call `UGC::init_for_game_server()`!**
Expand Down
5 changes: 5 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl<Manager> Utils<Manager> {
}
}

/// Returns whether or not the overlay is enabled in Steam
pub fn is_overlay_enabled(&self) -> bool {
unsafe { sys::SteamAPI_ISteamUtils_IsOverlayEnabled(self.utils) }
}

/// Returns the language the steam client is currently
/// running in.
///
Expand Down
8 changes: 1 addition & 7 deletions steamworks-sys/lib/steam/public/steam/isteamclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,12 @@ class ISteamClient
// Expose HTTP interface
virtual ISteamHTTP *GetISteamHTTP( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;

// Deprecated - the ISteamUnifiedMessages interface is no longer intended for public consumption.
STEAM_PRIVATE_API( virtual void *DEPRECATED_GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0 ; )

// Exposes the ISteamController interface - deprecated in favor of Steam Input
virtual ISteamController *GetISteamController( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;

// Exposes the ISteamUGC interface
virtual ISteamUGC *GetISteamUGC( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;

// returns app list interface, only available on specially registered apps
virtual ISteamAppList *GetISteamAppList( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;

// Music Player
virtual ISteamMusic *GetISteamMusic( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;

Expand Down Expand Up @@ -162,7 +156,7 @@ class ISteamClient
STEAM_PRIVATE_API( virtual void DestroyAllInterfaces() = 0; )

};
#define STEAMCLIENT_INTERFACE_VERSION "SteamClient020"
#define STEAMCLIENT_INTERFACE_VERSION "SteamClient021"

#ifndef STEAM_API_EXPORTS

Expand Down
1 change: 0 additions & 1 deletion steamworks-sys/lib/steam/public/steam/isteamcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ typedef uint64 ControllerAnalogActionHandle_t;
#define ControllerAnalogActionData_t InputAnalogActionData_t
#define ControllerDigitalActionData_t InputDigitalActionData_t
#define ControllerMotionData_t InputMotionData_t
#define ControllerMotionDataV2_t InputMotionDataV2_t
#else
struct ControllerAnalogActionData_t
{
Expand Down
4 changes: 4 additions & 0 deletions steamworks-sys/lib/steam/public/steam/isteamfriends.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ struct FriendGameInfo_t
};
#pragma pack( pop )

// special values for FriendGameInfo_t::m_usQueryPort
const uint16 k_usFriendGameInfoQueryPort_NotInitialized = 0xFFFF; // We haven't asked the GS for this query port's actual value yet. Was #define QUERY_PORT_NOT_INITIALIZED in older versions of Steamworks SDK.
const uint16 k_usFriendGameInfoQueryPort_Error = 0xFFFE; // We were unable to get the query port for this server. Was #define QUERY_PORT_ERROR in older versions of Steamworks SDK.

// maximum number of characters in a user's name. Two flavors; one for UTF-8 and one for UTF-16.
// The UTF-8 version has to be very generous to accomodate characters that get large when encoded
// in UTF-8.
Expand Down
Loading

0 comments on commit 821d4a9

Please sign in to comment.