Merge branch 'geode-sdk:main' into main

This commit is contained in:
dankmeme01 2024-01-18 16:45:36 +01:00 committed by GitHub
commit f3e937b8cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 76 additions and 25 deletions

View file

@ -158,6 +158,20 @@ namespace geode {
return "Undefined";
}
static constexpr char const* toShortString(Type lp, bool ignoreArch = false) {
switch (lp) {
case Unknown: return "unknown";
case Windows: return "win";
case MacOS: return "mac";
case iOS: return "ios";
case Android32: return ignoreArch ? "android" : "android32";
case Android64: return ignoreArch ? "android" : "android64";
case Linux: return "linux";
default: break;
}
return "undefined";
}
template <class T>
requires requires(T t) {
static_cast<Type>(t);

View file

@ -403,9 +403,6 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) {
return;
}
if (node->getID() == "absolllute.megahack")
log::debug("megahack creepypasta");
for (auto const& dep : node->m_impl->m_dependants) {
m_modsToLoad.push_front(dep);
}

View file

@ -83,6 +83,7 @@ namespace geode {
void updateModResources(Mod* mod);
void addSearchPaths();
void addNativeBinariesPath(ghc::filesystem::path const& path);
Result<> setup();
void forceReset();

View file

@ -46,8 +46,13 @@ Result<> Mod::Impl::setup() {
}
if (!m_resourcesLoaded) {
auto searchPathRoot = dirs::getModRuntimeDir() / m_metadata.getID() / "resources";
// TODO: why is this commented out
// CCFileUtils::get()->addSearchPath(searchPathRoot.string().c_str());
const auto binariesDir = searchPathRoot / m_metadata.getID() / "binaries" / PlatformID::toShortString(GEODE_PLATFORM_TARGET);
if (ghc::filesystem::exists(binariesDir))
LoaderImpl::get()->addNativeBinariesPath(binariesDir);
m_resourcesLoaded = true;
}

View file

@ -8,6 +8,7 @@
#include <utility>
#include "ModMetadataImpl.hpp"
#include "LoaderImpl.hpp"
using namespace geode::prelude;
@ -181,18 +182,7 @@ Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
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;
}
auto key = PlatformID::toShortString(GEODE_PLATFORM_TARGET, true);
if (json["gd"].contains(key))
ver = json["gd"][ver].as_string();
} else {
@ -201,8 +191,24 @@ Result<ModMetadata> ModMetadata::Impl::create(ModJson const& json) {
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)));
if (ver != "*") {
// probably a bad idea but oh well
double modTargetVer;
try {
// assume gd version is always a valid double
modTargetVer = std::stod(ver);
} catch (...) {
return Err("[mod.json] has invalid target GD version");
}
if (LoaderImpl::get()->isForwardCompatMode()) {
// this means current gd version is > GEODE_GD_VERSION
if (modTargetVer <= GEODE_GD_VERSION) {
return Err(fmt::format("[mod.json] doesn't support this GD version ({} < current version)", ver));
}
} else if (ver != GEODE_STR(GEODE_GD_VERSION)) {
// we are not in forward compat mode, so GEODE_GD_VERSION is the current 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");

View file

@ -32,3 +32,7 @@ std::string Loader::Impl::getGameVersion() {
bool Loader::Impl::userTriedToLoadDLLs() const {
return false;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
log::warn("LoaderImpl::addNativeBinariesPath not implement on this platform, not adding path {}", path.string());
}

View file

@ -135,3 +135,8 @@ void Loader::Impl::setupIPC() {
bool Loader::Impl::userTriedToLoadDLLs() const {
return false;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
log::warn("LoaderImpl::addNativeBinariesPath not implement on this platform, not adding path {}", path.string());
}

View file

@ -74,3 +74,12 @@ bool Loader::Impl::userTriedToLoadDLLs() const {
return triedToLoadDLLs;
}
void Loader::Impl::addNativeBinariesPath(ghc::filesystem::path const& path) {
// https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-adddlldirectory#remarks
static auto runOnce = [] {
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
return 0;
}();
AddDllDirectory(path.wstring().c_str());
}

View file

@ -42,19 +42,18 @@ int WINAPI gdMainHook(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
"Unable to Load Geode!",
fmt::format(
"This version of Geode is made for Geometry Dash {} "
"but you're trying to play with GD {}."
"but you're trying to play with GD {}.\n"
"Please, update your game or install an older version of Geode.",
GEODE_STR(GEODE_GD_VERSION),
LoaderImpl::get()->getGameVersion()
)
);
return 2;
} else {
int exitCode = geodeEntry(hInstance);
if (exitCode != 0)
return exitCode;
}
int exitCode = geodeEntry(hInstance);
if (exitCode != 0)
return exitCode;
return reinterpret_cast<decltype(&wWinMain)>(mainTrampolineAddr)(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

View file

@ -6,14 +6,25 @@ using namespace geode::prelude;
PlatformID PlatformID::from(const char* str) {
switch (hash(str)) {
default:
case hash("unknown"): return PlatformID::Unknown;
case hash("win"):
case hash("Windows"):
case hash("windows"): return PlatformID::Windows;
case hash("mac"):
case hash("MacOS"):
case hash("macos"): return PlatformID::MacOS;
case hash("iOS"):
case hash("ios"): return PlatformID::iOS;
case hash("Android32"):
case hash("android32"): return PlatformID::Android32;
case hash("Android64"):
case hash("android64"): return PlatformID::Android64;
case hash("Linux"):
case hash("linux"): return PlatformID::Linux;
default: return PlatformID::Unknown;
}
}