-
Notifications
You must be signed in to change notification settings - Fork 3
/
unluac.sh
executable file
·47 lines (39 loc) · 1.23 KB
/
unluac.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
#!/bin/sh
# unluac.sh
# A shell script to make unluac.jar easier to use. (Still requires the JRE, though)
if [ $# -eq 0 ]; then
echo "Use this shell script to bulk-decompile Playdate Lua bytecode with unluac."
echo "Usage: ./unluac.sh [-r] (input directory) [separate output directory]"
echo
echo "If '-r' is given, remove the input bytecode files after processing."
echo "If there is no output directory given, create code in the input directory."
echo
exit
fi
if [ "$1" = "-r" ]; then
REMOVE=1
else
REMOVE=0
fi
if [ $REMOVE -eq 0 ]; then
INPUTDIR="$1"
OUTPUTDIR="$2"
else
INPUTDIR="$2"
OUTPUTDIR="$3"
fi
if [ -z "$OUTPUTDIR" ]; then OUTPUTDIR=$INPUTDIR; fi
IFS=$(printf '\n')
find "$INPUTDIR" ! -name "$(printf "*\n*")" -name '*.luac' > tmp
while IFS= read -r LUACFILE; do
# Get the name of the new source file
LUAFILE=$(echo "$LUACFILE" | sed "s+$INPUTDIR+$OUTPUTDIR+gI" | sed 's+.luac+.lua+gI')
echo "Decompiling $LUAFILE..."
# If the folder containing it doesn't exist, create it
[ ! -f "$LUAFILE" ] && mkdir -p "$(dirname "$LUAFILE")"
# Run unluac
java -jar "$(dirname "$0")/unluac.jar" -o "$LUAFILE" "$LUACFILE"
# Remove the old bytecode file if '-r' was passed
[ $REMOVE -eq 1 ] && rm -f "$LUACFILE"
done < tmp
rm tmp