Skip to content

Commit

Permalink
Added a part of gd protocol
Browse files Browse the repository at this point in the history
TO DO : Make that the level is shown on LevelInfoLayer (plz Firee)
  • Loading branch information
Jouca committed Jan 11, 2024
1 parent dc106f7 commit 4746d66
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "C:\\Users\\proga\\Desktop\\ClarifyGDPS 2.2 GEODE\\ClarifyGDPS.exe",
"program": "C:\\Users\\proga\\Desktop\\ClarifyGDPS 2.202 GEODE\\GeometryDash.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\Users\\proga\\Desktop\\ClarifyGDPS 2.2 GEODE\\",
"cwd": "C:\\Users\\proga\\Desktop\\ClarifyGDPS 2.202 GEODE\\",
"environment": [],
"console": "internalConsole"
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventsPush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void EventsPush::onClickBtn(CCObject* ret) {
int level_id = events_layer->levelId;
#endif
//std::string const& url = "https://clarifygdps.com/getGJLevels21.php";
std::string const& fields = "secret=Wmfd2893gb7&gameVersion=21&type=0&binaryVersion=35&gdw=0&diff=-&len=-&count=1&str=" + std::to_string(level_id);
std::string const& fields = "secret=Wmfd2893gb7&gameVersion=22&type=0&binaryVersion=35&gdw=0&diff=-&len=-&count=1&str=" + std::to_string(level_id);
web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
Expand Down
158 changes: 158 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void processEvent(CCScene* self) {
EventsPush::pushRateLevel(self, data);
}
}

class $modify(CCScheduler) { // used to be GameManager
void update(float dt) {
CCScheduler::update(dt);
Expand All @@ -142,6 +143,7 @@ class $modify(CCScheduler) { // used to be GameManager
}
std::string layerName = misc::getNodeName(layer);
if (layerName == "cocos2d::CCLayerColor") return;
if (layerName == "LoadingLayer") return;
if (currentLayer != layerName) {
//Discord::update(layerName.c_str()); for next update ;)
currentLayer = layerName;
Expand Down Expand Up @@ -175,6 +177,58 @@ class $modify(CCScheduler) { // used to be GameManager
}
};

class $modify(CCScheduler) { // GD Protocol part
void update(float dt) {
CCScheduler::update(dt);
auto scene = CCDirector::sharedDirector()->getRunningScene();
if (scene->getChildrenCount() == 0) return;
auto layer = scene->getChildren()->objectAtIndex(0);
if (layer == nullptr) return;
if (ProcessLambdas::shouldProcessMenuHandler()) {
ProcessLambdas::processMenuHandler();
}
std::string layerName = misc::getNodeName(layer);

if (layerName == "LevelEditorLayer") return;
if (layerName == "PlayLayer") return;
if (layerName == "LoadingLayer") return;

for (const auto & entry : std::filesystem::directory_iterator("gdutils")) {
if (entry.path().extension() == ".flag") {
std::string path = entry.path().string();
std::string filename = entry.path().filename().string();
std::string levelName = filename.substr(0, filename.length() - 4);

std::filesystem::remove("gdutils/" + filename);

auto glm = GameLevelManager::sharedState();
std::string const& url = "https://www.boomlings.com/database/getGJLevels21.php";
std::string const& fields = "secret=Wmfd2893gb7&gameVersion=22&type=0&binaryVersion=35&gdw=0&diff=-&len=-&count=1&str=" + levelName;
web::AsyncWebRequest()
.bodyRaw(fields)
.postRequest()
.fetch(url).text()
.then([&](std::string & response) {
std::cout << response << std::endl;
if (response != "-1") {
auto scene = CCScene::create();
auto dict = glm->responseToDict(gd::string(response), false);
auto gjgl = GJGameLevel::create(dict, false);
auto layer = LevelInfoLayer::create(gjgl, false);
layer->downloadLevel();
scene->addChild(layer);
CCDirector::sharedDirector()->pushScene(cocos2d::CCTransitionFade::create(0.5f, scene));
} else {
log::info("Level not found. (-1)");
}
}).expect([](std::string const& error) {
log::error("Error occured while doing a web request: " + error);
});
}
}
}
};

// Spotify
bool is_muted = false;
#ifdef GEODE_IS_WINDOWS
Expand Down Expand Up @@ -968,5 +1022,109 @@ class $modify(LevelInfoLayer) {
#endif
//Mod::get()->addCustomSetting<class T>(const std::string &key, "Spotify.exe");
Mod::get()->addCustomSetting<SettingCreditsValue>("credit-buttons", "none");

#ifdef GEODE_IS_WINDOWS
#include <Windows.h>
#include <iostream>

std::array<WCHAR, MAX_PATH> buffer;
GetModuleFileNameW(NULL, buffer.data(), MAX_PATH);
auto aaaa = buffer.data();
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string nameStr = fmt::format("cmd /k cd \"{}\\gdutils\" && \"gd_protocol.bat\" %1 && exit", dirs::getGameDir());

std::wstring fullPath = std::wstring(buffer.data());
size_t lastBackslashPos = fullPath.find_last_of(L"\\");
std::wstring exeName;
if (lastBackslashPos != std::wstring::npos) {
exeName = fullPath.substr(lastBackslashPos + 1);
}

// Create the key for the custom protocol in user registry
HKEY hCurrentUserKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Classes", 0, KEY_SET_VALUE, &hCurrentUserKey) == ERROR_SUCCESS) {
HKEY hKey;
if (RegCreateKeyEx(hCurrentUserKey, "gdutils", 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
// Define the default value for the protocol key
if (RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)"URL:gdutils Protocol", sizeof("URL:gdutils Protocol")) == ERROR_SUCCESS) {
// Create the key "shell\open\command" for specify the exe path
HKEY hCommandKey;
if (RegCreateKeyEx(hKey, "shell\\open\\command", 0, NULL, 0, KEY_SET_VALUE, NULL, &hCommandKey, NULL) == ERROR_SUCCESS) {
if (RegSetValueExA(hCommandKey, NULL, 0, REG_SZ, (const BYTE*)nameStr.c_str(), nameStr.length() + 1) == ERROR_SUCCESS) {
log::info("Le protocole a été enregistré avec succès pour cet utilisateur.");
} else {
log::error("Erreur lors de la définition de la valeur du chemin de l'exécutable.");
}
RegCloseKey(hCommandKey);
} else {
log::error("Erreur lors de la création de la clé shell\\open\\command.");
}

RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, NULL, NULL);
} else {
log::error("Erreur lors de la définition de la valeur par défaut du protocole.");
}
RegCloseKey(hKey);
} else {
log::error("Erreur lors de la création de la clé du protocole.");
}
RegCloseKey(hCurrentUserKey);
} else {
log::error("Erreur lors de l'ouverture de la clé du registre utilisateur.");
}

ghc::filesystem::create_directory("gdutils");
if (!ghc::filesystem::exists("gdutils/gd_protocol.bat")) {
std::ofstream file("gdutils/gd_protocol.bat");
file << R"(
@echo off
setlocal enabledelayedexpansion
)";
file << fmt::format("set \"appName={}\"", converter.to_bytes(exeName));
file << R"(
set "argument=%1"
set "number="
REM Check if the argument contains /
echo !argument! | find "/" > nul
if not errorlevel 1 (
REM If / is found, extract the number part after the /
for /f "tokens=2 delims=/" %%a in ("!argument!") do (
set "number=%%a"
)
) else (
REM If / is not found, the argument is in the format gdutils:123
for /f "tokens=2 delims=:" %%a in ("!argument!") do (
set "number=%%a"
)
)
if not defined number (
echo Invalid argument format: %1
exit /b 1
)
set "flagFile=%number%.flag"
REM Check if the application is already running
tasklist /FI "IMAGENAME eq %appName%" | find /i "%appName%" > nul
if errorlevel 1 (
REM If not running, start the application with the provided argument
cd ..
start "" "%appName%"
cd gdutils
type nul > "%flagFile%"
) else (
REM If running, create an empty file based on the extracted number
type nul > "%flagFile%"
)
endlocal
)";
file.close();
}

#endif
}

0 comments on commit 4746d66

Please sign in to comment.