Skip to content

Commit

Permalink
Merge pull request Facepunch#702 from Peewi/master
Browse files Browse the repository at this point in the history
Initialize Steam Input so it actually works
  • Loading branch information
shana committed Nov 1, 2023
2 parents dc8a0c9 + ae29292 commit e480c75
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions Facepunch.Steamworks/SteamInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SteamInput : SteamClientClass<SteamInput>
internal override bool InitializeInterface( bool server )
{
SetInterface( server, new ISteamInput( server ) );
Internal.Init( false );
if ( Interface.Self == IntPtr.Zero ) return false;

return true;
Expand Down
57 changes: 56 additions & 1 deletion Facepunch.Steamworks/Structs/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,61 @@ public AnalogState GetAnalogState( string actionName )
return SteamInput.Internal.GetAnalogActionData( Handle, SteamInput.GetAnalogActionHandle( actionName ) );
}

/// <summary>
/// Trigger a vibration event on supported controllers.
/// </summary>
/// <remarks>
/// <para>This API call will be ignored for incompatible controller models.</para>
/// <para>This generates the traditional "rumble" vibration effect.</para>
/// </remarks>
/// <param name="leftSpeed">The intensity value for the left rumble motor.</param>
/// <param name="rightSpeed">The intensity value of the right rumble motor.</param>
public void TriggerVibration( ushort leftSpeed, ushort rightSpeed )
{
SteamInput.Internal.TriggerVibration( Handle, leftSpeed, rightSpeed );
}

/// <summary>
/// Trigger a vibration event on supported controllers, including impulse trigger for Xbox One controllers.
/// <para>This API call will be ignored for incompatible controller models.</para>
/// <para>This generates the traditional "rumble" vibration effect.</para>
/// </summary>
/// <param name="leftSpeed">The intensity value for the left rumble motor.</param>
/// <param name="rightSpeed">The intensity value of the right rumble motor.</param>
/// <param name="leftTriggerSpeed">The intensity value of the Xbox One left trigger rumble</param>
/// <param name="rightTriggerSpeed">The intensity value of the Xbox One right trigger rumble.</param>
public void TriggerVibrationExtended( ushort leftSpeed, ushort rightSpeed, ushort leftTriggerSpeed, ushort rightTriggerSpeed )
{
SteamInput.Internal.TriggerVibrationExtended( Handle, leftSpeed, rightSpeed, leftTriggerSpeed, rightTriggerSpeed );
}

/// <summary>
/// Set the controller LED color on supported controllers.
/// </summary>
/// <param name="red">The red component of the color to set (0-255).</param>
/// <param name="green">The green component of the color to set (0-255).</param>
/// <param name="blue">The blue component of the color to set (0-255).</param>
public void SetLEDColor( byte red, byte green, byte blue )
{
SteamInput.Internal.SetLEDColor( Handle, red, green, blue, (uint)SteamControllerLEDFlag.SetColor );
}

/// <summary>
/// Set the controller LED color on supported controllers.
/// </summary>
/// <param name="color">Color to set the LED</param>
public void SetLEDColor( Color color )
{
SteamInput.Internal.SetLEDColor( Handle, color.r, color.g, color.b, (uint)SteamControllerLEDFlag.SetColor );
}

/// <summary>
/// Restore the controller LED color to default (out-of-game) settings
/// </summary>
public void RestoreUserLEDColor()
{
SteamInput.Internal.SetLEDColor( Handle, 0, 0, 0, (uint)SteamControllerLEDFlag.RestoreUserDefault );
}

public override string ToString() => $"{InputType}.{Handle.Value}";

Expand Down Expand Up @@ -94,4 +149,4 @@ public struct DigitalState
public bool Pressed => BState != 0;
public bool Active => BActive != 0;
}
}
}

0 comments on commit e480c75

Please sign in to comment.