Browse Source

music hook advancement

ipatix 7 years ago
parent
commit
cc8831f5e1

+ 9
- 2
bpre.sym View File

87
 objc_exec = 0x08006B5D;
87
 objc_exec = 0x08006B5D;
88
 obj_sync = 0x08006BA9;
88
 obj_sync = 0x08006BA9;
89
 
89
 
90
-flag_clear = 0x0806E6A9;
90
+flag_clear = 0x0806E6A8|1;
91
+flag_set = 0x0806E680|1;
91
 
92
 
92
 divide = 0x081E4018;
93
 divide = 0x081E4018;
93
 
94
 
184
 m4aSongNumStart = 0x081DD0F5;
185
 m4aSongNumStart = 0x081DD0F5;
185
 MPlayStart_rev01 = 0x081DD859;
186
 MPlayStart_rev01 = 0x081DD859;
186
 MPlayContinue = 0x081DCFF9;
187
 MPlayContinue = 0x081DCFF9;
188
+MPlayAllStop = 0x081DD228|1;
189
+
190
+current_map_music_set = 0x08071A74|1;
191
+current_map_music_set_to_zero = 0x08071A44|1;
192
+current_map_music_fadeout = 0x08071AB4|1;
193
+
187
 __aeabi_idiv = 0x081E4018|1;
194
 __aeabi_idiv = 0x081E4018|1;
188
 __aeabi_idivmod = 0x081E40F4|1;
195
 __aeabi_idivmod = 0x081E40F4|1;
189
 __aeabi_uidiv = 0x081E460C|1;
196
 __aeabi_uidiv = 0x081E460C|1;
190
-__aeabi_uidivmod = 0x081E4684|1;
197
+__aeabi_uidivmod = 0x081E4684|1;

+ 1
- 1
makefile View File

13
 
13
 
14
 DEFINES   := -DBPRE -DSOFTWARE_VERSION=0
14
 DEFINES   := -DBPRE -DSOFTWARE_VERSION=0
15
 ASFLAGS   := -mthumb
15
 ASFLAGS   := -mthumb
16
-CFLAGS    := -mthumb -mthumb-interwork -g -mcpu=arm7tdmi -fno-inline -mlong-calls -march=armv4t -O3 -std=c99 -Wall -Isrc/include $(DEFINES)
16
+CFLAGS    := -mthumb -mthumb-interwork -g -mcpu=arm7tdmi -fno-inline -mlong-calls -march=armv4t -O3 -std=c99 -Wall -Wextra -Wunreachable-code -Isrc/include $(DEFINES)
17
 GRITFLAGS := -ftc -fa
17
 GRITFLAGS := -ftc -fa
18
 LDFLAGS   := -z muldefs
18
 LDFLAGS   := -z muldefs
19
 BLDPATH   := object
19
 BLDPATH   := object

+ 11
- 10
patches/hooks.asm View File

28
     BX  LR
28
     BX  LR
29
 
29
 
30
    // music overrides
30
    // music overrides
31
-.org 0x081DD0F4
32
-    LDR R1, =music_override|1  // TODO wait for replacement by functions below, but can stay for now
33
-    BX  R1
34
-    .pool
35
 
31
 
36
-.org 0x0808064C // intro music (!) song hook
32
+.org 0x0808064C // encounter music ([!] Box) song hook
37
     LDR R1, =mhk_intro_music_id_to_song|1
33
     LDR R1, =mhk_intro_music_id_to_song|1
38
     BL  _call_via_r1
34
     BL  _call_via_r1
39
     B   0x080806BA
35
     B   0x080806BA
40
     .pool
36
     .pool
41
 
37
 
42
-.org 0x08043FD4 // batle music song hook
43
-    LDR R0, =mhk_song_id_for_battle|1
44
-    BX  R0
38
+.org 0x08044090
39
+    LDR R1, =mhk_current_map_music_set_default_for_battle|1
40
+    BX  R1
45
     .pool
41
     .pool
46
 
42
 
47
 .org 0x080156FE // trainer victory music hook
43
 .org 0x080156FE // trainer victory music hook
51
     .pool
47
     .pool
52
 
48
 
53
 .org 0x08021D46  // wild poke defeated
49
 .org 0x08021D46  // wild poke defeated
54
-    BL  _call_via_r0 // call via r0
50
+    BL  _call_via_r0
55
 .org 0x08021D94
51
 .org 0x08021D94
56
     .word   mhk_wild_poke_def_music|1
52
     .word   mhk_wild_poke_def_music|1
57
 
53
 
58
 .org 0x0807F9F8
54
 .org 0x0807F9F8
59
     LDR R1, =0x0807FA3E
55
     LDR R1, =0x0807FA3E
60
-    BL  _call_via_r1 // call via r1
56
+    BL  _call_via_r1
61
     MOV R1, R0
57
     MOV R1, R0
62
     B   0x0807FA3E
58
     B   0x0807FA3E
63
     .pool
59
     .pool
64
 
60
 
61
+.org 0x080159D0
62
+    LDR R0, =mhk_fadeout|1
63
+    BL  _call_via_r0
64
+    B   0x080159DC
65
+    .pool
65
 
66
 
66
 
67
 
67
 //End of sound stuff
68
 //End of sound stuff

+ 1
- 0
src/battle_engine/custom_structs_malloc.c View File

67
     free(custom_battle_elements.ptr);
67
     free(custom_battle_elements.ptr);
68
     custom_battle_elements.ptr=0;
68
     custom_battle_elements.ptr=0;
69
     flag_clear(FLAG_DEOXYS_AURA);
69
     flag_clear(FLAG_DEOXYS_AURA);
70
+    flag_clear(FLAG_SKIP_BATTLE_MUSIC);
70
 }
71
 }
71
 
72
 
72
 //hijack switch in command, clean up battle structs and carry over baton pass
73
 //hijack switch in command, clean up battle structs and carry over baton pass

+ 1
- 5
src/include/config.h View File

48
 #define VAR_TO_3 0x51FF
48
 #define VAR_TO_3 0x51FF
49
 
49
 
50
 /*Flag to enable the music overrides*/
50
 /*Flag to enable the music overrides*/
51
-#define FLAG_ENABLE_MUSIC_OVERRIDES 0x742
52
-
53
-/*Special music override values*/
54
-#define MUS_NO_OVERRIDE 0xFFFF
55
-#define MUS_SKIP_PLAY 0xFFFE
51
+#define FLAG_SKIP_BATTLE_MUSIC 0x742
56
 
52
 
57
 /*Flag to deactivate transparent textboxes*/
53
 /*Flag to deactivate transparent textboxes*/
58
 #define FLAG_ACTIVATE		0x900
54
 #define FLAG_ACTIVATE		0x900

+ 6
- 0
src/include/game_engine.h View File

76
 extern void flag_clear(u16 flag);
76
 extern void flag_clear(u16 flag);
77
 
77
 
78
 /**
78
 /**
79
+ * @brief sets a flag
80
+ * @param flag flag index to set
81
+ */
82
+extern void flag_set(u16 flag);
83
+
84
+/**
79
  * @brief gets attribute of pokémon
85
  * @brief gets attribute of pokémon
80
  * @param poke_address address to pokémon structure
86
  * @param poke_address address to pokémon structure
81
  * @param request request from the attribute request table
87
  * @param request request from the attribute request table

+ 1
- 0
src/include/pokemon.h View File

2
 #define POKE_INDICES_H
2
 #define POKE_INDICES_H
3
 
3
 
4
 #define POKE_PIKACHU    25
4
 #define POKE_PIKACHU    25
5
+#define POKE_ODDISH     43
5
 #define POKE_FARFETCHD  83
6
 #define POKE_FARFETCHD  83
6
 #define POKE_CUBONE     104
7
 #define POKE_CUBONE     104
7
 #define POKE_MAROWAK    105
8
 #define POKE_MAROWAK    105

+ 9
- 3
src/include/sound.h View File

53
 
53
 
54
 extern m_play_table mplay_table[];
54
 extern m_play_table mplay_table[];
55
 extern song_table _songtable[];
55
 extern song_table _songtable[];
56
-extern void m4aSongNumStart(u16 songid);
57
-extern void MPlayStart_rev01(music_player_area *ma, song_header *so);
58
-extern void MPlayContinue(music_player_area *ma);
56
+void m4aSongNumStart(u16 songid);
57
+void MPlayStart_rev01(music_player_area *ma, song_header *so);
58
+void MPlayContinue(music_player_area *ma);
59
+void MPlayAllStop(void);
60
+
61
+// battle and map related stuff
62
+void current_map_music_set(u16);
63
+void current_map_music_set_to_zero(void);
64
+void current_map_music_fadeout(u8);
59
 
65
 
60
 #endif
66
 #endif

+ 40
- 2
src/music/battle_music_lookup.c View File

4
 #include <battle_structs.h>
4
 #include <battle_structs.h>
5
 #include <battle_common.h>
5
 #include <battle_common.h>
6
 #include <pokemon.h>
6
 #include <pokemon.h>
7
+#include <agb_debug.h>
8
+#include <sound.h>
9
+#include <config.h>
10
+
11
+#define SONG_ID_SKIP_PLAY 0xFFFF
12
+
13
+#define skip_song flag_check(FLAG_SKIP_BATTLE_MUSIC)
7
 
14
 
8
 u16 mhk_intro_music_id_to_song(u8 introid) {
15
 u16 mhk_intro_music_id_to_song(u8 introid) {
9
     u16 res = 0;
16
     u16 res = 0;
32
     return res;
39
     return res;
33
 }
40
 }
34
 
41
 
35
-// replaces sub_08043FD4
36
 u16 mhk_song_id_for_battle(void) {
42
 u16 mhk_song_id_for_battle(void) {
37
     u16 res = 0;
43
     u16 res = 0;
38
 
44
 
60
     return res;
66
     return res;
61
 }
67
 }
62
 
68
 
69
+// replaces 0x08044090
70
+void mhk_current_map_music_set_default_for_battle(u16 songid) {
71
+    if (skip_song)
72
+        return;
73
+    if (songid == 0) {
74
+        songid = mhk_song_id_for_battle();
75
+        if (songid != SONG_ID_SKIP_PLAY) {
76
+            current_map_music_set_to_zero();
77
+            MPlayAllStop();
78
+            current_map_music_set(songid);
79
+        }
80
+    } else {
81
+        current_map_music_set_to_zero();
82
+        MPlayAllStop();
83
+        current_map_music_set(songid);
84
+    }
85
+}
86
+
63
 void mhk_trainer_battle_play_defeat(void) {
87
 void mhk_trainer_battle_play_defeat(void) {
88
+    if (skip_song)
89
+        return;
64
     u16 song = 0;
90
     u16 song = 0;
65
 
91
 
66
     switch (trainer_data[trainerbattle_flag_id].trainer_class) {
92
     switch (trainer_data[trainerbattle_flag_id].trainer_class) {
77
 }
103
 }
78
 
104
 
79
 void mhk_wild_poke_def_music(void) {
105
 void mhk_wild_poke_def_music(void) {
80
-    song_play_for_text(SEQ_BGM_VIC_POKE);
106
+    if (!skip_song) {
107
+        song_play_for_text(SEQ_BGM_VIC_POKE);
108
+    }
81
 }
109
 }
82
 
110
 
111
+// this seems to work by special 0x138 only
83
 u16 mhk_species_to_song(u16 species) {
112
 u16 mhk_species_to_song(u16 species) {
84
     u16 res = 0;
113
     u16 res = 0;
85
 
114
 
104
 
133
 
105
     return res;
134
     return res;
106
 }
135
 }
136
+
137
+// hook from loc_80159D0
138
+void mhk_fadeout(void) {
139
+    void (*sub_8070E44)(u8) = (void (*)(u8))(0x08070E44|1);
140
+    sub_8070E44(3); // no idea what these values do
141
+    if (!skip_song) {
142
+        current_map_music_fadeout(5); // same here
143
+    }
144
+}

+ 0
- 78
src/music/music_override.c View File

1
-/****************************************************************************
2
- * Copyright (C) 2015-2016 by the SotS Team                                 *
3
- *                                                                          *
4
- * This file is part of Sovereign of the Skies.                             *
5
- *                                                                          *
6
- *   Sovereign of the Skies is free software: you can redistribute it       *
7
- *   and/or modify it                                                       *
8
- *   under the terms of the GNU Lesser General Public License as published  *
9
- *   by the Free Software Foundation, either version 3 of the License, or   *
10
- *   (at your option) any later version provided you include a copy of the  *
11
- *   licence and this header.                                               *
12
- *                                                                          *
13
- *   Sovereign of the Skies is distributed in the hope that it will be      *
14
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
- *   GNU Lesser General Public License for more details.                    *
17
- *                                                                          *
18
- *   You should have received a copy of the GNU Lesser General Public       *
19
- *   License along with Sovereign of the Skies.                             *
20
- *   If not, see <http://www.gnu.org/licenses/>.                            *
21
- ****************************************************************************/
22
-
23
-/**
24
- * @file music_override.c
25
- * @author ipatix
26
- * @date 15 dec 2016
27
- * @brief Play some custom music
28
- * 
29
- */
30
-
31
-/* === INCLUDES === */
32
-
33
-#include <sound.h>
34
-#include <game_engine.h>
35
-#include <config.h>
36
-
37
-/* === PROTTYPES === */
38
-/**
39
- * @brief overrides a music routine to load music ids from a custom variable
40
- * @param songid song_id to be overridden
41
- */
42
-void music_override(u16 songid);
43
-
44
-/* === IMPLEMENTATIONS === */
45
-void music_override(u16 songid) {
46
-    int skip = 0;
47
-    if (flag_check(FLAG_ENABLE_MUSIC_OVERRIDES)) {
48
-        u16 from1, from2, from3, to1, to2, to3;
49
-        if ((from1 = *var_access(VAR_FROM_1)) == songid) {
50
-            to1 = *var_access(VAR_TO_1);
51
-            if (to1 == MUS_SKIP_PLAY) {
52
-                skip = 1;
53
-            } else if (to1 != MUS_NO_OVERRIDE) {
54
-                songid = to1;
55
-            }
56
-        } else if ((from2 = *var_access(VAR_FROM_2)) == songid) {
57
-            to2 = *var_access(VAR_TO_2);
58
-            if (to2 == MUS_SKIP_PLAY) {
59
-                skip = 1;
60
-            } else if (to2 != MUS_NO_OVERRIDE) {
61
-                songid = to2;
62
-            }
63
-        } else if ((from3 = *var_access(VAR_FROM_3)) == songid) {
64
-            to3 = *var_access(VAR_TO_3);
65
-            if (to3 == MUS_SKIP_PLAY) {
66
-                skip = 1;
67
-            } else if (to3 != MUS_NO_OVERRIDE) {
68
-                songid = to3;
69
-            }
70
-        }
71
-    }
72
-
73
-    if (skip == 0) {
74
-        MPlayStart_rev01(mplay_table[_songtable[songid].ms].ma, _songtable[songid].so);
75
-    } else {
76
-        MPlayContinue(mplay_table[_songtable[songid].ms].ma);
77
-    }
78
-}

+ 1
- 2
src/specials/trainer_battle.c View File

41
 extern void battle_80801F0_something();
41
 extern void battle_80801F0_something();
42
 
42
 
43
 extern volatile u8 trainerbattle_battle_type;
43
 extern volatile u8 trainerbattle_battle_type;
44
-extern volatile u16 trainerbattle_flag_id;
45
 extern volatile u16 trainerbattle_arg2;
44
 extern volatile u16 trainerbattle_arg2;
46
 extern volatile char* trainerbattle_message_intro;
45
 extern volatile char* trainerbattle_message_intro;
47
 extern volatile char* trainerbattle_message_defeat;
46
 extern volatile char* trainerbattle_message_defeat;
313
     /* should never be reached */
312
     /* should never be reached */
314
     //assert(0);
313
     //assert(0);
315
    // return NULL;
314
    // return NULL;
316
-}
315
+}