From 6a617789d2bd43af0b5b328ffbe3cf10d57b448b Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:36:52 -0300 Subject: [PATCH] remove rvalue requirement, fix claimHook and claimPatch --- loader/include/Geode/loader/Mod.hpp | 4 ++-- loader/include/Geode/modify/Modify.hpp | 2 +- loader/src/loader/Mod.cpp | 8 ++++---- loader/src/loader/ModImpl.cpp | 12 ++++++------ loader/src/loader/ModImpl.hpp | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/loader/include/Geode/loader/Mod.hpp b/loader/include/Geode/loader/Mod.hpp index 73996585..5ae16dab 100644 --- a/loader/include/Geode/loader/Mod.hpp +++ b/loader/include/Geode/loader/Mod.hpp @@ -271,7 +271,7 @@ namespace geode { * @returns Returns a pointer to the hook, or an error if the * hook already has an owner, or was unable to enable the hook. */ - Result claimHook(std::shared_ptr&& hook); + Result claimHook(std::shared_ptr hook); /** * Disowns a hook which this mod owns, making this mod no longer its owner. @@ -306,7 +306,7 @@ namespace geode { * @returns Returns a pointer to the patch, or an error if the * patch already has an owner, or was unable to enable the patch. */ - Result claimPatch(std::shared_ptr&& patch); + Result claimPatch(std::shared_ptr patch); /** * Disowns a patch which this mod owns, making this mod no longer its owner. diff --git a/loader/include/Geode/modify/Modify.hpp b/loader/include/Geode/modify/Modify.hpp index 32e27459..f6f9bbdd 100644 --- a/loader/include/Geode/modify/Modify.hpp +++ b/loader/include/Geode/modify/Modify.hpp @@ -96,7 +96,7 @@ namespace geode::modifier { ModifyDerived::Derived::onModify(*this); std::vector added; for (auto& [uuid, hook] : m_hooks) { - auto res = Mod::get()->claimHook(std::move(hook)); + auto res = Mod::get()->claimHook(hook); if (!res) { log::error("Failed to claim hook {}: {}", hook->getDisplayName(), res.error()); } diff --git a/loader/src/loader/Mod.cpp b/loader/src/loader/Mod.cpp index 0e93d85b..e72f3c39 100644 --- a/loader/src/loader/Mod.cpp +++ b/loader/src/loader/Mod.cpp @@ -121,8 +121,8 @@ void Mod::registerCustomSetting(std::string_view const key, std::unique_ptrregisterCustomSetting(key, std::move(value)); } -Result Mod::claimHook(std::shared_ptr&& hook) { - return m_impl->claimHook(std::move(hook)); +Result Mod::claimHook(std::shared_ptr hook) { + return m_impl->claimHook(hook); } Result<> Mod::disownHook(Hook* hook) { @@ -133,8 +133,8 @@ std::vector Mod::getHooks() const { return m_impl->getHooks(); } -Result Mod::claimPatch(std::shared_ptr&& patch) { - return m_impl->claimPatch(std::move(patch)); +Result Mod::claimPatch(std::shared_ptr patch) { + return m_impl->claimPatch(patch); } Result<> Mod::disownPatch(Patch* patch) { diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index 61bcff5f..2b23e912 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -454,12 +454,14 @@ bool Mod::Impl::depends(std::string_view const id) const { // Hooks -Result Mod::Impl::claimHook(std::shared_ptr&& hook) { +Result Mod::Impl::claimHook(std::shared_ptr hook) { auto res1 = hook->m_impl->setOwner(m_self); if (!res1) { return Err("Cannot claim hook: {}", res1.unwrapErr()); } + m_hooks.push_back(hook); + auto ptr = hook.get(); if (this->isEnabled() && hook->getAutoEnable()) { if (LoaderImpl::get()->isReadyToHook()) { @@ -474,8 +476,6 @@ Result Mod::Impl::claimHook(std::shared_ptr&& hook) { } } - m_hooks.push_back(std::move(hook)); - return Ok(ptr); } @@ -510,12 +510,14 @@ Result<> Mod::Impl::disownHook(Hook* hook) { // Patches -Result Mod::Impl::claimPatch(std::shared_ptr&& patch) { +Result Mod::Impl::claimPatch(std::shared_ptr patch) { auto res1 = patch->m_impl->setOwner(m_self); if (!res1) { return Err("Cannot claim patch: {}", res1.unwrapErr()); } + m_patches.push_back(patch); + auto ptr = patch.get(); if (this->isEnabled() && patch->getAutoEnable()) { auto res2 = ptr->enable(); @@ -524,8 +526,6 @@ Result Mod::Impl::claimPatch(std::shared_ptr&& patch) { } } - m_patches.push_back(std::move(patch)); - return Ok(ptr); } diff --git a/loader/src/loader/ModImpl.hpp b/loader/src/loader/ModImpl.hpp index 335b054f..4a28408c 100644 --- a/loader/src/loader/ModImpl.hpp +++ b/loader/src/loader/ModImpl.hpp @@ -113,11 +113,11 @@ namespace geode { SettingValue* getSetting(std::string_view const key) const; void registerCustomSetting(std::string_view const key, std::unique_ptr value); - Result claimHook(std::shared_ptr&& hook); + Result claimHook(std::shared_ptr hook); Result<> disownHook(Hook* hook); [[nodiscard]] std::vector getHooks() const; - Result claimPatch(std::shared_ptr&& patch); + Result claimPatch(std::shared_ptr patch); Result<> disownPatch(Patch* patch); [[nodiscard]] std::vector getPatches() const;