From fc7c12c2576b021ad81a42094036a21d3ed451a0 Mon Sep 17 00:00:00 2001 From: anod <182859762@qq.com> Date: Sat, 11 Mar 2023 12:28:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8F=92=E5=80=BC=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/arm11/cheat.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/source/arm11/cheat.c b/source/arm11/cheat.c index d9b2a1a..5426541 100644 --- a/source/arm11/cheat.c +++ b/source/arm11/cheat.c @@ -19,10 +19,11 @@ typedef instruction_t* CodeLocation; typedef struct { u32 chtId; // acl_chtid_t u16 entLen; // entArr.length - acl_index_t *entArr; // 下标表示hole,值表示key + acl_index_t *entArr; // 下标表示hole,值表示key *改为分两段,前段key,后段overwrite value } CurrentCheat; static CurrentCheat setting = {0, 0, NULL}; +#define CCHT_OVERWRITE(c) (&c.entArr[c.entLen]) cheat_error_t init_current_cheat( u32 id, u16 len ) { @@ -33,9 +34,9 @@ cheat_error_t init_current_cheat( u32 id, u16 len ) setting.entLen = len; if( len ) { - acl_index_t *p = (acl_index_t*)malloc( len * sizeof(acl_index_t) ); + acl_index_t *p = (acl_index_t*)malloc( len * sizeof(acl_index_t) * 2 ); if( p == NULL ) return CCHT_NO_MEM; - memset(p, 0, len*sizeof(acl_index_t)); + memset(p, 0, len*sizeof(acl_index_t)*2); setting.entArr = p; } return CCHT_OK; @@ -56,6 +57,23 @@ cheat_error_t put_current_cheat( acl_entryid_t entid ) else return CCHT_INVALID; } +cheat_error_t overwrite_current_cheat( acl_entryid_t id, u16 value ) +{ + if( setting.chtId == 0 ) return CCHT_NOT_INIT; + + u16 index = ENT_HOLE(id); + u16 option = ENT_KEY(id); + if( index == 0 ) return CCHT_INVALID; + + if( index <= setting.entLen ) + { + u16 *valarr = CCHT_OVERWRITE(setting); + valarr[index-1] = value; + return CCHT_OK; + } + else return CCHT_INVALID; +} + cheat_error_t info_current_cheat( u32 *id, u32 *len ) { if( setting.chtId == 0 ) return CCHT_NOT_INIT; @@ -76,11 +94,6 @@ cheat_error_t get_current_cheat( u32 index, acl_entryid_t *id ) else return CCHT_INVALID; } -cheat_error_t overwrite_current_cheat( acl_entryid_t id, u16 value ) -{ - -} - cheat_error_t include_current_cheat( acl_entryid_t id ) { if( setting.chtId == 0 ) return CCHT_NOT_INIT; @@ -408,6 +421,7 @@ static void rom_append_cheatproc( int mode, CodeLocation start, u16 bindkey, u32 memcpy( start, MEM_OVERWRITE_INSTR, MO_INSTR_SIZE ); start += MO_INSTR_LEN; + u16 overwrite = CCHT_OVERWRITE(setting); for( int i=0; i < setting.entLen; ++i ) { u16 val = setting.entArr[i]; @@ -415,9 +429,17 @@ static void rom_append_cheatproc( int mode, CodeLocation start, u16 bindkey, u32 { acl_elemlen_t len; acl_select_entry( MAKE_ENT(i+1, val), &len ); + val = overwrite[i]; for( int j=0; j < len; ++j ) { - acl_entry_get_armcode(j, start++); + if( (val > 0) && (j & 1) ) + { + acl_armcode_t temp; + acl_entry_get_armcode(j, &temp); + *start++ = (temp & ~(0xff)) | (val & 0xff); + val >>= 8; + } + else acl_entry_get_armcode(j, start++); } } }