From 00549779f885752b6dd67df8486ff7b3a104eb91 Mon Sep 17 00:00:00 2001 From: Anod Date: Thu, 23 Feb 2023 13:52:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=EF=BC=8C=E6=8D=A2=E4=B8=80=E5=8F=B0=E7=94=B5?= =?UTF-8?q?=E8=84=91=E7=BB=A7=E7=BB=AD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arm11/cheat.h | 22 ++++++++++++++++++++++ include/arm11/filebrowser.h | 2 -- source/arm11/cheat.c | 7 +++++++ source/arm11/filebrowser.c | 19 ++++++++++++++++--- source/arm11/open_agb_firm.c | 34 ++++++++++++++++++++++++++++++---- 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 include/arm11/cheat.h create mode 100644 source/arm11/cheat.c diff --git a/include/arm11/cheat.h b/include/arm11/cheat.h new file mode 100644 index 0000000..a34ff3d --- /dev/null +++ b/include/arm11/cheat.h @@ -0,0 +1,22 @@ +#ifndef _CHEAT_H_ +#define _CHEAT_H_ + +#include "types.h" + +typedef int cheat_error_t; + +#define CCHT_OK 0 + +cheat_error_t init_current_cheat( u32 id, u32 len ); +cheat_error_t put_current_cheat( u32 index, u32 entry_id ); +cheat_error_t get_current_cheat( u32 *id, u32 *len, u32 *entry_array ); +cheat_error_t fini_current_cheat(); + +cheat_error_t push_current_cheat( const char *filename, int is_using ); +cheat_error_t pop_current_cheat( const char *filename, u32 chtid ); +cheat_error_t chtid_current_cheat( const char *filename, u32 *pointer_id ); +cheat_error_t chtlst_current_cheat( const char *filename, u8 pointer_data[256] ); + +cheat_error_t apply_cheat( int mode, int szrom ); + +#endif//_CHEAT_H_ diff --git a/include/arm11/filebrowser.h b/include/arm11/filebrowser.h index 7485675..243723e 100644 --- a/include/arm11/filebrowser.h +++ b/include/arm11/filebrowser.h @@ -20,6 +20,4 @@ #include "error_codes.h" - - Result browseFiles(const char *const basePath, char selected[512]); diff --git a/source/arm11/cheat.c b/source/arm11/cheat.c new file mode 100644 index 0000000..6d04457 --- /dev/null +++ b/source/arm11/cheat.c @@ -0,0 +1,7 @@ +#include "arm11/cheat.h" + +typedef struct { + u32 chtId; + u8 entLen; + u32 *entArr; +} CurrentCheat; diff --git a/source/arm11/filebrowser.c b/source/arm11/filebrowser.c index b50b0f2..8186e6e 100644 --- a/source/arm11/filebrowser.c +++ b/source/arm11/filebrowser.c @@ -29,6 +29,7 @@ #include "arm11/acf.h" #include "arm11/atp.h" #include "arm11/acl.h" +#include "arm11/cheat.h" #define screenClean() memset(consoleGet()->frameBuffer, 0, CWIDTH*CHEIGHT*sizeof(uint16_t)) @@ -235,11 +236,13 @@ static atp_error_t disp_str( atp_callerdata_t data, atp_counter_t, atp_linecfg_t } #define DEBUG( str ) atp_show(1, disp_str, str) -static atp_error_t select_region( atp_callerdata_t, atp_counter_t index, atp_itemcfg_t *config ) +static atp_error_t select_region( atp_callerdata_t *dat, atp_counter_t index, atp_itemcfg_t *config ) { static char text[16]; + u32 id = *(u32*)dat; acl_region_t sreg; - if( ACHTLIB_SUCCESS != acl_query_cheat_set(index, NULL, &sreg) ) + acl_chtid_t sid; + if( ACHTLIB_SUCCESS != acl_query_cheat_set(index, &sid, &sreg) ) { config->text = "无效数据"; config->value = index; @@ -260,6 +263,8 @@ static atp_error_t select_region( atp_callerdata_t, atp_counter_t index, atp_ite ee_sprintf(text, "%c-%s", 'A'+(char)index, t); config->text = text; config->value = index; + config->extra_text = sid == id ? "已启用" : "未启用"; + config->extra_text_color = sid == id ? ATP_COLOR_GREEN : ATP_COLOR_LIGHT; return ATP_SUCCESS; } @@ -379,17 +384,25 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a uint8_t status = DISP_REGION; atp_counter_t defi = 0; acl_entryid_t eid = 0; + char cheat_cfg_file[9]; + strncpy(cheat_cfg_file, serial, 4); + strcpy(cheat_cfg_file+4, ".cht"); + cheat_cfg_file[8] = '\0'; while( status != DISP_DONE ) { if( status == DISP_REGION ) { - res = atp_select("选择一个金手指配置", len, select_region, NULL, NULL, defi, 0, &item ); + u8 all_cheat_ids[256]; + chtlst_current_cheat( cheat_cfg_file, all_cheat_ids ); + chtid_current_cheat( cheat_cfg_file, all_cheat_ids + sizeof(all_cheat_ids)-sizeof(u32) ); + res = atp_select("选择一个金手指配置", len, select_region, NULL, all_cheat_ids, defi, 0, &item ); if( res == ATP_SUCCESS ) { defi = item; acl_chtid_t sid; acl_query_cheat_set((acl_index_t)item, &sid, NULL ); acl_select_cheat_set( sid ); + pop_current_cheat( cheat_cfg_file, sid ); eid = 0; status = DISP_HOLES; } diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index 7132367..9a97d6d 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -66,6 +66,12 @@ #define SAVE_POLICY_POPUP 3 #define SAVE_POLICY_SIZE 4 +#define CHEAT_MODE_DISABLED 0 +#define CHEAT_MODE_FULLTIME 1 +#define CHEAT_MODE_ENABYKEY 2 +#define CHEAT_MODE_KEYONOFF 3 +#define CHEAT_MODE_SIZE 3 + typedef struct { // [general] @@ -90,6 +96,8 @@ typedef struct // [by-anod] u8 savePolicy; + u8 cheatMode; + u16 cheatKeys; } OafConfig; typedef struct @@ -100,7 +108,6 @@ typedef struct u32 attr; } GameDbEntry; - // Default config. static OafConfig g_oafConfig = { @@ -125,6 +132,8 @@ static OafConfig g_oafConfig = // [by-anod] , SAVE_POLICY_GBADB // savePolicy + , 0 // cheatMode + , KEY_L|KEY_R|KEY_DOWN|KEY_SELECT }; static KHandle g_frameReadyEvent = 0; @@ -135,9 +144,11 @@ atp_text_t config_help[] = { "全局参数编辑操作指引", "~ ~ ~ ~ ~ ~ ~", - "修改后的全局参数保存在config.ini", + "-修改后的全局参数保存在config.ini", "保存修改时,存档方案的修改不会保存", "~ ~ ~ ~ ~ ~ ~", + "-金手指组合键为下方向+L+R+SELECT", + "~ ~ ~ ~ ~ ~ ~", "上下方向键      切换参数项目", "左右方向键          翻页", "L键和R键      调整当前参数", @@ -157,7 +168,9 @@ atp_text_t CONFIG_OUTPUT = "[general]\n" \ "brightness=0.0\n\n" \ "[advanced]\n" \ "saveOverride=false\n" \ - "defaultSave=14"; + "defaultSave=14\n" \ + "[by-anod]\n" \ + "cheatMode=%d"; extern atp_error_t help_page( atp_text_t *wording, atp_counter_t length ); @@ -168,6 +181,7 @@ static atp_error_t config_item( atp_callerdata_t, atp_counter_t index, atp_itemc { const char *scaler_val[] = {"上屏无缩放", "上屏GPU放大", "上屏DMA放大", "下屏无缩放"}; const char *savetype_name[] = {"和卡带序列号一致", "读取ROM的特定标记", "汉化带SRAM补丁", "自行决定"}; + const char *cheatmode_name[] = {"关闭金手指", "全程激活", "组合键单次激活", "组合键激活/关闭"}; static char buf[16]; cfg->extra_text_color = ATP_COLOR_GREEN; if( index == 0 ) @@ -193,6 +207,11 @@ static atp_error_t config_item( atp_callerdata_t, atp_counter_t index, atp_itemc cfg->text = "存档方案"; cfg->extra_text = savetype_name[g_oafConfig.savePolicy]; } + else if( index == 4 ) + { + cfg->text = "激活金手指"; + cfg->extra_text = cheatmode_name[g_oafConfig.cheatMode]; + } cfg->value = index; return ATP_SUCCESS; } @@ -221,6 +240,7 @@ static atp_pageopt_t config_adjust( atp_callerdata_t, atp_counter_t index, atp_b else if( index == 1 ) g_oafConfig.directBoot = !g_oafConfig.directBoot; else if( index == 2 ) g_oafConfig.scaler = ( SCALER_SIZE + ( g_oafConfig.scaler+(l?-1:1) ) ) % SCALER_SIZE; else if( index == 3 ) g_oafConfig.savePolicy = ( SAVE_POLICY_SIZE + ( g_oafConfig.savePolicy+(l?-1:1) ) ) % SAVE_POLICY_SIZE; + else if( index == 4 ) g_oafConfig.cheatMode = ( CHEAT_MODE_SIZE + (g_oafConfig.cheatMode+(l?-1:1) ) ) % CHEAT_MODE_SIZE; } else if( start ) { @@ -236,7 +256,7 @@ static atp_pageopt_t config_adjust( atp_callerdata_t, atp_counter_t index, atp_b ee_snprintf( data, len, CONFIG_OUTPUT, - g_oafConfig.backlight, g_oafConfig.directBoot ? "true":"false", g_oafConfig.scaler + g_oafConfig.backlight, g_oafConfig.directBoot ? "true":"false", g_oafConfig.scaler, g_oafConfig.cheatMode ); fsQuickWrite("config.ini", data, strlen(data)); free( data ); @@ -823,6 +843,12 @@ static int cfgIniCallback(void* user, const char* section, const char* name, con if(strcmp(name, "defaultSave") == 0) config->defaultSave = (u16)strtoul(value, NULL, 10); } + else if(strcmp(section, "by-anod") == 0) + { + if( strcmp(name, "cheatMode") == 0 ) + config->cheatMode = (u8)strtoul(value, NULL, 10); + if( config->cheatMode > CHEAT_MODE_SIZE ) config->cheatMode = CHEAT_MODE_DISABLED; + } else return 0; // Error. return 1; // 1 is no error? Really?