|
9 | 9 | #include "pokereader.h" |
10 | 10 | #include "title_info.h" |
11 | 11 | #include "hid.h" |
12 | | - |
13 | | -typedef enum SupportedTitle |
14 | | -{ |
15 | | - GAME_X = 0x0004000000055D00, |
16 | | - GAME_Y = 0x0004000000055E00, |
17 | | - GAME_OR = 0x000400000011C400, |
18 | | - GAME_AS = 0x000400000011C500, |
19 | | - GAME_S = 0x0004000000164800, |
20 | | - GAME_M = 0x0004000000175E00, |
21 | | - GAME_US = 0x00040000001B5000, |
22 | | - GAME_UM = 0x00040000001B5100, |
23 | | - GAME_TRANSPORTER = 0x00040000000C9C00, |
24 | | - GAME_CRYSTAL_EN = 0x0004000000172800, |
25 | | - GAME_CRYSTAL_DE = 0x0004000000172B00, |
26 | | - GAME_CRYSTAL_FR = 0x0004000000172E00, |
27 | | - GAME_CRYSTAL_ES = 0x0004000000173100, |
28 | | - GAME_CRYSTAL_IT = 0x0004000000173400, |
29 | | -} SupportedTitle; |
| 12 | +#include "memmem.h" |
30 | 13 |
|
31 | 14 | static Handle thread; |
32 | 15 | static Handle memLayoutChanged; |
@@ -142,6 +125,15 @@ u8 HID_INPUT_MAP_PATCH[0x8] = { |
142 | 125 | 0x00, 0xf0, 0x1f, 0xe5, // ldr pc,[pc + 0x8] |
143 | 126 | }; |
144 | 127 |
|
| 128 | +u8 PRESENT_FRAMEBUFFER_BYTES[0X10] = { |
| 129 | + 0x28, 0x00, 0x8d, 0xe2, 0x00, 0x80, 0xa0, 0xe3, 0x01, 0x70, 0xa0, 0xe1, 0x00, 0x0e, 0x90, 0xe8, |
| 130 | +}; |
| 131 | + |
| 132 | +u8 MAP_INPUT_BLOCK[] = { |
| 133 | + 0x01, 0x20, 0xa0, 0x13, 0x03, 0x20, 0xa0, 0x03, 0x01, 0x32, 0xa0, 0xe3, 0x1f, 0x00, |
| 134 | + 0x00, 0xef, 0xa0, 0x1f, 0xb0, 0xe1, 0x01, 0x10, 0xa0, 0x03, 0x18, 0x10, 0xc4, 0x05 |
| 135 | +}; |
| 136 | + |
145 | 137 | extern char *fake_heap_start; |
146 | 138 | extern char *fake_heap_end; |
147 | 139 | extern u32 __ctru_heap; |
@@ -181,76 +173,20 @@ void main(void) |
181 | 173 | // Get memory layout changed event |
182 | 174 | svcControlProcess(CUR_PROCESS_HANDLE, PROCESSOP_GET_ON_MEMORY_CHANGE_EVENT, (u32)&memLayoutChanged, 0); |
183 | 175 |
|
184 | | - u32 present_buffer_ptr = 0; |
185 | | - u32 get_screen_jump_inst = 0; |
186 | | - u32 map_input_memory_block = 0; |
187 | | - |
188 | | - switch (get_title_id()) |
189 | | - { |
190 | | - case GAME_X: |
191 | | - present_buffer_ptr = 0x149354; |
192 | | - get_screen_jump_inst = 0xeb006cca; |
193 | | - map_input_memory_block = 0x133dfc; |
194 | | - break; |
195 | | - case GAME_Y: |
196 | | - present_buffer_ptr = 0x149354; |
197 | | - get_screen_jump_inst = 0xeb006cca; |
198 | | - map_input_memory_block = 0x133dfc; |
199 | | - break; |
200 | | - case GAME_OR: |
201 | | - present_buffer_ptr = 0x148758; |
202 | | - get_screen_jump_inst = 0xeb0071d4; |
203 | | - map_input_memory_block = 0x1331e8; |
204 | | - break; |
205 | | - case GAME_AS: |
206 | | - present_buffer_ptr = 0x148758; |
207 | | - get_screen_jump_inst = 0xeb0071d4; |
208 | | - map_input_memory_block = 0x1331e8; |
209 | | - break; |
210 | | - case GAME_S: |
211 | | - present_buffer_ptr = 0x278540; |
212 | | - get_screen_jump_inst = 0xeb0003d3; |
213 | | - map_input_memory_block = 0x170eac; |
214 | | - break; |
215 | | - case GAME_M: |
216 | | - present_buffer_ptr = 0x278540; |
217 | | - get_screen_jump_inst = 0xeb0003d3; |
218 | | - map_input_memory_block = 0x170eac; |
219 | | - break; |
220 | | - case GAME_US: |
221 | | - present_buffer_ptr = 0x279bb4; |
222 | | - get_screen_jump_inst = 0xeb0003d3; |
223 | | - map_input_memory_block = 0x17234c; |
224 | | - break; |
225 | | - case GAME_UM: |
226 | | - present_buffer_ptr = 0x279bb4; |
227 | | - get_screen_jump_inst = 0xeb0003d3; |
228 | | - map_input_memory_block = 0x17234c; |
229 | | - break; |
230 | | - case GAME_TRANSPORTER: |
231 | | - present_buffer_ptr = 0x12b7ec; |
232 | | - get_screen_jump_inst = 0xeb02cbd4; |
233 | | - map_input_memory_block = 0x11f63c; |
234 | | - break; |
235 | | - case GAME_CRYSTAL_EN: |
236 | | - case GAME_CRYSTAL_DE: |
237 | | - case GAME_CRYSTAL_FR: |
238 | | - case GAME_CRYSTAL_ES: |
239 | | - case GAME_CRYSTAL_IT: |
240 | | - present_buffer_ptr = 0x14aa24; |
241 | | - get_screen_jump_inst = 0xeb00b512; |
242 | | - map_input_memory_block = 0x146a28; |
243 | | - break; |
244 | | - default: |
245 | | - return; |
246 | | - } |
| 176 | + MemInfo info; |
| 177 | + PageInfo out; |
| 178 | + svcQueryMemory(&info, &out, 0x100000); |
| 179 | + |
| 180 | + u32 present_buffer_ptr = (u32)memmem((u8*)info.base_addr, info.size, PRESENT_FRAMEBUFFER_BYTES, sizeof(PRESENT_FRAMEBUFFER_BYTES)) - 8; |
| 181 | + u32 map_input_memory_block = (u32)memmem((u8*)info.base_addr, info.size, MAP_INPUT_BLOCK, sizeof(MAP_INPUT_BLOCK)); |
247 | 182 |
|
| 183 | + u32 get_screen_branch = *(u32 *)(present_buffer_ptr + 0x20) - 4; |
248 | 184 | u32 *present_buffer_pa = (u32 *)PA_FROM_VA_PTR(present_buffer_ptr); |
249 | 185 | memcpy(present_buffer_pa, DRAW_PATCH, 0x94); |
250 | 186 | present_buffer_pa[0x4] = (u32)run_hook; |
251 | 187 | // 7 instructions * 4 bytes per instruction |
252 | | - present_buffer_pa[0x5] = (u32)present_buffer_ptr + (0x7 * 0x4); // set return address |
253 | | - present_buffer_pa[0xc] = get_screen_jump_inst; // fix get_screen branch instruction |
| 188 | + present_buffer_pa[0x5] = present_buffer_ptr + (0x7 * 0x4); // set return address |
| 189 | + present_buffer_pa[0xc] = get_screen_branch; // fix get_screen branch instruction |
254 | 190 |
|
255 | 191 | u32 *map_input_memory_block_pa = (u32 *)PA_FROM_VA_PTR(map_input_memory_block); |
256 | 192 | memcpy(map_input_memory_block_pa, HID_INPUT_MAP_PATCH, 0x8); |
|
0 commit comments