-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_roms.sh
executable file
·102 lines (84 loc) · 2.56 KB
/
create_roms.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
#!/usr/bin/env bash
# Apply each hack patch in a path to a ROM creating a new ROM each time.
# Will also delete bad or duplicate patches.
#
# You still have to obtain a clean Super Mario World ROM (as a
# .smc file).
# Check your ROM with this tool:
# https://media.smwcentral.net/onlinetools/jsromclean.htm
parent_dir=$(dirname $0)
flips="$parent_dir/../tools/floating/flips-linux"
removal_list="$parent_dir/../stats/remove_patches.txt"
print_usage() {
echo "Usage: $0 [-r|-c] <in_dir> <out_dir> <smc_file>"
echo ""
echo "Required arguments:"
echo " in_dir: The directory containing all .bps files (searched recursively)."
echo " out_dir: Where to create the different ROMs."
echo " smc_file: The ROM to apply patches to (read this file's first comment"
echo " for detailed information)."
echo ""
echo "Optional arguments:"
echo " -h: Print this message."
echo " -r or -c: Remove bad or duplicate patches before creating ROMs."
}
# Create a new ROM generated by applying the given .bps file to the
# given .smc file (the ROM).
# $1: The .bps patch file.
# $2: Output directory.
# $3: The .smc ROM file.
apply_patch() {
echo "Applying $1..."
patch_basename=$(basename "$1" .bps)
$flips --apply "$1" "$3" "$2/$patch_basename.smc"
}
# Process all patches in the given directory and write to the other
# given directory applying to the given ROM.
# $1: The directory containing the .bps patch files.
# $2: Where to output the .smc files.
# $3: Which ROM to apply to (a .smc file).
process_patches() {
chmod u+x $flips
mkdir -p "$2"
find "$1" -type f -name "*.bps" \
| while read bps_patch; do
apply_patch "$bps_patch" "$2" "$3"
done
}
remove_patches=''
while getopts ":rch" opt; do
case "$opt" in
r|c)
remove_patches=t
;;
h)
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
done
shift $((OPTIND-1))
in_dir=$1
out_dir=$2
smc_file=$3
if [ -z "$in_dir" ] || [ -z "$out_dir" ] || [ -z "$smc_file" ]; then
print_usage
exit 1
fi
if [ "x$remove_patches" != x ]; then
if [ -e "$removal_list" ]; then
cat "$removal_list" \
| while read bps_patch; do
rm "$in_dir/$bps_patch"
done
echo "Done cleaning."
else
echo "Could not remove bad patches."
echo "Please check the file $removal_list and delete manually (or retry)."
fi
fi
process_patches "$in_dir" "$out_dir" "$smc_file"