about summary refs log tree commit diff
path: root/pkgs/games
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-06-09 05:22:56 +0200
committeraszlig <aszlig@nix.build>2018-06-09 05:31:28 +0200
commit5d98818c8e2e7cdf2bfe0dbd0c2a8fd069e9acb9 (patch)
treeb2b8f05c987a3d0e332abad60e4c8edc192f2d3f /pkgs/games
parentc4429caf0224e928b34c8acc1c3d17e0b2a9673a (diff)
games/gog: Add World of Xeen
This is the result when you combine Might and Magic 4 and 5 and ScummVM
very recently got support for that. See http://scummvm.org/news/20180501
for the announcement.

So we're wrapping the game using latest git version of ScummVM.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/games')
-rw-r--r--pkgs/games/gog/default.nix1
-rw-r--r--pkgs/games/gog/xeen.nix123
2 files changed, 124 insertions, 0 deletions
diff --git a/pkgs/games/gog/default.nix b/pkgs/games/gog/default.nix
index 3e86c8a0..2379cd26 100644
--- a/pkgs/games/gog/default.nix
+++ b/pkgs/games/gog/default.nix
@@ -16,6 +16,7 @@ let
     stardew-valley-beta = lib.lowPrio (callPackage ./stardew-valley.nix {
       beta = true;
     });
+    xeen = callPackage ./xeen.nix {};
   };
 in {
   options.gog = {
diff --git a/pkgs/games/gog/xeen.nix b/pkgs/games/gog/xeen.nix
new file mode 100644
index 00000000..93a7beb8
--- /dev/null
+++ b/pkgs/games/gog/xeen.nix
@@ -0,0 +1,123 @@
+{ lib, stdenv, buildSandbox, fetchGog, innoextract, bchunk, p7zip
+, scummvm, fetchFromGitHub
+, runCommand, xvfb_run
+
+, showItemCosts ? true
+, durableArmor ? true
+}:
+
+let
+  version = "2.1.0.43";
+
+  gameData = stdenv.mkDerivation {
+    name = "world-of-xeen-gamedata-${version}";
+    inherit version;
+
+    src = fetchGog {
+      name = "setup_mm45_${version}.exe";
+      productId = 1207661233;
+      downloadName = "en1installer1";
+      sha256 = "0jv9k5rcapqlk61pawa5l4m34iwllx8j6cfz69gl092h04fvfqki";
+    };
+
+    unpackCmd = toString [
+      "${innoextract}/bin/innoextract"
+      "--include" "app/game1.gog"
+      "--include" "app/music"
+      "-L" "-m" "\"$curSrc\""
+    ];
+
+    patchPhase = ''
+      cat > game1.inst <<EOF
+      FILE "game1.gog" BINARY
+      TRACK 01 MODE1/2352
+        INDEX 01 00:00:00
+      EOF
+    '';
+
+    buildPhase = ''
+      ${bchunk}/bin/bchunk game1.gog game1.inst game_cd
+      ${p7zip}/bin/7z x game_cd01.iso
+    '';
+
+    installPhase = ''
+      for i in [Gg][Aa][Mm][Ee]/*.[Cc][Cc]; do
+        filename="$(basename "$i")"
+        install -vD -m 0644 "$i" "$out/''${filename,,}"
+      done
+
+      for i in music/*.ogg; do
+        filename="$(basename "$i")"
+        install -vD -m 0644 "$i" "$out/''${filename/xeen/track}"
+      done
+    '';
+
+    doInstallCheck = true;
+
+    installCheckPhase = ''
+      ccFileNo="$(ls -1 "$out/"*.cc | wc -l)"
+      if [ "$ccFileNo" -ne 3 ]; then
+        echo "Expected three .cc files, but got $ccFileNo." >&2
+        ls -l "$out"
+        exit 1
+      fi
+      trackFileNo="$(ls -1 "$out/"track[0-9][0-9].ogg | wc -l)"
+      if [ "$trackFileNo" -ne 59 ]; then
+        echo "Expected 59 track[0-9][0-9].ogg files, but got $trackFileNo." >&2
+        ls -l "$out"
+        exit 1
+      fi
+    '';
+  };
+
+  latestScummVM = scummvm.overrideAttrs (drv: {
+    src = fetchFromGitHub {
+      owner = "scummvm";
+      repo = "scummvm";
+      rev = "7edac197e4aa9846b71f398d9c5a4d56c5b7c34e";
+      sha256 = "0vj0widczlmvbnv6qzfsh14mhil3p2rbfpj86fb4syrbb8qrc01g";
+    };
+
+    configureFlags = (drv.configureFlags or []) ++ [
+      "--disable-all-engines" "--enable-engine=xeen"
+    ];
+
+    # Current Git version has an --enable-static option so the stdenv setup
+    # thinks that there is --disable-static as well, which is not.
+    dontDisableStatic = true;
+  });
+
+  injectOption = c: o: lib.optionalString c "-e '/^\\[worldof/a ${o}=true'";
+
+  scummVmConfig = runCommand "scummvm-xeen.ini" {
+    nativeBuildInputs = [ xvfb_run latestScummVM ];
+    inherit gameData;
+  } ''
+    xvfb-run scummvm -p "$gameData" -a
+    sed -e '/^\[scummvm\]/a enable_unsupported_game_warning=false' \
+      ${injectOption showItemCosts "ShowItemCosts"} \
+      ${injectOption durableArmor "DurableArmor"} \
+      scummvm.ini > "$out"
+  '';
+
+  unsandboxed = runCommand "word-of-xeen-${version}" {
+    scummVmCmd = "${latestScummVM}/bin/scummvm";
+    dataHome = "\"\${XDG_DATA_HOME:-$HOME/.local/share}/xeen\"";
+    inherit (stdenv) shell;
+    scummVmArgs = lib.concatMapStringsSep " " lib.escapeShellArg [
+      "-c" scummVmConfig
+    ];
+  } ''
+    mkdir -p "$out/bin"
+    cat > "$out/bin/xeen" <<EOF
+    #!$shell
+    exec $scummVmCmd $scummVmArgs --savepath=$dataHome "\$@" worldofxeen-cd
+    EOF
+    chmod +x "$out/bin/xeen"
+    cat "$out/bin/xeen"
+  '';
+
+in buildSandbox unsandboxed {
+  paths.required = [ "$XDG_DATA_HOME/xeen" ];
+  paths.runtimeVars = [ "LD_LIBRARY_PATH" ];
+}