-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-patch.sh
executable file
·61 lines (49 loc) · 1.49 KB
/
compile-patch.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
#!/bin/bash
echo "#ifndef __PATCHES_H__"
echo "#define __PATCHES_H__"
echo
echo "struct PatchedBytes {"
echo " const wchar_t *fnamePrefix;"
echo " const DWORD addr;"
echo " const char *bytes;"
echo "};"
echo
echo "static struct PatchedBytes changes[] = {"
FIRST_DISTRIB=1
for distrib_path in src/patch/dist_*; do
distrib=${distrib_path##*_}
distrib=${distrib^^}
if [[ $FIRST_DISTRIB -eq 1 ]]; then
echo "#ifdef PATCH_FOR_$distrib"
FIRST_DISTRIB=0
else
echo "#elif defined PATCH_FOR_$distrib"
fi
for asm_file in "$distrib_path"/*.s; do
obj_file=${asm_file%.s}.o
hex_file=${asm_file%.s}.hex
module=${asm_file##*/}
module=${module%%_*}
address=${asm_file##*_}
address=${address%.s}
as -msyntax=intel -mnaked-reg -32 -march=i386+387 \
--defsym base=0x$address --defsym PATCH_FOR_$distrib=1 \
-Isrc/patch -o "$obj_file" "$asm_file" || exit
ld -melf_i386 --oformat=binary -e 0 -Ttext=0 -o "$hex_file" "$obj_file" || exit
echo " { L\"$module\", 0x$address,"
hexdump -v -e '16/1 "%02x " "\n"' "$hex_file" | \
sed -e "s/ *$//" \
-e 's/^.*$/ "\0"/' \
-e '$ s/$/ },/' || exit
done
echo " { NULL, 0, NULL }"
rm "$distrib_path"/*.o || exit
rm "$distrib_path"/*.hex || exit
done
echo "#else"
echo "#error You need to specify which game distribution to build the patcher for."
echo "#endif"
echo "};"
echo
echo "#endif /* __PATCHES_H__ */"
echo