Browse Source

malloc battle resources

Philipp Auer 8 years ago
parent
commit
7452670315

+ 1
- 1
bpre.sym View File

1
 set_callback2 = 0x08000545;
1
 set_callback2 = 0x08000545;
2
 vblank_handler_set = 0x080006F5;
2
 vblank_handler_set = 0x080006F5;
3
-malloc = 0x08002BB1;
3
+malloc = 0x08002BB0|1;
4
 free = 0x08002BC4|1;
4
 free = 0x08002BC4|1;
5
 memset = 0x081E5ED8|1;
5
 memset = 0x081E5ED8|1;
6
 template_instanciate_forward_search = 0x08006F8D;
6
 template_instanciate_forward_search = 0x08006F8D;

+ 2
- 0
main.asm View File

28
 .include "patches/pokemon_data/pokemon_shiny_pal.asm"
28
 .include "patches/pokemon_data/pokemon_shiny_pal.asm"
29
 .include "patches/pokemon_data/pokemon_icons.asm"
29
 .include "patches/pokemon_data/pokemon_icons.asm"
30
 
30
 
31
+.include "patches/battle_engine/malloc.asm"
32
+
31
 
33
 
32
 .org 0x09000000
34
 .org 0x09000000
33
 .importobj "object/linked.o"
35
 .importobj "object/linked.o"

+ 8
- 2
patches/battle_engine/malloc.asm View File

1
+.org 0x0802E078
2
+ldr r1, =alloc_res_hook|1
3
+bx r1
4
+
5
+.pool
6
+
1
 .org 0x0802E224
7
 .org 0x0802E224
2
-.word alloc_res_hook|1
8
+.word free_res_hook|1
3
 
9
 
4
 .org 0x0802E1F8
10
 .org 0x0802E1F8
5
-bx r0
11
+bx r4

+ 6
- 3
src/battle_engine/custom_structs_malloc.c View File

1
 #include <bpre.h>
1
 #include <bpre.h>
2
-#include "custum_structs_malloc.h"
2
+#include "custom_structs.h"
3
+#include "custom_structs_malloc.h"
3
 
4
 
4
 void malloc_battle_structs()
5
 void malloc_battle_structs()
5
 {
6
 {
6
-	
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;
7
 }
9
 }
8
 
10
 
9
 void free_battle_structs()
11
 void free_battle_structs()
10
 {
12
 {
11
-	
13
+	free(custom_battle_struct.ptr);
14
+	custom_battle_struct.ptr=0;
12
 }
15
 }

+ 21
- 4
src/battle_engine/custom_structs_malloc_hook.S View File

4
 
4
 
5
 .global alloc_res_hook
5
 .global alloc_res_hook
6
 alloc_res_hook:
6
 alloc_res_hook:
7
+str r0, [r4] @save last malloced data pointer
8
+ldr r4, =0x02023FF4 @some battle struct pointer
9
+mov r0, #0x20 @size of struct
10
+bl malloc_and_clear
11
+str r0, [r4]
7
 
12
 
8
-bl malloc_battle_structs
13
+bl malloc_battle_structs @allocate custom stuff
9
 ldr r0, =0x0802E084|1
14
 ldr r0, =0x0802E084|1
10
 bx r0
15
 bx r0
11
 
16
 
12
 .align 2
17
 .align 2
13
-
14
 .global free_res_hook
18
 .global free_res_hook
15
 free_res_hook:
19
 free_res_hook:
16
-
20
+ldr r4, =0x02022BBC
21
+ldr r0, [r4]
22
+bl free_routine
23
+str r5, [r4]	@@null_pointer
17
 bl free_battle_structs
24
 bl free_battle_structs
18
 ldr r0, =0x0802E200|1
25
 ldr r0, =0x0802E200|1
19
-bx r0
26
+bx r0
27
+
28
+.align 2
29
+
30
+malloc_and_clear:
31
+ldr r3, =malloc
32
+bx r3
33
+
34
+free_routine:
35
+ldr r3, =free
36
+bx r3