cyanic's Steam Achievements Integration

Quick and Easy Steamworks Achievements Integration for RPG Maker VX Ace r7
by cyanic
​

Introduction
This script allows you to use Steam achievements from your game. It needs no intermediary DLLs, only a recent version of the Steamworks DLL.

Features
  • Set/clear achievements
  • Get/set player stats
  • Supports average rate stats
  • Get achievement state and unlocked time
  • Enumerate achievements programmatically, get their display name and hidden status
  • Reset all stats and achievements
  • Check game ownership
  • Check if a DLC is installed

Changelog
Spoiler
r7 (02/25/20)
  • Updated script for Steamworks SDK 1.48.
  • Relicense under MIT License

r6 (02/25/20)
  • Updated script for Steamworks SDK 1.43.
  • Automatically retrieve stats on init.

r5 (08/08/16)
  • Added indicate_achievement_progress method.

r4 (06/16/16)
  • Updated script for Steamworks SDK 1.37.

r3.2 (03/12/16)
  • Fixed pointer return type on DLL imports.

r3.1 (11/15/15)
  • Added app is subscribed and DLC is installed methods.

r3 (11/15/15)
  • Added get methods, stats set methods.

r2 (11/15/15)
  • Tested in RPG Maker, fixed to make the script actually run.

r1 (11/14/15)
  • Initial version, written for Ruby 2.2.3.

How to Use
  • Download a recent version of the Steamworks SDK (>= 1.37), and put its steam_api.dll into the root of your project folder.
  • Add the script into the script editor.
  • In the event or wherever else you want to set an achievement, add the following code:
    Code:
    steam = SteamUserStatsLite.instance
    steam.set_achievement 'YOUR_ACH_ID_HERE'
    steam.update
    Replace 'YOUR_ACH_ID_HERE' with the achievement's API name from the Steamworks partner site.
  • If you want to set a stat, use this code:
    Code:
    steam = SteamUserStatsLite.instance
    steam.set_stat 'YOUR_STAT_ID_HERE', 100
    steam.update
    Replace 'YOUR_STAT_ID_HERE' with the stat's API name from the Steamworks partner site.
  • The #set_achievement and #set_stat methods return true when the achievement/stat has been set succesfully. If it returns false, see the FAQ for more information.

Please see documentation on GitHub.

Demo
This demo was created by Miller Berto. Create a default RPG Maker project, and extract the contents of the ZIP file into the project folder. Please replace the SteamUserStatsLite script with the latest version.

Script
The version to download depends on which version of the Steamworks SDK you want to use. Different versions of Steamworks SDK have different and sometimes incompatible ways of calling its functions, so you need the correct script to have it use the SDK correctly.
  • Steamworks SDK v1.48 and above: r7
  • Steamworks SDK v1.43 to v1.47: r6
  • Steamworks SDK v1.37 to v1.42: r5
  • Steamworks SDK v1.32 to v1.36: r3.2

License
Licensed under the MIT License, which means you can do anything with the script as long as you include the copyright notice.

FAQ
Q: #set_achievement/#set_stat returns false. What's wrong?
A: It means either you haven't set up the achievement in the Steamworks partner site or you were playtesting through RPG Maker.
Because the playtesting game inherits the Steam context from RPG Maker, your achievements won't be found. If you launch your game directly, it should work. I recommend you add a steam_appid.txt file with your app ID during development so you can just launch the EXE and Steamworks will set the right context. If you have a steam_appid.txt file present, you can also launch RPG Maker by double clicking your project file, and the app ID would be set to yours so you can test achievements through playtesting from RPG Maker.
It could also be possible that Steamworks wasn't able to initialize. Check SteamUserStatsLite#initted? to see if Steamworks was initialized successfully.

Q: #set_stat is returning false, but I've already checked that Steamworks was initialized and the stat added and published on the Steamworks partner site. What do I do now?
A: #set_stat can take both Integers and Floats. Make sure when you're passing in the value, you have it converted to the type corresponding to what you set on the Steamworks partner site.

Q: I'm getting a RuntimeError telling me something about GetProcAddress.
A: You need to use at least Steamworks SDK 1.37 for this script to work. Download a newer version of the SDK.

Q: My game crashes when I try to call a Steamworks function. I'm using Steam DRM.
A: There is a compatibility problem with Steam DRM. So don't use it. Not as if it'll actually protect your game. It only gives you an illusion of safety, while in practice is practically useless for protection.

Q: I'm using r3.x, should I upgrade?
A: r4 is functionally the same as r3.2. If you do not need to use the latest Steamworks SDK, you do not need to (and probably should not) upgrade.

Credit and Thanks

Author's Notes
I'm actually a complete RPG Maker noob. I wrote this yesterday on pure Ruby 2.2.3, and only got a copy of RPG Maker VX Ace this morning to test and fix problems.
Great, seems like the post is finally live.. What you are doing is great, cyanic! Now everyone can easily get steam achievements in their games..

Ohh.. and this script works. Tried it with my game.
Hello!, Sorry for necro this...but, not when I obtain an achievement the game just crash...I think they changed the steam API...could it be that? I tried to update the new steamapi.dll but it's not working :c


Problem signature:Problem Event Name: APPCRASHApplication Name: Game.exeApplication Name: 3.0.0.1Application Timestamo: 4e8d3142Fault Module Name: steam_api.DLLFault Module Version: 3.4.27.90Fault Module Timestamp: 5627de96Exception Code: c0000005Exception Offset: 000014dbOS Version: 6.1.7601.2.1.0.256.1Locale ID: 3082Additional Information 1: 0a9eAdditional Information 2: 0a9e372d3b4ad19135b953a78882e789Additional Information 3: 0a9eAdditional Information 4: 0a9e372d3b4ad19135b953a78882e789
Hello!, Sorry for necro this...but, not when I obtain an achievement the game just crash...I think they changed the steam API...could it be that? I tried to update the new steamapi.dll but it's not working :c

Could you post how you're calling the script and what Steamworks SDK version you're using?
Could you post how you're calling the script and what Steamworks SDK version you're using?


Hello, thanks for answering, let me copy the exact script I was using until some days ago.
 


steam = SteamUserStatsLite.instance
steam.set_achievement 'NEW_ACHIEVEMENT_2_0'
steam.update




Where: 'NEW_ACHIEVEMENT_2_0' is the name of my 2nd achievement on Steamworks...


This worked fine, but now it's not working, I was using SDK 1.35, but they updated it some weeks ago, now is 1.36. I tried to download the new SDK and update the steam_api.dll but it's still crashing...If I play the game without steam open (the source files on my PC), it won't crash, so it only happens when Steam is open,and when obtaining any new achievement. 🙁


Thanks in advance for any help,
Hello, thanks for answering, let me copy the exact script I was using until some days ago.




steam = SteamUserStatsLite.instance
steam.set_achievement 'NEW_ACHIEVEMENT_2_0'
steam.update




Where: 'NEW_ACHIEVEMENT_2_0' is the name of my 2nd achievement on Steamworks...


This worked fine, but now it's not working, I was using SDK 1.35, but they updated it some weeks ago, now is 1.36. I tried to download the new SDK and update the steam_api.dll but it's still crashing...If I play the game without steam open (the source files on my PC), it won't crash, so it only happens when Steam is open,and when obtaining any new achievement. 🙁


Thanks in advance for any help,



I did some testing with "A Camp in the Woods" on Steam, and I found out that running it on 1.35 SDK works fine, but, when I tried 1.36, the RGSS Player crashed.


I use the same configuration as you do:


cyanicscript.png
I did some testing with "A Camp in the Woods" on Steam, and I found out that running it on 1.35 SDK works fine, but, when I tried 1.36, the RGSS Player crashed.


I use the same configuration as you do:


cyanicscript.png



I guess it has something to do with the new 'memory improvements'.



Really? that's weird, we didn't updated the game on Steam, but still people started to report this error, that's how we discover this. Then we checked and updated the steam_api.dll to 1.36 and still crashes 🙁
Try the version on the pointers-fix branch: link. I tested it on Windows 10, but nowhere else, so there may still be some problems.


Bug explanation: In the version of Ruby used in VX Ace, pointers are treated as strings. It appears that Ruby copied the return value literally as a string, so the end result is a truncated vtable at the first NULL character. Changing some return values to number should have Ruby retain the original pointer value.
Hello Cyanic,


I want to know is this going to work with a game made with RPG Maker MV?


thank in advance for your support 🙂
Try the version on the pointers-fix branch: link. I tested it on Windows 10, but nowhere else, so there may still be some problems.


Bug explanation: In the version of Ruby used in VX Ace, pointers are treated as strings. It appears that Ruby copied the return value literally as a string, so the end result is a truncated vtable at the first NULL character. Changing some return values to number should have Ruby retain the original pointer value.



You are awesome sir, it's working fine now! Was because of Steam update? It's weird because it was working fine until a few weeks ago.


But now it's working excellent! Tested on Windows 8.1 / 7.



Thanks Cyanic! 🙂

Q: My game crashes when I try to call a Steamworks function. I'm using Steam DRM.
A: There is a compatibility problem with Steam DRM. So don't use it. Not as if it'll actually protect your game. It only gives you an illusion of safety, while in practice is practically useless for protection.
​



When calling the steamworks function by game just crashed to desktop.


I replaced the exe with a fresh one thinking I added DRM but still get the issue. I can see that game.exe is listed in DRM on Steamworks.


Any idea on how to fix?
Hello Cyanic,


I want to know is this going to work with a game made with RPG Maker MV?


thank in advance for your support 🙂

Unfortunately, it will not, because VX Ace and MV use completely different languages and engines for scripting. For MV, you're looking for a JavaScript solution. I can't seem to find the thread about it right now, but what you're looking for is probably Greenworks.

You are awesome sir, it's working fine now! Was because of Steam update? It's weird because it was working fine until a few weeks ago.


But now it's working excellent! Tested on Windows 8.1 / 7.



Thanks Cyanic! 🙂

It was probably broken the entire time, and just got lucky it wasn't so broken that it didn't work until the most recent Steam update.

When calling the steamworks function by game just crashed to desktop.


I replaced the exe with a fresh one thinking I added DRM but still get the issue. I can see that game.exe is listed in DRM on Steamworks.


Any idea on how to fix?

Could you try the r3.2 script linked a few posts up?
Thx Cyanic I will look into it if I'm able to understand how it work 😉
On the demo I saw that the app id was set on a text file, is that correct? I tried setting mine up but I keep getting the following print:Capturar.PNG


What am I doing wrong?


Thanks for the nifty script by the way 😮
On the demo I saw that the app id was set on a text file, is that correct? I tried setting mine up but I keep getting the following print:View attachment 33558


What am I doing wrong?


Thanks for the nifty script by the way 😮

This means you are trying to run your game through RPG Maker VX Ace. Try running it outside of RPG Maker, and it'll work fine.


🙂
Hmm I'm trying to get all of the achievements available for oceanhorn (339200) to see if the code working but all I get is 0. 


steam = SteamUserStatsLite.instance

$game_variables[77] = 'num of achieves are' + steam.get_num_achievements.to_s


Then I do a message with \v[77]
Hmm I'm trying to get all of the achievements available for oceanhorn (339200) to see if the code working but all I get is 0. 



steam = SteamUserStatsLite.instance

$game_variables[77] = 'num of achieves are' + steam.get_num_achievements.to_s


Then I do a message with \v[77]



First, make sure that you're not starting the game from within RPG Maker, because it will inherit RPG Maker's app ID (see first FAQ item). Next, make sure you own the app you're testing on, and put its app ID in steam_appid.txt. After that, try again and see what happens. If you want to see the return value of the function when it's called, you can inspect it and open a msgbox, like this:

Code:
msgbox(steam.get_num_achievements.inspect)
Could you try the r3.2 script linked a few posts up?



That seems to have fixed it =D 
Okay I have two maybe dumb questions. Do I need to upload a build to a beta branch in order to the values to come? Also does the achievements need to be published?


I tried fetching a stat but it's returning as nil. I tried adding an achievement but the total I'm getting is still 0. 😮
You don't need to upload a build, but you do need to make sure the stats are configured properly, then published. If you need some live help, try chatting up Miller, since he's got it all integrated and should know how to get everything working on Steam's end (I don't have my own game, so no access to the partner panel to look things up).

Original thread: https://forums.rpgmakerweb.com/threads/cyanics-steam-achievements-integration.50640/