-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder
1189 lines (1013 loc) · 32.2 KB
/
builder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright (C) 2022-2023 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/>.
# Requirements: git-bash
# https://git-scm.com/download/win
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
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
}
function steamlib_by_steamid () # $1: SteamID
{
local Path
if ! [[ -f "$SteamLibFoldersVdf" ]]; then
return
fi
while read -r Line
do
if echo "$Line" | grep -Foq '"path"'; then
Path="$(echo "$Line" | sed -r 's|^\s*\"path\"\s*||' | sed 's|"||g')"
fi
if echo "$Line" | grep -Poq "^\s*\"${1}\"\s*\"\d+\"$"; then
wrapped_cygpath --unix "$Path"
fi
done < "$SteamLibFoldersVdf"
}
function wrapped_cygpath () # $@: Params
{
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
cygpath "$@"
fi
}
# Whoami
ScriptFullname="$(readlink -e "$0")"
ScriptName="$(basename "$0")"
ScriptDir="$(dirname "$ScriptFullname")"
# Common
SteamPath="$(reg_readkey "HKCU\Software\Valve\Steam" "SteamPath")"
DocumentsPath="$(wrapped_cygpath --mydocs)"
ThirdPartyBin="$ScriptDir/3rd-party-bin"
DummyPreview="$ScriptDir/dummy_preview.png"
SteamLibFoldersVdf="$SteamPath/steamapps/libraryfolders.vdf"
# Usefull KF2 executables / Paths / Configs
KFDoc="$DocumentsPath/My Games/KillingFloor2"
KFSteamLibraryFolder="$(steamlib_by_steamid "232090")"
KFSDKSteamLibraryFolder="$(steamlib_by_steamid "232150")"
KFPath="$KFSteamLibraryFolder/steamapps/common/killingfloor2"
KFSDKPath="$KFSDKSteamLibraryFolder/steamapps/common/killingfloor2"
KFDev="$KFSDKPath/Development/Src"
KFWin64="$KFSDKPath/Binaries/Win64"
KFEditor="$KFWin64/KFEditor.exe"
KFEditorPatcher="$KFWin64/kfeditor_patcher.exe"
KFEditorMergePackages="$KFWin64/KFEditor_mergepackages.exe"
KFGame="$KFPath/Binaries/Win64/KFGame.exe"
KFWorkshop="$KFPath/Binaries/WorkshopUserTool.exe"
KFUnpublish="$KFDoc/KFGame/Unpublished"
KFPublish="$KFDoc/KFGame/Published"
KFEditorConf="$KFDoc/KFGame/Config/KFEditor.ini"
KFLogs="$KFDoc/KFGame/Logs"
# Source filesystem
MutSource="$(readlink -e "$ScriptDir/..")"
MutConfig="$MutSource/Config"
MutLocalization="$MutSource/Localization"
MutBrewedPCAddon="$MutSource/BrewedPC"
MutBuilderConfig="$MutSource/builder.cfg"
MutPubContent="$MutSource/PublicationContent"
MutPubContentDescription="$MutPubContent/description.txt"
MutPubContentTitle="$MutPubContent/title.txt"
MutPubContentPreview="$MutPubContent/preview"
MutPubContentTags="$MutPubContent/tags.txt"
# 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
MutWsInfo="$KFDoc/wsinfo.txt"
KFEditorConfBackup="$KFEditorConf.backup"
# Args
ArgInit="false"
ArgCompile="false"
ArgBrew="false"
ArgUpload="false"
ArgTest="false"
ArgVersion="false"
ArgHelp="false"
ArgDebug="false"
ArgQuiet="false"
ArgHoldEditor="false"
ArgNoColors="false"
ArgForce="false"
ArgUpdate="false"
# Colors
RED=''
GRN=''
YLW=''
BLU=''
DEF=''
BLD=''
# PNG
DummyPreviewRaw='\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\x00\x00\x20\x00\x00\x00\x20\x01\x03\x00\x00\x00\x49\xb4\xe8\xb7\x00\x00\x00\x01\x73\x52\x47\x42\x00\xae\xce\x1c\xe9\x00\x00\x00\x04\x67\x41\x4d\x41\x00\x00\xb1\x8f\x0b\xfc\x61\x05\x00\x00\x00\x06\x50\x4c\x54\x45\x00\x00\x00\xff\xff\xff\xa5\xd9\x9f\xdd\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0e\xc4\x00\x00\x0e\xc4\x01\x95\x2b\x0e\x1b\x00\x00\x00\x14\x49\x44\x41\x54\x18\xd3\x63\x60\x60\xf8\xff\x9f\x9a\x04\x55\x4d\x63\x60\x00\x00\xed\xbd\x3f\xc1\xbb\x2a\xd9\x62\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82'
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.*?(?=")')"
local DownloadUrl="https://github.com/$1/releases/download/$LatestTag/$2"
msg "download $2 ($LatestTag)"
mkdir -p "$(dirname "$3")/"
curl -LJs "$DownloadUrl" -o "$3"
msg "successfully downloaded" "${GRN}"
}
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 repo_url () # $1: remote.origin.url
{
if echo "$1" | grep -qoP '^https?://'; then
echo "$1" | sed -r 's|\.git||'
else
echo "$1" | sed -r 's|^.+:(.+)\.git$|https://github.com/\1|'
fi
}
function setup_colors ()
{
if [[ -t 2 ]] && ! is_true "$ArgNoColors" && [[ "${TERM-}" != "dumb" ]]; then
RED='\e[31m'
GRN='\e[32m'
YLW='\e[33m'
BLU='\e[34m'
DEF='\e[0m'
BLD='\e[1m'
fi
}
function err () # $1: String
{
if ! is_true "$ArgQuiet"; then
echo -e "${RED}${1-}${DEF}" >&2
fi
}
function msg () # $1: String, $2: Color code (global)
{
if ! is_true "$ArgQuiet"; then
if is_true "$ArgDebug"; then
echo -e "${BLU}${2-}${1-}${DEF}" >&1
else
echo -e "${DEF}${2-}${1-}${DEF}" >&1
fi
fi
}
function die () # $1: String, $2: Exit code
{
err "${1-}"
exit "${2-3}"
}
function warn () # $1: String
{
msg "${1-}" "${YLW}"
}
function show_help ()
{
local HelpMessage=""
HelpMessage="$(cat <<EOF
${BLD}Usage:${DEF} $0 OPTIONS
Compile, brew, test and upload your kf2 packages to the Steam Workshop.
${BLD}Available options:${DEF}
-i, --init generate $(basename "$MutBuilderConfig") and $(basename "$MutPubContent")
-c, --compile compile package(s)
-b, --brew compress *.upk and place inside *.u
-u, --upload upload package(s) to the Steam Workshop
-t, --test run local single player test
-f, --force overwrites existing files when used with --init
-q, --quiet run without output
-he, --hold-editor do not close kf2editor automatically
-nc, --no-colors do not use color output
-d, --debug print every executed command (script debug)
--update update build tools
-v, --version show version
-h, --help show this help
${BLD}Short options can be combined, examples:${DEF}
-if recreate build.cfg and PublicationContent, replace old ones
-cbu compile, brew, upload
-cbhe compile and brew without closing kf2editor
etc...
EOF
)"
msg "$HelpMessage"
}
function version ()
{
local Version=""
Version="$(git describe 2> /dev/null)"
if [[ -z "$Version" ]]; then
Version="(standalone)"
fi
echo "$Version"
}
function show_version ()
{
msg "$ScriptName $(version)" "${BLD}"
}
function cleanup()
{
trap - SIGINT SIGTERM ERR EXIT
restore_kfeditorconf
}
function backup_kfeditorconf ()
{
if [[ -e "$KFEditorConf" ]]; then
msg "backup $(basename "$KFEditorConf") to $(basename "$KFEditorConfBackup")"
cp -f "$KFEditorConf" "$KFEditorConfBackup"
else
die "$(basename "$KFEditorConf") not found! Run KF2 Editor to generate the config" 2
fi
}
function restore_kfeditorconf ()
{
if [[ -f "$KFEditorConfBackup" ]]; then
msg "restore $(basename "$KFEditorConf") from backup"
mv -f "$KFEditorConfBackup" "$KFEditorConf"
fi
}
function print_list () # $1: List with spaces, $2: New separator
{
echo "${1// /$2}"
}
function init ()
{
local PackageList=""
local AviableMutators=""
local AviableGamemodes=""
local AviableMaps=""
local ProjectName=""
local GitUsername=""
local GitRemoteUrl=""
local PublicationTags=""
local DefGamemode=""
local DefMap=""
local BaseList=""
local BaseListNext=""
if [[ -e "$MutBuilderConfig" ]]; then
if is_true "$ArgForce"; then
msg "rewriting $(basename "$MutBuilderConfig")"
fi
else
msg "creating new $(basename "$MutBuilderConfig")"
fi
if [[ -d "$MutBrewedPCAddon" ]]; then
while read -r Map
do
if [[ -z "$AviableMaps" ]]; then
DefMap="$Map"
AviableMaps="$Map"
else
AviableMaps="$AviableMaps $Map"
fi
done < <(find "$MutBrewedPCAddon" -type f -iname '*.kfm' -printf "%f\n" | sort)
fi
while read -r Package
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)
if [[ -n "$PackageList" ]]; then
msg "packages found: $(print_list "$PackageList" ", ")"
fi
# DISCLAMER: BigO nightmare (*)
# Remove seniors with a weak psyche from the screen
#
# (*) As planned though:
# Initialized once and quickly even on large projects,
# There is no point in optimizing this
if [[ -n "$PackageList" ]]; then
# find available mutators
BaseList='(KF)?Mutator'
BaseListNext=''
while [[ -n "$BaseList" ]]
do
for Base in $BaseList
do
for Package in $PackageList
do
while read -r Class
do
if [[ -z "$AviableMutators" ]]; then
AviableMutators="$Package.$Class"
else
AviableMutators="$AviableMutators $Package.$Class"
fi
if [[ -z "$BaseListNext" ]]; then
BaseListNext="$Class"
else
BaseListNext="$BaseListNext $Class"
fi
done < <(grep -rihPo "\s.+extends\s${Base}(\W|$)" "${MutSource}/${Package}" | awk '{ print $1 }')
done
done
BaseList="$BaseListNext"
BaseListNext=""
done
# find available gamemodes
BaseList='KFGameInfo_'
BaseListNext=''
while [[ -n "$BaseList" ]]
do
for Base in $BaseList
do
for Package in $PackageList
do
while read -r Class
do
if [[ -z "$AviableGamemodes" ]]; then
AviableGamemodes="$Package.$Class"
if [[ -z "$DefGamemode" ]]; then
DefGamemode="$Package.$Class"
fi
else
AviableGamemodes="$AviableGamemodes $Package.$Class"
fi
if [[ -z "$BaseListNext" ]]; then
BaseListNext="$Class"
else
BaseListNext="$BaseListNext $Class"
fi
done < <(grep -rihPo "\s.+extends\s${Base}(\W|$)" "${MutSource}/${Package}" | awk '{ print $1 }')
done
done
BaseList="$BaseListNext"
BaseListNext=""
done
fi
if [[ -n "$AviableMutators" ]]; then
msg "mutators found: $(print_list "$AviableMutators" ", ")"
fi
if [[ -z "$AviableGamemodes" ]]; then
DefGamemode="KFGameContent.KFGameInfo_Survival"
else
msg "custom gamemodes found: $(print_list "$AviableGamemodes" ", ")"
fi
if [[ -z "$AviableMaps" ]]; then
DefMap="KF-Nuked"
else
msg "maps found: $(print_list "$AviableMaps" ", ")"
fi
if is_true "$ArgForce" || ! [[ -e "$MutBuilderConfig" ]]; then
cat > "$MutBuilderConfig" <<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"
### Brew parameters ###
# Packages you want to brew using @peelz's patched KFEditor.
# Useful for cases where regular brew doesn't put *.upk inside the package.
# Specify them with a space as a separator,
# The order doesn't matter
PackagePeelzBrew=""
### Steam Workshop upload parameters ###
# Mutators that will be uploaded to the workshop
# Specify them with a space as a separator,
# The order doesn't matter
PackageUpload="$PackageList"
### Test parameters ###
# Map:
Map="$DefMap"
# Game:
# Survival: KFGameContent.KFGameInfo_Survival
# WeeklyOutbreak: KFGameContent.KFGameInfo_WeeklySurvival
# Endless: KFGameContent.KFGameInfo_Endless
# Objective: KFGameContent.KFGameInfo_Objective
# Versus: KFGameContent.KFGameInfo_VersusSurvival
Game="$DefGamemode"
# 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="$(print_list "$AviableMutators" ",")"
# Additional parameters
Args=""
EOF
msg "$(basename "$MutBuilderConfig") created" "${GRN}"
fi
if ! [[ -d "$MutPubContent" ]]; then mkdir -p "$MutPubContent"; fi
ProjectName="$(basename "$(readlink -e "$MutSource")")"
if is_true "$ArgForce" || ! [[ -e "$MutPubContentTitle" ]]; then
echo "$ProjectName" > "$MutPubContentTitle"
msg "$(basename "$MutPubContentTitle") created" "${GRN}"
fi
if is_true "$ArgForce" || ! [[ -e "$MutPubContentDescription" ]]; then
:> "$MutPubContentDescription"
if [[ -n "$AviableGamemodes" ]] || [[ -n "$AviableMutators" ]] || [[ -n "$AviableMaps" ]]; then
echo "[h1]Description[/h1]" >> "$MutPubContentDescription"
if [[ -n "$AviableMaps" ]]; then
echo "[b]Maps:[/b][list][*]$(print_list "$AviableMaps" '[*]')[/list]" >> "$MutPubContentDescription"
fi
if [[ -n "$AviableGamemodes" ]]; then
echo "[b]Gamemodes:[/b][list][*]$(print_list "$AviableGamemodes" '[*]')[/list]" >> "$MutPubContentDescription"
fi
if [[ -n "$AviableMutators" ]]; then
echo "[b]Mutators:[/b][list][*]$(print_list "$AviableMutators" '[*]')[/list]" >> "$MutPubContentDescription"
fi
echo "" >> "$MutPubContentDescription"
fi
GitRemoteUrl="$(repo_url "$(git config --get remote.origin.url)")"
if [[ -n "$GitRemoteUrl" ]]; then
{
echo "[h1]Sources[/h1]"
echo "[url=${GitRemoteUrl}]${GitRemoteUrl}[/url]"
echo ""
} >> "$MutPubContentDescription"
fi
GitUsername="$(git config --get user.name)"
if [[ -n "$GitUsername" ]]; then
{
echo "[h1]Author[/h1]"
echo "[url=https://github.com/${GitUsername}]${GitUsername}[/url]"
echo ""
} >> "$MutPubContentDescription"
fi
msg "$(basename "$MutPubContentDescription") created" "${GRN}"
fi
if is_true "$ArgForce" || [[ "$(preview_extension)" == "None" ]]; then
if [[ -e "$DummyPreview" ]]; then
cp -f "$DummyPreview" "${MutPubContentPreview}.png"
else
printf '%b' "$DummyPreviewRaw" > "${MutPubContentPreview}.png"
fi
msg "$(basename "${MutPubContentPreview}.png") created" "${GRN}"
fi
if is_true "$ArgForce" || ! [[ -e "$MutPubContentTags" ]]; then
:> "$MutPubContentTags"
if [[ -n "$AviableGamemodes" ]]; then
PublicationTags="Gamemodes"
fi
if [[ -n "$AviableMutators" ]]; then
if [[ -n "$PublicationTags" ]]; then
PublicationTags="$PublicationTags,Mutators"
else
PublicationTags="Mutators"
fi
echo "$PublicationTags" >> "$MutPubContentTags"
fi
msg "$(basename "$MutPubContentTags") created" "${GRN}"
fi
}
function preview_extension ()
{
for Ext in gif png jpg jpeg
do
if [[ -e "${MutPubContentPreview}.${Ext}" ]]; then
echo "$Ext"
return 0
fi
done
echo "None"
}
function read_settings ()
{
if ! [[ -f "$MutBuilderConfig" ]]; then init; fi
if bash -n "$MutBuilderConfig"; then
# shellcheck source=./.shellcheck/builder.cfg
source "$MutBuilderConfig"
else
die "$MutBuilderConfig broken! Check this file before continue or create new one using --force --init" 2
fi
}
function merge_package () # $1: What, $2: Where
{
local ModificationTime=""
local ModificationTimeNew=""
local PID=""
msg "merge $1 into $2"
if is_true "$ArgHoldEditor"; then
pushd "$KFWin64" &> /dev/null
CMD //C "$(basename "$KFEditorMergePackages")" make "$1" "$2"
popd &> /dev/null
else
ModificationTime="$(stat -c %y "$KFWin64/$2")"
pushd "$KFWin64" &> /dev/null
CMD //C "$(basename "$KFEditorMergePackages")" make "$1" "$2" &
popd &> /dev/null
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
rm -f "$KFWin64/$1" # cleanup (manual)
}
function merge_packages () # $1: Mutator name
{
msg "merge packages for $1.u"
cp -f "$KFUnpublishScript/$1.u" "$KFWin64"
while read -r Upk
do
cp -f "$Upk" "$KFWin64"
merge_package "$(basename "$Upk")" "$1.u"
done < <(find "$MutSource/$1" -type f -iname '*.upk' -not -ipath "*/Weapons/*")
}
function parse_log () # $1: Logfile
{
local File=''
local FileUnix=''
local FileCompact=''
local Line=''
local Message=''
local I=1
if grep -qP ' Error:(.+:)? Error, ' "$1"; then # check to prevent a very strange crash
while read -r Error
do
if [[ -z "$Error" ]]; then break; fi
Message="$(echo "$Error" | sed -r 's|^.+Error:.+Error, (.+)$|\1|')"
File="$(echo "$Error" | sed -r 's|^.+Error: ((.+)\(([0-9]+)\) : )?Error,(.+)$|\2|')"
if [[ -n "$File" ]]; then
FileUnix="$(cygpath -u "$File")"
FileCompact="$(echo "$FileUnix" | sed -r "s|^$KFDev(.+)$|\1|")"
Line="$(echo "$Error" | sed -r 's|^.+Error: ((.+)\(([0-9]+)\) : )?Error,(.+)$|\3|')"
err "[$I] $FileCompact($Line): $Message"
else
err "[$I] $Message"
fi
((I+=1))
done < <(grep -P ' Error:(.+:)? Error, ' "$1")
fi
if grep -qP ' Warning:(.+:)? Warning, ' "$1"; then # and here too
while read -r Warning
do
if [[ -z "$Warning" ]]; then break; fi
Message="$(echo "$Warning" | sed -r 's|^.+Warning:.+Warning, (.+)$|\1|')"
if echo "$Message" | grep -qF 'Unknown language extension . Defaulting to INT'; then continue; fi
File="$(echo "$Warning" | sed -r 's|^.+Warning: ((.+)\(([0-9]+)\) : )?Warning,(.+)$|\2|')"
if [[ -n "$File" ]]; then
FileUnix="$(cygpath -u "$File")"
FileCompact="$(echo "$FileUnix" | sed -r "s|^$KFDev(.+)$|\1|")"
Line="$(echo "$Warning" | sed -r 's|^.+Warning: ((.+)\(([0-9]+)\) : )?Warning,(.+)$|\3|')"
warn "[$I] $FileCompact($Line): $Message"
else
warn "[$I] $Message"
fi
((I+=1))
done < <(grep -P ' Warning:(.+:)? Warning, ' "$1")
fi
}
function compiled ()
{
for Package in $PackageBuildOrder
do
if ! test -f "$KFUnpublishScript/$Package.u"; then
return 1
fi
done
}
function find_log ()
{
find "$KFLogs" -type f -iname '*.log' -printf '%T+ %p\n' | sort -r | head -n1 | cut -f2- -d" "
}
function compile ()
{
local StripSourceArg=""
local PID=""
local Logfile=""
read_settings
if ! command -v multini &> /dev/null; then
get_latest_multini "$ThirdPartyBin/multini.exe"
fi
if [[ -z "$PackageBuildOrder" ]]; then
die "No packages found! Check project filesystem, fix config and try again"
fi
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"
for Package in $PackageBuildOrder
do
find "$MutSource/$Package" -type f -iname '*.upk' -not -ipath "*/Weapons/*" -exec cp -f {} "$KFUnpublishPackages" \;
find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFUnpublishBrewedPC" \;
find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFUnpublishPackages" \;
done
if [[ -d "$MutLocalization" ]]; then
mkdir -p "$KFUnpublishLocalization"
cp -rf "$MutLocalization"/* "$KFUnpublishLocalization"
fi
if [[ -d "$MutConfig" ]]; then
mkdir -p "$KFUnpublishConfig"
cp -rf "$MutConfig"/* "$KFUnpublishConfig"
fi
if is_true "$StripSource"; then StripSourceArg="-stripsource"; fi
msg "compilation"
if is_true "$ArgHoldEditor"; then
CMD //C "$(cygpath -w "$KFEditor")" make $StripSourceArg -useunpublished
parse_log "$(find_log)"
if ! compiled; then
die "compilation failed"
fi
msg "successfully compiled" "${GRN}"
else
CMD //C "$(cygpath -w "$KFEditor")" make $StripSourceArg -useunpublished &
PID="$!"
while ps -p "$PID" &> /dev/null
do
sleep 1
Logfile="$(find_log)"
if compiled; then
msg "successfully compiled" "${GRN}"
msg "wait for the log"
while ! grep -qF 'Log file closed' "$Logfile"
do
sleep 1
done
kill "$PID"
parse_log "$Logfile"
break
elif grep -qF 'Log file closed' "$Logfile"; then
kill "$PID"
parse_log "$Logfile"
die "compilation failed"
fi
done
fi
find "$KFUnpublish" -type d -empty -delete
}
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
if [[ -d "$MutBrewedPCAddon" ]]; then
mkdir -p "$KFPublishBrewedPC"
cp -rf "$MutBrewedPCAddon"/* "$KFPublishBrewedPC"
fi
}
function brewed () # $1: Wait for packages
{
for Package in $1
do
if ! test -f "$KFPublishBrewedPC/$Package.u"; then
return 1
fi
done
}
function brew_cleanup ()
{
for Package in $PackageBuildOrder
do
if ! echo "$PackageUpload" | grep -Pq "(^|\s+)$Package(\s+|$)"; then
find "$KFPublishBrewedPC" -type f -iname "$Package.u" -delete
find "$MutSource/$Package" -type f -iname '*.upk' -printf "%f\n" | xargs -I{} find "$KFPublishBrewedPC" -type f -iname {} -delete
fi
done
}
function brew ()
{
local PackageBrew=""
local PID=""
msg "brewing"
read_settings
if ! compiled; then
die "You must compile packages before brewing. Use --compile option for this." 2
fi
if [[ -z "$PackagePeelzBrew" ]]; then
PackageBrew="$PackageBuildOrder"
else
for Package in $PackageBuildOrder
do
if ! echo "$PackagePeelzBrew" | grep -Pq "(^|\s+)$Package(\s+|$)"; then
PackageBrew="$Package "
fi
done
fi
rm -rf "$KFPublish"
mkdir -p "$KFPublishBrewedPC" "$KFPublishPackages"
for Package in $PackageBuildOrder
do
find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFPublishBrewedPC" \;
find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFPublishPackages" \;
done
if [[ -n "$PackageBrew" ]]; then
if is_true "$ArgHoldEditor"; then
pushd "$KFWin64" &> /dev/null
CMD //C "$(basename "$KFEditor")" brewcontent -platform=PC "$PackageBrew" -useunpublished
popd &> /dev/null
else
pushd "$KFWin64" &> /dev/null
CMD //C "$(basename "$KFEditor")" brewcontent -platform=PC "$PackageBrew" -useunpublished &
PID="$!"
popd &> /dev/null
while ps -p "$PID" &> /dev/null
do
if brewed "$PackageBrew"; then
kill "$PID"
break
fi
sleep 1
done
fi
if ! brewed "$PackageBrew"; then
brew_cleanup
die "brewing failed"
fi
fi
if [[ -n "$PackagePeelzBrew" ]]; then
msg "peelz brewing"
if ! [[ -x "$KFEditorPatcher" ]]; then
get_latest_kfeditor_patcher "$KFEditorPatcher"
fi
msg "patching $(basename "$KFEditor")"
pushd "$KFWin64" &> /dev/null
CMD //C "$(basename "$KFEditorPatcher")"
popd &> /dev/null
msg "successfully patched" "${GRN}"
for Package in $PackagePeelzBrew
do
merge_packages "$Package"
mv "$KFWin64/$Package.u" "$KFPublishBrewedPC"
find "$MutSource/$Package" -type f -iname '*.upk' -not -ipath '*/Weapons/*' -printf "%f\n" | xargs -I{} find "$KFPublishBrewedPC" -type f -iname {} -delete
done
fi
msg "successfully brewed" "${GRN}"
rm -f "$KFPublishBrewedPC"/*.tmp
find "$KFPublish" -type d -empty -delete
}
function publish_unpublished ()
{
warn "uploading without brewing${DEF}"
mkdir -p "$KFPublishBrewedPC" "$KFPublishScript" "$KFPublishPackages"
for Package in $PackageUpload
do
cp -f "$KFUnpublishScript/$Package.u" "$KFPublishScript"
find "$MutSource/$Package" -type f -iname '*.upk' -not -ipath '*/Weapons/*' -exec cp -f {} "$KFPublishPackages" \;
find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFPublishBrewedPC" \;
find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFPublishPackages" \;
done
find "$KFPublish" -type d -empty -delete
}
function upload ()
{
local PreparedWsDir=""
local Preview=""
local Success="False"
read_settings
if ! compiled && ! test -d "$MutBrewedPCAddon"; then
die "You must compile packages before uploading. Use --compile option for this." 2
fi
if [[ -d "$KFPublish" ]]; then
brew_cleanup
elif [[ -d "$KFUnpublish" ]]; then
publish_unpublished
fi
publish_common
Preview="${MutPubContentPreview}.$(preview_extension)"
if ! [[ -e "$Preview" ]]; then
die "No preview image in PublicationContent" 2
elif [[ $(stat --printf="%s" "$Preview") -ge 1048576 ]]; then
warn "The size of $(basename "$Preview") is greater than 1mb. Steam may prevent you from loading content with this image. if you get an error while loading - try using a smaller preview."
fi
if grep -Fq '"' "$MutPubContentDescription"; then
warn "Double quotes (\") found in $(basename "$MutPubContentDescription"), this may prevent the item from being uploaded to the workshop"
warn "Remove double quotes if there are problems uploading to the workshop"
fi
find "$KFPublish" -type d -empty -delete
# it's a bad idea to use the $KFPublish folder for upload
# because in that case some files won't get uploaded to the workshop for some reason
# so create a temporary folder to get around this
PreparedWsDir="$(mktemp -d -u -p "$KFDoc")"
cat > "$MutWsInfo" <<EOF
\$Description "$(cat "$MutPubContentDescription")"
\$Title "$(cat "$MutPubContentTitle")"
\$PreviewFile "$(cygpath -w "$Preview")"
\$Tags "$(cat "$MutPubContentTags")"
\$MicroTxItem "false"
\$PackageDirectory "$(cygpath -w "$PreparedWsDir")"
EOF
cp -rf "$KFPublish" "$PreparedWsDir"
msg "upload to steam workshop"
while read -r Output
do
if echo "$Output" | grep -qiF 'Successfully uploaded workshop file to Steam'; then
Success="True"
break
elif echo "$Output" | grep -qiF 'error'; then