Files
NX2navi/tests/cfg_parse_check.c
chrg6 5b9ed9ed12 Say so in the log when the settings table is full and a key or a menu change is not kept.
cfg.c keeps at most CFG_MAX_KEYS (512) keys. add, cfg_set, cfg_reset and migrate stopped silently at the cap, so a
file with more keys (every cheat ever switched keeps a cheat_<hash> line, unknown keys count too) had its later keys
ignored and a later menu change lost, with nothing in the log (the audit's probe: low_latency after 600 cheat lines
read as unset, a cfg_set of vk_present lost, 0 log lines). Only a file far past what players have reaches it.

A line now says so: at load once per load, naming the first key and line not read, and once a run for the changes
cfg_set, cfg_reset and migrate could not keep. Raising the cap would change which keys take effect and is left for
approval.

Not reproduced before the change by a game run; tests/cfg_parse_check.py gains the case: a file of 600 cheat keys
and then low_latency gives one line at load from line 513 on, and two cfg_set past the full table one line. The cfg
rows checks and the compile checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 18:42:34 -05:00

85 lines
3.0 KiB
C

// runtime/cfg.c's reading of nx2navi.ini and the environment, with stand-ins for what cfg.c links against. Built and
// run by tests/cfg_parse_check.py: `cfg_parse_check <case> <ini>` loads the file the script wrote and prints every line
// cfg.c logged ("log: ...") and what the case reads back ("got: ...").
// load cfg_load on the file; then cfg_init's check of the environment (the variables the script set)
// full cfg_load on the file, then two cfg_set of keys the file does not have
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cfg.h"
#include "host.h"
#include "platform/platform.h"
void rt_log(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
printf("log: ");
vprintf(fmt, ap);
printf("\n");
va_end(ap);
}
void rt_fatal(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
printf("FATAL: ");
vprintf(fmt, ap);
printf("\n");
va_end(ap);
exit(3);
}
const char *bugcap_replay_dir(void) { return NULL; }
void perf_size(PerfSizes *s, const char *name, uint64_t count, uint64_t limit, uint64_t bytes) {
(void)s, (void)name, (void)count, (void)limit, (void)bytes;
}
static const char *ini;
int plat_exe_path(char *out, size_t n) { (void)out, (void)n; return 0; }
int plat_file_exists(const char *p) {
FILE *f = fopen(p, "rb");
if (f) fclose(f);
return f != NULL;
}
uint8_t *plat_file_read(const char *path, uint64_t *size) {
FILE *f = fopen(path, "rb");
if (!f) return NULL;
fseek(f, 0, SEEK_END);
long n = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *d = malloc((size_t)n + 1);
if (fread(d, 1, (size_t)n, f) != (size_t)n) n = 0;
d[n] = 0;
fclose(f);
*size = (uint64_t)n;
return d;
}
int64_t plat_file_size(const char *p) { (void)p; return -1; }
int plat_file_write_atomic(const char *p, const void *d, size_t n) { (void)p, (void)d, (void)n; return 1; }
void plat_mutex_lock(PlatMutex *m) { (void)m; }
void plat_mutex_unlock(PlatMutex *m) { (void)m; }
int plat_setenv(const char *n, const char *v) { (void)n, (void)v; return 1; }
int main(int argc, char **argv) {
setvbuf(stdout, NULL, _IONBF, 0);
if (argc < 3) return 2;
ini = argv[2];
if (!strcmp(argv[1], "load")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
printf("got: pace_smooth '%s'\n", cfg_get("NX2NAVI_PACE_SMOOTH") ? cfg_get("NX2NAVI_PACE_SMOOTH") : "(unset)");
printf("--- environment\n");
cfg_init(); // finds no nx2navi.ini next to the stand-in exe; checks the environment's values
return 0;
}
if (!strcmp(argv[1], "full")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
const char *ll = cfg_get("NX2NAVI_LOW_LATENCY");
printf("got: low_latency %s\n", ll ? ll : "(unset)");
cfg_set("NX2NAVI_VK_PRESENT", "fifo");
cfg_set("NX2NAVI_FULLSCREEN", "1");
printf("got: vk_present %s\n", cfg_get("NX2NAVI_VK_PRESENT") ? cfg_get("NX2NAVI_VK_PRESENT") : "(unset)");
return 0;
}
return 2;
}