diff --git a/HelloScript.gm9 b/HelloScript.gm9 index a63b960..48a6445 100644 --- a/HelloScript.gm9 +++ b/HelloScript.gm9 @@ -29,6 +29,7 @@ ask "Continue running this script?" ask -o -s "Really continue running this script?\n(I will completely ignore your answer)" # ENVIRONMENTAL VARS +# REGION is the region of your device's SysNAND (USA, EUR, JPN, KOR, CHN, TWN or UNK for unknown) # SERIAL is the serial number of your device # GM9OUT is the standard output path # CURRDIR is the directory the script is running from @@ -40,8 +41,8 @@ ask -o -s "Really continue running this script?\n(I will completely ignore your # TIMESTAMP is the current time in hhmmss format # DATESTAMP is the current date in YYMMDD format # Use $[VAR] to get the *content* of a variable VAR -echo "Your serial number is $[SERIAL]\nYour std output path is $[GM9OUT]\nCurrent dir is $[CURRDIR]\nCurrent hax is $[HAX]\nYour system is a $[RDTYPE] $[ONTYPE]\nCurrent datestamp is: $[DATESTAMP]\nCurrent timestamp is: $[TIMESTAMP]\n \nYour sys / emu ID0 is:\n$[SYSID0]\n$[EMUID0]" -qr "You can also have this as a QR code :)" "Your serial number is $[SERIAL]\nYour std output path is $[GM9OUT]\nCurrent dir is $[CURRDIR]\nCurrent hax is $[HAX]\nYour system is a $[RDTYPE] $[ONTYPE]\nCurrent datestamp is: $[DATESTAMP]\nCurrent timestamp is: $[TIMESTAMP]\n \nYour sys / emu ID0 is:\n$[SYSID0]\n$[EMUID0]" +echo "Your region is $[REGION]\nYour serial number is $[SERIAL]\nYour std output path is $[GM9OUT]\nCurrent dir is $[CURRDIR]\nCurrent hax is $[HAX]\nYour system is a $[RDTYPE] $[ONTYPE]\nCurrent datestamp is: $[DATESTAMP]\nCurrent timestamp is: $[TIMESTAMP]\n \nYour sys / emu ID0 is:\n$[SYSID0]\n$[EMUID0]" +qr "You can also have this as a QR code :)" "Your region is $[REGION]\nYour serial number is $[SERIAL]\nYour std output path is $[GM9OUT]\nCurrent dir is $[CURRDIR]\nCurrent hax is $[HAX]\nYour system is a $[RDTYPE] $[ONTYPE]\nCurrent datestamp is: $[DATESTAMP]\nCurrent timestamp is: $[TIMESTAMP]\n \nYour sys / emu ID0 is:\n$[SYSID0]\n$[EMUID0]" # ERRORMSG and SUCCESSMSG / 'set' COMMAND # These two are special environment vars, allowing you to control the message on script failure or success diff --git a/source/utils/scripting.c b/source/utils/scripting.c index d0e2c59..34e7250 100644 --- a/source/utils/scripting.c +++ b/source/utils/scripting.c @@ -18,6 +18,7 @@ #include "sha.h" #include "hid.h" #include "ui.h" +#include "region.h" #define _MAX_ARGS 3 #define _ARG_MAX_LEN 512 @@ -267,13 +268,22 @@ char* set_var(const char* name, const char* content) { } void upd_var(const char* name) { - // device serial - if (!name || (strncmp(name, "SERIAL", _VAR_NAME_LEN) == 0)) { - char env_serial[16] = { 0 }; - if ((FileGetData("1:/rw/sys/SecureInfo_A", (u8*) env_serial, 0xF, 0x102) != 0xF) && - (FileGetData("1:/rw/sys/SecureInfo_B", (u8*) env_serial, 0xF, 0x102) != 0xF)) + // device serial / region + if (!name || (strncmp(name, "SERIAL", _VAR_NAME_LEN) == 0) || + (strncmp(name, "REGION", _VAR_NAME_LEN) == 0)) { + u8 secinfo_data[1 + 1 + 16] = { 0 }; + char* env_serial = (char*) secinfo_data + 2; + char env_region[3 + 1]; + + snprintf(env_region, 0x4, "UNK"); + if ((FileGetData("1:/rw/sys/SecureInfo_A", secinfo_data, 0x11, 0x100) != 0x11) && + (FileGetData("1:/rw/sys/SecureInfo_B", secinfo_data, 0x11, 0x100) != 0x11)) snprintf(env_serial, 0xF, "UNKNOWN"); + else if (*secinfo_data < SMDH_NUM_REGIONS) + strncpy(env_region, g_regionNamesShort[*secinfo_data], countof(env_region)); + set_var("SERIAL", env_serial); + set_var("REGION", env_region); } // device sysnand / emunand id0