diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 1723ae53..f915c9df 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -409,7 +409,8 @@ # Volume in percent (0 to 100), on top of the game's own. Changes while the game runs take effect at once. # volume = 100 # Speakers: stereo, 5.1 or auto (5.1 when the Windows speaker setup has six or more channels, stereo otherwise). The -# game is told the same channel count and mixes for it. Takes effect at the next start. +# game is told the same channel count and mixes for it. A change while the game runs takes effect at once: the game is +# told its output device changed, as on a console, and mixes for the new count. # audio_channels = stereo # Which output device the sound plays on. default (the default): the system default device, which the game follows when # the Windows default changes. Or a number, counting from 1 in the order `nx2navi.exe --list-audio-devices` prints; or part @@ -450,7 +451,7 @@ # stick_deadzone = 8 # Right-stick camera speed (0.1 to 3): multiplies the game's own camera turn rates, top speed included, at each of the # five camera sensitivities in the game's Options. Keys bound to the right stick follow it; the mouse keeps mouse_sens. -# Read at start. +# A change while the game runs takes effect at once (the first one of a run within a few seconds). # stick_sens = 1 # The dead zone of one stick, in place of stick_deadzone for that stick (0 to 50; unset = stick_deadzone). The Controls # tab shows each stick's deflection now, so a drifting stick's resting value can be read off. diff --git a/runtime/audio_mixer.c b/runtime/audio_mixer.c index e7255e90..0708e01a 100644 --- a/runtime/audio_mixer.c +++ b/runtime/audio_mixer.c @@ -71,6 +71,7 @@ typedef struct Mixer { unsigned reported; // one-time reports float voice_scratch[6][MAX_FRAME], filter_scratch[MAX_FRAME], output_scratch[MAX_FRAME * OUT_MAX]; double level_sum, level_peak; uint64_t level_count, level_frames; int first_sound_logged; + double input_sum[6]; // NX2NAVI_TRACE=audio: the device sink's inputs, squared and summed int prefill; // render blocks uint64_t trace_pass, trace_seen[1024]; // NX2NAVI_TRACE=audio: render passes; the pass each voice was last mixed in uint64_t trace_buf[1024]; // and the wave buffer address it read in that pass @@ -225,12 +226,13 @@ int list_audio_devices(void) { return 0; } -// NX2NAVI_AUDIO_CHANNELS: the output channels of this run, decided once. stereo gives 2; 5.1 gives 6 (FL FR C LFE RL RR, +// NX2NAVI_AUDIO_CHANNELS: the output channels, decided at the first call and again when the setting changes +// (audio_channels_live). stereo gives 2; 5.1 gives 6 (FL FR C LFE RL RR, // the device sink's order and SDL's); auto gives 6 when the chosen playback device (NX2NAVI_AUDIO_DEVICE; the system default unless set) has at least six channels (a 5.1 // or 7.1 speaker setup in Windows; SDL places 5.1 on 7.1) and 2 otherwise. IAudioDevice reports the same count to the // game (GetActiveChannelCount), which picks its sink layout from it. NX2NAVI_AUDIO=none: 2, without touching SDL. +static _Atomic int decided; // 0: output_channels decides at its next call static int output_channels(void) { - static _Atomic int decided; int n = atomic_load(&decided); if (n) return n; const char *want = cfg_value("NX2NAVI_AUDIO_CHANNELS"), *mode = cfg_get("NX2NAVI_AUDIO"); @@ -402,6 +404,29 @@ static void output_timing(Mixer *m, int rate) { dev.channels, m->prefill * 5, period, m->target * 1000.0 / rate); } +// Render thread (audio_mixer_render): the output takes another channel count after NX2NAVI_AUDIO_CHANNELS changed +// (audio_channels_live). The stream is made again with the new count on the device it was on: destroying it waits +// for the SDL callback, the only other reader of the ring and of m->channels, and what was queued in the old layout +// is dropped. +static void channels_switch(Mixer *m, int channels) { + if (m->stream) SDL_DestroyAudioStream(m->stream); + m->stream = NULL; + atomic_store_explicit(&m->rd, atomic_load(&m->wr), memory_order_release); + m->channels = channels; + m->ready = 0; + m->reported &= ~(1u << 6); // the device sink's line again, with the new output + atomic_store_explicit(&m->pulled_ns, 0, memory_order_release); + rt_log("audio: the output is now %s", channels == 6 ? "5.1" : "stereo"); + if (!m->device_ok) return; // mixing without a device + char err[256]; + if (stream_open(m, m->rate, m->device ? m->device : SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, err, sizeof err)) { + output_timing(m, m->rate); + } else { + m->device_ok = 0; + rt_log("audio: no output device (%s): mixing without sound", err); + } +} + // Render thread, from audio_mixer_pace_ns while the device takes nothing. An explicitly chosen device (NX2NAVI_AUDIO_DEVICE) // can disappear (a virtual sink removed, a USB headset unplugged); SDL keeps only the system default device alive across // that, so the stream of a chosen one just stops being pulled, and nothing in this file polls SDL's event queue for the @@ -523,6 +548,11 @@ static void level_note(AudioRenderer *r, Mixer *m, const float *out, int frames) (unsigned long long)atomic_load(&m->overruns), (unsigned long long)atomic_load(&m->missing_frames), (unsigned long long)atomic_load(&m->callback_frames), (unsigned long long)atomic_load(&m->callback_nonzero), queued * 1000.0 / r->param.sample_rate, (unsigned long long)atomic_load(&m->skipped_frames)); + double f = (double)m->level_frames; + rt_log("audio: device sink inputs rms FL %.4f FR %.4f C %.4f LFE %.4f RL %.4f RR %.4f, output %s", + sqrt(m->input_sum[0] / f), sqrt(m->input_sum[1] / f), sqrt(m->input_sum[2] / f), sqrt(m->input_sum[3] / f), + sqrt(m->input_sum[4] / f), sqrt(m->input_sum[5] / f), m->channels == 6 ? "5.1" : "stereo"); + memset(m->input_sum, 0, sizeof m->input_sum); m->level_sum = m->level_peak = 0; m->level_count = m->level_frames = 0; } @@ -1128,6 +1158,7 @@ void audio_mixer_render(AudioRenderer *r, double seconds) { if (r->sinks[i].type == SINK_DEVICE && !sink) sink = &r->sinks[i]; else if (r->sinks[i].type == SINK_CIRCULAR){mix_circular_sink(r,i);circular=1;} } else {m->sink_address[i]=0;m->sink_size[i]=m->sink_offset[i]=m->sink_old[i]=m->sink_written[i]=0;} + if (m->channels != output_channels()) channels_switch(m, output_channels()); const int oc = m->channels; float *out=m->output_scratch; memset(out, 0, sizeof(float) * (size_t)oc * (size_t)frames); @@ -1143,6 +1174,9 @@ void audio_mixer_render(AudioRenderer *r, double seconds) { const float *ch[6] = {0}; float raw[2 * MAX_FRAME]; for (uint32_t c = 0; c < sink->input_count; c++) if (sink->inputs[c] >= 0 && sink->inputs[c] < m->nbuf) ch[c] = mixbuf(m, sink->inputs[c]); + if (rt_trace & RT_TRACE_AUDIO) // what the game puts on each input: shows whether it mixes for 5.1 (level_note) + for (int c = 0; c < 6; c++) + for (int k = 0; ch[c] && k < frames; k++) m->input_sum[c] += (double)ch[c][k] * ch[c][k]; for (int k = 0; k < frames; k++) { float s[OUT_MAX] = {0}; /* FL FR C LFE RL RR */ if (sink->input_count >= 6 && oc == 6) { @@ -1170,6 +1204,41 @@ void audio_mixer_render(AudioRenderer *r, double seconds) { // ---- IAudioDevice: one output device, stereo or 5.1 (output_channels) static const char device_name[] = "AudioTvOutput"; +// The events the game took to hear of a change of the output device (IAudioDevice's, its notifications' and the +// virtual device manager's). audio_channels_live signals them all: the game then asks for the channel count again, as +// it does on a console whose output moves from the TV to headphones. +static uint32_t change_events[16]; +static _Atomic int n_change_events; + +static uint32_t change_event_new(void) { + uint32_t ev = kern_event_new(); + int i = atomic_fetch_add(&n_change_events, 1); + if (i < 16) change_events[i] = ev; + return ev; +} + +// Present path, after a settings change (gfx_present.c window_settings_live): a changed NX2NAVI_AUDIO_CHANNELS is +// decided again, and when it gives another channel count the game is told its output device changed. The game asks +// GetActiveChannelCount again and mixes for the new count; the mixer moves its device to that count at its next +// render (channels_switch). Measured on Ocarina 1.1.1: one event held, and the game asked within the same second. +void audio_channels_live(void) { + static char seen[16]; + const char *want = cfg_value("NX2NAVI_AUDIO_CHANNELS"); + if (!strncmp(want, seen, sizeof seen - 1)) return; + int first = !seen[0]; + snprintf(seen, sizeof seen, "%s", want); + int was = atomic_load(&decided); + if (first || !was) return; // nothing has asked yet: the first call decides + atomic_store(&decided, 0); + int now = output_channels(); + if (now == was) return; + int n = atomic_load(&n_change_events); + if (n > 16) n = 16; + for (int i = 0; i < n; i++) kern_event_signal(change_events[i]); + rt_log("audio: NX2NAVI_AUDIO_CHANNELS=%s: the output goes from %s to %s; the game is told the device changed " + "(%d events)", want, was == 6 ? "5.1" : "stereo", now == 6 ? "5.1" : "stereo", n); +} + static void put_name(const IpcBuffer *b, IpcResponse *rs, int pointer) { if (!b->size) return; char *dst = ipc_guest(b->addr, b->size); @@ -1185,7 +1254,7 @@ static IpcBuffer out_buffer(const IpcRequest *rq, int *pointer) { } void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs) { - static uint32_t change_event; // device change events: never signalled, the device does not change + static uint32_t change_event; // the device change event: signalled when the output's channels change (audio_channels_live) int pointer; switch (rq->cmd) { case 0: case 6: case 14: { // ListAudioDeviceName(Auto), ListAudioOutputDeviceName [13.0.0+] @@ -1210,7 +1279,7 @@ void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs) case 4: case 11: case 12: { // QueryAudioDeviceSystemEvent, ...InputEvent, ...OutputEvent uint32_t ev = __atomic_load_n(&change_event, __ATOMIC_ACQUIRE); if (!ev) { - uint32_t mine = kern_event_new(), expected = 0; + uint32_t mine = change_event_new(), expected = 0; if (__atomic_compare_exchange_n(&change_event, &expected, mine, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) ev = mine; else @@ -1222,9 +1291,9 @@ void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs) // 17.0.0+: Acquire/Release Audio{Input,Output}DeviceNotification (15-18), 18.0.0+: SetAudioDeviceOutputVolume- // AutoTuneEnabled (19) / IsAudioDeviceOutputVolumeAutoTuneEnabled (20), 21.0.0+: // IsActiveOutputDeviceEstimatedLowLatency (21). Command ids as the system answers them. The - // device never changes and the host applies no auto-tuned volume, so the answers are "off" / "no". - case 15: case 17: { // Acquire...Notification -> a readable event that is never signalled - uint32_t ev = kern_event_new(); + // host applies no auto-tuned volume, so the answers are "off" / "no". + case 15: case 17: { // Acquire...Notification -> a readable event, signalled with the others + uint32_t ev = change_event_new(); rs->copy[rs->ncopy++] = kern_event_readable(ev); return; } @@ -1293,7 +1362,7 @@ static void virtual_device_manager_handler(IpcSession *s, const IpcRequest *rq, put_block(rq, rs, block, sizeof block); return; } - case 500: rs->copy[rs->ncopy++] = kern_event_readable(kern_event_new()); return; // state change event + case 500: rs->copy[rs->ncopy++] = kern_event_readable(change_event_new()); return; // state change event case 700: case 800: return; // AttachStream / DetachStream default: { static volatile int32_t seen[64]; diff --git a/runtime/audren.h b/runtime/audren.h index e8289780..4f3d861e 100644 --- a/runtime/audren.h +++ b/runtime/audren.h @@ -194,5 +194,6 @@ int audio_mixer_out_stats(AudioRenderer *r, AudioOutStats *o); uint64_t audio_voice_consumed(const AudioRenderer *r, ServerVoice *v, int frames); // source samples over one frame; advances v->fraction int audio_buffer_empty(const AudrenWaveBuffer *b); // no samples to decode: played as soon as it is reached void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs); // IAudioDevice +void audio_channels_live(void); // after a settings change: another NX2NAVI_AUDIO_CHANNELS reaches the game and the mixer void audio_dmg_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs); // auddmg:u (Switch 2) void audio_sysmix_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs); // audsmx:u (Switch 2) diff --git a/runtime/camera_speed.c b/runtime/camera_speed.c index 447c3c93..db2b2fe7 100644 --- a/runtime/camera_speed.c +++ b/runtime/camera_speed.c @@ -1,4 +1,4 @@ -// Camera speed: NX2NAVI_STICK_SENS (0.1 to 3, default 1, read at start) multiplies the game's own right-stick camera speeds. +// Camera speed: NX2NAVI_STICK_SENS (0.1 to 3, default 1) multiplies the game's own right-stick camera speeds. // The game's Options menu offers five camera sensitivities, Very Low to Very High; their turn rates are the array // StickSensitivity {0.8, 1.2, 1.6, 2.0, 2.4} in Component/PlayerCameraParam/PlayerCamera.game__component__ // PlayerCameraParam.bgyml inside Pack/Actor/PlayerCamera.pack.zs. romfs.c serves a copy of that pack with every entry @@ -8,6 +8,13 @@ // // The pack is a SARC archive compressed with the dictionary pack.zsdic of Pack/ZsDic.pack.zs. A float in a BYML array // is stored in the array itself, so the multiplied values take the bytes of the old ones and no offset moves. +// +// During a run (cam_speed_tick): the pack served stays the one made at start, and the game has read it by the time the +// player changes the setting. So a change is written into the game's memory instead: the array as the game holds it +// (the five values in a row, times the factor in effect) is looked for in the guest's heap and every copy found is +// overwritten with the values times the new factor. The game reads the array each time it steps the camera, so the +// camera's speed follows at once. When the game opens the pack again (cam_pack_opened: romfs.c), what it reads holds +// the start's factor again, and the search runs once more a moment later. #include #include #include @@ -15,11 +22,15 @@ #include "cfg.h" #include "host.h" +#include "platform/platform.h" #define MEMBER "Component/PlayerCameraParam/PlayerCamera.game__component__PlayerCameraParam.bgyml" #define MAX_RAW (64u << 20) -static float applied = 1.0f; +static float applied = 1.0f; // the factor the game's values in memory carry: what cam_speed_applied reports +static float base[8]; // the game's own StickSensitivity values, from the pack as it is before multiplying +static int base_n; // how many; 0 until cam_pack_build has read the pack (or when it could not) +static float served_k = 1.0f; // the factor of the pack the game reads from the RomFS: the start's float cam_speed_wanted(void) { double v = cfg_double("NX2NAVI_STICK_SENS"); @@ -100,7 +111,6 @@ static int scale_sensitivity(uint8_t *p, size_t n, float k, float was[8]) { int cam_pack_build(const void *in, size_t n, const void *zsdic, size_t zsdic_n, void **out, size_t *out_n) { float k = cam_speed_wanted(); *out = NULL; - if (k == 1.0f) return 0; int ok = 0; uint8_t *dics = NULL, *raw = NULL; ZSTD_DDict *dd = NULL; @@ -135,6 +145,9 @@ int cam_pack_build(const void *in, size_t n, const void *zsdic, size_t zsdic_n, rt_log("camera speed: no StickSensitivity array in %s; the camera keeps its own speed", MEMBER); goto done; } + memcpy(base, was, sizeof(float) * (size_t)count); // what a change during the run looks for in memory (cam_speed_tick) + base_n = count; + if (k == 1.0f) goto done; // the game's own pack is served as it is cd = ZSTD_createCDict(dics + dic_at, dic_n, 9); size_t cap = ZSTD_compressBound((size_t)rn), zn = 0; ZSTD_CCtx *cctx = cd ? ZSTD_createCCtx() : NULL; @@ -158,4 +171,134 @@ done: return ok; } -void cam_pack_served(void) { applied = cam_speed_wanted(); } +void cam_pack_served(void) { applied = served_k = cam_speed_wanted(); } + +// ---- during a run + +#define COPIES 16 +static uint64_t copies[COPIES]; // where the game's memory held the array at the last search +static int ncopies; + +static void factor(float out[8], float k) { // the array at factor k, as cam_pack_build's multiplication gives it + for (int i = 0; i < base_n; i++) out[i] = base[i], out[i] *= k; +} + +// A pass over the guest's heap and alias regions for the array at factor k, byte for byte, in memory the game may +// read and write; each copy found becomes the array at factor to and is remembered (copies, when fresh is set). +// Returns how many were rewritten. Runs on its own thread: the regions are read 16 MiB at a time under mem_read_hold, +// so the game's own mapping calls wait for one piece at most. +static int rewrite(float k, float to, int fresh) { + enum { PIECE = 16 << 20 }; + float from[8], into[8]; + factor(from, k); + factor(into, to); + const size_t len = sizeof(float) * (size_t)base_n; + const uint8_t first = *(const uint8_t *)from; + const RtGuestLayout *l = mem_layout(); + const RtRange ranges[2] = {l->heap, l->alias}; + int found = 0; + if (fresh) ncopies = 0; + for (int r = 0; r < 2; r++) { + uint64_t a = ranges[r].base, end = ranges[r].base + ranges[r].size; + while (a < end) { + RtMemoryInfo mi; + if (mem_query(a, &mi) || !mi.size) break; + uint64_t stop = mi.base + mi.size < end ? mi.base + mi.size : end; + if (!mi.state || (mi.perm & 3) != 3) { // free, or not the game's to read and write + a = stop; + continue; + } + while (a < stop) { + uint64_t n = stop - a < PIECE ? stop - a : PIECE; + if (n >= len && mem_read_hold(a, n)) { + const uint8_t *p = (const uint8_t *)(uintptr_t)a, *e = p + n; + for (const uint8_t *q = p; q + len <= e && (q = memchr(q, first, (size_t)(e - q) - len + 1)); q++) { + if (memcmp(q, from, len)) continue; + mem_thaw((uint64_t)(uintptr_t)q, len); // a write-protected page of a tracked region + memcpy((void *)(uintptr_t)q, into, len); + if (ncopies < COPIES) copies[ncopies++] = (uint64_t)(uintptr_t)q; + found++; + } + mem_read_release(); + } + // a copy across two pieces: the next piece starts a little before this one's end + a += n < PIECE ? n : n - (len - 1); + } + } + } + return found; +} + +// The copies of the last search, still holding the array at factor k, rewritten to factor to: 1 when every one of them +// did (a step of the menu's slider then takes no search), 0 when one is gone or changed, with none of them touched. +static int rewrite_known(float k, float to) { + float from[8], into[8]; + factor(from, k); + factor(into, to); + const size_t len = sizeof(float) * (size_t)base_n; + if (!ncopies) return 0; + for (int pass = 0; pass < 2; pass++) // all checked first, then all written + for (int i = 0; i < ncopies; i++) { + if (!mem_read_hold(copies[i], len)) return 0; + int same = !memcmp((const void *)(uintptr_t)copies[i], pass ? into : from, len) || + (pass && !memcmp((const void *)(uintptr_t)copies[i], from, len)); + if (same && pass) { + mem_thaw(copies[i], len); + memcpy((void *)(uintptr_t)copies[i], into, len); + } + mem_read_release(); + if (!same) return 0; + } + return 1; +} + +static volatile int32_t searching; // the search thread runs +static volatile int32_t reopened; // the game opened the pack since the last search (cam_pack_opened) +static uint64_t due_ns; // when cam_speed_tick starts the next search; 0: none due +static int tries; // searches left after this one that found nothing +static float asked = 1.0f; // the factor the last search was started for + +static void search_main(void *arg) { + (void)arg; + float to = cam_speed_wanted(), was = applied; + uint64_t t0 = plat_now_ns(); + // what the game holds: the array at the factor in effect, and at the start's after it read the pack again + int n = to != was ? rewrite(was, to, 1) : 0; + if (served_k != was && served_k != to) n += rewrite(served_k, to, 0); // new copies beside the ones known + if (n) { + applied = to; + rt_log("camera speed: x%.2f now, written over %d cop%s of the game's StickSensitivity in memory (%.0f ms)", to, n, + n == 1 ? "y" : "ies", (plat_now_ns() - t0) / 1e6); + } else if (to != was) { + rt_log("camera speed: x%.2f asked for, but the game's StickSensitivity (x%.2f) is not in memory%s", to, was, + tries ? "; looking again in a moment" : ": the camera keeps its speed until the game loads it"); + } + plat_xchg32(&searching, 0); +} + +void cam_pack_opened(void) { plat_xchg32(&reopened, 1); } + +// Every present (gfx_present.c). A factor other than the one in effect goes to the copies the last search found at +// once; without them (the first change of a run, or the game moved them) a search starts, and a few more while one +// finds nothing (the game is still loading). A moment after the game opened the pack again a search looks for the +// start's factor, which is what the game has then read. +void cam_speed_tick(void) { + if (!base_n) return; + float want = cam_speed_wanted(); + if (plat_xchg32(&reopened, 0) && want != served_k) due_ns = plat_now_ns() + 1500000000ull, tries = 3; + if (want == applied && !due_ns) return; + if (plat_cas32(&searching, 0, 0)) return; // a search writes applied and the copies + uint64_t now = plat_now_ns(); + if (want != applied) { + if (rewrite_known(applied, want)) { + applied = asked = want; + return; + } + if (want != asked) asked = want, due_ns = now, tries = 3; + } + if (!due_ns || now < due_ns) return; + due_ns = 0; + if (tries > 0 && want != applied) tries--, due_ns = now + 4000000000ull; // again unless this one finds it + plat_xchg32(&searching, 1); + if (!plat_thread_spawn(search_main, NULL, "camera speed", 0)) plat_xchg32(&searching, 0); +} diff --git a/runtime/cfg.c b/runtime/cfg.c index 7a2a59b4..7c03acd2 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -178,14 +178,14 @@ static const CfgMeta metas[] = { {"OPERATION_MODE", "docked", "docked|handheld", LIVE}, {"ASSUME_FOCUS", "1", "0|1", LIVE}, // read on every focus change (ov_system.c) // Sound, Controls, Menu - {"VOLUME", "100", "0..100", LIVE}, {"MENU_SOUND_VOLUME", "80", "0..100", LIVE}, {"AUDIO_CHANNELS", "stereo", "auto|stereo|5.1", RESTART}, + {"VOLUME", "100", "0..100", LIVE}, {"MENU_SOUND_VOLUME", "80", "0..100", LIVE}, {"AUDIO_CHANNELS", "stereo", "auto|stereo|5.1", LIVE}, // audio_mixer.c audio_channels_live {"AUDIO_DEVICE", "default", NULL, RESTART}, // default|<1-based index>| (audio_mixer.c resolve_audio_device) {"MICROPHONE", "1", "0|1", RESTART}, // ov_audio_input.c mic_on: 0 refuses the game's input streams {"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE}, {"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "nintendo", "auto|nintendo|xbox|playstation", LIVE}, {"DS3", "0", "0|1", LIVE}, // input_ds3_win.c ds3_read: read a DualShock 3 directly; off: no HID scan {"PROMPTS", "nintendo", "nintendo|xbox|playstation|pc", RESTART}, - {"STICK_DEADZONE", "8", "0..50", LIVE}, {"STICK_SENS", "1", "0.1..3", RESTART}, + {"STICK_DEADZONE", "8", "0..50", LIVE}, {"STICK_SENS", "1", "0.1..3", LIVE}, // camera_speed.c cam_speed_tick {"LSTICK_DEADZONE", "", "0..50", LIVE}, {"RSTICK_DEADZONE", "", "0..50", LIVE}, {"MOUSE_MODE", "direct", "stick|direct", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE}, {"MENU_CURSOR", "1", "0|1", LIVE}, diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 3a8d1592..dad71666 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -15,6 +15,7 @@ #include #include +#include "audren.h" #include "cfg.h" #include "flight.h" #include "fs.h" @@ -258,6 +259,7 @@ static void window_settings_live(void) { // with what it got: on a display without HDR10 the setting stays on and the swapchain SDR, and that is settled. if (started && vk_hdr_wanted() != g_sc_hdr_wanted) plat_xchg32(&g_dirty, 1); ov_operation_mode_live(); + audio_channels_live(); if (started) gfx_window_apply_settings(); started = 1; } @@ -971,6 +973,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w if (cw <= 0 || ch <= 0) cx = cy = 0, cw = w, ch = h; // a crop outside the image (the game's nvnWindowSetCrop): // the whole image, not an inverted blit rectangle window_settings_live(); + cam_speed_tick(); // The menu overlay: laid out before recording (its first frame starts the ImGui back end and uploads the font) const char *menu_shot = NULL; MenuTarget mt = {c->instance, c->phys, c->device, c->gfx_family, c->gfx_queue, diff --git a/runtime/host.h b/runtime/host.h index 0d1feb45..0004a8c8 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -280,6 +280,8 @@ float cam_speed_applied(void); // the factor in effe int cam_pack_build(const void *in, size_t n, const void *zsdic, size_t zsdic_n, void **out, size_t *out_n); // Pack/Actor/PlayerCamera.pack.zs with the camera speeds // multiplied, malloc'd; 0 = factor 1 or cannot (logged) +void cam_pack_opened(void); // romfs.c: the game opened the camera's pack +void cam_speed_tick(void); // every present: a changed setting goes into the game's memory void cam_pack_served(void); // romfs.c serves the multiplied pack // ---- game resolution (resolution.c): NX2NAVI_OUTPUT_RES, NX2NAVI_RENDER_SCALE uint64_t res_heap_extra_bytes(void); // added to the application pool (mem_init), 2 MiB steps diff --git a/runtime/romfs.c b/runtime/romfs.c index fce2bc91..2e027fa4 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -769,7 +769,7 @@ static void heapdef_overlay(void) { // overlay that replaces the pack (a mod's camera stays), else the RomFS original; the dictionary is the RomFS's own. #define CAMPACK "Pack/Actor/PlayerCamera.pack.zs" static void camera_overlay(void) { - if (cam_speed_wanted() == 1.0f) return; + // also at factor 1: cam_pack_build reads the game's own values, which a change during the run needs static const char keeps[] = "the camera keeps its own speed"; Overlay *base, *dic_base; size_t n, dn; @@ -1158,6 +1158,7 @@ uint32_t romfs_open(uint64_t *out, const char *path, int mode) { uint64_t i = file_index(p); if (i == UINT64_MAX) return FS_R_PATH_NOT_FOUND; open_note(i, p); + if (!strcasecmp(p, CAMPACK)) cam_pack_opened(); // its values come into memory at the start's factor (camera_speed.c) uint32_t ov = overlay_slot(i); PlatFile *f = NULL; if (ov) {