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
4 changes: 3 additions & 1 deletion docs/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@
/**
* @func steam_input_get_controller_for_gamepad_index
* @desc This function returns the input handle for an XInput gamepad slot, or 0 if that slot is not powered by Steam Input. That can be used to match between native GameMaker `gamepad_` slots and Steam Input controllers on Windows. Since on Windows the GameMaker pad slots from 0 to 3 are XInput controllers, and from 4 to 12 are DirectInput controllers. This function only works with emulated XInput controllers.
*
* [[NOTE: Invalid slot values return `0`.]]
*
* @param {real} index XInput slot from 0 to 3 included.
*
Expand All @@ -911,7 +913,7 @@

/**
* @func steam_input_get_gamepad_index_for_controller
* @desc This function is the reverse of ${function.steam_input_get_controller_for_gamepad_index}, except it allows you to determine whether a Steam Input handle is being emulated as XInput as well or not. See the definition of the reverse function for more information about slots.
* @desc This function is the reverse of ${function.steam_input_get_controller_for_gamepad_index}, except it allows you to determine whether a Steam Input handle is being emulated as XInput as well or not. It returns `-1` when no XInput slot maps to the controller handle. See the definition of the reverse function for more information about slots.
*
* @param {real} controller Input handle of the controller.
*
Expand Down
4 changes: 2 additions & 2 deletions source/Steamworks_gml/extensions/steamworks/Steamworks.yy

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

Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,9 @@ YYEXPORT void steam_input_get_input_type_for_handle(RValue& Result, CInstance* s
Result.val = static_cast<double>(API->GetInputTypeForHandle(con));
}

static constexpr int steam_input_xinput_slot_count = 4;
static constexpr int steam_input_no_gamepad_index = -1;

/// (index:real)->input_handle
YYEXPORT void steam_input_get_controller_for_gamepad_index(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)
{
Expand All @@ -1012,6 +1015,12 @@ YYEXPORT void steam_input_get_controller_for_gamepad_index(RValue& Result, CInst
return;
}

if (xinput_ind < 0 || xinput_ind >= steam_input_xinput_slot_count)
{
Result.v64 = 0;
return;
}

Result.v64 = static_cast<int64>(API->GetControllerForGamepadIndex(xinput_ind));
}

Expand All @@ -1029,7 +1038,23 @@ YYEXPORT void steam_input_get_gamepad_index_for_controller(RValue& Result, CInst
return;
}

Result.val = API->GetGamepadIndexForController(con);
int gamepadIndex = API->GetGamepadIndexForController(con);
if (gamepadIndex >= 0 && gamepadIndex < steam_input_xinput_slot_count)
{
Result.val = gamepadIndex;
return;
}

for (int i = 0; i < steam_input_xinput_slot_count; ++i)
{
if (API->GetControllerForGamepadIndex(i) == con)
{
Result.val = i;
return;
}
}

Result.val = steam_input_no_gamepad_index;
}

/// (origin:xbox_origin)->string
Expand Down