You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.6 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. { stdenv, lib, pkgs, fetchurl, fetchpatch, nix, pkgsCross,
  2. installDir ? "$HOME/.local/starcitizen",
  3. launcherCache ? "$HOME/.local/share",
  4. prefixBaseDir ? "$HOME/.winenix",
  5. binName ? "starcitizen",
  6. launcherArgs ? [ "--use-gl=osmesa" ],
  7. vulkanDrivers ? [ ],
  8. dxvkPatches ? [ ],
  9. dxvkAsync ? false,
  10. winePackage ? pkgs.wineWowPackages.unstable,
  11. wineSrc ? null,
  12. wineGlobalEnv ? [ "DXVK_STATE_CACHE=0" ],
  13. winePatches ? [],
  14. applyReccomendedWinePatches ? true,
  15. virtualDesktop ? null,
  16. registryFiles ? [ ],
  17. captureMouse ? true,
  18. enableGameScope ? false,
  19. gameScopeArgs ? [ "-W 2560" "-H 1440" "-b" ],
  20. }:
  21. #check wether string is two positive integers separated by x
  22. assert virtualDesktop == null ||
  23. (lib.strings.toInt(lib.strings.concatStrings(lib.strings.splitString "x" virtualDesktop))) > 0;
  24. #check whether paths are not terminated with a /
  25. assert !(builtins.any (lib.strings.hasSuffix "/") [ installDir launcherCache prefixBaseDir ]);
  26. let
  27. wineReccomendedPatches = [
  28. (fetchpatch {
  29. name = "joyaxis.patch";
  30. url = "https://raw.githubusercontent.com/snatella/wine-runner-sc/5e48a6fb974da9f1585043a236026c7c57272e67/patches/6.4/joyaxis.patch";
  31. sha256 = "18f87anf0rkvbkjhgm9j6n2cccp1wl82a12vhzr7a4p7bc025yrz";
  32. })
  33. (fetchpatch {
  34. name = "StorageDeviceSeekPenalty.patch";
  35. url = "https://raw.githubusercontent.com/Frogging-Family/community-patches/f96b11b79d6aada264838d780dfd5a14f85cced0/wine-tkg-git/star-citizen-StorageDeviceSeekPenaltyProperty.mypatch";
  36. sha256 = "01ilxhl90ib05jwsqy0iajqixdvd571ad803z1qj3lgjk3siff13";
  37. })
  38. ];
  39. winePkg = winePackage.overrideAttrs (attrs: {
  40. patches = (if wineSrc == null then attrs.patches else []) ++ winePatches ++ lib.optional applyReccomendedWinePatches wineReccomendedPatches;
  41. src = if wineSrc != null then wineSrc else attrs.src;
  42. });
  43. dxvk = (pkgsCross.mingwW64.callPackage ./dxvk.nix { async = dxvkAsync; }).overrideAttrs
  44. ( attrs: { patches = attrs.patches ++ dxvkPatches; });
  45. dxvkAsyncEnv = "DXVK_ASYNC=1" ;
  46. gamescope = "${pkgs.callPackage ./gamescope.nix {}}/bin/gamescope";
  47. vulkanDriverPaths = {
  48. radeon = "${pkgs.mesa_drivers.drivers}/share/vulkan/icd.d/radeon_icd.x86_64.json";
  49. intel = "${pkgs.mesa_drivers.drivers}/share/vulkan/icd.d/intel_icd.x86_64.json";
  50. amdvlk = "${pkgs.amdvlk}/share/vulkan/icd.d/amd_icd64.json";
  51. };
  52. vkIcd = lib.strings.concatStringsSep ":" (lib.attrsets.attrVals vulkanDrivers vulkanDriverPaths);
  53. fonts = pkgs.callPackage ./fonts.nix {};
  54. rsiInstaller = fetchurl {
  55. url = "https://install.robertsspaceindustries.com/star-citizen/RSI-Setup-1.4.11.exe";
  56. sha256 = "1afc4b36dd1e22d75df8da2ecb925833f9b10327c991be20e138503cde627022";
  57. };
  58. vcrun2019 = fetchurl {
  59. url = "https://aka.ms/vs/16/release/vc_redist.x86.exe";
  60. sha256 = "1p22ibzx80zn2gxavmcsz7adkr5672smmlwgapfvx6a04f9n7a7k";
  61. };
  62. win10Reg = pkgs.writeTextFile {
  63. name = "win10.reg";
  64. text = ./win10.reg;
  65. };
  66. captureMouseReg = pkgs.writeTextFile {
  67. name = "captureMouse.reg";
  68. text = ./captureMouse.reg;
  69. };
  70. helpText = pkgs.writeTextFile {
  71. name = "scHelptext";
  72. text = ./helpText.txt;
  73. };
  74. wine64 = "${winePkg}/bin/wine64";
  75. wineMulti = "${winePkg}/bin/wine";
  76. regEdit = "${wine64} regedit";
  77. reg = "${wine64} reg";
  78. script = pkgs.writeShellScriptBin binName ''
  79. #sane bash
  80. set -eo pipefail
  81. function installPrefix () {
  82. if [ ! -d "$WINEPREFIX" ]; then
  83. ${winePkg}/bin/wineboot -i
  84. #set win 10
  85. ${regEdit} ${win10Reg}
  86. #install dxvk
  87. for library in ${dxvk}/bin/*.dll ; do
  88. cp $library "$WINEPREFIX/drive_c/windows/system32"
  89. local libraryFile=$(basename $library)
  90. ${reg} add 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v ''${libraryFile/\.dll/} /d native /f
  91. done
  92. #install fonts
  93. cp ${fonts}/share/fonts/*.TTF "$WINEPREFIX/drive_c/windows/Fonts"
  94. ${regEdit} ${fonts}/share/regs/fonts.reg
  95. #install vcrun2019
  96. ${wineMulti} ${vcrun2019} /q
  97. #symlink persistent game and launcher binaries into prefix.
  98. gameBinariesPers="${installDir}/Roberts Space Industries"
  99. gameBinariesLinkDest="$WINEPREFIX/drive_c/Program Files/"
  100. mkdir -p "$gameBinariesPers" "$gameBinariesLinkDest"
  101. ln -s "$gameBinariesPers" "$gameBinariesLinkDest"
  102. #symlink launcher cache
  103. launcherCachePers="${launcherCache}/rsilauncher"
  104. mkdir -p "$launcherCachePers" "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/"
  105. ln -s "$launcherCachePers" "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/"
  106. ${lib.optionalString captureMouse "${regEdit} ${captureMouseReg.text}"}
  107. #apply custom user registry files
  108. ${lib.concatMapStrings (x: "${regEdit} " + x + "\n") registryFiles}
  109. fi
  110. }
  111. function installLauncher () {
  112. installPrefix
  113. #install the launcher
  114. echo "Install with default parameters, launcherArgs won't be used when you launch the launcher from the setup"
  115. ${winePkg}/bin/wine ${rsiInstaller}
  116. }
  117. function runGame () {
  118. installPrefix
  119. #install the launcher conditionally here and not in the launcher to allow force reinstalls.
  120. if [ ! -f "${installDir}/Roberts Space Industries/RSI Launcher/RSI Launcher.exe" ]; then
  121. installLauncher
  122. fi
  123. ${lib.optionalString enableGameScope "${gamescope} ${builtins.concatStringsSep " " gameScopeArgs} --\\" }
  124. ${wineMulti} \
  125. ${lib.optionalString (virtualDesktop != null) "explorer /desktop=${binName},${virtualDesktop}"} \
  126. "$WINEPREFIX/drive_c/Program Files/Roberts Space Industries/RSI Launcher/RSI Launcher.exe" \
  127. ${lib.concatStringsSep " " launcherArgs}
  128. }
  129. function printPrefix () {
  130. echo "$WINEPREFIX"
  131. }
  132. function clean () {
  133. find "${prefixBaseDir}" -maxdepth 1 -type d -name ????????????????????????????????-"${binName}" -and -not -wholename "$WINEPREFIX" -exec rm -rf {} \;
  134. }
  135. function removePrefix () {
  136. #Good thing the GPL contains a no warranty clause
  137. rm -rf "$WINEPREFIX"
  138. }
  139. function help () {
  140. cat ${helpText.text}
  141. }
  142. function wine () {
  143. installPrefix
  144. ${winePkg}/bin/"$@"
  145. }
  146. #base setup
  147. if [ ! -d "${installDir}" ]; then
  148. mkdir -p "${installDir}/Roberts Space Industries"
  149. fi
  150. #create base dir for nix installs
  151. if [ ! -d ${prefixBaseDir} ]; then
  152. mkdir -p "${prefixBaseDir}"
  153. fi
  154. #core idea: Generate UUID from storage path of this script, ensure
  155. #new prefix for any changes. Needs fast prefix installs and state outside.
  156. uuid=$(basename $(${pkgs.nix}/bin/nix path-info "$(readlink -f $BASH_SOURCE)"))
  157. export WINEPREFIX="${prefixBaseDir}/$uuid"
  158. export WINEARCH=win64
  159. #optionally export vulkan drivers:
  160. #The following line might be empty in the resulting script.
  161. ${lib.optionalString (vulkanDrivers != []) "export VK_ICD_FILENAMES=${vkIcd}"}
  162. #export all global env vars
  163. ${lib.concatMapStrings (x: "export " + x + "\n") (wineGlobalEnv
  164. ++ lib.lists.optional dxvkAsync dxvkAsyncEnv
  165. )}
  166. #parse input
  167. case "$@" in
  168. --install-prefix)
  169. installPrefix
  170. ;;
  171. --install-launcher)
  172. installLauncher
  173. ;;
  174. --clean)
  175. clean
  176. ;;
  177. --remove-prefix)
  178. removePrefix
  179. ;;
  180. --run-game|"")
  181. runGame
  182. ;;
  183. --print-prefix)
  184. printPrefix
  185. ;;
  186. --help)
  187. help
  188. ;;
  189. --wine*)
  190. shift
  191. wine "$@"
  192. ;;
  193. *)
  194. help
  195. exit 1
  196. esac
  197. '';
  198. in script