Skip to content

Commit

Permalink
fixed fullscreen crash, betteredit compat, and anticheat spike
Browse files Browse the repository at this point in the history
  • Loading branch information
adafcaefc committed Dec 6, 2024
1 parent d7fc5d4 commit bde1bcd
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 10 deletions.
29 changes: 29 additions & 0 deletions Geome3Dash/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,32 @@

using namespace cocos2d;

// --- pre-load some stuff in pch ---

#include "engine/sus3d/ShaderProgram.h"
#include "engine/sus3d/Shader.h"
#include "engine/sus3d/Mesh.h"
#include "engine/sus3d/Texture.h"
#include "engine/sus3d/Model.h"
#include "engine/sus3d/Scene.h"
#include "engine/sus3d/Shaders.h"

#include "delegate/CustomKeyboard.h"
#include "delegate/CustomMouse.h"
#include "delegate/CustomTouch.h"

#include "helper/CommonHelper.h"
#include "helper/OpenGLStateHelper.h"

#include "transformer/AnimationGameObjectModelTransformer.h"
#include "transformer/FadeGameObjectModelTransformer.h"
#include "transformer/SplineCameraPlayerObjectModelTransformer.h"
#include "transformer/SplineGameObjectTransformer.h"
#include "transformer/SplinePlayerObjectTransformer.h"

#include "CocosShaderProgram.h"
#include "PlayerObjectModel.h"
#include "LevelDataManager.h"

// --- pre-load some stuff in pch ---

16 changes: 16 additions & 0 deletions Geome3Dash/src/BlockModelStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ namespace g3d
OpenGLStateHelper::pushState();
}

void BlockModelStorage::reloadAllShaders()
{
if (blockShaderProgram) { delete blockShaderProgram; }
if (waterShaderProgram) { delete waterShaderProgram; }
if (cloudShaderProgram) { delete cloudShaderProgram; }
if (idBufferShaderProgram) { delete idBufferShaderProgram; }
sus3d::Texture::cleanup();
//for (auto& [k, v] : blockModels) { delete v; }
//for (auto& [k, v] : allModels) { delete v; }
blockModels.clear();
allModels.clear();
for (auto& fn : clearModelCallbacks) { fn(); }
loadAllShaders();
loadAllModels();
}

bool BlockModelStorage::init()
{
basePath = geode::Mod::get()->getResourcesDir() / "model3d";
Expand Down
25 changes: 21 additions & 4 deletions Geome3Dash/src/BlockModelStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ namespace g3d
protected:
std::unordered_map<int, sus3d::Model*> blockModels;
std::unordered_map<std::filesystem::path, sus3d::Model*> allModels;
sus3d::ShaderProgram* blockShaderProgram;
sus3d::ShaderProgram* waterShaderProgram;
sus3d::ShaderProgram* cloudShaderProgram;
sus3d::ShaderProgram* idBufferShaderProgram;
sus3d::ShaderProgram* blockShaderProgram = nullptr;
sus3d::ShaderProgram* waterShaderProgram = nullptr;
sus3d::ShaderProgram* cloudShaderProgram = nullptr;
sus3d::ShaderProgram* idBufferShaderProgram = nullptr;
static BlockModelStorage* instance;
sus3d::ShaderProgram* loadShader(const std::string& vsString, const std::string& fsString);
void loadAllShaders();
void loadAllModels();
bool init();
std::filesystem::path basePath;
public:
bool shouldReloadShaders = false;
void reloadAllShaders();
sus3d::ShaderProgram* getBlockSP() { return blockShaderProgram; }
sus3d::ShaderProgram* getWaterSP() { return waterShaderProgram; }
sus3d::ShaderProgram* getCloudSP() { return cloudShaderProgram; }
Expand All @@ -47,6 +49,7 @@ namespace g3d
sus3d::Model* getBlockModel(const int id);
static BlockModelStorage* get();


template <typename ModelT = sus3d::Model>
ModelT* loadAndParseMtl(const std::filesystem::path& path)
{
Expand All @@ -57,10 +60,24 @@ namespace g3d
return sus3d::loadModelT<ModelT>(path);
}

std::vector<std::function<void()>> clearModelCallbacks;
template <typename ModelT>
ModelT* getModelT(const std::filesystem::path& path)
{
static std::unordered_map<std::filesystem::path, ModelT*> cModels;

// Add a lambda to clearModelCallbacks to clear cModels, if not already added
static bool isCallbackAdded = false;
if (!isCallbackAdded)
{
clearModelCallbacks.push_back([]()
{
//for (auto& [k, v] : cModels) { delete v; }
cModels.clear();
});
isCallbackAdded = true;
}

auto it = cModels.find(path);
if (it == cModels.end())
{
Expand Down
3 changes: 1 addition & 2 deletions Geome3Dash/src/GameObjectModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ namespace g3d
this->update();
this->applyTransformation();

//if (!this->getVisible()) { return; }
if (this->opacity == 0.f || this->scale == glm::vec3(0.f)) { return; }
if (!this->getVisible() || this->opacity == 0.f || this->scale == glm::vec3(0.f)) { return; }

auto tScale = model->getScale();
auto tPos = model->getPosition();
Expand Down
1 change: 0 additions & 1 deletion Geome3Dash/src/engine/sus3d/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ namespace sus3d
aiProcess_FlipUVs |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);

auto model = T::create(scene);
importer.FreeScene();
return model;
Expand Down
1 change: 1 addition & 0 deletions Geome3Dash/src/game/playing/G3DPlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace g3d
{
if (auto obj = dynamic_cast<GameObject*>(objxx))
{
if (obj == playLayer->m_anticheatSpike) { continue; }
if (auto model = BlockModelStorage::get()->getBlockModel(obj->m_objectID))
{
blocks.push_back(GameObjectModel(obj, { splineTr, fadeTr, animTr }));
Expand Down
2 changes: 2 additions & 0 deletions Geome3Dash/src/helper/CameraKeyframeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace g3d
~CameraKeyframeBuffer();
};

// to do : move this into classes

void setStartingKeyframe(
LevelData* cld,
CameraKeyframeBuffer* keyframeBuffer,
Expand Down
7 changes: 7 additions & 0 deletions Geome3Dash/src/hook/CCEGLView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "BlockModelStorage.h"
#include "delegate/CustomTouch.h"
#include "delegate/CustomKeyboard.h"

Expand All @@ -23,5 +24,11 @@ namespace g3d
CustomKeyboardManager::updateDelegates(window, key, scancode, action, mods);
CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods);
}

void toggleFullScreen(bool fullscreen, bool borderless, bool fix)
{
CCEGLView::toggleFullScreen(fullscreen, borderless, fix);
BlockModelStorage::get()->shouldReloadShaders = true;
}
};
}
6 changes: 3 additions & 3 deletions Geome3Dash/src/hook/LevelEditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ namespace g3d

auto sprite = CCSprite::createWithSpriteFrameName("GJ_plainBtn_001.png");
auto menu = CCMenuItemSpriteExtra::create(sprite, this, menu_selector(LevelEditorLayerG3D::onEditorPopup));
addG3DMenu(ccp(0, 0), "CAM", settingsButton, settingsMenu, menu, sprite);
addG3DMenu(ccp(-28, -40), "CAM", settingsButton, settingsMenu, menu, sprite);

auto sprite2 = CCSprite::createWithSpriteFrameName("GJ_plainBtn_001.png");
auto menu2 = CCMenuItemSpriteExtra::create(sprite2, this, menu_selector(LevelEditorLayerG3D::onSplineEditor));
addG3DMenu(ccp(-40, 0), "PATH", settingsButton, settingsMenu, menu2, sprite2);
addG3DMenu(ccp(-28, -120), "PATH", settingsButton, settingsMenu, menu2, sprite2);

auto sprite3 = CCSprite::createWithSpriteFrameName("GJ_plainBtn_001.png");
auto menu3 = CCMenuItemSpriteExtra::create(sprite3, this, menu_selector(LevelEditorLayerG3D::onCameraKeyframesEditor));
addG3DMenu(ccp(-40, -40), "KEY", settingsButton, settingsMenu, menu3, sprite3);
addG3DMenu(ccp(-28, -80), "KEY", settingsButton, settingsMenu, menu3, sprite3);

m_fields->curveEditorLayer = G3DCurveEditorLoader::create(this);
this->addChild(m_fields->curveEditorLayer);
Expand Down
8 changes: 8 additions & 0 deletions Geome3Dash/src/hook/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ namespace g3d
{
// load cache
auto bms = BlockModelStorage::get();

if (bms->shouldReloadShaders)
{
bms->reloadAllShaders();
bms->shouldReloadShaders = false;
}

bms->getBlockModel(1);
const auto modelPath = bms->getBP() / "planet" / "model";
bms->getModelT<PlanetModel>(modelPath / "new_planet_textured.obj");
bms->getModelT<PlanetModel>(modelPath / "planet_water.obj");
bms->getModelT<CloudModel>(modelPath / "clouds.obj");

if (!MenuLayer::init()) { return false; }
return true;
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Have suggestions or need help? Connect with developers and fans on our [Discord
- **[Weebify](https://www.youtube.com/channel/UCAE-cJ-exfnSlq0Ddkd985g)**
- **[A145](https://www.youtube.com/@A145)**
- **[Lexi](https://github.com/KontrollFreek)**
- **[Albert](https://github.com/covernts)**

---

Expand Down
1 change: 1 addition & 0 deletions bin/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Have suggestions or need help? Connect with developers and fans on our [Discord
- **[Weebify](https://www.youtube.com/channel/UCAE-cJ-exfnSlq0Ddkd985g)**
- **[A145](https://www.youtube.com/@A145)**
- **[Lexi](https://github.com/KontrollFreek)**
- **[Albert](https://github.com/covernts)**

---

Expand Down

0 comments on commit bde1bcd

Please sign in to comment.