Skip to content

Commit

Permalink
matjson 3/3, compiles but mod about.md dont load for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Nov 9, 2024
1 parent d1d34aa commit 9ed55c4
Show file tree
Hide file tree
Showing 33 changed files with 142 additions and 141 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ if (ANDROID)
endif()

set(MAT_JSON_AS_INTERFACE ON)
CPMAddPackage("gh:geode-sdk/json#1b182dd")
CPMAddPackage("gh:geode-sdk/[email protected]")
CPMAddPackage("gh:geode-sdk/json#8c6c325")
CPMAddPackage("gh:fmtlib/fmt#10.2.1")

target_compile_definitions(${PROJECT_NAME} INTERFACE MAT_JSON_DYNAMIC=1)
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/cocos/base_nodes/CCNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <Geode/utils/casts.hpp>

#ifndef GEODE_IS_MEMBER_TEST
#include <matjson3.hpp>
#include <matjson.hpp>
#endif

namespace geode {
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include "../utils/general.hpp"
#include <matjson3.hpp>
#include <matjson.hpp>
#include "Tulip.hpp"
#include <cinttypes>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/IPC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Event.hpp"
#include "Loader.hpp"
#include "Mod.hpp"
#include <matjson3.hpp>
#include <matjson.hpp>

namespace geode::ipc {
#ifdef GEODE_IS_WINDOWS
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Types.hpp"

#include <atomic>
#include <matjson3.hpp>
#include <matjson.hpp>
#include <mutex>
#include <optional>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <ccTypes.h>
#include <chrono>
#include <filesystem>
#include <matjson3.hpp>
#include <matjson.hpp>
#include <type_traits>
#include <fmt/core.h>
// for formatting std::vector and such
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Types.hpp"
#include "Loader.hpp"

#include <matjson3.hpp>
#include <matjson.hpp>
#include <matjson/stl_serialize.hpp>
#include <optional>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/ModMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../utils/VersionInfo.hpp"
#include "Types.hpp"

#include <matjson3.hpp>
#include <matjson.hpp>
#include <memory>

namespace geode {
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include "../platform/cplatform.h"
#include <matjson3.hpp>
#include <matjson.hpp>

#include <string>

Expand Down
9 changes: 8 additions & 1 deletion loader/include/Geode/utils/JsonValidation.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <matjson3.hpp>
#include <matjson.hpp>
#include "../loader/Log.hpp"
#include <set>
#include <variant>
Expand Down Expand Up @@ -223,6 +223,13 @@ namespace geode {
* @returns The key, which is a no-op value if it didn't exist
*/
JsonExpectedValue has(std::string_view key);
/**
* Check if this object has an optional key. Asserts that this JSON
* value is an object. If the key doesn't exist, or the value is null, returns a
* `JsonExpectValue` that does nothing
* @returns The key, which is a no-op value if it didn't exist, or was null
*/
JsonExpectedValue hasNullable(std::string_view key);
/**
* Check if this object has an optional key. Asserts that this JSON
* value is an object. If the key doesn't exist, sets an error and
Expand Down
8 changes: 4 additions & 4 deletions loader/include/Geode/utils/VersionInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include <string_view>
#include <matjson3.hpp>
#include <matjson.hpp>
#include <tuple>
#include <Geode/Result.hpp>

Expand Down Expand Up @@ -258,9 +258,9 @@ requires std::is_same_v<V, geode::VersionInfo> || std::is_same_v<V, geode::Compa
struct matjson::Serialize<V> {
static geode::Result<V, std::string> fromJson(Value const& value)
{
auto str = GEODE_UNWRAP(value.asString());
auto version = GEODE_UNWRAP(V::parse(str).mapErr([](auto&& err) {
return geode::Err("Invalid version format: {}", err);
GEODE_UNWRAP_INTO(auto str, value.asString());
GEODE_UNWRAP_INTO(auto version, V::parse(str).mapErr([](auto&& err) {
return fmt::format("Invalid version format: {}", err);
}));
return geode::Ok(version);
}
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/utils/cocos.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <matjson3.hpp>
#include <matjson.hpp>
#include "casts.hpp"
#include "general.hpp"
#include "../DefaultInclude.hpp"
Expand Down
4 changes: 2 additions & 2 deletions loader/include/Geode/utils/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../loader/Event.hpp"
#include "Task.hpp"

#include <matjson3.hpp>
#include <matjson.hpp>
#include <Geode/DefaultInclude.hpp>
#include <filesystem>
#include <string>
Expand All @@ -15,7 +15,7 @@ template <>
struct matjson::Serialize<std::filesystem::path> {
static geode::Result<std::filesystem::path, std::string> fromJson(Value const& value)
{
auto str = GEODE_UNWRAP(value.asString());
GEODE_UNWRAP_INTO(auto str, value.asString());
return geode::Ok(std::filesystem::path(str).make_preferred());
}

Expand Down
7 changes: 3 additions & 4 deletions loader/include/Geode/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <string>
#include <vector>
#include <filesystem>
#include <matjson3.hpp>
#include <matjson.hpp>
#include <charconv>
#include <clocale>
#include <type_traits>
Expand Down Expand Up @@ -170,9 +170,8 @@ namespace geode {

template<>
struct matjson::Serialize<geode::ByteVector> {
static Value toJson(geode::ByteVector const& bytes)
{
return matjson::Array(bytes.begin(), bytes.end());
static Value toJson(geode::ByteVector const& bytes) {
return std::vector<matjson::Value>(bytes.begin(), bytes.end());
}
};

Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/utils/web.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Geode/loader/Loader.hpp> // another great circular dependency fix
#include <matjson3.hpp>
#include <matjson.hpp>
#include <Geode/Result.hpp>
#include "Task.hpp"
#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/HookImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ std::string_view Hook::Impl::getDisplayName() const {
}

matjson::Value Hook::Impl::getRuntimeInfo() const {
auto json = matjson::Object();
matjson::Value json;
json["address"] = std::to_string(reinterpret_cast<uintptr_t>(m_address));
json["detour"] = std::to_string(reinterpret_cast<uintptr_t>(m_detour));
json["name"] = m_displayName;
Expand Down
4 changes: 2 additions & 2 deletions loader/src/loader/IPC.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Geode/loader/IPC.hpp>
#include "IPC.hpp"
#include <matjson3.hpp>
#include <matjson.hpp>
#include <Geode/loader/Mod.hpp>

using namespace geode::prelude;
Expand Down Expand Up @@ -34,7 +34,7 @@ matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) {
matjson::Value reply;

auto res = matjson::Value::parse(buffer);
if (error.size() > 0) {
if (!res) {
log::warn("Received IPC message that isn't valid JSON: {}", res.unwrapErr());
return reply;
}
Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/IPC.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <string>
#include <matjson3.hpp>
#include <matjson.hpp>

namespace geode::ipc {
void setup();
Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/LoaderImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "FileWatcher.hpp"

#include <matjson3.hpp>
#include <matjson.hpp>
#include <Geode/loader/Dirs.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Log.hpp>
Expand Down
42 changes: 20 additions & 22 deletions loader/src/loader/ModImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,12 @@ Result<> Mod::Impl::loadData() {
auto savedPath = m_saveDirPath / "saved.json";
if (std::filesystem::exists(savedPath)) {
GEODE_UNWRAP_INTO(auto data, utils::file::readString(savedPath));
std::string error;
auto res = matjson::parse(data, error);
if (error.size() > 0) {
return Err("Unable to parse saved values: " + error);
}
m_saved = res.value();
if (!m_saved.is_object()) {
m_saved = GEODE_UNWRAP(matjson::parse(data).mapErr([](auto&& err) {
return fmt::format("Unable to parse saved values: {}", err);
}));
if (!m_saved.isObject()) {
log::warn("saved.json was somehow not an object, forcing it to one");
m_saved = matjson::Object();
m_saved = matjson::Value::object();
}
}

Expand All @@ -218,11 +215,15 @@ Result<> Mod::Impl::saveData() {
// saveData is expected to be synchronous, and always called from GD thread
ModStateEvent(m_self, ModEventType::DataSaved).post();

auto res = utils::file::writeString(m_saveDirPath / "settings.json", json.dump());
auto res = json.dump().andThen([&](auto const& str) {
return utils::file::writeString(m_saveDirPath / "settings.json", str);
});
if (!res) {
log::error("Unable to save settings: {}", res.unwrapErr());
}
auto res2 = utils::file::writeString(m_saveDirPath / "saved.json", m_saved.dump());
auto res2 = m_saved.dump().andThen([&](auto const& str) {
return utils::file::writeString(m_saveDirPath / "saved.json", str);
});
if (!res2) {
log::error("Unable to save values: {}", res2.unwrapErr());
}
Expand Down Expand Up @@ -387,7 +388,7 @@ Result<> Mod::Impl::uninstall(bool deleteSaveData) {
ModRequestedAction::Uninstall;

// Make loader forget the mod should be disabled
Mod::get()->getSaveContainer().try_erase("should-load-" + m_metadata.getID());
Mod::get()->getSaveContainer().erase("should-load-" + m_metadata.getID());

std::error_code ec;
std::filesystem::remove(m_metadata.getPath(), ec);
Expand Down Expand Up @@ -674,14 +675,14 @@ std::string_view Mod::Impl::expandSpriteName(std::string_view name) {
ModJson Mod::Impl::getRuntimeInfo() const {
auto json = m_metadata.toJSON();

auto obj = matjson::Object();
obj["hooks"] = matjson::Array();
auto obj = matjson::Value::object();
obj["hooks"] = matjson::Value::array();
for (auto hook : m_hooks) {
obj["hooks"].as_array().push_back(ModJson(hook->getRuntimeInfo()));
obj["hooks"].push(ModJson(hook->getRuntimeInfo()));
}
obj["patches"] = matjson::Array();
obj["patches"] = matjson::Value::array();
for (auto patch : m_patches) {
obj["patches"].as_array().push_back(ModJson(patch->getRuntimeInfo()));
obj["patches"].push(ModJson(patch->getRuntimeInfo()));
}
obj["loaded"] = m_enabled;
obj["temp-dir"] = this->getTempDir();
Expand Down Expand Up @@ -722,12 +723,9 @@ std::vector<LoadProblem> Mod::Impl::getProblems() const {
}

static Result<ModMetadata> getModImplInfo() {
std::string error;
auto res = matjson::parse(about::getLoaderModJson(), error);
if (error.size() > 0) {
return Err("Unable to parse mod.json: " + error);
}
matjson::Value json = res.value();
auto json = GEODE_UNWRAP(matjson::parse(about::getLoaderModJson()).mapErr([](auto&& err) {
return fmt::format("Unable to parse mod.json: {}", err);
}));

GEODE_UNWRAP_INTO(auto info, ModMetadata::create(json));
return Ok(info);
Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/ModImpl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <matjson3.hpp>
#include <matjson.hpp>
#include "ModPatch.hpp"
#include <Geode/loader/Loader.hpp>
#include <string_view>
Expand Down
39 changes: 15 additions & 24 deletions loader/src/loader/ModMetadataImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Geode/utils/string.hpp>
#include <Geode/utils/general.hpp>
#include <about.hpp>
#include <matjson3.hpp>
#include <matjson.hpp>
#include <utility>
#include <clocale>

Expand Down Expand Up @@ -113,14 +113,14 @@ Result<ModMetadata> ModMetadata::Impl::createFromSchemaV010(ModJson const& rawJs

auto checkerRoot = fmt::format(
"[{}/v0.0.0/mod.json]",
rawJson.contains("id") ? rawJson["id"].as_string() : "unknown.mod"
rawJson.contains("id") ? GEODE_UNWRAP(rawJson["id"].asString()) : "unknown.mod"
);
// JsonChecker did it this way too
try {
checkerRoot = fmt::format(
"[{}/{}/mod.json]",
rawJson.contains("id") ? rawJson["id"].as_string() : "unknown.mod",
rawJson.contains("version") ? rawJson["version"].as<VersionInfo>().toVString() : "v0.0.0"
rawJson.contains("id") ? GEODE_UNWRAP(rawJson["id"].asString()) : "unknown.mod",
rawJson.contains("version") ? GEODE_UNWRAP(rawJson["version"].as<VersionInfo>()).toVString() : "v0.0.0"
);
}
catch (...) { }
Expand Down Expand Up @@ -304,10 +304,10 @@ Result<ModMetadata> ModMetadata::Impl::createFromSchemaV010(ModJson const& rawJs
Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
// Check mod.json target version
auto schema = about::getLoaderVersion();
if (json.contains("geode") && json["geode"].is_string()) {
if (json.contains("geode") && json["geode"].isString()) {
GEODE_UNWRAP_INTO(
schema,
VersionInfo::parse(json["geode"].as_string()).mapErr(
VersionInfo::parse(GEODE_UNWRAP(json["geode"].asString())).mapErr(
[](auto const& err) {
return fmt::format("[mod.json] has invalid target loader version: {}", err);
}
Expand Down Expand Up @@ -355,13 +355,9 @@ Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
Result<ModMetadata> ModMetadata::Impl::createFromFile(std::filesystem::path const& path) {
GEODE_UNWRAP_INTO(auto read, utils::file::readString(path));

std::string error;
auto res = matjson::parse(read, error);
if (error.size() > 0) {
return Err(std::string("Unable to parse mod.json: ") + error);
}

GEODE_UNWRAP_INTO(auto info, ModMetadata::create(res.value()));
GEODE_UNWRAP_INTO(auto info, ModMetadata::create(GEODE_UNWRAP(matjson::parse(read).mapErr([&](auto const& err) {
return fmt::format("Unable to parse mod.json: {}", err);
}))));

auto impl = info.m_impl.get();

Expand Down Expand Up @@ -390,18 +386,13 @@ Result<ModMetadata> ModMetadata::Impl::createFromGeodeZip(file::Unzip& unzip) {
})
);

std::string error;
auto res = matjson::parse(std::string(jsonData.begin(), jsonData.end()), error);
if (error.size() > 0) {
return Err(std::string("Unable to parse mod.json: ") + error);
}
ModJson json = res.value();
ModJson json = GEODE_UNWRAP(matjson::parse(std::string(jsonData.begin(), jsonData.end())).mapErr([](auto const& err) {
return fmt::format("Unable to parse mod.json: {}", err);
}));

auto res2 = ModMetadata::create(json);
if (!res2) {
return Err("\"" + unzip.getPath().string() + "\" - " + res2.unwrapErr());
}
auto info = res2.unwrap();
auto info = GEODE_UNWRAP(ModMetadata::create(json).mapErr([&](auto const& err) {
return fmt::format("\"{}\" - {}", unzip.getPath().string(), err);
}));
auto impl = info.m_impl.get();
impl->m_path = unzip.getPath();

Expand Down
Loading

0 comments on commit 9ed55c4

Please sign in to comment.