Skip to content

Commit 8c4e098

Browse files
committed
More improvements
Use switch statements where applicable, adjust Text Storage code to not activate multiple times upon entering the button combo, adjust Warp code to use less memory.
1 parent 402b88b commit 8c4e098

File tree

4 files changed

+68
-140
lines changed

4 files changed

+68
-140
lines changed

ttyd-tools/rel/include/mod.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Mod
3535

3636
// Text Storage
3737
void textStorage();
38+
bool textStorageDisable = false;
3839

3940
// Levitate
4041
void levitate();

ttyd-tools/rel/source/codes/AddRemovePartnersC.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,22 @@ void Mod::addOrRemovePartners()
5151
// Currently inside partners menu
5252
uint32_t PartnerOnCursor = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x1D8);
5353

54-
if (PartnerOnCursor == 0)
54+
switch (PartnerOnCursor)
5555
{
56-
// Goombella
57-
*reinterpret_cast<uint8_t *>(PouchAddress + 0xF) = 0;
58-
}
59-
else if (PartnerOnCursor == 1)
60-
{
61-
// Koops
62-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x1D) = 0;
63-
}
64-
else if (PartnerOnCursor == 2)
65-
{
66-
// Flurrie
67-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x47) = 0;
68-
}
69-
else if (PartnerOnCursor == 3)
70-
{
71-
// Yoshi
72-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x39) = 0;
73-
}
74-
else if (PartnerOnCursor == 4)
75-
{
76-
// Vivian
77-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x55) = 0;
78-
}
79-
else if (PartnerOnCursor == 5)
80-
{
81-
// Bobbery
82-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x2B) = 0;
83-
}
84-
else // if (PartnerOnCursor == 6)
85-
{
86-
// Mowz
87-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x63) = 0;
56+
case 0: // Goombella
57+
*reinterpret_cast<uint8_t *>(PouchAddress + 0xF) = 0; break;
58+
case 1: // Koops
59+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x1D) = 0; break;
60+
case 2: // Flurrie
61+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x47) = 0; break;
62+
case 3: // Yoshi
63+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x39) = 0; break;
64+
case 4: // Vivian
65+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x55) = 0; break;
66+
case 5: // Bobbery
67+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x2B) = 0; break;
68+
case 6: // Mowz
69+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x63) = 0; break;
8870
}
8971

9072
// Reload party menu

ttyd-tools/rel/source/codes/TextStorageC.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,26 @@ void Mod::textStorage()
1818

1919
if ((ButtonInput & TextStorageCombo) == (TextStorageCombo))
2020
{
21-
if (PartnerPointer != 0)
21+
if ((!textStorageDisable) && (PartnerPointer != 0))
2222
{
2323
// A Partner is currently out
2424
*reinterpret_cast<uint8_t *>(PartnerPointer + 0x39) = 0;
2525
}
26+
textStorageDisable = true;
2627
}
2728
else if ((ButtonInput & TimeStopTextStorageCombo) == (TimeStopTextStorageCombo))
2829
{
29-
if (PartnerPointer != 0)
30+
if ((!textStorageDisable) && (PartnerPointer != 0))
3031
{
3132
// A Partner is currently out
3233
*reinterpret_cast<uint8_t *>(PartnerPointer + 0x39) = 21;
3334
}
35+
textStorageDisable = true;
36+
}
37+
else
38+
{
39+
// Reset flag if no button combo is pressed/held
40+
textStorageDisable = false;
3441
}
3542
}
3643

ttyd-tools/rel/source/codes/WarpC.cpp

Lines changed: 43 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ extern char *NextArea;
1717

1818
namespace mod {
1919

20-
void writeMap(uint32_t Source)
21-
{
22-
ttyd::string::strcpy(NextMap, reinterpret_cast<char *>(Source));
23-
ttyd::string::strncpy(NextArea, reinterpret_cast<char *>(Source), 3);
24-
}
25-
2620
void Mod::warp()
2721
{
2822
if ((ttyd::system::keyGetButton(0) & WarpCombo) == WarpCombo)
@@ -34,108 +28,52 @@ void Mod::warp()
3428
{
3529
// Currently in the pause menu, and Current Tab is Mario's stats
3630
int16_t CoinCount = *reinterpret_cast<int16_t *>(ttyd::mario_pouch::pouchGetPtr() + 0x78);
31+
uint32_t WarpToMap = 0;
3732

38-
if (CoinCount == 0)
39-
{
40-
writeMap(gor_01);
41-
}
42-
else if (CoinCount == 1)
43-
{
44-
writeMap(tik_00);
45-
}
46-
else if (CoinCount == 2)
47-
{
48-
writeMap(hei_00);
49-
}
50-
else if (CoinCount == 3)
51-
{
52-
writeMap(gon_00);
53-
}
54-
else if (CoinCount == 4)
55-
{
56-
writeMap(win_06);
57-
}
58-
else if (CoinCount == 5)
59-
{
60-
writeMap(mri_01);
61-
}
62-
else if (CoinCount == 6)
63-
{
64-
writeMap(tou_02);
65-
}
66-
else if (CoinCount == 7)
67-
{
68-
writeMap(tou_05);
69-
}
70-
else if (CoinCount == 8)
71-
{
72-
writeMap(usu_00);
73-
}
74-
else if (CoinCount == 9)
75-
{
76-
writeMap(jin_00);
77-
}
78-
else if (CoinCount == 10)
79-
{
80-
writeMap(muj_01);
33+
switch (CoinCount)
34+
{
35+
case 0: WarpToMap = gor_01; break;
36+
case 1: WarpToMap = tik_00; break;
37+
case 2: WarpToMap = hei_00; break;
38+
case 3: WarpToMap = gon_00; break;
39+
case 4: WarpToMap = win_06; break;
40+
case 5: WarpToMap = mri_01; break;
41+
case 6: WarpToMap = tou_02; break;
42+
case 7: WarpToMap = tou_05; break;
43+
case 8: WarpToMap = usu_00; break;
44+
case 9: WarpToMap = jin_00; break;
45+
case 10: WarpToMap = muj_01; break;
46+
case 11: WarpToMap = dou_00; break;
47+
case 12: WarpToMap = rsh_02_a; break;
48+
case 13: WarpToMap = eki_00; break;
49+
case 14: WarpToMap = pik_00; break;
50+
case 15: WarpToMap = bom_00; break;
51+
case 16: WarpToMap = moo_00; break;
52+
case 17: WarpToMap = aji_00; break;
53+
case 18: WarpToMap = aji_13; break;
54+
case 19: WarpToMap = las_00; break;
55+
case 20: WarpToMap = las_09; break;
56+
case 21: WarpToMap = las_27; break;
57+
case 22:
58+
#ifdef TTYD_US
59+
uint32_t minnnanokoe = 0x802ECF74;
60+
#elif defined TTYD_JP
61+
uint32_t minnnanokoe = 0x802ECB70;
62+
#elif defined TTYD_EU
63+
uint32_t minnnanokoe = 0x802F8BD4;
64+
#endif
65+
66+
ttyd::string::strcpy(NextBero, reinterpret_cast<char *>(minnnanokoe));
67+
WarpToMap = las_29;
68+
ttyd::swdrv::swByteSet(0, 400);
69+
break;
8170
}
82-
else if (CoinCount == 11)
83-
{
84-
writeMap(dou_00);
85-
}
86-
else if (CoinCount == 12)
87-
{
88-
writeMap(rsh_02_a);
89-
}
90-
else if (CoinCount == 13)
91-
{
92-
writeMap(eki_00);
93-
}
94-
else if (CoinCount == 14)
95-
{
96-
writeMap(pik_00);
97-
}
98-
else if (CoinCount == 15)
99-
{
100-
writeMap(bom_00);
101-
}
102-
else if (CoinCount == 16)
103-
{
104-
writeMap(moo_00);
105-
}
106-
else if (CoinCount == 17)
107-
{
108-
writeMap(aji_00);
109-
}
110-
else if (CoinCount == 18)
111-
{
112-
writeMap(aji_13);
113-
}
114-
else if (CoinCount == 19)
115-
{
116-
writeMap(las_00);
117-
}
118-
else if (CoinCount == 20)
119-
{
120-
writeMap(las_09);
121-
}
122-
else if (CoinCount == 21)
123-
{
124-
writeMap(las_27);
125-
}
126-
else if (CoinCount == 22)
71+
72+
if (WarpToMap != 0)
12773
{
128-
#ifdef TTYD_US
129-
uint32_t minnnanokoe = 0x802ECF74;
130-
#elif defined TTYD_JP
131-
uint32_t minnnanokoe = 0x802ECB70;
132-
#elif defined TTYD_EU
133-
uint32_t minnnanokoe = 0x802F8BD4;
134-
#endif
135-
136-
ttyd::string::strcpy(NextBero, reinterpret_cast<char *>(minnnanokoe));
137-
writeMap(las_29);
138-
ttyd::swdrv::swByteSet(0, 400);
74+
// WarpToMap is set
75+
ttyd::string::strcpy(NextMap, reinterpret_cast<char *>(WarpToMap));
76+
ttyd::string::strncpy(NextArea, reinterpret_cast<char *>(WarpToMap), 3);
13977
}
14078
}
14179
}

0 commit comments

Comments
 (0)