Skip to content

Commit 51e5742

Browse files
committed
Added an option to keep the player's standard items when warping by event
1 parent 9dd68cd commit 51e5742

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

ttyd-tools/rel/include/global.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ enum WARPS_IN_ADJUSTABLE_VALUE_MENU_OPTIONS
406406
enum WARPS_EVENT_OPTIONS
407407
{
408408
EVENT_SELECT_EVENT = 1,
409+
EVENT_KEEP_INVENTORY,
409410
EVENT_WARP_NOW,
410411
};
411412

@@ -690,7 +691,13 @@ struct SaveFileDecriptionInfo
690691
struct WarpByEventStruct
691692
{
692693
int32_t CurrentIndex;
694+
bool ShouldKeepInventory;
693695
bool ShouldInit;
696+
697+
WarpByEventStruct()
698+
{
699+
ShouldKeepInventory = true;
700+
}
694701
};
695702

696703
struct WarpByEventDetailsStruct

ttyd-tools/rel/source/draw.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3406,7 +3406,29 @@ void drawWarpByEventMenuDetails()
34063406

34073407
const char *ExplainText = "Note: Warping via this menu will clear all game states.";
34083408
drawText(ExplainText, PosX, PosY, Alpha, Color, Scale);
3409-
PosY -= 100;
3409+
PosY -= 60;
3410+
3411+
// Draw the text for whether the standard inventory is being kept or not
3412+
const char *String;
3413+
if (WarpByEvent.ShouldKeepInventory)
3414+
{
3415+
Color = 0x1BBE23FF;
3416+
String = "Yes";
3417+
}
3418+
else
3419+
{
3420+
Color = 0xFF1414FF;
3421+
String = "No";
3422+
}
3423+
3424+
int32_t tempPosX = PosX + 222;
3425+
3426+
#ifdef TTYD_JP
3427+
tempPosX -= 10;
3428+
#endif
3429+
3430+
drawText(String, tempPosX, PosY, Alpha, Color, Scale);
3431+
PosY -= 60;
34103432

34113433
// Draw the details for the current event
34123434
drawEventDetails(PosX, PosY, WarpByEvent.CurrentIndex);

ttyd-tools/rel/source/global.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ const char *WarpDescriptions[] =
15891589
const char *WarpEventLines[] =
15901590
{
15911591
"Select Event",
1592+
"Keep Standard Inventory",
15921593
"Warp",
15931594
};
15941595

ttyd-tools/rel/source/menu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,6 +2739,13 @@ void menuCheckButton()
27392739
MenuVar.Timer = 0;
27402740
break;
27412741
}
2742+
case EVENT_KEEP_INVENTORY:
2743+
{
2744+
// Flip the bool
2745+
bool ShouldKeepInventory = WarpByEvent.ShouldKeepInventory;
2746+
WarpByEvent.ShouldKeepInventory = !ShouldKeepInventory;
2747+
break;
2748+
}
27422749
case EVENT_WARP_NOW:
27432750
{
27442751
int32_t ReturnCode = warpToMapByEvent(WarpByEvent.CurrentIndex);

ttyd-tools/rel/source/menufunctions.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,8 @@ void *initStageEvents()
34333433
WarpByEvent.ShouldInit = false;
34343434
int32_t StageAndEventIds[2];
34353435

3436-
if (!indexToStageAndEvent(WarpByEvent.CurrentIndex, StageAndEventIds))
3436+
int32_t CurrentIndex = WarpByEvent.CurrentIndex;
3437+
if (!indexToStageAndEvent(CurrentIndex, StageAndEventIds))
34373438
{
34383439
// The overwritten instruction sets r3 to the global work pointer, so return the global work pointer
34393440
return ttyd::mariost::globalWorkPointer;
@@ -3448,6 +3449,19 @@ void *initStageEvents()
34483449
return ttyd::mariost::globalWorkPointer;
34493450
}
34503451

3452+
// Back up the standard inventory if desired
3453+
int16_t StandardInventory[20];
3454+
void *StandardInventoryStartPtr = nullptr;
3455+
3456+
bool ShouldKeepInventory = WarpByEvent.ShouldKeepInventory;
3457+
if (ShouldKeepInventory)
3458+
{
3459+
StandardInventoryStartPtr = reinterpret_cast<void *>(
3460+
reinterpret_cast<uint32_t>(ttyd::mario_pouch::pouchGetPtr()) + 0x192);
3461+
3462+
memcpy(StandardInventory, StandardInventoryStartPtr, sizeof(StandardInventory));
3463+
}
3464+
34513465
// Clear all current states
34523466
ttyd::swdrv::swInit();
34533467

@@ -3467,6 +3481,21 @@ void *initStageEvents()
34673481
}
34683482
}
34693483

3484+
// Restore the standard inventory if desired
3485+
if (ShouldKeepInventory)
3486+
{
3487+
memcpy(StandardInventoryStartPtr, StandardInventory, sizeof(StandardInventory));
3488+
3489+
/* If the player warped to the event with the index of 278, then they should be
3490+
given a Coconut, as it is used to get the Chuckola Cola from Flavio*/
3491+
3492+
if (CurrentIndex == 278)
3493+
{
3494+
// Only add the item if the player has a free inventory slot for it
3495+
ttyd::mario_pouch::pouchGetItem(ttyd::item_data::Item::Coconut);
3496+
}
3497+
}
3498+
34703499
// Set the Sequence to the value for the current event
34713500
setSequencePosition(getGsw0ForEvent(StageId, EventId));
34723501

0 commit comments

Comments
 (0)