From 2319b2bde8e09a0d609dd72e9cd3fb1b0d47d2c2 Mon Sep 17 00:00:00 2001 From: Jamiras Date: Sat, 20 Apr 2019 08:50:51 -0600 Subject: [PATCH] fix C89/CXX build --- cheevos-new/cheevos.c | 13 +++++++---- deps/rcheevos/include/rcheevos.h | 10 ++++----- deps/rcheevos/src/rcheevos/internal.h | 5 +++-- deps/rcheevos/src/rcheevos/memref.c | 4 ++-- deps/rcheevos/src/rcheevos/operand.c | 32 +++++++++++++++------------ deps/rcheevos/src/rcheevos/term.c | 6 ++--- qb/config.params.sh | 2 -- 7 files changed, 40 insertions(+), 32 deletions(-) diff --git a/cheevos-new/cheevos.c b/cheevos-new/cheevos.c index 76626c177e..64a0ded8be 100644 --- a/cheevos-new/cheevos.c +++ b/cheevos-new/cheevos.c @@ -1627,7 +1627,8 @@ found: CORO_SUB(RCHEEVOS_GET_GAMEID) { - int size = rc_url_get_gameid(coro->url, sizeof(coro->url), coro->hash); + int size; + size = rc_url_get_gameid(coro->url, sizeof(coro->url), coro->hash); if (size < 0) { @@ -1777,12 +1778,16 @@ found: *************************************************************************/ CORO_SUB(RCHEEVOS_LOGIN) { - const char* username = coro->settings->arrays.cheevos_username; - const char* password = coro->settings->arrays.cheevos_password; - const char* token = coro->settings->arrays.cheevos_token; + const char* username; + const char* password; + const char* token; int ret; char tok[256]; + username = coro->settings->arrays.cheevos_username; + password = coro->settings->arrays.cheevos_password; + token = coro->settings->arrays.cheevos_token; + if (rcheevos_locals.token[0]) CORO_RET(); diff --git a/deps/rcheevos/include/rcheevos.h b/deps/rcheevos/include/rcheevos.h index c15f72596e..423be5e6db 100644 --- a/deps/rcheevos/include/rcheevos.h +++ b/deps/rcheevos/include/rcheevos.h @@ -150,15 +150,15 @@ typedef struct { /* A value read from memory. */ rc_memref_value_t* memref; - /* A value. */ - unsigned value; + /* An integer value. */ + unsigned num; /* A floating point value. */ - double fp_value; + double dbl; /* A reference to the Lua function that provides the value. */ - int function_ref; - }; + int luafunc; + } value; char type; } diff --git a/deps/rcheevos/src/rcheevos/internal.h b/deps/rcheevos/src/rcheevos/internal.h index abdb398371..18b123e871 100644 --- a/deps/rcheevos/src/rcheevos/internal.h +++ b/deps/rcheevos/src/rcheevos/internal.h @@ -3,10 +3,11 @@ #include "rcheevos.h" +#include + #define RC_TAG2(x,y) x ## y #define RC_TAG(x,y) RC_TAG2(x,y) -#define RC_OFFSETOF(s, f) ((int)(long long)(&((s*)0)->f)) -#define RC_ALIGNOF(t) RC_OFFSETOF(struct RC_TAG(_unnamed, __LINE__) {char c; t d;}, d) +#define RC_ALIGNOF(t) offsetof(struct RC_TAG(_unnamed, __LINE__) {char c; t d;}, d) #define RC_ALLOC(t, p) ((t*)rc_alloc((p)->buffer, &(p)->offset, sizeof(t), RC_ALIGNOF(t), &(p)->scratch)) diff --git a/deps/rcheevos/src/rcheevos/memref.c b/deps/rcheevos/src/rcheevos/memref.c index b4565bb679..01ab2692f8 100644 --- a/deps/rcheevos/src/rcheevos/memref.c +++ b/deps/rcheevos/src/rcheevos/memref.c @@ -22,7 +22,7 @@ rc_memref_value_t* rc_alloc_memref_value(rc_parse_state_t* parse, unsigned addre if (parse->scratch.memref_count == parse->scratch.memref_size) { if (parse->scratch.memref == parse->scratch.memref_buffer) { parse->scratch.memref_size += 16; - memref = malloc(parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); + memref = (rc_memref_t*)malloc(parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); if (memref) { parse->scratch.memref = memref; memcpy(memref, parse->scratch.memref_buffer, parse->scratch.memref_count * sizeof(parse->scratch.memref_buffer[0])); @@ -34,7 +34,7 @@ rc_memref_value_t* rc_alloc_memref_value(rc_parse_state_t* parse, unsigned addre } else { parse->scratch.memref_size += 32; - memref = realloc(parse->scratch.memref, parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); + memref = (rc_memref_t*)realloc(parse->scratch.memref, parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); if (memref) { parse->scratch.memref = memref; } diff --git a/deps/rcheevos/src/rcheevos/operand.c b/deps/rcheevos/src/rcheevos/operand.c index 85502fbd1f..f968e0e1c8 100644 --- a/deps/rcheevos/src/rcheevos/operand.c +++ b/deps/rcheevos/src/rcheevos/operand.c @@ -21,7 +21,9 @@ extern "C" { static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { const char* aux = *memaddr; +#ifndef RC_DISABLE_LUA const char* id; +#endif if (*aux++ != '@') { return RC_INVALID_LUA_OPERAND; @@ -31,7 +33,9 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_par return RC_INVALID_LUA_OPERAND; } +#ifndef RC_DISABLE_LUA id = aux; +#endif while (isalnum(*aux) || *aux == '_') { aux++; @@ -52,7 +56,7 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_par return RC_INVALID_LUA_OPERAND; } - self->function_ref = luaL_ref(parse->L, LUA_REGISTRYINDEX); + self->value.luafunc = luaL_ref(parse->L, LUA_REGISTRYINDEX); } #endif /* RC_DISABLE_LUA */ @@ -131,7 +135,7 @@ static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr, rc_ address = 0xffffffffU; } - self->memref = rc_alloc_memref_value(parse, address, size, is_bcd); + self->value.memref = rc_alloc_memref_value(parse, address, size, is_bcd); if (parse->offset < 0) return parse->offset; @@ -158,7 +162,7 @@ static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, rc } self->type = RC_OPERAND_CONST; - self->value = (unsigned)value; + self->value.num = (unsigned)value; aux = end; break; @@ -191,7 +195,7 @@ static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, rc } self->type = RC_OPERAND_CONST; - self->value = (unsigned)value; + self->value.num = (unsigned)value; aux = end; break; @@ -229,7 +233,7 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, rc_pa } self->type = RC_OPERAND_CONST; - self->value = (unsigned)value; + self->value.num = (unsigned)value; aux = end; break; @@ -246,7 +250,7 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, rc_pa } self->type = RC_OPERAND_CONST; - self->value = (unsigned)value; + self->value.num = (unsigned)value; aux = end; break; @@ -269,15 +273,15 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, rc_pa case '+': case '-': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - self->fp_value = strtod(aux, &end); + self->value.dbl = strtod(aux, &end); if (end == aux) { return RC_INVALID_FP_OPERAND; } - if (floor(self->fp_value) == self->fp_value) { + if (floor(self->value.dbl) == self->value.dbl) { self->type = RC_OPERAND_CONST; - self->value = (unsigned)floor(self->fp_value); + self->value.num = (unsigned)floor(self->value.dbl); } else { self->type = RC_OPERAND_FP; @@ -338,7 +342,7 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S switch (self->type) { case RC_OPERAND_CONST: - value = self->value; + value = self->value.num; break; case RC_OPERAND_FP: @@ -349,7 +353,7 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S #ifndef RC_DISABLE_LUA if (L != 0) { - lua_rawgeti(L, LUA_REGISTRYINDEX, self->function_ref); + lua_rawgeti(L, LUA_REGISTRYINDEX, self->value.luafunc); lua_pushcfunction(L, rc_luapeek); luapeek.peek = peek; @@ -374,15 +378,15 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S break; case RC_OPERAND_ADDRESS: - value = self->memref->value; + value = self->value.memref->value; break; case RC_OPERAND_DELTA: - value = self->memref->previous; + value = self->value.memref->previous; break; case RC_OPERAND_PRIOR: - value = self->memref->prior; + value = self->value.memref->prior; break; } diff --git a/deps/rcheevos/src/rcheevos/term.c b/deps/rcheevos/src/rcheevos/term.c index de4e01e048..3356a1ee43 100644 --- a/deps/rcheevos/src/rcheevos/term.c +++ b/deps/rcheevos/src/rcheevos/term.c @@ -37,7 +37,7 @@ rc_term_t* rc_parse_term(const char** memaddr, rc_parse_state_t* parse) { case RC_OPERAND_ADDRESS: case RC_OPERAND_DELTA: case RC_OPERAND_PRIOR: - size = self->operand2.memref->memref.size; + size = self->operand2.value.memref->memref.size; break; default: size = RC_MEMSIZE_32_BITS; @@ -81,7 +81,7 @@ rc_term_t* rc_parse_term(const char** memaddr, rc_parse_state_t* parse) { } else { self->operand2.type = RC_OPERAND_CONST; - self->operand2.value = 1; + self->operand2.value.num = 1; } *memaddr = aux; @@ -95,5 +95,5 @@ unsigned rc_evaluate_term(rc_term_t* self, rc_peek_t peek, void* ud, lua_State* return value * (rc_evaluate_operand(&self->operand2, peek, ud, L) ^ self->invert); } - return (unsigned)((double)value * self->operand2.fp_value); + return (unsigned)((double)value * self->operand2.value.dbl); } diff --git a/qb/config.params.sh b/qb/config.params.sh index 32f00a3bda..34699330c5 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -121,8 +121,6 @@ HAVE_QT=auto # Qt companion support C89_QT=no HAVE_XSHM=no # XShm video driver support HAVE_CHEEVOS=yes # Retro Achievements -C89_CHEEVOS=no -CXX_CHEEVOS=no HAVE_LUA=no # Lua support (for Retro Achievements) HAVE_DISCORD=yes # Discord Integration C89_DISCORD=no