hocclk: optimize kip routines
This commit is contained in:
@@ -34,19 +34,17 @@ namespace kip {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
CustomizeTable table;
|
CustomizeTable table;
|
||||||
FILE* fp;
|
FILE* fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "r+b");
|
||||||
fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "r");
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
notification::writeNotification("Horizon OC\nKip opening failed");
|
notification::writeNotification("Horizon OC\nKip opening failed");
|
||||||
kipAvailable = false;
|
kipAvailable = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
kipAvailable = true;
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
kipAvailable = true;
|
||||||
|
|
||||||
if (!cust_read_and_cache("sdmc:/atmosphere/kips/hoc.kip", &table)) {
|
if (!cust_read_table_f(fp, &table)) {
|
||||||
|
fclose(fp);
|
||||||
fileUtils::LogLine("[kip] Failed to read KIP file");
|
fileUtils::LogLine("[kip] Failed to read KIP file");
|
||||||
notification::writeNotification("Horizon OC\nKip read failed");
|
notification::writeNotification("Horizon OC\nKip read failed");
|
||||||
return;
|
return;
|
||||||
@@ -55,11 +53,13 @@ namespace kip {
|
|||||||
u32 custRev = cust_get_cust_rev(&table);
|
u32 custRev = cust_get_cust_rev(&table);
|
||||||
u32 kipVersion = cust_get_kip_version(&table);
|
u32 kipVersion = cust_get_kip_version(&table);
|
||||||
if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
|
if (custRev < CUST_REV || kipVersion < KIP_VERSION) {
|
||||||
|
fclose(fp);
|
||||||
notification::writeNotification("Horizon OC\nOutdated kip detected!\nPlease update Horizon OC");
|
notification::writeNotification("Horizon OC\nOutdated kip detected!\nPlease update Horizon OC");
|
||||||
fileUtils::LogLine("Cust revision: %u", custRev);
|
fileUtils::LogLine("Cust revision: %u", custRev);
|
||||||
fileUtils::LogLine("Kip version: %u", kipVersion);
|
fileUtils::LogLine("Kip version: %u", kipVersion);
|
||||||
return;
|
return;
|
||||||
} else if (custRev > CUST_REV || kipVersion > KIP_VERSION) {
|
} else if (custRev > CUST_REV || kipVersion > KIP_VERSION) {
|
||||||
|
fclose(fp);
|
||||||
notification::writeNotification("Horizon OC\nOutdated sysmodule detected!\nPlease update Horizon OC");
|
notification::writeNotification("Horizon OC\nOutdated sysmodule detected!\nPlease update Horizon OC");
|
||||||
fileUtils::LogLine("Cust revision: %u", custRev);
|
fileUtils::LogLine("Cust revision: %u", custRev);
|
||||||
fileUtils::LogLine("Kip version: %u", kipVersion);
|
fileUtils::LogLine("Kip version: %u", kipVersion);
|
||||||
@@ -138,10 +138,13 @@ namespace kip {
|
|||||||
CUST_WRITE_FIELD_BATCH(&table, t6_tRTW_fine_tune, config::GetConfigValue(KipConfigValue_t6_tRTW_fine_tune));
|
CUST_WRITE_FIELD_BATCH(&table, t6_tRTW_fine_tune, config::GetConfigValue(KipConfigValue_t6_tRTW_fine_tune));
|
||||||
CUST_WRITE_FIELD_BATCH(&table, t7_tWTR_fine_tune, config::GetConfigValue(KipConfigValue_t7_tWTR_fine_tune));
|
CUST_WRITE_FIELD_BATCH(&table, t7_tWTR_fine_tune, config::GetConfigValue(KipConfigValue_t7_tWTR_fine_tune));
|
||||||
|
|
||||||
if (!cust_write_table("sdmc:/atmosphere/kips/hoc.kip", &table)) {
|
if (!cust_write_table_f(fp, &table)) {
|
||||||
|
fclose(fp);
|
||||||
fileUtils::LogLine("[kip] Failed to write KIP file");
|
fileUtils::LogLine("[kip] Failed to write KIP file");
|
||||||
notification::writeNotification("Horizon OC\nKip write failed");
|
notification::writeNotification("Horizon OC\nKip write failed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
HocClkConfigValueList configValues;
|
HocClkConfigValueList configValues;
|
||||||
config::GetConfigValues(&configValues);
|
config::GetConfigValues(&configValues);
|
||||||
@@ -163,27 +166,26 @@ namespace kip {
|
|||||||
|
|
||||||
void GetKipData()
|
void GetKipData()
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "rb");
|
||||||
fp = fopen("sdmc:/atmosphere/kips/hoc.kip", "r");
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
notification::writeNotification("Horizon OC\nKip opening failed");
|
notification::writeNotification("Horizon OC\nKip opening failed");
|
||||||
kipAvailable = false;
|
kipAvailable = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
kipAvailable = true;
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
kipAvailable = true;
|
||||||
|
|
||||||
HocClkConfigValueList configValues;
|
HocClkConfigValueList configValues;
|
||||||
config::GetConfigValues(&configValues);
|
config::GetConfigValues(&configValues);
|
||||||
|
|
||||||
CustomizeTable table;
|
CustomizeTable table;
|
||||||
if (!cust_read_and_cache("sdmc:/atmosphere/kips/hoc.kip", &table)) {
|
if (!cust_read_table_f(fp, &table)) {
|
||||||
|
fclose(fp);
|
||||||
fileUtils::LogLine("[kip] Failed to read KIP file for GetKipData");
|
fileUtils::LogLine("[kip] Failed to read KIP file for GetKipData");
|
||||||
notification::writeNotification("Horizon OC\nKip read failed");
|
notification::writeNotification("Horizon OC\nKip read failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
// if(cust_get_cust_rev(&table) != CUST_REV) {
|
// if(cust_get_cust_rev(&table) != CUST_REV) {
|
||||||
// notification::writeNotification("Horizon OC\nKip version mismatch\nPlease reinstall Horizon OC");
|
// notification::writeNotification("Horizon OC\nKip version mismatch\nPlease reinstall Horizon OC");
|
||||||
|
|||||||
@@ -128,54 +128,59 @@ namespace kip {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long cachedCustOffset = -1;
|
||||||
|
|
||||||
|
static inline long cust_get_offset(FILE* f) {
|
||||||
|
if (cachedCustOffset >= 0) return cachedCustOffset;
|
||||||
|
long off;
|
||||||
|
if (!cust_find_offset(f, &off)) return -1;
|
||||||
|
cachedCustOffset = off;
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool cust_read_table_f(FILE* f, CustomizeTable* out) {
|
||||||
|
long off = cust_get_offset(f);
|
||||||
|
if (off < 0) return false;
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
|
||||||
|
|
||||||
|
fseek(f, off, SEEK_SET);
|
||||||
|
if (fread(out, 1, sizeof(CustomizeTable), f) != sizeof(CustomizeTable)) return false;
|
||||||
|
|
||||||
|
if (memcmp(out->cust, CUST_MAGIC, CUST_MAGIC_LEN) != 0) {
|
||||||
|
cachedCustOffset = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool cust_write_table_f(FILE* f, const CustomizeTable* in) {
|
||||||
|
long off = cust_get_offset(f);
|
||||||
|
if (off < 0) return false;
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
if (off + (long)sizeof(CustomizeTable) > ftell(f)) return false;
|
||||||
|
|
||||||
|
fseek(f, off, SEEK_SET);
|
||||||
|
bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
|
||||||
|
fflush(f);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool cust_read_table(const char* path, CustomizeTable* out) {
|
static inline bool cust_read_table(const char* path, CustomizeTable* out) {
|
||||||
FILE* f = fopen(path, "rb");
|
FILE* f = fopen(path, "rb");
|
||||||
if (!f) return false;
|
if (!f) return false;
|
||||||
|
bool ok = cust_read_table_f(f, out);
|
||||||
long off;
|
|
||||||
if (!cust_find_offset(f, &off)) {
|
|
||||||
fclose(f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
long size = ftell(f);
|
|
||||||
|
|
||||||
if (off + (long)sizeof(CustomizeTable) > size) {
|
|
||||||
fclose(f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(f, off, SEEK_SET);
|
|
||||||
bool ok = fread(out, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
return ok;
|
||||||
return ok && memcmp(out->cust, CUST_MAGIC, CUST_MAGIC_LEN) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool cust_write_table(const char* path, const CustomizeTable* in) {
|
static inline bool cust_write_table(const char* path, const CustomizeTable* in) {
|
||||||
FILE* f = fopen(path, "r+b");
|
FILE* f = fopen(path, "r+b");
|
||||||
if (!f) return false;
|
if (!f) return false;
|
||||||
|
bool ok = cust_write_table_f(f, in);
|
||||||
long off;
|
|
||||||
if (!cust_find_offset(f, &off)) {
|
|
||||||
fclose(f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
long size = ftell(f);
|
|
||||||
|
|
||||||
if (off + (long)sizeof(CustomizeTable) > size) {
|
|
||||||
fclose(f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(f, off, SEEK_SET);
|
|
||||||
bool ok = fwrite(in, 1, sizeof(CustomizeTable), f) == sizeof(CustomizeTable);
|
|
||||||
fflush(f);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp
vendored
BIN
dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp
vendored
Binary file not shown.
BIN
dist/atmosphere/kips/hoc.kip
vendored
BIN
dist/atmosphere/kips/hoc.kip
vendored
Binary file not shown.
BIN
dist/switch/.overlays/horizon-oc-overlay.ovl
vendored
BIN
dist/switch/.overlays/horizon-oc-overlay.ovl
vendored
Binary file not shown.
Reference in New Issue
Block a user