-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvl-share.cpp
176 lines (175 loc) · 6 KB
/
lvl-share.cpp
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//#include "lvl-share.hpp"
//#include <matdash.hpp>
//#include <matdash/minhook.hpp>
//#include <gd.h>
//#include "utils.hpp"
//#include <fstream>
//#include <matplist.hpp>
//#include <nfd.h>
//#include <cocos2d.h>
//
//using namespace cocos2d;
//
//
//template <class S>
//void dump_level(gd::GJGameLevel* level, S& stream) {
// const auto song_key = level->songID() ?
// format("<k>k45</k><i>{}</i>", level->songID()) :
// level->m_audioTrack ?
// format("<k>k8</k><i>{}</i>", level->m_audioTrack) : "";
// // encode it twice because gdshare does too
// // why? i dont know fod is stupid
// const auto encoded_desc = base64_encode(base64_encode(level->m_levelDesc.sv()));
// format_to(stream, R"(<d>
// <k>kCEK</k><i>4</i>
// <k>k2</k><s>{}</s>
// <k>k3</k><s>{}</s>
// <k>k4</k><s>{}</s>
// {}
// <k>k13</k><t/>
// <k>k21</k><i>2</i>
// <k>k50</k><i>24</i>
//</d>)", level->m_levelName.sv(), encoded_desc, level->m_levelString.sv(), song_key);
//}
//
//template <class S>
//gd::GJGameLevel* import_level(S& stream) {
// auto data = matplist::parse(stream);
// auto level = gd::GameLevelManager::sharedState()->createNewLevel();
// for (const auto& [key, var] : data) {
// if (!std::holds_alternative<matplist::Value>(var)) continue;
// matplist::Value value = std::get<matplist::Value>(var);
// using namespace std::literals;
// if (key == "k2"sv) {
// level->m_levelName = value.value;
// }
// else if (key == "k3"sv) {
// level->m_levelDesc = base64_decode(base64_decode(value.value));
// }
// else if (key == "k4"sv) {
// level->m_levelString = value.value;
// }
// else if (key == "k8"sv) {
// const auto text = value.value;
// level->m_audioTrack = std::stoi(text);
// }
// else if (key == "k45"sv) {
// const auto text = value.value;
// level->songID() = std::stoi(text);
// }
// }
// return level;
//}
//
//cocos2d::CCObject* levelObject;
//cocos2d::CCArray* localLevelArray;
//
//class MoveToTopProtocol : public gd::FLAlertLayerProtocol {
//public:
// void FLAlert_Clicked(gd::FLAlertLayer* layer, bool btn2) override {
// if (btn2) {
// localLevelArray->removeObject(levelObject, true);
// localLevelArray->insertObject(levelObject, 0);
// gd::LocalLevelManager::sharedState()->updateLevelOrder();
// }
// }
//};
//
//MoveToTopProtocol moveToTopProtocol;
//
//void EditLevelLayer::Callback::onMoveToTop(CCObject*) {
// gd::FLAlertLayer::create(&moveToTopProtocol, "Move To Top", "Move this level to the top of the created levels list?", "NO", "YES", 300.f, false, 140.f)->show();
//}
//
//bool EditLevelLayer_init(gd::EditLevelLayer* self, gd::GJGameLevel* level) {
// if (!matdash::orig<&EditLevelLayer_init>(self, level)) return false;
//
// localLevelArray = gd::LocalLevelManager::sharedState()->getLocalLevels();
// levelObject = (cocos2d::CCObject*)level;
//
// auto director = CCDirector::sharedDirector();
//
// auto menu = CCMenu::create();
//
// constexpr auto handler = [](CCObject* self, CCObject*) {
// auto* const level = reinterpret_cast<gd::EditLevelLayer*>(self)->level();
// nfdchar_t* path = nullptr;
// if (NFD_SaveDialog("gmd", nullptr, &path) == NFD_OKAY) {
// std::ofstream file(path);
// dump_level(level, file);
// free(path);
// gd::FLAlertLayer::create(nullptr, "Success", "The level has been saved", "OK", nullptr, 320.f, false, 0)->show();
// }
// };
//
// auto btn_spr = CCSprite::createWithSpriteFrameName("GJ_downloadBtn_001.png");
// if (!btn_spr->initWithFile("BE_Export_File.png")) {
// btn_spr->initWithSpriteFrameName("GJ_downloadBtn_001.png");
// }
// auto button = gd::CCMenuItemSpriteExtra::create(btn_spr, nullptr, self, to_handler<SEL_MenuHandler, handler>);
// button->setPosition({ -30, -270 });
//
// menu->setZOrder(1);
// menu->setPosition({ director->getScreenRight(), director->getScreenTop() });
// menu->addChild(button);
// self->addChild(menu);
//
// auto onMoveToTop_spr = CCSprite::createWithSpriteFrameName("edit_upBtn_001.png");
// if (!onMoveToTop_spr->initWithFile("GJ_orderUpBtn_001.png")) {
// onMoveToTop_spr->createWithSpriteFrameName("edit_upBtn_001.png");
// }
// onMoveToTop_spr->setScale(0.925f);
// auto onMoveToTop_btn = gd::CCMenuItemSpriteExtra::create(onMoveToTop_spr, onMoveToTop_spr, self, menu_selector(EditLevelLayer::Callback::onMoveToTop));
// onMoveToTop_btn->setPosition({ -30, -210 });
//
// menu->addChild(onMoveToTop_btn);
//
// return true;
//}
//
//bool LevelBrowserLayer_init(gd::LevelBrowserLayer* self, gd::GJSearchObject* obj) {
// if (!matdash::orig<&LevelBrowserLayer_init>(self, obj)) return false;
//
// if (obj->m_type == gd::SearchType::MyLevels) {
// auto menu = CCMenu::create();
// menu->setPosition(CCDirector::sharedDirector()->getWinSize().width - 30.f, 90);
// self->addChild(menu);
// constexpr auto handler = [](CCObject*, CCObject*) {
// nfdchar_t* path = nullptr;
// if (NFD_OpenDialog("gmd", nullptr, &path) == NFD_OKAY) {
// std::ifstream file(path);
// auto* const level = import_level(file);
// free(path);
// if (!level) {
// gd::FLAlertLayer::create(nullptr, "Error", "Failed to import", "OK", nullptr, 320.f, false, 0)->show();
// return;
// }
// auto scene = gd::EditLevelLayer::scene(level);
// CCDirector::sharedDirector()->pushScene(scene);
// }
// };
//
// auto btn_spr = CCSprite::createWithSpriteFrameName("GJ_downloadBtn_001.png");
// if (!btn_spr->initWithFile("BE_Import_File.png")) {
// btn_spr->initWithSpriteFrameName("GJ_downloadBtn_001.png");
// }
//
// auto button = gd::CCMenuItemSpriteExtra::create(btn_spr, nullptr, self, to_handler<SEL_MenuHandler, handler>);
//
// // auto button = CCMenuItemSpriteExtra::create(
// // ButtonSprite::create("import", 40, 0, 0.5f, false, "goldFont.fnt", "GJ_button_01.png", 30),
// // nullptr, self, to_handler<SEL_MenuHandler, handler>
// // );
// menu->setZOrder(1);
// menu->addChild(button);
// }
//
// return true;
//}
//
//
//void lvl_share::init() {
// matdash::add_hook<&EditLevelLayer_init>(gd::base + 0x3b5a0);
// matdash::add_hook<&LevelBrowserLayer_init>(gd::base + 0x89590);
// matdash::add_hook<&LevelInfoLayer_init>(gd::base + 0x9bc10);
//}