Skip to content

Commit dd67a7a

Browse files
committed
Custom States - Add option to overwrite states
1 parent aaa2e03 commit dd67a7a

File tree

6 files changed

+93
-65
lines changed

6 files changed

+93
-65
lines changed

ttyd-tools/rel/include/global.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,17 @@ enum CHEATS_MANAGE_CUSTOM_STATES_SELECTION
245245
LOAD_CUSTOM_STATE = 1,
246246
CREATE_CUSTOM_STATE,
247247
DELETE_CUSTOM_STATE,
248+
OVERWRITE_CUSTOM_STATE,
248249
RENAME_CUSTOM_STATE,
249250
};
250251

251252
enum CHEATS_MANAGE_CUSTOM_STATES_RETURN_VALUES
252253
{
253-
NO_STATES_EXIST = -4,
254+
NO_STATES_EXIST = -5,
254255
MAX_STATES_EXIST,
255256
STATES_CREATE_NOT_IN_GAME,
256257
STATES_WARP_NOT_IN_GAME,
258+
SUCCESSFULLY_OVERWROTE_STATE,
257259
};
258260

259261
// Various menu values

ttyd-tools/rel/include/menufunctions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int32_t convertDoubleToString(char *strOut, int32_t totalLength, int32_t decimal
116116
float *getMarioCoordinateFromIndex(int32_t index);
117117

118118
CustomStateStruct *resizeStateMemory(CustomStateStruct *state, uint32_t numEntries, int32_t incrementAmount);
119+
void setCustomStateData(CustomStateStruct *state);
119120
char *createCustomState();
120121
uint32_t deleteCustomState(uint32_t stateIndex);
121122

ttyd-tools/rel/source/draw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,7 @@ void drawCheatsManageCustomStates()
45694569
static_cast<int32_t>(TotalEntries),
45704570
CUSTOM_STATES_MAX_COUNT);
45714571

4572-
drawText(tempDisplayBuffer, -232, PosY - 100, Color, Scale);
4572+
drawText(tempDisplayBuffer, -232, PosY - 120, Color, Scale);
45734573

45744574
// If no custom states currently exist, then exit
45754575
if (TotalEntries == 0)

ttyd-tools/rel/source/global.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ const char *CheatsManageCustomStatesOptions[]
11311131
"Load State",
11321132
"Create State",
11331133
"Delete State",
1134+
"Overwrite State",
11341135
"Rename State",
11351136
};
11361137

ttyd-tools/rel/source/menu.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ void menuCheckButton()
15661566
}
15671567
case LOAD_CUSTOM_STATE:
15681568
case DELETE_CUSTOM_STATE:
1569+
case OVERWRITE_CUSTOM_STATE:
15691570
case RENAME_CUSTOM_STATE:
15701571
{
15711572
adjustCustomStatesSelection(CurrentButton);
@@ -1601,10 +1602,11 @@ void menuCheckButton()
16011602
break;
16021603
}
16031604

1604-
// Use the delete and rename code if didn't break
1605+
// Use the delete, overwrite, and rename code if didn't break
16051606
[[fallthrough]];
16061607
}
16071608
case DELETE_CUSTOM_STATE:
1609+
case OVERWRITE_CUSTOM_STATE:
16081610
case RENAME_CUSTOM_STATE:
16091611
{
16101612
if (tempTotalEntries > 0)
@@ -1694,6 +1696,15 @@ void menuCheckButton()
16941696
}
16951697
break;
16961698
}
1699+
case OVERWRITE_CUSTOM_STATE:
1700+
{
1701+
setCustomStateData(&CustomState.State[tempCurrentMenuOption]);
1702+
closeSecondaryMenu();
1703+
1704+
MenuVar.FunctionReturnCode = SUCCESSFULLY_OVERWROTE_STATE;
1705+
MenuVar.Timer = secondsToFrames(3);
1706+
break;
1707+
}
16971708
case RENAME_CUSTOM_STATE:
16981709
{
16991710
if (tempMenuSelectedOption == 0)
@@ -4430,9 +4441,8 @@ void drawMenu()
44304441
case NO_STATES_EXIST:
44314442
{
44324443
const char *CurrentLine = "No custom states currently exist.";
4433-
44344444
int32_t TextPosX = -138;
4435-
int32_t TextPosY = 20;
4445+
int32_t TextPosY = 5;
44364446
#ifdef TTYD_JP
44374447
TextPosX += 2;
44384448
#endif
@@ -4443,7 +4453,7 @@ void drawMenu()
44434453
{
44444454
const char *CurrentLine = "The maximum amount of custom\nstates currently exist.";
44454455
int32_t TextPosX = -129;
4446-
int32_t TextPosY = 20;
4456+
int32_t TextPosY = 5;
44474457
#ifdef TTYD_JP
44484458
TextPosX += 2;
44494459
#endif
@@ -4455,7 +4465,7 @@ void drawMenu()
44554465
const char *CurrentLine = "To create a custom state, you must have\na file loaded and not be in a battle nor a\nscreen transition.";
44564466

44574467
int32_t TextPosX = -173;
4458-
int32_t TextPosY = 20;
4468+
int32_t TextPosY = 5;
44594469
#ifdef TTYD_JP
44604470
TextPosX += 3;
44614471
#endif
@@ -4464,10 +4474,21 @@ void drawMenu()
44644474
}
44654475
case STATES_WARP_NOT_IN_GAME:
44664476
{
4467-
int32_t TextPosY = 20;
4477+
int32_t TextPosY = 5;
44684478
drawWarpsErrorMessage(TextPosY);
44694479
break;
44704480
}
4481+
case SUCCESSFULLY_OVERWROTE_STATE:
4482+
{
4483+
const char *CurrentLine = "The custom state was successfully overwritten.";
4484+
int32_t TextPosX = -197;
4485+
int32_t TextPosY = 5;
4486+
#ifdef TTYD_JP
4487+
TextPosX += 1;
4488+
#endif
4489+
drawErrorWindowAutoCheckForClose(CurrentLine, TextPosX, TextPosY);
4490+
break;
4491+
}
44714492
default:
44724493
{
44734494
break;

ttyd-tools/rel/source/menufunctions.cpp

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5380,77 +5380,43 @@ CustomStateStruct *resizeStateMemory(CustomStateStruct *state, uint32_t numEntri
53805380
return state;
53815381
}
53825382

5383-
char *createCustomState()
5383+
void setCustomStateData(CustomStateStruct *state)
53845384
{
5385-
uint32_t tempTotalEntries = CustomState.TotalEntries;
5386-
CustomStateStruct *tempState = CustomState.State;
5387-
5388-
if (tempTotalEntries == 0)
5389-
{
5390-
// No custom states exist, so create one
5391-
if (tempState)
5392-
{
5393-
delete[] (tempState);
5394-
}
5395-
5396-
tempState = new CustomStateStruct;
5397-
CustomState.State = tempState;
5398-
5399-
tempTotalEntries = 1;
5400-
CustomState.TotalEntries = tempTotalEntries;
5401-
}
5402-
else if (tempTotalEntries >= CUSTOM_STATES_MAX_COUNT)
5403-
{
5404-
// Maximum number of states have been made
5405-
return nullptr;
5406-
}
5407-
else
5408-
{
5409-
tempState = resizeStateMemory(tempState, tempTotalEntries, 1);
5410-
CustomState.State = tempState;
5411-
5412-
tempTotalEntries++;
5413-
CustomState.TotalEntries = tempTotalEntries;
5414-
}
5415-
5416-
// Set the info for the new state
5417-
tempState = &tempState[tempTotalEntries - 1];
5418-
54195385
// Back up the inventory
54205386
uint32_t PouchPtr = reinterpret_cast<uint32_t>(ttyd::mario_pouch::pouchGetPtr());
54215387

54225388
// Standard items
54235389
memcpy(
5424-
tempState->StandardItems,
5390+
state->StandardItems,
54255391
reinterpret_cast<void *>(PouchPtr + 0x192),
5426-
sizeof(tempState->StandardItems));
5392+
sizeof(state->StandardItems));
54275393

54285394
// Important items
54295395
memcpy(
5430-
tempState->ImportantItems,
5396+
state->ImportantItems,
54315397
reinterpret_cast<void *>(PouchPtr + 0xA0),
5432-
sizeof(tempState->ImportantItems));
5398+
sizeof(state->ImportantItems));
54335399

54345400
// Badges
54355401
memcpy(
5436-
tempState->Badges,
5402+
state->Badges,
54375403
reinterpret_cast<void *>(PouchPtr + 0x1FA),
5438-
sizeof(tempState->Badges));
5404+
sizeof(state->Badges));
54395405

54405406
// Equipped badges
54415407
memcpy(
5442-
tempState->EquippedBadges,
5408+
state->EquippedBadges,
54435409
reinterpret_cast<void *>(PouchPtr + 0x38A),
5444-
sizeof(tempState->EquippedBadges));
5410+
sizeof(state->EquippedBadges));
54455411

54465412
// Stored items
54475413
memcpy(
5448-
tempState->StoredItems,
5414+
state->StoredItems,
54495415
reinterpret_cast<void *>(PouchPtr + 0x1BA),
5450-
sizeof(tempState->StoredItems));
5416+
sizeof(state->StoredItems));
54515417

54525418
// Back up some of Mario's data
5453-
CustomStateMarioVars *MarioVars = &tempState->MarioVars;
5419+
CustomStateMarioVars *MarioVars = &state->MarioVars;
54545420
MarioVars->currentHP = *reinterpret_cast<int16_t *>(PouchPtr + 0x70);
54555421
MarioVars->maxHP = *reinterpret_cast<int16_t *>(PouchPtr + 0x72);
54565422
MarioVars->currentFP = *reinterpret_cast<int16_t *>(PouchPtr + 0x74);
@@ -5469,49 +5435,86 @@ char *createCustomState()
54695435

54705436
// Back up the partner data
54715437
memcpy(
5472-
tempState->PartyData,
5438+
state->PartyData,
54735439
reinterpret_cast<void *>(PouchPtr + sizeof(ttyd::mario_pouch::PouchPartyData)),
5474-
sizeof(tempState->PartyData));
5440+
sizeof(state->PartyData));
54755441

54765442
// Back up the sequence position
5477-
tempState->SequencePosition = getSequencePosition();
5443+
state->SequencePosition = getSequencePosition();
54785444

54795445
// Back up which partner is currently out
54805446
ttyd::mario::Player *player = ttyd::mario::marioGetPtr();
54815447
uint32_t PartnerPtr = reinterpret_cast<uint32_t>(getPartnerPointer());
54825448
if (PartnerPtr)
54835449
{
5484-
tempState->PartnerOut = player->prevFollowerId[0];
5450+
state->PartnerOut = player->prevFollowerId[0];
54855451
}
54865452

54875453
// Back up which follower is currently out
54885454
uint32_t FollowerPtr = reinterpret_cast<uint32_t>(getFollowerPointer());
54895455
if (FollowerPtr)
54905456
{
5491-
tempState->FollowerOut = player->prevFollowerId[1];
5457+
state->FollowerOut = player->prevFollowerId[1];
54925458
}
54935459

54945460
// Back up if Mario is currently using Boat Mode or not
54955461
if (player->currentMotionId == ttyd::mario_motion::MarioMotions::kShip)
54965462
{
5497-
tempState->MarioIsShip = true;
5463+
state->MarioIsShip = true;
54985464
}
54995465
else
55005466
{
5501-
tempState->MarioIsShip = false;
5467+
state->MarioIsShip = false;
55025468
}
55035469

55045470
// Back up the current map
55055471
strncpy(
5506-
tempState->CurrentMap,
5472+
state->CurrentMap,
55075473
ttyd::seq_mapchange::NextMap,
5508-
sizeof(tempState->CurrentMap));
5474+
sizeof(state->CurrentMap));
55095475

55105476
// Back up the current loading zone
55115477
strncpy(
5512-
tempState->CurrentBero,
5478+
state->CurrentBero,
55135479
ttyd::seq_mapchange::NextBero,
5514-
sizeof(tempState->CurrentBero));
5480+
sizeof(state->CurrentBero));
5481+
}
5482+
5483+
char *createCustomState()
5484+
{
5485+
uint32_t tempTotalEntries = CustomState.TotalEntries;
5486+
CustomStateStruct *tempState = CustomState.State;
5487+
5488+
if (tempTotalEntries == 0)
5489+
{
5490+
// No custom states exist, so create one
5491+
if (tempState)
5492+
{
5493+
delete[] (tempState);
5494+
}
5495+
5496+
tempState = new CustomStateStruct;
5497+
CustomState.State = tempState;
5498+
5499+
tempTotalEntries = 1;
5500+
CustomState.TotalEntries = tempTotalEntries;
5501+
}
5502+
else if (tempTotalEntries >= CUSTOM_STATES_MAX_COUNT)
5503+
{
5504+
// Maximum number of states have been made
5505+
return nullptr;
5506+
}
5507+
else
5508+
{
5509+
tempState = resizeStateMemory(tempState, tempTotalEntries, 1);
5510+
CustomState.State = tempState;
5511+
5512+
tempTotalEntries++;
5513+
CustomState.TotalEntries = tempTotalEntries;
5514+
}
5515+
5516+
tempState = &tempState[tempTotalEntries - 1];
5517+
setCustomStateData(tempState);
55155518

55165519
// Return a pointer to the new state's name
55175520
return tempState->StateName;

0 commit comments

Comments
 (0)