Skip to content

Instantly share code, notes, and snippets.

@ellraiser
Created February 27, 2022 14:37
Show Gist options
  • Select an option

  • Save ellraiser/308eff835695e39c10e2d13eed9b9490 to your computer and use it in GitHub Desktop.

Select an option

Save ellraiser/308eff835695e39c10e2d13eed9b9490 to your computer and use it in GitHub Desktop.
Check if running on SteamDeck in GMS2
// method for detecting if we're running on steamdeck in GMS2
// super flakey as maybe things will change but works good enough for now!
/*
* @method - sc_is_running_steamdeck()
* @desc - checks if GMS2 is running on a steamdeck by checking some vendor info
*
* @return {struct} - returns a struct with two keys, "is_steamdeck" (bool) and "gamepad_index" (int)
*/
function sc_is_running_steamdeck() {
// logs
// show_debug_message("[sc_is_running_steamdeck] Checking Device..");
// get device info
var info = os_get_info();
var vendor = info[? "gl_vendor_string"] + " " + info[? "gl_version_string"];
var renderer = info[? "gl_renderer_string"];
var gamepad_index = -1;
var is_steamdeck = false;
// find the device for the deck
var devices = gamepad_get_device_count();
for (var i = 0; i < devices; i++;) {
if (gamepad_is_connected(i)) {
var desc = gamepad_get_description(i);
// on steamdeck the gamepad is called "Valve Streaming Gamepad"
// use this index as normal for your gamepad controls
// there can be other "blank" devices picked up as well
if (desc != "" && string_pos("Valve", desc) != 0) {
gamepad_index = i;
}
}
}
// logs
// show_debug_message("[sc_is_running_steamdeck] Vendor is: " + vendor);
// show_debug_message("[sc_is_running_steamdeck] Renderer is: " + renderer);
// on steamdeck the vendor + version should be like "AMD 4.6 Mesa 22.0.0"
// on steamdeck the renderer should be like "AMD Custom GPU 0405 (LLVM 13.0.0, DRM 3.45, 5.13.0-valve)"
if (string_pos("AMD", vendor) != 0 && string_pos("Mesa", vendor) != 0 &&
string_pos("AMD", renderer) != 0 && string_pos("valve", renderer) != 0 &&
gamepad_index >= 0) {
is_steamdeck = true;
}
// return vals
return {
is_steamdeck: is_steamdeck,
gamepad_index: gamepad_index
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment