Skip to content

Commit

Permalink
beta 31
Browse files Browse the repository at this point in the history
  • Loading branch information
Minemaker0430 committed Jul 3, 2024
1 parent 4ee0175 commit 27f881b
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 27 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ project(GDDPIntegration VERSION 1.0.0)
add_library(${PROJECT_NAME} SHARED
src/main.cpp
# Add your cpp files here
src/CreatorLayer.cpp
src/LevelInfoLayer.cpp
src/LevelCell.cpp
src/hooks/CreatorLayer.cpp
src/hooks/LevelInfoLayer.cpp
src/hooks/LevelCell.cpp
src/ListManager.cpp
src/StatsPopup.cpp
src/Utils.cpp
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v1.0.0-beta.31

* Added JSON Validation checks to prevent crashes.
* Depreciated "listID", "practiceID", and "totalLevels"
* You will maintain your progress to a rank even if a level is moved to Legacy
* Note that this does not apply for Plus Ranks.

# v1.0.0-beta.30

* Attempted to fix crashes (again)
Expand Down
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"win": "2.206",
"android": "2.206"
},
"version": "v1.0.0-beta.30",
"version": "v1.0.0-beta.31",
"id": "minemaker0430.gddp_integration",
"name": "GDDP Integration",
"developer": "Minemaker0430",
Expand Down Expand Up @@ -42,7 +42,7 @@
"dependencies": [
{
"id": "geode.node-ids",
"version": ">=1.12.0",
"version": ">=1.13.1",
"importance": "required"
}
],
Expand Down
28 changes: 23 additions & 5 deletions src/DPLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//other headers
#include <Geode/utils/web.hpp>
#include <Geode/loader/Event.hpp>
#include <Geode/utils/JsonValidation.hpp>

#include "DPLayer.hpp"
#include "DPListLayer.hpp"
Expand Down Expand Up @@ -122,7 +123,11 @@ void DPLayer::reloadData(bool isInit) {
}
else {
m_loadcircle->fadeAndRemove();
FLAlertLayer::create("ERROR", fmt::format("Something went wrong getting the List Data. ({})", res->code()), "OK")->show();
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong getting the List Data. ({}, {})", res->code(), res->json().has_error()), "OK");
alert->m_scene = this;
alert->show();

m_finishedLoading = true;
}
}
else if (e->isCancelled()) {
Expand All @@ -147,7 +152,9 @@ void DPLayer::reloadData(bool isInit) {
}
}
else {
FLAlertLayer::create("ERROR", fmt::format("Something went wrong getting the Skillset Data. ({})", res->code()), "OK")->show();
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong getting the Skillset Data. ({}, {})", res->code(), res->json().has_error()), "OK");
alert->m_scene = this;
alert->show();
}
}
else if (e->isCancelled()) {
Expand Down Expand Up @@ -429,6 +436,17 @@ bool DPLayer::init() {

void DPLayer::reloadList(int type) {

//check for errors
auto jsonCheck = JsonChecker(m_data);

if (jsonCheck.isError()) {
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong validating the list data. ({})", jsonCheck.getError()), "OK");
alert->setParent(this);
alert->show();

return;
}

//all save stuff
auto localDatabaseVer = Mod::get()->getSavedValue<int>("database-version", 0);

Expand Down Expand Up @@ -465,7 +483,7 @@ void DPLayer::reloadList(int type) {
std::string name = "null";
std::string sprite = "DP_Beginner";
std::string plusSprite = "DP_BeginnerPlus"; //Main Only
int listID = 0;
//int listID = 0;
std::string saveID = "beginner";
matjson::Array levelIDs = {};
matjson::Array practiceIDs = {};
Expand All @@ -478,7 +496,7 @@ void DPLayer::reloadList(int type) {
name = m_data[dataIdx][i]["name"].as_string();
sprite = m_data[dataIdx][i]["sprite"].as_string();
if (type == static_cast<int>(DPListType::Main)) { plusSprite = m_data[dataIdx][i]["plusSprite"].as_string(); }
listID = m_data[dataIdx][i]["listID"].as_int(); //only used to obtain old saves
//listID = m_data[dataIdx][i]["listID"].as_int(); //only used to obtain old saves
if (type != static_cast<int>(DPListType::Monthly)) { saveID = m_data[dataIdx][i]["saveID"].as_string(); }
levelIDs = m_data[dataIdx][i]["levelIDs"].as_array();
if (type == static_cast<int>(DPListType::Main)) { practiceIDs = m_data[dataIdx][i]["practiceIDs"].as_array(); }
Expand All @@ -491,7 +509,7 @@ void DPLayer::reloadList(int type) {
if (type == static_cast<int>(DPListType::Monthly)) { saveID = fmt::format("{}-{}", month, year); }

//get list save
auto listSave = Mod::get()->getSavedValue<ListSaveFormat>(saveID, Mod::get()->getSavedValue<ListSaveFormat>(std::to_string(listID)));
auto listSave = Mod::get()->getSavedValue<ListSaveFormat>(saveID);

auto fullTitle = name;
if (type == static_cast<int>(DPListType::Main) || type == static_cast<int>(DPListType::Legacy)) {
Expand Down
23 changes: 18 additions & 5 deletions src/DPListLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//other headers
#include <Geode/utils/web.hpp>
#include <Geode/utils/JsonValidation.hpp>
#include <Geode/loader/Event.hpp>

#include "DPLayer.hpp"
Expand Down Expand Up @@ -64,8 +65,16 @@ bool DPListLayer::init(const char* type, int id, bool isPractice) {
backMenu->setID("back-menu");
this->addChild(backMenu);

//check for actual data
if (!data.contains("main")) { return true; }
//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong validating the list data. ({})", jsonCheck.getError()), "OK");
alert->setParent(this);
alert->show();

return true;
}

//info button
auto infoMenu = CCMenu::create();
Expand Down Expand Up @@ -287,6 +296,10 @@ void DPListLayer::updateSave() {
}
}

if (m_type == "main" && !listSave.hasRank && progress < listSave.progress) { //If you don't have the rank, any progress you have will be maintained even if a level is moved to legacy
progress == listSave.progress;
}

//update status
auto reqLevels = 0;
if (m_type == "main") { reqLevels = data[m_type][m_id]["reqLevels"].as_int(); }
Expand Down Expand Up @@ -315,15 +328,15 @@ void DPListLayer::updateSave() {
if (m_type == "monthly" && progress >= 5) {
auto completedMonthlies = Mod::get()->getSavedValue<matjson::Array>("monthly-completions");

auto listID = data[m_type][m_id]["listID"].as_int(); //Only used for obtaining old data
//auto listID = data[m_type][m_id]["listID"].as_int(); //Only used for obtaining old data

//replace old monthly data if it exists
if (std::find(completedMonthlies.begin(), completedMonthlies.end(), listID) != completedMonthlies.end()) {
/*if (std::find(completedMonthlies.begin(), completedMonthlies.end(), listID) != completedMonthlies.end()) {
auto pos = std::find(completedMonthlies.begin(), completedMonthlies.end(), listID);
completedMonthlies.erase(pos);
completedMonthlies.insert(pos, saveID);
Mod::get()->setSavedValue<matjson::Array>("monthly-completions", completedMonthlies);
}
}*/

if (std::find(completedMonthlies.begin(), completedMonthlies.end(), saveID) == completedMonthlies.end()) {
completedMonthlies.insert(completedMonthlies.begin(), saveID);
Expand Down
30 changes: 29 additions & 1 deletion src/StatsPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <Geode/Geode.hpp>

//other headers
#include <Geode/utils/JsonValidation.hpp>

#include "DPLayer.hpp"
#include "StatsPopup.hpp"

Expand Down Expand Up @@ -84,7 +86,14 @@ void StatsPopup::loadTab(int id) {

auto data = Mod::get()->getSavedValue<matjson::Value>("cached-data");

if (!data.contains("main")) {
//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong validating the list data. ({})", jsonCheck.getError()), "OK");
alert->setParent(this);
alert->show();

return;
}

Expand Down Expand Up @@ -1072,6 +1081,15 @@ int StatsPopup::getScore() {

auto data = Mod::get()->getSavedValue<matjson::Value>("cached-data");

//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
log::info("Something went wrong validating the list data. ({})", jsonCheck.getError());

return 0; //NO WAY GEOMETRY DASH REFERENCE OOOOOOOOOOOOOOOO
}

auto score = 0;

for (int i = 0; i < data["main"].as_array().size(); i++) {
Expand All @@ -1088,6 +1106,16 @@ int StatsPopup::getScore() {
float StatsPopup::getPercentToRank(int rankID, bool isPlus) {

auto data = Mod::get()->getSavedValue<matjson::Value>("cached-data");

//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
log::info("Something went wrong validating the list data. ({})", jsonCheck.getError());

return 0.f;
}

auto progress = 0;
auto totalLvls = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/CreatorLayer.cpp → src/hooks/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <Geode/Geode.hpp>

#include <Geode/modify/CreatorLayer.hpp>
#include "DPLayer.hpp"
#include "../DPLayer.hpp"

//geode namespace
using namespace geode::prelude;
Expand All @@ -17,7 +17,7 @@ class $modify(CreatorLayer) {
bool init() {
if (!CreatorLayer::init()) return false;

if (Mod::get()->getSavedValue<int>("database-version", 9) < 9) {
if (Mod::get()->getSavedValue<int>("database-version", 10) < 10) {
auto alert = FLAlertLayer::create(
"IMPORTANT",
"Your GDDP Data is outdated. Go into the menu to refresh it.\n\nCustom Difficulty Faces have been disabled for now.",
Expand Down
24 changes: 20 additions & 4 deletions src/LevelCell.cpp → src/hooks/LevelCell.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//geode header
#include <Geode/Geode.hpp>

#include <Geode/utils/JsonValidation.hpp>
#include <Geode/modify/LevelCell.hpp>
#include "DPLayer.hpp"
#include "ListManager.hpp"
#include "../DPLayer.hpp"
#include "../ListManager.hpp"

//geode namespace
using namespace geode::prelude;
Expand Down Expand Up @@ -35,7 +36,14 @@ class $modify(DemonProgression, LevelCell) {
inGDDP = true;
}

if (Mod::get()->getSavedValue<int>("database-version", 0) < 9) { return; }
//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
log::info("Something went wrong validating the list data. ({})", jsonCheck.getError());

return;
}

//log::info("{}", inGDDP);

Expand All @@ -58,13 +66,21 @@ class $modify(DemonProgression, LevelCell) {
auto type = Mod::get()->getSavedValue<std::string>("current-pack-type", "main");
auto id = Mod::get()->getSavedValue<int>("current-pack-index", 0);
auto reqLevels = Mod::get()->getSavedValue<int>("current-pack-requirement", 0);
auto totalLevels = Mod::get()->getSavedValue<int>("current-pack-totalLvls", 0);

auto hasRank = Mod::get()->getSavedValue<ListSaveFormat>(data[type][id]["saveID"].as_string()).hasRank;

auto data = Mod::get()->getSavedValue<matjson::Value>("cached-data");
auto skillsetData = Mod::get()->getSavedValue<matjson::Value>("skillset-info", matjson::parse("{\"unknown\": {\"display-name\": \"Unknown\",\"description\": \"This skill does not have a description.\",\"sprite\": \"DP_Skill_Unknown\"}}"));

//check for errors
auto jsonCheck2 = JsonChecker(skillsetData);

if (jsonCheck2.isError()) {
log::info("Something went wrong validating the skillset data. ({})", jsonCheck2.getError());

return;
}

int gddpDiff = 0;
matjson::Array skillsets = {};

Expand Down
30 changes: 25 additions & 5 deletions src/LevelInfoLayer.cpp → src/hooks/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//geode header
#include <Geode/Geode.hpp>

#include <Geode/utils/JsonValidation.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>
#include "DPLayer.hpp"
#include "ListManager.hpp"
#include "../DPLayer.hpp"
#include "../ListManager.hpp"

//geode namespace
using namespace geode::prelude;
Expand All @@ -30,10 +31,19 @@ class $modify(DemonProgression, LevelInfoLayer) {
bool init(GJGameLevel* p0, bool p1) {
if (!LevelInfoLayer::init(p0, p1)) return false;

if (Mod::get()->getSavedValue<int>("database-version", 0) < 9) { return true; }

auto data = Mod::get()->getSavedValue<matjson::Value>("cached-data");

//check for errors
auto jsonCheck = JsonChecker(data);

if (jsonCheck.isError()) {
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong validating the list data. ({})", jsonCheck.getError()), "OK");
alert->setParent(this);
alert->show();

return true;
}

bool inGDDP = Mod::get()->getSavedValue<bool>("in-gddp");

if (Mod::get()->getSettingValue<bool>("show-outside-menus")) {
Expand Down Expand Up @@ -66,14 +76,24 @@ class $modify(DemonProgression, LevelInfoLayer) {
auto type = Mod::get()->getSavedValue<std::string>("current-pack-type", "main");
auto id = Mod::get()->getSavedValue<int>("current-pack-index", 0);
auto reqLevels = Mod::get()->getSavedValue<int>("current-pack-requirement", 0);
auto totalLevels = Mod::get()->getSavedValue<int>("current-pack-totalLvls", 0);

auto hasRank = Mod::get()->getSavedValue<ListSaveFormat>(data[type][id]["saveID"].as_string()).hasRank;

auto diffSpr = typeinfo_cast<GJDifficultySprite*>(this->getChildByID("difficulty-sprite"));

auto skillsetData = Mod::get()->getSavedValue<matjson::Value>("skillset-info", matjson::parse("{\"unknown\": {\"display-name\": \"Unknown\",\"description\": \"This skill does not have a description.\",\"sprite\": \"DP_Skill_Unknown\"}}"));

//check for errors
auto jsonCheck2 = JsonChecker(skillsetData);

if (jsonCheck2.isError()) {
auto alert = FLAlertLayer::create("ERROR", fmt::format("Something went wrong validating the skillset data. ({})", jsonCheck2.getError()), "OK");
alert->setParent(this);
alert->show();

return true;
}

int gddpDiff = 0;
matjson::Array skillsets = {};

Expand Down
Loading

0 comments on commit 27f881b

Please sign in to comment.