forked from geode-sdk/DevTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
131 lines (109 loc) · 3.57 KB
/
main.cpp
File metadata and controls
131 lines (109 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "platform/platform.hpp"
#include <Geode/modify/CCKeyboardDispatcher.hpp>
#include <Geode/modify/AchievementNotifier.hpp>
#include <Geode/modify/CCDirector.hpp>
#ifndef GEODE_IS_IOS
#include <Geode/modify/CCEGLView.hpp>
#endif
#include <Geode/modify/CCNode.hpp>
#include "DevTools.hpp"
#include <imgui.h>
#include "ImGui.hpp"
using namespace geode::prelude;
class $modify(CCNode) {
void sortAllChildren() override {
if (DevTools::get()->shouldOrderChildren()) {
CCNode::sortAllChildren();
}
}
};
#ifndef GEODE_IS_IOS
// todo: use shortcuts api once Geode has those
class $modify(CCKeyboardDispatcher) {
bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool arr) {
if (down && (key == KEY_F11 GEODE_MACOS(|| key == KEY_F10))) {
DevTools::get()->toggle();
return true;
}
return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, arr);
}
};
#endif
#ifdef GEODE_IS_MOBILE
// lol
#include <Geode/modify/MenuLayer.hpp>
class $modify(MenuLayer) {
void onMoreGames(CCObject*) {
DevTools::get()->toggle();
}
};
#endif
class $modify(AchievementNotifier) {
void willSwitchToScene(CCScene* scene) {
AchievementNotifier::willSwitchToScene(scene);
DevTools::get()->sceneChanged();
}
};
class $modify(CCDirector) {
void drawScene() {
if (!DevTools::get()->shouldUseGDWindow()) {
return CCDirector::drawScene();
}
DevTools::get()->setup();
static GLRenderCtx* gdTexture = nullptr;
if (!DevTools::get()->shouldPopGame()) {
if (gdTexture) {
delete gdTexture;
gdTexture = nullptr;
}
shouldPassEventsToGDButTransformed() = false;
CCDirector::drawScene();
return;
}
if (shouldUpdateGDRenderBuffer()) {
if (gdTexture) {
delete gdTexture;
gdTexture = nullptr;
}
shouldUpdateGDRenderBuffer() = false;
}
#ifdef GEODE_IS_IOS
auto winSize = this->getOpenGLView()->m_obViewPortRect * geode::utils::getDisplayFactor();
#else
auto winSize = this->getOpenGLView()->getViewPortRect() * geode::utils::getDisplayFactor();
#endif
if (!gdTexture) {
gdTexture = new GLRenderCtx({ winSize.size.width, winSize.size.height });
}
if (!gdTexture->begin()) {
delete gdTexture;
gdTexture = nullptr;
CCDirector::drawScene();
DevTools::get()->render(nullptr);
return;
}
CCDirector::drawScene();
gdTexture->end();
DevTools::get()->render(gdTexture);
// if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
// auto backup_current_context = this->getOpenGLView()->getWindow();
// ImGui::UpdatePlatformWindows();
// ImGui::RenderPlatformWindowsDefault();
// glfwMakeContextCurrent(backup_current_context);
// }
}
};
#ifndef GEODE_IS_IOS
class $modify(CCEGLView) {
// this is needed for popout mode because we need to render after gd has rendered,
// but before the buffers have been swapped, which is not possible with just a
// CCDirector::drawScene hook.
void swapBuffers() {
if (!DevTools::get()->shouldUseGDWindow() || !DevTools::get()->shouldPopGame()) {
DevTools::get()->setup();
DevTools::get()->render(nullptr);
}
CCEGLView::swapBuffers();
}
};
#endif