Last active
March 20, 2016 09:33
-
-
Save jonongjs/57666f3900839cf734d4 to your computer and use it in GitHub Desktop.
Native Steam integration in Haxe, FRESteamWorks-style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<project> | |
<section> <!-- release flags --> | |
<!-- <set name="steam" /> (Steam build) set this when making a steam release --> | |
</section> | |
<!-- NMML reference: https://gist.github.com/1763850 --> | |
<!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) --> | |
<meta title="Spacejacked" package="com.rottenmage.spacejacked" version="1.0.3" company="Rotten Mage" /> | |
<haxedef name="VERSION_LABEL" value="v1.0.3" /> | |
<!-- output --> | |
<app main="Main" file="SPACEJACKED" preloader="CustomPreloader" path="bin" swf-version="11.8" /> | |
<window background="#000000" fps="60" /> | |
<window width="960" height="540" unless="mobile" /> | |
<window hardware="true" allow-shaders="true" if="cpp"/> | |
<window orientation="landscape" vsync="true" antialiasing="0" if="cpp" /> | |
<!-- classpath, haxe libs --> | |
<source path="src" /> | |
<!-- assets --> | |
<icon path="assets/icon_slimeball.png" /> | |
<assets path="assets/img" include="*.png" /> | |
<!-- Steam-related templates and defines --> | |
<section if="steam"> | |
<haxedef name="steam" /> <!-- for conditional compilation --> | |
<section if="mac"> | |
<source path="src/linux_steam" if="mac" /> | |
<template path="thirdparty/steamsdk/lib/Mac64/libsteam_api.dylib" rename="bin/SPACEJACKED.app/Contents/MacOS/libsteam_api.dylib" /> | |
</section> | |
<section if="linux"> | |
<source path="src/linux_steam" if="linux" /> | |
<template path="thirdparty/steamsdk/lib/Linux/libsteam_api.so" rename="libsteam_api.so" unless="HXCPP_M64" /> | |
<template path="thirdparty/steamsdk/lib/Linux64/libsteam_api.so" rename="libsteam_api.so" if="HXCPP_M64" /> | |
</section> | |
<section if="flash"> | |
<haxeflag name="-swf-lib" value="thirdparty/ventero/FRESteamWorks.ane" /> | |
</section> | |
</section> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spacejacked/ | |
├── Makefile | |
├── application.xml | |
├── assets/ | |
├── bin/ | |
├── src/ | |
| ... | |
│ ├── linux_steam/ | |
│ │ └── com/ | |
│ │ └── amanitadesign/ | |
│ │ └── steam/ | |
│ │ ├── DownloadUGCResult.hx | |
│ │ ├── FRESteamWorks.hx | |
│ │ ├── FileDetailsResult.hx | |
│ │ ├── FilesByUserActionResult.hx | |
│ │ ├── ItemVoteDetailsResult.hx | |
│ │ ├── LeaderboardEntry.hx | |
│ │ ├── MicroTxnAuthorizationResponse.hx | |
│ │ ├── SteamConstants.hx | |
│ │ ├── SteamEvent.hx | |
│ │ ├── SteamResults.hx | |
│ │ ├── SubscribedFilesResult.hx | |
│ │ ├── UploadLeaderboardScoreResult.hx | |
│ │ ├── UserFilesResult.hx | |
│ │ ├── UserStatsConstants.hx | |
│ │ ├── UserVoteDetails.hx | |
│ │ ├── UtilsConstants.hx | |
│ │ └── WorkshopFilesResult.hx | |
| ... | |
└── thirdparty/ | |
├── steamsdk/ | |
│ ├── include/ | |
│ │ └── steam/ | |
│ │ ... | |
│ └── lib/ | |
│ ├── Linux/ | |
│ │ └── libsteam_api.so | |
│ ├── Linux64/ | |
│ │ └── libsteam_api.so | |
│ └── Mac64/ | |
│ └── libsteam_api.dylib | |
└── ventero/ | |
└── src/ | |
├── CSteam/ | |
│ ├── CSteam.cpp | |
│ ├── CSteam.h | |
│ └── ResponseTypes.h | |
└── HxSteamWorks/ | |
├── HxSteamWorks.cpp | |
└── HxSteamWorks.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.amanitadesign.steam; | |
/* | |
* Adapted from FRESteamWorks (https://github.com/Ventero/FRESteamWorks). | |
* TODO: refactor by implementing with @:native instead. | |
* Original copyright notices below. | |
* | |
* Created by Ventero <http://github.com/Ventero> | |
* Copyright (c) 2012-2013 Level Up Labs, LLC. All rights reserved. | |
*/ | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
import flash.events.IEventDispatcher; | |
import flash.utils.ByteArray; | |
import haxe.Timer; | |
@:buildXml(" | |
<files id='haxe'> | |
<compilerflag value='-I../../../../thirdparty/steamsdk/include/' /> | |
<compilerflag value='-I../../../../thirdparty/ventero/src/' /> | |
<compilerflag value='-I../../../../thirdparty/ventero/src/HxSteamWorks' /> | |
<compilerflag value='-std=c++11' /> | |
<compilerflag value='-DVERSION_SAFE_STEAM_API_INTERFACES' /> | |
<compilerflag value='-DUSE_BREAKPAD_HANDLER' /> | |
<file name='../../../../thirdparty/ventero/src/CSteam/CSteam.cpp'/> | |
<file name='../../../../thirdparty/ventero/src/HxSteamWorks/HxSteamWorks.cpp'/> | |
</files> | |
<target id='haxe'> | |
<section if='linux'> | |
<lib name='../../../../thirdparty/steamsdk/lib/Linux/libsteam_api.so' unless='HXCPP_M64'/> | |
<lib name='../../../../thirdparty/steamsdk/lib/Linux64/libsteam_api.so' if='HXCPP_M64'/> | |
<flag value='-static-libstdc++' /> | |
<flag value='-static-libgcc' /> | |
</section> | |
<section if='mac'> | |
<lib name='../../../../thirdparty/steamsdk/lib/Mac64/libsteam_api.dylib' /> | |
<flag value='-mmacosx-version-min=10.7' /> | |
</section> | |
</target> | |
") | |
@:cppFileCode(" | |
#include <HxSteamWorks/HxSteamWorks.h> | |
") | |
class FRESteamWorks extends EventDispatcher /* implements ISteamWorks */ | |
{ | |
//// INTERNAL USE //// | |
private static var _instance:FRESteamWorks; | |
public static function dispatch(code:String, level:String):Void { | |
if (_instance != null) { | |
var req_type:Int = Std.parseInt(code); | |
var response:Int = Std.parseInt(level); | |
var sEvent:SteamEvent = new SteamEvent(SteamEvent.STEAM_RESPONSE, req_type, response); | |
_instance.dispatchEvent(sEvent); | |
} | |
} | |
//// END //// | |
private var _timer:Timer; | |
public var isReady:Bool = false; | |
public function new(target:IEventDispatcher=null) { | |
super(target); | |
_instance = this; | |
} | |
public function dispose():Void { | |
untyped __cpp__("HxSteam_Dispose()"); | |
if (_timer != null) { | |
_timer.stop(); | |
_timer = null; | |
} | |
_instance = null; | |
} | |
public function init():Bool { | |
isReady = untyped __cpp__("HxSteam_Init()"); | |
if (isReady) { | |
_timer = new Timer(100); | |
_timer.run = runCallbacks; | |
} | |
return isReady; | |
} | |
/********************************/ | |
/* General Steamworks functions */ | |
/********************************/ | |
public function runCallbacks():Void { | |
untyped __cpp__("HxSteam_RunCallbacks()"); | |
} | |
public function getUserID():String { | |
return new String(untyped __cpp__("uint64ToStr(HxSteam_GetUserID()).c_str()")); | |
} | |
public function getAppID():UInt { | |
return untyped __cpp__("HxSteam_GetAppID()"); | |
} | |
public function getAvailableGameLanguages():String { | |
return new String(untyped __cpp__("HxSteam_GetAvailableGameLanguages().c_str()")); | |
} | |
public function getCurrentGameLanguage():String { | |
return new String(untyped __cpp__("HxSteam_GetCurrentGameLanguage().c_str()")); | |
} | |
public function getPersonaName():String { | |
return new String(untyped __cpp__("HxSteam_GetPersonaName().c_str()")); | |
} | |
public function restartAppIfNecessary(appID:UInt):Bool { | |
return untyped __cpp__("HxSteam_RestartAppIfNecessary(appID)"); | |
} | |
/************************/ | |
/* Stats / Achievements */ | |
/************************/ | |
public function requestStats():Bool { | |
return untyped __cpp__("HxSteam_RequestStats()"); | |
} | |
public function setAchievement(name:String):Bool { | |
return untyped __cpp__("HxSteam_SetAchievement(name)"); | |
} | |
public function clearAchievement(name:String):Bool { | |
return untyped __cpp__("HxSteam_ClearAchievement(name)"); | |
} | |
public function isAchievement(name:String):Bool { | |
return untyped __cpp__("HxSteam_IsAchievement(name)"); | |
} | |
public function getStatInt(name:String):Int { | |
return untyped __cpp__("HxSteam_GetStatInt(name)"); | |
} | |
public function getStatFloat(name:String):Float { | |
return untyped __cpp__("HxSteam_GetStatFloat(name)"); | |
} | |
public function setStatInt(name:String, value:Int):Bool { | |
return untyped __cpp__("HxSteam_SetStatInt(name, value)"); | |
} | |
public function setStatFloat(name:String, value:Float):Bool { | |
return untyped __cpp__("HxSteam_SetStatFloat(name, value)"); | |
} | |
public function storeStats():Bool { | |
return untyped __cpp__("HxSteam_StoreStats()"); | |
} | |
public function resetAllStats(achievementsToo:Bool):Bool { | |
return untyped __cpp__("HxSteam_ResetAllStats(achievementsToo)"); | |
} | |
public function requestGlobalStats(historyDays:Int):Bool { | |
return untyped __cpp__("HxSteam_RequestGlobalStats(historyDays)"); | |
} | |
public function getGlobalStatInt(name:String):Float { | |
return untyped __cpp__("HxSteam_GetGlobalStatInt(name)"); | |
} | |
public function getGlobalStatFloat(name:String):Float { | |
return untyped __cpp__("HxSteam_GetGlobalStatFloat(name)"); | |
} | |
/****************/ | |
/* Leaderboards */ | |
/****************/ | |
public function findLeaderboard(name:String):Bool { | |
return untyped __cpp__("HxSteam_FindLeaderboard(name)"); | |
} | |
public function findOrCreateLeaderboard(name:String, sortMethod:UInt, displayType:UInt):Bool { | |
return untyped __cpp__("HxSteam_FindOrCreateLeaderboard(name, sortMethod, displayType)"); | |
} | |
public function findLeaderboardResult():String { | |
return new String(untyped __cpp__("uint64ToStr(HxSteam_FindLeaderboardResult()).c_str()")); | |
} | |
public function getLeaderboardName(handle:String):String { | |
return new String(untyped __cpp__("HxSteam_GetLeaderboardName(parseUint64(handle)).c_str()")); | |
} | |
public function getLeaderboardEntryCount(handle:String):Int { | |
return untyped __cpp__("HxSteam_GetLeaderboardEntryCount(parseUint64(handle))"); | |
} | |
public function getLeaderboardSortMethod(handle:String):UInt { | |
return untyped __cpp__("HxSteam_GetLeaderboardSortMethod(parseUint64(handle))"); | |
} | |
public function getLeaderboardDisplayType(handle:String):UInt { | |
return untyped __cpp__("HxSteam_GetLeaderboardDisplayType(parseUint64(handle))"); | |
} | |
public function uploadLeaderboardScore(handle:String, method:UInt, score:Int, details:Array<Int> = null):Bool { | |
untyped __cpp__("std::vector<int32> v"); | |
for (detail in details) { | |
untyped __cpp__("v.push_back(detail)"); | |
} | |
return untyped __cpp__("HxSteam_UploadLeaderboardScore(parseUint64(handle), method, score, v)"); | |
} | |
public function uploadLeaderboardScoreResult():UploadLeaderboardScoreResult { | |
var result = new UploadLeaderboardScoreResult(); | |
untyped __cpp__("auto details = HxSteam_UploadLeaderboardScoreResult()"); | |
var isNull:Bool = untyped __cpp__("details == nullptr"); | |
if (isNull) | |
return result; | |
result.success = untyped __cpp__("details->m_bSuccess != 0"); | |
result.leaderboardHandle = new String(untyped __cpp__("uint64ToStr(details->m_hSteamLeaderboard).c_str()")); | |
result.score = untyped __cpp__("details->m_nScore"); | |
result.scoreChanged = untyped __cpp__("details->m_bScoreChanged != 0"); | |
result.newGlobalRank = untyped __cpp__("details->m_nGlobalRankNew"); | |
result.previousGlobalRank = untyped __cpp__("details->m_nGlobalRankPrevious"); | |
return result; | |
} | |
public function downloadLeaderboardEntries(handle:String, request:UInt = UserStatsConstants.DATAREQUEST_GlobalAroundUser, rangeStart:Int = -4, rangeEnd:Int = 5):Bool { | |
return untyped __cpp__("HxSteam_DownloadLeaderboardEntries(parseUint64(handle), request, rangeStart, rangeEnd)"); | |
} | |
public function downloadLeaderboardEntriesResult(numDetails:Int = 0):Array<LeaderboardEntry> { | |
untyped __cpp__("auto entries = HxSteam_DownloadLeaderboardEntriesResult(numDetails)"); | |
var result = new Array<LeaderboardEntry>(); | |
var len:Int = untyped __cpp__("entries.size()"); | |
for (i in 0...len) { | |
untyped __cpp__("auto e = &entries[i].entry"); | |
var entry = new LeaderboardEntry(); | |
result.push(entry); | |
entry.userID = new String(untyped __cpp__("uint64ToStr(e->m_steamIDUser.ConvertToUint64()).c_str()")); | |
entry.globalRank = untyped __cpp__("e->m_nGlobalRank"); | |
entry.score = untyped __cpp__("e->m_nScore"); | |
entry.numDetails = untyped __cpp__("e->m_cDetails"); | |
entry.details = new Array(); | |
var dets = entry.numDetails; | |
if (numDetails < dets) dets = numDetails; | |
for (d in 0...dets) { | |
entry.details.push(untyped __cpp__("entries[i].details[d]")); | |
} | |
} | |
return result; | |
} | |
/**************************/ | |
/* Cloud / Remote Storage */ | |
/**************************/ | |
public function getFileCount():Int { | |
return untyped __cpp__("HxSteam_GetFileCount()"); | |
} | |
public function getFileSize(name:String):Int { | |
return untyped __cpp__("HxSteam_GetFileSize(name)"); | |
} | |
public function fileExists(name:String):Bool { | |
return untyped __cpp__("HxSteam_FileExists(name)"); | |
} | |
public function fileWrite(name:String, data:ByteArray):Bool { | |
return untyped __cpp__("HxSteam_FileWrite(name, data)"); | |
} | |
public function fileRead(name:String, data:ByteArray):Bool { | |
return untyped __cpp__("HxSteam_FileRead(name, data)"); | |
} | |
public function fileDelete(name:String):Bool { | |
return untyped __cpp__("HxSteam_FileDelete(name)"); | |
} | |
/***********/ | |
/* Friends */ | |
/***********/ | |
public function getFriendCount(flags:UInt):Int { | |
return untyped __cpp__("HxSteam_GetFriendCount(flags)"); | |
} | |
public function getFriendByIndex(index:Int, flags:UInt):String { | |
return new String(untyped __cpp__("uint64ToStr(HxSteam_GetFriendByIndex(index, flags)).c_str()")); | |
} | |
public function getFriendPersonaName(id:String):String { | |
return new String(untyped __cpp__("HxSteam_GetFriendPersonaName(parseUint64(id)).c_str()")); | |
} | |
/***********/ | |
/* Overlay */ | |
/***********/ | |
public function setOverlayNotificationPosition(position:UInt):Bool { | |
return untyped __cpp__("HxSteam_SetOverlayNotificationPosition(position)"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* HxSteamWorks.cpp | |
* Adapted from FRESteamWorks.cpp | |
* | |
* FRESteamWorks.cpp copyrights below. | |
* | |
* Created by David ´Oldes´ Oliva on 3/29/12. | |
* Contributors: Ventero <http://github.com/Ventero> | |
* Copyright (c) 2012 Amanita Design. All rights reserved. | |
* Copyright (c) 2012-2013 Level Up Labs, LLC. All rights reserved. | |
*/ | |
#include "HxSteamWorks.h" | |
#include "com/amanitadesign/steam/FRESteamWorks.h" | |
#include <cstdlib> | |
#include <sstream> | |
// Global access to Steam object | |
CSteam* g_Steam = NULL; | |
#ifdef DEBUG | |
#include <iostream> | |
void steamWarningMessageHook(int severity, const char* msg) { | |
std::cerr << "Severity " << severity << ": " << msg << std::endl; | |
} | |
#else | |
void steamWarningMessageHook(int severity, const char* msg) { | |
// ignore silently | |
} | |
#endif | |
uint64 parseUint64(const char *str) { | |
return std::strtoull(str, nullptr, 10); | |
} | |
std::string uint64ToStr(uint64 val) { | |
std::stringstream stream; | |
stream << val; | |
return stream.str(); | |
} | |
void HxSteam::DispatchEvent(char* code, char* level) { | |
::com::amanitadesign::steam::FRESteamWorks_obj::dispatch(String(code), String(level)); | |
} | |
/* | |
* general functions | |
*/ | |
bool HxSteam_Init() { | |
// check if already initialized | |
if (g_Steam) return true; | |
g_Steam = new HxSteam(); | |
if (!g_Steam->Initialize()) { | |
delete g_Steam; | |
g_Steam = nullptr; | |
return false; | |
} | |
#ifdef DEBUG | |
g_Steam->SetWarningMessageHook(steamWarningMessageHook); | |
#endif | |
return true; | |
} | |
void HxSteam_Dispose() { | |
// Shutdown Steam | |
SteamAPI_Shutdown(); | |
// Delete the SteamAchievements object | |
delete g_Steam; | |
g_Steam = nullptr; | |
} | |
bool HxSteam_RunCallbacks() { | |
SteamAPI_RunCallbacks(); | |
return true; | |
} | |
uint64_t HxSteam_GetUserID() { | |
if (!g_Steam) return 0; | |
return g_Steam->GetUserID().ConvertToUint64(); | |
} | |
uint32 HxSteam_GetAppID() { | |
if (!g_Steam) return 0; | |
return g_Steam->GetAppID(); | |
} | |
std::string HxSteam_GetAvailableGameLanguages() { | |
if (!g_Steam) return ""; | |
return g_Steam->GetAvailableGameLanguages(); | |
} | |
std::string HxSteam_GetCurrentGameLanguage() { | |
if (!g_Steam) return ""; | |
return g_Steam->GetCurrentGameLanguage(); | |
} | |
std::string HxSteam_GetPersonaName() { | |
if (!g_Steam) return ""; | |
return g_Steam->GetPersonaName(); | |
} | |
bool HxSteam_RestartAppIfNecessary(uint32 appID) { | |
return SteamAPI_RestartAppIfNecessary(appID); | |
} | |
/* | |
* stats / achievements | |
*/ | |
bool HxSteam_RequestStats() { | |
bool ret = false; | |
if (g_Steam) ret = g_Steam->RequestStats(); | |
SteamAPI_RunCallbacks(); | |
return ret; | |
} | |
bool HxSteam_SetAchievement(const char *name) { | |
bool ret = g_Steam->SetAchievement(name); | |
SteamAPI_RunCallbacks(); | |
return ret; | |
} | |
bool HxSteam_ClearAchievement(const char *name) { | |
if (!g_Steam) return false; | |
return g_Steam->ClearAchievement(name); | |
} | |
bool HxSteam_IsAchievement(const char *name) { | |
if (!g_Steam) return false; | |
return g_Steam->IsAchievement(name); | |
} | |
bool HxSteam_IndicateAchievementProgress(const char *name, uint32 current_progress, uint32 max_progress) { | |
if (!g_Steam) return false; | |
return g_Steam->IndicateAchievementProgress(name, | |
current_progress, max_progress); | |
} | |
int32 HxSteam_GetStatInt(const char *name) { | |
if (!g_Steam) return 0; | |
int32 value = 0; | |
g_Steam->GetStat(name, &value); | |
return value; | |
} | |
double HxSteam_GetStatFloat(const char *name) { | |
if (!g_Steam) return 0.0; | |
float value = 0.0f; | |
g_Steam->GetStat(name, &value); | |
return value; | |
} | |
bool HxSteam_SetStatInt(const char *name, int32 value) { | |
if (!g_Steam) return false; | |
return g_Steam->SetStat(name, value); | |
} | |
bool HxSteam_SetStatFloat(const char *name, double value) { | |
if (!g_Steam) return false; | |
return g_Steam->SetStat(name, (float)value); | |
} | |
bool HxSteam_StoreStats() { | |
if (!g_Steam) return false; | |
return g_Steam->StoreStats(); | |
} | |
bool HxSteam_ResetAllStats(bool achievementsToo) { | |
if (!g_Steam) return false; | |
return g_Steam->ResetAllStats(achievementsToo); | |
} | |
bool HxSteam_RequestGlobalStats(int32 days) { | |
if (!g_Steam) return false; | |
return g_Steam->RequestGlobalStats(days); | |
} | |
// Since Flash doesn't have support for 64bit integer types, we just always | |
// return a double (aka Number). | |
double HxSteam_GetGlobalStatInt(const char *name) { | |
if (!g_Steam) return 0.0; | |
int64 value = 0; | |
g_Steam->GetGlobalStat(name, &value); | |
return static_cast<double>(value); | |
} | |
double HxSteam_GetGlobalStatFloat(const char *name) { | |
if (!g_Steam) return 0.0; | |
double value = 0; | |
g_Steam->GetGlobalStat(name, &value); | |
return static_cast<double>(value); | |
} | |
// See above for why double is used. | |
std::vector<double> HxSteam_GetGlobalStatHistoryInt(const char *name, uint32 days) { | |
std::vector<double> array; | |
if (!g_Steam) return array; | |
auto history = g_Steam->GetGlobalStatHistoryInt(name, days); | |
uint32 size = static_cast<uint32>(history.size()); | |
for (uint32 i = 0; i < size; ++i) { | |
double value = static_cast<double>(history.at(i)); | |
array.push_back(value); | |
} | |
return array; | |
} | |
std::vector<double> HxSteam_GetGlobalStatHistoryFloat(const char *name, uint32 days) { | |
std::vector<double> array; | |
if (!g_Steam) return array; | |
auto history = g_Steam->GetGlobalStatHistoryFloat(name, days); | |
uint32 size = static_cast<uint32>(history.size()); | |
for (uint32 i = 0; i < size; ++i) { | |
double value = history.at(i); | |
array.push_back(value); | |
} | |
return array; | |
} | |
/* | |
* leaderboards | |
*/ | |
bool HxSteam_FindLeaderboard(const char *name) { | |
if (!g_Steam) return false; | |
return g_Steam->FindLeaderboard(name); | |
} | |
bool HxSteam_FindOrCreateLeaderboard(const char *name, uint32 sort, uint32 display) { | |
if (!g_Steam) return false; | |
return g_Steam->FindOrCreateLeaderboard(name, | |
ELeaderboardSortMethod(sort), ELeaderboardDisplayType(display)); | |
} | |
SteamLeaderboard_t HxSteam_FindLeaderboardResult() { | |
if (!g_Steam) return 0; | |
return g_Steam->FindLeaderboardResult(); | |
} | |
std::string HxSteam_GetLeaderboardName(SteamLeaderboard_t handle) { | |
if (!g_Steam) return ""; | |
return g_Steam->GetLeaderboardName(handle); | |
} | |
int32 HxSteam_GetLeaderboardEntryCount(SteamLeaderboard_t handle) { | |
if (!g_Steam) return 0; | |
return g_Steam->GetLeaderboardEntryCount(handle); | |
} | |
uint32 HxSteam_GetLeaderboardSortMethod(SteamLeaderboard_t handle) { | |
if (!g_Steam) return 0; | |
return g_Steam->GetLeaderboardSortMethod(handle); | |
} | |
uint32 HxSteam_GetLeaderboardDisplayType(SteamLeaderboard_t handle) { | |
if (!g_Steam) return 0; | |
return g_Steam->GetLeaderboardDisplayType(handle); | |
} | |
bool HxSteam_UploadLeaderboardScore(SteamLeaderboard_t handle, uint32 method, int32 score, std::vector<int32> details) { | |
if (!g_Steam) return false; | |
int num_details = static_cast<int>(details.size()); | |
return g_Steam->UploadLeaderboardScore(handle, | |
ELeaderboardUploadScoreMethod(method), score, | |
details.data(), num_details); | |
} | |
LeaderboardScoreUploaded_t* HxSteam_UploadLeaderboardScoreResult() { | |
if (!g_Steam) return nullptr; | |
return g_Steam->UploadLeaderboardScoreResult(); | |
} | |
bool HxSteam_DownloadLeaderboardEntries(SteamLeaderboard_t handle, uint32 request, int rangeStart, int rangeEnd) { | |
if (!g_Steam) return false; | |
return g_Steam->DownloadLeaderboardEntries(handle, | |
ELeaderboardDataRequest(request), rangeStart, rangeEnd); | |
} | |
std::vector<LeaderboardEntry> HxSteam_DownloadLeaderboardEntriesResult(int32 numDetails) { | |
if (!g_Steam) return std::vector<LeaderboardEntry>(); | |
return g_Steam->DownloadLeaderboardEntriesResult(numDetails); | |
} | |
/* | |
* cloud storage | |
*/ | |
int32 HxSteam_GetFileCount() { | |
if (!g_Steam) return 0; | |
return g_Steam->GetFileCount(); | |
} | |
int32 HxSteam_GetFileSize(const char *name) { | |
if (!g_Steam) return 0; | |
return g_Steam->GetFileSize(name); | |
} | |
bool HxSteam_FileExists(const char *name) { | |
if (!g_Steam) return false; | |
return g_Steam->FileExists(name); | |
} | |
bool HxSteam_FileWrite(const char *name, hx::ObjectPtr<flash::utils::ByteArray_obj>& byteArray) { | |
if (!g_Steam) return false; | |
const char *dataPtr = byteArray->b->GetBase(); | |
int32 size = byteArray->getLength(); | |
return g_Steam->FileWrite(name, dataPtr, size); | |
} | |
bool HxSteam_FileRead(const char *name, hx::ObjectPtr<flash::utils::ByteArray_obj>& byteArray) { | |
if (!g_Steam) return false; | |
char* data = NULL; | |
int32 size = g_Steam->FileRead(name, &data); | |
byteArray->setLength(size); | |
char *outData = byteArray->b->GetBase(); | |
memcpy(outData, data, size); | |
delete[] data; | |
return true; | |
} | |
bool HxSteam_FileDelete(const char *name) { | |
if (!g_Steam) return false; | |
return g_Steam->FileDelete(name); | |
} | |
/* | |
* friends | |
*/ | |
int32 HxSteam_GetFriendCount(uint32 flags) { | |
if (!g_Steam) return 0; | |
return g_Steam->GetFriendCount(flags); | |
} | |
uint64_t HxSteam_GetFriendByIndex(int32 index, uint32 flags) { | |
if (!g_Steam) return 0ull; | |
return g_Steam->GetFriendByIndex(index, flags).ConvertToUint64(); | |
} | |
std::string HxSteam_GetFriendPersonaName(uint64 steamId) { | |
if (!g_Steam) return ""; | |
return g_Steam->GetFriendPersonaName(CSteamID(steamId)); | |
} | |
/* | |
* overlay | |
*/ | |
bool HxSteam_SetOverlayNotificationPosition(uint32 pos) { | |
if (!g_Steam) return 0; | |
return g_Steam->SetOverlayNotificationPosition( | |
ENotificationPosition(pos)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* HxSteamWorks.h | |
* Adapted from FRESteamWorks.h | |
* | |
* FRESteamWorks.h copyrights below. | |
* | |
* Created by David ´Oldes´ Oliva on 3/29/12. | |
* Contributors: Ventero <http://github.com/Ventero> | |
* Copyright (c) 2012 Amanita Design. All rights reserved. | |
* Copyright (c) 2012-2013 Level Up Labs, LLC. All rights reserved. | |
*/ | |
#ifndef HXSTEAMWORKS_H | |
#define HXSTEAMWORKS_H | |
#include "CSteam/CSteam.h" | |
#include "flash/utils/ByteArray.h" | |
void steamWarningMessageHook(int severity, const char* msg); | |
uint64 parseUint64(const char *str); | |
std::string uint64ToStr(uint64 val); | |
class HxSteam : public CSteam { | |
void DispatchEvent(char* code, char* level); | |
}; | |
// Declarations | |
bool HxSteam_Init(); | |
void HxSteam_Dispose(); | |
bool HxSteam_RunCallbacks(); | |
uint64_t HxSteam_GetUserID(); | |
uint32 HxSteam_GetAppID(); | |
std::string HxSteam_GetAvailableGameLanguages(); | |
std::string HxSteam_GetCurrentGameLanguage(); | |
std::string HxSteam_GetPersonaName(); | |
bool HxSteam_RestartAppIfNecessary(uint32 appID); | |
bool HxSteam_RequestStats(); | |
bool HxSteam_SetAchievement(const char *name); | |
bool HxSteam_ClearAchievement(const char *name); | |
bool HxSteam_IsAchievement(const char *name); | |
bool HxSteam_IndicateAchievementProgress(const char *name, uint32 current_progress, uint32 max_progress); | |
int32 HxSteam_GetStatInt(const char *name); | |
double HxSteam_GetStatFloat(const char *name); | |
bool HxSteam_SetStatInt(const char *name, int32 value); | |
bool HxSteam_SetStatFloat(const char *name, double value); | |
bool HxSteam_StoreStats(); | |
bool HxSteam_ResetAllStats(bool achievementsToo); | |
bool HxSteam_RequestGlobalStats(int32 days); | |
double HxSteam_GetGlobalStatInt(const char *name); | |
double HxSteam_GetGlobalStatFloat(const char *name); | |
std::vector<double> HxSteam_GetGlobalStatHistoryInt(const char *name, uint32 days); | |
std::vector<double> HxSteam_GetGlobalStatHistoryFloat(const char *name, uint32 days); | |
bool HxSteam_FindLeaderboard(const char *name); | |
bool HxSteam_FindOrCreateLeaderboard(const char *name, uint32 sort, uint32 display); | |
SteamLeaderboard_t HxSteam_FindLeaderboardResult(); | |
std::string HxSteam_GetLeaderboardName(SteamLeaderboard_t handle); | |
int32 HxSteam_GetLeaderboardEntryCount(SteamLeaderboard_t handle); | |
uint32 HxSteam_GetLeaderboardSortMethod(SteamLeaderboard_t handle); | |
uint32 HxSteam_GetLeaderboardDisplayType(SteamLeaderboard_t handle); | |
bool HxSteam_UploadLeaderboardScore(SteamLeaderboard_t handle, uint32 method, int32 score, std::vector<int32> details); | |
LeaderboardScoreUploaded_t* HxSteam_UploadLeaderboardScoreResult(); | |
bool HxSteam_DownloadLeaderboardEntries(SteamLeaderboard_t handle, uint32 request, int rangeStart, int rangeEnd); | |
std::vector<LeaderboardEntry> HxSteam_DownloadLeaderboardEntriesResult(int32 numDetails); | |
int32 HxSteam_GetFileCount(); | |
int32 HxSteam_GetFileSize(const char *name); | |
bool HxSteam_FileExists(const char *name); | |
bool HxSteam_FileWrite(const char *name, hx::ObjectPtr<flash::utils::ByteArray_obj>& byteArray); | |
bool HxSteam_FileRead(const char *name, hx::ObjectPtr<flash::utils::ByteArray_obj>& byteArray); | |
bool HxSteam_FileDelete(const char *name); | |
int32 HxSteam_GetFriendCount(uint32 flags); | |
uint64_t HxSteam_GetFriendByIndex(int32 index, uint32 flags); | |
std::string HxSteam_GetFriendPersonaName(uint64 steamId); | |
bool HxSteam_SetOverlayNotificationPosition(uint32 pos); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment