瀏覽代碼

malloc battle resources

Philipp Auer 8 年之前
父節點
當前提交
7452670315
共有 5 個文件被更改,包括 38 次插入10 次删除
  1. 1
    1
      bpre.sym
  2. 2
    0
      main.asm
  3. 8
    2
      patches/battle_engine/malloc.asm
  4. 6
    3
      src/battle_engine/custom_structs_malloc.c
  5. 21
    4
      src/battle_engine/custom_structs_malloc_hook.S

+ 1
- 1
bpre.sym 查看文件

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

+ 2
- 0
main.asm 查看文件

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

+ 8
- 2
patches/battle_engine/malloc.asm 查看文件

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

+ 6
- 3
src/battle_engine/custom_structs_malloc.c 查看文件

@@ -1,12 +1,15 @@
1 1
 #include <bpre.h>
2
-#include "custum_structs_malloc.h"
2
+#include "custom_structs.h"
3
+#include "custom_structs_malloc.h"
3 4
 
4 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 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 查看文件

@@ -4,16 +4,33 @@
4 4
 
5 5
 .global alloc_res_hook
6 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 14
 ldr r0, =0x0802E084|1
10 15
 bx r0
11 16
 
12 17
 .align 2
13
-
14 18
 .global free_res_hook
15 19
 free_res_hook:
16
-
20
+ldr r4, =0x02022BBC
21
+ldr r0, [r4]
22
+bl free_routine
23
+str r5, [r4]	@@null_pointer
17 24
 bl free_battle_structs
18 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