2022-10-30 14:56:36 -04:00
|
|
|
#include "../core/Core.hpp"
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
#include <Geode/loader/Loader.hpp>
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <Geode/loader/Log.hpp>
|
|
|
|
#include <Geode/loader/Mod.hpp>
|
2022-09-28 12:15:27 -04:00
|
|
|
#include <Geode/loader/SettingEvent.hpp>
|
2022-11-22 10:24:03 -05:00
|
|
|
#include <Geode/loader/Setting.hpp>
|
2022-11-22 10:21:00 -05:00
|
|
|
#include <Geode/loader/IPC.hpp>
|
2022-07-30 12:24:03 -04:00
|
|
|
#include <InternalLoader.hpp>
|
|
|
|
#include <InternalMod.hpp>
|
2022-10-08 05:41:36 -04:00
|
|
|
#include <array>
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-11-22 10:24:03 -05:00
|
|
|
USE_GEODE_NAMESPACE();
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
int geodeEntry(void* platformData);
|
|
|
|
// platform-specific entry points
|
|
|
|
|
|
|
|
#if defined(GEODE_IS_IOS) || defined(GEODE_IS_MACOS)
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#include <unistd.h>
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
std::length_error::~length_error() _NOEXCEPT {} // do not ask...
|
|
|
|
|
2022-10-30 14:56:36 -04:00
|
|
|
// camila has an old ass macos and this function turned
|
|
|
|
// from dynamic to static thats why she needs to define it
|
2022-10-08 05:41:36 -04:00
|
|
|
// this is what old versions does to a silly girl
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
__attribute__((constructor)) void _entry() {
|
2022-10-08 05:59:06 -04:00
|
|
|
auto dylib = dlopen("GeodeBootstrapper.dylib", RTLD_NOLOAD);
|
|
|
|
dlclose(dylib);
|
|
|
|
|
2022-10-08 05:41:36 -04:00
|
|
|
std::array<char, PATH_MAX> gddir;
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
uint32_t out = PATH_MAX;
|
2022-10-08 05:41:36 -04:00
|
|
|
_NSGetExecutablePath(gddir.data(), &out);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-08 05:41:36 -04:00
|
|
|
ghc::filesystem::path gdpath = gddir.data();
|
2022-07-30 12:24:03 -04:00
|
|
|
ghc::filesystem::current_path(gdpath.parent_path().parent_path());
|
|
|
|
|
2022-10-08 06:21:57 -04:00
|
|
|
auto workingDir = gdpath.parent_path().parent_path();
|
|
|
|
auto libDir = workingDir / "Frameworks";
|
2022-10-08 05:41:36 -04:00
|
|
|
auto updatesDir = workingDir / "geode" / "update";
|
|
|
|
|
|
|
|
auto error = std::error_code();
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dylib", error) && !error) {
|
|
|
|
ghc::filesystem::rename(
|
2022-10-30 14:56:36 -04:00
|
|
|
updatesDir / "GeodeBootstrapper.dylib", libDir / "GeodeBootstrapper.dylib", error
|
2022-10-08 05:41:36 -04:00
|
|
|
);
|
|
|
|
if (error) return;
|
|
|
|
}
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
geodeEntry(nullptr);
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
#elif defined(GEODE_IS_WINDOWS)
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <Windows.h>
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
DWORD WINAPI loadThread(void* arg) {
|
2022-10-11 15:03:16 -04:00
|
|
|
bool canMoveBootstrapper = true;
|
|
|
|
if (auto mod = GetModuleHandleA("GeodeBootstrapper.dll")) {
|
|
|
|
if (WaitForSingleObject(mod, 1000) != WAIT_OBJECT_0) {
|
|
|
|
canMoveBootstrapper = false;
|
|
|
|
}
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
|
2022-10-11 15:03:16 -04:00
|
|
|
if (canMoveBootstrapper) {
|
|
|
|
auto workingDir = ghc::filesystem::current_path();
|
|
|
|
auto updatesDir = workingDir / "geode" / "update";
|
2022-10-08 05:41:36 -04:00
|
|
|
|
2022-10-11 15:03:16 -04:00
|
|
|
auto error = std::error_code();
|
|
|
|
|
|
|
|
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dll", error) && !error) {
|
|
|
|
ghc::filesystem::rename(
|
2022-10-30 14:56:36 -04:00
|
|
|
updatesDir / "GeodeBootstrapper.dll", workingDir / "GeodeBootstrapper.dll", error
|
2022-10-11 15:03:16 -04:00
|
|
|
);
|
|
|
|
if (error) return error.value();
|
|
|
|
}
|
2022-10-08 05:41:36 -04:00
|
|
|
}
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
return geodeEntry(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE lib, DWORD reason, LPVOID) {
|
|
|
|
switch (reason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
// Prevents threads from notifying this DLL on creation or destruction.
|
|
|
|
// Kind of redundant for a game that isn't multi-threaded but will provide
|
|
|
|
// some slight optimizations if a mod frequently creates and deletes threads.
|
|
|
|
DisableThreadLibraryCalls(lib);
|
|
|
|
|
|
|
|
// loading thread
|
|
|
|
HANDLE _ = CreateThread(0, 0, loadThread, lib, 0, nullptr);
|
|
|
|
if (_) CloseHandle(_);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-22 10:21:00 -05:00
|
|
|
#define $_ GEODE_CONCAT(unnamedVar_, __LINE__)
|
|
|
|
|
2022-11-22 17:35:08 -05:00
|
|
|
static auto $_ = listenForSettingChanges<BoolSetting>(
|
2022-10-11 15:00:08 -04:00
|
|
|
"show-platform-console",
|
2022-11-19 13:13:11 -05:00
|
|
|
[](BoolSetting* setting) {
|
2022-09-28 12:15:27 -04:00
|
|
|
if (setting->getValue()) {
|
|
|
|
Loader::get()->openPlatformConsole();
|
2022-10-30 14:56:36 -04:00
|
|
|
}
|
|
|
|
else {
|
2022-09-28 12:15:27 -04:00
|
|
|
Loader::get()->closePlatfromConsole();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-11-23 08:53:38 -05:00
|
|
|
static auto $_ = listenForIPC("ipc-test", +[](IPCEvent* event) -> nlohmann::json {
|
|
|
|
return "Hello from Geode!";
|
2022-11-22 10:21:00 -05:00
|
|
|
});
|
|
|
|
|
2022-11-23 08:53:38 -05:00
|
|
|
static auto $_ = listenForIPC("list-mods", +[](IPCEvent* event) -> nlohmann::json {
|
|
|
|
log::debug("List mods for {}", event->getReplyID().value_or("<None>"));
|
|
|
|
return ranges::map<std::vector<nlohmann::json>>(
|
|
|
|
ranges::concat(
|
|
|
|
{ Loader::get()->getInternalMod() },
|
|
|
|
Loader::get()->getAllMods()
|
|
|
|
),
|
|
|
|
[](Mod* mod) {
|
2022-11-22 17:35:08 -05:00
|
|
|
return mod->getModInfo().toJSON();
|
|
|
|
}
|
2022-11-23 08:53:38 -05:00
|
|
|
);
|
2022-11-22 10:21:00 -05:00
|
|
|
});
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
int geodeEntry(void* platformData) {
|
|
|
|
// setup internals
|
|
|
|
|
|
|
|
if (!InternalLoader::get()) {
|
|
|
|
InternalLoader::platformMessageBox(
|
|
|
|
"Unable to Load Geode!",
|
|
|
|
"There was an unknown fatal error setting up "
|
|
|
|
"internal tools and Geode can not be loaded. "
|
|
|
|
"(InternalLoader::get returned nullptr)"
|
|
|
|
);
|
2022-11-19 07:05:10 -05:00
|
|
|
return 1;
|
2022-07-30 12:24:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!geode::core::hook::initialize()) {
|
|
|
|
InternalLoader::platformMessageBox(
|
|
|
|
"Unable to load Geode!",
|
|
|
|
"There was an unknown fatal error setting up "
|
|
|
|
"internal tools and Geode can not be loaded. "
|
|
|
|
"(Unable to set up hook manager)"
|
|
|
|
);
|
2022-11-19 07:05:10 -05:00
|
|
|
return 1;
|
2022-07-30 12:24:03 -04:00
|
|
|
}
|
|
|
|
|
2022-10-08 09:53:09 -04:00
|
|
|
geode_implicit_load(InternalMod::get());
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
if (!InternalLoader::get()->setup()) {
|
2022-10-30 14:56:36 -04:00
|
|
|
// if we've made it here, Geode will
|
|
|
|
// be gettable (otherwise the call to
|
2022-07-30 12:24:03 -04:00
|
|
|
// setup would've immediately crashed)
|
|
|
|
|
|
|
|
InternalLoader::platformMessageBox(
|
|
|
|
"Unable to Load Geode!",
|
|
|
|
"There was an unknown fatal error setting up "
|
|
|
|
"internal tools and Geode can not be loaded. "
|
|
|
|
"(InternalLoader::setup) returned false"
|
|
|
|
);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-10-08 10:05:53 -04:00
|
|
|
log::debug("Loaded internal Geode class");
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
// set up loader, load mods, etc.
|
|
|
|
if (!Loader::get()->setup()) {
|
|
|
|
InternalLoader::platformMessageBox(
|
|
|
|
"Unable to Load Geode!",
|
|
|
|
"There was an unknown fatal error setting up "
|
|
|
|
"the loader and Geode can not be loaded."
|
|
|
|
);
|
|
|
|
delete InternalLoader::get();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-10-08 10:05:53 -04:00
|
|
|
log::debug("Set up loader");
|
2022-10-30 14:56:36 -04:00
|
|
|
|
2022-09-28 10:38:02 -04:00
|
|
|
if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
|
2022-09-28 12:15:27 -04:00
|
|
|
Loader::get()->openPlatformConsole();
|
2022-09-28 10:38:02 -04:00
|
|
|
}
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-08 10:05:53 -04:00
|
|
|
log::debug("Entry done.");
|
2022-10-06 17:09:15 -04:00
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
return 0;
|
|
|
|
}
|