Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
make bot not crash editor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Jan 26, 2024
1 parent 5b76ce6 commit e871a6b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Macrobot/Macrobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ class $modify(CCKeyboardDispatcher){
};

class $modify(PlayLayer){

void onQuit()
{
PlayLayer::onQuit();
playerObject1 = nullptr;
playerObject2 = nullptr;
checkpoints.clear();
}

void loadFromCheckpoint(CheckpointObject * checkpoint)
{
if (checkpoints.contains(checkpoint) && playerMode != -1 && playerObject1)
if (checkpoints.contains(checkpoint) && playerMode != -1 && GameManager::get()->getPlayLayer())
{
CheckpointData checkpointData = checkpoints[checkpoint];
const auto check = [&](const Action &action) -> bool { return action.time >= checkpointData.time; };
Expand Down Expand Up @@ -102,7 +111,7 @@ class $modify(PlayerObject){
void pushButton(PlayerButton btn){
PlayerObject::pushButton(btn);

if (playerObject1 && playerMode == 1 && gameTime != 9999999999)
if (GameManager::get()->getPlayLayer() && playerMode == 1 && gameTime != 9999999999)
{
Action *ac = recordAction(btn, gameTime, true, this == playerObject1);

Expand All @@ -121,7 +130,7 @@ void releaseButton(PlayerButton btn)
{
PlayerObject::releaseButton(btn);

if (playerObject1 && playerMode == 1 && gameTime != 9999999999)
if (GameManager::get()->getPlayLayer() && playerMode == 1 && gameTime != 9999999999)
{
if (btn == PlayerButton::Right && direction == 1)
return;
Expand Down Expand Up @@ -159,7 +168,7 @@ class $modify(CheckpointObject)
{
auto self = CheckpointObject::create();

if (playerMode != -1 && gameTime > 0 && playerObject1)
if (playerMode != -1 && gameTime > 0 && GameManager::get()->getPlayLayer())
{
CheckpointData data;
data.time = gameTime;
Expand All @@ -175,7 +184,7 @@ class $modify(CheckpointObject)

void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self)
{
if (playerMode != -1 && playerObject1)
if (playerMode != -1 && GameManager::get()->getPlayLayer())
{
double currentTime = *((double *)GameManager::get()->getPlayLayer() + 1412);
gameTime = currentTime;
Expand Down

0 comments on commit e871a6b

Please sign in to comment.