From 803df4faebdfa3568c9ed19f84f5b58a4eebca38 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Mon, 12 Feb 2024 18:39:46 +0300 Subject: [PATCH] edit is_jsons to be more detailed --- loader/include/Geode/utils/VersionInfo.hpp | 6 +++++- loader/src/utils/cocos.cpp | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/loader/include/Geode/utils/VersionInfo.hpp b/loader/include/Geode/utils/VersionInfo.hpp index 3aca9db6..9c6827c2 100644 --- a/loader/include/Geode/utils/VersionInfo.hpp +++ b/loader/include/Geode/utils/VersionInfo.hpp @@ -240,7 +240,11 @@ struct matjson::Serialize { } static bool is_json(matjson::Value const& json) { - return json.is_string(); + if (json.is_string()) { + auto ver = V::parse(json.as_string()); + return !ver.isErr(); + } + return false; } static V from_json(matjson::Value const& json) { diff --git a/loader/src/utils/cocos.cpp b/loader/src/utils/cocos.cpp index 8ae980b6..ec319a16 100644 --- a/loader/src/utils/cocos.cpp +++ b/loader/src/utils/cocos.cpp @@ -8,7 +8,16 @@ using namespace geode::prelude; bool matjson::Serialize::is_json(matjson::Value const& json) { - return json.is_array() || json.is_object() || json.is_string(); + if (json.is_array()) { + return json.as_array().size() == 3; + } + if (json.is_object()) { + return json.contains("r") && json.contains("g") && json.contains("b"); + } + if (json.is_string()) { + return !cc3bFromHexString(json.as_string()).isErr(); + } + return false; } matjson::Value matjson::Serialize::to_json(ccColor3B const& color) { @@ -54,7 +63,16 @@ ccColor3B matjson::Serialize::from_json(matjson::Value const& json) { } bool matjson::Serialize::is_json(matjson::Value const& json) { - return json.is_array() || json.is_object() || json.is_string(); + if (json.is_array()) { + return json.as_array().size() == 4; + } + if (json.is_object()) { + return json.contains("r") && json.contains("g") && json.contains("b") && json.contains("a"); + } + if (json.is_string()) { + return !cc4bFromHexString(json.as_string()).isErr(); + } + return false; } matjson::Value matjson::Serialize::to_json(ccColor4B const& color) {