2018-01-18 19:24:05 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "steam_defs.h"
|
|
|
|
|
|
|
|
#include "steamclient_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
|
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
char g_tmppath[PATH_MAX];
|
|
|
|
|
|
|
|
static char *controller_glyphs[512]; /* at least k_EControllerActionOrigin_Count */
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %u, %p)\n", instance, reason, reserved);
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(instance);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
/* returns the number of bytes written to dst, not including the NUL terminator */
|
|
|
|
unsigned int steamclient_unix_path_to_dos_path(bool api_result, const char *src, char *dst, uint32 dst_bytes)
|
2018-01-18 19:24:05 +03:00
|
|
|
{
|
2018-11-20 20:10:12 +03:00
|
|
|
WCHAR *dosW;
|
2018-01-18 19:24:05 +03:00
|
|
|
uint32 r;
|
|
|
|
|
2019-01-02 16:31:53 +03:00
|
|
|
if(!dst || !dst_bytes)
|
|
|
|
return 0;
|
|
|
|
|
2018-12-07 13:59:21 +03:00
|
|
|
if(!src || !api_result){
|
|
|
|
*dst = 0;
|
2018-01-18 19:24:05 +03:00
|
|
|
return 0;
|
2018-12-07 13:59:21 +03:00
|
|
|
}
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
dosW = wine_get_dos_file_name(src);
|
2018-12-07 13:59:21 +03:00
|
|
|
*dst = 0;
|
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
if(!dosW){
|
|
|
|
WARN("Unable to convert unix filename to DOS: %s\n", src);
|
2018-01-18 19:24:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-07 14:00:30 +03:00
|
|
|
r = WideCharToMultiByte(CP_ACP, 0, dosW, -1, dst, dst_bytes,
|
2018-01-18 19:24:05 +03:00
|
|
|
NULL, NULL);
|
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
HeapFree(GetProcessHeap(), 0, dosW);
|
|
|
|
|
|
|
|
return r == 0 ? 0 : r - 1;
|
|
|
|
}
|
|
|
|
|
2018-11-30 17:47:13 +03:00
|
|
|
#define IS_ABSOLUTE(x) (*x == '/' || *x == '\\' || (*x && *(x + 1) == ':'))
|
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
/* returns non-zero on success, zero on failure */
|
|
|
|
bool steamclient_dos_path_to_unix_path(const char *src, char *dst)
|
|
|
|
{
|
|
|
|
*dst = 0;
|
|
|
|
|
2018-11-30 17:47:13 +03:00
|
|
|
if(!src || !*src)
|
2018-11-20 20:10:12 +03:00
|
|
|
return 0;
|
|
|
|
|
2018-11-30 17:47:13 +03:00
|
|
|
if(IS_ABSOLUTE(src)){
|
|
|
|
/* absolute path, use wine conversion */
|
|
|
|
WCHAR srcW[PATH_MAX];
|
|
|
|
char *unix_path;
|
|
|
|
uint32 r;
|
|
|
|
|
|
|
|
r = MultiByteToWideChar(CP_UNIXCP, 0, src, -1, srcW, PATH_MAX);
|
|
|
|
if(r == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unix_path = wine_get_unix_file_name(srcW);
|
|
|
|
if(!unix_path){
|
|
|
|
WARN("Unable to convert DOS filename to unix: %s\n", src);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(dst, unix_path, PATH_MAX);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_path);
|
|
|
|
}else{
|
|
|
|
/* relative path, just fix up backslashes */
|
|
|
|
const char *s;
|
|
|
|
char *d;
|
|
|
|
|
|
|
|
for(s = src, d = dst; *src; ++s, ++d){
|
|
|
|
if(*s == '\\')
|
|
|
|
*d = '/';
|
|
|
|
else
|
|
|
|
*d = *s;
|
|
|
|
}
|
|
|
|
|
|
|
|
*d = 0;
|
2018-11-20 20:10:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char **steamclient_dos_to_unix_stringlist(const char **src)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char **s;
|
|
|
|
char **out, **o;
|
|
|
|
WCHAR scratch[PATH_MAX];
|
|
|
|
|
|
|
|
if(!src)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = sizeof(char*); /* NUL */
|
|
|
|
for(s = src; *s; ++s)
|
|
|
|
len += sizeof(char*);
|
|
|
|
|
|
|
|
out = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
|
|
|
|
for(s = src, o = out; *s; ++s, ++o){
|
2018-11-30 17:47:13 +03:00
|
|
|
if(IS_ABSOLUTE(*s)){
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, *s, -1, scratch, sizeof(scratch)/sizeof(*scratch));
|
|
|
|
*o = wine_get_unix_file_name(scratch);
|
|
|
|
}else{
|
|
|
|
const char *r;
|
|
|
|
char *l;
|
|
|
|
*o = HeapAlloc(GetProcessHeap(), 0, strlen(*s) + 1);
|
2018-12-11 00:19:45 +03:00
|
|
|
for(r = *s, l = *o; *r; ++l, ++r){
|
2018-11-30 17:47:13 +03:00
|
|
|
if(*r == '\\')
|
|
|
|
*l = '/';
|
|
|
|
else
|
|
|
|
*l = *r;
|
|
|
|
}
|
|
|
|
*l = 0;
|
|
|
|
}
|
2018-11-20 20:10:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*o = NULL;
|
|
|
|
|
|
|
|
return (const char **)out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void steamclient_free_stringlist(const char **out)
|
|
|
|
{
|
|
|
|
if(out){
|
|
|
|
const char **o;
|
|
|
|
for(o = out; *o; o++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (char *)*o);
|
|
|
|
HeapFree(GetProcessHeap(), 0, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *steamclient_isteamcontroller_getglyph(int origin, const char *lin_path)
|
|
|
|
{
|
|
|
|
if(!lin_path)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!controller_glyphs[origin])
|
|
|
|
controller_glyphs[origin] = HeapAlloc(GetProcessHeap(), 0, PATH_MAX);
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
steamclient_unix_path_to_dos_path(1, lin_path, controller_glyphs[origin], PATH_MAX);
|
2018-01-18 19:24:05 +03:00
|
|
|
|
2018-11-20 20:10:12 +03:00
|
|
|
return controller_glyphs[origin];
|
2018-01-18 19:24:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "win_constructors.h"
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const char *iface_version;
|
|
|
|
void *(*ctor)(void *);
|
|
|
|
} constructors[] = {
|
|
|
|
#include "win_constructors_table.dat"
|
|
|
|
};
|
|
|
|
|
|
|
|
void *create_win_interface(const char *name, void *linux_side)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("trying to create %s\n", name);
|
|
|
|
|
|
|
|
if(!linux_side)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for(i = 0; i < sizeof(constructors) / sizeof(*constructors); ++i){
|
|
|
|
if(!strcmp(name, constructors[i].iface_version))
|
|
|
|
return constructors[i].ctor(linux_side);
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Don't recognize interface name: %s\n", name);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *steamclient_lib;
|
|
|
|
static void *(*steamclient_CreateInterface)(const char *name, int *return_code);
|
|
|
|
static bool (*steamclient_BGetCallback)(HSteamPipe a, CallbackMsg_t *b, int32 *c);
|
|
|
|
static bool (*steamclient_GetAPICallResult)(HSteamPipe, SteamAPICall_t, void *, int, int, bool *);
|
|
|
|
static bool (*steamclient_FreeLastCallback)(HSteamPipe);
|
2018-10-30 21:57:33 +03:00
|
|
|
static void (*steamclient_ReleaseThreadLocalMemory)(int);
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
static int load_steamclient(void)
|
|
|
|
{
|
2019-02-04 05:18:51 +03:00
|
|
|
char path[PATH_MAX], resolved_path[PATH_MAX];
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
if(steamclient_lib)
|
|
|
|
return 1;
|
|
|
|
|
2018-03-07 23:35:05 +03:00
|
|
|
#ifdef __APPLE__
|
2018-03-29 19:40:13 +03:00
|
|
|
if(getenv("STEAM_COMPAT_CLIENT_INSTALL_PATH")){
|
|
|
|
snprintf(path, PATH_MAX, "%s/steamclient.dylib", getenv("STEAM_COMPAT_CLIENT_INSTALL_PATH"));
|
|
|
|
}else{
|
|
|
|
WARN("Old Steam client, falling back to DYLD environment to locate native steamclient library\n");
|
|
|
|
strcpy(path, "steamclient.dylib");
|
|
|
|
}
|
2018-03-07 23:35:05 +03:00
|
|
|
#else
|
2018-01-18 19:24:05 +03:00
|
|
|
#ifdef _WIN64
|
|
|
|
snprintf(path, PATH_MAX, "%s/.steam/sdk64/steamclient.so", getenv("HOME"));
|
|
|
|
#else
|
|
|
|
snprintf(path, PATH_MAX, "%s/.steam/sdk32/steamclient.so", getenv("HOME"));
|
|
|
|
#endif
|
2019-02-04 05:18:51 +03:00
|
|
|
if (realpath(path, resolved_path)){
|
|
|
|
strncpy(path, resolved_path, PATH_MAX);
|
|
|
|
path[PATH_MAX - 1] = 0;
|
|
|
|
}
|
2018-03-07 23:35:05 +03:00
|
|
|
#endif
|
2018-03-29 19:40:13 +03:00
|
|
|
steamclient_lib = wine_dlopen(path, RTLD_NOW, NULL, 0);
|
2018-01-18 19:24:05 +03:00
|
|
|
if(!steamclient_lib){
|
2018-03-07 23:35:05 +03:00
|
|
|
ERR("unable to load native steamclient library\n");
|
2018-01-18 19:24:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
steamclient_CreateInterface = wine_dlsym(steamclient_lib, "CreateInterface", NULL, 0);
|
|
|
|
if(!steamclient_CreateInterface){
|
|
|
|
ERR("unable to load CreateInterface method\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
steamclient_BGetCallback = wine_dlsym(steamclient_lib, "Steam_BGetCallback", NULL, 0);
|
|
|
|
if(!steamclient_BGetCallback){
|
|
|
|
ERR("unable to load BGetCallback method\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
steamclient_GetAPICallResult = wine_dlsym(steamclient_lib, "Steam_GetAPICallResult", NULL, 0);
|
|
|
|
if(!steamclient_GetAPICallResult){
|
|
|
|
ERR("unable to load GetAPICallResult method\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
steamclient_FreeLastCallback = wine_dlsym(steamclient_lib, "Steam_FreeLastCallback", NULL, 0);
|
|
|
|
if(!steamclient_FreeLastCallback){
|
|
|
|
ERR("unable to load FreeLastCallback method\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:57:33 +03:00
|
|
|
steamclient_ReleaseThreadLocalMemory = wine_dlsym(steamclient_lib, "Steam_ReleaseThreadLocalMemory", NULL, 0);
|
|
|
|
if(!steamclient_ReleaseThreadLocalMemory){
|
|
|
|
ERR("unable to load ReleaseThreadLocalMemory method\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *CDECL CreateInterface(const char *name, int *return_code)
|
|
|
|
{
|
|
|
|
TRACE("name: %s, return_code: %p\n", name, return_code);
|
|
|
|
|
|
|
|
if(!load_steamclient())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return create_win_interface(name, steamclient_CreateInterface(name, return_code));
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "cb_converters.h"
|
|
|
|
|
2018-10-30 16:09:46 +03:00
|
|
|
#pragma pack( push, 8 )
|
2018-01-18 19:24:05 +03:00
|
|
|
struct winCallbackMsg_t
|
|
|
|
{
|
|
|
|
HSteamUser m_hSteamUser;
|
|
|
|
int m_iCallback;
|
|
|
|
uint8 *m_pubParam;
|
|
|
|
int m_cubParam;
|
2018-10-30 16:09:46 +03:00
|
|
|
} __attribute__ ((ms_struct));
|
|
|
|
#pragma pack( pop )
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
static void *last_cb = NULL;
|
|
|
|
|
|
|
|
bool CDECL Steam_BGetCallback(HSteamPipe pipe, struct winCallbackMsg_t *win_msg, int32 *ignored)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
CallbackMsg_t lin_msg;
|
|
|
|
|
|
|
|
TRACE("%u, %p, %p\n", pipe, win_msg, ignored);
|
|
|
|
|
|
|
|
if(!load_steamclient())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = steamclient_BGetCallback(pipe, &lin_msg, ignored);
|
|
|
|
|
|
|
|
if(ret){
|
2018-10-30 16:09:46 +03:00
|
|
|
BOOL need_free = TRUE;
|
2018-01-18 19:24:05 +03:00
|
|
|
win_msg->m_hSteamUser = lin_msg.m_hSteamUser;
|
|
|
|
win_msg->m_iCallback = lin_msg.m_iCallback;
|
|
|
|
switch(win_msg->m_iCallback | (lin_msg.m_cubParam << 16)){
|
|
|
|
#include "cb_converters.dat"
|
|
|
|
default:
|
2018-10-30 16:09:46 +03:00
|
|
|
/* structs are compatible */
|
|
|
|
need_free = FALSE;
|
|
|
|
win_msg->m_cubParam = lin_msg.m_cubParam;
|
|
|
|
win_msg->m_pubParam = lin_msg.m_pubParam;
|
|
|
|
break;
|
2018-01-18 19:24:05 +03:00
|
|
|
}
|
2018-10-30 16:09:46 +03:00
|
|
|
if(need_free)
|
|
|
|
last_cb = win_msg->m_pubParam;
|
2018-01-18 19:24:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_callback_len(int cb)
|
|
|
|
{
|
|
|
|
switch(cb){
|
|
|
|
#include "cb_getapi_sizes.dat"
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:30:28 +03:00
|
|
|
bool do_cb_wrap(HSteamPipe pipe, void *linux_side,
|
|
|
|
bool (*cpp_func)(void *, SteamAPICall_t, void *, int, int, bool *),
|
|
|
|
SteamAPICall_t call, void *callback, int callback_len, int cb_expected, bool *failed)
|
2018-01-18 19:24:05 +03:00
|
|
|
{
|
2018-10-30 16:09:46 +03:00
|
|
|
void *lin_callback = NULL;
|
2018-01-18 19:24:05 +03:00
|
|
|
int lin_callback_len;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
lin_callback_len = get_callback_len(cb_expected);
|
2018-10-30 19:30:28 +03:00
|
|
|
if(!lin_callback_len){
|
2018-10-30 16:09:46 +03:00
|
|
|
/* structs are compatible, pass on through */
|
2018-10-30 19:30:28 +03:00
|
|
|
if(!cpp_func){
|
|
|
|
if(!load_steamclient())
|
|
|
|
return 0;
|
|
|
|
return steamclient_GetAPICallResult(pipe, call, callback, callback_len, cb_expected, failed);
|
|
|
|
}
|
|
|
|
return cpp_func(linux_side, call, callback, callback_len, cb_expected, failed);
|
|
|
|
}
|
2018-10-30 16:09:46 +03:00
|
|
|
|
|
|
|
/* structs require conversion */
|
2018-01-18 19:24:05 +03:00
|
|
|
lin_callback = HeapAlloc(GetProcessHeap(), 0, lin_callback_len);
|
|
|
|
|
2018-10-30 19:30:28 +03:00
|
|
|
if(!cpp_func){
|
|
|
|
if(!load_steamclient())
|
|
|
|
return 0;
|
|
|
|
ret = steamclient_GetAPICallResult(pipe, call, lin_callback, lin_callback_len, cb_expected, failed);
|
|
|
|
}else
|
|
|
|
ret = cpp_func(linux_side, call, lin_callback, lin_callback_len, cb_expected, failed);
|
2018-01-18 19:24:05 +03:00
|
|
|
|
|
|
|
if(ret){
|
|
|
|
switch(cb_expected){
|
|
|
|
#include "cb_getapi_table.dat"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:09:46 +03:00
|
|
|
HeapFree(GetProcessHeap(), 0, lin_callback);
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:30:28 +03:00
|
|
|
bool CDECL Steam_GetAPICallResult(HSteamPipe pipe, SteamAPICall_t call,
|
|
|
|
void *callback, int callback_len, int cb_expected, bool *failed)
|
|
|
|
{
|
|
|
|
TRACE("%u, x, %p, %u, %u, %p\n", pipe, callback, callback_len, cb_expected, failed);
|
|
|
|
return do_cb_wrap(pipe, NULL, NULL, call, callback, callback_len, cb_expected, failed);
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
bool CDECL Steam_FreeLastCallback(HSteamPipe pipe)
|
|
|
|
{
|
|
|
|
TRACE("%u\n", pipe);
|
|
|
|
|
|
|
|
if(!load_steamclient())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, last_cb);
|
|
|
|
last_cb = NULL;
|
|
|
|
|
|
|
|
return steamclient_FreeLastCallback(pipe);
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:57:33 +03:00
|
|
|
void CDECL Steam_ReleaseThreadLocalMemory(int bThreadExit)
|
|
|
|
{
|
|
|
|
TRACE("%d\n", bThreadExit);
|
|
|
|
|
|
|
|
if(!load_steamclient())
|
|
|
|
return;
|
|
|
|
|
|
|
|
steamclient_ReleaseThreadLocalMemory(bThreadExit);
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:24:05 +03:00
|
|
|
void CDECL Breakpad_SteamMiniDumpInit(uint32_t a, const char *b, const char *c)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL Breakpad_SteamSetAppID(uint32_t appid)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int CDECL Breakpad_SteamSetSteamID(uint64_t steamid)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CDECL Breakpad_SteamWriteMiniDumpSetComment(const char *comment)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL Breakpad_SteamWriteMiniDumpUsingExceptionInfoWithBuildId(int a, int b)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
}
|