From 11bd13327b59ea2d81132f1881b65dcbe776f464 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 5 Jul 2018 23:01:56 +0200 Subject: gomes/gog: Add Settlers 2 Gold edition using RTTR This packages "Return to the Roots" along with the game data fetched from GOG. So basically it's RTTR with a "RTTR_GAMEDIR" set to the files extracted from the GOG version. In reality it's a bit more involved as we need to patch a few things and also make sure that the sounds are built via Nix rather to be generated at runtime. The RTTR standard procedure would be to just install RTTR and you put your game data somewhere in /usr/share (or any other place you've configured) and on first startup it's generating the SOUND.LST file. We want all the games in Vuizvui to be completely dispensible so that the persistent files are *only* in $XDG_DATA_HOME/settlers2, so I've made sure that everything is baked in at *build* time instead. Signed-off-by: aszlig --- pkgs/games/gog/default.nix | 1 + pkgs/games/gog/settlers2.nix | 103 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 pkgs/games/gog/settlers2.nix (limited to 'pkgs/games') diff --git a/pkgs/games/gog/default.nix b/pkgs/games/gog/default.nix index 38ebf489..eaf7e28a 100644 --- a/pkgs/games/gog/default.nix +++ b/pkgs/games/gog/default.nix @@ -16,6 +16,7 @@ let overload = callPackage ./overload.nix {}; party-hard = callPackage ./party-hard.nix {}; satellite-reign = callPackage ./satellite-reign.nix {}; + settlers2 = callPackage ./settlers2.nix {}; stardew-valley = callPackage ./stardew-valley.nix {}; stardew-valley-beta = lib.lowPrio (callPackage ./stardew-valley.nix { beta = true; diff --git a/pkgs/games/gog/settlers2.nix b/pkgs/games/gog/settlers2.nix new file mode 100644 index 00000000..1d4497b9 --- /dev/null +++ b/pkgs/games/gog/settlers2.nix @@ -0,0 +1,103 @@ +{ stdenv, lib, buildSandbox, fetchGog, innoextract, bchunk, p7zip + +, fetchFromGitHub, cmake, gettext, boost, miniupnpc, bzip2 +, SDL, SDL_mixer, libpulseaudio, alsaLib, libGL, lua5_2 +}: + +let + gameData = stdenv.mkDerivation rec { + name = "settlers2-game-data-${version}"; + version = "1.31"; + + src = fetchGog { + productId = 1207658786; + downloadName = "en1installer0"; + sha256 = "19c88h972ydfpdbay61lz6pi4gnlm2lq5dcya5im9mmlin2nvyr7"; + }; + + unpackCmd = toString [ + "innoextract" + "--include" "/app/DATA" + "--include" "/app/GFX" + "-m" "\"$curSrc\"" + ]; + + nativeBuildInputs = [ innoextract ]; + phases = [ "unpackPhase" "patchPhase" "installPhase" ]; + + installPhase = '' + mkdir -p "$out" + mv -t "$out" DATA GFX + ''; + }; + +in buildSandbox (stdenv.mkDerivation rec { + name = "settlers2-${version}"; + version = "20180702"; + + src = fetchFromGitHub { + repo = "s25client"; + owner = "Return-To-The-Roots"; + rev = "27721e58fbaedd2be9489d1926a2fc9d6387f372"; + sha256 = "051saafh2scdi284gl16z2nqwxq71wnr6fsbs189wvm5w2ly2y9r"; + fetchSubmodules = true; + }; + + postPatch = '' + # The build process tries to figure out the version from .git, so let's + # use the commit from the "src" attribute. + mkdir .git + echo ${lib.escapeShellArg src.rev} > .git/HEAD + + # This tries to mix the LUA version in contrib with the one in nixpkgs. + rm -rf contrib/lua + + # We already bake in the gameData store path, so there is no need to put a + # placeholder in there (which will fail anyway, because it can't write to + # gameData). + sed -i -e '/install.*RTTR_S2_PLACEHOLDER_PATH/d' CMakeLists.txt + + # SOUND.LST is generated in postInstall, so let's correct the path. + substituteInPlace rttrConfig/files.h \ + --replace '/LSTS/SOUND.LST' '/LSTS/SOUND.LST' + + # Use "$XDG_DATA_HOME/settlers2" instead of "$HOME/.s25rttr". + sed -i -e 's!getPathFromEnvVar("HOME")!${ + "getPathFromEnvVar(\"XDG_DATA_HOME\");" + + "if (homePath.empty()) homePath = " + + "getPathFromEnvVar(\"HOME\") / \".local\" / \"share\"" + }!' libutil/src/System.cpp + sed -i -e '1i #define RTTR_SETTINGSDIR "~/settlers2"' \ + rttrConfig/RttrConfig.cpp + ''; + + cmakeFlags = [ "-DRTTR_GAMEDIR=${gameData}" ]; + + nativeBuildInputs = [ cmake gettext ]; + buildInputs = [ + boost miniupnpc SDL SDL_mixer bzip2 libpulseaudio alsaLib libGL lua5_2 + ]; + + postInstall = '' + # Rename the game binaries to match up the derivation name. + mv "$out/bin/s25client" "$out/bin/settlers2" + mv "$out/bin/s25edit" "$out/bin/settlers2editor" + + # We don't want the updater and store paths are immutable anyway. + rm "$out/bin/rttr.sh" + + # Convert sounds from game data, which is usually done at runtime but we + # can avoid it because we already have the game data available. + "$out/libexec/s25rttr/sound-convert" \ + -s "$out/share/s25rttr/RTTR/sound.scs" \ + -f ${lib.escapeShellArg gameData}/DATA/SOUNDDAT/SOUND.LST \ + -t "$out/share/s25rttr/RTTR/LSTS/SOUND.LST" + + # The sound converter and resampler now are no longer needed. + rm "$out/libexec/s25rttr/sound-convert" "$out/libexec/s25rttr/s-c_resample" + rmdir "$out/libexec/s25rttr" "$out/libexec" + ''; +}) { + paths.required = [ "$XDG_DATA_HOME/settlers2" ]; + paths.runtimeVars = [ "LD_LIBRARY_PATH" "LOCALE_ARCHIVE" ]; +} -- cgit 1.4.1