about summary refs log tree commit diff
path: root/pkgs/games/humblebundle/opus-magnum.nix
blob: f7b2a24433ee1797f338d77f243fd5e6696bc898 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{ stdenv, lib, buildGame, fetchHumbleBundle, makeWrapper, mono50
, SDL2, SDL2_image, SDL2_mixer, libvorbis
}:

buildGame rec {
  name = "opus-magnum-${version}";
  version = "20180111";

  src = fetchHumbleBundle {
    machineName = "opus_magnum_4vffp_linux_Z9zWf";
    suffix = "zip";
    md5 = "8bfc49528b69630f8df983fd545518bb";
  };

  arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86";

  nativeBuildInputs = [ makeWrapper ];

  buildPhase = let
    dllmap = {
      SDL2 = "${SDL2}/lib/libSDL2.so";
      SDL2_image = "${SDL2_image}/lib/libSDL2_image.so";
      SDL2_mixer = "${SDL2_mixer}/lib/libSDL2_mixer.so";
      libvorbisfile-3 = "${libvorbis}/lib/libvorbisfile.so";
    };
  in lib.concatStrings (lib.mapAttrsToList (dll: target: ''
    sed -i -e '/<dllmap.*dll="${dll}\.dll".*os="linux"/ {
      s!target="[^"]*"!target="${target}"!
    }' Lightning.exe.config
  '') dllmap);

  installPhase = ''
    mkdir -p "$out/bin" "$out/share/opus-magnum" "$out/libexec/opus-magnum"
    cp -rvt "$out/share/opus-magnum" Content PackedContent
    cp -rvt "$out/libexec/opus-magnum" Lightning.exe* Ionic.Zip.Reduced.dll

    makeWrapper ${lib.escapeShellArg mono50}/bin/mono "$out/bin/opus-magnum" \
      --add-flags "$out/libexec/opus-magnum/Lightning.exe" \
      --run "cd '$out/share/opus-magnum'"
  '';

  sandbox.paths.required = [ "$XDG_DATA_HOME/Opus Magnum" "$HOME/Desktop" ];
}