Use OneShot's fixed version of steamshim

This commit is contained in:
Ancurio 2021-10-03 00:35:22 +02:00
parent 46494766bd
commit 1445381756
2 changed files with 38 additions and 22 deletions

View File

@ -9,7 +9,6 @@ typedef __int32 int32;
typedef unsigned __int64 uint64;
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
@ -22,16 +21,16 @@ typedef uint64_t uint64;
typedef int PipeType;
#define NULLPIPE -1
#endif
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "steamshim_child.h"
#define DEBUGPIPE 1
#if DEBUGPIPE
#ifdef STEAMSHIM_DEBUG
#define dbgpipe printf
#else
static inline void dbgpipe(const char *fmt, ...) {}
static inline void dbgpipe(const char *fmt, ...) {
(void)fmt;
}
#endif
static int writePipe(PipeType fd, const void *buf, const unsigned int _len);
@ -68,12 +67,11 @@ static void closePipe(PipeType fd)
CloseHandle(fd);
} /* closePipe */
static char *getEnvVar(const char *key, char *buf, const size_t _buflen)
static char *getEnvVar(const char *key, char *buf, const size_t buflen)
{
const DWORD buflen = (DWORD) _buflen;
const DWORD rc = GetEnvironmentVariableA(key, buf, buflen);
/* rc doesn't count null char, hence "<". */
return ((rc > 0) && (rc < buflen)) ? NULL : buf;
return ((rc > 0) && (rc < buflen)) ? buf : NULL;
} /* getEnvVar */
#else
@ -135,6 +133,8 @@ typedef enum ShimCmd
SHIMCMD_GETSTATI,
SHIMCMD_SETSTATF,
SHIMCMD_GETSTATF,
SHIMCMD_GETPERSONANAME,
SHIMCMD_GETCURRENTGAMELANGUAGE,
} ShimCmd;
static int write1ByteCmd(const uint8 b1)
@ -158,21 +158,14 @@ static inline int writeBye(void)
static int initPipes(void)
{
char buf[64];
unsigned long long val;
if (!getEnvVar("STEAMSHIM_READHANDLE", buf, sizeof (buf)))
return 0;
else if (sscanf(buf, "%llu", &val) != 1)
return 0;
else
GPipeRead = (PipeType) val;
GPipeRead = (PipeType) strtoull(buf, 0, 10);
if (!getEnvVar("STEAMSHIM_WRITEHANDLE", buf, sizeof (buf)))
return 0;
else if (sscanf(buf, "%llu", &val) != 1)
return 0;
else
GPipeWrite = (PipeType) val;
GPipeWrite = (PipeType) strtoull(buf, 0, 10);
return ((GPipeRead != NULLPIPE) && (GPipeWrite != NULLPIPE));
} /* initPipes */
@ -239,7 +232,7 @@ static const STEAMSHIM_Event *processEvent(const uint8 *buf, size_t buflen)
event.type = type;
event.okay = 1;
#if DEBUGPIPE
#ifdef STEAMSHIM_DEBUG
if (0) {}
#define PRINTGOTEVENT(x) else if (type == x) printf("Child got " #x ".\n")
PRINTGOTEVENT(SHIMEVENT_BYE);
@ -252,6 +245,8 @@ static const STEAMSHIM_Event *processEvent(const uint8 *buf, size_t buflen)
PRINTGOTEVENT(SHIMEVENT_GETSTATI);
PRINTGOTEVENT(SHIMEVENT_SETSTATF);
PRINTGOTEVENT(SHIMEVENT_GETSTATF);
PRINTGOTEVENT(SHIMEVENT_GETPERSONANAME);
PRINTGOTEVENT(SHIMEVENT_GETCURRENTGAMELANGUAGE);
#undef PRINTGOTEVENT
else printf("Child got unknown shimevent %d.\n", (int) type);
#endif
@ -306,6 +301,11 @@ static const STEAMSHIM_Event *processEvent(const uint8 *buf, size_t buflen)
strcpy(event.name, (const char *) buf);
break;
case SHIMEVENT_GETPERSONANAME:
case SHIMEVENT_GETCURRENTGAMELANGUAGE:
strcpy(event.name, (const char *) buf);
break;
default: /* uh oh */
return NULL;
} /* switch */
@ -446,5 +446,18 @@ void STEAMSHIM_getStatF(const char *name)
writeStatThing(SHIMCMD_GETSTATF, name, NULL, 0);
} /* STEAMSHIM_getStatF */
/* end of steamshim_child.c ... */
void STEAMSHIM_getPersonaName()
{
if (isDead()) return;
dbgpipe("Child sending SHIMCMD_GETPERSONANAME().\n");
write1ByteCmd(SHIMCMD_GETPERSONANAME);
} /* STEAMSHIM_getPersonaName */
void STEAMSHIM_getCurrentGameLanguage()
{
if (isDead()) return;
dbgpipe("Child sending SHIMCMD_GETCURRENTGAMELANGUAGE().\n");
write1ByteCmd(SHIMCMD_GETCURRENTGAMELANGUAGE);
} /* STEAMSHIM_getCurrentGameLanguage */
/* end of steamshim_child.c ... */

View File

@ -17,6 +17,8 @@ typedef enum STEAMSHIM_EventType
SHIMEVENT_GETSTATI,
SHIMEVENT_SETSTATF,
SHIMEVENT_GETSTATF,
SHIMEVENT_GETPERSONANAME,
SHIMEVENT_GETCURRENTGAMELANGUAGE,
} STEAMSHIM_EventType;
/* not all of these fields make sense in a given event. */
@ -43,6 +45,8 @@ void STEAMSHIM_setStatI(const char *name, const int _val);
void STEAMSHIM_getStatI(const char *name);
void STEAMSHIM_setStatF(const char *name, const float val);
void STEAMSHIM_getStatF(const char *name);
void STEAMSHIM_getPersonaName();
void STEAMSHIM_getCurrentGameLanguage();
#ifdef __cplusplus
}
@ -51,4 +55,3 @@ void STEAMSHIM_getStatF(const char *name);
#endif /* include-once blocker */
/* end of steamshim_child.h ... */