Merge branch 'main' into hook-patch-refactor

This commit is contained in:
Chloe 2024-01-15 22:19:54 -07:00 committed by GitHub
commit 45a04cc330
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 10 deletions

View file

@ -1,5 +1,6 @@
{
"geode": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@",
"gd": "*",
"id": "geode.loader",
"version": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@",
"name": "Geode",

View file

@ -12,11 +12,12 @@ $execute {
(void)Mod::get()->patch(
reinterpret_cast<void*>(base::get() + 0x603948), toByteArray(&cast::typeinfoCastInternal)
);
#elif defined(GEODE_IS_ANDROID32)
(void)Mod::get()->hook(reinterpret_cast<void*>(base::get() + (0x720348 - 0x10000) + 1), &cast::typeinfoCastInternal, "__dynamic_cast");
#elif defined(GEODE_IS_ANDROID64)
(void)Mod::get()->hook(reinterpret_cast<void*>(base::get() + (0xd6cb8c - 0x100000)), &cast::typeinfoCastInternal, "__dynamic_cast");
#elif defined(GEODE_IS_ANDROID)
void* handle = dlopen("libcocos2dcpp.so", RTLD_LAZY | RTLD_NOLOAD);
void* dynamicCastAddr = dlsym(handle, "__dynamic_cast");
(void)Mod::get()->hook(dynamicCastAddr, &cast::typeinfoCastInternal, "__dynamic_cast");
dlclose(handle);
#endif
}

View file

@ -52,6 +52,7 @@ Result<ModMetadata> ModMetadata::Impl::createFromSchemaV010(ModJson const& rawJs
auto root = checker.root("[mod.json]").obj();
root.addKnownKey("geode");
root.addKnownKey("gd");
// don't think its used locally yet
root.addKnownKey("tags");
@ -63,14 +64,10 @@ Result<ModMetadata> ModMetadata::Impl::createFromSchemaV010(ModJson const& rawJs
root.has("description").into(impl->m_description);
root.has("repository").into(impl->m_repository);
root.has("early-load").into(impl->m_needsEarlyLoad);
// TODO for 2.0.0: fix this lol
// i think whoever wrote that intended that has would return the value if the key is present and false otherwise
// but the actual behavior here is false if key not present and true if key is present
if (root.has("api")) {
impl->m_isAPI = true;
}
// TODO for 2.0.0: specify this in mod.json manually
if (info.getID() != "geode.loader") {
impl->m_dependencies.push_back({
"geode.loader",
@ -178,6 +175,39 @@ Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
);
}
// Check GD version
if (json.contains("gd")) {
std::string ver;
if (json["gd"].is_string()) {
ver = json["gd"].as_string();
} else if (json["gd"].is_object()) {
std::string key;
switch (GEODE_PLATFORM_TARGET) {
case PlatformID::Android32:
case PlatformID::Android64:
key = "android"; break;
case PlatformID::MacOS:
key = "mac"; break;
case PlatformID::Windows:
key = "win"; break;
case PlatformID::iOS:
key = "ios"; break;
}
if (json["gd"].contains(key))
ver = json["gd"][ver].as_string();
} else {
return Err("[mod.json] has invalid target GD version");
}
if (ver.empty()) {
return Err("[mod.json] could not find GD version for current platform");
}
if (ver != "*" && ver != GEODE_STR(GEODE_GD_VERSION)) {
return Err(fmt::format("[mod.json] doesn't support this GD version ({} != {})", ver, GEODE_STR(GEODE_GD_VERSION)));
}
} else {
return Err("[mod.json] is missing target GD version");
}
return Impl::createFromSchemaV010(json);
}