This commit is contained in:
souldbminersmwc
2025-12-23 19:10:41 -05:00
parent 152f92a9a9
commit b5022ea839
43 changed files with 5143 additions and 3939 deletions

View File

@@ -1,8 +1,8 @@
/********************************************************************************
* File: audio_player.hpp
* File: audio.hpp
* Author: ppkantorski
* Description:
* This header defines the AudioPlayer class and related structures used for
* This header defines the Audio class and related structures used for
* handling sound playback within the Ultrahand Overlay. It provides interfaces
* for loading, caching, and playing WAV audio through libnxs audout service,
* along with basic sound type management and synchronization support.
@@ -25,9 +25,10 @@
#include <atomic>
#include <cstring>
#include <mutex>
#include "tsl_utils.hpp"
namespace ult {
class AudioPlayer {
class Audio {
public:
enum class SoundType : uint8_t { // <- uint8_t saves space
Navigate,
@@ -64,7 +65,7 @@ namespace ult {
static void setMasterVolume(float volume);
static void setEnabled(bool enabled);
static bool isEnabled();
static bool isDocked();
//static bool isDocked();
static bool reloadIfDockedChanged();
static void reloadAllSounds();
static void unloadAllSounds(const std::initializer_list<SoundType>& excludeSounds = {});

View File

@@ -12,7 +12,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once

View File

@@ -13,7 +13,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once

View File

@@ -14,7 +14,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once

View File

@@ -13,7 +13,7 @@
* altered or removed.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
@@ -39,6 +39,11 @@ namespace ult {
extern const std::string ROOT_PATH;
extern const std::string SETTINGS_PATH;
extern const std::string NX_OVLLOADER_PATH;
extern const std::string OVL_HEAP_CONFIG_PATH;
extern const std::string OVL_EXIT_FLAG_PATH;
extern const std::string ULTRAHAND_CONFIG_INI_PATH;
extern const std::string TESLA_CONFIG_INI_PATH;
extern const std::string LANG_PATH;
@@ -63,7 +68,8 @@ namespace ult {
extern const std::string PACKAGE_FILENAME;
extern const std::string DOWNLOADS_PATH;
extern const std::string EXPANSION_PATH;
//extern const std::string EXPANSION_PATH;
extern const std::string FUSE_DATA_INI_PATH;
extern const std::string PACKAGE_PATH;
extern const std::string OVERLAY_PATH;
@@ -77,12 +83,13 @@ namespace ult {
extern const std::string ULTRAHAND_REPO_URL;
extern const std::string INCLUDED_THEME_FOLDER_URL;
extern const std::string LATEST_RELEASE_INFO_URL;
extern const std::string NX_OVLLOADER_ZIP_URL;
extern const std::string NX_OVLLOADER_PLUS_ZIP_URL;
extern const std::string LATEST_UPDATER_INI_URL;
//extern const std::string NX_OVLLOADER_ZIP_URL;
//extern const std::string NX_OVLLOADER_PLUS_ZIP_URL;
extern const std::string OLD_NX_OVLLOADER_ZIP_URL;
extern const std::string OLD_NX_OVLLOADER_PLUS_ZIP_URL;
//extern const std::string OLD_NX_OVLLOADER_PLUS_ZIP_URL;
extern const std::string UPDATER_PAYLOAD_URL;
extern const std::string SOUND_EFFECTS_URL;
//extern const std::string SOUND_EFFECTS_URL;
extern const std::string LAUNCH_ARGS_STR;
extern const std::string USE_LAUNCH_ARGS_STR;
@@ -137,6 +144,7 @@ namespace ult {
extern const std::string FALSE_STR;
extern const std::string GLOBAL_STR;
extern const std::string DEFAULT_STR;
extern const std::string HOLD_STR;
extern const std::string SLOT_STR;
extern const std::string OPTION_STR;
extern const std::string FORWARDER_STR;
@@ -161,6 +169,7 @@ namespace ult {
extern const std::string INPROGRESS_SYMBOL;
extern const std::string STAR_SYMBOL;
extern const std::string DIVIDER_SYMBOL;
extern const std::string NOTIFY_HEADER;
extern const std::vector<std::string> THROBBER_SYMBOLS;

View File

@@ -26,12 +26,12 @@
namespace ult {
//extern bool rumbleInitialized;
extern std::atomic<bool> rumbleActive;
extern std::atomic<bool> clickActive;
extern std::atomic<bool> doubleClickActive;
//void initRumble();
void deinitRumble();
void checkAndReinitRumble();
void initHaptics();
void deinitHaptics();
void checkAndReinitHaptics();
void rumbleClick();
void rumbleDoubleClick();

View File

@@ -13,7 +13,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once
@@ -206,6 +206,9 @@ namespace ult {
std::string extractVersionFromBinary(const std::string &filePath);
std::string decodeBase64ToString(const std::string& b64);
}
#endif

View File

@@ -13,7 +13,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once
@@ -290,7 +290,7 @@ namespace ult {
//}
void syncIniValue(std::map<std::string, std::map<std::string, std::string>>& packageConfigData,
bool syncIniValue(std::map<std::string, std::map<std::string, std::string>>& packageConfigData,
const std::string& packageConfigIniPath,
const std::string& optionName,
const std::string& key,
@@ -339,6 +339,36 @@ namespace ult {
* @param data The complete INI data structure to save.
*/
void saveIniFileData(const std::string& filePath, const std::map<std::string, std::map<std::string, std::string>>& data);
/**
* @brief Adds a key-value pair to all sections that contain a specified pattern key.
*
* If patternKey is empty, the key-value pair will be added to ALL sections.
* If patternKey is specified, only sections containing that key will be modified.
*
* @param filePath The path to the INI file.
* @param patternKey The key to search for (empty = all sections).
* @param newKey The new key to add.
* @param newValue The value for the new key.
*/
void addKeyToMatchingSections(const std::string& filePath, const std::string& patternKey,
const std::string& newKey, const std::string& newValue);
/**
* @brief Removes a key from all sections that contain a specified pattern key.
*
* If patternKey is empty, the key will be removed from ALL sections.
* If patternKey is specified, only sections containing that key will have keyToRemove deleted.
*
* @param filePath The path to the INI file.
* @param patternKey The key to search for (empty = all sections).
* @param keyToRemove The key to remove from matching sections.
*/
void removeKeyFromMatchingSections(const std::string& filePath, const std::string& patternKey,
const std::string& keyToRemove);
}
#endif

View File

@@ -12,8 +12,9 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once
#ifndef JSON_FUNCS_HPP
#define JSON_FUNCS_HPP

View File

@@ -14,7 +14,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
@@ -70,7 +70,7 @@ namespace ult {
// Function to read file into a vector of strings
std::vector<std::string> readListFromFile(const std::string& filePath, size_t maxLines=0);
std::vector<std::string> readListFromFile(const std::string& filePath, size_t maxLines=0, bool preserveNewlines = false);
// Function to get an entry from the list based on the index
@@ -89,7 +89,7 @@ namespace ult {
// Function to read file into a set of strings
std::unordered_set<std::string> readSetFromFile(const std::string& filePath);
std::unordered_set<std::string> readSetFromFile(const std::string& filePath, const std::string& packagePath = "");
// Function to write a set to a file

View File

@@ -13,7 +13,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2024-2025 ppkantorski
********************************************************************************/
#pragma once

View File

@@ -14,7 +14,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once
@@ -36,6 +36,7 @@
#include "get_funcs.hpp"
#include <queue>
#include <mutex>
#include <unordered_set>
namespace ult {
@@ -143,7 +144,7 @@ namespace ult {
*
* @param pathPattern The pattern used to match and delete files or directories.
*/
void deleteFileOrDirectoryByPattern(const std::string& pathPattern, const std::string& logSource = "");
void deleteFileOrDirectoryByPattern(const std::string& pathPattern, const std::string& logSourc = "", const std::unordered_set<std::string>* filterSet = nullptr);
void moveDirectory(const std::string& sourcePath, const std::string& destinationPath,
@@ -176,12 +177,16 @@ namespace ult {
*
* This function identifies files or directories that match the `sourcePathPattern` and moves them to the `destinationPath`.
* It processes each matching entry in the source directory pattern and moves them to the specified destination.
* Files/directories in the filterSet will be skipped.
*
* @param sourcePathPattern The pattern used to match files or directories to be moved.
* @param destinationPath The destination directory where matching files or directories will be moved.
* @param logSource Optional log source identifier.
* @param logDestination Optional log destination identifier.
* @param filterSet Optional set of paths to exclude from moving (nullptr to move all).
*/
void moveFilesOrDirectoriesByPattern(const std::string& sourcePathPattern, const std::string& destinationPath,
const std::string& logSource = "", const std::string& logDestination = "");
const std::string& logSource = "", const std::string& logDestination = "", const std::unordered_set<std::string>* filterSet = nullptr);
@@ -227,12 +232,16 @@ namespace ult {
*
* This function identifies files or directories that match the `sourcePathPattern` and copies them to the `toDirectory`.
* It processes each matching entry in the source directory pattern and copies them to the specified destination.
* Files/directories in the filterSet will be skipped.
*
* @param sourcePathPattern The pattern used to match files or directories to be copied.
* @param toDirectory The destination directory where matching files or directories will be copied.
* @param logSource Optional log source identifier.
* @param logDestination Optional log destination identifier.
* @param filterSet Optional set of paths to exclude from copying (nullptr to copy all).
*/
void copyFileOrDirectoryByPattern(const std::string& sourcePathPattern, const std::string& toDirectory,
const std::string& logSource = "", const std::string& logDestination = "");
const std::string& logSource = "", const std::string& logDestination = "", const std::unordered_set<std::string>* filterSet = nullptr);

View File

@@ -14,7 +14,7 @@
* of the project's documentation and must remain intact.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
#pragma once
@@ -40,7 +40,7 @@ namespace ult {
extern int stoi(const std::string& str, std::size_t* pos = nullptr, int base = 10);
extern float stof(const std::string& str);
extern bool canConvertToInt(const std::string& str);
//extern bool canConvertToInt(const std::string& str);
/**
* @brief A lightweight string stream class that mimics basic functionality of std::istringstream.
@@ -144,7 +144,7 @@ namespace ult {
* @param input The input string to process.
* @return The string with multiple slashes replaced.
*/
std::string replaceMultipleSlashes(const std::string& input);
//std::string replaceMultipleSlashes(const std::string& input);
void resolveDirectoryTraversal(std::string& path);

View File

@@ -18,7 +18,7 @@
* altered or removed.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2023-2025 ppkantorski
********************************************************************************/
@@ -54,39 +54,39 @@
#include <map>
#include <barrier>
#ifndef APPROXIMATE_cos
// Approximation for cos(x) using Taylor series around 0
#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
#endif
#ifndef APPROXIMATE_ifloor
#define APPROXIMATE_ifloor(x) ((int)((x) >= 0 ? (x) : (x) - 1)) // truncate toward negative infinity
#define APPROXIMATE_iceil(x) ((int)((x) == (int)(x) ? (x) : ((x) > 0 ? (int)(x) + 1 : (int)(x)))) // truncate toward positive infinity
#endif
#ifndef APPROXIMATE_sqrt
// Fast approximation for sqrt using Newton's method
#define APPROXIMATE_sqrt(x) ((x) <= 0 ? 0 : (x) / 2.0 * (3.0 - ((x) * (x) * 0.5))) // Approximation for x close to 1
#define APPROXIMATE_pow(x, y) ((y) == 0 ? 1 : ((y) == 1 ? (x) : APPROXIMATE_sqrt(x))) // limited to approximate sqrt if y=0.5
#endif
#ifndef APPROXIMATE_fmod
#define APPROXIMATE_fmod(x, y) ((x) - ((int)((x) / (y)) * (y))) // equivalent to x - floor(x/y) * y
#endif
#ifndef APPROXIMATE_cos
// Approximation for cos(x) using Taylor series around 0
#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
#endif
#ifndef APPROXIMATE_acos
#define APPROXIMATE_acos(x) (1.5708 - (x) - (x)*(x)*(x) / 6) // limited approximation for acos in range [-1, 1]
#endif
#ifndef APPROXIMATE_fabs
#define APPROXIMATE_fabs(x) ((x) < 0 ? -(x) : (x))
#endif
//#ifndef APPROXIMATE_cos
//// Approximation for cos(x) using Taylor series around 0
//#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
//#endif
//
//
//#ifndef APPROXIMATE_ifloor
//#define APPROXIMATE_ifloor(x) ((int)((x) >= 0 ? (x) : (x) - 1)) // truncate toward negative infinity
//#define APPROXIMATE_iceil(x) ((int)((x) == (int)(x) ? (x) : ((x) > 0 ? (int)(x) + 1 : (int)(x)))) // truncate toward positive infinity
//#endif
//
//#ifndef APPROXIMATE_sqrt
//// Fast approximation for sqrt using Newton's method
//#define APPROXIMATE_sqrt(x) ((x) <= 0 ? 0 : (x) / 2.0 * (3.0 - ((x) * (x) * 0.5))) // Approximation for x close to 1
//#define APPROXIMATE_pow(x, y) ((y) == 0 ? 1 : ((y) == 1 ? (x) : APPROXIMATE_sqrt(x))) // limited to approximate sqrt if y=0.5
//#endif
//
//#ifndef APPROXIMATE_fmod
//#define APPROXIMATE_fmod(x, y) ((x) - ((int)((x) / (y)) * (y))) // equivalent to x - floor(x/y) * y
//#endif
//
//#ifndef APPROXIMATE_cos
//// Approximation for cos(x) using Taylor series around 0
//#define APPROXIMATE_cos(x) (1 - (x) * (x) / 2 + (x) * (x) * (x) * (x) / 24) // valid for small x
//#endif
//
//#ifndef APPROXIMATE_acos
//#define APPROXIMATE_acos(x) (1.5708 - (x) - (x)*(x)*(x) / 6) // limited approximation for acos in range [-1, 1]
//#endif
//
//#ifndef APPROXIMATE_fabs
//#define APPROXIMATE_fabs(x) ((x) < 0 ? -(x) : (x))
//#endif
struct OverlayCombo {
std::string path; // full overlay path
@@ -99,6 +99,35 @@ struct SwapDepth {
};
namespace ult {
// math funcs
inline double cos(double x) {
static constexpr double PI = 3.14159265358979323846;
static constexpr double TWO_PI = 6.28318530717958647692;
static constexpr double HALF_PI = 1.57079632679489661923;
// Fast normalization using multiply instead of divide when possible
x = x - TWO_PI * static_cast<int>(x * 0.159154943091895); // 1/(2π)
if (x < 0) x += TWO_PI;
// Use symmetry to reduce range
int sign = 1;
if (x > PI) {
x -= PI;
sign = -1;
}
if (x > HALF_PI) {
x = PI - x;
sign = -sign;
}
// Horner's method for faster polynomial evaluation (fewer operations)
// 5-term minimax polynomial for [0, π/2] - accurate to ~10^-8
const double x2 = x * x;
return sign * (1.0 + x2 * (-0.5 + x2 * (0.04166666666666666 + x2 * (-0.001388888888888889 + x2 * (0.0000248015873015873 - x2 * 0.0000002755731922398589)))));
}
extern bool correctFrameSize; // for detecting the correct Overlay display size
extern u16 DefaultFramebufferWidth; ///< Width of the framebuffer
@@ -182,6 +211,9 @@ namespace ult {
extern std::atomic<float> selectWidth;
extern std::atomic<float> nextPageWidth;
extern std::atomic<bool> inMainMenu;
extern std::atomic<bool> inHiddenMode;
extern std::atomic<bool> inSettingsMenu;
extern std::atomic<bool> inSubSettingsMenu;
extern std::atomic<bool> inOverlaysPage;
extern std::atomic<bool> inPackagesPage;
@@ -200,7 +232,7 @@ namespace ult {
//bool progressAnimation = false;
extern bool disableTransparency;
//bool useCustomWallpaper = false;
extern bool useMemoryExpansion;
//extern bool useMemoryExpansion;
extern bool useOpaqueScreenshots;
extern std::atomic<bool> onTrackBar;
@@ -344,6 +376,7 @@ namespace ult {
extern std::string HIDE_OVERLAY;
extern std::string HIDE_PACKAGE;
extern std::string LAUNCH_ARGUMENTS;
extern std::string FORCE_AMS110_SUPPORT;
extern std::string QUICK_LAUNCH;
extern std::string BOOT_COMMANDS;
extern std::string EXIT_COMMANDS;
@@ -371,6 +404,8 @@ namespace ult {
extern std::string USER_GUIDE;
extern std::string SHOW_HIDDEN;
extern std::string SHOW_DELETE;
extern std::string SHOW_UNSUPPORTED;
extern std::string PAGE_SWAP;
extern std::string RIGHT_SIDE_MODE;
extern std::string OVERLAY_VERSIONS;
@@ -379,7 +414,7 @@ namespace ult {
//extern std::string VERSION_LABELS;
extern std::string KEY_COMBO;
extern std::string MODE;
extern std::string MODES;
extern std::string LAUNCH_MODES;
extern std::string LANGUAGE;
extern std::string OVERLAY_INFO;
extern std::string SOFTWARE_UPDATE;
@@ -394,11 +429,19 @@ namespace ult {
extern std::string VENDOR;
extern std::string MODEL;
extern std::string STORAGE;
extern std::string NOTICE;
extern std::string UTILIZES;
//extern std::string NOTICE;
//extern std::string UTILIZES;
extern std::string MEMORY_EXPANSION;
extern std::string REBOOT_REQUIRED;
extern std::string OVERLAY_MEMORY;
extern std::string NOT_ENOUGH_MEMORY;
extern std::string WALLPAPER_SUPPORT_DISABLED;
extern std::string SOUND_SUPPORT_DISABLED;
extern std::string WALLPAPER_SUPPORT_ENABLED;
extern std::string SOUND_SUPPORT_ENABLED;
extern std::string EXIT_OVERLAY_SYSTEM;
//extern std::string MEMORY_EXPANSION;
//extern std::string REBOOT_REQUIRED;
extern std::string LOCAL_IP;
extern std::string WALLPAPER;
extern std::string THEME;
@@ -443,9 +486,16 @@ namespace ult {
extern std::string ULTRAHAND_HAS_STARTED;
extern std::string NEW_UPDATE_IS_AVAILABLE;
extern std::string REBOOT_IS_REQUIRED;
extern std::string HOLD_A_TO_DELETE;
//extern std::string REBOOT_IS_REQUIRED;
//extern std::string HOLD_A_TO_DELETE;
extern std::string DELETE_PACKAGE;
extern std::string DELETE_OVERLAY;
extern std::string SELECTION_IS_EMPTY;
extern std::string FORCED_SUPPORT_WARNING;
extern std::string TASK_IS_COMPLETE;
extern std::string TASK_HAS_FAILED;
//extern std::string PACKAGE_VERSIONS;
//extern std::string PROGRESS_ANIMATION;
@@ -456,6 +506,8 @@ namespace ult {
extern std::string BOOT_ENTRY;
#endif
extern std::string INCOMPATIBLE_WARNING;
extern std::string SYSTEM_RAM;
extern std::string FREE;
extern std::string DEFAULT_CHAR_WIDTH;
@@ -567,7 +619,7 @@ namespace ult {
float calculateAmplitude(float x, float peakDurationFactor = 0.25f);
//float calculateAmplitude(float x, float peakDurationFactor = 0.25f);
extern std::atomic<bool> refreshWallpaperNow;
@@ -685,9 +737,44 @@ namespace ult {
extern bool cleanVersionLabels, hideOverlayVersions, hidePackageVersions, useLibultrahandTitles, useLibultrahandVersions, usePackageTitles, usePackageVersions;
// nx-ovlloader settings
enum class OverlayHeapSize : u64 {
Size_4MB = 0x400000,
Size_6MB = 0x600000,
Size_8MB = 0x800000
};
// Static cache
static struct {
bool initialized = false;
OverlayHeapSize cachedSize = OverlayHeapSize::Size_6MB;
u64 customSizeMB = 0; // NEW: store custom size in MB
} heapSizeCache;
// Helper function to convert MB to bytes
extern u64 mbToBytes(u32 mb);
// Helper function to convert bytes to MB
extern u32 bytesToMB(u64 bytes);
// Implementation
OverlayHeapSize getCurrentHeapSize();
extern OverlayHeapSize currentHeapSize;
bool setOverlayHeapSize(OverlayHeapSize heapSize);
// Implementation
bool requestOverlayExit();
extern const std::string loaderInfo;
extern const std::string loaderTitle;
extern const bool expandedMemory;
extern std::string loaderTitle;
extern bool expandedMemory;
extern bool furtherExpandedMemory;
extern bool limitedMemory;
extern std::string versionLabel;

View File

@@ -19,7 +19,7 @@
* altered or removed.
*
* Licensed under both GPLv2 and CC-BY-4.0
* Copyright (c) 2024 ppkantorski
* Copyright (c) 2024-2025 ppkantorski
********************************************************************************/
#pragma once
@@ -43,7 +43,7 @@
#include "download_funcs.hpp"
#include "mod_funcs.hpp"
#include "tsl_utils.hpp"
#include "audio_player.hpp"
#include "audio.hpp"
#include "haptics.hpp"
#endif // ULTRA_HPP