Skip to content

Commit

Permalink
Merge branch 'develop' into rp_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed May 4, 2019
2 parents 855a820 + bdaf7c6 commit 174df53
Show file tree
Hide file tree
Showing 17 changed files with 1,366 additions and 721 deletions.
101 changes: 65 additions & 36 deletions include/rcheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum {
RC_MISSING_SUBMIT = -15,
RC_MISSING_VALUE = -16,
RC_INVALID_LBOARD_FIELD = -17,
RC_MISSING_DISPLAY_STRING = -18
RC_MISSING_DISPLAY_STRING = -18,
RC_OUT_OF_MEMORY = -19
};

/*****************************************************************************\
Expand Down Expand Up @@ -83,27 +84,57 @@ enum {
typedef unsigned (*rc_peek_t)(unsigned address, unsigned num_bytes, void* ud);

/*****************************************************************************\
| Operands |
| Memory References |
\*****************************************************************************/

/* Sizes. */
enum {
RC_OPERAND_BIT_0,
RC_OPERAND_BIT_1,
RC_OPERAND_BIT_2,
RC_OPERAND_BIT_3,
RC_OPERAND_BIT_4,
RC_OPERAND_BIT_5,
RC_OPERAND_BIT_6,
RC_OPERAND_BIT_7,
RC_OPERAND_LOW,
RC_OPERAND_HIGH,
RC_OPERAND_8_BITS,
RC_OPERAND_16_BITS,
RC_OPERAND_24_BITS,
RC_OPERAND_32_BITS
RC_MEMSIZE_BIT_0,
RC_MEMSIZE_BIT_1,
RC_MEMSIZE_BIT_2,
RC_MEMSIZE_BIT_3,
RC_MEMSIZE_BIT_4,
RC_MEMSIZE_BIT_5,
RC_MEMSIZE_BIT_6,
RC_MEMSIZE_BIT_7,
RC_MEMSIZE_LOW,
RC_MEMSIZE_HIGH,
RC_MEMSIZE_8_BITS,
RC_MEMSIZE_16_BITS,
RC_MEMSIZE_24_BITS,
RC_MEMSIZE_32_BITS
};

typedef struct {
/* The memory address of this variable. */
unsigned address;
/* The size of the variable. */
char size;
/* True if the value is in BCD. */
char is_bcd;
} rc_memref_t;

typedef struct rc_memref_value_t rc_memref_value_t;

struct rc_memref_value_t {
/* The value of this memory reference. */
unsigned value;
/* The previous value of this memory reference. */
unsigned previous;
/* The last differing value of this memory reference. */
unsigned prior;

/* The referenced memory */
rc_memref_t memref;

/* The next memory reference in the chain */
rc_memref_value_t* next;
};

/*****************************************************************************\
| Operands |
\*****************************************************************************/

/* types */
enum {
RC_OPERAND_ADDRESS, /* Compare to the value of a live address in RAM. */
Expand All @@ -117,27 +148,17 @@ enum {
typedef struct {
union {
/* A value read from memory. */
struct {
/* The memory address or constant value of this variable. */
unsigned value;
/* The previous memory contents if RC_OPERAND_DELTA or RC_OPERAND_PRIOR. */
unsigned previous;
/* The last differing value if RC_OPERAND_PRIOR. */
unsigned prior;

/* The size of the variable. */
char size;
/* True if the value is in BCD. */
char is_bcd;
/* The type of the variable. */
};
rc_memref_value_t* memref;

/* 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;
}
Expand Down Expand Up @@ -171,9 +192,6 @@ enum {
typedef struct rc_condition_t rc_condition_t;

struct rc_condition_t {
/* The next condition in the chain. */
rc_condition_t* next;

/* The condition's operands. */
rc_operand_t operand1;
rc_operand_t operand2;
Expand All @@ -183,6 +201,9 @@ struct rc_condition_t {
/* Number of hits so far. */
unsigned current_hits;

/* The next condition in the chain. */
rc_condition_t* next;

/**
* Set if the condition needs to processed as part of the "check if paused"
* pass
Expand Down Expand Up @@ -222,6 +243,9 @@ typedef struct {

/* The list of sub condition sets in this test. */
rc_condset_t* alternative;

/* The memory references required by the trigger. */
rc_memref_value_t* memrefs;
}
rc_trigger_t;

Expand Down Expand Up @@ -262,6 +286,9 @@ struct rc_expression_t {
typedef struct {
/* The list of expression to evaluate. */
rc_expression_t* expressions;

/* The memory references required by the value. */
rc_memref_value_t* memrefs;
}
rc_value_t;

Expand All @@ -288,6 +315,7 @@ typedef struct {
rc_trigger_t cancel;
rc_value_t value;
rc_value_t* progress;
rc_memref_value_t* memrefs;

char started;
char submitted;
Expand Down Expand Up @@ -358,6 +386,7 @@ struct rc_richpresence_display_t {
typedef struct {
rc_richpresence_display_t* first_display;
rc_richpresence_lookup_t* first_lookup;
rc_memref_value_t* memrefs;
}
rc_richpresence_t;

Expand Down
30 changes: 26 additions & 4 deletions src/rcheevos/alloc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "internal.h"

#include <memory.h>
#include <stdlib.h>
#include <string.h>

void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t* scratch) {
void* ptr;
Expand All @@ -10,22 +11,43 @@ void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t
if (pointer != 0) {
ptr = (void*)((char*)pointer + *offset);
}
else if (scratch != 0) {
ptr = &scratch->obj;
}
else {
ptr = scratch;
ptr = 0;
}

*offset += size;
return ptr;
}

char* rc_alloc_str(void* pointer, int* offset, const char* text, int length) {
char* rc_alloc_str(rc_parse_state_t* parse, const char* text, int length) {
char* ptr;

ptr = (char*)rc_alloc(pointer, offset, length + 1, RC_ALIGNOF(char), 0);
ptr = (char*)rc_alloc(parse->buffer, &parse->offset, length + 1, RC_ALIGNOF(char), 0);
if (ptr) {
memcpy(ptr, text, length);
ptr[length] = '\0';
}

return ptr;
}

void rc_init_parse_state(rc_parse_state_t* parse, void* buffer, lua_State* L, int funcs_ndx)
{
parse->offset = 0;
parse->L = L;
parse->funcs_ndx = funcs_ndx;
parse->buffer = buffer;
parse->scratch.memref = parse->scratch.memref_buffer;
parse->scratch.memref_size = sizeof(parse->scratch.memref_buffer) / sizeof(parse->scratch.memref_buffer[0]);
parse->scratch.memref_count = 0;
parse->first_memref = 0;
}

void rc_destroy_parse_state(rc_parse_state_t* parse)
{
if (parse->scratch.memref != parse->scratch.memref_buffer)
free(parse->scratch.memref);
}
20 changes: 10 additions & 10 deletions src/rcheevos/condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include <stdlib.h>

rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) {
rc_condition_t* rc_parse_condition(const char** memaddr, rc_parse_state_t* parse) {
rc_condition_t* self;
const char* aux;
int ret2;

aux = *memaddr;
self = RC_ALLOC(rc_condition_t, buffer, ret, scratch);
self = RC_ALLOC(rc_condition_t, parse);
self->current_hits = 0;

if (*aux != 0 && aux[1] == ':') {
Expand All @@ -19,7 +19,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
case 'b': case 'B': self->type = RC_CONDITION_SUB_SOURCE; break;
case 'c': case 'C': self->type = RC_CONDITION_ADD_HITS; break;
case 'n': case 'N': self->type = RC_CONDITION_AND_NEXT; break;
default: *ret = RC_INVALID_CONDITION_TYPE; return 0;
default: parse->offset = RC_INVALID_CONDITION_TYPE; return 0;
}

aux += 2;
Expand All @@ -28,10 +28,10 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
self->type = RC_CONDITION_STANDARD;
}

ret2 = rc_parse_operand(&self->operand1, &aux, 1, L, funcs_ndx);
ret2 = rc_parse_operand(&self->operand1, &aux, 1, parse);

if (ret2 < 0) {
*ret = ret2;
parse->offset = ret2;
return 0;
}

Expand All @@ -45,7 +45,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
if (*aux++ != '=') {
/* fall through */
default:
*ret = RC_INVALID_OPERATOR;
parse->offset = RC_INVALID_OPERATOR;
return 0;
}

Expand Down Expand Up @@ -73,10 +73,10 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
break;
}

ret2 = rc_parse_operand(&self->operand2, &aux, 1, L, funcs_ndx);
ret2 = rc_parse_operand(&self->operand2, &aux, 1, parse);

if (ret2 < 0) {
*ret = ret2;
parse->offset = ret2;
return 0;
}

Expand All @@ -85,7 +85,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
self->required_hits = (unsigned)strtoul(++aux, &end, 10);

if (end == aux || *end != ')') {
*ret = RC_INVALID_REQUIRED_HITS;
parse->offset = RC_INVALID_REQUIRED_HITS;
return 0;
}

Expand All @@ -96,7 +96,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch
self->required_hits = (unsigned)strtoul(++aux, &end, 10);

if (end == aux || *end != '.') {
*ret = RC_INVALID_REQUIRED_HITS;
parse->offset = RC_INVALID_REQUIRED_HITS;
return 0;
}

Expand Down
16 changes: 11 additions & 5 deletions src/rcheevos/condset.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ static void rc_update_condition_pause(rc_condition_t* condition, int* in_pause)
}
}

rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) {
rc_condset_t* rc_parse_condset(const char** memaddr, rc_parse_state_t* parse) {
rc_condset_t* self;
rc_condition_t** next;
int in_pause;

self = RC_ALLOC(rc_condset_t, buffer, ret, scratch);
self = RC_ALLOC(rc_condset_t, parse);
self->has_pause = 0;
next = &self->conditions;

if (**memaddr == 'S' || **memaddr == 's' || !**memaddr) {
/* empty group - editor allows it, so we have to support it */
*next = 0;
return self;
}

for (;;) {
*next = rc_parse_condition(ret, buffer, scratch, memaddr, L, funcs_ndx);
*next = rc_parse_condition(memaddr, parse);

if (*ret < 0) {
if (parse->offset < 0) {
return 0;
}

Expand All @@ -52,7 +58,7 @@ rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, co
*next = 0;


if (buffer != 0) {
if (parse->buffer != 0) {
in_pause = 0;
rc_update_condition_pause(self->conditions, &in_pause);
}
Expand Down
8 changes: 4 additions & 4 deletions src/rcheevos/expression.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "internal.h"

rc_expression_t* rc_parse_expression(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) {
rc_expression_t* rc_parse_expression(const char** memaddr, rc_parse_state_t* parse) {
rc_expression_t* self;
rc_term_t** next;

self = RC_ALLOC(rc_expression_t, buffer, ret, scratch);
self = RC_ALLOC(rc_expression_t, parse);
next = &self->terms;

for (;;) {
*next = rc_parse_term(ret, buffer, scratch, memaddr, L, funcs_ndx);
*next = rc_parse_term(memaddr, parse);

if (*ret < 0) {
if (parse->offset < 0) {
return 0;
}

Expand Down
Loading

0 comments on commit 174df53

Please sign in to comment.