-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoRun.cpp
More file actions
71 lines (61 loc) · 1.55 KB
/
autoRun.cpp
File metadata and controls
71 lines (61 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "Sound.h"
asm(R"(
nsub_02029784:
beq 0x020297b0 @ skip if only start and/or select is pressed
bl UpdateAutoRunState
cmp r0, #0
beq 0x020297b0
b 0x02029788
)");
bool autoRunEnabled = false;
extern volatile const uint16_t hardwareButtons;
asm("hardwareButtons = 0x04000130");
extern "C" unsigned UpdateAutoRunState(unsigned buttons)
{
// The button flags here are slightly different from Input.h
constexpr unsigned r = 0x100;
constexpr unsigned l = 0x200;
constexpr unsigned y = 0x800;
if (buttons & y) // if Y is pressed
{
if (const auto heldButtons = ~hardwareButtons; heldButtons & l && heldButtons & r)
{
Sound::UnkPlaySoundFunc(autoRunEnabled ? 1 : 38);
autoRunEnabled = !autoRunEnabled;
}
else
Sound::UnkPlaySoundFunc(8);
}
else if (buttons & (r | l)) // if L or R is pressed
Sound::UnkPlaySoundFunc(8);
// return non-zero if buttons other than L, R or Y are pressed
return buttons & ~(r | l | y);
}
asm(R"(
@ Swap Y pressed / Y not pressed when auto-running is enabled
nsub_0202c78c:
ldr r0, =autoRunEnabled
ldrb r0, [r0]
cmp r0, #0
ldrneh r0, [r9, #4]
eornes r0, r0, #0x800
strneh r0, [r9, #4]
ldrb r0, [r9, #0x16]
b 0x0202c790
@ Disable run-up when auto-running is enabled
nsub_020d3044_ov_02:
beq 0x020d3134
ldr r1, =autoRunEnabled
ldrb r1, [r1]
cmp r1, #0
beq 0x020d3048
b 0x020d3134
@ Fix swimming when auto-running is enabled
repl_020cda18_ov_02:
ldr r1, =autoRunEnabled
ldrb r1, [r1]
cmp r1, #0
mov r1, #2
orreq r1, #0x800
bx lr
)");