1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2025-01-24 09:49:46 +01:00

Guard all cases obj.getcompanion() is used unchecked

And this the function with the least amount of cases where its sentinel
value is used unchecked. Thankfully. obj.getplayer() was a bit of a slug
to get through.
This commit is contained in:
Misa 2020-06-12 20:43:19 -07:00 committed by Ethan Lee
parent beab344267
commit fdce412680
2 changed files with 66 additions and 27 deletions

View file

@ -1533,8 +1533,11 @@ void Game::updatestate()
companion = 6; companion = 6;
i = obj.getcompanion(); i = obj.getcompanion();
obj.entities[i].tile = 0; if (i > -1)
obj.entities[i].state = 1; {
obj.entities[i].tile = 0;
obj.entities[i].state = 1;
}
advancetext = true; advancetext = true;
hascontrol = false; hascontrol = false;
@ -1559,8 +1562,11 @@ void Game::updatestate()
music.playef(2); music.playef(2);
graphics.textboxactive(); graphics.textboxactive();
i = obj.getcompanion(); i = obj.getcompanion();
obj.entities[i].tile = 54; if (i > -1)
obj.entities[i].state = 0; {
obj.entities[i].tile = 54;
obj.entities[i].state = 0;
}
} }
break; break;
case 108: case 108:
@ -1574,8 +1580,11 @@ void Game::updatestate()
{ {
i = obj.getcompanion(); i = obj.getcompanion();
obj.entities[i].tile = 0; if (i > -1)
obj.entities[i].state = 1; {
obj.entities[i].tile = 0;
obj.entities[i].state = 1;
}
graphics.createtextbox("Follow me!", 185, 154, 164, 164, 255); graphics.createtextbox("Follow me!", 185, 154, 164, 164, 255);
state++; state++;
music.playef(11); music.playef(11);
@ -1649,8 +1658,11 @@ void Game::updatestate()
case 122: case 122:
companion = 7; companion = 7;
i = obj.getcompanion(); i = obj.getcompanion();
obj.entities[i].tile = 6; if (i > -1)
obj.entities[i].state = 1; {
obj.entities[i].tile = 6;
obj.entities[i].state = 1;
}
advancetext = true; advancetext = true;
hascontrol = false; hascontrol = false;
@ -1665,7 +1677,7 @@ void Game::updatestate()
state++; state++;
music.playef(2); music.playef(2);
graphics.textboxactive(); graphics.textboxactive();
i = obj.getcompanion(); //obj.entities[i].tile = 66; obj.entities[i].state = 0; i = obj.getcompanion(); if (i > -1) { /*obj.entities[i].tile = 66; obj.entities[i].state = 0;*/ }
break; break;
case 126: case 126:
graphics.createtextbox("I can help with that!", 125, 152-40, 164, 164, 255); graphics.createtextbox("I can help with that!", 125, 152-40, 164, 164, 255);
@ -1687,8 +1699,11 @@ void Game::updatestate()
music.playef(14); music.playef(14);
graphics.textboxactive(); graphics.textboxactive();
i = obj.getcompanion(); i = obj.getcompanion();
obj.entities[i].tile = 6; if (i > -1)
obj.entities[i].state = 1; {
obj.entities[i].tile = 6;
obj.entities[i].state = 1;
}
break; break;
case 132: case 132:
graphics.textboxremove(); graphics.textboxremove();

View file

@ -1226,8 +1226,11 @@ void gamelogic()
case 6: case 6:
obj.createentity(obj.entities[i].xp, 121.0f, 15.0f,1); //Y=121, the floor in that particular place! obj.createentity(obj.entities[i].xp, 121.0f, 15.0f,1); //Y=121, the floor in that particular place!
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
break; break;
case 7: case 7:
if (game.roomy <= 105) //don't jump after him! if (game.roomy <= 105) //don't jump after him!
@ -1241,8 +1244,11 @@ void gamelogic()
obj.createentity(obj.entities[i].xp, 86.0f, 16.0f, 1); //Y=86, the ROOF in that particular place! obj.createentity(obj.entities[i].xp, 86.0f, 16.0f, 1); //Y=86, the ROOF in that particular place!
} }
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
break; break;
case 8: case 8:
@ -1252,15 +1258,21 @@ void gamelogic()
{ {
obj.createentity(310, 177, 17, 1); obj.createentity(310, 177, 17, 1);
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
else else
{ {
obj.createentity(obj.entities[i].xp, 177.0f, 17.0f, 1); obj.createentity(obj.entities[i].xp, 177.0f, 17.0f, 1);
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
} }
break; break;
@ -1276,8 +1288,11 @@ void gamelogic()
obj.createentity(obj.entities[i].xp, 185.0f, 18.0f, 15, 0, 1); obj.createentity(obj.entities[i].xp, 185.0f, 18.0f, 15, 0, 1);
} }
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
break; break;
case 10: case 10:
@ -1288,8 +1303,11 @@ void gamelogic()
{ {
obj.createentity(225.0f, 169.0f, 18, graphics.crewcolour(game.lastsaved), 0, 10); obj.createentity(225.0f, 169.0f, 18, graphics.crewcolour(game.lastsaved), 0, 10);
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
} }
else if (game.roomy >= 52) else if (game.roomy >= 52)
@ -1298,16 +1316,22 @@ void gamelogic()
{ {
obj.createentity(160.0f, 177.0f, 18, graphics.crewcolour(game.lastsaved), 0, 18, 1); obj.createentity(160.0f, 177.0f, 18, graphics.crewcolour(game.lastsaved), 0, 18, 1);
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
else else
{ {
obj.flags[59] = true; obj.flags[59] = true;
obj.createentity(obj.entities[i].xp, -20.0f, 18.0f, graphics.crewcolour(game.lastsaved), 0, 10, 0); obj.createentity(obj.entities[i].xp, -20.0f, 18.0f, graphics.crewcolour(game.lastsaved), 0, 10, 0);
j = obj.getcompanion(); j = obj.getcompanion();
obj.entities[j].vx = obj.entities[i].vx; if (j > -1)
obj.entities[j].dir = obj.entities[i].dir; {
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
}
} }
} }
break; break;