Skip to content

Commit

Permalink
Implement saving/loading attempts, implement cancel play level popup.…
Browse files Browse the repository at this point in the history
… Update bindings branch and bump geode ver
  • Loading branch information
0x5abe committed Aug 2, 2024
1 parent 98b1915 commit 00a134c
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ jobs:
uses: 0x5abe/build-geode-mod@main
with:
bindings: 0x5abe/geode-bindings
bindings-ref: main
bindings-ref: cocos
combine: true
cli: "latest"
sdk: "latest"
sdk: "nightly"
target: ${{ matrix.config.target }}

package:
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.3.1",
"geode": "3.4.0",
"gd": {
"win": "2.206"
},
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "LevelInfoLayer.hpp"

using namespace geode::prelude;
using namespace persistenceAPI;

unsigned long long s_levelInfoLayerDelegate1 = 0;
unsigned long long s_levelInfoLayerDelegate2 = 0;

// overrides

void PSLevelInfoLayer::onPlay(cocos2d::CCObject* i_sender) {
// stupid way of not letting it unregister the keyboard delegates
s_levelInfoLayerDelegate1 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-3*sizeof(void*);
s_levelInfoLayerDelegate2 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-2*sizeof(void*);

LevelInfoLayer::onPlay(i_sender);

s_levelInfoLayerDelegate1 = 0;
s_levelInfoLayerDelegate2 = 0;
}
20 changes: 20 additions & 0 deletions src/hooks/LevelInfoLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "Geode/binding/LevelInfoLayer.hpp"
#include <Geode/Geode.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>
#include <sabe.persistenceapi/include/PersistenceAPI.hpp>

extern unsigned long long s_levelInfoLayerDelegate1;
extern unsigned long long s_levelInfoLayerDelegate2;

class $modify(PSLevelInfoLayer, LevelInfoLayer) {
public:
struct Fields {
unsigned long long m_keyboardDelegate1;
unsigned long long m_keyboardDelegate2;
};

// overrides
$override
void onPlay(cocos2d::CCObject* i_sender);
};
21 changes: 16 additions & 5 deletions src/hooks/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using namespace geode::prelude;
using namespace persistenceAPI;

PSPlayLayer* s_currentPlayLayer = nullptr;
char s_psfMagicAndVer[] = "PSF v0.0.8";
int s_psfVersion = 8;
char s_psfMagicAndVer[] = "PSF v0.0.9";
int s_psfVersion = 9;

// overrides

Expand Down Expand Up @@ -116,9 +116,10 @@ void PSPlayLayer::postUpdate(float i_unkFloat) {

PlayLayer::postUpdate(i_unkFloat);

if (m_fields->m_updatePersistentTimerItemSet) {
m_fields->m_updatePersistentTimerItemSet = false;
if (m_fields->m_updateExtraData) {
m_fields->m_updateExtraData = false;
m_effectManager->m_persistentTimerItemSet = m_fields->m_loadedPersistentTimerItemSet;
m_attempts = m_fields->m_loadedAttempts;
}

m_fields->m_inPostUpdate = false;
Expand Down Expand Up @@ -306,7 +307,17 @@ bool PSPlayLayer::updatePsfFormat() {
m_fields->m_stream.write(s_psfMagicAndVer,sizeof(s_psfMagicAndVer));
m_fields->m_stream.seek(0, true);
m_fields->m_stream.clear();
m_fields->m_stream.writeZero(2*sizeof(int));
m_fields->m_stream.writeZero(3*sizeof(int));
m_fields->m_stream.seek(sizeof(s_psfMagicAndVer));
m_fields->m_readPsfVersion = s_psfVersion;
return true;
}
case 8: {
m_fields->m_stream.seek(0);
m_fields->m_stream.write(s_psfMagicAndVer,sizeof(s_psfMagicAndVer));
m_fields->m_stream.seek(0, true);
m_fields->m_stream.clear();
m_fields->m_stream.writeZero(sizeof(int));
m_fields->m_stream.seek(sizeof(s_psfMagicAndVer));
m_fields->m_readPsfVersion = s_psfVersion;
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/PlayLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ class $modify(PSPlayLayer, PlayLayer) {
bool m_exitAfterSave = false;
bool m_editorNoticeClosed = false;
bool m_cancelLevelLoad = false;
bool m_updatePersistentTimerItemSet = false;
bool m_updateExtraData = false;
int m_saveSlot = -1;
int m_uniqueIdBase = 12;
int m_readPsfVersion = -1;
int m_loadedAttempts = 0;
unsigned int m_remainingCheckpointLoadCount = 0;
unsigned int m_remainingCheckpointSaveCount = 0;
unsigned int m_bytesToRead = 0;
Expand Down
18 changes: 13 additions & 5 deletions src/hooks/PlayLayerLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void PSPlayLayer::loadGame() {
}
else if (m_fields->m_saveSlot == -2) {
m_fields->m_saveSlot = 0;
m_fields->m_loadingState = LoadingState::Ready;
//m_fields->m_loadingState = LoadingState::CancelLevelLoad;
//m_fields->m_loadingState = LoadingState::Ready;
m_fields->m_loadingState = LoadingState::CancelLevelLoad;
break;
}
else if (m_fields->m_saveSlot == -3) {
Expand Down Expand Up @@ -149,8 +149,12 @@ void PSPlayLayer::loadGame() {
}
case LoadingState::ReadExtraData: {
m_fields->m_stream >> m_effectManager->m_persistentItemCountMap;

m_fields->m_stream >> m_fields->m_loadedPersistentTimerItemSet;
m_fields->m_updatePersistentTimerItemSet = true;

m_fields->m_stream >> m_fields->m_loadedAttempts;

m_fields->m_updateExtraData = true;
m_fields->m_loadingState = LoadingState::Ready;
// falls through
}
Expand All @@ -175,7 +179,9 @@ void PSPlayLayer::loadGame() {
m_fields->m_loadingState = LoadingState::Ready;
} else {
m_fields->m_loadingState = LoadingState::Ready;
//Todo: Fix cancel level load for Vanilla platformers m_fields->m_loadingState = LoadingState::CancelLevelLoad;
//Todo: Fix cancel level load for Vanilla platformers
m_fields->m_loadingState = LoadingState::CancelLevelLoad;
// TodoEnd
}
CCEGLView::get()->showCursor(false);
bool l_lockCursor = GameManager::get()->getGameVariable("0128");
Expand Down Expand Up @@ -229,7 +235,9 @@ void PSPlayLayer::loadGame() {
m_fields->m_loadingState = LoadingState::Ready;
} else {
m_fields->m_loadingState = LoadingState::Ready;
//Todo: Fix cancel level load for Vanilla platformers m_fields->m_loadingState = LoadingState::CancelLevelLoad;
//Todo: Fix cancel level load for Vanilla platformers
m_fields->m_loadingState = LoadingState::CancelLevelLoad;
// TodoEnd
}
CCEGLView::get()->showCursor(false);
bool l_lockCursor = GameManager::get()->getGameVariable("0128");
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/PlayLayerSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ void PSPlayLayer::saveGame() {
}
case SavingState::SaveExtraData: {
m_fields->m_stream << m_effectManager->m_persistentItemCountMap;

m_fields->m_stream << m_effectManager->m_persistentTimerItemSet;

m_fields->m_stream << m_attempts;

m_fields->m_savingState = SavingState::Ready;
// falls through
}
Expand Down
11 changes: 10 additions & 1 deletion src/hooks/cocos2d/CCDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ bool PSCCDirector::replaceScene(CCScene* i_scene) {
if (!l_playButton) {
return false;
}
CCNode* l_playButtonSprite = static_cast<CCNode*>(l_playButton->getChildren()->objectAtIndex(0));
CCSprite* l_playButtonSprite = static_cast<CCSprite*>(l_playButton->getChildren()->objectAtIndex(0));
if (!l_playButtonSprite) {
return false;
}
l_playButtonSprite->removeAllChildrenWithCleanup(true);
l_playButtonSprite->setColor({255, 255, 255});
}

LevelSelectLayer* l_mainLayer = static_cast<LevelSelectLayer*>(CCScene::get()->getChildByID("main-layer"));
Expand Down Expand Up @@ -84,6 +85,14 @@ bool PSCCDirector::replaceScene(CCScene* i_scene) {
*reinterpret_cast<byte*>(geode::base::get()+0x685ff8) = 0;
}

LevelAreaInnerLayer* l_levelAreaInnerLayer = static_cast<LevelAreaInnerLayer*>(CCScene::get()->getChildByID("LevelAreaInnerLayer"));
if (l_levelAreaInnerLayer) {
l_levelAreaInnerLayer->m_isBusy = false;
if (l_levelAreaInnerLayer->getChildrenCount() == 3) {
l_levelAreaInnerLayer->getChildren()->removeObjectAtIndex(2);
}
}

return false;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/cocos2d/CCKeyboardDispatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "CCKeyboardDispatcher.hpp"
#include "Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDispatcher.h"
#include <hooks/PlayLayer.hpp>

using namespace geode::prelude;
using namespace persistenceAPI;

// overrides

void PSCCKeyboardDispatcher::removeDelegate(cocos2d::CCKeyboardDelegate* i_delegate) {
if (s_levelInfoLayerDelegate1 == reinterpret_cast<unsigned long long>(i_delegate) || s_levelInfoLayerDelegate2 == reinterpret_cast<unsigned long long>(i_delegate)) {
return;
}
CCKeyboardDispatcher::removeDelegate(i_delegate);
}
15 changes: 15 additions & 0 deletions src/hooks/cocos2d/CCKeyboardDispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "Geode/cocos/robtop/keyboard_dispatcher/CCKeyboardDelegate.h"
#include <Geode/Geode.hpp>
#include <Geode/modify/CCKeyboardDispatcher.hpp>
#include <sabe.persistenceapi/include/PersistenceAPI.hpp>

extern unsigned long long s_levelInfoLayerDelegate1;
extern unsigned long long s_levelInfoLayerDelegate2;

class $modify(PSCCKeyboardDispatcher, cocos2d::CCKeyboardDispatcher) {
public:
// overrides
$override
void removeDelegate(cocos2d::CCKeyboardDelegate* i_delegate);
};
7 changes: 1 addition & 6 deletions src/ui/PlayLevelMenuPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ void PlayLevelMenuPopup::onContinue(CCObject* sender) {
void PlayLevelMenuPopup::keyBackClicked() {
PSPlayLayer* l_playLayer = static_cast<PSPlayLayer*>(PlayLayer::get());
if (l_playLayer && l_playLayer->m_fields->m_loadingState == LoadingState::WaitingForPlayLevelMenuPopup) {
l_playLayer->m_fields->m_saveSlot = 0;

std::string l_filePath = l_playLayer->getSaveFilePath(-1, true);
if (l_filePath == "") {
l_playLayer->m_fields->m_saveSlot = -3;
}
l_playLayer->m_fields->m_saveSlot = -2;
}

onClose(nullptr);
Expand Down

0 comments on commit 00a134c

Please sign in to comment.