Skip to content

Commit 2319657

Browse files
committed
Check for valid button combos for cheats/displays
For the cheats/displays that use button combos, check to see if a button combo is set, and set the default if there isn't one set.
1 parent d497d16 commit 2319657

File tree

3 files changed

+133
-18
lines changed

3 files changed

+133
-18
lines changed

ttyd-tools/rel/include/global.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ extern bool MarioFreeze;
598598
extern uint16_t JumpStorageSetCounter;
599599

600600
void initMenuVars();
601+
void assignCheatButtonCombo(uint32_t cheat);
602+
void assignDisplayButtonCombo(uint32_t display);
601603
void initArtAttackAssemblyOverwrites();
602604
void initAssemblyOverwrites();
603605

ttyd-tools/rel/source/global.cpp

Lines changed: 130 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,24 +1061,137 @@ void initMenuVars()
10611061
// Cheat[BOBBERY_EARLY].Active = false;
10621062
Cheat[FORCE_ITEM_DROP].Active = false;
10631063

1064-
Cheat[WALK_THROUGH_WALLS].ButtonCombo = PAD_Z;
1065-
Cheat[SAVE_COORDINATES].ButtonCombo = PAD_L | PAD_DPAD_LEFT;
1066-
Cheat[LOAD_COORDINATES].ButtonCombo = PAD_L | PAD_DPAD_UP;
1067-
Cheat[SAVE_ANYWHERE].ButtonCombo = PAD_Y | PAD_B;
1068-
Cheat[TEXT_STORAGE].ButtonCombo = PAD_L | PAD_X;
1069-
Cheat[TIME_STOP_TEXT_STORAGE].ButtonCombo = PAD_L | PAD_R;
1070-
Cheat[SPEED_UP_MARIO].ButtonCombo = PAD_L | PAD_Y;
1071-
Cheat[DISABLE_BATTLES].ButtonCombo = PAD_Y;
1072-
Cheat[AUTO_ACTION_COMMANDS].ButtonCombo = PAD_R;
1073-
Cheat[INFINITE_ITEM_USAGE].ButtonCombo = PAD_Y;
1074-
Cheat[RELOAD_ROOM].ButtonCombo = PAD_L | PAD_B;
1075-
Cheat[LEVITATE].ButtonCombo = PAD_L | PAD_A;
1076-
Cheat[SPAWN_ITEM].ButtonCombo = PAD_L | PAD_DPAD_DOWN;
1077-
10781064
Displays[GUARD_SUPERGUARD_TIMINGS] = true;
1079-
1080-
OnScreenTimer.ButtonCombo[START_PAUSE_RESUME] = PAD_L | PAD_Z;
1081-
OnScreenTimer.ButtonCombo[RESET] = PAD_L | PAD_DPAD_RIGHT;
1065+
}
1066+
1067+
// Assign the cheats a button combo if they don't already have one
1068+
uint32_t Size = sizeof(Cheat) / sizeof(Cheat[0]);
1069+
for (uint32_t i = 0; i < Size; i++)
1070+
{
1071+
// Don't assign if the cheat already has a button combo
1072+
if (!Cheat[i].ButtonCombo)
1073+
{
1074+
assignCheatButtonCombo(i);
1075+
}
1076+
}
1077+
1078+
// Assign the displays a button combo if they don't already have one
1079+
Size = sizeof(Displays);
1080+
for (uint32_t i = 0; i < Size; i++)
1081+
{
1082+
// Don't assign if the display already has a button combo
1083+
if (i == ONSCREEN_TIMER)
1084+
{
1085+
if (!OnScreenTimer.ButtonCombo[START_PAUSE_RESUME] ||
1086+
!OnScreenTimer.ButtonCombo[RESET])
1087+
{
1088+
assignDisplayButtonCombo(i);
1089+
}
1090+
}
1091+
else
1092+
{
1093+
// Extra checks will be added when more displays that use button combos are added
1094+
}
1095+
}
1096+
}
1097+
1098+
void assignCheatButtonCombo(uint32_t cheat)
1099+
{
1100+
switch (cheat)
1101+
{
1102+
case WALK_THROUGH_WALLS:
1103+
{
1104+
Cheat[cheat].ButtonCombo = PAD_Z;
1105+
break;
1106+
}
1107+
case SAVE_COORDINATES:
1108+
{
1109+
Cheat[cheat].ButtonCombo = PAD_L | PAD_DPAD_LEFT;
1110+
break;
1111+
}
1112+
case LOAD_COORDINATES:
1113+
{
1114+
Cheat[cheat].ButtonCombo = PAD_L | PAD_DPAD_UP;
1115+
break;
1116+
}
1117+
case SAVE_ANYWHERE:
1118+
{
1119+
Cheat[cheat].ButtonCombo = PAD_Y | PAD_B;
1120+
break;
1121+
}
1122+
case TEXT_STORAGE:
1123+
{
1124+
Cheat[cheat].ButtonCombo = PAD_L | PAD_X;
1125+
break;
1126+
}
1127+
case TIME_STOP_TEXT_STORAGE:
1128+
{
1129+
Cheat[cheat].ButtonCombo = PAD_L | PAD_R;
1130+
break;
1131+
}
1132+
case SPEED_UP_MARIO:
1133+
{
1134+
Cheat[cheat].ButtonCombo = PAD_L | PAD_Y;
1135+
break;
1136+
}
1137+
case DISABLE_BATTLES:
1138+
{
1139+
Cheat[cheat].ButtonCombo = PAD_Y;
1140+
break;
1141+
}
1142+
case AUTO_ACTION_COMMANDS:
1143+
{
1144+
Cheat[cheat].ButtonCombo = PAD_R;
1145+
break;
1146+
}
1147+
case INFINITE_ITEM_USAGE:
1148+
{
1149+
Cheat[cheat].ButtonCombo = PAD_Y;
1150+
break;
1151+
}
1152+
case RELOAD_ROOM:
1153+
{
1154+
Cheat[cheat].ButtonCombo = PAD_L | PAD_B;
1155+
break;
1156+
}
1157+
case LEVITATE:
1158+
{
1159+
Cheat[cheat].ButtonCombo = PAD_L | PAD_A;
1160+
break;
1161+
}
1162+
case SPAWN_ITEM:
1163+
{
1164+
Cheat[cheat].ButtonCombo = PAD_L | PAD_DPAD_DOWN;
1165+
break;
1166+
}
1167+
default:
1168+
{
1169+
return;
1170+
}
1171+
}
1172+
}
1173+
1174+
void assignDisplayButtonCombo(uint32_t display)
1175+
{
1176+
switch (display)
1177+
{
1178+
case ONSCREEN_TIMER:
1179+
{
1180+
if (!OnScreenTimer.ButtonCombo[START_PAUSE_RESUME])
1181+
{
1182+
OnScreenTimer.ButtonCombo[START_PAUSE_RESUME] = PAD_L | PAD_Z;
1183+
}
1184+
1185+
if (!OnScreenTimer.ButtonCombo[RESET])
1186+
{
1187+
OnScreenTimer.ButtonCombo[RESET] = PAD_L | PAD_DPAD_RIGHT;
1188+
}
1189+
break;
1190+
}
1191+
default:
1192+
{
1193+
return;
1194+
}
10821195
}
10831196
}
10841197

ttyd-tools/rel/source/memcard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int32_t writeSettings(char *description, char *fileName,
210210
// Make sure the size being written does not exceed the current size
211211
if (FileSizeAdjusted > StoredFileSizeAdjusted)
212212
{
213-
// The new size exceeds the current size, so a new file must be made created
213+
// The new size exceeds the current size, so a new file must be created
214214
// Close the file
215215
ReturnCode = gc::card::CARDClose(fileInfo);
216216
if (ReturnCode != CARD_ERROR_READY)

0 commit comments

Comments
 (0)