1
0
KF2-BuildTools/builder

776 lines
20 KiB
Plaintext
Raw Normal View History

2022-01-10 07:00:54 +00:00
#!/bin/bash
2022-02-13 23:20:24 +00:00
# Copyright (C) 2022 GenZmeY
# mailto: genzmey@gmail.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2022-01-10 07:00:54 +00:00
# Requirements: git-bash
# https://git-scm.com/download/win
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
2022-02-13 23:57:53 +00:00
function reg_readkey () # $1: path, $2: key
{
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
cygpath -u "$(
reg query "$1" //v "$2" | \
grep -F "$2" | \
awk '{ $1=$2=""; print $0 }' | \
sed -r 's|^\s*(.+)\s*|\1|g')"
fi
2022-02-13 23:57:53 +00:00
}
2022-02-13 17:15:24 +00:00
# Whoami
2022-01-10 07:00:54 +00:00
ScriptFullname=$(readlink -e "$0")
ScriptName=$(basename "$0")
ScriptDir=$(dirname "$ScriptFullname")
# Common
SteamPath=$(reg_readkey "HKCU\Software\Valve\Steam" "SteamPath")
DocumentsPath=$(reg_readkey "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Personal")
ThirdPartyBin="$ScriptDir/3rd-party-bin"
# Usefull KF2 executables / Paths / Configs
KFDoc="$DocumentsPath/My Games/KillingFloor2"
KFPath="$SteamPath/steamapps/common/killingfloor2"
KFWin64="$KFPath/Binaries/Win64"
KFEditor="$KFWin64/KFEditor.exe"
KFEditorPatcher="$KFWin64/kfeditor_patcher.exe"
KFEditorMergePackages="$KFWin64/KFEditor_mergepackages.exe"
KFGame="$KFWin64/KFGame.exe"
KFWorkshop="$KFPath/Binaries/WorkshopUserTool.exe"
KFUnpublish="$KFDoc/KFGame/Unpublished"
KFPublish="$KFDoc/KFGame/Published"
KFEditorConf="$KFDoc/KFGame/Config/KFEditor.ini"
# Source filesystem
MutSource="$ScriptDir/.."
MutPubContent="$MutSource/PublicationContent"
MutConfig="$MutSource/Config"
MutLocalization="$MutSource/Localization"
2022-01-14 23:51:08 +00:00
MutBuildConfig="$MutSource/build.cfg"
MutTestConfig="$MutSource/test.cfg"
2022-01-10 07:00:54 +00:00
# Steam workshop upload filesystem
KFUnpublishBrewedPC="$KFUnpublish/BrewedPC"
KFUnpublishPackages="$KFUnpublishBrewedPC/Packages"
KFUnpublishScript="$KFUnpublishBrewedPC/Script"
KFUnpublishConfig="$KFUnpublish/Config"
KFUnpublishLocalization="$KFUnpublish/Localization"
KFPublishBrewedPC="$KFPublish/BrewedPC"
KFPublishPackages="$KFPublishBrewedPC/Packages"
KFPublishScript="$KFPublishBrewedPC/Script"
KFPublishConfig="$KFPublish/Config"
KFPublishLocalization="$KFPublish/Localization"
# Tmp files
2022-01-14 22:22:30 +00:00
MutWsInfo="$KFDoc/wsinfo.txt"
2022-01-10 07:00:54 +00:00
KFEditorConfBackup="$KFEditorConf.backup"
# Args
ArgInitBuild="false"
ArgInitTest="false"
ArgCompile="false"
ArgBrew="false"
ArgBrewManual="false"
ArgUpload="false"
ArgTest="false"
ArgVersion="false"
ArgHelp="false"
ArgDebug="false"
ArgQuiet="false"
ArgWarnings="false"
ArgNoColors="false"
2022-02-14 00:47:44 +00:00
# Colors
RED=''
GRN=''
YLW=''
2022-02-14 01:11:24 +00:00
BLU=''
2022-02-14 00:47:44 +00:00
DEF=''
BLD=''
2022-02-13 17:15:24 +00:00
function is_true () # $1: Bool arg to check
{
echo "$1" | grep -Piq '^true$'
}
function get_latest () # $1: Reponame, $2: filename, $3: output filename
{
local ApiUrl="https://api.github.com/repos/$1/releases/latest"
local LatestTag=""
LatestTag=$(curl --silent "$ApiUrl" | grep -Po '"tag_name": "\K.*?(?=")')
2022-02-13 17:15:24 +00:00
local DownloadUrl="https://github.com/$1/releases/download/$LatestTag/$2"
2022-02-14 01:11:24 +00:00
msg "download $2 ($LatestTag)"
2022-02-13 17:15:24 +00:00
mkdir -p "$(dirname "$3")/"
curl -LJs "$DownloadUrl" -o "$3"
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully downloaded${DEF}"
2022-02-13 17:15:24 +00:00
}
function get_latest_multini () # $1: file to save
{
get_latest "GenZmeY/multini" "multini-windows-amd64.exe" "$1"
}
function get_latest_kfeditor_patcher () # $1: file to save
{
get_latest "notpeelz/kfeditor-patcher" "kfeditor_patcher.exe" "$1"
}
function setup_colors ()
{
if [[ -t 2 ]] && ! is_true "$ArgNoColors" && [[ "${TERM-}" != "dumb" ]]; then
RED='\e[31m'
GRN='\e[32m'
YLW='\e[33m'
2022-02-14 01:11:24 +00:00
BLU='\e[34m'
DEF='\e[0m'
BLD='\e[1m'
fi
2022-01-10 07:00:54 +00:00
}
function err () # $1: String
{
if ! is_true "$ArgQuiet"; then
echo -e "${RED}${1-}${DEF}" >&2
fi
}
function msg () # $1: String
{
if ! is_true "$ArgQuiet"; then
2022-02-14 01:11:24 +00:00
if is_true "$ArgDebug"; then
echo -e "${BLU}${1-}${DEF}" >&1
else
2022-02-14 01:57:54 +00:00
echo -e "${DEF}${1-}${DEF}" >&1
2022-02-14 01:11:24 +00:00
fi
fi
}
function die () # $1: String, $2: Exit code
{
err "${1-}"
exit "${2-3}"
}
function usage ()
{
2022-02-14 00:08:18 +00:00
local HelpMessage=""
HelpMessage=$(cat <<EOF
${BLD}Usage:${DEF} $0 OPTIONS
Build, pack, test and upload your kf2 packages to the Steam Workshop.
${BLD}Available options:${DEF}
-ib, --init-build generate $(basename "$MutBuildConfig") with build parameters
-it, --init-test generate $(basename "$MutTestConfig") with test parameters
-i, --init the same as "./$ScriptName --init-build; ./$ScriptName --init-test"
-c, --compile build package(s)
-b, --brew compress *.upk and place inside *.u
-bm, --brew-manual the same (almost) as above, but with patched kfeditor by @notpeelz
-u, --upload upload package(s) to the Steam Workshop
-t, --test run local single player test with $(basename "$MutTestConfig") parameters
-q, --quiet run without output
-w, --warnings do not close kf2editor automatically (to be able to read warnings)
-nc, --no-colors do not use color output
-d, --debug print every executed command (script debug)
-v, --version show version
-h, --help show this help
${BLD}Short options can be combined, examples:${DEF}
-cbu compile, brew, upload
-cbmt compile, brew_manual, run_test
-wcb compile and brew without closing kf2editor
etc...
EOF
)
msg "$HelpMessage"
}
function version ()
{
msg "${BLD}$ScriptName $(git describe 2> /dev/null)${DEF}"
}
2022-01-10 07:00:54 +00:00
function cleanup()
{
trap - SIGINT SIGTERM ERR EXIT
restore_kfeditorconf
}
function backup_kfeditorconf ()
{
2022-02-14 01:57:54 +00:00
msg "backup $(basename "$KFEditorConf") to $(basename "$KFEditorConfBackup")"
2022-01-10 07:00:54 +00:00
cp -f "$KFEditorConf" "$KFEditorConfBackup"
}
function restore_kfeditorconf ()
{
if [[ -f "$KFEditorConfBackup" ]]; then
2022-02-14 01:57:54 +00:00
msg "restore $(basename "$KFEditorConf") from backup"
2022-01-10 07:00:54 +00:00
mv -f "$KFEditorConfBackup" "$KFEditorConf"
fi
}
function init_build ()
{
local PackageList=""
2022-02-14 01:57:54 +00:00
msg "creating new build config"
2022-01-10 07:00:54 +00:00
:> "$MutBuildConfig"
2022-01-14 22:22:30 +00:00
while read -r Package
2022-01-10 07:00:54 +00:00
do
if [[ -z "$PackageList" ]]; then
PackageList="$Package"
else
PackageList="$PackageList $Package"
fi
done < <(find "$MutSource" -mindepth 2 -maxdepth 2 -type d -ipath '*/Classes' | sed -r 's|.+/([^/]+)/[^/]+|\1|' | sort)
2022-02-14 01:57:54 +00:00
msg "packages found: $PackageList"
2022-01-16 02:07:46 +00:00
cat > "$MutBuildConfig" <<EOF
# Build parameters
# If True - compresses the mutator when compiling
# Scripts will be stored in binary form
# (reduces the size of the output file)
StripSource="True"
# Mutators to be compiled
# Specify them with a space as a separator,
# Mutators will be compiled in the specified order
PackageBuildOrder="$PackageList"
# Mutators that will be uploaded to the workshop
# Specify them with a space as a separator,
# The order doesn't matter
PackageUpload="$PackageList"
EOF
2022-02-14 01:57:54 +00:00
msg "${GRN}$(basename "$MutBuildConfig") created${DEF}"
2022-01-10 07:00:54 +00:00
}
function read_build_settings ()
{
if ! [[ -f "$MutBuildConfig" ]]; then init_build; fi
if bash -n "$MutBuildConfig"; then
2022-01-14 23:59:00 +00:00
# shellcheck source=./.shellcheck/build.cfg
2022-01-10 07:00:54 +00:00
source "$MutBuildConfig"
else
die "$MutBuildConfig broken! Check this file before continue or create new one using --init-build option" 2
2022-01-10 07:00:54 +00:00
fi
}
function read_test_settings ()
{
if ! [[ -f "$MutTestConfig" ]]; then init_test; fi
if bash -n "$MutTestConfig"; then
2022-01-14 23:59:00 +00:00
# shellcheck source=./.shellcheck/test.cfg
2022-01-10 07:00:54 +00:00
source "$MutTestConfig"
else
die "$MutTestConfig broken! Check this file before continue or create new one using --init-test option" 2
2022-01-10 07:00:54 +00:00
return 1
fi
}
2022-01-24 00:20:41 +00:00
function merge_package () # $1: What, $2: Where
2022-01-10 07:00:54 +00:00
{
2022-01-14 22:22:30 +00:00
local ModificationTime=""
2022-01-24 00:20:41 +00:00
local ModificationTimeNew=""
2022-01-14 22:22:30 +00:00
local PID=""
2022-01-10 07:00:54 +00:00
2022-02-14 01:11:24 +00:00
msg "merge $1 into $2"
if is_true "$ArgWarnings"; then
CMD //C "cd /D $(cygpath -w "$KFWin64") && $(basename "$KFEditorMergePackages") make $1 $2"
else
ModificationTime=$(stat -c %y "$KFWin64/$2")
CMD //C "cd /D $(cygpath -w "$KFWin64") && $(basename "$KFEditorMergePackages") make $1 $2" &
PID="$!"
while ps -p "$PID" &> /dev/null
do
ModificationTimeNew="$(stat -c %y "$KFWin64/$2")"
if [[ "$ModificationTime" != "$ModificationTimeNew" ]]; then # wait for write
while ps -p "$PID" &> /dev/null
do
ModificationTime="$ModificationTimeNew"
sleep 1
ModificationTimeNew="$(stat -c %y "$KFWin64/$2")"
if [[ "$ModificationTime" == "$ModificationTimeNew" ]]; then # wait for write finish
kill "$PID"
rm -f "$KFWin64/$1" # cleanup (auto)
return 0
fi
done
fi
sleep 1
done
fi
2022-01-24 00:20:41 +00:00
rm -f "$KFWin64/$1" # cleanup (manual)
}
function merge_packages () # $1: Mutator name
{
msg "merge packages for $1.u"
2022-01-10 07:00:54 +00:00
cp -f "$KFUnpublishScript/$1.u" "$KFWin64"
2022-01-14 22:22:30 +00:00
while read -r Upk
2022-01-10 07:00:54 +00:00
do
cp -f "$MutSource/$1/$Upk" "$KFWin64"
2022-01-24 00:20:41 +00:00
merge_package "$Upk" "$1.u"
2022-01-10 07:00:54 +00:00
done < <(find "$MutSource/$1" -type f -name '*.upk' -printf "%f\n")
}
function compiled ()
{
for Package in $PackageBuildOrder
do
if ! test -f "$KFUnpublishScript/$Package.u"; then
return 1
fi
done
}
function compile ()
{
2022-01-16 02:07:46 +00:00
local StripSourceArg=""
2022-01-14 22:22:30 +00:00
local PID=""
2022-01-10 07:00:54 +00:00
read_build_settings
2022-01-15 02:48:16 +00:00
2022-01-10 07:00:54 +00:00
if ! command -v multini &> /dev/null; then
2022-01-15 02:48:16 +00:00
get_latest_multini "$ThirdPartyBin/multini.exe"
2022-01-10 07:00:54 +00:00
fi
backup_kfeditorconf
multini --del "$KFEditorConf" 'ModPackages' 'ModPackages'
for Package in $PackageBuildOrder
do
multini --add "$KFEditorConf" 'ModPackages' 'ModPackages' "$Package"
done
multini --set "$KFEditorConf" 'ModPackages' 'ModPackagesInPath' "$(cygpath -w "$MutSource")"
rm -rf "$KFUnpublish" "$KFPublish"
mkdir -p "$KFUnpublishPackages" "$KFUnpublishScript"
2022-01-14 22:22:30 +00:00
for Package in $PackageBuildOrder
do
find "$MutSource/$Package" -type f -name '*.upk' -exec cp -f {} "$KFUnpublishPackages" \;
done
2022-01-10 07:00:54 +00:00
if [[ -d "$MutLocalization" ]]; then
mkdir -p "$KFUnpublishLocalization"
cp -rf "$MutLocalization"/* "$KFUnpublishLocalization"
fi
if [[ -d "$MutConfig" ]]; then
mkdir -p "$KFUnpublishConfig"
cp -rf "$MutConfig"/* "$KFUnpublishConfig"
fi
2022-01-16 02:07:46 +00:00
if is_true "$StripSource"; then StripSourceArg="-stripsource"; fi
2022-02-14 00:35:07 +00:00
msg "compilation"
if is_true "$ArgWarnings"; then
CMD //C "$(cygpath -w "$KFEditor") make $StripSourceArg -useunpublished"
if ! compiled; then
2022-02-14 00:47:44 +00:00
die "compilation failed"
fi
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully compiled${DEF}"
else
CMD //C "$(cygpath -w "$KFEditor") make $StripSourceArg -useunpublished" &
PID="$!"
while ps -p "$PID" &> /dev/null
do
2022-02-14 00:35:07 +00:00
if compiled; then
kill "$PID"
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully compiled${DEF}"
2022-02-14 00:35:07 +00:00
break
fi
sleep 1
done
fi
2022-01-24 04:17:19 +00:00
find "$KFUnpublish" -type d -empty -delete
2022-01-10 07:00:54 +00:00
restore_kfeditorconf
}
function publish_common ()
{
if [[ -d "$MutLocalization" ]]; then
mkdir -p "$KFPublishLocalization"
cp -rf "$MutLocalization"/* "$KFPublishLocalization"
fi
if [[ -d "$MutConfig" ]]; then
mkdir -p "$KFPublishConfig"
cp -rf "$MutConfig"/* "$KFPublishConfig"
fi
}
function brewed ()
{
for Package in $PackageUpload
do
if ! test -f "$KFPublishBrewedPC/$Package.u"; then
return 1
fi
done
}
2022-01-24 02:26:49 +00:00
function brew_cleanup ()
{
for Package in $PackageBuildOrder
do
if ! echo "$PackageUpload" | grep -Pq "(^|\s+)$Package(\s+|$)"; then
find "$KFPublishBrewedPC" -type f -name "$Package.u" -delete
find "$MutSource/$Package" -type f -name '*.upk' -printf "%f\n" | xargs -I{} find "$KFPublishBrewedPC" -type f -name {} -delete
fi
done
2022-01-24 03:22:17 +00:00
2022-01-24 02:26:49 +00:00
rm -f "$KFPublishBrewedPC"/*.tmp
}
2022-01-10 07:00:54 +00:00
function brew ()
{
2022-01-14 22:22:30 +00:00
local PID=""
2022-02-14 00:35:07 +00:00
msg "brewing"
2022-01-10 07:00:54 +00:00
read_build_settings
if ! compiled ; then
die "You must compile packages before brewing. Use --compile option for this." 2
2022-01-10 07:00:54 +00:00
fi
rm -rf "$KFPublish"
mkdir -p "$KFPublishBrewedPC"
if is_true "$ArgWarnings"; then
CMD //C "cd /D $(cygpath -w "$KFWin64") && $(basename "$KFEditor") brewcontent -platform=PC $PackageUpload -useunpublished"
if ! brewed; then
brew_cleanup
2022-02-14 00:47:44 +00:00
die "brewing failed"
fi
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully brewed${DEF}"
else
CMD //C "cd /D $(cygpath -w "$KFWin64") && $(basename "$KFEditor") brewcontent -platform=PC $PackageUpload -useunpublished" &
PID="$!"
while ps -p "$PID" &> /dev/null
do
2022-02-14 00:35:07 +00:00
if brewed; then
kill "$PID"
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully brewed${DEF}"
2022-02-14 00:35:07 +00:00
break
fi
sleep 1
done
fi
2022-01-10 07:00:54 +00:00
publish_common
2022-01-24 02:26:49 +00:00
brew_cleanup
2022-01-24 03:22:17 +00:00
2022-01-24 04:17:19 +00:00
find "$KFPublish" -type d -empty -delete
2022-01-10 07:00:54 +00:00
}
function brew_manual ()
{
2022-02-14 00:35:07 +00:00
msg "manual brewing"
2022-01-10 07:00:54 +00:00
read_build_settings
if ! compiled ; then
die "You must compile packages before brewing. Use --compile option for this." 2
2022-01-10 07:00:54 +00:00
fi
rm -rf "$KFPublish"
2022-01-24 00:20:41 +00:00
mkdir -p "$KFPublishBrewedPC"
2022-01-10 07:00:54 +00:00
if ! [[ -x "$KFEditorPatcher" ]]; then
get_latest_kfeditor_patcher "$KFEditorPatcher"
fi
2022-02-14 01:57:54 +00:00
msg "patching $(basename "$KFEditor")"
2022-01-24 00:20:41 +00:00
CMD //C "cd /D $(cygpath -w "$KFWin64") && $(basename "$KFEditorPatcher")"
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully patched${DEF}"
2022-01-10 07:00:54 +00:00
for Package in $PackageUpload
do
merge_packages "$Package"
2022-01-24 00:20:41 +00:00
mv "$KFWin64/$Package.u" "$KFPublishBrewedPC"
2022-01-10 07:00:54 +00:00
done
2022-02-14 01:57:54 +00:00
msg "${GRN}successfully brewed${DEF}"
2022-02-14 01:11:24 +00:00
2022-01-10 07:00:54 +00:00
publish_common
2022-01-24 03:22:17 +00:00
2022-01-24 04:17:19 +00:00
find "$KFPublish" -type d -empty -delete
2022-01-24 03:22:17 +00:00
}
function publish_unpublished ()
{
2022-02-14 01:57:54 +00:00
msg "${YLW}warn: uploading without brewing${DEF}"
2022-01-24 03:22:17 +00:00
mkdir -p "$KFPublishBrewedPC" "$KFPublishScript" "$KFPublishPackages"
for Package in $PackageUpload
do
cp -f "$KFUnpublishScript/$Package.u" "$KFPublishScript"
find "$MutSource/$Package" -type f -name '*.upk' -exec cp -f {} "$KFPublishPackages" \;
done
publish_common
2022-01-24 04:17:19 +00:00
find "$KFPublish" -type d -empty -delete
2022-01-10 07:00:54 +00:00
}
function upload ()
{
2022-01-14 22:22:30 +00:00
local PreparedWsDir=""
2022-01-10 07:00:54 +00:00
read_build_settings
if ! compiled ; then
die "You must compile packages before uploading. Use --compile option for this." 2
2022-01-10 07:00:54 +00:00
fi
if ! [[ -d "$KFPublish" ]]; then
2022-01-24 03:22:17 +00:00
publish_unpublished
2022-01-10 07:00:54 +00:00
fi
2022-01-24 04:17:19 +00:00
find "$KFPublish" -type d -empty -delete
2022-01-10 07:00:54 +00:00
2022-01-24 03:22:17 +00:00
PreparedWsDir=$(mktemp -d -u -p "$KFDoc")
2022-01-10 07:00:54 +00:00
cat > "$MutWsInfo" <<EOF
2022-01-16 04:18:08 +00:00
\$Description "$(cat "$MutPubContent/description.txt")"
\$Title "$(cat "$MutPubContent/title.txt")"
\$PreviewFile "$(cygpath -w "$MutPubContent/preview.png")"
\$Tags "$(cat "$MutPubContent/tags.txt")"
\$MicroTxItem "false"
\$PackageDirectory "$(cygpath -w "$PreparedWsDir")"
2022-01-10 07:00:54 +00:00
EOF
2022-01-15 02:48:16 +00:00
cp -rf "$KFPublish" "$PreparedWsDir"
2022-01-10 07:00:54 +00:00
2022-02-14 01:57:54 +00:00
msg "upload to steam workshop"
if is_true "$ArgQuiet"; then
CMD //C "$(cygpath -w "$KFWorkshop") $(basename "$MutWsInfo")" &>/dev/null
else
CMD //C "$(cygpath -w "$KFWorkshop") $(basename "$MutWsInfo")"
fi
msg "${GRN}successfully uploaded to steam workshop${DEF}"
2022-01-10 07:00:54 +00:00
rm -rf "$PreparedWsDir"
rm -f "$MutWsInfo"
}
function init_test ()
{
local AviableMutators=""
local AviableGamemodes=""
2022-02-14 01:57:54 +00:00
msg "creating new test config"
2022-01-15 02:48:16 +00:00
read_build_settings
2022-01-10 07:00:54 +00:00
for Package in $PackageUpload
do
# find available mutators
2022-01-14 22:22:30 +00:00
while read -r MutClass
2022-01-10 07:00:54 +00:00
do
if [[ -z "$AviableMutators" ]]; then
AviableMutators="$Package.$MutClass"
else
AviableMutators="$AviableMutators,$Package.$MutClass"
fi
done < <(grep -rihPo '\s.+extends\s(KF)?Mutator' "$MutSource/$Package" | awk '{ print $1 }')
# find available gamemodes
2022-01-14 22:22:30 +00:00
while read -r GamemodeClass
2022-01-10 07:00:54 +00:00
do
if [[ -z "$AviableGamemodes" ]]; then
2022-01-14 22:22:30 +00:00
AviableGamemodes="$Package.$GamemodeClass"
2022-01-10 07:00:54 +00:00
else
2022-01-14 22:22:30 +00:00
AviableGamemodes="$AviableGamemodes,$Package.$GamemodeClass"
2022-01-10 07:00:54 +00:00
fi
done < <(grep -rihPo '\s.+extends\sKFGameInfo_' "$MutSource/$Package" | awk '{ print $1 }')
done
2022-02-14 01:57:54 +00:00
if [[ -n "$AviableMutators" ]]; then
msg "mutators found: $AviableMutators"
fi
2022-01-10 07:00:54 +00:00
if [[ -z "$AviableGamemodes" ]]; then
AviableGamemodes="KFGameContent.KFGameInfo_Survival"
2022-02-14 01:57:54 +00:00
else
msg "custom gamemodes found: $AviableGamemodes"
2022-01-10 07:00:54 +00:00
fi
cat > "$MutTestConfig" <<EOF
# Test parameters
# Map:
Map="KF-Nuked"
# Game:
# Survival: KFGameContent.KFGameInfo_Survival
# WeeklyOutbreak: KFGameContent.KFGameInfo_WeeklySurvival
# Endless: KFGameContent.KFGameInfo_Endless
# Objective: KFGameContent.KFGameInfo_Objective
# Versus: KFGameContent.KFGameInfo_VersusSurvival
Game="$AviableGamemodes"
# Difficulty:
# Normal: 0
# Hard: 1
# Suicide: 2
# Hell: 3
Difficulty="0"
# GameLength:
# 4 waves: 0
# 7 waves: 1
# 10 waves: 2
GameLength="0"
# Mutators
Mutators="$AviableMutators"
# Additional parameters
Args=""
EOF
2022-02-14 01:57:54 +00:00
msg "${GRN}$(basename "$MutTestConfig") created${DEF}"
2022-01-10 07:00:54 +00:00
}
function run_test ()
{
local UseUnpublished=""
read_build_settings
read_test_settings
2022-02-14 01:57:54 +00:00
if ! brewed; then
UseUnpublished="-useunpublished"
msg "run test (unpublished)"
else
msg "run test (brewed)"
fi
2022-01-10 07:00:54 +00:00
2022-01-15 02:48:16 +00:00
CMD //C "$(cygpath -w "$KFGame") $Map?Difficulty=$Difficulty?GameLength=$GameLength?Game=$Game?Mutator=$Mutators?$Args $UseUnpublished" -log
2022-01-10 07:00:54 +00:00
}
function parse_combined_params () # $1: Combined short parameters
{
local Param="${1}"
local Length="${#Param}"
local Position=1
while true
do
2022-02-14 02:10:22 +00:00
if [[ "$Position" -ge "$Length" ]]; then break; fi
case "${Param:$Position:2}" in
ib ) ((Position+=2)); ArgInitBuild="true" ;;
it ) ((Position+=2)); ArgInitTest="true" ;;
bm ) ((Position+=2)); ArgBrewManual="true" ;;
nc ) ((Position+=2)); ArgNoColors="true" ;;
esac
2022-02-14 01:11:24 +00:00
if [[ "$Position" -ge "$Length" ]]; then break; fi
case "${Param:$Position:1}" in
h ) ((Position+=1)); ArgHelp="true" ;;
v ) ((Position+=1)); ArgVersion="true" ;;
i ) ((Position+=1)); ArgInitBuild="true"; ArgInitTest="true" ;;
c ) ((Position+=1)); ArgCompile="true" ;;
b ) ((Position+=1)); ArgBrew="true" ;;
u ) ((Position+=1)); ArgUpload="true" ;;
t ) ((Position+=1)); ArgTest="true" ;;
d ) ((Position+=1)); ArgDebug="true" ;;
q ) ((Position+=1)); ArgQuiet="true" ;;
2022-02-14 00:47:44 +00:00
w ) ((Position+=1)); ArgWarnings="true" ;;
* ) die "Unknown short option: -${Param:$Position:1}" 1 ;;
esac
done
}
function parse_params () # $@: Args
{
while true
do
case "${1-}" in
-h | --help ) ArgHelp="true" ;;
-v | --version ) ArgVersion="true" ;;
-ib | --init-build ) ArgInitBuild="true" ;;
-it | --init-test ) ArgInitTest="true" ;;
-i | --init ) ArgInitBuild="true"; ArgInitTest="true" ;;
-c | --compile ) ArgCompile="true" ;;
-b | --brew ) ArgBrew="true" ;;
-bm | --brew-manual ) ArgBrewManual="true" ;;
-u | --upload ) ArgUpload="true" ;;
-t | --test ) ArgTest="true" ;;
-d | --debug ) ArgDebug="true" ;;
-q | --quiet ) ArgQuiet="true" ;;
-w | --warnings ) ArgWarnings="true" ;;
-nc | --no-color ) ArgNoColors="true" ;;
--* ) die "Unknown option: ${1}" 1 ;;
-* ) parse_combined_params "${1}" ;;
* ) if [[ -n "${1-}" ]]; then die "Unknown option: ${1-}" 1; fi; break ;;
esac
shift
done
}
function main ()
{
if [[ $# -eq 0 ]]; then usage; die "" 0; fi
parse_params "$@"
setup_colors
export PATH="$PATH:$ThirdPartyBin"
# Modifiers
if is_true "$ArgDebug"; then set -o xtrace; fi
# Actions
if is_true "$ArgVersion"; then version; die "" 0; fi
if is_true "$ArgHelp"; then usage; die "" 0; fi
if is_true "$ArgInitBuild"; then init_build; fi
if is_true "$ArgInitTest"; then init_test; fi
if is_true "$ArgCompile"; then compile; fi
if is_true "$ArgBrew"; then brew; fi
if is_true "$ArgBrewManual"; then brew_manual; fi
if is_true "$ArgUpload"; then upload; fi
if is_true "$ArgTest"; then run_test; fi
}
main "$@"