Skip to content

Commit

Permalink
Guard against steam not being initialized
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
britzl committed Nov 22, 2023
1 parent 174d664 commit 0a362b4
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 21 deletions.
4 changes: 2 additions & 2 deletions steam/src/steam_apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamApps* g_SteamApps;
static ISteamApps* g_SteamApps = 0;

int SteamApps_Init(lua_State* L)
{
Expand All @@ -19,9 +19,9 @@ int SteamApps_Init(lua_State* L)
*/
int SteamApps_IsDlcInstalled(lua_State* L)
{
if (!g_SteamApps) return 0;
DM_LUA_STACK_CHECK(L, 1);
AppId_t appID = luaL_checknumber(L, 1);
dmLogInfo("SteamApps_IsDlcInstalled %d", appID);
bool installed = g_SteamApps->BIsDlcInstalled(appID);
lua_pushboolean(L, installed);
return 1;
Expand Down
13 changes: 12 additions & 1 deletion steam/src/steam_friends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamFriends* g_SteamFriends;
static ISteamFriends* g_SteamFriends = 0;

int SteamFriends_Init(lua_State* L)
{
Expand All @@ -27,6 +27,7 @@ int SteamFriends_Init(lua_State* L)
*/
int SteamFriends_GetFriendPersonaName(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
CSteamID steamIDFriend = check_uint64(L, 1);
const char* name = g_SteamFriends->GetFriendPersonaName(steamIDFriend);
Expand All @@ -43,6 +44,7 @@ int SteamFriends_GetFriendPersonaName(lua_State* L)
*/
int SteamFriends_GetPersonaName(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
const char* name = g_SteamFriends->GetPersonaName();
lua_pushstring(L, name);
Expand All @@ -56,6 +58,7 @@ int SteamFriends_GetPersonaName(lua_State* L)
*/
int SteamFriends_GetPersonaState(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
EPersonaState e = g_SteamFriends->GetPersonaState();
lua_pushnumber(L, e);
Expand All @@ -74,6 +77,7 @@ int SteamFriends_GetPersonaState(lua_State* L)
*/
int SteamFriends_GetFriendCount(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
int iFriendFlags = luaL_checknumber(L, 1);
int count = g_SteamFriends->GetFriendCount(iFriendFlags);
Expand All @@ -92,6 +96,7 @@ int SteamFriends_GetPersonaState(lua_State* L)
*/
int SteamFriends_GetFriendByIndex(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
int iFriend = luaL_checknumber(L, 1);
int iFriendFlags = luaL_checknumber(L, 2);
Expand All @@ -111,6 +116,7 @@ int SteamFriends_GetFriendByIndex(lua_State* L)
*/
int SteamFriends_GetFriendPersonaState(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
CSteamID steamIDFriend = check_uint64(L, 1);
EPersonaState state = g_SteamFriends->GetFriendPersonaState(steamIDFriend);
Expand All @@ -126,6 +132,7 @@ int SteamFriends_GetFriendPersonaState(lua_State* L)
*/
int SteamFriends_GetFriendSteamLevel(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
CSteamID steamIDFriend = check_uint64(L, 1);
int level = g_SteamFriends->GetFriendSteamLevel(steamIDFriend);
Expand All @@ -141,6 +148,7 @@ int SteamFriends_GetFriendSteamLevel(lua_State* L)
*/
int SteamFriends_GetFriendRelationship(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
CSteamID steamIDFriend = check_uint64(L, 1);
EFriendRelationship relationship = g_SteamFriends->GetFriendRelationship(steamIDFriend);
Expand All @@ -157,6 +165,7 @@ int SteamFriends_GetFriendRelationship(lua_State* L)
*/
int SteamFriends_GetSmallFriendAvatar(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 1);
CSteamID steamIDFriend = check_uint64(L, 1);
int handle = g_SteamFriends->GetSmallFriendAvatar(steamIDFriend);
Expand All @@ -172,6 +181,7 @@ int SteamFriends_GetSmallFriendAvatar(lua_State* L)
*/
int SteamFriends_ActivateGameOverlayToStore(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 0);
AppId_t nAppID = luaL_checknumber(L, 1);
EOverlayToStoreFlag eFlag;
Expand All @@ -194,6 +204,7 @@ int SteamFriends_ActivateGameOverlayToStore(lua_State* L)
*/
int SteamFriends_ActivateGameOverlayToWebPage(lua_State* L)
{
if (!g_SteamFriends) return 0;
DM_LUA_STACK_CHECK(L, 0);
const char *pchURL = luaL_checkstring(L, 1);
EActivateGameOverlayToWebPageMode eMode;
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_game_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamGameSearch* g_SteamGameSearch;
static ISteamGameSearch* g_SteamGameSearch = 0;

int SteamGameSearch_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamInput* g_SteamInput;
static ISteamInput* g_SteamInput = 0;

int SteamInput_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamInventory* g_SteamInventory;
static ISteamInventory* g_SteamInventory = 0;

int SteamInventory_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "steam_types.h"


static dmScript::LuaCallbackInfo* g_SteamListener;
static dmScript::LuaCallbackInfo* g_SteamListener = 0;

void SteamListener_Invoke(int (*fn)(lua_State*, void*), void* data)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_matchmaking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamMatchmaking* g_SteamMatchmaking;
static ISteamMatchmaking* g_SteamMatchmaking = 0;

int SteamMatchmaking_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamMusic* g_SteamMusic;
static ISteamMusic* g_SteamMusic = 0;

int SteamMusic_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_musicremote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamMusicRemote* g_SteamMusicRemote;
static ISteamMusicRemote* g_SteamMusicRemote = 0;

int SteamMusicRemote_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamNetworking* g_SteamNetworking;
static ISteamNetworking* g_SteamNetworking = 0;

int SteamNetworking_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_parties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamParties* g_SteamParties;
static ISteamParties* g_SteamParties = 0;

int SteamParties_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_remotestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamRemoteStorage* g_SteamRemoteStorage;
static ISteamRemoteStorage* g_SteamRemoteStorage = 0;

int SteamRemoteStorage_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_screenshots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamScreenshots* g_SteamScreenshots;
static ISteamScreenshots* g_SteamScreenshots = 0;

int SteamScreenshots_Init(lua_State* L)
{
Expand Down
2 changes: 1 addition & 1 deletion steam/src/steam_ugc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamUGC* g_SteamUGC;
static ISteamUGC* g_SteamUGC = 0;

int SteamUGC_Init(lua_State* L)
{
Expand Down
11 changes: 10 additions & 1 deletion steam/src/steam_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "steam_api.h"
#include "steam_types.h"

static ISteamUser* g_SteamUser;
static ISteamUser* g_SteamUser = 0;


int SteamUser_Init(lua_State* L)
Expand All @@ -21,6 +21,7 @@ int SteamUser_Init(lua_State* L)
*/
int SteamUser_GetSteamId(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
push_CSteamID(L, g_SteamUser->GetSteamID());
return 1;
Expand All @@ -32,6 +33,7 @@ int SteamUser_GetSteamId(lua_State* L)
*/
int SteamUser_GetPlayerSteamLevel(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushnumber(L, g_SteamUser->GetPlayerSteamLevel());
return 1;
Expand All @@ -47,6 +49,7 @@ int SteamUser_GetPlayerSteamLevel(lua_State* L)
*/
int SteamUser_GetGameBadgeLevel(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
int series = luaL_checknumber(L, 1);
bool foil = lua_toboolean(L, 2);
Expand All @@ -61,6 +64,7 @@ int SteamUser_GetGameBadgeLevel(lua_State* L)
*/
int SteamUser_LoggedOn(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BLoggedOn());
return 1;
Expand All @@ -73,6 +77,7 @@ int SteamUser_LoggedOn(lua_State* L)
*/
int SteamUser_IsBehindNAT(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BIsBehindNAT());
return 1;
Expand All @@ -84,6 +89,7 @@ int SteamUser_IsBehindNAT(lua_State* L)
*/
int SteamUser_IsPhoneVerified(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BIsPhoneVerified());
return 1;
Expand All @@ -95,6 +101,7 @@ int SteamUser_IsPhoneVerified(lua_State* L)
*/
int SteamUser_IsPhoneIdentifying(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BIsPhoneIdentifying());
return 1;
Expand All @@ -106,6 +113,7 @@ int SteamUser_IsPhoneIdentifying(lua_State* L)
*/
int SteamUser_IsPhoneRequiringVerification(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BIsPhoneRequiringVerification());
return 1;
Expand All @@ -117,6 +125,7 @@ int SteamUser_IsPhoneRequiringVerification(lua_State* L)
*/
int SteamUser_IsTwoFactorEnabled(lua_State* L)
{
if (!g_SteamUser) return 0;
DM_LUA_STACK_CHECK(L, 1);
lua_pushboolean(L, g_SteamUser->BIsTwoFactorEnabled());
return 1;
Expand Down
Loading

0 comments on commit 0a362b4

Please sign in to comment.