ソースを参照

music hook advancement

ipatix 7 年 前
コミット
cc8831f5e1
共有11 個のファイルを変更した80 個の追加103 個の削除を含む
  1. 9
    2
      bpre.sym
  2. 1
    1
      makefile
  3. 11
    10
      patches/hooks.asm
  4. 1
    0
      src/battle_engine/custom_structs_malloc.c
  5. 1
    5
      src/include/config.h
  6. 6
    0
      src/include/game_engine.h
  7. 1
    0
      src/include/pokemon.h
  8. 9
    3
      src/include/sound.h
  9. 40
    2
      src/music/battle_music_lookup.c
  10. 0
    78
      src/music/music_override.c
  11. 1
    2
      src/specials/trainer_battle.c

+ 9
- 2
bpre.sym ファイルの表示

@@ -87,7 +87,8 @@ task_exec = 0x08077579;
87 87
 objc_exec = 0x08006B5D;
88 88
 obj_sync = 0x08006BA9;
89 89
 
90
-flag_clear = 0x0806E6A9;
90
+flag_clear = 0x0806E6A8|1;
91
+flag_set = 0x0806E680|1;
91 92
 
92 93
 divide = 0x081E4018;
93 94
 
@@ -184,7 +185,13 @@ mplay_table = 0x084A329C;
184 185
 m4aSongNumStart = 0x081DD0F5;
185 186
 MPlayStart_rev01 = 0x081DD859;
186 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 194
 __aeabi_idiv = 0x081E4018|1;
188 195
 __aeabi_idivmod = 0x081E40F4|1;
189 196
 __aeabi_uidiv = 0x081E460C|1;
190
-__aeabi_uidivmod = 0x081E4684|1;
197
+__aeabi_uidivmod = 0x081E4684|1;

+ 1
- 1
makefile ファイルの表示

@@ -13,7 +13,7 @@ export PATH := $(realpath ../tools):$(PATH)
13 13
 
14 14
 DEFINES   := -DBPRE -DSOFTWARE_VERSION=0
15 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 17
 GRITFLAGS := -ftc -fa
18 18
 LDFLAGS   := -z muldefs
19 19
 BLDPATH   := object

+ 11
- 10
patches/hooks.asm ファイルの表示

@@ -28,20 +28,16 @@ _call_via_r1 equ 0x081E3BAC
28 28
     BX  LR
29 29
 
30 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 33
     LDR R1, =mhk_intro_music_id_to_song|1
38 34
     BL  _call_via_r1
39 35
     B   0x080806BA
40 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 41
     .pool
46 42
 
47 43
 .org 0x080156FE // trainer victory music hook
@@ -51,17 +47,22 @@ _call_via_r1 equ 0x081E3BAC
51 47
     .pool
52 48
 
53 49
 .org 0x08021D46  // wild poke defeated
54
-    BL  _call_via_r0 // call via r0
50
+    BL  _call_via_r0
55 51
 .org 0x08021D94
56 52
     .word   mhk_wild_poke_def_music|1
57 53
 
58 54
 .org 0x0807F9F8
59 55
     LDR R1, =0x0807FA3E
60
-    BL  _call_via_r1 // call via r1
56
+    BL  _call_via_r1
61 57
     MOV R1, R0
62 58
     B   0x0807FA3E
63 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 68
 //End of sound stuff

+ 1
- 0
src/battle_engine/custom_structs_malloc.c ファイルの表示

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

+ 1
- 5
src/include/config.h ファイルの表示

@@ -48,11 +48,7 @@
48 48
 #define VAR_TO_3 0x51FF
49 49
 
50 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 53
 /*Flag to deactivate transparent textboxes*/
58 54
 #define FLAG_ACTIVATE		0x900

+ 6
- 0
src/include/game_engine.h ファイルの表示

@@ -76,6 +76,12 @@ extern u8 flag_check(u32 flag);
76 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 85
  * @brief gets attribute of pokémon
80 86
  * @param poke_address address to pokémon structure
81 87
  * @param request request from the attribute request table

+ 1
- 0
src/include/pokemon.h ファイルの表示

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

+ 9
- 3
src/include/sound.h ファイルの表示

@@ -53,8 +53,14 @@ typedef struct {
53 53
 
54 54
 extern m_play_table mplay_table[];
55 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 66
 #endif

+ 40
- 2
src/music/battle_music_lookup.c ファイルの表示

@@ -4,6 +4,13 @@
4 4
 #include <battle_structs.h>
5 5
 #include <battle_common.h>
6 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 15
 u16 mhk_intro_music_id_to_song(u8 introid) {
9 16
     u16 res = 0;
@@ -32,7 +39,6 @@ u16 mhk_intro_music_id_to_song(u8 introid) {
32 39
     return res;
33 40
 }
34 41
 
35
-// replaces sub_08043FD4
36 42
 u16 mhk_song_id_for_battle(void) {
37 43
     u16 res = 0;
38 44
 
@@ -60,7 +66,27 @@ u16 mhk_song_id_for_battle(void) {
60 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 87
 void mhk_trainer_battle_play_defeat(void) {
88
+    if (skip_song)
89
+        return;
64 90
     u16 song = 0;
65 91
 
66 92
     switch (trainer_data[trainerbattle_flag_id].trainer_class) {
@@ -77,9 +103,12 @@ void mhk_trainer_battle_play_defeat(void) {
77 103
 }
78 104
 
79 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 112
 u16 mhk_species_to_song(u16 species) {
84 113
     u16 res = 0;
85 114
 
@@ -104,3 +133,12 @@ u16 mhk_species_to_song(u16 species) {
104 133
 
105 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 ファイルの表示

@@ -1,78 +0,0 @@
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 ファイルの表示

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