Skip to content

Commit 121e106

Browse files
committed
Fixed the Speed Up Mario code
marioSetSpec resets Mario's hitbox, so it can't be used. Furthermore, the code now does not write to the values every frame when Mario is not being sped up.
1 parent dfd824c commit 121e106

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

ttyd-tools/rel/include/global.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ struct SaveAnywhereStruct
397397
bool ScriptIsRunning;
398398
};
399399

400+
struct SpeedUpMarioStruct
401+
{
402+
float MarioVar[2];
403+
uint8_t ValuesChangedState;
404+
};
405+
400406
struct ReloadRoomStruct
401407
{
402408
bool SystemLevelShouldBeLowered;
@@ -466,6 +472,7 @@ extern AutoIncrement AdjustableValueMenu;
466472
extern CheatsHandleDisplayButtons CheatsDisplayButtons;
467473
extern MarioPartnerPositionsStruct MarioPartnerPositions;
468474
extern SaveAnywhereStruct SaveAnywhere;
475+
extern SpeedUpMarioStruct SpeedUpMario;
469476
extern ReloadRoomStruct ReloadRoom;
470477
extern SpawnItems SpawnItem;
471478
extern ClearAreaFlagsStruct ClearAreaFlags;

ttyd-tools/rel/source/codes.cpp

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,45 +281,60 @@ void setTimeStopTextStorage()
281281
void speedUpMario()
282282
{
283283
ttyd::mario::Player *player = ttyd::mario::marioGetPtr();
284-
const uint16_t TubeMode = 22;
284+
float SpeedValueToSet = 16;
285+
286+
float current_unk_184 = SpeedUpMario.MarioVar[0];
287+
float current_unk_188 = SpeedUpMario.MarioVar[1];
288+
float new_unk_184 = player->unk_184;
289+
float new_unk_188 = player->unk_188;
290+
291+
const uint8_t NoChanges = 0;
292+
const uint8_t ValuesModified = 1;
293+
const uint8_t ValuesShouldBeRestored = 2;
285294

286295
if (!Cheat[SPEED_UP_MARIO].Active || ChangingCheatButtonCombo)
287296
{
288-
// Check to see if Mario is currently in Tube Mode or not
289-
if (player->currentMotionId == TubeMode)
297+
// Check if the values should be restored
298+
if (SpeedUpMario.ValuesChangedState > NoChanges)
290299
{
291-
// marioSetSpec does not set the values for Tube Mode
292-
player->unk_184 = 1;
293-
player->unk_188 = 3;
300+
SpeedUpMario.ValuesChangedState = 0;
301+
player->unk_184 = current_unk_184;
302+
player->unk_188 = current_unk_188;
294303
}
295-
else
304+
return;
305+
}
306+
307+
// Check to see if the current values have changed
308+
if (((current_unk_184 != new_unk_184)) ||
309+
(current_unk_188 != new_unk_188))
310+
{
311+
// Don't update if the new value is what was just set by this function
312+
if (new_unk_188 != SpeedValueToSet)
296313
{
297-
// Set the values to their default for the current character
298-
ttyd::mario::marioSetSpec();
314+
// Set the current values to the new values
315+
SpeedUpMario.MarioVar[0] = new_unk_184;
316+
SpeedUpMario.MarioVar[1] = new_unk_188;
299317
}
300-
return;
301318
}
302319

303320
if (checkButtonComboEveryFrame(Cheat[SPEED_UP_MARIO].ButtonCombo))
304321
{
305-
player->wPlayerBaseSpeed = 16;
306-
player->unk_184 = 16;
307-
player->unk_188 = 16;
322+
SpeedUpMario.ValuesChangedState = ValuesModified;
323+
player->wPlayerBaseSpeed = SpeedValueToSet;
324+
player->unk_184 = SpeedValueToSet;
325+
player->unk_188 = SpeedValueToSet;
308326
}
309-
else
327+
else if (SpeedUpMario.ValuesChangedState == ValuesModified)
310328
{
311-
// Check to see if Mario is currently in Tube Mode or not
312-
if (player->currentMotionId == TubeMode)
313-
{
314-
// marioSetSpec does not set the values for Tube Mode
315-
player->unk_184 = 1;
316-
player->unk_188 = 3;
317-
}
318-
else
319-
{
320-
// Set the values to their default for the current character
321-
ttyd::mario::marioSetSpec();
322-
}
329+
SpeedUpMario.ValuesChangedState = ValuesShouldBeRestored;
330+
}
331+
332+
// Check if the values should be restored
333+
if (SpeedUpMario.ValuesChangedState == ValuesShouldBeRestored)
334+
{
335+
SpeedUpMario.ValuesChangedState = 0;
336+
player->unk_184 = SpeedUpMario.MarioVar[0];
337+
player->unk_188 = SpeedUpMario.MarioVar[1];
323338
}
324339
}
325340

ttyd-tools/rel/source/global.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ struct AutoIncrement AdjustableValueMenu;
776776
struct CheatsHandleDisplayButtons CheatsDisplayButtons;
777777
struct MarioPartnerPositionsStruct MarioPartnerPositions;
778778
struct SaveAnywhereStruct SaveAnywhere;
779+
struct SpeedUpMarioStruct SpeedUpMario;
779780
struct ReloadRoomStruct ReloadRoom;
780781
struct SpawnItems SpawnItem;
781782
struct ClearAreaFlagsStruct ClearAreaFlags;

0 commit comments

Comments
 (0)