Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use modified memref chain for mathematic rich presence macro values #385

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rc_runtime_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ struct rc_richpresence_display_part_t {
rc_richpresence_display_part_t* next;
const char* text;
rc_richpresence_lookup_t* lookup;
rc_memref_value_t* value;
rc_operand_t value;
uint8_t display_type;
};

Expand Down
52 changes: 52 additions & 0 deletions src/rcheevos/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,58 @@ char* rc_alloc_str(rc_parse_state_t* parse, const char* text, size_t length) {
return ptr;
}

void rc_sync_operand(rc_operand_t* operand, rc_parse_state_t* parse, const rc_memref_t* memrefs)
{
if (rc_operand_is_memref(operand) || rc_operand_is_recall(operand)) {
const rc_memref_t* src_memref = operand->value.memref;
const rc_memref_t* memref;

memref = memrefs;
while (memref && memref != src_memref)
memref = memref->next;

if (memref) {
switch (memref->value.memref_type) {
case RC_MEMREF_TYPE_MEMREF:
operand->value.memref = rc_alloc_memref(parse, memref->address, memref->value.size);
break;

case RC_MEMREF_TYPE_MODIFIED_MEMREF: {
const rc_modified_memref_t* modified_memref = (const rc_modified_memref_t*)memref;

rc_modified_memref_t* dst_modified_memref = rc_alloc_modified_memref(parse, modified_memref->memref.value.size,
&modified_memref->parent, modified_memref->modifier_type, &modified_memref->modifier);

operand->value.memref = &dst_modified_memref->memref;
break;
}
}
}
}
}

void rc_copy_memrefs_into_parse_state(rc_parse_state_t* parse, rc_memref_t* memrefs)
{
rc_memref_t* memref;
for (memref = memrefs; memref; memref = memref->next) {
switch (memref->value.memref_type) {
case RC_MEMREF_TYPE_MEMREF:
rc_alloc_memref(parse, memref->address, memref->value.size);
break;

case RC_MEMREF_TYPE_MODIFIED_MEMREF: {
rc_modified_memref_t* modified_memref = (rc_modified_memref_t*)memref;
rc_sync_operand(&modified_memref->parent, parse, memrefs);
rc_sync_operand(&modified_memref->modifier, parse, memrefs);

rc_alloc_modified_memref(parse, modified_memref->memref.value.size,
&modified_memref->parent, modified_memref->modifier_type, &modified_memref->modifier);
break;
}
}
}
}

void rc_init_parse_state(rc_parse_state_t* parse, void* buffer, lua_State* L, int funcs_ndx)
{
/* could use memset here, but rc_parse_state_t contains a 512 byte buffer that doesn't need to be initialized */
Expand Down
2 changes: 1 addition & 1 deletion src/rcheevos/operand.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ int rc_operand_is_float(const rc_operand_t* self) {
return rc_operand_is_float_memref(self);
}

uint32_t rc_transform_operand_value(uint32_t value, const rc_operand_t* self) {
static uint32_t rc_transform_operand_value(uint32_t value, const rc_operand_t* self) {
switch (self->type)
{
case RC_OPERAND_BCD:
Expand Down
14 changes: 13 additions & 1 deletion src/rcheevos/rc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ typedef struct __rc_value_type_enum_t { uint8_t value; } __rc_value_type_enum_t;
typedef struct __rc_memref_type_enum_t { uint8_t value; } __rc_memref_type_enum_t;
typedef struct __rc_condition_enum_t { uint8_t value; } __rc_condition_enum_t;
typedef struct __rc_condition_enum_str_t { uint8_t value; } __rc_condition_enum_str_t;
typedef struct __rc_condset_list_t { rc_condset_t* first_condset; } __rc_condset_list_t;
typedef struct __rc_operator_enum_t { uint8_t value; } __rc_operator_enum_t;
typedef struct __rc_operator_enum_str_t { uint8_t value; } __rc_operator_enum_str_t;
typedef struct __rc_operand_memref_t { rc_operand_t operand; } __rc_operand_memref_t; /* requires &rc_operand_t to be the same as &rc_operand_t.value.memref */
typedef struct __rc_memref_list_t { rc_memref_t* first_memref; } __rc_memref_list_t;
typedef struct __rc_value_list_t { rc_value_t* first_value; } __rc_value_list_t;
typedef struct __rc_trigger_state_enum_t { uint8_t value; } __rc_trigger_state_enum_t;
typedef struct __rc_lboard_state_enum_t { uint8_t value; } __rc_lboard_state_enum_t;
typedef struct __rc_richpresence_display_list_t { rc_richpresence_display_t* first_display; } __rc_richpresence_display_list_t;
typedef struct __rc_richpresence_display_part_list_t { rc_richpresence_display_part_t* display; } __rc_richpresence_display_part_list_t;
typedef struct __rc_richpresence_lookup_list_t { rc_richpresence_lookup_t* first_lookup; } __rc_richpresence_lookup_list_t;
typedef struct __rc_format_enum_t { uint8_t value; } __rc_format_enum_t;

#define RC_ALLOW_ALIGN(T) struct __align_ ## T { uint8_t ch; T t; };

Expand Down Expand Up @@ -103,13 +108,18 @@ typedef struct {
__rc_memref_type_enum_t memref_type;
__rc_condition_enum_t condition;
__rc_condition_enum_str_t condition_str;
__rc_condset_list_t condset_list;
__rc_operator_enum_t oper;
__rc_operator_enum_str_t oper_str;
__rc_operand_memref_t operand_memref;
__rc_memref_list_t memref_list;
__rc_value_list_t value_list;
__rc_trigger_state_enum_t trigger_state;
__rc_lboard_state_enum_t lboard_state;
__rc_richpresence_display_list_t richpresence_display_list;
__rc_richpresence_display_part_list_t richpresence_display_part_list;
__rc_richpresence_lookup_list_t richpresence_lookup_list;
__rc_format_enum_t format;
} natvis_extension;
} objs;
}
Expand Down Expand Up @@ -201,6 +211,8 @@ void rc_init_parse_state(rc_parse_state_t* parse, void* buffer, lua_State* L, in
void rc_init_parse_state_memrefs(rc_parse_state_t* parse, rc_memref_t** memrefs);
void rc_init_parse_state_variables(rc_parse_state_t* parse, rc_value_t** variables);
void rc_destroy_parse_state(rc_parse_state_t* parse);
void rc_copy_memrefs_into_parse_state(rc_parse_state_t* parse, rc_memref_t* memrefs);
void rc_sync_operand(rc_operand_t* operand, rc_parse_state_t* parse, const rc_memref_t* memrefs);

void* rc_alloc(void* pointer, int32_t* offset, uint32_t size, uint32_t alignment, rc_scratch_t* scratch, uint32_t scratch_object_pointer_offset);
void* rc_alloc_scratch(void* pointer, int32_t* offset, uint32_t size, uint32_t alignment, rc_scratch_t* scratch, uint32_t scratch_object_pointer_offset);
Expand Down Expand Up @@ -274,7 +286,7 @@ void rc_parse_value_internal(rc_value_t* self, const char** memaddr, rc_parse_st
int rc_evaluate_value_typed(rc_value_t* self, rc_typed_value_t* value, rc_peek_t peek, void* ud, lua_State* L);
void rc_reset_value(rc_value_t* self);
int rc_value_from_hits(rc_value_t* self);
rc_value_t* rc_alloc_helper_variable(const char* memaddr, size_t memaddr_len, rc_parse_state_t* parse);
rc_value_t* rc_alloc_variable(const char* memaddr, size_t memaddr_len, rc_parse_state_t* parse);
void rc_update_variables(rc_value_t* variable, rc_peek_t peek, void* ud, lua_State* L);

void rc_typed_value_convert(rc_typed_value_t* value, char new_type);
Expand Down
142 changes: 136 additions & 6 deletions src/rcheevos/rc_runtime_types.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
</Type>
<Type Name="rc_memref_t">
<DisplayString Condition="value.memref_type==RC_MEMREF_TYPE_MODIFIED_MEMREF">{*(rc_modified_memref_t*)&amp;value}</DisplayString>
<DisplayString Condition="value.memref_type==RC_MEMREF_TYPE_VALUE">{*(rc_value_t*)&amp;value}</DisplayString>
<DisplayString Condition="value.size==RC_MEMSIZE_VARIABLE">var</DisplayString>
<DisplayString>{*((__rc_memsize_enum_func_t*)&amp;value.size)}({address,x})</DisplayString>
<Expand>
Expand All @@ -109,6 +110,7 @@
</Type>
<Type Name="__rc_operand_memref_t">
<DisplayString Condition="operand.value.memref->value.memref_type==RC_MEMREF_TYPE_MODIFIED_MEMREF">... {*((__rc_memsize_enum_func_t*)&amp;operand.size)} {operand.value.memref->address,x}</DisplayString>
<DisplayString Condition="operand.value.memref->value.memref_type==RC_MEMREF_TYPE_VALUE">value {((rc_value_t*)operand.value.memref)->name,s}</DisplayString>
<DisplayString>{*((__rc_memsize_enum_func_t*)&amp;operand.size)} {operand.value.memref->address,x}</DisplayString>
<Expand>
<Item Name="[rc_modified_memref_t]" Condition="operand.value.memref->value.memref_type==RC_MEMREF_TYPE_MODIFIED_MEMREF">(rc_modified_memref_t*)&amp;operand.value</Item>
Expand Down Expand Up @@ -256,6 +258,16 @@
</LinkedListItems>
</Expand>
</Type>
<Type Name="__rc_condset_list_t">
<DisplayString Condition="first_condset==0">{{}}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>first_condset</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="rc_modified_memref_t">
<DisplayString Condition="modifier_type==RC_OPERATOR_INDIRECT_READ">$({parent} + {modifier})</DisplayString>
<DisplayString Condition="modifier_type==RC_OPERATOR_SUB_PARENT">({modifier} - {parent})</DisplayString>
Expand Down Expand Up @@ -284,12 +296,8 @@
<Item Name="has_hits">*((__rc_bool_enum_t*)&amp;has_hits)</Item>
<Item Name="has_required_hits">*((__rc_bool_enum_t*)&amp;has_required_hits)</Item>
<Item Name="measured_as_percent">*((__rc_bool_enum_t*)&amp;measured_as_percent)</Item>
<Item Name="requirement">*requirement</Item>
<LinkedListItems>
<HeadPointer>alternative</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
<Item Name="requirement">requirement</Item>
<Item Name="alternative">*((__rc_condset_list_t*)&amp;alternative)</Item>
</Expand>
</Type>
<Type Name="rc_value_t">
Expand Down Expand Up @@ -332,6 +340,109 @@
</LinkedListItems>
</Expand>
</Type>
<Type Name="__rc_format_enum_t">
<DisplayString Condition="value==RC_FORMAT_FRAMES">{RC_FORMAT_FRAMES}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_SECONDS">{RC_FORMAT_SECONDS}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_CENTISECS">{RC_FORMAT_CENTISECS}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_SCORE">{RC_FORMAT_SCORE}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_VALUE">{RC_FORMAT_VALUE}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_MINUTES">{RC_FORMAT_MINUTES}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_SECONDS_AS_MINUTES">{RC_FORMAT_SECONDS_AS_MINUTES}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT1">{RC_FORMAT_FLOAT1}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT2">{RC_FORMAT_FLOAT2}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT3">{RC_FORMAT_FLOAT3}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT4">{RC_FORMAT_FLOAT4}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT5">{RC_FORMAT_FLOAT5}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FLOAT6">{RC_FORMAT_FLOAT6}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FIXED1">{RC_FORMAT_FIXED1}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FIXED2">{RC_FORMAT_FIXED2}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_FIXED3">{RC_FORMAT_FIXED3}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_TENS">{RC_FORMAT_TENS}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_HUNDREDS">{RC_FORMAT_HUNDREDS}</DisplayString>
<DisplayString Condition="value==RC_FORMAT_THOUSANDS">{RC_FORMAT_THOUSANDS}</DisplayString>
<DisplayString Condition="value==101">RC_FORMAT_STRING (101)</DisplayString>
<DisplayString Condition="value==102">RC_FORMAT_LOOKUP (102)</DisplayString>
<DisplayString Condition="value==103">RC_FORMAT_UNKNOWN_MACRO (103)</DisplayString>
<DisplayString Condition="value==104">RC_FORMAT_ASCIICHAR (104)</DisplayString>
<DisplayString Condition="value==105">RC_FORMAT_UNICODECHAR (105)</DisplayString>
<DisplayString>unknown ({value})</DisplayString>
</Type>
<Type Name="rc_richpresence_display_part_t">
<DisplayString Condition="display_type==101">{text,s}</DisplayString>
<DisplayString Condition="display_type==103">[Unknown macro]{text,sb}</DisplayString>
<DisplayString Condition="lookup==0">@{text,sb}({value,na})</DisplayString>
<DisplayString>@{lookup->name,sb}({value,na})</DisplayString>
<Expand>
<Item Name="text" Condition="display_type==101||display_type==103">text</Item>
<Item Name="lookup" Condition="display_type!=101&amp;&amp;display_type!=103">lookup</Item>
<Item Name="value" Condition="display_type!=101&amp;&amp;display_type!=103">value</Item>
<Item Name="display_type">*((__rc_format_enum_t*)&amp;display_type)</Item>
</Expand>
</Type>
<Type Name="__rc_richpresence_display_part_list_t">
<DisplayString Condition="display->next->next!=0">{display,na} {display->next,na} {display->next->next,na}</DisplayString>
<DisplayString Condition="display->next!=0">{display,na} {display->next,na}</DisplayString>
<DisplayString>{display,na}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>display</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="rc_richpresence_display_t">
<Expand>
<Item Name="displays">*((__rc_richpresence_display_part_list_t*)&amp;display)</Item>
<Item Name="trigger">trigger</Item>
</Expand>
</Type>
<Type Name="__rc_richpresence_display_list_t">
<DisplayString Condition="first_display==0">{{NULL}}</DisplayString>
<DisplayString>{(void*)&amp;first_display,na}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>first_display</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="rc_richpresence_lookup_item_t">
<DisplayString Condition="first==last">{first}: {label,na}</DisplayString>
<DisplayString>{first}-{last}: {label,na}</DisplayString>
</Type>
<Type Name="rc_richpresence_lookup_t">
<DisplayString>{name,na}</DisplayString>
<Expand>
<Item Name="name">name</Item>
<Item Name="format">*((__rc_format_enum_t*)&amp;format)</Item>
<Item Name="default_label" Condition="format>101">default_label</Item>
<TreeItems>
<HeadPointer>root</HeadPointer>
<LeftPointer>left</LeftPointer>
<RightPointer>right</RightPointer>
<ValueNode>this</ValueNode>
</TreeItems>
</Expand>
</Type>
<Type Name="__rc_richpresence_lookup_list_t">
<DisplayString Condition="first_lookup==0">{{NULL}}</DisplayString>
<DisplayString>{(void*)&amp;first_lookup,na}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>first_lookup</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="rc_richpresence_t">
<Expand>
<Item Name="displays">((__rc_richpresence_display_list_t*)&amp;first_display)</Item>
<Item Name="lookups">((__rc_richpresence_lookup_list_t*)&amp;first_lookup)</Item>
</Expand>
</Type>
<Type Name="__rc_value_list_t">
<DisplayString Condition="first_value==0">{{NULL}}</DisplayString>
<DisplayString>{(void*)&amp;first_value,na}</DisplayString>
Expand All @@ -358,6 +469,25 @@
<Item Name="measured_as_percent">*((__rc_bool_enum_t*)&amp;measured_as_percent)</Item>
</Expand>
</Type>
<Type Name="rc_buffer_chunk_t">
<DisplayString>{{used={write-start} size={end-start}}}</DisplayString>
<Expand>
<Item Name="[size]">end-start</Item>
<Item Name="[used]">write-start</Item>
<Item Name="[available]">end-write</Item>
<Item Name="next">next</Item>
</Expand>
</Type>
<Type Name="rc_buffer_t">
<DisplayString></DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>&amp;chunk</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="__rc_runtime_trigger_list_t">
<DisplayString>{{count={runtime.trigger_count}}}</DisplayString>
<Expand>
Expand Down
Loading
Loading