Unverified Commit a13c8b87 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

banjorecomp: init at 1.0.1 (#483692)

parents 6678b182 d05d7819
Loading
Loading
Loading
Loading
+159 −0
Original line number Diff line number Diff line
{
  lib,
  banjobaserom ? null,
  requireFile,
  fetchFromGitHub,
  llvmPackages_21,
  cmake,
  copyDesktopItems,
  installShellFiles,
  makeWrapper,
  ninja,
  pkg-config,
  wrapGAppsHook3,
  SDL2,
  gtk3,
  vulkan-loader,
  makeDesktopItem,
  n64recomp,
  directx-shader-compiler,
  bk_rom_compressor,
}:

let

  baseRom =
    if banjobaserom != null then
      banjobaserom
    else
      requireFile {
        name = "baserom.us.v10.z64";
        message = ''
          banjorecomp only supports the US 1.0 version of Banjo-Kazooie.
          Please dump your copy and rename it to baserom.us.v10.z64
          and add it to the nix store using
          nix-store --add-fixed sha256 baserom.us.v10.z64
          See https://dumping.guide/carts/nintendo/n64 for more details.
        '';
        hash = "sha256-WYdYNbmlEouwBUMVp/kp4gccIAHlKNcL9UPh1mgObv8=";
      };

in

llvmPackages_21.stdenv.mkDerivation (finalAttrs: {
  pname = "banjorecomp";
  version = "1.0.1";

  src = fetchFromGitHub {
    owner = "BanjoRecomp";
    repo = "BanjoRecomp";
    tag = "v${finalAttrs.version}";
    hash = "sha256-QIiSjwA0iyoGTaeKANah6WhTUwPGXv1qR26kTdg7OqU=";
    fetchSubmodules = true;
  };

  strictDeps = true;
  __structuredAttrs = true;

  nativeBuildInputs = [
    cmake
    copyDesktopItems
    installShellFiles
    llvmPackages_21.lld
    makeWrapper
    ninja
    pkg-config
    wrapGAppsHook3
  ];

  buildInputs = [
    SDL2
    gtk3
    vulkan-loader
  ];

  desktopItems = [
    (makeDesktopItem {
      name = "BanjoRecompiled";
      icon = "BanjoRecompiled";
      exec = "BanjoRecompiled";
      comment = "Recompilation of Banjo-Kazooie";
      desktopName = "BanjoRecompiled";
      categories = [ "Game" ];
    })
  ];

  preConfigure = ''
    ln -s ${baseRom} ./baserom.us.v10.z64
    cp ${n64recomp}/bin/* .
    cp ${bk_rom_compressor}/bin/* .

    ./bk_rom_decompress baserom.us.v10.z64 banjo.us.v10.decompressed.z64

    ./N64Recomp banjo.us.rev0.toml
    ./RSPRecomp n_aspMain.us.rev0.toml

    substituteInPlace lib/rt64/CMakeLists.txt \
      --replace-fail "\''${PROJECT_SOURCE_DIR}/src/contrib/dxc/lib/x64" "${directx-shader-compiler}/lib/" \
      --replace-fail "\''${PROJECT_SOURCE_DIR}/src/contrib/dxc/bin/x64/dxc-linux" "${directx-shader-compiler}/bin/dxc" \
      --replace-fail "\''${PROJECT_SOURCE_DIR}/src/contrib/dxc/inc" "${directx-shader-compiler.src}/include/dxc"

    substituteInPlace CMakeLists.txt \
      --replace-fail "\''${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/x64" "${directx-shader-compiler}/lib/" \
      --replace-fail "\''${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/x64/dxc-linux" "${directx-shader-compiler}/bin/dxc"
  '';

  # This is required or else nothing will build
  hardeningDisable = [
    "format"
    "pic"
    "stackprotector"
    "zerocallusedregs"
  ];

  installPhase = ''
    runHook preInstall

    installBin BanjoRecompiled
    install -Dm644 -t $out/share ../recompcontrollerdb.txt
    install -Dm644 ../icons/app.png $out/share/icons/hicolor/512x512/apps/BanjoRecompiled.png
    cp -r ../assets $out/share/
    ln -s $out/share/recompcontrollerdb.txt $out/bin/recompcontrollerdb.txt
    ln -s $out/share/assets $out/bin/assets

    install -Dm644 -t $out/share/licenses/banjorecomp ../COPYING
    install -Dm644 -t $out/share/licenses/banjorecomp/N64ModernRuntime ../lib/N64ModernRuntime/COPYING
    install -Dm644 -t $out/share/licenses/banjorecomp/rt64 ../lib/rt64/LICENSE

    runHook postInstall
  '';

  preFixup = ''
    gappsWrapperArgs+=(
       --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ vulkan-loader ]}
     )
  '';

  # The game will segfault when not run from the same directory as the binary.
  postFixup = ''
    wrapProgram $out/bin/BanjoRecompiled --chdir "$out/bin/"
  '';

  meta = {
    description = "PC Port of Banjo-Kazooie made using N64: Recompiled";
    homepage = "https://github.com/BanjoRecomp/BanjoRecomp";
    license = with lib.licenses; [
      # BanjoRecompiled, N64ModernRuntime
      gpl3Only

      # RT64
      mit

      # reverse engineering
      unfree
    ];
    maintainers = with lib.maintainers; [ qubitnano ];
    mainProgram = "BanjoRecompiled";
    platforms = [ "x86_64-linux" ];
  };
})
+32 −0
Original line number Diff line number Diff line
{
  lib,
  rustPlatform,
  fetchFromGitHub,
  rarezip,
}:

rustPlatform.buildRustPackage {
  pname = "bk_rom_compressor";
  version = "0-unstable-2024-09-08";

  src = fetchFromGitHub {
    owner = "MittenzHugg";
    repo = "bk_rom_compressor";
    rev = "272180b527b01c0023dc2ab02bdfdfd373670906";
    hash = "sha256-lnmnoomJTy8lAjoUjXvkXWFnf9LGtAGcD4WNFTDkiPk=";
    fetchSubmodules = true;
  };

  buildInputs = [
    rarezip
  ];

  cargoHash = "sha256-JxK2S0JTBepT8nTTlBsZlS9+NvL+/rIRPmreX1Kmat4=";

  meta = {
    description = "Banjo-Kazooie rom compressor/decompressor";
    homepage = "https://github.com/MittenzHugg/bk_rom_compressor";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [ qubitnano ];
  };
}
+38 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchFromGitHub,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "rarezip";
  version = "0-unstable-2023-09-05";

  src = fetchFromGitHub {
    owner = "MittenzHugg";
    repo = "rarezip";
    rev = "2c4ba146c1b2fec851d3db8cf455c6af090bc544";
    hash = "sha256-t4/DgDeUOZAiX3yc2FUrm5mCRIgX0THFVBFSEYOSAhI=";
  };

  buildPhase = ''
    substituteInPlace gzip/zip.c \
      --replace-fail "size_t bufs_init();" ""

    mkdir c
    make c
  '';

  installPhase = ''
    mkdir -p $out/lib
    cp c/librarezip.a $out/lib
  '';

  meta = {
    description = "Library version gzip v1.2.4 with foreign function interfaces to multiple languages";
    homepage = "https://github.com/MittenzHugg/rarezip";
    license = lib.licenses.gpl2Only;
    maintainers = with lib.maintainers; [ qubitnano ];
    platforms = lib.platforms.all;
  };
})