Add new functions to script and properly handle indexer save in the SystemWipe script
This commit is contained in:
@@ -65,6 +65,27 @@ int arrayClassAdd(Variable_t *caller, Variable_t *add){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arrayClassAddRange(Variable_t* caller, Variable_t* add)
|
||||
{
|
||||
// Check if IntArrayClass or StringArrayClass or ByteArrayClass
|
||||
if ((caller->variableType == IntArrayClass) || (caller->variableType == StringArrayClass) || (caller->variableType == ByteArrayClass)) {
|
||||
if (caller->variableType != add->variableType) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (s64 i = 0; i < add->solvedArray.vector.count; i++)
|
||||
{
|
||||
Variable_t v = arrayClassGetIdx(add, i);
|
||||
if (arrayClassAdd(caller, &v))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ClassFunction(getArrayIdx) {
|
||||
s64 getVal = (*args)->integer.value;
|
||||
// Out of bounds
|
||||
@@ -167,6 +188,20 @@ ClassFunction(arrayAdd) {
|
||||
return &emptyClass;
|
||||
}
|
||||
|
||||
ClassFunction(arrayAddRange) {
|
||||
Variable_t* arg = *args;
|
||||
|
||||
if (caller->readOnly) {
|
||||
SCRIPT_FATAL_ERR("Array is read-only");
|
||||
}
|
||||
|
||||
if (arrayClassAddRange(caller, arg)) {
|
||||
SCRIPT_FATAL_ERR("Adding the wrong type to a typed array");
|
||||
}
|
||||
|
||||
return &emptyClass;
|
||||
}
|
||||
|
||||
ClassFunction(arrayContains) {
|
||||
Vector_t* v = &caller->solvedArray.vector;
|
||||
Variable_t* arg = *args;
|
||||
@@ -258,6 +293,7 @@ ClassFunctionTableEntry_t arrayFunctions[] = {
|
||||
{"set", arraySet, 2, oneIntOneAny},
|
||||
{"+", arrayAdd, 1, anotherAnotherOneVarArg},
|
||||
{"add", arrayAdd, 1, anotherAnotherOneVarArg},
|
||||
{"addrange", arrayAddRange, 1, anotherAnotherOneVarArg},
|
||||
{"-", arrayMinus, 1, anotherOneIntArg},
|
||||
{"contains", arrayContains, 1, anotherAnotherOneVarArg},
|
||||
{"bytestostr", bytesToStr, 0, 0},
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
u8 oneStringArgSave[] = {StringClass};
|
||||
u8 oneStrOneByteArrayArgSave[] = {StringClass, ByteArrayClass};
|
||||
u8 oneStringOneIntArgSave[] = {StringClass, IntClass};
|
||||
|
||||
ClassFunction(readFile){
|
||||
Variable_t *arg = (*args);
|
||||
@@ -96,11 +97,25 @@ ClassFunction(saveClassCommit){
|
||||
return newIntVariablePtr(!save_commit(&caller->save->saveCtx));
|
||||
}
|
||||
|
||||
ClassFunction(writeFileSize) {
|
||||
Variable_t* arg = (*args);
|
||||
save_data_file_ctx_t dataArc;
|
||||
if (!save_open_file(&caller->save->saveCtx, &dataArc, arg->string.value, OPEN_MODE_WRITE))
|
||||
return newIntVariablePtr(1);
|
||||
|
||||
if (!save_data_file_set_size(&dataArc, args[1]->integer.value)) {
|
||||
return newIntVariablePtr(2);
|
||||
};
|
||||
|
||||
return newIntVariablePtr(0);
|
||||
}
|
||||
|
||||
ClassFunctionTableEntry_t saveFunctions[] = {
|
||||
{"read", readFile, 1, oneStringArgSave},
|
||||
{"write", writeFile, 2, oneStrOneByteArrayArgSave},
|
||||
//{"readdir", getFiles, 1, oneStringArgSave}, // Seems broken?
|
||||
{"commit", saveClassCommit, 0, 0},
|
||||
{"resize", writeFileSize, 2, oneStringOneIntArgSave},
|
||||
};
|
||||
|
||||
Variable_t getSaveMember(Variable_t* var, char* memberName) {
|
||||
|
||||
@@ -399,6 +399,16 @@ ClassFunction(stdFileRead){
|
||||
return copyVariableToPtr(v);
|
||||
}
|
||||
|
||||
ClassFunction(stdFileReadSize) {
|
||||
u32 fSize = 0;
|
||||
u8* buff = sd_file_read(args[0]->string.value, &fSize);
|
||||
if (buff == NULL) {
|
||||
SCRIPT_FATAL_ERR("Failed to read file");
|
||||
}
|
||||
|
||||
return newIntVariablePtr(fSize);
|
||||
}
|
||||
|
||||
ClassFunction(stdFileWrite){
|
||||
return newIntVariablePtr(sd_save_to_file(args[1]->solvedArray.vector.data, args[1]->solvedArray.vector.count, args[0]->string.value));
|
||||
}
|
||||
@@ -506,6 +516,7 @@ STUBBED(stdFileMove)
|
||||
STUBBED(stdLaunchPayload)
|
||||
STUBBED(stdFileWrite)
|
||||
STUBBED(stdFileRead)
|
||||
STUBBED(stdFileReadSize)
|
||||
STUBBED(stdCombinePaths)
|
||||
STUBBED(stdEmmcFileWrite)
|
||||
STUBBED(stdEmmcFileRead)
|
||||
@@ -579,6 +590,7 @@ ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
||||
{"movefile", stdFileMove, 2, twoStringArgStd},
|
||||
{"delfile", stdFileDel, 1, twoStringArgStd},
|
||||
{"readfile", stdFileRead, 1, twoStringArgStd},
|
||||
{"getfilesize", stdFileReadSize, 1, twoStringArgStd},
|
||||
{"writefile", stdFileWrite, 2, oneStringOneByteArrayStd},
|
||||
|
||||
// Utils
|
||||
|
||||
Reference in New Issue
Block a user