From 963987d639a812dcf5f4388a97f34d9eb5e36754 Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Sun, 10 Jan 2021 16:32:50 +0100 Subject: [PATCH] [script] add operators, add reboot to payload - Add a function to reboot to payload - Add an "Empty array" variable type that is created when you try to assign []. This will get filled with a valid entry upon first addition - Adds operator string array plus string --- source/script/args.c | 85 ++++++++++++++++++++++++++++----------- source/script/functions.c | 7 ++++ source/script/types.h | 1 + 3 files changed, 70 insertions(+), 23 deletions(-) diff --git a/source/script/args.c b/source/script/args.c index 9eb0cb9..ff53131 100644 --- a/source/script/args.c +++ b/source/script/args.c @@ -132,42 +132,44 @@ Variable_t getVarFromToken(scriptCtx_t* ctx, lexarToken_t* tokens, int* index, u val = executeFunction(ctx, tokens[i - 2].text, &tokens[i], argCount); - //val = IntValue(1); i += argCount; } ELIFTX(LSBracket) { i++; int argCount = distanceBetweenTokens(&tokens[i], maxLen - 1, LSBracket, RSBracket); - if (argCount <= 0) + if (argCount < 0) return ErrValue(ERRSYNTAX); - // ArrayVars should be a Vector_t containing Variable_t's. Not implemented yet! - Vector_t arrayVars = extractVars(ctx, &tokens[i], argCount); - Variable_t* variables = vecGetArray(Variable_t*, arrayVars); - int type = variables[0].varType; - if (!(type == StringType || type == IntType)) - return ErrValue(ERRINVALIDTYPE); + val.varType = EmptyArrayType; - val.varType = (type + 2); - val.free = 1; - val.vectorType = newVec((type == IntType) ? sizeof(int) : sizeof(char*), arrayVars.count); + if (argCount > 0){ + Vector_t arrayVars = extractVars(ctx, &tokens[i], argCount); + Variable_t* variables = vecGetArray(Variable_t*, arrayVars); + int type = variables[0].varType; + if (!(type == StringType || type == IntType)) + return ErrValue(ERRINVALIDTYPE); - for (int i = 0; i < arrayVars.count; i++) { - if (variables[i].varType != type) - return ErrValue(ERRINVALIDTYPE); // Free-ing issue!! + val.varType = (type + 2); + val.free = 1; + val.vectorType = newVec((type == IntType) ? sizeof(int) : sizeof(char*), arrayVars.count); - if (type == StringType) { - char* temp = CpyStr(variables[i].stringType); - vecAddElement(&val.vectorType, temp); - } - else { - vecAddElement(&val.vectorType, variables[i].integerType); + for (int j = 0; j < arrayVars.count; j++) { + if (variables[j].varType != type) + return ErrValue(ERRINVALIDTYPE); // Free-ing issue!! + + if (type == StringType) { + char* temp = CpyStr(variables[j].stringType); + vecAddElement(&val.vectorType, temp); + } + else { + vecAddElement(&val.vectorType, variables[j].integerType); + } } + + i += argCount; + freeVariableVector(&arrayVars); } - - i += argCount; - freeVariableVector(&arrayVars); } ELIFTX(LBracket) { i++; @@ -397,6 +399,43 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho else return ErrValue(ERRBADOPERATOR); } + else if (res.varType == EmptyArrayType && localOpToken == Plus){ + res.free = 1; + res.varType = val.varType + 2; + + if (val.varType == IntType){ + res.vectorType = newVec(sizeof(int), 4); + vecAddElem(&res.vectorType, val.integerType); + } + else if (val.varType == StringType) { + res.vectorType = newVec(sizeof(char*), 4); + char *temp = CpyStr(val.stringType); + vecAddElem(&res.vectorType, temp); + } + else + return ErrValue(ERRBADOPERATOR); + + freeVariable(val); + } + else if (res.varType == StringArrayType && val.varType == StringType){ + if (localOpToken == Plus){ + Vector_t new = vecCopy(&res.vectorType); + vecDefArray(char **, strings, new); + for (int j = 0; j < new.count; j++){ + strings[j] = CpyStr(strings[j]); + } + + freeVariable(res); + + char *temp = CpyStr(val.stringType); + vecAddElem(&new, temp); + + res.free = 1; + res.vectorType = new; + } + else + return ErrValue(ERRBADOPERATOR); + } else return ErrValue(ERRBADOPERATOR); } diff --git a/source/script/functions.c b/source/script/functions.c index 0ad3b67..57c06ae 100644 --- a/source/script/functions.c +++ b/source/script/functions.c @@ -396,6 +396,12 @@ scriptFunction(funcGetMs){ return varInt(get_tmr_ms()); } +extern int launch_payload(char *path); + +scriptFunction(funcLaunchPayload){ + return varInt(launch_payload(vars[0].stringType)); +} + u8 fiveInts[] = {IntType, IntType, IntType, IntType, IntType}; u8 singleIntArray[] = { IntArrayType }; u8 singleInt[] = { IntType }; @@ -448,6 +454,7 @@ functionStruct_t scriptFunctions[] = { {"ncaGetType", funcGetNcaType, 1, singleStr}, {"saveSign", funcSignSave, 1, singleStr}, {"timerMs", funcGetMs, 0, NULL}, + {"launchPayload", funcLaunchPayload, 1, singleStr}, // Left from old: keyboard(?) }; diff --git a/source/script/types.h b/source/script/types.h index c9f4063..e224c94 100644 --- a/source/script/types.h +++ b/source/script/types.h @@ -74,6 +74,7 @@ enum Variables { DictType, NullType, ErrType, + EmptyArrayType, }; typedef struct { // this is to keep track of how many {} we passed. Keep an internal var with the "indentation level", +1 for {, -1 for }. have an array with the following def on what to do (on func: enter, set indentation & jump back, on while, jump to while, use while as if, on if simply set true or false)