├── .gitignore ├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── .gitmodules ├── README.md ├── source ├── main.cpp ├── dir_iterator.cpp └── gui_main.cpp ├── include ├── dir_iterator.hpp └── gui_main.hpp ├── .vscode ├── settings.json └── c_cpp_properties.json ├── lang ├── zh-Hans.json └── zh-Hant.json ├── Makefile └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | build/ 3 | SdOut/ 4 | 5 | *.ovl 6 | 7 | *.elf 8 | 9 | *.nacp 10 | 11 | *.nro 12 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: werwolv 4 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KP7XRJAND9KWU&source=url 5 | github: WerWolv 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/libtesla"] 2 | path = libs/libtesla 3 | url = https://github.com/zdm65477730/libtesla 4 | [submodule "libs/SimpleIniParser"] 5 | path = libs/SimpleIniParser 6 | url = https://github.com/zdm65477730/SimpleIniParser.git 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ovlSysmodule 2 | 3 | A Tesla overlay that allows you to toggle sysmodules on the fly 4 | 5 | ## Installation 6 | 7 | Download the latest ovlSysmodules.ovl from the release page and drop it into the /switch/.overlays folder on your Switch's SD card 8 | -------------------------------------------------------------------------------- /source/main.cpp: -------------------------------------------------------------------------------- 1 | #define TESLA_INIT_IMPL 2 | #include "gui_main.hpp" 3 | 4 | class OverlaySysmodules : public tsl::Overlay { 5 | public: 6 | OverlaySysmodules() {} 7 | ~OverlaySysmodules() {} 8 | 9 | void initServices() override { 10 | ASSERT_FATAL(pmshellInitialize()); 11 | } 12 | 13 | void exitServices() override { 14 | pmshellExit(); 15 | } 16 | 17 | std::unique_ptr loadInitialGui() override { 18 | return std::make_unique(); 19 | } 20 | }; 21 | 22 | int main(int argc, char **argv) { 23 | return tsl::loop(argc, argv); 24 | } -------------------------------------------------------------------------------- /include/dir_iterator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class FsDirIterator { 6 | private: 7 | FsDir m_dir; 8 | FsDirectoryEntry entry; 9 | s64 count; 10 | 11 | public: 12 | FsDirIterator() = default; 13 | FsDirIterator(FsDir dir); 14 | 15 | ~FsDirIterator() = default; 16 | 17 | const FsDirectoryEntry &operator*() const; 18 | const FsDirectoryEntry *operator->() const; 19 | FsDirIterator &operator++(); 20 | 21 | bool operator!=(const FsDirIterator &rhs); 22 | }; 23 | 24 | inline FsDirIterator begin(FsDirIterator iter) noexcept { return iter; } 25 | 26 | inline FsDirIterator end(FsDirIterator) noexcept { return FsDirIterator(); } 27 | -------------------------------------------------------------------------------- /source/dir_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "dir_iterator.hpp" 2 | 3 | FsDirIterator::FsDirIterator(FsDir dir) : m_dir(dir) { 4 | if (R_FAILED(fsDirRead(&this->m_dir, &this->count, 1, &this->entry))) 5 | this->count = 0; 6 | } 7 | 8 | const FsDirectoryEntry &FsDirIterator::operator*() const { 9 | return this->entry; 10 | } 11 | 12 | const FsDirectoryEntry *FsDirIterator::operator->() const { 13 | return &**this; 14 | } 15 | 16 | FsDirIterator &FsDirIterator::operator++() { 17 | if (R_FAILED(fsDirRead(&this->m_dir, &this->count, 1, &this->entry))) 18 | this->count = 0; 19 | return *this; 20 | } 21 | 22 | bool FsDirIterator::operator!=(const FsDirIterator &__rhs) { 23 | return this->count > 0; 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | issue_comment: 5 | types: [ created ] 6 | 7 | jobs: 8 | build_and_release: 9 | name: Build and release 10 | runs-on: ubuntu-latest 11 | container: devkitpro/devkita64:latest 12 | if: contains(github.event.comment.body, '/release-action') 13 | 14 | steps: 15 | - name: Update latest libnx 16 | run: | 17 | git config --global --add safe.directory "*" 18 | git clone --recurse-submodules https://github.com/switchbrew/libnx.git 19 | cd libnx 20 | make install -j$(nproc) 21 | shell: bash 22 | - name: Checkout latest code 23 | uses: actions/checkout@v4.2.2 24 | with: 25 | ref: master 26 | clean: true 27 | fetch-depth: 0 28 | fetch-tags: true 29 | submodules: recursive 30 | - name: Setup ENV parameters 31 | run: | 32 | VER_FILE=Makefile 33 | VERSION=$(awk '/^APP_VERSION/{print $3}' $VER_FILE) 34 | echo "TAG=${VERSION}" >> "${GITHUB_ENV}" 35 | echo "RELEASE_NAME=ovl-sysmodules ${VERSION}" >> "${GITHUB_ENV}" 36 | shell: bash 37 | - name: Build 38 | run: | 39 | export DEVKITPRO=/opt/devkitpro 40 | make all 41 | shell: bash 42 | - name: Upload Release Asset 43 | uses: softprops/action-gh-release@v2.0.9 44 | with: 45 | name: ${{ env.RELEASE_NAME }} 46 | tag_name: ${{ env.TAG }} 47 | draft: false 48 | prerelease: false 49 | generate_release_notes: yes 50 | make_latest: true 51 | files: | 52 | ./SdOut/ovl-sysmodules.zip 53 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "chrono": "cpp", 4 | "string_view": "cpp", 5 | "array": "cpp", 6 | "atomic": "cpp", 7 | "bit": "cpp", 8 | "*.tcc": "cpp", 9 | "cctype": "cpp", 10 | "clocale": "cpp", 11 | "cmath": "cpp", 12 | "cstdarg": "cpp", 13 | "cstddef": "cpp", 14 | "cstdint": "cpp", 15 | "cstdio": "cpp", 16 | "cstdlib": "cpp", 17 | "cstring": "cpp", 18 | "ctime": "cpp", 19 | "cwchar": "cpp", 20 | "cwctype": "cpp", 21 | "deque": "cpp", 22 | "unordered_map": "cpp", 23 | "vector": "cpp", 24 | "exception": "cpp", 25 | "algorithm": "cpp", 26 | "functional": "cpp", 27 | "iterator": "cpp", 28 | "memory": "cpp", 29 | "memory_resource": "cpp", 30 | "numeric": "cpp", 31 | "optional": "cpp", 32 | "random": "cpp", 33 | "ratio": "cpp", 34 | "string": "cpp", 35 | "system_error": "cpp", 36 | "tuple": "cpp", 37 | "type_traits": "cpp", 38 | "utility": "cpp", 39 | "fstream": "cpp", 40 | "initializer_list": "cpp", 41 | "iosfwd": "cpp", 42 | "istream": "cpp", 43 | "limits": "cpp", 44 | "new": "cpp", 45 | "ostream": "cpp", 46 | "sstream": "cpp", 47 | "stdexcept": "cpp", 48 | "streambuf": "cpp", 49 | "thread": "cpp", 50 | "cinttypes": "cpp", 51 | "typeinfo": "cpp", 52 | "codecvt": "cpp", 53 | "condition_variable": "cpp", 54 | "iomanip": "cpp", 55 | "mutex": "cpp", 56 | "forward_list": "cpp", 57 | "list": "cpp", 58 | "map": "cpp", 59 | "valarray": "cpp" 60 | } 61 | } -------------------------------------------------------------------------------- /include/gui_main.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct SystemModule { 6 | tsl::elm::ListItem *listItem; 7 | u64 programId; 8 | bool needReboot; 9 | }; 10 | 11 | enum class BootDatType { 12 | SXOS_BOOT_TYPE, 13 | SXGEAR_BOOT_TYPE 14 | }; 15 | 16 | struct SystemModuleEnabledFlag { 17 | int powerControlEnabled{1}; 18 | int wifiControlEnabled{1}; 19 | int sysmodulesControlEnabled{1}; 20 | int bootFileControlEnabled{1}; 21 | int hekateRestartControlEnabled{1}; 22 | int consoleRegionControlEnabled{1}; 23 | #if 0 24 | int wlanCountryCodeControlEnabled{1}; 25 | #endif 26 | }; 27 | 28 | class GuiMain : public tsl::Gui { 29 | private: 30 | FsFileSystem m_fs; 31 | std::list m_sysmoduleListItems; 32 | tsl::elm::ListItem *m_listItemSXOSBootType; 33 | tsl::elm::ListItem *m_listItemSXGEARBootType; 34 | tsl::elm::ListItem *m_listItemWifiSwitch; 35 | bool m_scanned; 36 | 37 | public: 38 | GuiMain(); 39 | ~GuiMain(); 40 | 41 | virtual tsl::elm::Element *createUI(); 42 | virtual void update() override; 43 | 44 | private: 45 | void updateStatus(const SystemModule &module); 46 | bool hasFlag(const SystemModule &module); 47 | bool isRunning(const SystemModule &module); 48 | Result CopyFile(const char *srcPath, const char *destPath); 49 | Result setGetIniConfig(std::string iniPath, std::string iniSection, std::string iniOption, std::string &iniValue, bool getOption = true); 50 | #if 0 51 | Result setWLANCountryCode(std::string wlanCountCode); 52 | Result getWLANCountryCode(std::string &outWlanCountCode); 53 | #endif 54 | 55 | SystemModuleEnabledFlag m_sysmodEnabledFlags; 56 | BootDatType m_bootRunning; 57 | bool m_isTencentVersion; 58 | bool m_isWifiOn; 59 | #if 0 60 | std::string m_curCountryCode; 61 | #endif 62 | }; -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "DKP Aarch64 Windows", 5 | "includePath": [ 6 | "C:/devkitPro/devkitA64/aarch64-none-elf/include/**", 7 | "C:/devkitPro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include/**", 8 | "C:/devkitPro/libnx/include/**", 9 | "C:/devkitPro/portlibs/switch/include/**", 10 | "C:/devkitPro/portlibs/switch/include/freetype2/**", 11 | "${workspaceFolder}/include/**", 12 | "${workspaceFolder}/libtesla/include/**" 13 | ], 14 | "defines": [ 15 | "SWITCH", 16 | "__SWITCH__", 17 | "__aarch64__", 18 | "VERSION=\"\"" 19 | ], 20 | "compilerPath": "C:/devkitPro/devkitA64/bin/aarch64-none-elf-g++", 21 | "cStandard": "c11", 22 | "cppStandard": "c++17", 23 | "intelliSenseMode": "gcc-x64" 24 | }, 25 | { 26 | "name": "DKP Aarch64 Linux", 27 | "includePath": [ 28 | "/opt/devkitpro/devkitA64/aarch64-none-elf/include/**", 29 | "/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include/**", 30 | "/opt/devkitpro/libnx/include/**", 31 | "/opt/devkitpro/portlibs/switch/include/**", 32 | "/opt/devkitpro/portlibs/switch/include/**", 33 | "/opt/devkitpro/portlibs/switch/include/freetype2/**", 34 | "${workspaceFolder}/include/**", 35 | "${workspaceFolder}/libs/libtesla/include/**" 36 | ], 37 | "defines": [ 38 | "SWITCH", 39 | "__SWITCH__", 40 | "__aarch64__", 41 | "VERSION=\"\"" 42 | ], 43 | "compilerPath": "/opt/devkitpro/devkitA64/bin/aarch64-none-elf-g++", 44 | "cStandard": "c11", 45 | "cppStandard": "c++17", 46 | "intelliSenseMode": "gcc-x64" 47 | } 48 | ], 49 | "version": 4 50 | } -------------------------------------------------------------------------------- /lang/zh-Hans.json: -------------------------------------------------------------------------------- 1 | { 2 | "PluginName": "系统模块", 3 | "RunAndHasFlagListItemValue": "正在使用 | \uE0F4", 4 | "RunAndNoFlagListItemValue": "正在使用 | \uE098", 5 | "NotRunAndHasFlagListItemValue": "未启用 | \uE0F4", 6 | "NotRunAndNoFlagListItemValue": "未启用 | \uE098", 7 | "PowerCategoryHeaderText": "SWITCH电源控制 | \uE0E0 重启和关机", 8 | "PowerCustomDrawerText": "\uE016 快速重启或者关闭您的SWITCH。", 9 | "PowerResetListItemKey": "重启", 10 | "PowerResetListItemValue": "| \uE0F4", 11 | "PowerListItemErrorText": "spsmShutdown失败!错误码:", 12 | "PowerOffListItemKey": "关机", 13 | "PowerOffListItemValue": "| \uE098", 14 | "WifiSwitchCategoryHeaderText": "WIFI切换 | \uE0E0 切换", 15 | "WifiSwitchCustomDrawerText": "\uE016 快速切换SWITCH WIFI开关。", 16 | "WifiSwitchListItemKey": "WIFI状态", 17 | "WifiSwitchStatusCheckErrorListItemText": "检查WIFI状态失败!错误码:", 18 | "WifiSwitchSetErrorListItemext": "nifmSetWirelessCommunicationEnabled失败!错误码", 19 | "SysmodulesNotFoundScanOKCustomDrawerText": "没有找到任何系统模块!", 20 | "SysmodulesNotFoundScanNOKCustomDrawerText": "检索失败!", 21 | "SysmodulesDynamicCategoryHeaderText": "动态 | \uE0E0 切换 | \uE0E3 自动启动", 22 | "SysmodulesDynamicCustomDrawerText": "\uE016 这些系统模块可以任何时候切换。", 23 | "SysmodulesStaticCategoryHeaderText": "静态 | \uE0E3 自动启动", 24 | "SysmodulesStaticCustomDrawerText": "\uE016 这些系统模块需要重启切换。", 25 | "BootFileSwitchCategoryHeaderText": "支持系统引导的Boot文件 | \uE0E0 切换", 26 | "BootFileSwitchCustomDrawerText": "\uE016 切换后重启生效。", 27 | "BootFileSXOSBootCopyNOKListItemText": "切换SXOS boot.dat失败!错误码: ", 28 | "BootFileSXGEARBootCopyNOKListItemText": "切换SXGEAR boot.dat失败!错误码:", 29 | "BootFileSXOSBootSourceFileNotFoundListItemText": "切换SXOS boot.dat失败!启动文件不存在!", 30 | "BootFileSXGEARBootSourceFileNotFoundListItemText": "切换SXGEAR boot.dat失败!启动文件不存在!", 31 | "HekateRestartHitCategoryHeaderText": "更新hekate配置 | \uE0E0 切换", 32 | "HekateRestartHitCustomDrawerText": "\uE016 切换后重启生效。", 33 | "HekateAutoRestartHitListItemKey": "hekate启动提示", 34 | "HekateAutoRestartHitINIParseNOKListItemValue": "INI解析失败", 35 | "HekateAutoRestartHitININoSectionListItemValue": "INI中无对应节", 36 | "HekateAutoRestartHitININoParameterListItemValue": "INI节无参数", 37 | "HekateAutoRestartHitINIWriteNOKListItemValue": "INI写入失败", 38 | "VersionSwitchCategoryHeaderText": "大陆与国际版本切换 | \uE0E2 大陆 \uE0E3 国际", 39 | "VersionSwitchCustomDrawerText": "\uE016 切换后无需洗白和初始化,重启同意EULA即可。", 40 | "VersionSwitchListItemKey": "当前版本", 41 | "VersionSwitchMainlandListItemValue": "大陆", 42 | "VersionSwitchInternationalListItemValue": "国际", 43 | "VersionSwitchSetTNOKListItemValue": "setsysSetT失败!错误码:", 44 | "VersionSwitchSetRegionCodeNOKListItemValue": "setsysSetRegionCode失败!错误码:", 45 | "WlanCountryCodeSwitchCategoryHeaderText": "大陆与日本WLan国家码切换 | \uE0E2 大陆 \uE0E3 日本", 46 | "WlanCountryCodeSwitchCustomDrawerText": "\uE016 建议先备份PRODINFO。切换后,重启生效。", 47 | "WlanCountryCodeSwitchListItemKey": "当前WLan国家码", 48 | "WlanCountryCodeSwitchMainlandListItemValue": "大陆", 49 | "WlanCountryCodeSwitchJapanListItemValue": "日本", 50 | "WlanCountryCodeSwitchSetTNOKListItemValue": "setWLANCountryCode失败!错误码:" 51 | } 52 | -------------------------------------------------------------------------------- /lang/zh-Hant.json: -------------------------------------------------------------------------------- 1 | { 2 | "PluginName": "系統模塊", 3 | "RunAndHasFlagListItemValue": "正在使用 | \uE0F4", 4 | "RunAndNoFlagListItemValue": "正在使用 | \uE098", 5 | "NotRunAndHasFlagListItemValue": "未啟用 | \uE0F4", 6 | "NotRunAndNoFlagListItemValue": "未啟用 | \uE098", 7 | "PowerCategoryHeaderText": "SWITCH電源控制 | \uE0E0 重啟和關機", 8 | "PowerCustomDrawerText": "\uE016 快速重啟或者關閉您的SWITCH。", 9 | "PowerResetListItemKey": "重啟", 10 | "PowerResetListItemValue": "| \uE0F4", 11 | "PowerListItemErrorText": "spsmShutdown失敗!錯誤碼:", 12 | "PowerOffListItemKey": "關機", 13 | "PowerOffListItemValue": "| \uE098", 14 | "WifiSwitchCategoryHeaderText": "WIFI切換 | \uE0E0 切換", 15 | "WifiSwitchCustomDrawerText": "\uE016 快速切換SWITCH WIFI開關。", 16 | "WifiSwitchListItemKey": "WIFI狀態", 17 | "WifiSwitchStatusCheckErrorListItemText": "檢查WIFI狀態失敗!錯誤碼:", 18 | "WifiSwitchSetErrorListItemext": "nifmSetWirelessCommunicationEnabled失敗!錯誤碼", 19 | "SysmodulesNotFoundScanOKCustomDrawerText": "沒有找到任何系統模塊!", 20 | "SysmodulesNotFoundScanNOKCustomDrawerText": "檢索失敗!", 21 | "SysmodulesDynamicCategoryHeaderText": "動態 | \uE0E0 切換 | \uE0E3 自動啟動", 22 | "SysmodulesDynamicCustomDrawerText": "\uE016 這些系統模塊可以任何時候切換。", 23 | "SysmodulesStaticCategoryHeaderText": "靜態 | \uE0E3 自動啟動", 24 | "SysmodulesStaticCustomDrawerText": "\uE016 這些系統模塊需要重啟切換。", 25 | "BootFileSwitchCategoryHeaderText": "支持系統引導的Boot文件 | \uE0E0 切換", 26 | "BootFileSwitchCustomDrawerText": "\uE016 切換後重啟生效。", 27 | "BootFileSXOSBootCopyNOKListItemText": "切換SXOS boot.dat失敗!錯誤碼: ", 28 | "BootFileSXGEARBootCopyNOKListItemText": "切換SXGEAR boot.dat失敗!錯誤碼:", 29 | "BootFileSXOSBootSourceFileNotFoundListItemText": "切換SXOS boot.dat失敗!啟動文件不存在!", 30 | "BootFileSXGEARBootSourceFileNotFoundListItemText": "切換SXGEAR boot.dat失敗!啟動文件不存在!", 31 | "HekateRestartHitCategoryHeaderText": "更新hekate配置 | \uE0E0 切換", 32 | "HekateRestartHitCustomDrawerText": "\uE016 切換後重啟生效。", 33 | "HekateAutoRestartHitListItemKey": "hekate啟動提示", 34 | "HekateAutoRestartHitINIParseNOKListItemValue": "INI解析失敗", 35 | "HekateAutoRestartHitININoSectionListItemValue": "INI中無對應節", 36 | "HekateAutoRestartHitININoParameterListItemValue": "INI節無參數", 37 | "HekateAutoRestartHitINIWriteNOKListItemValue": "INI寫入失敗", 38 | "VersionSwitchCategoryHeaderText": "大陸與國際版本切換 | \uE0E2 大陸 \uE0E3 國際", 39 | "VersionSwitchCustomDrawerText": "\uE016 切換後無需洗白和初始化,重啟同意EULA即可。", 40 | "VersionSwitchListItemKey": "當前版本", 41 | "VersionSwitchMainlandListItemValue": "大陸", 42 | "VersionSwitchInternationalListItemValue": "國際", 43 | "VersionSwitchSetTNOKListItemValue": "setsysSetT失敗!錯誤碼:", 44 | "VersionSwitchSetRegionCodeNOKListItemValue": "setsysSetRegionCode失敗!錯誤碼:", 45 | "WlanCountryCodeSwitchCategoryHeaderText": "大陸與日本WLan國家碼切換 | \uE0E2 大陸 \uE0E3 日本", 46 | "WlanCountryCodeSwitchCustomDrawerText": "\uE016 建議先備份PRODINFO。切換後,重啟生效。", 47 | "WlanCountryCodeSwitchListItemKey": "當前WLan國家碼", 48 | "WlanCountryCodeSwitchMainlandListItemValue": "大陸", 49 | "WlanCountryCodeSwitchJapanListItemValue": "日本", 50 | "WlanCountryCodeSwitchSetTNOKListItemValue": "setWLANCountryCode失敗!錯誤碼:" 51 | } 52 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITPRO)/libnx/switch_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) 19 | # 20 | # NO_ICON: if set to anything, do not use icon. 21 | # NO_NACP: if set to anything, no .nacp file is generated. 22 | # APP_TITLE is the name of the app stored in the .nacp file (Optional) 23 | # APP_AUTHOR is the author of the app stored in the .nacp file (Optional) 24 | # APP_VERSION is the version of the app stored in the .nacp file (Optional) 25 | # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) 26 | # ICON is the filename of the icon (.jpg), relative to the project folder. 27 | # If not set, it attempts to use one of the following (in this order): 28 | # - .jpg 29 | # - icon.jpg 30 | # - /default_icon.jpg 31 | # 32 | # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. 33 | # If not set, it attempts to use one of the following (in this order): 34 | # - .json 35 | # - config.json 36 | # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead 37 | # of a homebrew executable (.nro). This is intended to be used for sysmodules. 38 | # NACP building is skipped as well. 39 | #--------------------------------------------------------------------------------- 40 | APP_TITLE := ovl-sysmodules 41 | APP_VERSION := v1.3.1 42 | 43 | TARGET := $(APP_TITLE) 44 | BUILD := build 45 | SOURCES := source libs/SimpleIniParser/source/SimpleIniParser 46 | DATA := data 47 | INCLUDES := include libs/libtesla/include libs/SimpleIniParser/include libs/SimpleIniParser/include/SimpleIniParser 48 | 49 | ifeq ($(RELEASE),) 50 | APP_VERSION := $(APP_VERSION)-$(shell git describe --always) 51 | endif 52 | 53 | NO_ICON := 1 54 | 55 | #--------------------------------------------------------------------------------- 56 | # options for code generation 57 | #--------------------------------------------------------------------------------- 58 | ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE 59 | 60 | CFLAGS := -g -Wall -O2 -ffunction-sections \ 61 | $(ARCH) $(DEFINES) 62 | 63 | CFLAGS += $(INCLUDE) -D__SWITCH__ -DAPPTITLE=\"$(APP_TITLE)\" -DVERSION=\"$(APP_VERSION)\" 64 | 65 | CXXFLAGS := $(CFLAGS) -fexceptions -std=c++20 66 | 67 | ASFLAGS := -g $(ARCH) 68 | LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 69 | 70 | LIBS := -lnx -lSimpleIniParser 71 | 72 | #--------------------------------------------------------------------------------- 73 | # list of directories containing libraries, this must be the top level containing 74 | # include and lib 75 | #--------------------------------------------------------------------------------- 76 | LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/libs/SimpleIniParser 77 | 78 | #--------------------------------------------------------------------------------- 79 | # no real need to edit anything past this point unless you need to add additional 80 | # rules for different file extensions 81 | #--------------------------------------------------------------------------------- 82 | ifneq ($(BUILD),$(notdir $(CURDIR))) 83 | #--------------------------------------------------------------------------------- 84 | 85 | export OUTPUT := $(CURDIR)/$(TARGET) 86 | export TOPDIR := $(CURDIR) 87 | 88 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 89 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 90 | 91 | export DEPSDIR := $(CURDIR)/$(BUILD) 92 | 93 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 94 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 95 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 96 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 97 | 98 | #--------------------------------------------------------------------------------- 99 | # use CXX for linking C++ projects, CC for standard C 100 | #--------------------------------------------------------------------------------- 101 | ifeq ($(strip $(CPPFILES)),) 102 | #--------------------------------------------------------------------------------- 103 | export LD := $(CC) 104 | #--------------------------------------------------------------------------------- 105 | else 106 | #--------------------------------------------------------------------------------- 107 | export LD := $(CXX) 108 | #--------------------------------------------------------------------------------- 109 | endif 110 | #--------------------------------------------------------------------------------- 111 | 112 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 113 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 114 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 115 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) 116 | 117 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 118 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 119 | -I$(CURDIR)/$(BUILD) 120 | 121 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 122 | 123 | ifeq ($(strip $(CONFIG_JSON)),) 124 | jsons := $(wildcard *.json) 125 | ifneq (,$(findstring $(TARGET).json,$(jsons))) 126 | export APP_JSON := $(TOPDIR)/$(TARGET).json 127 | else 128 | ifneq (,$(findstring config.json,$(jsons))) 129 | export APP_JSON := $(TOPDIR)/config.json 130 | endif 131 | endif 132 | else 133 | export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) 134 | endif 135 | 136 | ifeq ($(strip $(ICON)),) 137 | icons := $(wildcard *.jpg) 138 | ifneq (,$(findstring $(TARGET).jpg,$(icons))) 139 | export APP_ICON := $(TOPDIR)/$(TARGET).jpg 140 | else 141 | ifneq (,$(findstring icon.jpg,$(icons))) 142 | export APP_ICON := $(TOPDIR)/icon.jpg 143 | endif 144 | endif 145 | else 146 | export APP_ICON := $(TOPDIR)/$(ICON) 147 | endif 148 | 149 | ifeq ($(strip $(NO_ICON)),) 150 | export NROFLAGS += --icon=$(APP_ICON) 151 | endif 152 | 153 | ifeq ($(strip $(NO_NACP)),) 154 | export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp 155 | endif 156 | 157 | ifneq ($(APP_TITLEID),) 158 | export NACPFLAGS += --titleid=$(APP_TITLEID) 159 | endif 160 | 161 | ifneq ($(ROMFS),) 162 | export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) 163 | endif 164 | 165 | .PHONY: $(BUILD) clean all 166 | 167 | #--------------------------------------------------------------------------------- 168 | all: $(BUILD) 169 | 170 | 171 | $(BUILD): 172 | @[ -d $@ ] || mkdir -p $@ 173 | @$(MAKE) --no-print-directory -C $(CURDIR)/libs/SimpleIniParser 174 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 175 | @rm -rf $(CURDIR)/SdOut 176 | @mkdir -p $(CURDIR)/SdOut/switch/.overlays/lang/$(APP_TITLE) 177 | @mkdir -p $(CURDIR)/SdOut/config/$(APP_TITLE) 178 | @cp -r $(TARGET).ovl $(CURDIR)/SdOut/switch/.overlays/ 179 | @cp -r $(CURDIR)/lang/* $(CURDIR)/SdOut/switch/.overlays/lang/$(APP_TITLE)/ 180 | @echo "[$(APP_TITLE)]\npowerControlEnabled=1\nwifiControlEnabled=1\nsysmodulesControlEnabled=1\nbootFileControlEnabled=0\nhekateRestartControlEnabled=0\nconsoleRegionControlEnabled=0" > $(CURDIR)/SdOut/config/$(APP_TITLE)/config.ini 181 | @cd $(CURDIR)/SdOut; zip -r -q -9 $(APP_TITLE).zip switch config; cd $(CURDIR) 182 | 183 | #--------------------------------------------------------------------------------- 184 | clean: 185 | @rm -fr $(BUILD) $(CURDIR)/SdOut $(TARGET).ovl $(TARGET).nro $(TARGET).nacp $(TARGET).elf 186 | 187 | 188 | #--------------------------------------------------------------------------------- 189 | else 190 | .PHONY: all 191 | 192 | DEPENDS := $(OFILES:.o=.d) 193 | 194 | #--------------------------------------------------------------------------------- 195 | # main targets 196 | #--------------------------------------------------------------------------------- 197 | all : $(OUTPUT).ovl 198 | 199 | $(OUTPUT).ovl : $(OUTPUT).elf $(OUTPUT).nacp 200 | @elf2nro $< $@ $(NROFLAGS) 201 | @echo "built ... $(notdir $(OUTPUT).ovl)" 202 | 203 | $(OUTPUT).elf : $(OFILES) 204 | 205 | $(OFILES_SRC) : $(HFILES_BIN) 206 | 207 | #--------------------------------------------------------------------------------- 208 | # you need a rule like this for each extension you use as binary data 209 | #--------------------------------------------------------------------------------- 210 | %.bin.o %_bin.h : %.bin 211 | #--------------------------------------------------------------------------------- 212 | @echo $(notdir $<) 213 | @$(bin2o) 214 | 215 | -include $(DEPENDS) 216 | 217 | #--------------------------------------------------------------------------------------- 218 | endif 219 | #--------------------------------------------------------------------------------------- 220 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /source/gui_main.cpp: -------------------------------------------------------------------------------- 1 | #include "gui_main.hpp" 2 | #include "dir_iterator.hpp" 3 | 4 | #include 5 | 6 | /* Below copy from rexshao's source code 7 | \uE093 ↓ 8 | \uE092 ↑ 9 | \uE091 ← 10 | \uE090 → 11 | \uE08f 逆时针转 12 | \uE08e 顺时针转 13 | \uE08d 上下箭头 14 | \uE08c 左右箭头 15 | \uE0Ed 方向键左 16 | \uE0Ee 方向键 右 17 | \uE0EB 方向键 上 18 | \uE0EC 方向键 下 19 | \uE0EA 方向键4个 20 | \uE0Ef ➕键 带白底 21 | \uE0f0 ➖键 带白底 22 | \uE0f1 ➕键 23 | \uE0f2 ➖键 24 | \uE0f3 电源键 25 | \uE0f4 home 键 白底 26 | \uE0f5 截屏键 27 | 特殊字符 \uE098 X 28 | \uE099 像是切换视角按钮 29 | 特殊字符 \uE0E0 A按钮 30 | 特殊字符 \uE0E1 B按钮 31 | 特殊字符 \uE0E2 X按钮 32 | 特殊字符 \uE0E3 Y按钮BC 33 | \uE0E4 L 34 | \uE0E5 R 35 | \uE0E6 ZL 36 | \uE0E7 ZR 37 | \uE0E8 SL 38 | \uE0E9 SR 39 | \uE150 !圆底 40 | \uE151 !方底 41 | \uE152 ❓圆底 42 | \uE153 i圆白底 43 | \uE14E 禁止图标 44 | \uE14D i圆空底 45 | \uE14c × 46 | \uE14B √ 47 | \uE14A > 48 | \uE149 < 49 | \uE148 上尖括号 50 | \uE147 下尖括号 51 | */ 52 | 53 | using json = nlohmann::json; 54 | using namespace tsl; 55 | 56 | constexpr const char *const amsContentsPath = "/atmosphere/contents"; 57 | //constexpr const char *const boot2FlagFormat = "/atmosphere/contents/%016lX/flags/boot2.flag"; 58 | //constexpr const char *const boot2FlagFolder = "/atmosphere/contents/%016lX/flags"; 59 | constexpr const char *const sxosTitlesPath = "/sxos/titles"; 60 | constexpr const char *const boot2FlagFile = "/%016lX/flags/boot2.flag"; 61 | constexpr const char *const boot2FlagsFolder = "/%016lX/flags"; 62 | constexpr const char *const toolboxJsonPath = "/%.*s/toolbox.json"; 63 | 64 | static constexpr u32 AMSVersionConfigItem = 65000; 65 | //static constexpr s64 SXOS_MIN_BOOT_SIZE = 10 * 1024 * 1024; 66 | 67 | #if 0 68 | /* Calibration 69 | * This is the raw data stored under the PRODINFO partition. 70 | * Offset Size Field escription 71 | * 0x0008 0x04 BodySize Total size of calibration data starting at offset 0x40. 72 | * 0x0020 0x20 BodyHash SHA256 hash calculated over calibration data. 73 | * 0x0088 0x180 WlanCountryCodes Array of WLAN country code strings. Each element is 3 bytes (code + NULL terminator). 74 | */ 75 | static constexpr s64 BodySize_OFFSET = 0x0008; 76 | static constexpr s64 BodyHash_OFFSET = 0x0020; 77 | static constexpr s64 BodyHash_SIZE = 0x20; 78 | static constexpr s64 BodyHashBeigin_OFFSET = 0x0040; 79 | static constexpr s64 WlanCountryCodes_OFFSET = 0x0088; 80 | static constexpr s64 WlanCountryCode_SIZE = 0x3; 81 | static constexpr char CHINA_WLAN_COUNTRY_CODE[WlanCountryCode_SIZE] = "S4"; 82 | static constexpr char JAPAN_WLAN_COUNTRY_CODE[WlanCountryCode_SIZE] = "U1"; 83 | static constexpr char JAPAN_WLAN_COUNTRY_CODE1[WlanCountryCode_SIZE] = "R1"; 84 | #endif 85 | 86 | static std::string boot2FlagFormat{amsContentsPath}; 87 | static std::string boot2FlagFolder{amsContentsPath}; 88 | static char pathBuffer[FS_MAX_PATH]; 89 | 90 | constexpr const char *const bootFiledescriptions[2] = { 91 | [0] = "SXOS boot.dat", 92 | [1] = "SXGEAR boot.dat" 93 | }; 94 | 95 | GuiMain::GuiMain() { 96 | Result rc; 97 | 98 | static std::string jsonStr = R"( 99 | { 100 | "PluginName": "ovl-sysmodules", 101 | "RunAndHasFlagListItemValue": "In use | \uE0F4", 102 | "RunAndNoFlagListItemValue": "In use | \uE098", 103 | "NotRunAndHasFlagListItemValue": "Not in use | \uE0F4", 104 | "NotRunAndNoFlagListItemValue": "Not in use | \uE098", 105 | "PowerCategoryHeaderText": "SWITCH Power Control | \uE0E0 Restart and Power off", 106 | "PowerCustomDrawerText": "\uE016 Quick reset or power off your console.", 107 | "PowerResetListItemKey": "Reset", 108 | "PowerResetListItemValue": "| \uE0F4", 109 | "PowerOffListItemKey": "Power off", 110 | "PowerOffListItemValue": "| \uE098", 111 | "PowerOffListItemErrorText": "spsmShutdown failed!Error code: ", 112 | "WifiSwitchCategoryHeaderText": "WIFI toggle | \uE0E0 Toggle", 113 | "WifiSwitchCustomDrawerText": "\uE016 Quick toggle Switch WIFI status.", 114 | "WifiSwitchListItemKey": "WIFI status", 115 | "WifiSwitchStatusCheckErrorListItemText": "Check WIFI status failed! Error code: ", 116 | "WifiSwitchSetErrorListItemext": "nifmSetWirelessCommunicationEnabled failed! Error code: ", 117 | "SysmodulesNotFoundScanOKCustomDrawerText": "No sysmodules found!", 118 | "SysmodulesNotFoundScanNOKCustomDrawerText": "Scan failed!", 119 | "SysmodulesDynamicCategoryHeaderText": "Dynamic | \uE0E0 Toggle | \uE0E3 Toggle auto start", 120 | "SysmodulesDynamicCustomDrawerText": "\uE016 These sysmodules can be toggled at any time.", 121 | "SysmodulesStaticCategoryHeaderText": "Static | \uE0E3 Toggle auto start", 122 | "SysmodulesStaticCustomDrawerText": "\uE016 These sysmodules need a reboot to work.", 123 | "BootFileSwitchCategoryHeaderText": "Support CFW boot file switch | \uE0E0 Toggle", 124 | "BootFileSwitchCustomDrawerText": "\uE016 Takes effect after console restart.", 125 | "BootFileSXOSBootCopyNOKListItemText": "Select SXOS boot.dat failed! Error code: ", 126 | "BootFileSXGEARBootCopyNOKListItemText": "Select SXGEAR boot.dat failed! Error code: ", 127 | "BootFileSXOSBootSourceFileNotFoundListItemText": "Select SXOS boot.dat failed! Boot file not exist!", 128 | "BootFileSXGEARBootSourceFileNotFoundListItemText": "Select SXGEAR boot.dat failed! Boot file not exist!", 129 | "HekateRestartHitCategoryHeaderText": "Update hekate setting | \uE0E0 Toggle", 130 | "HekateRestartHitCustomDrawerText": "\uE016 Takes effect after toggle and console restart.", 131 | "HekateAutoRestartHitListItemKey": "Hekate restart without hit", 132 | "HekateAutoRestartHitINIParseNOKListItemValue": "INI parse failed", 133 | "HekateAutoRestartHitININoSectionListItemValue": "INI no such section", 134 | "HekateAutoRestartHitININoParameterListItemValue": "INI no such parameter", 135 | "HekateAutoRestartHitINIWriteNOKListItemValue": "INI write failed", 136 | "VersionSwitchCategoryHeaderText": "Mainland and international version switching | \uE0E2 Mainland \uE0E3 international", 137 | "VersionSwitchCustomDrawerText": "\uE016 No need to wash white and initialize after switch. Just need restart and agree to the EULA", 138 | "VersionSwitchListItemKey": "Current version", 139 | "VersionSwitchMainlandListItemValue": "Mainland", 140 | "VersionSwitchInternationalListItemValue": "International", 141 | "VersionSwitchSetTNOKListItemValue": "setsysSetT failed, Error code: ", 142 | "VersionSwitchSetRegionCodeNOKListItemValue": "setsysSetRegionCode failed, Error code: ", 143 | "WlanCountryCodeSwitchCategoryHeaderText": "Mainland and Japen WLan country code switching | \uE0E2 Mainland \uE0E3 Japan", 144 | "WlanCountryCodeSwitchCustomDrawerText": "\uE016 Suggest to backup the PRODINFO. Takes effect after restarted.", 145 | "WlanCountryCodeSwitchListItemKey": "Current WLan Country Code", 146 | "WlanCountryCodeSwitchMainlandListItemValue": "Mainland", 147 | "WlanCountryCodeSwitchJapanListItemValue": "Japan", 148 | "WlanCountryCodeSwitchSetTNOKListItemValue": "setWLANCountryCode failed! Error Code: " 149 | } 150 | )"; 151 | std::string lanPath = std::string("sdmc:/switch/.overlays/lang/") + APPTITLE + "/"; 152 | fsdevMountSdmc(); 153 | tsl::hlp::doWithSmSession([&lanPath]{ 154 | tsl::tr::InitTrans(lanPath, jsonStr); 155 | }); 156 | fsdevUnmountDevice("sdmc"); 157 | 158 | // Open a service manager session. 159 | if (R_FAILED(rc = smInitialize())) return; 160 | 161 | if (R_FAILED(rc = nifmInitialize(NifmServiceType_Admin))) return; 162 | 163 | if (R_FAILED(rc = fsOpenSdCardFileSystem(&this->m_fs))) return; 164 | 165 | if (R_FAILED(rc = setsysInitialize())) return; 166 | 167 | std::string option; 168 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "powerControlEnabled", option))) 169 | this->m_sysmodEnabledFlags.powerControlEnabled = std::stoi(option); 170 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "wifiControlEnabled", option))) 171 | this->m_sysmodEnabledFlags.wifiControlEnabled = std::stoi(option); 172 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "sysmodulesControlEnabled", option))) 173 | this->m_sysmodEnabledFlags.sysmodulesControlEnabled = std::stoi(option); 174 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "bootFileControlEnabled", option))) 175 | this->m_sysmodEnabledFlags.bootFileControlEnabled = std::stoi(option); 176 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "hekateRestartControlEnabled", option))) 177 | this->m_sysmodEnabledFlags.hekateRestartControlEnabled = std::stoi(option); 178 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "consoleRegionControlEnabled", option))) 179 | this->m_sysmodEnabledFlags.consoleRegionControlEnabled = std::stoi(option); 180 | #if 0 181 | if (R_SUCCEEDED(rc = setGetIniConfig("sdmc:/config/" APPTITLE "/config.ini", APPTITLE, "wlanCountryCodeControlEnabled", option))) 182 | this->m_sysmodEnabledFlags.wlanCountryCodeControlEnabled = std::stoi(option); 183 | #endif 184 | 185 | /* Attempt to get the exosphere version. */ 186 | if (R_SUCCEEDED(rc = splInitialize())) { 187 | u64 version{0}; 188 | u32 version_micro{0xff}; 189 | u32 version_minor{0xff}; 190 | u32 version_major{0xff}; 191 | if (R_SUCCEEDED(rc = splGetConfig(static_cast(AMSVersionConfigItem), &version))) { 192 | version_micro = (version >> 40) & 0xff; 193 | version_minor = (version >> 48) & 0xff; 194 | version_major = (version >> 56) & 0xff; 195 | } 196 | splExit(); 197 | if (version_major == 0 && version_minor == 0 && version_micro == 0) { 198 | if (this->m_sysmodEnabledFlags.bootFileControlEnabled) 199 | this->m_bootRunning = BootDatType::SXOS_BOOT_TYPE; 200 | std::strcpy(pathBuffer, sxosTitlesPath); 201 | } else if ((version_major == 0 && version_minor >= 9 && version_micro >= 0) || (version_major == 1 && version_minor >= 0 && version_micro >= 0)) { 202 | if (this->m_sysmodEnabledFlags.bootFileControlEnabled) 203 | this->m_bootRunning = BootDatType::SXGEAR_BOOT_TYPE; 204 | std::strcpy(pathBuffer, amsContentsPath); 205 | } else { 206 | return; 207 | } 208 | } 209 | 210 | if (this->m_sysmodEnabledFlags.consoleRegionControlEnabled) { 211 | this->m_isTencentVersion = false; 212 | if (R_FAILED(rc = setsysGetT(&this->m_isTencentVersion))) { 213 | return; 214 | } 215 | } 216 | 217 | #if 0 218 | if (R_FAILED(rc = getWLANCountryCode(this->m_curCountryCode))) return; 219 | #endif 220 | 221 | if (this->m_sysmodEnabledFlags.sysmodulesControlEnabled) { 222 | FsDir contentDir; 223 | if (R_FAILED(rc = fsFsOpenDirectory(&this->m_fs, pathBuffer, FsDirOpenMode_ReadDirs, &contentDir))) 224 | return; 225 | 226 | tsl::hlp::ScopeGuard dirGuard([&] { fsDirClose(&contentDir); }); 227 | 228 | boot2FlagFormat = std::string(pathBuffer) + boot2FlagFile; 229 | boot2FlagFolder = std::string(pathBuffer) + boot2FlagsFolder; 230 | std::string toolboxJsonFormat = std::string(pathBuffer) + toolboxJsonPath; 231 | 232 | /* Iterate over contents folder. */ 233 | for (const auto &entry : FsDirIterator(contentDir)) { 234 | FsFile toolboxFile; 235 | std::snprintf(pathBuffer, FS_MAX_PATH, toolboxJsonFormat.c_str(), FS_MAX_PATH - 35, entry.name); 236 | if (R_FAILED(rc = fsFsOpenFile(&this->m_fs, pathBuffer, FsOpenMode_Read, &toolboxFile))) 237 | continue; 238 | tsl::hlp::ScopeGuard fileGuard([&] { fsFileClose(&toolboxFile); }); 239 | 240 | /* Get toolbox file size. */ 241 | s64 size; 242 | if (R_FAILED(rc = fsFileGetSize(&toolboxFile, &size))) 243 | continue; 244 | 245 | /* Read toolbox file. */ 246 | std::string toolBoxData(size, '\0'); 247 | u64 bytesRead; 248 | rc = fsFileRead(&toolboxFile, 0, toolBoxData.data(), size, FsReadOption_None, &bytesRead); 249 | if (R_FAILED(rc)) 250 | continue; 251 | 252 | /* Parse toolbox file data. */ 253 | json toolboxFileContent = json::parse(toolBoxData); 254 | 255 | u64 sysmoduleProgramId = std::strtoul(entry.name, nullptr, 16); 256 | 257 | /* Let's not allow Tesla to be killed with this. */ 258 | if (sysmoduleProgramId == 0x420000000007E51AULL) 259 | continue; 260 | 261 | SystemModule module = { 262 | .listItem = new tsl::elm::ListItem(toolboxFileContent["name"]), 263 | .programId = sysmoduleProgramId, 264 | .needReboot = toolboxFileContent["requires_reboot"], 265 | }; 266 | 267 | module.listItem->setClickListener([this, module](u64 click) -> bool { 268 | /* if the folder "flags" does not exist, it will be created */ 269 | std::snprintf(pathBuffer, FS_MAX_PATH, boot2FlagFolder.c_str(), module.programId); 270 | fsFsCreateDirectory(&this->m_fs, pathBuffer); 271 | std::snprintf(pathBuffer, FS_MAX_PATH, boot2FlagFormat.c_str(), module.programId); 272 | 273 | if (click & HidNpadButton_A && !module.needReboot) { 274 | if (this->isRunning(module)) { 275 | /* Kill process. */ 276 | pmshellTerminateProgram(module.programId); 277 | 278 | /* Remove boot2 flag file. */ 279 | if (this->hasFlag(module)) 280 | fsFsDeleteFile(&this->m_fs, pathBuffer); 281 | } else { 282 | /* Start process. */ 283 | const NcmProgramLocation programLocation{ 284 | .program_id = module.programId, 285 | .storageID = NcmStorageId_None, 286 | }; 287 | u64 pid = 0; 288 | pmshellLaunchProgram(0, &programLocation, &pid); 289 | 290 | /* Create boot2 flag file. */ 291 | if (!this->hasFlag(module)) 292 | fsFsCreateFile(&this->m_fs, pathBuffer, 0, FsCreateOption(0)); 293 | } 294 | return true; 295 | } 296 | 297 | if (click & HidNpadButton_Y) { 298 | if (this->hasFlag(module)) { 299 | /* Remove boot2 flag file. */ 300 | fsFsDeleteFile(&this->m_fs, pathBuffer); 301 | } else { 302 | /* Create boot2 flag file. */ 303 | fsFsCreateFile(&this->m_fs, pathBuffer, 0, FsCreateOption(0)); 304 | } 305 | return true; 306 | } 307 | 308 | return false; 309 | }); 310 | this->m_sysmoduleListItems.push_back(std::move(module)); 311 | } 312 | this->m_scanned = true; 313 | } 314 | } 315 | 316 | GuiMain::~GuiMain() { 317 | setsysExit(); 318 | fsFsClose(&this->m_fs); 319 | nifmExit(); 320 | smExit(); 321 | } 322 | 323 | tsl::elm::Element *GuiMain::createUI() { 324 | tsl::elm::OverlayFrame *rootFrame = new tsl::elm::OverlayFrame("PluginName"_tr, VERSION); 325 | 326 | tsl::elm::List *sysmoduleList = new tsl::elm::List(); 327 | 328 | if (this->m_sysmodEnabledFlags.powerControlEnabled) { 329 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("PowerCategoryHeaderText"_tr, true)); 330 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 331 | renderer->drawString("PowerCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 332 | }), 30); 333 | tsl::elm::ListItem *powerResetListItem = new tsl::elm::ListItem("PowerResetListItemKey"_tr); 334 | powerResetListItem->setValue("PowerResetListItemValue"_tr); 335 | powerResetListItem->setClickListener([this, powerResetListItem](u64 click) -> bool { 336 | if (click & HidNpadButton_A) { 337 | Result rc; 338 | //if (R_FAILED(rc = bpcInitialize()) || R_FAILED(rc = bpcRebootSystem())) 339 | if (R_FAILED(rc = spsmInitialize()) || R_FAILED(rc = spsmShutdown(true))) 340 | powerResetListItem->setText("PowerListItemErrorText"_tr + std::to_string(rc)); 341 | spsmExit(); 342 | //bpcExit(); 343 | return true; 344 | } 345 | return false; 346 | }); 347 | sysmoduleList->addItem(powerResetListItem); 348 | tsl::elm::ListItem *powerOffListItem = new tsl::elm::ListItem("PowerOffListItemKey"_tr); 349 | powerOffListItem->setValue("PowerOffListItemValue"_tr); 350 | powerOffListItem->setClickListener([this, powerOffListItem](u64 click) -> bool { 351 | if (click & HidNpadButton_A) { 352 | Result rc; 353 | //if (R_FAILED(rc = bpcInitialize()) || R_FAILED(rc = bpcShutdownSystem())) 354 | if (R_FAILED(rc = spsmInitialize()) || R_FAILED(rc = spsmShutdown(false))) 355 | powerOffListItem->setText("PowerListItemErrorText"_tr + std::to_string(rc)); 356 | spsmExit(); 357 | //bpcExit(); 358 | return true; 359 | } 360 | return false; 361 | }); 362 | sysmoduleList->addItem(powerOffListItem); 363 | } 364 | 365 | if (this->m_sysmodEnabledFlags.wifiControlEnabled) { 366 | tsl::elm::CategoryHeader *wifiSwitchCatHeader = new tsl::elm::CategoryHeader("WifiSwitchCategoryHeaderText"_tr, true); 367 | sysmoduleList->addItem(wifiSwitchCatHeader); 368 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 369 | renderer->drawString("WifiSwitchCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 370 | }), 30); 371 | this->m_listItemWifiSwitch = new tsl::elm::ListItem("WifiSwitchListItemKey"_tr); 372 | Result rc; 373 | if (R_FAILED(rc = nifmIsWirelessCommunicationEnabled(&this->m_isWifiOn))) 374 | this->m_listItemWifiSwitch->setValue("WifiSwitchStatusCheckErrorListItemText"_tr + std::to_string(rc)); 375 | this->m_listItemWifiSwitch->setClickListener([this](u64 click) -> bool { 376 | if (click == HidNpadButton_A) { 377 | Result rc; 378 | bool isWifiOn = false; 379 | if (R_FAILED(rc = nifmIsWirelessCommunicationEnabled(&isWifiOn))) 380 | this->m_listItemWifiSwitch->setValue("WifiSwitchStatusCheckErrorListItemText"_tr + std::to_string(rc)); 381 | else { 382 | if (R_FAILED(rc = nifmSetWirelessCommunicationEnabled(!isWifiOn))) { 383 | this->m_listItemWifiSwitch->setValue("WifiSwitchSetErrorListItemext"_tr + std::to_string(rc)); 384 | } else { 385 | this->m_isWifiOn = !isWifiOn; 386 | } 387 | } 388 | if (R_FAILED(rc)) 389 | return false; 390 | else 391 | return true; 392 | } 393 | return false; 394 | }); 395 | sysmoduleList->addItem(this->m_listItemWifiSwitch); 396 | } 397 | 398 | if (this->m_sysmodEnabledFlags.sysmodulesControlEnabled) { 399 | if (this->m_sysmoduleListItems.size() == 0) { 400 | std::string description = this->m_scanned ? "SysmodulesNotFoundScanOKCustomDrawerText"_tr : "SysmodulesNotFoundScanNOKCustomDrawerText"_tr; 401 | auto *warning = new tsl::elm::CustomDrawer([description](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 402 | renderer->drawString("\uE150", false, 180, 250, 90, renderer->a(0xFFFF)); 403 | renderer->drawString(description.c_str(), false, 110, 340, 25, renderer->a(0xFFFF)); 404 | }); 405 | sysmoduleList->addItem(warning); 406 | } else { 407 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("SysmodulesDynamicCategoryHeaderText"_tr, true)); 408 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 409 | renderer->drawString("SysmodulesDynamicCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 410 | }), 30); 411 | for (const auto &module : this->m_sysmoduleListItems) { 412 | if (!module.needReboot) 413 | sysmoduleList->addItem(module.listItem); 414 | } 415 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("SysmodulesStaticCategoryHeaderText"_tr, true)); 416 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 417 | renderer->drawString("SysmodulesStaticCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 418 | }), 30); 419 | for (const auto &module : this->m_sysmoduleListItems) { 420 | if (module.needReboot) 421 | sysmoduleList->addItem(module.listItem); 422 | } 423 | } 424 | } 425 | 426 | if (this->m_sysmodEnabledFlags.bootFileControlEnabled) { 427 | tsl::elm::CategoryHeader *bootCatHeader = new tsl::elm::CategoryHeader("BootFileSwitchCategoryHeaderText"_tr, true); 428 | sysmoduleList->addItem(bootCatHeader); 429 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 430 | renderer->drawString("BootFileSwitchCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 431 | }), 30); 432 | this->m_listItemSXOSBootType = new tsl::elm::ListItem(bootFiledescriptions[0]); 433 | this->m_listItemSXOSBootType->setClickListener([this, bootCatHeader](u64 click) -> bool { 434 | if (click & HidNpadButton_A) { 435 | if (this->m_bootRunning == BootDatType::SXOS_BOOT_TYPE) return true; 436 | Result rc; 437 | rc = this->CopyFile("/bootloader/boot-sxos.dat", "/boot.dat"); 438 | if (R_FAILED(rc)) { 439 | if (rc == 514) { 440 | bootCatHeader->setText("BootFileSXOSBootSourceFileNotFoundListItemText"_tr); 441 | } else { 442 | bootCatHeader->setText("BootFileSXOSBootCopyNOKListItemText"_tr + std::to_string(rc)); 443 | } 444 | return false; 445 | } 446 | this->m_bootRunning = BootDatType::SXOS_BOOT_TYPE; 447 | return true; 448 | } 449 | return false; 450 | }); 451 | sysmoduleList->addItem(this->m_listItemSXOSBootType); 452 | this->m_listItemSXGEARBootType = new tsl::elm::ListItem(bootFiledescriptions[1]); 453 | this->m_listItemSXGEARBootType->setClickListener([this, bootCatHeader](u64 click) -> bool { 454 | if (click & HidNpadButton_A) { 455 | if (this->m_bootRunning == BootDatType::SXGEAR_BOOT_TYPE) return true; 456 | Result rc; 457 | rc = CopyFile("/bootloader/boot-sxgear.dat", "/boot.dat"); 458 | if (R_FAILED(rc)) { 459 | if (rc == 514) { 460 | bootCatHeader->setText("BootFileSXGEARBootSourceFileNotFoundListItemText"_tr); 461 | } else { 462 | bootCatHeader->setText("BootFileSXGEARBootCopyNOKListItemText"_tr + std::to_string(rc)); 463 | } 464 | return false; 465 | } 466 | this->m_bootRunning = BootDatType::SXGEAR_BOOT_TYPE; 467 | return true; 468 | } 469 | return false; 470 | }); 471 | sysmoduleList->addItem(this->m_listItemSXGEARBootType); 472 | } 473 | 474 | if (this->m_sysmodEnabledFlags.hekateRestartControlEnabled) { 475 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("HekateRestartHitCategoryHeaderText"_tr, true)); 476 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 477 | renderer->drawString("HekateRestartHitCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 478 | }), 30); 479 | tsl::elm::ListItem *opAutoboot = new tsl::elm::ListItem("HekateAutoRestartHitListItemKey"_tr); 480 | static std::string autobootValue = "-1"; 481 | Result rc = setGetIniConfig("/bootloader/hekate_ipl.ini", "config", "autoboot", autobootValue); 482 | switch (rc) 483 | { 484 | case 1: 485 | opAutoboot->setValue("HekateAutoRestartHitINIParseNOKListItemValue"_tr); 486 | break; 487 | case 2: 488 | opAutoboot->setValue("HekateAutoRestartHitININoSectionListItemValue"_tr); 489 | break; 490 | case 3: 491 | opAutoboot->setValue("HekateAutoRestartHitININoParameterListItemValue"_tr); 492 | break; 493 | default: 494 | break; 495 | } 496 | if (rc) { 497 | sysmoduleList->addItem(opAutoboot); 498 | rootFrame->setContent(sysmoduleList); 499 | return rootFrame; 500 | } 501 | opAutoboot->setValue(autobootValue); 502 | opAutoboot->setClickListener([this, opAutoboot](u64 click) -> bool { 503 | if (click & HidNpadButton_A) { 504 | if (autobootValue == "1") 505 | autobootValue = "0"; 506 | else if (autobootValue == "0") 507 | autobootValue = "1"; 508 | else 509 | autobootValue = "-1"; 510 | opAutoboot->setValue(autobootValue); 511 | Result rc; 512 | rc = setGetIniConfig("/bootloader/hekate_ipl.ini", "config", "autoboot", autobootValue, false); 513 | switch (rc) 514 | { 515 | case 1: 516 | opAutoboot->setValue("HekateAutoRestartHitINIParseNOKListItemValue"_tr); 517 | break; 518 | case 2: 519 | opAutoboot->setValue("HekateAutoRestartHitININoSectionListItemValue"_tr); 520 | break; 521 | case 3: 522 | opAutoboot->setValue("HekateAutoRestartHitININoParameterListItemValue"_tr); 523 | break; 524 | case 4: 525 | opAutoboot->setValue("HekateAutoRestartHitINIWriteNOKListItemValue"_tr); 526 | break; 527 | default: 528 | break; 529 | } 530 | 531 | if (rc) return false; 532 | 533 | return true; 534 | } 535 | return false; 536 | }); 537 | sysmoduleList->addItem(opAutoboot); 538 | } 539 | 540 | if (this->m_sysmodEnabledFlags.consoleRegionControlEnabled) { 541 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("VersionSwitchCategoryHeaderText"_tr, true)); 542 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 543 | renderer->drawString("VersionSwitchCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 544 | }), 30); 545 | tsl::elm::ListItem *verSwitchItem = new tsl::elm::ListItem("VersionSwitchListItemKey"_tr); 546 | verSwitchItem->setValue(this->m_isTencentVersion ? "VersionSwitchMainlandListItemValue"_tr : "VersionSwitchInternationalListItemValue"_tr); 547 | verSwitchItem->setClickListener([this, verSwitchItem](u64 click) -> bool { 548 | Result rc; 549 | if (click & HidNpadButton_X) { 550 | if (this->m_isTencentVersion) return true; 551 | if (R_FAILED(rc = setsysSetT(true))) { 552 | verSwitchItem->setText("VersionSwitchSetTNOKListItemValue"_tr + std::to_string(rc)); 553 | return false; 554 | } 555 | if (R_FAILED(rc = setsysSetRegionCode(SetRegion_CHN))) { 556 | verSwitchItem->setText("VersionSwitchSetRegionCodeNOKListItemValue"_tr + std::to_string(rc)); 557 | return false; 558 | } 559 | this->m_isTencentVersion = true; 560 | verSwitchItem->setValue("VersionSwitchMainlandListItemValue"_tr); 561 | return true; 562 | } else if (click & HidNpadButton_Y) { 563 | if (!this->m_isTencentVersion) return true; 564 | if (R_FAILED(rc = setsysSetT(false))) { 565 | verSwitchItem->setText("VersionSwitchSetTNOKListItemValue"_tr + std::to_string(rc)); 566 | return false; 567 | } 568 | if (R_FAILED(rc = setsysSetRegionCode(SetRegion_HTK))) { 569 | verSwitchItem->setText("VersionSwitchSetRegionCodeNOKListItemValue"_tr + std::to_string(rc)); 570 | return false; 571 | } 572 | this->m_isTencentVersion = false; 573 | verSwitchItem->setValue("VersionSwitchInternationalListItemValue"_tr); 574 | return true; 575 | } 576 | return false; 577 | }); 578 | sysmoduleList->addItem(verSwitchItem); 579 | } 580 | 581 | #if 0 582 | if (this->m_sysmodEnabledFlags.wlanCountryCodeControlEnabled) { 583 | sysmoduleList->addItem(new tsl::elm::CategoryHeader("WlanCountryCodeSwitchCategoryHeaderText"_tr, true)); 584 | sysmoduleList->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 585 | renderer->drawString("WlanCountryCodeSwitchCustomDrawerText"_tr.c_str(), false, x + 5, y + 20, 15, renderer->a(tsl::style::color::ColorDescription)); 586 | }), 30); 587 | tsl::elm::ListItem *wlanCountryCodeSwitchItem = new tsl::elm::ListItem("WlanCountryCodeSwitchListItemKey"_tr); 588 | wlanCountryCodeSwitchItem->setValue((this->m_curCountryCode.compare(CHINA_WLAN_COUNTRY_CODE) == 0) ? "WlanCountryCodeSwitchMainlandListItemValue"_tr : "WlanCountryCodeSwitchJapanListItemValue"_tr); 589 | wlanCountryCodeSwitchItem->setClickListener([this, wlanCountryCodeSwitchItem](u64 click) -> bool { 590 | Result rc; 591 | if (click & HidNpadButton_X) { 592 | if (this->m_curCountryCode.compare(CHINA_WLAN_COUNTRY_CODE) == 0) return true; 593 | if (R_FAILED(rc = this->setWLANCountryCode(CHINA_WLAN_COUNTRY_CODE))) { 594 | wlanCountryCodeSwitchItem->setText("WlanCountryCodeSwitchSetTNOKListItemValue"_tr + std::to_string(rc)); 595 | return false; 596 | } 597 | this->m_curCountryCode = CHINA_WLAN_COUNTRY_CODE; 598 | wlanCountryCodeSwitchItem->setValue("WlanCountryCodeSwitchMainlandListItemValue"_tr); 599 | return true; 600 | } else if (click & HidNpadButton_Y) { 601 | if (this->m_curCountryCode.compare(JAPAN_WLAN_COUNTRY_CODE) == 0) return true; 602 | if (R_FAILED(rc = this->setWLANCountryCode(JAPAN_WLAN_COUNTRY_CODE))) { 603 | wlanCountryCodeSwitchItem->setText("WlanCountryCodeSwitchSetTNOKListItemValue"_tr + std::to_string(rc)); 604 | return false; 605 | } 606 | this->m_curCountryCode = JAPAN_WLAN_COUNTRY_CODE; 607 | wlanCountryCodeSwitchItem->setValue("WlanCountryCodeSwitchJapanListItemValue"_tr); 608 | return true; 609 | } 610 | return false; 611 | }); 612 | sysmoduleList->addItem(wlanCountryCodeSwitchItem); 613 | } 614 | #endif 615 | 616 | rootFrame->setContent(sysmoduleList); 617 | 618 | return rootFrame; 619 | } 620 | 621 | Result GuiMain::setGetIniConfig(std::string iniPath, std::string iniSection, std::string iniOption, std::string &iniValue, bool getOption) { 622 | Result ret = 0; 623 | 624 | fsdevMountSdmc(); 625 | simpleIniParser::Ini *ini = simpleIniParser::Ini::parseFile(iniPath); 626 | if (!ini) ret = 1; 627 | simpleIniParser::IniSection *section = ini->findSection(iniSection); 628 | if (!section) ret = 2; 629 | simpleIniParser::IniOption *option = section->findFirstOption(iniOption); 630 | if (!option) ret = 3; 631 | 632 | if (!ret) { 633 | if (getOption) { 634 | iniValue = option->value; 635 | } else { 636 | option->value = iniValue; 637 | if (!(ini->writeToFile(iniPath))) ret = 4; 638 | } 639 | } 640 | fsdevUnmountDevice("sdmc"); 641 | 642 | return ret; 643 | } 644 | 645 | Result GuiMain::CopyFile(const char *srcPath, const char *destPath) { 646 | Result ret{0}; 647 | 648 | FsFile src_handle, dest_handle; 649 | if (R_FAILED(ret = fsFsOpenFile(&this->m_fs, srcPath, FsOpenMode_Read, &src_handle))) return ret; 650 | tsl::hlp::ScopeGuard fileGuard1([&] { fsFileClose(&src_handle); }); 651 | 652 | s64 size = 0; 653 | if (R_FAILED(ret = fsFileGetSize(&src_handle, &size))) return ret; 654 | 655 | if (R_SUCCEEDED(fsFsOpenFile(&this->m_fs, destPath, FsOpenMode_Read, &dest_handle))) { 656 | fsFileClose(&dest_handle); 657 | if (R_FAILED(ret = fsFsDeleteFile(&this->m_fs, destPath))) return ret; 658 | if (R_FAILED(ret = fsFsCreateFile(&this->m_fs, destPath, size, 0))) return ret; 659 | } 660 | 661 | if (R_FAILED(ret = fsFsOpenFile(&this->m_fs, destPath, FsOpenMode_Write, &dest_handle))) return ret; 662 | tsl::hlp::ScopeGuard fileGuard2([&] { fsFileClose(&dest_handle); }); 663 | 664 | u64 bytes_read = 0; 665 | const u64 buf_size = 0x10000; 666 | s64 offset = 0; 667 | unsigned char *buf = new unsigned char[buf_size]; 668 | tsl::hlp::ScopeGuard fileGuard3([&] { delete[] buf; }); 669 | std::string filename = std::filesystem::path(srcPath).filename(); 670 | 671 | do { 672 | std::memset(buf, 0, buf_size); 673 | if (R_FAILED(ret = fsFileRead(&src_handle, offset, buf, buf_size, FsReadOption_None, &bytes_read))) return ret; 674 | if (R_FAILED(ret = fsFileWrite(&dest_handle, offset, buf, bytes_read, FsWriteOption_Flush))) return ret; 675 | offset += bytes_read; 676 | } while(offset < size); 677 | 678 | return ret; 679 | } 680 | 681 | void GuiMain::update() { 682 | static u8 counter = 0; 683 | 684 | if (counter++ % 15 != 0) 685 | return; 686 | else 687 | counter = 0; 688 | 689 | if (this->m_sysmodEnabledFlags.sysmodulesControlEnabled) { 690 | for (const auto &module : this->m_sysmoduleListItems) { 691 | this->updateStatus(module); 692 | } 693 | } 694 | 695 | if (this->m_sysmodEnabledFlags.bootFileControlEnabled) { 696 | this->m_listItemSXOSBootType->setValue((this->m_bootRunning == BootDatType::SXOS_BOOT_TYPE) ? "RunAndHasFlagListItemValue"_tr : "NotRunAndNoFlagListItemValue"_tr); 697 | this->m_listItemSXGEARBootType->setValue((this->m_bootRunning == BootDatType::SXGEAR_BOOT_TYPE) ? "RunAndHasFlagListItemValue"_tr : "NotRunAndNoFlagListItemValue"_tr); 698 | } 699 | 700 | if (this->m_sysmodEnabledFlags.wifiControlEnabled) { 701 | this->m_listItemWifiSwitch->setValue(this->m_isWifiOn ? "RunAndHasFlagListItemValue"_tr : "NotRunAndNoFlagListItemValue"_tr); 702 | } 703 | } 704 | 705 | void GuiMain::updateStatus(const SystemModule &module) { 706 | bool running = this->isRunning(module); 707 | bool hasFlag = this->hasFlag(module); 708 | 709 | static const std::string descriptions[2][2] = { 710 | [0] = { 711 | [0] = "NotRunAndNoFlagListItemValue"_tr, 712 | [1] = "NotRunAndHasFlagListItemValue"_tr, 713 | }, 714 | [1] = { 715 | [0] = "RunAndNoFlagListItemValue"_tr, 716 | [1] = "RunAndHasFlagListItemValue"_tr, 717 | }, 718 | }; 719 | 720 | module.listItem->setValue(descriptions[running][hasFlag]); 721 | } 722 | 723 | bool GuiMain::hasFlag(const SystemModule &module) { 724 | FsFile flagFile; 725 | std::snprintf(pathBuffer, FS_MAX_PATH, boot2FlagFormat.c_str(), module.programId); 726 | Result rc = fsFsOpenFile(&this->m_fs, pathBuffer, FsOpenMode_Read, &flagFile); 727 | if (R_SUCCEEDED(rc)) { 728 | fsFileClose(&flagFile); 729 | return true; 730 | } else { 731 | return false; 732 | } 733 | } 734 | 735 | bool GuiMain::isRunning(const SystemModule &module) { 736 | u64 pid = 0; 737 | if (R_FAILED(pmdmntGetProcessId(&pid, module.programId))) 738 | return false; 739 | return pid > 0; 740 | } 741 | 742 | #if 0 743 | Result GuiMain::setWLANCountryCode(std::string wlanCountCode) 744 | { 745 | Result rc = 1; 746 | FsStorage fs; 747 | u32 calibrationDataSize = 0; 748 | u8 oriHash[BodyHash_SIZE]; 749 | u8 newHash[BodyHash_SIZE]; 750 | u8 oriWlanCountCode[WlanCountryCode_SIZE] = {}; 751 | u8* buffer = nullptr; 752 | 753 | if (R_SUCCEEDED(rc = fsOpenBisStorage(&fs, FsBisPartitionId_CalibrationBinary))) { 754 | if (R_SUCCEEDED(rc = fsStorageRead(&fs, BodySize_OFFSET, &calibrationDataSize, sizeof(calibrationDataSize)))) { 755 | if (R_SUCCEEDED(rc = fsStorageRead(&fs, BodyHash_OFFSET, oriHash, sizeof(oriHash)))) { 756 | if (R_SUCCEEDED(rc = fsStorageRead(&fs, WlanCountryCodes_OFFSET, oriWlanCountCode, WlanCountryCode_SIZE))) { 757 | // 写之前要加密? 758 | if (R_SUCCEEDED(rc = fsStorageWrite(&fs, WlanCountryCodes_OFFSET, wlanCountCode.c_str(), WlanCountryCode_SIZE))) { 759 | buffer = new u8[calibrationDataSize]; 760 | if (buffer) { 761 | if (R_SUCCEEDED(rc = fsStorageRead(&fs, BodyHashBeigin_OFFSET, buffer, calibrationDataSize))) { 762 | sha256CalculateHash(newHash, buffer, calibrationDataSize); 763 | if (R_FAILED(rc = fsStorageWrite(&fs, BodyHash_OFFSET, newHash, BodyHash_SIZE))) { 764 | if (R_SUCCEEDED(rc = fsStorageRead(&fs, BodyHashBeigin_OFFSET, buffer, calibrationDataSize))) { 765 | sha256CalculateHash(newHash, buffer, calibrationDataSize); 766 | if (R_FAILED(rc = memcmp(oriHash, newHash, sizeof(oriHash)))) { 767 | if (R_FAILED(rc = fsStorageWrite(&fs, WlanCountryCodes_OFFSET, oriWlanCountCode, WlanCountryCode_SIZE))) { 768 | rc = fsStorageWrite(&fs, BodyHash_OFFSET, oriHash, BodyHash_SIZE); 769 | } 770 | } 771 | } 772 | } 773 | } 774 | delete buffer; 775 | buffer = nullptr; 776 | } 777 | } 778 | } 779 | } 780 | } 781 | fsStorageClose(&fs); 782 | } 783 | 784 | return rc; 785 | } 786 | 787 | Result GuiMain::getWLANCountryCode(std::string &outWlanCountCode) 788 | { 789 | Result rc = 1; 790 | SetCalCountryCode wlanCountrycodes{}; 791 | s32 wlanCountryCodeTotalcounts = 0; 792 | if (R_SUCCEEDED(rc = setcalInitialize())) { 793 | if (R_SUCCEEDED(rc = setcalGetWirelessLanCountryCodes(&wlanCountryCodeTotalcounts, &wlanCountrycodes, 1))) { 794 | outWlanCountCode = wlanCountrycodes.code; 795 | } else { 796 | outWlanCountCode = ""; 797 | } 798 | setcalExit(); 799 | } 800 | return rc; 801 | } 802 | #endif --------------------------------------------------------------------------------