hoc-sys: revert to an ancient version that works on mariko units
This commit is contained in:
@@ -20,7 +20,7 @@ make -j$CORES
|
||||
popd > /dev/null
|
||||
|
||||
mkdir -p "$DIST_DIR/atmosphere/contents/$TITLE_ID/flags"
|
||||
cp -vf "$ROOT_DIR/sysmodule/out/horizon-oc.nsp" "$DIST_DIR/atmosphere/contents/$TITLE_ID/exefs.nsp"
|
||||
cp -vf "$ROOT_DIR/sysmodule/out/sys-clk.nsp" "$DIST_DIR/atmosphere/contents/$TITLE_ID/exefs.nsp"
|
||||
>"$DIST_DIR/atmosphere/contents/$TITLE_ID/flags/boot2.flag"
|
||||
cp -vf "$ROOT_DIR/sysmodule/toolbox.json" "$DIST_DIR/atmosphere/contents/$TITLE_ID/toolbox.json"
|
||||
echo "*** manager ***"
|
||||
|
||||
@@ -74,11 +74,10 @@ typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkPartLoad_EMC = 0,
|
||||
SysClkPartLoad_EMCCpu,
|
||||
HocClkPartLoad_GPU,
|
||||
SysClkPartLoad_EnumMax
|
||||
} SysClkPartLoad;
|
||||
SysClkRamLoad_All = 0,
|
||||
SysClkRamLoad_Cpu,
|
||||
SysClkRamLoad_EnumMax
|
||||
} SysClkRamLoad;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
@@ -49,7 +49,6 @@ Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues);
|
||||
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues);
|
||||
Result sysclkIpcGetFreqList(SysClkModule module, u32* list, u32 maxCount, u32* outCount);
|
||||
Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode);
|
||||
Result hocClkIpcUpdateEmcRegs();
|
||||
|
||||
static inline Result sysclkIpcRemoveOverride(SysClkModule module)
|
||||
{
|
||||
|
||||
@@ -40,8 +40,8 @@ typedef struct
|
||||
uint32_t overrideFreqs[SysClkModule_EnumMax];
|
||||
uint32_t temps[SysClkThermalSensor_EnumMax];
|
||||
int32_t power[SysClkPowerSensor_EnumMax];
|
||||
uint32_t partLoad[SysClkPartLoad_EnumMax];
|
||||
// uint32_t perfConfId;
|
||||
uint32_t ramLoad[SysClkRamLoad_EnumMax];
|
||||
uint32_t perfConfId;
|
||||
} SysClkContext;
|
||||
|
||||
typedef struct
|
||||
@@ -52,4 +52,6 @@ typedef struct
|
||||
};
|
||||
} SysClkTitleProfileList;
|
||||
|
||||
#define SYSCLK_FREQ_LIST_MAX 32
|
||||
#define SYSCLK_FREQ_LIST_MAX 32
|
||||
#define SYSCLK_GPU_BOOST_HZ 76800000
|
||||
#define SYSCLK_CPU_BOOST_HZ 1785000000
|
||||
@@ -47,9 +47,6 @@ typedef enum {
|
||||
HocClkConfigValue_MarikoMaxGpuClock,
|
||||
HocClkConfigValue_MarikoMaxMemClock,
|
||||
|
||||
HocClkConfigValue_MarikoCpuBoostClock,
|
||||
HocClkConfigValue_EristaCpuBoostClock,
|
||||
|
||||
HocClkConfigValue_ThermalThrottle,
|
||||
HocClkConfigValue_ThermalThrottleThreshold,
|
||||
|
||||
@@ -59,13 +56,10 @@ typedef enum {
|
||||
HocClkConfigValue_HandheldTDP,
|
||||
HocClkConfigValue_HandheldTDPLimit,
|
||||
HocClkConfigValue_LiteTDPLimit,
|
||||
HocClkConfigValue_TDPCycleLimit,
|
||||
|
||||
HocClkConfigValue_EnforceBoardLimit,
|
||||
|
||||
HocClkConfigValue_EMCDVFS,
|
||||
HocClkConfigValue_EMCVdd2VoltageUV,
|
||||
HocClkConfigValue_EMCVdd2VoltageUVStockErista,
|
||||
HocClkConfigValue_EMCVdd2VoltageUVStockMariko,
|
||||
SysClkConfigValue_EnumMax,
|
||||
} SysClkConfigValue;
|
||||
|
||||
@@ -106,12 +100,6 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
|
||||
case HocClkConfigValue_MarikoMaxMemClock:
|
||||
return pretty ? "Max MEM Clock" : "mem_max_m";
|
||||
|
||||
case HocClkConfigValue_MarikoCpuBoostClock:
|
||||
return pretty ? "CPU Boost Clock" : "cpu_boost_m";
|
||||
|
||||
case HocClkConfigValue_EristaCpuBoostClock:
|
||||
return pretty ? "CPU Boost Clock" : "cpu_boost_e";
|
||||
|
||||
case HocClkConfigValue_ThermalThrottle:
|
||||
return pretty ? "Thermal Throttle" : "thermal_throttle";
|
||||
|
||||
@@ -132,16 +120,9 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
return pretty ? "Lite TDP Limit" : "tdp_limit_l";
|
||||
|
||||
case HocClkConfigValue_EnforceBoardLimit:
|
||||
return pretty ? "Enforce Board Limit" : "enforce_board_limit";
|
||||
case HocClkConfigValue_EMCDVFS:
|
||||
return pretty ? "EMC DVFS" : "emc_dvfs";
|
||||
case HocClkConfigValue_EMCVdd2VoltageUV:
|
||||
return pretty ? "Overclocked EMC Vdd2 Voltage" : "emc_vdd2_voltage_uv";
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockErista:
|
||||
return pretty ? "Stock EMC Vdd2 Voltage" : "emc_vdd2_voltage_uv_s_e";
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockMariko:
|
||||
return pretty ? "Stock EMC Vdd2 Voltage" : "emc_vdd2_voltage_uv_s_m";
|
||||
case HocClkConfigValue_TDPCycleLimit:
|
||||
return pretty ? "TDP Cycle Limit" : "tdp_limit_c";
|
||||
|
||||
default:
|
||||
return pretty ? "Null" : "null";
|
||||
}
|
||||
@@ -161,7 +142,6 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
return 0ULL;
|
||||
case HocClkConfigValue_EristaMaxCpuClock:
|
||||
case HocClkConfigValue_EristaCpuBoostClock:
|
||||
return 1785ULL;
|
||||
case HocClkConfigValue_EristaMaxGpuClock:
|
||||
return 921ULL;
|
||||
@@ -169,10 +149,9 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
return 1600ULL;
|
||||
|
||||
case HocClkConfigValue_MarikoMaxCpuClock:
|
||||
case HocClkConfigValue_MarikoCpuBoostClock:
|
||||
return 1963ULL;
|
||||
case HocClkConfigValue_MarikoMaxGpuClock:
|
||||
return 1152ULL;
|
||||
return 1075ULL;
|
||||
case HocClkConfigValue_MarikoMaxMemClock:
|
||||
return 1862ULL;
|
||||
|
||||
@@ -180,8 +159,6 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
case HocClkConfigValue_DockedGovernor:
|
||||
case HocClkConfigValue_HandheldGovernor:
|
||||
case HocClkConfigValue_HandheldTDP:
|
||||
case HocClkConfigValue_EnforceBoardLimit:
|
||||
case HocClkConfigValue_EMCDVFS:
|
||||
return 1ULL;
|
||||
case HocClkConfigValue_ThermalThrottleThreshold:
|
||||
return 70ULL;
|
||||
@@ -189,12 +166,8 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
return 8600ULL;
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
return 6400ULL;
|
||||
case HocClkConfigValue_EMCVdd2VoltageUV:
|
||||
return 1175000ULL;
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockErista:
|
||||
return 1125000ULL;
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockMariko:
|
||||
return 1100000ULL;
|
||||
case HocClkConfigValue_TDPCycleLimit:
|
||||
return 10ULL;
|
||||
default:
|
||||
return 0ULL;
|
||||
}
|
||||
@@ -210,8 +183,6 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
|
||||
case HocClkConfigValue_MarikoMaxCpuClock:
|
||||
case HocClkConfigValue_MarikoMaxGpuClock:
|
||||
case HocClkConfigValue_MarikoMaxMemClock:
|
||||
case HocClkConfigValue_EristaCpuBoostClock:
|
||||
case HocClkConfigValue_MarikoCpuBoostClock:
|
||||
case HocClkConfigValue_ThermalThrottleThreshold:
|
||||
case HocClkConfigValue_HandheldTDPLimit:
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
@@ -221,9 +192,7 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
|
||||
case SysClkConfigValue_FreqLogIntervalMs:
|
||||
case SysClkConfigValue_PowerLogIntervalMs:
|
||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||
case HocClkConfigValue_EMCVdd2VoltageUV:
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockErista:
|
||||
case HocClkConfigValue_EMCVdd2VoltageUVStockMariko:
|
||||
case HocClkConfigValue_TDPCycleLimit:
|
||||
return input >= 0;
|
||||
case HocClkConfigValue_UncappedClocks:
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
@@ -231,8 +200,6 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
|
||||
case HocClkConfigValue_DockedGovernor:
|
||||
case HocClkConfigValue_HandheldGovernor:
|
||||
case HocClkConfigValue_HandheldTDP:
|
||||
case HocClkConfigValue_EnforceBoardLimit:
|
||||
case HocClkConfigValue_EMCDVFS:
|
||||
return (input & 0x1) == input;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "clock_manager.h"
|
||||
|
||||
#define SYSCLK_IPC_API_VERSION 4
|
||||
#define SYSCLK_IPC_SERVICE_NAME "hoc:sys"
|
||||
#define SYSCLK_IPC_SERVICE_NAME "sys:clk"
|
||||
|
||||
enum SysClkIpcCmd
|
||||
{
|
||||
@@ -49,7 +49,6 @@ enum SysClkIpcCmd
|
||||
SysClkIpcCmd_SetConfigValues = 10,
|
||||
SysClkIpcCmd_GetFreqList = 11,
|
||||
SysClkIpcCmd_SetReverseNXRTMode = 12,
|
||||
HocClkIpcCmd_UpdateEMCRegs = 13,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -148,9 +148,3 @@ Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode)
|
||||
{
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
|
||||
}
|
||||
|
||||
Result hocClkIpcUpdateEmcRegs()
|
||||
{
|
||||
int nil = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, nil);
|
||||
}
|
||||
|
||||
@@ -27,17 +27,9 @@ CheatSheetTab::CheatSheetTab()
|
||||
// CPU
|
||||
this->addView(new brls::Header("CPU Clocks"));
|
||||
brls::Table *cpuTable = new brls::Table();
|
||||
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Mariko Absolute Max", "2601 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Mariko Unsafe Max", "2397 MHz");
|
||||
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Erista Absolute Max", "2295 MHz");
|
||||
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Erista Unsafe Max", "2091 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Mariko Safe Max", "1963 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Erista Safe Max", "1785 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Maximum", "1785 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Official Docked and Handheld", "1020 MHz");
|
||||
cpuTable->addRow(brls::TableRowType::BODY, "Sleep mode", "612 MHz");
|
||||
|
||||
this->addView(cpuTable);
|
||||
|
||||
@@ -45,22 +37,11 @@ CheatSheetTab::CheatSheetTab()
|
||||
this->addView(new brls::Header("GPU Clocks"));
|
||||
brls::Table *gpuTable = new brls::Table();
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Mariko Absolute Max", "1536 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Mariko Unsafe Max", "1267 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Mariko Safe Max", "1152 MHz");
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Erista Absolute Max", "1075 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Erista Safe Max", "860 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Maximum", "921 MHz");
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Official Docked", "768 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Maximum Mariko Handheld", "614 MHz");
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Maximum Erista Handheld", "460 MHz");
|
||||
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Official Handheld", "307-460 MHz");
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Boost Mode", "76 MHz");
|
||||
gpuTable->addRow(brls::TableRowType::BODY, "Official Handheld", "384 MHz");
|
||||
|
||||
this->addView(gpuTable);
|
||||
|
||||
@@ -68,48 +49,10 @@ CheatSheetTab::CheatSheetTab()
|
||||
this->addView(new brls::Header("MEM Clocks"));
|
||||
brls::Table *memTable = new brls::Table();
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 2133BL Max", "3500 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 1866BL Max", "3200 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 1600BL Max", "2900 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 1331BL Max", "2500 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Erista 2133BL Max", "2360 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Erista 1600BL Max", "2227 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 4266MT/s Safe Max", "2133 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Mariko 3766MT/s Safe Max", "1866 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Erista Unsafe Max", "1862 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Erista Safe Max", "1600 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Maximum, Official Docked", "1600 MHz");
|
||||
memTable->addRow(brls::TableRowType::BODY, "Official Handheld", "1331 MHz");
|
||||
|
||||
memTable->addRow(brls::TableRowType::BODY, "Sleep Mode", "204 MHz");
|
||||
|
||||
this->addView(memTable);
|
||||
|
||||
this->addView(new brls::Header("Display Freqs"));
|
||||
brls::Table *lcdTable = new brls::Table();
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "External Display (720P) Max", "240 HZ");
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "External Display (1080P) Max", "120 HZ");
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "OLED Max", "90 HZ");
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "LCD Max", "72 HZ");
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "Default", "60 HZ");
|
||||
|
||||
lcdTable->addRow(brls::TableRowType::BODY, "Minimum", "40 HZ");
|
||||
|
||||
this->addView(lcdTable);
|
||||
}
|
||||
|
||||
void CheatSheetTab::customSpacing(brls::View* current, brls::View* next, int* spacing)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "logo.h"
|
||||
|
||||
Logo::Logo(LogoStyle style) {
|
||||
this->logoLabel = new brls::Label(brls::LabelStyle::LIST_ITEM, "Horizon OC", style == LogoStyle::ABOUT);
|
||||
this->logoLabel = new brls::Label(brls::LabelStyle::LIST_ITEM, "sys-clk", style == LogoStyle::ABOUT);
|
||||
this->logoLabel->setParent(this);
|
||||
|
||||
int logoFont = brls::Application::findFont(LOGO_FONT_NAME);
|
||||
|
||||
@@ -37,7 +37,7 @@ include ${TOPDIR}/lib/libultrahand/ultrahand.mk
|
||||
# version control constants
|
||||
#---------------------------------------------------------------------------------
|
||||
#TARGET_VERSION := $(shell git describe --dirty --always --tags)
|
||||
APP_VERSION := 0.0.4
|
||||
APP_VERSION := 1.0.1
|
||||
TARGET_VERSION := $(APP_VERSION)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@@ -53,7 +53,7 @@ CFLAGS := -Os -Wall -flto -fdata-sections -ffunction-sections -fno-rtti -fno-com
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
# Enable appearance overriding
|
||||
UI_OVERRIDE_PATH := /config/horizon-oc/
|
||||
UI_OVERRIDE_PATH := /config/sys-clk/
|
||||
CFLAGS += -DUI_OVERRIDE_PATH="\"$(UI_OVERRIDE_PATH)\""
|
||||
|
||||
# Disable fstream
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
github: ppkantorski
|
||||
ko_fi: ppkantorski
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 381 KiB |
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,211 +0,0 @@
|
||||
# ☆ libultrahand
|
||||
[](https://gbatemp.net/forums/nintendo-switch.283/?prefix_id=44)
|
||||
[](https://github.com/topics/cpp)
|
||||
[](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
|
||||
[](https://github.com/ppkantorski/libultrahand/releases/latest)
|
||||
[](https://github.com/ppkantorski/libultrahand/graphs/traffic)
|
||||
[](https://github.com/ppkantorski/libultrahand/issues)
|
||||
[](https://github.com/ppkantorski/libultrahand/stargazers)
|
||||
|
||||
|
||||
Expanded [**libtesla**](https://github.com/WerWolv/libtesla) (originally by [WerWolv](https://github.com/WerWolv)) + **libultra** libraries for overlay development on the Nintendo Switch
|
||||
|
||||

|
||||
|
||||
## Compiling
|
||||
|
||||
### Necessary Libraries and Imports
|
||||
For easy importing and inclusion, try using `ultrahand.mk`. These lines must go after your projects `SOURCES` and `INCLUDES` definitions.
|
||||
```sh
|
||||
include $(TOPDIR)/lib/libultrahand/ultrahand.mk
|
||||
```
|
||||
This location should reflect where you place the `libultrahand` directory (`lib` can vary between projects).
|
||||
|
||||
##
|
||||
|
||||
Otherwise developers should include the following `SOURCES` and `INCLUDES` lines.
|
||||
```sh
|
||||
SOURCES += lib/libultrahand/common lib/libultrahand/libultra/source
|
||||
INCLUDES += lib/libultrahand/common lib/libultrahand/libultra/include lib/libultrahand/libtesla/include
|
||||
```
|
||||
##
|
||||
|
||||
Including the following libraries are also essential for compilation.
|
||||
```sh
|
||||
LIBS := -lcurl -lz -lminizip -lmbedtls -lmbedx509 -lmbedcrypto -lnx
|
||||
```
|
||||
|
||||
### Active Services
|
||||
Service conflictions can occur, so if you are already using the following libnx services, you may want to remove them from your project.
|
||||
```cpp
|
||||
i2cInitialize();
|
||||
fsdevMountSdmc();
|
||||
splInitialize();
|
||||
spsmInitialize();
|
||||
ASSERT_FATAL(socketInitializeDefault());
|
||||
ASSERT_FATAL(nifmInitialize(NifmServiceType_User));
|
||||
ASSERT_FATAL(smInitialize()); // needed to prevent issues with powering device into sleep
|
||||
```
|
||||
Service `i2cInitialize` however is only utilized in accordance with `USING_WIDGET_DIRECTIVE`.
|
||||
|
||||
### Optional Compilation Flags
|
||||
```
|
||||
-ffunction-sections -fdata-sections
|
||||
```
|
||||
These options are present in both CFLAGS and CXXFLAGS. They instruct the compiler to place each function and data item in its own section, which allows the linker to more easily identify and remove unused code.
|
||||
|
||||
```
|
||||
-Wl,--gc-sections
|
||||
```
|
||||
Included in LDFLAGS. This linker flag instructs the linker to remove unused sections that were created by -ffunction-sections and -fdata-sections. This ensures that functions or data that are not used are removed from the final executable.
|
||||
|
||||
```
|
||||
-flto (Link Time Optimization)
|
||||
```
|
||||
Present in CFLAGS, CXXFLAGS, and LDFLAGS. It enables link-time optimization, allowing the compiler to optimize across different translation units and remove any unused code during the linking phase. You also use -flto=6 to control the number of threads for parallel LTO, which helps speed up the process.
|
||||
|
||||
```
|
||||
-fuse-linker-plugin
|
||||
```
|
||||
This flag allows the compiler and linker to better collaborate when using LTO, which further helps in optimizing and eliminating unused code.
|
||||
Together, these flags (-ffunction-sections, -fdata-sections, -Wl,--gc-sections, and -flto) ensure that any unused functions or data are stripped out during the build process, leading to a smaller and more optimized final binary.
|
||||
|
||||
|
||||
## Build Examples
|
||||
- [Ultrahand Overlay](https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
|
||||
- [Tetris Overlay](https://github.com/ppkantorski/Tetris-Overlay)
|
||||
|
||||
- [Status Monitor Overlay](https://github.com/ppkantorski/Status-Monitor-Overlay)
|
||||
|
||||
- [Edizon Overlay](https://github.com/ppkantorski/EdiZon-Overlay)
|
||||
|
||||
- [Sysmodules](https://github.com/ppkantorski/ovl-sysmodules)
|
||||
|
||||
- [sys-clk](https://github.com/ppkantorski/sys-clk)
|
||||
|
||||
- [FPSLocker](https://github.com/ppkantorski/FPSLocker)
|
||||
|
||||
- [ReverseNX-RT](https://github.com/ppkantorski/ReverseNX-RT)
|
||||
|
||||
- [QuickNTP](https://github.com/ppkantorski/QuickNTP)
|
||||
|
||||
- [SysDVR Overlay](https://github.com/ppkantorski/sysdvr-overlay)
|
||||
|
||||
- [Fizeau](https://github.com/ppkantorski/Fizeau)
|
||||
|
||||
- [NX-FanControl](https://github.com/ppkantorski/NX-FanControl)
|
||||
|
||||
- [DNS-MITM_Manager](https://github.com/ppkantorski/DNS-MITM_Manager)
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
### Overriding Themes and Wallpapers
|
||||
|
||||
To customize theme, wallpaper and / or allow direct language translations for your overlay, you can override the default settings by adding the following lines to your `Makefile`:
|
||||
|
||||
```
|
||||
# Enable appearance overriding
|
||||
UI_OVERRIDE_PATH := /config/<OVERLAY_NAME>/
|
||||
CFLAGS += -DUI_OVERRIDE_PATH="\"$(UI_OVERRIDE_PATH)\""
|
||||
```
|
||||
|
||||
Replace `<OVERLAY_NAME>` with the desired name of your overlay config directory.
|
||||
|
||||
Users can specify custom Ultrahand `theme.ini` and `wallpaper.rgba` files for the overlay to use located in your SD card's `/config/<OVERLAY_NAME>/` or `{UI_OVERRIDE_PATH}` directory.
|
||||
|
||||
#### **Troubleshooting**
|
||||
**Notice:** Makefile directives also must be added to `CXXFLAGS`.
|
||||
You can do this by adding the directives before `CXXFLAGS := $(CFLAGS)` gets defined, or include `CXXFLAGS += ...`.
|
||||
|
||||
|
||||
There are rare occurences where the theme and wallpaper are still not being loaded. This may have to do with how the GUI class is used in some projects. For a work around, you can try adding the `INITIALIZE_IN_GUI_DIRECTIVE` directive.
|
||||
|
||||
```
|
||||
# For theme / wallpaper loading in GUI class method (add to project if theme does not appear)
|
||||
INITIALIZE_IN_GUI_DIRECTIVE := 1
|
||||
CFLAGS += -DINITIALIZE_IN_GUI_DIRECTIVE=$(INITIALIZE_IN_GUI_DIRECTIVE)
|
||||
```
|
||||
|
||||
This fix will work for many projects, but other projects may not like this directive or may not need it at all so use with that in mind.
|
||||
|
||||
---
|
||||
|
||||
### Overriding Languages
|
||||
For language translation, `UI_OVERRIDE_PATH` must be defined. Translations are performed direction on the rederer's `drawString` method. Direct strings can be added to a json located in `/config/<OVERLAY_NAME>/lang/` or `{UI_OVERRIDE_PATH}/lang/`.
|
||||
|
||||
Jsons will need to be named ISO 639-1 format (en, de, fr, es, etc...) and will only be used in accordance with the current language set in the Ultrahand Overlay `/config/ultrahand/config.ini`.
|
||||
|
||||
The format for language jsons is as follows.
|
||||
```json
|
||||
{
|
||||
"English String": "Translated String",
|
||||
"Another String": "Another Translation",
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Ultrahand Overlay Widget
|
||||
|
||||
To add the Ultrahand Overlay widget to your `OverlayFrame`'s, add the following directive to your `Makefile`:
|
||||
|
||||
```
|
||||
# Enable Widget
|
||||
USING_WIDGET_DIRECTIVE := 1
|
||||
CFLAGS += -DUSING_WIDGET_DIRECTIVE=$(USING_WIDGET_DIRECTIVE)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Forcing use of `<fstream>` instead of `<stdio.h>` (unnecessary)
|
||||
|
||||
To compile utilizing `fstream`, add the following directive to your `Makefile`:
|
||||
|
||||
```
|
||||
# Enable fstream
|
||||
USING_FSTREAM_DIRECTIVE := 1
|
||||
CFLAGS += -DUSING_FSTREAM_DIRECTIVE=$(USING_FSTREAM_DIRECTIVE)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Initializing Settings
|
||||
|
||||
Ultrahand Overlay theme variables and settings for your overlay are read automatically upon initialization. Themes loading implementation is currently set within `OverlayFrame` and `HeaderOverlayFrame`.
|
||||
|
||||
However if you are breaking your project up into individual parts that only import `tesla.hpp` and modify elements, you may need to declare `/libultrahand/libultra/include` at the start of your `INCLUDES` in your make file.
|
||||
|
||||
If that still is not working, then you may need to add this line somewhere for the theme to be applied to that element.
|
||||
|
||||
```cpp
|
||||
tsl::initializeThemeVars(); // Initialize variables for ultrahand themes
|
||||
```
|
||||
|
||||
### Download Methods
|
||||
|
||||
To utilize the `libultra` download methods in your project, you will need to add the following line to your `initServices` function:
|
||||
```cpp
|
||||
initializeCurl();
|
||||
```
|
||||
As well as the following line to your `exetServices` function:
|
||||
```cpp
|
||||
cleanupCurl();
|
||||
```
|
||||
|
||||
These lines will ensure `curl` functions properly within the overlay.
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please raise an [issue](https://github.com/ppkantorski/libultrahand/issues/new/choose), submit a [pull request](https://github.com/ppkantorski/libultrahand/compare) or reach out to me directly on [GBATemp](https://gbatemp.net/threads/ultrahand-overlay-the-fully-craft-able-overlay-executor.633560/).
|
||||
|
||||
[](https://ko-fi.com/X8X3VR194)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed and distributed under [GPLv2](LICENSE) with a [custom library](libultra) utilizing [CC-BY-4.0](SUB_LICENSE).
|
||||
|
||||
Copyright (c) 2024 ppkantorski
|
||||
@@ -1,395 +0,0 @@
|
||||
Attribution 4.0 International
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||
does not provide legal services or legal advice. Distribution of
|
||||
Creative Commons public licenses does not create a lawyer-client or
|
||||
other relationship. Creative Commons makes its licenses and related
|
||||
information available on an "as-is" basis. Creative Commons gives no
|
||||
warranties regarding its licenses, any material licensed under their
|
||||
terms and conditions, or any related information. Creative Commons
|
||||
disclaims all liability for damages resulting from their use to the
|
||||
fullest extent possible.
|
||||
|
||||
Using Creative Commons Public Licenses
|
||||
|
||||
Creative Commons public licenses provide a standard set of terms and
|
||||
conditions that creators and other rights holders may use to share
|
||||
original works of authorship and other material subject to copyright
|
||||
and certain other rights specified in the public license below. The
|
||||
following considerations are for informational purposes only, are not
|
||||
exhaustive, and do not form part of our licenses.
|
||||
|
||||
Considerations for licensors: Our public licenses are
|
||||
intended for use by those authorized to give the public
|
||||
permission to use material in ways otherwise restricted by
|
||||
copyright and certain other rights. Our licenses are
|
||||
irrevocable. Licensors should read and understand the terms
|
||||
and conditions of the license they choose before applying it.
|
||||
Licensors should also secure all rights necessary before
|
||||
applying our licenses so that the public can reuse the
|
||||
material as expected. Licensors should clearly mark any
|
||||
material not subject to the license. This includes other CC-
|
||||
licensed material, or material used under an exception or
|
||||
limitation to copyright. More considerations for licensors:
|
||||
wiki.creativecommons.org/Considerations_for_licensors
|
||||
|
||||
Considerations for the public: By using one of our public
|
||||
licenses, a licensor grants the public permission to use the
|
||||
licensed material under specified terms and conditions. If
|
||||
the licensor's permission is not necessary for any reason--for
|
||||
example, because of any applicable exception or limitation to
|
||||
copyright--then that use is not regulated by the license. Our
|
||||
licenses grant only permissions under copyright and certain
|
||||
other rights that a licensor has authority to grant. Use of
|
||||
the licensed material may still be restricted for other
|
||||
reasons, including because others have copyright or other
|
||||
rights in the material. A licensor may make special requests,
|
||||
such as asking that all changes be marked or described.
|
||||
Although not required by our licenses, you are encouraged to
|
||||
respect those requests where reasonable. More_considerations
|
||||
for the public:
|
||||
wiki.creativecommons.org/Considerations_for_licensees
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Attribution 4.0 International Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree
|
||||
to be bound by the terms and conditions of this Creative Commons
|
||||
Attribution 4.0 International Public License ("Public License"). To the
|
||||
extent this Public License may be interpreted as a contract, You are
|
||||
granted the Licensed Rights in consideration of Your acceptance of
|
||||
these terms and conditions, and the Licensor grants You such rights in
|
||||
consideration of benefits the Licensor receives from making the
|
||||
Licensed Material available under these terms and conditions.
|
||||
|
||||
|
||||
Section 1 -- Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar
|
||||
Rights that is derived from or based upon the Licensed Material
|
||||
and in which the Licensed Material is translated, altered,
|
||||
arranged, transformed, or otherwise modified in a manner requiring
|
||||
permission under the Copyright and Similar Rights held by the
|
||||
Licensor. For purposes of this Public License, where the Licensed
|
||||
Material is a musical work, performance, or sound recording,
|
||||
Adapted Material is always produced where the Licensed Material is
|
||||
synched in timed relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright
|
||||
and Similar Rights in Your contributions to Adapted Material in
|
||||
accordance with the terms and conditions of this Public License.
|
||||
|
||||
c. Copyright and Similar Rights means copyright and/or similar rights
|
||||
closely related to copyright including, without limitation,
|
||||
performance, broadcast, sound recording, and Sui Generis Database
|
||||
Rights, without regard to how the rights are labeled or
|
||||
categorized. For purposes of this Public License, the rights
|
||||
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||
Rights.
|
||||
|
||||
d. Effective Technological Measures means those measures that, in the
|
||||
absence of proper authority, may not be circumvented under laws
|
||||
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||
Treaty adopted on December 20, 1996, and/or similar international
|
||||
agreements.
|
||||
|
||||
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||
any other exception or limitation to Copyright and Similar Rights
|
||||
that applies to Your use of the Licensed Material.
|
||||
|
||||
f. Licensed Material means the artistic or literary work, database,
|
||||
or other material to which the Licensor applied this Public
|
||||
License.
|
||||
|
||||
g. Licensed Rights means the rights granted to You subject to the
|
||||
terms and conditions of this Public License, which are limited to
|
||||
all Copyright and Similar Rights that apply to Your use of the
|
||||
Licensed Material and that the Licensor has authority to license.
|
||||
|
||||
h. Licensor means the individual(s) or entity(ies) granting rights
|
||||
under this Public License.
|
||||
|
||||
i. Share means to provide material to the public by any means or
|
||||
process that requires permission under the Licensed Rights, such
|
||||
as reproduction, public display, public performance, distribution,
|
||||
dissemination, communication, or importation, and to make material
|
||||
available to the public including in ways that members of the
|
||||
public may access the material from a place and at a time
|
||||
individually chosen by them.
|
||||
|
||||
j. Sui Generis Database Rights means rights other than copyright
|
||||
resulting from Directive 96/9/EC of the European Parliament and of
|
||||
the Council of 11 March 1996 on the legal protection of databases,
|
||||
as amended and/or succeeded, as well as other essentially
|
||||
equivalent rights anywhere in the world.
|
||||
|
||||
k. You means the individual or entity exercising the Licensed Rights
|
||||
under this Public License. Your has a corresponding meaning.
|
||||
|
||||
|
||||
Section 2 -- Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License,
|
||||
the Licensor hereby grants You a worldwide, royalty-free,
|
||||
non-sublicensable, non-exclusive, irrevocable license to
|
||||
exercise the Licensed Rights in the Licensed Material to:
|
||||
|
||||
a. reproduce and Share the Licensed Material, in whole or
|
||||
in part; and
|
||||
|
||||
b. produce, reproduce, and Share Adapted Material.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||
Exceptions and Limitations apply to Your use, this Public
|
||||
License does not apply, and You do not need to comply with
|
||||
its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section
|
||||
6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The
|
||||
Licensor authorizes You to exercise the Licensed Rights in
|
||||
all media and formats whether now known or hereafter created,
|
||||
and to make technical modifications necessary to do so. The
|
||||
Licensor waives and/or agrees not to assert any right or
|
||||
authority to forbid You from making technical modifications
|
||||
necessary to exercise the Licensed Rights, including
|
||||
technical modifications necessary to circumvent Effective
|
||||
Technological Measures. For purposes of this Public License,
|
||||
simply making modifications authorized by this Section 2(a)
|
||||
(4) never produces Adapted Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
a. Offer from the Licensor -- Licensed Material. Every
|
||||
recipient of the Licensed Material automatically
|
||||
receives an offer from the Licensor to exercise the
|
||||
Licensed Rights under the terms and conditions of this
|
||||
Public License.
|
||||
|
||||
b. No downstream restrictions. You may not offer or impose
|
||||
any additional or different terms or conditions on, or
|
||||
apply any Effective Technological Measures to, the
|
||||
Licensed Material if doing so restricts exercise of the
|
||||
Licensed Rights by any recipient of the Licensed
|
||||
Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or
|
||||
may be construed as permission to assert or imply that You
|
||||
are, or that Your use of the Licensed Material is, connected
|
||||
with, or sponsored, endorsed, or granted official status by,
|
||||
the Licensor or others designated to receive attribution as
|
||||
provided in Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not
|
||||
licensed under this Public License, nor are publicity,
|
||||
privacy, and/or other similar personality rights; however, to
|
||||
the extent possible, the Licensor waives and/or agrees not to
|
||||
assert any such rights held by the Licensor to the limited
|
||||
extent necessary to allow You to exercise the Licensed
|
||||
Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this
|
||||
Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to
|
||||
collect royalties from You for the exercise of the Licensed
|
||||
Rights, whether directly or through a collecting society
|
||||
under any voluntary or waivable statutory or compulsory
|
||||
licensing scheme. In all other cases the Licensor expressly
|
||||
reserves any right to collect such royalties.
|
||||
|
||||
|
||||
Section 3 -- License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the
|
||||
following conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified
|
||||
form), You must:
|
||||
|
||||
a. retain the following if it is supplied by the Licensor
|
||||
with the Licensed Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed
|
||||
Material and any others designated to receive
|
||||
attribution, in any reasonable manner requested by
|
||||
the Licensor (including by pseudonym if
|
||||
designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of
|
||||
warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the
|
||||
extent reasonably practicable;
|
||||
|
||||
b. indicate if You modified the Licensed Material and
|
||||
retain an indication of any previous modifications; and
|
||||
|
||||
c. indicate the Licensed Material is licensed under this
|
||||
Public License, and include the text of, or the URI or
|
||||
hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||
reasonable manner based on the medium, means, and context in
|
||||
which You Share the Licensed Material. For example, it may be
|
||||
reasonable to satisfy the conditions by providing a URI or
|
||||
hyperlink to a resource that includes the required
|
||||
information.
|
||||
|
||||
3. If requested by the Licensor, You must remove any of the
|
||||
information required by Section 3(a)(1)(A) to the extent
|
||||
reasonably practicable.
|
||||
|
||||
4. If You Share Adapted Material You produce, the Adapter's
|
||||
License You apply must not prevent recipients of the Adapted
|
||||
Material from complying with this Public License.
|
||||
|
||||
|
||||
Section 4 -- Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that
|
||||
apply to Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||
to extract, reuse, reproduce, and Share all or a substantial
|
||||
portion of the contents of the database;
|
||||
|
||||
b. if You include all or a substantial portion of the database
|
||||
contents in a database in which You have Sui Generis Database
|
||||
Rights, then the database in which You have Sui Generis Database
|
||||
Rights (but not its individual contents) is Adapted Material; and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share
|
||||
all or a substantial portion of the contents of the database.
|
||||
|
||||
For the avoidance of doubt, this Section 4 supplements and does not
|
||||
replace Your obligations under this Public License where the Licensed
|
||||
Rights include other Copyright and Similar Rights.
|
||||
|
||||
|
||||
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||
|
||||
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided
|
||||
above shall be interpreted in a manner that, to the extent
|
||||
possible, most closely approximates an absolute disclaimer and
|
||||
waiver of all liability.
|
||||
|
||||
|
||||
Section 6 -- Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and
|
||||
Similar Rights licensed here. However, if You fail to comply with
|
||||
this Public License, then Your rights under this Public License
|
||||
terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under
|
||||
Section 6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided
|
||||
it is cured within 30 days of Your discovery of the
|
||||
violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||
right the Licensor may have to seek remedies for Your violations
|
||||
of this Public License.
|
||||
|
||||
c. For the avoidance of doubt, the Licensor may also offer the
|
||||
Licensed Material under separate terms or conditions or stop
|
||||
distributing the Licensed Material at any time; however, doing so
|
||||
will not terminate this Public License.
|
||||
|
||||
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||
License.
|
||||
|
||||
|
||||
Section 7 -- Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different
|
||||
terms or conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the
|
||||
Licensed Material not stated herein are separate from and
|
||||
independent of the terms and conditions of this Public License.
|
||||
|
||||
|
||||
Section 8 -- Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and
|
||||
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||
conditions on any use of the Licensed Material that could lawfully
|
||||
be made without permission under this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is
|
||||
deemed unenforceable, it shall be automatically reformed to the
|
||||
minimum extent necessary to make it enforceable. If the provision
|
||||
cannot be reformed, it shall be severed from this Public License
|
||||
without affecting the enforceability of the remaining terms and
|
||||
conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no
|
||||
failure to comply consented to unless expressly agreed to by the
|
||||
Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted
|
||||
as a limitation upon, or waiver of, any privileges and immunities
|
||||
that apply to the Licensor or You, including from the legal
|
||||
processes of any jurisdiction or authority.
|
||||
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons is not a party to its public
|
||||
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||
its public licenses to material it publishes and in those instances
|
||||
will be considered the “Licensor.” The text of the Creative Commons
|
||||
public licenses is dedicated to the public domain under the CC0 Public
|
||||
Domain Dedication. Except for the limited purpose of indicating that
|
||||
material is shared under a Creative Commons public license or as
|
||||
otherwise permitted by the Creative Commons policies published at
|
||||
creativecommons.org/policies, Creative Commons does not authorize the
|
||||
use of the trademark "Creative Commons" or any other trademark or logo
|
||||
of Creative Commons without its prior written consent including,
|
||||
without limitation, in connection with any unauthorized modifications
|
||||
to any of its public licenses or any other arrangements,
|
||||
understandings, or agreements concerning use of licensed material. For
|
||||
the avoidance of doubt, this paragraph does not form part of the
|
||||
public licenses.
|
||||
|
||||
Creative Commons may be contacted at creativecommons.org.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,306 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 18
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* Limits the length of circular references can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_CIRCULAR_LIMIT
|
||||
#define CJSON_CIRCULAR_LIMIT 10000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
|
||||
#define cJSON_SetBoolValue(object, boolValue) ( \
|
||||
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
||||
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
||||
cJSON_Invalid\
|
||||
)
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,32 +0,0 @@
|
||||
# libtesla
|
||||
|
||||
<p align="center">
|
||||
<img src="https://i.imgur.com/fhwyjbd.png">
|
||||
</p>
|
||||
|
||||
libtesla is the interface between the Tesla overlay loader and user-made Overlays. It handles all layer creation, UI creation, drawing and input management.
|
||||
It's main goal is to make sure all overlays look and feel similar and don't differenciate themselves from the switch's native overlays.
|
||||
|
||||
## Screenshots
|
||||
|
||||
<div>
|
||||
<img src="https://i.imgur.com/jJpxYjb.jpg" style="width: 50%; float: center">
|
||||
<img src="https://i.imgur.com/nBUc7ps.jpg" style="width: 50%; float: right">
|
||||
</div>
|
||||
|
||||
`Overlays do NOT show up on Screenshots. These pictures were taken using a capture card`
|
||||
|
||||
## Example
|
||||
|
||||
An example for how to use libtesla can be found here: https://github.com/WerWolv/libtesla/tree/master/example
|
||||
To create your own Overlay, please consider creating a new repository using the official Tesla overlay template: https://github.com/WerWolv/Tesla-Template
|
||||
|
||||
**Please Note:** While it is possible to create overlays without libtesla, it's highly recommended to not do so. libtesla handles showing and hiding of overlays, button combo detection, layer creation and a lot more. Not using it will lead to an inconsistent user experience when using multiple different overlays ultimately making it worse for the end user. If something's missing, please consider opening a PR here.
|
||||
|
||||
## Credits
|
||||
|
||||
- **switchbrew** for nx-hbloader which is used as basis for overlay loading
|
||||
- **kardch** for the amazing icon
|
||||
- **All the devs on AtlasNX, RetroNX and Switchbrew** for their feedback
|
||||
- **All overlay devs** for making something awesome out of this :)
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
|
||||
#
|
||||
# NO_ICON: if set to anything, do not use icon.
|
||||
# NO_NACP: if set to anything, no .nacp file is generated.
|
||||
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
|
||||
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
|
||||
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
|
||||
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
|
||||
# ICON is the filename of the icon (.jpg), relative to the project folder.
|
||||
# If not set, it attempts to use one of the following (in this order):
|
||||
# - <Project name>.jpg
|
||||
# - icon.jpg
|
||||
# - <libnx folder>/default_icon.jpg
|
||||
#
|
||||
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
|
||||
# If not set, it attempts to use one of the following (in this order):
|
||||
# - <Project name>.json
|
||||
# - config.json
|
||||
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
|
||||
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
|
||||
# NACP building is skipped as well.
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
APP_TITLE := Tesla Example
|
||||
APP_VERSION := 1.3.0
|
||||
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := ../include
|
||||
|
||||
NO_ICON := 1
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++20
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lnx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
ifeq ($(strip $(CONFIG_JSON)),)
|
||||
jsons := $(wildcard *.json)
|
||||
ifneq (,$(findstring $(TARGET).json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/$(TARGET).json
|
||||
else
|
||||
ifneq (,$(findstring config.json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/config.json
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(ICON)),)
|
||||
icons := $(wildcard *.jpg)
|
||||
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
|
||||
else
|
||||
ifneq (,$(findstring icon.jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/icon.jpg
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_ICON := $(TOPDIR)/$(ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_ICON)),)
|
||||
export NROFLAGS += --icon=$(APP_ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
|
||||
endif
|
||||
|
||||
ifneq ($(APP_TITLEID),)
|
||||
export NACPFLAGS += --titleid=$(APP_TITLEID)
|
||||
endif
|
||||
|
||||
ifneq ($(ROMFS),)
|
||||
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
|
||||
endif
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@rm -fr $(BUILD) $(TARGET).ovl $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).ovl
|
||||
|
||||
$(OUTPUT).ovl : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
@elf2nro $< $@ $(NROFLAGS)
|
||||
@echo "built ... $(notdir $(OUTPUT).ovl)"
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
@@ -1,100 +0,0 @@
|
||||
#define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one
|
||||
#include <tesla.hpp> // The Tesla Header
|
||||
|
||||
|
||||
class GuiSecondary : public tsl::Gui {
|
||||
public:
|
||||
GuiSecondary() {}
|
||||
|
||||
virtual tsl::elm::Element* createUI() override {
|
||||
auto *rootFrame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2 - Secondary Gui");
|
||||
|
||||
rootFrame->setContent(new tsl::elm::DebugRectangle(tsl::Color{ 0x8, 0x3, 0x8, 0xF }));
|
||||
|
||||
return rootFrame;
|
||||
}
|
||||
};
|
||||
|
||||
class GuiTest : public tsl::Gui {
|
||||
public:
|
||||
GuiTest(u8 arg1, u8 arg2, bool arg3) { }
|
||||
|
||||
// Called when this Gui gets loaded to create the UI
|
||||
// Allocate all elements on the heap. libtesla will make sure to clean them up when not needed anymore
|
||||
virtual tsl::elm::Element* createUI() override {
|
||||
// A OverlayFrame is the base element every overlay consists of. This will draw the default Title and Subtitle.
|
||||
// If you need more information in the header or want to change it's look, use a HeaderOverlayFrame.
|
||||
auto frame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2");
|
||||
|
||||
// A list that can contain sub elements and handles scrolling
|
||||
auto list = new tsl::elm::List();
|
||||
|
||||
// List Items
|
||||
list->addItem(new tsl::elm::CategoryHeader("List items"));
|
||||
|
||||
auto *clickableListItem = new tsl::elm::ListItem("Clickable List Item", "...");
|
||||
clickableListItem->setClickListener([](u64 keys) {
|
||||
if (keys & HidNpadButton_A) {
|
||||
tsl::changeTo<GuiSecondary>();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
list->addItem(clickableListItem);
|
||||
list->addItem(new tsl::elm::ListItem("Default List Item"));
|
||||
list->addItem(new tsl::elm::ListItem("Default List Item with an extra long name to trigger truncation and scrolling"));
|
||||
list->addItem(new tsl::elm::ToggleListItem("Toggle List Item", true));
|
||||
|
||||
// Custom Drawer, a element that gives direct access to the renderer
|
||||
list->addItem(new tsl::elm::CategoryHeader("Custom Drawer", true));
|
||||
list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
|
||||
renderer->drawCircle(x + 40, y + 40, 20, true, renderer->a(0xF00F));
|
||||
renderer->drawCircle(x + 50, y + 50, 20, true, renderer->a(0xF0F0));
|
||||
renderer->drawRect(x + 130, y + 30, 60, 40, renderer->a(0xFF00));
|
||||
renderer->drawString("Hello :)", false, x + 250, y + 70, 20, renderer->a(0xFF0F));
|
||||
renderer->drawRect(x + 40, y + 90, 300, 10, renderer->a(0xF0FF));
|
||||
}), 100);
|
||||
|
||||
// Track bars
|
||||
list->addItem(new tsl::elm::CategoryHeader("Track bars"));
|
||||
list->addItem(new tsl::elm::TrackBar("\u2600"));
|
||||
list->addItem(new tsl::elm::StepTrackBar("\uE13C", 20));
|
||||
list->addItem(new tsl::elm::NamedStepTrackBar("\uE132", { "Selection 1", "Selection 2", "Selection 3" }));
|
||||
|
||||
// Add the list to the frame for it to be drawn
|
||||
frame->setContent(list);
|
||||
|
||||
// Return the frame to have it become the top level element of this Gui
|
||||
return frame;
|
||||
}
|
||||
|
||||
// Called once every frame to update values
|
||||
virtual void update() override {
|
||||
|
||||
}
|
||||
|
||||
// Called once every frame to handle inputs not handled by other UI elements
|
||||
virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override {
|
||||
return false; // Return true here to signal the inputs have been consumed
|
||||
}
|
||||
};
|
||||
|
||||
class OverlayTest : public tsl::Overlay {
|
||||
public:
|
||||
// libtesla already initialized fs, hid, pl, pmdmnt, hid:sys and set:sys
|
||||
virtual void initServices() override {} // Called at the start to initialize all services necessary for this Overlay
|
||||
virtual void exitServices() override {} // Called at the end to clean up all services previously initialized
|
||||
|
||||
virtual void onShow() override {} // Called before overlay wants to change from invisible to visible state
|
||||
virtual void onHide() override {} // Called before overlay wants to change from visible to invisible state
|
||||
|
||||
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
|
||||
return initially<GuiTest>(1, 2, true); // Initial Gui to load. It's possible to pass arguments to it's constructor like this
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
return tsl::loop<OverlayTest>(argc, argv);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,69 +0,0 @@
|
||||
# libultra
|
||||
|
||||

|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
`libultra` is a powerful collection of helper functions designed specifically for the Ultrahand Overlay project. This library offers a comprehensive set of utilities aimed at simplifying common tasks and enhancing the efficiency of your projects within the Ultrahand Overlay ecosystem.
|
||||
|
||||
## Features
|
||||
|
||||
### [Ultra Header](/libultra/include/ultra.hpp)
|
||||
|
||||
- **ultra.hpp**: The main header file for the `libultra` library, including all essential functions and declarations for seamless integration into your projects.
|
||||
|
||||
### [Debug Functions](/libultra/include/debug_funcs.hpp)
|
||||
|
||||
- **debug_funcs.hpp**: A collection of functions tailored for debugging purposes, aiding in identifying and resolving issues within your codebase.
|
||||
|
||||
### [Download Functions](/libultra/include/download_funcs.hpp)
|
||||
|
||||
- **download_funcs.hpp**: Utilities for managing file downloads, enabling seamless retrieval of resources from external sources.
|
||||
|
||||
### [Get Functions](/libultra/include/get_funcs.hpp)
|
||||
|
||||
- **get_funcs.hpp**: Functions for retrieving data from various sources, simplifying the process of fetching information within your applications.
|
||||
|
||||
### [Hex Functions](/libultra/include/hex_funcs.hpp)
|
||||
|
||||
- **hex_funcs.hpp**: Tools for working with hexadecimal data, facilitating operations such as conversion and manipulation of hexadecimal values.
|
||||
|
||||
### [INI Functions](/libultra/include/ini_funcs.hpp)
|
||||
|
||||
- **ini_funcs.hpp**: Helper functions for handling INI configuration files, offering a convenient way to manage application settings.
|
||||
|
||||
### [JSON Functions](/libultra/include/json_funcs.hpp)
|
||||
|
||||
- **json_funcs.hpp**: Utilities for parsing and manipulating JSON data, providing easy integration with JSON-based APIs and services.
|
||||
|
||||
### [List Functions](/libultra/include/list_funcs.hpp)
|
||||
|
||||
- **list_funcs.hpp**: Functions for working with lists and arrays, offering essential operations like sorting, searching, and manipulation of list elements.
|
||||
|
||||
### [Mod Functions](/libultra/include/mod_funcs.hpp)
|
||||
|
||||
- **mod_funcs.hpp**: Functions for manipulating game mods, facilitating operations and management tasks related to modifications in gaming environments.
|
||||
|
||||
### [Path Functions](/libultra/include/path_funcs.hpp)
|
||||
|
||||
- **path_funcs.hpp**: Tools for working with file paths and directories, simplifying file system operations within your applications.
|
||||
|
||||
### [String Functions](/libultra/include/string_funcs.hpp)
|
||||
|
||||
- **string_funcs.hpp**: A collection of string manipulation functions, providing utilities for tasks such as formatting, searching, and modification of strings.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
To build Ultrahand overlays with `libultra` + `libtesla`, simply add the `lib` folder to your project, then import `tesla.hpp`.
|
||||
|
||||
## Contribution
|
||||
|
||||
Contributions to `libultra` are welcome. If you have ideas for additional helper functions or improvements to existing ones, feel free to submit a pull request or open an issue on GitHub.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under both [GPLv2](LICENSE) and [CC-BY-4.0](SUB_LICENSE).
|
||||
|
||||
Copyright (c) 2024 ppkantorski
|
||||
@@ -1,395 +0,0 @@
|
||||
Attribution 4.0 International
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||
does not provide legal services or legal advice. Distribution of
|
||||
Creative Commons public licenses does not create a lawyer-client or
|
||||
other relationship. Creative Commons makes its licenses and related
|
||||
information available on an "as-is" basis. Creative Commons gives no
|
||||
warranties regarding its licenses, any material licensed under their
|
||||
terms and conditions, or any related information. Creative Commons
|
||||
disclaims all liability for damages resulting from their use to the
|
||||
fullest extent possible.
|
||||
|
||||
Using Creative Commons Public Licenses
|
||||
|
||||
Creative Commons public licenses provide a standard set of terms and
|
||||
conditions that creators and other rights holders may use to share
|
||||
original works of authorship and other material subject to copyright
|
||||
and certain other rights specified in the public license below. The
|
||||
following considerations are for informational purposes only, are not
|
||||
exhaustive, and do not form part of our licenses.
|
||||
|
||||
Considerations for licensors: Our public licenses are
|
||||
intended for use by those authorized to give the public
|
||||
permission to use material in ways otherwise restricted by
|
||||
copyright and certain other rights. Our licenses are
|
||||
irrevocable. Licensors should read and understand the terms
|
||||
and conditions of the license they choose before applying it.
|
||||
Licensors should also secure all rights necessary before
|
||||
applying our licenses so that the public can reuse the
|
||||
material as expected. Licensors should clearly mark any
|
||||
material not subject to the license. This includes other CC-
|
||||
licensed material, or material used under an exception or
|
||||
limitation to copyright. More considerations for licensors:
|
||||
wiki.creativecommons.org/Considerations_for_licensors
|
||||
|
||||
Considerations for the public: By using one of our public
|
||||
licenses, a licensor grants the public permission to use the
|
||||
licensed material under specified terms and conditions. If
|
||||
the licensor's permission is not necessary for any reason--for
|
||||
example, because of any applicable exception or limitation to
|
||||
copyright--then that use is not regulated by the license. Our
|
||||
licenses grant only permissions under copyright and certain
|
||||
other rights that a licensor has authority to grant. Use of
|
||||
the licensed material may still be restricted for other
|
||||
reasons, including because others have copyright or other
|
||||
rights in the material. A licensor may make special requests,
|
||||
such as asking that all changes be marked or described.
|
||||
Although not required by our licenses, you are encouraged to
|
||||
respect those requests where reasonable. More_considerations
|
||||
for the public:
|
||||
wiki.creativecommons.org/Considerations_for_licensees
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Attribution 4.0 International Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree
|
||||
to be bound by the terms and conditions of this Creative Commons
|
||||
Attribution 4.0 International Public License ("Public License"). To the
|
||||
extent this Public License may be interpreted as a contract, You are
|
||||
granted the Licensed Rights in consideration of Your acceptance of
|
||||
these terms and conditions, and the Licensor grants You such rights in
|
||||
consideration of benefits the Licensor receives from making the
|
||||
Licensed Material available under these terms and conditions.
|
||||
|
||||
|
||||
Section 1 -- Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar
|
||||
Rights that is derived from or based upon the Licensed Material
|
||||
and in which the Licensed Material is translated, altered,
|
||||
arranged, transformed, or otherwise modified in a manner requiring
|
||||
permission under the Copyright and Similar Rights held by the
|
||||
Licensor. For purposes of this Public License, where the Licensed
|
||||
Material is a musical work, performance, or sound recording,
|
||||
Adapted Material is always produced where the Licensed Material is
|
||||
synched in timed relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright
|
||||
and Similar Rights in Your contributions to Adapted Material in
|
||||
accordance with the terms and conditions of this Public License.
|
||||
|
||||
c. Copyright and Similar Rights means copyright and/or similar rights
|
||||
closely related to copyright including, without limitation,
|
||||
performance, broadcast, sound recording, and Sui Generis Database
|
||||
Rights, without regard to how the rights are labeled or
|
||||
categorized. For purposes of this Public License, the rights
|
||||
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||
Rights.
|
||||
|
||||
d. Effective Technological Measures means those measures that, in the
|
||||
absence of proper authority, may not be circumvented under laws
|
||||
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||
Treaty adopted on December 20, 1996, and/or similar international
|
||||
agreements.
|
||||
|
||||
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||
any other exception or limitation to Copyright and Similar Rights
|
||||
that applies to Your use of the Licensed Material.
|
||||
|
||||
f. Licensed Material means the artistic or literary work, database,
|
||||
or other material to which the Licensor applied this Public
|
||||
License.
|
||||
|
||||
g. Licensed Rights means the rights granted to You subject to the
|
||||
terms and conditions of this Public License, which are limited to
|
||||
all Copyright and Similar Rights that apply to Your use of the
|
||||
Licensed Material and that the Licensor has authority to license.
|
||||
|
||||
h. Licensor means the individual(s) or entity(ies) granting rights
|
||||
under this Public License.
|
||||
|
||||
i. Share means to provide material to the public by any means or
|
||||
process that requires permission under the Licensed Rights, such
|
||||
as reproduction, public display, public performance, distribution,
|
||||
dissemination, communication, or importation, and to make material
|
||||
available to the public including in ways that members of the
|
||||
public may access the material from a place and at a time
|
||||
individually chosen by them.
|
||||
|
||||
j. Sui Generis Database Rights means rights other than copyright
|
||||
resulting from Directive 96/9/EC of the European Parliament and of
|
||||
the Council of 11 March 1996 on the legal protection of databases,
|
||||
as amended and/or succeeded, as well as other essentially
|
||||
equivalent rights anywhere in the world.
|
||||
|
||||
k. You means the individual or entity exercising the Licensed Rights
|
||||
under this Public License. Your has a corresponding meaning.
|
||||
|
||||
|
||||
Section 2 -- Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License,
|
||||
the Licensor hereby grants You a worldwide, royalty-free,
|
||||
non-sublicensable, non-exclusive, irrevocable license to
|
||||
exercise the Licensed Rights in the Licensed Material to:
|
||||
|
||||
a. reproduce and Share the Licensed Material, in whole or
|
||||
in part; and
|
||||
|
||||
b. produce, reproduce, and Share Adapted Material.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||
Exceptions and Limitations apply to Your use, this Public
|
||||
License does not apply, and You do not need to comply with
|
||||
its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section
|
||||
6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The
|
||||
Licensor authorizes You to exercise the Licensed Rights in
|
||||
all media and formats whether now known or hereafter created,
|
||||
and to make technical modifications necessary to do so. The
|
||||
Licensor waives and/or agrees not to assert any right or
|
||||
authority to forbid You from making technical modifications
|
||||
necessary to exercise the Licensed Rights, including
|
||||
technical modifications necessary to circumvent Effective
|
||||
Technological Measures. For purposes of this Public License,
|
||||
simply making modifications authorized by this Section 2(a)
|
||||
(4) never produces Adapted Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
a. Offer from the Licensor -- Licensed Material. Every
|
||||
recipient of the Licensed Material automatically
|
||||
receives an offer from the Licensor to exercise the
|
||||
Licensed Rights under the terms and conditions of this
|
||||
Public License.
|
||||
|
||||
b. No downstream restrictions. You may not offer or impose
|
||||
any additional or different terms or conditions on, or
|
||||
apply any Effective Technological Measures to, the
|
||||
Licensed Material if doing so restricts exercise of the
|
||||
Licensed Rights by any recipient of the Licensed
|
||||
Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or
|
||||
may be construed as permission to assert or imply that You
|
||||
are, or that Your use of the Licensed Material is, connected
|
||||
with, or sponsored, endorsed, or granted official status by,
|
||||
the Licensor or others designated to receive attribution as
|
||||
provided in Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not
|
||||
licensed under this Public License, nor are publicity,
|
||||
privacy, and/or other similar personality rights; however, to
|
||||
the extent possible, the Licensor waives and/or agrees not to
|
||||
assert any such rights held by the Licensor to the limited
|
||||
extent necessary to allow You to exercise the Licensed
|
||||
Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this
|
||||
Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to
|
||||
collect royalties from You for the exercise of the Licensed
|
||||
Rights, whether directly or through a collecting society
|
||||
under any voluntary or waivable statutory or compulsory
|
||||
licensing scheme. In all other cases the Licensor expressly
|
||||
reserves any right to collect such royalties.
|
||||
|
||||
|
||||
Section 3 -- License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the
|
||||
following conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified
|
||||
form), You must:
|
||||
|
||||
a. retain the following if it is supplied by the Licensor
|
||||
with the Licensed Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed
|
||||
Material and any others designated to receive
|
||||
attribution, in any reasonable manner requested by
|
||||
the Licensor (including by pseudonym if
|
||||
designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of
|
||||
warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the
|
||||
extent reasonably practicable;
|
||||
|
||||
b. indicate if You modified the Licensed Material and
|
||||
retain an indication of any previous modifications; and
|
||||
|
||||
c. indicate the Licensed Material is licensed under this
|
||||
Public License, and include the text of, or the URI or
|
||||
hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||
reasonable manner based on the medium, means, and context in
|
||||
which You Share the Licensed Material. For example, it may be
|
||||
reasonable to satisfy the conditions by providing a URI or
|
||||
hyperlink to a resource that includes the required
|
||||
information.
|
||||
|
||||
3. If requested by the Licensor, You must remove any of the
|
||||
information required by Section 3(a)(1)(A) to the extent
|
||||
reasonably practicable.
|
||||
|
||||
4. If You Share Adapted Material You produce, the Adapter's
|
||||
License You apply must not prevent recipients of the Adapted
|
||||
Material from complying with this Public License.
|
||||
|
||||
|
||||
Section 4 -- Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that
|
||||
apply to Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||
to extract, reuse, reproduce, and Share all or a substantial
|
||||
portion of the contents of the database;
|
||||
|
||||
b. if You include all or a substantial portion of the database
|
||||
contents in a database in which You have Sui Generis Database
|
||||
Rights, then the database in which You have Sui Generis Database
|
||||
Rights (but not its individual contents) is Adapted Material; and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share
|
||||
all or a substantial portion of the contents of the database.
|
||||
|
||||
For the avoidance of doubt, this Section 4 supplements and does not
|
||||
replace Your obligations under this Public License where the Licensed
|
||||
Rights include other Copyright and Similar Rights.
|
||||
|
||||
|
||||
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||
|
||||
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided
|
||||
above shall be interpreted in a manner that, to the extent
|
||||
possible, most closely approximates an absolute disclaimer and
|
||||
waiver of all liability.
|
||||
|
||||
|
||||
Section 6 -- Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and
|
||||
Similar Rights licensed here. However, if You fail to comply with
|
||||
this Public License, then Your rights under this Public License
|
||||
terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under
|
||||
Section 6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided
|
||||
it is cured within 30 days of Your discovery of the
|
||||
violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||
right the Licensor may have to seek remedies for Your violations
|
||||
of this Public License.
|
||||
|
||||
c. For the avoidance of doubt, the Licensor may also offer the
|
||||
Licensed Material under separate terms or conditions or stop
|
||||
distributing the Licensed Material at any time; however, doing so
|
||||
will not terminate this Public License.
|
||||
|
||||
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||
License.
|
||||
|
||||
|
||||
Section 7 -- Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different
|
||||
terms or conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the
|
||||
Licensed Material not stated herein are separate from and
|
||||
independent of the terms and conditions of this Public License.
|
||||
|
||||
|
||||
Section 8 -- Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and
|
||||
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||
conditions on any use of the Licensed Material that could lawfully
|
||||
be made without permission under this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is
|
||||
deemed unenforceable, it shall be automatically reformed to the
|
||||
minimum extent necessary to make it enforceable. If the provision
|
||||
cannot be reformed, it shall be severed from this Public License
|
||||
without affecting the enforceability of the remaining terms and
|
||||
conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no
|
||||
failure to comply consented to unless expressly agreed to by the
|
||||
Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted
|
||||
as a limitation upon, or waiver of, any privileges and immunities
|
||||
that apply to the Licensor or You, including from the legal
|
||||
processes of any jurisdiction or authority.
|
||||
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons is not a party to its public
|
||||
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||
its public licenses to material it publishes and in those instances
|
||||
will be considered the “Licensor.” The text of the Creative Commons
|
||||
public licenses is dedicated to the public domain under the CC0 Public
|
||||
Domain Dedication. Except for the limited purpose of indicating that
|
||||
material is shared under a Creative Commons public license or as
|
||||
otherwise permitted by the Creative Commons policies published at
|
||||
creativecommons.org/policies, Creative Commons does not authorize the
|
||||
use of the trademark "Creative Commons" or any other trademark or logo
|
||||
of Creative Commons without its prior written consent including,
|
||||
without limitation, in connection with any unauthorized modifications
|
||||
to any of its public licenses or any other arrangements,
|
||||
understandings, or agreements concerning use of licensed material. For
|
||||
the avoidance of doubt, this paragraph does not form part of the
|
||||
public licenses.
|
||||
|
||||
Creative Commons may be contacted at creativecommons.org.
|
||||
@@ -1,96 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: audio_player.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header defines the AudioPlayer class and related structures used for
|
||||
* handling sound playback within the Ultrahand Overlay. It provides interfaces
|
||||
* for loading, caching, and playing WAV audio through libnx’s audout service,
|
||||
* along with basic sound type management and synchronization support.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2025 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
namespace ult {
|
||||
class AudioPlayer {
|
||||
public:
|
||||
enum class SoundType : uint8_t { // <- uint8_t saves space
|
||||
Navigate,
|
||||
Enter,
|
||||
Exit,
|
||||
Wall,
|
||||
On,
|
||||
Off,
|
||||
Settings,
|
||||
Move,
|
||||
Count
|
||||
};
|
||||
|
||||
struct CachedSound {
|
||||
void* buffer = nullptr;
|
||||
uint32_t bufferSize = 0;
|
||||
uint32_t dataSize = 0;
|
||||
};
|
||||
|
||||
static bool initialize();
|
||||
static void exit();
|
||||
static void playSound(SoundType type);
|
||||
|
||||
// Inline wrappers - same API, zero overhead
|
||||
static inline void playNavigateSound() { playSound(SoundType::Navigate); }
|
||||
static inline void playEnterSound() { playSound(SoundType::Enter); }
|
||||
static inline void playExitSound() { playSound(SoundType::Exit); }
|
||||
static inline void playWallSound() { playSound(SoundType::Wall); }
|
||||
static inline void playOnSound() { playSound(SoundType::On); }
|
||||
static inline void playOffSound() { playSound(SoundType::Off); }
|
||||
static inline void playSettingsSound() { playSound(SoundType::Settings); }
|
||||
static inline void playMoveSound() { playSound(SoundType::Move); }
|
||||
|
||||
static void setMasterVolume(float volume);
|
||||
static void setEnabled(bool enabled);
|
||||
static bool isEnabled();
|
||||
static bool isDocked();
|
||||
static bool reloadIfDockedChanged();
|
||||
static void reloadAllSounds();
|
||||
static void unloadAllSounds(const std::initializer_list<SoundType>& excludeSounds = {});
|
||||
static std::mutex m_audioMutex;
|
||||
|
||||
private:
|
||||
static bool m_initialized;
|
||||
static std::atomic<bool> m_enabled; // <- atomic for lock-free reads
|
||||
static float m_masterVolume;
|
||||
static std::vector<CachedSound> m_cachedSounds;
|
||||
|
||||
static bool m_lastDockedState;
|
||||
|
||||
inline static constexpr const char* m_soundPaths[static_cast<size_t>(SoundType::Count)] = {
|
||||
"sdmc:/config/ultrahand/sounds/tick.wav",
|
||||
"sdmc:/config/ultrahand/sounds/enter.wav",
|
||||
"sdmc:/config/ultrahand/sounds/exit.wav",
|
||||
"sdmc:/config/ultrahand/sounds/wall.wav",
|
||||
"sdmc:/config/ultrahand/sounds/on.wav",
|
||||
"sdmc:/config/ultrahand/sounds/off.wav",
|
||||
"sdmc:/config/ultrahand/sounds/settings.wav",
|
||||
"sdmc:/config/ultrahand/sounds/move.wav"
|
||||
};
|
||||
|
||||
//static void playAudioBuffer(void* buffer, uint32_t bufferSize);
|
||||
static bool loadSoundFromWav(SoundType type, const char* path);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: debug_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains debugging functions for the Ultrahand Overlay project.
|
||||
* These functions allow logging messages with timestamps to a log file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#ifndef DEBUG_FUNCS_HPP
|
||||
#define DEBUG_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
namespace ult {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
|
||||
// Specify the log file path
|
||||
extern const std::string defaultLogFilePath;
|
||||
|
||||
extern std::string logFilePath; // Declare logFilePath as extern
|
||||
extern bool disableLogging; // Declare disableLogging as extern
|
||||
|
||||
// Global mutex for thread-safe logging
|
||||
extern std::mutex logMutex; // Declare logMutex as extern
|
||||
|
||||
/**
|
||||
* @brief Logs a message with a timestamp to a log file in a thread-safe manner.
|
||||
*
|
||||
* @param message The message to be logged.
|
||||
*/
|
||||
void logMessage(const char* message);
|
||||
void logMessage(const std::string& message);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // DEBUG_FUNCS_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: download_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains functions for downloading and extracting files
|
||||
* using libcurl and miniz. It includes functions for downloading files from URLs,
|
||||
* writing received data to a file, and extracting files from ZIP archives.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#ifndef DOWNLOAD_FUNCS_HPP
|
||||
#define DOWNLOAD_FUNCS_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <switch.h>
|
||||
|
||||
#define CURL_DISABLE_DEFLATE
|
||||
#include <curl/curl.h>
|
||||
#include <zlib.h>
|
||||
#include <minizip/unzip.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include "global_vars.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
// Constants for buffer sizes
|
||||
|
||||
extern size_t DOWNLOAD_READ_BUFFER;
|
||||
extern size_t DOWNLOAD_WRITE_BUFFER;
|
||||
extern size_t UNZIP_READ_BUFFER;
|
||||
extern size_t UNZIP_WRITE_BUFFER;
|
||||
|
||||
// Path to the CA certificate
|
||||
//extern const std::string cacertPath;
|
||||
//extern const std::string cacertURL;
|
||||
|
||||
// Thread-safe atomic flags for operation control
|
||||
extern std::atomic<bool> abortDownload;
|
||||
extern std::atomic<bool> abortUnzip;
|
||||
extern std::atomic<int> downloadPercentage;
|
||||
extern std::atomic<int> unzipPercentage;
|
||||
|
||||
|
||||
// Thread-safe callback functions
|
||||
//#if !USING_FSTREAM_DIRECTIVE
|
||||
//size_t writeCallback(void* ptr, size_t size, size_t nmemb, FILE* stream);
|
||||
//#else
|
||||
//size_t writeCallback(void* ptr, size_t size, size_t nmemb, std::ostream* stream);
|
||||
//#endif
|
||||
|
||||
//int progressCallback(void* ptr, curl_off_t totalToDownload, curl_off_t nowDownloaded, curl_off_t totalToUpload, curl_off_t nowUploaded);
|
||||
|
||||
|
||||
// Thread-safe initialization and cleanup functions
|
||||
//void initializeCurl();
|
||||
//void cleanupCurl();
|
||||
|
||||
// Main API functions - thread-safe and optimized
|
||||
bool downloadFile(const std::string& url, const std::string& toDestination, bool noPercentagePolling=false);
|
||||
bool unzipFile(const std::string& zipFilePath, const std::string& extractTo);
|
||||
}
|
||||
|
||||
#endif // DOWNLOAD_FUNCS_HPP
|
||||
@@ -1,160 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: get_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains functions for retrieving information and data
|
||||
* from various sources, including file system and JSON files. It includes
|
||||
* functions for obtaining overlay module information, reading file contents,
|
||||
* and parsing JSON data.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef GET_FUNCS_HPP
|
||||
#define GET_FUNCS_HPP
|
||||
|
||||
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fnmatch.h>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
struct DirCloser {
|
||||
void operator()(DIR* dir) const {
|
||||
if (dir) closedir(dir);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads the contents of a file and returns it as a string, normalizing line endings.
|
||||
*
|
||||
* @param filePath The path to the file to be read.
|
||||
* @return The content of the file as a string with line endings normalized to '\n'.
|
||||
*/
|
||||
//std::string getFileContents(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Concatenates the provided directory and file names to form a destination path.
|
||||
*
|
||||
* @param destinationDir The directory where the file should be placed.
|
||||
* @param fileName The name of the file.
|
||||
* @return The destination path as a string.
|
||||
*/
|
||||
std::string getDestinationPath(const std::string& destinationDir, const std::string& fileName);
|
||||
|
||||
/**
|
||||
* @brief Extracts the value part from a string line containing a key-value pair.
|
||||
*
|
||||
* @param line The string line containing a key-value pair (e.g., "key=value").
|
||||
* @return The extracted value as a string. If no value is found, an empty string is returned.
|
||||
*/
|
||||
std::string getValueFromLine(const std::string& line);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name from a file path, including handling directories.
|
||||
*
|
||||
* @param path The file path from which to extract the name.
|
||||
* @return The extracted name as a string. If the path indicates a directory, it extracts the last directory name.
|
||||
* If the path is empty or no name is found, an empty string is returned.
|
||||
*/
|
||||
std::string getNameFromPath(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the file name from a full file path.
|
||||
*
|
||||
* This function takes a filesystem path and returns only the file name,
|
||||
* stripping away any directory paths that precede it.
|
||||
*
|
||||
* @param path The full path to the file.
|
||||
* @return The file name extracted from the full path.
|
||||
*/
|
||||
std::string getFileName(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name of the parent directory from a given file path at a specified level.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory name.
|
||||
* @param level The level of the parent directory to extract (0 for immediate parent, 1 for grandparent, and so on).
|
||||
* @return The name of the parent directory at the specified level.
|
||||
*/
|
||||
std::string getParentDirNameFromPath(const std::string& path, size_t level = 0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the parent directory path from a given file path.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory path.
|
||||
* @return The parent directory path.
|
||||
*/
|
||||
std::string getParentDirFromPath(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets a list of subdirectories in a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the names of subdirectories.
|
||||
*/
|
||||
std::vector<std::string> getSubdirectories(const std::string& directoryPath);
|
||||
|
||||
// Cache to store directory status
|
||||
// Assuming a very simple cache implementation
|
||||
//extern std::vector<std::pair<std::string, bool>> directoryCache;
|
||||
|
||||
bool isDirectory(struct dirent* entry, const std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Recursively retrieves a list of files from a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the paths of the files.
|
||||
*/
|
||||
std::vector<std::string> getFilesListFromDirectory(const std::string& directoryPath);
|
||||
|
||||
// Helper function to check if a path is a directory
|
||||
//bool isDirectoryCached(const struct dirent* entry, const std::string& fullPath) {
|
||||
// struct stat st;
|
||||
// if (stat(fullPath.c_str(), &st) != 0) return false;
|
||||
// return S_ISDIR(st.st_mode);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
void handleDirectory(const std::string& basePath, const std::vector<std::string>& parts, size_t partIndex, std::vector<std::string>& results, bool directoryOnly, size_t maxLines=0);
|
||||
/**
|
||||
* @brief Gets a list of files and folders based on a wildcard pattern.
|
||||
*
|
||||
* This function searches for files and folders in a directory that match the
|
||||
* specified wildcard pattern.
|
||||
*
|
||||
* @param pathPattern The wildcard pattern to match files and folders.
|
||||
* @return A vector of strings containing the paths of matching files and folders.
|
||||
*/
|
||||
std::vector<std::string> getFilesListByWildcards(const std::string& pathPattern, size_t maxLines=0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,173 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: global_vars.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides the definitions of global constants and paths used
|
||||
* throughout the Ultrahand Overlay project. These constants are essential for
|
||||
* file management and configuration settings within the application.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <set>
|
||||
|
||||
// Auto-detect constexpr std::string support based on C++ version
|
||||
#if __cplusplus >= 202400L
|
||||
#define CONSTEXPR_STRING constexpr
|
||||
#else
|
||||
#define CONSTEXPR_STRING const
|
||||
#endif
|
||||
|
||||
namespace ult {
|
||||
extern const std::string CONFIG_FILENAME;
|
||||
|
||||
extern const std::string ULTRAHAND_PROJECT_NAME;
|
||||
extern const std::string CAPITAL_ULTRAHAND_PROJECT_NAME;
|
||||
|
||||
extern const std::string ROOT_PATH;
|
||||
extern const std::string SETTINGS_PATH;
|
||||
extern const std::string ULTRAHAND_CONFIG_INI_PATH;
|
||||
extern const std::string TESLA_CONFIG_INI_PATH;
|
||||
extern const std::string LANG_PATH;
|
||||
extern const std::string THEMES_PATH;
|
||||
extern const std::string WALLPAPERS_PATH;
|
||||
extern const std::string SOUNDS_PATH;
|
||||
extern const std::string FLAGS_PATH;
|
||||
extern const std::string NOTIFICATIONS_PATH;
|
||||
extern const std::string PAYLOADS_PATH;
|
||||
extern const std::string HB_APPSTORE_JSON;
|
||||
|
||||
// Can be overriden with APPEARANCE_OVERRIDE_PATH directive
|
||||
extern std::string THEME_CONFIG_INI_PATH;
|
||||
extern std::string WALLPAPER_PATH;
|
||||
|
||||
|
||||
//#if IS_LAUNCHER_DIRECTIVE
|
||||
extern const std::string SPLIT_PROJECT_NAME_1;
|
||||
extern const std::string SPLIT_PROJECT_NAME_2;
|
||||
extern const std::string BOOT_PACKAGE_FILENAME;
|
||||
extern const std::string EXIT_PACKAGE_FILENAME;
|
||||
extern const std::string PACKAGE_FILENAME;
|
||||
|
||||
extern const std::string DOWNLOADS_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;
|
||||
extern const std::string OVERLAYS_INI_FILEPATH;
|
||||
extern const std::string PACKAGES_INI_FILEPATH;
|
||||
|
||||
extern const std::string NOTIFICATIONS_FLAG_FILEPATH;
|
||||
|
||||
extern const std::set<std::string> PROTECTED_FILES;
|
||||
|
||||
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 OLD_NX_OVLLOADER_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 LAUNCH_ARGS_STR;
|
||||
extern const std::string USE_LAUNCH_ARGS_STR;
|
||||
extern const std::string USE_QUICK_LAUNCH_STR;
|
||||
extern const std::string USE_BOOT_PACKAGE_STR;
|
||||
extern const std::string USE_EXIT_PACKAGE_STR;
|
||||
extern const std::string USE_LOGGING_STR;
|
||||
|
||||
//#endif
|
||||
|
||||
extern const std::string TESLA_COMBO_STR;
|
||||
extern const std::string ULTRAHAND_COMBO_STR;
|
||||
|
||||
extern const std::string FUSE_STR;
|
||||
extern const std::string TESLA_STR;
|
||||
extern const std::string ERISTA_STR;
|
||||
extern const std::string MARIKO_STR;
|
||||
extern const std::string KEY_COMBO_STR;
|
||||
extern const std::string DEFAULT_LANG_STR;
|
||||
|
||||
|
||||
extern const std::string LIST_STR;
|
||||
extern const std::string LIST_FILE_STR;
|
||||
extern const std::string JSON_STR;
|
||||
extern const std::string JSON_FILE_STR;
|
||||
extern const std::string INI_FILE_STR;
|
||||
extern const std::string HEX_FILE_STR;
|
||||
extern const std::string PACKAGE_STR;
|
||||
extern const std::string PACKAGES_STR;
|
||||
extern const std::string OVERLAY_STR;
|
||||
extern const std::string OVERLAYS_STR;
|
||||
extern const std::string IN_OVERLAY_STR;
|
||||
extern const std::string IN_HIDDEN_OVERLAY_STR;
|
||||
extern const std::string IN_HIDDEN_PACKAGE_STR;
|
||||
extern const std::string FILE_STR;
|
||||
extern const std::string SYSTEM_STR;
|
||||
extern const std::string MODE_STR;
|
||||
extern const std::string GROUPING_STR;
|
||||
extern const std::string FOOTER_STR;
|
||||
extern const std::string TOGGLE_STR;
|
||||
extern const std::string LEFT_STR;
|
||||
extern const std::string RIGHT_STR;
|
||||
extern const std::string CENTER_STR;
|
||||
extern const std::string HIDE_STR;
|
||||
extern const std::string STAR_STR;
|
||||
extern const std::string PRIORITY_STR;
|
||||
extern const std::string ON_STR;
|
||||
extern const std::string OFF_STR;
|
||||
extern const std::string CAPITAL_ON_STR;
|
||||
extern const std::string CAPITAL_OFF_STR;
|
||||
extern const std::string TRUE_STR;
|
||||
extern const std::string FALSE_STR;
|
||||
extern const std::string GLOBAL_STR;
|
||||
extern const std::string DEFAULT_STR;
|
||||
extern const std::string SLOT_STR;
|
||||
extern const std::string OPTION_STR;
|
||||
extern const std::string FORWARDER_STR;
|
||||
extern const std::string TEXT_STR;
|
||||
extern const std::string TABLE_STR;
|
||||
extern const std::string TRACKBAR_STR;
|
||||
extern const std::string STEP_TRACKBAR_STR;
|
||||
extern const std::string NAMED_STEP_TRACKBAR_STR;
|
||||
extern const std::string NULL_STR;
|
||||
extern const std::string THEME_STR;
|
||||
extern const std::string NOT_AVAILABLE_STR;
|
||||
extern const std::string MEMORY_STR;
|
||||
|
||||
// Pre-defined symbols
|
||||
extern const std::string OPTION_SYMBOL;
|
||||
extern const std::string DROPDOWN_SYMBOL;
|
||||
extern const std::string CHECKMARK_SYMBOL;
|
||||
extern const std::string CROSSMARK_SYMBOL;
|
||||
extern const std::string DOWNLOAD_SYMBOL;
|
||||
extern const std::string UNZIP_SYMBOL;
|
||||
extern const std::string COPY_SYMBOL;
|
||||
extern const std::string INPROGRESS_SYMBOL;
|
||||
extern const std::string STAR_SYMBOL;
|
||||
extern const std::string DIVIDER_SYMBOL;
|
||||
|
||||
extern const std::vector<std::string> THROBBER_SYMBOLS;
|
||||
|
||||
extern std::atomic<int> downloadPercentage;
|
||||
extern std::atomic<int> unzipPercentage;
|
||||
extern std::atomic<int> copyPercentage;
|
||||
extern std::atomic<int> displayPercentage;
|
||||
|
||||
void resetPercentages();
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: haptics.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header declares functions and shared flags for managing haptic feedback
|
||||
* in the Ultrahand Overlay. It includes routines for initializing vibration
|
||||
* devices, sending rumble and double-click patterns, and controlling timing
|
||||
* for single and double pulse haptics. Atomic flags ensure safe access across
|
||||
* threads.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2025 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
namespace ult {
|
||||
|
||||
//extern bool rumbleInitialized;
|
||||
extern std::atomic<bool> rumbleActive;
|
||||
extern std::atomic<bool> doubleClickActive;
|
||||
|
||||
//void initRumble();
|
||||
void deinitRumble();
|
||||
void checkAndReinitRumble();
|
||||
|
||||
void rumbleClick();
|
||||
void rumbleDoubleClick();
|
||||
void processRumbleStop(u64 nowNs);
|
||||
void processRumbleDoubleClick(u64 nowNs);
|
||||
void rumbleDoubleClickStandalone();
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: hex_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with hexadecimal data in C++.
|
||||
* It includes functions for converting between ASCII and hexadecimal strings,
|
||||
* finding hexadecimal data offsets in a file, and editing hexadecimal data in a file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HEX_FUNCS_HPP
|
||||
#define HEX_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
//#include <cstdio> // Added for FILE and fopen
|
||||
#include <cstring> // Added for std::memcmp
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include <global_vars.hpp>
|
||||
#include <debug_funcs.hpp>
|
||||
#include <string_funcs.hpp>
|
||||
|
||||
|
||||
namespace ult {
|
||||
extern size_t HEX_BUFFER_SIZE;
|
||||
|
||||
|
||||
// For improving the speed of hexing consecutively with the same file and asciiPattern.
|
||||
extern std::unordered_map<std::string, std::string> hexSumCache; // MOVED TO main.cpp
|
||||
|
||||
// Lookup table for hex characters
|
||||
inline constexpr char hexLookup[] = "0123456789ABCDEF";
|
||||
|
||||
|
||||
// ULTRA-FAST hex conversion with lookup table
|
||||
inline constexpr unsigned char hexTable[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,
|
||||
0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
|
||||
extern void clearHexSumCache();
|
||||
extern size_t getHexSumCacheSize();
|
||||
|
||||
/**
|
||||
* @brief Converts an ASCII string to a hexadecimal string.
|
||||
*
|
||||
* This function takes an ASCII string as input and converts it into a hexadecimal string.
|
||||
*
|
||||
* @param asciiStr The ASCII string to convert.
|
||||
* @return The corresponding hexadecimal string.
|
||||
*/
|
||||
|
||||
|
||||
// Function to convert ASCII string to Hex string
|
||||
std::string asciiToHex(const std::string& asciiStr);
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a hexadecimal string.
|
||||
*
|
||||
* This function takes a decimal string as input and converts it into a hexadecimal string.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @return The corresponding hexadecimal string.
|
||||
*/
|
||||
std::string decimalToHex(const std::string& decimalStr, int byteGroupSize = 2);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a hexadecimal string to a decimal string.
|
||||
*
|
||||
* This function takes a hexadecimal string as input and converts it into a decimal string.
|
||||
*
|
||||
* @param hexStr The hexadecimal string to convert.
|
||||
* @return The corresponding decimal string.
|
||||
*/
|
||||
std::string hexToDecimal(const std::string& hexStr);
|
||||
|
||||
|
||||
|
||||
std::string hexToReversedHex(const std::string& hexadecimal, int order = 2);
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a reversed hexadecimal string.
|
||||
*
|
||||
* This function takes a decimal string as input, converts it into a hexadecimal
|
||||
* string, and reverses the resulting hexadecimal string in groups of byteGroupSize.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @param byteGroupSize The grouping byteGroupSize for reversing the hexadecimal string.
|
||||
* @return The reversed hexadecimal string.
|
||||
*/
|
||||
std::string decimalToReversedHex(const std::string& decimalStr, int byteGroupSize = 2);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds the offsets of hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and returns the file offsets where the data is found.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexData The hexadecimal data to search for.
|
||||
* @return A vector of strings containing the file offsets where the data is found.
|
||||
*/
|
||||
std::vector<std::string> findHexDataOffsets(const std::string& filePath, const std::string& hexData);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Edits hexadecimal data in a file at a specified offset.
|
||||
*
|
||||
* This function opens a binary file, seeks to a specified offset, and replaces
|
||||
* the data at that offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The offset in the file to performthe edit.
|
||||
* @param hexData The hexadecimal data to replace at the offset.
|
||||
*/
|
||||
void hexEditByOffset(const std::string& filePath, const std::string& offsetStr, const std::string& hexData);
|
||||
|
||||
/**
|
||||
* @brief Edits a specific offset in a file with custom hexadecimal data.
|
||||
*
|
||||
* This function searches for a custom pattern in the file and calculates a new offset
|
||||
* based on user-provided offsetStr and the found pattern. It then replaces the data
|
||||
* at the calculated offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The user-provided offset for the edit.
|
||||
* @param customPattern The custom pattern to search for in the file.
|
||||
* @param hexDataReplacement The hexadecimal data to replace at the calculated offset.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditByCustomOffset(const std::string& filePath, const std::string& customAsciiPattern, const std::string& offsetStr, const std::string& hexDataReplacement, size_t occurrence = 0);
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditFindReplace(const std::string& filePath, const std::string& hexDataToReplace, const std::string& hexDataReplacement, size_t occurrence = 0);
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
std::string parseHexDataAtCustomOffset(const std::string& filePath, const std::string& customAsciiPattern, const std::string& offsetStr, size_t length, size_t occurrence = 0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
|
||||
std::string replaceHexPlaceholder(const std::string& arg, const std::string& hexPath);
|
||||
|
||||
|
||||
|
||||
std::string extractVersionFromBinary(const std::string &filePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,344 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: ini_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with INI (Initialization) files
|
||||
* in C++. It includes functions for reading, parsing, and editing INI files,
|
||||
* as well as cleaning INI file formatting.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef INI_FUNCS_HPP
|
||||
#define INI_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
//#include "nx_fstream.hpp"
|
||||
#endif
|
||||
|
||||
#include <cstring> // For std::string, strlen(), etc.
|
||||
#include <string> // For std::string
|
||||
#include <vector> // For std::vector
|
||||
#include <map> // For std::map
|
||||
//#include <sstream> // For std::istringstream
|
||||
#include <algorithm> // For std::remove_if
|
||||
//#include <cctype> // For ::isspace
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
extern void clearIniMutexCache();
|
||||
|
||||
extern size_t INI_BUFFER_SIZE;
|
||||
extern size_t INI_BUFFER_LARGE;
|
||||
|
||||
/**
|
||||
* @brief Represents a package header structure.
|
||||
*
|
||||
* This structure holds information about a package header, including version,
|
||||
* creator, and description.
|
||||
*/
|
||||
struct PackageHeader {
|
||||
std::string title;
|
||||
std::string display_title;
|
||||
std::string version;
|
||||
std::string creator;
|
||||
std::string about;
|
||||
std::string credits;
|
||||
std::string color;
|
||||
std::string show_version;
|
||||
std::string show_widget;
|
||||
|
||||
void clear() {
|
||||
title.clear();
|
||||
display_title.clear();
|
||||
version.clear();
|
||||
creator.clear();
|
||||
about.clear();
|
||||
credits.clear();
|
||||
color.clear();
|
||||
show_version.clear();
|
||||
show_widget.clear();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Retrieves the package header information from an INI file.
|
||||
*
|
||||
* This function parses an INI file and extracts the package header information.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @return The package header structure.
|
||||
*/
|
||||
PackageHeader getPackageHeaderFromIni(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a vector of substrings using a specified delimiter.
|
||||
*
|
||||
* This function splits a given string into multiple substrings based on the specified delimiter.
|
||||
*
|
||||
* @param str The input string to be split.
|
||||
* @param delim The delimiter character used for splitting (default is space ' ').
|
||||
* @return A vector of substrings obtained by splitting the input string.
|
||||
*/
|
||||
std::vector<std::string> split(const std::string& str, char delim = ' ');
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI-formatted string into a map of sections and key-value pairs.
|
||||
*
|
||||
* This function parses an INI-formatted string and organizes the data into a map,
|
||||
* where sections are keys and key-value pairs are stored within each section.
|
||||
*
|
||||
* @param str The INI-formatted string to parse.
|
||||
* @return A map representing the parsed INI data.
|
||||
*/
|
||||
std::map<std::string, std::map<std::string, std::string>> parseIni(const std::string &str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI file and returns its content as a map of sections and key-value pairs.
|
||||
*
|
||||
* This function reads the contents of an INI file located at the specified path,
|
||||
* parses it into a map structure, where section names are keys and key-value pairs
|
||||
* are stored within each section.
|
||||
*
|
||||
* @param configIniPath The path to the INI file to be parsed.
|
||||
* @return A map representing the parsed INI data.
|
||||
*/
|
||||
std::map<std::string, std::map<std::string, std::string>> getParsedDataFromIniFile(const std::string& configIniPath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses an INI file and retrieves key-value pairs from a specific section.
|
||||
*
|
||||
* This function reads the contents of an INI file located at the specified path,
|
||||
* and returns the key-value pairs within a specific section.
|
||||
*
|
||||
* @param configIniPath The path to the INI file to be parsed.
|
||||
* @param sectionName The name of the section to retrieve key-value pairs from.
|
||||
* @return A map representing the key-value pairs in the specified section.
|
||||
*/
|
||||
std::map<std::string, std::string> getKeyValuePairsFromSection(const std::string& configIniPath, const std::string& sectionName);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses sections from an INI file and returns them as a list of strings.
|
||||
*
|
||||
* This function reads an INI file and extracts the section names from it.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @return A vector of section names.
|
||||
*/
|
||||
std::vector<std::string> parseSectionsFromIni(const std::string& filePath);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses a specific value from a section and key in an INI file.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section containing the desired key.
|
||||
* @param keyName The name of the key whose value is to be retrieved.
|
||||
* @return The value as a string, or an empty string if the key or section isn't found.
|
||||
*/
|
||||
std::string parseValueFromIniSection(const std::string& filePath, const std::string& sectionName, const std::string& keyName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Cleans the formatting of an INI file by removing empty lines and standardizing section formatting.
|
||||
*
|
||||
* This function takes an INI file located at the specified path, removes empty lines,
|
||||
* and standardizes the formatting of sections by ensuring that there is a newline
|
||||
* between each section's closing ']' and the next section's opening '['.
|
||||
*
|
||||
* @param filePath The path to the INI file to be cleaned.
|
||||
*/
|
||||
void cleanIniFormatting(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Modifies or creates an INI file by adding or updating key-value pairs in the specified section.
|
||||
*
|
||||
* This function attempts to open the specified INI file for reading. If the file doesn't exist,
|
||||
* it creates a new file and adds the specified section and key-value pair. If the file exists,
|
||||
* it reads its contents, modifies or adds the key-value pair in the specified section, and saves
|
||||
* the changes back to the original file.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-value pair should be added or updated.
|
||||
* @param desiredKey The key for the key-value pair to be added or updated.
|
||||
* @param desiredValue The new value for the key-value pair.
|
||||
* @param desiredNewKey (Optional) If provided, the function will rename the key while preserving the original value.
|
||||
*/
|
||||
void setIniFile(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredValue, const std::string& desiredNewKey = "", const std::string& comment = "");
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a key in an INI file within the specified section and cleans the formatting.
|
||||
*
|
||||
* This function sets the value of the specified key within the given section of the INI file.
|
||||
* If the key or section does not exist, it creates them. After updating the INI file,
|
||||
* it cleans the formatting to ensure proper INI file structure.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-value pair should be added or updated.
|
||||
* @param desiredKey The key for the key-value pair to be added or updated.
|
||||
* @param desiredValue The new value for the key-value pair.
|
||||
*/
|
||||
void setIniFileValue(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredValue, const std::string& comment="");
|
||||
|
||||
/**
|
||||
* @brief Sets the key name to a new name in an INI file within the specified section and cleans the formatting.
|
||||
*
|
||||
* This function sets the key name to a new name within the given section of the INI file.
|
||||
* If the key or section does not exist, it creates them. After updating the INI file,
|
||||
* it cleans the formatting to ensure proper INI file structure.
|
||||
*
|
||||
* @param fileToEdit The path to the INI file to be modified or created.
|
||||
* @param desiredSection The name of the section in which the key-name change should occur.
|
||||
* @param desiredKey The key name to be changed.
|
||||
* @param desiredNewKey The new key name to replace the original key name.
|
||||
*/
|
||||
void setIniFileKey(const std::string& fileToEdit, const std::string& desiredSection, const std::string& desiredKey, const std::string& desiredNewKey, const std::string& comment="");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds a new section to an INI file.
|
||||
*
|
||||
* This function adds a new section with the specified name to the INI file located at the
|
||||
* specified path. If the section already exists, it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section to add.
|
||||
*/
|
||||
void addIniSection(const std::string& filePath, const std::string& sectionName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Renames a section in an INI file.
|
||||
*
|
||||
* This function renames the section with the specified current name to the specified new name
|
||||
* in the INI file located at the specified path. If the current section does not exist, or if the
|
||||
* new section name already exists, it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param currentSectionName The name of the section to rename.
|
||||
* @param newSectionName The new name for the section.
|
||||
*/
|
||||
void renameIniSection(const std::string& filePath, const std::string& currentSectionName, const std::string& newSectionName);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes a section from an INI file.
|
||||
*
|
||||
* This function removes the section with the specified name, including all its associated key-value
|
||||
* pairs, from the INI file located at the specified path. If the section does not exist in the file,
|
||||
* it does nothing.
|
||||
*
|
||||
* @param filePath The path to the INI file.
|
||||
* @param sectionName The name of the section to remove.
|
||||
*/
|
||||
void removeIniSection(const std::string& filePath, const std::string& sectionName);
|
||||
|
||||
|
||||
// Removes a key-value pair from an ini accordingly.
|
||||
void removeIniKey(const std::string& filePath, const std::string& sectionName, const std::string& keyName);
|
||||
|
||||
|
||||
//void saveIniFileData(const std::string& filePath, const std::map<std::string, std::map<std::string, std::string>>& data) {
|
||||
// std::ofstream file(filePath);
|
||||
// if (!file.is_open()) {
|
||||
// // Handle error: could not open file
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (const auto& section : data) {
|
||||
// file << "[" << section.first << "]\n";
|
||||
// for (const auto& kv : section.second) {
|
||||
// file << kv.first << "=" << kv.second << "\n";
|
||||
// }
|
||||
// file << "\n"; // Separate sections with a newline
|
||||
// }
|
||||
//
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
|
||||
void syncIniValue(std::map<std::string, std::map<std::string, std::string>>& packageConfigData,
|
||||
const std::string& packageConfigIniPath,
|
||||
const std::string& optionName,
|
||||
const std::string& key,
|
||||
std::string& value);
|
||||
|
||||
/**
|
||||
* @brief Parses a command line into individual parts, handling quoted strings.
|
||||
*
|
||||
* @param line The command line to parse.
|
||||
* @return A vector of strings containing the parsed command parts.
|
||||
*/
|
||||
std::vector<std::string> parseCommandLine(const std::string& line);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads and parses options from an INI file.
|
||||
*
|
||||
* This function reads and parses options from an INI file, organizing them by section.
|
||||
*
|
||||
* @param packageIniPath The path to the INI file.
|
||||
* @return A vector containing pairs of section names and their associated key-value pairs.
|
||||
*/
|
||||
std::vector<std::pair<std::string, std::vector<std::vector<std::string>>>> loadOptionsFromIni(const std::string& packageIniPath);
|
||||
|
||||
/**
|
||||
* @brief Loads a specific section from an INI file.
|
||||
*
|
||||
* This function reads and parses a specific section from an INI file.
|
||||
*
|
||||
* @param packageIniPath The path to the INI file.
|
||||
* @param sectionName The name of the section to load.
|
||||
* @return A vector of commands within the specified section.
|
||||
*/
|
||||
std::vector<std::vector<std::string>> loadSpecificSectionFromIni(const std::string& packageIniPath, const std::string& sectionName);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Saves INI data structure to a file.
|
||||
*
|
||||
* This function writes a complete INI data structure to the specified file path.
|
||||
* The data structure should be organized as sections containing key-value pairs.
|
||||
*
|
||||
* @param filePath The path to the INI file to write.
|
||||
* @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);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,107 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: json_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file provides functions for working with JSON files in C++ using
|
||||
* the `cJSON` library. It includes a function to read JSON data from a file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
#pragma once
|
||||
#ifndef JSON_FUNCS_HPP
|
||||
#define JSON_FUNCS_HPP
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <cJSON.h>
|
||||
#include "string_funcs.hpp"
|
||||
#include <switch.h>
|
||||
|
||||
namespace ult {
|
||||
// Define json_t as an opaque type to maintain API compatibility
|
||||
typedef void json_t;
|
||||
|
||||
// Define a custom deleter for json_t*
|
||||
struct JsonDeleter {
|
||||
void operator()(json_t* json) const {
|
||||
if (json) {
|
||||
cJSON_Delete(reinterpret_cast<cJSON*>(json));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reads JSON data from a file and returns it as a `json_t` object.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @return A `json_t` object representing the parsed JSON data. Returns `nullptr` on error.
|
||||
*/
|
||||
json_t* readJsonFromFile(const std::string& filePath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses a JSON string into a json_t object.
|
||||
*
|
||||
* This function takes a JSON string as input and parses it into a json_t object using cJSON library's `cJSON_Parse` function.
|
||||
* If parsing fails, it logs the error and returns nullptr.
|
||||
*
|
||||
* @param input The input JSON string to parse.
|
||||
* @return A json_t object representing the parsed JSON, or nullptr if parsing fails.
|
||||
*/
|
||||
json_t* stringToJson(const std::string& input);
|
||||
|
||||
|
||||
// Function to get a string from a JSON object
|
||||
std::string getStringFromJson(const json_t* root, const char* key);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads a JSON file from the specified path and retrieves a string value for a given key.
|
||||
*
|
||||
* This function combines the functionality of loading a JSON file and retrieving a string value associated
|
||||
* with a given key in a single step.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key whose associated string value is to be retrieved.
|
||||
* @return A string containing the value associated with the given key, or an empty string if the key is not found.
|
||||
*/
|
||||
std::string getStringFromJsonFile(const std::string& filePath, const std::string& key);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in a JSON file, creating the file if it doesn't exist.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key to set.
|
||||
* @param value The value to set (auto-detected type).
|
||||
* @param createIfNotExists Whether to create the file if it doesn't exist.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool setJsonValue(const std::string& filePath, const std::string& key, const std::string& value, bool createIfNotExists = false);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Renames a key in a JSON file.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param oldKey The current key name.
|
||||
* @param newKey The new key name.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool renameJsonKey(const std::string& filePath, const std::string& oldKey, const std::string& newKey);
|
||||
|
||||
|
||||
void pushNotificationJson(const std::string& appID, const std::string& text, size_t fontSize=28);
|
||||
}
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: list_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions related
|
||||
* to working with lists and vectors of strings. These functions are used in the
|
||||
* Ultrahand Overlay project to perform various operations on lists, such as
|
||||
* removing entries, filtering, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LIST_FUNCS_HPP
|
||||
#define LIST_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
|
||||
std::vector<std::string> splitIniList(const std::string& value);
|
||||
|
||||
|
||||
std::string joinIniList(const std::vector<std::string>& list);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes entries from a vector of strings that match a specified entry.
|
||||
*
|
||||
* This function removes entries from the `itemsList` vector of strings that match the `entry`.
|
||||
*
|
||||
* @param entry The entry to be compared against the elements in `itemsList`.
|
||||
* @param itemsList The vector of strings from which matching entries will be removed.
|
||||
*/
|
||||
void removeEntryFromList(const std::string& entry, std::vector<std::string>& itemsList);
|
||||
|
||||
/**
|
||||
* @brief Filters a list of strings based on a specified filter list.
|
||||
*
|
||||
* This function filters a list of strings (`itemsList`) by removing entries that match any
|
||||
* of the criteria specified in the `filterList`. It uses the `removeEntryFromList` function
|
||||
* to perform the removal.
|
||||
*
|
||||
* @param filterList The list of entries to filter by. Entries in `itemsList` matching any entry in this list will be removed.
|
||||
* @param itemsList The list of stringsto be filtered.
|
||||
*/
|
||||
void filterItemsList(const std::vector<std::string>& filterList, std::vector<std::string>& itemsList);
|
||||
|
||||
|
||||
// Function to read file into a vector of strings
|
||||
std::vector<std::string> readListFromFile(const std::string& filePath, size_t maxLines=0);
|
||||
|
||||
|
||||
// Function to get an entry from the list based on the index
|
||||
std::string getEntryFromListFile(const std::string& listPath, size_t listIndex);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a vector of strings using a delimiter.
|
||||
*
|
||||
* This function splits the input string into multiple strings using the specified delimiter.
|
||||
*
|
||||
* @param str The input string to split.
|
||||
* @return A vector of strings containing the split values.
|
||||
*/
|
||||
std::vector<std::string> stringToList(const std::string& str);
|
||||
|
||||
|
||||
// Function to read file into a set of strings
|
||||
std::unordered_set<std::string> readSetFromFile(const std::string& filePath);
|
||||
|
||||
|
||||
// Function to write a set to a file
|
||||
void writeSetToFile(const std::unordered_set<std::string>& fileSet, const std::string& filePath);
|
||||
|
||||
|
||||
// Function to compare two file lists and save duplicates to an output file
|
||||
void compareFilesLists(const std::string& txtFilePath1, const std::string& txtFilePath2, const std::string& outputTxtFilePath);
|
||||
|
||||
|
||||
// Helper function to read a text file and process each line with a callback
|
||||
//void processFileLines(const std::string& filePath, const std::function<void(const std::string&)>& callback);
|
||||
|
||||
|
||||
void compareWildcardFilesLists(const std::string& wildcardPatternFilePath, const std::string& txtFilePath, const std::string& outputTxtFilePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,121 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: mod_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions for IPS
|
||||
* binary generations. These functions are used in the Ultrahand Overlay project
|
||||
* to convert `.pchtxt` mods into `.ips` binaries.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef MOD_FUNCS_HPP
|
||||
#define MOD_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
//#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include "debug_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "hex_funcs.hpp"
|
||||
#include <iomanip> // Include this header for std::setw and std::setfill
|
||||
|
||||
namespace ult {
|
||||
inline constexpr const char* IPS32_HEAD_MAGIC = "IPS32";
|
||||
inline constexpr const char* IPS32_FOOT_MAGIC = "EEOF";
|
||||
|
||||
//const std::string CHEAT_HEADER = "// auto generated by pchtxt2cheat\n\n";
|
||||
//extern const std::string CHEAT_TYPE;
|
||||
//extern const std::string CHEAT_EXT;
|
||||
//extern const std::string CHEAT_ENCODING;
|
||||
|
||||
/**
|
||||
* @brief Checks if a cheat already exists in the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to check.
|
||||
* @return True if the cheat exists, otherwise false.
|
||||
*/
|
||||
bool cheatExists(const std::string &cheatFilePath, const std::string &newCheat);
|
||||
|
||||
/**
|
||||
* @brief Appends a new cheat to the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to append.
|
||||
*/
|
||||
void appendCheatToFile(const std::string &cheatFilePath, const std::string &newCheat);
|
||||
|
||||
/**
|
||||
* @brief Extracts the cheat name from the given file path.
|
||||
* @param filePath The full file path.
|
||||
* @return The extracted cheat name.
|
||||
*/
|
||||
std::string extractCheatName(const std::string &filePath);
|
||||
|
||||
// Helper function to determine if a string is a valid title ID
|
||||
bool isValidTitleID(const std::string &str);
|
||||
|
||||
// Function to find the title ID in the text, avoiding the @nsobid- line
|
||||
std::string findTitleID(const std::string &text);
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to a cheat file.
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param cheatName The name of the cheat.
|
||||
* @param outCheatPath The file path for the output cheat file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2cheat(const std::string &pchtxtPath, std::string cheatName = "", std::string outCheatPath = "");
|
||||
|
||||
// Corrected helper function to convert values to big-endian format
|
||||
//uint32_t toBigEndian(uint32_t value);
|
||||
//
|
||||
//uint16_t toBigEndian(uint16_t value);
|
||||
|
||||
// Corrected helper function to convert values to big-endian format
|
||||
inline uint32_t toBigEndian(uint32_t value) {
|
||||
return ((value & 0x000000FF) << 24) |
|
||||
((value & 0x0000FF00) << 8) |
|
||||
((value & 0x00FF0000) >> 8) |
|
||||
((value & 0xFF000000) >> 24);
|
||||
}
|
||||
|
||||
inline uint16_t toBigEndian(uint16_t value) {
|
||||
return ((value & 0x00FF) << 8) |
|
||||
((value & 0xFF00) >> 8);
|
||||
}
|
||||
|
||||
// Helper function to convert a vector of bytes to a hex string for logging
|
||||
|
||||
//std::string hexToString(const std::vector<uint8_t>& bytes);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to an IPS file using fstream.
|
||||
*
|
||||
* This function reads the contents of a .pchtxt file, extracts the address-value pairs,
|
||||
* and generates an IPS file with the provided output folder.
|
||||
*
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param outputFolder The folder path for the output IPS file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2ips(const std::string& pchtxtPath, const std::string& outputFolder);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,279 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: path_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions related
|
||||
* to file and directory path manipulation. These functions are used in the
|
||||
* Ultrahand Overlay project to handle file operations, such as creating
|
||||
* directories, moving files, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PATH_FUNCS_HPP
|
||||
#define PATH_FUNCS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include "global_vars.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace ult {
|
||||
extern std::atomic<bool> abortFileOp;
|
||||
|
||||
extern size_t COPY_BUFFER_SIZE; // Made const for thread safety
|
||||
extern std::atomic<int> copyPercentage;
|
||||
|
||||
// Mutex for thread-safe logging operations
|
||||
extern std::mutex logMutex;
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a directory.
|
||||
*
|
||||
* This function checks if the specified path points to a directory.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is a directory, false otherwise.
|
||||
*/
|
||||
bool isDirectory(const std::string& path);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a file.
|
||||
*
|
||||
* This function checks if the specified path points to a file.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is a file, false otherwise.
|
||||
*/
|
||||
bool isFile(const std::string& path);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if a path points to a file or directory.
|
||||
*
|
||||
* This function checks if the specified path points to either a file or a directory.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path points to a file or directory, false otherwise.
|
||||
*/
|
||||
bool isFileOrDirectory(const std::string& path);
|
||||
|
||||
|
||||
bool isDirectoryEmpty(const std::string& dirPath);
|
||||
|
||||
/**
|
||||
* @brief Creates a single directory if it doesn't exist.
|
||||
*
|
||||
* This function checks if the specified directory exists, and if not, it creates the directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to be created.
|
||||
*/
|
||||
void createSingleDirectory(const std::string& directoryPath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a directory and its parent directories if they don't exist.
|
||||
*
|
||||
* This function creates a directory specified by `directoryPath` and also creates any parent directories
|
||||
* if they don't exist. It handles nested directory creation.
|
||||
*
|
||||
* @param directoryPath The path of the directory to be created.
|
||||
*/
|
||||
void createDirectory(const std::string& directoryPath);
|
||||
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
void writeLog(FILE* logFile, const std::string& line);
|
||||
#else
|
||||
void writeLog(std::ofstream& logFile, const std::string& line);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Creates a text file with the specified content.
|
||||
*
|
||||
* This function creates a text file specified by `filePath` and writes the given `content` to the file.
|
||||
*
|
||||
* @param filePath The path of the text file to be created.
|
||||
* @param content The content to be written to the text file.
|
||||
*/
|
||||
void createTextFile(const std::string& filePath, const std::string& content);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes a file or directory.
|
||||
*
|
||||
* This function deletes the file or directory specified by `path`. It can delete both files and directories.
|
||||
*
|
||||
* @param path The path of the file or directory to be deleted.
|
||||
*/
|
||||
void deleteFileOrDirectory(const std::string& pathToDelete, const std::string& logSource = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes files or directories that match a specified pattern.
|
||||
*
|
||||
* This function deletes files or directories specified by `pathPattern` by matching against a pattern.
|
||||
* It identifies files or directories that match the pattern and deletes them.
|
||||
*
|
||||
* @param pathPattern The pattern used to match and delete files or directories.
|
||||
*/
|
||||
void deleteFileOrDirectoryByPattern(const std::string& pathPattern, const std::string& logSource = "");
|
||||
|
||||
|
||||
void moveDirectory(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
bool moveFile(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Moves a file or directory to a new destination.
|
||||
*
|
||||
* This function moves a file or directory from the `sourcePath` to the `destinationPath`. It can handle both
|
||||
* files and directories and ensures that the destination directory exists before moving.
|
||||
*
|
||||
* @param sourcePath The path of the source file or directory.
|
||||
* @param destinationPath The path of the destination where the file or directory will be moved.
|
||||
*/
|
||||
void moveFileOrDirectory(const std::string& sourcePath, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Moves files or directories matching a specified pattern to a destination directory.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
void moveFilesOrDirectoriesByPattern(const std::string& sourcePathPattern, const std::string& destinationPath,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies a single file from the source path to the destination path.
|
||||
*
|
||||
* This function copies a single file specified by `fromFile` to the location specified by `toFile`.
|
||||
*
|
||||
* @param fromFile The path of the source file to be copied.
|
||||
* @param toFile The path of the destination where the file will be copied.
|
||||
*/
|
||||
void copySingleFile(const std::string& fromFile, const std::string& toFile, long long& totalBytesCopied, const long long totalSize,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Recursively calculates the total size of the given file or directory.
|
||||
* @param path The path to the file or directory.
|
||||
* @return The total size in bytes of all files within the directory or the size of a file.
|
||||
*/
|
||||
long long getTotalSize(const std::string& path);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies a file or directory from the source path to the destination path.
|
||||
*
|
||||
* This function copies a file or directory specified by `fromFileOrDirectory` to the location specified by `toFileOrDirectory`.
|
||||
* If the source is a regular file, it copies the file to the destination. If the source is a directory, it recursively copies
|
||||
* the entire directory and its contents to the destination.
|
||||
*
|
||||
* @param fromPath The path of the source file or directory to be copied.
|
||||
* @param toPath The path of the destination where the file or directory will be copied.
|
||||
*/
|
||||
void copyFileOrDirectory(const std::string& fromPath, const std::string& toPath, long long* totalBytesCopied = nullptr, long long totalSize = 0,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies files or directories matching a specified pattern to a destination directory.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
void copyFileOrDirectoryByPattern(const std::string& sourcePathPattern, const std::string& toDirectory,
|
||||
const std::string& logSource = "", const std::string& logDestination = "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mirrors the deletion of files from a source directory to a target directory.
|
||||
*
|
||||
* This function mirrors the deletion of files from a `sourcePath` directory to a `targetPath` directory.
|
||||
* It deletes corresponding files in the `targetPath` that match the source directory structure.
|
||||
*
|
||||
* @param sourcePath The path of the source directory.
|
||||
* @param targetPath The path of the target directory where files will be mirrored and deleted.
|
||||
* Default is "sdmc:/". You can specify a different target path if needed.
|
||||
*/
|
||||
void mirrorFiles(const std::string& sourcePath, const std::string targetPath, const std::string mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief For each match of the wildcard pattern, creates an empty text file
|
||||
* named basename.txt inside the output directory.
|
||||
* Uses FILE* if !USING_FSTREAM_DIRECTIVE is defined, otherwise uses std::ofstream.
|
||||
*
|
||||
* @param wildcardPattern A path with a wildcard, such as /some/path/[*].
|
||||
* Each match results in a file named after the basename.
|
||||
* @param outputDir Directory where the output files will be written.
|
||||
* Created if it doesn't already exist.
|
||||
*/
|
||||
void createFlagFiles(const std::string& wildcardPattern, const std::string& outputDir);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes all files starting with "._" from a directory and its subdirectories.
|
||||
*
|
||||
* This function recursively scans the specified directory and removes all files
|
||||
* whose names start with "._" (commonly macOS metadata files). It processes
|
||||
* all subdirectories recursively.
|
||||
*
|
||||
* @param sourcePath The path of the directory to clean.
|
||||
*/
|
||||
void dotCleanDirectory(const std::string& sourcePath);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,274 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: string_funcs.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This header file contains function declarations and utility functions for string
|
||||
* manipulation. These functions are used in the Ultrahand Overlay project to
|
||||
* perform operations like trimming whitespaces, removing quotes, replacing
|
||||
* multiple slashes, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef STRING_FUNCS_HPP
|
||||
#define STRING_FUNCS_HPP
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
//#include <jansson.h>
|
||||
//#include <regex>
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "global_vars.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
extern std::string to_string(int value);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief A lightweight string stream class that mimics basic functionality of std::istringstream.
|
||||
*/
|
||||
class StringStream {
|
||||
public:
|
||||
StringStream() : position(0), hexMode(false), validState(true) {}
|
||||
|
||||
|
||||
// Add this constructor to accept a string
|
||||
StringStream(const std::string& input) : data(input), position(0), hexMode(false) {}
|
||||
|
||||
// Set hex mode
|
||||
StringStream& hex() {
|
||||
hexMode = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Reset hex mode
|
||||
StringStream& resetHex() {
|
||||
hexMode = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Mimics std::getline() with a delimiter
|
||||
bool getline(std::string& output, char delimiter);
|
||||
|
||||
// Mimics operator >> to split by whitespace
|
||||
StringStream& operator>>(std::string& output);
|
||||
|
||||
// Overload the << operator to insert strings and integers
|
||||
StringStream& operator<<(const std::string& input);
|
||||
StringStream& operator<<(const char* input);
|
||||
StringStream& operator<<(char input);
|
||||
StringStream& operator<<(int input); // Handles int insertion with hex support
|
||||
StringStream& operator<<(long long input); // for long long
|
||||
|
||||
// Conversion to bool for checking stream state (success/failure)
|
||||
explicit operator bool() const {
|
||||
return validState;
|
||||
}
|
||||
|
||||
std::string str() const;
|
||||
void clear() { data.clear(); position = 0; } // Add clear function
|
||||
|
||||
private:
|
||||
std::string data;
|
||||
size_t position;
|
||||
bool hexMode;
|
||||
bool validState; // Track if the stream is in a valid state
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Trims leading and trailing whitespaces from a string.
|
||||
*
|
||||
* This function removes leading and trailing whitespaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to trim.
|
||||
* @return The trimmed string.
|
||||
*/
|
||||
void trim(std::string& str);
|
||||
|
||||
|
||||
|
||||
// Function to trim newline characters from the end of a string
|
||||
void trimNewline(std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes all white spaces from a string.
|
||||
*
|
||||
* This function removes all white spaces, including spaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to remove white spaces from.
|
||||
* @return The string with white spaces removed.
|
||||
*/
|
||||
std::string removeWhiteSpaces(const std::string& str);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes quotes from a string.
|
||||
*
|
||||
* This function removes single and double quotes from the beginning and end of the input string.
|
||||
*
|
||||
* @param str The input string to remove quotes from.
|
||||
* @return The string with quotes removed.
|
||||
*/
|
||||
void removeQuotes(std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Replaces multiple consecutive slashes with a single slash in a string.
|
||||
*
|
||||
* This function replaces sequences of two or more consecutive slashes with a single slash in the input string.
|
||||
*
|
||||
* @param input The input string to process.
|
||||
* @return The string with multiple slashes replaced.
|
||||
*/
|
||||
std::string replaceMultipleSlashes(const std::string& input);
|
||||
|
||||
|
||||
void resolveDirectoryTraversal(std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a path string by replacing multiple slashes and adding "sdmc:" prefix.
|
||||
*
|
||||
* This function preprocesses a path string by removing multiple consecutive slashes,
|
||||
* adding the "sdmc:" prefix if not present, and modifying the input string in place.
|
||||
*
|
||||
* @param path The input path string to preprocess, passed by reference.
|
||||
*/
|
||||
void preprocessPath(std::string& path, const std::string& packagePath = "");
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a URL string by adding "https://" prefix.
|
||||
*
|
||||
* This function preprocesses a URL string by adding the "https://" prefix if not already present.
|
||||
*
|
||||
* @param path The input URL string to preprocess, passed by reference and modified in-place.
|
||||
*/
|
||||
void preprocessUrl(std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Drops the file extension from a filename.
|
||||
*
|
||||
* This function removes the file extension (characters after the last dot) from the input filename string.
|
||||
*
|
||||
* @param filename The input filename from which to drop the extension, passed by reference and modified in-place.
|
||||
*/
|
||||
void dropExtension(std::string& filename);
|
||||
|
||||
/**
|
||||
* @brief Checks if a string starts with a given prefix.
|
||||
*
|
||||
* This function checks if the input string starts with the specified prefix.
|
||||
*
|
||||
* @param str The input string to check.
|
||||
* @param prefix The prefix to check for.
|
||||
* @return True if the string starts with the prefix, false otherwise.
|
||||
*/
|
||||
bool startsWith(const std::string& str, const std::string& prefix);
|
||||
|
||||
|
||||
// Helper function to check if a string is a valid integer
|
||||
bool isValidNumber(const std::string& str);
|
||||
|
||||
// For properly handling placeholder replacements
|
||||
std::string returnOrNull(const std::string& value);
|
||||
|
||||
|
||||
// Function to slice a string from start to end index
|
||||
std::string sliceString(const std::string& str, size_t start, size_t end);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a string to lowercase.
|
||||
*
|
||||
* This function takes a string as input and returns a lowercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to lowercase.
|
||||
* @return The lowercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToLowercase(const std::string& str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a string to uppercase.
|
||||
*
|
||||
* This function takes a string as input and returns an uppercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to uppercase.
|
||||
* @return The uppercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToUppercase(const std::string& str);
|
||||
|
||||
/**
|
||||
* @brief Formats a priority string to a desired width.
|
||||
*
|
||||
* This function takes a priority string and formats it to a specified desired width by padding with '0's if it's shorter
|
||||
* or truncating with '9's if it's longer.
|
||||
*
|
||||
* @param priority The input priority string to format.
|
||||
* @param desiredWidth The desired width of the formatted string (default is 4).
|
||||
* @return A formatted priority string.
|
||||
*/
|
||||
std::string formatPriorityString(const std::string& priority, int desiredWidth = 4);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes the part of the string after the first occurrence of '?' character.
|
||||
*
|
||||
* This function takes a string and removes the portion of the string that appears after
|
||||
* the first '?' character, if found. If no '?' character is present, the string remains unchanged.
|
||||
*
|
||||
* @param input The input string from which to remove the tag, passed by reference and modified in-place.
|
||||
*/
|
||||
void removeTag(std::string &input);
|
||||
|
||||
std::string getFirstLongEntry(const std::string& input, size_t minLength = 8);
|
||||
|
||||
|
||||
// This will take a string like "v1.3.5-abasdfasdfa" and output "1.3.5". string could also look like "test-1.3.5-1" or "v1.3.5" and we will only want "1.3.5"
|
||||
std::string cleanVersionLabel(const std::string& input);
|
||||
|
||||
|
||||
std::string extractTitle(const std::string& input);
|
||||
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, const std::string& delimiter);
|
||||
|
||||
|
||||
// Function to split a string by a delimiter and return a specific index
|
||||
std::string splitStringAtIndex(const std::string& str, const std::string& delimiter, size_t index);
|
||||
|
||||
|
||||
std::string customAlign(int number);
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
std::string inputExists(const std::string& input);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,726 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: tsl_utils.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* 'tsl_utils.hpp' is a central utility header for the Ultrahand Overlay project,
|
||||
* containing a variety of functions and definitions related to system status,
|
||||
* input handling, and application-specific behavior on the Nintendo Switch.
|
||||
* This header provides essential utilities for interacting with the system,
|
||||
* managing key input, and enhancing overlay functionality.
|
||||
*
|
||||
* The utilities defined here are designed to operate independently, facilitating
|
||||
* robust system interaction capabilities required for custom overlays.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef TSL_UTILS_HPP
|
||||
#define TSL_UTILS_HPP
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE // For not using fstream (needs implementing)
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include <ultra.hpp>
|
||||
#include <switch.h>
|
||||
#include <arm_neon.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
//#include <math.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cwctype>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
//#include <chrono>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#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
|
||||
|
||||
struct OverlayCombo {
|
||||
std::string path; // full overlay path
|
||||
std::string launchArg; // empty = use per-overlay launch_args key, otherwise a “mode” arg
|
||||
};
|
||||
|
||||
struct SwapDepth {
|
||||
u32 value;
|
||||
explicit SwapDepth(u32 v) : value(v) {}
|
||||
};
|
||||
|
||||
namespace ult {
|
||||
extern bool correctFrameSize; // for detecting the correct Overlay display size
|
||||
|
||||
extern u16 DefaultFramebufferWidth; ///< Width of the framebuffer
|
||||
extern u16 DefaultFramebufferHeight; ///< Height of the framebuffer
|
||||
|
||||
extern std::unordered_map<std::string, std::string> translationCache;
|
||||
|
||||
extern std::unordered_map<u64, OverlayCombo> g_entryCombos;
|
||||
extern std::atomic<bool> launchingOverlay;
|
||||
extern std::atomic<bool> settingsInitialized;
|
||||
extern std::atomic<bool> currentForeground;
|
||||
//extern std::mutex simulatedNextPageMutex;
|
||||
|
||||
//void loadOverlayKeyCombos();
|
||||
//std::string getOverlayForKeyCombo(u64 keys);
|
||||
|
||||
bool readFileContent(const std::string& filePath, std::string& content);
|
||||
void parseJsonContent(const std::string& content, std::unordered_map<std::string, std::string>& result);
|
||||
bool parseJsonToMap(const std::string& filePath, std::unordered_map<std::string, std::string>& result);
|
||||
|
||||
bool loadTranslationsFromJSON(const std::string& filePath);
|
||||
|
||||
extern u16 activeHeaderHeight;
|
||||
|
||||
bool consoleIsDocked();
|
||||
|
||||
std::string getBuildIdAsString();
|
||||
|
||||
std::string getTitleIdAsString();
|
||||
|
||||
extern std::string lastTitleID;
|
||||
extern std::atomic<bool> resetForegroundCheck;
|
||||
|
||||
|
||||
//extern bool isLauncher;
|
||||
extern std::atomic<bool> internalTouchReleased;
|
||||
extern u32 layerEdge;
|
||||
extern bool useRightAlignment;
|
||||
extern bool useSwipeToOpen;
|
||||
extern bool useLaunchCombos;
|
||||
extern bool useNotifications;
|
||||
extern bool useSoundEffects;
|
||||
extern bool useHapticFeedback;
|
||||
extern bool usePageSwap;
|
||||
extern std::atomic<bool> noClickableItems;
|
||||
|
||||
extern bool useDynamicLogo;
|
||||
extern bool useSelectionBG;
|
||||
extern bool useSelectionText;
|
||||
extern bool useSelectionValue;
|
||||
|
||||
|
||||
|
||||
// Define the duration boundaries (for smooth scrolling)
|
||||
//extern const std::chrono::milliseconds initialInterval; // Example initial interval
|
||||
//extern const std::chrono::milliseconds shortInterval; // Short interval after long hold
|
||||
//extern const std::chrono::milliseconds transitionPoint; // Point at which the shortest interval is reached
|
||||
|
||||
|
||||
|
||||
//constexpr std::chrono::milliseconds initialInterval = std::chrono::milliseconds(67); // Example initial interval
|
||||
//constexpr std::chrono::milliseconds shortInterval = std::chrono::milliseconds(10); // Short interval after long hold
|
||||
//constexpr std::chrono::milliseconds transitionPoint = std::chrono::milliseconds(2000); // Point at which the shortest interval is reached
|
||||
|
||||
// Function to interpolate between two durations
|
||||
//std::chrono::milliseconds interpolateDuration(std::chrono::milliseconds start, std::chrono::milliseconds end, float t);
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
extern std::atomic<bool> overlayLaunchRequested;
|
||||
extern std::string requestedOverlayPath;
|
||||
extern std::string requestedOverlayArgs;
|
||||
extern std::mutex overlayLaunchMutex;
|
||||
#endif
|
||||
|
||||
|
||||
//#include <filesystem> // Comment out filesystem
|
||||
|
||||
// CUSTOM SECTION START
|
||||
//extern float backWidth, selectWidth, nextPageWidth;
|
||||
extern std::atomic<float> backWidth;
|
||||
extern std::atomic<float> selectWidth;
|
||||
extern std::atomic<float> nextPageWidth;
|
||||
extern std::atomic<bool> inMainMenu;
|
||||
extern std::atomic<bool> inOverlaysPage;
|
||||
extern std::atomic<bool> inPackagesPage;
|
||||
|
||||
extern bool firstBoot; // for detecting first boot
|
||||
|
||||
//static std::unordered_map<std::string, std::string> hexSumCache;
|
||||
|
||||
// Define an atomic bool for interpreter completion
|
||||
extern std::atomic<bool> threadFailure;
|
||||
extern std::atomic<bool> runningInterpreter;
|
||||
extern std::atomic<bool> shakingProgress;
|
||||
|
||||
extern std::atomic<bool> isHidden;
|
||||
extern std::atomic<bool> externalAbortCommands;
|
||||
|
||||
//bool progressAnimation = false;
|
||||
extern bool disableTransparency;
|
||||
//bool useCustomWallpaper = false;
|
||||
extern bool useMemoryExpansion;
|
||||
extern bool useOpaqueScreenshots;
|
||||
|
||||
extern std::atomic<bool> onTrackBar;
|
||||
extern std::atomic<bool> allowSlide;
|
||||
extern std::atomic<bool> unlockedSlide;
|
||||
|
||||
void atomicToggle(std::atomic<bool>& b);
|
||||
|
||||
/**
|
||||
* @brief Shutdown modes for the Ultrahand-Overlay project.
|
||||
*
|
||||
* These macros define the shutdown modes used in the Ultrahand-Overlay project:
|
||||
* - `SpsmShutdownMode_Normal`: Normal shutdown mode.
|
||||
* - `SpsmShutdownMode_Reboot`: Reboot mode.
|
||||
*/
|
||||
#define SpsmShutdownMode_Normal 0
|
||||
#define SpsmShutdownMode_Reboot 1
|
||||
|
||||
/**
|
||||
* @brief Key mapping macros for button keys.
|
||||
*
|
||||
* These macros define button keys for the Ultrahand-Overlay project to simplify key mappings.
|
||||
* For example, `KEY_A` represents the `HidNpadButton_A` key.
|
||||
*/
|
||||
#define KEY_A HidNpadButton_A
|
||||
#define KEY_B HidNpadButton_B
|
||||
#define KEY_X HidNpadButton_X
|
||||
#define KEY_Y HidNpadButton_Y
|
||||
#define KEY_L HidNpadButton_L
|
||||
#define KEY_R HidNpadButton_R
|
||||
#define KEY_ZL HidNpadButton_ZL
|
||||
#define KEY_ZR HidNpadButton_ZR
|
||||
#define KEY_PLUS HidNpadButton_Plus
|
||||
#define KEY_MINUS HidNpadButton_Minus
|
||||
#define KEY_DUP HidNpadButton_Up
|
||||
#define KEY_DDOWN HidNpadButton_Down
|
||||
#define KEY_DLEFT HidNpadButton_Left
|
||||
#define KEY_DRIGHT HidNpadButton_Right
|
||||
#define KEY_SL HidNpadButton_AnySL
|
||||
#define KEY_SR HidNpadButton_AnySR
|
||||
#define KEY_LSTICK HidNpadButton_StickL
|
||||
#define KEY_RSTICK HidNpadButton_StickR
|
||||
#define KEY_UP HidNpadButton_AnyUp
|
||||
#define KEY_DOWN HidNpadButton_AnyDown
|
||||
#define KEY_LEFT HidNpadButton_AnyLeft
|
||||
#define KEY_RIGHT HidNpadButton_AnyRight
|
||||
|
||||
#define SCRIPT_KEY HidNpadButton_Minus
|
||||
#define SYSTEM_SETTINGS_KEY HidNpadButton_Plus
|
||||
#define SETTINGS_KEY HidNpadButton_Y
|
||||
#define STAR_KEY HidNpadButton_X
|
||||
|
||||
|
||||
// Define a mask with all possible key flags
|
||||
#define ALL_KEYS_MASK (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_DUP | KEY_DDOWN | KEY_DLEFT | KEY_DRIGHT | KEY_L | KEY_R | KEY_ZL | KEY_ZR | KEY_SL | KEY_SR | KEY_LSTICK | KEY_RSTICK | KEY_PLUS | KEY_MINUS)
|
||||
|
||||
|
||||
extern bool updateMenuCombos;
|
||||
|
||||
/**
|
||||
* @brief Ultrahand-Overlay Input Macros
|
||||
*
|
||||
* This block of code defines macros for handling input in the Ultrahand-Overlay project.
|
||||
* These macros simplify the mapping of input events to corresponding button keys and
|
||||
* provide aliases for touch and joystick positions.
|
||||
*
|
||||
* The macros included in this block are:
|
||||
*
|
||||
* - `touchPosition`: An alias for a constant `HidTouchState` pointer.
|
||||
* - `touchInput`: An alias for `&touchPos`, representing touch input.
|
||||
* - `JoystickPosition`: An alias for `HidAnalogStickState`, representing joystick input.
|
||||
*
|
||||
* These macros are utilized within the Ultrahand-Overlay project to manage and interpret
|
||||
* user input, including touch and joystick events.
|
||||
*/
|
||||
#define touchPosition const HidTouchState
|
||||
#define touchInput &touchPos
|
||||
#define JoystickPosition HidAnalogStickState
|
||||
|
||||
//void convertComboToUnicode(std::string& combo);
|
||||
|
||||
/**
|
||||
* @brief Combo key mapping
|
||||
*/
|
||||
struct KeyInfo {
|
||||
u64 key;
|
||||
const char* name;
|
||||
const char* glyph;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Combo key mappings
|
||||
*
|
||||
* Ordered as they should be displayed
|
||||
*/
|
||||
extern std::array<KeyInfo, 18> KEYS_INFO;
|
||||
|
||||
std::unordered_map<std::string, std::string> createButtonCharMap();
|
||||
|
||||
extern std::unordered_map<std::string, std::string> buttonCharMap;
|
||||
|
||||
|
||||
void convertComboToUnicode(std::string& combo);
|
||||
|
||||
|
||||
// English string definitions
|
||||
|
||||
extern const std::string whiteColor;
|
||||
extern const std::string blackColor;
|
||||
extern const std::string greyColor;
|
||||
|
||||
extern std::atomic<bool> languageWasChanged;
|
||||
|
||||
inline constexpr double _M_PI = 3.14159265358979323846; // For double precision
|
||||
inline constexpr double RAD_TO_DEG = 180.0f / _M_PI;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
extern std::string ENGLISH;
|
||||
extern std::string SPANISH;
|
||||
extern std::string FRENCH;
|
||||
extern std::string GERMAN;
|
||||
extern std::string JAPANESE;
|
||||
extern std::string KOREAN;
|
||||
extern std::string ITALIAN;
|
||||
extern std::string DUTCH;
|
||||
extern std::string PORTUGUESE;
|
||||
extern std::string RUSSIAN;
|
||||
extern std::string UKRAINIAN;
|
||||
extern std::string POLISH;
|
||||
extern std::string SIMPLIFIED_CHINESE;
|
||||
extern std::string TRADITIONAL_CHINESE;
|
||||
|
||||
extern std::string OVERLAYS; //defined in libTesla now
|
||||
extern std::string OVERLAYS_ABBR;
|
||||
extern std::string OVERLAY;
|
||||
extern std::string HIDDEN_OVERLAYS;
|
||||
extern std::string PACKAGES; //defined in libTesla now
|
||||
extern std::string PACKAGE;
|
||||
extern std::string HIDDEN_PACKAGES;
|
||||
extern std::string HIDDEN;
|
||||
extern std::string HIDE_OVERLAY;
|
||||
extern std::string HIDE_PACKAGE;
|
||||
extern std::string LAUNCH_ARGUMENTS;
|
||||
extern std::string QUICK_LAUNCH;
|
||||
extern std::string BOOT_COMMANDS;
|
||||
extern std::string EXIT_COMMANDS;
|
||||
extern std::string ERROR_LOGGING;
|
||||
extern std::string COMMANDS;
|
||||
extern std::string SETTINGS;
|
||||
extern std::string FAVORITE;
|
||||
extern std::string MAIN_SETTINGS;
|
||||
extern std::string UI_SETTINGS;
|
||||
|
||||
extern std::string WIDGET;
|
||||
extern std::string WIDGET_ITEMS;
|
||||
extern std::string WIDGET_SETTINGS;
|
||||
extern std::string CLOCK;
|
||||
extern std::string BATTERY;
|
||||
extern std::string SOC_TEMPERATURE;
|
||||
extern std::string PCB_TEMPERATURE;
|
||||
extern std::string BACKDROP;
|
||||
extern std::string DYNAMIC_COLORS;
|
||||
extern std::string CENTER_ALIGNMENT;
|
||||
extern std::string EXTENDED_BACKDROP;
|
||||
extern std::string MISCELLANEOUS;
|
||||
//extern std::string MENU_ITEMS;
|
||||
extern std::string MENU_SETTINGS;
|
||||
extern std::string USER_GUIDE;
|
||||
extern std::string SHOW_HIDDEN;
|
||||
extern std::string SHOW_DELETE;
|
||||
extern std::string PAGE_SWAP;
|
||||
extern std::string RIGHT_SIDE_MODE;
|
||||
extern std::string OVERLAY_VERSIONS;
|
||||
extern std::string PACKAGE_VERSIONS;
|
||||
extern std::string CLEAN_VERSIONS;
|
||||
//extern std::string VERSION_LABELS;
|
||||
extern std::string KEY_COMBO;
|
||||
extern std::string MODE;
|
||||
extern std::string MODES;
|
||||
extern std::string LANGUAGE;
|
||||
extern std::string OVERLAY_INFO;
|
||||
extern std::string SOFTWARE_UPDATE;
|
||||
extern std::string UPDATE_ULTRAHAND;
|
||||
extern std::string UPDATE_LANGUAGES;
|
||||
extern std::string SYSTEM;
|
||||
extern std::string DEVICE_INFO;
|
||||
extern std::string FIRMWARE;
|
||||
extern std::string BOOTLOADER;
|
||||
extern std::string HARDWARE;
|
||||
extern std::string MEMORY;
|
||||
extern std::string VENDOR;
|
||||
extern std::string MODEL;
|
||||
extern std::string STORAGE;
|
||||
extern std::string NOTICE;
|
||||
extern std::string UTILIZES;
|
||||
|
||||
extern std::string MEMORY_EXPANSION;
|
||||
extern std::string REBOOT_REQUIRED;
|
||||
extern std::string LOCAL_IP;
|
||||
extern std::string WALLPAPER;
|
||||
extern std::string THEME;
|
||||
extern std::string DEFAULT;
|
||||
extern std::string ROOT_PACKAGE;
|
||||
extern std::string SORT_PRIORITY;
|
||||
extern std::string OPTIONS;
|
||||
extern std::string FAILED_TO_OPEN;
|
||||
|
||||
extern std::string LAUNCH_COMBOS;
|
||||
extern std::string NOTIFICATIONS;
|
||||
extern std::string SOUND_EFFECTS;
|
||||
extern std::string HAPTIC_FEEDBACK;
|
||||
extern std::string OPAQUE_SCREENSHOTS;
|
||||
|
||||
extern std::string PACKAGE_INFO;
|
||||
extern std::string _TITLE;
|
||||
extern std::string _VERSION;
|
||||
extern std::string _CREATOR;
|
||||
extern std::string _ABOUT;
|
||||
extern std::string _CREDITS;
|
||||
|
||||
extern std::string USERGUIDE_OFFSET;
|
||||
extern std::string SETTINGS_MENU;
|
||||
extern std::string SCRIPT_OVERLAY;
|
||||
extern std::string STAR_FAVORITE;
|
||||
extern std::string APP_SETTINGS;
|
||||
extern std::string ON_MAIN_MENU;
|
||||
extern std::string ON_A_COMMAND;
|
||||
extern std::string ON_OVERLAY_PACKAGE;
|
||||
extern std::string FEATURES;
|
||||
extern std::string SWIPE_TO_OPEN;
|
||||
|
||||
extern std::string THEME_SETTINGS;
|
||||
extern std::string DYNAMIC_LOGO;
|
||||
extern std::string SELECTION_BACKGROUND;
|
||||
extern std::string SELECTION_TEXT;
|
||||
extern std::string SELECTION_VALUE;
|
||||
extern std::string LIBULTRAHAND_TITLES;
|
||||
extern std::string LIBULTRAHAND_VERSIONS;
|
||||
extern std::string PACKAGE_TITLES;
|
||||
|
||||
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 SELECTION_IS_EMPTY;
|
||||
|
||||
//extern std::string PACKAGE_VERSIONS;
|
||||
//extern std::string PROGRESS_ANIMATION;
|
||||
|
||||
extern std::string REBOOT_TO;
|
||||
extern std::string REBOOT;
|
||||
extern std::string SHUTDOWN;
|
||||
extern std::string BOOT_ENTRY;
|
||||
#endif
|
||||
|
||||
extern std::string FREE;
|
||||
|
||||
extern std::string DEFAULT_CHAR_WIDTH;
|
||||
extern std::string UNAVAILABLE_SELECTION;
|
||||
|
||||
extern std::string ON;
|
||||
extern std::string OFF;
|
||||
|
||||
extern std::string OK;
|
||||
extern std::string BACK;
|
||||
extern std::string HIDE;
|
||||
extern std::string CANCEL;
|
||||
|
||||
extern std::string GAP_1;
|
||||
extern std::string GAP_2;
|
||||
extern std::atomic<float> halfGap;
|
||||
|
||||
//extern std::string EMPTY;
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
extern std::string SUNDAY;
|
||||
extern std::string MONDAY;
|
||||
extern std::string TUESDAY;
|
||||
extern std::string WEDNESDAY;
|
||||
extern std::string THURSDAY;
|
||||
extern std::string FRIDAY;
|
||||
extern std::string SATURDAY;
|
||||
|
||||
extern std::string JANUARY;
|
||||
extern std::string FEBRUARY;
|
||||
extern std::string MARCH;
|
||||
extern std::string APRIL;
|
||||
extern std::string MAY;
|
||||
extern std::string JUNE;
|
||||
extern std::string JULY;
|
||||
extern std::string AUGUST;
|
||||
extern std::string SEPTEMBER;
|
||||
extern std::string OCTOBER;
|
||||
extern std::string NOVEMBER;
|
||||
extern std::string DECEMBER;
|
||||
|
||||
extern std::string SUN;
|
||||
extern std::string MON;
|
||||
extern std::string TUE;
|
||||
extern std::string WED;
|
||||
extern std::string THU;
|
||||
extern std::string FRI;
|
||||
extern std::string SAT;
|
||||
|
||||
extern std::string JAN;
|
||||
extern std::string FEB;
|
||||
extern std::string MAR;
|
||||
extern std::string APR;
|
||||
extern std::string MAY_ABBR;
|
||||
extern std::string JUN;
|
||||
extern std::string JUL;
|
||||
extern std::string AUG;
|
||||
extern std::string SEP;
|
||||
extern std::string OCT;
|
||||
extern std::string NOV;
|
||||
extern std::string DEC;
|
||||
#endif
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
// Constant string definitions (English)
|
||||
void reinitializeLangVars();
|
||||
#endif
|
||||
|
||||
|
||||
// Define the updateIfNotEmpty function
|
||||
void updateIfNotEmpty(std::string& constant, const char* jsonKey, const json_t* jsonData);
|
||||
|
||||
void parseLanguage(const std::string& langFile);
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
void localizeTimeStr(char* timeStr);
|
||||
#endif
|
||||
|
||||
// Unified function to apply replacements
|
||||
void applyLangReplacements(std::string& text, bool isValue = false);
|
||||
|
||||
|
||||
|
||||
//// Map of character widths (pre-calibrated)
|
||||
//extern std::unordered_map<wchar_t, float> characterWidths;
|
||||
|
||||
//extern float defaultNumericCharWidth;
|
||||
|
||||
|
||||
|
||||
// Predefined hexMap
|
||||
//extern const std::array<int, 256> hexMap;
|
||||
inline constexpr std::array<int, 256> hexMap = [] {
|
||||
std::array<int, 256> map = {0};
|
||||
map['0'] = 0; map['1'] = 1; map['2'] = 2; map['3'] = 3; map['4'] = 4;
|
||||
map['5'] = 5; map['6'] = 6; map['7'] = 7; map['8'] = 8; map['9'] = 9;
|
||||
map['A'] = 10; map['B'] = 11; map['C'] = 12; map['D'] = 13; map['E'] = 14; map['F'] = 15;
|
||||
map['a'] = 10; map['b'] = 11; map['c'] = 12; map['d'] = 13; map['e'] = 14; map['f'] = 15;
|
||||
return map;
|
||||
}();
|
||||
|
||||
|
||||
// Prepare a map of default settings
|
||||
extern std::map<const std::string, std::string> defaultThemeSettingsMap;
|
||||
|
||||
bool isNumericCharacter(char c);
|
||||
|
||||
bool isValidHexColor(const std::string& hexColor);
|
||||
|
||||
|
||||
|
||||
float calculateAmplitude(float x, float peakDurationFactor = 0.25f);
|
||||
|
||||
|
||||
extern std::atomic<bool> refreshWallpaperNow;
|
||||
extern std::atomic<bool> refreshWallpaper;
|
||||
extern std::vector<u8> wallpaperData;
|
||||
extern std::atomic<bool> inPlot;
|
||||
|
||||
extern std::mutex wallpaperMutex;
|
||||
extern std::condition_variable cv;
|
||||
|
||||
|
||||
|
||||
// Function to load the RGBA file into memory and modify wallpaperData directly
|
||||
void loadWallpaperFile(const std::string& filePath, s32 width = 448, s32 height = 720);
|
||||
void loadWallpaperFileWhenSafe();
|
||||
|
||||
void reloadWallpaper();
|
||||
|
||||
// Global variables for FPS calculation
|
||||
//extern double lastTimeCount;
|
||||
//extern int frameCount;
|
||||
//extern float fps;
|
||||
//extern double elapsedTime;
|
||||
|
||||
|
||||
extern std::atomic<bool> themeIsInitialized;
|
||||
|
||||
// Variables for touch commands
|
||||
extern std::atomic<bool> touchingBack;
|
||||
extern std::atomic<bool> touchingSelect;
|
||||
extern std::atomic<bool> touchingNextPage;
|
||||
extern std::atomic<bool> touchingMenu;
|
||||
extern std::atomic<bool> shortTouchAndRelease;
|
||||
extern std::atomic<bool> longTouchAndRelease;
|
||||
extern std::atomic<bool> simulatedBack;
|
||||
//extern bool simulatedBackComplete;
|
||||
extern std::atomic<bool> simulatedSelect;
|
||||
//extern bool simulatedSelectComplete;
|
||||
extern std::atomic<bool> simulatedNextPage;
|
||||
//extern std::atomic<bool> simulatedNextPageComplete;
|
||||
extern std::atomic<bool> simulatedMenu;
|
||||
//extern bool simulatedMenuComplete;
|
||||
extern std::atomic<bool> stillTouching;
|
||||
extern std::atomic<bool> interruptedTouch;
|
||||
extern std::atomic<bool> touchInBounds;
|
||||
|
||||
|
||||
#if USING_WIDGET_DIRECTIVE
|
||||
// Battery implementation
|
||||
extern bool powerInitialized;
|
||||
extern bool powerCacheInitialized;
|
||||
extern uint32_t powerCacheCharge;
|
||||
extern bool powerCacheIsCharging;
|
||||
extern PsmSession powerSession;
|
||||
|
||||
// Define variables to store previous battery charge and time
|
||||
//extern uint32_t prevBatteryCharge;
|
||||
//extern s64 timeOut;
|
||||
|
||||
|
||||
extern std::atomic<uint32_t> batteryCharge;
|
||||
extern std::atomic<bool> isCharging;
|
||||
|
||||
//constexpr std::chrono::seconds min_delay = std::chrono::seconds(3); // Minimum delay between checks
|
||||
|
||||
bool powerGetDetails(uint32_t *_batteryCharge, bool *_isCharging);
|
||||
|
||||
void powerInit(void);
|
||||
|
||||
void powerExit(void);
|
||||
#endif
|
||||
|
||||
// Temperature Implementation
|
||||
extern std::atomic<float> PCB_temperature;
|
||||
extern std::atomic<float> SOC_temperature;
|
||||
|
||||
/*
|
||||
I2cReadRegHandler was taken from Switch-OC-Suite source code made by KazushiMe
|
||||
Original repository link (Deleted, last checked 15.04.2023): https://github.com/KazushiMe/Switch-OC-Suite
|
||||
*/
|
||||
|
||||
Result I2cReadRegHandler(u8 reg, I2cDevice dev, u16 *out);
|
||||
|
||||
|
||||
#define TMP451_SOC_TEMP_REG 0x01 // Register for SOC temperature integer part
|
||||
#define TMP451_SOC_TMP_DEC_REG 0x10 // Register for SOC temperature decimal part
|
||||
#define TMP451_PCB_TEMP_REG 0x00 // Register for PCB temperature integer part
|
||||
#define TMP451_PCB_TMP_DEC_REG 0x15 // Register for PCB temperature decimal part
|
||||
|
||||
// Common helper function to read temperature (integer and fractional parts)
|
||||
Result ReadTemperature(float *temperature, u8 integerReg, u8 fractionalReg, bool integerOnly);
|
||||
|
||||
// Function to get the SOC temperature
|
||||
Result ReadSocTemperature(float *temperature, bool integerOnly = true);
|
||||
|
||||
// Function to get the PCB temperature
|
||||
Result ReadPcbTemperature(float *temperature, bool integerOnly = true);
|
||||
|
||||
|
||||
|
||||
// Time implementation
|
||||
|
||||
extern const std::string DEFAULT_DT_FORMAT;
|
||||
extern std::string datetimeFormat;
|
||||
|
||||
|
||||
// Widget settings
|
||||
//static std::string hideClock, hideBattery, hidePCBTemp, hideSOCTemp;
|
||||
extern bool hideClock, hideBattery, hidePCBTemp, hideSOCTemp, dynamicWidgetColors;
|
||||
extern bool hideWidgetBackdrop, centerWidgetAlignment, extendedWidgetBackdrop;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
void reinitializeWidgetVars();
|
||||
#endif
|
||||
|
||||
extern bool cleanVersionLabels, hideOverlayVersions, hidePackageVersions, useLibultrahandTitles, useLibultrahandVersions, usePackageTitles, usePackageVersions;
|
||||
|
||||
extern const std::string loaderInfo;
|
||||
extern const std::string loaderTitle;
|
||||
extern const bool expandedMemory;
|
||||
|
||||
extern std::string versionLabel;
|
||||
|
||||
#if IS_LAUNCHER_DIRECTIVE
|
||||
void reinitializeVersionLabels();
|
||||
#endif
|
||||
|
||||
|
||||
// Number of renderer threads to use
|
||||
extern const unsigned numThreads;
|
||||
extern std::vector<std::thread> renderThreads;
|
||||
extern const s32 bmpChunkSize;
|
||||
extern std::atomic<s32> currentRow;
|
||||
|
||||
|
||||
|
||||
static std::barrier inPlotBarrier(numThreads, [](){
|
||||
inPlot.store(false, std::memory_order_release);
|
||||
});
|
||||
|
||||
|
||||
//extern std::atomic<unsigned int> barrierCounter;
|
||||
//extern std::mutex barrierMutex;
|
||||
//extern std::condition_variable barrierCV;
|
||||
//
|
||||
//extern void barrierWait();
|
||||
|
||||
|
||||
void initializeThemeVars();
|
||||
|
||||
void initializeUltrahandSettings();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: ultra.hpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* 'ultra.hpp' serves as a central include header for the Ultrahand Overlay project,
|
||||
* bringing together a comprehensive suite of utility functions essential for the
|
||||
* development and operation of custom overlays on the Nintendo Switch. This header
|
||||
* provides consolidated access to functions facilitating debugging, string processing,
|
||||
* file management, JSON manipulation, and more, enhancing the modularity and
|
||||
* reusability of code within the project.
|
||||
*
|
||||
* These utilities are designed to operate independently, providing robust tools to
|
||||
* support complex overlay functionalities and interactions.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
#ifndef ULTRA_HPP
|
||||
#define ULTRA_HPP
|
||||
|
||||
// Include all functional headers used in the libUltra library
|
||||
|
||||
#include "global_vars.hpp"
|
||||
#include "debug_funcs.hpp"
|
||||
#include "string_funcs.hpp"
|
||||
#include "get_funcs.hpp"
|
||||
#include "path_funcs.hpp"
|
||||
#include "list_funcs.hpp"
|
||||
#include "json_funcs.hpp"
|
||||
#include "ini_funcs.hpp"
|
||||
#include "hex_funcs.hpp"
|
||||
#include "download_funcs.hpp"
|
||||
#include "mod_funcs.hpp"
|
||||
#include "tsl_utils.hpp"
|
||||
#include "audio_player.hpp"
|
||||
#include "haptics.hpp"
|
||||
|
||||
#endif // ULTRA_HPP
|
||||
@@ -1,312 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: audio_player.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* Memory-optimized version with reduced allocation overhead and chunked I/O.
|
||||
* Key changes:
|
||||
* - Eliminated temporary vector allocations (saves 50% memory during load)
|
||||
* - Chunked file reading to reduce peak memory usage
|
||||
* - Reduced alignment padding (saves ~3-4KB per sound)
|
||||
* - Added lazy loading option via unloadAllSounds()
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2025 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "audio_player.hpp"
|
||||
|
||||
namespace ult {
|
||||
bool AudioPlayer::m_initialized = false;
|
||||
std::atomic<bool> AudioPlayer::m_enabled{true};
|
||||
float AudioPlayer::m_masterVolume = 0.6f;
|
||||
bool AudioPlayer::m_lastDockedState = false;
|
||||
std::vector<AudioPlayer::CachedSound> AudioPlayer::m_cachedSounds;
|
||||
std::mutex AudioPlayer::m_audioMutex;
|
||||
|
||||
bool AudioPlayer::initialize() {
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
|
||||
if (m_initialized) return true;
|
||||
|
||||
if (R_FAILED(audoutInitialize()) || R_FAILED(audoutStartAudioOut())) {
|
||||
audoutExit();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
m_cachedSounds.resize(static_cast<uint32_t>(SoundType::Count));
|
||||
m_lastDockedState = isDocked();
|
||||
reloadAllSounds();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioPlayer::exit() {
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
|
||||
// Free all cached sound buffers
|
||||
for (auto& cached : m_cachedSounds) {
|
||||
if (cached.buffer) {
|
||||
free(cached.buffer);
|
||||
cached.buffer = nullptr;
|
||||
}
|
||||
cached.bufferSize = 0;
|
||||
cached.dataSize = 0;
|
||||
}
|
||||
|
||||
if (m_initialized) {
|
||||
audoutStopAudioOut();
|
||||
audoutExit();
|
||||
m_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlayer::reloadAllSounds() {
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(SoundType::Count); ++i) {
|
||||
loadSoundFromWav(static_cast<SoundType>(i), m_soundPaths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlayer::unloadAllSounds(const std::initializer_list<SoundType>& excludeSounds) {
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
if (!m_initialized) return;
|
||||
|
||||
for (uint32_t i = 0; i < m_cachedSounds.size(); ++i) {
|
||||
SoundType current = static_cast<SoundType>(i);
|
||||
|
||||
// Skip if this sound is in the exclude list
|
||||
if (std::find(excludeSounds.begin(), excludeSounds.end(), current) != excludeSounds.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& cached = m_cachedSounds[i];
|
||||
if (cached.buffer) {
|
||||
free(cached.buffer);
|
||||
cached.buffer = nullptr;
|
||||
}
|
||||
cached.bufferSize = 0;
|
||||
cached.dataSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioPlayer::reloadIfDockedChanged() {
|
||||
if (!m_initialized) return false;
|
||||
|
||||
const bool currentDocked = isDocked();
|
||||
if (currentDocked == m_lastDockedState) return false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
m_lastDockedState = currentDocked;
|
||||
reloadAllSounds();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioPlayer::loadSoundFromWav(SoundType type, const char* path) {
|
||||
const uint32_t idx = static_cast<uint32_t>(type);
|
||||
if (!m_initialized || idx >= static_cast<uint32_t>(SoundType::Count)) return false;
|
||||
|
||||
// Free existing buffer
|
||||
free(m_cachedSounds[idx].buffer);
|
||||
m_cachedSounds[idx] = { nullptr, 0, 0 };
|
||||
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
// Parse WAV header
|
||||
char hdr[12];
|
||||
if (fread(hdr, 1, 12, f) != 12 || memcmp(hdr, "RIFF", 4) || memcmp(hdr + 8, "WAVE", 4)) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
u16 fmt = 0, ch = 0, bits = 0;
|
||||
u32 rate = 0, dSize = 0;
|
||||
long dPos = 0;
|
||||
|
||||
// Find fmt and data chunks
|
||||
while (fread(hdr, 1, 8, f) == 8) {
|
||||
const u32 sz = *(u32*)(hdr + 4);
|
||||
if (!memcmp(hdr, "fmt ", 4)) {
|
||||
fread(&fmt, 2, 1, f);
|
||||
fread(&ch, 2, 1, f);
|
||||
fread(&rate, 4, 1, f);
|
||||
fseek(f, 6, SEEK_CUR);
|
||||
fread(&bits, 2, 1, f);
|
||||
fseek(f, sz - 16, SEEK_CUR);
|
||||
} else if (!memcmp(hdr, "data", 4)) {
|
||||
dSize = sz;
|
||||
dPos = ftell(f);
|
||||
break;
|
||||
} else {
|
||||
fseek(f, sz, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate format
|
||||
if (!dSize || fmt != 1 || ch == 0 || ch > 2 || (bits != 8 && bits != 16)) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Calculate buffer sizes
|
||||
// Note: audout REQUIRES stereo (2 channels), so we must duplicate mono
|
||||
const bool mono = (ch == 1);
|
||||
const uint32_t inSamples = dSize / (bits / 8);
|
||||
const uint32_t outSamples = mono ? inSamples * 2 : inSamples; // Duplicate mono to stereo
|
||||
const uint32_t outSize = outSamples * 2; // 16-bit samples
|
||||
|
||||
// Use smaller alignment to reduce waste (256 bytes instead of 4KB)
|
||||
const uint32_t align = 0x100;
|
||||
const uint32_t bufSize = (outSize + align - 1) & ~(align - 1);
|
||||
|
||||
// Allocate output buffer
|
||||
void* buf = aligned_alloc(align, bufSize);
|
||||
if (!buf) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(f, dPos, SEEK_SET);
|
||||
s16* out = (s16*)buf;
|
||||
|
||||
// Calculate volume scaling
|
||||
float effectiveVolume = m_masterVolume;
|
||||
if (m_lastDockedState) {
|
||||
effectiveVolume *= 0.5f;
|
||||
}
|
||||
const float scale = std::clamp(effectiveVolume, 0.0f, 1.0f);
|
||||
|
||||
// Process audio in chunks to minimize memory usage
|
||||
// This eliminates the need for temporary vectors
|
||||
constexpr uint32_t CHUNK_SIZE = 512;
|
||||
|
||||
if (bits == 8) {
|
||||
// 8-bit audio: read and convert in chunks
|
||||
const int32_t scaleInt = static_cast<int32_t>(scale * 256.0f);
|
||||
u8 chunk[CHUNK_SIZE];
|
||||
uint32_t remaining = inSamples;
|
||||
uint32_t outIdx = 0;
|
||||
|
||||
while (remaining > 0) {
|
||||
const uint32_t toRead = std::min(remaining, CHUNK_SIZE);
|
||||
if (fread(chunk, 1, toRead, f) != toRead) {
|
||||
free(buf);
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < toRead; ++i) {
|
||||
const s16 sample = static_cast<s16>((chunk[i] - 128) * scaleInt);
|
||||
if (mono) {
|
||||
// Duplicate to both L and R channels for stereo output
|
||||
out[outIdx++] = sample; // Left
|
||||
out[outIdx++] = sample; // Right
|
||||
} else {
|
||||
out[outIdx++] = sample;
|
||||
}
|
||||
}
|
||||
remaining -= toRead;
|
||||
}
|
||||
} else {
|
||||
// 16-bit audio: read and convert in chunks
|
||||
s16 chunk[CHUNK_SIZE];
|
||||
uint32_t remaining = inSamples;
|
||||
uint32_t outIdx = 0;
|
||||
|
||||
while (remaining > 0) {
|
||||
const uint32_t toRead = std::min(remaining, CHUNK_SIZE);
|
||||
if (fread(chunk, sizeof(s16), toRead, f) != toRead) {
|
||||
free(buf);
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < toRead; ++i) {
|
||||
const s16 sample = static_cast<s16>(chunk[i] * scale);
|
||||
if (mono) {
|
||||
// Duplicate to both L and R channels for stereo output
|
||||
out[outIdx++] = sample; // Left
|
||||
out[outIdx++] = sample; // Right
|
||||
} else {
|
||||
out[outIdx++] = sample;
|
||||
}
|
||||
}
|
||||
remaining -= toRead;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
// Zero-fill any padding
|
||||
if (outSize < bufSize) {
|
||||
memset((u8*)buf + outSize, 0, bufSize - outSize);
|
||||
}
|
||||
|
||||
m_cachedSounds[idx] = { buf, bufSize, outSize };
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioPlayer::playSound(SoundType type) {
|
||||
// Lock-free check - SAFE with atomic
|
||||
if (!m_enabled.load(std::memory_order_relaxed)) return;
|
||||
|
||||
const uint32_t idx = static_cast<uint32_t>(type);
|
||||
if (idx >= static_cast<uint32_t>(SoundType::Count)) return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
|
||||
// Check again under lock
|
||||
if (!m_initialized) return;
|
||||
|
||||
auto& cached = m_cachedSounds[idx];
|
||||
if (!cached.buffer) return;
|
||||
|
||||
// Release any finished buffers
|
||||
AudioOutBuffer* releasedBuffers = nullptr;
|
||||
u32 releasedCount = 0;
|
||||
audoutGetReleasedAudioOutBuffer(&releasedBuffers, &releasedCount);
|
||||
|
||||
// Static buffer is safe with mutex protection
|
||||
static AudioOutBuffer audioBuffer = {};
|
||||
audioBuffer = {};
|
||||
audioBuffer.buffer = cached.buffer;
|
||||
audioBuffer.buffer_size = cached.bufferSize;
|
||||
audioBuffer.data_size = cached.dataSize;
|
||||
audioBuffer.data_offset = 0;
|
||||
audioBuffer.next = nullptr;
|
||||
|
||||
AudioOutBuffer* rel = nullptr;
|
||||
audoutPlayBuffer(&audioBuffer, &rel);
|
||||
}
|
||||
|
||||
void AudioPlayer::setMasterVolume(float v) {
|
||||
std::lock_guard<std::mutex> lock(m_audioMutex);
|
||||
m_masterVolume = std::clamp(v, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void AudioPlayer::setEnabled(bool e) {
|
||||
m_enabled.store(e, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
bool AudioPlayer::isEnabled() {
|
||||
return m_enabled.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
bool AudioPlayer::isDocked() {
|
||||
Result rc = apmInitialize();
|
||||
if (R_FAILED(rc)) return false;
|
||||
|
||||
ApmPerformanceMode perfMode = ApmPerformanceMode_Invalid;
|
||||
rc = apmGetPerformanceMode(&perfMode);
|
||||
apmExit();
|
||||
|
||||
return R_SUCCEEDED(rc) && (perfMode == ApmPerformanceMode_Boost);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: debug_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file contains the implementation of debugging functions for the
|
||||
* Ultrahand Overlay project.
|
||||
********************************************************************************/
|
||||
|
||||
#include "debug_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
// Define static variables
|
||||
const std::string defaultLogFilePath = "sdmc:/switch/.packages/log.txt";
|
||||
std::string logFilePath = defaultLogFilePath;
|
||||
bool disableLogging = true;
|
||||
std::mutex logMutex;
|
||||
|
||||
void logMessage(const char* message) {
|
||||
std::time_t currentTime = std::time(nullptr);
|
||||
std::tm* timeInfo = std::localtime(¤tTime);
|
||||
char timestamp[30];
|
||||
strftime(timestamp, sizeof(timestamp), "[%Y-%m-%d %H:%M:%S] ", timeInfo);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logMutex);
|
||||
|
||||
FILE* file = fopen(logFilePath.c_str(), "a");
|
||||
if (file != nullptr) {
|
||||
fputs(timestamp, file);
|
||||
fputs(message, file);
|
||||
fputc('\n', file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logMutex);
|
||||
|
||||
std::ofstream file(logFilePath.c_str(), std::ios::app);
|
||||
if (file.is_open()) {
|
||||
file << timestamp << message << "\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Overload for std::string
|
||||
void logMessage(const std::string& message) {
|
||||
logMessage(message.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,879 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: download_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides implementations for the functions declared in
|
||||
* download_funcs.hpp. These functions utilize libcurl for downloading files
|
||||
* from the internet and minizip-ng for extracting ZIP archives with proper
|
||||
* 64-bit file support.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "download_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
|
||||
// Base loader definitions
|
||||
size_t DOWNLOAD_READ_BUFFER = 8*1024;//64 * 1024;//4096*10;
|
||||
size_t DOWNLOAD_WRITE_BUFFER = 8*1024;//64 * 1024;
|
||||
size_t UNZIP_READ_BUFFER = 32*1024;//131072*2;//4096*4;
|
||||
size_t UNZIP_WRITE_BUFFER = 16*1024;//131072*2;//4096*4;
|
||||
|
||||
|
||||
// Path to the CA certificate
|
||||
//const std::string cacertPath = "sdmc:/config/ultrahand/cacert.pem";
|
||||
//const std::string cacertURL = "https://curl.se/ca/cacert.pem";
|
||||
|
||||
// User agent string for curl requests
|
||||
static constexpr const char* userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36";
|
||||
|
||||
// Shared atomic flag to indicate whether to abort the download operation
|
||||
std::atomic<bool> abortDownload(false);
|
||||
// Define an atomic bool for interpreter completion
|
||||
std::atomic<bool> abortUnzip(false);
|
||||
std::atomic<int> downloadPercentage(-1);
|
||||
std::atomic<int> unzipPercentage(-1);
|
||||
|
||||
// Thread-safe curl initialization
|
||||
static std::mutex curlInitMutex;
|
||||
static std::atomic<bool> curlInitialized(false);
|
||||
|
||||
|
||||
// Definition of CurlDeleter
|
||||
struct CurlDeleter {
|
||||
void operator()(CURL* curl) const noexcept {
|
||||
if (curl) {
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct FileDeleter {
|
||||
void operator()(FILE* f) const {
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Callback function to write received data to a file.
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Using stdio.h functions (FILE*, fwrite)
|
||||
size_t writeCallback(void* ptr, size_t size, size_t nmemb, FILE* stream) {
|
||||
if (!ptr || !stream) return 0;
|
||||
//size_t totalBytes = size * nmemb;
|
||||
//size_t writtenBytes = fwrite(ptr, 1, totalBytes, stream);
|
||||
//return writtenBytes;
|
||||
return fwrite(ptr, 1, size * nmemb, stream);
|
||||
}
|
||||
#else
|
||||
// Using std::ofstream for writing
|
||||
size_t writeCallback(void* ptr, size_t size, size_t nmemb, std::ostream* stream) {
|
||||
if (!ptr || !stream) return 0;
|
||||
auto& file = *static_cast<std::ofstream*>(stream);
|
||||
const size_t totalBytes = size * nmemb;
|
||||
file.write(static_cast<const char*>(ptr), totalBytes);
|
||||
return totalBytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Your C function
|
||||
int progressCallback(void *ptr, curl_off_t totalToDownload, curl_off_t nowDownloaded, curl_off_t totalToUpload, curl_off_t nowUploaded) {
|
||||
if (!ptr) return 1;
|
||||
|
||||
auto percentage = static_cast<std::atomic<int>*>(ptr);
|
||||
|
||||
if (totalToDownload > 0) {
|
||||
//int newProgress = static_cast<int>((static_cast<double>(nowDownloaded) / static_cast<double>(totalToDownload)) * 100.0);
|
||||
percentage->store(static_cast<int>((static_cast<double>(nowDownloaded) / static_cast<double>(totalToDownload)) * 100.0), std::memory_order_release);
|
||||
}
|
||||
|
||||
if (abortDownload.load(std::memory_order_acquire)) {
|
||||
percentage->store(-1, std::memory_order_release);
|
||||
return 1; // Abort the download
|
||||
}
|
||||
|
||||
return 0; // Continue the download
|
||||
}
|
||||
|
||||
// Global initialization function
|
||||
//void initializeCurl() {
|
||||
// std::lock_guard<std::mutex> lock(curlInitMutex);
|
||||
// if (!curlInitialized.load(std::memory_order_acquire)) {
|
||||
// const CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
// if (res != CURLE_OK) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// if (!disableLogging)
|
||||
// logMessage("curl_global_init() failed: " + std::string(curl_easy_strerror(res)));
|
||||
// #endif
|
||||
// // Handle error appropriately, possibly exit the program
|
||||
// } else {
|
||||
// curlInitialized.store(true, std::memory_order_release);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// Global cleanup function
|
||||
//void cleanupCurl() {
|
||||
// std::lock_guard<std::mutex> lock(curlInitMutex);
|
||||
// if (curlInitialized.load(std::memory_order_acquire)) {
|
||||
// curl_global_cleanup();
|
||||
// curlInitialized.store(false, std::memory_order_release);
|
||||
// }
|
||||
//}
|
||||
|
||||
std::unique_ptr<char[]> globalWriteBuffer;
|
||||
|
||||
/**
|
||||
* @brief Downloads a file from a URL to a specified destination.
|
||||
*
|
||||
* @param url The URL of the file to download.
|
||||
* @param toDestination The destination path where the file should be saved.
|
||||
* @return True if the download was successful, false otherwise.
|
||||
*/
|
||||
bool downloadFile(const std::string& url, const std::string& toDestination, bool noPercentagePolling) {
|
||||
abortDownload.store(false, std::memory_order_release);
|
||||
|
||||
if (url.find_first_of("{}") != std::string::npos) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Invalid URL: " + url);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string destination = toDestination;
|
||||
if (destination.back() == '/') {
|
||||
createDirectory(destination);
|
||||
const size_t lastSlash = url.find_last_of('/');
|
||||
if (lastSlash != std::string::npos) {
|
||||
destination += url.substr(lastSlash + 1);
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Invalid URL: " + url);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
createDirectory(destination.substr(0, destination.find_last_of('/')));
|
||||
}
|
||||
|
||||
const std::string tempFilePath = getParentDirFromPath(destination) + "." + getFileName(destination) + ".tmp";
|
||||
|
||||
#if USING_FSTREAM_DIRECTIVE
|
||||
// Use ofstream if !USING_FSTREAM_DIRECTIVE is not defined
|
||||
std::ofstream file(tempFilePath, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error opening file: " + tempFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
// Alternative method of opening file (depending on your platform, like using POSIX open())
|
||||
std::unique_ptr<FILE, FileDeleter> file(fopen(tempFilePath.c_str(), "wb"));
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error opening file: " + tempFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// ADD THIS: Set up write buffer for better performance
|
||||
//std::unique_ptr<char[]> globalWriteBuffer;
|
||||
if (DOWNLOAD_WRITE_BUFFER > 0) {
|
||||
//if (!globalWriteBuffer)
|
||||
globalWriteBuffer = std::make_unique<char[]>(DOWNLOAD_WRITE_BUFFER);
|
||||
// _IOFBF = full buffering, _IOLBF = line buffering, _IONBF = no buffering
|
||||
setvbuf(file.get(), globalWriteBuffer.get(), _IOFBF, DOWNLOAD_WRITE_BUFFER);
|
||||
}
|
||||
|
||||
//setvbuf(file.get(), NULL, _IOFBF, DOWNLOAD_WRITE_BUFFER);
|
||||
#endif
|
||||
|
||||
// Ensure curl is initialized
|
||||
//initializeCurl();
|
||||
|
||||
//if (!R_SUCCEEDED(socketInitializeDefault())) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// if (!disableLogging)
|
||||
// logMessage("Failed to initialize socket.");
|
||||
// #endif
|
||||
// return false;
|
||||
//}
|
||||
|
||||
std::unique_ptr<CURL, CurlDeleter> curl(curl_easy_init());
|
||||
if (!curl) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error initializing curl.");
|
||||
#endif
|
||||
#if USING_FSTREAM_DIRECTIVE
|
||||
file.close();
|
||||
#else
|
||||
file.reset();
|
||||
globalWriteBuffer.reset();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only initialize downloadPercentage if we're tracking progress
|
||||
if (!noPercentagePolling) {
|
||||
downloadPercentage.store(0, std::memory_order_release);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, writeCallback);
|
||||
#if USING_FSTREAM_DIRECTIVE
|
||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &file);
|
||||
#else
|
||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, file.get());
|
||||
#endif
|
||||
|
||||
// Conditionally set up progress callback based on noPercentagePolling
|
||||
if (noPercentagePolling) {
|
||||
// Disable progress function entirely
|
||||
curl_easy_setopt(curl.get(), CURLOPT_NOPROGRESS, 1L);
|
||||
} else {
|
||||
// Enable progress callback for percentage updates
|
||||
curl_easy_setopt(curl.get(), CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_XFERINFOFUNCTION, progressCallback);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_XFERINFODATA, &downloadPercentage);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl.get(), CURLOPT_USERAGENT, userAgent);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // Enable HTTP/2
|
||||
curl_easy_setopt(curl.get(), CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); // Force TLS 1.2
|
||||
|
||||
curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_BUFFERSIZE, DOWNLOAD_READ_BUFFER); // Increase buffer size
|
||||
|
||||
// Add timeout options
|
||||
curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 10L); // 10 seconds to connect
|
||||
curl_easy_setopt(curl.get(), CURLOPT_LOW_SPEED_LIMIT, 1L); // 1 byte/s (virtually any progress)
|
||||
curl_easy_setopt(curl.get(), CURLOPT_LOW_SPEED_TIME, 60L); // 1 minutes of no progress
|
||||
|
||||
//curl_easy_setopt(curl.get(), CURLOPT_DNS_USE_GLOBAL_CACHE, 0L);
|
||||
//curl_easy_setopt(curl.get(), CURLOPT_FORBID_REUSE, 1L);
|
||||
//curl_easy_setopt(curl.get(), CURLOPT_CLOSESOCKETDATA, NULL); // ensure no dangling sockets
|
||||
//curl_easy_setopt(curl.get(), CURLOPT_TCP_NODELAY, 1L);
|
||||
|
||||
CURLcode result = curl_easy_perform(curl.get());
|
||||
|
||||
// Detect if download was aborted
|
||||
//const bool wasAborted = (result == CURLE_ABORTED_BY_CALLBACK ||
|
||||
// abortDownload.load(std::memory_order_acquire));
|
||||
|
||||
|
||||
#if USING_FSTREAM_DIRECTIVE
|
||||
file.close();
|
||||
#else
|
||||
file.reset();
|
||||
globalWriteBuffer.reset();
|
||||
#endif
|
||||
|
||||
curl.reset();
|
||||
|
||||
// Always cleanup global state
|
||||
//curl_global_cleanup();
|
||||
//
|
||||
//// Sleep to let cleanup finish
|
||||
//for (int i = 0; i < 10; ++i) {
|
||||
// svcSleepThread(50'000'000ULL);
|
||||
//}
|
||||
//
|
||||
//// Explicitly reinitialize for next download
|
||||
//curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
// CRITICAL: For aborted downloads, give curl time to clean up network/SSL state
|
||||
// before destroying the handle. This prevents memory leaks in the global heap.
|
||||
//if (wasAborted) {
|
||||
// for (int i = 0; i < 10; ++i) {
|
||||
// svcSleepThread(50'000'000ULL); // 50ms x 10 = 500ms total
|
||||
// }
|
||||
//}
|
||||
|
||||
//cleanupCurl();
|
||||
|
||||
//socketExit();
|
||||
|
||||
if (result != CURLE_OK) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (result == CURLE_ABORTED_BY_CALLBACK) {
|
||||
if (!disableLogging)
|
||||
logMessage("Download aborted by user: " + url);
|
||||
} else if (result == CURLE_OPERATION_TIMEDOUT) {
|
||||
if (!disableLogging)
|
||||
logMessage("Download timed out: " + url);
|
||||
} else if (result == CURLE_COULDNT_CONNECT) {
|
||||
if (!disableLogging)
|
||||
logMessage("Could not connect to: " + url);
|
||||
} else {
|
||||
if (!disableLogging)
|
||||
logMessage("Error downloading file: " + std::string(curl_easy_strerror(result)));
|
||||
}
|
||||
#endif
|
||||
deleteFileOrDirectory(tempFilePath);
|
||||
if (!noPercentagePolling) {
|
||||
downloadPercentage.store(-1, std::memory_order_release);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if USING_FSTREAM_DIRECTIVE
|
||||
std::ifstream checkFile(tempFilePath);
|
||||
if (!checkFile || checkFile.peek() == std::ifstream::traits_type::eof()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error downloading file: Empty file");
|
||||
#endif
|
||||
deleteFileOrDirectory(tempFilePath);
|
||||
// Only update percentage if we're tracking it
|
||||
if (!noPercentagePolling) {
|
||||
downloadPercentage.store(-1, std::memory_order_release);
|
||||
}
|
||||
checkFile.close();
|
||||
return false;
|
||||
}
|
||||
checkFile.close();
|
||||
#else
|
||||
// Alternative method for checking if the file is empty (POSIX example)
|
||||
struct stat fileStat;
|
||||
if (stat(tempFilePath.c_str(), &fileStat) != 0 || fileStat.st_size == 0) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error downloading file: Empty file");
|
||||
#endif
|
||||
deleteFileOrDirectory(tempFilePath);
|
||||
// Only update percentage if we're tracking it
|
||||
if (!noPercentagePolling) {
|
||||
downloadPercentage.store(-1, std::memory_order_release);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only update percentage if we're tracking it
|
||||
if (!noPercentagePolling) {
|
||||
downloadPercentage.store(100, std::memory_order_release);
|
||||
}
|
||||
|
||||
// CHECK FOR PROTECTED FILES AND ADD .ultra EXTENSION IF NEEDED
|
||||
if (PROTECTED_FILES.find(destination) != PROTECTED_FILES.end()) {
|
||||
destination += ".ultra";
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Protected file detected, renaming download to: " + destination);
|
||||
#endif
|
||||
}
|
||||
|
||||
moveFile(tempFilePath, destination);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Custom I/O function for opening files with larger buffer
|
||||
*/
|
||||
static voidpf ZCALLBACK fopen64_file_func_custom(voidpf opaque, const void* filename, int mode) {
|
||||
FILE* file = nullptr;
|
||||
const char* mode_fopen = nullptr;
|
||||
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename != nullptr) && (mode_fopen != nullptr)) {
|
||||
file = fopen((const char*)filename, mode_fopen);
|
||||
if (file && ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)) {
|
||||
// Set 64KB buffer for reading the ZIP file - reduces syscalls
|
||||
//static const size_t zipReadBufferSize = UNZIP_READ_BUFFER;
|
||||
setvbuf(file, nullptr, _IOFBF, UNZIP_READ_BUFFER);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static int ZCALLBACK fclose64_file_func_custom(voidpf opaque, voidpf stream) {
|
||||
int ret = EOF;
|
||||
if (stream != nullptr) {
|
||||
ret = fclose((FILE*)stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extracts files from a ZIP archive to a specified destination.
|
||||
*
|
||||
* Ultra-optimized single-pass extraction with smooth byte-based progress reporting
|
||||
* using miniz with proper 64-bit file support and streaming extraction.
|
||||
* Fixed memory leaks with RAII for proper resource cleanup on abort.
|
||||
*
|
||||
* @param zipFilePath The path to the ZIP archive file.
|
||||
* @param toDestination The destination directory where files should be extracted.
|
||||
* @return True if the extraction was successful, false otherwise.
|
||||
*/
|
||||
bool unzipFile(const std::string& zipFilePath, const std::string& toDestination) {
|
||||
abortUnzip.store(false, std::memory_order_release);
|
||||
unzipPercentage.store(0, std::memory_order_release);
|
||||
|
||||
// Time-based abort checking - pre-calculated constants
|
||||
//u64 lastAbortCheck = armTicksToNs(armGetSystemTick());
|
||||
//u64 currentNanos; // Reused for all tick operations
|
||||
bool success = true;
|
||||
|
||||
// RAII wrapper for unzFile
|
||||
struct UnzFileManager {
|
||||
unzFile file = nullptr;
|
||||
|
||||
UnzFileManager(const std::string& path) {
|
||||
zlib_filefunc64_def ffunc;
|
||||
fill_fopen64_filefunc(&ffunc);
|
||||
ffunc.zopen64_file = fopen64_file_func_custom;
|
||||
ffunc.zclose_file = fclose64_file_func_custom;
|
||||
file = unzOpen2_64(path.c_str(), &ffunc);
|
||||
}
|
||||
|
||||
~UnzFileManager() {
|
||||
if (file) {
|
||||
unzClose(file);
|
||||
file = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_valid() const { return file != nullptr; }
|
||||
operator unzFile() const { return file; }
|
||||
};
|
||||
|
||||
// RAII wrapper for output file
|
||||
struct OutputFileManager {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = nullptr;
|
||||
std::unique_ptr<char[]> buffer;
|
||||
size_t bufferSize;
|
||||
|
||||
OutputFileManager(size_t bufSize) : bufferSize(bufSize) {
|
||||
buffer = std::make_unique<char[]>(bufferSize);
|
||||
}
|
||||
|
||||
bool open(const std::string& path) {
|
||||
close();
|
||||
file = fopen(path.c_str(), "wb");
|
||||
if (file) {
|
||||
setvbuf(file, buffer.get(), _IOFBF, bufferSize);
|
||||
}
|
||||
return file != nullptr;
|
||||
}
|
||||
|
||||
void close() {
|
||||
if (file) {
|
||||
fclose(file);
|
||||
file = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_open() const { return file != nullptr; }
|
||||
|
||||
size_t write(const void* data, size_t size) {
|
||||
return file ? fwrite(data, 1, size, file) : 0;
|
||||
}
|
||||
|
||||
~OutputFileManager() { close(); }
|
||||
#else
|
||||
std::ofstream file;
|
||||
|
||||
OutputFileManager(size_t bufSize) {
|
||||
// Constructor for consistency with FILE* version
|
||||
}
|
||||
|
||||
bool open(const std::string& path) {
|
||||
close();
|
||||
file.open(path, std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
file.rdbuf()->pubsetbuf(nullptr, UNZIP_WRITE_BUFFER);
|
||||
}
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
void close() {
|
||||
if (file.is_open()) {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool is_open() const { return file.is_open(); }
|
||||
|
||||
size_t write(const void* data, size_t size) {
|
||||
if (file.is_open()) {
|
||||
file.write(static_cast<const char*>(data), size);
|
||||
return file.good() ? size : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
UnzFileManager zipFile(zipFilePath);
|
||||
if (!zipFile.is_valid()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open zip file: " + zipFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get global info about the ZIP file
|
||||
unz_global_info64 globalInfo;
|
||||
if (unzGetGlobalInfo64(zipFile, &globalInfo) != UNZ_OK) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to get zip file info");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
const uLong numFiles = globalInfo.number_entry;
|
||||
if (numFiles == 0) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("No files found in archive");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// ALWAYS calculate total size for accurate byte-based progress
|
||||
ZPOS64_T totalUncompressedSize = 0;
|
||||
char tempFilenameBuffer[512];
|
||||
unz_file_info64 fileInfo;
|
||||
|
||||
// First pass: calculate total uncompressed size
|
||||
int result = unzGoToFirstFile(zipFile);
|
||||
while (result == UNZ_OK) {
|
||||
// Time-based abort check at start of each file (only if 2+ seconds have passed)
|
||||
//currentNanos = armTicksToNs(armGetSystemTick());
|
||||
//if ((currentNanos - lastAbortCheck) >= 2000000000ULL) {
|
||||
// if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
// unzipPercentage.store(-1, std::memory_order_release);
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// logMessage("Extraction aborted during size calculation");
|
||||
// #endif
|
||||
// abortUnzip.store(false, std::memory_order_release);
|
||||
// return false;
|
||||
// }
|
||||
// lastAbortCheck = currentNanos;
|
||||
//}
|
||||
if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
unzipPercentage.store(-1, std::memory_order_release);
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Extraction aborted during size calculation");
|
||||
#endif
|
||||
abortUnzip.store(false, std::memory_order_release);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (unzGetCurrentFileInfo64(zipFile, &fileInfo, tempFilenameBuffer, sizeof(tempFilenameBuffer),
|
||||
nullptr, 0, nullptr, 0) == UNZ_OK) {
|
||||
const size_t nameLen = strlen(tempFilenameBuffer);
|
||||
if (nameLen > 0 && tempFilenameBuffer[nameLen - 1] != '/') {
|
||||
totalUncompressedSize += std::max(fileInfo.uncompressed_size, static_cast<ZPOS64_T>(1));
|
||||
}
|
||||
}
|
||||
result = unzGoToNextFile(zipFile);
|
||||
}
|
||||
|
||||
// Fallback to 1 if no actual data (avoid division by zero)
|
||||
if (totalUncompressedSize == 0) {
|
||||
totalUncompressedSize = 1;
|
||||
}
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging) {
|
||||
logMessage("Processing " + std::to_string(numFiles) + " files, " +
|
||||
std::to_string(totalUncompressedSize) + " total bytes from archive");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Pre-allocate ALL reusable strings and variables outside the main loop
|
||||
std::string fileName, extractedFilePath, directoryPath;
|
||||
//fileName.reserve(512);
|
||||
//extractedFilePath.reserve(1024);
|
||||
//directoryPath.reserve(1024);
|
||||
|
||||
// Single large buffer for extraction - reused for all files
|
||||
const size_t bufferSize = UNZIP_WRITE_BUFFER;
|
||||
//std::unique_ptr<char[]> buffer = std::make_unique<char[]>(bufferSize);
|
||||
|
||||
globalWriteBuffer = std::make_unique<char[]>(bufferSize);
|
||||
|
||||
char filenameBuffer[512]; // Stack allocated for filename reading
|
||||
|
||||
// Progress tracking variables - OPTIMIZED for smooth byte-based tracking
|
||||
ZPOS64_T totalBytesProcessed = 0;
|
||||
uLong filesProcessed = 0;
|
||||
int currentProgress = 0; // Current percentage (0-100)
|
||||
|
||||
// Create output file manager
|
||||
OutputFileManager outputFile(bufferSize);
|
||||
|
||||
// Loop variables moved outside
|
||||
bool extractSuccess;
|
||||
ZPOS64_T fileBytesProcessed;
|
||||
int bytesRead;
|
||||
|
||||
// String operation variables
|
||||
const char* filename;
|
||||
size_t nameLen;
|
||||
size_t lastSlashPos;
|
||||
size_t invalid_pos;
|
||||
size_t start_pos;
|
||||
|
||||
// Ensure destination directory exists
|
||||
createDirectory(toDestination);
|
||||
|
||||
// Ensure destination ends with '/' - pre-allocate final string
|
||||
std::string destination;
|
||||
//destination.reserve(toDestination.size() + 1);
|
||||
|
||||
destination = toDestination;
|
||||
if (!destination.empty() && destination.back() != '/') {
|
||||
destination += '/';
|
||||
}
|
||||
|
||||
int newProgress;;
|
||||
|
||||
// Extract files
|
||||
result = unzGoToFirstFile(zipFile);
|
||||
while (result == UNZ_OK && success) {
|
||||
// Time-based abort check at start of each file (only if 2+ seconds have passed)
|
||||
//currentNanos = armTicksToNs(armGetSystemTick());
|
||||
//if ((currentNanos - lastAbortCheck) >= 2000000000ULL) {
|
||||
// if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
// success = false;
|
||||
// break; // RAII will handle cleanup
|
||||
// }
|
||||
// lastAbortCheck = currentNanos;
|
||||
//}
|
||||
|
||||
if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
success = false;
|
||||
break; // RAII will handle cleanup
|
||||
}
|
||||
|
||||
// Get current file info - reuse fileInfo variable
|
||||
if (unzGetCurrentFileInfo64(zipFile, &fileInfo, filenameBuffer, sizeof(filenameBuffer),
|
||||
nullptr, 0, nullptr, 0) != UNZ_OK) {
|
||||
result = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
filename = filenameBuffer;
|
||||
|
||||
// Quick filename validation
|
||||
if (!filename || filename[0] == '\0') {
|
||||
result = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
nameLen = strlen(filename);
|
||||
if (nameLen > 0 && filename[nameLen - 1] == '/') { // Skip directories
|
||||
result = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Build extraction path - reuse allocated strings
|
||||
fileName.assign(filename, nameLen);
|
||||
//extractedFilePath.clear();
|
||||
extractedFilePath = destination;
|
||||
extractedFilePath += fileName;
|
||||
|
||||
// Optimized character cleaning - only if needed
|
||||
invalid_pos = extractedFilePath.find_first_of(":*?\"<>|");
|
||||
if (invalid_pos != std::string::npos) {
|
||||
start_pos = std::min(extractedFilePath.find(ROOT_PATH) + 5, extractedFilePath.size());
|
||||
auto it = extractedFilePath.begin() + start_pos;
|
||||
extractedFilePath.erase(std::remove_if(it, extractedFilePath.end(), [](char c) {
|
||||
return c == ':' || c == '*' || c == '?' || c == '\"' || c == '<' || c == '>' || c == '|';
|
||||
}), extractedFilePath.end());
|
||||
}
|
||||
|
||||
// CHECK FOR PROTECTED FILES AND ADD .ultra EXTENSION IF NEEDED
|
||||
if (PROTECTED_FILES.find(extractedFilePath) != PROTECTED_FILES.end()) {
|
||||
extractedFilePath += ".ultra";
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Protected file detected, renaming to: " + extractedFilePath);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Open the current file in the ZIP
|
||||
if (unzOpenCurrentFile(zipFile) != UNZ_OK) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Could not open file in ZIP: " + fileName);
|
||||
#endif
|
||||
result = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create directory if needed
|
||||
lastSlashPos = extractedFilePath.find_last_of('/');
|
||||
if (lastSlashPos != std::string::npos) {
|
||||
directoryPath.assign(extractedFilePath, 0, lastSlashPos + 1);
|
||||
createDirectory(directoryPath);
|
||||
}
|
||||
|
||||
// Open output file
|
||||
if (!outputFile.open(extractedFilePath)) {
|
||||
unzCloseCurrentFile(zipFile);
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error creating file: " + extractedFilePath);
|
||||
#endif
|
||||
result = unzGoToNextFile(zipFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract file data in chunks
|
||||
extractSuccess = true;
|
||||
fileBytesProcessed = 0;
|
||||
|
||||
|
||||
while ((bytesRead = unzReadCurrentFile(zipFile, globalWriteBuffer.get(), bufferSize)) > 0) {
|
||||
if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
extractSuccess = false;
|
||||
break; // RAII will handle cleanup
|
||||
}
|
||||
|
||||
// Write data to file
|
||||
if (outputFile.write(globalWriteBuffer.get(), bytesRead) != static_cast<size_t>(bytesRead)) {
|
||||
extractSuccess = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Update progress tracking
|
||||
fileBytesProcessed += bytesRead;
|
||||
totalBytesProcessed += bytesRead;
|
||||
|
||||
// FIXED: Allow progress to reach 100% naturally during processing
|
||||
if (totalUncompressedSize > 0) {
|
||||
newProgress = static_cast<int>((totalBytesProcessed * 100) / totalUncompressedSize);
|
||||
if (newProgress > currentProgress && newProgress <= 100) {
|
||||
currentProgress = newProgress;
|
||||
unzipPercentage.store(currentProgress, std::memory_order_release);
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
// Only log at 10% intervals to avoid spam
|
||||
if (currentProgress % 10 == 0) {
|
||||
if (!disableLogging) {
|
||||
logMessage("Progress: " + std::to_string(currentProgress) + "% (" +
|
||||
std::to_string(totalBytesProcessed) + "/" +
|
||||
std::to_string(totalUncompressedSize) + " bytes)");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CRITICAL FIX: Handle 0-byte files that don't enter the while loop
|
||||
if (bytesRead == 0 && fileBytesProcessed == 0 && extractSuccess) {
|
||||
// This is a 0-byte file - update progress by 1 byte equivalent
|
||||
totalBytesProcessed += 1;
|
||||
|
||||
// Update progress for 0-byte files
|
||||
if (totalUncompressedSize > 0) {
|
||||
newProgress = static_cast<int>((totalBytesProcessed * 100) / totalUncompressedSize);
|
||||
if (newProgress > currentProgress && newProgress <= 100) {
|
||||
currentProgress = newProgress;
|
||||
unzipPercentage.store(currentProgress, std::memory_order_release);
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (currentProgress % 10 == 0) {
|
||||
if (!disableLogging)
|
||||
logMessage("Progress: " + std::to_string(currentProgress) + "% (0-byte file processed)");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for read errors
|
||||
if (bytesRead < 0) {
|
||||
extractSuccess = false;
|
||||
}
|
||||
|
||||
// Close current file handles
|
||||
outputFile.close();
|
||||
unzCloseCurrentFile(zipFile);
|
||||
|
||||
if (!extractSuccess) {
|
||||
deleteFileOrDirectory(extractedFilePath);
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to extract: " + fileName);
|
||||
#endif
|
||||
|
||||
if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
filesProcessed++;
|
||||
}
|
||||
|
||||
// Move to next file
|
||||
result = unzGoToNextFile(zipFile);
|
||||
}
|
||||
|
||||
globalWriteBuffer.reset();
|
||||
|
||||
// Check final abort state
|
||||
if (abortUnzip.load(std::memory_order_relaxed)) {
|
||||
unzipPercentage.store(-1, std::memory_order_release);
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Extraction aborted by user");
|
||||
#endif
|
||||
abortUnzip.store(false, std::memory_order_release);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (success && filesProcessed > 0) {
|
||||
abortUnzip.store(false, std::memory_order_release);
|
||||
unzipPercentage.store(100, std::memory_order_release);
|
||||
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging) {
|
||||
logMessage("Extraction completed: " + std::to_string(filesProcessed) + " files, " +
|
||||
std::to_string(totalBytesProcessed) + " bytes");
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} else {
|
||||
abortUnzip.store(false, std::memory_order_release);
|
||||
unzipPercentage.store(-1, std::memory_order_release);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,506 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: get_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides the implementations of functions declared in
|
||||
* get_funcs.hpp. These functions are responsible for retrieving and handling
|
||||
* data from the file system and JSON files, including parsing overlay module
|
||||
* information, reading file contents, and accessing structured data used
|
||||
* in the Ultrahand Overlay project.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "get_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
|
||||
/**
|
||||
* @brief Reads the contents of a file and returns it as a string, normalizing line endings.
|
||||
*
|
||||
* @param filePath The path to the file to be read.
|
||||
* @return The content of the file as a string with line endings normalized to '\n'.
|
||||
*/
|
||||
//std::string getFileContents(const std::string& filePath) {
|
||||
// #if !USING_FSTREAM_DIRECTIVE
|
||||
// FILE* file = fopen(filePath.c_str(), "rb");
|
||||
// if (!file) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// logMessage("Failed to open file: " + filePath);
|
||||
// #endif
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// // Determine the file size
|
||||
// fseek(file, 0, SEEK_END);
|
||||
// long size = ftell(file);
|
||||
// if (size <= 0) {
|
||||
// fclose(file);
|
||||
// return "";
|
||||
// }
|
||||
// fseek(file, 0, SEEK_SET);
|
||||
//
|
||||
// // Read the entire file into a string
|
||||
// std::string content(size, '\0');
|
||||
// if (fread(&content[0], 1, size, file) != static_cast<size_t>(size)) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// logMessage("Failed to read file: " + filePath);
|
||||
// #endif
|
||||
// fclose(file);
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// fclose(file);
|
||||
//
|
||||
// #else
|
||||
// std::ifstream file(filePath, std::ios::binary);
|
||||
// if (!file) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// logMessage("Failed to open file: " + filePath);
|
||||
// #endif
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// // Determine the file size
|
||||
// file.seekg(0, std::ios::end);
|
||||
// std::streamsize size = file.tellg();
|
||||
// if (size <= 0) {
|
||||
// return "";
|
||||
// }
|
||||
// file.seekg(0, std::ios::beg);
|
||||
//
|
||||
// // Read the entire file into a string
|
||||
// std::string content(size, '\0');
|
||||
// if (!file.read(&content[0], size)) {
|
||||
// #if USING_LOGGING_DIRECTIVE
|
||||
// logMessage("Failed to read file: " + filePath);
|
||||
// #endif
|
||||
// return "";
|
||||
// }
|
||||
// #endif
|
||||
//
|
||||
// // Erase any carriage return characters (normalize line endings)
|
||||
// content.erase(std::remove(content.begin(), content.end(), '\r'), content.end());
|
||||
// return content;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Concatenates the provided directory and file names to form a destination path.
|
||||
*
|
||||
* @param destinationDir The directory where the file should be placed.
|
||||
* @param fileName The name of the file.
|
||||
* @return The destination path as a string.
|
||||
*/
|
||||
std::string getDestinationPath(const std::string& destinationDir,
|
||||
const std::string& fileName)
|
||||
{
|
||||
// e.g. "foo/bar" + "/" + "baz.txt" → "foo/bar/baz.txt", but if destinationDir ended in '/',
|
||||
// you’d get "foo/bar//baz.txt" → collapse again:
|
||||
std::string combined = destinationDir + "/" + fileName;
|
||||
preprocessPath(combined);
|
||||
return combined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extracts the value part from a string line containing a key-value pair.
|
||||
*
|
||||
* @param line The string line containing a key-value pair (e.g., "key=value").
|
||||
* @return The extracted value as a string. If no value is found, an empty string is returned.
|
||||
*/
|
||||
std::string getValueFromLine(const std::string& line) {
|
||||
const size_t equalsPos = line.rfind('=');
|
||||
if (equalsPos == std::string::npos || equalsPos + 1 >= line.size()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// OPTIMIZATION: Find trim boundaries directly - no temporary string
|
||||
size_t start = equalsPos + 1;
|
||||
size_t end = line.size() - 1;
|
||||
|
||||
// Skip leading whitespace
|
||||
while (start <= end && (line[start] == ' ' || line[start] == '\t' ||
|
||||
line[start] == '\n' || line[start] == '\r' ||
|
||||
line[start] == '\f' || line[start] == '\v')) {
|
||||
++start;
|
||||
}
|
||||
|
||||
// Skip trailing whitespace
|
||||
while (end >= start && (line[end] == ' ' || line[end] == '\t' ||
|
||||
line[end] == '\n' || line[end] == '\r' ||
|
||||
line[end] == '\f' || line[end] == '\v')) {
|
||||
--end;
|
||||
}
|
||||
|
||||
// Return trimmed substring directly
|
||||
return (start <= end) ? line.substr(start, end - start + 1) : "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name from a file path, including handling directories.
|
||||
*
|
||||
* @param path The file path from which to extract the name.
|
||||
* @return The extracted name as a string. If the path indicates a directory, it extracts the last directory name.
|
||||
* If the path is empty or no name is found, an empty string is returned.
|
||||
*/
|
||||
std::string getNameFromPath(const std::string& path) {
|
||||
const size_t lastNonSlash = path.find_last_not_of('/');
|
||||
if (lastNonSlash == std::string::npos) {
|
||||
return ""; // All slashes, or empty string effectively
|
||||
}
|
||||
|
||||
const size_t lastSlash = path.find_last_of('/', lastNonSlash);
|
||||
if (lastSlash == std::string::npos) {
|
||||
return path.substr(0, lastNonSlash + 1); // No slashes, the entire path is a filename
|
||||
}
|
||||
|
||||
return path.substr(lastSlash + 1, lastNonSlash - lastSlash); // Standard case, efficiently handled
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the file name from a full file path.
|
||||
*
|
||||
* This function takes a filesystem path and returns only the file name,
|
||||
* stripping away any directory paths that precede it.
|
||||
*
|
||||
* @param path The full path to the file.
|
||||
* @return The file name extracted from the full path.
|
||||
*/
|
||||
std::string getFileName(const std::string& path) {
|
||||
const size_t pos = path.find_last_of('/');
|
||||
return (pos != std::string::npos) ? path.substr(pos + 1) : "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the name of the parent directory from a given file path at a specified level.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory name.
|
||||
* @param level The level of the parent directory to extract (0 for immediate parent, 1 for grandparent, and so on).
|
||||
* @return The name of the parent directory at the specified level.
|
||||
*/
|
||||
std::string getParentDirNameFromPath(const std::string& path, size_t level) {
|
||||
if (path.empty()) return "";
|
||||
|
||||
// Start from the end of the string and move backwards to find the slashes
|
||||
size_t endPos = path.find_last_not_of('/');
|
||||
if (endPos == std::string::npos) return "";
|
||||
|
||||
size_t pos = path.rfind('/', endPos);
|
||||
if (pos == std::string::npos || pos == 0) return "";
|
||||
|
||||
// Navigate up the specified number of levels
|
||||
while (level-- > 0 && pos != std::string::npos) {
|
||||
endPos = pos - 1;
|
||||
pos = path.rfind('/', endPos);
|
||||
if (pos == std::string::npos || pos == 0) return "";
|
||||
}
|
||||
|
||||
size_t start = path.rfind('/', pos - 1);
|
||||
if (start == std::string::npos) start = 0;
|
||||
else start += 1;
|
||||
|
||||
// OPTIMIZATION 1: Use find_first_of instead of manual loop - much faster
|
||||
const bool hasWhitespace = (path.find_first_of(" \t\n\r\f\v", start, pos - start) != std::string::npos);
|
||||
|
||||
if (hasWhitespace) {
|
||||
// OPTIMIZATION 2: Pre-allocate exact size and build efficiently
|
||||
const size_t dirNameLen = pos - start;
|
||||
std::string result;
|
||||
result.reserve(dirNameLen + 2); // +2 for quotes
|
||||
|
||||
result = '"';
|
||||
result.append(path, start, dirNameLen);
|
||||
result += '"';
|
||||
return result;
|
||||
} else {
|
||||
return path.substr(start, pos - start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the parent directory path from a given file path.
|
||||
*
|
||||
* @param path The file path from which to extract the parent directory path.
|
||||
* @return The parent directory path.
|
||||
*/
|
||||
std::string getParentDirFromPath(const std::string& path) {
|
||||
const size_t lastSlash = path.find_last_of('/');
|
||||
if (lastSlash != std::string::npos) {
|
||||
return path.substr(0, lastSlash + 1);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets a list of subdirectories in a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the names of subdirectories.
|
||||
*/
|
||||
std::vector<std::string> getSubdirectories(const std::string& directoryPath) {
|
||||
std::vector<std::string> subdirectories;
|
||||
std::unique_ptr<DIR, DirCloser> dir(opendir(directoryPath.c_str()));
|
||||
|
||||
if (!dir) return subdirectories;
|
||||
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir.get())) != nullptr) {
|
||||
const std::string entryName = entry->d_name;
|
||||
|
||||
// Skip . and ..
|
||||
if (entryName == "." || entryName == "..") continue;
|
||||
|
||||
const std::string fullPath = directoryPath + "/" + entryName;
|
||||
|
||||
if (isDirectory(entry, fullPath)) {
|
||||
subdirectories.emplace_back(entryName);
|
||||
}
|
||||
}
|
||||
|
||||
return subdirectories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if a directory entry is a directory (no caching).
|
||||
* Fast path for known types, stat() only when necessary.
|
||||
*/
|
||||
inline bool isDirectory(struct dirent* entry, const std::string& path) {
|
||||
// Fast path - most filesystems populate d_type correctly
|
||||
if (entry->d_type == DT_DIR) {
|
||||
return true;
|
||||
} else if (entry->d_type != DT_UNKNOWN) {
|
||||
return false; // DT_REG, DT_LNK, etc.
|
||||
}
|
||||
|
||||
// Only stat when d_type is unknown (rare on modern filesystems)
|
||||
struct stat entryStat;
|
||||
return (stat(path.c_str(), &entryStat) == 0) && S_ISDIR(entryStat.st_mode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Iteratively retrieves a list of files from a directory.
|
||||
*
|
||||
* @param directoryPath The path of the directory to search.
|
||||
* @return A vector of strings containing the paths of the files.
|
||||
*/
|
||||
std::vector<std::string> getFilesListFromDirectory(const std::string& directoryPath) {
|
||||
std::vector<std::string> fileList;
|
||||
std::vector<std::string> dirsToProcess;
|
||||
|
||||
// Initialize with the starting directory
|
||||
dirsToProcess.emplace_back(directoryPath);
|
||||
|
||||
// Pre-allocate string buffer to avoid repeated allocations
|
||||
std::string fullPath;
|
||||
std::string currentDir;
|
||||
|
||||
size_t dirIndex = 0;
|
||||
while (dirIndex < dirsToProcess.size()) {
|
||||
currentDir = std::move(dirsToProcess[dirIndex]);
|
||||
dirsToProcess[dirIndex].shrink_to_fit();
|
||||
dirIndex++;
|
||||
|
||||
std::unique_ptr<DIR, DirCloser> dir(opendir(currentDir.c_str()));
|
||||
if (!dir) continue;
|
||||
|
||||
// Cache directory path info
|
||||
const bool needsSlash = currentDir.back() != '/';
|
||||
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir.get())) != nullptr) {
|
||||
const char* entryName = entry->d_name;
|
||||
|
||||
// Direct comparison without string creation
|
||||
if (entryName[0] == '.' && (entryName[1] == '\0' || (entryName[1] == '.' && entryName[2] == '\0'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// More efficient path building
|
||||
fullPath.clear();
|
||||
fullPath.assign(currentDir);
|
||||
if (needsSlash) fullPath += '/';
|
||||
fullPath += entryName;
|
||||
|
||||
if (entry->d_type == DT_REG) {
|
||||
// Definitely a regular file
|
||||
fileList.emplace_back(fullPath);
|
||||
} else if (isDirectory(entry, fullPath)) {
|
||||
// Add directory to processing queue
|
||||
dirsToProcess.emplace_back(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fileList;
|
||||
}
|
||||
|
||||
|
||||
// Iterative function to handle wildcard directories and file patterns
|
||||
void handleDirectory(const std::string& basePath,
|
||||
const std::vector<std::string>& parts,
|
||||
size_t partIndex,
|
||||
std::vector<std::string>& results,
|
||||
bool directoryOnly,
|
||||
size_t maxLines) {
|
||||
|
||||
std::vector<std::pair<std::string, size_t>> stack;
|
||||
stack.emplace_back(basePath, partIndex);
|
||||
|
||||
// Pre-declare strings to avoid repeated allocations
|
||||
std::string fullPath;
|
||||
std::string result;
|
||||
std::string currentPath;
|
||||
//fullPath.reserve(512);
|
||||
//result.reserve(512);
|
||||
//currentPath.reserve(512);
|
||||
|
||||
struct stat st;
|
||||
|
||||
bool isDir;
|
||||
//std::string pathRef;
|
||||
size_t currentPartIndex;
|
||||
|
||||
while (!stack.empty()) {
|
||||
if (maxLines > 0 && results.size() >= maxLines) return;
|
||||
|
||||
std::tie(currentPath, currentPartIndex) = stack.back();
|
||||
stack.pop_back();
|
||||
|
||||
// Copy once to avoid repeated access
|
||||
//currentPath = pathRef;
|
||||
|
||||
if (currentPartIndex >= parts.size()) continue;
|
||||
|
||||
DIR* dirPtr = opendir(currentPath.c_str());
|
||||
if (!dirPtr) continue;
|
||||
std::unique_ptr<DIR, DirCloser> dir(dirPtr);
|
||||
|
||||
const std::string& pattern = parts[currentPartIndex];
|
||||
const bool isLastPart = (currentPartIndex == parts.size() - 1);
|
||||
const bool needsSlash = currentPath.back() != '/';
|
||||
|
||||
// Pre-calculate base path for efficiency
|
||||
//const size_t basePathLen = currentPath.length();
|
||||
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir.get())) != nullptr) {
|
||||
if (maxLines > 0 && results.size() >= maxLines) return;
|
||||
|
||||
const char* name = entry->d_name;
|
||||
if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) continue;
|
||||
|
||||
if (fnmatch(pattern.c_str(), name, FNM_NOESCAPE) != 0) continue;
|
||||
|
||||
if (entry->d_type != DT_UNKNOWN) {
|
||||
isDir = (entry->d_type == DT_DIR);
|
||||
} else {
|
||||
// More efficient path building for stat check
|
||||
fullPath.clear();
|
||||
fullPath.assign(currentPath);
|
||||
if (needsSlash) fullPath += '/';
|
||||
fullPath += name;
|
||||
isDir = (stat(fullPath.c_str(), &st) == 0) && S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
if (isLastPart) {
|
||||
if (!directoryOnly || isDir) {
|
||||
// More efficient result building
|
||||
result.clear();
|
||||
result.assign(currentPath);
|
||||
if (needsSlash) result += '/';
|
||||
result += name;
|
||||
if (isDir) result += '/';
|
||||
results.emplace_back(std::move(result));
|
||||
if (maxLines > 0 && results.size() >= maxLines) return;
|
||||
}
|
||||
} else if (isDir) {
|
||||
// More efficient path building for stack
|
||||
fullPath.clear();
|
||||
fullPath.assign(currentPath);
|
||||
if (needsSlash) fullPath += '/';
|
||||
fullPath += name;
|
||||
stack.emplace_back(std::move(fullPath), currentPartIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a list of files and folders based on a wildcard pattern.
|
||||
*
|
||||
* This function searches for files and folders in a directory that match the
|
||||
* specified wildcard pattern.
|
||||
*
|
||||
* @param pathPattern The wildcard pattern to match files and folders.
|
||||
* @return A vector of strings containing the paths of matching files and folders.
|
||||
*/
|
||||
std::vector<std::string> getFilesListByWildcards(const std::string& pathPattern, size_t maxLines) {
|
||||
std::vector<std::string> results;
|
||||
|
||||
if (pathPattern.empty()) return results;
|
||||
|
||||
// Disallow any `/**/` or ending with `/**`
|
||||
if (pathPattern.find("**") != std::string::npos || pathPattern.find("*null") != std::string::npos || pathPattern.find("null*") != std::string::npos) {
|
||||
return results; // Exclude invalid patterns
|
||||
}
|
||||
|
||||
const bool directoryOnly = pathPattern.back() == '/';
|
||||
const size_t prefixEnd = pathPattern.find(":/");
|
||||
|
||||
if (prefixEnd == std::string::npos) return results;
|
||||
|
||||
const std::string basePath = pathPattern.substr(0, prefixEnd + 2);
|
||||
std::vector<std::string> parts;
|
||||
|
||||
size_t start = prefixEnd + 2;
|
||||
size_t pos = start;
|
||||
const size_t pathLen = pathPattern.length();
|
||||
|
||||
while (pos <= pathLen) {
|
||||
if (pos == pathLen || pathPattern[pos] == '/') {
|
||||
if (pos > start) {
|
||||
parts.emplace_back(pathPattern.data() + start, pos - start);
|
||||
}
|
||||
start = pos + 1;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
if (start < pathLen && !directoryOnly) {
|
||||
parts.emplace_back(pathPattern.data() + start, pathLen - start);
|
||||
}
|
||||
|
||||
// Extra: check parsed parts to disallow "**"
|
||||
for (size_t i = 0; i + 1 < parts.size(); ++i) {
|
||||
if (parts[i] == "**" && parts[i + 1] == "**") {
|
||||
return results; // invalid, exclude
|
||||
}
|
||||
}
|
||||
|
||||
if (!parts.empty()) {
|
||||
handleDirectory(basePath, parts, 0, results, directoryOnly, maxLines);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: global_vars.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides the definitions of global constants and paths used
|
||||
* throughout the Ultrahand Overlay project. These constants are essential for
|
||||
* file management and configuration settings within the application.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository:
|
||||
* GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay
|
||||
*
|
||||
* Note: This notice is integral to the project's documentation and must not be
|
||||
* altered or removed.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "global_vars.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
// Base paths
|
||||
const std::string ROOT_PATH = "sdmc:/";
|
||||
const std::string BASE_CONFIG_PATH = ROOT_PATH + "config/ultrahand/";
|
||||
const std::string TESLA_CONFIG_PATH = ROOT_PATH + "config/tesla/";
|
||||
const std::string SWITCH_PATH = ROOT_PATH + "switch/";
|
||||
|
||||
// Filenames
|
||||
CONSTEXPR_STRING std::string CONFIG_FILENAME = "config.ini";
|
||||
const std::string BOOT_PACKAGE_FILENAME = "boot_package.ini";
|
||||
const std::string EXIT_PACKAGE_FILENAME = "exit_package.ini";
|
||||
const std::string PACKAGE_FILENAME = "package.ini";
|
||||
const std::string THEME_FILENAME = "theme.ini";
|
||||
const std::string WALLPAPER_FILENAME = "wallpaper.rgba";
|
||||
const std::string FUSE_FILENAME = "fuse.ini";
|
||||
const std::string OVERLAYS_INI_FILENAME = "overlays.ini";
|
||||
const std::string PACKAGES_INI_FILENAME = "packages.ini";
|
||||
const std::string NOTIFICATIONS_FLAG_FILENAME = "NOTIFICATIONS.flag";
|
||||
|
||||
// Project names
|
||||
CONSTEXPR_STRING std::string ULTRAHAND_PROJECT_NAME = "ultrahand";
|
||||
CONSTEXPR_STRING std::string CAPITAL_ULTRAHAND_PROJECT_NAME = "Ultrahand";
|
||||
CONSTEXPR_STRING std::string SPLIT_PROJECT_NAME_1 = "Ultra";
|
||||
CONSTEXPR_STRING std::string SPLIT_PROJECT_NAME_2 = "hand";
|
||||
|
||||
// Paths
|
||||
const std::string SETTINGS_PATH = BASE_CONFIG_PATH;
|
||||
const std::string ULTRAHAND_CONFIG_INI_PATH = BASE_CONFIG_PATH + CONFIG_FILENAME;
|
||||
const std::string TESLA_CONFIG_INI_PATH = TESLA_CONFIG_PATH + CONFIG_FILENAME;
|
||||
const std::string LANG_PATH = BASE_CONFIG_PATH + "lang/";
|
||||
const std::string THEMES_PATH = BASE_CONFIG_PATH + "themes/";
|
||||
const std::string WALLPAPERS_PATH = BASE_CONFIG_PATH + "wallpapers/";
|
||||
const std::string SOUNDS_PATH = BASE_CONFIG_PATH + "sounds/";
|
||||
const std::string FLAGS_PATH = BASE_CONFIG_PATH + "flags/";
|
||||
const std::string NOTIFICATIONS_PATH = BASE_CONFIG_PATH + "notifications/";
|
||||
const std::string PAYLOADS_PATH = BASE_CONFIG_PATH + "payloads/";
|
||||
const std::string HB_APPSTORE_JSON = SWITCH_PATH + "appstore/.get/packages/UltrahandOverlay/info.json";
|
||||
std::string THEME_CONFIG_INI_PATH = BASE_CONFIG_PATH + THEME_FILENAME;
|
||||
std::string WALLPAPER_PATH = BASE_CONFIG_PATH + WALLPAPER_FILENAME;
|
||||
const std::string DOWNLOADS_PATH = BASE_CONFIG_PATH + "downloads/";
|
||||
const std::string EXPANSION_PATH = BASE_CONFIG_PATH + "expansion/";
|
||||
const std::string FUSE_DATA_INI_PATH = BASE_CONFIG_PATH + FUSE_FILENAME;
|
||||
const std::string PACKAGE_PATH = SWITCH_PATH + ".packages/";
|
||||
const std::string OVERLAY_PATH = SWITCH_PATH + ".overlays/";
|
||||
const std::string OVERLAYS_INI_FILEPATH = BASE_CONFIG_PATH + OVERLAYS_INI_FILENAME;
|
||||
const std::string PACKAGES_INI_FILEPATH = BASE_CONFIG_PATH + PACKAGES_INI_FILENAME;
|
||||
const std::string NOTIFICATIONS_FLAG_FILEPATH = FLAGS_PATH + NOTIFICATIONS_FLAG_FILENAME;
|
||||
|
||||
// Protected files
|
||||
const std::set<std::string> PROTECTED_FILES = {
|
||||
ROOT_PATH + "atmosphere/package3",
|
||||
ROOT_PATH + "atmosphere/stratosphere.romfs"
|
||||
};
|
||||
|
||||
// GitHub URLs
|
||||
const std::string GITHUB_BASE_URL = "https://github.com/ppkantorski/";
|
||||
const std::string GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com/ppkantorski/";
|
||||
const std::string ULTRAHAND_REPO_URL = GITHUB_BASE_URL + "Ultrahand-Overlay/";
|
||||
const std::string INCLUDED_THEME_FOLDER_URL = GITHUB_RAW_BASE_URL + "Ultrahand-Overlay/main/themes/";
|
||||
const std::string LATEST_RELEASE_INFO_URL = GITHUB_RAW_BASE_URL + "Ultrahand-Overlay/main/RELEASE.ini";
|
||||
const std::string NX_OVLLOADER_ZIP_URL = GITHUB_BASE_URL + "nx-ovlloader/releases/latest/download/nx-ovlloader.zip";
|
||||
const std::string NX_OVLLOADER_PLUS_ZIP_URL = GITHUB_BASE_URL + "nx-ovlloader/releases/latest/download/nx-ovlloader+.zip";
|
||||
const std::string OLD_NX_OVLLOADER_ZIP_URL = GITHUB_BASE_URL + "nx-ovlloader/releases/download/v1.0.8/nx-ovlloader.zip";
|
||||
const std::string OLD_NX_OVLLOADER_PLUS_ZIP_URL = GITHUB_BASE_URL + "nx-ovlloader/releases/download/v1.0.8/nx-ovlloader+.zip";
|
||||
const std::string UPDATER_PAYLOAD_URL = GITHUB_RAW_BASE_URL + "Ultrahand-Overlay/main/payloads/ultrahand_updater.bin";
|
||||
const std::string SOUND_EFFECTS_URL = GITHUB_RAW_BASE_URL + "Ultrahand-Overlay/main/sounds/sounds.zip";
|
||||
|
||||
// Launch options
|
||||
const std::string LAUNCH_ARGS_STR = "launch_args";
|
||||
const std::string USE_LAUNCH_ARGS_STR = "use_launch_args";
|
||||
const std::string USE_QUICK_LAUNCH_STR = "use_quick_launch";
|
||||
const std::string USE_BOOT_PACKAGE_STR = "use_boot_package";
|
||||
const std::string USE_EXIT_PACKAGE_STR = "use_exit_package";
|
||||
const std::string USE_LOGGING_STR = "use_logging";
|
||||
|
||||
// Combos
|
||||
CONSTEXPR_STRING std::string TESLA_COMBO_STR = "L+DDOWN+RS";
|
||||
CONSTEXPR_STRING std::string ULTRAHAND_COMBO_STR = "ZL+ZR+DDOWN";
|
||||
|
||||
// System / mode strings
|
||||
CONSTEXPR_STRING std::string FUSE_STR = "fuse";
|
||||
CONSTEXPR_STRING std::string TESLA_STR = "tesla";
|
||||
CONSTEXPR_STRING std::string ERISTA_STR = "erista";
|
||||
CONSTEXPR_STRING std::string MARIKO_STR = "mariko";
|
||||
CONSTEXPR_STRING std::string KEY_COMBO_STR = "key_combo";
|
||||
CONSTEXPR_STRING std::string DEFAULT_LANG_STR = "default_lang";
|
||||
|
||||
// Generic strings
|
||||
CONSTEXPR_STRING std::string LIST_STR = "list";
|
||||
CONSTEXPR_STRING std::string LIST_FILE_STR = "list_file";
|
||||
CONSTEXPR_STRING std::string JSON_STR = "json";
|
||||
CONSTEXPR_STRING std::string JSON_FILE_STR = "json_file";
|
||||
CONSTEXPR_STRING std::string INI_FILE_STR = "ini_file";
|
||||
CONSTEXPR_STRING std::string HEX_FILE_STR = "hex_file";
|
||||
CONSTEXPR_STRING std::string PACKAGE_STR = "package";
|
||||
CONSTEXPR_STRING std::string PACKAGES_STR = "packages";
|
||||
CONSTEXPR_STRING std::string OVERLAY_STR = "overlay";
|
||||
CONSTEXPR_STRING std::string OVERLAYS_STR = "overlays";
|
||||
const std::string IN_OVERLAY_STR = "in_overlay";
|
||||
const std::string IN_HIDDEN_OVERLAY_STR = "in_hidden_overlay";
|
||||
const std::string IN_HIDDEN_PACKAGE_STR = "in_hidden_package";
|
||||
CONSTEXPR_STRING std::string FILE_STR = "file";
|
||||
CONSTEXPR_STRING std::string SYSTEM_STR = "system";
|
||||
CONSTEXPR_STRING std::string MODE_STR = "mode";
|
||||
CONSTEXPR_STRING std::string GROUPING_STR = "grouping";
|
||||
CONSTEXPR_STRING std::string FOOTER_STR = "footer";
|
||||
CONSTEXPR_STRING std::string TOGGLE_STR = "toggle";
|
||||
CONSTEXPR_STRING std::string LEFT_STR = "left";
|
||||
CONSTEXPR_STRING std::string RIGHT_STR = "right";
|
||||
CONSTEXPR_STRING std::string CENTER_STR = "center";
|
||||
CONSTEXPR_STRING std::string HIDE_STR = "hide";
|
||||
CONSTEXPR_STRING std::string STAR_STR = "star";
|
||||
CONSTEXPR_STRING std::string PRIORITY_STR = "priority";
|
||||
CONSTEXPR_STRING std::string ON_STR = "on";
|
||||
CONSTEXPR_STRING std::string OFF_STR = "off";
|
||||
CONSTEXPR_STRING std::string CAPITAL_ON_STR = "On";
|
||||
CONSTEXPR_STRING std::string CAPITAL_OFF_STR = "Off";
|
||||
CONSTEXPR_STRING std::string TRUE_STR = "true";
|
||||
CONSTEXPR_STRING std::string FALSE_STR = "false";
|
||||
CONSTEXPR_STRING std::string GLOBAL_STR = "global";
|
||||
CONSTEXPR_STRING std::string DEFAULT_STR = "default";
|
||||
CONSTEXPR_STRING std::string SLOT_STR = "slot";
|
||||
CONSTEXPR_STRING std::string OPTION_STR = "option";
|
||||
CONSTEXPR_STRING std::string FORWARDER_STR = "forwarder";
|
||||
CONSTEXPR_STRING std::string TEXT_STR = "text";
|
||||
CONSTEXPR_STRING std::string TABLE_STR = "table";
|
||||
CONSTEXPR_STRING std::string TRACKBAR_STR = "trackbar";
|
||||
CONSTEXPR_STRING std::string STEP_TRACKBAR_STR = "step_trackbar";
|
||||
const std::string NAMED_STEP_TRACKBAR_STR = "named_step_trackbar";
|
||||
CONSTEXPR_STRING std::string NULL_STR = "null";
|
||||
CONSTEXPR_STRING std::string THEME_STR = "theme";
|
||||
CONSTEXPR_STRING std::string NOT_AVAILABLE_STR = "Not available";
|
||||
CONSTEXPR_STRING std::string MEMORY_STR = "memory";
|
||||
|
||||
// Pre-defined symbols
|
||||
CONSTEXPR_STRING std::string OPTION_SYMBOL = "\u22EF";
|
||||
CONSTEXPR_STRING std::string DROPDOWN_SYMBOL = "\uE14A";
|
||||
CONSTEXPR_STRING std::string CHECKMARK_SYMBOL = "\uE14B";
|
||||
CONSTEXPR_STRING std::string CROSSMARK_SYMBOL = "\uE14C";
|
||||
CONSTEXPR_STRING std::string DOWNLOAD_SYMBOL = "\u2193";
|
||||
CONSTEXPR_STRING std::string UNZIP_SYMBOL = "\u2191";
|
||||
CONSTEXPR_STRING std::string COPY_SYMBOL = "\u2192";
|
||||
CONSTEXPR_STRING std::string INPROGRESS_SYMBOL = "\u25CF";
|
||||
CONSTEXPR_STRING std::string STAR_SYMBOL = "\u2605";
|
||||
CONSTEXPR_STRING std::string DIVIDER_SYMBOL = "";
|
||||
|
||||
const std::vector<std::string> THROBBER_SYMBOLS = {"", "", "", "", "", "", "", ""};
|
||||
|
||||
// Atomic variables for progress tracking
|
||||
std::atomic<int> displayPercentage(0); // for interpreter percentage progress
|
||||
|
||||
void resetPercentages() {
|
||||
displayPercentage.store(-1, std::memory_order_release);
|
||||
downloadPercentage.store(-1, std::memory_order_release);
|
||||
unzipPercentage.store(-1, std::memory_order_release);
|
||||
copyPercentage.store(-1, std::memory_order_release);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
@@ -1,202 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: haptics.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides implementations for the functions declared in
|
||||
* haptics.hpp. These functions manage haptic feedback for the Ultrahand Overlay
|
||||
* using libnx’s vibration interfaces. It includes routines for initializing
|
||||
* rumble devices, sending vibration patterns, and handling single or double
|
||||
* click feedback with timing control. Thread safety is maintained through
|
||||
* atomic operations and synchronization mechanisms.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2025 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "haptics.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
// ===== Internal state (private to this file) =====
|
||||
//bool rumbleInitialized = false;
|
||||
static HidVibrationDeviceHandle vibHandheld;
|
||||
static HidVibrationDeviceHandle vibPlayer1Left;
|
||||
static HidVibrationDeviceHandle vibPlayer1Right;
|
||||
static u64 rumbleStartTick = 0;
|
||||
static u64 doubleClickTick = 0;
|
||||
static u8 doubleClickPulse = 0;
|
||||
|
||||
// ===== Shared flags (accessible globally) =====
|
||||
std::atomic<bool> rumbleActive{false};
|
||||
std::atomic<bool> doubleClickActive{false};
|
||||
|
||||
// ===== Constants =====
|
||||
static constexpr u64 RUMBLE_DURATION_NS = 30'000'000ULL;
|
||||
static constexpr u64 DOUBLE_CLICK_PULSE_DURATION_NS = 30'000'000ULL;
|
||||
static constexpr u64 DOUBLE_CLICK_GAP_NS = 100'000'000ULL;
|
||||
|
||||
static constexpr HidVibrationValue clickDocked = {
|
||||
.amp_low = 0.20f,
|
||||
.freq_low = 100.0f,
|
||||
.amp_high = 0.80f,
|
||||
.freq_high = 300.0f
|
||||
};
|
||||
|
||||
static constexpr HidVibrationValue clickHandheld = {
|
||||
.amp_low = 0.25f,
|
||||
.freq_low = 100.0f,
|
||||
.amp_high = 1.0f,
|
||||
.freq_high = 300.0f
|
||||
};
|
||||
|
||||
static constexpr HidVibrationValue vibrationStop{0};
|
||||
|
||||
// ===== Internal helpers =====
|
||||
static void initController(HidNpadIdType npad, HidVibrationDeviceHandle* handles, int count) {
|
||||
const u32 styleMask = hidGetNpadStyleSet(npad);
|
||||
if (styleMask)
|
||||
hidInitializeVibrationDevices(handles, count, npad, static_cast<HidNpadStyleTag>(styleMask));
|
||||
}
|
||||
|
||||
static void sendVibration(const HidVibrationValue* value) {
|
||||
if (hidGetNpadStyleSet(HidNpadIdType_Handheld))
|
||||
hidSendVibrationValue(vibHandheld, value);
|
||||
|
||||
if (hidGetNpadStyleSet(HidNpadIdType_No1)) {
|
||||
hidSendVibrationValue(vibPlayer1Left, value);
|
||||
hidSendVibrationValue(vibPlayer1Right, value);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Public API =====
|
||||
void initRumble() {
|
||||
//if (rumbleInitialized) return;
|
||||
|
||||
// Try to initialize whatever is available
|
||||
// Don't check if controllers exist - let initController handle it
|
||||
initController(HidNpadIdType_Handheld, &vibHandheld, 1);
|
||||
|
||||
HidVibrationDeviceHandle handles[2];
|
||||
initController(HidNpadIdType_No1, handles, 2);
|
||||
vibPlayer1Left = handles[0];
|
||||
vibPlayer1Right = handles[1];
|
||||
|
||||
// Only mark as initialized if at least one controller was found
|
||||
hidGetNpadStyleSet(HidNpadIdType_Handheld);
|
||||
hidGetNpadStyleSet(HidNpadIdType_No1);
|
||||
|
||||
//rumbleInitialized = (handheldStyle || player1Style);
|
||||
|
||||
// If neither exist, stay uninitialized so we retry later
|
||||
}
|
||||
|
||||
//void deinitRumble() {
|
||||
// rumbleInitialized = false;
|
||||
//}
|
||||
|
||||
void checkAndReinitRumble() {
|
||||
static u32 lastHandheldStyle = 0;
|
||||
static u32 lastPlayer1Style = 0;
|
||||
|
||||
const u32 currentHandheldStyle = hidGetNpadStyleSet(HidNpadIdType_Handheld);
|
||||
const u32 currentPlayer1Style = hidGetNpadStyleSet(HidNpadIdType_No1);
|
||||
|
||||
// If not initialized but controllers exist, try to init
|
||||
// This handles the boot race condition where HID reports controllers
|
||||
// but vibration subsystem isn't ready yet
|
||||
//if (!rumbleInitialized && (currentHandheldStyle || currentPlayer1Style)) {
|
||||
// initRumble();
|
||||
//}
|
||||
|
||||
// Reinit if controller configuration changed
|
||||
if (currentHandheldStyle != lastHandheldStyle || currentPlayer1Style != lastPlayer1Style) {
|
||||
//rumbleInitialized = false;
|
||||
initRumble();
|
||||
}
|
||||
// Update last style tracking regardless
|
||||
lastHandheldStyle = currentHandheldStyle;
|
||||
lastPlayer1Style = currentPlayer1Style;
|
||||
}
|
||||
|
||||
void rumbleClick() {
|
||||
//if (!rumbleInitialized) {
|
||||
// initRumble();
|
||||
// if (!rumbleInitialized) return;
|
||||
//}
|
||||
|
||||
sendVibration(hidGetNpadStyleSet(HidNpadIdType_Handheld) ? &clickHandheld : &clickDocked);
|
||||
rumbleActive.store(true, std::memory_order_release);
|
||||
rumbleStartTick = armGetSystemTick();
|
||||
}
|
||||
|
||||
void rumbleDoubleClick() {
|
||||
//if (!rumbleInitialized) {
|
||||
// initRumble();
|
||||
// if (!rumbleInitialized) return;
|
||||
//}
|
||||
|
||||
sendVibration(hidGetNpadStyleSet(HidNpadIdType_Handheld) ? &clickHandheld : &clickDocked);
|
||||
doubleClickActive.store(true, std::memory_order_release);
|
||||
doubleClickPulse = 1;
|
||||
doubleClickTick = armGetSystemTick();
|
||||
}
|
||||
|
||||
void processRumbleStop(u64 nowNs) {
|
||||
if (rumbleActive.load(std::memory_order_acquire) &&
|
||||
nowNs - armTicksToNs(rumbleStartTick) >= RUMBLE_DURATION_NS) {
|
||||
sendVibration(&vibrationStop);
|
||||
rumbleActive.store(false, std::memory_order_release);
|
||||
}
|
||||
}
|
||||
|
||||
void processRumbleDoubleClick(u64 nowNs) {
|
||||
if (!doubleClickActive.load(std::memory_order_acquire)) return;
|
||||
|
||||
const u64 elapsed = nowNs - armTicksToNs(doubleClickTick);
|
||||
|
||||
switch (doubleClickPulse) {
|
||||
case 1:
|
||||
if (elapsed >= DOUBLE_CLICK_PULSE_DURATION_NS) {
|
||||
sendVibration(&vibrationStop);
|
||||
doubleClickPulse = 2;
|
||||
doubleClickTick = armGetSystemTick();
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (elapsed >= DOUBLE_CLICK_GAP_NS) {
|
||||
sendVibration(hidGetNpadStyleSet(HidNpadIdType_Handheld) ? &clickHandheld : &clickDocked);
|
||||
doubleClickPulse = 3;
|
||||
doubleClickTick = armGetSystemTick();
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (elapsed >= DOUBLE_CLICK_PULSE_DURATION_NS) {
|
||||
sendVibration(&vibrationStop);
|
||||
doubleClickActive.store(false, std::memory_order_release);
|
||||
doubleClickPulse = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rumbleDoubleClickStandalone() {
|
||||
sendVibration(hidGetNpadStyleSet(HidNpadIdType_Handheld) ? &clickHandheld : &clickDocked);
|
||||
svcSleepThread(DOUBLE_CLICK_PULSE_DURATION_NS);
|
||||
|
||||
sendVibration(&vibrationStop);
|
||||
svcSleepThread(DOUBLE_CLICK_GAP_NS);
|
||||
|
||||
sendVibration(hidGetNpadStyleSet(HidNpadIdType_Handheld) ? &clickHandheld : &clickDocked);
|
||||
svcSleepThread(DOUBLE_CLICK_PULSE_DURATION_NS);
|
||||
|
||||
sendVibration(&vibrationStop);
|
||||
}
|
||||
}
|
||||
@@ -1,881 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: hex_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file implements the functions declared in hex_funcs.hpp.
|
||||
* These functions provide support for manipulating hexadecimal data,
|
||||
* including conversions between ASCII and hexadecimal strings,
|
||||
* locating specific hex patterns within files, and editing file contents
|
||||
* at hex offsets.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "hex_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
size_t HEX_BUFFER_SIZE = 4096;//65536/4;
|
||||
|
||||
// Thread-safe cache and file operation mutexes
|
||||
std::shared_mutex cacheMutex; // Allows multiple readers, single writer
|
||||
std::mutex fileWriteMutex; // Protects file write operations
|
||||
|
||||
// For improving the speed of hexing consecutively with the same file and asciiPattern.
|
||||
std::unordered_map<std::string, std::string> hexSumCache;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Thread-safe cache management functions
|
||||
*/
|
||||
void clearHexSumCache() {
|
||||
std::lock_guard<std::shared_mutex> writeLock(cacheMutex);
|
||||
//hexSumCache.clear();
|
||||
hexSumCache = {};
|
||||
}
|
||||
|
||||
size_t getHexSumCacheSize() {
|
||||
std::shared_lock<std::shared_mutex> readLock(cacheMutex);
|
||||
return hexSumCache.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts an ASCII string to a hexadecimal string.
|
||||
*
|
||||
* This function takes an ASCII string as input and converts it into a hexadecimal string.
|
||||
*
|
||||
* @param asciiStr The ASCII string to convert.
|
||||
* @return The corresponding hexadecimal string.
|
||||
*/
|
||||
|
||||
|
||||
// Function to convert ASCII string to Hex string
|
||||
std::string asciiToHex(const std::string& asciiStr) {
|
||||
std::string hexStr;
|
||||
//hexStr.reserve(asciiStr.length() * 2); // Reserve space for the hexadecimal string
|
||||
|
||||
for (unsigned char c : asciiStr) {
|
||||
hexStr.push_back(hexLookup[c >> 4]); // High nibble
|
||||
hexStr.push_back(hexLookup[c & 0x0F]); // Low nibble
|
||||
}
|
||||
|
||||
return hexStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a fixed-width hexadecimal string.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @param byteGroupSize The number of hex digits to output (must be even for byte alignment).
|
||||
* @return Hex string of exactly 'byteGroupSize' digits, or empty string if value doesn't fit.
|
||||
*/
|
||||
std::string decimalToHex(const std::string& decimalStr, int byteGroupSize) {
|
||||
const int decimalValue = ult::stoi(decimalStr);
|
||||
if (decimalValue < 0 || byteGroupSize <= 0 || (byteGroupSize % 2) != 0) {
|
||||
// Invalid input: negative number, or byteGroupSize <= 0, or odd byteGroupSize
|
||||
return "";
|
||||
}
|
||||
|
||||
// Special case: zero
|
||||
if (decimalValue == 0) {
|
||||
return std::string(byteGroupSize, '0');
|
||||
}
|
||||
|
||||
// Convert decimalValue to hex (uppercase, minimal length)
|
||||
std::string hex;
|
||||
int tempValue = decimalValue;
|
||||
int remainder;
|
||||
char hexChar;
|
||||
while (tempValue > 0) {
|
||||
remainder = tempValue % 16;
|
||||
hexChar = (remainder < 10) ? ('0' + remainder) : ('A' + remainder - 10);
|
||||
hex.insert(hex.begin(), hexChar);
|
||||
tempValue /= 16;
|
||||
}
|
||||
|
||||
// Ensure hex length is even by adding leading zero if needed
|
||||
if (hex.length() % 2 != 0) {
|
||||
hex.insert(hex.begin(), '0');
|
||||
}
|
||||
|
||||
// Minimum size needed to fit hex string
|
||||
const size_t hexLen = hex.length();
|
||||
|
||||
// Adjust minimum byteGroupSize to be at least hexLen
|
||||
size_t minByteGroupSize = std::max(static_cast<size_t>(byteGroupSize), hexLen);
|
||||
|
||||
// If byteGroupSize was too small, adjust to hex length (must be even)
|
||||
if (minByteGroupSize % 2 != 0) {
|
||||
minByteGroupSize++;
|
||||
}
|
||||
|
||||
// If minByteGroupSize is less than hex length, number doesn't fit
|
||||
if (minByteGroupSize < hexLen) {
|
||||
return ""; // can't fit
|
||||
}
|
||||
|
||||
// Pad with leading zeros to match minByteGroupSize
|
||||
if (hexLen < minByteGroupSize) {
|
||||
hex.insert(hex.begin(), minByteGroupSize - hexLen, '0');
|
||||
}
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a hexadecimal string to a decimal string.
|
||||
*
|
||||
* This function takes a hexadecimal string as input and converts it into a decimal string.
|
||||
*
|
||||
* @param hexStr The hexadecimal string to convert.
|
||||
* @return The corresponding decimal string.
|
||||
*/
|
||||
std::string hexToDecimal(const std::string& hexStr) {
|
||||
// Convert hexadecimal string to integer
|
||||
int decimalValue = 0;
|
||||
const size_t len = hexStr.length();
|
||||
|
||||
char hexChar;
|
||||
int value;
|
||||
|
||||
// Iterate over each character in the hexadecimal string
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
hexChar = hexStr[i];
|
||||
//int value;
|
||||
|
||||
// Convert hex character to its decimal value
|
||||
if (hexChar >= '0' && hexChar <= '9') {
|
||||
value = hexChar - '0';
|
||||
} else if (hexChar >= 'A' && hexChar <= 'F') {
|
||||
value = 10 + (hexChar - 'A');
|
||||
} else if (hexChar >= 'a' && hexChar <= 'f') {
|
||||
value = 10 + (hexChar - 'a');
|
||||
} else {
|
||||
break;
|
||||
//throw std::invalid_argument("Invalid hexadecimal character");
|
||||
}
|
||||
|
||||
// Update the decimal value
|
||||
decimalValue = decimalValue * 16 + value;
|
||||
}
|
||||
|
||||
// Convert the decimal value to a string
|
||||
return ult::to_string(decimalValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string hexToReversedHex(const std::string& hexadecimal, int order) {
|
||||
// Reverse the hexadecimal string in groups of order
|
||||
std::string reversedHex;
|
||||
for (int i = hexadecimal.length() - order; i >= 0; i -= order) {
|
||||
reversedHex += hexadecimal.substr(i, order);
|
||||
}
|
||||
|
||||
return reversedHex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts a decimal string to a reversed hexadecimal string.
|
||||
*
|
||||
* This function takes a decimal string as input, converts it into a hexadecimal
|
||||
* string, and reverses the resulting hexadecimal string in groups of byteGroupSize.
|
||||
*
|
||||
* @param decimalStr The decimal string to convert.
|
||||
* @param byteGroupSize The grouping byteGroupSize for reversing the hexadecimal string.
|
||||
* @return The reversed hexadecimal string.
|
||||
*/
|
||||
std::string decimalToReversedHex(const std::string& decimalStr, int byteGroupSize) {
|
||||
//std::string hexadecimal = decimalToHex(decimalStr, byteGroupSize);
|
||||
|
||||
// Reverse the hexadecimal string in groups of byteGroupSize
|
||||
//std::string reversedHex;
|
||||
//for (int i = hexadecimal.length() - byteGroupSize; i >= 0; i -= byteGroupSize) {
|
||||
// reversedHex += hexadecimal.substr(i, byteGroupSize);
|
||||
//}
|
||||
|
||||
return hexToReversedHex(decimalToHex(decimalStr, byteGroupSize));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds the offsets of hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and returns the file offsets where the data is found.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexData The hexadecimal data to search for.
|
||||
* @return A vector of strings containing the file offsets where the data is found.
|
||||
*/
|
||||
std::vector<std::string> findHexDataOffsets(const std::string& filePath, const std::string& hexData) {
|
||||
std::vector<std::string> offsets;
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (!file) {
|
||||
return offsets;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
const size_t fileSize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
std::vector<unsigned char> binaryData;
|
||||
if (hexData.length() % 2 != 0) {
|
||||
fclose(file);
|
||||
return offsets;
|
||||
}
|
||||
|
||||
|
||||
const size_t hexLen = hexData.length();
|
||||
binaryData.resize(hexLen / 2);
|
||||
const unsigned char* hexPtr = reinterpret_cast<const unsigned char*>(hexData.c_str());
|
||||
|
||||
// Unrolled hex conversion loop
|
||||
size_t i = 0;
|
||||
for (; i + 4 <= hexLen; i += 4) {
|
||||
binaryData[i/2] = (hexTable[hexPtr[i]] << 4) | hexTable[hexPtr[i + 1]];
|
||||
binaryData[i/2 + 1] = (hexTable[hexPtr[i + 2]] << 4) | hexTable[hexPtr[i + 3]];
|
||||
}
|
||||
// Handle remaining bytes
|
||||
for (; i < hexLen; i += 2) {
|
||||
binaryData[i/2] = (hexTable[hexPtr[i]] << 4) | hexTable[hexPtr[i + 1]];
|
||||
}
|
||||
|
||||
// Optimized search variables
|
||||
const unsigned char* patternPtr = binaryData.data();
|
||||
const size_t patternLen = binaryData.size();
|
||||
const unsigned char firstByte = patternPtr[0];
|
||||
|
||||
std::vector<unsigned char> buffer(HEX_BUFFER_SIZE);
|
||||
size_t bytesRead = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
|
||||
while ((bytesRead = fread(buffer.data(), 1, HEX_BUFFER_SIZE, file)) > 0) {
|
||||
const unsigned char* bufPtr = buffer.data();
|
||||
|
||||
// Optimized search with first-byte filtering and loop unrolling
|
||||
i = 0;
|
||||
const size_t searchEnd = bytesRead;
|
||||
|
||||
// Process 4 bytes at a time for better cache usage
|
||||
for (; i + 4 <= searchEnd; i += 4) {
|
||||
// Check 4 positions at once
|
||||
if (bufPtr[i] == firstByte) {
|
||||
if (offset + i + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 1] == firstByte) {
|
||||
if (offset + i + 1 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 1, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 1));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 2] == firstByte) {
|
||||
if (offset + i + 2 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 2, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 2));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 3] == firstByte) {
|
||||
if (offset + i + 3 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 3, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle remaining bytes
|
||||
for (; i < searchEnd; ++i) {
|
||||
if (bufPtr[i] == firstByte) {
|
||||
if (offset + i + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
offset += bytesRead;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
#else
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
return offsets;
|
||||
}
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
const size_t fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<unsigned char> binaryData;
|
||||
if (hexData.length() % 2 != 0) {
|
||||
file.close();
|
||||
return offsets;
|
||||
}
|
||||
|
||||
|
||||
const size_t hexLen = hexData.length();
|
||||
binaryData.resize(hexLen / 2);
|
||||
const unsigned char* hexPtr = reinterpret_cast<const unsigned char*>(hexData.c_str());
|
||||
|
||||
size_t i = 0;
|
||||
for (; i + 4 <= hexLen; i += 4) {
|
||||
binaryData[i/2] = (hexTable[hexPtr[i]] << 4) | hexTable[hexPtr[i + 1]];
|
||||
binaryData[i/2 + 1] = (hexTable[hexPtr[i + 2]] << 4) | hexTable[hexPtr[i + 3]];
|
||||
}
|
||||
for (; i < hexLen; i += 2) {
|
||||
binaryData[i/2] = (hexTable[hexPtr[i]] << 4) | hexTable[hexPtr[i + 1]];
|
||||
}
|
||||
|
||||
const unsigned char* patternPtr = binaryData.data();
|
||||
const size_t patternLen = binaryData.size();
|
||||
const unsigned char firstByte = patternPtr[0];
|
||||
|
||||
std::vector<unsigned char> buffer(HEX_BUFFER_SIZE);
|
||||
size_t bytesRead = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
while (file.read(reinterpret_cast<char*>(buffer.data()), HEX_BUFFER_SIZE) || file.gcount() > 0) {
|
||||
bytesRead = file.gcount();
|
||||
const unsigned char* bufPtr = buffer.data();
|
||||
|
||||
// Same optimized search as FILE* version
|
||||
i = 0;
|
||||
const size_t searchEnd = bytesRead;
|
||||
|
||||
for (; i + 4 <= searchEnd; i += 4) {
|
||||
if (bufPtr[i] == firstByte) {
|
||||
if (offset + i + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 1] == firstByte) {
|
||||
if (offset + i + 1 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 1, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 1));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 2] == firstByte) {
|
||||
if (offset + i + 2 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 2, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 2));
|
||||
}
|
||||
}
|
||||
if (bufPtr[i + 3] == firstByte) {
|
||||
if (offset + i + 3 + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i + 3, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i + 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < searchEnd; ++i) {
|
||||
if (bufPtr[i] == firstByte) {
|
||||
if (offset + i + patternLen <= fileSize &&
|
||||
memcmp(bufPtr + i, patternPtr, patternLen) == 0) {
|
||||
offsets.emplace_back(ult::to_string(offset + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
offset += bytesRead;
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Edits hexadecimal data in a file at a specified offset.
|
||||
*
|
||||
* This function opens a binary file, seeks to a specified offset, and replaces
|
||||
* the data at that offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The offset in the file to perform the edit.
|
||||
* @param hexData The hexadecimal data to replace at the offset.
|
||||
*/
|
||||
void hexEditByOffset(const std::string& filePath, const std::string& offsetStr, const std::string& hexData) {
|
||||
// Lock file writes to prevent concurrent modifications to the same file
|
||||
std::lock_guard<std::mutex> fileWriteLock(fileWriteMutex);
|
||||
|
||||
const std::streampos offset = std::stoll(offsetStr);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Open the file for both reading and writing in binary mode
|
||||
FILE* file = fopen(filePath.c_str(), "rb+");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open the file.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve the file size
|
||||
fseek(file, 0, SEEK_END);
|
||||
const std::streampos fileSize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
if (offset >= fileSize) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Offset exceeds file size.");
|
||||
#endif
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the hex string to binary data
|
||||
std::vector<unsigned char> binaryData(hexData.length() / 2);
|
||||
std::string byteString;
|
||||
for (size_t i = 0, j = 0; i < hexData.length(); i += 2, ++j) {
|
||||
byteString = hexData.substr(i, 2);
|
||||
binaryData[j] = static_cast<unsigned char>(ult::stoi(byteString, nullptr, 16));
|
||||
}
|
||||
|
||||
// Move to the specified offset and write the binary data directly to the file
|
||||
fseek(file, offset, SEEK_SET);
|
||||
const size_t bytesWritten = fwrite(binaryData.data(), sizeof(unsigned char), binaryData.size(), file);
|
||||
if (bytesWritten != binaryData.size()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to write data to the file.");
|
||||
#endif
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
// Open the file for both reading and writing in binary mode
|
||||
std::fstream file(filePath, std::ios::binary | std::ios::in | std::ios::out);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open the file.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve the file size
|
||||
file.seekg(0, std::ios::end);
|
||||
const std::streampos fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
if (offset >= fileSize) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Offset exceeds file size.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the hex string to binary data
|
||||
std::vector<unsigned char> binaryData(hexData.length() / 2);
|
||||
std::string byteString;
|
||||
for (size_t i = 0, j = 0; i < hexData.length(); i += 2, ++j) {
|
||||
byteString = hexData.substr(i, 2);
|
||||
binaryData[j] = static_cast<unsigned char>(ult::stoi(byteString, nullptr, 16));
|
||||
}
|
||||
|
||||
// Move to the specified offset and write the binary data directly to the file
|
||||
file.seekp(offset);
|
||||
file.write(reinterpret_cast<const char*>(binaryData.data()), binaryData.size());
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to write data to the file.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Edits a specific offset in a file with custom hexadecimal data.
|
||||
*
|
||||
* This function searches for a custom pattern in the file and calculates a new offset
|
||||
* based on user-provided offsetStr and the found pattern. It then replaces the data
|
||||
* at the calculated offset with the provided hexadecimal data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param offsetStr The user-provided offset for the edit.
|
||||
* @param customPattern The custom pattern to search for in the file.
|
||||
* @param hexDataReplacement The hexadecimal data to replace at the calculated offset.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditByCustomOffset(const std::string& filePath, const std::string& customAsciiPattern, const std::string& offsetStr, const std::string& hexDataReplacement, size_t occurrence) {
|
||||
|
||||
// Create a cache key based on filePath and customAsciiPattern
|
||||
const std::string cacheKey = filePath + '?' + customAsciiPattern + '?' + ult::to_string(occurrence);
|
||||
|
||||
int hexSum = -1;
|
||||
|
||||
// Thread-safe cache access
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> readLock(cacheMutex);
|
||||
const auto cachedResult = hexSumCache.find(cacheKey);
|
||||
if (cachedResult != hexSumCache.end()) {
|
||||
hexSum = ult::stoi(cachedResult->second);
|
||||
}
|
||||
}
|
||||
|
||||
if (hexSum == -1) {
|
||||
std::string customHexPattern;
|
||||
if (customAsciiPattern[0] == '#') {
|
||||
// remove #
|
||||
customHexPattern = customAsciiPattern.substr(1);
|
||||
} else {
|
||||
// Convert custom ASCII pattern to a custom hex pattern
|
||||
customHexPattern = asciiToHex(customAsciiPattern);
|
||||
}
|
||||
|
||||
|
||||
// Find hex data offsets in the file
|
||||
const std::vector<std::string> offsets = findHexDataOffsets(filePath, customHexPattern);
|
||||
|
||||
if (!offsets.empty()) {
|
||||
hexSum = ult::stoi(offsets[occurrence]);
|
||||
|
||||
// Thread-safe cache write
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> writeLock(cacheMutex);
|
||||
hexSumCache[cacheKey] = ult::to_string(hexSum);
|
||||
}
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Offset not found.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hexSum != -1) {
|
||||
// Calculate the total offset to seek in the file
|
||||
//int sum = hexSum + ult::stoi(offsetStr);
|
||||
hexEditByOffset(filePath, ult::to_string(hexSum + ult::stoi(offsetStr)), hexDataReplacement);
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to find " + customAsciiPattern + ".");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
void hexEditFindReplace(const std::string& filePath, const std::string& hexDataToReplace, const std::string& hexDataReplacement, size_t occurrence) {
|
||||
const std::vector<std::string> offsetStrs = findHexDataOffsets(filePath, hexDataToReplace);
|
||||
if (!offsetStrs.empty()) {
|
||||
if (occurrence == 0) {
|
||||
// Replace all occurrences
|
||||
for (const std::string& offsetStr : offsetStrs) {
|
||||
//logMessage("offsetStr: "+offsetStr);
|
||||
//logMessage("hexDataReplacement: "+hexDataReplacement);
|
||||
hexEditByOffset(filePath, offsetStr, hexDataReplacement);
|
||||
}
|
||||
} else {
|
||||
// Convert the occurrence string to an integer
|
||||
if (occurrence > 0 && occurrence <= offsetStrs.size()) {
|
||||
// Replace the specified occurrence/index
|
||||
//std::string offsetStr = offsetStrs[occurrence - 1];
|
||||
//logMessage("offsetStr: "+offsetStr);
|
||||
//logMessage("hexDataReplacement: "+hexDataReplacement);
|
||||
hexEditByOffset(filePath, offsetStrs[occurrence - 1], hexDataReplacement);
|
||||
} else {
|
||||
// Invalid occurrence/index specified
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Invalid hex occurrence/index specified.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
//std::cout << "Hex data replaced successfully." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
std::string parseHexDataAtCustomOffset(const std::string& filePath, const std::string& customAsciiPattern,
|
||||
const std::string& offsetStr, size_t length, size_t occurrence) {
|
||||
const std::string cacheKey = filePath + '?' + customAsciiPattern + '?' + ult::to_string(occurrence);
|
||||
int hexSum = -1;
|
||||
|
||||
// Thread-safe cache read
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> readLock(cacheMutex);
|
||||
const auto cachedResult = hexSumCache.find(cacheKey);
|
||||
if (cachedResult != hexSumCache.end()) {
|
||||
hexSum = ult::stoi(cachedResult->second);
|
||||
}
|
||||
}
|
||||
|
||||
if (hexSum == -1) {
|
||||
const std::string customHexPattern = asciiToHex(customAsciiPattern);
|
||||
const std::vector<std::string> offsets = findHexDataOffsets(filePath, customHexPattern);
|
||||
|
||||
if (!offsets.empty() && offsets.size() > occurrence) {
|
||||
hexSum = ult::stoi(offsets[occurrence]);
|
||||
|
||||
// Thread-safe cache write
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> writeLock(cacheMutex);
|
||||
hexSumCache[cacheKey] = ult::to_string(hexSum);
|
||||
}
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Offset not found.");
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const std::streampos totalOffset = hexSum + std::stoll(offsetStr);
|
||||
std::vector<char> hexBuffer(length);
|
||||
std::vector<char> hexStream(length * 2);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open the file.");
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
if (fseek(file, totalOffset, SEEK_SET) != 0) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error seeking to offset.");
|
||||
#endif
|
||||
fclose(file);
|
||||
return "";
|
||||
}
|
||||
|
||||
const size_t bytesRead = fread(hexBuffer.data(), sizeof(char), length, file);
|
||||
if (bytesRead == length) {
|
||||
static constexpr char hexDigits[] = "0123456789ABCDEF";
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
hexStream[i * 2] = hexDigits[(hexBuffer[i] >> 4) & 0xF];
|
||||
hexStream[i * 2 + 1] = hexDigits[hexBuffer[i] & 0xF];
|
||||
}
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error reading data from file or end of file reached.");
|
||||
#endif
|
||||
fclose(file);
|
||||
return "";
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open the file.");
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
file.seekg(totalOffset);
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error seeking to offset.");
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
file.read(hexBuffer.data(), length);
|
||||
if (file.gcount() == static_cast<std::streamsize>(length)) {
|
||||
static constexpr char hexDigits[] = "0123456789ABCDEF";
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
hexStream[i * 2] = hexDigits[(hexBuffer[i] >> 4) & 0xF];
|
||||
hexStream[i * 2 + 1] = hexDigits[hexBuffer[i] & 0xF];
|
||||
}
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error reading data from file or end of file reached.");
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
std::string result(hexStream.begin(), hexStream.end());
|
||||
result = stringToUppercase(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds and replaces hexadecimal data in a file.
|
||||
*
|
||||
* This function searches for occurrences of hexadecimal data in a binary file
|
||||
* and replaces them with a specified hexadecimal replacement data.
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @param hexDataToReplace The hexadecimal data to search for and replace.
|
||||
* @param hexDataReplacement The hexadecimal data to replace with.
|
||||
* @param occurrence The occurrence/index of the data to replace (default is "0" to replace all occurrences).
|
||||
*/
|
||||
|
||||
std::string replaceHexPlaceholder(const std::string& arg, const std::string& hexPath) {
|
||||
std::string replacement = arg;
|
||||
const std::string searchString = "{hex_file(";
|
||||
|
||||
const size_t startPos = replacement.find(searchString);
|
||||
const size_t endPos = replacement.find(")}");
|
||||
|
||||
if (startPos != std::string::npos && endPos != std::string::npos && endPos > startPos) {
|
||||
const std::string placeholderContent = replacement.substr(startPos + searchString.length(), endPos - startPos - searchString.length());
|
||||
|
||||
// Split the placeholder content into its components (customAsciiPattern, offsetStr, length)
|
||||
std::vector<std::string> components;
|
||||
|
||||
// Use StringStream instead of std::istringstream
|
||||
StringStream componentStream(placeholderContent);
|
||||
std::string component;
|
||||
|
||||
while (componentStream.getline(component, ',')) {
|
||||
trim(component);
|
||||
components.push_back(component);
|
||||
}
|
||||
|
||||
if (components.size() == 3) {
|
||||
// Extract individual components
|
||||
const std::string customAsciiPattern = components[0];
|
||||
const std::string offsetStr = components[1];
|
||||
const size_t length = std::stoul(components[2]);
|
||||
|
||||
// Call the parsing function and replace the placeholder
|
||||
const std::string parsedResult = parseHexDataAtCustomOffset(hexPath, customAsciiPattern, offsetStr, length);
|
||||
|
||||
// Only replace if parsedResult returns a non-empty string
|
||||
if (!parsedResult.empty()) {
|
||||
// Replace the entire placeholder with the parsed result
|
||||
replacement.replace(startPos, endPos - startPos + searchString.length() + 2, parsedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return replacement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the version string from a binary file.
|
||||
*
|
||||
* This function reads a binary file and searches for a version pattern
|
||||
* in the format "v#.#.#" (e.g., "v1.2.3").
|
||||
*
|
||||
* @param filePath The path to the binary file.
|
||||
* @return The version string if found; otherwise, an empty string.
|
||||
*/
|
||||
std::string extractVersionFromBinary(const std::string &filePath) {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Step 1: Open the binary file
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (!file) {
|
||||
return ""; // Return empty string if file cannot be opened
|
||||
}
|
||||
|
||||
// Get the file size
|
||||
fseek(file, 0, SEEK_END);
|
||||
const std::streamsize size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// Read the entire file into a buffer
|
||||
std::vector<uint8_t> buffer(size);
|
||||
const size_t bytesRead = fread(buffer.data(), sizeof(uint8_t), size, file);
|
||||
fclose(file); // Close the file after reading
|
||||
|
||||
if (bytesRead != static_cast<size_t>(size)) {
|
||||
return ""; // Return empty string if reading fails
|
||||
}
|
||||
#else
|
||||
// Step 1: Read the entire binary file into a vector
|
||||
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open()) {
|
||||
return ""; // Return empty string if file cannot be opened
|
||||
}
|
||||
|
||||
const std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<uint8_t> buffer(size);
|
||||
if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
|
||||
return ""; // Return empty string if reading fails
|
||||
}
|
||||
#endif
|
||||
|
||||
// Step 2: Search for the pattern "v#.#.#"
|
||||
const char* data = reinterpret_cast<const char*>(buffer.data());
|
||||
for (std::streamsize i = 0; i < size; ++i) {
|
||||
if (data[i] == 'v' && i + 5 < size &&
|
||||
std::isdigit(data[i + 1]) && data[i + 2] == '.' &&
|
||||
std::isdigit(data[i + 3]) && data[i + 4] == '.' &&
|
||||
std::isdigit(data[i + 5])) {
|
||||
|
||||
// Extract the version string
|
||||
return std::string(data + i, 6); // Return the version string
|
||||
}
|
||||
}
|
||||
|
||||
return ""; // Return empty string if no match is found
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,400 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: json_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides functions for working with JSON files in C++ using
|
||||
* the `cJSON` library. It includes a function to read JSON data from a file.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "json_funcs.hpp"
|
||||
|
||||
|
||||
namespace ult {
|
||||
|
||||
static std::mutex json_access_mutex;
|
||||
|
||||
/**
|
||||
* @brief Reads JSON data from a file and returns it as a `json_t` object.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @return A `json_t` object representing the parsed JSON data. Returns `nullptr` on error.
|
||||
*/
|
||||
json_t* readJsonFromFile(const std::string& filePath) {
|
||||
std::lock_guard<std::mutex> lock(json_access_mutex);
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (!file) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get file size
|
||||
fseek(file, 0, SEEK_END);
|
||||
const long fileSize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// Check for reasonable file size
|
||||
if (fileSize <= 0 || fileSize > 6 * 1024 * 1024) { // 6MB limit
|
||||
fclose(file);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Use vector<char> for better performance and explicit null termination
|
||||
std::vector<char> buffer;
|
||||
buffer.resize(static_cast<size_t>(fileSize) + 1); // +1 for null terminator
|
||||
|
||||
// Read the file in one operation
|
||||
const size_t bytesRead = fread(buffer.data(), 1, static_cast<size_t>(fileSize), file);
|
||||
fclose(file);
|
||||
|
||||
if (bytesRead != static_cast<size_t>(fileSize)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Ensure null termination for cJSON
|
||||
buffer[bytesRead] = '\0';
|
||||
|
||||
#else
|
||||
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get file size from current position (end)
|
||||
const std::streampos fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
// Check for reasonable file size
|
||||
if (fileSize <= 0 || fileSize > 6 * 1024 * 1024) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Use vector<char> for better performance and explicit null termination
|
||||
std::vector<char> buffer;
|
||||
buffer.resize(static_cast<size_t>(fileSize) + 1); // +1 for null terminator
|
||||
|
||||
file.read(buffer.data(), static_cast<std::streamsize>(fileSize));
|
||||
|
||||
// Check how much was actually read
|
||||
std::streamsize actualRead = file.gcount();
|
||||
if (actualRead != fileSize) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Ensure null termination for cJSON
|
||||
buffer[actualRead] = '\0';
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
// Parse the JSON content - pass buffer directly to avoid string copy
|
||||
cJSON* root = cJSON_Parse(buffer.data());
|
||||
if (!root) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
const char* error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr) {
|
||||
if (!disableLogging)
|
||||
logMessage("JSON parsing error: " + std::string(error_ptr));
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return reinterpret_cast<json_t*>(root);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parses a JSON string into a json_t object.
|
||||
*
|
||||
* This function takes a JSON string as input and parses it into a json_t object using cJSON library's `cJSON_Parse` function.
|
||||
* If parsing fails, it logs the error and returns nullptr.
|
||||
*
|
||||
* @param input The input JSON string to parse.
|
||||
* @return A json_t object representing the parsed JSON, or nullptr if parsing fails.
|
||||
*/
|
||||
json_t* stringToJson(const std::string& input) {
|
||||
cJSON* jsonObj = cJSON_Parse(input.c_str());
|
||||
|
||||
if (!jsonObj) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
const char* error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != nullptr) {
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to parse JSON: " + std::string(error_ptr));
|
||||
}
|
||||
#endif
|
||||
return nullptr; // Return nullptr to indicate failure clearly
|
||||
}
|
||||
|
||||
return reinterpret_cast<json_t*>(jsonObj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Function to get a string from a JSON object
|
||||
std::string getStringFromJson(const json_t* root, const char* key) {
|
||||
const cJSON* croot = reinterpret_cast<const cJSON*>(root);
|
||||
const cJSON* value = cJSON_GetObjectItemCaseSensitive(croot, key);
|
||||
if (value && cJSON_IsString(value) && value->valuestring) {
|
||||
return value->valuestring;
|
||||
} else {
|
||||
return ""; // Key not found or not a string, return empty string/char*
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads a JSON file from the specified path and retrieves a string value for a given key.
|
||||
*
|
||||
* This function combines the functionality of loading a JSON file and retrieving a string value associated
|
||||
* with a given key in a single step.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key whose associated string value is to be retrieved.
|
||||
* @return A string containing the value associated with the given key, or an empty string if the key is not found.
|
||||
*/
|
||||
std::string getStringFromJsonFile(const std::string& filePath, const std::string& key) {
|
||||
// Load JSON from file using a smart pointer
|
||||
std::unique_ptr<json_t, JsonDeleter> root(readJsonFromFile(filePath), JsonDeleter());
|
||||
if (!root) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage("Failed to load JSON file from path: " + filePath);
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
// Retrieve the string value associated with the key
|
||||
cJSON* croot = reinterpret_cast<cJSON*>(root.get());
|
||||
cJSON* jsonKey = cJSON_GetObjectItemCaseSensitive(croot, key.c_str());
|
||||
const char* value = (cJSON_IsString(jsonKey) && jsonKey->valuestring) ? jsonKey->valuestring : nullptr;
|
||||
|
||||
// Check if the value was found and return it
|
||||
if (value) {
|
||||
return std::string(value);
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage("Key not found or not a string in JSON: " + key);
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in a JSON file, creating the file if it doesn't exist.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param key The key to set.
|
||||
* @param value The value to set (auto-detected type).
|
||||
* @param createIfNotExists Whether to create the file if it doesn't exist.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool setJsonValue(const std::string& filePath, const std::string& key, const std::string& value, bool createIfNotExists) {
|
||||
// Try to load existing file
|
||||
std::unique_ptr<json_t, JsonDeleter> root(readJsonFromFile(filePath), JsonDeleter());
|
||||
|
||||
cJSON* croot = nullptr;
|
||||
|
||||
// If file doesn't exist, create new JSON object if allowed
|
||||
if (!root) {
|
||||
if (!createIfNotExists) {
|
||||
return false;
|
||||
}
|
||||
croot = cJSON_CreateObject();
|
||||
if (!croot) {
|
||||
return false;
|
||||
}
|
||||
root.reset(reinterpret_cast<json_t*>(croot));
|
||||
} else {
|
||||
croot = reinterpret_cast<cJSON*>(root.get());
|
||||
}
|
||||
|
||||
// FIXED: Better value type detection
|
||||
cJSON* jsonValue = nullptr;
|
||||
|
||||
// Trim whitespace first
|
||||
std::string trimmedValue = value;
|
||||
// Remove leading whitespace
|
||||
trimmedValue.erase(0, trimmedValue.find_first_not_of(" \t\n\r"));
|
||||
// Remove trailing whitespace
|
||||
trimmedValue.erase(trimmedValue.find_last_not_of(" \t\n\r") + 1);
|
||||
|
||||
if (trimmedValue.empty()) {
|
||||
jsonValue = cJSON_CreateString("");
|
||||
} else if (trimmedValue == "true") {
|
||||
jsonValue = cJSON_CreateBool(1);
|
||||
} else if (trimmedValue == "false") {
|
||||
jsonValue = cJSON_CreateBool(0);
|
||||
} else if (trimmedValue == "null") {
|
||||
jsonValue = cJSON_CreateNull();
|
||||
} else {
|
||||
// Try parsing as number (integer or float)
|
||||
char* endPtr = nullptr;
|
||||
errno = 0;
|
||||
|
||||
// Try as integer first
|
||||
const long longValue = std::strtol(trimmedValue.c_str(), &endPtr, 10);
|
||||
if (endPtr == trimmedValue.c_str() + trimmedValue.length() && errno == 0) {
|
||||
// Successfully parsed as integer
|
||||
jsonValue = cJSON_CreateNumber(static_cast<double>(longValue));
|
||||
} else {
|
||||
// Try as float
|
||||
endPtr = nullptr;
|
||||
errno = 0;
|
||||
const double doubleValue = std::strtod(trimmedValue.c_str(), &endPtr);
|
||||
if (endPtr == trimmedValue.c_str() + trimmedValue.length() && errno == 0) {
|
||||
// Successfully parsed as float
|
||||
jsonValue = cJSON_CreateNumber(doubleValue);
|
||||
} else {
|
||||
// Treat as string
|
||||
jsonValue = cJSON_CreateString(trimmedValue.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!jsonValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete existing item if it exists
|
||||
cJSON_DeleteItemFromObject(croot, key.c_str());
|
||||
|
||||
// Add the new value
|
||||
cJSON_AddItemToObject(croot, key.c_str(), jsonValue);
|
||||
|
||||
// Save to file with formatted output for better readability
|
||||
char* jsonString = cJSON_Print(croot); // Use formatted output instead of PrintUnformatted
|
||||
if (!jsonString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(json_access_mutex);
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "w"); // Use text mode for JSON
|
||||
if (file) {
|
||||
const size_t jsonLength = std::strlen(jsonString);
|
||||
const size_t bytesWritten = fwrite(jsonString, 1, jsonLength, file);
|
||||
success = (bytesWritten == jsonLength);
|
||||
fclose(file);
|
||||
}
|
||||
#else
|
||||
std::ofstream file(filePath); // Use text mode for JSON
|
||||
if (file.is_open()) {
|
||||
file << jsonString;
|
||||
success = !file.fail();
|
||||
file.close();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cJSON_free(jsonString);
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Renames a key in a JSON file.
|
||||
*
|
||||
* @param filePath The path to the JSON file.
|
||||
* @param oldKey The current key name.
|
||||
* @param newKey The new key name.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool renameJsonKey(const std::string& filePath, const std::string& oldKey, const std::string& newKey) {
|
||||
// Try to load existing file
|
||||
std::unique_ptr<json_t, JsonDeleter> root(readJsonFromFile(filePath), JsonDeleter());
|
||||
|
||||
if (!root) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON* croot = reinterpret_cast<cJSON*>(root.get());
|
||||
|
||||
// Check if old key exists
|
||||
cJSON* value = cJSON_GetObjectItemCaseSensitive(croot, oldKey.c_str());
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Detach the value from the object
|
||||
cJSON_DetachItemFromObject(croot, oldKey.c_str());
|
||||
|
||||
// Add it back with the new key
|
||||
cJSON_AddItemToObject(croot, newKey.c_str(), value);
|
||||
|
||||
// Save to file
|
||||
char* jsonString = cJSON_Print(croot); // Use formatted output
|
||||
if (!jsonString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(json_access_mutex);
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "w"); // Use text mode
|
||||
if (file) {
|
||||
const size_t jsonLength = std::strlen(jsonString);
|
||||
const size_t bytesWritten = fwrite(jsonString, 1, jsonLength, file);
|
||||
success = (bytesWritten == jsonLength);
|
||||
fclose(file);
|
||||
}
|
||||
#else
|
||||
std::ofstream file(filePath); // Use text mode
|
||||
if (file.is_open()) {
|
||||
file << jsonString;
|
||||
success = !file.fail();
|
||||
file.close();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cJSON_free(jsonString);
|
||||
return success;
|
||||
}
|
||||
|
||||
void pushNotificationJson(const std::string& appID, const std::string& text, size_t fontSize) {
|
||||
u64 tick = armGetSystemTick();
|
||||
std::string filename = appID + "-" + std::to_string(tick) + ".notify"; // priority 20 default
|
||||
|
||||
// Build full path
|
||||
const std::string fullPath = NOTIFICATIONS_PATH + filename;
|
||||
|
||||
// Create JSON object
|
||||
cJSON* notif = cJSON_CreateObject();
|
||||
if (!notif) return;
|
||||
|
||||
cJSON_AddStringToObject(notif, "text", text.c_str());
|
||||
cJSON_AddNumberToObject(notif, "font_size", static_cast<double>(fontSize));
|
||||
//cJSON_AddNumberToObject(notif, "arrival_ns", static_cast<double>(armTicksToNs(tick)));
|
||||
|
||||
// Serialize JSON
|
||||
char* rendered = cJSON_PrintUnformatted(notif);
|
||||
if (!rendered) {
|
||||
cJSON_Delete(notif);
|
||||
return;
|
||||
}
|
||||
|
||||
// Write to file (C-style)
|
||||
FILE* file = fopen(fullPath.c_str(), "wb");
|
||||
if (file) {
|
||||
fwrite(rendered, 1, strlen(rendered), file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
cJSON_free(rendered);
|
||||
cJSON_Delete(notif);
|
||||
}
|
||||
}
|
||||
@@ -1,514 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: list_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file contains function declarations and utility functions related
|
||||
* to working with lists and vectors of strings. These functions are used in the
|
||||
* Ultrahand Overlay project to perform various operations on lists, such as
|
||||
* removing entries, filtering, and more.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include <list_funcs.hpp>
|
||||
#include <mutex>
|
||||
|
||||
namespace ult {
|
||||
static constexpr const char* UNABLE_TO_OPEN_FILE = "Unable to open file: ";
|
||||
|
||||
// Thread-safe file access mutex
|
||||
static std::mutex file_access_mutex;
|
||||
|
||||
std::vector<std::string> splitIniList(const std::string& value) {
|
||||
std::vector<std::string> result;
|
||||
std::string trimmed = value;
|
||||
trim(trimmed);
|
||||
if (trimmed.size() > 2 && trimmed.front() == '(' && trimmed.back() == ')') {
|
||||
trimmed = trimmed.substr(1, trimmed.size() - 2);
|
||||
ult::StringStream ss(trimmed);
|
||||
std::string token;
|
||||
while (ss.getline(token, ',')) {
|
||||
trim(token);
|
||||
result.push_back(token);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string joinIniList(const std::vector<std::string>& list) {
|
||||
std::string result = "";
|
||||
for (size_t i = 0; i < list.size(); ++i) {
|
||||
result += list[i];
|
||||
if (i + 1 < list.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes entries from a vector of strings that match a specified entry.
|
||||
*
|
||||
* This function removes entries from the `itemsList` vector of strings that match the `entry`.
|
||||
*
|
||||
* @param entry The entry to be compared against the elements in `itemsList`.
|
||||
* @param itemsList The vector of strings from which matching entries will be removed.
|
||||
*/
|
||||
void removeEntryFromList(const std::string& entry, std::vector<std::string>& itemsList) {
|
||||
itemsList.erase(std::remove_if(itemsList.begin(), itemsList.end(), [&](const std::string& item) {
|
||||
return item.compare(0, entry.length(), entry) == 0;
|
||||
}), itemsList.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Filters a list of strings based on a specified filter list.
|
||||
*
|
||||
* This function filters a list of strings (`itemsList`) by removing entries that match any
|
||||
* of the criteria specified in the `filterList`. It uses the `removeEntryFromList` function
|
||||
* to perform the removal.
|
||||
*
|
||||
* @param filterList The list of entries to filter by. Entries in `itemsList` matching any entry in this list will be removed.
|
||||
* @param itemsList The list of strings to be filtered.
|
||||
*/
|
||||
void filterItemsList(const std::vector<std::string>& filterList, std::vector<std::string>& itemsList) {
|
||||
for (const auto& entry : filterList) {
|
||||
removeEntryFromList(entry, itemsList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to read file into a vector of strings with optional cap
|
||||
std::vector<std::string> readListFromFile(const std::string& filePath, size_t maxLines) {
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
std::vector<std::string> lines;
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "r");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return lines;
|
||||
}
|
||||
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
char buffer[BUFFER_SIZE];
|
||||
size_t len;
|
||||
|
||||
while (fgets(buffer, BUFFER_SIZE, file)) {
|
||||
// Check cap before processing
|
||||
if (maxLines > 0 && lines.size() >= maxLines) {
|
||||
break;
|
||||
}
|
||||
|
||||
// More efficient newline removal
|
||||
len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
--len;
|
||||
// Also remove carriage return if present
|
||||
if (len > 0 && buffer[len - 1] == '\r') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
lines.emplace_back(buffer);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// Check cap before adding
|
||||
if (maxLines > 0 && lines.size() >= maxLines) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Remove carriage return if present (getline removes \n but not \r)
|
||||
if (!line.empty() && line.back() == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
lines.emplace_back(std::move(line));
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
// Function to get an entry from the list based on the index
|
||||
std::string getEntryFromListFile(const std::string& listPath, size_t listIndex) {
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(listPath.c_str(), "r");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + listPath);
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
char buffer[BUFFER_SIZE];
|
||||
|
||||
// Skip lines until reaching the desired index
|
||||
for (size_t i = 0; i < listIndex; ++i) {
|
||||
if (!fgets(buffer, BUFFER_SIZE, file)) {
|
||||
fclose(file);
|
||||
return ""; // Index out of bounds
|
||||
}
|
||||
}
|
||||
|
||||
// Read the target line
|
||||
if (!fgets(buffer, BUFFER_SIZE, file)) {
|
||||
fclose(file);
|
||||
return ""; // Index out of bounds
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
// Efficiently remove newline character
|
||||
const size_t len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
if (len > 1 && buffer[len - 2] == '\r') {
|
||||
buffer[len - 2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return std::string(buffer);
|
||||
|
||||
#else
|
||||
std::ifstream file(listPath);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + listPath);
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string line;
|
||||
|
||||
// Skip lines until reaching the desired index
|
||||
for (size_t i = 0; i < listIndex; ++i) {
|
||||
if (!std::getline(file, line)) {
|
||||
return ""; // Index out of bounds
|
||||
}
|
||||
}
|
||||
|
||||
// Read the target line
|
||||
if (!std::getline(file, line)) {
|
||||
return ""; // Index out of bounds
|
||||
}
|
||||
|
||||
file.close();
|
||||
return line;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a vector of strings using a delimiter.
|
||||
*
|
||||
* This function splits the input string into multiple strings using the specified delimiter.
|
||||
*
|
||||
* @param str The input string to split.
|
||||
* @return A vector of strings containing the split values.
|
||||
*/
|
||||
std::vector<std::string> stringToList(const std::string& str) {
|
||||
std::vector<std::string> result;
|
||||
|
||||
if (str.empty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if the input string starts and ends with '(' and ')' or '[' and ']'
|
||||
if ((str.front() == '(' && str.back() == ')') || (str.front() == '[' && str.back() == ']')) {
|
||||
// Work directly with the original string using indices instead of creating substring
|
||||
size_t start = 1; // Skip opening bracket/paren
|
||||
size_t end = 1;
|
||||
const size_t values_end = str.size() - 1; // Skip closing bracket/paren
|
||||
|
||||
// Pre-declare item string to avoid repeated allocations
|
||||
std::string item;
|
||||
|
||||
// Iterate through the string manually to split by commas
|
||||
while ((end = str.find(',', start)) != std::string::npos && end < values_end) {
|
||||
// Extract item directly from original string without creating substring
|
||||
item.assign(str, start, end - start);
|
||||
|
||||
// Trim leading and trailing spaces
|
||||
trim(item);
|
||||
|
||||
// Remove quotes from each token if necessary
|
||||
removeQuotes(item);
|
||||
|
||||
result.push_back(std::move(item));
|
||||
start = end + 1;
|
||||
}
|
||||
|
||||
// Handle the last item after the last comma
|
||||
if (start < values_end) {
|
||||
item.assign(str, start, values_end - start);
|
||||
trim(item);
|
||||
removeQuotes(item);
|
||||
result.push_back(std::move(item));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to read file into a set of strings
|
||||
std::unordered_set<std::string> readSetFromFile(const std::string& filePath) {
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
std::unordered_set<std::string> lines;
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "r");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return lines;
|
||||
}
|
||||
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
char buffer[BUFFER_SIZE];
|
||||
size_t len;
|
||||
while (fgets(buffer, BUFFER_SIZE, file)) {
|
||||
// Remove trailing newline character if it exists
|
||||
len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
lines.insert(buffer);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines.insert(std::move(line));
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
// Function to write a set to a file
|
||||
void writeSetToFile(const std::unordered_set<std::string>& fileSet, const std::string& filePath) {
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "w");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& entry : fileSet) {
|
||||
fprintf(file, "%s\n", entry.c_str());
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
std::ofstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& entry : fileSet) {
|
||||
file << entry << '\n';
|
||||
}
|
||||
|
||||
file.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Helper function for streaming comparison
|
||||
void streamCompareAndWrite(const std::string& streamFilePath,
|
||||
const std::unordered_set<std::string>& compareSet,
|
||||
const std::string& outputTxtFilePath) {
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* streamFile = fopen(streamFilePath.c_str(), "r");
|
||||
if (!streamFile) return;
|
||||
|
||||
FILE* outputFile = fopen(outputTxtFilePath.c_str(), "w");
|
||||
if (!outputFile) {
|
||||
fclose(streamFile);
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
char buffer[BUFFER_SIZE];
|
||||
size_t len;
|
||||
|
||||
while (fgets(buffer, BUFFER_SIZE, streamFile)) {
|
||||
len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
|
||||
if (compareSet.count(std::string(buffer))) {
|
||||
fprintf(outputFile, "%s\n", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(streamFile);
|
||||
fclose(outputFile);
|
||||
|
||||
#else
|
||||
std::ifstream streamFile(streamFilePath);
|
||||
if (!streamFile.is_open()) return;
|
||||
|
||||
std::ofstream outputFile(outputTxtFilePath);
|
||||
if (!outputFile.is_open()) return;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(streamFile, line)) {
|
||||
if (compareSet.count(line)) {
|
||||
outputFile << line << '\n';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Function to compare two file lists and save duplicates to an output file
|
||||
void compareFilesLists(const std::string& txtFilePath1, const std::string& txtFilePath2, const std::string& outputTxtFilePath) {
|
||||
// Read files into sets
|
||||
std::unordered_set<std::string> fileSet1 = readSetFromFile(txtFilePath1);
|
||||
std::unordered_set<std::string> fileSet2 = readSetFromFile(txtFilePath2);
|
||||
|
||||
// Always work with the smaller set for better performance
|
||||
if (fileSet1.size() <= fileSet2.size()) {
|
||||
// fileSet1 is smaller or equal - modify it
|
||||
for (auto it = fileSet1.begin(); it != fileSet1.end();) {
|
||||
if (fileSet2.count(*it) == 0) {
|
||||
it = fileSet1.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
writeSetToFile(fileSet1, outputTxtFilePath);
|
||||
} else {
|
||||
// fileSet2 is smaller - modify it instead
|
||||
for (auto it = fileSet2.begin(); it != fileSet2.end();) {
|
||||
if (fileSet1.count(*it) == 0) {
|
||||
it = fileSet2.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
writeSetToFile(fileSet2, outputTxtFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
void compareWildcardFilesLists(
|
||||
const std::string& wildcardPatternFilePath,
|
||||
const std::string& txtFilePath,
|
||||
const std::string& outputTxtFilePath
|
||||
) {
|
||||
std::unordered_set<std::string> targetLines = readSetFromFile(txtFilePath);
|
||||
std::unordered_set<std::string> duplicates;
|
||||
|
||||
auto wildcardFiles = getFilesListByWildcards(wildcardPatternFilePath);
|
||||
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
|
||||
for (auto& filePath : wildcardFiles) {
|
||||
if (filePath == txtFilePath || targetLines.empty()) {
|
||||
filePath = ""; // Clear early
|
||||
continue;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(file_access_mutex);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* file = fopen(filePath.c_str(), "r");
|
||||
if (!file) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
char buffer[BUFFER_SIZE];
|
||||
|
||||
while (fgets(buffer, BUFFER_SIZE, file) && !targetLines.empty()) { // Early exit!
|
||||
char* newlinePos = strchr(buffer, '\n');
|
||||
if (newlinePos) *newlinePos = '\0';
|
||||
|
||||
auto it = targetLines.find(std::string(buffer));
|
||||
if (it != targetLines.end()) {
|
||||
duplicates.emplace(std::move(*it)); // Move instead of copy
|
||||
targetLines.erase(it);
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
#else
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
logMessage(UNABLE_TO_OPEN_FILE + filePath);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line) && !targetLines.empty()) { // Early exit!
|
||||
auto it = targetLines.find(line);
|
||||
if (it != targetLines.end()) {
|
||||
duplicates.emplace(std::move(*it)); // Move instead of copy
|
||||
targetLines.erase(it);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
filePath = ""; // Clear after processing - reduces vector memory footprint
|
||||
}
|
||||
|
||||
writeSetToFile(duplicates, outputTxtFilePath);
|
||||
}
|
||||
}
|
||||
@@ -1,736 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: mod_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides the implementations of functions declared in
|
||||
* mod_funcs.hpp. These functions handle the conversion of `.pchtxt` mod files
|
||||
* into `.ips` binary patches used by the Ultrahand Overlay project. This includes
|
||||
* parsing, validating, and encoding patch data into the IPS format.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include <mod_funcs.hpp>
|
||||
|
||||
namespace ult {
|
||||
|
||||
//const std::string CHEAT_HEADER = "// auto generated by pchtxt2cheat\n\n";
|
||||
static const std::string CHEAT_TYPE = "04000000";
|
||||
static const std::string CHEAT_EXT = ".txt";
|
||||
static const std::string CHEAT_ENCODING = "ascii";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if a cheat already exists in the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to check.
|
||||
* @return True if the cheat exists, otherwise false.
|
||||
*/
|
||||
bool cheatExists(const std::string& cheatFilePath, const std::string& newCheat) {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* cheatFile = fopen(cheatFilePath.c_str(), "r"); // Open the cheat file in read mode
|
||||
if (!cheatFile) {
|
||||
return false; // Return false if the file cannot be opened
|
||||
}
|
||||
|
||||
//size_t len;
|
||||
char buffer[1024]; // Buffer to store each line
|
||||
while (fgets(buffer, sizeof(buffer), cheatFile)) {
|
||||
// Remove newline character, if present
|
||||
const size_t len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
if (newCheat == buffer) {
|
||||
fclose(cheatFile); // Close the file before returning
|
||||
return true; // Cheat exists
|
||||
}
|
||||
}
|
||||
|
||||
fclose(cheatFile); // Close the file after processing
|
||||
return false; // Cheat does not exist
|
||||
#else
|
||||
std::ifstream cheatFile(cheatFilePath);
|
||||
if (!cheatFile) {
|
||||
return false; // Return false if the file cannot be opened
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(cheatFile, line)) {
|
||||
if (line == newCheat) {
|
||||
return true; // Cheat exists
|
||||
}
|
||||
}
|
||||
return false; // Cheat does not exist
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Appends a new cheat to the cheat file.
|
||||
* @param cheatFilePath The path to the cheat file.
|
||||
* @param newCheat The new cheat to append.
|
||||
*/
|
||||
void appendCheatToFile(const std::string& cheatFilePath, const std::string& newCheat) {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* cheatFile = fopen(cheatFilePath.c_str(), "a"); // Open the cheat file in append mode
|
||||
if (!cheatFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open cheat file for appending: " + cheatFilePath);
|
||||
#endif
|
||||
return; // Handle the error accordingly
|
||||
}
|
||||
|
||||
fprintf(cheatFile, "%s\n", newCheat.c_str()); // Write the new cheat followed by a newline
|
||||
fclose(cheatFile); // Close the file
|
||||
#else
|
||||
std::ofstream cheatFile(cheatFilePath, std::ios::app);
|
||||
if (!cheatFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Failed to open cheat file for appending: " + cheatFilePath);
|
||||
#endif
|
||||
return; // Handle the error accordingly
|
||||
}
|
||||
|
||||
cheatFile << newCheat << std::endl; // Write the new cheat
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extracts the cheat name from the given file path.
|
||||
* @param filePath The full file path.
|
||||
* @return The extracted cheat name.
|
||||
*/
|
||||
std::string extractCheatName(const std::string &filePath) {
|
||||
const size_t lastSlash = filePath.find_last_of("/\\");
|
||||
if (lastSlash == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
const size_t secondLastSlash = filePath.find_last_of("/\\", lastSlash - 1);
|
||||
if (secondLastSlash == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
const std::string lastDir = filePath.substr(secondLastSlash + 1, lastSlash - secondLastSlash - 1);
|
||||
std::string fileName = filePath.substr(lastSlash + 1);
|
||||
const size_t dotPos = fileName.find_last_of('.');
|
||||
if (dotPos != std::string::npos) {
|
||||
fileName = fileName.substr(0, dotPos);
|
||||
}
|
||||
|
||||
// If lastDir contains " - ", extract the part after " - "
|
||||
const size_t dashPos = lastDir.find(" - ");
|
||||
std::string cheatName = lastDir;
|
||||
if (dashPos != std::string::npos) {
|
||||
cheatName = lastDir.substr(dashPos + 3);
|
||||
}
|
||||
|
||||
return cheatName + " " + fileName;
|
||||
}
|
||||
|
||||
// Helper function to determine if a string is a valid title ID
|
||||
bool isValidTitleID(const std::string &str) {
|
||||
if (str.length() != 16) return false;
|
||||
for (char c : str) {
|
||||
if (!std::isxdigit(c)) return false; // Check if each character is a hexadecimal digit
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Function to find the title ID in the text, avoiding the @nsobid- line
|
||||
std::string findTitleID(const std::string &text) {
|
||||
const size_t nsobidPos = text.find("@nsobid-");
|
||||
const size_t startPos = (nsobidPos != std::string::npos) ? nsobidPos + 40 + 8 : 0; // Skip past @nsobid- and its value
|
||||
|
||||
std::string potentialID;
|
||||
for (size_t i = startPos; i <= text.length() - 16; ++i) {
|
||||
potentialID = text.substr(i, 16);
|
||||
if (isValidTitleID(potentialID)) {
|
||||
return potentialID;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to a cheat file.
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param cheatName The name of the cheat.
|
||||
* @param outCheatPath The file path for the output cheat file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2cheat(const std::string &pchtxtPath, std::string cheatName, std::string outCheatPath) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Starting pchtxt2cheat with pchtxtPath: " + pchtxtPath);
|
||||
#endif
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* pchtxtFile = fopen(pchtxtPath.c_str(), "r");
|
||||
if (!pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the entire file into a string
|
||||
std::string pchtxt;
|
||||
char buffer[4096];
|
||||
while (fgets(buffer, sizeof(buffer), pchtxtFile)) {
|
||||
pchtxt += buffer;
|
||||
}
|
||||
fclose(pchtxtFile);
|
||||
#else
|
||||
std::ifstream pchtxtFile(pchtxtPath);
|
||||
if (!pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string pchtxt((std::istreambuf_iterator<char>(pchtxtFile)), std::istreambuf_iterator<char>());
|
||||
#endif
|
||||
|
||||
const size_t nsobidPos = pchtxt.find("@nsobid-");
|
||||
if (nsobidPos == std::string::npos) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Could not find bid in pchtxt file, the file is likely invalid.");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string bid = pchtxt.substr(nsobidPos + 8, 40);
|
||||
const std::string bidShort = bid.substr(0, 16);
|
||||
|
||||
const std::string tid = findTitleID(pchtxt);
|
||||
if (tid.empty()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Could not find TID in pchtxt file, the file is likely invalid.");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cheatFilePath;
|
||||
|
||||
if (outCheatPath.empty()) {
|
||||
const std::string folderPath = "sdmc:/atmosphere/contents/" + tid + "/cheats/";
|
||||
createDirectory(folderPath);
|
||||
cheatFilePath = folderPath + bidShort + CHEAT_EXT;
|
||||
} else {
|
||||
cheatFilePath = outCheatPath;
|
||||
}
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* existingCheatFile = fopen(cheatFilePath.c_str(), "r");
|
||||
bool cheatNameExists = false;
|
||||
if (existingCheatFile) {
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), existingCheatFile)) {
|
||||
if (std::string(line) == "[" + cheatName + "]\n") {
|
||||
cheatNameExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(existingCheatFile);
|
||||
}
|
||||
#else
|
||||
std::ifstream existingCheatFile(cheatFilePath);
|
||||
bool cheatNameExists = false;
|
||||
if (existingCheatFile) {
|
||||
std::string line;
|
||||
while (std::getline(existingCheatFile, line)) {
|
||||
if (line == "[" + cheatName + "]") {
|
||||
cheatNameExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
existingCheatFile.close();
|
||||
#endif
|
||||
|
||||
// Open output cheat file
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
FILE* outCheatFile = fopen(cheatFilePath.c_str(), "a");
|
||||
if (!outCheatFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to create cheat file " + cheatFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
std::ofstream outCheatFile(cheatFilePath, std::ios::app);
|
||||
if (!outCheatFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to create cheat file " + cheatFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!cheatNameExists) {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
fprintf(outCheatFile, "[%s]\n", cheatName.c_str());
|
||||
#else
|
||||
outCheatFile << "[" << cheatName << "]\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
bool enabled = true;
|
||||
int validCheatsProcessed = 0; // ADDED: Track number of valid cheats processed
|
||||
StringStream iss(pchtxt); // Use your custom StringStream
|
||||
std::string line;
|
||||
|
||||
std::string addrStr, valStr;
|
||||
size_t spacePos;
|
||||
int codeOffset;
|
||||
std::string cheatLine;
|
||||
char offsetBuffer[9];
|
||||
|
||||
// Use your custom getline method instead of std::getline
|
||||
while (iss.getline(line, '\n')) { // Custom getline with newline as the delimiter
|
||||
|
||||
// strip inline C++-style comments
|
||||
const auto slashPos = line.find("//");
|
||||
if (slashPos != std::string::npos)
|
||||
line = line.substr(0, slashPos);
|
||||
|
||||
// strip inline hash comments (but leave full-line # for headers)
|
||||
const auto hashPos = line.find('#');
|
||||
if (hashPos != std::string::npos && hashPos > 0)
|
||||
line = line.substr(0, hashPos);
|
||||
|
||||
trim(line);
|
||||
if (line.empty() || line[0] == '#') continue;
|
||||
|
||||
if (line.find("@flag offset_shift ") == 0) {
|
||||
const std::string offsetStr = line.substr(19);
|
||||
offset = (offsetStr.find("0x") == 0 ? std::strtol(offsetStr.c_str(), nullptr, 16) : std::strtol(offsetStr.c_str(), nullptr, 10)) - 0x100;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.find("@enabled") == 0) {
|
||||
enabled = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.find("@disabled") == 0) {
|
||||
enabled = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.find("@stop") == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
spacePos = line.find(' ');
|
||||
if (spacePos == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
addrStr = line.substr(0, spacePos);
|
||||
valStr = line.substr(spacePos + 1);
|
||||
|
||||
if (addrStr.find_first_not_of("0123456789abcdefABCDEF") != std::string::npos || valStr.find_first_not_of("0123456789abcdefABCDEF") != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
codeOffset = std::strtol(valStr.c_str(), nullptr, 16) + offset;
|
||||
snprintf(offsetBuffer, sizeof(offsetBuffer), "%08X", codeOffset);
|
||||
cheatLine = CHEAT_TYPE + " " + addrStr + " " + hexToReversedHex(offsetBuffer);
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Check if cheat already exists
|
||||
FILE* checkFile = fopen(cheatFilePath.c_str(), "r");
|
||||
bool exists = false;
|
||||
if (checkFile) {
|
||||
char checkLine[256];
|
||||
while (fgets(checkLine, sizeof(checkLine), checkFile)) {
|
||||
if (std::string(checkLine) == cheatLine + "\n") {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(checkFile);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
fprintf(outCheatFile, "%s\n", cheatLine.c_str());
|
||||
validCheatsProcessed++; // ADDED: Increment counter for new cheats
|
||||
}
|
||||
#else
|
||||
if (!cheatExists(cheatFilePath, cheatLine)) {
|
||||
outCheatFile << cheatLine << "\n";
|
||||
validCheatsProcessed++; // ADDED: Increment counter for new cheats
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
fclose(outCheatFile);
|
||||
#else
|
||||
outCheatFile.close();
|
||||
#endif
|
||||
|
||||
// ADDED: Check if any valid cheats were processed
|
||||
if (validCheatsProcessed == 0) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Warning: No valid patch data found to convert to cheats in " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Corrected helper function to convert values to big-endian format
|
||||
//uint32_t toBigEndian(uint32_t value) {
|
||||
// return ((value & 0x000000FF) << 24) |
|
||||
// ((value & 0x0000FF00) << 8) |
|
||||
// ((value & 0x00FF0000) >> 8) |
|
||||
// ((value & 0xFF000000) >> 24);
|
||||
//}
|
||||
//
|
||||
//uint16_t toBigEndian(uint16_t value) {
|
||||
// return ((value & 0x00FF) << 8) |
|
||||
// ((value & 0xFF00) >> 8);
|
||||
//}
|
||||
|
||||
// Helper function to convert a vector of bytes to a hex string for logging
|
||||
|
||||
//std::string hexToString(const std::vector<uint8_t>& bytes) {
|
||||
// StringStream oss; // Use your custom StringStream
|
||||
// oss.hex(); // Enable hex mode for the stream
|
||||
//
|
||||
// for (uint8_t byte : bytes) {
|
||||
// if (byte < 0x10) {
|
||||
// oss << "0"; // Append leading zero for single-digit hex values
|
||||
// }
|
||||
// oss << static_cast<int>(byte); // Convert byte to int and then append it
|
||||
// }
|
||||
//
|
||||
// return oss.str(); // Return the final hex string
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a .pchtxt file to an IPS file using fstream.
|
||||
*
|
||||
* This function reads the contents of a .pchtxt file, extracts the address-value pairs,
|
||||
* and generates an IPS file with the provided output folder.
|
||||
*
|
||||
* @param pchtxtPath The file path to the .pchtxt file.
|
||||
* @param outputFolder The folder path for the output IPS file.
|
||||
* @return True if the conversion was successful, false otherwise.
|
||||
*/
|
||||
bool pchtxt2ips(const std::string& pchtxtPath, const std::string& outputFolder) {
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Use FILE* for reading
|
||||
FILE* pchtxtFile = fopen(pchtxtPath.c_str(), "r");
|
||||
if (!pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint32_t, std::vector<uint8_t>>> patches;
|
||||
char lineBuffer[512]; // Fixed: Use char buffer for fgets
|
||||
std::string line;
|
||||
uint32_t lineNum = 0;
|
||||
std::string nsobid;
|
||||
int offset = 0; // Default offset
|
||||
bool enabled = true;
|
||||
|
||||
uint32_t address;
|
||||
uint8_t byte;
|
||||
std::vector<uint8_t> valueBytes;
|
||||
std::string offsetStr;
|
||||
|
||||
while (fgets(lineBuffer, sizeof(lineBuffer), pchtxtFile) != nullptr) {
|
||||
line = lineBuffer; // Convert to string
|
||||
++lineNum;
|
||||
if (line.empty() || line.front() == '@' || !enabled) {
|
||||
if (line.find("@nsobid-") == 0) {
|
||||
nsobid = line.substr(8);
|
||||
}
|
||||
if (line.find("@flag offset_shift ") == 0) {
|
||||
offsetStr = line.substr(19);
|
||||
offset = (offsetStr.find("0x") == 0 ? std::strtol(offsetStr.c_str(), nullptr, 16) : std::strtol(offsetStr.c_str(), nullptr, 10));
|
||||
}
|
||||
if (line.find("@enabled") == 0) {
|
||||
enabled = true;
|
||||
continue;
|
||||
}
|
||||
if (line.find("@disabled") == 0) {
|
||||
enabled = false;
|
||||
continue;
|
||||
}
|
||||
if (line.find("@stop") == 0) {
|
||||
break;
|
||||
}
|
||||
continue; // Skip empty lines and lines starting with '@'
|
||||
}
|
||||
|
||||
StringStream iss(line);
|
||||
std::string addressStr, valueStr;
|
||||
|
||||
if (!(iss >> addressStr >> valueStr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* endPtr;
|
||||
address = std::strtoul(addressStr.c_str(), &endPtr, 16) + offset; // Adjust address by offset
|
||||
if (*endPtr != '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < valueStr.length(); i += 2) {
|
||||
byte = ult::stoi(valueStr.substr(i, 2), nullptr, 16);
|
||||
valueBytes.push_back(byte);
|
||||
}
|
||||
|
||||
if (valueBytes.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
patches.push_back(std::make_pair(address, valueBytes));
|
||||
valueBytes.clear();
|
||||
}
|
||||
|
||||
fclose(pchtxtFile);
|
||||
|
||||
#else
|
||||
// Use fstream for reading
|
||||
std::ifstream pchtxtFile(pchtxtPath);
|
||||
if (!pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint32_t, std::vector<uint8_t>>> patches;
|
||||
std::string line;
|
||||
uint32_t lineNum = 0;
|
||||
std::string nsobid;
|
||||
int offset = 0; // Default offset
|
||||
|
||||
uint32_t address;
|
||||
uint8_t byte;
|
||||
std::vector<uint8_t> valueBytes;
|
||||
std::string offsetStr;
|
||||
|
||||
while (std::getline(pchtxtFile, line)) {
|
||||
++lineNum;
|
||||
if (line.empty() || line.front() == '@') {
|
||||
if (line.find("@nsobid-") == 0) {
|
||||
nsobid = line.substr(8);
|
||||
}
|
||||
if (line.find("@flag offset_shift ") == 0) {
|
||||
offsetStr = line.substr(19);
|
||||
offset = (offsetStr.find("0x") == 0 ? std::strtol(offsetStr.c_str(), nullptr, 16) : std::strtol(offsetStr.c_str(), nullptr, 10));
|
||||
}
|
||||
if (line.find("@stop") == 0) {
|
||||
break;
|
||||
}
|
||||
continue; // Skip empty lines and lines starting with '@'
|
||||
}
|
||||
|
||||
StringStream iss(line);
|
||||
std::string addressStr, valueStr;
|
||||
|
||||
if (!(iss >> addressStr >> valueStr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char* endPtr;
|
||||
address = std::strtoul(addressStr.c_str(), &endPtr, 16) + offset; // Adjust address by offset
|
||||
if (*endPtr != '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < valueStr.length(); i += 2) {
|
||||
byte = ult::stoi(valueStr.substr(i, 2), nullptr, 16);
|
||||
valueBytes.push_back(byte);
|
||||
}
|
||||
|
||||
if (valueBytes.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
patches.push_back(std::make_pair(address, valueBytes));
|
||||
valueBytes.clear();
|
||||
}
|
||||
|
||||
pchtxtFile.close();
|
||||
#endif
|
||||
|
||||
// CHECK: Return false if no patches were found
|
||||
if (patches.empty()) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Warning: No valid patches found in " + pchtxtPath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nsobid.empty()) {
|
||||
nsobid = pchtxtPath.substr(pchtxtPath.find_last_of("/\\") + 1);
|
||||
nsobid = nsobid.substr(0, nsobid.find_last_of("."));
|
||||
}
|
||||
|
||||
// Trim any newline characters from nsobid
|
||||
trim(nsobid);
|
||||
trimNewline(nsobid);
|
||||
|
||||
const std::string ipsFileName = nsobid + ".ips";
|
||||
const std::string ipsFilePath = outputFolder + ipsFileName;
|
||||
|
||||
#if !USING_FSTREAM_DIRECTIVE
|
||||
// Use FILE* for writing
|
||||
FILE* ipsFile = fopen(ipsFilePath.c_str(), "wb");
|
||||
if (!ipsFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to create IPS file " + ipsFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
fwrite(IPS32_HEAD_MAGIC, sizeof(char), std::strlen(IPS32_HEAD_MAGIC), ipsFile);
|
||||
|
||||
uint16_t valueLength;
|
||||
uint32_t bigEndianAddress;
|
||||
|
||||
for (const auto& patch : patches) {
|
||||
bigEndianAddress = toBigEndian(patch.first); // Convert address to big-endian
|
||||
fwrite(&bigEndianAddress, sizeof(bigEndianAddress), 1, ipsFile); // Write address
|
||||
|
||||
valueLength = toBigEndian(static_cast<uint16_t>(patch.second.size())); // Convert length to big-endian
|
||||
fwrite(&valueLength, sizeof(valueLength), 1, ipsFile); // Write length of value
|
||||
|
||||
fwrite(patch.second.data(), sizeof(uint8_t), patch.second.size(), ipsFile); // Write value
|
||||
}
|
||||
|
||||
fwrite(IPS32_FOOT_MAGIC, sizeof(char), std::strlen(IPS32_FOOT_MAGIC), ipsFile);
|
||||
fclose(ipsFile);
|
||||
|
||||
|
||||
FILE* _pchtxtFile = fopen(pchtxtPath.c_str(), "r");
|
||||
if (!_pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false; // Changed: Return false if we can't read the file for title ID
|
||||
}
|
||||
|
||||
// Read the entire file into a string
|
||||
std::string pchtxt;
|
||||
char buffer[4096];
|
||||
while (fgets(buffer, sizeof(buffer), _pchtxtFile)) {
|
||||
pchtxt += buffer;
|
||||
}
|
||||
fclose(_pchtxtFile);
|
||||
|
||||
|
||||
const std::string tid = findTitleID(pchtxt);
|
||||
if (!tid.empty()) {
|
||||
const std::string tidFilePath = outputFolder + tid;
|
||||
FILE* tidFile = fopen(tidFilePath.c_str(), "w");
|
||||
if (tidFile) {
|
||||
fclose(tidFile); // Creates an empty file
|
||||
}
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Warning: Could not find Title ID in " + pchtxtPath);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
// Use fstream for writing
|
||||
std::ofstream ipsFile(ipsFilePath, std::ios::binary);
|
||||
if (!ipsFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to create IPS file " + ipsFilePath);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
ipsFile.write(IPS32_HEAD_MAGIC, std::strlen(IPS32_HEAD_MAGIC));
|
||||
|
||||
uint16_t valueLength;
|
||||
uint32_t bigEndianAddress;
|
||||
for (const auto& patch : patches) {
|
||||
bigEndianAddress = toBigEndian(patch.first); // Convert address to big-endian
|
||||
ipsFile.write(reinterpret_cast<const char*>(&bigEndianAddress), sizeof(bigEndianAddress)); // Write address
|
||||
|
||||
valueLength = toBigEndian(static_cast<uint16_t>(patch.second.size())); // Convert length to big-endian
|
||||
ipsFile.write(reinterpret_cast<const char*>(&valueLength), sizeof(valueLength)); // Write length of value
|
||||
|
||||
ipsFile.write(reinterpret_cast<const char*>(patch.second.data()), patch.second.size()); // Write value
|
||||
}
|
||||
|
||||
ipsFile.write(IPS32_FOOT_MAGIC, std::strlen(IPS32_FOOT_MAGIC));
|
||||
ipsFile.close();
|
||||
|
||||
|
||||
std::ifstream _pchtxtFile(pchtxtPath);
|
||||
if (!_pchtxtFile) {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Error: Unable to open file " + pchtxtPath);
|
||||
#endif
|
||||
return false; // Changed: Return false if we can't read the file for title ID
|
||||
}
|
||||
|
||||
std::string pchtxt((std::istreambuf_iterator<char>(_pchtxtFile)), std::istreambuf_iterator<char>());
|
||||
|
||||
const std::string tid = findTitleID(pchtxt);
|
||||
if (!tid.empty()) {
|
||||
const std::string tidFilePath = outputFolder + tid;
|
||||
std::ofstream tidFile(tidFilePath);
|
||||
tidFile.close(); // Creates an empty file
|
||||
} else {
|
||||
#if USING_LOGGING_DIRECTIVE
|
||||
if (!disableLogging)
|
||||
logMessage("Warning: Could not find Title ID in " + pchtxtPath);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,636 +0,0 @@
|
||||
/********************************************************************************
|
||||
* File: string_funcs.cpp
|
||||
* Author: ppkantorski
|
||||
* Description:
|
||||
* This source file provides implementations for the string manipulation
|
||||
* functions declared in string_funcs.hpp. These utility functions support
|
||||
* operations such as trimming whitespace, removing quotes, normalizing
|
||||
* slashes, and performing other string cleanup tasks used throughout
|
||||
* the Ultrahand Overlay project.
|
||||
*
|
||||
* For the latest updates and contributions, visit the project's GitHub repository.
|
||||
* (GitHub Repository: https://github.com/ppkantorski/Ultrahand-Overlay)
|
||||
*
|
||||
* Note: Please be aware that this notice cannot be altered or removed. It is a part
|
||||
* of the project's documentation and must remain intact.
|
||||
*
|
||||
* Licensed under both GPLv2 and CC-BY-4.0
|
||||
* Copyright (c) 2024 ppkantorski
|
||||
********************************************************************************/
|
||||
|
||||
#include "string_funcs.hpp"
|
||||
|
||||
namespace ult {
|
||||
|
||||
|
||||
// Custom string conversion methods in place of std::
|
||||
std::string to_string(int value) {
|
||||
char buffer[12]; // Sufficient for 32-bit int
|
||||
snprintf(buffer, sizeof(buffer), "%d", value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
int stoi(const std::string& str, std::size_t* pos, int base) {
|
||||
char* end;
|
||||
const long result = std::strtol(str.c_str(), &end, base);
|
||||
|
||||
if (pos) {
|
||||
*pos = end - str.c_str(); // Set the position to the last character processed
|
||||
}
|
||||
|
||||
// Handle out-of-range or conversion issues here if needed
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
|
||||
|
||||
float stof(const std::string& str) {
|
||||
return strtof(str.c_str(), nullptr);
|
||||
}
|
||||
|
||||
|
||||
//bool canConvertToInt(const std::string& str) {
|
||||
// if (str.empty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// size_t start = 0;
|
||||
// if (str[0] == '-' || str[0] == '+') {
|
||||
// if (str.length() == 1) return false;
|
||||
// start = 1;
|
||||
// }
|
||||
//
|
||||
// for (size_t i = start; i < str.length(); ++i) {
|
||||
// if (!std::isdigit(static_cast<unsigned char>(str[i]))) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
|
||||
// Mimics std::getline() with a delimiter
|
||||
bool StringStream::getline(std::string& output, char delimiter) {
|
||||
if (position >= data.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t nextPos = data.find(delimiter, position);
|
||||
|
||||
if (nextPos != std::string::npos) {
|
||||
output.assign(data, position, nextPos - position); // No temporary string creation
|
||||
position = nextPos + 1;
|
||||
} else {
|
||||
output.assign(data, position, data.size() - position); // No temporary string creation
|
||||
position = data.size();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mimics operator >> to split by whitespace
|
||||
StringStream& StringStream::operator>>(std::string& output) {
|
||||
// Skip leading whitespace
|
||||
while (position < data.size() && std::isspace(data[position])) {
|
||||
++position;
|
||||
}
|
||||
|
||||
if (position >= data.size()) {
|
||||
output.clear();
|
||||
validState = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
size_t nextPos = position;
|
||||
while (nextPos < data.size() && !std::isspace(data[nextPos])) {
|
||||
++nextPos;
|
||||
}
|
||||
|
||||
output.assign(data, position, nextPos - position); // Replace substr() with assign()
|
||||
position = nextPos;
|
||||
|
||||
validState = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload << operator for std::string
|
||||
StringStream& StringStream::operator<<(const std::string& input) {
|
||||
data += input;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload << operator for const char*
|
||||
StringStream& StringStream::operator<<(const char* input) {
|
||||
data += input;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload << operator for char
|
||||
StringStream& StringStream::operator<<(char input) {
|
||||
data += input;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload << operator for int (handles hex mode)
|
||||
StringStream& StringStream::operator<<(int input) {
|
||||
if (hexMode) {
|
||||
char buffer[20]; // Buffer large enough for hex conversion
|
||||
sprintf(buffer, "%x", input); // Convert integer to hex string
|
||||
data += buffer;
|
||||
} else {
|
||||
data += ult::to_string(input);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Define the new overload for long long
|
||||
StringStream& StringStream::operator<<(long long input) {
|
||||
data += std::to_string(input);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return the current buffer content
|
||||
std::string StringStream::str() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Trims leading and trailing whitespaces from a string.
|
||||
*
|
||||
* This function removes leading and trailing whitespaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to trim.
|
||||
* @return The trimmed string.
|
||||
*/
|
||||
void trim(std::string& str) {
|
||||
const size_t first = str.find_first_not_of(" \t\n\r\f\v");
|
||||
if (first == std::string::npos) {
|
||||
str.clear(); // Fix: clear all-whitespace strings
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t last = str.find_last_not_of(" \t\n\r\f\v");
|
||||
|
||||
// True in-place modification - no temporary string creation
|
||||
if (last + 1 < str.length()) {
|
||||
str.erase(last + 1); // Remove trailing whitespace
|
||||
}
|
||||
if (first > 0) {
|
||||
str.erase(0, first); // Remove leading whitespace
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to trim newline characters from the end of a string
|
||||
void trimNewline(std::string& str) {
|
||||
const size_t end = str.find_last_not_of("\n");
|
||||
if (end == std::string::npos) {
|
||||
str.clear(); // If the string consists entirely of newlines, clear it
|
||||
} else {
|
||||
str.erase(end + 1); // Remove all characters after the last non-newline character
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes all white spaces from a string.
|
||||
*
|
||||
* This function removes all white spaces, including spaces, tabs, newlines, carriage returns, form feeds,
|
||||
* and vertical tabs from the input string.
|
||||
*
|
||||
* @param str The input string to remove white spaces from.
|
||||
* @return The string with white spaces removed.
|
||||
*/
|
||||
std::string removeWhiteSpaces(const std::string& str) {
|
||||
std::string result;
|
||||
result.reserve(str.size()); // Reserve space for the result to avoid reallocations
|
||||
|
||||
std::remove_copy_if(str.begin(), str.end(), std::back_inserter(result), [](unsigned char c) {
|
||||
return std::isspace(c);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes quotes from a string.
|
||||
*
|
||||
* This function removes single and double quotes from the beginning and end of the input string.
|
||||
*
|
||||
* @param str The input string to remove quotes from.
|
||||
* @return The string with quotes removed.
|
||||
*/
|
||||
void removeQuotes(std::string& str) {
|
||||
if (str.size() >= 2) {
|
||||
const char front = str[0];
|
||||
const char back = str[str.size() - 1];
|
||||
if ((front == '\'' && back == '\'') || (front == '"' && back == '"')) {
|
||||
str.erase(0, 1);
|
||||
str.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Replaces multiple consecutive slashes with a single slash in a string.
|
||||
*
|
||||
* This function replaces sequences of two or more consecutive slashes with a single slash in the input string.
|
||||
*
|
||||
* @param input The input string to process.
|
||||
* @return The string with multiple slashes replaced.
|
||||
*/
|
||||
std::string replaceMultipleSlashes(const std::string& input) {
|
||||
std::string output;
|
||||
output.reserve(input.size()); // Reserve space for the output string
|
||||
|
||||
bool previousSlash = false;
|
||||
for (char c : input) {
|
||||
if (c == '/') {
|
||||
if (!previousSlash) {
|
||||
output.push_back(c);
|
||||
}
|
||||
previousSlash = true;
|
||||
} else {
|
||||
output.push_back(c);
|
||||
previousSlash = false;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a path string by replacing multiple slashes and adding "sdmc:" prefix.
|
||||
*
|
||||
* This function preprocesses a path string by removing multiple consecutive slashes,
|
||||
* resolving relative path components (. and ..), adding the "sdmc:" prefix if not present,
|
||||
* and modifying the input string in place.
|
||||
*
|
||||
* @param path The input path string to preprocess, passed by reference.
|
||||
* @param packagePath The base package path to resolve relative paths against.
|
||||
*/
|
||||
void preprocessPath(std::string& path, const std::string& packagePath) {
|
||||
removeQuotes(path);
|
||||
|
||||
if (path.empty())
|
||||
return;
|
||||
|
||||
// In-place multiple slash removal
|
||||
size_t writePos = 0;
|
||||
bool previousSlash = false;
|
||||
|
||||
for (size_t i = 0, len = path.length(); i < len; ++i) {
|
||||
const char c = path[i];
|
||||
if (c == '/') {
|
||||
if (!previousSlash) {
|
||||
path[writePos++] = '/';
|
||||
previousSlash = true;
|
||||
}
|
||||
} else {
|
||||
path[writePos++] = c;
|
||||
previousSlash = false;
|
||||
}
|
||||
}
|
||||
path.resize(writePos);
|
||||
|
||||
// Handle "./" replacement if present
|
||||
if (!packagePath.empty() && path.length() >= 2 && path[0] == '.' && path[1] == '/') {
|
||||
path.replace(0, 2, packagePath);
|
||||
}
|
||||
|
||||
// Handle "../" sequences
|
||||
size_t dotDotPos;
|
||||
size_t searchEnd;
|
||||
while ((dotDotPos = path.find("../")) != std::string::npos) {
|
||||
// Check if there's a trailing slash before "../"
|
||||
searchEnd = dotDotPos;
|
||||
if (searchEnd > 0 && path[searchEnd - 1] == '/') {
|
||||
--searchEnd;
|
||||
}
|
||||
|
||||
// Find the previous slash
|
||||
const size_t lastSlash = (searchEnd > 0) ? path.rfind('/', searchEnd - 1) : std::string::npos;
|
||||
|
||||
if (lastSlash != std::string::npos) {
|
||||
// Erase from after lastSlash to after "../"
|
||||
path.erase(lastSlash + 1, dotDotPos + 3 - lastSlash - 1);
|
||||
} else {
|
||||
// No slash found, replace with root
|
||||
path.erase(0, dotDotPos);
|
||||
path.insert(0, "/");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for sdmc: prefix
|
||||
if (path.length() < 5 ||
|
||||
path[0] != 's' || path[1] != 'd' || path[2] != 'm' || path[3] != 'c' || path[4] != ':') {
|
||||
path.insert(0, "sdmc:");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Preprocesses a URL string by adding "https://" prefix.
|
||||
*
|
||||
* This function preprocesses a URL string by adding the "https://" prefix if not already present.
|
||||
*
|
||||
* @param path The input URL string to preprocess, passed by reference and modified in-place.
|
||||
*/
|
||||
void preprocessUrl(std::string& path) {
|
||||
removeQuotes(path);
|
||||
|
||||
if (path.size() >= 7 && path[0] == 'h' && path[1] == 't' &&
|
||||
path[2] == 't' && path[3] == 'p') {
|
||||
if ((path.size() >= 8 && path[4] == 's' && path[5] == ':') ||
|
||||
(path[4] == ':')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
path.insert(0, "https://");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Drops the file extension from a filename.
|
||||
*
|
||||
* This function removes the file extension (characters after the last dot) from the input filename string.
|
||||
*
|
||||
* @param filename The input filename from which to drop the extension, passed by reference and modified in-place.
|
||||
*/
|
||||
void dropExtension(std::string& filename) {
|
||||
const size_t lastDotPos = filename.find_last_of('.'); // Single char instead of string
|
||||
if (lastDotPos != std::string::npos) {
|
||||
filename.resize(lastDotPos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if a string starts with a given prefix.
|
||||
*
|
||||
* This function checks if the input string starts with the specified prefix.
|
||||
*
|
||||
* @param str The input string to check.
|
||||
* @param prefix The prefix to check for.
|
||||
* @return True if the string starts with the prefix, false otherwise.
|
||||
*/
|
||||
bool startsWith(const std::string& str, const std::string& prefix) {
|
||||
return str.compare(0, prefix.length(), prefix) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper function to check if a string is a valid integer
|
||||
bool isValidNumber(const std::string& str) {
|
||||
if (str.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t start = 0;
|
||||
if (str[0] == '-' || str[0] == '+') {
|
||||
if (str.length() == 1) return false;
|
||||
start = 1;
|
||||
}
|
||||
|
||||
for (size_t i = start; i < str.length(); ++i) {
|
||||
if (!std::isdigit(static_cast<unsigned char>(str[i]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string returnOrNull(const std::string& value) {
|
||||
return value.empty() ? NULL_STR : value;
|
||||
}
|
||||
|
||||
|
||||
// Function to slice a string from start to end index
|
||||
std::string sliceString(const std::string& str, size_t start, size_t end) {
|
||||
if (start < 0) start = 0;
|
||||
if (end > static_cast<size_t>(str.length())) end = str.length();
|
||||
if (start > end) start = end;
|
||||
return str.substr(start, end - start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//std::string addQuotesIfNeeded(const std::string& str) {
|
||||
// if (str.find(' ') != std::string::npos) {
|
||||
// return "\"" + str + "\"";
|
||||
// }
|
||||
// return str;
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a string to lowercase.
|
||||
*
|
||||
* This function takes a string as input and returns a lowercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to lowercase.
|
||||
* @return The lowercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToLowercase(const std::string& str) {
|
||||
std::string result = str;
|
||||
//std::transform(result.begin(), result.end(), result.begin(),
|
||||
// [](unsigned char c) { return std::tolower(c); });
|
||||
//return result;
|
||||
for (char& c : result) {
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
c += 32;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts a string to uppercase.
|
||||
*
|
||||
* This function takes a string as input and returns an uppercase version of that string.
|
||||
*
|
||||
* @param str The input string to convert to uppercase.
|
||||
* @return The uppercase version of the input string.
|
||||
*/
|
||||
|
||||
std::string stringToUppercase(const std::string& str) {
|
||||
std::string result = str;
|
||||
for (char& c : result) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
c -= 32;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Formats a priority string to a desired width.
|
||||
*
|
||||
* This function takes a priority string and formats it to a specified desired width by padding with '0's if it's shorter
|
||||
* or truncating with '9's if it's longer.
|
||||
*
|
||||
* @param priority The input priority string to format.
|
||||
* @param desiredWidth The desired width of the formatted string (default is 4).
|
||||
* @return A formatted priority string.
|
||||
*/
|
||||
std::string formatPriorityString(const std::string& priority, int desiredWidth) {
|
||||
const int priorityLength = priority.length();
|
||||
|
||||
if (priorityLength > desiredWidth) {
|
||||
// FASTEST: Single allocation with direct fill
|
||||
return std::string(desiredWidth, '9');
|
||||
} else {
|
||||
// FASTEST: Single allocation + direct memory copy
|
||||
std::string result(desiredWidth, '0'); // Pre-fill with zeros
|
||||
memcpy(&result[desiredWidth - priorityLength], priority.data(), priorityLength);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes the part of the string after the first occurrence of '?' character.
|
||||
*
|
||||
* This function takes a string and removes the portion of the string that appears after
|
||||
* the first '?' character, if found. If no '?' character is present, the string remains unchanged.
|
||||
*
|
||||
* @param input The input string from which to remove the tag, passed by reference and modified in-place.
|
||||
*/
|
||||
void removeTag(std::string &input) {
|
||||
const size_t pos = input.find('?');
|
||||
if (pos != std::string::npos) {
|
||||
input.resize(pos); // Modify the string in-place to remove everything after the '?'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string getFirstLongEntry(const std::string& input, size_t minLength) {
|
||||
StringStream iss(input); // Use custom StringStream
|
||||
std::string word;
|
||||
|
||||
// Split the input string based on spaces and get the first word
|
||||
if (iss >> word) {
|
||||
// Check if the first word's length is greater than the specified length
|
||||
if (word.length() > minLength) {
|
||||
return word;
|
||||
}
|
||||
}
|
||||
|
||||
// Return an empty string if the first word is not longer than minLength
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
// This will take a string like "v1.3.5-abasdfasdfa" and output "1.3.5". string could also look like "test-1.3.5-1" or "v1.3.5" and we will only want "1.3.5"
|
||||
std::string cleanVersionLabel(const std::string& input) {
|
||||
std::string result;
|
||||
result.reserve(input.size());
|
||||
|
||||
size_t start = 0;
|
||||
|
||||
// Find the start of the version number (first digit)
|
||||
while (start < input.size() && !std::isdigit(input[start])) {
|
||||
start++;
|
||||
}
|
||||
|
||||
if (start == input.size()) {
|
||||
return ""; // No digits found
|
||||
}
|
||||
|
||||
|
||||
// Extract version number with dots and plus signs
|
||||
for (size_t i = start; i < input.size(); ++i) {
|
||||
const char c = input[i];
|
||||
if (std::isdigit(c) || c == '.' || c == '+') {
|
||||
result += c;
|
||||
} else {
|
||||
break; // Stop at first character that's not digit, dot, or plus
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string extractTitle(const std::string& input) {
|
||||
const size_t spacePos = input.find(' '); // Find the position of the first space
|
||||
|
||||
if (spacePos != std::string::npos) {
|
||||
// Extract the substring before the first space
|
||||
return input.substr(0, spacePos);
|
||||
} else {
|
||||
// If no space is found, return the original string
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, const std::string& delimiter) {
|
||||
std::vector<std::string> tokens;
|
||||
|
||||
// OPTIMIZATION: Pre-allocate space to avoid reallocations
|
||||
tokens.reserve(str.length() / (delimiter.length() + 1) + 1);
|
||||
|
||||
size_t start = 0;
|
||||
size_t end = str.find(delimiter);
|
||||
|
||||
while (end != std::string::npos) {
|
||||
// OPTIMIZATION: Direct construction instead of substr() - no temporary string
|
||||
tokens.emplace_back(str, start, end - start);
|
||||
start = end + delimiter.length();
|
||||
end = str.find(delimiter, start);
|
||||
}
|
||||
|
||||
// OPTIMIZATION: Direct construction for last token
|
||||
tokens.emplace_back(str, start);
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
// Function to split a string by a delimiter and return a specific index
|
||||
std::string splitStringAtIndex(const std::string& str, const std::string& delimiter, size_t index) {
|
||||
const std::vector<std::string> tokens = splitString(str, delimiter);
|
||||
|
||||
if (index < tokens.size()) {
|
||||
return tokens[index];
|
||||
} else {
|
||||
return ""; // Return empty string if index is out of bounds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string customAlign(int number) {
|
||||
const std::string numStr = ult::to_string(number);
|
||||
const int paddingSpaces = (4 - numStr.length()) * 2;
|
||||
|
||||
// FASTEST: Single allocation + direct memory operations
|
||||
std::string result(paddingSpaces + numStr.length(), ' ');
|
||||
memcpy(&result[paddingSpaces], numStr.data(), numStr.length());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//#if IS_LAUNCHER_DIRECTIVE
|
||||
//std::string inputExists(const std::string& input) {
|
||||
// std::string e;
|
||||
// for (char c : input) {
|
||||
// e += (c + 5);
|
||||
// }
|
||||
// return e;
|
||||
//}
|
||||
//#endif
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
# Ultrahand Library Configuration
|
||||
# Auto-detects libultrahand directory location
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
# Assume TOPDIR is the root project directory where you run make
|
||||
TOPDIR ?= $(CURDIR)
|
||||
|
||||
# Get the absolute path of this .mk file directory
|
||||
ULTRA_ABS := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
# Convert absolute path to relative path from TOPDIR
|
||||
ULTRA_DIR := $(subst $(TOPDIR)/,,$(ULTRA_ABS))
|
||||
|
||||
# If ULTRA_DIR equals ULTRA_ABS, then ULTRA_ABS is outside TOPDIR,
|
||||
# fallback to just ULTRA_ABS (rare case)
|
||||
ifeq ($(ULTRA_DIR),$(ULTRA_ABS))
|
||||
ULTRA_DIR := $(ULTRA_ABS)
|
||||
endif
|
||||
|
||||
|
||||
# Now add folder paths relative to TOPDIR (or absolute if fallback)
|
||||
SOURCES += \
|
||||
$(ULTRA_DIR)/common \
|
||||
$(ULTRA_DIR)/libultra/source
|
||||
|
||||
INCLUDES += \
|
||||
$(ULTRA_DIR)/common \
|
||||
$(ULTRA_DIR)/libultra/include \
|
||||
$(ULTRA_DIR)/libtesla/include
|
||||
@@ -57,7 +57,7 @@ class AppOverlay : public tsl::Overlay
|
||||
if(!sysclkIpcRunning())
|
||||
{
|
||||
return initially<FatalGui>(
|
||||
"Horizon OC is not running.\n\n"
|
||||
"sys-clk is not running.\n\n"
|
||||
"\n"
|
||||
"Please make sure it is correctly\n\n"
|
||||
"installed and enabled.",
|
||||
@@ -68,7 +68,7 @@ class AppOverlay : public tsl::Overlay
|
||||
if(R_FAILED(sysclkIpcInitialize()) || R_FAILED(sysclkIpcGetAPIVersion(&apiVersion)))
|
||||
{
|
||||
return initially<FatalGui>(
|
||||
"Could not connect to Horizon OC.\n\n"
|
||||
"Could not connect to sys-clk.\n\n"
|
||||
"\n"
|
||||
"Please make sure it is correctly\n\n"
|
||||
"installed and enabled.",
|
||||
@@ -80,7 +80,7 @@ class AppOverlay : public tsl::Overlay
|
||||
{
|
||||
return initially<FatalGui>(
|
||||
"Overlay not compatible with\n\n"
|
||||
"the running Horizon OC version.\n\n"
|
||||
"the running sys-clk version.\n\n"
|
||||
"\n"
|
||||
"Please make sure everything is\n\n"
|
||||
"installed and up to date.",
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -24,124 +24,37 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "base_gui.h"
|
||||
|
||||
#include "../elements/base_frame.h"
|
||||
#include "logo_rgba_bin.h"
|
||||
|
||||
#include <tesla.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Layout constants
|
||||
// -------------------------------------------------------------
|
||||
|
||||
|
||||
#define LOGO_X 20
|
||||
#define LOGO_Y 50
|
||||
#define LOGO_LABEL_FONT_SIZE 45
|
||||
#define LOGO_Y 45
|
||||
#define LOGO_LABEL_FONT_SIZE 35
|
||||
|
||||
#define VERSION_X (LOGO_X + 250)
|
||||
#define VERSION_Y (LOGO_Y - 40)
|
||||
#define VERSION_Y LOGO_Y-40
|
||||
#define VERSION_FONT_SIZE 15
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Version string getter
|
||||
// -------------------------------------------------------------
|
||||
|
||||
std::string getVersionString() {
|
||||
char buf[0x100] = "";
|
||||
char buf[0x100] = ""; // 256 bytes — safe for any expected version string
|
||||
Result rc = sysclkIpcGetVersionString(buf, sizeof(buf));
|
||||
if (R_FAILED(rc) || buf[0] == '\0') {
|
||||
return "HorizonOC-Misc";
|
||||
return "unknown";
|
||||
}
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Animated Ultra Text
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// Your animated wave colors (example placeholders)
|
||||
static constexpr tsl::Color dynamicLogoRGB1 = tsl::Color(40, 255, 80, 255);
|
||||
static constexpr tsl::Color dynamicLogoRGB2 = tsl::Color(120, 255, 160, 255);
|
||||
|
||||
// Your project name rendered letter-by-letter
|
||||
static constexpr const char* PROJECT_NAME = "Horizon OC Gaea";
|
||||
|
||||
// Fully corrected function signature
|
||||
static s32 drawDynamicUltraText(
|
||||
tsl::gfx::Renderer* renderer,
|
||||
s32 startX,
|
||||
s32 y,
|
||||
u32 fontSize,
|
||||
const tsl::Color& staticColor,
|
||||
bool useNotificationMethod = false)
|
||||
{
|
||||
static constexpr double cycleDuration = 1.6;
|
||||
|
||||
const std::string name = "Horizon OC Gaea";
|
||||
s32 currentX = startX;
|
||||
|
||||
const u64 currentTime_ns = armTicksToNs(armGetSystemTick());
|
||||
const double timeNow = static_cast<double>(currentTime_ns) / 1e9;
|
||||
const double timeBase = fmod(timeNow, cycleDuration);
|
||||
|
||||
// Controls wave spacing
|
||||
const double waveScale = 2.0 * M_PI / cycleDuration;
|
||||
|
||||
// Every character has its own index offset
|
||||
for (size_t i = 0; i < name.size(); i++)
|
||||
{
|
||||
char letter = name[i];
|
||||
if (letter == '\0') break;
|
||||
|
||||
// phase shift per character → THIS CREATES THE WAVE
|
||||
double phase = waveScale * (timeBase + i * 0.12);
|
||||
|
||||
double raw = cos(phase);
|
||||
double n = (raw + 1.0) * 0.5;
|
||||
|
||||
// Smoothstep ×2 (ultra smooth)
|
||||
double s1 = n * n * (3.0 - 2.0 * n);
|
||||
double s2 = s1 * s1 * (3.0 - 2.0 * s1);
|
||||
|
||||
double blend = std::clamp(s2, 0.0, 1.0);
|
||||
|
||||
tsl::Color color = {
|
||||
static_cast<u8>(staticColor.r + (dynamicLogoRGB2.r - staticColor.r) * blend),
|
||||
static_cast<u8>(staticColor.g + (dynamicLogoRGB2.g - staticColor.g) * blend),
|
||||
static_cast<u8>(staticColor.b + (dynamicLogoRGB2.b - staticColor.b) * blend),
|
||||
255
|
||||
};
|
||||
|
||||
std::string ls(1, letter);
|
||||
|
||||
if (useNotificationMethod)
|
||||
currentX += renderer->drawNotificationString(ls, false, currentX, y, fontSize, color).first;
|
||||
else
|
||||
currentX += renderer->drawString(ls, false, currentX, y, fontSize, color).first;
|
||||
}
|
||||
|
||||
return currentX;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Rendering functions
|
||||
// -------------------------------------------------------------
|
||||
|
||||
void BaseGui::preDraw(tsl::gfx::Renderer* renderer)
|
||||
{
|
||||
static constexpr tsl::Color STATIC_GREEN = tsl::Color(80, 255, 120, 255);
|
||||
|
||||
drawDynamicUltraText(
|
||||
renderer,
|
||||
LOGO_X,
|
||||
LOGO_Y,
|
||||
LOGO_LABEL_FONT_SIZE,
|
||||
STATIC_GREEN,
|
||||
false
|
||||
);
|
||||
// renderer->drawBitmap(LOGO_X, LOGO_Y, LOGO_WIDTH, LOGO_HEIGHT, logo_rgba_bin);
|
||||
renderer->drawString("Horizon OC overlay", false, LOGO_X, LOGO_Y, LOGO_LABEL_FONT_SIZE, renderer->a(TEXT_COLOR));
|
||||
// renderer->drawString(TARGET_VERSION, false, VERSION_X, VERSION_Y, VERSION_FONT_SIZE, tsl::bannerVersionTextColor);
|
||||
}
|
||||
|
||||
tsl::elm::Element* BaseGui::createUI()
|
||||
|
||||
@@ -25,184 +25,154 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "freq_choice_gui.h"
|
||||
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
|
||||
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz,
|
||||
std::uint32_t* hzList,
|
||||
std::uint32_t hzCount,
|
||||
SysClkModule module,
|
||||
FreqChoiceListener listener,
|
||||
bool checkMax,
|
||||
std::map<uint32_t, std::string> labels)
|
||||
{
|
||||
this->selectedHz = selectedHz;
|
||||
this->hzList = hzList;
|
||||
this->hzCount = hzCount;
|
||||
this->module = module;
|
||||
this->listener = listener;
|
||||
this->checkMax = checkMax;
|
||||
this->labels = labels; // NEW
|
||||
this->configList = new SysClkConfigValueList {};
|
||||
}
|
||||
#include "freq_choice_gui.h"
|
||||
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
|
||||
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedHz, std::uint32_t *hzList, std::uint32_t hzCount, SysClkModule module, FreqChoiceListener listener, bool checkMax)
|
||||
{
|
||||
this->selectedHz = selectedHz;
|
||||
this->hzList = hzList;
|
||||
this->hzCount = hzCount;
|
||||
this->module = module;
|
||||
this->listener = listener;
|
||||
this->checkMax = checkMax;
|
||||
this->configList = new SysClkConfigValueList {};
|
||||
}
|
||||
FreqChoiceGui::~FreqChoiceGui()
|
||||
{
|
||||
delete this->configList;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety)
|
||||
{
|
||||
std::string text = formatListFreqHz(hz);
|
||||
if (selected)
|
||||
text += " \uE14B";
|
||||
|
||||
// NEW: Right-side label
|
||||
std::string rightText = "";
|
||||
auto it = labels.find(hz);
|
||||
if (it != labels.end())
|
||||
rightText = it->second;
|
||||
|
||||
tsl::elm::ListItem* listItem =
|
||||
new tsl::elm::ListItem(text, rightText, false);
|
||||
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
// Make annotation grey
|
||||
if (!rightText.empty())
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
|
||||
listItem->setClickListener([this, hz](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(hz)) {
|
||||
tsl::goBack();
|
||||
tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t hz, bool selected, int safety)
|
||||
{
|
||||
std::string text = formatListFreqHz(hz);
|
||||
if (selected) text += " \uE14B";
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, "", false);
|
||||
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
listItem->setClickListener([this, hz](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(hz)) {
|
||||
tsl::goBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return listItem;
|
||||
}
|
||||
|
||||
void FreqChoiceGui::listUI()
|
||||
{
|
||||
sysclkIpcGetConfigValues(this->configList);
|
||||
// Add CategoryHeader based on module
|
||||
std::string moduleName = sysclkFormatModule(this->module, false);
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName));
|
||||
|
||||
this->listElement->addItem(this->createFreqListItem(0, this->selectedHz == 0, false));
|
||||
std::uint32_t hz;
|
||||
for (std::uint32_t i = 0; i < this->hzCount; i++)
|
||||
{
|
||||
hz = this->hzList[i];
|
||||
uint32_t mhz = hz / 1000000;
|
||||
// Skip 204 MHz exactly
|
||||
if(checkMax && IsMariko()) {
|
||||
if (this->configList->values[HocClkConfigValue_MarikoMaxCpuClock] < mhz && moduleName == "cpu") {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return listItem;
|
||||
}
|
||||
|
||||
void FreqChoiceGui::listUI()
|
||||
{
|
||||
sysclkIpcGetConfigValues(this->configList);
|
||||
|
||||
// Header based on CPU/GPU/MEM module
|
||||
std::string moduleName = sysclkFormatModule(this->module, false);
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(moduleName));
|
||||
|
||||
// Default option
|
||||
this->listElement->addItem(
|
||||
this->createFreqListItem(0, this->selectedHz == 0, 0));
|
||||
|
||||
for (std::uint32_t i = 0; i < this->hzCount; i++)
|
||||
{
|
||||
std::uint32_t hz = this->hzList[i];
|
||||
uint32_t mhz = hz / 1000000;
|
||||
|
||||
if (checkMax && IsMariko()) {
|
||||
if (moduleName == "cpu" &&
|
||||
this->configList->values[HocClkConfigValue_MarikoMaxCpuClock] < mhz)
|
||||
|
||||
if (this->configList->values[HocClkConfigValue_MarikoMaxGpuClock] < mhz && moduleName == "gpu") {
|
||||
continue;
|
||||
|
||||
if (moduleName == "gpu" &&
|
||||
this->configList->values[HocClkConfigValue_MarikoMaxGpuClock] < mhz)
|
||||
}
|
||||
if (this->configList->values[HocClkConfigValue_MarikoMaxMemClock] < mhz && moduleName == "mem") {
|
||||
continue;
|
||||
|
||||
if (moduleName == "mem" &&
|
||||
this->configList->values[HocClkConfigValue_MarikoMaxMemClock] < mhz)
|
||||
continue;
|
||||
|
||||
}
|
||||
} else if (checkMax && IsErista()) {
|
||||
if (moduleName == "cpu" &&
|
||||
this->configList->values[HocClkConfigValue_EristaMaxCpuClock] < mhz)
|
||||
if (this->configList->values[HocClkConfigValue_EristaMaxCpuClock] < mhz && moduleName == "cpu") {
|
||||
continue;
|
||||
|
||||
if (moduleName == "gpu" &&
|
||||
this->configList->values[HocClkConfigValue_EristaMaxGpuClock] < mhz)
|
||||
}
|
||||
|
||||
if (this->configList->values[HocClkConfigValue_EristaMaxGpuClock] < mhz && moduleName == "gpu") {
|
||||
continue;
|
||||
|
||||
if (moduleName == "mem" &&
|
||||
this->configList->values[HocClkConfigValue_EristaMaxMemClock] < mhz)
|
||||
}
|
||||
if (this->configList->values[HocClkConfigValue_EristaMaxMemClock] < mhz && moduleName == "mem") {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (moduleName == "mem" && mhz <= 600)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
uint32_t unsafe_cpu;
|
||||
uint32_t unsafe_gpu;
|
||||
uint32_t danger_cpu;
|
||||
uint32_t danger_gpu;
|
||||
if (IsMariko())
|
||||
{
|
||||
unsafe_cpu = 1964;
|
||||
unsafe_gpu = 1076;
|
||||
danger_cpu = 2398;
|
||||
danger_gpu = 1306;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsafe_cpu = 1786;
|
||||
unsafe_gpu = 922;
|
||||
danger_cpu = 2092;
|
||||
danger_gpu = 999;
|
||||
}
|
||||
|
||||
if (moduleName == "mem" && mhz <= 600)
|
||||
if (moduleName == "cpu") {
|
||||
if (mhz >= danger_cpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 2));
|
||||
continue;
|
||||
}
|
||||
if (mhz >= unsafe_cpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 1));
|
||||
continue;
|
||||
}
|
||||
if (mhz <= unsafe_cpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 0));
|
||||
continue;
|
||||
}
|
||||
} else if (moduleName == "gpu") {
|
||||
if (mhz >= danger_gpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 2));
|
||||
continue;
|
||||
}
|
||||
if (mhz >= unsafe_gpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 1));
|
||||
continue;
|
||||
}
|
||||
if (mhz <= unsafe_gpu) {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 0));
|
||||
continue;
|
||||
}
|
||||
} else if (moduleName == "mem") {
|
||||
this->listElement->addItem(this->createFreqListItem(hz, mhz == this->selectedHz / 1000000, 0));
|
||||
continue;
|
||||
|
||||
uint32_t unsafe_cpu;
|
||||
uint32_t unsafe_gpu;
|
||||
uint32_t danger_cpu;
|
||||
uint32_t danger_gpu;
|
||||
|
||||
if (IsMariko())
|
||||
{
|
||||
unsafe_cpu = 1964;
|
||||
unsafe_gpu = 1076;
|
||||
danger_cpu = 2398;
|
||||
danger_gpu = 1306;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsafe_cpu = 1786;
|
||||
unsafe_gpu = 922;
|
||||
danger_cpu = 2092;
|
||||
danger_gpu = 999;
|
||||
}
|
||||
|
||||
int safety = 0;
|
||||
|
||||
if (moduleName == "cpu") {
|
||||
|
||||
if (mhz >= danger_cpu)
|
||||
safety = 2;
|
||||
else if (mhz >= unsafe_cpu)
|
||||
safety = 1;
|
||||
else
|
||||
safety = 0;
|
||||
|
||||
} else if (moduleName == "gpu") {
|
||||
|
||||
if (mhz >= danger_gpu)
|
||||
safety = 2;
|
||||
else if (mhz >= unsafe_gpu)
|
||||
safety = 1;
|
||||
else
|
||||
safety = 0;
|
||||
|
||||
} else if (moduleName == "mem") {
|
||||
|
||||
safety = 0;
|
||||
|
||||
}
|
||||
|
||||
this->listElement->addItem(
|
||||
this->createFreqListItem(
|
||||
hz,
|
||||
(mhz == this->selectedHz / 1000000),
|
||||
safety
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
this->listElement->jumpToItem("", "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
this->listElement->jumpToItem("", "");
|
||||
}
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using FreqChoiceListener = std::function<bool(std::uint32_t hz)>;
|
||||
@@ -43,24 +42,19 @@ protected:
|
||||
std::uint32_t selectedHz;
|
||||
std::uint32_t* hzList;
|
||||
std::uint32_t hzCount;
|
||||
SysClkModule module;
|
||||
SysClkModule module; // added module
|
||||
FreqChoiceListener listener;
|
||||
bool checkMax;
|
||||
|
||||
// NEW: Optional annotation labels
|
||||
std::map<uint32_t, std::string> labels;
|
||||
|
||||
bool checkMax; // new member
|
||||
tsl::elm::ListItem* createFreqListItem(std::uint32_t hz, bool selected, int safety);
|
||||
|
||||
public:
|
||||
// Updated constructor with checkMaxValue
|
||||
FreqChoiceGui(std::uint32_t selectedHz,
|
||||
std::uint32_t* hzList,
|
||||
std::uint32_t hzCount,
|
||||
SysClkModule module,
|
||||
FreqChoiceListener listener,
|
||||
bool checkMax = true,
|
||||
std::map<uint32_t, std::string> labels = {}); // NEW ARG
|
||||
|
||||
bool checkMax = true);
|
||||
~FreqChoiceGui();
|
||||
|
||||
void listUI() override;
|
||||
|
||||
@@ -59,8 +59,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
const char* altName,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels)
|
||||
const ValueThresholds* thresholds)
|
||||
{
|
||||
const char* configName = altName ? altName : sysclkFormatConfigValue(configVal, true);
|
||||
|
||||
@@ -83,7 +82,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
ValueThresholds thresholdsCopy = (thresholds ? *thresholds : ValueThresholds{});
|
||||
|
||||
listItem->setClickListener(
|
||||
[this, configVal, range, categoryName, thresholdsCopy, labels](u64 keys)
|
||||
[this, configVal, range, categoryName, thresholdsCopy](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == 0)
|
||||
return false;
|
||||
@@ -107,8 +106,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
return true;
|
||||
},
|
||||
thresholdsCopy,
|
||||
true,
|
||||
labels // <── NEW
|
||||
true
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -125,10 +123,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
}
|
||||
this->lastContextUpdate = armGetSystemTick();
|
||||
return true;
|
||||
},
|
||||
ValueThresholds(),
|
||||
false,
|
||||
labels // <── NEW
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -140,11 +135,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
this->configRanges[configVal] = range;
|
||||
}
|
||||
|
||||
void MiscGui::addFreqButton(SysClkConfigValue configVal,
|
||||
const char* altName,
|
||||
SysClkModule module,
|
||||
const std::map<uint32_t, std::string>& labels)
|
||||
{
|
||||
void MiscGui::addFreqButton(SysClkConfigValue configVal, const char* altName, SysClkModule module) {
|
||||
const char* configName = altName ? altName : sysclkFormatConfigValue(configVal, true);
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(configName);
|
||||
@@ -154,48 +145,45 @@ void MiscGui::addFreqButton(SysClkConfigValue configVal,
|
||||
snprintf(valueText, sizeof(valueText), "%lu MHz", currentMHz);
|
||||
listItem->setValue(valueText);
|
||||
|
||||
listItem->setClickListener(
|
||||
[this, configVal, module, labels](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == 0)
|
||||
return false;
|
||||
listItem->setClickListener([this, configVal, module](u64 keys) {
|
||||
if ((keys & HidNpadButton_A) == 0)
|
||||
return false;
|
||||
|
||||
std::uint32_t hzList[SYSCLK_FREQ_LIST_MAX];
|
||||
std::uint32_t hzCount;
|
||||
std::uint32_t hzList[SYSCLK_FREQ_LIST_MAX];
|
||||
std::uint32_t hzCount;
|
||||
|
||||
Result rc = sysclkIpcGetFreqList(module, hzList, SYSCLK_FREQ_LIST_MAX, &hzCount);
|
||||
if (R_FAILED(rc)) {
|
||||
FatalGui::openWithResultCode("sysclkIpcGetFreqList", rc);
|
||||
return false;
|
||||
}
|
||||
Result rc = sysclkIpcGetFreqList(module, hzList, SYSCLK_FREQ_LIST_MAX, &hzCount);
|
||||
if (R_FAILED(rc)) {
|
||||
FatalGui::openWithResultCode("sysclkIpcGetFreqList", rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::uint32_t currentHz = this->configList->values[configVal] * 1'000'000;
|
||||
std::uint32_t currentHz = this->configList->values[configVal] * 1'000'000;
|
||||
|
||||
tsl::changeTo<FreqChoiceGui>(
|
||||
currentHz,
|
||||
hzList,
|
||||
hzCount,
|
||||
module,
|
||||
[this, configVal](std::uint32_t hz)
|
||||
{
|
||||
uint64_t mhz = hz / 1'000'000;
|
||||
this->configList->values[configVal] = mhz;
|
||||
tsl::changeTo<FreqChoiceGui>(
|
||||
currentHz,
|
||||
hzList,
|
||||
hzCount,
|
||||
module,
|
||||
[this, configVal](std::uint32_t hz) {
|
||||
|
||||
Result rc = sysclkIpcSetConfigValues(this->configList);
|
||||
if (R_FAILED(rc)) {
|
||||
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
|
||||
return false;
|
||||
}
|
||||
uint64_t mhz = hz / 1'000'000;
|
||||
this->configList->values[configVal] = mhz;
|
||||
|
||||
this->lastContextUpdate = armGetSystemTick();
|
||||
return true;
|
||||
},
|
||||
false,
|
||||
labels
|
||||
);
|
||||
Result rc = sysclkIpcSetConfigValues(this->configList);
|
||||
if (R_FAILED(rc)) {
|
||||
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
this->lastContextUpdate = armGetSystemTick();
|
||||
return true;
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
this->listElement->addItem(listItem);
|
||||
this->configButtons[configVal] = listItem;
|
||||
@@ -216,184 +204,46 @@ void MiscGui::listUI()
|
||||
addConfigToggle(HocClkConfigValue_UncappedClocks, nullptr);
|
||||
addConfigToggle(HocClkConfigValue_OverwriteBoostMode, nullptr);
|
||||
|
||||
// this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental"));
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("Experimental"));
|
||||
addConfigToggle(HocClkConfigValue_ThermalThrottle, nullptr);
|
||||
addConfigToggle(HocClkConfigValue_HandheldTDP, nullptr);
|
||||
addConfigToggle(HocClkConfigValue_EnforceBoardLimit, nullptr);
|
||||
std::map<uint32_t, std::string> labels_pwr_r = {
|
||||
{8600, "Official Rating"}
|
||||
};
|
||||
std::map<uint32_t, std::string> labels_pwr_l = {
|
||||
{6400, "Official Rating"}
|
||||
};
|
||||
|
||||
ValueThresholds tdpThresholds(8600, 9500);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_HandheldTDPLimit,
|
||||
"TDP Threshold",
|
||||
ValueRange(5000, 10000, 200, "mW", 1),
|
||||
ValueRange(5000, 10000, 100, "mW", 1),
|
||||
"Power",
|
||||
&tdpThresholds,
|
||||
labels_pwr_r
|
||||
&tdpThresholds
|
||||
);
|
||||
|
||||
ValueThresholds tdpThresholdsLite(6400, 7500);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_LiteTDPLimit,
|
||||
"Lite TDP Threshold",
|
||||
ValueRange(4000, 8000, 200, "mW", 1),
|
||||
ValueRange(4000, 8000, 100, "mW", 1),
|
||||
"Power",
|
||||
&tdpThresholdsLite,
|
||||
labels_pwr_l
|
||||
&tdpThresholdsLite
|
||||
);
|
||||
|
||||
ValueThresholds throttleThresholds(70, 80);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_ThermalThrottleThreshold,
|
||||
"Thermal Throttle Limit",
|
||||
ValueRange(50, 85, 5, "°C", 1),
|
||||
ValueRange(50, 85, 1, "°C", 1),
|
||||
"Temp",
|
||||
&throttleThresholds
|
||||
);
|
||||
std::map<uint32_t, std::string> cpu_freq_label_m = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Boost Mode"},
|
||||
{1963000000, "Safe Max"},
|
||||
{2397000000, "Unsafe Max"},
|
||||
{2805000000, "Aboslute Max"},
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> cpu_freq_label_e = {
|
||||
{612000000, "Sleep Mode"},
|
||||
{1020000000, "Stock"},
|
||||
{1224000000, "Dev OC"},
|
||||
{1785000000, "Boost Mode & Safe Max"},
|
||||
{2091000000, "Unsafe Max"},
|
||||
{2295000000, "Aboslute Max"},
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_e = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{460800000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{844000000, "Safe Max"},
|
||||
{998400000, "Unsafe Max"},
|
||||
{1075200000, "Aboslute Max"},
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> gpu_freq_label_m = {
|
||||
{76800000, "Boost Mode"},
|
||||
{307200000, "Handheld"},
|
||||
{384000000, "Handheld"},
|
||||
{460800000, "Handheld"},
|
||||
{614400000, "Handheld Safe Max"},
|
||||
{768000000, "Docked"},
|
||||
{1152200000, "Safe Max"},
|
||||
{1305600000, "Unsafe Max"},
|
||||
{1536000000, "Aboslute Max"},
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> emc_freq_label_e = {
|
||||
{133120000, "Handheld"},
|
||||
{160000000, "Docked & Safe Max"},
|
||||
{213100000, "JEDEC Max"},
|
||||
{236000000, "Absolute Max"},
|
||||
};
|
||||
|
||||
|
||||
std::map<uint32_t, std::string> emc_freq_label_m = {
|
||||
{133120000, "Handheld"},
|
||||
{160000000, "Docked"},
|
||||
{186600000, "Safe Max (3733MT/s)"},
|
||||
{213300000, "Safe Max (4266MT/s)"},
|
||||
{320000000, "Absolute Max"},
|
||||
};
|
||||
|
||||
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("Clocks"));
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("Max Clocks"));
|
||||
if(IsMariko()) {
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxCpuClock, nullptr, SysClkModule_CPU, cpu_freq_label_m);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxGpuClock, nullptr, SysClkModule_GPU, gpu_freq_label_m);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxMemClock, nullptr, SysClkModule_MEM, emc_freq_label_m);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxCpuClock, nullptr, SysClkModule_CPU);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxGpuClock, nullptr, SysClkModule_GPU);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxMemClock, nullptr, SysClkModule_MEM);
|
||||
} else {
|
||||
addFreqButton(HocClkConfigValue_EristaMaxCpuClock, nullptr, SysClkModule_CPU, cpu_freq_label_e);
|
||||
addFreqButton(HocClkConfigValue_EristaMaxGpuClock, nullptr, SysClkModule_GPU, gpu_freq_label_e);
|
||||
addFreqButton(HocClkConfigValue_EristaMaxMemClock, nullptr, SysClkModule_MEM, emc_freq_label_e);
|
||||
addFreqButton(HocClkConfigValue_EristaMaxCpuClock, nullptr, SysClkModule_CPU);
|
||||
addFreqButton(HocClkConfigValue_EristaMaxGpuClock, nullptr, SysClkModule_GPU);
|
||||
addFreqButton(HocClkConfigValue_EristaMaxMemClock, nullptr, SysClkModule_MEM);
|
||||
}
|
||||
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("EMC"));
|
||||
|
||||
addConfigToggle(HocClkConfigValue_EMCDVFS, nullptr);
|
||||
|
||||
std::map<uint32_t, std::string> emc_voltage_label_m = {
|
||||
{1100000, "Default"},
|
||||
{1175000, "Rating"},
|
||||
{1212500, "Safe Max"},
|
||||
};
|
||||
|
||||
std::map<uint32_t, std::string> emc_voltage_label_e = {
|
||||
{1125000, "Default"},
|
||||
{1175000, "Rating"},
|
||||
{1237500, "Safe Max"},
|
||||
};
|
||||
|
||||
|
||||
if(IsMariko()) {
|
||||
ValueThresholds emcUvThresholds(1212500, 1250000);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_EMCVdd2VoltageUV,
|
||||
"EMC VDD2 Voltage",
|
||||
ValueRange(1100000, 1237500, 12500, "mV", 1000, 1),
|
||||
"EMC VDD2 Voltage",
|
||||
&emcUvThresholds,
|
||||
emc_voltage_label_m
|
||||
);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_EMCVdd2VoltageUVStockMariko,
|
||||
"EMC Stock VDD2 Voltage",
|
||||
ValueRange(912500, 1175000, 12500, "mV", 1000, 1),
|
||||
"EMC Stock VDD2 Voltage",
|
||||
&emcUvThresholds,
|
||||
emc_voltage_label_m
|
||||
);
|
||||
} else {
|
||||
ValueThresholds emcUvThresholds(1237500, 1300000);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_EMCVdd2VoltageUV,
|
||||
"EMC VDD2 Voltage",
|
||||
ValueRange(1100000, 1237500, 12500, "mV", 1000, 1),
|
||||
"EMC VDD2 Voltage",
|
||||
&emcUvThresholds,
|
||||
emc_voltage_label_e
|
||||
);
|
||||
addConfigButton(
|
||||
HocClkConfigValue_EMCVdd2VoltageUVStockErista,
|
||||
"EMC Stock VDD2 Voltage",
|
||||
ValueRange(1000000, 1175000, 12500, "mV", 1000, 1),
|
||||
"EMC Stock VDD2 Voltage",
|
||||
&emcUvThresholds,
|
||||
emc_voltage_label_e
|
||||
);
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* applyBtn = new tsl::elm::ListItem("Apply EMC Regs");
|
||||
applyBtn->setClickListener([](u64 keys) {
|
||||
if (keys & HidNpadButton_A) {
|
||||
Result rc = hocClkIpcUpdateEmcRegs();
|
||||
if (R_FAILED(rc)) {
|
||||
FatalGui::openWithResultCode("hocClkIpcUpdateEmcRegs", rc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
this->listElement->addItem(applyBtn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MiscGui::refresh() {
|
||||
|
||||
@@ -27,12 +27,8 @@ protected:
|
||||
const char* altName,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels = {});
|
||||
void addFreqButton(SysClkConfigValue configVal,
|
||||
const char* altName,
|
||||
SysClkModule module,
|
||||
const std::map<uint32_t, std::string>& labels = {});
|
||||
const ValueThresholds* thresholds = nullptr);
|
||||
void addFreqButton(SysClkConfigValue configVal, const char* altName, SysClkModule module);
|
||||
void updateConfigToggles();
|
||||
|
||||
tsl::elm::ToggleListItem* enabledToggle;
|
||||
|
||||
@@ -1,121 +1,145 @@
|
||||
#include "value_choice_gui.h"
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
/*
|
||||
* Copyright (c) Souldbminer and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds,
|
||||
bool enableThresholds,
|
||||
std::map<std::uint32_t, std::string> labels)
|
||||
: selectedValue(selectedValue),
|
||||
range(range),
|
||||
categoryName(categoryName),
|
||||
listener(listener),
|
||||
thresholds(thresholds),
|
||||
enableThresholds(enableThresholds),
|
||||
labels(labels)
|
||||
{
|
||||
}
|
||||
|
||||
ValueChoiceGui::~ValueChoiceGui()
|
||||
{
|
||||
}
|
||||
#include "value_choice_gui.h"
|
||||
#include "../format.h"
|
||||
#include "fatal_gui.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds,
|
||||
bool enableThresholds)
|
||||
: selectedValue(selectedValue),
|
||||
range(range),
|
||||
categoryName(categoryName),
|
||||
listener(listener),
|
||||
thresholds(thresholds),
|
||||
enableThresholds(enableThresholds)
|
||||
{
|
||||
}
|
||||
|
||||
if (value == 0) {
|
||||
return VALUE_DEFAULT_TEXT;
|
||||
}
|
||||
ValueChoiceGui::~ValueChoiceGui()
|
||||
{
|
||||
}
|
||||
|
||||
double displayValue = static_cast<double>(value) / static_cast<double>(range.divisor);
|
||||
std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << std::fixed << std::setprecision(range.decimalPlaces) << displayValue;
|
||||
if (value == 0) {
|
||||
|
||||
if (!range.suffix.empty()) {
|
||||
oss << " " << range.suffix;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
return VALUE_DEFAULT_TEXT;
|
||||
}
|
||||
|
||||
int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
|
||||
{
|
||||
if (value > thresholds.danger) {
|
||||
return 2;
|
||||
}
|
||||
if (value > thresholds.warning) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
std::uint32_t displayValue = value / range.divisor;
|
||||
|
||||
tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety)
|
||||
{
|
||||
std::string text = formatValue(value);
|
||||
if (selected) {
|
||||
text += " \uE14B";
|
||||
}
|
||||
oss << displayValue;
|
||||
if (!range.suffix.empty()) {
|
||||
oss << " " << range.suffix;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string rightText = "";
|
||||
auto it = labels.find(value);
|
||||
if (it != labels.end()) {
|
||||
rightText = it->second;
|
||||
}
|
||||
int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
|
||||
{
|
||||
if (!enableThresholds) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, rightText, false);
|
||||
std::uint32_t scaledValue = value / range.divisor;
|
||||
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
if (scaledValue > thresholds.danger) {
|
||||
return 2;
|
||||
}
|
||||
if (scaledValue > thresholds.warning) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!rightText.empty())
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, bool selected, int safety)
|
||||
{
|
||||
std::string text = formatValue(value);
|
||||
if (selected) {
|
||||
text += " \uE14B";
|
||||
}
|
||||
|
||||
listItem->setClickListener([this, value](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(value)) {
|
||||
tsl::goBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, "", false);
|
||||
|
||||
return listItem;
|
||||
}
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
void ValueChoiceGui::listUI()
|
||||
{
|
||||
if (!categoryName.empty()) {
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
|
||||
}
|
||||
listItem->setClickListener([this, value](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
|
||||
this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0));
|
||||
if (this->listener(value)) {
|
||||
tsl::goBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
|
||||
{
|
||||
int safety = getSafetyLevel(value);
|
||||
bool selected = (value == this->selectedValue);
|
||||
this->listElement->addItem(this->createValueListItem(value, selected, safety));
|
||||
}
|
||||
return listItem;
|
||||
}
|
||||
|
||||
this->listElement->jumpToItem("", "\uE14B");
|
||||
}
|
||||
void ValueChoiceGui::listUI()
|
||||
{
|
||||
|
||||
if (!categoryName.empty()) {
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
|
||||
}
|
||||
|
||||
this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0));
|
||||
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
|
||||
{
|
||||
int safety = getSafetyLevel(value);
|
||||
bool selected = (value == this->selectedValue);
|
||||
this->listElement->addItem(this->createValueListItem(value, selected, safety));
|
||||
}
|
||||
|
||||
this->listElement->jumpToItem("", "\uE14B");
|
||||
}
|
||||
@@ -25,69 +25,62 @@
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
|
||||
|
||||
#define VALUE_DEFAULT_TEXT "Default"
|
||||
|
||||
struct ValueRange {
|
||||
std::uint32_t min;
|
||||
std::uint32_t max;
|
||||
std::uint32_t step;
|
||||
std::string suffix;
|
||||
std::uint32_t divisor;
|
||||
int decimalPlaces;
|
||||
|
||||
ValueRange()
|
||||
: min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {}
|
||||
|
||||
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step,
|
||||
const std::string& suffix = "", std::uint32_t divisor = 1, int decimalPlaces = 0)
|
||||
: min(min), max(max), step(step), suffix(suffix),
|
||||
divisor(divisor), decimalPlaces(decimalPlaces) {}
|
||||
};
|
||||
|
||||
struct ValueThresholds {
|
||||
std::uint32_t warning;
|
||||
std::uint32_t danger;
|
||||
|
||||
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0)
|
||||
: warning(warning), danger(danger) {}
|
||||
};
|
||||
|
||||
class ValueChoiceGui : public BaseMenuGui
|
||||
{
|
||||
protected:
|
||||
std::uint32_t selectedValue;
|
||||
ValueRange range;
|
||||
std::string categoryName;
|
||||
ValueChoiceListener listener;
|
||||
ValueThresholds thresholds;
|
||||
bool enableThresholds;
|
||||
|
||||
// NEW — map of value → right-side text (like version numbers)
|
||||
std::map<std::uint32_t, std::string> labels;
|
||||
|
||||
tsl::elm::ListItem* createValueListItem(std::uint32_t value, bool selected, int safety);
|
||||
std::string formatValue(std::uint32_t value);
|
||||
int getSafetyLevel(std::uint32_t value);
|
||||
|
||||
public:
|
||||
ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds = ValueThresholds(),
|
||||
bool enableThresholds = false,
|
||||
std::map<std::uint32_t, std::string> labels = {});
|
||||
~ValueChoiceGui();
|
||||
|
||||
void listUI() override;
|
||||
};
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
|
||||
|
||||
#define VALUE_DEFAULT_TEXT "Default"
|
||||
|
||||
struct ValueRange {
|
||||
std::uint32_t min;
|
||||
std::uint32_t max;
|
||||
std::uint32_t step;
|
||||
std::string suffix;
|
||||
std::uint32_t divisor; // Divide input values by this for display
|
||||
|
||||
// Default constructor
|
||||
ValueRange() : min(0), max(0), step(1), suffix(""), divisor(1) {}
|
||||
|
||||
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step,
|
||||
const std::string& suffix = "", std::uint32_t divisor = 1)
|
||||
: min(min), max(max), step(step), suffix(suffix), divisor(divisor) {}
|
||||
};
|
||||
|
||||
struct ValueThresholds {
|
||||
std::uint32_t warning; // Values >= this show orange
|
||||
std::uint32_t danger; // Values >= this show red
|
||||
|
||||
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0)
|
||||
: warning(warning), danger(danger) {}
|
||||
};
|
||||
|
||||
class ValueChoiceGui : public BaseMenuGui
|
||||
{
|
||||
protected:
|
||||
std::uint32_t selectedValue;
|
||||
ValueRange range;
|
||||
std::string categoryName;
|
||||
ValueChoiceListener listener;
|
||||
ValueThresholds thresholds;
|
||||
bool enableThresholds;
|
||||
|
||||
tsl::elm::ListItem* createValueListItem(std::uint32_t value, bool selected, int safety);
|
||||
std::string formatValue(std::uint32_t value);
|
||||
int getSafetyLevel(std::uint32_t value);
|
||||
|
||||
public:
|
||||
ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds = ValueThresholds(),
|
||||
bool enableThresholds = false);
|
||||
~ValueChoiceGui();
|
||||
|
||||
void listUI() override;
|
||||
};
|
||||
@@ -17,7 +17,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
||||
# INCLUDES is a list of directories containing header files
|
||||
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := horizon-oc
|
||||
TARGET := sys-clk
|
||||
BUILD := build
|
||||
OUTDIR := out
|
||||
RESOURCES := res
|
||||
@@ -39,7 +39,7 @@ DEFINES := -DDISABLE_IPC -DTARGET="\"$(TARGET)\"" -DTARGET_VERSION="\"$(TARGET_V
|
||||
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
|
||||
CFLAGS := -g -Wall -Os -ffunction-sections \
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "hoc:sys",
|
||||
"name": "sys:clk",
|
||||
"title_id": "0x00FF0000636C6BFF",
|
||||
"title_id_range_min": "0x00FF0000636C6BFF",
|
||||
"title_id_range_max": "0x00FF0000636C6BFF",
|
||||
@@ -18,7 +18,7 @@
|
||||
"*"
|
||||
],
|
||||
"service_host": [
|
||||
"hoc:sys"
|
||||
"sys:clk"
|
||||
],
|
||||
"kernel_capabilities": [
|
||||
{
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
|
||||
#define HOSSVC_HAS_CLKRST (hosversionAtLeast(8,0,0))
|
||||
#define HOSSVC_HAS_TC (hosversionAtLeast(5,0,0))
|
||||
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
|
||||
|
||||
Result nvCheck = 1;
|
||||
u32 fd = 0;
|
||||
|
||||
static SysClkSocType g_socType = SysClkSocType_Erista;
|
||||
|
||||
@@ -121,11 +117,6 @@ void Board::Initialize()
|
||||
rc = tmp451Initialize();
|
||||
ASSERT_RESULT_OK(rc, "tmp451Initialize");
|
||||
|
||||
// u32 fd = 0;
|
||||
|
||||
// if (R_SUCCEEDED(nvInitialize())) nvCheck = nvOpen(&fd, "/dev/nvhost-ctrl-gpu");
|
||||
|
||||
|
||||
FetchHardwareInfos();
|
||||
}
|
||||
|
||||
@@ -150,7 +141,6 @@ void Board::Exit()
|
||||
|
||||
max17050Exit();
|
||||
tmp451Exit();
|
||||
nvExit();
|
||||
}
|
||||
|
||||
SysClkProfile Board::GetProfile()
|
||||
@@ -473,23 +463,16 @@ std::int32_t Board::GetPowerMw(SysClkPowerSensor sensor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint32_t Board::GetPartLoad(SysClkPartLoad loadSource)
|
||||
std::uint32_t Board::GetRamLoad(SysClkRamLoad loadSource)
|
||||
{
|
||||
// u32 temp, GPU_Load_u = 0;
|
||||
|
||||
switch(loadSource)
|
||||
{
|
||||
case SysClkPartLoad_EMC:
|
||||
case SysClkRamLoad_All:
|
||||
return t210EmcLoadAll();
|
||||
case SysClkPartLoad_EMCCpu:
|
||||
case SysClkRamLoad_Cpu:
|
||||
return t210EmcLoadCpu();
|
||||
// case HocClkPartLoad_GPU:
|
||||
// #define gpu_samples_average 10
|
||||
// // nvIoctl(fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp);
|
||||
// GPU_Load_u = ((GPU_Load_u * (gpu_samples_average-1)) + temp) / gpu_samples_average;
|
||||
// return GPU_Load_u / 10;
|
||||
default:
|
||||
ASSERT_ENUM_VALID(SysClkPartLoad, loadSource);
|
||||
ASSERT_ENUM_VALID(SysClkRamLoad, loadSource);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -513,10 +496,15 @@ void Board::FetchHardwareInfos()
|
||||
|
||||
switch(sku)
|
||||
{
|
||||
case 2 ... 5:
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
g_socType = SysClkSocType_Mariko;
|
||||
break;
|
||||
case 4:
|
||||
g_socType = SysClkSocType_MarikoLite;
|
||||
break;
|
||||
default:
|
||||
g_socType = SysClkSocType_Erista;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class Board
|
||||
static void GetFreqList(SysClkModule module, std::uint32_t* outList, std::uint32_t maxCount, std::uint32_t* outCount);
|
||||
static std::uint32_t GetTemperatureMilli(SysClkThermalSensor sensor);
|
||||
static std::int32_t GetPowerMw(SysClkPowerSensor sensor);
|
||||
static std::uint32_t GetPartLoad(SysClkPartLoad load);
|
||||
static std::uint32_t GetRamLoad(SysClkRamLoad load);
|
||||
static SysClkSocType GetSocType();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
#include "clock_manager.h"
|
||||
#include <cstring>
|
||||
@@ -36,10 +35,6 @@
|
||||
|
||||
#define HOSPPC_HAS_BOOST (hosversionAtLeast(7,0,0))
|
||||
|
||||
bool HAS_TDP_BEEN_FIRED = false;
|
||||
bool HAS_EBL_BEEN_FIRED = false;
|
||||
bool HAS_TT_BEEN_FIRED = false;
|
||||
|
||||
ClockManager *ClockManager::instance = NULL;
|
||||
|
||||
ClockManager *ClockManager::GetInstance()
|
||||
@@ -233,92 +228,41 @@ void ClockManager::RefreshFreqTableRow(SysClkModule module)
|
||||
|
||||
void ClockManager::Tick()
|
||||
{
|
||||
|
||||
std::uint32_t mode = 0;
|
||||
AppletOperationMode opMode = appletGetOperationMode();
|
||||
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
|
||||
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_EMCDVFS)) {
|
||||
|
||||
#define DEFAULT_FREQ_MHZ 1600
|
||||
#define DEFAULT_FREQ_MHZ_M 1862
|
||||
|
||||
int ram_mhz = Board::GetHz((SysClkModule)SysClkModule_MEM) / 1000000;
|
||||
|
||||
if (Board::GetSocType() == SysClkSocType_Mariko) {
|
||||
if(ram_mhz > DEFAULT_FREQ_MHZ_M)
|
||||
set_sd1_voltage(this->config->GetConfigValue(HocClkConfigValue_EMCVdd2VoltageUV));
|
||||
else
|
||||
set_sd1_voltage(this->config->GetConfigValue(HocClkConfigValue_EMCVdd2VoltageUVStockMariko));
|
||||
} else {
|
||||
if(ram_mhz > DEFAULT_FREQ_MHZ)
|
||||
set_sd1_voltage(this->config->GetConfigValue(HocClkConfigValue_EMCVdd2VoltageUV));
|
||||
else
|
||||
set_sd1_voltage(this->config->GetConfigValue(HocClkConfigValue_EMCVdd2VoltageUVStockErista));
|
||||
}
|
||||
}
|
||||
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_HandheldTDP) && opMode == AppletOperationMode_Handheld) {
|
||||
if(Board::GetSocType() == SysClkSocType_MarikoLite) {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Avg) < -(int)this->config->GetConfigValue(HocClkConfigValue_LiteTDPLimit)) {
|
||||
if(!HAS_TDP_BEEN_FIRED)
|
||||
writeNotification("Horizon OC\nTDP has been activated");
|
||||
HAS_TDP_BEEN_FIRED = true;
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
} else {
|
||||
HAS_TDP_BEEN_FIRED = false;
|
||||
}
|
||||
} else {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Avg) < -(int)this->config->GetConfigValue(HocClkConfigValue_HandheldTDPLimit)) {
|
||||
if(!HAS_TDP_BEEN_FIRED)
|
||||
writeNotification("Horizon OC\nTDP has been activated");
|
||||
HAS_TDP_BEEN_FIRED = true;
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
} else {
|
||||
HAS_TDP_BEEN_FIRED = false;
|
||||
}
|
||||
}
|
||||
} else if(opMode == AppletOperationMode_Console && this->config->GetConfigValue(HocClkConfigValue_EnforceBoardLimit)) {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Avg) < 0) {
|
||||
if(!HAS_EBL_BEEN_FIRED)
|
||||
writeNotification("Horizon OC\nBoard Limit has been exeeded");
|
||||
HAS_EBL_BEEN_FIRED = true;
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
} else {
|
||||
HAS_EBL_BEEN_FIRED = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
|
||||
if(tmp451TempSoc() / 1000 > (int)this->config->GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) {
|
||||
if(!HAS_TT_BEEN_FIRED)
|
||||
writeNotification("Horizon OC\nThermal Throttle has started");
|
||||
HAS_TT_BEEN_FIRED = true;
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
} else {
|
||||
HAS_TT_BEEN_FIRED = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::scoped_lock lock{this->contextMutex};
|
||||
if (this->RefreshContext() || this->config->Refresh())
|
||||
{
|
||||
std::uint32_t targetHz = 0;
|
||||
std::uint32_t maxHz = 0;
|
||||
std::uint32_t nearestHz = 0;
|
||||
std::uint32_t mode = 0;
|
||||
|
||||
AppletOperationMode opMode = appletGetOperationMode();
|
||||
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_HandheldTDP) && opMode == AppletOperationMode_Handheld) {
|
||||
if(Board::GetSocType() == SysClkSocType_MarikoLite) {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Now) < -(int)this->config->GetConfigValue(HocClkConfigValue_LiteTDPLimit)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Now) < -(int)this->config->GetConfigValue(HocClkConfigValue_HandheldTDPLimit)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(apmExtIsBoostMode(mode) && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(((tmp451TempSoc() / 1000) > (int)this->config->GetConfigValue(HocClkConfigValue_ThermalThrottleThreshold)) && this->config->GetConfigValue(HocClkConfigValue_ThermalThrottle)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_HandheldGovernor) && opMode == AppletOperationMode_Handheld) {
|
||||
|
||||
}
|
||||
@@ -482,9 +426,9 @@ bool ClockManager::RefreshContext()
|
||||
}
|
||||
|
||||
// ram load do not and should not force a refresh, hasChanged untouched
|
||||
for (unsigned int loadSource = 0; loadSource < SysClkPartLoad_EnumMax; loadSource++)
|
||||
for (unsigned int loadSource = 0; loadSource < SysClkRamLoad_EnumMax; loadSource++)
|
||||
{
|
||||
this->context->partLoad[loadSource] = Board::GetPartLoad((SysClkPartLoad)loadSource);
|
||||
this->context->ramLoad[loadSource] = Board::GetRamLoad((SysClkRamLoad)loadSource);
|
||||
}
|
||||
|
||||
if (this->ConfigIntervalTimeout(SysClkConfigValue_CsvWriteIntervalMs, ns, &this->lastCsvWriteNs))
|
||||
@@ -498,50 +442,4 @@ bool ClockManager::RefreshContext()
|
||||
void ClockManager::SetRNXRTMode(ReverseNXMode mode)
|
||||
{
|
||||
this->rnxSync->SetRTMode(mode);
|
||||
}
|
||||
|
||||
void ClockManager::set_sd1_voltage(uint32_t voltage_uv)
|
||||
{
|
||||
// SD1 parameters
|
||||
const u32 uv_step = 12500;
|
||||
const u32 uv_min = 600000;
|
||||
const u32 uv_max = 1237500;
|
||||
const u8 volt_addr = 0x17; // MAX77620_REG_SD1
|
||||
const u8 volt_mask = 0x7F; // MAX77620_SD1_VOLT_MASK
|
||||
|
||||
if (voltage_uv < uv_min || voltage_uv > uv_max)
|
||||
return;
|
||||
|
||||
u32 mult = (voltage_uv + uv_step - 1 - uv_min) / uv_step;
|
||||
mult = mult & volt_mask;
|
||||
|
||||
I2cSession session;
|
||||
Result res = i2cOpenSession(&session, I2cDevice_Max77620Pmic);
|
||||
if (R_FAILED(res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
u8 current_val = 0;
|
||||
res = i2csessionSendAuto(&session, &volt_addr, 1, I2cTransactionOption_Start);
|
||||
if (R_FAILED(res)) {
|
||||
writeNotification("I2C write failed. This may be a hardware issue");
|
||||
i2csessionClose(&session);
|
||||
return;
|
||||
}
|
||||
|
||||
res = i2csessionReceiveAuto(&session, ¤t_val, 1, I2cTransactionOption_Stop);
|
||||
if (R_FAILED(res)) {
|
||||
writeNotification("I2C write failed. This may be a hardware issue");
|
||||
i2csessionClose(&session);
|
||||
return;
|
||||
}
|
||||
|
||||
// Mask in the new voltage bits, preserving other bits
|
||||
u8 new_val = (current_val & ~volt_mask) | mult;
|
||||
|
||||
// Write back register with START and STOP conditions
|
||||
u8 write_buf[2] = {volt_addr, new_val};
|
||||
res = i2csessionSendAuto(&session, write_buf, sizeof(write_buf), I2cTransactionOption_All);
|
||||
|
||||
i2csessionClose(&session);
|
||||
}
|
||||
@@ -70,7 +70,6 @@ class ClockManager
|
||||
bool ConfigIntervalTimeout(SysClkConfigValue intervalMsConfigValue, std::uint64_t ns, std::uint64_t* lastLogNs);
|
||||
void RefreshFreqTableRow(SysClkModule module);
|
||||
bool RefreshContext();
|
||||
void set_sd1_voltage(uint32_t voltage_uv);
|
||||
|
||||
static ClockManager *instance;
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
@@ -25,6 +24,7 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -197,24 +197,17 @@ bool Config::SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bo
|
||||
std::scoped_lock lock{this->configMutex};
|
||||
uint8_t numProfiles = 0;
|
||||
|
||||
// String pointer array passed to ini
|
||||
char* iniKeys[SysClkProfile_EnumMax * SysClkModule_EnumMax + 1];
|
||||
char* iniValues[SysClkProfile_EnumMax * SysClkModule_EnumMax + 1];
|
||||
|
||||
// Char arrays to build strings
|
||||
char keysStr[SysClkProfile_EnumMax * SysClkModule_EnumMax * 0x40];
|
||||
char valuesStr[SysClkProfile_EnumMax * SysClkModule_EnumMax * 0x10];
|
||||
char section[17] = {0};
|
||||
|
||||
// Iteration pointers
|
||||
char** ik = &iniKeys[0];
|
||||
char** iv = &iniValues[0];
|
||||
char* sk = &keysStr[0];
|
||||
char* sv = &valuesStr[0];
|
||||
std::uint32_t* mhz = &profiles->mhz[0];
|
||||
|
||||
snprintf(section, sizeof(section), "%016lX", tid);
|
||||
|
||||
// Use dynamic allocation
|
||||
std::vector<std::string> keys;
|
||||
std::vector<std::string> values;
|
||||
keys.reserve(SysClkProfile_EnumMax * SysClkModule_EnumMax);
|
||||
values.reserve(SysClkProfile_EnumMax * SysClkModule_EnumMax);
|
||||
|
||||
std::uint32_t* mhz = &profiles->mhz[0];
|
||||
|
||||
for(unsigned int profile = 0; profile < SysClkProfile_EnumMax; profile++)
|
||||
{
|
||||
for(unsigned int module = 0; module < SysClkModule_EnumMax; module++)
|
||||
@@ -223,34 +216,38 @@ bool Config::SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bo
|
||||
{
|
||||
numProfiles++;
|
||||
|
||||
// Put key and value as string
|
||||
snprintf(sk, 0x40, "%s_%s", Board::GetProfileName((SysClkProfile)profile, false), Board::GetModuleName((SysClkModule)module, false));
|
||||
snprintf(sv, 0x10, "%d", *mhz);
|
||||
// Build key and value strings
|
||||
std::string key = std::string(Board::GetProfileName((SysClkProfile)profile, false)) +
|
||||
"_" +
|
||||
Board::GetModuleName((SysClkModule)module, false);
|
||||
std::string value = std::to_string(*mhz);
|
||||
|
||||
// Add them to the ini key/value str arrays
|
||||
*ik = sk;
|
||||
*iv = sv;
|
||||
ik++;
|
||||
iv++;
|
||||
|
||||
// We used those chars, get to the next ones
|
||||
sk += 0x40;
|
||||
sv += 0x10;
|
||||
keys.push_back(key);
|
||||
values.push_back(value);
|
||||
}
|
||||
|
||||
mhz++;
|
||||
}
|
||||
}
|
||||
|
||||
*ik = NULL;
|
||||
*iv = NULL;
|
||||
// Build pointer arrays
|
||||
std::vector<const char*> keyPointers;
|
||||
std::vector<const char*> valuePointers;
|
||||
keyPointers.reserve(keys.size() + 1);
|
||||
valuePointers.reserve(values.size() + 1);
|
||||
|
||||
if(!ini_putsection(section, (const char**)iniKeys, (const char**)iniValues, this->path.c_str()))
|
||||
for(size_t i = 0; i < keys.size(); i++) {
|
||||
keyPointers.push_back(keys[i].c_str());
|
||||
valuePointers.push_back(values[i].c_str());
|
||||
}
|
||||
keyPointers.push_back(NULL);
|
||||
valuePointers.push_back(NULL);
|
||||
|
||||
if(!ini_putsection(section, keyPointers.data(), valuePointers.data(), this->path.c_str()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only actually apply changes in memory after a succesful save
|
||||
// Only actually apply changes in memory after a successful save
|
||||
if(immediate)
|
||||
{
|
||||
mhz = &profiles->mhz[0];
|
||||
@@ -431,46 +428,43 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
|
||||
{
|
||||
std::scoped_lock lock{this->configMutex};
|
||||
|
||||
// String pointer array passed to ini
|
||||
const char* iniKeys[SysClkConfigValue_EnumMax + 1];
|
||||
char* iniValues[SysClkConfigValue_EnumMax + 1];
|
||||
|
||||
// char arrays to build strings
|
||||
char valuesStr[SysClkConfigValue_EnumMax * 0x20];
|
||||
|
||||
// Iteration pointers
|
||||
char* sv = &valuesStr[0];
|
||||
const char** ik = &iniKeys[0];
|
||||
char** iv = &iniValues[0];
|
||||
// Use dynamic allocation instead of fixed stack buffers
|
||||
std::vector<const char*> iniKeys;
|
||||
std::vector<std::string> iniValues;
|
||||
|
||||
iniKeys.reserve(SysClkConfigValue_EnumMax + 1);
|
||||
iniValues.reserve(SysClkConfigValue_EnumMax);
|
||||
|
||||
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
|
||||
{
|
||||
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) || configValues->values[kval] == sysclkDefaultConfigValue((SysClkConfigValue)kval))
|
||||
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) ||
|
||||
configValues->values[kval] == sysclkDefaultConfigValue((SysClkConfigValue)kval))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Put key and value as string
|
||||
// And add them to the ini key/value str arrays
|
||||
snprintf(sv, 0x20, "%ld", configValues->values[kval]);
|
||||
*ik = sysclkFormatConfigValue((SysClkConfigValue)kval, false);
|
||||
*iv = sv;
|
||||
|
||||
// We used those chars, get to the next ones
|
||||
sv += 0x20;
|
||||
ik++;
|
||||
iv++;
|
||||
// Store as string in vector (automatically managed memory)
|
||||
iniValues.push_back(std::to_string(configValues->values[kval]));
|
||||
iniKeys.push_back(sysclkFormatConfigValue((SysClkConfigValue)kval, false));
|
||||
}
|
||||
|
||||
*ik = NULL;
|
||||
*iv = NULL;
|
||||
// Null terminate
|
||||
iniKeys.push_back(NULL);
|
||||
|
||||
if(!ini_putsection(CONFIG_VAL_SECTION, (const char**)iniKeys, (const char**)iniValues, this->path.c_str()))
|
||||
// Build pointer array for ini function
|
||||
std::vector<const char*> valuePointers;
|
||||
valuePointers.reserve(iniValues.size() + 1);
|
||||
for(const auto& val : iniValues) {
|
||||
valuePointers.push_back(val.c_str());
|
||||
}
|
||||
valuePointers.push_back(NULL);
|
||||
|
||||
if(!ini_putsection(CONFIG_VAL_SECTION, iniKeys.data(), valuePointers.data(), this->path.c_str()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only actually apply changes in memory after a succesful save
|
||||
// Only actually apply changes in memory after a successful save
|
||||
if(immediate)
|
||||
{
|
||||
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
|
||||
|
||||
0
Source/sys-clk/sysmodule/src/emc.h
Normal file
0
Source/sys-clk/sysmodule/src/emc.h
Normal file
@@ -1,91 +0,0 @@
|
||||
#include "emc_patcher.h"
|
||||
#include "file_utils.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
#define MC_BASE 0x70019000
|
||||
#define EMC_BASE 0x7001B000
|
||||
#define MC_EMC_BASE_SIZE 0x1000
|
||||
#define EMC_TIMING_CONTROL_0 0x28
|
||||
#define EMC_RAS_0 0x34
|
||||
#define EMC_RAS_BIT_END 5
|
||||
|
||||
#define HOSSVC_HAS_MM (hosversionAtLeast(10,0,0))
|
||||
|
||||
|
||||
EMCpatcher* EMCpatcher::instance = nullptr;
|
||||
|
||||
EMCpatcher* EMCpatcher::GetInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
void EMCpatcher::Initialize()
|
||||
{
|
||||
if (!instance)
|
||||
{
|
||||
instance = new EMCpatcher();
|
||||
FileUtils::LogLine("[emc] Initialized EMCpatcher");
|
||||
}
|
||||
}
|
||||
|
||||
Config *EMCpatcher::GetConfig()
|
||||
{
|
||||
return this->config;
|
||||
}
|
||||
|
||||
void EMCpatcher::Exit()
|
||||
{
|
||||
if (instance)
|
||||
{
|
||||
FileUtils::LogLine("[emc] Exiting EMCpatcher");
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
EMCpatcher::EMCpatcher()
|
||||
{
|
||||
this->config = Config::CreateDefault();
|
||||
}
|
||||
|
||||
|
||||
|
||||
EMCpatcher::~EMCpatcher()
|
||||
{
|
||||
delete this->config;
|
||||
}
|
||||
|
||||
void EMCpatcher::Run()
|
||||
{
|
||||
std::scoped_lock lock{this->patcherMutex};
|
||||
this->config->Refresh();
|
||||
this->ApplyEMCPatch();
|
||||
}
|
||||
|
||||
|
||||
void EMCpatcher::ApplyEMCPatch()
|
||||
{
|
||||
// if(HOSSVC_HAS_MM) { // only for 10.0.0+, older versions need rewrites
|
||||
// u64 mc_virt_addr = 0;
|
||||
// u64 mc_out_size = 0;
|
||||
// u64 emc_virt_addr = 0;
|
||||
// u64 emc_out_size = 0;
|
||||
// Result rc;
|
||||
|
||||
// // rc = svcQueryMemoryMapping(&mc_virt_addr, &mc_out_size, MC_BASE, MC_EMC_BASE_SIZE); // map mc
|
||||
// // ASSERT_RESULT_OK(rc, "svcQueryMemoryMapping");
|
||||
|
||||
// // rc = svcQueryMemoryMapping(&emc_virt_addr, &emc_out_size, EMC_BASE, MC_EMC_BASE_SIZE); // map emc
|
||||
// // ASSERT_RESULT_OK(rc, "svcQueryMemoryMapping");
|
||||
|
||||
// write_reg64(EMC_BASE, EMC_RAS_0, 1);
|
||||
|
||||
// write_reg64(EMC_BASE, EMC_TIMING_CONTROL_0, 0x1); // apply shadow regs
|
||||
|
||||
|
||||
// // svcUnmapMemory((void *)mc_virt_addr, (void *)MC_BASE, MC_EMC_BASE_SIZE); // clean up
|
||||
// // svcUnmapMemory((void *)emc_virt_addr, (void *)EMC_BASE, MC_EMC_BASE_SIZE);
|
||||
|
||||
// }
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <cstdint>
|
||||
#include "config.h"
|
||||
#include <array>
|
||||
#include "errors.h"
|
||||
|
||||
// Read a 32-bit register via libnx SVC
|
||||
static inline uint32_t read_reg64(uint64_t phys_addr, uint32_t offset) {
|
||||
uint32_t value = 0;
|
||||
Result rc = svcReadWriteRegister(&value, phys_addr + offset, 0, false);
|
||||
if (R_FAILED(rc)) {
|
||||
// Handle failure if needed
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// Write a 32-bit register via libnx SVC
|
||||
static inline void write_reg64(uint64_t phys_addr, uint32_t offset, uint32_t value) {
|
||||
Result rc = svcReadWriteRegister(NULL, phys_addr + offset, value, true);
|
||||
if (R_FAILED(rc)) {
|
||||
// Handle failure if needed
|
||||
}
|
||||
}
|
||||
|
||||
// Bitfield helper remains the same
|
||||
static inline uint32_t set_bits(uint32_t reg_value, uint8_t start_bit, uint8_t end_bit, uint32_t value)
|
||||
{
|
||||
if (end_bit < start_bit || end_bit > 31)
|
||||
return reg_value;
|
||||
|
||||
uint32_t mask = ((1u << (end_bit - start_bit + 1)) - 1u) << start_bit;
|
||||
reg_value = (reg_value & ~mask) | ((value << start_bit) & mask);
|
||||
return reg_value;
|
||||
}
|
||||
|
||||
/* Primary timings. */
|
||||
const std::array<double, 8> tRCD_values = {18, 17, 16, 15, 14, 13, 12, 11};
|
||||
const std::array<double, 8> tRP_values = {18, 17, 16, 15, 14, 13, 12, 11};
|
||||
const std::array<double, 10> tRAS_values = {42, 36, 34, 32, 30, 28, 26, 24, 22, 20};
|
||||
|
||||
/* Secondary timings. */
|
||||
const std::array<double, 8> tRRD_values = {10.0, 7.5, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0};
|
||||
const std::array<double, 6> tRFC_values = {140, 120, 100, 80, 60, 40};
|
||||
const std::array<u32, 10> tRTW_values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; /* Is this even correct? */
|
||||
const std::array<double, 10> tWTR_values = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
|
||||
const std::array<u32, 7> tREFpb_values = {488, 732, 488 * 2, 488 * 3, 488 * 4, 488 * 6, 488 * 8}; /* TODO: Figure out if it's actually 8 and if this is even right. */
|
||||
|
||||
struct SOC_THERM_THERMCTL_LEVEL0_GROUP_CPU_0 {
|
||||
|
||||
};
|
||||
|
||||
class EMCpatcher
|
||||
{
|
||||
private:
|
||||
static EMCpatcher* instance;
|
||||
Config* config;
|
||||
std::mutex patcherMutex;
|
||||
|
||||
public:
|
||||
static EMCpatcher* GetInstance();
|
||||
static void Initialize();
|
||||
Config *GetConfig();
|
||||
static void Exit();
|
||||
|
||||
EMCpatcher();
|
||||
~EMCpatcher();
|
||||
|
||||
void Run();
|
||||
void ApplyEMCPatch();
|
||||
};
|
||||
@@ -31,8 +31,6 @@
|
||||
#include "file_utils.h"
|
||||
#include "errors.h"
|
||||
#include "clock_manager.h"
|
||||
#include "emc_patcher.h"
|
||||
|
||||
IpcService::IpcService(ClockManager* clockMgr)
|
||||
{
|
||||
std::int32_t priority;
|
||||
@@ -191,9 +189,6 @@ Result IpcService::ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8*
|
||||
return ipcSrv->SetReverseNXRTMode(mode);
|
||||
}
|
||||
break;
|
||||
case HocClkIpcCmd_UpdateEMCRegs: // Trigger, not data
|
||||
return ipcSrv->PatchEmcRegs();
|
||||
break;
|
||||
}
|
||||
|
||||
return SYSCLK_ERROR(Generic);
|
||||
@@ -230,7 +225,6 @@ Result IpcService::Exit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Result IpcService::GetProfileCount(std::uint64_t* tid, std::uint8_t* out_count)
|
||||
{
|
||||
Config* config = this->clockMgr->GetConfig();
|
||||
@@ -269,7 +263,7 @@ Result IpcService::SetProfiles(SysClkIpc_SetProfiles_Args* args)
|
||||
|
||||
if(!config->SetProfiles(args->tid, &profiles, true))
|
||||
{
|
||||
return SYSCLK_ERROR(ConfigSaveFailed); // 0x584
|
||||
return SYSCLK_ERROR(ConfigSaveFailed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -351,9 +345,3 @@ Result IpcService::SetReverseNXRTMode(ReverseNXMode mode) {
|
||||
ClockManager::GetInstance()->SetRNXRTMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Result IpcService::PatchEmcRegs() {
|
||||
EMCpatcher::GetInstance()->Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ class IpcService
|
||||
Result SetConfigValues(SysClkConfigValueList* configValues);
|
||||
Result GetFreqList(SysClkIpc_GetFreqList_Args* args, std::uint32_t* out_list, std::size_t size, std::uint32_t* out_count);
|
||||
Result SetReverseNXRTMode(ReverseNXMode mode);
|
||||
|
||||
Result PatchEmcRegs();
|
||||
|
||||
bool running;
|
||||
Thread thread;
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
#include "clock_manager.h"
|
||||
#include "ipc_service.h"
|
||||
#include "fancontrol.h"
|
||||
#include "emc_patcher.h"
|
||||
|
||||
#define INNER_HEAP_SIZE 0x50000
|
||||
#define INNER_HEAP_SIZE 0x30000
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -68,22 +66,12 @@ extern "C"
|
||||
|
||||
void __appInit(void)
|
||||
{
|
||||
Result rc;
|
||||
if (R_FAILED(smInitialize()))
|
||||
{
|
||||
fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
|
||||
}
|
||||
|
||||
rc = fanInitialize();
|
||||
if (R_FAILED(rc))
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
|
||||
rc = i2cInitialize();
|
||||
if (R_FAILED(rc))
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
|
||||
|
||||
rc = setsysInitialize();
|
||||
Result rc = setsysInitialize();
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
SetSysFirmwareVersion fw;
|
||||
@@ -92,7 +80,14 @@ extern "C"
|
||||
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
|
||||
setsysExit();
|
||||
}
|
||||
|
||||
|
||||
rc = fanInitialize();
|
||||
if (R_FAILED(rc))
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
|
||||
rc = i2cInitialize();
|
||||
if (R_FAILED(rc))
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
}
|
||||
|
||||
void __appExit(void)
|
||||
@@ -101,8 +96,7 @@ extern "C"
|
||||
fanExit();
|
||||
i2cExit();
|
||||
fsExit();
|
||||
fsdevUnmountAll();
|
||||
smExit();
|
||||
fsdevUnmountAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +119,7 @@ int main(int argc, char** argv)
|
||||
ClockManager* clockMgr = new ClockManager();
|
||||
IpcService* ipcSrv = new IpcService(clockMgr);
|
||||
|
||||
FileUtils::LogLine("Starting Horizon OC Sysmodule");
|
||||
FileUtils::LogLine("Ready");
|
||||
|
||||
clockMgr->SetRunning(true);
|
||||
clockMgr->GetConfig()->SetEnabled(true);
|
||||
|
||||
@@ -1,691 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Defining registers address and its bit definitions of MAX77620 and MAX20024
|
||||
*
|
||||
* Copyright (c) 2019-2020 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#ifndef MAX77XXX_H
|
||||
#define MAX77XXX_H
|
||||
|
||||
|
||||
#define MAX17050_BOARD_CGAIN 2 /* Actual: 1.99993 */
|
||||
#define MAX17050_BOARD_SNS_RESISTOR_UOHM 5000 /* 0.005 Ohm */
|
||||
|
||||
#define MAX17050_STATUS_BattAbsent BIT(3)
|
||||
|
||||
/* Consider RepCap which is less then 10 units below FullCAP full */
|
||||
#define MAX17050_FULL_THRESHOLD 10
|
||||
|
||||
#define MAX17050_CHARACTERIZATION_DATA_SIZE 48
|
||||
|
||||
#define MAXIM17050_I2C_ADDR 0x36
|
||||
|
||||
enum MAX17050_reg {
|
||||
MAX17050_STATUS = 0x00,
|
||||
MAX17050_VALRT_Th = 0x01,
|
||||
MAX17050_TALRT_Th = 0x02,
|
||||
MAX17050_SALRT_Th = 0x03,
|
||||
MAX17050_AtRate = 0x04,
|
||||
MAX17050_RepCap = 0x05,
|
||||
MAX17050_RepSOC = 0x06,
|
||||
MAX17050_Age = 0x07,
|
||||
MAX17050_TEMP = 0x08,
|
||||
MAX17050_VCELL = 0x09,
|
||||
MAX17050_Current = 0x0A,
|
||||
MAX17050_AvgCurrent = 0x0B,
|
||||
|
||||
MAX17050_SOC = 0x0D,
|
||||
MAX17050_AvSOC = 0x0E,
|
||||
MAX17050_RemCap = 0x0F,
|
||||
MAX17050_FullCAP = 0x10,
|
||||
MAX17050_TTE = 0x11,
|
||||
MAX17050_QRTbl00 = 0x12,
|
||||
MAX17050_FullSOCThr = 0x13,
|
||||
MAX17050_RSLOW = 0x14,
|
||||
|
||||
MAX17050_AvgTA = 0x16,
|
||||
MAX17050_Cycles = 0x17,
|
||||
MAX17050_DesignCap = 0x18,
|
||||
MAX17050_AvgVCELL = 0x19,
|
||||
MAX17050_MinMaxTemp = 0x1A,
|
||||
MAX17050_MinMaxVolt = 0x1B,
|
||||
MAX17050_MinMaxCurr = 0x1C,
|
||||
MAX17050_CONFIG = 0x1D,
|
||||
MAX17050_ICHGTerm = 0x1E,
|
||||
MAX17050_AvCap = 0x1F,
|
||||
MAX17050_ManName = 0x20,
|
||||
MAX17050_DevName = 0x21,
|
||||
MAX17050_QRTbl10 = 0x22,
|
||||
MAX17050_FullCAPNom = 0x23,
|
||||
MAX17050_TempNom = 0x24,
|
||||
MAX17050_TempLim = 0x25,
|
||||
MAX17050_TempHot = 0x26,
|
||||
MAX17050_AIN = 0x27,
|
||||
MAX17050_LearnCFG = 0x28,
|
||||
MAX17050_FilterCFG = 0x29,
|
||||
MAX17050_RelaxCFG = 0x2A,
|
||||
MAX17050_MiscCFG = 0x2B,
|
||||
MAX17050_TGAIN = 0x2C,
|
||||
MAX17050_TOFF = 0x2D,
|
||||
MAX17050_CGAIN = 0x2E,
|
||||
MAX17050_COFF = 0x2F,
|
||||
|
||||
MAX17050_QRTbl20 = 0x32,
|
||||
MAX17050_SOC_empty = 0x33,
|
||||
MAX17050_T_empty = 0x34,
|
||||
MAX17050_FullCAP0 = 0x35,
|
||||
MAX17050_LAvg_empty = 0x36,
|
||||
MAX17050_FCTC = 0x37,
|
||||
MAX17050_RCOMP0 = 0x38,
|
||||
MAX17050_TempCo = 0x39,
|
||||
MAX17050_V_empty = 0x3A,
|
||||
MAX17050_K_empty0 = 0x3B,
|
||||
MAX17050_TaskPeriod = 0x3C,
|
||||
MAX17050_FSTAT = 0x3D,
|
||||
MAX17050_TIMER = 0x3E,
|
||||
MAX17050_SHDNTIMER = 0x3F,
|
||||
|
||||
MAX17050_QRTbl30 = 0x42,
|
||||
|
||||
MAX17050_dQacc = 0x45,
|
||||
MAX17050_dPacc = 0x46,
|
||||
|
||||
MAX17050_VFSOC0 = 0x48,
|
||||
|
||||
Max17050_QH0 = 0x4C,
|
||||
MAX17050_QH = 0x4D,
|
||||
MAX17050_QL = 0x4E,
|
||||
|
||||
MAX17050_MinVolt = 0x50, // Custom ID. Not to be sent to i2c.
|
||||
MAX17050_MaxVolt = 0x51, // Custom ID. Not to be sent to i2c.
|
||||
|
||||
MAX17050_VFSOC0Enable = 0x60,
|
||||
MAX17050_MODELEnable1 = 0x62,
|
||||
MAX17050_MODELEnable2 = 0x63,
|
||||
|
||||
MAX17050_MODELChrTbl = 0x80,
|
||||
|
||||
MAX17050_OCV = 0xEE,
|
||||
|
||||
MAX17050_OCVInternal = 0xFB,
|
||||
|
||||
MAX17050_VFSOC = 0xFF,
|
||||
};
|
||||
|
||||
#define MAX77620_I2C_ADDR 0x3C
|
||||
|
||||
/* GLOBAL, PMIC, GPIO, FPS, ONOFFC, CID Registers */
|
||||
#define MAX77620_REG_CNFGGLBL1 0x00
|
||||
#define MAX77620_CNFGGLBL1_LBRSTEN BIT(0)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_MASK 0x0E
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_2700 (0 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_2800 (1 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_2900 (2 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_3000 (3 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_3100 (4 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_3200 (5 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_3300 (6 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_3400 (7 << 1)
|
||||
#define MAX77620_CNFGGLBL1_LBHYST_100 (0 << 4)
|
||||
#define MAX77620_CNFGGLBL1_LBHYST_200 (1 << 4)
|
||||
#define MAX77620_CNFGGLBL1_LBHYST_300 (2 << 4)
|
||||
#define MAX77620_CNFGGLBL1_LBHYST_400 (3 << 4)
|
||||
#define MAX77620_CNFGGLBL1_MPPLD BIT(6)
|
||||
#define MAX77620_CNFGGLBL1_LBDAC_EN BIT(7)
|
||||
|
||||
#define MAX77620_REG_CNFGGLBL2 0x01
|
||||
#define MAX77620_TWD_MASK 0x3
|
||||
#define MAX77620_TWD_2s 0x0
|
||||
#define MAX77620_TWD_16s 0x1
|
||||
#define MAX77620_TWD_64s 0x2
|
||||
#define MAX77620_TWD_128s 0x3
|
||||
#define MAX77620_WDTEN BIT(2)
|
||||
#define MAX77620_WDTSLPC BIT(3)
|
||||
#define MAX77620_WDTOFFC BIT(4)
|
||||
#define MAX77620_GLBL_LPM BIT(5)
|
||||
#define MAX77620_I2CTWD_MASK 0xC0
|
||||
#define MAX77620_I2CTWD_DISABLED 0x00
|
||||
#define MAX77620_I2CTWD_1_33ms 0x40
|
||||
#define MAX77620_I2CTWD_35_7ms 0x80
|
||||
#define MAX77620_I2CTWD_41_7ms 0xC0
|
||||
|
||||
#define MAX77620_REG_CNFGGLBL3 0x02
|
||||
#define MAX77620_WDTC_MASK 0x3
|
||||
|
||||
#define MAX77620_REG_CNFG1_32K 0x03
|
||||
#define MAX77620_CNFG1_PWR_MD_32K_MASK 0x3
|
||||
#define MAX77620_CNFG1_32K_OUT0_EN BIT(2)
|
||||
#define MAX77620_CNFG1_32KLOAD_MASK 0x30
|
||||
#define MAX77620_CNFG1_32K_OK BIT(7)
|
||||
|
||||
#define MAX77620_REG_CNFGBBC 0x04
|
||||
#define MAX77620_CNFGBBC_ENABLE BIT(0)
|
||||
#define MAX77620_CNFGBBC_CURRENT_MASK 0x06
|
||||
#define MAX77620_CNFGBBC_CURRENT_SHIFT 1
|
||||
#define MAX77620_CNFGBBC_VOLTAGE_MASK 0x18
|
||||
#define MAX77620_CNFGBBC_VOLTAGE_SHIFT 3
|
||||
#define MAX77620_CNFGBBC_LOW_CURRENT_DISABLE BIT(5)
|
||||
#define MAX77620_CNFGBBC_RESISTOR_MASK 0xC0
|
||||
#define MAX77620_CNFGBBC_RESISTOR_SHIFT 6
|
||||
#define MAX77620_CNFGBBC_RESISTOR_100 (0 << MAX77620_CNFGBBC_RESISTOR_SHIFT)
|
||||
#define MAX77620_CNFGBBC_RESISTOR_1K (1 << MAX77620_CNFGBBC_RESISTOR_SHIFT)
|
||||
#define MAX77620_CNFGBBC_RESISTOR_3K (2 << MAX77620_CNFGBBC_RESISTOR_SHIFT)
|
||||
#define MAX77620_CNFGBBC_RESISTOR_6K (3 << MAX77620_CNFGBBC_RESISTOR_SHIFT)
|
||||
|
||||
#define MAX77620_REG_IRQTOP 0x05
|
||||
#define MAX77620_REG_IRQTOPM 0x0D
|
||||
#define MAX77620_IRQ_TOP_ONOFF_MASK BIT(1)
|
||||
#define MAX77620_IRQ_TOP_32K_MASK BIT(2)
|
||||
#define MAX77620_IRQ_TOP_RTC_MASK BIT(3)
|
||||
#define MAX77620_IRQ_TOP_GPIO_MASK BIT(4)
|
||||
#define MAX77620_IRQ_TOP_LDO_MASK BIT(5)
|
||||
#define MAX77620_IRQ_TOP_SD_MASK BIT(6)
|
||||
#define MAX77620_IRQ_TOP_GLBL_MASK BIT(7)
|
||||
|
||||
#define MAX77620_REG_INTLBT 0x06
|
||||
#define MAX77620_REG_INTENLBT 0x0E
|
||||
#define MAX77620_IRQ_GLBLM_MASK BIT(0)
|
||||
#define MAX77620_IRQ_TJALRM2_MASK BIT(1)
|
||||
#define MAX77620_IRQ_TJALRM1_MASK BIT(2)
|
||||
#define MAX77620_IRQ_LBM_MASK BIT(3)
|
||||
|
||||
#define MAX77620_REG_IRQSD 0x07
|
||||
#define MAX77620_REG_IRQMASKSD 0x0F
|
||||
#define MAX77620_IRQSD_PFI_SD3 BIT(4)
|
||||
#define MAX77620_IRQSD_PFI_SD2 BIT(5)
|
||||
#define MAX77620_IRQSD_PFI_SD1 BIT(6)
|
||||
#define MAX77620_IRQSD_PFI_SD0 BIT(7)
|
||||
|
||||
#define MAX77620_REG_IRQ_LVL2_L0_7 0x08 // LDO number that irq occurred.
|
||||
#define MAX77620_REG_IRQ_MSK_L0_7 0x10
|
||||
#define MAX77620_REG_IRQ_LVL2_L8 \
|
||||
0x09 // LDO number that irq occurred. Only bit0: LDO8 is valid.
|
||||
#define MAX77620_REG_IRQ_MSK_L8 0x11
|
||||
#define MAX77620_REG_IRQ_LVL2_GPIO 0x0A // Edge detection interrupt.
|
||||
|
||||
#define MAX77620_REG_ONOFFIRQ 0x0B
|
||||
#define MAX77620_REG_ONOFFIRQM 0x12
|
||||
#define MAX77620_ONOFFIRQ_MRWRN BIT(0)
|
||||
#define MAX77620_ONOFFIRQ_EN0_1SEC BIT(1)
|
||||
#define MAX77620_ONOFFIRQ_EN0_F BIT(2)
|
||||
#define MAX77620_ONOFFIRQ_EN0_R BIT(3)
|
||||
#define MAX77620_ONOFFIRQ_LID_F BIT(4)
|
||||
#define MAX77620_ONOFFIRQ_LID_R BIT(5)
|
||||
#define MAX77620_ONOFFIRQ_ACOK_F BIT(6)
|
||||
#define MAX77620_ONOFFIRQ_ACOK_R BIT(7)
|
||||
|
||||
#define MAX77620_REG_NVERC 0x0C // Shutdown reason (non-volatile).
|
||||
#define MAX77620_NVERC_SHDN BIT(0)
|
||||
#define MAX77620_NVERC_WTCHDG BIT(1)
|
||||
#define MAX77620_NVERC_HDRST BIT(2)
|
||||
#define MAX77620_NVERC_TOVLD BIT(3)
|
||||
#define MAX77620_NVERC_MBLSD BIT(4)
|
||||
#define MAX77620_NVERC_MBO BIT(5)
|
||||
#define MAX77620_NVERC_MBU BIT(6)
|
||||
#define MAX77620_NVERC_RSTIN BIT(7)
|
||||
|
||||
#define MAX77620_REG_STATLBT 0x13
|
||||
#define MAX77620_REG_STATSD 0x14
|
||||
|
||||
#define MAX77620_REG_ONOFFSTAT 0x15
|
||||
#define MAX77620_ONOFFSTAT_LID BIT(0)
|
||||
#define MAX77620_ONOFFSTAT_ACOK BIT(1)
|
||||
#define MAX77620_ONOFFSTAT_EN0 BIT(2)
|
||||
|
||||
/* SD and LDO Registers */
|
||||
#define MAX77620_REG_SD0 0x16
|
||||
#define MAX77620_REG_SD1 0x17
|
||||
#define MAX77620_REG_SD2 0x18
|
||||
#define MAX77620_REG_SD3 0x19
|
||||
#define MAX77620_REG_SD4 0x1A
|
||||
#define MAX77620_REG_DVSSD0 0x1B
|
||||
#define MAX77620_REG_DVSSD1 0x1C
|
||||
#define MAX77620_SDX_VOLT_MASK 0xFF
|
||||
#define MAX77620_SD0_VOLT_MASK 0x7F // Max is 0x40.
|
||||
#define MAX77620_SD1_VOLT_MASK 0x7F // Max is 0x4C.
|
||||
#define MAX77620_LDO_VOLT_MASK 0x3F
|
||||
|
||||
#define MAX77620_REG_SD0_CFG 0x1D
|
||||
#define MAX77620_REG_SD1_CFG 0x1E
|
||||
#define MAX77620_REG_SD2_CFG 0x1F
|
||||
#define MAX77620_REG_SD3_CFG 0x20
|
||||
#define MAX77620_REG_SD4_CFG 0x21
|
||||
#define MAX77620_SD_SR_MASK 0xC0
|
||||
#define MAX77620_SD_SR_SHIFT 6
|
||||
#define MAX77620_SD_POWER_MODE_MASK 0x30
|
||||
#define MAX77620_SD_POWER_MODE_SHIFT 4
|
||||
#define MAX77620_SD_CFG1_ADE_MASK BIT(3)
|
||||
#define MAX77620_SD_CFG1_ADE_DISABLE 0
|
||||
#define MAX77620_SD_CFG1_ADE_ENABLE BIT(3)
|
||||
#define MAX77620_SD_FPWM_MASK 0x04
|
||||
#define MAX77620_SD_FPWM_SHIFT 2
|
||||
#define MAX77620_SD_FSRADE_MASK 0x01
|
||||
#define MAX77620_SD_FSRADE_SHIFT 0
|
||||
#define MAX77620_SD_CFG1_FPWM_SD_MASK BIT(2)
|
||||
#define MAX77620_SD_CFG1_FPWM_SD_SKIP 0
|
||||
#define MAX77620_SD_CFG1_FPWM_SD_FPWM BIT(2)
|
||||
#define MAX77620_SD_CFG1_MPOK_MASK BIT(1)
|
||||
#define MAX77620_SD_CFG1_FSRADE_SD_MASK BIT(0)
|
||||
#define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0
|
||||
#define MAX77620_SD_CFG1_FSRADE_SD_ENABLE BIT(0)
|
||||
|
||||
#define MAX77620_REG_SD_CFG2 0x22
|
||||
#define MAX77620_SD_CNF2_RSVD BIT(0)
|
||||
#define MAX77620_SD_CNF2_ROVS_EN_SD1 BIT(1)
|
||||
#define MAX77620_SD_CNF2_ROVS_EN_SD0 BIT(2)
|
||||
|
||||
#define MAX77620_REG_LDO0_CFG 0x23
|
||||
#define MAX77620_REG_LDO0_CFG2 0x24
|
||||
#define MAX77620_REG_LDO1_CFG 0x25
|
||||
#define MAX77620_REG_LDO1_CFG2 0x26
|
||||
#define MAX77620_REG_LDO2_CFG 0x27
|
||||
#define MAX77620_REG_LDO2_CFG2 0x28
|
||||
#define MAX77620_REG_LDO3_CFG 0x29
|
||||
#define MAX77620_REG_LDO3_CFG2 0x2A
|
||||
#define MAX77620_REG_LDO4_CFG 0x2B
|
||||
#define MAX77620_REG_LDO4_CFG2 0x2C
|
||||
#define MAX77620_REG_LDO5_CFG 0x2D
|
||||
#define MAX77620_REG_LDO5_CFG2 0x2E
|
||||
#define MAX77620_REG_LDO6_CFG 0x2F
|
||||
#define MAX77620_REG_LDO6_CFG2 0x30
|
||||
#define MAX77620_REG_LDO7_CFG 0x31
|
||||
#define MAX77620_REG_LDO7_CFG2 0x32
|
||||
#define MAX77620_REG_LDO8_CFG 0x33
|
||||
#define MAX77620_REG_LDO8_CFG2 0x34
|
||||
/*! LDO CFG */
|
||||
#define MAX77620_LDO_POWER_MODE_SHIFT 6
|
||||
#define MAX77620_LDO_POWER_MODE_MASK (3 << MAX77620_LDO_POWER_MODE_SHIFT)
|
||||
#define MAX77620_POWER_MODE_NORMAL 3
|
||||
#define MAX77620_POWER_MODE_LPM 2
|
||||
#define MAX77620_POWER_MODE_GLPM 1
|
||||
#define MAX77620_POWER_MODE_DISABLE 0
|
||||
/*! LDO CFG2 */
|
||||
#define MAX77620_LDO_CFG2_SS_MASK (1 << 0)
|
||||
#define MAX77620_LDO_CFG2_SS_FAST (0 << 0)
|
||||
#define MAX77620_LDO_CFG2_SS_SLOW (1 << 0)
|
||||
#define MAX77620_LDO_CFG2_ADE_MASK (1 << 1)
|
||||
#define MAX77620_LDO_CFG2_ADE_DISABLE (0 << 1)
|
||||
#define MAX77620_LDO_CFG2_ADE_ENABLE (1 << 1)
|
||||
#define MAX77620_LDO_CFG2_MPOK_MASK BIT(2)
|
||||
#define MAX77620_LDO_CFG2_POK_MASK BIT(3)
|
||||
#define MAX77620_LDO_CFG2_COMP_SHIFT 4
|
||||
#define MAX77620_LDO_CFG2_COMP_MASK (3 << MAX77620_LDO_COMP_SHIFT)
|
||||
#define MAX77620_LDO_CFG2_COMP_SLOW 3
|
||||
#define MAX77620_LDO_CFG2_COMP_MID_SLOW 2
|
||||
#define MAX77620_LDO_CFG2_COMP_MID_FAST 1
|
||||
#define MAX77620_LDO_CFG2_COMP_FAST 0
|
||||
#define MAX77620_LDO_CFG2_ALPM_EN_MASK BIT(6)
|
||||
#define MAX77620_LDO_CFG2_OVCLMP_MASK BIT(7)
|
||||
|
||||
#define MAX77620_REG_LDO_CFG3 0x35
|
||||
#define MAX77620_LDO_BIAS_EN BIT(0)
|
||||
#define MAX77620_TRACK4_SHIFT 5
|
||||
#define MAX77620_TRACK4_MASK (1 << MAX77620_TRACK4_SHIFT)
|
||||
|
||||
#define MAX77620_REG_GPIO0 0x36
|
||||
#define MAX77620_REG_GPIO1 0x37
|
||||
#define MAX77620_REG_GPIO2 0x38
|
||||
#define MAX77620_REG_GPIO3 0x39
|
||||
#define MAX77620_REG_GPIO4 0x3A
|
||||
#define MAX77620_REG_GPIO5 0x3B
|
||||
#define MAX77620_REG_GPIO6 0x3C
|
||||
#define MAX77620_REG_GPIO7 0x3D
|
||||
#define MAX77620_CNFG_GPIO_DRV_MASK (1 << 0)
|
||||
#define MAX77620_CNFG_GPIO_DRV_PUSHPULL (1 << 0)
|
||||
#define MAX77620_CNFG_GPIO_DRV_OPENDRAIN (0 << 0)
|
||||
#define MAX77620_CNFG_GPIO_DIR_MASK (1 << 1)
|
||||
#define MAX77620_CNFG_GPIO_DIR_INPUT (1 << 1)
|
||||
#define MAX77620_CNFG_GPIO_DIR_OUTPUT (0 << 1)
|
||||
#define MAX77620_CNFG_GPIO_INPUT_VAL_MASK (1 << 2)
|
||||
#define MAX77620_CNFG_GPIO_OUTPUT_VAL_MASK (1 << 3)
|
||||
#define MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH (1 << 3)
|
||||
#define MAX77620_CNFG_GPIO_OUTPUT_VAL_LOW (0 << 3)
|
||||
#define MAX77620_CNFG_GPIO_INT_MASK (0x3 << 4)
|
||||
#define MAX77620_CNFG_GPIO_INT_FALLING (1 << 4)
|
||||
#define MAX77620_CNFG_GPIO_INT_RISING (1 << 5)
|
||||
#define MAX77620_CNFG_GPIO_DBNC_MASK (0x3 << 6)
|
||||
#define MAX77620_CNFG_GPIO_DBNC_None (0x0 << 6)
|
||||
#define MAX77620_CNFG_GPIO_DBNC_8ms (0x1 << 6)
|
||||
#define MAX77620_CNFG_GPIO_DBNC_16ms (0x2 << 6)
|
||||
#define MAX77620_CNFG_GPIO_DBNC_32ms (0x3 << 6)
|
||||
#define MAX77620_GPIO_OUTPUT_DISABLE 0
|
||||
#define MAX77620_GPIO_OUTPUT_ENABLE 1
|
||||
|
||||
#define MAX77620_REG_PUE_GPIO 0x3E // Gpio Pullup resistor enable.
|
||||
#define MAX77620_REG_PDE_GPIO 0x3F // Gpio Pulldown resistor enable.
|
||||
|
||||
#define MAX77620_REG_AME_GPIO \
|
||||
0x40 // Gpio pinmuxing. Clear bits are Standard GPIO.
|
||||
|
||||
#define MAX77620_REG_ONOFFCNFG1 0x41
|
||||
#define MAX20024_ONOFFCNFG1_CLRSE 0x18
|
||||
#define MAX77620_ONOFFCNFG1_PWR_OFF BIT(1)
|
||||
#define MAX77620_ONOFFCNFG1_SLPEN BIT(2)
|
||||
#define MAX77620_ONOFFCNFG1_MRT_SHIFT 0x3
|
||||
#define MAX77620_ONOFFCNFG1_MRT_MASK 0x38
|
||||
#define MAX77620_ONOFFCNFG1_RSVD BIT(6)
|
||||
#define MAX77620_ONOFFCNFG1_SFT_RST BIT(7)
|
||||
|
||||
#define MAX77620_REG_ONOFFCNFG2 0x42
|
||||
#define MAX77620_ONOFFCNFG2_WK_EN0 BIT(0)
|
||||
#define MAX77620_ONOFFCNFG2_WK_ALARM2 BIT(1)
|
||||
#define MAX77620_ONOFFCNFG2_WK_ALARM1 BIT(2)
|
||||
#define MAX77620_ONOFFCNFG2_WK_MBATT \
|
||||
BIT(3) // MBATT event generates a wakeup signal. use it in android/l4t?
|
||||
#define MAX77620_ONOFFCNFG2_WK_ACOK BIT(4)
|
||||
#define MAX77620_ONOFFCNFG2_SLP_LPM_MSK BIT(5)
|
||||
#define MAX77620_ONOFFCNFG2_WD_RST_WK BIT(6)
|
||||
#define MAX77620_ONOFFCNFG2_SFT_RST_WK BIT(7)
|
||||
|
||||
/* FPS Registers */
|
||||
#define MAX77620_REG_FPS_CFG0 0x43 // FPS0.
|
||||
#define MAX77620_REG_FPS_CFG1 0x44 // FPS1.
|
||||
#define MAX77620_REG_FPS_CFG2 0x45 // FPS2.
|
||||
#define MAX77620_FPS_ENFPS_SW_MASK 0x01
|
||||
#define MAX77620_FPS_ENFPS_SW 0x01
|
||||
#define MAX77620_FPS_EN_SRC_SHIFT 1
|
||||
#define MAX77620_FPS_EN_SRC_MASK 0x06
|
||||
#define MAX77620_FPS_TIME_PERIOD_SHIFT 3
|
||||
#define MAX77620_FPS_TIME_PERIOD_MASK 0x38
|
||||
|
||||
#define MAX77620_REG_FPS_LDO0 0x46
|
||||
#define MAX77620_REG_FPS_LDO1 0x47
|
||||
#define MAX77620_REG_FPS_LDO2 0x48
|
||||
#define MAX77620_REG_FPS_LDO3 0x49
|
||||
#define MAX77620_REG_FPS_LDO4 0x4A
|
||||
#define MAX77620_REG_FPS_LDO5 0x4B
|
||||
#define MAX77620_REG_FPS_LDO6 0x4C
|
||||
#define MAX77620_REG_FPS_LDO7 0x4D
|
||||
#define MAX77620_REG_FPS_LDO8 0x4E
|
||||
#define MAX77620_REG_FPS_SD0 0x4F
|
||||
#define MAX77620_REG_FPS_SD1 0x50
|
||||
#define MAX77620_REG_FPS_SD2 0x51
|
||||
#define MAX77620_REG_FPS_SD3 0x52
|
||||
#define MAX77620_REG_FPS_SD4 0x53
|
||||
#define MAX77620_REG_FPS_GPIO1 0x54
|
||||
#define MAX77620_REG_FPS_GPIO2 0x55
|
||||
#define MAX77620_REG_FPS_GPIO3 0x56
|
||||
#define MAX77620_REG_FPS_RSO 0x57
|
||||
#define MAX77620_FPS_PD_PERIOD_SHIFT 0
|
||||
#define MAX77620_FPS_PD_PERIOD_MASK 0x07
|
||||
#define MAX77620_FPS_PU_PERIOD_SHIFT 3
|
||||
#define MAX77620_FPS_PU_PERIOD_MASK 0x38
|
||||
#define MAX77620_FPS_SRC_SHIFT 6
|
||||
#define MAX77620_FPS_SRC_MASK 0xC0
|
||||
|
||||
#define MAX77620_FPS_COUNT 3
|
||||
#define MAX77620_FPS_PERIOD_MIN_US 40
|
||||
#define MAX77620_FPS_PERIOD_MAX_US 2560
|
||||
|
||||
#define MAX77620_REG_CID0 0x58
|
||||
#define MAX77620_REG_CID1 0x59
|
||||
#define MAX77620_REG_CID2 0x5A
|
||||
#define MAX77620_REG_CID3 0x5B
|
||||
#define MAX77620_REG_CID4 0x5C // OTP version.
|
||||
#define MAX77620_REG_CID5 0x5D // ES version.
|
||||
#define MAX77620_CID_DIDO_MASK 0xF
|
||||
#define MAX77620_CID_DIDO_SHIFT 0
|
||||
#define MAX77620_CID_DIDM_MASK 0xF0
|
||||
#define MAX77620_CID_DIDM_SHIFT 4
|
||||
|
||||
/* Device Identification Metal */
|
||||
#define MAX77620_CID5_DIDM(n) (((n) >> 4) & 0xF)
|
||||
/* Device Indentification OTP */
|
||||
#define MAX77620_CID5_DIDO(n) ((n) & 0xF)
|
||||
|
||||
#define MAX77620_REG_DVSSD4 0x5E
|
||||
#define MAX20024_REG_MAX_ADD 0x70
|
||||
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE0 BIT(0)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE1 BIT(1)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE2 BIT(2)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE3 BIT(3)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE4 BIT(4)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE5 BIT(5)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE6 BIT(6)
|
||||
#define MAX77620_IRQ_LVL2_GPIO_EDGE7 BIT(7)
|
||||
|
||||
/* Interrupts */
|
||||
enum {
|
||||
MAX77620_IRQ_TOP_GLBL, /* Low-Battery */
|
||||
MAX77620_IRQ_TOP_SD, /* SD power fail */
|
||||
MAX77620_IRQ_TOP_LDO, /* LDO power fail */
|
||||
MAX77620_IRQ_TOP_GPIO, /* TOP GPIO internal int to MAX77620 */
|
||||
MAX77620_IRQ_TOP_RTC, /* RTC */
|
||||
MAX77620_IRQ_TOP_32K, /* 32kHz oscillator */
|
||||
MAX77620_IRQ_TOP_ONOFF, /* ON/OFF oscillator */
|
||||
MAX77620_IRQ_LBT_MBATLOW, /* Thermal alarm status, > 120C */
|
||||
MAX77620_IRQ_LBT_TJALRM1, /* Thermal alarm status, > 120C */
|
||||
MAX77620_IRQ_LBT_TJALRM2, /* Thermal alarm status, > 140C */
|
||||
};
|
||||
|
||||
/* GPIOs */
|
||||
enum {
|
||||
MAX77620_GPIO0,
|
||||
MAX77620_GPIO1,
|
||||
MAX77620_GPIO2,
|
||||
MAX77620_GPIO3,
|
||||
MAX77620_GPIO4,
|
||||
MAX77620_GPIO5,
|
||||
MAX77620_GPIO6,
|
||||
MAX77620_GPIO7,
|
||||
MAX77620_GPIO_NR,
|
||||
};
|
||||
|
||||
/* FPS Source */
|
||||
enum max77620_fps_src {
|
||||
MAX77620_FPS_SRC_0,
|
||||
MAX77620_FPS_SRC_1,
|
||||
MAX77620_FPS_SRC_2,
|
||||
MAX77620_FPS_SRC_NONE,
|
||||
MAX77620_FPS_SRC_DEF,
|
||||
};
|
||||
|
||||
#define MAX77812_PHASE31_CPU_I2C_ADDR \
|
||||
0x31 // High power GPU. 2 Outputs: 3-phase M1 + 1-phase M4.
|
||||
#define MAX77812_PHASE211_CPU_I2C_ADDR \
|
||||
0x33 // Low power GPU. 3 Outputs: 2-phase M1 + 1-phase M3 + 1-phase M4.
|
||||
|
||||
#define MAX77812_REG_RSET 0x00
|
||||
#define MAX77812_REG_INT_SRC 0x01
|
||||
#define MAX77812_REG_INT_SRC_M 0x02
|
||||
#define MAX77812_REG_TOPSYS_INT 0x03
|
||||
#define MAX77812_REG_TOPSYS_INT_M 0x04
|
||||
#define MAX77812_REG_TOPSYS_STAT 0x05
|
||||
#define MAX77812_REG_EN_CTRL 0x06
|
||||
#define MAX77812_EN_CTRL_ENABLE 1
|
||||
#define MAX77812_EN_CTRL_EN_M1_SHIFT 0
|
||||
#define MAX77812_EN_CTRL_EN_M1_MASK (1 << MAX77812_EN_CTRL_EN_M1_SHIFT)
|
||||
#define MAX77812_EN_CTRL_EN_M2_SHIFT 2
|
||||
#define MAX77812_EN_CTRL_EN_M2_MASK (1 << MAX77812_EN_CTRL_EN_M2_SHIFT)
|
||||
#define MAX77812_EN_CTRL_EN_M3_SHIFT 4
|
||||
#define MAX77812_EN_CTRL_EN_M3_MASK (1 << MAX77812_EN_CTRL_EN_M3_SHIFT)
|
||||
#define MAX77812_EN_CTRL_EN_M4_SHIFT 6
|
||||
#define MAX77812_EN_CTRL_EN_M4_MASK (1 << MAX77812_EN_CTRL_EN_M4_SHIFT)
|
||||
#define MAX77812_REG_STUP_DLY2 0x07
|
||||
#define MAX77812_REG_STUP_DLY3 0x08
|
||||
#define MAX77812_REG_STUP_DLY4 0x09
|
||||
#define MAX77812_REG_SHDN_DLY1 0x0A
|
||||
#define MAX77812_REG_SHDN_DLY2 0x0B
|
||||
#define MAX77812_REG_SHDN_DLY3 0x0C
|
||||
#define MAX77812_REG_SHDN_DLY4 0x0D
|
||||
#define MAX77812_REG_WDTRSTB_DEB 0x0E
|
||||
#define MAX77812_REG_GPI_FUNC 0x0F
|
||||
#define MAX77812_REG_GPI_DEB1 0x10
|
||||
#define MAX77812_REG_GPI_DEB2 0x11
|
||||
#define MAX77812_REG_GPI_PD_CTRL 0x12
|
||||
#define MAX77812_REG_PROT_CFG 0x13
|
||||
#define MAX77812_REG_VERSION 0x14
|
||||
#define MAX77812_REG_I2C_CFG 0x15
|
||||
#define MAX77812_REG_BUCK_INT 0x20
|
||||
#define MAX77812_REG_BUCK_INT_M 0x21
|
||||
#define MAX77812_REG_BUCK_STAT 0x22
|
||||
#define MAX77812_REG_M1_VOUT 0x23 // GPU.
|
||||
#define MAX77812_REG_M2_VOUT 0x24
|
||||
#define MAX77812_REG_M3_VOUT 0x25 // DRAM on PHASE211.
|
||||
#define MAX77812_REG_M4_VOUT 0x26 // CPU.
|
||||
#define MAX77812_REG_M1_VOUT_D 0x27
|
||||
#define MAX77812_REG_M2_VOUT_D 0x28
|
||||
#define MAX77812_REG_M3_VOUT_D 0x29
|
||||
#define MAX77812_REG_M4_VOUT_D 0x2A
|
||||
#define MAX77812_REG_M1_VOUT_S 0x2B
|
||||
#define MAX77812_REG_M2_VOUT_S 0x2C
|
||||
#define MAX77812_REG_M3_VOUT_S 0x2D
|
||||
#define MAX77812_REG_M4_VOUT_S 0x2E
|
||||
#define MAX77812_REG_M1_CFG 0x2F // HOS: M1_ILIM - 7.2A/4.8A.
|
||||
#define MAX77812_REG_M2_CFG 0x30 // HOS: M2_ILIM - 7.2A/4.8A.
|
||||
#define MAX77812_REG_M3_CFG 0x31 // HOS: M3_ILIM - 7.2A/4.8A.
|
||||
#define MAX77812_REG_M4_CFG 0x32 // HOS: M4_ILIM - 7.2A/4.8A.
|
||||
#define MAX77812_REG_GLB_CFG1 0x33 // HOS: B_SD_SR/B_SS_SR - 5mV/us.
|
||||
#define MAX77812_REG_GLB_CFG2 0x34 // HOS: B_RD_SR/B_RU_SR - 5mV/us
|
||||
#define MAX77812_REG_GLB_CFG3 0x35
|
||||
|
||||
/*! Protected area and settings only for MAX77812_ES2_VERSION */
|
||||
#define MAX77812_REG_GLB_CFG4 0x36 // QS: 0xBB.
|
||||
#define MAX77812_REG_GLB_CFG5 0x37 // QS: 0x39. ES2: Set to 0x3E.
|
||||
#define MAX77812_REG_GLB_CFG6 0x38 // QS: 0x88. ES2: Set to 0x90.
|
||||
#define MAX77812_REG_GLB_CFG7 0x39 // QS: 0x04.
|
||||
#define MAX77812_REG_GLB_CFG8 0x3A // QS: 0x3A. ES2: Set to 0x3A.
|
||||
|
||||
#define MAX77812_REG_PROT_ACCESS 0xFD // 0x00: Lock, 0x5A: Unlock.
|
||||
#define MAX77812_REG_UNKNOWN 0xFE
|
||||
|
||||
#define MAX77812_REG_EN_CTRL_MASK(n) BIT(n)
|
||||
#define MAX77812_START_SLEW_RATE_MASK 0x07
|
||||
#define MAX77812_SHDN_SLEW_RATE_MASK 0x70
|
||||
#define MAX77812_RAMPUP_SLEW_RATE_MASK 0x07
|
||||
#define MAX77812_RAMPDOWN_SLEW_RATE_MASK 0x70
|
||||
#define MAX77812_SLEW_RATE_SHIFT 4
|
||||
|
||||
#define MAX77812_OP_ACTIVE_DISCHARGE_MASK BIT(7)
|
||||
#define MAX77812_PEAK_CURRENT_LMT_MASK 0x70
|
||||
#define MAX77812_SWITCH_FREQ_MASK 0x0C
|
||||
#define MAX77812_FORCED_PWM_MASK BIT(1)
|
||||
#define MAX77812_SLEW_RATE_CNTRL_MASK BIT(0)
|
||||
#define MAX77812_START_SHD_DELAY_MASK 0x1F
|
||||
#define MAX77812_VERSION_MASK 0x07
|
||||
#define MAX77812_ES2_VERSION 0x04
|
||||
#define MAX77812_QS_VERSION 0x05
|
||||
|
||||
#define MAX77812_BUCK_VOLT_MASK 0xFF
|
||||
|
||||
#define BQ24193_I2C_ADDR 0x6B
|
||||
|
||||
// REG 0 masks.
|
||||
#define BQ24193_INCONFIG_INLIMIT_MASK (7 << 0)
|
||||
#define BQ24193_INCONFIG_VINDPM_MASK 0x78
|
||||
#define BQ24193_INCONFIG_HIZ_EN_MASK (1 << 7)
|
||||
|
||||
// REG 1 masks.
|
||||
#define BQ24193_PORCONFIG_BOOST_MASK (1 << 0)
|
||||
#define BQ24193_PORCONFIG_SYSMIN_MASK (7 << 1) // 3000uV HOS default.
|
||||
#define BQ24193_PORCONFIG_CHGCONFIG_MASK (3 << 4)
|
||||
#define BQ24193_PORCONFIG_CHGCONFIG_CHARGER_EN (1 << 4)
|
||||
#define BQ24193_PORCONFIG_I2CWATCHDOG_MASK (1 << 6)
|
||||
#define BQ24193_PORCONFIG_RESET_MASK (1 << 7)
|
||||
|
||||
// REG 2 masks.
|
||||
#define BQ24193_CHRGCURR_20PCT_MASK (1 << 0)
|
||||
#define BQ24193_CHRGCURR_ICHG_MASK 0xFC
|
||||
|
||||
// REG 3 masks.
|
||||
#define BQ24193_PRECHRG_ITERM 0x0F
|
||||
#define BQ24193_PRECHRG_IPRECHG 0xF0
|
||||
|
||||
// REG 4 masks.
|
||||
#define BQ24193_CHRGVOLT_VTHRES (1 << 0)
|
||||
#define BQ24193_CHRGVOLT_BATTLOW (1 << 1)
|
||||
#define BQ24193_CHRGVOLT_VREG 0xFC
|
||||
|
||||
// REG 5 masks.
|
||||
#define BQ24193_CHRGTERM_ISET_MASK (1 << 0)
|
||||
#define BQ24193_CHRGTERM_CHGTIMER_MASK (3 << 1)
|
||||
#define BQ24193_CHRGTERM_ENTIMER_MASK (1 << 3)
|
||||
#define BQ24193_CHRGTERM_WATCHDOG_MASK (3 << 4)
|
||||
#define BQ24193_CHRGTERM_TERM_ST_MASK (1 << 6)
|
||||
#define BQ24193_CHRGTERM_TERM_EN_MASK (1 << 7)
|
||||
|
||||
// REG 6 masks.
|
||||
#define BQ24193_IRTHERMAL_THERM_MASK (3 << 0)
|
||||
#define BQ24193_IRTHERMAL_VCLAMP_MASK (7 << 2)
|
||||
#define BQ24193_IRTHERMAL_BATTCOMP_MASK (7 << 5)
|
||||
|
||||
// REG 7 masks.
|
||||
#define BQ24193_MISC_INT_MASK (3 << 0)
|
||||
#define BQ24193_MISC_VSET_MASK (1 << 4)
|
||||
#define BQ24193_MISC_BATFET_DI_MASK (1 << 5)
|
||||
#define BQ24193_MISC_TMR2X_EN_MASK (1 << 6)
|
||||
#define BQ24193_MISC_DPDM_EN_MASK (1 << 7)
|
||||
|
||||
// REG 8 masks.
|
||||
#define BQ24193_STATUS_VSYS_MASK (1 << 0)
|
||||
#define BQ24193_STATUS_THERM_MASK (1 << 1)
|
||||
#define BQ24193_STATUS_PG_MASK (1 << 2)
|
||||
#define BQ24193_STATUS_DPM_MASK (1 << 3)
|
||||
#define BQ24193_STATUS_CHRG_MASK (3 << 4)
|
||||
#define BQ24193_STATUS_VBUS_MASK (3 << 6)
|
||||
|
||||
// REG 9 masks.
|
||||
#define BQ24193_FAULT_THERM_MASK (7 << 0)
|
||||
#define BQ24193_FAULT_BATT_OVP_MASK (1 << 3)
|
||||
#define BQ24193_FAULT_CHARGE_MASK (3 << 4)
|
||||
#define BQ24193_FAULT_BOOST_MASK (1 << 6)
|
||||
#define BQ24193_FAULT_WATCHDOG_MASK (1 << 7)
|
||||
|
||||
// REG A masks.
|
||||
#define BQ24193_VENDORPART_DEV_MASK (3 << 0)
|
||||
#define BQ24193_VENDORPART_PN_MASK (7 << 3)
|
||||
|
||||
enum BQ24193_reg {
|
||||
BQ24193_InputSource = 0x00,
|
||||
BQ24193_PORConfig = 0x01,
|
||||
BQ24193_ChrgCurr = 0x02,
|
||||
BQ24193_PreChrgTerm = 0x03,
|
||||
BQ24193_ChrgVolt = 0x04,
|
||||
BQ24193_ChrgTermTimer = 0x05,
|
||||
BQ24193_IRCompThermal = 0x06,
|
||||
BQ24193_Misc = 0x07,
|
||||
BQ24193_Status = 0x08,
|
||||
BQ24193_FaultReg = 0x09,
|
||||
BQ24193_VendorPart = 0x0A,
|
||||
};
|
||||
|
||||
enum BQ24193_reg_prop {
|
||||
BQ24193_InputVoltageLimit, // REG 0.
|
||||
BQ24193_InputCurrentLimit, // REG 0.
|
||||
BQ24193_SystemMinimumVoltage, // REG 1.
|
||||
BQ24193_FastChargeCurrentLimit, // REG 2.
|
||||
BQ24193_ChargeVoltageLimit, // REG 4.
|
||||
BQ24193_RechargeThreshold, // REG 4.
|
||||
BQ24193_ThermalRegulation, // REG 6.
|
||||
BQ24193_ChargeStatus, // REG 8.
|
||||
BQ24193_TempStatus, // REG 9.
|
||||
BQ24193_DevID, // REG A.
|
||||
BQ24193_ProductNumber, // REG A.
|
||||
};
|
||||
|
||||
#endif /* MAX77XXX_H */
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
static void writeNotification(const std::string& message) {
|
||||
const char* flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
|
||||
|
||||
// Check if flag file exists
|
||||
FILE* flagFile = fopen(flagPath, "r");
|
||||
if (!flagFile) {
|
||||
// Flag file does not exist, do nothing
|
||||
return;
|
||||
}
|
||||
fclose(flagFile);
|
||||
|
||||
// Generate filename with timestamp
|
||||
std::string filename = "Horzon OC -" + std::to_string(std::time(nullptr)) + ".notify";
|
||||
std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename;
|
||||
|
||||
// Write JSON manually
|
||||
FILE* file = fopen(fullPath.c_str(), "w");
|
||||
if (file) {
|
||||
fprintf(file, "{\n");
|
||||
fprintf(file, " \"text\": \"%s\",\n", message.c_str());
|
||||
fprintf(file, " \"fontSize\": 28\n");
|
||||
fprintf(file, "}\n");
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* * HOS soctherm driver by Souldbminer & Dominatorul * Licensed under the LGPLv3 */
|
||||
#ifndef _SOCTHERM_H_
|
||||
#define _SOCTHERM_H_
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define SOCTHERM_BASE 0x700E2000ULL
|
||||
|
||||
#define SENSOR_TEMP1 0x1c8
|
||||
#define SENSOR_TEMP2 0x1cc
|
||||
|
||||
#define SOC_THERM_THERMCTL_LEVEL0_GROUP_CPU_0 0x0
|
||||
#define SOC_THERM_THERMCTL_LEVEL0_GROUP_GPU_0 0x4
|
||||
#define SOC_THERM_THERMCTL_LEVEL0_GROUP_MEM_0 0x8
|
||||
#define SOC_THERM_THERMCTL_LEVEL0_GROUP_TSENSE_0 0xC
|
||||
|
||||
#define SENSOR_CPU0_CONFIG0 0xC0
|
||||
#define SENSOR_CPU1_CONFIG0 0xE0
|
||||
#define SENSOR_CPU2_CONFIG0 0x100
|
||||
#define SENSOR_CPU3_CONFIG0 0x120
|
||||
#define SENSOR_GPU_CONFIG0 0x180
|
||||
#define SENSOR_PLLX_CONFIG0 0x1A0
|
||||
|
||||
#define SENSOR_CPU0_CONFIG1 0xC4
|
||||
#define SENSOR_CPU1_CONFIG1 0xE4
|
||||
#define SENSOR_CPU2_CONFIG1 0x104
|
||||
#define SENSOR_CPU3_CONFIG1 0x124
|
||||
#define SENSOR_GPU_CONFIG1 0x184
|
||||
#define SENSOR_PLLX_CONFIG1 0x1A4
|
||||
|
||||
#define SENSOR_CPU0_STATUS 0xC8
|
||||
#define SENSOR_GPU_STATUS 0x188
|
||||
#define SENSOR_PLLX_STATUS 0x1A8
|
||||
|
||||
#define SENSOR_CONFIG0_STOP_MASK (1U << 0)
|
||||
#define SENSOR_CONFIG0_TALL_SHIFT 8
|
||||
#define SENSOR_CONFIG0_TALL_MASK (0xFFFFF << 8)
|
||||
|
||||
#define SENSOR_CONFIG1_TEMP_ENABLE_MASK (1U << 31)
|
||||
#define SENSOR_CONFIG1_TEN_COUNT_SHIFT 24
|
||||
#define SENSOR_CONFIG1_TEN_COUNT_MASK (0x3F << 24)
|
||||
#define SENSOR_CONFIG1_TIDDQ_EN_SHIFT 15
|
||||
#define SENSOR_CONFIG1_TIDDQ_EN_MASK (0x3F << 15)
|
||||
#define SENSOR_CONFIG1_TSAMPLE_SHIFT 0
|
||||
#define SENSOR_CONFIG1_TSAMPLE_MASK 0x3FF
|
||||
|
||||
#define SENSOR_STATUS_VALID_MASK (1U << 31)
|
||||
|
||||
#define TSENSOR_TALL_DEFAULT 16300
|
||||
#define TSENSOR_TIDDQ_EN_DEFAULT 1
|
||||
#define TSENSOR_TEN_COUNT_DEFAULT 1
|
||||
#define TSENSOR_TSAMPLE_DEFAULT 120
|
||||
|
||||
#define SENSOR_TEMP1_CPU_TEMP_MASK (0xFFFF << 16)
|
||||
#define SENSOR_TEMP1_GPU_TEMP_MASK 0xFFFF
|
||||
#define SENSOR_TEMP2_PLLX_TEMP_MASK 0xFFFF
|
||||
|
||||
#define READBACK_VALUE_MASK 0xFF00
|
||||
#define READBACK_VALUE_SHIFT 8
|
||||
#define READBACK_ADD_HALF (1 << 7)
|
||||
#define READBACK_NEGATE (1 << 0)
|
||||
|
||||
#define REG_GET_MASK(r, m) (((r) & (m)) >> (__builtin_ffs(m) - 1))
|
||||
|
||||
// Timing constants (in microseconds)
|
||||
#define SENSOR_STABILIZATION_DELAY_US 2000 // 2ms for sensor to stabilize
|
||||
#define SENSOR_READ_DELAY_US 100 // 100us between config operations
|
||||
|
||||
// Makes my life easier
|
||||
#define BITMASK(bits) (0UL | (bits))
|
||||
#define BIT(n) (1UL << (n))
|
||||
|
||||
#define WRITE_REG_BIT(addr, bit, val) do { \
|
||||
u32 _tmp; \
|
||||
svcReadWriteRegister(&_tmp, (addr), 0, false); \
|
||||
if (val) \
|
||||
_tmp |= (1U << (bit)); /* set bit */ \
|
||||
else \
|
||||
_tmp &= ~(1U << (bit)); /* clear bit */ \
|
||||
svcReadWriteRegister(&_tmp, (addr), 0, true); \
|
||||
} while (0)
|
||||
|
||||
typedef enum {
|
||||
SENSOR_CPU = 0,
|
||||
SENSOR_GPU = 1,
|
||||
SENSOR_PLLX = 2,
|
||||
} SocthermSensor;
|
||||
|
||||
void socthermInit(void) {
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU0_CONFIG0, 0, 0); // start cpu0
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU0_CONFIG1, 31, 1); // start cpu0
|
||||
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU1_CONFIG0, 0, 0); // start cpu1
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU1_CONFIG1, 31, 1); // start cpu1
|
||||
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU2_CONFIG0, 0, 0); // start cpu2
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU2_CONFIG1, 31, 1); // start cpu2
|
||||
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU3_CONFIG0, 0, 0); // start cpu3
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_CPU3_CONFIG1, 31, 1); // start cpu3
|
||||
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_GPU_CONFIG0, 0, 0); // start gpu
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_GPU_CONFIG1, 31, 1); // start gpu
|
||||
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_PLLX_CONFIG0, 0, 0); // start pllx
|
||||
WRITE_REG_BIT(SOCTHERM_BASE + SENSOR_PLLX_CONFIG1, 31, 1); // start pllx
|
||||
}
|
||||
|
||||
int socthermRead(SocthermSensor sensor) {
|
||||
switch(sensor) {
|
||||
case SENSOR_CPU: {
|
||||
u32 temp_reg;
|
||||
svcReadWriteRegister(&temp_reg, SOCTHERM_BASE + SENSOR_TEMP1, 0, false);
|
||||
return REG_GET_MASK(temp_reg, SENSOR_TEMP1_CPU_TEMP_MASK);
|
||||
}
|
||||
case SENSOR_GPU: {
|
||||
u32 temp_reg;
|
||||
svcReadWriteRegister(&temp_reg, SOCTHERM_BASE + SENSOR_TEMP1, 0, false);
|
||||
return REG_GET_MASK(temp_reg, SENSOR_TEMP1_GPU_TEMP_MASK);
|
||||
}
|
||||
case SENSOR_PLLX: {
|
||||
u32 temp_reg;
|
||||
svcReadWriteRegister(&temp_reg, SOCTHERM_BASE + SENSOR_TEMP2, 0, false);
|
||||
return REG_GET_MASK(temp_reg, SENSOR_TEMP2_PLLX_TEMP_MASK);
|
||||
}
|
||||
default:
|
||||
return -1; // Invalid sensor
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _SOCTHERM_H_
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name" : "Horizon OC",
|
||||
"name" : "hoc-clk",
|
||||
"tid" : "00FF0000636C6BFF",
|
||||
"requires_reboot": false
|
||||
}
|
||||
Reference in New Issue
Block a user