-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightNerf.sh
executable file
·165 lines (155 loc) · 6.98 KB
/
lightNerf.sh
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
#!/bin/bash
#Locates all objects with lighting flicker and creates a patch file to remove said flicker.
PERSISTFILE='SafeFTL.persist'
if grep -q '^SBDIRPersist: ' "$PERSISTFILE" ; then
SBDIRPERSIST="$(grep '^SBDIRPersist' "$PERSISTFILE" | sed 's/^SBDIRPersist: //')"
else
echo "SBDIRPersist: $HOME/.local/share/Steam/steamapps/common/Starbound/" >> "$PERSISTFILE"
SBDIRPERSIST="$HOME/.local/share/Steam/steamapps/common/Starbound/"
fi
function readDir {
printf "Please enter the location of your starbound directory: [${SBDIRPERSIST}] "
read SBDIR
echo ''
}
function readMods {
printf 'Would you like to include modded files? [y/N]: '
read MODSOPT
echo ''
}
function readUnpack {
printf 'Would you like to update packed assets to the latest version (including mod paks)? [Y/n]: '
read UNPACKOPT
echo ''
}
function readDebug {
printf "Would you like to see debug information? [y/N]: "
read DEBUGOPT
echo ''
}
readDir
if [ -z "$SBDIR" ] ; then
SBDIR="$SBDIRPERSIST"
elif [ ! -d "$SBDIR" ] ; then
echo "Sorry, the directory '$SBDIR' does not seem to exist."
readDir
elif [ -d "$SBDIR" ] ; then
sed -i "s,^SBDIRPersist: .*,SBDIRPersist: ${SBDIR}," "$PERSISTFILE"
fi
readMods
if [ "$MODSOPT" != "Y" ] && [ "$MODSOPT" != "y" ] && [ "$MODSOPT" != "N" ] && [ "$MODSOPT" != "n" ] && [ ! -z "$MODSOPT" ] ; then
echo "I'm not sure how, but you managed to enter something other than a Y or a N."
readMods
fi
readUnpack
if [ "$UNPACKOPT" != "Y" ] && [ "$UNPACKOPT" != "y" ] && [ "$UNPACKOPT" != "N" ] && [ "$UNPACKOPT" != "n" ] && [ ! -z "$UNPACKOPT" ] ; then
echo "I'm not sure how, but you managed to enter something other than a Y or a N."
readUnpack
fi
readDebug
if [ "$DEBUGOPT" != "Y" ] && [ "$DEBUGOPT" != "y" ] && [ "$DEBUGOPT" != "N" ] && [ "$DEBUGOPT" != "n" ] && [ ! -z "$DEBUGOPT" ] ; then
echo "I'm not sure how, but you managed to enter something other than a Y or a N."
readDebug
fi
if [ "$UNPACKOPT" == "N" ] || [ "$UNPACKOPT" == "n" ] ; then
echo "Using existing assets."
else
rm -r ./unpack
mkdir ./unpack
if [ "$MODSOPT" == "Y" ] || [ "$MODSOPT" == "y" ] ; then
mkdir ./unpack/mods
echo "Searching for mod paks in '$SBDIR/giraffe_storage/mods'"
find "$SBDIR/giraffe_storage/mods" -type f \( -name "*.modpak" -or -name "*.pak" \) | sed "s,$SBDIR/giraffe_storage/mods/,,g" | while read line ; do
echo "Unpacking '$SBDIR/giraffe_storage/mods/$line' to './unpack/mods/$(echo $line | sed 's,/, ,g' | awk '{$NF=""; print $0}' | sed 's, ,/,g')'"
"$SBDIR/linux64/asset_unpacker" "$SBDIR/giraffe_storage/mods/$line" "./unpack/mods/$(echo $line | sed 's,/, ,g' | awk '{$NF=""; print $0}' | sed 's, ,/,g')"
done
fi
echo "Unpacking '$SBDIR/assets/packed.pak' to './unpack/assets/'"
"$SBDIR/linux64/asset_unpacker" "$SBDIR/assets/packed.pak" ./unpack/assets/
fi
function genPatches {
echo "$FLICKERLIST" | sed 's/\t/ /g' | sed 's/.object:"/.object: "/g' | while read line ; do
if [ "$DEBUGOPT" == "Y" ] || [ "$DEBUGOPT" == "y" ] ; then
echo "$line"
fi
#currentFile="$(echo "$line" | awk '{ print $1 }' | sed "s,.*/objects/,objects/," | sed 's/.\{1\}$//')"
currentFile="$(echo "$line" | sed 's/\.object:.*/\.object/g' | sed 's,.*/objects/,objects/,')"
if [ ! -f "${SECTION}/$currentFile.patch" ] ; then
mkdir -p -- "${SECTION}/$currentFile" #&& echo 'mkdir OK' || echo 'mkdir FAIL'
rm -r -- "${SECTION}/$currentFile" #&& echo 'rm OK' || echo 'rm FAIL'
echo '[' > "${SECTION}/$currentFile.patch"
fi
if echo "$line" | grep -qi '"flickerPeriod"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerPeriod"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op1 OK' || echo 'Op1 FAIL'
fi
if echo "$line" | grep -qi '"flickerMinIntensity"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerMinIntensity"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op2 OK' || echo 'Op2 FAIL'
fi
if echo "$line" | grep -qi '"flickerMaxIntensity"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerMaxIntensity"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op3 OK' || echo 'Op3 FAIL'
fi
if echo "$line" | grep -qi '"flickerPeriodVariance"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerPeriodVariance"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op4 OK' || echo 'Op4 FAIL'
fi
if echo "$line" | grep -qi '"flickerIntensityVariance"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerIntensityVariance"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op5 OK' || echo 'Op5 FAIL'
fi
if echo "$line" | grep -qi '"flickerDistance"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerDistance"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op6 OK' || echo 'Op6 FAIL'
fi
if echo "$line" | grep -qi '"flickerStrength"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile.patch" ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerStrength"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op7 OK' || echo 'Op7 FAIL'
fi
if echo "$line" | grep -qi '"flickerTiming"' ; then
if grep -qi '"op"' "${SECTION}/$currentFile".patch ; then
echo ',' >> "${SECTION}/$currentFile.patch"
fi
printf '{"op":"remove","path":"/flickerTiming"}' >> "${SECTION}/$currentFile.patch" #&& echo 'Op8 OK' || echo 'Op8 FAIL'
fi
done
find "${SECTION}" -type f | grep '.patch' | while read line ; do
echo '' >> "$line"
echo ']' >> "$line"
done
}
rm -r mods/SafeFTL-lights/
mkdir mods/SafeFTL-lights/
echo "Searching for files to patch in vanilla assets..."
FLICKERLIST="$(grep -r --include \*.object '"flicker' "./unpack/assets/objects" | grep -v 'fluorescentlight' | sort -u)"
SECTION="./mods/SafeFTL-lights"
echo "Patching..."
genPatches
if [ "$MODSOPT" == "Y" ] || [ "$MODSOPT" == "y" ] ; then
rm -r mods/SafeFTL-lights_modded/
mkdir mods/SafeFTL-lights_modded/
SECTION="./mods/SafeFTL-lights_modded"
echo "Searching for files to patch in unpacked mods..."
FLICKERLIST="$(grep -r --include \*.object '"flicker' "./unpack/mods" | grep -v 'fluorescentlight' | sort -u)"
echo "Patching..."
genPatches
echo "Searching for files to patch in mods..."
FLICKERLIST="$(grep -r --include \*.object '"flicker' "${SBDIR}/giraffe_storage/mods" | grep -v 'fluorescentlight' | sort -u)"
echo "Patching..."
genPatches
fi