fix internal mod being setup at static init time

This commit is contained in:
HJfod 2023-01-21 19:02:23 +02:00
parent 51f70bc810
commit e322cc5fae
3 changed files with 17 additions and 10 deletions

View file

@ -133,9 +133,8 @@ namespace geode {
T setSavedValue(std::string const& key, T const& value);
/**
* Get the mod container stored in the Interface
* @returns nullptr if Interface is not initialized,
* the mod pointer if it is initialized
* Get the Mod of the current mod being developed
* @returns The current mod
*/
template <class = void>
static inline GEODE_HIDDEN Mod* get() {

View file

@ -21,8 +21,6 @@ Mod::Impl* ModImpl::getImpl(Mod* mod) {
}
Mod::Impl::Impl(Mod* self, ModInfo const& info) : m_self(self), m_info(info) {
m_saveDirPath = dirs::getModsSaveDir() / info.id;
ghc::filesystem::create_directories(m_saveDirPath);
}
Mod::Impl::~Impl() {
@ -30,6 +28,9 @@ Mod::Impl::~Impl() {
}
Result<> Mod::Impl::setup() {
m_saveDirPath = dirs::getModsSaveDir() / m_info.id;
ghc::filesystem::create_directories(m_saveDirPath);
this->setupSettings();
auto loadRes = this->loadData();
if (!loadRes) {
@ -673,9 +674,4 @@ void Loader::Impl::setupInternalMod() {
auto& mod = Mod::sharedMod<>;
if (mod) return;
mod = new Mod(getModImplInfo());
auto setupRes = mod->m_impl->setup();
if (!setupRes) {
log::error("Failed to setup internal mod! ({})", setupRes.unwrapErr());
}
}

View file

@ -154,6 +154,18 @@ $execute {
int geodeEntry(void* platformData) {
// setup internals
auto intModSetupRes = ModImpl::getImpl(Mod::get())->setup();
if (!intModSetupRes) {
LoaderImpl::get()->platformMessageBox(
"Unable to load Geode!",
"There was an unknown fatal error setting up "
"the internal mod representation and Geode can "
"not be loaded. "
"(" + intModSetupRes.unwrapErr() + ")"
);
return 1;
}
if (!geode::core::hook::initialize()) {
LoaderImpl::get()->platformMessageBox(
"Unable to load Geode!",