Last active
September 14, 2022 16:59
-
-
Save Miouyouyou/803722fa0f58d6d7cb2157667c6a612c to your computer and use it in GitHub Desktop.
SteamIdler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A really dumb Steam Idler in C for Linux systems. | |
* Might work on Mac OS too but I never tested it. | |
* | |
* /!\ You need to have Steam currently running on the computer | |
* ⁻⁻⁻ executing this software. | |
* | |
* Short version : | |
* gcc -o SteamIdler steam-idler.c libsteam_api.so | |
* | |
* Long version : | |
* | |
* The point : | |
* This will make Steam believes you're currently running the game, | |
* increasing the 'Play Time' by the amount of 'seconds' this software | |
* is running. | |
* This program works for any game in your Steam library, whether it | |
* is installed, not installed or not available for your platform. | |
* | |
* The current interesting point of this software is "Cards drops". | |
* "Cards drops" being influenced by the 'Play Time', by using this | |
* software you can obtain droppable cards from any game in your | |
* library without even installing them. | |
* | |
* Getting the AppId of a Steam game/app : | |
* The simplest way is to visit the Store Page of that game/app and | |
* look at the number on the right side of the URL (within Steam, you | |
* might need to copy the URL and paste it elsewhere) | |
* Let's take the game "Borderlands 2" as an example : | |
* The Store Page URL is http://store.steampowered.com/app/49520/ | |
* Therefore, the AppId is 49520 | |
* | |
* A more complex way is to parse the HTML of your "Badges" profile. | |
* | |
* Compiling informations : | |
* You need to link the executable to a library containing a | |
* 'SteamAPI_Init' symbol. | |
* | |
* Such library is generally named "libsteam_api.so" and present in | |
* the folders of any Steam game installed. | |
* | |
* You can check the symbol availability in a library with 'nm' : | |
* $ nm libsteam_api.so | grep SteamAPI_Init | |
* => (numeric_address) T SteamAPI_Init | |
* | |
* If nm returns nothing, or if there's no address before the symbol | |
* name, look elsewhere. | |
* If there's no address, chances are that the right library is in a | |
* folder nearby. `ldd library_name` could give you a hint. | |
* | |
*/ | |
#include <stdio.h> /* puts, printf, fflush */ | |
#include <unistd.h> /* sleep */ | |
#include <stdint.h> /* uint32_t */ | |
#include <stdlib.h> /* setenv, atoi */ | |
/* Technically, SteamAPI_Init returns a bool */ | |
extern uint32_t SteamAPI_Init(); | |
void usage(const char*) __attribute__((noreturn)); | |
void idle_and_exit(const uint32_t) __attribute__((noreturn)); | |
int main(const int argc, const char *argv[]) { | |
/* ProgramName appId time -> argc == 3 */ | |
if (argc != 3) usage(argv[0]); | |
const char *appId = argv[1]; | |
const uint32_t time = atoi(argv[2]); | |
/* The Steam API will use the SteamAppId environment variable to | |
* determine the application to initialise. */ | |
puts("Setting environment"); | |
setenv("SteamAppId", appId, 1); | |
puts("Initialising Steam"); | |
if (SteamAPI_Init()) { | |
puts("Steam Initialised"); | |
idle_and_exit(time); | |
} | |
puts("Could not initialise Steam correctly."); | |
puts("This might happen if you're running too many games at once"); | |
return 1; | |
} | |
void usage(const char *program_name) { | |
printf("%s appId seconds\n", program_name); | |
exit(1); | |
} | |
void idle_and_exit(const uint32_t time) { | |
printf("Sleeping for %d seconds\n", time); | |
fflush(stdout); | |
sleep(time); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment