Skip to content

Commit f039473

Browse files
committed
Fix bug with spawning items
Originally, if you were to spawn some items and then spawn a bunch more and letting them despawn, but keeping some items spawned, the counter would overflow and could end up using the same value as an item that is already spawned. This change should avoid that. Technically, this code will still cause that to happen if the counter falls below 256, but it is highly unlikely that the code will be used that many times.
1 parent 7f3a3bf commit f039473

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

ttyd-tools/rel/include/mod.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Mod
107107

108108
// Spawn Item
109109
void spawnItem();
110-
uint8_t spawnItemNameCounter;
110+
uint16_t spawnItemNameCounter = 0xFFFF;
111111
bool spawnItemDisable = false;
112112
void spawnItemPreventCrash();
113113

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ void Mod::spawnItem()
2929
if ((CoinCount >= 1) && (CoinCount <= 338))
3030
{
3131
// Coin count is a valid item ID
32-
char *ItemName = new char[8]; // 6 bytes for C_Item, 1 byte for spawnItemNameCounter, 1 byte for NULL
32+
char *ItemName = new char[9]; // 6 bytes for C_Item, 2 bytes for spawnItemNameCounter, 1 byte for NULL
3333
ttyd::string::strcpy(ItemName, "C_Item");
3434
ttyd::string::strcat(ItemName, reinterpret_cast<char *>(&spawnItemNameCounter));
35-
spawnItemNameCounter++;
35+
spawnItemNameCounter--;
3636

3737
ttyd::mario::Player *player = ttyd::mario::marioGetPtr();
3838
float ItemCoordinateX = player->playerPosition[0];
@@ -42,10 +42,12 @@ void Mod::spawnItem()
4242
// Move item 30 units in front of Mario
4343
if (player->wPlayerDirection <= 0)
4444
{
45+
// Mario is facing left
4546
ItemCoordinateX -= 30;
4647
}
4748
else
4849
{
50+
// Mario is facing right
4951
ItemCoordinateX += 30;
5052
}
5153

0 commit comments

Comments
 (0)