Jump to content

Linux/Script: KSP Launcher script


Recommended Posts

Current version: 2.5.1  License - GPLv3+

Description
Based upon known launch options of the Kerbal Space Program, I have created a small bash script.
It is configured directly by changing the options inside the script. Each line is commented, and if the script is run with any parameter - it will also spill the help.

It is not a GUI application on purpose - so it can be chain-launched from existing launchers (.desktop file, Steam, GOG Galaxy etc).

How to install:
Scroll down to the link,  save and paste contents into new file, rename it to "KSP_launcher.sh" and make it executable;
Place this file in same directory with KSP binary;
Edit it with text editor and adjust options;
(Option) Integrate it into your launcher (.desktop file in ~/.local/share/applications, or other launcher) so it runs this script instead of KSP
(Option) If you use GOG offline installer, in "start.sh" replace strings "KSP.x86_64" and "KSP.x86",  with "KSP_launcher.sh"
Run

For console help:
run the script with some parameter ("./KSP_launcher --help" or similar)

How to modify settings:
edit the script, change the variable values, save.

 

What script currently allows:
- force LC_C to fix disappearing saves/forgetting settings
- automatically rotate it with compression or disable KSP logfile completely
- turn vsync on/off (both nvidia and mesa/opensource radeon or intel)
- force fullscreen or any video resolution
- specify opengl / gles level
- change R600_DEBUG variable
- change Mesa options
- start gallium benchmark mode to display fps
- protect KSP from shutdown if it asks for too much RAM at once (if you run many mods)
- properly waits for KSP to end for cleanup, even if it segfaults
- integrated help and options documented inside script
- debug mode that shows options it would run
some options were deprecated as no longer applicable.


Current version: https://pastebin.com/CeVvvdpT
previous version (2.5): https://pastebin.com/GVexVATS
previous version (2.4):
https://pastebin.com/dw1B8fDk
previous version (2.2): https://pastebin.com/ctpp53Bd
previous version (2.0): https://pastebin.com/2vwj6szQ


Warning
if you use the "download" button on pastebin.com, instead of copy-pasting raw contents into new text file, then you may encounter the error:
"/bin/bash^M: bad interpreter: No such file or directory"
To fix it, open this script in text editor and change the line end encodings from Windows to Unix. This done by "pastebin.com", I have no control over this.


Heads up of the Linux problems I am aware of, being Linux player myself:

- KSP runs hot on GPU
Use either nvidia settings panel (for proprietary Nvidia) or radeon profile tool (for AMD, ubuntu PPA) to limit the performance mode of the GPU. In case of Radeon, switch it to manual and low.
From my observations, only simulations in atmosphere require a lot of GPU. In VAB/SPH the GPU is perfectly fine in manual low-power mode, consuming 10-20% energy and running cool.
Since KSP supports window switching (alt-tab), you can easily adjust performance as you need it.

- KSP does not remember settings and always starts in window mode
This stopped happening in Linux (for me), but it doesn't seem to be fixed globally. Unity uses comma delimiter set by locale and some locales have "," instead of "."  This leads to the problem and solution is to force en_US through LC_ALL=C. This does not prevent using different keyboard layout and does not interfere with game localization.
Solution: KSP_unity_forceLC="on", which is default in my script

- KSP starts with window of weird size
This stopped happening in Linux (for me, since 1.2), but it doesn't seem to be fixed globally. This is because Unity fails to get screen size from window manager.
Solution: KSP_ksp_cleanprefs="on" which is default and will remove Unity's "prefs", and you can force the settings for one launch with KSP_unity_forceX, KSP_unity_forceY, KSP_unity_fullscreen variables.

- KSP sometimes at loading crashes Xorg session, booting to login
Solution: KSP_ksp_protect="on" , which is default in my script

- KSP starts with black screen, noticed in Mesa 11 (fixed)
Solution: KSP_unity_glcore to "on" or "33" (or higher value, if your GL library supports it)

- Bop and Minmus have terrain glitches, noticed in Mesa 12 (fixed)
Solution: KSP_unity_glcore to "on" or "41"

- RasterPropMonitor shows has pink lines instead of IVA panels (fixed)
This is result of having "glcore" enabled, as it breaks the shaders. Here is the bug report.

- KSP sometimes crashes
I read about this bug being present on Intel opensource drivers. To solve, disable antialiasing in KSP settings.

- VAB/SPH floor markers are weird (fixed)
(gradient - AMD, covered in flickering noise - Nvidia). This is connected with shader rendering and OpenGL library in the system.
On AMD / Mesa 17, the system also freezes at random time and its connected with issue below.
On AMD / Catalyst(depricated driver), its reported to be fixed by disabling PPFX edge shaders in settings.
On Nvidia (proprietary driver), is reported to happen with driver 378.13 and later.
Its possible to workaround this issue by installing Hangar Extender mod.

- KSP freezes the system completely (fixed)
Freeze happens at random point. The freeze happens earlier, if there are Mods that require a lot of GPU work.
After many attempts I have traced this issue to Mesa 17+.
Solution: If you have OIBAF or PADOKA Mesa installed, try removing them and downgrading to "hwe" Mesa.
This is likely DRI3 issue, but no option I know helped, its somewhere in the Mesa userspace stack. Upgrading kernel does not help.

 

If this interests anyone, I am using x64 Kernel 5.x and NixOS.
For driver, I use opensource radeon driver, running with R9 280 (still!).


Enjoy!!

Edited by Kerbal101
2.5.1 version
Link to post
Share on other sites
if [[ -n "$1" ]]; then display_help; fi

Bash has a 'getopts' builtin for handling command line parameters. It only supports single letter flags, but they can have arguments, and it's a pretty easy way to support multiple flags if you find a need for that in the future:

while getopts 'o:h' arg
do
	case $arg in
		h)
			display_help
			;;
		o)
			other_opt=$OPTARG
			;;
	esac
done

 

Link to post
Share on other sites

@HebaruSan Thank you, HebaruSan. :) I have worked with GNU's "getopt" and  "getopts", but I think right now it would overcomplicate the code.
I am pushing another version soon supporting more parameters, with various in-script and description improvements.
I will be thankful, if you or any other members could point me to other valuable settings.

In addition,..  KSP freezes for me few seconds in main menu.., but this is another topic >:) So, I am helping myself, as well as others with this script :)

Link to post
Share on other sites

2.0 released.

Changelog:

- variables carry more convenient/context name and alphabetically sorted
- debug option also shows exported variables and other actions
- improved help section readability
- included dri3 disable, mesa software, gl single thread, r600 debug, mesa noerror options
- removed "auto" as parameter, using on/off instead. Automation applies on case-bases to either on or off and is documented where
- consistent "on / off" settings

Probably missing some more options and intel settings.
Probably help can be translated.

Link to post
Share on other sites
On 6/12/2017 at 3:13 AM, Kerbal101 said:

@HebaruSan No its not an addon. Its just a bunch of if-statements that help start KSP easier. If you are coming from Windows, its like .bat/powershell starting script.

Thanks for reminding of license, I'll update the OP.

I once posted a few Module Manager configs that added the ability for probes to do science. Basically just a few patches. I got warned by the moderators that I needed to put a license on it.

Link to post
Share on other sites

@Starwaster I see. :)

 

Proof-testing 2.1, should be out very soon.

 

Edit: and 2.2 up. I bumped the version higher due to more features than initially expected.

Edit2: I have noticed that KSP on Linux currently segfaults, causing script to be aborted too. I have addressed this quickly in 2.3 by changing how KSP is called... Tests show that its fixed now.

Edited by Kerbal101
2.3 release
Link to post
Share on other sites
  • 3 weeks later...

I've been stuck for weeks with the process going to sleep when it should be getting the game controller info from the underlying linux system.

Logs had no errors in them.

Found a fix by using

LD_PRELOAD="/usr/lib64/liblemalloc.so.1" %ksp_command%

Not sure if you can integrate into your script .

 

Damn. You can't edit a code block !
Spelling error or finger trouble. "liblemalloc" should be 'libjemalloc'

Edited by v8Dave
Spelling error
Link to post
Share on other sites
7 hours ago, Kerbal101 said:

@v8Dave Could you please provide more detail and links to background of how this works? Google can't find any "liblemalloc"... Thanks!

Sorry, finger trouble. Look for libjemalloc.so.1

A few linux users have been seeing a problem where KSP opens a window or goes full screen but just shows a blank black page.
Investigating the logs shows not critical errors and that KSP stops here.

Default vsync count 1
requesting resize 1280 x 720
resizing window to 1280 x 720
Desktop is 1920 x 1200 @ 60 Hz
Using libudev for joystick management


Importing game controller configs
 

The usual ldd check shows all libraries are present.
Checks with gdb didn't help me identify the fault.
My system monitor told me the KSP.x86_64 process was sleeping.
Broadening my search actually turned up and answer from the distro I use, Slackware.
It seems a problem can occur for any unity powered game which means it goes to sleep during the startup process and leaves the user watching the black screen or window, but only on some 64 bit distros using glibc-2.25.

More info here

HTH

It is probable that so few people are effected that it's not worth editing your script.

Link to post
Share on other sites
  • 2 years later...

Released 2.5. I am still using and developing the script. Works with 1.8.

edit: if you downloaded it in first minutes and it doesn't start, please get new version 2.5-1 code from new link; I have forgot to uncomment debug line before posting. My mistake, sorry.

Link to post
Share on other sites
  • 3 months later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...