Skip to content

Commit 9d8ed71

Browse files
committed
Stored the Link Register when calling functions via assembly
This is mainly done so that the backtrace screen will show the proper address(es) in the LR Save field when the function that was called at that point was done via injected assembly. Doing this also allows using bl branches instead of regular branches, which actually ends up using less memory overall. Renamed and/or moved some functions that are called via assembly. Created a trampoline for the marioKeyOn fix, as it is easier to manage. Adjusted the Player struct to include the key variable.
1 parent 57f428d commit 9d8ed71

21 files changed

+364
-364
lines changed

ttyd-tools/rel/include/codes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ void displayYoshiSkipDetails();
3434
void displayPalaceSkipDetails();
3535
void actionCommandsTimingsInit();
3636
void displayActionCommandsTiming();
37-
void displayArtAttackHitboxes();
3837

3938
int32_t warpToMap(uint32_t value);
4039
int32_t warpToMapByString(const char *map);

ttyd-tools/rel/include/mod.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Mod
2020
const char *getCustomMessage(const char *);
2121
uint32_t pauseArtAttackTimer();
2222
uint32_t setIndexWarpEntrance(void *, uint32_t);
23+
int32_t fixMarioKeyOn();
2324

2425
private:
2526
void (*mPFN_marioStMain_trampoline)() = nullptr;
@@ -34,6 +35,7 @@ class Mod
3435
const char *(*mPFN_msgSearch_trampoline)(const char *) = nullptr;
3536
uint32_t (*mPFN_scissor_timer_main_trampoline)() = nullptr;
3637
uint32_t (*mPFN_evt_bero_get_info_trampoline)(void *, uint32_t) = nullptr;
38+
int32_t (*mPFN_marioKeyOn_trampoline)() = nullptr;
3739
};
3840

3941
}

ttyd-tools/rel/include/ttyd/mario.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ struct Player
2222
uint16_t prevMotionId;
2323
uint16_t pad_32;
2424
uint32_t wMapTime;
25-
uint32_t wUnkCounter;
25+
uint8_t unk_38;
26+
int8_t wKey;
27+
uint8_t unk_3a[2];
2628
int8_t characterId;
2729
int8_t colorId;
2830
uint8_t unk_3e;
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
.global StartAllowRunningFromBattles
2-
.global BranchBackAllowRunningFromBattles
32

43
StartAllowRunningFromBattles:
4+
stwu %sp,-0x8(%sp)
5+
mflr %r0
6+
stw %r0,0xC(%sp)
7+
58
# r3 already contains ptr
69
bl allowRunningFromBattles
710
mr %r0,%r3
811

9-
BranchBackAllowRunningFromBattles:
10-
b 0
12+
lwz %r3,0xC(%sp)
13+
mtlr %r3
14+
addi %sp,%sp,0x8
15+
blr
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
.global StartDisableDPadOptionsDisplay
2-
.global BranchBackDisableDPadOptionsDisplay
32

43
StartDisableDPadOptionsDisplay:
54
stwu %sp,-0xC(%sp)
5+
mflr %r3
6+
stw %r3,0x10(%sp)
67
stw %r31,0x8(%sp)
78
mr %r31,%r4
89

@@ -14,7 +15,7 @@ cmpwi %r3,0 # False
1415

1516
mr %r4,%r31
1617
lwz %r31,0x8(%sp)
18+
lwz %r0,0x10(%sp)
19+
mtlr %r0
1720
addi %sp,%sp,0xC
18-
19-
BranchBackDisableDPadOptionsDisplay:
20-
b 0
21+
blr
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
.global StartDisableBattles
2-
.global BranchBackDisableBattles
32

43
StartDisableBattles:
4+
stwu %sp,-0x8(%sp)
5+
mflr %r0
6+
stw %r0,0xC(%sp)
7+
58
mr %r3,%r30 # ptr
69
bl disableBattles
710
mr %r21,%r3
811

9-
# Restore overwritten CR value(s)
10-
rlwinm. %r26,%r19,0,27,27
12+
lwz %r0,0xC(%sp)
13+
mtlr %r0
14+
addi %sp,%sp,0x8
1115

12-
BranchBackDisableBattles:
13-
b 0
16+
# Restore the overwritten CR value(s)
17+
rlwinm. %r26,%r19,0,27,27
18+
blr

ttyd-tools/rel/source/assembly/DisplayMegaHammerBadgesInBattleMenu.s

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
StartDisplayMegaHammerBadgesBattleMenu:
55
stwu %sp,-0x14(%sp)
6+
mflr %r3
7+
stw %r3,0x18(%sp)
68
stmw %r30,0x8(%sp)
79
mr %r31,%r4
810
mr %r30,%r5
911

1012
mr %r3,%r0 # checkBit
1113
bl displayMegaHammerBadgesInMenu
1214

15+
# Check the returned bool
16+
cmpwi %r3,0 # False
17+
1318
mr %r4,%r31
1419
mr %r5,%r30
1520
lmw %r30,0x8(%sp)
21+
lwz %r0,0x18(%sp)
22+
mtlr %r0
1623
addi %sp,%sp,0x14
17-
18-
# Check the returned bool
19-
cmpwi %r3,0 # False
20-
21-
BranchBackDisplayMegaHammerBadgesBattleMenu:
22-
b 0
24+
blr

ttyd-tools/rel/source/assembly/DisplayMegaJumpBadgeInBattleMenu.s

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
StartDisplayMegaJumpBadgeBattleMenu:
55
stwu %sp,-0x14(%sp)
6+
mflr %r3
7+
stw %r3,0x18(%sp)
68
stmw %r30,0x8(%sp)
79
mr %r31,%r4
810
mr %r30,%r5
911

1012
mr %r3,%r0 # checkBit
1113
bl displayMegaJumpBadgeInMenu
1214

15+
# Check the returned bool
16+
cmpwi %r3,0 # False
17+
1318
mr %r4,%r31
1419
mr %r5,%r30
1520
lmw %r30,0x8(%sp)
21+
lwz %r0,0x18(%sp)
22+
mtlr %r0
1623
addi %sp,%sp,0x14
17-
18-
# Check the returned bool
19-
cmpwi %r3,0 # False
20-
21-
BranchBackDisplayMegaJumpBadgeBattleMenu:
22-
b 0
24+
blr
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.global StartDrawArtAttackHitboxes
2+
3+
StartDrawArtAttackHitboxes:
4+
stwu %sp,-0x8(%sp)
5+
mflr %r0
6+
stw %r0,0xC(%sp)
7+
8+
bl drawArtAttackHitboxes
9+
10+
lwz %r0,0xC(%sp)
11+
mtlr %r0
12+
addi %sp,%sp,0x8
13+
14+
# Restore the overwritten instruction
15+
lmw %r26,0x18(%sp)
16+
blr
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
.global StartFixBlooperCrash1
2-
.global BranchBackFixBlooperCrash1
32

43
StartFixBlooperCrash1:
54
mr %r3,%r31 # unkValue
65
# r4 already contains battleUnitPointer
7-
bl fixBlooperCrash1
8-
9-
BranchBackFixBlooperCrash1:
10-
b 0
6+
b fixBlooperCrash1

0 commit comments

Comments
 (0)