Files
totk-pc-recomp/runtime/cfg.h
T
Valiantsin DzerakhandClaude Opus 5.5 b9a7896095 Make settings changeable while the game runs and save them back to totk.ini
cfg_set stores a value in memory and bumps cfg_version; consumers that keep a
parsed value compare the version and parse again when it changed. cfg_save
rewrites only the changed lines of totk.ini, keeps comments, and adds a missing
key under its section (after its commented example line when there is one).
The environment still wins over both.

Live consumers: volume (new TOTK_VOLUME host gain in the mixer), frame limit
(TOTK_FPS60 switches the fps60 patch set and the pacer caps at 30 or 60),
rumble strength, curve and triggers, gyro on or off, mouse sensitivity.
TOTK_MOTION=0 and rumble strength 0 now keep their hid handles and read at
rest or stay silent, so they can be turned back on. --probe-cfg covers
cfg_set and cfg_save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 23:54:56 +03:00

30 lines
1.9 KiB
C

// Settings: the TOTK_* environment variables, with totk.ini next to totk.exe behind them.
#pragma once
// getenv for a setting: the environment variable when set, else the totk.ini key (the name without "TOTK_", any
// case), else NULL. Same string semantics as getenv; the pointer stays valid for the process (a value cfg_set replaces
// is kept). A name without the TOTK_ prefix goes to getenv unchanged. Safe from any thread once cfg_init has returned.
const char *cfg_get(const char *name);
// Reads totk.ini once, first thing in main. Logs the file, its key count, unknown keys and environment overrides.
void cfg_init(void);
// Replaces the loaded keys with those of the file at path (tests). 1 when the file was read, 0 when missing.
// Not thread-safe: nothing else may call cfg_get meanwhile.
int cfg_load(const char *path);
// Live settings (the in-game menu). cfg_set stores value as the totk.ini value of name (TOTK_ prefixed), marks it for
// cfg_save and bumps cfg_version. cfg_get returns it unless the environment sets name. Any thread.
void cfg_set(const char *name, const char *value);
// Bumped by every cfg_set. A consumer that keeps a parsed value compares this with the number it last saw (one atomic
// load) and parses again when it changed.
unsigned cfg_version(void);
// 1 when the environment sets name: cfg_set cannot change what cfg_get returns (the menu greys the setting out).
int cfg_from_env(const char *name);
// Writes the keys cfg_set changed since the last save into totk.ini next to totk.exe (cfg_save_to: the file at path).
// Only those lines change: the last line of a changed key gets the new value, a missing key goes under its section
// (after the commented example line of the key when the section has one; the section is added at the end of the file
// when missing), comments and every other line stay byte for byte. 1 on success or with nothing to write.
int cfg_save(void);
int cfg_save_to(const char *path);