Advertisement
Guest User

KSP_launcher.sh

a guest
Jun 13th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.96 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## version 2.0
  4.  
  5. ## run this script with any parameter in terminal for help, like this:
  6. ## KSP_launcher.sh --help
  7.  
  8. ## otherwise place it into the same directory where KSP binary exists, run.
  9.  
  10. ## if you use GOG standalone installer, in start.sh replace strings "KSP.x86_64" and "KSP.x86",  with "KSP_launcher.sh"
  11. ## you can also make the KSP desktop file invoke this script.
  12.  
  13.  
  14. ########################### values: >default< / possible
  15.  
  16. ## debug setting.
  17. ## setting this variable to anything other than "off", will cause script to dump the launch string, instead of running ksp.
  18. KSP_debuglauncher="off"
  19.  
  20. KSP_gallium_bench="off"     ## on / >off<
  21. KSP_ksp_cleanprefs="on"     ## >on< / off
  22. KSP_ksp_forceversion="off"  ## >off< / 32 / 64
  23. KSP_ksp_protect="on"        ## >on< / off
  24. KSP_mesa_disableDRI3="off"  ## on / >off<
  25. KSP_mesa_noerror="off"      ## on / >off<
  26. KSP_mesa_software="off"     ## on / >off<
  27. KSP_mesa_vsync="on"         ## >on< / off
  28. KSP_nv_opts="on"            ## >on< / off
  29. KSP_nv_preload="off"        ## on / >off<
  30. KSP_nv_vsync="on"           ## >on< / off
  31. KSP_radeon_R600_DEBUG="off" ## >off< / clear / (nosb/>sb<,sbcl,sbsafemaths),(>hyperz<,nohyperz), (nocpdma,nodma/forcedma), nowc
  32. KSP_unity_forceX="off"      ## >off< / horizontal resolution, like 1920
  33. KSP_unity_forceY="off"      ## >off< / vertical resolution, like 1080
  34. KSP_unity_forceLC="on"      ## >on< / off
  35. KSP_unity_fullscreen="off"  ## on / >off<
  36. KSP_unity_gl_old="off"      ## on / >off<
  37. KSP_unity_glclamp="off"     ## on / >off<
  38. KSP_unity_glcore="off"      ## on / >off< / 32 / 33 / 40 / 41 / 42 / 43 / 44 / 45
  39. KSP_unity_gles="off"        ## on / >off< / 20 / 30 / 31 / 31aep
  40. KSP_unity_glthread="off"    ## on / >off<
  41.  
  42.  
  43. display_help() {
  44.  
  45. echo 'written by Kerbal101. GPL3+ '
  46. echo ''
  47.  
  48. echo '==============================================='
  49. echo 'KSP_gallium_bench '
  50. echo 'on / >off< '
  51. echo ''
  52. echo 'gallium-drivers only: radeon/amdgpu, nouveau, intel-gallium (not intel classic). '
  53. echo 'enable string to debug performance. outputs cpu, gpu, fps, gpu memory graphs. '
  54. echo ''
  55.  
  56. echo '==============================================='
  57. echo 'KSP_ksp_cleanprefs '
  58. echo '>on< / off '
  59. echo 'cleans "prefs" file, which is unity thing and will prevent game from starting, '
  60. echo 'if you change video resolution in settings. its absolutely safe. '
  61. echo ''
  62.  
  63. echo '==============================================='
  64. echo 'KSP_ksp_forceversion '
  65. echo '>off< (autodetect) / 32 / 64 '
  66. echo ''
  67. echo 'you can force the 32 or 64 bit version here.'
  68. echo ''
  69.  
  70. echo '==============================================='
  71. echo 'KSP_ksp_protect '
  72. echo '>on< / off '
  73. echo 'enable crash protection, if KSP requests too much memory too fast. '
  74. echo 'this causes Linux to kill KSP instead of whole Xorg session, by rising KSP "naughtiness level". '
  75. echo 'you should really leave at "on". '
  76. echo ''
  77.  
  78. echo '==============================================='
  79. echo 'KSP_mesa_disableDRI3 '
  80. echo 'on / >off< '
  81. echo ''
  82. echo 'mesa only: disables DRI3, which will cause driver to fallback to DRI2. '
  83. echo 'this will impact (worsen) performance and is used for debugging. '
  84. echo 'known to solve issue with game freezing at random points on intel driver. '
  85. echo 'https://bugs.freedesktop.org/show_bug.cgi?id=97890 '
  86. echo ''
  87.  
  88. echo '==============================================='
  89. echo 'KSP_mesa_noerror'
  90. echo 'on / >off< '
  91. echo ''
  92. echo 'mesa only: disables error checking in mesa driver. '
  93. echo 'this may reduce CPU overhead, at the price of disabled error checks, which would crash the misbehaving game. '
  94. echo ''
  95.  
  96. echo '==============================================='
  97. echo 'KSP_mesa_software '
  98. echo 'on / >off< '
  99. echo ''
  100. echo 'mesa only: disables hardware accelerated rendering completely and switches to LLVM-assisted software renderer. '
  101. echo 'usefull for debugging properties only, severely impacts performance. '
  102. echo ''
  103.  
  104. echo '==============================================='
  105. echo 'KSP_mesa_vsync '
  106. echo '>on< / off '
  107. echo ''
  108. echo 'mesa only: disables vsync (off setting), which improves performance at cost of tearing and will cause GPU to run constantly hot. '
  109. echo 'you may want to disable SwapBuffersWait for DDX driver (in xorg.conf.d) too '
  110. echo 'see https://www.x.org/wiki/RadeonFeature/ '
  111. echo ''
  112.  
  113. echo '==============================================='
  114. echo 'KSP_nv_opts '
  115. echo '>on< / off '
  116. echo 'nvidia proprietary only: force driver threaded optimizations by exporting a variable. '
  117. echo ''
  118.  
  119. echo '==============================================='
  120. echo 'KSP_nv_preload '
  121. echo 'on / >off< '
  122. echo 'nvidia proprietary only: preloads the blob, which can solve some problems. '
  123. echo 'will interfere with benchmarking software like GLXOSD. '
  124. echo ''
  125.  
  126. echo '==============================================='
  127. echo 'KSP_nv_vsync '
  128. echo '>on< / off '
  129. echo ''
  130. echo 'nvidia proprietary only: disables vsync (off) on nvidia proprietary driver. '
  131. echo ''
  132.  
  133. echo '==============================================='
  134. echo 'KSP_radeon_R600_DEBUG '
  135. echo '>off< / clear / (nosb/>sb<,sbcl,sbsafemaths),(>hyperz<,nohyperz), (nocpdma,nodma/forcedma), nowc '
  136. echo ''
  137. echo 'radeon/amdgpu driver only: "R600_DEBUG" is a variable for changing driver options of Radeon/RadeonSI/AMDGPU. '
  138. echo 'some options may be already enabled in the driver internally, these are marked with "enabled by default" below. '
  139. echo '"off" and "clear" are handled by the script and can′t be combined with others. '
  140. echo 'options can be combined using comma where it makes sense: "KSP_mesa_R600_DEBUG=sbcl,hyperz,llvm,sisched,forcedma" '
  141. echo ''
  142. echo 'off - (script) do not touch R600_DEBUG variable. '
  143. echo 'clear - (script) clear the R600_DEBUG variable, causing driver to run with default options. '
  144. echo 'sb - enable shader optimizer. (enabled by default) '
  145. echo 'sbcl - enable shader optimizer with opencl improvements. '
  146. echo 'sbsafemaths - enable optimized shader backend but disable fast unsafe math ops. '
  147. echo 'nosb  - disable shader backend. '
  148. echo 'hyperz - enable hyperz. (enabled by default) '
  149. echo 'nohyperz - disable hyperz. '
  150. echo 'forcedma - enable dma. '
  151. echo 'nodma - disable dma. '
  152. echo 'nocpdma - disable CP dma. '
  153. echo 'nowc - disable write combining. '
  154. echo 'llvm - enable llvm backend for shader compilation. (enabled by default?) '
  155. echo 'sisched - enable improved radensi scheduler in llvm. '
  156. echo ''
  157.  
  158. echo '==============================================='
  159. echo 'KSP_unity_forceX '
  160. echo '>off< / horizontal resolution, like 1920 '
  161. echo 'KSP_unity_forceY '
  162. echo '>off< / vertical resolution, like 1080 '
  163. echo ''
  164. echo 'unity option: force horizontal and vertical resolution. '
  165. echo 'useful to if KSP starts with window of weird sizes. '
  166. echo ''
  167.  
  168. echo '==============================================='
  169. echo 'KSP_unity_forceLC '
  170. echo '>on< / off '
  171. echo ''
  172. echo 'exports LC_ALL=C var, which solves the problem of non-us_US encoding with numeric comma. '
  173. echo 'symptons include absent savegames and KSP forgetting settings. '
  174. echo ''
  175.  
  176. echo '==============================================='
  177. echo 'KSP_unity_fullscreen '
  178. echo 'on / >off<'
  179. echo ''
  180. echo 'unity option: force fullscreen in KSP. '
  181. echo ''
  182.  
  183. echo '==============================================='
  184. echo 'KSP_unity_gl_old '
  185. echo 'on / >off< '
  186. echo ''
  187. echo 'unity option: force old unity OpenGL backend. blocks gles settings. '
  188. echo ''
  189.  
  190. echo '==============================================='
  191. echo 'KSP_unity_glclamp '
  192. echo 'on / >off< '
  193. echo ''
  194. echo 'unity option: disable opengl extensions. primary used for debugging.'
  195. echo ''
  196.  
  197. echo '==============================================='
  198. echo 'KSP_unity_glcore '
  199. echo 'on / >off< / 32 / 33 / 40 / 41 / 42 / 43 / 44 / 45 '
  200. echo ''
  201. echo 'unity option: force unity to use GL "core profile", instead of the "compat. profile" - which has legacy/outdated GL codepaths. '
  202. echo 'recommended on mesa and drivers that dont implement legacy functions fully. '
  203. echo 'enable if you experience weird planet colors or black screen during launch. '
  204. echo 'see: https://docs.unity3d.com/Manual/OpenGLCoreDetails.html '
  205. echo 'blocks gles settings. '
  206. echo 'off = use compat. profile, on = force and detect core profile, number = on +limit core profile to specified level'
  207. echo ''
  208.  
  209. echo '==============================================='
  210. echo 'KSP_unity_gles '
  211. echo 'on / >off< / 20 / 30 / 31 / 31aep '
  212. echo 'unity option: force opengles. will not work, if glcore or oldgl options are enabled. '
  213. echo 'see: https://docs.unity3d.com/Manual/OpenGLCoreDetails.html '
  214. echo 'off = use opengl, on = use gles, number = on+limit gles profile to level'
  215. echo ''
  216.  
  217. echo '==============================================='
  218. echo 'KSP_unity_glthread '
  219. echo 'on / >off< '
  220. echo ''
  221. echo 'unity option: force OpenGL backend to use single rendering thread. may reduce render performance. '
  222. echo 'this is known to solve issues with old amd proprietary driver (fglrx/catalyst) freezing, but is applicable to all drivers. '
  223. echo ''
  224.  
  225. exit 0
  226.  
  227. }
  228.  
  229.  
  230. ## this is an internal variable that is filled as needed. Do not change.
  231. KSP_params=""
  232. ## this is an internal variable that is filled with exported values, shown at debug. Do not change.
  233. KSP_env_debug=""
  234.  
  235. ## display help if we have any parameters, else run.
  236. if [[ -n "$1" ]]; then display_help; fi
  237.  
  238.  
  239. if [[ "$KSP_ksp_forceversion" = "32" ]]; then
  240.     KSP_bin="./KSP.x86"
  241. elif [[ "$KSP_ksp_forceversion" = "64" ]]; then
  242.     KSP_bin="./KSP.x86_64"
  243. else
  244.     if [[ "$(uname -m)" = "x86_64" ]]; then
  245.         KSP_bin="./KSP.x86_64"
  246.     else
  247.         KSP_bin="./KSP.x86"
  248.     fi
  249. fi
  250.  
  251.  
  252. if [[ "$KSP_mesa_vsync" = "off" ]]; then
  253.     export vblank_mode=0
  254.     KSP_env_debug+="export vblank_mode=0\n"
  255. fi
  256.  
  257. if [[ "$KSP_nv_vsync" = "off" ]]; then
  258.     nvidia-settings --load-config-only --assign="SyncToVBlank=0"
  259.     KSP_nvcorrect="yes"
  260.     KSP_env_debug+="execute: nvidia-settings --load-config-only --assign=\"SyncToVBlank=0\"\n"
  261. fi
  262.  
  263. ## options can be extracted with "GALLIUM_HUD=help glxgears"
  264. ## each option consumes cycles, so stat sparingly!
  265. if [[ ! "$KSP_gallium_bench" = "off" ]]; then
  266.     export GALLIUM_HUD="VRAM-usage+temperature+fps+cpu+GPU-load,cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7"
  267.     KSP_env_debug+="export GALLIUM_HUD=\"VRAM-usage+temperature+fps+cpu+GPU-load,cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7\"\n"
  268. fi
  269.  
  270. if [[ ! "$KSP_mesa_noerror" = "off" ]]; then
  271.     export MESA_NO_ERROR=1
  272.     KSP_env_debug+="export MESA_NO_ERROR=1\n"
  273. fi
  274.  
  275. if [[ "$KSP_ksp_cleanprefs" = "on" ]]; then
  276.     rm -f "${HOME}/.config/unity3d/Squad/Kerbal Space Program/prefs"
  277.     KSP_env_debug+="execute: rm -f \"${HOME}/.config/unity3d/Squad/Kerbal Space Program/prefs\"\n"
  278. fi
  279.  
  280.  
  281. if [[ "$KSP_unity_forceLC" = "on" ]]; then
  282.     export LC_ALL=C
  283.     KSP_env_debug+="export LC_ALL=C\n"
  284. fi
  285.  
  286.  
  287. if [[ ! "$KSP_mesa_disableDRI3" = "off" ]]; then
  288.     export LIBGL_DRI3_DISABLE=1
  289.     KSP_env_debug+="export LIBGL_DRI3_DISABLE=1\n"
  290. fi
  291.  
  292.  
  293. if [[ ! "$KSP_mesa_software" = "off" ]]; then
  294.     export LIBGL_ALWAYS_SOFTWARE=1
  295.     KSP_env_debug+="export LIBGL_ALWAYS_SOFTWARE=1\n"
  296. fi
  297.  
  298.  
  299. if [[ ! "$KSP_unity_fullscreen" = "off" ]]; then
  300.     KSP_params+=" -screen-fullscreen 1 "
  301. fi
  302.  
  303. if [[ ! "$KSP_radeon_R600_DEBUG" = "off" ]]; then
  304.     if [[ "$KSP_radeon_R600_DEBUG" = "clear" ]]; then
  305.         unset R600_DEBUG
  306.         KSP_env_debug+="unset R600_DEBUG\n"
  307.     else
  308.         unset R600_DEBUG
  309.         export R600_DEBUG="${KSP_radeon_R600_DEBUG}"
  310.         KSP_env_debug+="unset R600_DEBUG\n"
  311.         KSP_env_debug+="export R600_DEBUG=\"${KSP_radeon_R600_DEBUG}\"\n"
  312.     fi
  313. fi
  314.  
  315. if [[ ! "$KSP_unity_forceX" = "off" ]]; then
  316.     KSP_params+=" -screen-width ${KSP_unity_forceX} "
  317. fi
  318.  
  319.  
  320. if [[ ! "$KSP_unity_forceY" = "off" ]]; then
  321.     KSP_params+=" -screen-height ${KSP_unity_forceY} "
  322. fi
  323.  
  324.  
  325. if [[ ! "$KSP_unity_gl_old" = "off" ]]; then
  326.     KSP_params+=" -force-opengl "
  327. fi
  328.  
  329.  
  330. if [[ ! "$KSP_unity_glthread" = "off" ]]; then
  331.     KSP_params+=" -force-gfx-direct "
  332. fi
  333.  
  334.  
  335. if [[ ! "$KSP_unity_glcore" = "off" ]]; then
  336.     if [[ "$KSP_unity_glcore" = "on" ]]; then
  337.         KSP_params+=" -force-glcore "
  338.     else
  339.         KSP_params+=" -force-glcore${KSP_unity_glcore} "
  340.     fi
  341. fi
  342.  
  343.  
  344. if [[ ! "$KSP_unity_glclamp" = "off" ]]; then
  345.     KSP_params+=" -force-clamped "
  346. fi
  347.  
  348.  
  349. if [[ ! "$KSP_unity_gles" = "off" ]] && [[ "$KSP_unity_glcore" = "off" ]] && [[ "$KSP_unity_gl_old" == "off" ]]; then
  350.  
  351.     if [[ "$KSP_unity_gles" = "on" ]]; then
  352.         KSP_params+=" -force-gles "
  353.     else
  354.         KSP_params+=" -force-gles${KSP_unity_gles} "
  355.     fi
  356. fi
  357.  
  358. if [[ ! "$KSP_nv_preload" = "off" ]]; then
  359.     export LD_PRELOAD="libpthread.so.0 libGL.so.1"
  360.     KSP_env_debug+="export LD_PRELOAD=\"libpthread.so.0 libGL.so.1\"\n"
  361. fi
  362.  
  363.  
  364. if [[ ! "$KSP_nv_opts" = "off" ]]; then
  365.     export __GL_THREADED_OPTIMIZATIONS=1
  366.     KSP_env_debug+="export __GL_THREADED_OPTIMIZATIONS=1\n"
  367. fi
  368.  
  369. if [[ ! "$KSP_ksp_protect" = "off" ]]; then
  370.     if [[ ! "$KSP_debuglauncher" = "off" ]]; then
  371.         KSP_env_debug+="Would increase KSP binary naughtiness value.\n"
  372.     else
  373.         if [[ "$KSP_bin" = "./KSP.x86" ]]; then
  374.             sh -c 'sleep 3 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
  375.             sh -c 'sleep 2 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
  376.             sh -c 'sleep 1 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
  377.         else
  378.             sh -c 'sleep 3 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
  379.             sh -c 'sleep 2 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
  380.             sh -c 'sleep 1 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
  381.         fi
  382.     fi
  383. fi
  384.  
  385.  
  386. ####### executing KSP if debug is off, otherwise just spill the parameters into shell
  387.  
  388. if [[ ! "$KSP_debuglauncher" = "off" ]]; then
  389.     echo -e "${KSP_env_debug}"
  390.     echo ''
  391.     echo -e "Would finally execute: ${KSP_bin} ${KSP_params}"
  392. else
  393.     exec "$KSP_bin" "$KSP_params"
  394. fi
  395.  
  396. #######
  397.  
  398. ## will restore vsync for nvidia after game exit, if the script enabled it.
  399.  
  400. if [[ $KSP_nvcorrect = "yes" ]]; then
  401.     nvidia-settings --load-config-only --assign="SyncToVBlank=1"
  402. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement