Browse Source

variable debugging

SBird1337 7 years ago
parent
commit
839c05bdee
2 changed files with 48 additions and 50 deletions
  1. 5
    1
      patches/hooks.asm
  2. 43
    49
      src/savefile/flag_manipulation.c

+ 5
- 1
patches/hooks.asm View File

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

+ 43
- 49
src/savefile/flag_manipulation.c View File

20
  *   If not, see <http://www.gnu.org/licenses/>.                            *
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
 #include <pokeagb/pokeagb.h>
29
 #include <pokeagb/pokeagb.h>
30
 
30
 
31
 #define TRAINER_FLAG_SPACE_START 0x1000
31
 #define TRAINER_FLAG_SPACE_START 0x1000
33
 extern u16 tb_modify_flag_id(u16 flag_id);
33
 extern u16 tb_modify_flag_id(u16 flag_id);
34
 u16 trainerflag_fix_difficulty(u16 flag_id);
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
     u16 result = *to_load;
38
     u16 result = *to_load;
40
-    u16 result2 = *(to_load+1) << 8;
39
+    u16 result2 = *(to_load + 1) << 8;
41
     return result | result2;
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
     u16 new_flag = ((flag_id - TRAINER_FLAG_SPACE_START + 1) / 3) + TRAINER_FLAG_SPACE_START;
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
     return new_flag;
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
     /* probably inject some script execution here */
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
     /* check for line of sight */
57
     /* check for line of sight */
63
 
58
 
64
     u8 hit_result = npc_trainer_and_raycast_hit(&npc_states[npc_id]);
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
         return false;
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
         return false;
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
         return false;
68
         return false;
74
-    
69
+
75
     spot_trainer_8080334(npc_id, script);
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
     return true;
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
     u16 flag = load_hword(script_location);
77
     u16 flag = load_hword(script_location);
85
-    //dprintf("trainerflag_read_fix: 0x%x", flag);
78
+    // dprintf("trainerflag_read_fix: 0x%x", flag);
86
     flag = trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START);
79
     flag = trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START);
87
     return flag_check(flag);
80
     return flag_check(flag);
88
 }
81
 }
89
 
82
 
90
 volatile u8 test;
83
 volatile u8 test;
91
 
84
 
92
-u16 trainerflag_opponent_fix(void)
93
-{
85
+u16 trainerflag_opponent_fix(void) {
94
     return trainerflag_fix_difficulty(trainerbattle_flag_id + TRAINER_FLAG_SPACE_START);
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
         *addr |= 1 << (flag & 7);
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
+}