Skip to content

Commit 4f43654

Browse files
committed
Further optimizations
1 parent faa904e commit 4f43654

File tree

4 files changed

+152
-164
lines changed

4 files changed

+152
-164
lines changed

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

Lines changed: 70 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,94 +15,90 @@ namespace mod {
1515

1616
void Mod::addOrRemovePartners()
1717
{
18-
if (ttyd::mariost::marioStGetSystemLevel() == 15)
18+
uint32_t PauseMenuAddress = *reinterpret_cast<uint32_t *>(PauseMenuAddressesStart);
19+
uint32_t CurrentTab = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x40);
20+
21+
if ((ttyd::mariost::marioStGetSystemLevel() == 15) && (CurrentTab == 1))
1922
{
20-
// Currently in the pause menu
21-
uint32_t PauseMenuAddress = *reinterpret_cast<uint32_t *>(PauseMenuAddressesStart);
22-
uint32_t CurrentTab = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x40);
23+
// Currently in the partners menu
24+
uint32_t ButtonInput = ttyd::system::keyGetButton(0);
25+
uint32_t PouchAddress = ttyd::mario_pouch::pouchGetPtr();
2326

24-
if (CurrentTab == 1)
27+
if ((ButtonInput & AddPartnersCombo) == AddPartnersCombo)
2528
{
26-
// Currently in partners menu
27-
uint32_t ButtonInput = ttyd::system::keyGetButton(0);
28-
uint32_t PouchAddress = ttyd::mario_pouch::pouchGetPtr();
29-
30-
if ((ButtonInput & AddPartnersCombo) == AddPartnersCombo)
29+
if (!addOrRemovePartnersDisable)
3130
{
32-
if (!addOrRemovePartnersDisable)
31+
for (int i = 0; i < 7; i++)
3332
{
34-
for (int i = 0; i < 7; i++)
33+
PouchAddress += 0xE;
34+
*reinterpret_cast<uint8_t *>(PouchAddress + 0x1) = 1;
35+
}
36+
37+
// Reload party menu
38+
uint32_t *PauseMenuPointer = reinterpret_cast<uint32_t *>(PauseMenuAddress);
39+
ttyd::win_party::winPartyExit(PauseMenuPointer);
40+
ttyd::win_party::winPartyInit(PauseMenuPointer);
41+
}
42+
addOrRemovePartnersDisable = true;
43+
}
44+
else if ((ButtonInput & RemovePartnersCombo) == RemovePartnersCombo)
45+
{
46+
if (!addOrRemovePartnersDisable)
47+
{
48+
uint32_t CurrentMenuInside = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x24);
49+
if (CurrentMenuInside == 12)
50+
{
51+
// Currently inside partners menu
52+
uint32_t PartnerOnCursor = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x1D8);
53+
54+
if (PartnerOnCursor == 0)
55+
{
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)
3575
{
36-
PouchAddress += 0xE;
37-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x1) = 1;
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;
3888
}
3989

4090
// Reload party menu
4191
uint32_t *PauseMenuPointer = reinterpret_cast<uint32_t *>(PauseMenuAddress);
4292
ttyd::win_party::winPartyExit(PauseMenuPointer);
4393
ttyd::win_party::winPartyInit(PauseMenuPointer);
4494
}
45-
addOrRemovePartnersDisable = true;
46-
}
47-
else if ((ButtonInput & RemovePartnersCombo) == RemovePartnersCombo)
48-
{
49-
if (!addOrRemovePartnersDisable)
50-
{
51-
uint32_t CurrentMenuInside = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x24);
52-
if (CurrentMenuInside == 12)
53-
{
54-
// Currently inside partners menu
55-
uint32_t PartnerOnCursor = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x1D8);
56-
57-
if (PartnerOnCursor == 0)
58-
{
59-
// Goombella
60-
*reinterpret_cast<uint8_t *>(PouchAddress + 0xF) = 0;
61-
}
62-
else if (PartnerOnCursor == 1)
63-
{
64-
// Koops
65-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x1D) = 0;
66-
}
67-
else if (PartnerOnCursor == 2)
68-
{
69-
// Flurrie
70-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x47) = 0;
71-
}
72-
else if (PartnerOnCursor == 3)
73-
{
74-
// Yoshi
75-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x39) = 0;
76-
}
77-
else if (PartnerOnCursor == 4)
78-
{
79-
// Vivian
80-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x55) = 0;
81-
}
82-
else if (PartnerOnCursor == 5)
83-
{
84-
// Bobbery
85-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x2B) = 0;
86-
}
87-
else // if (PartnerOnCursor == 6)
88-
{
89-
// Mowz
90-
*reinterpret_cast<uint8_t *>(PouchAddress + 0x63) = 0;
91-
}
92-
93-
// Reload party menu
94-
uint32_t *PauseMenuPointer = reinterpret_cast<uint32_t *>(PauseMenuAddress);
95-
ttyd::win_party::winPartyExit(PauseMenuPointer);
96-
ttyd::win_party::winPartyInit(PauseMenuPointer);
97-
}
98-
}
99-
addOrRemovePartnersDisable = true;
100-
}
101-
else
102-
{
103-
// Reset flag if no button combo is pressed/held
104-
addOrRemovePartnersDisable = false;
10595
}
96+
addOrRemovePartnersDisable = true;
97+
}
98+
else
99+
{
100+
// Reset flag if no button combo is pressed/held
101+
addOrRemovePartnersDisable = false;
106102
}
107103
}
108104
}

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

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,96 +27,92 @@ void adjustCoinCount(uint32_t tempCoinCountAddress, int16_t tempCoinCount, int16
2727

2828
void Mod::adjustCoinCountSetSequence()
2929
{
30-
if (ttyd::mariost::marioStGetSystemLevel() == 15)
30+
uint32_t PauseMenuAddress = *reinterpret_cast<uint32_t *>(PauseMenuAddressesStart);
31+
uint32_t CurrentTab = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x40);
32+
33+
if ((ttyd::mariost::marioStGetSystemLevel() == 15) && (CurrentTab == 0))
3134
{
32-
// Currently in the pause menu
33-
uint32_t PauseMenuAddress = *reinterpret_cast<uint32_t *>(PauseMenuAddressesStart);
34-
uint32_t CurrentTab = *reinterpret_cast<uint32_t *>(PauseMenuAddress + 0x40);
35-
35+
// Currently in the pause menu and Current Tab is Mario's stats
3636
uint32_t CoinCountAddress = ttyd::mario_pouch::pouchGetPtr() + 0x78;
3737
int16_t CoinCount = *reinterpret_cast<int16_t *>(CoinCountAddress);
3838

3939
uint32_t ButtonInput = ttyd::system::keyGetButton(0);
4040
uint16_t ButtonHoldFrames = 45; // 0.75 Seconds
4141

42-
if (CurrentTab == 0)
42+
if ((ButtonInput & CoinsSetToZeroCombo) == CoinsSetToZeroCombo)
4343
{
44-
// Current Tab is Mario's stats
45-
if ((ButtonInput & CoinsSetToZeroCombo) == CoinsSetToZeroCombo)
46-
{
47-
// Set Coin Count to 0
48-
*reinterpret_cast<int16_t *>(CoinCountAddress) = 0;
49-
}
50-
else if ((ButtonInput & CoinsSetSequenceCombo) == CoinsSetSequenceCombo)
51-
{
52-
// Set Sequence Position to Coin Count
53-
ttyd::swdrv::swByteSet(0, CoinCount);
54-
}
55-
else if ((ButtonInput & CoinsIncrement1Combo) == CoinsIncrement1Combo)
56-
{
57-
if (CoinCountButtonHoldCounter == 0)
58-
{
59-
// Increment Coin Count by 1
60-
adjustCoinCount(CoinCountAddress, CoinCount, 1);
61-
}
62-
CoinCountButtonHoldCounter++;
63-
}
64-
else if ((ButtonInput & CoinsIncrement10Combo) == CoinsIncrement10Combo)
65-
{
66-
if (CoinCountButtonHoldCounter == 0)
67-
{
68-
// Increment Coin Count by 10
69-
adjustCoinCount(CoinCountAddress, CoinCount, 10);
70-
}
71-
CoinCountButtonHoldCounter++;
72-
}
73-
else if ((ButtonInput & CoinsIncrement100Combo) == CoinsIncrement100Combo)
44+
// Set Coin Count to 0
45+
*reinterpret_cast<int16_t *>(CoinCountAddress) = 0;
46+
}
47+
else if ((ButtonInput & CoinsSetSequenceCombo) == CoinsSetSequenceCombo)
48+
{
49+
// Set Sequence Position to Coin Count
50+
ttyd::swdrv::swByteSet(0, CoinCount);
51+
}
52+
else if ((ButtonInput & CoinsIncrement1Combo) == CoinsIncrement1Combo)
53+
{
54+
if (CoinCountButtonHoldCounter == 0)
7455
{
75-
if (CoinCountButtonHoldCounter == 0)
76-
{
77-
// Increment Coin Count by 100
78-
adjustCoinCount(CoinCountAddress, CoinCount, 100);
79-
}
80-
CoinCountButtonHoldCounter++;
56+
// Increment Coin Count by 1
57+
adjustCoinCount(CoinCountAddress, CoinCount, 1);
8158
}
82-
else if ((ButtonInput & CoinsDecrement1Combo) == CoinsDecrement1Combo)
59+
CoinCountButtonHoldCounter++;
60+
}
61+
else if ((ButtonInput & CoinsIncrement10Combo) == CoinsIncrement10Combo)
62+
{
63+
if (CoinCountButtonHoldCounter == 0)
8364
{
84-
if (CoinCountButtonHoldCounter == 0)
85-
{
86-
// Decrement Coin Count by 1
87-
adjustCoinCount(CoinCountAddress, CoinCount, -1);
88-
}
89-
CoinCountButtonHoldCounter++;
65+
// Increment Coin Count by 10
66+
adjustCoinCount(CoinCountAddress, CoinCount, 10);
9067
}
91-
else if ((ButtonInput & CoinsDecrement10Combo) == CoinsDecrement10Combo)
68+
CoinCountButtonHoldCounter++;
69+
}
70+
else if ((ButtonInput & CoinsIncrement100Combo) == CoinsIncrement100Combo)
71+
{
72+
if (CoinCountButtonHoldCounter == 0)
9273
{
93-
if (CoinCountButtonHoldCounter == 0)
94-
{
95-
// Decrement Coin Count by 10
96-
adjustCoinCount(CoinCountAddress, CoinCount, -10);
97-
}
98-
CoinCountButtonHoldCounter++;
74+
// Increment Coin Count by 100
75+
adjustCoinCount(CoinCountAddress, CoinCount, 100);
9976
}
100-
else if ((ButtonInput & CoinsDecrement100Combo) == CoinsDecrement100Combo)
77+
CoinCountButtonHoldCounter++;
78+
}
79+
else if ((ButtonInput & CoinsDecrement1Combo) == CoinsDecrement1Combo)
80+
{
81+
if (CoinCountButtonHoldCounter == 0)
10182
{
102-
if (CoinCountButtonHoldCounter == 0)
103-
{
104-
// Decrement Coin Count by 100
105-
adjustCoinCount(CoinCountAddress, CoinCount, -100);
106-
}
107-
CoinCountButtonHoldCounter++;
83+
// Decrement Coin Count by 1
84+
adjustCoinCount(CoinCountAddress, CoinCount, -1);
10885
}
109-
else
86+
CoinCountButtonHoldCounter++;
87+
}
88+
else if ((ButtonInput & CoinsDecrement10Combo) == CoinsDecrement10Combo)
89+
{
90+
if (CoinCountButtonHoldCounter == 0)
11091
{
111-
// Reset counter if no button combo is pressed/held
112-
CoinCountButtonHoldCounter = 0;
92+
// Decrement Coin Count by 10
93+
adjustCoinCount(CoinCountAddress, CoinCount, -10);
11394
}
114-
115-
if (CoinCountButtonHoldCounter > ButtonHoldFrames)
95+
CoinCountButtonHoldCounter++;
96+
}
97+
else if ((ButtonInput & CoinsDecrement100Combo) == CoinsDecrement100Combo)
98+
{
99+
if (CoinCountButtonHoldCounter == 0)
116100
{
117-
// Reset if counter exceeds ButtonHoldFrames
118-
CoinCountButtonHoldCounter = 0;
101+
// Decrement Coin Count by 100
102+
adjustCoinCount(CoinCountAddress, CoinCount, -100);
119103
}
104+
CoinCountButtonHoldCounter++;
105+
}
106+
else
107+
{
108+
// Reset counter if no button combo is pressed/held
109+
CoinCountButtonHoldCounter = 0;
110+
}
111+
112+
if (CoinCountButtonHoldCounter > ButtonHoldFrames)
113+
{
114+
// Reset if counter exceeds ButtonHoldFrames
115+
CoinCountButtonHoldCounter = 0;
120116
}
121117
}
122118
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ void Mod::buttonInputDisplay()
5151
ttyd::fontmgr::FontDrawEdge();
5252
ttyd::fontmgr::FontDrawMessage(DrawX, -140, mDisplayBuffer);
5353
}
54-
55-
DrawX += 20;
54+
DrawX += 20;
5655
}
5756
}
5857
}

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ void Mod::saveAnywhere()
2020
if ((ttyd::system::keyGetButton(0) & SaveAnywhereCombo) == (SaveAnywhereCombo))
2121
{
2222
uint32_t Game = static_cast<uint32_t>(ttyd::seqdrv::SeqIndex::kGame);
23-
if (ttyd::seqdrv::seqGetNextSeq() == Game)
23+
if ((ttyd::seqdrv::seqGetNextSeq() == Game) && (ttyd::mariost::marioStGetSystemLevel() != 15))
2424
{
25-
if (ttyd::mariost::marioStGetSystemLevel() != 15)
26-
{
27-
// Not in the Pause Menu
28-
#ifdef TTYD_US
29-
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803BAC3C);
30-
#elif defined TTYD_JP
31-
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803B68BC);
32-
#elif defined TTYD_EU
33-
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803C6C4C);
34-
#endif
35-
36-
// Take away control from the player and start the Save script
37-
ttyd::mario::marioKeyOff();
38-
ttyd::mariost::marioStSystemLevel(1);
39-
mSaveAnywhereThreadID = *reinterpret_cast<uint32_t *>(ttyd::evtmgr::evtEntryType(SaveScript, 0, 0, 0) + 0x15C);
40-
mSaveAnywhereScriptRunning = true;
41-
}
25+
// Not in the Pause Menu
26+
#ifdef TTYD_US
27+
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803BAC3C);
28+
#elif defined TTYD_JP
29+
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803B68BC);
30+
#elif defined TTYD_EU
31+
uint32_t *SaveScript = reinterpret_cast<uint32_t *>(0x803C6C4C);
32+
#endif
33+
34+
// Take away control from the player and start the Save script
35+
ttyd::mario::marioKeyOff();
36+
ttyd::mariost::marioStSystemLevel(1);
37+
mSaveAnywhereThreadID = *reinterpret_cast<uint32_t *>(ttyd::evtmgr::evtEntryType(SaveScript, 0, 0, 0) + 0x15C);
38+
mSaveAnywhereScriptRunning = true;
4239
}
4340
}
4441
}

0 commit comments

Comments
 (0)