mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 15:49:57 -04:00
Read the mods folder the way the setup's tools do, and keep each mod's start state with it.
- A pchtxt file's build id is read as tools/exefs_patches.py reads it: after a UTF-8 BOM and blanks, the last @nsobid line before @stop, a // comment after it left out. A file saved with a BOM or an indented line was taken for another game version although the setup had built it into the game. - A symbolic link or junction to a folder in mods/ is a mod, as the setup's tools see it; it was left out, so the patch sets built for it were never switched on. - A relative mods_dir is under the game's folder, not the folder the game was started from. - A mods folder that cannot be listed is logged instead of showing no mods without a word. - The start state of a mod's switch moves with the mod when the list is reordered, so the ExeFS patches waiting for the rebuild are counted for the right mods. --probe-mods checks each of these. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,10 @@
|
||||
#include "mods.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static int fails;
|
||||
#define CHECK(c, what) do { if (!(c)) { fails++; fprintf(stderr, "FAIL mods: %s\n", what); } } while (0)
|
||||
#define EQ(a, b) ((a) && !strcmp((a), (b)))
|
||||
@@ -23,6 +27,27 @@ static void put(const char *root, const char *rel) {
|
||||
if (slash[1]) plat_file_write(p, "probe", 5);
|
||||
}
|
||||
|
||||
// root/rel as a file holding text.
|
||||
static void put_text(const char *root, const char *rel, const char *text) {
|
||||
put(root, rel);
|
||||
char p[2048];
|
||||
snprintf(p, sizeof p, "%s/%s", root, rel);
|
||||
plat_file_write(p, text, strlen(text));
|
||||
}
|
||||
|
||||
// link (a path) as a symbolic link to the folder target; 0 when the system refuses (Windows without developer mode).
|
||||
static int dir_link(const char *target, const char *link) {
|
||||
#ifdef _WIN32
|
||||
wchar_t t[1024], l[1024];
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, target, -1, t, 1024) || !MultiByteToWideChar(CP_UTF8, 0, link, -1, l, 1024))
|
||||
return 0;
|
||||
return CreateSymbolicLinkW(l, t, SYMBOLIC_LINK_FLAG_DIRECTORY | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) != 0;
|
||||
#else
|
||||
(void)target, (void)link;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int remove_cb(const char *name, int kind, uint64_t size, void *ctx);
|
||||
static void remove_tree(const char *dir) {
|
||||
plat_fs_list(dir, remove_cb, (void *)dir);
|
||||
@@ -33,7 +58,7 @@ static int remove_cb(const char *name, int kind, uint64_t size, void *ctx) {
|
||||
char sub[2048];
|
||||
snprintf(sub, sizeof sub, "%s/%s", (const char *)ctx, name);
|
||||
if (kind == PLAT_FS_DIR) remove_tree(sub);
|
||||
else plat_fs_unlink(sub);
|
||||
else if (kind != PLAT_FS_LINK || plat_fs_rmdir(sub) != PLAT_FS_OK) plat_fs_unlink(sub); // a link: never followed
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -71,23 +96,48 @@ int probe_mods(void) {
|
||||
char ips[160];
|
||||
snprintf(ips, sizeof ips, "M/atmosphere/exefs_patches/x/%s.ips", *mods_main_build_id() ? mods_main_build_id() : "0");
|
||||
put(root, ips);
|
||||
// pchtxt files for main as tools/exefs_patches.py reads them: a BOM and an indented build id line (N); a build id
|
||||
// line with more than hex on it (O) and one after @stop (P) name no build, so another version's
|
||||
const char *bid = *mods_main_build_id() ? mods_main_build_id() : "0";
|
||||
char text[256];
|
||||
snprintf(text, sizeof text, "\xEF\xBB\xBF// a title\r\n @nsobid-%s // main\r\n@enabled\r\n", bid);
|
||||
put_text(root, "N/exefs/bom.pchtxt", text);
|
||||
snprintf(text, sizeof text, "@nsobid-%s v2\n", bid);
|
||||
put_text(root, "O/exefs/junk.pchtxt", text);
|
||||
snprintf(text, sizeof text, "@stop\n@nsobid-%s\n", bid);
|
||||
put_text(root, "P/exefs/stop.pchtxt", text);
|
||||
// a link to a folder outside the mods folder is a mod (Q); left out when the system cannot make one
|
||||
char outside[1100], link[1100];
|
||||
snprintf(outside, sizeof outside, "%s-linked", root);
|
||||
remove_tree(outside);
|
||||
put(outside, "romfs/q.bin");
|
||||
snprintf(link, sizeof link, "%s/Q", root);
|
||||
int linked = dir_link(outside, link);
|
||||
if (!linked) printf("mods: no symbolic link made (developer mode off?); the linked folder check is skipped\n");
|
||||
|
||||
cfg_set("NX2NAVI_MODS_DIR", root);
|
||||
cfg_set("NX2NAVI_MODS_DIR", "mods-probe"); // relative: under the folder of nx2navi.exe
|
||||
cfg_set("NX2NAVI_MODS_ORDER", "B|A|Gone");
|
||||
cfg_set("NX2NAVI_MODS_DISABLED", "C");
|
||||
mods_scan();
|
||||
|
||||
static const char *const order[] = {"B", "A", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
|
||||
"Ultra \xD0\x96"};
|
||||
CHECK(ends_with(mods_dir(), "/mods-probe"), "a relative mods_dir is under the folder of nx2navi.exe");
|
||||
static const char *const order[] = {"B", "A", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
|
||||
"Q", "Ultra \xD0\x96"};
|
||||
enum { N = sizeof order / sizeof *order };
|
||||
CHECK(mods_count() == N, "fourteen mod folders");
|
||||
int in_order = mods_count() == N;
|
||||
for (int i = 0; in_order && i < N; i++) in_order = EQ(mods_at(i)->name, order[i]);
|
||||
// without the link Q is missing: the names after it move up one
|
||||
int n_want = linked ? N : N - 1, in_order = mods_count() == n_want;
|
||||
CHECK(in_order, linked ? "eighteen mod folders" : "seventeen mod folders");
|
||||
for (int i = 0, k = 0; in_order && i < N; i++) {
|
||||
if (!linked && EQ(order[i], "Q")) continue;
|
||||
in_order = EQ(mods_at(k)->name, order[i]);
|
||||
k++;
|
||||
}
|
||||
CHECK(in_order, "order: mods_order first, the rest by name");
|
||||
if (mods_count() == N && in_order) {
|
||||
if (in_order) {
|
||||
ModInfo *a = mods_at(1), *b = mods_at(0), *c = mods_at(2), *d = mods_at(3), *e = mods_at(4), *f = mods_at(5),
|
||||
*g = mods_at(6), *hm = mods_at(7), *im = mods_at(8), *jm = mods_at(9), *km = mods_at(10),
|
||||
*lm = mods_at(11), *mm = mods_at(12), *u = mods_at(13);
|
||||
*lm = mods_at(11), *mm = mods_at(12), *nm = mods_at(13), *om = mods_at(14), *pm = mods_at(15),
|
||||
*u = mods_at(n_want - 1);
|
||||
CHECK(hm->kind == (MOD_ROMFS | MOD_SUBSDK) && hm->problem == MOD_PLUGIN, "RomFS + subsdk plugin: unusable");
|
||||
CHECK(im->kind == (MOD_ROMFS | MOD_SUBSDK) && im->problem == MOD_PLUGIN, "RomFS + replaced exefs/main");
|
||||
CHECK(ends_with(b->romfs, "B/atmosphere/contents/0400486024DEC000/romfs"), "Atmosphere RomFS root");
|
||||
@@ -107,24 +157,46 @@ int probe_mods(void) {
|
||||
CHECK(km->kind == MOD_ROMFS && km->problem == MOD_OK && ends_with(km->romfs, "K/romfslite"), "merged romfslite");
|
||||
CHECK(lm->kind == (MOD_ROMFS | MOD_CHEATS) && lm->problem == MOD_OK, "RomFS + cheats, main.npdm is no code");
|
||||
CHECK(u->kind == MOD_ROMFS && ends_with(u->romfs, "Ultra \xD0\x96/romfs"), "Unicode folder name");
|
||||
CHECK(nm->kind == MOD_EXEFS && nm->problem == MOD_EXEFS_LATER && nm->pending == 1 && !nm->other_version,
|
||||
"pchtxt with a BOM and an indented build id line is for main");
|
||||
CHECK(om->problem == MOD_EXEFS_OTHER && om->other_version == 1 && !om->pending,
|
||||
"pchtxt build id line with more than hex: another version's");
|
||||
CHECK(pm->problem == MOD_EXEFS_OTHER && pm->other_version == 1, "pchtxt build id after @stop is not read");
|
||||
if (linked) {
|
||||
const ModInfo *q = mods_at(16);
|
||||
CHECK(q->kind == MOD_ROMFS && q->problem == MOD_OK && ends_with(q->romfs, "Q/romfs"),
|
||||
"a linked mod folder is a mod");
|
||||
}
|
||||
CHECK(!mods_changed(), "nothing changed after the scan");
|
||||
|
||||
mods_move(1, -1);
|
||||
CHECK(EQ(mods_at(0)->name, "A") && EQ(mods_at(1)->name, "B"), "move up");
|
||||
CHECK(EQ(cfg_get("NX2NAVI_MODS_ORDER"), "A|B|C|D|E|F|G|H|I|J|K|L|M|Ultra \xD0\x96"),
|
||||
CHECK(EQ(cfg_get("NX2NAVI_MODS_ORDER"), linked ? "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|Ultra \xD0\x96"
|
||||
: "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Ultra \xD0\x96"),
|
||||
"order written without the gone name");
|
||||
mods_move(0, -1);
|
||||
CHECK(EQ(mods_at(0)->name, "A"), "move up at the top does nothing");
|
||||
mods_move(N - 1, 1);
|
||||
CHECK(EQ(mods_at(N - 1)->name, "Ultra \xD0\x96"), "move down at the bottom does nothing");
|
||||
mods_move(n_want - 1, 1);
|
||||
CHECK(EQ(mods_at(n_want - 1)->name, "Ultra \xD0\x96"), "move down at the bottom does nothing");
|
||||
mods_set_enabled(2, 1);
|
||||
const char *dis = cfg_get("NX2NAVI_MODS_DISABLED");
|
||||
CHECK(mods_at(2)->enabled && (!dis || !*dis), "switching C on empties mods_disabled");
|
||||
mods_set_enabled(0, 0);
|
||||
CHECK(EQ(cfg_get("NX2NAVI_MODS_DISABLED"), "A"), "switching A off writes it");
|
||||
CHECK(mods_changed(), "changes seen");
|
||||
|
||||
// the ExeFS patch files waiting for the rebuild follow the mods' start state, wherever the menu moved them:
|
||||
// M and N wait (both on at the start); M moved onto C's place (off at the start) and switched off still waits
|
||||
uint32_t key = 0;
|
||||
CHECK(mods_exefs_pending(&key) == 2, "two ExeFS patch files wait for the rebuild");
|
||||
for (int i = 12; i > 2; i--) mods_move(i, -1);
|
||||
CHECK(EQ(mods_at(2)->name, "M"), "M moved up to the third place");
|
||||
mods_set_enabled(2, 0);
|
||||
key = 0;
|
||||
CHECK(mods_exefs_pending(&key) == 2, "the start state goes with its mod when the menu moves it");
|
||||
}
|
||||
remove_tree(root);
|
||||
remove_tree(outside);
|
||||
printf("mods: %s\n", fails ? "FAIL" : "ok");
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user