-
Notifications
You must be signed in to change notification settings - Fork 5
/
genhooks
executable file
·47 lines (42 loc) · 1.63 KB
/
genhooks
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/bash
elf="$1"
if [ -z "$elf" ]; then
echo usage: \`genhooks \<elf\>\`
exit
fi
symtbl="$(mktemp)"
mips64-nm "$elf" | awk '(/^[0-9A-Za-z_ ]*$/) {printf "sym_%s=0x%s\n",$3,substr($1,length($1)-7)}' >"$symtbl"
. "$symtbl"
rm -f "$symtbl"
gsc16()
{
addr="$(printf "%d" "$1")"
addr="$(expr "$addr" % 16777216 + 2164260864)" # addr = addr & 0x00FFFFFF | 0x81000000
val="$(printf "%d" "$2")"
val="$(expr "$val" % 65536)" # val = val & 0xFFFF
printf "%08X %04X\n" "$addr" "$val"
}
genhook()
{
addr="$(printf "%d" "$1")"
tmp="$(mktemp)"
echo ".set noreorder; .set noat; $2" | mips64-as - -o "$tmp"
mips64-readelf -x .text "$tmp" | grep "0x[0-9A-Fa-f]\{8\}" | grep -o " [0-9A-Fa-f]\{8\}" |
while read -r line; do
gsc16 "$addr" "0x`echo "$line" | sed -e "s/\(....\)..../\1/"`"
addr="$(expr "$addr" + 2)"
gsc16 "$addr" "0x`echo "$line" | sed -e "s/....\(....\)/\1/"`"
addr="$(expr "$addr" + 2)"
done
rm -f "$tmp"
}
genhook "$sym_update_hook" "jal $sym_fpUpdateEntry;"
genhook "$sym_draw_hook" "jal $sym_fpDrawEntry;"
genhook "$sym_after_draw_hook" "jal $sym_fpAfterDrawEntry;"
genhook "$sym_flush_backups_hook_1" "nop;" # Remove calls to update backup save in slot 7 to make room for fp settings
genhook "$sym_flush_backups_hook_2" "nop;"
genhook "$sym_update_camera_zone_interp_hook" "jal $sym_fpUpdateCameraZoneInterpHook;"
genhook "$sym_get_npc_unsafe_hook" "jal $sym_fpGetNpcUnsafe;"
genhook "$sym_update_player_input_rom_hook" "jal $sym_fpUpdateInput;"
genhook "$sym_peekaboo_hook" "jal $sym_fpIsAbilityActive;"
genhook "$sym_fire_flower_hook" "nop;" # Fix wii vc fire flower crash