mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 07:31:06 -04:00
Stop calling RTSS's EnumProfiles, which crashed the game at start where RivaTuner Statistics Server runs.
EnumProfiles walks RTSS's Profiles\*.cfg with _findfirst and _findnext and keeps the find handle in 32 bits. The handle points into the process heap, which lies above 4 GB here because the guest address space takes the low part (memory.c mem_init), so _findnext gets a cut pointer and faults in ntdll: the crash report then ends the game with code 71 before the title screen (issue #231). rtss_limit.c profile_exists now looks for Profiles\<name>.cfg in RTSS's folder, which is what EnumProfiles reports. NX2NAVI_RTSS_ENUM=1 calls EnumProfiles again, to test an RTSS that keeps the whole handle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
# it, or with frame generation on, the game limits by itself, and also when RTSS's own frame counter shows the game
|
||||
# well past the limit (RTSS then hooks the game without holding it back). rtss = 0 always leaves it to the game.
|
||||
# rtss = 1
|
||||
# 1: asks RTSS's EnumProfiles whether the game's profile exists, instead of looking for its file. EnumProfiles crashes
|
||||
# the game (RTSS keeps a pointer of the game's in 32 bits); only for testing an RTSS that fixed it.
|
||||
# rtss_enum = 0
|
||||
# Older key, read only while fps_limit is unset: fps60 = 0 means a limit of 30.
|
||||
# fps60 = 1
|
||||
# Real-time frame step: game speed follows the clock instead of the frame count.
|
||||
|
||||
@@ -53,7 +53,7 @@ static const char *const known[] = {
|
||||
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPELINE_CACHE_MAX_MB", "PIPE_BINARIES", "PIPE_BINARIES_MAX_MB", "PIPE_FEEDBACK", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME", "PRESENT_HELD", "HELD_SYNC",
|
||||
"PREWARM_FULL", "PREWARM_WAIT_MS", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_REPLAY", "PROFILE_SLOW",
|
||||
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_END", "REEXEC",
|
||||
"REFLEX", "RENDER_SCALE", "REPLAY_ASYNC", "RTSS",
|
||||
"REFLEX", "RENDER_SCALE", "REPLAY_ASYNC", "RTSS", "RTSS_ENUM",
|
||||
"REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
|
||||
"ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE",
|
||||
"SHADER_CACHE_FLUSH", "SHADER_CARRY", "SHADER_MEMO", "SHADOW_COMPARE", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR",
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
// HKLM\SOFTWARE\WOW6432Node\Unwinder\RTSS, InstallDir) exports the profile calls, loaded here at run time:
|
||||
// LoadProfile(name) reads a profile (the global one for a name without its own), Get/SetProfileProperty read and change
|
||||
// the loaded copy, SaveProfile(name) writes it to Profiles\<name>.cfg, UpdateProfiles makes every hooked process
|
||||
// read its profile again, EnumProfiles lists the profiles that exist, DeleteProfile removes one. "FramerateLimit" is
|
||||
// the limit in frames per second (0: none); "FramerateLimitDenominator" divides it, so 59940 over 1000 limits to
|
||||
// 59.94 (a monitor's measured rate). SaveProfile reports nothing: RTSS's Profiles folder sits under Program Files, which
|
||||
// a process without administrator rights cannot write, and the save then fails silently. So every change is read back
|
||||
// read its profile again, EnumProfiles lists the profiles that exist (profile_exists says why it is not called),
|
||||
// DeleteProfile removes one. "FramerateLimit" is the limit in frames per second (0: none); "FramerateLimitDenominator"
|
||||
// divides it, so 59940 over 1000 limits to 59.94 (a monitor's measured rate). SaveProfile reports nothing: RTSS's
|
||||
// Profiles folder sits under Program Files, which a process without administrator rights cannot write, and the save
|
||||
// then fails silently. So every change is read back
|
||||
// from the saved profile, and a limit that did not stick leaves the game's own limiter in charge for the session.
|
||||
//
|
||||
// RTSS runs when its shared memory "RTSSSharedMemoryV2" carries the signature 'RTSS'; it limits this process once the
|
||||
@@ -53,7 +54,7 @@ static _Atomic int64_t want = -2; // millihertz from the pacer: >0 a li
|
||||
static _Atomic int active; // RTSS limits this process now
|
||||
static _Atomic int failed; // FAIL_*: RTSS is out of it for the rest of the run
|
||||
static int started;
|
||||
static char dll_path[MAX_PATH], profile[MAX_PATH];
|
||||
static char dll_path[MAX_PATH], profile[MAX_PATH], rtss_dir[MAX_PATH];
|
||||
static HMODULE dll;
|
||||
static EnumProfilesFn enum_profiles;
|
||||
static ProfileFn load_profile, save_profile, delete_profile;
|
||||
@@ -122,8 +123,17 @@ static int load_hooks(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The profile exists on its own (EnumProfiles: a comma-separated list of names).
|
||||
// The profile exists on its own: RTSS keeps it as Profiles\<name>.cfg in its folder. EnumProfiles would say the same
|
||||
// (a comma-separated list of names) but crashes this process: it walks Profiles\*.cfg with _findfirst and _findnext and
|
||||
// keeps the find handle in 32 bits. The handle points into the process heap, which here lies above 4 GB (the guest
|
||||
// address space takes the low part, memory.c mem_init), so _findnext gets a cut pointer and faults in ntdll writing to
|
||||
// it. NX2NAVI_RTSS_ENUM=1 calls EnumProfiles anyway, to test an RTSS that keeps the whole handle.
|
||||
static int profile_exists(void) {
|
||||
if (!rt_knob("RTSS_ENUM", "0")) {
|
||||
char path[MAX_PATH * 2];
|
||||
snprintf(path, sizeof path, "%s\\Profiles\\%s.cfg", rtss_dir, profile);
|
||||
return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
char list[8192];
|
||||
DWORD need = enum_profiles(list, sizeof list);
|
||||
list[sizeof list - 1] = 0;
|
||||
@@ -293,6 +303,7 @@ static void start(void) {
|
||||
return;
|
||||
}
|
||||
snprintf(dll_path, sizeof dll_path, "%s\\RTSSHooks64.dll", dir);
|
||||
snprintf(rtss_dir, sizeof rtss_dir, "%s", dir);
|
||||
if (GetFileAttributesA(dll_path) == INVALID_FILE_ATTRIBUTES) {
|
||||
rt_log("frame rate: RivaTuner Statistics Server's folder %s has no RTSSHooks64.dll; the game's own limiter", dir);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user