-
Notifications
You must be signed in to change notification settings - Fork 0
/
genhooks
executable file
·49 lines (44 loc) · 2.02 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
48
49
#!/bin/sh
AS="${AS:-mips64-as}"
OBJCOPY="${OBJCOPY:-mips64-objcopy}"
NM="${NM:-mips64-nm}"
elf="$1"
if [ -z "$elf" ]; then
echo 'usage: genhooks <elf-file>'
exit 1
fi
symrc="$(mktemp)"
$NM "$elf" |
awk '(/^[0-9A-Za-z_ ]*$/) {printf "sym_%s=0x%s\n",$3,substr($1,length($1)-7)}' >"$symrc"
. "$symrc"
rm -f "$symrc"
asmgsc()
{
addr="$(( $1 & 0x00FFFFFF ))"
objfile="$(mktemp)"
binfile="$(mktemp)"
echo ".data; .set noreorder; .set noat; $2" | $AS -o "$objfile"
$OBJCOPY -j .data -O binary "$objfile" "$binfile"
od -An -t x1 -v "$binfile" |
awk 'BEGIN {RS=""; a='"$addr"'} {for (i=1; i<=NF; i++) {if (i<NF) {printf "81%06x %s%s\n",a,$i,$(i+1); i++; a++} else printf "80%06x 00%s",a,$i; a++}}'
rm -f "$objfile" "$binfile"
}
asmgsc "$sym_z64_main_hook" "jal $sym__start;"
asmgsc "$sym_z64_entrance_offset_hook" "jal $sym_entrance_offset_hook; nop;"
asmgsc "$sym_z64_draw_room_1_call" "jal $sym_draw_room_hook;"
asmgsc "$sym_z64_draw_room_2_call" "jal $sym_draw_room_hook;"
asmgsc "$sym_z64_draw_actors_call" "jal $sym_draw_actors_hook;"
asmgsc "$sym_z64_srand_call" "jal $sym_srand_hook;"
asmgsc "$sym_z64_frame_input_call" "jal $sym_input_hook; nop;"
asmgsc "$sym_z64_ocarina_update_call" "jal $sym_ocarina_update_hook;"
asmgsc "$sym_z64_ocarina_input_call" "jal $sym_ocarina_input_hook;"
asmgsc "$sym_z64_ocarina_sync_hook" "jal $sym_ocarina_sync_hook; nop; b 0x000C; nop;"
asmgsc "$sym_z64_afx_rand_call" "jal $sym_afx_rand_hook;"
asmgsc "$sym_z64_room_load_sync_hook" "jal $sym_room_load_sync_hook;"
asmgsc "$sym_z64_camera_hook" "jal $sym_camera_hook;"
asmgsc "$sym_z64_guPerspectiveF_hook" "jal $sym_guPerspectiveF_hook; sw \$a2, 0x0038(\$sp);"
asmgsc "$sym_z64_guPerspective_camo" "nop; nop;"
asmgsc "$sym_z64_disp_swap_1" "jal $sym_disp_hook;"
asmgsc "$sym_z64_disp_swap_2" "jal $sym_disp_hook;"
asmgsc "$sym_z64_disp_swap_3" "jal $sym_disp_hook;"
asmgsc "$sym_z64_disp_swap_4" "jal $sym_disp_hook;"