Documentation by YARD 0.8.7.6

cyanic's Quick and Easy Steamworks Achievements Integration for Ruby github.com/GMMan/RGSS_SteamUserStatsLite r4 06/16/16

Drop steam_api.dll into the root of your project. Requires Steamworks SDK version >= 1.37.

“Miller complained about how hard achievements were to implement in C++, so this was born.”

Top Level Namespace

Defined Under Namespace

Classes: SteamAPIContext, SteamUserStatsLite

Class: SteamAPIContext

Inherits:
Object
  • Object
show all
Defined in:
steam_user_stats_lite.rb

Overview

A context class to get Steamworks pointers to interfaces.

Author:

Constant Summary

Instance Method Summary (collapse)

Constructor Details

- (SteamAPIContext) initialize

Instantiates a new instance of SteamAPIContext.



26
27
28
29
30
31
32
33
34
35
36
# File 'steam_user_stats_lite.rb', line 26

def initialize
  @initted = false
  @h_steam_user = @@dll_SteamAPI_GetHSteamUser.call
  if (@h_steam_pipe = @@dll_SteamAPI_GetHSteamPipe.call) != 0
    return if (@steam_client = @@dll_SteamInternal_CreateInterface.call(STEAMCLIENT_INTERFACE_VERSION)) == 0
    return if (@steam_user_stats = @@dll_SteamAPI_ISteamClient_GetISteamUserStats.call(@steam_client, @h_steam_user, @h_steam_pipe, STEAMUSERSTATS_INTERFACE_VERSION)) == 0
    return if (@steam_apps = @@dll_SteamAPI_ISteamClient_GetISteamApps.call(@steam_client, @h_steam_user, @h_steam_pipe, STEAMAPPS_INTERFACE_VERSION)) == 0

    @initted = true
  end
end

Instance Method Details

- (true, false) initted?

Checks if context is initialized.

Returns:

  • (true, false)

    Whether context is initialized.



41
42
43
# File 'steam_user_stats_lite.rb', line 41

def initted?
  @initted
end

- (Fixnum?) steam_apps

Gets the ISteamApps pointer

Returns:

  • (Fixnum, nil)

    The ISteamUserStats pointer if context is initialized, otherwise nil.



62
63
64
# File 'steam_user_stats_lite.rb', line 62

def steam_apps
  @steam_apps if initted?
end

- (Fixnum?) steam_client

Gets the ISteamClient pointer

Returns:

  • (Fixnum, nil)

    The ISteamClient pointer if context is initialized, otherwise nil.



48
49
50
# File 'steam_user_stats_lite.rb', line 48

def steam_client
  @steam_client if initted?
end

- (Fixnum?) steam_user_stats

Gets the ISteamUserStats pointer

Returns:

  • (Fixnum, nil)

    The ISteamUserStats pointer if context is initialized, otherwise nil.



55
56
57
# File 'steam_user_stats_lite.rb', line 55

def steam_user_stats
  @steam_user_stats if initted?
end

Class: SteamUserStatsLite

Inherits:
Object
  • Object
show all
Defined in:
steam_user_stats_lite.rb

Overview

A simple class for Steamworks UserStats integration.

Author:

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SteamUserStatsLite) initialize

Instantiates a new instance of SteamUserStatsLite.



90
91
92
93
94
95
96
97
98
99
100
101
# File 'steam_user_stats_lite.rb', line 90

def initialize
  @initted = false
  api_initted = @@dll_SteamAPI_Init.call % 256 != 0
  if api_initted
    @context = SteamAPIContext.new
    if @context.initted?
      @i_apps = @context.steam_apps
      @i_user_stats = @context.steam_user_stats
      @initted = true
    end
  end
end

Class Method Details

+ (SteamUserStatsLite) instance

Gets the global instance of SteamUserStatsLite.

Returns:



348
349
350
# File 'steam_user_stats_lite.rb', line 348

def self.instance
  @@instance
end

+ (true, false) restart_app_if_necessary(app_id)

Restarts the app if Steamworks is not availble.

Parameters:

  • app_id (Integer)

    The app ID to relaunch as.

Returns:

  • (true, false)

    true if current instance should exit, false if not.



126
127
128
# File 'steam_user_stats_lite.rb', line 126

def self.restart_app_if_necessary(app_id)
  @@dll_SteamAPI_RestartAppIfNecessary.call(app_id) % 256 != 0
end

Instance Method Details

- (true, false) clear_achievement(name)

Sets an achievement as locked.

Parameters:

  • name (String)

    The name of the achievement.

Returns:

  • (true, false)

    Whether the achievement was cleared successfully.



272
273
274
275
276
277
278
279
# File 'steam_user_stats_lite.rb', line 272

def clear_achievement(name)
  if initted?
    ok = @@dll_SteamAPI_ISteamUserStats_ClearAchievement.call(@i_user_stats, name) % 256 != 0
    @@dll_SteamAPI_ISteamUserStats_StoreStats.call(@i_user_stats) % 256 != 0 && ok
  else
    false
  end
end

- (true, ...) get_achievement(name)

Gets an achievement's state.

Parameters:

  • name (String)

    The name of the achievement.

Returns:

  • (true, false, nil)

    Whether the achievement has unlocked, or nil if the achievement cannot be retrieved.



241
242
243
244
245
246
247
248
249
# File 'steam_user_stats_lite.rb', line 241

def get_achievement(name)
  if initted?
    val = ' '
    ok = @@dll_SteamAPI_ISteamUserStats_GetAchievement.call(@i_user_stats, name, val) % 256 != 0
    ok ? val.unpack('C')[0] != 0 : nil
  else
    nil
  end
end

- (<Object, Time>) get_achievement_and_unlock_time(name)

Gets an achievement's state and unlock time.

Parameters:

  • name (String)

    The name of the achievement.

Returns:

  • (<Object, Time>)

    The achievement's state (true or false) and the time it was unlocked.



285
286
287
288
289
290
291
292
293
294
# File 'steam_user_stats_lite.rb', line 285

def get_achievement_and_unlock_time(name)
  if initted?
    achieved = ' '
    unlock_time = ' ' * 4
    ok = @@dll_SteamAPI_ISteamUserStats_GetAchievementAndUnlockTime.call(@i_user_stats, name, achieved, unlock_time) % 256 != 0
    ok ? [achieved.unpack('C')[0] != 0, Time.at(unlock_time.unpack('L')[0])] : nil
  else
    nil
  end
end

- (String) get_achievement_display_attribute(name, key)

Gets the value of an achievement's display attribute.

Parameters:

  • name (String)

    The name of the achievement.

  • key (String)

    The key of the display attribute.

Returns:

  • (String)

    The value of the display attribute.



301
302
303
304
305
306
307
# File 'steam_user_stats_lite.rb', line 301

def get_achievement_display_attribute(name, key)
  if initted?
    @@dll_SteamAPI_ISteamUserStats_GetAchievementDisplayAttribute.call @i_user_stats, name, key
  else
    nil
  end
end

- (String) get_achievement_name(achievement)

Gets the name of an achievement by its index.

Parameters:

  • achievement (Integer)

    The index of the achievement.

Returns:

  • (String)

    The name of the achievement.



324
325
326
327
328
329
330
# File 'steam_user_stats_lite.rb', line 324

def get_achievement_name(achievement)
  if initted?
    @@dll_SteamAPI_ISteamUserStats_GetAchievementName.call @i_user_stats, achievement
  else
    nil
  end
end

- (Integer?) get_num_achievements

Gets the number of achievements.

Returns:

  • (Integer, nil)

    The number of achievements, or nil if the number cannot be retrieved.



312
313
314
315
316
317
318
# File 'steam_user_stats_lite.rb', line 312

def get_num_achievements
  if initted?
    @@dll_SteamAPI_ISteamUserStats_GetNumAchievements.call @i_user_stats
  else
    nil
  end
end

- (Float?) get_stat_float(name)

Gets the value of an FLOAT stat.

Parameters:

  • name (String)

    The name of the stat.

Returns:

  • (Float, nil)

    The value of the stat, or nil if the stat cannot be retrieved.



189
190
191
192
193
194
195
196
197
# File 'steam_user_stats_lite.rb', line 189

def get_stat_float(name)
  if initted?
    val = ' ' * 4
    ok = @@dll_SteamAPI_ISteamUserStats_GetStat0.call(@i_user_stats, name, val) % 256 != 0
    ok ? val.unpack('f')[0] : nil
  else
    nil
  end
end

- (Integer?) get_stat_int(name)

Gets the value of an INT stat.

Parameters:

  • name (String)

    The name of the stat.

Returns:

  • (Integer, nil)

    The value of the stat, or nil if the stat cannot be retrieved.



175
176
177
178
179
180
181
182
183
# File 'steam_user_stats_lite.rb', line 175

def get_stat_int(name)
  if initted?
    val = ' ' * 4
    ok = @@dll_SteamAPI_ISteamUserStats_GetStat.call(@i_user_stats, name, val) % 256 != 0
    ok ? val.unpack('I')[0] : nil
  else
    nil
  end
end

- (true, false) initted?

Checks if Steamworks is initialized.

Returns:

  • (true, false)

    Whether Steamworks is initialized.



118
119
120
# File 'steam_user_stats_lite.rb', line 118

def initted?
  @initted
end

- (true, ...) is_dlc_installed(app_id)

Checks if a DLC is installed.

Parameters:

  • app_id (Integer)

    The app ID of the DLC to check.

Returns:

  • (true, false, nil)

    Whether the DLC is installed. nil is returned if the installation status can't be retrieved.



152
153
154
155
156
157
158
# File 'steam_user_stats_lite.rb', line 152

def is_dlc_installed(app_id)
  if initted?
    @@dll_SteamAPI_ISteamApps_BIsDlcInstalled.call(@i_apps, app_id) % 256 != 0
  else
    nil
  end
end

- (true, ...) is_subscribed

Checks if current app is owned.

Returns:

  • (true, false, nil)

    Whether the current user has a license for the current app. nil is returned if ownership status can't be retrieved.



140
141
142
143
144
145
146
# File 'steam_user_stats_lite.rb', line 140

def is_subscribed
  if initted?
    @@dll_SteamAPI_ISteamApps_BIsSubscribed.call(@i_apps) % 256 != 0
  else
    nil
  end
end

- (true, false) request_current_stats

Pulls current user's stats from Steam.

Returns:

  • (true, false)

    Whether the stats have been successfully pulled.



163
164
165
166
167
168
169
# File 'steam_user_stats_lite.rb', line 163

def request_current_stats
  if initted?
    @@dll_SteamAPI_ISteamUserStats_RequestCurrentStats.call(@i_user_stats) % 256 != 0
  else
    false
  end
end

- (true, false) reset_all_stats(achievements_too)

Resets all stats.

Parameters:

  • achievements_too (true, false)

    Whether to reset achievements as well.

Returns:

  • (true, false)

    Whether achievements have been reset.



336
337
338
339
340
341
342
343
# File 'steam_user_stats_lite.rb', line 336

def reset_all_stats(achievements_too)
  if initted?
    ok = @@dll_SteamAPI_ISteamUserStats_ResetAllStats.call(@i_user_stats, achievements_too ? 1 : 0) % 256 != 0
    @@dll_SteamAPI_ISteamUserStats_StoreStats.call(@i_user_stats) % 256 != 0 && ok
  else
    false
  end
end

- (true, false) set_achievement(name)

Sets an achievement as unlocked.

Examples:

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

Parameters:

  • name (String)

    The name of the achievement.

Returns:

  • (true, false)

    Whether the achievement was set successfully.



259
260
261
262
263
264
265
266
# File 'steam_user_stats_lite.rb', line 259

def set_achievement(name)
  if initted?
    ok = @@dll_SteamAPI_ISteamUserStats_SetAchievement.call(@i_user_stats, name) % 256 != 0
    @@dll_SteamAPI_ISteamUserStats_StoreStats.call(@i_user_stats) % 256 != 0 && ok
  else
    false
  end
end

- (true, false) set_stat(name, val)

Sets the value of a stat.

Examples:

steam = SteamUserStatsLite.instance
steam.set_stat 'YOUR_STAT_ID_HERE', 100
steam.update

Parameters:

  • name (String)

    The name of the stat.

  • val (Integer, Float)

    The value of the stat.

Returns:

  • (true, false)

    Whether the stat was successfully updated.



208
209
210
211
212
213
214
215
216
217
218
219
# File 'steam_user_stats_lite.rb', line 208

def set_stat(name, val)
  if initted?
    if val.is_a? Float
      ok = @@dll_SteamAPI_ISteamUserStats_SetStat0.call(@i_user_stats, name, self.class.pack_float(val)) % 256 != 0
    else
      ok = @@dll_SteamAPI_ISteamUserStats_SetStat.call(@i_user_stats, name, val.to_i) % 256 != 0
    end
    @@dll_SteamAPI_ISteamUserStats_StoreStats.call(@i_user_stats) % 256 != 0 && ok
  else
    false
  end
end

- (void) shutdown

This method returns an undefined value.

Shuts down Steamworks.



106
107
108
109
110
111
112
113
# File 'steam_user_stats_lite.rb', line 106

def shutdown
  if @initted
    @i_apps = nil
    @i_user_stats = nil
    @@dll_SteamAPI_Shutdown.call
    @initted = false
  end
end

- (void) update

This method returns an undefined value.

Runs Steam callbacks.



133
134
135
# File 'steam_user_stats_lite.rb', line 133

def update
  @@dll_SteamAPI_RunCallbacks.call if initted?
end

- (true, false) update_avg_rate_stat(name, count_this_session, session_length)

Updates an AVGRATE stat.

Parameters:

  • name (String)

    The name of the stat.

  • count_this_session (Float)

    The value during this session.

  • session_length (Float)

    The length of this session.

Returns:

  • (true, false)

    Whether the stat was successfully updated.



227
228
229
230
231
232
233
234
235
# File 'steam_user_stats_lite.rb', line 227

def update_avg_rate_stat(name, count_this_session, session_length)
  if initted?
    packed = self.class.pack_double session_length
    ok = @@dll_SteamAPI_ISteamUserStats_UpdateAvgRateStat.call(@i_user_stats, name, self.class.pack_float(count_this_session.to_f), packed[0], packed[1]) % 256 != 0
    @@dll_SteamAPI_ISteamUserStats_StoreStats.call(@i_user_stats) % 256 != 0 && ok
  else
    false
  end
end