From db5d7784385dc7730d4e747fc7a31201665e35b0 Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Mon, 11 Jan 2021 22:19:54 +0100 Subject: [PATCH] Add systemRestore, update readme for TE 3.0.1 --- README.md | 32 ++++- scripts/systemRestore.te | 273 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 scripts/systemRestore.te diff --git a/README.md b/README.md index 6d1361d..8267acd 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Variables can be of the following types: - Integer Array - String Array - Byte Array +- Empty Array Creating and accessing Array variables goes as follows: ``` @@ -36,6 +37,8 @@ Note: Minus integer values are supported this time around Another note: You can do !variable to flip the integer inside +Another another note: Every object in TScript is not a reference type! every time you try to modify an array it re-makes the array. In practise array operations are slow + Every variable in TegraScript v2 is global, thus you can access any variable in any self-defined function ### Built in variables @@ -82,7 +85,7 @@ TegraScript has the following functions for flow control: `if()`, `else()`, `whi - `return()` exits the current running function, if there is one - `exit()` exits the script entirely -Lets try to build a loop that iterates 30 times, and printing even numbers +Let's try to build a loop that iterates 30 times, and printing even numbers ``` i = 0 while (i < 30){ # check if i is below 30, if so, run the code between the brackets @@ -138,6 +141,16 @@ Operator | Output `-` | Removes right integer amount of characters from the left string `:` | Removes right integer amount of character from the beginning of the left string +### StringArray, String +Operator | Output +|:-|:-| +`+` | Adds a string to an array + +### EmptyArray, (String, Int) +Operator | Output +|:-|:-| +`+` | Creates the array of the right type and puts the given value as the first entry + ## Functions ### Flow control functions @@ -166,6 +179,7 @@ Name | Description | OutType `version()` | Returns an Integer array of the current TE version | IntegerArray `menu(StringArray options, int startPos)` | Makes a menu with the cursor at startPos, with the provided options. Returns the current pos when a is pressed. B always returns 0 | Integer `menu(StringArray options, int startPos, StringArray colors)` | Same as above, but the entries now get colors defined by the colors array. Uses the same colors as the `colors()` function | Integer +`menu(StringArray options, int startPos, StringArray colors, IntegerArray modifier)` | Same as above, but entries can be hidden or skipped defined by the modifier array. 0 for normal, 1 for skip, 2 for hide | Integer Note about `pause()`. You need to work with raw bitfields. Have an example ``` @@ -200,6 +214,7 @@ Name | Description | OutType `dirCopy(string src, string dst)`| Copies a folder from src to dst. Dst needs to be the containing folder of where you want src to go (`"sd:/tegraexplorer", "sd:/backup` -> `"sd:/backup/tegraexplorer"`). Returns non zero on error | Integer `dirDel(string path)` | Deletes the dir located at path. Returns non zero on error | Integer `mkdir(string path)` | Makes a directory at path | Integer +`launchPayload(string path)`| Launches the payload at the given path. Returns non zero on error | Integer ### Storage functions !! Dangerous Name | Description | OutType @@ -212,6 +227,17 @@ Name | Description | OutType `saveSign(string path)` | Signs the (system) save at the given location. Make sure you provide a save and nothing else! Returns non zero on error | Integer # Changelog -5/1/2021 @ 1:32am // Sleep is still a lie +### 11/1/2021 @ 22:10 // Wow it isn't 2am for once! -Initial writeup on TScript v2 +For the release of TE 3.0.1, the following changes were made: +- A new type was added: Empty array type. You can get this type by running `var = []` +- Operators were added for StringArray, String and EmptyArray, (String, Integer) +- launchPayload was added as a function +- Menu now allows for an additional integer array to define hidden or skip flags +- A bug was fixed with <= and >= registering as < and > +- fileCopy's should not leave an ugly [ anymore +- A script now get executed at TE bootup if a script called `startup.te` is found on the root of the SD + +### 5/1/2021 @ 1:32am // Sleep is still a lie + +- Initial writeup on TScript v2 diff --git a/scripts/systemRestore.te b/scripts/systemRestore.te new file mode 100644 index 0000000..2c11693 --- /dev/null +++ b/scripts/systemRestore.te @@ -0,0 +1,273 @@ +readNext = { + next = all - (len(all) - readAmount) + all = all : readAmount +} + +getInt = { + resInt = (next[0] << 24) | (next[1] << 16) | (next[2] << 8) | (next[3]) +} + +getNextInt = { + readAmount = 4 + readNext() + getInt() +} + +extractBis = { + path = pathCombine(_CWD, "boot.bis") + all = fileRead(path) + readAmount = 0x10 + readNext() + + bisver = bytesToStr(next) + + readAmount = 1 + readNext() + # println(next[0]) + + sizes = [0, 0, 0, 0] + files = ["BOOT0.bin", "BOOT1.bin", "BCPKG2-1-Normal-Main", "BCPKG2-3-SafeMode-Main"] + + i = 0 + while (i < 4) { + getNextInt() + sizes[i] = resInt + i = i + 1 + } + + # println(sizes) + + i = 0 + while (i < 4) { + readAmount = sizes[i] + readNext() + res = fileWrite(pathCombine(_CWD, files[i]), next)) + if (res){ + return() + } + i = i + 1 + } + + res = fileCopy(pathCombine(_CWD, "BCPKG2-1-Normal-Main"), pathCombine(_CWD, "BCPKG2-2-Normal-Sub")) + if (!res){ + res = fileCopy(pathCombine(_CWD, "BCPKG2-3-SafeMode-Main"), pathCombine(_CWD, "BCPKG2-4-SafeMode-Sub")) + } +} + +restoreBis = { + toRestoreFiles = ["BOOT0.bin", "BOOT1.bin", "BCPKG2-1-Normal-Main", "BCPKG2-2-Normal-Sub", "BCPKG2-3-SafeMode-Main", "BCPKG2-4-SafeMode-Sub"] + i = 0 + color("GREEN") + while (i < len(toRestoreFiles)){ + print("Restoring ", toRestoreFiles[i], "... ") + res = mmcRestore(pathCombine(_CWD, toRestoreFiles[i]), toRestoreFiles[i], 1) + if (res){ + color("RED") + print("An error occured! ", res) + return() + } + println() + i = i + 1 + } + color("WHITE") +} + +restoreSystem = { + color("RED") + print("Deleting SYSTEM contents... ") + if (dirDel("bis:/Contents/registered")){ + println("\nAn error occured during deletion!") + return() + } + println() + + color("GREEN") + print("Copying registered... ") + if (dirCopy(pathCombine(_CWD, "SYSTEM/Contents/registered"), "bis:/Contents")) { + println("\nAn error occured during copying!") + return() + } + println() + + color("BLUE") + print("Copying 120 save...") + if (fileCopy(pathCombine(_CWD, "SYSTEM/save/8000000000000120"), "bis:/save/8000000000000120")) { + println("\nFailed to copy system save") + } + println() + + color("WHITE") +} + +signSave = { + print("Signing 120 save... ") + if (saveSign("bis:/save/8000000000000120")){ + println("\nSave sign failed!") + pause() + exit() + } + else(){ + println("Done!") + } +} + + + +origOptions = ["Boot", "System", "Save Sign"] +SystemRestore = 1 +BisRestore = 1 +SaveSign = 0 + +menuOptions = ["Exit", "\n-- Options: --", "Boot.bis not found...", "SYSTEM dir not found...", "", "\n-- Restore to --", "SYSMMC", "EMUMMC"] +menuColors = ["WHITE", "VIOLET", "BLUE", "BLUE", "BLUE", "VIOLET", "YELLOW", "YELLOW"] +menuBits = [0, 1, 1, 1, 0, 1, 0, 0] + +setMenuOptions = { + if (!menuBits[2]) { + if (BisRestore){ + menuOptions[2] = origOptions[0] + ": ON" + } + else() { + menuOptions[2] = origOptions[0] + ": OFF" + } + } + + if (!menuBits[3]) { + if (SystemRestore){ + menuOptions[3] = origOptions[1] + ": ON" + } + else() { + menuOptions[3] = origOptions[1] + ": OFF" + } + } + + if (SaveSign){ + menuOptions[4] = origOptions[2] + ": ON" + } + else() { + menuOptions[4] = origOptions[2] + ": OFF" + } +} + +if (!fileExists(pathCombine(_CWD, "boot.bis"))) { + println("[WARN] boot.bis not found!") + BisRestore = 0 +} +else() { + menuBits[2] = 0 +} + +if (!fileExists(pathCombine(_CWD, "SYSTEM"))) { + println("[WARN] SYSTEM dir not found!") + SystemRestore = 0 +} +else() { + menuBits[3] = 0 +} + +if (_EMU){ + menuBits[7] = 0 +} +else() { + menuBits[7] = 2 +} + + +println("\n-- System Restore Script --\n\n") + +res = 0 +while (res < 6){ + printPos(0, 5) + setMenuOptions() + res = menu(menuOptions, res, menuColors, menuBits) + + if (res == 0){ + exit() + } + + if (res == 2){ + BisRestore = !BisRestore + } + + if (res == 3){ + SystemRestore = !SystemRestore + } + + if (res == 4){ + SaveSign = !SaveSign + } +} + +clearscreen() + +if (res == 6){ + println("Mounting SYS") + if (mmcConnect("SYSMMC")){ + println("An error occured during mmc connect!") + pause() + exit() + } +} + +if (res == 7){ + println("Mounting EMU") + if (mmcConnect("EMUMMC")){ + println("An error occured during mmc connect!") + pause() + exit() + } +} + +if (BisRestore){ + print("Extracting bis... ") + extractBis() + if (res){ + println("\nError while extracting bis...") + pause() + exit() + } + else(){ + println(" Done!\nExtracted version: ", bisver) + } +} + + +println("\n\nReady!\n") + +color("RED") +print("WARNING!!!\nIf you do not know exactly what this does. STOP!!!\nThis will fuck with your system!\nOnly do this as a last ditch recovery effort!\n") +color("GREEN") +println("For help go here: https://discord.gg/C29hYvh\n") +color("WHITE") +wait(10000) +println("X to continue \nAny other button to exit") + +if (!(pause() & 0x2)){ + exit() +} + +clearscreen() +println("GO!\n") + +if (BisRestore){ + restoreBis() +} + +println() + +if (mmcMount("SYSTEM")){ + println("Failed to mount system!") + pause() + exit() +} + +if (SystemRestore){ + restoreSystem() +} + +if (SaveSign) { + signSave() +} + +println("\n\nDone!\nPress any button to exit") +pause() \ No newline at end of file