sync fwk
parent
d4a5fdcf46
commit
ba6aacaf5b
|
@ -0,0 +1,24 @@
|
|||
// steamworks demo
|
||||
// - rlyeh, public domain
|
||||
|
||||
#include "v4k.h"
|
||||
|
||||
main() {
|
||||
window_create(0.75, 0);
|
||||
|
||||
steam_init(0); // steam_appid: 0 to use SpaceWar vanilla project from Valve
|
||||
|
||||
while( window_swap() ) {
|
||||
steam_tick();
|
||||
|
||||
if( ui_panel("Steam", PANEL_OPEN) ) {
|
||||
ui_steam();
|
||||
|
||||
if( ui_button("Clear trophy") ) steam_trophy("ACH_TRAVEL_FAR_ACCUM", 0);
|
||||
if( ui_button("Redeem trophy") ) steam_trophy("ACH_TRAVEL_FAR_ACCUM", 1);
|
||||
if( ui_button("Submit Screenshot") ) steam_screenshot();
|
||||
|
||||
ui_panel_end();
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -152,6 +152,8 @@
|
|||
|
||||
{{FILE:v4k_sprite.c}}
|
||||
|
||||
{{FILE:v4k_steam.c}}
|
||||
|
||||
{{FILE:v4k_system.c}}
|
||||
|
||||
{{FILE:v4k_time.c}}
|
||||
|
|
|
@ -147,6 +147,8 @@ extern "C" {
|
|||
{{FILE:v4k_sprite.h}}
|
||||
{{FILE:v4k_gui.h}}
|
||||
|
||||
{{FILE:v4k_steam.h}}
|
||||
|
||||
{{FILE:v4k_system.h}}
|
||||
|
||||
{{FILE:v4k_time.h}}
|
||||
|
|
|
@ -221,4 +221,6 @@ static char *ui_filter = 0;
|
|||
//#define LM_DEBUG_INTERPOLATION
|
||||
{{FILE:3rd_lightmapper.h}}
|
||||
|
||||
{{FILE:3rd_sdk_steam.h}}
|
||||
|
||||
#endif // V4K_3RD
|
||||
|
|
3118
engine/v4k
3118
engine/v4k
File diff suppressed because it is too large
Load Diff
192
engine/v4k.c
192
engine/v4k.c
|
@ -23950,6 +23950,198 @@ AUTORUN {
|
|||
}
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_steam.c"
|
||||
// ----------------------------------------------------------------------------
|
||||
// steam framework
|
||||
// - rlyeh, public domain
|
||||
//
|
||||
// hints:
|
||||
// - steam must be running in background
|
||||
// - steamworks dll must be close to executable (may be "steam_api64.dll", "libsteam_api.dylib" or "libsteam_api.so")
|
||||
// - family mode should be off (achievements not displayed otherwise)
|
||||
//
|
||||
// [src] https://steamdb.info/app/480/
|
||||
// [src] https://steamdb.info/app/480/stats/
|
||||
// [src] https://partner.steamgames.com/doc/
|
||||
// [src] dumpbin /exports steam_api64.dll
|
||||
|
||||
#ifndef STEAM_APPID
|
||||
#define STEAM_APPID 480
|
||||
#endif
|
||||
|
||||
#ifndef STEAM_DLL
|
||||
#define STEAM_DLL ifdef(win32, "steam_api64.dll", "libsteam_api" ifdef(osx, ".dylib", ".so"))
|
||||
#endif
|
||||
|
||||
#define STEAM_API_DECL(ret,name,args) API ret (*name) args;
|
||||
#define STEAM_API_DEFN(ret,name,args) ret (*name) args;
|
||||
#define STEAM_API_LOAD(ret,name,args) name = dll(STEAM_DLL, #name); if(!name) PRINTF("Cannot load `" STEAM_DLL "@%s`\n", #name);
|
||||
|
||||
STEAM_API(STEAM_API_DECL);
|
||||
STEAM_API(STEAM_API_DEFN);
|
||||
|
||||
struct steam_t {
|
||||
intptr_t iclient;
|
||||
intptr_t iapps;
|
||||
intptr_t ifriends;
|
||||
intptr_t ihtmlsurface;
|
||||
intptr_t imatchmaking;
|
||||
intptr_t imatchmakingservers;
|
||||
intptr_t inetworking;
|
||||
intptr_t iremoteplay;
|
||||
intptr_t iremotestorage;
|
||||
intptr_t iscreenshots;
|
||||
intptr_t iuser;
|
||||
intptr_t iuserstats;
|
||||
intptr_t iutils;
|
||||
uint64_t steamid;
|
||||
|
||||
int num_friends;
|
||||
bool running, overlay;
|
||||
bool logged, behindnat;
|
||||
char status[256], username[256], language[32];
|
||||
} steam = {0};
|
||||
|
||||
static
|
||||
void steam_message_cb(int severity, const char *message) {
|
||||
/**/ if( severity == 0 ) printf("%s", message);
|
||||
else if( severity == 1 ) printf("Warning: %s", message);
|
||||
else printf("Unknown severity %d: %s", severity, message);
|
||||
}
|
||||
|
||||
bool steam_init(unsigned app_id) {
|
||||
struct steam_t z = {0};
|
||||
steam = z;
|
||||
|
||||
app_id = app_id ? app_id : STEAM_APPID;
|
||||
|
||||
// Steam installed?
|
||||
HKEY hSteamProcess;
|
||||
if( RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Valve\\Steam\\ActiveProcess", 0, KEY_READ, &hSteamProcess) ) {
|
||||
return !strcpy(steam.status, "Err: steam not installed");
|
||||
}
|
||||
RegCloseKey(hSteamProcess);
|
||||
|
||||
// dll present?
|
||||
if( !file_exist(STEAM_DLL) ) {
|
||||
return !strcpy(steam.status, "Err: " STEAM_DLL " not found");
|
||||
}
|
||||
|
||||
// Load symbols
|
||||
STEAM_API(STEAM_API_LOAD);
|
||||
if( !SteamAPI_Init ) SteamAPI_Init = SteamAPI_InitSafe;
|
||||
|
||||
// Initialize
|
||||
char *app_id_str = va("%d", app_id);
|
||||
//if( !file_exist("steam_appid.txt") ) file_write("steam_appid.txt", app_id_str, strlen(app_id_str));
|
||||
if( !getenv("SteamAppId") ) SetEnvironmentVariableA("SteamAppId", app_id_str);
|
||||
|
||||
int started = SteamAPI_Init && SteamAPI_Init();
|
||||
if( !started ) {
|
||||
return !strcpy(steam.status, "Err: steam not running");
|
||||
}
|
||||
|
||||
SteamAPI_RestartAppIfNecessary(app_id);
|
||||
|
||||
// Create interfaces
|
||||
steam.iclient = (intptr_t)SteamInternal_CreateInterface("SteamClient020");
|
||||
if( !steam.iclient ) {
|
||||
return !strcpy(steam.status, "Err: incompatible dll");
|
||||
}
|
||||
|
||||
HSteamPipe hpipe = SteamAPI_ISteamClient_CreateSteamPipe(steam.iclient);
|
||||
HSteamUser huser = SteamAPI_ISteamClient_ConnectToGlobalUser(steam.iclient, hpipe);
|
||||
|
||||
steam.iapps = (intptr_t)SteamAPI_ISteamClient_GetISteamApps(steam.iclient, huser, hpipe, "STEAMAPPS_INTERFACE_VERSION008");
|
||||
steam.ifriends = (intptr_t)SteamAPI_ISteamClient_GetISteamFriends(steam.iclient, huser, hpipe, "SteamFriends017"); // 015
|
||||
steam.ihtmlsurface = (intptr_t)SteamAPI_ISteamClient_GetISteamHTMLSurface(steam.iclient, huser, hpipe, "STEAMHTMLSURFACE_INTERFACE_VERSION_005");
|
||||
steam.imatchmaking = (intptr_t)SteamAPI_ISteamClient_GetISteamMatchmaking(steam.iclient, huser, hpipe, "SteamMatchMaking009");
|
||||
steam.imatchmakingservers = (intptr_t)SteamAPI_ISteamClient_GetISteamMatchmakingServers(steam.iclient, huser, hpipe, "SteamMatchMakingServers002");
|
||||
steam.inetworking = (intptr_t)SteamAPI_ISteamClient_GetISteamNetworking(steam.iclient, huser, hpipe, "SteamNetworking006");
|
||||
//steam.iremoteplay = (intptr_t)SteamAPI_ISteamClient_GetISteamRemotePlay(steam.iclient, huser, hpipe, "STEAMREMOTEPLAY_INTERFACE_VERSION001");
|
||||
steam.iremotestorage = (intptr_t)SteamAPI_ISteamClient_GetISteamRemoteStorage(steam.iclient, huser, hpipe, "STEAMREMOTESTORAGE_INTERFACE_VERSION014");
|
||||
steam.iscreenshots = (intptr_t)SteamAPI_ISteamClient_GetISteamScreenshots(steam.iclient, huser, hpipe, "STEAMSCREENSHOTS_INTERFACE_VERSION003");
|
||||
steam.iuser = (intptr_t)SteamAPI_ISteamClient_GetISteamUser(steam.iclient, huser, hpipe, "SteamUser021"); // 019
|
||||
steam.iuserstats = (intptr_t)SteamAPI_ISteamClient_GetISteamUserStats(steam.iclient, huser, hpipe, "STEAMUSERSTATS_INTERFACE_VERSION012");
|
||||
steam.iutils = (intptr_t)SteamAPI_ISteamClient_GetISteamUtils(steam.iclient, hpipe, "SteamUtils010");
|
||||
|
||||
SteamAPI_ISteamClient_SetWarningMessageHook(steam.iclient, steam_message_cb);
|
||||
|
||||
// Retrieve some vars
|
||||
steam.running = SteamAPI_IsSteamRunning();
|
||||
steam.steamid = SteamAPI_ISteamUser_GetSteamID(steam.iuser);
|
||||
steam.logged = SteamAPI_ISteamUser_BLoggedOn(steam.iuser);
|
||||
steam.behindnat = SteamAPI_ISteamUser_BIsBehindNAT(steam.iuser);
|
||||
steam.num_friends = SteamAPI_ISteamFriends_GetFriendCount(steam.ifriends, k_EFriendFlagAll);
|
||||
strncpy(steam.username, SteamAPI_ISteamFriends_GetPersonaName(steam.ifriends), sizeof(steam.username));
|
||||
strncpy(steam.language, SteamAPI_ISteamUtils_GetSteamUILanguage(steam.iutils), sizeof(steam.language)); // SteamAPI_ISteamApps_GetCurrentGameLanguage(steam.iapps)
|
||||
|
||||
if(steam.logged)
|
||||
SteamAPI_ISteamUserStats_RequestCurrentStats(steam.iuserstats);
|
||||
|
||||
ASSERT(steam.iapps);
|
||||
ASSERT(steam.ifriends);
|
||||
ASSERT(steam.ihtmlsurface);
|
||||
ASSERT(steam.imatchmaking);
|
||||
ASSERT(steam.imatchmakingservers);
|
||||
ASSERT(steam.inetworking);
|
||||
// ASSERT(steam.iremoteplay);
|
||||
ASSERT(steam.iremotestorage);
|
||||
ASSERT(steam.iscreenshots);
|
||||
ASSERT(steam.iuser);
|
||||
ASSERT(steam.iuserstats);
|
||||
ASSERT(steam.iutils);
|
||||
|
||||
strcpy(steam.status, "Ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
void steam_tick() {
|
||||
if( steam.iclient ) {
|
||||
SteamAPI_RunCallbacks();
|
||||
steam.overlay = SteamAPI_ISteamUtils_IsOverlayEnabled(steam.iutils);
|
||||
}
|
||||
}
|
||||
|
||||
void steam_trophy(const char *trophy_id, bool redeem) {
|
||||
if( steam.iclient && steam.logged ) {
|
||||
if( redeem )
|
||||
SteamAPI_ISteamUserStats_SetAchievement(steam.iuserstats, trophy_id);
|
||||
else
|
||||
SteamAPI_ISteamUserStats_ClearAchievement(steam.iuserstats, trophy_id);
|
||||
SteamAPI_ISteamUserStats_StoreStats(steam.iuserstats);
|
||||
}
|
||||
}
|
||||
|
||||
void steam_screenshot() {
|
||||
if( steam.iclient ) {
|
||||
SteamAPI_ISteamScreenshots_TriggerScreenshot(steam.iscreenshots);
|
||||
}
|
||||
}
|
||||
|
||||
void steam_destroy() {
|
||||
if( steam.iclient ) {
|
||||
steam.iclient = 0;
|
||||
SteamAPI_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
int ui_steam() {
|
||||
ui_disable();
|
||||
|
||||
ui_label2("Status", steam.status);
|
||||
ui_label2("Username", steam.username);
|
||||
ui_label2("Language", steam.language);
|
||||
ui_label2("Friends", va("%d", steam.num_friends));
|
||||
ui_label2("SteamID", va("%llu", steam.steamid));
|
||||
ui_bool("Overlay?", &steam.overlay);
|
||||
|
||||
ui_enable();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_system.c"
|
||||
#if (is(tcc) && is(linux)) || (is(gcc) && !is(mingw)) // || is(clang)
|
||||
int __argc; char **__argv;
|
||||
|
|
16
engine/v4k.h
16
engine/v4k.h
|
@ -2002,6 +2002,9 @@ API void script_call(const char *lua_function);
|
|||
|
||||
API bool script_tests();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// script framework
|
||||
|
||||
enum {
|
||||
SCRIPT_LUA = 1,
|
||||
SCRIPT_DEBUGGER = 2,
|
||||
|
@ -4286,6 +4289,19 @@ typedef struct skinned_t {
|
|||
API guiskin_t gui_skinned(const char *asefile, float scale);
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_steam.h"
|
||||
// ----------------------------------------------------------------------------
|
||||
// steam framework
|
||||
|
||||
API bool steam_init(unsigned app_id);
|
||||
API void steam_tick();
|
||||
API void steam_trophy(const char *trophy_id, bool redeem);
|
||||
API void steam_screenshot();
|
||||
API void steam_destroy();
|
||||
|
||||
API int ui_steam();
|
||||
#line 0
|
||||
|
||||
#line 1 "v4k_system.h"
|
||||
// -----------------------------------------------------------------------------
|
||||
// system framework utils
|
||||
|
|
Loading…
Reference in New Issue