Skip to content

Commit

Permalink
Add CSteamAPI::GetSteam2ID()
Browse files Browse the repository at this point in the history
  • Loading branch information
samisalreadytaken committed Feb 8, 2022
1 parent ee4df55 commit d912643
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions sp/src/game/shared/mapbase/vscript_singletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,9 +1291,6 @@ void CNetMsgScriptHelper::InitPostVM()
{
ScriptVariant_t hHooks;
g_pScriptVM->CreateTable( hHooks );
#if _DEBUG
g_pScriptVM->SetValue( NULL, "__NetMsg_hooks", hHooks );
#endif
m_Hooks = (HSCRIPT)hHooks;
}

Expand Down Expand Up @@ -1356,13 +1353,13 @@ void CNetMsgScriptHelper::ReceiveMessage( bf_read &msg )
if ( g_pScriptVM->ExecuteFunction( hfn, NULL, 0, NULL, NULL, true ) == SCRIPT_ERROR )
#endif
{
DevWarning( 2, DLL_LOC_STR " NetMsg: invalid callback [%d]\n", hash );
DevWarning( 1, DLL_LOC_STR " NetMsg: invalid callback [%d]\n", hash );
}
g_pScriptVM->ReleaseValue( hfn );
}
else
{
DevWarning( 2, DLL_LOC_STR " NetMsg hook not found [%d]\n", hash );
DevWarning( 1, DLL_LOC_STR " NetMsg hook not found [%d]\n", hash );
}
}

Expand Down Expand Up @@ -1416,9 +1413,13 @@ void CNetMsgScriptHelper::Send()
void CNetMsgScriptHelper::Receive( const char *msg, HSCRIPT func )
{
if ( func )
{
g_pScriptVM->SetValue( m_Hooks, int( HashStringCaseless(msg) ), func );
}
else
{
g_pScriptVM->ClearValue( m_Hooks, int( HashStringCaseless(msg) ) );
}
}

#ifdef GAME_DLL
Expand Down Expand Up @@ -3017,6 +3018,23 @@ END_SCRIPTDESC();
class CScriptSteamAPI
{
public:
const char *GetSteam2ID()
{
if ( !steamapicontext || !steamapicontext->SteamUser() )
return NULL;

CSteamID id = steamapicontext->SteamUser()->GetSteamID();

uint32 accountID = id.GetAccountID();
uint32 steamInstanceID = 0;
uint32 high32bits = accountID % 2;
uint32 low32bits = accountID / 2;

static char ret[48];
V_snprintf( ret, sizeof(ret), "STEAM_%u:%u:%u", steamInstanceID, high32bits, low32bits );
return ret;
}

int GetSecondsSinceComputerActive()
{
if ( !steamapicontext || !steamapicontext->SteamUtils() )
Expand All @@ -3032,7 +3050,7 @@ class CScriptSteamAPI

return steamapicontext->SteamUtils()->GetCurrentBatteryPower();
}

#if 0
const char *GetIPCountry()
{
if ( !steamapicontext || !steamapicontext->SteamUtils() )
Expand All @@ -3047,7 +3065,7 @@ class CScriptSteamAPI

return ret;
}

#endif
const char *GetCurrentGameLanguage()
{
if ( !steamapicontext || !steamapicontext->SteamApps() )
Expand All @@ -3066,6 +3084,7 @@ class CScriptSteamAPI
} g_ScriptSteamAPI;

BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptSteamAPI, "CSteamAPI", SCRIPT_SINGLETON "" )
DEFINE_SCRIPTFUNC( GetSteam2ID, "" )
//DEFINE_SCRIPTFUNC( IsVACBanned, "" )
DEFINE_SCRIPTFUNC( GetSecondsSinceComputerActive, "Returns the number of seconds since the user last moved the mouse." )
DEFINE_SCRIPTFUNC( GetCurrentBatteryPower, "Return the amount of battery power left in the current system in % [0..100], 255 for being on AC power" )
Expand Down

0 comments on commit d912643

Please sign in to comment.