[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
This commit is contained in:
suchmememanyskill 2021-01-10 16:32:50 +01:00
parent 3f80693d9e
commit 963987d639
3 changed files with 70 additions and 23 deletions

View File

@ -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);
}

View File

@ -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(?)
};

View File

@ -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)