import games/libcsteamworks. ok sthen@

CSteamworks is a C ABI Wrapper for Valve's Steamworks API. It relys heavily on
automatic code generation. The primary use case for CSteamworks is to act as a
buffer between a scripting language and the Steamworks C++ Interfaces.
This commit is contained in:
thfr 2022-12-13 15:10:45 +00:00
parent 7301c09a45
commit 406b5108b7
7 changed files with 269 additions and 0 deletions

View File

@ -0,0 +1,32 @@
COMMENT = C bindings for Steamworks
V = 1.30
DISTNAME = csteamworks-${V}
PKGNAME = libcsteamworks-${V}
GH_ACCOUNT = rlabrecque
GH_PROJECT = CSteamworks
GH_TAGNAME = v1.30-1.40
SHARED_LIBS = CSteamworks 0.0 # 1.30-1.40
CATEGORIES = games
MAINTAINER = Thomas Frohwein <thfr@openbsd.org>
# MIT
PERMIT_PACKAGE = Yes
WANTLIB += ${COMPILER_LIBCXX} m steam_api
FIX_CRLF_FILES = src/CSteamworks.h \
src/steam_api.cpp
# C++
COMPILER = base-clang ports-gcc base-gcc
LIB_DEPENDS = games/goldberg_emulator
MAKE_FLAGS = CXX=${CXX} CXXFLAGS="${CXXFLAGS}"
USE_GMAKE = Yes
NO_TEST = Yes
CXXFLAGS += -I${LOCALBASE}/include/goldberg_emulator/steam
WRKSRC = ${WRKDIST}/build/linux
do-install:
${INSTALL_DATA} ${WRKBUILD}/libCSteamworks.so \
${PREFIX}/lib/libCSteamworks.so.${LIBCSteamworks_VERSION}
.include <bsd.port.mk>

View File

@ -0,0 +1,2 @@
SHA256 (csteamworks-1.30.tar.gz) = MIoR7kmuXUNXgFMH5AMJgeTx7/bML0mru1W6IHXnJ2c=
SIZE (csteamworks-1.30.tar.gz) = 11986

View File

@ -0,0 +1,35 @@
use arch-independent output location
remove -m{32,64} optimizations
Index: build/linux/Makefile
--- build/linux/Makefile.orig
+++ build/linux/Makefile
@@ -1,16 +1,14 @@
STEAM_RUNTIME_TARGET_ARCH := $(shell uname -m)
ifeq ($(STEAM_RUNTIME_TARGET_ARCH), i686)
- ARCH := -m32
LINKERSEARCHPATH := ../../redistributable_bin/linux32
else
- ARCH := -m64
LINKERSEARCHPATH := ../../redistributable_bin/linux64
endif
CXX := g++
INCLUDES := -I"../../src" -I"../../steam" -I"../../wrapper"
-CPPFLAGS := -fPIC $(ARCH) $(INCLUDES) -DGNUC -DCSTEAMWORKS_DLLEXPORT -Wall
-OBJDIR := $(STEAM_RUNTIME_TARGET_ARCH)/obj
-OUTFILE := $(STEAM_RUNTIME_TARGET_ARCH)/libCSteamworks.so
+CPPFLAGS := ${CXXFLAGS} -I$(LOCALBASE)/include/goldberg_emulator/sdk_includes -fPIC $(ARCH) $(INCLUDES) -DGNUC -DCSTEAMWORKS_DLLEXPORT -Wall
+OBJDIR := obj
+OUTFILE := libCSteamworks.so
CPP_FILES := ../../src/steam_api.cpp
OBJ_FILES := $(OBJDIR)/steam_api.o
@@ -21,7 +19,7 @@ $(OBJDIR)/%.o: $(CPP_FILES)
@echo "Compiling $<"
all: $(OBJ_FILES)
- $(CXX) $(CPPFLAGS) -Wl,-z,origin '-Wl,-rpath,$$ORIGIN' -L$(LINKERSEARCHPATH) -shared $^ -lsteam_api -o $(OUTFILE)
+ $(CXX) $(CPPFLAGS) -Wl,-z,origin '-Wl,-rpath,$$ORIGIN' -L$(LINKERSEARCHPATH) -L$(LOCALBASE)/lib -shared $^ -lsteam_api -o $(OUTFILE)
clean:
rm -rf ./$(STEAM_RUNTIME_TARGET_ARCH)/

View File

@ -0,0 +1,17 @@
include steam_api_flat.h (for ISteamUser_GetSteamID)
Index: src/CSteamworks.h
--- src/CSteamworks.h.orig
+++ src/CSteamworks.h
@@ -12,9 +12,11 @@ __pragma(warning(push))
__pragma(warning(disable:4127)) // 'conditional expression is constant'
__pragma(warning(disable:4996)) // 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead.
#endif
+#define STEAMAPI_API extern "C"
#include "steam_gameserver.h" // Includes steam_api internally
#include "steamencryptedappticket.h"
#include "isteamgamecoordinator.h"
+#include "steam_api_flat.h"
#if defined( _WIN32 )
__pragma(warning(pop))
#endif

View File

@ -0,0 +1,179 @@
disable the Unity bits
supply InitSafe method as an alternative name for Init
supply ISteamUser_GetSteamID
... and more ...
Stubs: FindOrCreateLeaderboard, FileExists, SetStat
Index: src/steam_api.cpp
--- src/steam_api.cpp.orig
+++ src/steam_api.cpp
@@ -15,6 +15,14 @@ SB_API bool S_CALLTYPE Init() {
return SteamAPI_Init();
}
+SB_API bool S_CALLTYPE Steam_Init() {
+ return SteamAPI_Init();
+}
+
+SB_API bool S_CALLTYPE InitSafe() {
+ return SteamAPI_Init();
+}
+
SB_API void S_CALLTYPE Shutdown() {
SteamAPI_Shutdown();
}
@@ -23,6 +31,10 @@ SB_API bool S_CALLTYPE RestartAppIfNecessary(uint32 un
return SteamAPI_RestartAppIfNecessary(unOwnAppID);
}
+SB_API bool S_CALLTYPE Steam_RestartAppIfNecessary(uint32 unOwnAppID) {
+ return SteamAPI_RestartAppIfNecessary(unOwnAppID);
+}
+
SB_API void S_CALLTYPE ReleaseCurrentThreadMemory() {
SteamAPI_ReleaseCurrentThreadMemory();
}
@@ -204,4 +216,142 @@ SB_API const uint8 *GetUserVariableData(uint8 *rgubTic
}
#endif // 0
-#include "unitybuild.cpp"
+// port-added API
+
+SB_API uint64 S_CALLTYPE ISteamUser_GetSteamID(ISteamUser* self) { return SteamAPI_ISteamUser_GetSteamID(self); }
+SB_API bool S_CALLTYPE ISteamUserStats_RequestCurrentStats(ISteamUserStats* self) { return SteamAPI_ISteamUserStats_RequestCurrentStats(self); }
+SB_API int S_CALLTYPE ISteamUserStats_FindOrCreateLeaderboard(ISteamUserStats* self, const char * pchLeaderboardName, ELeaderboardSortMethod eLeaderboardSortMethod, ELeaderboardDisplayType eLeaderboardDisplayType) { return 0; }
+SB_API void *ISteamUserStats_FindLeaderboard(ISteamUserStats* self, const char * pchLeaderboardName) { return nullptr; }
+SB_API const char *ISteamFriends_GetPersonaName() { return ""; }
+SB_API bool ISteamFriends_SetRichPresence(const char *pchKey, const char *pchValue) { return 0; }
+SB_API void *ISteamUserStats_RequestUserStats(CSteamID steamIDUser) { return nullptr; }
+SB_API uint32 ISteamUtils_GetServerRealTime() { return 0; }
+SB_API bool ISteamRemoteStorage_IsCloudEnabledForAccount() { return 0; }
+SB_API bool ISteamApps_GetCurrentBetaName(char *pchName, int cchNameBufferSize) { return 0; }
+SB_API int ISteamFriends_GetLargeFriendAvatar(CSteamID steamIDFriend) { return 0; }
+SB_API bool ISteamUtils_GetImageSize(int iImage, uint32 *pnWidth, uint32 *pnHeight) { return 0; }
+SB_API bool ISteamUtils_IsSteamRunningOnSteamDeck() { return 0; }
+SB_API bool ISteamHTMLSurface_Init() { return 0; }
+SB_API void ISteamHTMLSurface_SetSize(HHTMLBrowser unBrowserHandle, uint32 unWidth, uint32 unHeight) { }
+SB_API void *ISteamHTMLSurface_CreateBrowser(const char *pchUserAgent, const char *pchUserCSS) { return nullptr; }
+SB_API void *ISteamMatchmaking_CreateLobby(ELobbyType eLobbyType, int cMaxMembers) { return nullptr; }
+SB_API bool ISteamApps_BIsDlcInstalled(AppId_t appID) { return 0; }
+SB_API bool ISteamRemoteStorage_IsCloudEnabledForApp() { return 1; }
+SB_API char *ISteamApps_GetCurrentGameLanguage() { return "en"; }
+SB_API bool ISteamNetworking_IsP2PPacketAvailable() { return 0; }
+SB_API int32 ISteamRemoteStorage_GetFileSize(const char *pchFile) { return 0; }
+SB_API bool ISteamUtils_IsOverlayEnabled() { return false; }
+SB_API int Steam_SetCallback_GameLobbyJoinRequested() { return 0; }
+SB_API int Steam_SetCallback_GameOverlayActivated() { return 0; }
+SB_API int Steam_SetCallback_GameRichPresenceJoinRequested() { return 0; }
+SB_API int Steam_SetCallback_LobbyChatMsg() { return 0; }
+SB_API int Steam_SetCallback_LobbyChatUpdate() { return 0; }
+SB_API int Steam_SetCallback_LobbyDataUpdate() { return 0; }
+SB_API int Steam_SetCallback_PersonaStateChange() { return 0; }
+SB_API int Steam_SetCallback_SteamServersConnected() { return 0; }
+SB_API int Steam_SetCallback_SteamServersDisconnected() { return 0; }
+SB_API int Steam_SetCallback_UserAchievementStored() { return 0; }
+SB_API int Steam_SetCallback_UserStatsReceived() { return 0; }
+
+// from v1.21
+
+typedef bool (__cdecl * BGetCallback_t)(HSteamPipe, CallbackMsg_t *);
+SB_API bool __cdecl Steam_BGetCallback2(HSteamPipe hSteamPipe, CallbackMsg_t *pCallbackMsg) {
+ return false;
+ /*
+ static BGetCallback_t _Steam_BGetCallback = NULL;
+ if(!_Steam_BGetCallback) {
+ HMODULE hSteamClient = GetModuleHandleA(s_SteamClientDLLName);
+ if(hSteamClient) {
+ _Steam_BGetCallback = reinterpret_cast<BGetCallback_t>(GetProcAddress(hSteamClient, "Steam_BGetCallback"));
+
+ if(!_Steam_BGetCallback) {
+ fprintf(stderr, "[CSteamworks] GetProcAddress failed to find Steam_BGetCallback\n");
+ return false;
+ }
+ }
+ else {
+ fprintf(stderr, "[CSteamworks] GetModuleHandleA failed opening steamclient.dll\n");
+ return false;
+ }
+ }
+
+ return _Steam_BGetCallback(hSteamPipe, pCallbackMsg);
+ */
+}
+
+SB_API void S_CALLTYPE ISteamUtils_RunFrame() {
+ SteamAPI_RunCallbacks();
+}
+
+SB_API void ISteamController_RunFrame(ISteamController* self) {
+ SteamAPI_ISteamController_RunFrame(self);
+}
+
+SB_API uint32 ISteamUtils_GetAppID(ISteamUtils* self) {
+ return SteamAPI_ISteamUtils_GetAppID(self);
+}
+
+SB_API bool ISteamRemoteStorage_FileExists(ISteamRemoteStorage* self, const char * pchFile) {
+ // while Goldberg Emulator backend is defective, just return false
+ //return SteamAPI_ISteamRemoteStorage_FileExists(self, pchFile);
+ return false;
+}
+
+SB_API int32 ISteamRemoteStorage_FileRead(ISteamRemoteStorage* self, const char * pchFile, void * pvData, int32 cubDataToRead) {
+ return SteamAPI_ISteamRemoteStorage_FileRead(self, pchFile, pvData, cubDataToRead);
+}
+
+/*
+SB_API SteamAPICall_t ISteamUserStats_FindLeaderboard(ISteamUserStats* self, const char * pchLeaderboardName) {
+ return SteamAPI_ISteamUserStats_FindLeaderboard(self, pchLeaderboardName);
+}
+*/
+
+SB_API bool ISteamRemoteStorage_FileWrite(ISteamRemoteStorage* self, const char * pchFile, const void * pvData, int32 cubData) {
+ // while Goldberg Emulator backend is defective, just return false
+ //return SteamAPI_ISteamRemoteStorage_FileWrite(self, pchFile, pvData, cubData);
+ return false;
+}
+
+SB_API bool ISteamUserStats_StoreStats(ISteamUserStats* self) {
+ return SteamAPI_ISteamUserStats_StoreStats(self);
+}
+
+SB_API bool ISteamUserStats_GetStat(ISteamUserStats* self, const char * pchName, int32 * pData){
+ return SteamAPI_ISteamUserStats_GetStatInt32(self, pchName, pData);
+}
+
+SB_API bool ISteamUserStats_SetStat(ISteamUserStats* self, const char * pchName, int32 nData){
+ //return SteamAPI_ISteamUserStats_SetStatInt32(self, pchName, nData);
+ return false;
+}
+
+SB_API bool ISteamUserStats_GetAchievement(ISteamUserStats* self, const char * pchName, bool * pbAchieved) {
+ return SteamAPI_ISteamUserStats_GetAchievement(self, pchName, pbAchieved);
+}
+
+SB_API SteamAPICall_t ISteamUserStats_UploadLeaderboardScore(ISteamUserStats* self, SteamLeaderboard_t hSteamLeaderboard, ELeaderboardUploadScoreMethod eLeaderboardUploadScoreMethod, int32 nScore, const int32 * pScoreDetails, int cScoreDetailsCount) {
+ return SteamAPI_ISteamUserStats_UploadLeaderboardScore(self, hSteamLeaderboard, eLeaderboardUploadScoreMethod, nScore, pScoreDetails, cScoreDetailsCount);
+}
+
+SB_API void ISteamClient_SetWarningMessageHook(ISteamClient* self, SteamAPIWarningMessageHook_t pFunction) {
+ SteamAPI_ISteamClient_SetWarningMessageHook(self, pFunction);
+}
+
+SB_API void SteamUtils_SetWarningMessageHook(ISteamClient* self, SteamAPIWarningMessageHook_t pFunction) {
+ SteamAPI_ISteamClient_SetWarningMessageHook(self, pFunction);
+}
+
+SB_API SteamAPICall_t ISteamUserStats_RequestGlobalStats(ISteamUserStats* self, int nHistoryDays) {
+ return SteamAPI_ISteamUserStats_RequestGlobalStats(self, nHistoryDays);
+}
+
+SB_API bool ISteamUserStats_SetAchievement(ISteamUserStats* self, const char * pchName) {
+ //return SteamAPI_ISteamUserStats_SetAchievement(self, pchName);
+ return false;
+}
+
+SB_API bool ISteamUser_BLoggedOn(ISteamUser* self) {
+ return SteamAPI_ISteamUser_BLoggedOn(self);
+}

View File

@ -0,0 +1,3 @@
CSteamworks is a C ABI Wrapper for Valve's Steamworks API. It relys heavily on
automatic code generation. The primary use case for CSteamworks is to act as a
buffer between a scripting language and the Steamworks C++ Interfaces.

View File

@ -0,0 +1 @@
@lib lib/libCSteamworks.so.${LIBCSteamworks_VERSION}