Merge pull request #8610 from meleu/runtime_rcheevos_switch_c89

C89/CXX support for rcheevos
This commit is contained in:
Twinaphex 2019-04-20 22:25:11 +02:00 committed by GitHub
commit 287c95ac8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 32 deletions

View File

@ -1627,7 +1627,8 @@ found:
CORO_SUB(RCHEEVOS_GET_GAMEID) 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) if (size < 0)
{ {
@ -1777,12 +1778,16 @@ found:
*************************************************************************/ *************************************************************************/
CORO_SUB(RCHEEVOS_LOGIN) CORO_SUB(RCHEEVOS_LOGIN)
{ {
const char* username = coro->settings->arrays.cheevos_username; const char* username;
const char* password = coro->settings->arrays.cheevos_password; const char* password;
const char* token = coro->settings->arrays.cheevos_token; const char* token;
int ret; int ret;
char tok[256]; 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]) if (rcheevos_locals.token[0])
CORO_RET(); CORO_RET();

View File

@ -150,15 +150,15 @@ typedef struct {
/* A value read from memory. */ /* A value read from memory. */
rc_memref_value_t* memref; rc_memref_value_t* memref;
/* A value. */ /* An integer value. */
unsigned value; unsigned num;
/* A floating point value. */ /* A floating point value. */
double fp_value; double dbl;
/* A reference to the Lua function that provides the value. */ /* A reference to the Lua function that provides the value. */
int function_ref; int luafunc;
}; } value;
char type; char type;
} }

View File

@ -3,10 +3,11 @@
#include "rcheevos.h" #include "rcheevos.h"
#include <stddef.h>
#define RC_TAG2(x,y) x ## y #define RC_TAG2(x,y) x ## y
#define RC_TAG(x,y) RC_TAG2(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) offsetof(struct RC_TAG(_unnamed, __LINE__) {char c; t d;}, d)
#define RC_ALIGNOF(t) RC_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)) #define RC_ALLOC(t, p) ((t*)rc_alloc((p)->buffer, &(p)->offset, sizeof(t), RC_ALIGNOF(t), &(p)->scratch))

View File

@ -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_count == parse->scratch.memref_size) {
if (parse->scratch.memref == parse->scratch.memref_buffer) { if (parse->scratch.memref == parse->scratch.memref_buffer) {
parse->scratch.memref_size += 16; 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) { if (memref) {
parse->scratch.memref = memref; parse->scratch.memref = memref;
memcpy(memref, parse->scratch.memref_buffer, parse->scratch.memref_count * sizeof(parse->scratch.memref_buffer[0])); 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 { else {
parse->scratch.memref_size += 32; 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) { if (memref) {
parse->scratch.memref = memref; parse->scratch.memref = memref;
} }

View File

@ -21,7 +21,9 @@ extern "C" {
static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) {
const char* aux = *memaddr; const char* aux = *memaddr;
#ifndef RC_DISABLE_LUA
const char* id; const char* id;
#endif
if (*aux++ != '@') { if (*aux++ != '@') {
return RC_INVALID_LUA_OPERAND; 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; return RC_INVALID_LUA_OPERAND;
} }
#ifndef RC_DISABLE_LUA
id = aux; id = aux;
#endif
while (isalnum(*aux) || *aux == '_') { while (isalnum(*aux) || *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; 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 */ #endif /* RC_DISABLE_LUA */
@ -131,7 +135,7 @@ static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr, rc_
address = 0xffffffffU; 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) if (parse->offset < 0)
return parse->offset; 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->type = RC_OPERAND_CONST;
self->value = (unsigned)value; self->value.num = (unsigned)value;
aux = end; aux = end;
break; 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->type = RC_OPERAND_CONST;
self->value = (unsigned)value; self->value.num = (unsigned)value;
aux = end; aux = end;
break; 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->type = RC_OPERAND_CONST;
self->value = (unsigned)value; self->value.num = (unsigned)value;
aux = end; aux = end;
break; 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->type = RC_OPERAND_CONST;
self->value = (unsigned)value; self->value.num = (unsigned)value;
aux = end; aux = end;
break; break;
@ -269,15 +273,15 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, rc_pa
case '+': case '-': case '+': case '-':
case '1': case '2': case '3': case '4': case '5': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': case '6': case '7': case '8': case '9':
self->fp_value = strtod(aux, &end); self->value.dbl = strtod(aux, &end);
if (end == aux) { if (end == aux) {
return RC_INVALID_FP_OPERAND; 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->type = RC_OPERAND_CONST;
self->value = (unsigned)floor(self->fp_value); self->value.num = (unsigned)floor(self->value.dbl);
} }
else { else {
self->type = RC_OPERAND_FP; 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) { switch (self->type) {
case RC_OPERAND_CONST: case RC_OPERAND_CONST:
value = self->value; value = self->value.num;
break; break;
case RC_OPERAND_FP: 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 #ifndef RC_DISABLE_LUA
if (L != 0) { if (L != 0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, self->function_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, self->value.luafunc);
lua_pushcfunction(L, rc_luapeek); lua_pushcfunction(L, rc_luapeek);
luapeek.peek = peek; luapeek.peek = peek;
@ -374,15 +378,15 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S
break; break;
case RC_OPERAND_ADDRESS: case RC_OPERAND_ADDRESS:
value = self->memref->value; value = self->value.memref->value;
break; break;
case RC_OPERAND_DELTA: case RC_OPERAND_DELTA:
value = self->memref->previous; value = self->value.memref->previous;
break; break;
case RC_OPERAND_PRIOR: case RC_OPERAND_PRIOR:
value = self->memref->prior; value = self->value.memref->prior;
break; break;
} }

View File

@ -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_ADDRESS:
case RC_OPERAND_DELTA: case RC_OPERAND_DELTA:
case RC_OPERAND_PRIOR: case RC_OPERAND_PRIOR:
size = self->operand2.memref->memref.size; size = self->operand2.value.memref->memref.size;
break; break;
default: default:
size = RC_MEMSIZE_32_BITS; size = RC_MEMSIZE_32_BITS;
@ -81,7 +81,7 @@ rc_term_t* rc_parse_term(const char** memaddr, rc_parse_state_t* parse) {
} }
else { else {
self->operand2.type = RC_OPERAND_CONST; self->operand2.type = RC_OPERAND_CONST;
self->operand2.value = 1; self->operand2.value.num = 1;
} }
*memaddr = aux; *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 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);
} }

View File

@ -121,8 +121,6 @@ HAVE_QT=auto # Qt companion support
C89_QT=no C89_QT=no
HAVE_XSHM=no # XShm video driver support HAVE_XSHM=no # XShm video driver support
HAVE_CHEEVOS=yes # Retro Achievements HAVE_CHEEVOS=yes # Retro Achievements
C89_CHEEVOS=no
CXX_CHEEVOS=no
HAVE_LUA=no # Lua support (for Retro Achievements) HAVE_LUA=no # Lua support (for Retro Achievements)
HAVE_DISCORD=yes # Discord Integration HAVE_DISCORD=yes # Discord Integration
C89_DISCORD=no C89_DISCORD=no