From 12d6a88c605ce91e9077df1fed4aa9c52cecde49 Mon Sep 17 00:00:00 2001 From: bicarus-dev <202771338+bicarus-dev@users.noreply.github.com> Date: Sun, 30 Nov 2025 16:13:34 -0800 Subject: [PATCH] iidx: turn off camera access by default (#428) ## Link to GitHub Issue, if one exists For #345 Similar idea as https://github.com/spice2x/spice2x.github.io/pull/350 ## Description of change Disable camera access by default by setting `CONNECT_CAMERA` environment var to 0 before launching. This was one of those "required" things people clicked on, but now it's done automatically to reduce friction for new users. On cab setups (i.e., running without -iidx module), cameras will remain on, unless user overrides it. On franken setups (partial I/O) - user will need to specify what they want via the new option, we can't guess correctly. ## Testing --- src/spice2x/games/iidx/iidx.cpp | 30 +++++++++++++++++------- src/spice2x/games/iidx/iidx.h | 2 +- src/spice2x/games/iidx/legacy_camera.cpp | 2 ++ src/spice2x/launcher/launcher.cpp | 23 +++++++++++++++--- src/spice2x/launcher/options.cpp | 19 ++++++++++++++- src/spice2x/launcher/options.h | 1 + 6 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/spice2x/games/iidx/iidx.cpp b/src/spice2x/games/iidx/iidx.cpp index 9a193f4..0e4baa3 100644 --- a/src/spice2x/games/iidx/iidx.cpp +++ b/src/spice2x/games/iidx/iidx.cpp @@ -53,7 +53,7 @@ namespace games::iidx { // settings bool FLIP_CAMS = false; - bool DISABLE_CAMS = false; + std::optional DISABLE_CAMS; bool TDJ_CAMERA = false; bool TDJ_CAMERA_PREFER_16_9 = true; bool TDJ_MODE = false; @@ -334,11 +334,6 @@ namespace games::iidx { wintouchemu::INJECT_MOUSE_AS_WM_TOUCH = true; wintouchemu::hook_title_ends("beatmania IIDX", "main", avs::game::DLL_INSTANCE); } - - // prevent crash on TDJ mode without correct DLL - if (!GetModuleHandle("nvcuda.dll")) { - DISABLE_CAMS = true; - } } // insert BI2X hooks @@ -399,7 +394,10 @@ namespace games::iidx { "RegQueryValueExA", RegQueryValueExA_hook, avs::game::DLL_INSTANCE); // check if cam hook should be enabled - if (!DISABLE_CAMS) { + if (!DISABLE_CAMS.has_value()) { + log_fatal("iidx", "assertion failure - DISABLE_CAMS not set during attach"); + } + if (!DISABLE_CAMS.value()) { init_legacy_camera_hook(FLIP_CAMS); } @@ -409,15 +407,31 @@ namespace games::iidx { void IIDXGame::pre_attach() { Game::pre_attach(); + auto options = games::get_options(eamuse_get_game()); // environment variables must be set before the DLL is loaded as the VC++ runtime copies all // environment variables at startup if (SCREEN_MODE.has_value()) { + log_misc("iidx", "SCREEN_MODE env var set to {}", SCREEN_MODE.value().c_str()); SetEnvironmentVariable("SCREEN_MODE", SCREEN_MODE.value().c_str()); } + // check for cab camera access for the second time (first time was in launcher.cpp) + // this time, we are inside -iidx module hook, which means the user is likely NOT on a cab + // therefore, start with cams OFF by default, and allow user to forcibly override to ON + if (!games::iidx::DISABLE_CAMS.has_value()) { + games::iidx::DISABLE_CAMS = true; + if (options->at(launcher::Options::IIDXCabCamAccess).is_active() && + options->at(launcher::Options::IIDXCabCamAccess).value_text() == "on") { + games::iidx::DISABLE_CAMS = false; + } + if (games::iidx::DISABLE_CAMS.value()) { + log_misc("iidx", "CONNECT_CAMERA env var set to 0"); + SetEnvironmentVariable("CONNECT_CAMERA", "0"); + } + } + // windowed subscreen, enabled by default, unless turned off by user - auto options = games::get_options(eamuse_get_game()); if (GRAPHICS_WINDOWED && !options->at(launcher::Options::spice2x_IIDXNoSub).value_bool()) { GRAPHICS_IIDX_WSUB = true; } diff --git a/src/spice2x/games/iidx/iidx.h b/src/spice2x/games/iidx/iidx.h index 0e92368..623ecf4 100644 --- a/src/spice2x/games/iidx/iidx.h +++ b/src/spice2x/games/iidx/iidx.h @@ -14,7 +14,7 @@ namespace games::iidx { // settings extern bool FLIP_CAMS; - extern bool DISABLE_CAMS; + extern std::optional DISABLE_CAMS; extern bool TDJ_CAMERA; extern bool TDJ_CAMERA_PREFER_16_9; extern std::optional TDJ_CAMERA_OVERRIDE; diff --git a/src/spice2x/games/iidx/legacy_camera.cpp b/src/spice2x/games/iidx/legacy_camera.cpp index 7ad92fc..40ee190 100644 --- a/src/spice2x/games/iidx/legacy_camera.cpp +++ b/src/spice2x/games/iidx/legacy_camera.cpp @@ -213,6 +213,8 @@ namespace games::iidx { } void init_legacy_camera_hook(bool flip_cams) { + log_info("iidx::cam", "initializing legacy camera hook"); + should_flip_cams = flip_cams; // camera media framework hook diff --git a/src/spice2x/launcher/launcher.cpp b/src/spice2x/launcher/launcher.cpp index 5391aba..cfe4a19 100644 --- a/src/spice2x/launcher/launcher.cpp +++ b/src/spice2x/launcher/launcher.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -458,17 +459,26 @@ int main_implementation(int argc, char *argv[]) { if (options[launcher::Options::IIDXCameraOrderFlip].value_bool()) { games::iidx::FLIP_CAMS = true; } + + // IIDX CONNECT_CAMERA logic here for cases where user is running without -iidx module + // for now, we assume that user may be running on a cab + // (games::iidx::DISABLE_CAMS starts out as false unless user overrides) + // we will check again in IIDX module with a different default + assert(!games::iidx::DISABLE_CAMS.has_value()); if (options[launcher::Options::IIDXDisableCameras].value_bool()) { games::iidx::DISABLE_CAMS = true; } + if (options[launcher::Options::IIDXCabCamAccess].is_active() && + options[launcher::Options::IIDXCabCamAccess].value_text() == "off") { + games::iidx::DISABLE_CAMS = true; + } if (options[launcher::Options::IIDXCamHook].value_bool()) { games::iidx::TDJ_CAMERA = true; // Disable legacy behaviour to avoid conflict games::iidx::DISABLE_CAMS = true; } - if (games::iidx::DISABLE_CAMS) { - SetEnvironmentVariable("CONNECT_CAMERA", "0"); - } + // CONNECT_CAMERA env var will be set once logging is enabled + if (options[launcher::Options::IIDXCamHookOverride].is_active()) { games::iidx::TDJ_CAMERA_OVERRIDE = options[launcher::Options::IIDXCamHookOverride].value_text(); } @@ -1348,6 +1358,13 @@ int main_implementation(int argc, char *argv[]) { GRAPHICS_FS_ORIENTATION_SWAP = true; } + if (games::iidx::DISABLE_CAMS.has_value() && + games::iidx::DISABLE_CAMS.value() && + !cfg::CONFIGURATOR_STANDALONE) { + log_misc("launcher", "CONNECT_CAMERA env var set to 0"); + SetEnvironmentVariable("CONNECT_CAMERA", "0"); + } + // deleted options if (options[launcher::Options::OpenKFControl].value_bool() && !cfg::CONFIGURATOR_STANDALONE) { log_fatal("launcher", "KFControl has been removed from spice2x; please use an older version."); diff --git a/src/spice2x/launcher/options.cpp b/src/spice2x/launcher/options.cpp index 02d1c1d..4948cc9 100644 --- a/src/spice2x/launcher/options.cpp +++ b/src/spice2x/launcher/options.cpp @@ -456,13 +456,30 @@ static const std::vector OPTION_DEFINITIONS = { .category = "Game Options (Advanced)", }, { - .title = "IIDX Disable Cameras", + // IIDXDisableCameras + .title = "IIDX Disable Cameras (DEPRECATED - no longer needed)", .name = "iidxdisablecams", .desc = "Disables cameras", .type = OptionType::Bool, + .hidden = true, .game_name = "Beatmania IIDX", .category = "Game Options", }, + { + // IIDXCabCamAccess + .title = "IIDX Use Official AC Cams", + .name = "iidxcabcams", + .desc = "For IIDX25+, allow direct access to cameras from real arcade cabinets. " + "Only turn this on if you have OFFICIAL arcade cameras connected to the correct USB ports. Default: auto", + .type = OptionType::Enum, + .game_name = "Beatmania IIDX", + .category = "Game Options (Advanced)", + .elements = { + {"auto", ""}, + {"off", ""}, + {"on", ""} + }, + }, { // IIDXCamHook .title = "IIDX Cam Hook", diff --git a/src/spice2x/launcher/options.h b/src/spice2x/launcher/options.h index 6599da7..cc06d40 100644 --- a/src/spice2x/launcher/options.h +++ b/src/spice2x/launcher/options.h @@ -55,6 +55,7 @@ namespace launcher { LoadIIDXModule, IIDXCameraOrderFlip, IIDXDisableCameras, + IIDXCabCamAccess, IIDXCamHook, IIDXCamHookRatio, IIDXCamHookOverride,