Просмотр исходного кода

finished entry hazards (switchin cleanup)

SBird1337 7 лет назад
Родитель
Сommit
a22c9a2615

+ 5
- 1
bpre.sym Просмотреть файл

@@ -1,8 +1,12 @@
1
+agbprintf = 0x081E39D8|1;
2
+agbprint_flush = 0x081E3B04|1;
3
+agb_assert = 0x081E3B14|1;
1 4
 set_callback2 = 0x08000545;
2 5
 vblank_handler_set = 0x080006F5;
3 6
 malloc = 0x08002BB0|1;
4 7
 free = 0x08002BC4|1;
5 8
 memset = 0x081E5ED8|1;
9
+memcpy = 0x081E5E78|1;
6 10
 template_instanciate_forward_search = 0x08006F8D;
7 11
 gpu_copy_to_vram_by_bgid = 0x08001298|1;
8 12
 bg_set_tilemap = 0x08001FA0|1;
@@ -96,7 +100,7 @@ battle_status3_bits_pbs = 0x02023DFC;
96 100
 
97 101
 mugshots = 0x097007E0;
98 102
 battle_bg_table = 0x0824ee34;
99
-custom_battle_struct = 0x0203FE00;
103
+custom_battle_elements = 0x0203FE00;
100 104
 
101 105
 
102 106
 mplay_table = 0x084A329C;

+ 6
- 0
nbproject/configurations.xml Просмотреть файл

@@ -4594,6 +4594,7 @@
4594 4594
             <in>hazards.S</in>
4595 4595
           </df>
4596 4596
           <in>battle_help.c</in>
4597
+          <in>battle_switch_in_hook.S</in>
4597 4598
           <in>custom_structs_malloc.c</in>
4598 4599
           <in>custom_structs_malloc_hook.S</in>
4599 4600
           <in>entry_hazards.c</in>
@@ -27132,6 +27133,11 @@
27132 27133
       </item>
27133 27134
       <item path="src/battle_engine/battle_help.c" ex="false" tool="0" flavor2="0">
27134 27135
       </item>
27136
+      <item path="src/battle_engine/battle_switch_in_hook.S"
27137
+            ex="false"
27138
+            tool="4"
27139
+            flavor2="0">
27140
+      </item>
27135 27141
       <item path="src/battle_engine/custom_structs_malloc.c"
27136 27142
             ex="false"
27137 27143
             tool="0"

+ 11
- 2
nbproject/private/configurations.xml Просмотреть файл

@@ -4733,6 +4733,7 @@
4733 4733
           </df>
4734 4734
           <in>battle_help.c</in>
4735 4735
           <in>battle_help.h</in>
4736
+          <in>battle_switch_in_hook.S</in>
4736 4737
           <in>custom_structs_malloc.c</in>
4737 4738
           <in>custom_structs_malloc.h</in>
4738 4739
           <in>custom_structs_malloc_hook.S</in>
@@ -4864,10 +4865,18 @@
4864 4865
       <runprofile version="9">
4865 4866
         <runcommandpicklist>
4866 4867
           <runcommandpicklistitem>"${OUTPUT_PATH}"</runcommandpicklistitem>
4868
+          <runcommandpicklistitem>"./tools/vba buld/pkmn_sots.gba"</runcommandpicklistitem>
4869
+          <runcommandpicklistitem>"./tools/vba" "build/pkmn_sots.gba"</runcommandpicklistitem>
4870
+          <runcommandpicklistitem>"../tools/vba" "build/pkmn_sots.gba"</runcommandpicklistitem>
4871
+          <runcommandpicklistitem>"../tools/vbam.exe --verbose=128" "build/pkmn_sots.gba"</runcommandpicklistitem>
4872
+          <runcommandpicklistitem>"../tools/vbam.exe"  --verbose=128 "build/pkmn_sots.gba"</runcommandpicklistitem>
4873
+          <runcommandpicklistitem>"../tools/vbam.exe" "build/pkmn_sots.gba" --agb-print --verbose=128</runcommandpicklistitem>
4874
+          <runcommandpicklistitem>"../tools/vbam.exe" "build/pkmn_sots.gba"</runcommandpicklistitem>
4875
+          <runcommandpicklistitem>"../tools/vba.exe" "build/pkmn_sots.gba"</runcommandpicklistitem>
4867 4876
         </runcommandpicklist>
4868
-        <runcommand>"${OUTPUT_PATH}"</runcommand>
4877
+        <runcommand>"../tools/vba.exe" "build/pkmn_sots.gba"</runcommand>
4869 4878
         <rundir>.</rundir>
4870
-        <buildfirst>false</buildfirst>
4879
+        <buildfirst>true</buildfirst>
4871 4880
         <terminal-type>0</terminal-type>
4872 4881
         <remove-instrumentation>0</remove-instrumentation>
4873 4882
         <environment>

+ 5
- 0
patches/battle_engine/battle_engine.asm Просмотреть файл

@@ -1,4 +1,9 @@
1 1
 .org 0x08024E80
2 2
 ldr r0, =entry_hazards_hook|1
3 3
 bx r0
4
+.pool
5
+
6
+.org 0x08024FE4
7
+ldr r4, =battle_switch_in_hook|1
8
+bx r4
4 9
 .pool

+ 1
- 1
src/battle_engine/battle_help.c Просмотреть файл

@@ -37,7 +37,7 @@ u16 damage_type_effectiveness_update(u8 attacking_type, u8 defending_type, u8 at
37 37
         dtype=dtype-5;
38 38
 	effect=type_effectiveness_table[atype][dtype];
39 39
 	
40
-	if (custom_battle_struct.ptr->various.inverse_battle)
40
+	if (custom_battle_elements.ptr->various.inverse_battle)
41 41
     {
42 42
         if (effect == 20)
43 43
         {

+ 15
- 0
src/battle_engine/battle_switch_in_hook.S Просмотреть файл

@@ -0,0 +1,15 @@
1
+.text
2
+.align 2
3
+.thumb
4
+
5
+.global battle_switch_in_hook
6
+battle_switch_in_hook:
7
+    ldr r1, =0xFDFF
8
+    and r1, r2
9
+    strh r1, [r0]
10
+    mov r4, #0
11
+    push {r0-r3}
12
+    bl battle_switch_in
13
+    pop {r0-r3}
14
+    ldr r0, =0x08024FEC|1
15
+    bx r0

+ 44
- 4
src/battle_engine/custom_structs_malloc.c Просмотреть файл

@@ -1,15 +1,55 @@
1 1
 #include <bpre.h>
2
+#include <battle.h>
2 3
 #include "custom_structs.h"
3 4
 #include "custom_structs_malloc.h"
4 5
 
5 6
 void malloc_battle_structs()
6 7
 {
7
-	custom_battle_struct.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
8
-	custom_battle_struct.ptr->side_affecting[0].sticky_web=1;
8
+	custom_battle_elements.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
9
+        custom_battle_elements.ptr->side_affecting[0].stealth_rock=1;
10
+        custom_battle_elements.ptr->side_affecting[0].toxic_spikes_psn=1;
11
+        custom_battle_elements.ptr->side_affecting[0].sticky_web=1;
9 12
 }
10 13
 
11 14
 void free_battle_structs()
12 15
 {
13
-	free(custom_battle_struct.ptr);
14
-	custom_battle_struct.ptr=0;
16
+	free(custom_battle_elements.ptr);
17
+	custom_battle_elements.ptr=0;
18
+}
19
+
20
+//hijack switch in command, clean up battle structs and carry over baton pass
21
+void battle_switch_in()
22
+{
23
+    struct bank_affecting* current_bank_affecting = &custom_battle_elements.ptr->bank_affecting[battle_active_bank];
24
+    //copy of the old structure to carry over baton pass effects
25
+    struct bank_affecting prev_bank_affecting = custom_battle_elements.ptr->bank_affecting[battle_active_bank];
26
+    memset(current_bank_affecting, 0, sizeof(struct bank_affecting));
27
+    //handle type 3 if needed
28
+    current_bank_affecting->just_switched_in = 1;
29
+    current_bank_affecting->wish_hp = prev_bank_affecting.wish_hp;
30
+    if(battle_executed_move == MOVE_BATON_PASS)
31
+    {
32
+        current_bank_affecting->aqua_ring = prev_bank_affecting.aqua_ring;
33
+        current_bank_affecting->embargo = prev_bank_affecting.embargo;
34
+        current_bank_affecting->powertrick = prev_bank_affecting.powertrick;
35
+        current_bank_affecting->gastro_acided = prev_bank_affecting.gastro_acided;
36
+        current_bank_affecting->heal_block = prev_bank_affecting.heal_block;
37
+        
38
+        if(prev_bank_affecting.powertrick)
39
+        {
40
+            //carry over switched stats of power trick
41
+            u16 *atk = &battle_participants[battle_active_bank].atk;
42
+            u16 *def = &battle_participants[battle_active_bank].def;
43
+            u16 switch_var = *atk;
44
+            *atk = *def;
45
+            *def = switch_var;
46
+        }
47
+    }
48
+    struct side_affecting* active_side = &custom_battle_elements.ptr->side_affecting[get_side_from_bank(battle_active_bank)];
49
+    active_side->stealth_rock_done = 0;
50
+    active_side->sticky_web_done = 0;
51
+    active_side->toxic_spikes_done = 0;
52
+    active_side->lunardance_done = 0;
53
+    
54
+    return;
15 55
 }

+ 1
- 0
src/battle_engine/custom_structs_malloc.h Просмотреть файл

@@ -3,5 +3,6 @@
3 3
 
4 4
 void malloc_battle_structs();
5 5
 void free_battle_structs();
6
+void battle_switch_in();
6 7
 
7 8
 #endif

+ 117
- 147
src/battle_engine/entry_hazards.c Просмотреть файл

@@ -12,163 +12,133 @@ extern void* bs_rocks_lain;
12 12
 extern void* bs_toxic_lain;
13 13
 extern void* bs_sticky_lain;
14 14
 
15
-u8 execute_entry_hazards()
16
-{
17
-	u8 active_side = get_side_from_bank(battle_active_bank);
18
-	u8 has_effect = 0;
19
-	struct side_affecting* active_side_affecting = &custom_battle_struct.ptr->side_affecting[active_side];
20
-	if(side_affecting_halfword[active_side].spikes_on && !(side_affecting_halfword[active_side].spikes_damage_done))
21
-	{
22
-		//spikes lay down, deal spiky damage
23
-		u32 damage = (battle_participants[battle_active_bank].max_hp) / ((5 - battle_side_timers[active_side].spikes_amount) * 2);
15
+u8 execute_entry_hazards() {
16
+    u8 active_side = get_side_from_bank(battle_active_bank);
17
+    u8 has_effect = 0;
18
+    struct side_affecting* active_side_affecting = &custom_battle_elements.ptr->side_affecting[active_side];
19
+    if (side_affecting_halfword[active_side].spikes_on && !(side_affecting_halfword[active_side].spikes_damage_done)) {
20
+        //spikes lay down, deal spiky damage
21
+        u32 damage = (battle_participants[battle_active_bank].max_hp) / ((5 - battle_side_timers[active_side].spikes_amount) * 2);
24 22
         if (damage == 0)
25 23
             damage = 1;
26 24
         battle_damage_store = damage;
27
-		
28
-		side_affecting_halfword[active_side].spikes_damage_done = 1;
29
-		battle_script_push();
30
-		battlescript_cursor = (void*)(0x081D8CBE);
31
-		has_effect = 1;
32
-	}
33
-	else if(active_side_affecting->stealth_rock && !(active_side_affecting->stealth_rock_done))
34
-	{
35
-		active_side_affecting->stealth_rock_done=1;
36
-		//check for magic guard here
37
-		u32 damage = battle_participants[battle_active_bank].max_hp;
38
-		switch (type_effectiveness_calc(MOVE_STEALTH_ROCK, TYPE_ROCK, battle_active_bank^1, battle_active_bank, 0) >> 4)
39
-		{
40
-			case 1:
41
-				damage = damage >> 5;
42
-				break;
43
-			case 2:
44
-				damage = damage >> 4;
45
-				break;
46
-			case 4:
47
-				damage = damage >> 3;
48
-				break;
49
-			case 8:
50
-				damage = damage >> 2;
51
-				break;
52
-			case 16:
53
-				damage = damage >> 1;
54
-				break;
55
-		}
56
-		if(damage == 0)
57
-			damage = 1;
58
-		battle_damage_store = damage;
59
-		
60
-		battle_script_push();
61
-		battlescript_cursor = bs_stealth_rock;
62
-		has_effect = 1;
63
-	}
64
-	else if(active_side_affecting->toxic_spikes_psn && !(active_side_affecting->toxic_spikes_done))
65
-	{
66
-		active_side_affecting->toxic_spikes_done=1;
67
-		if(has_type(battle_active_bank, TYPE_POISON))
68
-		{
69
-			has_effect = 1;
70
-			active_side_affecting->toxic_spikes_psn=0;
71
-			active_side_affecting->toxic_spikes_badpsn=0;
72
-			battle_script_push();
73
-			battlescript_cursor = bs_toxic_resolve;
74
-		}
75
-		else if(!cant_poison(battle_active_bank, 0))
76
-		{
77
-			if (active_side_affecting->toxic_spikes_badpsn)
78
-			{
79
-				battle_participants[battle_active_bank].status.flags.toxic_poison = 1;
80
-				battle_script_push();
81
-				battlescript_cursor = bs_toxic_spikes_bad;
82
-			}
83
-                
84
-            else
85
-			{
86
-				battle_participants[battle_active_bank].status.flags.poison = 1;
87
-				battle_script_push();
88
-				battlescript_cursor = bs_toxic_spikes;
89
-			}
25
+
26
+        side_affecting_halfword[active_side].spikes_damage_done = 1;
27
+        battle_script_push();
28
+        battlescript_cursor = (void*) (0x081D8CBE);
29
+        has_effect = 1;
30
+    } else if (active_side_affecting->stealth_rock && !(active_side_affecting->stealth_rock_done)) {
31
+        active_side_affecting->stealth_rock_done = 1;
32
+        //check for magic guard here
33
+        u32 damage = battle_participants[battle_active_bank].max_hp;
34
+        switch (type_effectiveness_calc(MOVE_STEALTH_ROCK, TYPE_ROCK, battle_active_bank^1, battle_active_bank, 0) >> 4) {
35
+            case 1:
36
+                damage = damage >> 5;
37
+                break;
38
+            case 2:
39
+                damage = damage >> 4;
40
+                break;
41
+            case 4:
42
+                damage = damage >> 3;
43
+                break;
44
+            case 8:
45
+                damage = damage >> 2;
46
+                break;
47
+            case 16:
48
+                damage = damage >> 1;
49
+                break;
50
+        }
51
+        if (damage == 0)
52
+            damage = 1;
53
+        battle_damage_store = damage;
54
+
55
+        battle_script_push();
56
+        battlescript_cursor = bs_stealth_rock;
57
+        has_effect = 1;
58
+    } else if (active_side_affecting->toxic_spikes_psn && !(active_side_affecting->toxic_spikes_done)) {
59
+        active_side_affecting->toxic_spikes_done = 1;
60
+        if (has_type(battle_active_bank, TYPE_POISON)) {
61
+            has_effect = 1;
62
+            active_side_affecting->toxic_spikes_psn = 0;
63
+            active_side_affecting->toxic_spikes_badpsn = 0;
64
+            battle_script_push();
65
+            battlescript_cursor = bs_toxic_resolve;
66
+        } else if (!cant_poison(battle_active_bank, 0)) {
67
+            if (active_side_affecting->toxic_spikes_badpsn) {
68
+                battle_participants[battle_active_bank].status.flags.toxic_poison = 1;
69
+                battle_script_push();
70
+                battlescript_cursor = bs_toxic_spikes_bad;
71
+            }
72
+            else {
73
+                battle_participants[battle_active_bank].status.flags.poison = 1;
74
+                battle_script_push();
75
+                battlescript_cursor = bs_toxic_spikes;
76
+            }
90 77
             prepare_setattributes_in_battle(0, REQUEST_STATUS_BATTLE, 0, 4, &battle_participants[battle_active_bank].status.flags);
91 78
             mark_buffer_bank_for_execution(battle_active_bank);
92
-			has_effect = 1;
93
-		}
94
-	}
95
-	else if(active_side_affecting->sticky_web && !(active_side_affecting->sticky_web_done) && battle_participants[battle_active_bank].spd_buff != 0)
96
-	{
97
-		active_side_affecting->sticky_web_done=1;
79
+            has_effect = 1;
80
+        }
81
+    } else if (active_side_affecting->sticky_web && !(active_side_affecting->sticky_web_done) && battle_participants[battle_active_bank].spd_buff != 0) {
82
+        active_side_affecting->sticky_web_done = 1;
98 83
         battle_script_push();
99 84
         battlescript_cursor = bs_sticky_web;
100 85
         battle_stat_changer = 0x93;
101 86
         has_effect = 1;
102
-	}
103
-	
104
-	if (has_effect)
105
-    {
106
-       custom_battle_struct.ptr->various.var1 = battle_active_bank;
107
-       battle_participants[battle_active_bank].status2.destinny_bond = 0;
108
-       battle_hitmarker &= 0xFFFFFFBF;
109 87
     }
110
-	return has_effect;
88
+
89
+    if (has_effect) {
90
+        custom_battle_elements.ptr->various.var1 = battle_active_bank;
91
+        battle_participants[battle_active_bank].status2.destinny_bond = 0;
92
+        battle_hitmarker &= 0xFFFFFFBF;
93
+    }
94
+    return has_effect;
111 95
 }
112 96
 
113
-u8 lay_entry_hazards()
114
-{
115
-	u8 target_side = get_side_from_bank(battle_defender_bank);
116
-	u8 fail=0;
117
-	struct side_affecting* target_side_struct = &custom_battle_struct.ptr->side_affecting[target_side];
118
-	switch(battle_executed_move)
119
-	{
120
-		case MOVE_SPIKES:
121
-			if(battle_side_timers[target_side].spikes_amount < 3)
122
-			{
123
-				battle_side_timers[target_side].spikes_amount++;
124
-				side_affecting_halfword[target_side].spikes_on = 1;
125
-				battlescript_cursor = bs_spikes_lain;
126
-			}
127
-			else
128
-			{
129
-				fail = 1;
130
-			}
131
-			break;
132
-		case MOVE_STEALTH_ROCK:
133
-			if(target_side_struct->stealth_rock==0)
134
-			{	
135
-				target_side_struct->stealth_rock=1;
136
-				battlescript_cursor = bs_rocks_lain;
137
-			}
138
-			else
139
-				fail=1;
140
-			break;
141
-		case MOVE_TOXIC_SPIKES:
142
-			if(target_side_struct->toxic_spikes_psn==0)
143
-			{
144
-				target_side_struct->toxic_spikes_psn=1;
145
-				battlescript_cursor = bs_toxic_lain;
146
-			}
147
-			else if(target_side_struct->toxic_spikes_badpsn==0)
148
-			{
149
-				target_side_struct->toxic_spikes_badpsn=1;
150
-				battlescript_cursor = bs_toxic_lain;
151
-			}
152
-			else
153
-				fail=1;
154
-			break;
155
-		case MOVE_STICKY_WEB:
156
-			if(target_side_struct->sticky_web==0)
157
-			{
158
-				target_side_struct->sticky_web=1;
159
-				battlescript_cursor = bs_sticky_lain;
160
-			}
161
-			else
162
-				fail=1;
163
-			break;
164
-		default:
165
-			fail=1;
166
-			break;
167
-	}
168
-	if(fail)
169
-	{
170
-		//failed execution
171
-		battlescript_cursor = (void*) (0x081D7DF0);
172
-	}
173
-	return 1;
97
+u8 lay_entry_hazards() {
98
+    u8 target_side = get_side_from_bank(battle_defender_bank);
99
+    u8 fail = 0;
100
+    struct side_affecting* target_side_struct = &custom_battle_elements.ptr->side_affecting[target_side];
101
+    switch (battle_executed_move) {
102
+        case MOVE_SPIKES:
103
+            if (battle_side_timers[target_side].spikes_amount < 3) {
104
+                battle_side_timers[target_side].spikes_amount++;
105
+                side_affecting_halfword[target_side].spikes_on = 1;
106
+                battlescript_cursor = bs_spikes_lain;
107
+            } else {
108
+                fail = 1;
109
+            }
110
+            break;
111
+        case MOVE_STEALTH_ROCK:
112
+            if (target_side_struct->stealth_rock == 0) {
113
+                target_side_struct->stealth_rock = 1;
114
+                battlescript_cursor = bs_rocks_lain;
115
+            } else
116
+                fail = 1;
117
+            break;
118
+        case MOVE_TOXIC_SPIKES:
119
+            if (target_side_struct->toxic_spikes_psn == 0) {
120
+                target_side_struct->toxic_spikes_psn = 1;
121
+                battlescript_cursor = bs_toxic_lain;
122
+            } else if (target_side_struct->toxic_spikes_badpsn == 0) {
123
+                target_side_struct->toxic_spikes_badpsn = 1;
124
+                battlescript_cursor = bs_toxic_lain;
125
+            } else
126
+                fail = 1;
127
+            break;
128
+        case MOVE_STICKY_WEB:
129
+            if (target_side_struct->sticky_web == 0) {
130
+                target_side_struct->sticky_web = 1;
131
+                battlescript_cursor = bs_sticky_lain;
132
+            } else
133
+                fail = 1;
134
+            break;
135
+        default:
136
+            fail = 1;
137
+            break;
138
+    }
139
+    if (fail) {
140
+        //failed execution
141
+        battlescript_cursor = (void*) (0x081D7DF0);
142
+    }
143
+    return 1;
174 144
 }

+ 4
- 0
src/include/bpre.h Просмотреть файл

@@ -15,6 +15,10 @@ void clear_flag(u16 flag);
15 15
 void* malloc(int size);
16 16
 void free(void* address);
17 17
 
18
+//debug
19
+void agbprintf(const char* pBuf, ...);
20
+void agbprint_flush();
21
+void agb_assert(const char *file, int line, const char *expression, u32 stop);
18 22
 
19 23
 // sound related stuff
20 24
 extern MPlayTable mplay_table[];

+ 5
- 5
src/include/custom_structs.h Просмотреть файл

@@ -4,7 +4,7 @@
4 4
 #include <types.h>
5 5
 
6 6
 struct bank_affecting {
7
-	u8 embargo : 3;
7
+    u8 embargo : 3;
8 8
     u8 electrify : 1;
9 9
     u8 telekinesis: 3;
10 10
     u8 magnet_rise : 3;
@@ -53,7 +53,7 @@ struct bank_affecting {
53 53
 };
54 54
 
55 55
 struct side_affecting {
56
-	u8 sticky_web : 1;
56
+    u8 sticky_web : 1;
57 57
     u8 sticky_web_done : 1;
58 58
     u8 toxic_spikes_psn : 1;
59 59
     u8 toxic_spikes_badpsn : 1;
@@ -81,7 +81,7 @@ struct side_affecting {
81 81
 };
82 82
 
83 83
 struct field_affecting {
84
-	u8 trick_room : 3;
84
+    u8 trick_room : 3;
85 85
     u8 wonder_room : 3;
86 86
     u8 magic_room : 3;
87 87
     u8 grassy_terrain : 3;
@@ -94,7 +94,7 @@ struct field_affecting {
94 94
 };
95 95
 
96 96
 struct various {
97
-	u8 eaten_berry_player : 6;
97
+    u8 eaten_berry_player : 6;
98 98
     u8 eaten_berry_opponent : 6;
99 99
     u8 active_bank : 2;
100 100
     u8 inverse_battle : 1;
@@ -117,6 +117,6 @@ struct custom_battle_struct_ptr{
117 117
     struct custom_battle_struct *ptr;
118 118
 };
119 119
 
120
-extern struct custom_battle_struct_ptr custom_battle_struct;
120
+extern struct custom_battle_struct_ptr custom_battle_elements;
121 121
 
122 122
 #endif