From da80e70fe712d87b00006acd16f9f6b1f1fe6779 Mon Sep 17 00:00:00 2001 From: ZIlko <69888540+ZiLko@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:16:54 -0600 Subject: [PATCH] Update main.cpp --- src/main.cpp | 310 +++++++++++++++++++-------------------------------- 1 file changed, 112 insertions(+), 198 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 91d0092..6eb865e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,9 @@ #include #include -#include -#include #include #include +#include +#include #include #include #include @@ -182,62 +182,6 @@ class recordSystem { macro.push_back({realp1, frame, button, holding, false, p1Data, p2Data}); } - void eraseActions(PlayLayer* pl) { - if (pl->m_isPracticeMode && !macro.empty()) { - try { - int frame = currentFrame(); - if (!macro.empty()) { - for (auto it = macro.rbegin(); it != macro.rend(); ++it) { - if (it->frame >= frame) { - try { - macro.erase((it + 1).base()); - } catch (const std::exception& e) { - log::debug("wtfffff amaze? - {}",e); - } - } else break; - } - bool fix = false; - if (macro.size() >= 2) { - if (macro.back().holding || (macro[macro.size() - 2].holding && !macro[macro.size() - 2].player1)) - fix = true; - } else if (macro.back().holding) - fix = true; - - if (fix) { - playerData p1; - playerData p2; - p1 = { - 0.f, - 0.f, - false, - -80085, - -80085, - -80085 - }; - p2 = { - 0.f, - 0.f, - false, - -80085, - -80085, - -80085 - }; - macro.push_back({false, currentFrame(), 1, false, false, p1, p2}); - macro.push_back({true, currentFrame(), 1, false, false, p1, p2}); - if (pl->m_levelSettings->m_platformerMode) { - macro.push_back({false, currentFrame(), 2, false, false, p1, p2}); - macro.push_back({true, currentFrame(), 2, false, false, p1, p2}); - macro.push_back({false, currentFrame(), 3, false, false, p1, p2}); - macro.push_back({true, currentFrame(), 3, false, false, p1, p2}); - } - } - } - } catch (const std::exception& e) { - log::debug("wtfffff? - {}",e); - } - } - } - }; recordSystem recorder; @@ -250,7 +194,7 @@ class RecordLayer : public geode::Popup { protected: bool setup(std::string const& value) override { auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize(); - auto versionLabel = CCLabelBMFont::create("xdBot v1.5.0 - made by Zilko", "chatFont.fnt"); + auto versionLabel = CCLabelBMFont::create("xdBot v1.5.1 - made by Zilko", "chatFont.fnt"); versionLabel->setOpacity(60); versionLabel->setAnchorPoint(ccp(0.0f,0.5f)); versionLabel->setPosition(winSize/2 + ccp(-winSize.width/2, -winSize.height/2) + ccp(3, 6)); @@ -354,6 +298,8 @@ class RecordLayer : public geode::Popup { label->setAnchorPoint({0, 0.5}); m_mainLayer->addChild(label); + + playing = CCMenuItemToggler::create(checkOffSprite, checkOnSprite, this, menu_selector(RecordLayer::togglePlay)); @@ -548,6 +494,7 @@ void saveMacroPopup::openSaveMacro(CCObject*) { && recorder.state == state::recording) ? true : false; layer->show(); } + void saveMacroPopup::saveMacro(CCObject*) { if (std::string(macroNameInput->getString()).length() < 1) { FLAlertLayer::create( @@ -562,11 +509,11 @@ void saveMacroPopup::saveMacro(CCObject*) { +slash+std::string(macroNameInput->getString()) + ".xd"; std::wstring_convert> converter; - std::wstring widePath = converter.from_bytes(savePath); + std::wstring wideString = converter.from_bytes(savePath); std::locale utf8_locale(std::locale(), new std::codecvt_utf8); - std::wifstream tempFile(widePath); - + std::wifstream tempFile(wideString); + if (tempFile.good()) { FLAlertLayer::create( "Save Macro", @@ -578,7 +525,7 @@ void saveMacroPopup::saveMacro(CCObject*) { } tempFile.close(); - std::wofstream file(widePath); + std::wofstream file(wideString); file.imbue(utf8_locale); if (file.is_open()) { @@ -626,11 +573,11 @@ void macroCell::handleLoad(CCObject* btn) { recorder.macro.clear(); std::wstring_convert> converter; - std::wstring widePath = converter.from_bytes(loadPath); + std::wstring wideString = converter.from_bytes(loadPath); std::locale utf8_locale(std::locale(), new std::codecvt_utf8); - std::wifstream file(widePath); + std::wifstream file(wideString); file.imbue(utf8_locale); std::wstring line; if (!file.is_open()) { @@ -686,7 +633,7 @@ void macroCell::handleLoad(CCObject* btn) { (double)p2xSpeed, (double)p2ySpeed, }; - //if ((isAndroid && !(bool)posOnly) || !isAndroid) + if ((isAndroid && !(bool)posOnly) || !isAndroid) recorder.macro.push_back({(bool)player1, (int)frame, (int)button, (bool)holding, (bool)posOnly, p1, p2}); } } else if (count < 1) { @@ -757,28 +704,28 @@ void clearState(bool safeMode) { } recorder.state = state::off; + playingAction = false; if (isAndroid && PlayLayer::get()) { if (disableFSBtn != nullptr) { disableFSBtn->removeFromParent(); + disableFSBtn = nullptr; } if (advanceFrameBtn != nullptr) { advanceFrameBtn->removeFromParent(); + advanceFrameBtn = nullptr; } if (speedhackBtn != nullptr) { speedhackBtn->removeFromParent(); + speedhackBtn = nullptr; } if (buttonsMenu != nullptr) { buttonsMenu->removeFromParent(); + buttonsMenu = nullptr; } } - disableFSBtn = nullptr; - advanceFrameBtn = nullptr; - speedhackBtn = nullptr; - buttonsMenu = nullptr; - releaseKeys(); frameLabel = nullptr; @@ -1057,6 +1004,25 @@ void checkUI() { } // ---------------- Hooks ---------------- 539// +class $modify(PlayerObject) { +void playerDestroyed(bool p0) { + if (isAndroid) androidAction = nullptr; + if (isAndroid && mod->getSettingValue("auto_safe_mode") && playedMacro) { + noDelayedReset = true; + onReset(); + return PlayLayer::get()->resetLevel(); + } + if ((!mod->getSettingValue("instant_respawn") || recorder.state == state::off)) + return PlayerObject::playerDestroyed(p0); + onReset(); + return PlayLayer::get()->resetLevel(); +} +void playDeathEffect() { + if (!mod->getSettingValue("disable_death_effect") || recorder.state == state::off) + PlayerObject::playDeathEffect(); +} +}; + class $modify(PauseLayer) { void customSetup() { PauseLayer::customSetup(); @@ -1118,60 +1084,8 @@ class $modify(PauseLayer) { } }; -void onReset() { - if (recorder.state != state::off && restart != false) { - restart = false; - } - - if (recorder.state != state::off) { - checkUI(); - playerHolding = false; - if (!isAndroid) leftOver = 0.f; - } - - if (isAndroid) androidAction = nullptr; - - if (safeModeEnabled && !isAndroid && mod->getSettingValue("auto_safe_mode")) { - safeModeEnabled = false; - safeMode::updateSafeMode(); - } - - if (playedMacro) playedMacro = false; - - - if (recorder.state == state::playing) { - playingAction = false; - releaseKeys(); - recorder.currentAction = 0; - if (mod->getSettingValue("speedhack_audio")) { - FMOD::ChannelGroup* channel; - FMODAudioEngine::sharedEngine()->m_system->getMasterChannelGroup(&channel); - channel->setPitch(1); - } - } -} -class $modify(PlayerObject) { -void playerDestroyed(bool p0) { - if (isAndroid) androidAction = nullptr; - if (isAndroid && mod->getSettingValue("auto_safe_mode") && playedMacro) { - noDelayedReset = true; - onReset(); - return PlayLayer::get()->resetLevel(); - } - if ((!mod->getSettingValue("instant_respawn") || recorder.state == state::off)) - return PlayerObject::playerDestroyed(p0); - onReset(); - return PlayLayer::get()->resetLevel(); -} -void playDeathEffect() { - if (!mod->getSettingValue("disable_death_effect") || recorder.state == state::off) - PlayerObject::playDeathEffect(); -} -}; class $modify(GJBaseGameLayer) { - - void toggleFlipped(bool p0, bool p1) { if (!mod->getSettingValue("instant_mirror") || recorder.state == state::off) return GJBaseGameLayer::toggleFlipped(p0, p1); @@ -1181,7 +1095,7 @@ class $modify(GJBaseGameLayer) { if (!isAndroid) { if ((recorder.state == state::playing && (playingAction || !mod->getSettingValue("ignore_inputs"))) || recorder.state != state::playing) GJBaseGameLayer::handleButton(holding,button,player1); -} + } if (isAndroid) { if (recorder.state == state::recording) { GJBaseGameLayer::handleButton(holding,button,player1); @@ -1207,15 +1121,11 @@ class $modify(GJBaseGameLayer) { } else { p2.xPos = 0; } - int frame = recorder.currentFrame(); + int frame = recorder.currentFrame(); recorder.recordAction(holding, button, player1, frame, this, p1, p2); } else if (recorder.state == state::playing) { - if (!mod->getSettingValue("ignore_inputs")) - GJBaseGameLayer::handleButton(holding,button,player1); - + GJBaseGameLayer::handleButton(holding,button,player1); if (androidAction != nullptr) { - if (mod->getSettingValue("ignore_inputs")) - GJBaseGameLayer::handleButton(holding,button,player1); if (androidAction->p1.xPos != 0) { if (!areEqual(this->m_player1->getPositionX(), androidAction->p1.xPos) || !areEqual(this->m_player1->getPositionY(), androidAction->p1.yPos)) @@ -1229,7 +1139,6 @@ class $modify(GJBaseGameLayer) { } } } - androidAction = nullptr; } else GJBaseGameLayer::handleButton(holding,button,player1); } else if (recorder.state == state::recording) { @@ -1310,58 +1219,7 @@ class $modify(GJBaseGameLayer) { } } - if (recorder.state == state::off) { - if (frameLabel != nullptr) { - frameLabel->removeFromParent(); - frameLabel = nullptr; - } - if (stateLabel != nullptr) { - stateLabel->removeFromParent(); - stateLabel = nullptr; - } - } - - if (recorder.state != state::recording && isAndroid) { - if (disableFSBtn != nullptr) { - disableFSBtn->removeFromParent(); - disableFSBtn = nullptr; - } - if (advanceFrameBtn != nullptr) { - advanceFrameBtn->removeFromParent(); - advanceFrameBtn = nullptr; - } - if (speedhackBtn != nullptr) { - speedhackBtn->removeFromParent(); - speedhackBtn = nullptr; - } - if (buttonsMenu != nullptr) { - buttonsMenu->removeFromParent(); - buttonsMenu = nullptr; - } - } - if (recorder.state == state::playing) { - if (stateLabel != nullptr) { - if (stateLabel->getString() != "Playing" && mod->getSettingValue("show_playing_label")) - stateLabel->setString("Playing"); - else if (!mod->getSettingValue("show_playing_label")) { - stateLabel->removeFromParent(); - stateLabel = nullptr; - } - } else if (mod->getSettingValue("show_playing_label")) { - addLabel("Playing"); - } - } if (recorder.state == state::recording) { - if (stateLabel != nullptr) { - if (stateLabel->getString() != "Recording" && mod->getSettingValue("show_recording_label")) - stateLabel->setString("Recording"); - else if (!mod->getSettingValue("show_recording_label")) { - stateLabel->removeFromParent(); - stateLabel = nullptr; - } - } else if (mod->getSettingValue("show_recording_label")) { - addLabel("Recording"); - } if (mod->getSettingValue("frame_stepper") && stepFrame == false) return; else if (stepFrame) { @@ -1385,7 +1243,7 @@ if (recorder.state == state::playing && isAndroid) { ? getPlayer1(currentActionIndex.player1, this) : 0; - playedMacro = true; + if (!playedMacro) playedMacro = true; int pBtn = (currentActionIndex.button < 4 && currentActionIndex.button > 0) ? currentActionIndex.button : 1; cocos2d::CCKeyboardDispatcher::get()->dispatchKeyboardMSG( @@ -1449,7 +1307,7 @@ void GJBaseGameLayerProcessCommands(GJBaseGameLayer* self) { safeModeEnabled = true; safeMode::updateSafeMode(); } - if (!playedMacro) playedMacro = true; + playedMacro = true; if (!mod->getSettingValue("override_macro_mode") && currentActionIndex.p1.xPos != 0) { if (!areEqual(self->m_player1->getPositionX(), currentActionIndex.p1.xPos) || !areEqual(self->m_player1->getPositionY(), currentActionIndex.p1.yPos)) @@ -1527,9 +1385,7 @@ void GJBaseGameLayerProcessCommands(GJBaseGameLayer* self) { } } - class $modify(PlayLayer) { - void destroyPlayer(PlayerObject* p1, GameObject* p2) { if (!mod->getSettingValue("noclip") || recorder.state == state::off) PlayLayer::destroyPlayer(p1,p2); @@ -1544,14 +1400,15 @@ class $modify(PlayLayer) { PlayLayer::delayedResetLevel(); } void resetLevel() { + checkUI(); + PlayLayer::resetLevel(); if (recorder.state != state::off && restart != false) { restart = false; } if (recorder.state != state::off) { - checkUI(); playerHolding = false; - if (!isAndroid) leftOver = 0.f; + leftOver = 0.f; } if (isAndroid) androidAction = nullptr; @@ -1566,25 +1423,74 @@ class $modify(PlayLayer) { if (recorder.state == state::playing) { playingAction = false; - releaseKeys(); recorder.currentAction = 0; if (mod->getSettingValue("speedhack_audio")) { FMOD::ChannelGroup* channel; FMODAudioEngine::sharedEngine()->m_system->getMasterChannelGroup(&channel); channel->setPitch(1); } - PlayLayer::resetLevel(); } else if (recorder.state != state::off) { - PlayLayer::resetLevel(); - if (recorder.currentFrame() == 0) { + checkUI(); + if (this->m_isPracticeMode && !recorder.macro.empty() && recorder.currentFrame() != 0) { + int frame = recorder.currentFrame(); + try { + if (!recorder.macro.empty()) { + for (auto it = recorder.macro.rbegin(); it != recorder.macro.rend(); ++it) { + if (it->frame >= frame) { + try { + recorder.macro.erase((it + 1).base()); + } catch (const std::exception& e) { + log::debug("wtfffff amaze? - {}",e); + } + } else break; + } + bool fix = false; + if (macro.size() >= 2) { + if (macro.back().holding || (macro[macro.size() - 2].holding && !macro[macro.size() - 2].player1)) + fix = true; + } else if (macro.back().holding) + fix = true; + + if (fix) { + playerData p1; + playerData p2; + p1 = { + 0.f, + 0.f, + false, + -80085, + -80085, + -80085 + }; + p2 = { + 0.f, + 0.f, + false, + -80085, + -80085, + -80085 + }; + macro.push_back({false, currentFrame(), 1, false, false, p1, p2}); + macro.push_back({true, currentFrame(), 1, false, false, p1, p2}); + if (pl->m_levelSettings->m_platformerMode) { + macro.push_back({false, currentFrame(), 2, false, false, p1, p2}); + macro.push_back({true, currentFrame(), 2, false, false, p1, p2}); + macro.push_back({false, currentFrame(), 3, false, false, p1, p2}); + macro.push_back({true, currentFrame(), 3, false, false, p1, p2}); + } + } + } + } catch (const std::exception& e) { + log::debug("wtfffff? - {}",e); + } + } else { if (!recorder.macro.empty()) - recorder.macro.clear(); + recorder.macro.clear(); recorder.android = false; recorder.fps = fpsArr[fpsIndex]; - } else - recorder.eraseActions(this); - } + } + } } void levelComplete() { @@ -1654,6 +1560,7 @@ class $modify(EndLevelLayer) { clearState(false); } }; +int syncCooldown = 0; int holdCooldown = 0; class $modify(CCScheduler) { void update(float dt) { @@ -1697,6 +1604,12 @@ class $modify(CCScheduler) { } } leftOver += (dt - dt2 * mult); + if (recorder.state == state::playing && !PlayLayer::get()->m_levelSettings->m_platformerMode) { + syncCooldown++; + if (syncCooldown >= 20 && leftOver > 1) { + syncCooldown = 0; + } + } } }; @@ -1742,7 +1655,6 @@ class $modify(CCKeyboardDispatcher) { $execute { mod = Mod::get(); - if (mod->getSavedValue("previous_fps")) fpsIndex = mod->getSavedValue("previous_fps"); else if (isAndroid) @@ -1759,9 +1671,11 @@ class $modify(CCKeyboardDispatcher) { if (!isAndroid) mod->hook(reinterpret_cast(base::get() + 0x1BD240), &GJBaseGameLayerProcessCommands, "GJBaseGameLayer::processCommands", tulip::hook::TulipConvention::Thiscall); - else if (sizeof(void*) == 8) { + else { + if (sizeof(void*) == 8) { offset = 0x3B8; } + } for (std::size_t i = 0; i < 15; i++) { safeMode::patches[i] = mod->patch(reinterpret_cast(base::get() + std::get<0>(safeMode::codes[i])),