chore: many changes
This commit is contained in:
186
Source/OnDeviceConfig/Makefile
Normal file
186
Source/OnDeviceConfig/Makefile
Normal file
@@ -0,0 +1,186 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Project Info
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := hoc-configurator
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
#ROMFS := romfs
|
||||
|
||||
APP_TITLE := HOC Configurator
|
||||
APP_AUTHOR := Dominatorul
|
||||
APP_VERSION := 2.0.0
|
||||
ICON := icon.jpg
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Compilation Settings
|
||||
#---------------------------------------------------------------------------------
|
||||
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-rtti -fno-exceptions -std=gnu++17
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lnx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Library Paths
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Automatic Build Rules
|
||||
#---------------------------------------------------------------------------------
|
||||
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)/*.*)))
|
||||
|
||||
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 rebuild
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Automatically clean before build
|
||||
#---------------------------------------------------------------------------------
|
||||
all: clean $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
||||
else
|
||||
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# Optional: Full rebuild command
|
||||
#---------------------------------------------------------------------------------
|
||||
rebuild: clean all
|
||||
@echo "Rebuilt from scratch."
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
|
||||
all : $(OUTPUT).nro
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
else
|
||||
$(OUTPUT).nro : $(OUTPUT).elf
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
all : $(OUTPUT).nsp
|
||||
|
||||
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
|
||||
|
||||
$(OUTPUT).nso : $(OUTPUT).elf
|
||||
|
||||
endif
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
%.bin.o %_bin.h : %.bin
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
BIN
Source/OnDeviceConfig/hoc-configurator.elf
Normal file
BIN
Source/OnDeviceConfig/hoc-configurator.elf
Normal file
Binary file not shown.
BIN
Source/OnDeviceConfig/hoc-configurator.nacp
Normal file
BIN
Source/OnDeviceConfig/hoc-configurator.nacp
Normal file
Binary file not shown.
BIN
Source/OnDeviceConfig/hoc-configurator.nro
Normal file
BIN
Source/OnDeviceConfig/hoc-configurator.nro
Normal file
Binary file not shown.
BIN
Source/OnDeviceConfig/icon.jpg
Normal file
BIN
Source/OnDeviceConfig/icon.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
20
Source/OnDeviceConfig/include/config.hpp
Normal file
20
Source/OnDeviceConfig/include/config.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* HOC Configurator - Configuration Handler
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class Config {
|
||||
public:
|
||||
std::string kipPath;
|
||||
bool autoSave;
|
||||
|
||||
Config();
|
||||
|
||||
bool loadConfig();
|
||||
bool saveConfig();
|
||||
bool checkKipExists();
|
||||
bool checkAtmosphereExists();
|
||||
};
|
||||
143
Source/OnDeviceConfig/include/constants.hpp
Normal file
143
Source/OnDeviceConfig/include/constants.hpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* HOC Configurator - Constants
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Constants {
|
||||
// Application info
|
||||
constexpr const char* APP_VERSION = "2.0.0";
|
||||
constexpr const char* APP_NAME = "HOC Configurator";
|
||||
constexpr const char* APP_AUTHOR = "Dominatorul";
|
||||
|
||||
// Paths
|
||||
constexpr const char* DEFAULT_KIP_PATH = "sdmc:/atmosphere/kips/loader.kip";
|
||||
constexpr const char* CONFIG_DIR = "sdmc:/config/hoc-configurator";
|
||||
constexpr const char* CONFIG_FILE = "sdmc:/config/hoc-configurator/config.ini";
|
||||
constexpr const char* ATMOSPHERE_PATH = "sdmc:/atmosphere";
|
||||
constexpr const char* SYSTEM_SETTINGS_INI = "sdmc:/atmosphere/config/system_settings.ini";
|
||||
|
||||
// Frequency arrays (in kHz)
|
||||
constexpr uint32_t MARIKO_GPU_FREQS[] = {
|
||||
76800, 153600, 230400, 307200, 384000, 460800, 537600, 614400,
|
||||
691200, 768000, 844800, 921600, 998400, 1075200, 1152000, 1228800,
|
||||
1267200, 1305600, 1344000, 1382400, 1420800, 1459200, 1497600, 1536000
|
||||
};
|
||||
|
||||
constexpr uint32_t ERISTA_GPU_FREQS[] = {
|
||||
76800, 153600, 230400, 307200, 384000, 460800, 537600, 614400,
|
||||
691200, 768000, 844800, 921600, 998400, 1075200
|
||||
};
|
||||
|
||||
constexpr uint32_t CPU_FREQS[] = {
|
||||
1020000, 1122000, 1224000, 1326000, 1428000, 1581000, 1683000,
|
||||
1785000, 1887000, 1963500, 2091000, 2193000, 2295000, 2397000,
|
||||
2499000, 2601000, 2703000, 2805000, 2907000
|
||||
};
|
||||
|
||||
constexpr uint32_t RAM_FREQS[] = {
|
||||
0, 1600000, 1633000, 1666000, 1700000, 1733000, 1766000, 1800000,
|
||||
1833000, 1866000, 1900000, 1933000, 1966000, 2000000, 2033000, 2066000,
|
||||
2100000, 2133000, 2166000, 2200000, 2233000, 2266000, 2300000
|
||||
};
|
||||
|
||||
// Voltage ranges
|
||||
constexpr uint32_t MARIKO_GPU_MIN_VOLT = 480;
|
||||
constexpr uint32_t MARIKO_GPU_MAX_VOLT = 960;
|
||||
constexpr uint32_t MARIKO_GPU_MAX_VMIN = 700;
|
||||
|
||||
constexpr uint32_t ERISTA_GPU_MIN_VOLT = 700;
|
||||
constexpr uint32_t ERISTA_GPU_MAX_VOLT = 1000;
|
||||
constexpr uint32_t ERISTA_GPU_MAX_VMIN = 850;
|
||||
|
||||
constexpr uint32_t MARIKO_CPU_MIN_VMIN = 700;
|
||||
constexpr uint32_t MARIKO_CPU_MAX_VMIN = 750;
|
||||
|
||||
constexpr uint32_t VOLTAGE_STEP = 5;
|
||||
constexpr uint32_t GPU_OFFSET_MAX = 50;
|
||||
|
||||
// Thresholds
|
||||
constexpr uint32_t MARIKO_MEME_THRESHOLD = 1536000;
|
||||
constexpr uint32_t MARIKO_DANGEROUS_GPU_THRESHOLD = 1382400;
|
||||
constexpr uint32_t MARIKO_UNSAFE_GPU_THRESHOLD = 1152000;
|
||||
|
||||
constexpr uint32_t ERISTA_DANGEROUS_GPU_THRESHOLD = 1151000;
|
||||
constexpr uint32_t ERISTA_UNSAFE_GPU_THRESHOLD = 922000;
|
||||
|
||||
// RAM Types
|
||||
const std::string RAM_TYPES[] = {
|
||||
"Samsung AA-MGCL/MGCR",
|
||||
"SK Hynix NEI/NEE/x267",
|
||||
"Micron WT:B",
|
||||
"Micron AUT:B",
|
||||
"Micron WT:F",
|
||||
"Samsung AM-MGCJ",
|
||||
"Micron WT:E",
|
||||
"Samsung AB-MGCL",
|
||||
"SK Hynix NME",
|
||||
"Samsung HB-MGCH"
|
||||
};
|
||||
|
||||
// Fan curve profiles
|
||||
namespace FanProfiles {
|
||||
constexpr const char* V1_ERISTA = "V1_Erista";
|
||||
constexpr const char* V2_MARIKO = "V2_Mariko";
|
||||
constexpr const char* LITE_MARIKO = "Lite_Mariko";
|
||||
constexpr const char* OLED_MARIKO = "OLED_Mariko";
|
||||
}
|
||||
|
||||
// PSM (Battery) options
|
||||
struct PSMOption {
|
||||
const char* name;
|
||||
uint32_t value;
|
||||
};
|
||||
|
||||
constexpr PSMOption PSM_OPTIONS[] = {
|
||||
{"1024mA", 0x400},
|
||||
{"1280mA", 0x500},
|
||||
{"1536mA", 0x600},
|
||||
{"1660mA (Lite Default)", 0x67C},
|
||||
{"1792mA", 0x700},
|
||||
{"2048mA (Default)", 0x800},
|
||||
{"2304mA (UNSAFE)", 0x900},
|
||||
{"2560mA (UNSAFE)", 0xA00},
|
||||
{"2816mA (DANGEROUS)", 0xB00},
|
||||
{"3072mA (DANGEROUS)", 0xC00}
|
||||
};
|
||||
|
||||
// Memory timing presets
|
||||
struct TimingPreset {
|
||||
uint32_t tRCD;
|
||||
uint32_t tRP;
|
||||
uint32_t tRAS;
|
||||
uint32_t tRRD;
|
||||
uint32_t tRFC;
|
||||
uint32_t tRTW;
|
||||
uint32_t tWTR;
|
||||
uint32_t tREFI;
|
||||
};
|
||||
|
||||
// Default timing preset
|
||||
constexpr TimingPreset TIMING_DEFAULT = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// Samsung AA-MGCL/MGCR presets
|
||||
constexpr TimingPreset TIMING_AAMGCL_CONSERVATIVE = {4, 4, 5, 5, 5, 5, 7, 6};
|
||||
constexpr TimingPreset TIMING_AAMGCL_TIGHT = {4, 4, 8, 6, 5, 7, 8, 6};
|
||||
|
||||
// SK Hynix NEE presets
|
||||
constexpr TimingPreset TIMING_NEE_CONSERVATIVE = {3, 3, 2, 2, 5, 5, 4, 6};
|
||||
constexpr TimingPreset TIMING_NEE_TIGHT = {4, 4, 4, 3, 7, 6, 5, 6};
|
||||
|
||||
// Micron WT:B presets
|
||||
constexpr TimingPreset TIMING_WTB_CONSERVATIVE = {4, 4, 5, 5, 2, 6, 5, 6};
|
||||
constexpr TimingPreset TIMING_WTB_TIGHT = {6, 6, 7, 7, 2, 6, 5, 6};
|
||||
|
||||
// UI Constants
|
||||
constexpr int MAX_VISIBLE_ITEMS = 20;
|
||||
constexpr int MENU_START_Y = 7;
|
||||
constexpr int SCREEN_WIDTH = 80;
|
||||
constexpr int SCREEN_HEIGHT = 45;
|
||||
}
|
||||
94
Source/OnDeviceConfig/include/defaults.hpp
Normal file
94
Source/OnDeviceConfig/include/defaults.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* HOC Configurator - Default Values
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
class KipHandler;
|
||||
|
||||
class Defaults {
|
||||
public:
|
||||
template<typename T>
|
||||
static void initDefaults(T& data) {
|
||||
data.custRev = 0;
|
||||
data.mtcConf = 0;
|
||||
data.commonCpuBoostClock = 1785000;
|
||||
data.commonEmcMemVolt = 1175000;
|
||||
data.eristaCpuMaxVolt = 1235;
|
||||
data.eristaEmcMaxClock = 1862400;
|
||||
data.marikoCpuMaxVolt = 1120;
|
||||
data.marikoEmcMaxClock = 1996800;
|
||||
data.marikoEmcVddqVolt = 600000;
|
||||
data.marikoCpuUV = 0;
|
||||
data.marikoGpuUV = 0;
|
||||
data.eristaCpuUV = 0;
|
||||
data.eristaGpuUV = 0;
|
||||
data.enableMarikoGpuUnsafeFreqs = 0;
|
||||
data.enableEristaGpuUnsafeFreqs = 0;
|
||||
data.enableMarikoCpuUnsafeFreqs = 0;
|
||||
data.enableEristaCpuUnsafeFreqs = 0;
|
||||
data.commonGpuVoltOffset = 0;
|
||||
data.marikoEmcDvbShift = 0;
|
||||
|
||||
// Memory timings
|
||||
data.t1_tRCD = 0;
|
||||
data.t2_tRP = 0;
|
||||
data.t3_tRAS = 0;
|
||||
data.t4_tRRD = 0;
|
||||
data.t5_tRFC = 0;
|
||||
data.t6_tRTW = 0;
|
||||
data.t7_tWTR = 0;
|
||||
data.t8_tREFI = 0;
|
||||
data.mem_burst_latency = 2;
|
||||
|
||||
// Additional voltages
|
||||
data.marikoCpuVmin = 0;
|
||||
data.eristaGpuVmin = 0;
|
||||
data.marikoGpuVmin = 0;
|
||||
data.marikoGpuVmax = 0;
|
||||
|
||||
// Initialize all GPU voltages to 600 (default safe value)
|
||||
data.g_volt_76800 = 600;
|
||||
data.g_volt_153600 = 600;
|
||||
data.g_volt_230400 = 600;
|
||||
data.g_volt_307200 = 600;
|
||||
data.g_volt_384000 = 600;
|
||||
data.g_volt_460800 = 600;
|
||||
data.g_volt_537600 = 600;
|
||||
data.g_volt_614400 = 600;
|
||||
data.g_volt_691200 = 600;
|
||||
data.g_volt_768000 = 600;
|
||||
data.g_volt_844800 = 605;
|
||||
data.g_volt_921600 = 635;
|
||||
data.g_volt_998400 = 665;
|
||||
data.g_volt_1075200 = 695;
|
||||
data.g_volt_1152000 = 730;
|
||||
data.g_volt_1228800 = 760;
|
||||
data.g_volt_1267200 = 785;
|
||||
data.g_volt_1305600 = 800;
|
||||
data.g_volt_1344000 = 0;
|
||||
data.g_volt_1382400 = 0;
|
||||
data.g_volt_1420800 = 0;
|
||||
data.g_volt_1459200 = 0;
|
||||
data.g_volt_1497600 = 0;
|
||||
data.g_volt_1536000 = 0;
|
||||
|
||||
// Erista GPU voltages
|
||||
data.g_volt_e_76800 = 700;
|
||||
data.g_volt_e_153600 = 700;
|
||||
data.g_volt_e_230400 = 700;
|
||||
data.g_volt_e_307200 = 700;
|
||||
data.g_volt_e_384000 = 700;
|
||||
data.g_volt_e_460800 = 700;
|
||||
data.g_volt_e_537600 = 700;
|
||||
data.g_volt_e_614400 = 700;
|
||||
data.g_volt_e_691200 = 700;
|
||||
data.g_volt_e_768000 = 700;
|
||||
data.g_volt_e_844800 = 710;
|
||||
data.g_volt_e_921600 = 740;
|
||||
data.g_volt_e_998400 = 770;
|
||||
data.g_volt_e_1075200 = 800;
|
||||
}
|
||||
};
|
||||
24
Source/OnDeviceConfig/include/ini_header.hpp
Normal file
24
Source/OnDeviceConfig/include/ini_header.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class IniHandler {
|
||||
private:
|
||||
std::string iniPath;
|
||||
std::map<std::string, std::map<std::string, std::string>> sections;
|
||||
|
||||
public:
|
||||
IniHandler(const std::string& path);
|
||||
|
||||
bool load();
|
||||
bool save();
|
||||
|
||||
void setValue(const std::string& section, const std::string& key, const std::string& value);
|
||||
std::string getValue(const std::string& section, const std::string& key, const std::string& defaultValue = "");
|
||||
void removeKey(const std::string& section, const std::string& key);
|
||||
void removeSection(const std::string& section);
|
||||
|
||||
bool sectionExists(const std::string& section);
|
||||
bool keyExists(const std::string& section, const std::string& key);
|
||||
};
|
||||
123
Source/OnDeviceConfig/include/kip_handler.hpp
Normal file
123
Source/OnDeviceConfig/include/kip_handler.hpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* HOC Configurator - KIP Handler
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "defaults.hpp"
|
||||
|
||||
class KipHandler {
|
||||
private:
|
||||
std::string kipPath;
|
||||
const uint8_t MAGIC[4] = {'C', 'U', 'S', 'T'};
|
||||
|
||||
struct KipData {
|
||||
uint32_t custRev;
|
||||
uint32_t mtcConf;
|
||||
uint32_t commonCpuBoostClock;
|
||||
uint32_t commonEmcMemVolt;
|
||||
uint32_t eristaCpuMaxVolt;
|
||||
uint32_t eristaEmcMaxClock;
|
||||
uint32_t marikoCpuMaxVolt;
|
||||
uint32_t marikoEmcMaxClock;
|
||||
uint32_t marikoEmcVddqVolt;
|
||||
uint32_t marikoCpuUV;
|
||||
uint32_t marikoGpuUV;
|
||||
uint32_t eristaCpuUV;
|
||||
uint32_t eristaGpuUV;
|
||||
uint32_t enableMarikoGpuUnsafeFreqs;
|
||||
uint32_t enableEristaGpuUnsafeFreqs;
|
||||
uint32_t enableMarikoCpuUnsafeFreqs;
|
||||
uint32_t enableEristaCpuUnsafeFreqs;
|
||||
uint32_t commonGpuVoltOffset;
|
||||
uint32_t marikoEmcDvbShift;
|
||||
|
||||
// Memory timings
|
||||
uint32_t t1_tRCD;
|
||||
uint32_t t2_tRP;
|
||||
uint32_t t3_tRAS;
|
||||
uint32_t t4_tRRD;
|
||||
uint32_t t5_tRFC;
|
||||
uint32_t t6_tRTW;
|
||||
uint32_t t7_tWTR;
|
||||
uint32_t t8_tREFI;
|
||||
uint32_t mem_burst_latency;
|
||||
|
||||
// Additional voltages
|
||||
uint32_t marikoCpuVmin;
|
||||
uint32_t eristaGpuVmin;
|
||||
uint32_t marikoGpuVmin;
|
||||
uint32_t marikoGpuVmax;
|
||||
|
||||
// GPU voltages for each frequency (Mariko)
|
||||
uint32_t g_volt_76800;
|
||||
uint32_t g_volt_153600;
|
||||
uint32_t g_volt_230400;
|
||||
uint32_t g_volt_307200;
|
||||
uint32_t g_volt_384000;
|
||||
uint32_t g_volt_460800;
|
||||
uint32_t g_volt_537600;
|
||||
uint32_t g_volt_614400;
|
||||
uint32_t g_volt_691200;
|
||||
uint32_t g_volt_768000;
|
||||
uint32_t g_volt_844800;
|
||||
uint32_t g_volt_921600;
|
||||
uint32_t g_volt_998400;
|
||||
uint32_t g_volt_1075200;
|
||||
uint32_t g_volt_1152000;
|
||||
uint32_t g_volt_1228800;
|
||||
uint32_t g_volt_1267200;
|
||||
uint32_t g_volt_1305600;
|
||||
uint32_t g_volt_1344000;
|
||||
uint32_t g_volt_1382400;
|
||||
uint32_t g_volt_1420800;
|
||||
uint32_t g_volt_1459200;
|
||||
uint32_t g_volt_1497600;
|
||||
uint32_t g_volt_1536000;
|
||||
|
||||
// GPU voltages for each frequency (Erista)
|
||||
uint32_t g_volt_e_76800;
|
||||
uint32_t g_volt_e_153600;
|
||||
uint32_t g_volt_e_230400;
|
||||
uint32_t g_volt_e_307200;
|
||||
uint32_t g_volt_e_384000;
|
||||
uint32_t g_volt_e_460800;
|
||||
uint32_t g_volt_e_537600;
|
||||
uint32_t g_volt_e_614400;
|
||||
uint32_t g_volt_e_691200;
|
||||
uint32_t g_volt_e_768000;
|
||||
uint32_t g_volt_e_844800;
|
||||
uint32_t g_volt_e_921600;
|
||||
uint32_t g_volt_e_998400;
|
||||
uint32_t g_volt_e_1075200;
|
||||
};
|
||||
|
||||
KipData data;
|
||||
|
||||
public:
|
||||
KipHandler(const std::string& path) : kipPath(path) {
|
||||
// Initialize with defaults
|
||||
Defaults::initDefaults(data);
|
||||
}
|
||||
|
||||
bool readKip();
|
||||
bool writeKip();
|
||||
|
||||
// Getters
|
||||
KipData& getData() { return data; }
|
||||
const KipData& getData() const { return data; }
|
||||
|
||||
// Setters for common values
|
||||
void setCommonCpuBoostClock(uint32_t val) { data.commonCpuBoostClock = val; }
|
||||
void setCommonEmcMemVolt(uint32_t val) { data.commonEmcMemVolt = val; }
|
||||
void setMarikoCpuMaxVolt(uint32_t val) { data.marikoCpuMaxVolt = val; }
|
||||
void setMarikoEmcMaxClock(uint32_t val) { data.marikoEmcMaxClock = val; }
|
||||
void setMarikoEmcVddqVolt(uint32_t val) { data.marikoEmcVddqVolt = val; }
|
||||
|
||||
// Utility
|
||||
std::string getKipPath() const { return kipPath; }
|
||||
void setKipPath(const std::string& path) { kipPath = path; }
|
||||
};
|
||||
91
Source/OnDeviceConfig/include/ui.hpp
Normal file
91
Source/OnDeviceConfig/include/ui.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* HOC Configurator - UI Handler
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <switch.h>
|
||||
|
||||
// Forward declarations
|
||||
class KipHandler;
|
||||
class ValueEditor;
|
||||
|
||||
enum class EditorType {
|
||||
TOGGLE,
|
||||
FREQUENCY,
|
||||
VOLTAGE,
|
||||
SLIDER,
|
||||
LIST
|
||||
};
|
||||
|
||||
enum class MenuState {
|
||||
MAIN,
|
||||
GPU,
|
||||
CPU,
|
||||
RAM,
|
||||
MISC,
|
||||
ABOUT,
|
||||
SETTINGS
|
||||
};
|
||||
|
||||
class UI {
|
||||
private:
|
||||
MenuState currentState;
|
||||
int selectedIndex;
|
||||
int scrollOffset;
|
||||
std::string statusMessage;
|
||||
std::string kipPath;
|
||||
bool kipLoaded;
|
||||
bool autoSave;
|
||||
KipHandler* kipHandler;
|
||||
ValueEditor* editor;
|
||||
|
||||
const int MAX_VISIBLE_ITEMS = 20;
|
||||
|
||||
void renderMainMenu();
|
||||
void renderGPUMenu();
|
||||
void renderCPUMenu();
|
||||
void renderRAMMenu();
|
||||
void renderMiscMenu();
|
||||
void renderAboutMenu();
|
||||
void renderSettingsMenu();
|
||||
|
||||
void handleMainMenuInput(u64 kDown);
|
||||
void handleGPUMenuInput(u64 kDown);
|
||||
void handleCPUMenuInput(u64 kDown);
|
||||
void handleRAMMenuInput(u64 kDown);
|
||||
void handleMiscMenuInput(u64 kDown);
|
||||
void handleAboutMenuInput(u64 kDown);
|
||||
void handleSettingsMenuInput(u64 kDown);
|
||||
|
||||
void drawHeader();
|
||||
void drawFooter();
|
||||
void drawMenuItem(const std::string& text, bool selected, int y);
|
||||
void drawText(const std::string& text, int x, int y);
|
||||
|
||||
void showValueEditor(const std::string& title, EditorType type, int currentValue,
|
||||
std::function<void(int)> callback,
|
||||
const std::vector<std::string>& options = {},
|
||||
int min = 0, int max = 100, int step = 1);
|
||||
|
||||
public:
|
||||
UI();
|
||||
~UI();
|
||||
|
||||
void render();
|
||||
void handleInput(u64 kDown);
|
||||
|
||||
void setStatus(const std::string& msg) { statusMessage = msg; }
|
||||
void setKipPath(const std::string& path) { kipPath = path; }
|
||||
void setKipLoaded(bool loaded) { kipLoaded = loaded; }
|
||||
void setAutoSave(bool enabled) { autoSave = enabled; }
|
||||
void setKipHandler(KipHandler* handler) { kipHandler = handler; }
|
||||
|
||||
std::string getStatus() const { return statusMessage; }
|
||||
std::string getKipPath() const { return kipPath; }
|
||||
bool isKipLoaded() const { return kipLoaded; }
|
||||
bool isAutoSaveEnabled() const { return autoSave; }
|
||||
};
|
||||
43
Source/OnDeviceConfig/include/value_editor.hpp
Normal file
43
Source/OnDeviceConfig/include/value_editor.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* HOC Configurator - Value Editor
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <switch.h>
|
||||
#include "ui.hpp" // This includes EditorType
|
||||
|
||||
class KipHandler;
|
||||
|
||||
struct EditorConfig {
|
||||
std::string title;
|
||||
EditorType type;
|
||||
int currentValue;
|
||||
int minValue;
|
||||
int maxValue;
|
||||
int step;
|
||||
std::vector<std::string> options;
|
||||
std::function<void(int)> onValueChange;
|
||||
};
|
||||
|
||||
class ValueEditor {
|
||||
private:
|
||||
EditorConfig config;
|
||||
int selectedValue;
|
||||
bool active;
|
||||
|
||||
public:
|
||||
ValueEditor();
|
||||
|
||||
void show(const EditorConfig& cfg);
|
||||
void hide();
|
||||
bool isActive() const { return active; }
|
||||
|
||||
void handleInput(u64 kDown);
|
||||
void render();
|
||||
|
||||
int getSelectedValue() const { return selectedValue; }
|
||||
};
|
||||
59
Source/OnDeviceConfig/source/config.cpp
Normal file
59
Source/OnDeviceConfig/source/config.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* HOC Configurator - Configuration Implementation
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#include "config.hpp"
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
Config::Config() {
|
||||
kipPath = "sdmc:/atmosphere/kips/loader.kip";
|
||||
autoSave = false;
|
||||
}
|
||||
|
||||
bool Config::loadConfig() {
|
||||
std::ifstream file("sdmc:/config/hoc-configurator/config.ini");
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
if (line.find("kip_path=") == 0) {
|
||||
kipPath = line.substr(9);
|
||||
} else if (line.find("auto_save=") == 0) {
|
||||
autoSave = (line.substr(10) == "1");
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config::saveConfig() {
|
||||
// Create directory if it doesn't exist
|
||||
mkdir("sdmc:/config", 0777);
|
||||
mkdir("sdmc:/config/hoc-configurator", 0777);
|
||||
|
||||
std::ofstream file("sdmc:/config/hoc-configurator/config.ini");
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "kip_path=" << kipPath << "\n";
|
||||
file << "auto_save=" << (autoSave ? "1" : "0") << "\n";
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config::checkKipExists() {
|
||||
struct stat buffer;
|
||||
return (stat(kipPath.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
bool Config::checkAtmosphereExists() {
|
||||
struct stat buffer;
|
||||
return (stat("sdmc:/atmosphere", &buffer) == 0);
|
||||
}
|
||||
24
Source/OnDeviceConfig/source/ini_header.cpp
Normal file
24
Source/OnDeviceConfig/source/ini_header.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class IniHandler {
|
||||
private:
|
||||
std::string iniPath;
|
||||
std::map<std::string, std::map<std::string, std::string>> sections;
|
||||
|
||||
public:
|
||||
IniHandler(const std::string& path);
|
||||
|
||||
bool load();
|
||||
bool save();
|
||||
|
||||
void setValue(const std::string& section, const std::string& key, const std::string& value);
|
||||
std::string getValue(const std::string& section, const std::string& key, const std::string& defaultValue = "");
|
||||
void removeKey(const std::string& section, const std::string& key);
|
||||
void removeSection(const std::string& section);
|
||||
|
||||
bool sectionExists(const std::string& section);
|
||||
bool keyExists(const std::string& section, const std::string& key);
|
||||
};
|
||||
254
Source/OnDeviceConfig/source/kip_handler.cpp
Normal file
254
Source/OnDeviceConfig/source/kip_handler.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* HOC Configurator - KIP Handler Implementation
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#include "kip_handler.hpp"
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
bool KipHandler::readKip() {
|
||||
std::ifstream file(kipPath, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read entire file
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<uint8_t> buffer(fileSize);
|
||||
file.read(reinterpret_cast<char*>(buffer.data()), fileSize);
|
||||
file.close();
|
||||
|
||||
// Find CUST magic
|
||||
size_t magicPos = 0;
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < fileSize - 4; i++) {
|
||||
if (memcmp(&buffer[i], MAGIC, 4) == 0) {
|
||||
magicPos = i + 4;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read structure (assuming packed uint32_t structure)
|
||||
size_t offset = magicPos;
|
||||
auto readU32 = [&]() -> uint32_t {
|
||||
uint32_t val;
|
||||
memcpy(&val, &buffer[offset], sizeof(uint32_t));
|
||||
offset += sizeof(uint32_t);
|
||||
return val;
|
||||
};
|
||||
|
||||
data.custRev = readU32();
|
||||
data.mtcConf = readU32();
|
||||
data.commonCpuBoostClock = readU32();
|
||||
data.commonEmcMemVolt = readU32();
|
||||
data.eristaCpuMaxVolt = readU32();
|
||||
data.eristaEmcMaxClock = readU32();
|
||||
data.marikoCpuMaxVolt = readU32();
|
||||
data.marikoEmcMaxClock = readU32();
|
||||
data.marikoEmcVddqVolt = readU32();
|
||||
data.marikoCpuUV = readU32();
|
||||
data.marikoGpuUV = readU32();
|
||||
data.eristaCpuUV = readU32();
|
||||
data.eristaGpuUV = readU32();
|
||||
data.enableMarikoGpuUnsafeFreqs = readU32();
|
||||
data.enableEristaGpuUnsafeFreqs = readU32();
|
||||
data.enableMarikoCpuUnsafeFreqs = readU32();
|
||||
data.enableEristaCpuUnsafeFreqs = readU32();
|
||||
data.commonGpuVoltOffset = readU32();
|
||||
data.marikoEmcDvbShift = readU32();
|
||||
|
||||
// Memory timings
|
||||
data.t1_tRCD = readU32();
|
||||
data.t2_tRP = readU32();
|
||||
data.t3_tRAS = readU32();
|
||||
data.t4_tRRD = readU32();
|
||||
data.t5_tRFC = readU32();
|
||||
data.t6_tRTW = readU32();
|
||||
data.t7_tWTR = readU32();
|
||||
data.t8_tREFI = readU32();
|
||||
data.mem_burst_latency = readU32();
|
||||
|
||||
// Additional voltages
|
||||
data.marikoCpuVmin = readU32();
|
||||
data.eristaGpuVmin = readU32();
|
||||
data.marikoGpuVmin = readU32();
|
||||
data.marikoGpuVmax = readU32();
|
||||
|
||||
// GPU voltages Mariko
|
||||
data.g_volt_76800 = readU32();
|
||||
data.g_volt_153600 = readU32();
|
||||
data.g_volt_230400 = readU32();
|
||||
data.g_volt_307200 = readU32();
|
||||
data.g_volt_384000 = readU32();
|
||||
data.g_volt_460800 = readU32();
|
||||
data.g_volt_537600 = readU32();
|
||||
data.g_volt_614400 = readU32();
|
||||
data.g_volt_691200 = readU32();
|
||||
data.g_volt_768000 = readU32();
|
||||
data.g_volt_844800 = readU32();
|
||||
data.g_volt_921600 = readU32();
|
||||
data.g_volt_998400 = readU32();
|
||||
data.g_volt_1075200 = readU32();
|
||||
data.g_volt_1152000 = readU32();
|
||||
data.g_volt_1228800 = readU32();
|
||||
data.g_volt_1267200 = readU32();
|
||||
data.g_volt_1305600 = readU32();
|
||||
data.g_volt_1344000 = readU32();
|
||||
data.g_volt_1382400 = readU32();
|
||||
data.g_volt_1420800 = readU32();
|
||||
data.g_volt_1459200 = readU32();
|
||||
data.g_volt_1497600 = readU32();
|
||||
data.g_volt_1536000 = readU32();
|
||||
|
||||
// GPU voltages Erista
|
||||
data.g_volt_e_76800 = readU32();
|
||||
data.g_volt_e_153600 = readU32();
|
||||
data.g_volt_e_230400 = readU32();
|
||||
data.g_volt_e_307200 = readU32();
|
||||
data.g_volt_e_384000 = readU32();
|
||||
data.g_volt_e_460800 = readU32();
|
||||
data.g_volt_e_537600 = readU32();
|
||||
data.g_volt_e_614400 = readU32();
|
||||
data.g_volt_e_691200 = readU32();
|
||||
data.g_volt_e_768000 = readU32();
|
||||
data.g_volt_e_844800 = readU32();
|
||||
data.g_volt_e_921600 = readU32();
|
||||
data.g_volt_e_998400 = readU32();
|
||||
data.g_volt_e_1075200 = readU32();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KipHandler::writeKip() {
|
||||
std::fstream file(kipPath, std::ios::in | std::ios::out | std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read entire file
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<uint8_t> buffer(fileSize);
|
||||
file.read(reinterpret_cast<char*>(buffer.data()), fileSize);
|
||||
|
||||
// Find CUST magic
|
||||
size_t magicPos = 0;
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < fileSize - 4; i++) {
|
||||
if (memcmp(&buffer[i], MAGIC, 4) == 0) {
|
||||
magicPos = i + 4;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write structure
|
||||
size_t offset = magicPos;
|
||||
auto writeU32 = [&](uint32_t val) {
|
||||
memcpy(&buffer[offset], &val, sizeof(uint32_t));
|
||||
offset += sizeof(uint32_t);
|
||||
};
|
||||
|
||||
writeU32(data.custRev);
|
||||
writeU32(data.mtcConf);
|
||||
writeU32(data.commonCpuBoostClock);
|
||||
writeU32(data.commonEmcMemVolt);
|
||||
writeU32(data.eristaCpuMaxVolt);
|
||||
writeU32(data.eristaEmcMaxClock);
|
||||
writeU32(data.marikoCpuMaxVolt);
|
||||
writeU32(data.marikoEmcMaxClock);
|
||||
writeU32(data.marikoEmcVddqVolt);
|
||||
writeU32(data.marikoCpuUV);
|
||||
writeU32(data.marikoGpuUV);
|
||||
writeU32(data.eristaCpuUV);
|
||||
writeU32(data.eristaGpuUV);
|
||||
writeU32(data.enableMarikoGpuUnsafeFreqs);
|
||||
writeU32(data.enableEristaGpuUnsafeFreqs);
|
||||
writeU32(data.enableMarikoCpuUnsafeFreqs);
|
||||
writeU32(data.enableEristaCpuUnsafeFreqs);
|
||||
writeU32(data.commonGpuVoltOffset);
|
||||
writeU32(data.marikoEmcDvbShift);
|
||||
|
||||
// Memory timings
|
||||
writeU32(data.t1_tRCD);
|
||||
writeU32(data.t2_tRP);
|
||||
writeU32(data.t3_tRAS);
|
||||
writeU32(data.t4_tRRD);
|
||||
writeU32(data.t5_tRFC);
|
||||
writeU32(data.t6_tRTW);
|
||||
writeU32(data.t7_tWTR);
|
||||
writeU32(data.t8_tREFI);
|
||||
writeU32(data.mem_burst_latency);
|
||||
|
||||
// Additional voltages
|
||||
writeU32(data.marikoCpuVmin);
|
||||
writeU32(data.eristaGpuVmin);
|
||||
writeU32(data.marikoGpuVmin);
|
||||
writeU32(data.marikoGpuVmax);
|
||||
|
||||
// GPU voltages Mariko
|
||||
writeU32(data.g_volt_76800);
|
||||
writeU32(data.g_volt_153600);
|
||||
writeU32(data.g_volt_230400);
|
||||
writeU32(data.g_volt_307200);
|
||||
writeU32(data.g_volt_384000);
|
||||
writeU32(data.g_volt_460800);
|
||||
writeU32(data.g_volt_537600);
|
||||
writeU32(data.g_volt_614400);
|
||||
writeU32(data.g_volt_691200);
|
||||
writeU32(data.g_volt_768000);
|
||||
writeU32(data.g_volt_844800);
|
||||
writeU32(data.g_volt_921600);
|
||||
writeU32(data.g_volt_998400);
|
||||
writeU32(data.g_volt_1075200);
|
||||
writeU32(data.g_volt_1152000);
|
||||
writeU32(data.g_volt_1228800);
|
||||
writeU32(data.g_volt_1267200);
|
||||
writeU32(data.g_volt_1305600);
|
||||
writeU32(data.g_volt_1344000);
|
||||
writeU32(data.g_volt_1382400);
|
||||
writeU32(data.g_volt_1420800);
|
||||
writeU32(data.g_volt_1459200);
|
||||
writeU32(data.g_volt_1497600);
|
||||
writeU32(data.g_volt_1536000);
|
||||
|
||||
// GPU voltages Erista
|
||||
writeU32(data.g_volt_e_76800);
|
||||
writeU32(data.g_volt_e_153600);
|
||||
writeU32(data.g_volt_e_230400);
|
||||
writeU32(data.g_volt_e_307200);
|
||||
writeU32(data.g_volt_e_384000);
|
||||
writeU32(data.g_volt_e_460800);
|
||||
writeU32(data.g_volt_e_537600);
|
||||
writeU32(data.g_volt_e_614400);
|
||||
writeU32(data.g_volt_e_691200);
|
||||
writeU32(data.g_volt_e_768000);
|
||||
writeU32(data.g_volt_e_844800);
|
||||
writeU32(data.g_volt_e_921600);
|
||||
writeU32(data.g_volt_e_998400);
|
||||
writeU32(data.g_volt_e_1075200);
|
||||
|
||||
// Write back to file
|
||||
file.seekp(0, std::ios::beg);
|
||||
file.write(reinterpret_cast<char*>(buffer.data()), fileSize);
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
108
Source/OnDeviceConfig/source/main.cpp
Normal file
108
Source/OnDeviceConfig/source/main.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* HOC Configurator - Nintendo Switch Homebrew
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*
|
||||
* 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>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <algorithm>
|
||||
#include "kip_handler.hpp"
|
||||
#include "ui.hpp"
|
||||
#include "config.hpp"
|
||||
#include "defaults.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Initialize services
|
||||
socketInitializeDefault();
|
||||
nxlinkStdio();
|
||||
|
||||
consoleInit(NULL);
|
||||
|
||||
// Configure input
|
||||
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||
PadState pad;
|
||||
padInitializeDefault(&pad);
|
||||
|
||||
// Initialize configuration
|
||||
Config config;
|
||||
config.loadConfig();
|
||||
|
||||
// Initialize KIP handler
|
||||
KipHandler* kipHandler = new KipHandler(config.kipPath);
|
||||
|
||||
// Initialize UI
|
||||
UI ui;
|
||||
ui.setKipPath(config.kipPath);
|
||||
ui.setKipHandler(kipHandler);
|
||||
ui.setAutoSave(config.autoSave);
|
||||
|
||||
// Check if KIP exists and load it
|
||||
if (config.checkKipExists()) {
|
||||
if (kipHandler->readKip()) {
|
||||
ui.setStatus("KIP loaded successfully from " + config.kipPath);
|
||||
ui.setKipLoaded(true);
|
||||
} else {
|
||||
ui.setStatus("ERROR: Failed to parse KIP file!");
|
||||
ui.setKipLoaded(false);
|
||||
}
|
||||
} else if (config.checkAtmosphereExists()) {
|
||||
ui.setStatus("Atmosphere found, but KIP not found at: " + config.kipPath);
|
||||
ui.setKipLoaded(false);
|
||||
} else {
|
||||
ui.setStatus("ERROR: Atmosphere not detected! Is your SD card mounted?");
|
||||
ui.setKipLoaded(false);
|
||||
}
|
||||
|
||||
bool running = true;
|
||||
u64 kDownOld = 0;
|
||||
int frameCounter = 0;
|
||||
const int FRAME_DELAY = 3; // Add input delay for better responsiveness
|
||||
|
||||
while (running && appletMainLoop()) {
|
||||
padUpdate(&pad);
|
||||
u64 kDown = padGetButtonsDown(&pad);
|
||||
|
||||
// Exit on Plus button
|
||||
if (kDown & HidNpadButton_Plus) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Process input with debouncing and frame delay
|
||||
if (kDown && kDown != kDownOld && frameCounter >= FRAME_DELAY) {
|
||||
ui.handleInput(kDown);
|
||||
frameCounter = 0;
|
||||
}
|
||||
|
||||
// Render UI
|
||||
ui.render();
|
||||
consoleUpdate(NULL);
|
||||
|
||||
kDownOld = kDown;
|
||||
frameCounter++;
|
||||
|
||||
// Frame limiter - 30 FPS
|
||||
svcSleepThread(33333333); // ~33ms
|
||||
}
|
||||
|
||||
// Save config before exit
|
||||
config.autoSave = ui.isAutoSaveEnabled();
|
||||
config.kipPath = ui.getKipPath();
|
||||
config.saveConfig();
|
||||
|
||||
// Cleanup
|
||||
delete kipHandler;
|
||||
|
||||
consoleExit(NULL);
|
||||
socketExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
552
Source/OnDeviceConfig/source/ui.cpp
Normal file
552
Source/OnDeviceConfig/source/ui.cpp
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* HOC Configurator - Complete UI Implementation
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "kip_handler.hpp"
|
||||
#include "value_editor.hpp"
|
||||
#include "constants.hpp"
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
UI::UI() : currentState(MenuState::MAIN), selectedIndex(0), scrollOffset(0),
|
||||
kipLoaded(false), autoSave(false), kipHandler(nullptr), editor(nullptr) {
|
||||
statusMessage = "Welcome to HOC Configurator";
|
||||
editor = new ValueEditor();
|
||||
}
|
||||
|
||||
UI::~UI() {
|
||||
if (editor) delete editor;
|
||||
}
|
||||
|
||||
void UI::drawHeader() {
|
||||
printf("\x1b[2J\x1b[1;1H");
|
||||
printf("\x1b[47;30m");
|
||||
printf("================================================================================\n");
|
||||
printf(" HOC Configurator v%s | Made by Dominatorul \n", Constants::APP_VERSION);
|
||||
printf("================================================================================\n");
|
||||
printf("\x1b[0m");
|
||||
}
|
||||
|
||||
void UI::drawFooter() {
|
||||
printf("\x1b[42;1H");
|
||||
printf("\x1b[47;30m");
|
||||
printf("================================================================================\n");
|
||||
std::string truncStatus = statusMessage;
|
||||
if (truncStatus.length() > 50) {
|
||||
truncStatus = truncStatus.substr(0, 47) + "...";
|
||||
}
|
||||
printf(" [A] Select [B] Back [+] Exit | %s\n", truncStatus.c_str());
|
||||
printf("================================================================================\n");
|
||||
printf("\x1b[0m");
|
||||
}
|
||||
|
||||
void UI::drawMenuItem(const std::string& text, bool selected, int y) {
|
||||
printf("\x1b[%d;1H", y);
|
||||
std::string displayText = text;
|
||||
if (displayText.length() > 74) {
|
||||
displayText = displayText.substr(0, 71) + "...";
|
||||
}
|
||||
if (selected) {
|
||||
printf("\x1b[44;37m > %-76s\x1b[0m\n", displayText.c_str());
|
||||
} else {
|
||||
printf(" %-76s\n", displayText.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void UI::drawText(const std::string& text, int x, int y) {
|
||||
printf("\x1b[%d;%dH%s", y, x, text.c_str());
|
||||
}
|
||||
|
||||
void UI::showValueEditor(const std::string& title, EditorType type, int currentValue,
|
||||
std::function<void(int)> callback, const std::vector<std::string>& options,
|
||||
int min, int max, int step) {
|
||||
if (!editor) return;
|
||||
EditorConfig cfg;
|
||||
cfg.title = title;
|
||||
cfg.type = type;
|
||||
cfg.currentValue = currentValue;
|
||||
cfg.minValue = min;
|
||||
cfg.maxValue = max;
|
||||
cfg.step = step;
|
||||
cfg.options = options;
|
||||
cfg.onValueChange = callback;
|
||||
editor->show(cfg);
|
||||
}
|
||||
|
||||
void UI::renderMainMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- Main Menu -------------------------------------------------------------------+\n");
|
||||
std::vector<std::string> menuItems = {
|
||||
"GPU Settings", "CPU Settings", "RAM Settings",
|
||||
"Misc Settings", "Settings", "About"
|
||||
};
|
||||
int startY = 7;
|
||||
for (size_t i = 0; i < menuItems.size(); i++) {
|
||||
drawMenuItem(menuItems[i], (int)i == selectedIndex, startY + (int)i);
|
||||
}
|
||||
printf("\x1b[%d;1H", startY + (int)menuItems.size() + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
printf("\n");
|
||||
printf(" KIP Path: %s\n", kipPath.c_str());
|
||||
printf(" KIP Status: %s\n", kipLoaded ? "\x1b[32mLoaded\x1b[0m" : "\x1b[31mNot Loaded\x1b[0m");
|
||||
printf(" Auto-save: %s\n", autoSave ? "\x1b[32mEnabled\x1b[0m" : "\x1b[33mDisabled\x1b[0m");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderGPUMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- GPU Settings ----------------------------------------------------------------+\n");
|
||||
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
printf("\n \x1b[31mNo KIP loaded! Go to Settings to load a KIP file.\x1b[0m\n\n");
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
return;
|
||||
}
|
||||
|
||||
auto& data = kipHandler->getData();
|
||||
std::vector<std::string> menuItems = {
|
||||
"Enable Unsafe Frequencies (Mariko): " + std::string(data.enableMarikoGpuUnsafeFreqs ? "ON" : "OFF"),
|
||||
"Enable Unsafe Frequencies (Erista): " + std::string(data.enableEristaGpuUnsafeFreqs ? "ON" : "OFF"),
|
||||
"Mariko GPU vMin: " + (data.marikoGpuVmin == 0 ? "Disabled" : std::to_string(data.marikoGpuVmin) + "mV"),
|
||||
"Mariko GPU vMax: " + (data.marikoGpuVmax == 0 ? "Disabled" : std::to_string(data.marikoGpuVmax) + "mV"),
|
||||
"Erista GPU vMin: " + (data.eristaGpuVmin == 0 ? "Disabled" : std::to_string(data.eristaGpuVmin) + "mV"),
|
||||
"Mariko Undervolt: UV" + std::to_string(data.marikoGpuUV),
|
||||
"Erista Undervolt: UV" + std::to_string(data.eristaGpuUV),
|
||||
"GPU Volt Offset: " + (data.commonGpuVoltOffset == 0 ? "Disabled" : "-" + std::to_string(data.commonGpuVoltOffset) + "mV")
|
||||
};
|
||||
|
||||
int startY = 7;
|
||||
for (size_t i = 0; i < menuItems.size(); i++) {
|
||||
drawMenuItem(menuItems[i], (int)i == selectedIndex, startY + (int)i);
|
||||
}
|
||||
printf("\x1b[%d;1H", startY + (int)menuItems.size() + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderCPUMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- CPU Settings ----------------------------------------------------------------+\n");
|
||||
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
printf("\n \x1b[31mNo KIP loaded! Go to Settings to load a KIP file.\x1b[0m\n\n");
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
return;
|
||||
}
|
||||
|
||||
auto& data = kipHandler->getData();
|
||||
std::vector<std::string> menuItems = {
|
||||
"Enable Unsafe Frequencies (Mariko): " + std::string(data.enableMarikoCpuUnsafeFreqs ? "ON" : "OFF"),
|
||||
"Enable Unsafe Frequencies (Erista): " + std::string(data.enableEristaCpuUnsafeFreqs ? "ON" : "OFF"),
|
||||
"CPU Boost Frequency: " + std::to_string(data.commonCpuBoostClock / 1000) + " MHz",
|
||||
"Mariko CPU vMin: " + (data.marikoCpuVmin == 0 ? "Default" : std::to_string(data.marikoCpuVmin) + "mV"),
|
||||
"Mariko CPU vMax: " + (data.marikoCpuMaxVolt == 0 ? "Disabled" : std::to_string(data.marikoCpuMaxVolt) + "mV"),
|
||||
"Erista CPU vMax: " + (data.eristaCpuMaxVolt == 0 ? "Disabled" : std::to_string(data.eristaCpuMaxVolt) + "mV"),
|
||||
"Mariko CPU Undervolt: UV" + std::to_string(data.marikoCpuUV),
|
||||
"Erista CPU Undervolt: UV" + std::to_string(data.eristaCpuUV)
|
||||
};
|
||||
|
||||
int startY = 7;
|
||||
for (size_t i = 0; i < menuItems.size(); i++) {
|
||||
drawMenuItem(menuItems[i], (int)i == selectedIndex, startY + (int)i);
|
||||
}
|
||||
printf("\x1b[%d;1H", startY + (int)menuItems.size() + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderRAMMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- RAM Settings ----------------------------------------------------------------+\n");
|
||||
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
printf("\n \x1b[31mNo KIP loaded! Go to Settings to load a KIP file.\x1b[0m\n\n");
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
return;
|
||||
}
|
||||
|
||||
auto& data = kipHandler->getData();
|
||||
std::vector<std::string> menuItems = {
|
||||
"RAM Max Frequency (Mariko): " + std::to_string(data.marikoEmcMaxClock / 1000) + " MHz",
|
||||
"RAM Max Frequency (Erista): " + std::to_string(data.eristaEmcMaxClock / 1000) + " MHz",
|
||||
"RAM Primary Voltage (VDD2): " + std::to_string(data.commonEmcMemVolt / 1000) + " mV",
|
||||
"RAM Secondary Voltage (VDDQ): " + std::to_string(data.marikoEmcVddqVolt / 1000) + " mV",
|
||||
"SoC DVB Shift: " + std::to_string(data.marikoEmcDvbShift),
|
||||
"Base Latency: " + std::to_string(data.mem_burst_latency),
|
||||
"t1 tRCD: " + std::to_string(data.t1_tRCD),
|
||||
"t2 tRP: " + std::to_string(data.t2_tRP),
|
||||
"t3 tRAS: " + std::to_string(data.t3_tRAS),
|
||||
"t4 tRRD: " + std::to_string(data.t4_tRRD),
|
||||
"t5 tRFC: " + std::to_string(data.t5_tRFC)
|
||||
};
|
||||
|
||||
int startY = 7;
|
||||
int visibleStart = scrollOffset;
|
||||
int visibleEnd = std::min((int)menuItems.size(), scrollOffset + MAX_VISIBLE_ITEMS);
|
||||
|
||||
for (int i = visibleStart; i < visibleEnd; i++) {
|
||||
drawMenuItem(menuItems[i], i == selectedIndex, startY + (i - visibleStart));
|
||||
}
|
||||
|
||||
printf("\x1b[%d;1H", startY + (visibleEnd - visibleStart) + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderMiscMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- Misc Settings ---------------------------------------------------------------+\n");
|
||||
std::vector<std::string> menuItems = {
|
||||
"Optimize Fan Curve (V1 Erista)",
|
||||
"Optimize Fan Curve (V2 Mariko)",
|
||||
"Optimize Fan Curve (Lite)",
|
||||
"Optimize Fan Curve (OLED)",
|
||||
"Reset Fan Curve to Default",
|
||||
"Sleep Mode Battery Fix: Toggle",
|
||||
"Battery Charge Limit \x1b[31m(DANGEROUS)\x1b[0m"
|
||||
};
|
||||
|
||||
int startY = 7;
|
||||
for (size_t i = 0; i < menuItems.size(); i++) {
|
||||
drawMenuItem(menuItems[i], (int)i == selectedIndex, startY + (int)i);
|
||||
}
|
||||
printf("\x1b[%d;1H", startY + (int)menuItems.size() + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderAboutMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- About -----------------------------------------------------------------------+\n");
|
||||
printf("| |\n");
|
||||
printf("| Horizon OC Configurator v%-50s |\n", Constants::APP_VERSION);
|
||||
printf("| Nintendo Switch Homebrew Edition |\n");
|
||||
printf("| |\n");
|
||||
printf("| Contributors: |\n");
|
||||
printf("| * Dominatorul - Homebrew port and development |\n");
|
||||
printf("| * Souldbminer - Original PC configurator |\n");
|
||||
printf("| * Lightos - L4T timings research |\n");
|
||||
printf("| * Lightos, Samybigio, Flopsider - Testing |\n");
|
||||
printf("| |\n");
|
||||
printf("| License: GNU General Public License v2.0 or later |\n");
|
||||
printf("| Source: github.com/souldbminersmwc/Horizon-OC |\n");
|
||||
printf("| |\n");
|
||||
printf("| \x1b[33mWARNING: Improper overclocking can damage your console!\x1b[0m |\n");
|
||||
printf("| Use at your own risk. Always test stability before daily use. |\n");
|
||||
printf("| |\n");
|
||||
printf("+------------------------------------------------------------------------------+\n");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::renderSettingsMenu() {
|
||||
drawHeader();
|
||||
printf("\x1b[5;1H");
|
||||
printf("+- Settings --------------------------------------------------------------------+\n");
|
||||
std::vector<std::string> menuItems = {
|
||||
"Toggle Auto-save: " + std::string(autoSave ? "\x1b[32mON\x1b[0m" : "\x1b[33mOFF\x1b[0m"),
|
||||
"Save KIP Now",
|
||||
"Reload KIP",
|
||||
"Back to Main Menu"
|
||||
};
|
||||
|
||||
int startY = 7;
|
||||
for (size_t i = 0; i < menuItems.size(); i++) {
|
||||
drawMenuItem(menuItems[i], (int)i == selectedIndex, startY + (int)i);
|
||||
}
|
||||
printf("\x1b[%d;1H", startY + (int)menuItems.size() + 1);
|
||||
printf("+-------------------------------------------------------------------------------+\n");
|
||||
printf("\n");
|
||||
printf(" Current KIP Path: %s\n", kipPath.c_str());
|
||||
printf(" Auto-save Status: %s\n", autoSave ? "\x1b[32mEnabled\x1b[0m" : "\x1b[33mDisabled\x1b[0m");
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
void UI::render() {
|
||||
if (editor && editor->isActive()) {
|
||||
editor->render();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentState) {
|
||||
case MenuState::MAIN: renderMainMenu(); break;
|
||||
case MenuState::GPU: renderGPUMenu(); break;
|
||||
case MenuState::CPU: renderCPUMenu(); break;
|
||||
case MenuState::RAM: renderRAMMenu(); break;
|
||||
case MenuState::MISC: renderMiscMenu(); break;
|
||||
case MenuState::ABOUT: renderAboutMenu(); break;
|
||||
case MenuState::SETTINGS: renderSettingsMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleInput(u64 kDown) {
|
||||
if (editor && editor->isActive()) {
|
||||
editor->handleInput(kDown);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentState) {
|
||||
case MenuState::MAIN: handleMainMenuInput(kDown); break;
|
||||
case MenuState::GPU: handleGPUMenuInput(kDown); break;
|
||||
case MenuState::CPU: handleCPUMenuInput(kDown); break;
|
||||
case MenuState::RAM: handleRAMMenuInput(kDown); break;
|
||||
case MenuState::MISC: handleMiscMenuInput(kDown); break;
|
||||
case MenuState::ABOUT: handleAboutMenuInput(kDown); break;
|
||||
case MenuState::SETTINGS: handleSettingsMenuInput(kDown); break;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleMainMenuInput(u64 kDown) {
|
||||
if (kDown & HidNpadButton_Down) selectedIndex = (selectedIndex + 1) % 6;
|
||||
if (kDown & HidNpadButton_Up) selectedIndex = (selectedIndex - 1 + 6) % 6;
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
switch (selectedIndex) {
|
||||
case 0: currentState = MenuState::GPU; break;
|
||||
case 1: currentState = MenuState::CPU; break;
|
||||
case 2: currentState = MenuState::RAM; break;
|
||||
case 3: currentState = MenuState::MISC; break;
|
||||
case 4: currentState = MenuState::SETTINGS; break;
|
||||
case 5: currentState = MenuState::ABOUT; break;
|
||||
}
|
||||
selectedIndex = 0;
|
||||
scrollOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleGPUMenuInput(u64 kDown) {
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int maxItems = 8;
|
||||
if (kDown & HidNpadButton_Down) selectedIndex = (selectedIndex + 1) % maxItems;
|
||||
if (kDown & HidNpadButton_Up) selectedIndex = (selectedIndex - 1 + maxItems) % maxItems;
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
auto& data = kipHandler->getData();
|
||||
|
||||
switch (selectedIndex) {
|
||||
case 0: { // Mariko GPU Unsafe Freqs
|
||||
std::vector<std::string> opts = {"Disabled (0)", "Enabled (1)"};
|
||||
showValueEditor("Enable Unsafe GPU Frequencies (Mariko)", EditorType::LIST,
|
||||
data.enableMarikoGpuUnsafeFreqs,
|
||||
[this, &data](int val) {
|
||||
data.enableMarikoGpuUnsafeFreqs = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Mariko GPU unsafe: " + std::string(val ? "ENABLED" : "DISABLED"));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
case 1: { // Erista GPU Unsafe Freqs
|
||||
std::vector<std::string> opts = {"Disabled (0)", "Enabled (1)"};
|
||||
showValueEditor("Enable Unsafe GPU Frequencies (Erista)", EditorType::LIST,
|
||||
data.enableEristaGpuUnsafeFreqs,
|
||||
[this, &data](int val) {
|
||||
data.enableEristaGpuUnsafeFreqs = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Erista GPU unsafe: " + std::string(val ? "ENABLED" : "DISABLED"));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
case 5: { // Mariko GPU UV
|
||||
std::vector<std::string> opts = {"UV0 (No Table)", "UV1 (Regular)", "UV2 (High)", "UV3 (Custom)"};
|
||||
showValueEditor("Mariko GPU Undervolt Mode", EditorType::LIST,
|
||||
data.marikoGpuUV,
|
||||
[this, &data](int val) {
|
||||
data.marikoGpuUV = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Mariko GPU UV mode set to UV" + std::to_string(val));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
case 6: { // Erista GPU UV
|
||||
std::vector<std::string> opts = {"UV0 (No Table)", "UV1 (Regular)", "UV2 (High)", "UV3 (Custom)"};
|
||||
showValueEditor("Erista GPU Undervolt Mode", EditorType::LIST,
|
||||
data.eristaGpuUV,
|
||||
[this, &data](int val) {
|
||||
data.eristaGpuUV = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Erista GPU UV mode set to UV" + std::to_string(val));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
setStatus("Feature in development");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleCPUMenuInput(u64 kDown) {
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int maxItems = 8;
|
||||
if (kDown & HidNpadButton_Down) selectedIndex = (selectedIndex + 1) % maxItems;
|
||||
if (kDown & HidNpadButton_Up) selectedIndex = (selectedIndex - 1 + maxItems) % maxItems;
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
auto& data = kipHandler->getData();
|
||||
|
||||
switch (selectedIndex) {
|
||||
case 0: { // Mariko CPU Unsafe
|
||||
std::vector<std::string> opts = {"Disabled (0)", "Enabled (1)"};
|
||||
showValueEditor("Enable Unsafe CPU Frequencies (Mariko)", EditorType::LIST,
|
||||
data.enableMarikoCpuUnsafeFreqs,
|
||||
[this, &data](int val) {
|
||||
data.enableMarikoCpuUnsafeFreqs = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Mariko CPU unsafe: " + std::string(val ? "ENABLED" : "DISABLED"));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
case 1: { // Erista CPU Unsafe
|
||||
std::vector<std::string> opts = {"Disabled (0)", "Enabled (1)"};
|
||||
showValueEditor("Enable Unsafe CPU Frequencies (Erista)", EditorType::LIST,
|
||||
data.enableEristaCpuUnsafeFreqs,
|
||||
[this, &data](int val) {
|
||||
data.enableEristaCpuUnsafeFreqs = val;
|
||||
if (autoSave && kipHandler) kipHandler->writeKip();
|
||||
setStatus("Erista CPU unsafe: " + std::string(val ? "ENABLED" : "DISABLED"));
|
||||
}, opts);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
setStatus("Feature in development");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleRAMMenuInput(u64 kDown) {
|
||||
if (!kipHandler || !kipLoaded) {
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int maxItems = 11;
|
||||
|
||||
if (kDown & HidNpadButton_Down) {
|
||||
selectedIndex++;
|
||||
if (selectedIndex >= maxItems) selectedIndex = 0;
|
||||
if (selectedIndex >= scrollOffset + MAX_VISIBLE_ITEMS) {
|
||||
scrollOffset = selectedIndex - MAX_VISIBLE_ITEMS + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_Up) {
|
||||
selectedIndex--;
|
||||
if (selectedIndex < 0) selectedIndex = maxItems - 1;
|
||||
if (selectedIndex < scrollOffset) scrollOffset = selectedIndex;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
scrollOffset = 0;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
setStatus("RAM setting (in development)");
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleMiscMenuInput(u64 kDown) {
|
||||
int maxItems = 7;
|
||||
if (kDown & HidNpadButton_Down) selectedIndex = (selectedIndex + 1) % maxItems;
|
||||
if (kDown & HidNpadButton_Up) selectedIndex = (selectedIndex - 1 + maxItems) % maxItems;
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
setStatus("Misc feature (in development)");
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleAboutMenuInput(u64 kDown) {
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UI::handleSettingsMenuInput(u64 kDown) {
|
||||
int maxItems = 4;
|
||||
if (kDown & HidNpadButton_Down) selectedIndex = (selectedIndex + 1) % maxItems;
|
||||
if (kDown & HidNpadButton_Up) selectedIndex = (selectedIndex - 1 + maxItems) % maxItems;
|
||||
if (kDown & HidNpadButton_B) {
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
switch (selectedIndex) {
|
||||
case 0: // Toggle Auto-save
|
||||
autoSave = !autoSave;
|
||||
setStatus(autoSave ? "Auto-save ENABLED" : "Auto-save DISABLED");
|
||||
break;
|
||||
case 1: // Save KIP Now
|
||||
if (kipHandler && kipLoaded) {
|
||||
if (kipHandler->writeKip()) {
|
||||
setStatus("KIP saved successfully!");
|
||||
} else {
|
||||
setStatus("ERROR: Failed to save KIP!");
|
||||
}
|
||||
} else {
|
||||
setStatus("ERROR: No KIP loaded!");
|
||||
}
|
||||
break;
|
||||
case 2: // Reload KIP
|
||||
if (kipHandler) {
|
||||
if (kipHandler->readKip()) {
|
||||
setStatus("KIP reloaded successfully!");
|
||||
kipLoaded = true;
|
||||
} else {
|
||||
setStatus("ERROR: Failed to reload KIP!");
|
||||
kipLoaded = false;
|
||||
}
|
||||
} else {
|
||||
setStatus("ERROR: No KIP handler initialized!");
|
||||
}
|
||||
break;
|
||||
case 3: // Back to Main
|
||||
currentState = MenuState::MAIN;
|
||||
selectedIndex = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
134
Source/OnDeviceConfig/source/value_editor.cpp
Normal file
134
Source/OnDeviceConfig/source/value_editor.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* HOC Configurator - Value Editor Implementation
|
||||
* Copyright (C) Dominatorul, Souldbminer
|
||||
*/
|
||||
|
||||
#include "value_editor.hpp"
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
|
||||
ValueEditor::ValueEditor() : selectedValue(0), active(false) {}
|
||||
|
||||
void ValueEditor::show(const EditorConfig& cfg) {
|
||||
config = cfg;
|
||||
selectedValue = cfg.currentValue;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void ValueEditor::hide() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
void ValueEditor::handleInput(u64 kDown) {
|
||||
if (!active) return;
|
||||
|
||||
if (kDown & HidNpadButton_B) {
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (kDown & HidNpadButton_A) {
|
||||
if (config.onValueChange) {
|
||||
config.onValueChange(selectedValue);
|
||||
}
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (config.type) {
|
||||
case EditorType::TOGGLE:
|
||||
if (kDown & (HidNpadButton_Left | HidNpadButton_Right |
|
||||
HidNpadButton_Up | HidNpadButton_Down)) {
|
||||
selectedValue = !selectedValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case EditorType::LIST:
|
||||
case EditorType::FREQUENCY:
|
||||
case EditorType::VOLTAGE:
|
||||
if (kDown & HidNpadButton_Down) {
|
||||
selectedValue++;
|
||||
if (selectedValue >= (int)config.options.size()) {
|
||||
selectedValue = 0;
|
||||
}
|
||||
}
|
||||
if (kDown & HidNpadButton_Up) {
|
||||
selectedValue--;
|
||||
if (selectedValue < 0) {
|
||||
selectedValue = config.options.size() - 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EditorType::SLIDER:
|
||||
if (kDown & HidNpadButton_Right) {
|
||||
selectedValue = std::min(selectedValue + config.step, config.maxValue);
|
||||
}
|
||||
if (kDown & HidNpadButton_Left) {
|
||||
selectedValue = std::max(selectedValue - config.step, config.minValue);
|
||||
}
|
||||
if (kDown & HidNpadButton_Down) {
|
||||
selectedValue = std::max(selectedValue - config.step * 5, config.minValue);
|
||||
}
|
||||
if (kDown & HidNpadButton_Up) {
|
||||
selectedValue = std::min(selectedValue + config.step * 5, config.maxValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ValueEditor::render() {
|
||||
if (!active) return;
|
||||
|
||||
// Draw editor overlay
|
||||
printf("\x1b[2J\x1b[1;1H");
|
||||
|
||||
// Header
|
||||
printf("\x1b[47;30m");
|
||||
printf("===============================================================================\n");
|
||||
printf(" %s%-73s \n", config.title.c_str(), "");
|
||||
printf("===============================================================================\n");
|
||||
printf("\x1b[0m");
|
||||
|
||||
printf("\x1b[10;1H");
|
||||
printf("+- Value Editor ----------------------------------------------------------------+\n");
|
||||
printf("| |\n");
|
||||
|
||||
// Display current value based on type
|
||||
switch (config.type) {
|
||||
case EditorType::TOGGLE:
|
||||
printf("| Current: %-66s |\n", selectedValue ? "Enabled (1)" : "Disabled (0)");
|
||||
printf("| |\n");
|
||||
printf("| Use D-Pad to toggle |\n");
|
||||
break;
|
||||
|
||||
case EditorType::LIST:
|
||||
case EditorType::FREQUENCY:
|
||||
case EditorType::VOLTAGE:
|
||||
if (selectedValue >= 0 && selectedValue < (int)config.options.size()) {
|
||||
printf("| Current: %-66s |\n", config.options[selectedValue].c_str());
|
||||
}
|
||||
printf("| |\n");
|
||||
printf("| Use Up/Down to change value |\n");
|
||||
break;
|
||||
|
||||
case EditorType::SLIDER:
|
||||
printf("| Current: %-66d |\n", selectedValue);
|
||||
printf("| |\n");
|
||||
printf("| Left/Right: +/-%d Up/Down: +/-%d |\n",
|
||||
config.step, config.step * 5);
|
||||
printf("| Range: %d - %d%-56s|\n", config.minValue, config.maxValue, "");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("| |\n");
|
||||
printf("+------------------------------------------------------------------------------+\n");
|
||||
|
||||
// Footer
|
||||
printf("\x1b[42;1H");
|
||||
printf("\x1b[47;30m");
|
||||
printf("===============================================================================\n");
|
||||
printf(" [A] Confirm [B] Cancel \n");
|
||||
printf("===============================================================================\n");
|
||||
printf("\x1b[0m");
|
||||
}
|
||||
Reference in New Issue
Block a user