CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

isteamcontroller.cs (19046B)


      1 // This file is provided under The MIT License as part of Steamworks.NET.
      2 // Copyright (c) 2013-2019 Riley Labrecque
      3 // Please see the included LICENSE.txt for additional information.
      4 
      5 // This file is automatically generated.
      6 // Changes to this file will be reverted when you update Steamworks.NET
      7 
      8 #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
      9 	#define DISABLESTEAMWORKS
     10 #endif
     11 
     12 #if !DISABLESTEAMWORKS
     13 
     14 using System.Runtime.InteropServices;
     15 using IntPtr = System.IntPtr;
     16 
     17 namespace Steamworks {
     18 	public static class SteamController {
     19 		/// <summary>
     20 		/// <para> Init and Shutdown must be called when starting/ending use of this interface</para>
     21 		/// </summary>
     22 		public static bool Init() {
     23 			InteropHelp.TestIfAvailableClient();
     24 			return NativeMethods.ISteamController_Init(CSteamAPIContext.GetSteamController());
     25 		}
     26 
     27 		public static bool Shutdown() {
     28 			InteropHelp.TestIfAvailableClient();
     29 			return NativeMethods.ISteamController_Shutdown(CSteamAPIContext.GetSteamController());
     30 		}
     31 
     32 		/// <summary>
     33 		/// <para> Synchronize API state with the latest Steam Controller inputs available. This</para>
     34 		/// <para> is performed automatically by SteamAPI_RunCallbacks, but for the absolute lowest</para>
     35 		/// <para> possible latency, you call this directly before reading controller state. This must</para>
     36 		/// <para> be called from somewhere before GetConnectedControllers will return any handles</para>
     37 		/// </summary>
     38 		public static void RunFrame() {
     39 			InteropHelp.TestIfAvailableClient();
     40 			NativeMethods.ISteamController_RunFrame(CSteamAPIContext.GetSteamController());
     41 		}
     42 
     43 		/// <summary>
     44 		/// <para> Enumerate currently connected controllers</para>
     45 		/// <para> handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles</para>
     46 		/// <para> Returns the number of handles written to handlesOut</para>
     47 		/// </summary>
     48 		public static int GetConnectedControllers(ControllerHandle_t[] handlesOut) {
     49 			InteropHelp.TestIfAvailableClient();
     50 			if (handlesOut != null && handlesOut.Length != Constants.STEAM_CONTROLLER_MAX_COUNT) {
     51 				throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_CONTROLLER_MAX_COUNT!");
     52 			}
     53 			return NativeMethods.ISteamController_GetConnectedControllers(CSteamAPIContext.GetSteamController(), handlesOut);
     54 		}
     55 
     56 		/// <summary>
     57 		/// <para>-----------------------------------------------------------------------------</para>
     58 		/// <para> ACTION SETS</para>
     59 		/// <para>-----------------------------------------------------------------------------</para>
     60 		/// <para> Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls.</para>
     61 		/// </summary>
     62 		public static ControllerActionSetHandle_t GetActionSetHandle(string pszActionSetName) {
     63 			InteropHelp.TestIfAvailableClient();
     64 			using (var pszActionSetName2 = new InteropHelp.UTF8StringHandle(pszActionSetName)) {
     65 				return (ControllerActionSetHandle_t)NativeMethods.ISteamController_GetActionSetHandle(CSteamAPIContext.GetSteamController(), pszActionSetName2);
     66 			}
     67 		}
     68 
     69 		/// <summary>
     70 		/// <para> Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive')</para>
     71 		/// <para> This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in</para>
     72 		/// <para> your state loops, instead of trying to place it in all of your state transitions.</para>
     73 		/// </summary>
     74 		public static void ActivateActionSet(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle) {
     75 			InteropHelp.TestIfAvailableClient();
     76 			NativeMethods.ISteamController_ActivateActionSet(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle);
     77 		}
     78 
     79 		public static ControllerActionSetHandle_t GetCurrentActionSet(ControllerHandle_t controllerHandle) {
     80 			InteropHelp.TestIfAvailableClient();
     81 			return (ControllerActionSetHandle_t)NativeMethods.ISteamController_GetCurrentActionSet(CSteamAPIContext.GetSteamController(), controllerHandle);
     82 		}
     83 
     84 		/// <summary>
     85 		/// <para> ACTION SET LAYERS</para>
     86 		/// </summary>
     87 		public static void ActivateActionSetLayer(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetLayerHandle) {
     88 			InteropHelp.TestIfAvailableClient();
     89 			NativeMethods.ISteamController_ActivateActionSetLayer(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetLayerHandle);
     90 		}
     91 
     92 		public static void DeactivateActionSetLayer(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetLayerHandle) {
     93 			InteropHelp.TestIfAvailableClient();
     94 			NativeMethods.ISteamController_DeactivateActionSetLayer(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetLayerHandle);
     95 		}
     96 
     97 		public static void DeactivateAllActionSetLayers(ControllerHandle_t controllerHandle) {
     98 			InteropHelp.TestIfAvailableClient();
     99 			NativeMethods.ISteamController_DeactivateAllActionSetLayers(CSteamAPIContext.GetSteamController(), controllerHandle);
    100 		}
    101 
    102 		/// <summary>
    103 		/// <para> Enumerate currently active layers</para>
    104 		/// <para> handlesOut should point to a STEAM_CONTROLLER_MAX_ACTIVE_LAYERS sized array of ControllerActionSetHandle_t handles.</para>
    105 		/// <para> Returns the number of handles written to handlesOut</para>
    106 		/// </summary>
    107 		public static int GetActiveActionSetLayers(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t[] handlesOut) {
    108 			InteropHelp.TestIfAvailableClient();
    109 			if (handlesOut != null && handlesOut.Length != Constants.STEAM_CONTROLLER_MAX_ACTIVE_LAYERS) {
    110 				throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ACTIVE_LAYERS!");
    111 			}
    112 			return NativeMethods.ISteamController_GetActiveActionSetLayers(CSteamAPIContext.GetSteamController(), controllerHandle, handlesOut);
    113 		}
    114 
    115 		/// <summary>
    116 		/// <para>-----------------------------------------------------------------------------</para>
    117 		/// <para> ACTIONS</para>
    118 		/// <para>-----------------------------------------------------------------------------</para>
    119 		/// <para> Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls.</para>
    120 		/// </summary>
    121 		public static ControllerDigitalActionHandle_t GetDigitalActionHandle(string pszActionName) {
    122 			InteropHelp.TestIfAvailableClient();
    123 			using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) {
    124 				return (ControllerDigitalActionHandle_t)NativeMethods.ISteamController_GetDigitalActionHandle(CSteamAPIContext.GetSteamController(), pszActionName2);
    125 			}
    126 		}
    127 
    128 		/// <summary>
    129 		/// <para> Returns the current state of the supplied digital game action</para>
    130 		/// </summary>
    131 		public static ControllerDigitalActionData_t GetDigitalActionData(ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle) {
    132 			InteropHelp.TestIfAvailableClient();
    133 			return NativeMethods.ISteamController_GetDigitalActionData(CSteamAPIContext.GetSteamController(), controllerHandle, digitalActionHandle);
    134 		}
    135 
    136 		/// <summary>
    137 		/// <para> Get the origin(s) for a digital action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.</para>
    138 		/// <para> originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles. The EControllerActionOrigin enum will get extended as support for new controller controllers gets added to</para>
    139 		/// <para> the Steam client and will exceed the values from this header, please check bounds if you are using a look up table.</para>
    140 		/// </summary>
    141 		public static int GetDigitalActionOrigins(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerDigitalActionHandle_t digitalActionHandle, EControllerActionOrigin[] originsOut) {
    142 			InteropHelp.TestIfAvailableClient();
    143 			if (originsOut != null && originsOut.Length != Constants.STEAM_CONTROLLER_MAX_ORIGINS) {
    144 				throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ORIGINS!");
    145 			}
    146 			return NativeMethods.ISteamController_GetDigitalActionOrigins(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle, digitalActionHandle, originsOut);
    147 		}
    148 
    149 		/// <summary>
    150 		/// <para> Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls.</para>
    151 		/// </summary>
    152 		public static ControllerAnalogActionHandle_t GetAnalogActionHandle(string pszActionName) {
    153 			InteropHelp.TestIfAvailableClient();
    154 			using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) {
    155 				return (ControllerAnalogActionHandle_t)NativeMethods.ISteamController_GetAnalogActionHandle(CSteamAPIContext.GetSteamController(), pszActionName2);
    156 			}
    157 		}
    158 
    159 		/// <summary>
    160 		/// <para> Returns the current state of these supplied analog game action</para>
    161 		/// </summary>
    162 		public static ControllerAnalogActionData_t GetAnalogActionData(ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle) {
    163 			InteropHelp.TestIfAvailableClient();
    164 			return NativeMethods.ISteamController_GetAnalogActionData(CSteamAPIContext.GetSteamController(), controllerHandle, analogActionHandle);
    165 		}
    166 
    167 		/// <summary>
    168 		/// <para> Get the origin(s) for an analog action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.</para>
    169 		/// <para> originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles. The EControllerActionOrigin enum will get extended as support for new controller controllers gets added to</para>
    170 		/// <para> the Steam client and will exceed the values from this header, please check bounds if you are using a look up table.</para>
    171 		/// </summary>
    172 		public static int GetAnalogActionOrigins(ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerAnalogActionHandle_t analogActionHandle, EControllerActionOrigin[] originsOut) {
    173 			InteropHelp.TestIfAvailableClient();
    174 			if (originsOut != null && originsOut.Length != Constants.STEAM_CONTROLLER_MAX_ORIGINS) {
    175 				throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_CONTROLLER_MAX_ORIGINS!");
    176 			}
    177 			return NativeMethods.ISteamController_GetAnalogActionOrigins(CSteamAPIContext.GetSteamController(), controllerHandle, actionSetHandle, analogActionHandle, originsOut);
    178 		}
    179 
    180 		/// <summary>
    181 		/// <para> Get a local path to art for on-screen glyph for a particular origin - this call is cheap</para>
    182 		/// </summary>
    183 		public static string GetGlyphForActionOrigin(EControllerActionOrigin eOrigin) {
    184 			InteropHelp.TestIfAvailableClient();
    185 			return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetGlyphForActionOrigin(CSteamAPIContext.GetSteamController(), eOrigin));
    186 		}
    187 
    188 		/// <summary>
    189 		/// <para> Returns a localized string (from Steam's language setting) for the specified origin - this call is serialized</para>
    190 		/// </summary>
    191 		public static string GetStringForActionOrigin(EControllerActionOrigin eOrigin) {
    192 			InteropHelp.TestIfAvailableClient();
    193 			return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetStringForActionOrigin(CSteamAPIContext.GetSteamController(), eOrigin));
    194 		}
    195 
    196 		public static void StopAnalogActionMomentum(ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t eAction) {
    197 			InteropHelp.TestIfAvailableClient();
    198 			NativeMethods.ISteamController_StopAnalogActionMomentum(CSteamAPIContext.GetSteamController(), controllerHandle, eAction);
    199 		}
    200 
    201 		/// <summary>
    202 		/// <para> Returns raw motion data from the specified controller</para>
    203 		/// </summary>
    204 		public static ControllerMotionData_t GetMotionData(ControllerHandle_t controllerHandle) {
    205 			InteropHelp.TestIfAvailableClient();
    206 			return NativeMethods.ISteamController_GetMotionData(CSteamAPIContext.GetSteamController(), controllerHandle);
    207 		}
    208 
    209 		/// <summary>
    210 		/// <para>-----------------------------------------------------------------------------</para>
    211 		/// <para> OUTPUTS</para>
    212 		/// <para>-----------------------------------------------------------------------------</para>
    213 		/// <para> Trigger a haptic pulse on a controller</para>
    214 		/// </summary>
    215 		public static void TriggerHapticPulse(ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec) {
    216 			InteropHelp.TestIfAvailableClient();
    217 			NativeMethods.ISteamController_TriggerHapticPulse(CSteamAPIContext.GetSteamController(), controllerHandle, eTargetPad, usDurationMicroSec);
    218 		}
    219 
    220 		/// <summary>
    221 		/// <para> Trigger a pulse with a duty cycle of usDurationMicroSec / usOffMicroSec, unRepeat times.</para>
    222 		/// <para> nFlags is currently unused and reserved for future use.</para>
    223 		/// </summary>
    224 		public static void TriggerRepeatedHapticPulse(ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec, ushort usOffMicroSec, ushort unRepeat, uint nFlags) {
    225 			InteropHelp.TestIfAvailableClient();
    226 			NativeMethods.ISteamController_TriggerRepeatedHapticPulse(CSteamAPIContext.GetSteamController(), controllerHandle, eTargetPad, usDurationMicroSec, usOffMicroSec, unRepeat, nFlags);
    227 		}
    228 
    229 		/// <summary>
    230 		/// <para> Trigger a vibration event on supported controllers.</para>
    231 		/// </summary>
    232 		public static void TriggerVibration(ControllerHandle_t controllerHandle, ushort usLeftSpeed, ushort usRightSpeed) {
    233 			InteropHelp.TestIfAvailableClient();
    234 			NativeMethods.ISteamController_TriggerVibration(CSteamAPIContext.GetSteamController(), controllerHandle, usLeftSpeed, usRightSpeed);
    235 		}
    236 
    237 		/// <summary>
    238 		/// <para> Set the controller LED color on supported controllers.</para>
    239 		/// </summary>
    240 		public static void SetLEDColor(ControllerHandle_t controllerHandle, byte nColorR, byte nColorG, byte nColorB, uint nFlags) {
    241 			InteropHelp.TestIfAvailableClient();
    242 			NativeMethods.ISteamController_SetLEDColor(CSteamAPIContext.GetSteamController(), controllerHandle, nColorR, nColorG, nColorB, nFlags);
    243 		}
    244 
    245 		/// <summary>
    246 		/// <para>-----------------------------------------------------------------------------</para>
    247 		/// <para> Utility functions availible without using the rest of Steam Input API</para>
    248 		/// <para>-----------------------------------------------------------------------------</para>
    249 		/// <para> Invokes the Steam overlay and brings up the binding screen if the user is using Big Picture Mode</para>
    250 		/// <para> If the user is not in Big Picture Mode it will open up the binding in a new window</para>
    251 		/// </summary>
    252 		public static bool ShowBindingPanel(ControllerHandle_t controllerHandle) {
    253 			InteropHelp.TestIfAvailableClient();
    254 			return NativeMethods.ISteamController_ShowBindingPanel(CSteamAPIContext.GetSteamController(), controllerHandle);
    255 		}
    256 
    257 		/// <summary>
    258 		/// <para> Returns the input type for a particular handle</para>
    259 		/// </summary>
    260 		public static ESteamInputType GetInputTypeForHandle(ControllerHandle_t controllerHandle) {
    261 			InteropHelp.TestIfAvailableClient();
    262 			return NativeMethods.ISteamController_GetInputTypeForHandle(CSteamAPIContext.GetSteamController(), controllerHandle);
    263 		}
    264 
    265 		/// <summary>
    266 		/// <para> Returns the associated controller handle for the specified emulated gamepad - can be used with the above 2 functions</para>
    267 		/// <para> to identify controllers presented to your game over Xinput. Returns 0 if the Xinput index isn't associated with Steam Input</para>
    268 		/// </summary>
    269 		public static ControllerHandle_t GetControllerForGamepadIndex(int nIndex) {
    270 			InteropHelp.TestIfAvailableClient();
    271 			return (ControllerHandle_t)NativeMethods.ISteamController_GetControllerForGamepadIndex(CSteamAPIContext.GetSteamController(), nIndex);
    272 		}
    273 
    274 		/// <summary>
    275 		/// <para> Returns the associated gamepad index for the specified controller, if emulating a gamepad or -1 if not associated with an Xinput index</para>
    276 		/// </summary>
    277 		public static int GetGamepadIndexForController(ControllerHandle_t ulControllerHandle) {
    278 			InteropHelp.TestIfAvailableClient();
    279 			return NativeMethods.ISteamController_GetGamepadIndexForController(CSteamAPIContext.GetSteamController(), ulControllerHandle);
    280 		}
    281 
    282 		/// <summary>
    283 		/// <para> Returns a localized string (from Steam's language setting) for the specified Xbox controller origin.</para>
    284 		/// </summary>
    285 		public static string GetStringForXboxOrigin(EXboxOrigin eOrigin) {
    286 			InteropHelp.TestIfAvailableClient();
    287 			return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetStringForXboxOrigin(CSteamAPIContext.GetSteamController(), eOrigin));
    288 		}
    289 
    290 		/// <summary>
    291 		/// <para> Get a local path to art for on-screen glyph for a particular Xbox controller origin.</para>
    292 		/// </summary>
    293 		public static string GetGlyphForXboxOrigin(EXboxOrigin eOrigin) {
    294 			InteropHelp.TestIfAvailableClient();
    295 			return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamController_GetGlyphForXboxOrigin(CSteamAPIContext.GetSteamController(), eOrigin));
    296 		}
    297 
    298 		/// <summary>
    299 		/// <para> Get the equivalent ActionOrigin for a given Xbox controller origin this can be chained with GetGlyphForActionOrigin to provide future proof glyphs for</para>
    300 		/// <para> non-Steam Input API action games. Note - this only translates the buttons directly and doesn't take into account any remapping a user has made in their configuration</para>
    301 		/// </summary>
    302 		public static EControllerActionOrigin GetActionOriginFromXboxOrigin(ControllerHandle_t controllerHandle, EXboxOrigin eOrigin) {
    303 			InteropHelp.TestIfAvailableClient();
    304 			return NativeMethods.ISteamController_GetActionOriginFromXboxOrigin(CSteamAPIContext.GetSteamController(), controllerHandle, eOrigin);
    305 		}
    306 
    307 		/// <summary>
    308 		/// <para> Convert an origin to another controller type - for inputs not present on the other controller type this will return k_EControllerActionOrigin_None</para>
    309 		/// </summary>
    310 		public static EControllerActionOrigin TranslateActionOrigin(ESteamInputType eDestinationInputType, EControllerActionOrigin eSourceOrigin) {
    311 			InteropHelp.TestIfAvailableClient();
    312 			return NativeMethods.ISteamController_TranslateActionOrigin(CSteamAPIContext.GetSteamController(), eDestinationInputType, eSourceOrigin);
    313 		}
    314 
    315 		/// <summary>
    316 		/// <para> Get the binding revision for a given device. Returns false if the handle was not valid or if a mapping is not yet loaded for the device</para>
    317 		/// </summary>
    318 		public static bool GetControllerBindingRevision(ControllerHandle_t controllerHandle, out int pMajor, out int pMinor) {
    319 			InteropHelp.TestIfAvailableClient();
    320 			return NativeMethods.ISteamController_GetControllerBindingRevision(CSteamAPIContext.GetSteamController(), controllerHandle, out pMajor, out pMinor);
    321 		}
    322 	}
    323 }
    324 
    325 #endif // !DISABLESTEAMWORKS