Bläddra i källkod

variable debugging

SBird1337 7 år sedan
förälder
incheckning
839c05bdee
2 ändrade filer med 48 tillägg och 50 borttagningar
  1. 5
    1
      patches/hooks.asm
  2. 43
    49
      src/savefile/flag_manipulation.c

+ 5
- 1
patches/hooks.asm Visa fil

@@ -101,8 +101,12 @@ _call_via_r1 equ 0x081E3BAC
101 101
 	lsl r0, #0
102 102
 	.pool
103 103
 
104
+.org 0x0806E584
105
+    ldr r3, =var_set_hack|1
106
+    bx r3
107
+
104 108
 .org 0x0806E680
105
-    ldr r1, =flag_set|1
109
+    ldr r1, =flag_set_hack|1
106 110
     bx r1
107 111
     .pool
108 112
 //end of flag routine

+ 43
- 49
src/savefile/flag_manipulation.c Visa fil

@@ -20,12 +20,12 @@
20 20
  *   If not, see <http://www.gnu.org/licenses/>.                            *
21 21
  ****************************************************************************/
22 22
 
23
- /**
24
- * @file flag_manipulation.c
25
- * @author Sturmvogel
26
- * @date 25 may 2017
27
- * @brief functions for preserving flags and reusing difficulty
28
- */
23
+/**
24
+* @file flag_manipulation.c
25
+* @author Sturmvogel
26
+* @date 25 may 2017
27
+* @brief functions for preserving flags and reusing difficulty
28
+*/
29 29
 #include <pokeagb/pokeagb.h>
30 30
 
31 31
 #define TRAINER_FLAG_SPACE_START 0x1000
@@ -33,85 +33,79 @@
33 33
 extern u16 tb_modify_flag_id(u16 flag_id);
34 34
 u16 trainerflag_fix_difficulty(u16 flag_id);
35 35
 
36
-u16 load_hword(void* ptr)
37
-{
38
-    u8* to_load = (u8*)ptr;
36
+u16 load_hword(void *ptr) {
37
+    u8 *to_load = (u8 *)ptr;
39 38
     u16 result = *to_load;
40
-    u16 result2 = *(to_load+1) << 8;
39
+    u16 result2 = *(to_load + 1) << 8;
41 40
     return result | result2;
42 41
 }
43 42
 
44
-u8 load_byte(void* ptr)
45
-{
46
-    return (u8) (*((u8*)ptr));
47
-}
43
+u8 load_byte(void *ptr) { return (u8)(*((u8 *)ptr)); }
48 44
 
49
-u16 trainerflag_fix_difficulty(u16 flag_id)
50
-{
45
+u16 trainerflag_fix_difficulty(u16 flag_id) {
51 46
     u16 new_flag = ((flag_id - TRAINER_FLAG_SPACE_START + 1) / 3) + TRAINER_FLAG_SPACE_START;
52
-    dprintf("trainerflag_fix_difficulty;; flag_id: 0x%x, reduced: 0x%x, status: %s\n", flag_id, new_flag, flag_check(new_flag) ? "true" : "false");
47
+    dprintf("trainerflag_fix_difficulty;; flag_id: 0x%x, reduced: 0x%x, status: %s\n", flag_id, new_flag,
48
+            flag_check(new_flag) ? "true" : "false");
53 49
     return new_flag;
54 50
 }
55 51
 
56
-bool trainer_check_flag_on_spot(u8 npc_id)
57
-{
58
-    void* script = npc_get_script_by_npc_id(npc_id);
52
+bool trainer_check_flag_on_spot(u8 npc_id) {
53
+    void *script = npc_get_script_by_npc_id(npc_id);
59 54
     /* probably inject some script execution here */
60 55
 
61
-    u16 flag = tb_modify_flag_id(load_hword(script+2));
56
+    u16 flag = tb_modify_flag_id(load_hword(script + 2));
62 57
     /* check for line of sight */
63 58
 
64 59
     u8 hit_result = npc_trainer_and_raycast_hit(&npc_states[npc_id]);
65 60
 
66
-    if(hit_result == 0)
61
+    if (hit_result == 0)
67 62
         return false;
68 63
 
69
-    if(flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)))
64
+    if (flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)))
70 65
         return false;
71 66
 
72
-    if((load_byte(script + 1) == 4) && (player_cant_double_battle() > 0))
67
+    if ((load_byte(script + 1) == 4) && (player_cant_double_battle() > 0))
73 68
         return false;
74
-    
69
+
75 70
     spot_trainer_8080334(npc_id, script);
76
-    spot_trainer_8081E68(&npc_states[npc_id], hit_result -1);
71
+    spot_trainer_8081E68(&npc_states[npc_id], hit_result - 1);
77 72
     return true;
78
-
79 73
 }
80 74
 
81
-u8 trainerflag_read_fix(void* script_location)
82
-{
83
-    script_location+=2;
75
+u8 trainerflag_read_fix(void *script_location) {
76
+    script_location += 2;
84 77
     u16 flag = load_hword(script_location);
85
-    //dprintf("trainerflag_read_fix: 0x%x", flag);
78
+    // dprintf("trainerflag_read_fix: 0x%x", flag);
86 79
     flag = trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START);
87 80
     return flag_check(flag);
88 81
 }
89 82
 
90 83
 volatile u8 test;
91 84
 
92
-u16 trainerflag_opponent_fix(void)
93
-{
85
+u16 trainerflag_opponent_fix(void) {
94 86
     return trainerflag_fix_difficulty(trainerbattle_flag_id + TRAINER_FLAG_SPACE_START);
95 87
 }
96 88
 
97
-bool trainerflag_check_fix(u16 flag)
98
-{
99
-    return flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START));
100
-}
89
+bool trainerflag_check_fix(u16 flag) { return flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)); }
101 90
 
102
-void trainerflag_set_fix(u16 flag)
103
-{
104
-    flag_set(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)); 
105
-}
91
+void trainerflag_set_fix(u16 flag) { flag_set(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)); }
106 92
 
107
-void trainerflag_clear_fix(u16 flag)
108
-{
109
-    flag_clear(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START));
110
-}
93
+void trainerflag_clear_fix(u16 flag) { flag_clear(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)); }
111 94
 
112
-void flag_set(u16 flag)
113
-{
114
-    u8* addr = flag_byte_access(flag);
115
-    if(addr != NULL)
95
+void flag_set_hack(u16 flag) {
96
+    u8 *addr = flag_byte_access(flag);
97
+    if (addr != NULL) {
98
+        dprintf("flag 0x%x was set\n", flag);
116 99
         *addr |= 1 << (flag & 7);
100
+    }
117 101
 }
102
+
103
+bool var_set_hack(u16 var, u16 val) {
104
+    u16 *ptr = var_access(var);
105
+    if (ptr != NULL) {
106
+        dprintf("variable 0x%x was set to 0x%x (Address: 0x%x)\n", var, val, ptr);
107
+        *ptr = val;
108
+        return true;
109
+    }
110
+    return false;
111
+}