Files
Aldo Vargas 17ac584898 webMAN MOD 1.47.45
- Fixed script not disabling /dev_blind (use /dev_blind?0)
2023-11-22 19:42:34 -04:00

265 lines
9.5 KiB
C

// # remmark
// if/elseif/else/end
// if exist <path>
// if not exist <path>
// if L1
// if R1
// if cobra/nocobra/debug/mamba/ps3hen/dex/firmware x.xx
// if titleid <titleid/pattern>
// abort if exist <path>
// abort if not exist <path>
// :label
// goto label
// map <path>=<path>
// unmap <path>
// md <path>
// del <path>
// copy <path>=<path>
// fcopy <path>=<path>
// swap <path>=<path>
// ren <path>=<path>
// wait xmb
// wait <1-9 secs>
// wait <path>
// lwait <path>
// logfile <pah>
// log <text>
// popup <text>
// beep1 / beep2 / beep3 / ... beep9
// mute coldboot
// <webman_cmd> e.g. /mount.ps3<path>
#define EVENT_BOOT_INIT 0
#define EVENT_AUTOEXEC 1
#define EVENT_ON_XMB 2
#define EVENT_INGAME 3
#define EVENT_PER_GAME 4
#ifdef COPY_PS3
#if defined(WM_CUSTOM_COMBO) || defined(WM_REQUEST)
#define line buffer /* "line", "path" and "buffer" are synonyms */
#define path buffer /* "line", "path" and "buffer" are synonyms */
#define IS_WEB_COMMAND(line) (islike(line, "/mount") || strstr(line, ".ps3") || strstr(line, "_ps3") || strstr(line, ".lv1?") || strstr(line, ".lv2?"))
static void handle_file_request(const char *wm_url)
{
if(wm_url || file_exists(WM_REQUEST_FILE))
{
do_web_command(WM_FILE_REQUEST, wm_url);
}
}
static void parse_script(const char *script_file)
{
if(script_running) return;
if(file_exists(script_file))
{
u32 max_size = _64KB_;
sys_addr_t sysmem = sys_mem_allocate(max_size);
if(!sysmem) return;
char *buffer, *pos, *dest = NULL, label[24]; u16 l;
u8 exec_mode = true, enable_db = true, do_else = true; size_t buffer_size;
char log_file[STD_PATH_LEN]; strcpy(log_file, SC_LOG_FILE); *label = NULL;
reload_script:
buffer = (char*)sysmem; buffer_size = read_file(script_file, buffer, max_size, 0); buffer[buffer_size] = 0;
if(*buffer && !strchr(buffer, '\n')) strcat(buffer, "\n");
l = 0, script_running = true;
if(*label) {pos = strcasestr(buffer, label); if(pos) buffer = pos; else *buffer = NULL; *label = NULL;}
while(*buffer)
{
if(++l > 9999 || !working) break;
while( *buffer && (*buffer <= ' ')) buffer++; // skip blank chars \n \r \t
if(*buffer == '\0') break;
// process line
pos = strchr(line, '\n'); if(!pos) pos = line;
if(pos)
{
*pos = NULL; //EOL
replace_char(line, '\r', 0); // crlf
if(exec_mode)
{
if(IS_WEB_COMMAND(line))
dest = NULL;
else
{
dest = strstr(line, "=/");
if(!dest) dest = strstr(line, ",/");
if(!dest) dest = strstr(line, ", /");
}
if(enable_db && (strstr(line, "/dev_blind"))) {enable_dev_blind(NO_MSG); enable_db = false;}
}
parse_cmd:
if(dest)
{
*dest++ = NULL; while(*dest == ' ') dest++; //split parameters
char *wildcard = strchr(line, '*');
#ifdef COBRA_ONLY
if(_islike(line, "map /")) {line += 4;}
if(*line == '/') {check_path_tags(path); if(IS_WEB_COMMAND(line)) handle_file_request(line); else if(IS(path, "/app_home")) set_app_home(path); else sys_map_path(path, dest);} else
#else
if(*line == '/') {check_path_tags(path); if(IS_WEB_COMMAND(line)) handle_file_request(line);} else
#endif
if(_islike(line, "ren /")) {path += 4; check_path_tags(path); if(wildcard) {*wildcard++ = NULL; scan(path, true, wildcard, SCAN_RENAME, dest);} else rename_file(path, dest);} else
if(_islike(line, "copy /")) {path += 5; check_path_tags(path); if(wildcard) {*wildcard++ = NULL; scan(path, true, wildcard, SCAN_COPY, dest);} else if(isDir(path)) folder_copy(path, dest); else file_copy(path, dest);} else
if(_islike(line, "fcopy /")){path += 6; check_path_tags(path); if(wildcard) {*wildcard++ = NULL; scan(path, true, wildcard, SCAN_FCOPY, dest);} else if(isDir(path)) force_folder_copy(path, dest); else force_copy(path, dest);} else
if(_islike(line, "swap /")) {path += 5; check_path_tags(path); strcpy(cp_path, path); char *slash = get_filename(cp_path); sprintf(slash, "/~swap"); rename_file(path, cp_path); rename_file(dest, path); rename_file(cp_path, dest);} else
if(_islike(line, "move /")) {path += 5; check_path_tags(path); if(wildcard) {*wildcard++ = NULL; scan(path, true, wildcard, SCAN_MOVE, dest);} else rename_file(path, dest);} else
if(_islike(line, "list /")) {path += 5; check_path_tags(path); if(wildcard) {*wildcard++ = NULL;} scan(path, true, wildcard, SCAN_LIST, dest);} else
if(_islike(line, "cpbk /")) {path += 5; check_path_tags(path); if(wildcard) {*wildcard++ = NULL;} scan(path, true, wildcard, SCAN_COPYBK, dest);}
}
else if(*line == '#' || *line == ':' || *line == ';' || *line == '*') ; // remark
else if(_islike(line, "else") && do_else) {if(exec_mode) do_else = false; exec_mode ^= 1; line += 4; while(*line == ' ') line++; if(exec_mode && *line) goto parse_cmd;}
else if(_islike(line, "end")) {exec_mode = do_else = true;}
else if(exec_mode)
{
if(*line == '/') {if(islike(line, "/dev_blind?0")) disable_dev_blind(); else if(IS_WEB_COMMAND(line)) handle_file_request(line);} else
if(_islike(line, "goto ")) {snprintf(label, 24, ":%s", line + 5); goto reload_script;} else
if(_islike(line, "del /")) {path += 4; check_path_tags(path); char *wildcard = strchr(path, '*'); if(wildcard) {*wildcard++ = NULL; scan(path, true, wildcard, SCAN_DELETE, NULL);} else del(path, RECURSIVE_DELETE);} else
if(_islike(line, "md /")) {path += 3; check_path_tags(path); mkdir_tree(path);} else
if(_islike(line, "wait xmb")) {wait_for_xmb();} else
if(_islike(line, "wait /")) {path += 5; check_path_tags(path); wait_for(path, 5);} else
if(_islike(line, "wait ")) {line += 5; sys_ppu_thread_sleep((u8)val(line));} else
if(_islike(line, "lwait /")) {path += 6; check_path_tags(path); wait_for(path, 10);} else
#ifdef PS3MAPI
if(_islike(line, "beep")) {play_sound_id((u8)(line[4]));} else
#else
if(_islike(line, "beep")) {if(line[4] == '3') {BEEP3;} else if(line[4] == '2') {BEEP2;} else {BEEP1;}} else
#endif
if(_islike(line, "popup ")) {line += 6; parse_tags(line); show_msg(line);} else
if(_islike(line, "log ")) {line += 4; parse_tags(line); save_file(log_file, line, APPEND_TEXT);} else
if(_islike(line, "logfile /")) {path += 8; check_path_tags(path); strcpy(log_file, path);} else
#ifdef UNLOCK_SAVEDATA
if(_islike(line, "unlock /")) {path += 7; scan(path, true, "/PARAM.SFO", SCAN_UNLOCK_SAVE, NULL);} else
#endif
#ifdef COBRA_ONLY
if(_islike(line, "unmap /")) {path += 6; sys_map_path(path, NULL);} else
if(_islike(line, "mute coldboot"))
{
sys_map_path(VSH_RESOURCE_DIR "coldboot_stereo.ac3", SYSMAP_EMPTY_DIR);
sys_map_path(VSH_RESOURCE_DIR "coldboot_multi.ac3", SYSMAP_EMPTY_DIR);
}
else
#endif
if(_islike(line, "if ") || _islike(line, "abort if "))
{
#define ABORT_IF 9
bool ret = false; u8 ifmode = (_islike(line, "if ")) ? 3 : ABORT_IF; line += ifmode; do_else = true;
if(_islike(line, "exist /")) {path += 6; check_path_tags(path); ret = file_exists(path);} else
if(_islike(line, "not exist /")) {path += 10; check_path_tags(path); ret = not_exists(path);} else
if(_islike(line, "Firmware")) {line += 9; ret = IS(fw_version, line);} else
if(_islike(line, "noCobra")) {ret = !cobra_version;} else
#if defined(PS3MAPI) || defined(DEBUG_MEM)
if(_islike(line, "titleid ")){path += 8; get_game_info(); ret = (strlen(_game_TitleID) >= strlen(path)) ? bcompare(_game_TitleID, path, strlen(path), path) : 0;} else
#endif
#ifdef COBRA_ONLY
if(_islike(line, "Cobra")) {ret = cobra_version;} else
if(_islike(line, "Debug")) {ret = isCobraDebug;} else
if(_islike(line, "Mamba")) {ret = is_mamba;} else
if(_islike(line, "PS3HEN")) {ret = payload_ps3hen;} else
#endif
if(_islike(line, "DEX")) {ret = dex_mode;} else
{
// check for hold L1 or R1 in script
if(_islike(line, "L1")) ret = is_pressed(CELL_PAD_CTRL_L1);
if(_islike(line, "R1")) ret = is_pressed(CELL_PAD_CTRL_R1);
}
if(ifmode == ABORT_IF) {if(ret) break;} else if(!ret) exec_mode = false;
}
}
buffer = pos + 1, dest = NULL;
}
else
break;
}
sys_memory_free(sysmem);
script_running = false;
disable_progress();
}
}
static void script_thread(u64 event_id)
{
if(event_id == EVENT_PER_GAME)
{
get_game_info();
if(strlen(_game_TitleID) >= 9)
{
char script_file[40];
snprintf(script_file, sizeof(script_file), "%s/%s%s", WM_INGAME_PATH, _game_TitleID, ".bat");
parse_script(script_file);
}
}
else
parse_script(script_events[event_id]);
sys_ppu_thread_exit(0);
}
static void start_event(u8 event_id)
{
if((event_id < EVENT_PER_GAME) && not_exists(script_events[event_id])) return;
if(wm_reload) return;
if(event_id == EVENT_ON_XMB)
{
wait_for_xmb();
sys_ppu_thread_sleep(3);
}
sys_ppu_thread_t t_id;
sys_ppu_thread_create(&t_id, script_thread, event_id, THREAD_PRIO, THREAD_STACK_SIZE_SCRIPT, SYS_PPU_THREAD_CREATE_NORMAL, THREAD_NAME_CMD);
}
#undef line
#undef path
#undef IS_WEB_COMMAND
static bool do_custom_combo(const char *filename)
{
#ifdef WM_CUSTOM_COMBO
char combo_file[128];
if(*filename == '/')
snprintf(combo_file, 127, "%s", filename);
else
snprintf(combo_file, 127, "%s%s", WM_CUSTOM_COMBO, filename); // use default path
#else
const char *combo_file = filename;
#endif
if(file_exists(combo_file))
{
parse_script(combo_file);
sys_ppu_thread_sleep(2);
return true;
}
return false;
}
#endif
#else
#define start_event(a)
#endif // #ifdef COPY_PS3