From d1daa32a054461531d2d4d5b8427a9608ad15500 Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Sat, 2 Mar 2024 20:53:28 +0800 Subject: [PATCH] revert: revert --- .github/workflows/release.yml | 4 +- src/change_this/Entry.cpp | 85 ---------------------------------- src/change_this/Entry.h | 9 ---- src/change_this/RenameThis.cpp | 58 +++++++++++++++++++++++ src/change_this/RenameThis.h | 33 +++++++++++++ 5 files changed, 93 insertions(+), 96 deletions(-) delete mode 100644 src/change_this/Entry.cpp delete mode 100644 src/change_this/Entry.h create mode 100644 src/change_this/RenameThis.cpp create mode 100644 src/change_this/RenameThis.h diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d096964..95ee427 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,10 +23,10 @@ jobs: xmake repo -u - run: | - xmake f -a x64 -m release -p windows -v -y + xmake f -a x64 -m release -p windows -y - run: | - xmake -v -w -y + xmake -w -y - uses: actions/upload-artifact@v4 with: diff --git a/src/change_this/Entry.cpp b/src/change_this/Entry.cpp deleted file mode 100644 index 574351b..0000000 --- a/src/change_this/Entry.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "Entry.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace change_this { - -namespace { - -std::unique_ptr> selfPluginInstance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) - -auto disable(ll::plugin::NativePlugin& /*self*/) -> bool { - auto& logger = getSelfPluginInstance().getLogger(); - - logger.info("disabling..."); - - // Your code here. - - logger.info("disabled"); - - return true; -} - -auto enable(ll::plugin::NativePlugin& /*self*/) -> bool { - auto& logger = getSelfPluginInstance().getLogger(); - - logger.info("enabling..."); - - logger.info("enabled"); - - return true; -} - -auto load(ll::plugin::NativePlugin& self) -> bool { - auto& logger = self.getLogger(); - - logger.info("loading..."); - - selfPluginInstance = std::make_unique>(self); - - // Your code here. - - logger.info("loaded"); - - return true; -} - -auto unload(ll::plugin::NativePlugin& self) -> bool { - auto& logger = self.getLogger(); - - logger.info("unloading..."); - - selfPluginInstance.reset(); - - // Your code here. - - logger.info("unloaded"); - - return true; -} - -} // namespace - -auto getSelfPluginInstance() -> ll::plugin::NativePlugin& { - if (!selfPluginInstance) { - throw std::runtime_error("selfPluginInstance is null"); - } - - return *selfPluginInstance; -} - -} // namespace change_this - -extern "C" { -_declspec(dllexport) auto ll_plugin_disable(ll::plugin::NativePlugin& self) -> bool { return change_this::disable(self); } -_declspec(dllexport) auto ll_plugin_enable(ll::plugin::NativePlugin& self) -> bool { return change_this::enable(self); } -_declspec(dllexport) auto ll_plugin_load(ll::plugin::NativePlugin& self) -> bool { return change_this::load(self); } -_declspec(dllexport) auto ll_plugin_unload(ll::plugin::NativePlugin& self) -> bool { return change_this::unload(self); } -} diff --git a/src/change_this/Entry.h b/src/change_this/Entry.h deleted file mode 100644 index 80e3a6e..0000000 --- a/src/change_this/Entry.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace change_this { - -[[nodiscard]] auto getSelfPluginInstance() -> ll::plugin::NativePlugin&; - -} // namespace change_this diff --git a/src/change_this/RenameThis.cpp b/src/change_this/RenameThis.cpp new file mode 100644 index 0000000..0722e0f --- /dev/null +++ b/src/change_this/RenameThis.cpp @@ -0,0 +1,58 @@ +#include "RenameThis.h" + +#include +#include + +namespace rename_this { + +RenameThis::RenameThis() = default; + +RenameThis& RenameThis::getInstance() { + static RenameThis instance; + return instance; +} + +ll::plugin::NativePlugin& RenameThis::getSelf() const { return *mSelf; } + +bool RenameThis::load(ll::plugin::NativePlugin& self) { + mSelf = std::addressof(self); + getSelf().getLogger().info("loading..."); + + // Code for loading the plugin goes here. + + return true; +} + +bool RenameThis::enable() { + getSelf().getLogger().info("enabling..."); + + // Code for enabling the plugin goes here. + + return true; +} + +bool RenameThis::disable() { + getSelf().getLogger().info("disabling..."); + + // Code for disabling the plugin goes here. + + return true; +} + +extern "C" { +_declspec(dllexport) bool ll_plugin_load(ll::plugin::NativePlugin& self) { + return RenameThis::getInstance().load(self); +} + +_declspec(dllexport) bool ll_plugin_enable(ll::plugin::NativePlugin&) { return RenameThis::getInstance().enable(); } + +_declspec(dllexport) bool ll_plugin_disable(ll::plugin::NativePlugin&) { return RenameThis::getInstance().disable(); } + +/// @warning Unloading the plugin may cause a crash if the plugin has not released all of its +/// resources. If you are unsure, keep this function commented out. +// _declspec(dllexport) bool ll_plugin_unload(ll::plugin::NativePlugin&) { +// return RenameThis::getInstance().unload(); +// } +} + +} // namespace rename_this diff --git a/src/change_this/RenameThis.h b/src/change_this/RenameThis.h new file mode 100644 index 0000000..2568e4f --- /dev/null +++ b/src/change_this/RenameThis.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +namespace rename_this { + +class RenameThis { + RenameThis(); + +public: + RenameThis(RenameThis&&) = delete; + RenameThis(const RenameThis&) = delete; + RenameThis& operator=(RenameThis&&) = delete; + RenameThis& operator=(const RenameThis&) = delete; + + static RenameThis& getInstance(); + + [[nodiscard]] ll::plugin::NativePlugin& getSelf() const; + + /// @return True if the plugin is loaded successfully. + bool load(ll::plugin::NativePlugin&); + + /// @return True if the plugin is enabled successfully. + bool enable(); + + /// @return True if the plugin is disabled successfully. + bool disable(); + +private: + ll::plugin::NativePlugin* mSelf{}; +}; + +} // namespace rename_this