From 142861f957db6eb88a33ed68f275ef4d3c80fea6 Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Sat, 11 Oct 2025 23:16:09 -0700 Subject: [PATCH] feat(mewtris): battle.net handled sanely-ish (60s timeout???) --- modules/nixos/mewtris.nix | 42 +++++++++++++++++-------- nixos/profiles/gaming/bnet_script.bat | 17 +++++++++++ nixos/profiles/gaming/wine.nix | 44 ++++++++++++++++++--------- 3 files changed, 76 insertions(+), 27 deletions(-) create mode 100755 nixos/profiles/gaming/bnet_script.bat diff --git a/modules/nixos/mewtris.nix b/modules/nixos/mewtris.nix index c16e8698..b9f96d96 100644 --- a/modules/nixos/mewtris.nix +++ b/modules/nixos/mewtris.nix @@ -4,13 +4,15 @@ lib, std, ... -}: { +}: let + inherit (lib.meta) getExe'; +in { options.mewtris = let - inherit (lib.types) path attrsOf submodule str nullOr enum either package bool lines listOf; + inherit (lib.types) path attrsOf submodule str nullOr enum either package lines listOf; inherit (lib.options) mkEnableOption mkOption; - inherit (lib.meta) getExe'; in { enable = mkEnableOption "Enable mewtris"; + createDesktopItems = mkEnableOption "Create XDG desktop items for starting, stopping and killing all the installed mewtris games, for use with dmenu or wofi for example"; umuLauncher = mkOption { description = "umu-launcher package"; type = package; @@ -83,11 +85,6 @@ type = listOf str; default = []; }; - battleNetGame = mkOption { - description = "Is this a battle.net game? Not used for battle.net itself!"; - type = bool; - default = false; - }; prefixArch = mkOption { description = "Wine prefix architecture"; type = enum [ @@ -179,9 +176,6 @@ ])}" ${cfg.globalPrerun} ${config.prerun} - ${optionalString config.battleNetGame '' - "${protonLauncher}" "${config.gameFolder}/Battle.net Launcher.exe" & - ''} cd "${config.gameFolder}" "${protonLauncher}" "${config.gameExecutable}" ${escapeShellArgs config.gameArguments} ''; @@ -196,13 +190,35 @@ }; config = let cfg = config.mewtris; - inherit (lib.lists) singleton concatMap; + inherit (lib.lists) singleton concatMap concatLists; inherit (lib.strings) replaceStrings; - inherit (lib.attrsets) mapAttrs nameValuePair mapAttrs' attrNames attrValues; + inherit (lib.attrsets) mapAttrs nameValuePair mapAttrs' attrNames attrValues mapAttrsToList; inherit (lib.modules) mkIf; inherit (std.set) merge; in mkIf cfg.enable { + environment.systemPackages = mkIf cfg.createDesktopItems (concatLists (mapAttrsToList (_k: v: let + start = pkgs.makeDesktopItem { + inherit (v) name; + desktopName = v.long_name; + exec = "${getExe' pkgs.systemd "systemctl"} --user start ${v.name}"; + }; + stop = pkgs.makeDesktopItem { + name = "${v.name}-stop"; + desktopName = "Stop ${v.long_name}"; + exec = "${getExe' pkgs.systemd "systemctl"} --user stop ${v.name}"; + }; + kill = pkgs.makeDesktopItem { + name = "${v.name}-kill"; + desktopName = "Kill ${v.long_name}"; + exec = "${getExe' pkgs.systemd "systemctl"} --user kill --signal=SIGKILL ${v.name}"; + }; + in [ + start + stop + kill + ]) + config.mewtris.games)); systemd.user.services = mapAttrs' (_k: v: nameValuePair v.name { description = v.long_name; diff --git a/nixos/profiles/gaming/bnet_script.bat b/nixos/profiles/gaming/bnet_script.bat new file mode 100755 index 00000000..42eaa24a --- /dev/null +++ b/nixos/profiles/gaming/bnet_script.bat @@ -0,0 +1,17 @@ +@echo on +set BNET_DIR=%1 +set BNET_EXE=%~2 +set GAME=%3 + +echo "Setting UTF-8..." +chcp 65001 > nul + +echo "Launching Battle.net..." +cd /d %BNET_DIR% +start /b %BNET_EXE% --in-process-gpu + +timeout /t 60 /nobreak > NUL + +echo "Launching game within Battle.net..." +start /b %BNET_EXE% --exec="launch %GAME%" +REM exit diff --git a/nixos/profiles/gaming/wine.nix b/nixos/profiles/gaming/wine.nix index e8cca0ee..62d4af41 100644 --- a/nixos/profiles/gaming/wine.nix +++ b/nixos/profiles/gaming/wine.nix @@ -9,9 +9,11 @@ cfg = config.mewtris; in { mewtris = let + inherit (lib.strings) concatStringsSep; gameStorage = "/home/kat/Games"; in { enable = true; + createDesktopItems = true; inherit gameStorage; runnerVariants = { PROTON_CACHYOS = "${inputs.chaotic.packages.${pkgs.system}.proton-cachyos_x86_64_v3.out}/bin"; @@ -21,7 +23,15 @@ in { runnerEnvironments = { common = { PROTON_LOG = builtins.toString 1; - WINEDEBUG = "+warn"; + WINEDEBUG = concatStringsSep "," [ + "+warn" + "+timestamp" + "+pid" + "+tid" + "+seh" + "+debugstr" + "+module" + ]; WINEUSERSANDBOX = builtins.toString 1; }; dxvk = { @@ -38,9 +48,7 @@ in { __GL_SHADER_DISK_CACHE = builtins.toString 1; __GL_SHADER_DISK_CACHE_PATH = builtins.placeholder "prefix"; }; - mangohud = let - inherit (lib.strings) concatStringsSep; - in { + mangohud = { MANGOHUD = builtins.toString 1; MANGOHUD_CONFIG = concatStringsSep "," [ "no_display" @@ -91,18 +99,24 @@ in { battlenet = { long_name, launchArg, - }: (protonCommon - // rec { - inherit long_name; - battleNetGame = false; - prefixFolder = gameStorage + "/battlenet"; - gameFolder = prefixFolder + "/drive_c/Program Files (x86)/Battle.net"; - gameExecutable = gameFolder + "/Battle.net.exe"; + }: let + prefixFolder = gameStorage + "/battlenet"; + gameFolder' = "C:\\Program Files (x86)\\Battle.net"; + gameExecutable' = "Battle.net.exe"; + in + protonCommon + // { + inherit long_name prefixFolder; + gameFolder = prefixFolder; + gameExecutable = "./drive_c/cmd.exe"; gameArguments = [ - "--in-process-gpu" - "--exec=\"launch ${launchArg}\"" + "/k" + "C:/script.bat" + gameFolder' + gameExecutable' + launchArg ]; - }); + }; vn = { long_name, vnDir, @@ -257,6 +271,8 @@ in { # games; home-manager.users.kat.home.file = { + "Games/battlenet/drive_c/script.bat".source = ./bnet_script.bat; + "Games/battlenet/drive_c/cmd.exe".source = ./reactos_cmd.exe; # https://learnjapanese.moe/vn-linux/ "Games/VNs/drive_c/script.bat".source = ./vn_script.bat; "Games/VNs/drive_c/cmd.exe".source = ./reactos_cmd.exe;