Subversion Repositories eduke32

Rev

Rev 8096 | Rev 8113 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8094 hendricks2 1
// Made possible by the Build Engine linking exception.
2
 
3
#if defined _WIN32 || defined __linux__ || defined EDUKE32_OSX
4
# define VW_ENABLED
5
#endif
6
 
7
#ifdef VW_ENABLED
8
# define VOIDWRAP_RUNTIMELINK
9
# include "voidwrap_steam.h"
10
#endif
11
 
12
#include "build.h"
13
#include "communityapi.h"
14
 
15
#ifdef VW_ENABLED
16
 
17
static bool steamworks_enabled;
18
static VW_LIBHANDLE wrapper_handle;
19
 
20
#ifdef _WIN32
21
# ifdef _WIN64
22
static char const wrapper_lib[] = "voidwrap_steam_x64.dll";
23
# else
24
static char const wrapper_lib[] = "voidwrap_steam_x86.dll";
25
# endif
26
#else
27
static char const wrapper_lib[] = "libvoidwrap_steam.so.0";
28
#endif
29
 
30
#ifdef VWSCREENSHOT
31
static void steam_callback_screenshotrequested()
32
{
33
#ifdef VWDEBUG
34
    initprintf("Voidwrap: Preparing steam screenshot!\n");
35
#endif
36
    videoCaptureScreen("steam0000.png", 0);
37
}
38
 
39
#if 0
40
static void steam_callback_screenshotready(int32_t result)
41
{
42
#ifdef VWDEBUG
43
    initprintf("Voidwrap: Steam screenshot ready! - Result: %d\n", result);
44
#endif
45
}
46
#endif
47
#endif
48
 
49
#ifdef VWDEBUG
50
static void steam_callback_printdebug(char const * str)
51
{
52
    initprintf("[DEBUG](%s): %s\n", wrapper_lib, str);
53
}
54
#endif
55
 
56
#endif
57
 
8096 hendricks2 58
 
8094 hendricks2 59
void communityapiInit()
60
{
61
#ifdef VW_ENABLED
62
    wrapper_handle = Voidwrap_LoadLibrary(wrapper_lib);
63
    if (wrapper_handle == nullptr)
64
    {
65
#ifdef VWDEBUG
66
#ifdef _WIN32
67
        initprintf("Voidwrap: %s missing or load failed.\n", wrapper_lib);
68
#else
69
        initprintf("Voidwrap: %s dlopen error: %s\n", wrapper_lib, dlerror());
70
#endif
71
#endif
72
        return;
73
    }
74
 
75
#ifdef VWDEBUG
76
    initprintf("Voidwrap: %s found!\n", wrapper_lib);
77
#endif
78
 
79
    Voidwrap_Steam_Init = (VW_BOOL)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_Init");
80
    Voidwrap_Steam_Shutdown = (VW_VOID)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_Shutdown");
81
    Voidwrap_Steam_RunCallbacks = (VW_VOID)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_RunCallbacks");
82
 
83
#ifdef VWDEBUG
8096 hendricks2 84
    Voidwrap_Steam_SetCallback_PrintDebug = (VW_SETCALLBACK_VOID_CONSTCHARPTR)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_SetCallback_PrintDebug");
8094 hendricks2 85
    Voidwrap_Steam_SetCallback_PrintDebug(steam_callback_printdebug);
86
#endif
87
 
8096 hendricks2 88
    Voidwrap_Steam_UnlockAchievement = (VW_VOID_CONSTCHARPTR)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_UnlockAchievement");
89
    Voidwrap_Steam_SetStat = (VW_VOID_CONSTCHARPTR_INT32)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_SetStat");
8112 terminx 90
    Voidwrap_Steam_ResetStats = (VW_VOID)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_ResetStats");
8094 hendricks2 91
#ifdef VWSCREENSHOT
92
    Voidwrap_Steam_SendScreenshot = (VW_BOOL_SCREENSHOT)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_SendScreenshot");
8096 hendricks2 93
    Voidwrap_Steam_SetCallback_ScreenshotRequested = (VW_SETCALLBACK_VOID)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_SetCallback_ScreenshotRequested");
8094 hendricks2 94
    Voidwrap_Steam_SetCallback_ScreenshotRequested(steam_callback_screenshotrequested);
95
#if 0
8096 hendricks2 96
    Voidwrap_Steam_SetCallback_ScreenshotReady = (VW_SETCALLBACK_VOID_INT32)Voidwrap_GetSymbol(wrapper_handle, "Voidwrap_Steam_SetCallback_ScreenshotReady");
8094 hendricks2 97
    Voidwrap_Steam_SetCallback_ScreenshotReady(steam_callback_screenshotready);
98
#endif
99
#endif
100
 
101
    if (Voidwrap_Steam_Init == nullptr || Voidwrap_Steam_RunCallbacks == nullptr)
102
    {
103
#ifdef VWDEBUG
104
        initprintf("Voidwrap: getproc_ failure.\n");
105
#endif
106
        return;
107
    }
108
 
109
    if (!Voidwrap_Steam_Init())
110
    {
111
#ifdef VWDEBUG
112
        initprintf("Voidwrap: Steamworks init failure.\n");
113
#endif
114
        return;
115
    }
116
 
117
#ifdef VWDEBUG
118
    initprintf("Voidwrap: Steamworks init success!\n");
119
#endif
120
    steamworks_enabled = true;
121
#endif
122
}
123
 
124
void communityapiShutdown()
125
{
126
#ifdef VW_ENABLED
127
    if (!steamworks_enabled)
128
        return;
129
 
8096 hendricks2 130
    if (nullptr == Voidwrap_Steam_Shutdown)
131
        return;
132
 
8094 hendricks2 133
    Voidwrap_Steam_Shutdown();
134
#endif
135
}
136
 
137
void communityapiRunCallbacks()
138
{
139
#ifdef VW_ENABLED
140
    if (!steamworks_enabled)
141
        return;
142
 
143
    Voidwrap_Steam_RunCallbacks();
144
#endif
145
}
146
 
8096 hendricks2 147
 
148
void communityapiUnlockAchievement(char const * id)
149
{
150
#ifdef VW_ENABLED
151
    if (!steamworks_enabled)
152
        return;
153
 
154
    if (nullptr == Voidwrap_Steam_UnlockAchievement)
155
        return;
156
 
157
    Voidwrap_Steam_UnlockAchievement(id);
158
#endif
159
}
160
 
161
void communityapiSetStat(char const * id, int32_t value)
162
{
163
#ifdef VW_ENABLED
164
    if (!steamworks_enabled)
165
        return;
166
 
167
    if (nullptr == Voidwrap_Steam_SetStat)
168
        return;
169
 
170
    Voidwrap_Steam_SetStat(id, value);
171
#endif
172
}
173
 
8112 terminx 174
void communityapiResetStats()
175
{
176
#ifdef VW_ENABLED
177
    if (!steamworks_enabled)
178
        return;
8096 hendricks2 179
 
8112 terminx 180
    if (nullptr == Voidwrap_Steam_ResetStats)
181
        return;
182
 
183
    Voidwrap_Steam_ResetStats();
184
#endif
185
}
186
 
8094 hendricks2 187
#ifdef VWSCREENSHOT
188
void communityapiSendScreenshot(char * filename)
189
{
190
#ifdef VW_ENABLED
191
    if (!steamworks_enabled)
192
        return;
193
 
194
    char fullpath[BMAX_PATH];
195
    buildvfs_getcwd(fullpath, sizeof(fullpath));
196
    Bstrcat(fullpath, "/");
197
    Bstrcat(fullpath, filename);
198
#ifdef VWDEBUG
199
    OSD_Printf("Voidwrap: Steam screenshot full path: %s\n", fullpath);
200
#endif
201
 
202
    Voidwrap_Steam_SendScreenshot(fullpath, xdim, ydim);
203
#else
204
    UNREFERENCED_PARAMETER(filename);
205
#endif
206
}
207
#endif