Ver código fonte

trainer flag fix

SBird1337 7 anos atrás
pai
commit
5c78e4381b

+ 1
- 1
bpre.sym Ver arquivo

@@ -71,7 +71,7 @@ flag_decrypt_func = 0x0806E6D1;
71 71
 var_access = 0x0806E455;
72 72
 var_get = 0x0806E569;
73 73
 var_set = 0x0806E585;
74
-flag_check = 0x0806E6D1;
74
+flag_check = 0x0806E6D0 | 1;
75 75
 get_bs_elem_env_index = 0x0800FC2D;
76 76
 load_battle_screen_elements_1 = 0x0800F261;
77 77
 npc_states = 0x02036E38;

+ 20
- 15
patches/hooks.asm Ver arquivo

@@ -111,25 +111,30 @@ _call_via_r1 equ 0x081E3BAC
111 111
 //end of var routine
112 112
 
113 113
 //trainer Flag stuff
114
-.org 0x08080382
115
-	mov r1, #0x80
116
-	lsl r1, #0x15
114
+.org 0x08080378
115
+	ldr r1, =trainerflag_read_fix+1
116
+	bx r1
117
+    .pool
117 118
 
118
-.org 0x080800BA
119
-	mov r2, #0x80
120
-	lsl r2, #0x5
119
+.org 0x080800B8
120
+    ldr r2, =trainerflag_opponent_fix+1
121
+    bx r2
122
+    .pool
121 123
 
122
-.org 0x08080428
123
-    mov r1, #0x80
124
-    lsl r1, #0x15
124
+.org 0x08080424
125
+    ldr r1, =trainerflag_check_fix+1
126
+    bx r1
127
+    .pool
125 128
 
126
-.org 0x08080440
127
-    mov r1, #0x80
128
-    lsl r1, #0x15
129
+.org 0x0808043c
130
+    ldr r1, =trainerflag_set_fix+1
131
+    bx r1
132
+    .pool
129 133
 
130
-.org 0x08080454
131
-    mov r1, #0x80
132
-    lsl r1, #0x15
134
+.org 0x08080450
135
+    ldr r1, =trainerflag_clear_fix+1
136
+    bx r1
137
+    .pool
133 138
 //end of trainer flag stuff
134 139
 
135 140
 //New behavior bytes for jumping

+ 3
- 1
src/savefile/flag_hook.S Ver arquivo

@@ -22,8 +22,10 @@ flag_hook:
22 22
 exit:	pop {r4-r6}
23 23
 	pop {r1}
24 24
 	bx r1
25
-normal:	ldr r0, normalmemoryblock
25
+normal:	
26
+	ldr r0, normalmemoryblock
26 27
 	ldr r0, [r0, #0x0]
28
+	
27 29
 there:	lsr r1, r6, #0x3
28 30
 	mov r3, #0xEE
29 31
 	lsl r3, r3, #0x4

+ 84
- 0
src/savefile/flag_manipulation.c Ver arquivo

@@ -0,0 +1,84 @@
1
+/****************************************************************************
2
+ * Copyright (C) 2015-2017 by the SotS Team                                 *
3
+ *                                                                          *
4
+ * This file is part of Sovereign of the Skies.                             *
5
+ *                                                                          *
6
+ *   Sovereign of the Skies is free software: you can redistribute it       *
7
+ *   and/or modify it                                                       *
8
+ *   under the terms of the GNU Lesser General Public License as published  *
9
+ *   by the Free Software Foundation, either version 3 of the License, or   *
10
+ *   (at your option) any later version provided you include a copy of the  *
11
+ *   licence and this header.                                               *
12
+ *                                                                          *
13
+ *   Sovereign of the Skies is distributed in the hope that it will be      *
14
+ *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
+ *   GNU Lesser General Public License for more details.                    *
17
+ *                                                                          *
18
+ *   You should have received a copy of the GNU Lesser General Public       *
19
+ *   License along with Sovereign of the Skies.                             *
20
+ *   If not, see <http://www.gnu.org/licenses/>.                            *
21
+ ****************************************************************************/
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
+ */
29
+
30
+#define TRAINER_FLAG_SPACE_START 0x1000
31
+
32
+#include <types.h>
33
+#include <agb_debug.h>
34
+#include <stdbool.h>
35
+#include <game_engine.h>
36
+#include <battle_structs.h>
37
+
38
+u16 trainerflag_fix_difficulty(u16 flag_id);
39
+
40
+u16 load_hword(void* ptr)
41
+{
42
+    u8* to_load = (u8*)ptr;
43
+    u16 result = *to_load;
44
+    u16 result2 = *(to_load+1) << 8;
45
+    return result | result2;
46
+}
47
+
48
+u16 trainerflag_fix_difficulty(u16 flag_id)
49
+{
50
+    u16 new_flag = ((flag_id - TRAINER_FLAG_SPACE_START + 1) / 3) + TRAINER_FLAG_SPACE_START;
51
+    dprintf("trainerflag_fix_difficulty;; flag_id: 0x%x, reduced: 0x%x\n", flag_id, new_flag);
52
+    return new_flag;
53
+}
54
+
55
+u8 trainerflag_read_fix(void* script_location)
56
+{
57
+    script_location+=2;
58
+    u16 flag = load_hword(script_location);
59
+    //dprintf("trainerflag_read_fix: 0x%x", flag);
60
+    flag = trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START);
61
+    return flag_check(flag);
62
+}
63
+
64
+volatile u8 test;
65
+
66
+u16 trainerflag_opponent_fix(void)
67
+{
68
+    return trainerflag_fix_difficulty(trainerbattle_flag_id + TRAINER_FLAG_SPACE_START);
69
+}
70
+
71
+bool trainerflag_check_fix(u16 flag)
72
+{
73
+    return flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START));
74
+}
75
+
76
+void trainerflag_set_fix(u16 flag)
77
+{
78
+    flag_set(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)); 
79
+}
80
+
81
+void trainerflag_clear_fix(u16 flag)
82
+{
83
+    flag_clear(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START));
84
+}

+ 9
- 4
src/specials/trainer_battle.c Ver arquivo

@@ -35,6 +35,7 @@
35 35
 #include <debug.h>
36 36
 #include <config.h>
37 37
 #include <callback.h>
38
+#include <agb_debug.h>
38 39
 
39 40
 /* === ENGINE EXTERNS === */
40 41
 extern void battle_init();
@@ -104,16 +105,20 @@ u32 load_word(void* ptr)
104 105
 u16 tb_modify_flag_id(u16 flag)
105 106
 {
106 107
     u16 difficulty = var_get(0x5052);
108
+    u16 new_flag = flag;
107 109
     switch(difficulty)
108 110
     {
109 111
         case 0:
110
-            return flag;
112
+            break;
111 113
         case 1:
112
-            return flag + 1;
114
+            new_flag = flag + 1;
115
+            break;
113 116
         case 2:
114
-            return flag + 2;
117
+            new_flag = flag + 2;
118
+            break;
115 119
     }
116
-    return 0;
120
+    dprintf("tb_modify_flag_id;; trainer ID: %d, difficulty: %d, new trainer id: %d\n", flag, difficulty, new_flag);
121
+    return new_flag;
117 122
 }
118 123
 
119 124
 /**