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

Commit

Permalink
somehow fix checkpoints i want to kms
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Feb 12, 2024
1 parent 64bfbe8 commit 110da62
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 73 deletions.
2 changes: 1 addition & 1 deletion cmake/gdr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
gdr
GIT_REPOSITORY https://github.com/maxnut/GDReplayFormat.git
GIT_TAG abb26e1f820883b0fa59d84674047ecd3404d124
GIT_TAG 0b803b44a3769a9c450c113ef1aa028f2c960127
GIT_PROGRESS TRUE
)
message("Fetching gdr")
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"gd": {
"win": "2.204"
},
"version": "v2.4.9",
"version": "v2.5.0",
"id": "maxnu.gd_mega_overlay",
"name": "GD Mega Overlay",
"developer": "maxnu & SpaghettDev",
Expand Down
16 changes: 16 additions & 0 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ void Common::setPriority()
}
}

float Common::getTPS()
{
float tps = 240.f;

if (Settings::get<bool>("general/tps/enabled"))
tps = Settings::get<float>("general/tps/value", 240.f);
else
tps = 240.f;
if(Macrobot::playerMode == Macrobot::PLAYBACK)
tps = Macrobot::macro.framerate;
if(tps < 1.f)
tps = 1.f;

return tps;
}

void Common::onAudioSpeedChange()
{
float speed;
Expand Down
2 changes: 2 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ namespace Common
void saveIcons();
void loadIcons();

float getTPS();

void updateCheating();
};
1 change: 1 addition & 0 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using namespace geode::prelude;


class $modify(CCKeyboardDispatcher)
{
bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool arr)
Expand Down
2 changes: 1 addition & 1 deletion src/Hacks/Labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class $modify(PlayLayer)
"Macro Info",
[&](cocos2d::CCLabelBMFont* pointer) {
if(Macrobot::playerMode == Macrobot::PLAYBACK)
pointer->setString(fmt::format("Playing {}/{}", Macrobot::actionIndex + 1, Macrobot::macro.inputs.size()).c_str());
pointer->setString(fmt::format("Playing {}/{}", Macrobot::actionIndex, Macrobot::macro.inputs.size()).c_str());
else if(Macrobot::playerMode == Macrobot::RECORDING)
pointer->setString(fmt::format("Recording {}", Macrobot::macro.inputs.size()).c_str());
else
Expand Down
14 changes: 2 additions & 12 deletions src/Hacks/PhysicsBypass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Settings.hpp"
#include "Macrobot/Macrobot.h"
#include <Geode/modify/PlayLayer.hpp>
#include "util.hpp"
#include "Common.h"

class $modify(PlayLayer)
{
Expand All @@ -22,17 +22,7 @@ class $modify(PlayLayer)

void PhysicsBypass::calculateTickrate()
{
float tps = 240.f;

if (Settings::get<bool>("general/tps/enabled"))
tps = Settings::get<float>("general/tps/value", 240.f);

if(Macrobot::playerMode == Macrobot::PLAYBACK)
tps = Macrobot::macro.framerate;

if(tps < 1.f)
tps = 1.f;

float tps = Common::getTPS();
util::Write<float>(base::get() + 0x49D548, 1.f / tps);

if(tps == 240.f)
Expand Down
107 changes: 50 additions & 57 deletions src/Macrobot/Macrobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "../Settings.hpp"

#include <fstream>
#include <imgui.h>
#include <imgui-cocos.hpp>
#include <iostream>

#include "Macrobot.h"
Expand Down Expand Up @@ -58,15 +58,9 @@ class $modify(PlayLayer)
macro.inputs.erase(std::remove_if (macro.inputs.begin(), macro.inputs.end(), check), macro.inputs.end());
PlayLayer::loadFromCheckpoint(checkpoint);

*((double *)GameManager::get()->getPlayLayer() + 1412) = checkpointData.time;
gameTime = checkpointData.time;
checkpointData.p1.apply(this->m_player1, true);
checkpointData.p2.apply(this->m_player2, true);
if (playerMode == RECORDING)
{
this->m_player1->releaseButton(PlayerButton::Jump);
this->m_player2->releaseButton(PlayerButton::Jump);
}
}
else
PlayLayer::loadFromCheckpoint(checkpoint);
Expand All @@ -80,6 +74,8 @@ class $modify(PlayLayer)
correctionIndex = 0;
gameTime = 9999999999;

resetFrame = true;

downForKey1.clear();
downForKey2.clear();
timeForKey1.clear();
Expand All @@ -93,7 +89,6 @@ class $modify(PlayLayer)

if (gameTime == 9999999999)
{
*((double *)GameManager::get()->getPlayLayer() + 1412) = 0.0;
gameTime = 0;
if (playerMode == RECORDING)
{
Expand All @@ -102,6 +97,8 @@ class $modify(PlayLayer)
}
}

resetFrame = false;

if (this->m_player1->m_isPlatformer)
{
if ((ImGui::IsKeyDown(ImGuiKey_RightArrow) || ImGui::IsKeyDown(ImGuiKey_D)) &&
Expand All @@ -111,6 +108,10 @@ class $modify(PlayLayer)
(ImGui::IsKeyDown(ImGuiKey_LeftArrow) || ImGui::IsKeyDown(ImGuiKey_A)))
this->m_player1->pushButton(PlayerButton::Left);
}

gameTime += (1.0 / (double)Common::getTPS()) + 0.00000001;
this->handleButton(false, 1, true);
gameTime -= (1.0 / (double)Common::getTPS()) + 0.00000001;
}
else
PlayLayer::resetLevel();
Expand All @@ -121,7 +122,7 @@ class $modify(PlayerObject)
{
void pushButton(PlayerButton btn)
{
if(playerMode == PLAYBACK && !botInput)
if((playerMode == PLAYBACK && !botInput) || resetFrame)
return;
PlayerObject::pushButton(btn);

Expand All @@ -132,22 +133,13 @@ class $modify(PlayerObject)
if(!pl->m_levelSettings->m_twoPlayerMode && this == pl->m_player2)
return;

Action *ac = recordAction(btn, gameTime, true, this == pl->m_player1);

if (Settings::get<int>("macrobot/corrections") > 0)
{
Correction c;
c.time = gameTime;
c.player2 = this == pl->m_player2;
c.checkpoint.fromPlayer(this, false);
ac->correction = c;
}
recordAction(btn, gameTime, true, this == pl->m_player1);
}
}

void releaseButton(PlayerButton btn)
{
if(playerMode == PLAYBACK && !botInput)
if((playerMode == PLAYBACK && !botInput) || resetFrame)
return;
PlayerObject::releaseButton(btn);

Expand All @@ -164,16 +156,7 @@ class $modify(PlayerObject)
if (btn == PlayerButton::Left && direction == -1)
return;

Action *ac = recordAction(btn, gameTime, false, this == pl->m_player1);

if (Settings::get<int>("macrobot/corrections") > 0)
{
Correction c;
c.time = gameTime;
c.player2 = this == pl->m_player2;
c.checkpoint.fromPlayer(this, false);
ac->correction = c;
}
recordAction(btn, gameTime, false, this == pl->m_player1);
}
}
};
Expand All @@ -182,7 +165,18 @@ Macrobot::Action* Macrobot::recordAction(PlayerButton key, double frame, bool pr
{
Action ac(frame, (int)key, !player1, press);

ac.frame = gdr::frameForTime(frame);
ac.frame = macro.frameForTime(frame);

PlayLayer* pl = GameManager::get()->getPlayLayer();

if (Settings::get<int>("macrobot/corrections") > 0)
{
Correction c;
c.time = gameTime;
c.player2 = !player1;
c.checkpoint.fromPlayer(player1 ? pl->m_player1 : pl->m_player2, false);
ac.correction = c;
}

macro.inputs.push_back(ac);

Expand All @@ -202,6 +196,8 @@ class $modify(CheckpointObject)
data.p1.fromPlayer(GameManager::get()->getPlayLayer()->m_player1, true);
data.p2.fromPlayer(GameManager::get()->getPlayLayer()->m_player2, true);

//log::debug("FROMPLAYER {} {} {}", data.p1.yVel, data.p1.xPos, gdr::frameForTime(data.time));

checkpoints[this] = data;
}

Expand Down Expand Up @@ -263,20 +259,18 @@ void Macrobot::handleAction(bool down, int button, bool player1, float timestamp
clickChannel->setVolume(volume);
}

float delay = 1.f;
int frames = 0;

void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer* self)
{
if (playerMode != DISABLED && GameManager::get()->getPlayLayer())
{
double currentTime = *((double *)GameManager::get()->getPlayLayer() + 1412);
gameTime = currentTime;
gameTime += (1.0 / (double)Common::getTPS()) + 0.00000001;

uint32_t gameFrame = macro.frameForTime(gameTime);

uint32_t frame = gdr::frameForTime(gameTime);
//log::debug("PROCESSCOMMANDS {} {} {}", MBO(double, GameManager::get()->getPlayLayer()->m_player1, 1936), GameManager::get()->getPlayLayer()->m_player1->m_position.x, gameFrame);

if (playerMode == PLAYBACK && macro.inputs.size() > 0 && actionIndex < macro.inputs.size() &&
((gameTime >= macro.inputs[actionIndex].time && macro.inputs[actionIndex].time > 0) || (frame >= macro.inputs[actionIndex].frame && macro.inputs[actionIndex].frame > 0)))
gameFrame >= macro.inputs[actionIndex].frame)
{
do
{
Expand All @@ -292,7 +286,7 @@ void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer* self)
co.checkpoint.apply(co.player2 ? GameManager::get()->getPlayLayer()->m_player2 : GameManager::get()->getPlayLayer()->m_player1, false);
}
actionIndex++;
} while (actionIndex < macro.inputs.size() && ((gameTime >= macro.inputs[actionIndex].time && macro.inputs[actionIndex].time > 0) || (frame >= macro.inputs[actionIndex].frame && macro.inputs[actionIndex].frame > 0)));
} while (actionIndex < macro.inputs.size() && (gameFrame >= macro.inputs[actionIndex].frame));
}
}

Expand All @@ -312,7 +306,7 @@ void Macrobot::PlayerCheckpoint::fromPlayer(PlayerObject *player, bool fullCaptu
return;

cocos2d::CCPoint position = player->m_position;
this->yVel = player->m_yVelocity;
this->yVel = MBO(double, player, 1936);
this->rotation = player->getRotation();
this->xVel = player->m_platformerXVelocity;
this->xPos = position.x;
Expand Down Expand Up @@ -344,22 +338,6 @@ void Macrobot::PlayerCheckpoint::apply(PlayerObject* player, bool fullRestore)
{
if (gameTime <= 0)
return;

player->m_objectSnappedTo = this->lastSnappedTo;

player->m_yVelocity =
this->yVel; // get all these offsets from playerobject constructor
player->setRotation(this->rotation);

player->setPositionX(this->nodeXPos);
player->setPositionY(this->nodeYPos);

player->m_position =
cocos2d::CCPoint(this->xPos, this->yPos);

player->m_platformerXVelocity = this->xVel;

player->m_rotationSpeed = this->rotationRate;

if (fullRestore)
{
Expand All @@ -381,7 +359,7 @@ void Macrobot::PlayerCheckpoint::apply(PlayerObject* player, bool fullRestore)
}
}

for (int i = 0; i < 1200; i++)
for (int i = 0; i < 1300; i++)
{
if (this->randomProperties[i] < 10000 && this->randomProperties[i] > -10000)
{
Expand All @@ -391,6 +369,21 @@ void Macrobot::PlayerCheckpoint::apply(PlayerObject* player, bool fullRestore)
}

// 1350 - 1410

player->m_objectSnappedTo = this->lastSnappedTo;

MBO(double, player, 1936) = this->yVel; //remove this when geode fixes the offset
player->setRotation(this->rotation);

player->setPositionX(this->nodeXPos);
player->setPositionY(this->nodeYPos);

player->m_position =
cocos2d::CCPoint(this->xPos, this->yPos);

player->m_platformerXVelocity = this->xVel;

player->m_rotationSpeed = this->rotationRate;
}

void Macrobot::save(const std::string& file)
Expand Down
3 changes: 2 additions & 1 deletion src/Macrobot/Macrobot.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Macrobot

struct Action : gdr::Input
{
double time = 0.0;
double time = -1.0;
std::optional<Correction> correction;

Action() = default;
Expand Down Expand Up @@ -114,6 +114,7 @@ namespace Macrobot
};

inline bool botInput = false;
inline bool resetFrame = false;

inline PlayerMode playerMode = DISABLED;

Expand Down

0 comments on commit 110da62

Please sign in to comment.