(2013-07-12) Kerbal Space Program Fixes

I've been playing a *lot* of Kerbal Space Program recently and with that comes the temptation to use mods. KSP is one of those games where there is a mod for almost everything -- kind of like how the TES games get a constant stream of mods, except more sciency.

Anyway, after installing a few mods it became apparant that KSP was very unstable. To the point where I could almost predict when a CTD would happen (though that didn't stop me from forgetting to quick save).

A long story short and it turns out that there a few potential fixes for this; but the most likely to work is the byte code modifications to the main KSP executable. Now, I don't know if the values are different for the x86 version but doing the following worked fantastically for me:

(thanks to a.g. and velusip for this)

~~~~
echo "7cebc7: 00" | xxd -r - KSP.x86_64
echo "7cebcc: 00" | xxd -r - KSP.x86_64
~~~~

Before running those commands though, it may be worth checking the actual returned value of those bytes:

~~~~
xxd -s +0x7cebc7 -l 1 KSP.x86_64
xxd -s +0x7cebcc -l 1 KSP.x86_64
~~~~

Should give you:

~~~~
07cebc7: 01
07cebcc: 01
~~~~

Anyway, that has at least meant that I can use the x86_64 binary and mods (without it crashing on the loading screen) and it seems to have made my install a million times more stable.

There are a few extra fixes regarding preloading libaries and enabling OpenGL optimisations which you can find in the Linux Compatibility Thread: @@ http://forum.kerbalspaceprogram.com/showthread.php/24529-The-Linux-compatibility-thread!; LCT; here; @@

However, I had an idea to combie the above fixes in to a generalised Linux Launcher to make finding these fixes easier. I will also be adding documentation to what each option does in the future, as well as using a globalised config file.

So, here's version 0.1 of my KSPLL:

~~~~
#!/bin/bash

# Linux launcher for Kerbal Space Program with fixes
# By edgley (edgley.org)

## BEGIN CONFIGURATION ##
dir="path/to/ksp"
bin="KSP.x86_64"

byte=( "0x7cebc7" "0x7cebcc" )
flag=( "00" "00" )
## END CONFIGURATION ##

scriptName="Kerbal Space Program Linux Launcher"
scriptAuthor="edgley"
scriptVersion="0.1"

function __check_byte__ () {
while [[ ${1} ]]; do
xxd -s "+${1}" -l 1 "${dir}${bin}"
__error_check__ ${?}
shift
done
echo "Press any key to continue..."
read -n 1 pause
__menu__
}

function __insert_byte__ () {
i=0
while [[ ${1} ]]; do
echo "${1}: ${flag[${i}]}" | xxd -r - "${dir}${bin}"
__error_check__ ${?}
i=$[${i}+1]
shift 1
done
echo "Press any key to continue..."
read -n 1 pause
__menu__
}

function __error_check__ () {
[[ ${1} == 2 || ${1} == 3 ]] && echo "Exception caught!"
}

function __launch_options__ () {
clear
echo "Launcher Options"
echo
[[ ${lc_all} == "1" ]] && echo "1) Disable LC_ALL" || echo "1) Enable LC_ALL"
[[ ${ld_preload} == "1" ]] && echo "2) Disable LD_PRELOAD" || echo "2) Enable LD_PRELOAD"
[[ ${gl_threaded} == "1" ]] && echo "3) Disable GL_THREADED_OPTIMIZATIONS" || echo "3) Enable GL_THREADED_OPTIMIZATIONS"
echo "5) Main Menu"
echo -n ">> "
read -n 1 userin
case ${userin} in
"1") [[ ${lc_all} == "1" ]] && lc_all=0 || lc_all=1 ;;
"2") [[ ${ld_preload} == "1" ]] && ld_preload=0 || ld_preload=1 ;;
"3") [[ ${gl_threaded} == "1" ]] && gl_threaded=0 || gl_threaded=1 ;;
"5") __menu__
esac
__launch_options__
}

function __launch__ () {
echo "Enviroment Variables Overridden"
echo "==============================="
[[ ${lc_all} == "1" ]] && LC_ALL=C && echo "LC_ALL=C"
[[ ${ld_preload} == "1" ]] && LD_PRELOAD="libpthread.so.0 libGL.so.1" && echo "LD_PRELOAD=libpthread.so.0 libGL.so.1"
[[ ${gl_threaded} == "1" ]] && __GL_THREADED_OPTIMIZATIONS=1 && echo "__GL_THREADED_OPTIMIZATIONS=1"
echo
echo "Game Launched"
echo "============="
${dir}${bin}
__error_check__ ${?}
echo "Press any key to continue..."
read -n 1 pause
__menu__
}

function __menu__ () {
clear
echo "${scriptName} - ${scriptVersion}"
echo "by ${scriptAuthor}"
echo
echo "1) Read bytecodes"
echo "2) Insert bytecodes"
echo "3) Edit Launch Options"
echo "4) Launch Game"
echo "5) Quit"
echo -n ">> "
read -n 1 userin
echo
case ${userin} in
"1") __check_byte__ ${byte[@]} ;;
"2") __insert_byte__ ${byte[@]} ;;
"3") __launch_options__ ;;
"4") __launch__ ;;
"5") clear && exit 1 ;;
"6") __get_logs__ ;;
*) __menu__ ;;
esac
}

__menu__
~~~~

I've created a git hub page: @@ https://github.com/edgleyUK/kspll; kspll; here; @@ where I will be keeping the script up to date and you can see the source code just a little better.