From e49f184f9b60c490bec2b27083756c61a51b0968 Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Mon, 19 Jul 2021 16:25:32 +0200 Subject: [PATCH] properly implement #REQUIRE (VER x.x.x, MINERVA, KEYS) --- Makefile | 3 +- source/script/compat.h | 1 + source/script/parser.c | 50 ++++++++++++++++++++------------- source/script/scriptError.h | 1 + source/tegraexplorer/mainmenu.c | 8 ++++-- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index f88173a..c9b3049 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ IPL_LOAD_ADDR := 0x40008000 LPVERSION_MAJOR := 3 LPVERSION_MINOR := 0 LPVERSION_BUGFX := 6 +LPVERSION := \"$(LPVERSION_MAJOR).$(LPVERSION_MINOR).$(LPVERSION_BUGFX)\" ################################################################################ @@ -40,7 +41,7 @@ FFCFG_INC := '"../$(SOURCEDIR)/libs/fatfs/ffconf.h"' ################################################################################ CUSTOMDEFINES := -DIPL_LOAD_ADDR=$(IPL_LOAD_ADDR) -CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) +CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX) -DLP_VER=$(LPVERSION) CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC) # 0: UART_A, 1: UART_B. diff --git a/source/script/compat.h b/source/script/compat.h index 63eebf3..0c594c5 100644 --- a/source/script/compat.h +++ b/source/script/compat.h @@ -9,6 +9,7 @@ #define LP_VER_MJ 3 #define LP_VER_MN 0 #define LP_VER_BF 5 + #define LP_VER "3.0.5" #define FREE(x) if (x) free(x) #define CpyStr(x) _strdup(x); #include "vector.h" diff --git a/source/script/parser.c b/source/script/parser.c index 0833042..100a73e 100644 --- a/source/script/parser.c +++ b/source/script/parser.c @@ -13,6 +13,10 @@ #include "scriptError.h" #include "standardLibrary.h" +#ifndef WIN32 +#include "../tegraexplorer/tconf.h" +#endif + static inline int isValidWord(char c) { char r = c | 0x20; return ((r >= 'a' && r <= 'z') || c == '_'); @@ -80,36 +84,42 @@ u8 nextToken(char** inPtr, void** val) { if (*in == '#') { if (!memcmp(in + 1, "REQUIRE ", 8)) { if (!memcmp(in + 9, "VER ", 4)) { - u8 vers[3] = { 0 }; char* verStart = in + 13; - for (u8 i = 0; i < 3; i++) { - while (isValidNum(*verStart)) { - vers[i] = vers[i] * 10 + *verStart++ - '0'; - } - verStart++; - } + char* verEnd = verStart; - u8 outdated = 0; - if (vers[0] > LP_VER_MJ) - outdated = 1; - else if (vers[0] == LP_VER_MJ) { - if (vers[1] > LP_VER_MN) - outdated = 1; - else if (vers[1] == LP_VER_MN) { - if (vers[2] > LP_VER_BF) - outdated = 1; - } + while (isValidNum(*verEnd) || *verEnd == '.') + verEnd++; + + u8 outdated = (verEnd - verStart != strlen(LP_VER)); + + if (!outdated){ + outdated = (memcmp(LP_VER, verStart, verEnd - verStart) < 0); } if (outdated) { - printScriptError(SCRIPT_FATAL, "Script requires TegraExplorer %d.%d.%d or up!", vers[0], vers[1], vers[2]); + printScriptError(SCRIPT_LEXER_FATAL, "Script requires a newer TegraExplorer version!"); return Token_Fatal_Err; } } else if (!memcmp(in + 9, "MINERVA", 7)) { - u8 minervaEnabled = 0; // TODO: Change this to the actual value + #ifdef WIN32 + u8 minervaEnabled = 0; + #else + u8 minervaEnabled = TConf.minervaEnabled; + #endif if (!minervaEnabled) { - printScriptError(SCRIPT_FATAL, "Extended memory required.\nPut the bootloader folder from hekate on your sd!"); + printScriptError(SCRIPT_LEXER_FATAL, "Extended memory required.\nPut the bootloader folder from hekate on your sd!"); + return Token_Fatal_Err; + } + } + else if (!memcmp(in + 9, "KEYS", 4)) { + #ifdef WIN32 + u8 gotKeys = 0; + #else + u8 gotKeys = TConf.keysDumped; + #endif + if (!gotKeys){ + printScriptError(SCRIPT_LEXER_FATAL, "Keys required.\nMake sure you're on the latest version of TegraExplorer!"); return Token_Fatal_Err; } } diff --git a/source/script/scriptError.h b/source/script/scriptError.h index 161c55f..8b4d74f 100644 --- a/source/script/scriptError.h +++ b/source/script/scriptError.h @@ -5,6 +5,7 @@ enum { SCRIPT_FATAL = 0, SCRIPT_PARSER_FATAL, SCRIPT_WARN, + SCRIPT_LEXER_FATAL, SCRIPT_BREAK, }; diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 48c2112..714593e 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -222,12 +222,14 @@ void EnterMainMenu(){ gfx_clearscreen(); gfx_putc('\n'); - res = newMenu(&ent, res, 79, 30, ALWAYSREDRAW, 0); + res = newMenu(&ent, res, 79, 30, (ent.count == ARRAY_SIZE(mainMenuEntries)) ? ALWAYSREDRAW : ALWAYSREDRAW | ENABLEPAGECOUNT, ent.count - ARRAY_SIZE(mainMenuEntries)); if (res < MainScripts && mainMenuPaths[res] != NULL) mainMenuPaths[res](); else if (hasScripts){ - vecDefArray(FSEntry_t*, scriptFilesArray, scriptFiles); - RunScript("sd:/tegraexplorer/scripts", scriptFilesArray[res - ARRAY_SIZE(mainMenuEntries)]); + vecDefArray(MenuEntry_t*, entArray, ent); + MenuEntry_t entry = entArray[res]; + FSEntry_t fsEntry = {.name = entry.name, .sizeUnion = entry.sizeUnion}; + RunScript("sd:/tegraexplorer/scripts", fsEntry); hidWait(); }