#!/bin/bash
# shellcheck source=scripts/functions.sh
source "/home/steam/server/functions.sh"

config_file="/satisfactory/FactoryGame/Saved/Config/LinuxServer/GameUserSettings.ini"
config_dir=$(dirname "$config_file")

mkdir -p "$config_dir" || exit

export INT_VALUES=${INT_VALUES:-"()"}
export FLOAT_VALUES=${FLOAT_VALUES:-"((\"FG.AutosaveInterval\", 300))"}
export PRIMARY_LANGUAGE=${PRIMARY_LANGUAGE:-""}
export CURRENT_FG_GAME_USER_SETTINGS_VERSION=${CURRENT_FG_GAME_USER_SETTINGS_VERSION:-0}
export PREFERRED_ONLINE_INTEGRATION_MODE=${PREFERRED_ONLINE_INTEGRATION_MODE:-"Undefined"}
export USE_VSYNC=${USE_VSYNC:-False}
export USE_DYNAMIC_RESOLUTION=${USE_DYNAMIC_RESOLUTION:-False}
export RESOLUTION_SIZE_X=${RESOLUTION_SIZE_X:-1280}
export RESOLUTION_SIZE_Y=${RESOLUTION_SIZE_Y:-720}
export LAST_USER_CONFIRMED_RESOLUTION_SIZE_X=${LAST_USER_CONFIRMED_RESOLUTION_SIZE_X:-1280}
export LAST_USER_CONFIRMED_RESOLUTION_SIZE_Y=${LAST_USER_CONFIRMED_RESOLUTION_SIZE_Y:-720}
export WINDOW_POS_X=${WINDOW_POS_X:-"-1"}
export WINDOW_POS_Y=${WINDOW_POS_Y:-"-1"}
export FULLSCREEN_MODE=${FULLSCREEN_MODE:-1}
export LAST_CONFIRMED_FULLSCREEN_MODE=${LAST_CONFIRMED_FULLSCREEN_MODE:-1}
export PREFERRED_FULLSCREEN_MODE=${PREFERRED_FULLSCREEN_MODE:-1}
export VERSION=${VERSION:-5}
export AUDIO_QUALITY_LEVEL=${AUDIO_QUALITY_LEVEL:-0}
export LAST_CONFIRMED_AUDIO_QUALITY_LEVEL=${LAST_CONFIRMED_AUDIO_QUALITY_LEVEL:-0}
export FRAME_RATE_LIMIT=${FRAME_RATE_LIMIT:-0.000000}
export DESIRED_SCREEN_WIDTH=${DESIRED_SCREEN_WIDTH:-1280}
export DESIRED_SCREEN_HEIGHT=${DESIRED_SCREEN_HEIGHT:-720}
export LAST_USER_CONFIRMED_DESIRED_SCREEN_WIDTH=${LAST_USER_CONFIRMED_DESIRED_SCREEN_WIDTH:-1280}
export LAST_USER_CONFIRMED_DESIRED_SCREEN_HEIGHT=${LAST_USER_CONFIRMED_DESIRED_SCREEN_HEIGHT:-720}
export LAST_RECOMMENDED_SCREEN_WIDTH=${LAST_RECOMMENDED_SCREEN_WIDTH:-"-1.000000"}
export LAST_RECOMMENDED_SCREEN_HEIGHT=${LAST_RECOMMENDED_SCREEN_HEIGHT:-"-1.000000"}
export LAST_CPU_BENCHMARK_RESULT=${LAST_CPU_BENCHMARK_RESULT:-"-1.000000"}
export LAST_GPU_BENCHMARK_RESULT=${LAST_GPU_BENCHMARK_RESULT:-"-1.000000"}
export LAST_GPU_BENCHMARK_MULTIPLIER=${LAST_GPU_BENCHMARK_MULTIPLIER:-1.000000}
export USE_HDR_DISPLAY_OUTPUT=${USE_HDR_DISPLAY_OUTPUT:-False}
export HDR_DISPLAY_OUTPUT_NITS=${HDR_DISPLAY_OUTPUT_NITS:-1000}
export RESOLUTION_QUALITY=${RESOLUTION_QUALITY:-100.000000}
export VIEW_DISTANCE_QUALITY=${VIEW_DISTANCE_QUALITY:-3}
export ANTI_ALIASING_QUALITY=${ANTI_ALIASING_QUALITY:-3}
export SHADOW_QUALITY=${SHADOW_QUALITY:-3}
export POST_PROCESS_QUALITY=${POST_PROCESS_QUALITY:-3}
export TEXTURE_QUALITY=${TEXTURE_QUALITY:-3}
export EFFECTS_QUALITY=${EFFECTS_QUALITY:-3}
export FOLIAGE_QUALITY=${FOLIAGE_QUALITY:-3}
export SHADING_QUALITY=${SHADING_QUALITY:-3}
export USE_DESIRED_SCREEN_HEIGHT=${USE_DESIRED_SCREEN_HEIGHT:-False}

cat > "$config_file" <<EOF
$(envsubst < /home/steam/server/templates/GameUserSettings.ini.template)
EOF