diff --git a/src/DllMain.cpp b/src/DllMain.cpp deleted file mode 100644 index b2d0c68..0000000 --- a/src/DllMain.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -#include - -#include "Plugin.h" - -namespace plugin { - -// The global plugin instance. -std::unique_ptr plugin = nullptr; - -extern "C" { -_declspec(dllexport) bool ll_plugin_load(ll::plugin::NativePlugin& self) { - plugin = std::make_unique(self); - - return true; -} - -/// @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::Plugin&) { -// plugin.reset(); -// -// return true; -// } - -_declspec(dllexport) bool ll_plugin_enable(ll::plugin::NativePlugin&) { return plugin->enable(); } - -_declspec(dllexport) bool ll_plugin_disable(ll::plugin::NativePlugin&) { return plugin->disable(); } -} - -} // namespace plugin diff --git a/src/Entry.cpp b/src/Entry.cpp new file mode 100644 index 0000000..82da79a --- /dev/null +++ b/src/Entry.cpp @@ -0,0 +1,57 @@ +#include "Entry.h" +#include "Global.h" + +ll::Logger logger(PLUGIN_NAME); + +namespace GMLIB_LegacyRemoteCallApi { + +namespace { + +std::unique_ptr> + selfPluginInstance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + +auto disable(ll::plugin::NativePlugin& /*self*/) -> bool { return false; } + +auto enable(ll::plugin::NativePlugin& /*self*/) -> bool { return true; } + +auto load(ll::plugin::NativePlugin& self) -> bool { + selfPluginInstance = std::make_unique>(self); + Export_Legacy_GMLib_ModAPI(); + Export_Legacy_GMLib_ServerAPI(); + Export_Compatibility_API(); + ExportPAPI(); + logger.info("GMLIB-LegacyRemoteCallApi Loaded!"); + logger.info("Version: {}", LIB_VERSION.asString()); + logger.info("Author: GroupMountain"); + logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi"); + return true; +} + +auto unload(ll::plugin::NativePlugin& self) -> bool { return false; } + +} // namespace + +auto getSelfPluginInstance() -> ll::plugin::NativePlugin& { + if (!selfPluginInstance) { + throw std::runtime_error("selfPluginInstance is null"); + } + + return *selfPluginInstance; +} + +} // namespace GMLIB_LegacyRemoteCallApi + +extern "C" { +_declspec(dllexport) auto ll_plugin_disable(ll::plugin::NativePlugin& self) -> bool { + return GMLIB_LegacyRemoteCallApi::disable(self); +} +_declspec(dllexport) auto ll_plugin_enable(ll::plugin::NativePlugin& self) -> bool { + return GMLIB_LegacyRemoteCallApi::enable(self); +} +_declspec(dllexport) auto ll_plugin_load(ll::plugin::NativePlugin& self) -> bool { + return GMLIB_LegacyRemoteCallApi::load(self); +} +_declspec(dllexport) auto ll_plugin_unload(ll::plugin::NativePlugin& self) -> bool { + return GMLIB_LegacyRemoteCallApi::unload(self); +} +} diff --git a/src/Entry.h b/src/Entry.h new file mode 100644 index 0000000..3bd0e52 --- /dev/null +++ b/src/Entry.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace GMLIB_LegacyRemoteCallApi { + +[[nodiscard]] auto getSelfPluginInstance() -> ll::plugin::NativePlugin&; + +} // namespace GMLIB_LegacyRemoteCallApi diff --git a/src/Global.h b/src/Global.h index 0599c1d..b822874 100644 --- a/src/Global.h +++ b/src/Global.h @@ -3,7 +3,7 @@ #include #define PLUGIN_NAME "GMLIB-LRCA" -#define LIB_VERSION SemVersion(0, 8, 4, "", "") +#define LIB_VERSION SemVersion(0, 9, 0, "", "") extern ll::Logger logger; diff --git a/src/Plugin.cpp b/src/Plugin.cpp deleted file mode 100644 index 6246abd..0000000 --- a/src/Plugin.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "Plugin.h" -#include "Global.h" - -ll::Logger logger(PLUGIN_NAME); - -namespace plugin { - -Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { - // Code for loading the plugin goes here. - Export_Legacy_GMLib_ModAPI(); - Export_Legacy_GMLib_ServerAPI(); - Export_Compatibility_API(); - ExportPAPI(); - logger.info("GMLIB-LegacyRemoteCallApi Loaded!"); - logger.info("Version: {}", LIB_VERSION.asString()); - logger.info("Author: GroupMountain"); - logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi"); -} - -bool Plugin::enable() { - // Code for enabling the plugin goes here. - return true; -} - -bool Plugin::disable() { - // Code for disabling the plugin goes here. - return true; -} - -} // namespace plugin \ No newline at end of file diff --git a/src/Plugin.h b/src/Plugin.h deleted file mode 100644 index e2a0359..0000000 --- a/src/Plugin.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include - -namespace plugin { - -class Plugin { -public: - explicit Plugin(ll::plugin::NativePlugin& self); - - Plugin(Plugin&&) = delete; - Plugin(const Plugin&) = delete; - Plugin& operator=(Plugin&&) = delete; - Plugin& operator=(const Plugin&) = delete; - - ~Plugin() = default; - - /// @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 plugin diff --git a/tooth.json b/tooth.json index eb92da5..11fa278 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", - "version": "0.8.4", + "version": "0.9.0", "info": { "name": "GMLIB-LegacyRemoteCallApi", "description": "Legacy RemoteCall API for GMLIB", @@ -14,9 +14,9 @@ "library" ] }, - "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.8.4/GMLIB-LegacyRemoteCallApi-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.9.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.8.5" + "github.com/GroupMountain/GMLIB": ">=0.9.0" }, "files": { "place": [