Skip to content

Instantly share code, notes, and snippets.

@SMJSGaming
Created May 1, 2022 14:24
Show Gist options
  • Save SMJSGaming/58a5b16951c8caffa5b114534644abff to your computer and use it in GitHub Desktop.
Save SMJSGaming/58a5b16951c8caffa5b114534644abff to your computer and use it in GitHub Desktop.
A full reload system for Geometry Dash using cocos2d
#pragma once
#include <cocos2d.h>
using namespace cocos2d;
namespace cocos2d {
struct CCAnimateFrameCache : CCObject {
CCDictionary* m_dict0;
CCDictionary* m_dict1;
CCDictionary* m_dict2;
static CCAnimateFrameCache* sharedAnimateFrameCache() {
return reinterpret_cast<CCAnimateFrameCache*(__thiscall*)()>(gd::base + 0x158F0)();
}
void addSpriteFramesWithFile(const char* file) {
reinterpret_cast<void(__thiscall*)(CCAnimateFrameCache*, const char*)>(gd::base + 0x159B0)(this, file);
}
};
}
#pragma once
#include <cocos2d.h>
using namespace cocos2d;
RT_ADD(
class CC_DLL CCContentManager : public CCObject {
public:
static CCContentManager* sharedManager();
CCContentManager();
bool init();
CCDictionary* addDict(const char* dict, bool unk);
CCDictionary* addDictDS(const char* dict);
void clearCache();
};
);
#include <cocos2d.h>
#include "CCContentManager.hpp"
#include "CCAnimateFrameCache.hpp"
using namespace cocos2d;
// Keep in mind, this is truly a reload, calling this on a startup will crash
void reload() {
CCDirector* director = CCDirector::sharedDirector();
CCAnimateFrameCache* animateFrameCache = CCAnimateFrameCache::sharedAnimateFrameCache();
// Replace the scene with a clean scene
director->popToRootScene();
director->replaceScene(CCScene::create());
// Clear caches
// Only required if you want shader and texture related cocos settings to reinitialize
CCContentManager::sharedManager()->clearCache();
CCTextureCache::purgeSharedTextureCache();
CCLabelBMFont::purgeCachedData();
animateFrameCache->m_dict0->removeAllObjects();
animateFrameCache->m_dict1->removeAllObjects();
animateFrameCache->m_dict2->removeAllObjects();
CCShaderCache::purgeSharedShaderCache();
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
// Initialize the reload
CCApplication::sharedApplication()->applicationDidFinishLaunching();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment