about summary refs log tree commit diff
path: root/nixpkgs/pkgs/games/shipwright/default.nix
blob: 182e2cf654aef5ebd33a36c206725abe54f86878 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
{ stdenv
, cmake
, lsb-release
, ninja
, lib
, fetchFromGitHub
, fetchurl
, makeDesktopItem
, python3
, libX11
, libXrandr
, libXinerama
, libXcursor
, libXi
, libXext
, glew
, boost
, SDL2
, SDL2_net
, pkg-config
, libpulseaudio
, libpng
, imagemagick
, requireFile

, oot ? rec {
    enable = true;
    variant = "debug";

    rom = requireFile {
      name = "oot-${variant}.z64";
      message = ''
        This nix expression requires that oot-${variant}.z64 is already part of the store.
        To get this file you can dump your Ocarina of Time's cartridge to a file,
        and add it to the nix store with nix-store --add-fixed sha1 <FILE>, or override the package:
          shipwright.override { oot = { enable = true; variant = "debug"; rom = path/to/oot-debug-mq.z64; } }

        The supported variants are:
         - debug: Ocarina of Time Debug PAL GC (not Master Quest)
         - pal-gc: Ocarina of Time PAL GameCube (may lead to crashes and instability)

        This is optional if you have imported an Ocarina of Time Master Quest ROM.
        If so, please set oot.enable to false and ootMq.enable to true.
        If both are enabled, Ship of Harkinian will be built with both ROMs.
      '';

      # From upstream: https://github.com/HarbourMasters/Shipwright/blob/e46c60a7a1396374e23f7a1f7122ddf9efcadff7/README.md#1-check-your-sha1
      sha1 = {
        debug = "cee6bc3c2a634b41728f2af8da54d9bf8cc14099";
        pal-gc = "0227d7c0074f2d0ac935631990da8ec5914597b4";
      }.${variant} or (throw "Unsupported romVariant ${variant}. Valid options are 'debug' and 'pal-gc'.");
    };
  }

, ootMq ? rec {
    enable = false;
    variant = "debug-mq";

    rom = requireFile {
      name = "oot-${variant}.z64";
      message = ''
        This nix expression requires that oot-${variant}.z64 is already part of the store.
        To get this file you can dump your Ocarina of Time Master Quest's cartridge to a file,
        and add it to the nix store with nix-store --add-fixed sha1 <FILE>, or override the package:
          shipwright.override { ootMq = { enable = true; variant = "debug-mq"; rom = path/to/oot-debug-mq.z64; } }

        The supported variants are:
         - debug-mq: Ocarina of Time Debug PAL GC MQ (Dungeons will be Master Quest)
         - debug-mq-alt: Alternate ROM, not produced by decompilation.

        This is optional if you have imported an Ocarina of Time ROM.
        If so, please set oot.enable to true and ootMq.enable to false.
        If both are enabled, Ship of Harkinian will be built with both ROMs.
      '';

      # From upstream: https://github.com/HarbourMasters/Shipwright/blob/e46c60a7a1396374e23f7a1f7122ddf9efcadff7/README.md#1-check-your-sha1
      sha1 = {
        debug-mq = "079b855b943d6ad8bd1eb026c0ed169ecbdac7da";
        debug-mq-alt = "50bebedad9e0f10746a52b07239e47fa6c284d03";
      }.${variant} or (throw "Unsupported mqRomVariant ${variant}. Valid options are 'debug-mq' and 'debug-mq-alt'.");
    };
  }
}:

let
  checkAttrs = attrs:
    let
      validAttrs = [ "enable" "rom" "variant" ];
    in
    lib.all (name: lib.elem name validAttrs) (lib.attrNames attrs);
in
assert (lib.assertMsg (checkAttrs oot) "oot must have the attributes 'enable' and 'rom', and none other");
assert (lib.assertMsg (checkAttrs ootMq) "ootMq must have the attributes 'enable' and 'rom', and none other");
assert (lib.assertMsg (oot.enable || ootMq.enable) "At least one of 'oot.enable' and 'ootMq.enable' must be true");

stdenv.mkDerivation rec {
  pname = "shipwright";
  version = "7.0.2";

  src = fetchFromGitHub {
    owner = "harbourmasters";
    repo = "shipwright";
    rev = version;
    hash = "sha256-2VCcczGWSvp6hk8FTA1/T1E1KkrrvWyOdkEw8eiYYnY=";
    fetchSubmodules = true;
  };

  # This would get fetched at build time otherwise, see:
  # https://github.com/HarbourMasters/Shipwright/blob/e46c60a7a1396374e23f7a1f7122ddf9efcadff7/soh/CMakeLists.txt#L736
  gamecontrollerdb = fetchurl {
    name = "gamecontrollerdb.txt";
    url = "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/c5b4df0e1061175cb11e3ebbf8045178339864a5/gamecontrollerdb.txt";
    hash = "sha256-2VFCsaalXoe+JYWCH6IbgjnLXNKxe0UqSyJNGZMn5Ko=";
  };

  nativeBuildInputs = [
    cmake
    ninja
    pkg-config
    lsb-release
    python3
    imagemagick
  ];

  buildInputs = [
    boost
    libX11
    libXrandr
    libXinerama
    libXcursor
    libXi
    libXext
    glew
    SDL2
    SDL2_net
    libpulseaudio
    libpng
  ];

  patches = [
    # These patches make soh look inside the nix store for data files (the controller database and the OTRs)
    ./lus-install-paths.patch
    ./soh-misc-otr-patches.patch
  ];

  cmakeFlags = [
    "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}/lib"
  ];

  dontAddPrefix = true;

  # Linking fails without this
  hardeningDisable = [ "format" ];

  postBuild = ''
    cp ${gamecontrollerdb} ${gamecontrollerdb.name}

    pushd ../OTRExporter
    ${lib.optionalString oot.enable "python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out ${oot.rom}"}
    ${lib.optionalString ootMq.enable "python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out ${ootMq.rom}"}
    popd
  '';

  preInstall = ''
    # Cmake likes it here for its install paths
    cp ../OTRExporter/soh.otr ..
  '';

  postInstall = ''
    mkdir -p $out/bin

    # Copy the extracted assets, required to be in the same directory as the executable
    ${lib.optionalString oot.enable "cp ../OTRExporter/oot.otr $out/lib"}
    ${lib.optionalString ootMq.enable "cp ../OTRExporter/oot-mq.otr $out/lib"}

    ln -s $out/lib/soh.elf $out/bin/soh
  '';

  desktopItems = [
    (makeDesktopItem {
      name = "soh";
      icon = "soh";
      exec = "soh";
      genericName = "Ship of Harkinian";
      desktopName = "soh";
      categories = [ "Game" ];
    })
  ];

  meta = with lib; {
    homepage = "https://github.com/HarbourMasters/Shipwright";
    description = "A PC port of Ocarina of Time with modern controls, widescreen, high-resolution, and more";
    longDescription = ''
      An PC port of Ocarina of Time with modern controls, widescreen, high-resolution and more, based off of decompilation.
      Note that you must supply an OoT rom yourself to use this package because propietary assets are extracted from it.

      You can change the game variant like this:
        shipwright.override { oot.enable = false; ootMq.enable = true }

      The default ROM variants for Oot and OotMq are debug and debug-mq respectively.
      If you have a pal-gc rom, you should override like this:
        shipwright.override { oot = { enable = true; variant = "pal-gc"; rom = path/to/oot-pal-gc.z64; } }

      The supported Oot variants are:
       - debug: Ocarina of Time Debug PAL GC (not Master Quest)
       - pal-gc: Ocarina of Time PAL GameCube (may lead to crashes and instability)

      The supported OotMq variants are:
       - debug-mq: Ocarina of Time Debug PAL GC MQ (Dungeons will be Master Quest)
       - debug-mq-alt: Alternate ROM, not produced by decompilation.
    '';
    mainProgram = "soh";
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ ivar j0lol ];
    license = with licenses; [
      # OTRExporter, OTRGui, ZAPDTR, libultraship
      mit
      # Ship of Harkinian itself
      unfree
    ];
  };
}