chore: many changes

This commit is contained in:
souldbminersmwc
2025-10-06 19:18:21 -04:00
parent 4d910c1b39
commit 3bdb6dc23e
31 changed files with 3156 additions and 472 deletions

View 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);
}

View 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);
};

View 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;
}

View 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;
}

View 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;
}
}
}

View 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");
}