Read a comment after a setting's value, and off, false and no for a switch, as players mean them in nx2navi.ini.

A hand-edited "pace_smooth = 0 ; off" kept the comment in the value, which the readers took as on, "fps_limit = 144 #
monitor" gave 60, and "fullscreen = false" or "rtss = off" were on, since every reader took anything but "0" as on;
the log only named these lines (the check added for F-7). Now, for a key whose row has a set of values, cfg_load cuts
an unquoted value at the first blank followed by ';' or '#' after the '=' ("key = ; note" is unset) and logs the line
once; free text keeps its whole value (window_size, monitor, audio_device and keys without a row such as mods_dir,
pipeline_cache and the bindings, where a path or name may hold " #"), as do a value in double quotes and the
environment's values. A switch (a row whose set is 0|1) written as false, off or no reads as 0 and as true, on or yes
as 1 through cfg_get itself, so every reader agrees (cfg_bool, rt_knob, the readers that compare with "0" or parse a
number); cfg_bool and rt_knob also take those words for keys of other rows, and rt_knob no longer logs them. F-7's
check now names a switch value only when it is none of those, and a comment kept in a value only where it stays
(free text, the environment). The launcher's reader (launcher/gameini.py) cuts the same way for keys the caller
says have a set of values; its mods keys stay free text. The menu's save still writes a changed key's line again
without its comment.

This changes what existing files with such lines do, which is what was approved. tests/cfg_parse_check.py,
tests/rt_knob_check.py and launcher_test PlayerIniTest cover the cut, the words, free text, quotes and the
environment, and pass; cfg_rows_check reports 0 problems; the runtime compile check and the -Wall comparison of cfg.c
and perf.c show no new warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:14:43 -05:00
parent 1c26907abe
commit b6709da852
9 changed files with 264 additions and 59 deletions

View File

@@ -3,6 +3,8 @@
// 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
// read cfg_load on the file and cfg_init's check of the environment; then what cfg_get, cfg_bool and cfg_int give
// for a list of keys
// norow cfg_int and cfg_double of a key without a row whose value (the environment's) does not parse
#include <stdarg.h>
#include <stdint.h>
@@ -81,6 +83,24 @@ int main(int argc, char **argv) {
printf("got: vk_present %s\n", cfg_get("NX2NAVI_VK_PRESENT") ? cfg_get("NX2NAVI_VK_PRESENT") : "(unset)");
return 0;
}
if (!strcmp(argv[1], "read")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
printf("--- environment\n");
cfg_init();
static const char *const keys[] = {"PACE_SMOOTH", "FULLSCREEN", "FPS_LIMIT", "VK_PRESENT", "ASPECT", "RTSS",
"HDR_LIVE", "CLOTH_REALTIME", "WINDOW_SIZE", "DLSS_PRESET", "MODS_DIR",
"DYN_RES", "SHADOW_PCF"};
for (size_t i = 0; i < sizeof keys / sizeof *keys; i++) {
char name[64];
snprintf(name, sizeof name, "NX2NAVI_%s", keys[i]);
const char *v = cfg_get(name);
printf("got: %s '%s'", keys[i], v ? v : "(unset)");
const CfgMeta *m = cfg_meta(name);
if (m && m->values && !strcmp(m->values, "0|1")) printf(" bool %d int %d", cfg_bool(name), cfg_int(name));
printf("\n");
}
return 0;
}
if (!strcmp(argv[1], "norow")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
printf("got: cfg_int %d cfg_double %g\n", cfg_int("NX2NAVI_NO_ROW_CHECK"), cfg_double("NX2NAVI_NO_ROW_CHECK"));

View File

@@ -1,9 +1,15 @@
"""Build and run tests/cfg_parse_check.c: runtime/cfg.c's reading of nx2navi.ini and the environment, against stand-ins
for what it links with. The values stay as written; what is checked is what the log says about them:
for what it links with. What the readers get and what the log says about the values:
- a comment after a value (cfg.c cut_comment): cut at a blank followed by ';' or '#' for a key whose row has a set of
values, the line logged once with its line number, "key = ; note" left unset; kept whole in free text (a row
without a set, a key without a row), in a value in double quotes and in the environment, where the log still says
it is part of the value; at most 16 lines, then a count;
- switches written as words (cfg.c switch_word, cfg_bool): false, off and no in any case read as 0 and true, on and
yes as 1 through cfg_get, cfg_bool and cfg_int, from the file and from the environment, with no line about them;
- values outside their rows' sets (cfg.c check_value): a 0|1 switch with another value, a number outside its range, a
word that is none of the menu's choices, and a ';' or '#' comment kept in a value, each named with its line; none
for a file whose values fit, nor for a list with numbers in it (the menu's presets); at most 16 lines, then a count;
word that is none of the menu's choices, each named with its line; none for a file whose values fit, nor for a list
with numbers in it (the menu's presets); at most 16 lines, then a count;
- a full settings table (cfg.c CFG_MAX_KEYS): one line at load naming the first key not read, one at the first menu
change not kept;
- a number read of a key without a row whose set value does not parse gives 0 (cfg.c default_number), not a crash.
@@ -53,6 +59,24 @@ color_gamma = 2
vk_present = vsync
fps_limit = 144 # my monitor
sharpness_typo = 3
cloth_realtime = disabled
window_size = 1280x720 # small
aspect = ; stretch some day
dlss_preset = "k ; quoted"
'''
READ = '''[display]
fullscreen = false
rtss = OFF
hdr_live = Yes
cloth_realtime = on ; the default
pace_smooth = No
vk_present = fifo\t; tear-free
fps_limit = 144 # my monitor
window_size = 1280x720 # small
aspect = ; nothing yet
mods_dir = D:\\My Mods #2
dlss_preset = "k ; quoted"
'''
@@ -94,21 +118,48 @@ def main():
lines = [l for l in out.splitlines() if l.startswith('log: cfg:') and '=' in l and 'line' in l]
check(rc == 0 and not lines, 'a file whose values fit logs nothing about them', out)
# values that do not: one line each, with the line number
# values that do not: one line each, with the line number; a comment after a value of a row with a set: cut, and
# one line
rc, out = run(exe, env, 'load', BAD, work, {'NX2NAVI_SHARPNESS': '500', 'NX2NAVI_VK_PRESENT': 'fifo'})
want = [
"line 2: pace_smooth = '0 ; off' is not 0 or 1; a ';' or '#' after the value is part of it",
"line 3: fullscreen = 'false' is not 0 or 1",
"line 2: pace_smooth = '0', and '; off' after it is a comment",
"line 4: sharpness = '250' is not a number in 0..100",
"line 5: color_gamma = '2' is not a number in 0.8..1.2",
"line 6: vk_present = 'vsync' is none of the menu's choices mailbox|fifo|immediate",
"line 7: fps_limit = '144 # my monitor' a ';' or '#' after the value is part of it",
"line 7: fps_limit = '144', and '# my monitor' after it is a comment",
"line 9: cloth_realtime = 'disabled' is not 0, 1, on, off, true, false, yes or no",
"line 10: window_size = '1280x720 # small' a ';' or '#' after the value is part of it",
"line 11: aspect = '', and '; stretch some day' after it is a comment",
"line 12: dlss_preset = 'k ; quoted' is none of the menu's choices default|k|j; a ';' or '#' after the value "
"is part of it",
"the environment's NX2NAVI_SHARPNESS = '500' is not a number in 0..100",
]
for w in want:
check(rc == 0 and w in out, f'logged: {w}', out if w not in out else '')
cfg_lines = [l for l in out.splitlines() if l.startswith('log: cfg: nx2navi.ini line') and 'unknown key' not in l]
check(len(cfg_lines) == 9, f'one line each for the nine lines, none for "fullscreen = false" ({len(cfg_lines)})',
out)
check(not any(' line 2: ' in l and 'is not 0' in l for l in cfg_lines), 'a cut value is checked as cut', out)
check('NX2NAVI_VK_PRESENT' not in out, 'an environment value that fits is not logged', out)
check("pace_smooth '0 ; off'" in out, 'the value itself is read as written', out)
check("got: pace_smooth '0'" in out, 'the value is read without its comment', out)
# what the readers get: switches written as words, cut comments, free text kept whole, the environment as written
rc, out = run(exe, env, 'read', READ, work, {'NX2NAVI_DYN_RES': 'TRUE', 'NX2NAVI_SHADOW_PCF': '0 ; env note'})
got = {l.split()[1]: l.split(' ', 2)[2] for l in out.splitlines() if l.startswith('got: ')}
want = {'PACE_SMOOTH': "'0' bool 0 int 0", 'FULLSCREEN': "'0' bool 0 int 0", 'RTSS': "'0' bool 0 int 0",
'HDR_LIVE': "'1' bool 1 int 1", 'CLOTH_REALTIME': "'1' bool 1 int 1", 'FPS_LIMIT': "'144'",
'VK_PRESENT': "'fifo'", 'ASPECT': "'(unset)'", 'WINDOW_SIZE': "'1280x720 # small'",
'DLSS_PRESET': "'k ; quoted'", 'MODS_DIR': "'D:\\My Mods #2'", 'DYN_RES': "'1' bool 1 int 1",
'SHADOW_PCF': "'0 ; env note' bool 1 int 0"}
for k, w in want.items():
check(rc == 0 and got.get(k) == w, f'read: {k} {w}', f'got {got.get(k)!r}\n{out}' if got.get(k) != w else '')
cut = [l for l in out.splitlines() if 'after it is a comment' in l]
check(len(cut) == 4 and any("line 7: vk_present = 'fifo', and '; tear-free'" in l for l in cut),
f'four cut lines, a tab before the comment too ({len(cut)})', out)
check(not any(w in out for w in ('fullscreen =', 'rtss =', 'hdr_live =', 'pace_smooth =', 'NX2NAVI_DYN_RES =')),
'no line about switches written as words', out)
check("the environment's NX2NAVI_SHADOW_PCF = '0 ; env note' is not 0, 1, on, off, true, false, yes or no; a ';' "
"or '#' after the value is part of it" in out, "the environment's comment stays in its value", out)
# at most 16 lines, then a count
many = '\n'.join(f'sharpness = {200 + i}' if i % 2 else f'fullscreen = no{i}' for i in range(2)) + '\n'
@@ -121,6 +172,10 @@ def main():
listed = sum(1 for l in out.splitlines() if l.startswith('log: cfg: nx2navi.ini line') and "= '7'" in l)
check(rc == 0 and listed == 16 and 'more values outside their settings' in out,
f'20 values outside their sets: {listed} lines and a count', out)
rc, out = run(exe, env, 'load', ''.join(f'vk_present = fifo ; note {i}\n' for i in range(20)), work)
listed = sum(1 for l in out.splitlines() if 'after it is a comment' in l)
check(rc == 0 and listed == 16 and '4 more comments after a value are not listed' in out,
f'20 comments after values: {listed} lines and a count', out)
# more keys than the table holds: one line at load, one for the menu's changes
full = ''.join(f'cheat_{0x1000 + i:08x} = 1\n' for i in range(600)) + 'low_latency = 1\n'
rc, out = run(exe, env, 'full', full, work)

View File

@@ -380,6 +380,32 @@ class PlayerIniTest(Tmp):
gameini.put(self.tmp, 'discord', 'discord_rpc', '1')
self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 1\r\n')
def test_a_comment_after_a_value_as_the_game_reads_it(self):
"""runtime/cfg.c cut_comment: for a key whose row has a set of values (choices=True), a blank followed by ';'
or '#' starts a comment, "key = ; note" has no value, and a value in double quotes keeps its text; free text,
the mods folder and lists the launcher writes, keeps the whole value. tests/cfg_parse_check.py has the same
lines for the game."""
ini = self.tmp / 'nx2navi.ini'
body = (b'[frame rate]\r\npace_smooth = 0 ; off\r\nfps_limit = 144 # my monitor\r\nvk_present = fifo\t; x\r\n'
b'aspect = ; later\r\ndlss_preset = "k ; quoted"\r\n[mods]\r\nmods_dir = D:\\My Mods #2\r\n'
b'mods_disabled = a #1|b ; c\r\n')
ini.write_bytes(body)
for key, want in (('pace_smooth', '0'), ('fps_limit', '144'), ('vk_present', 'fifo'), ('aspect', ''),
('dlss_preset', 'k ; quoted')):
self.assertEqual(gameini.get(self.tmp, key, choices=True), want, key)
self.assertEqual(gameini.get(self.tmp, 'fps_limit'), '144 # my monitor')
self.assertEqual(gameini.get(self.tmp, 'mods_dir'), 'D:\\My Mods #2')
self.assertEqual(gameini.get(self.tmp, 'mods_disabled'), 'a #1|b ; c')
from launcher import mods
self.assertEqual(mods._names(self.tmp, 'MODS_DISABLED'), ['a #1', 'b ; c'])
# a key's line that has only a comment has no value as the game reads it: the change goes on the line before
ini.write_bytes(b'vk_present = fifo\r\nvk_present = ; later\r\n')
gameini.put(self.tmp, 'display', 'vk_present', 'mailbox', choices=True)
self.assertEqual(ini.read_bytes(), b'vk_present = mailbox\r\nvk_present = ; later\r\n')
ini.write_bytes(b'pace_smooth = 0 ; off\r\n') # the line is written again whole, as the game's menu writes it
gameini.put(self.tmp, 'performance', 'pace_smooth', '1', choices=True)
self.assertEqual(ini.read_bytes(), b'pace_smooth = 1\r\n')
def test_the_older_installer_changes_the_language_line_only(self):
"""installer/ini.py sets the language, in the older installer's last step at every install and update: the
one line goes under [language] with the file's own line ends, and every other byte stays (it used to write

View File

@@ -1,6 +1,7 @@
"""Build and run runtime/perf.c's rt_knob (cut out of the file with its warning table) with stand-ins for the settings and
the log: 0, 1 and ab read as before and log nothing; a value such as "off", "false" or "0 ; a note" still reads as 1
and is logged once per switch, however often the switch is read.
the log: 0, 1 and ab read as before and log nothing; false, off and no in any case read as 0 and true, on and yes as 1,
without a line; any other value, such as "0 ; a note" from the environment (nx2navi.ini's loader cuts that comment) or
"enabled", reads as 1 and is logged once per switch, however often the switch is read.
No GPU, no game files, any Python.
@@ -22,7 +23,9 @@ HARNESS = r'''
#include <string.h>
static const char *vals[][2] = {{"NX2NAVI_A", "0"}, {"NX2NAVI_B", "1"}, {"NX2NAVI_C", "ab"}, {"NX2NAVI_D", "off"},
{"NX2NAVI_E", "false"}, {"NX2NAVI_F", "0 ; a note"}, {"NX2NAVI_G", ""}};
{"NX2NAVI_E", "false"}, {"NX2NAVI_F", "0 ; a note"}, {"NX2NAVI_G", ""},
{"NX2NAVI_I", "No"}, {"NX2NAVI_J", "OFF"}, {"NX2NAVI_K", "TRUE"}, {"NX2NAVI_L", "on"},
{"NX2NAVI_M", "Yes"}, {"NX2NAVI_N", "enabled"}};
static const char *cfg_get(const char *key) {
for (size_t i = 0; i < sizeof vals / sizeof *vals; i++)
if (!strcmp(vals[i][0], key)) return vals[i][1];
@@ -55,18 +58,27 @@ int main(void) {
expect("empty, default 0", rt_knob("G", "0"), 0);
}
expect("lines for 0, 1, ab and defaults", logs, 0);
expect("off", rt_knob("D", "0"), 1);
expect("a line for off", logs, 1);
if (strcmp(last, "cfg: NX2NAVI_D = 'off' is not 0, 1 or ab: read as 1"))
printf("FAIL the line: %%s\n", last), fails++;
for (int i = 0; i < 5; i++) rt_knob("D", "0");
expect("off read again", logs, 1);
expect("false", rt_knob("E", "1"), 1);
for (int round = 0; round < 2; round++) {
expect("off", rt_knob("D", "1"), 0);
expect("false", rt_knob("E", "1"), 0);
expect("No", rt_knob("I", "1"), 0);
expect("OFF", rt_knob("J", "1"), 0);
expect("TRUE", rt_knob("K", "0"), 1);
expect("on", rt_knob("L", "0"), 1);
expect("Yes", rt_knob("M", "0"), 1);
}
expect("lines for the words", logs, 0);
expect("0 with a note", rt_knob("F", "0"), 1);
expect("a line each", logs, 3);
if (!strstr(last, "'0 ; a note'")) printf("FAIL the line: %%s\n", last), fails++;
for (int i = 0; i < 3; i++) rt_knob("E", "1"), rt_knob("F", "0");
expect("each once", logs, 3);
expect("a line for it", logs, 1);
if (strcmp(last, "cfg: NX2NAVI_F = '0 ; a note' is not 0, 1, ab, on, off, true, false, yes or no: read as 1"))
printf("FAIL the line: %%s\n", last), fails++;
for (int i = 0; i < 5; i++) rt_knob("F", "0");
expect("read again", logs, 1);
expect("enabled", rt_knob("N", "0"), 1);
expect("a line each", logs, 2);
if (!strstr(last, "'enabled'")) printf("FAIL the line: %%s\n", last), fails++;
for (int i = 0; i < 3; i++) rt_knob("N", "0"), rt_knob("F", "0");
expect("each once", logs, 2);
if (fails) return 1;
printf("rt_knob_check: all checks passed\n");
return 0;