From f064f674b798e10947b0d686aad191e7bedf4116 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 Date: Mon, 25 Mar 2024 18:40:11 +0800 Subject: [PATCH] adapt: adapt GMLIB v0.9.8 --- SDK-GMLIB | 2 +- manifest.json | 3 +++ src/DeathMessage.cpp | 2 +- src/DllMain.cpp | 32 -------------------------------- src/Entry.cpp | 28 ++++++++++++++++++++++++++++ src/Entry.h | 33 +++++++++++++++++++++++++++++++++ src/MemoryOperators.cpp | 6 ++++++ src/Plugin.cpp | 38 -------------------------------------- src/Plugin.h | 27 --------------------------- tooth.json | 6 +++--- 10 files changed, 75 insertions(+), 102 deletions(-) delete mode 100644 src/DllMain.cpp create mode 100644 src/Entry.cpp create mode 100644 src/Entry.h create mode 100644 src/MemoryOperators.cpp delete mode 100644 src/Plugin.cpp delete mode 100644 src/Plugin.h diff --git a/SDK-GMLIB b/SDK-GMLIB index 1a7e0ba..cda5bfb 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 1a7e0ba55d0b9be5cd2680ecf47b4ab26bb4bff0 +Subproject commit cda5bfbf85a291a85a78529f760883d1ca7216da diff --git a/manifest.json b/manifest.json index 6827888..2ad0b47 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "${pluginName}", "entry": "${pluginFile}", "type": "native", + "version": "0.9.0", + "author": "GroupMountain", + "description": "Better Death Messages", "dependencies": [ { "name": "GMLIB" diff --git a/src/DeathMessage.cpp b/src/DeathMessage.cpp index ab0be83..aca6023 100644 --- a/src/DeathMessage.cpp +++ b/src/DeathMessage.cpp @@ -45,7 +45,7 @@ void ListenEvents() { auto msg = ev.getDeathMessage(); auto info = tr(msg.first, msg.second); deathLogger.info(info); - ev.setDeathMessage({info, msg.second}); + ev.getDeathMessage() = {info, msg.second}; } ); } 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..aea670c --- /dev/null +++ b/src/Entry.cpp @@ -0,0 +1,28 @@ +#include "Entry.h" +#include "Global.h" + +ll::Logger logger(PLUGIN_NAME); + +namespace DeathMessages { + +std::unique_ptr& Entry::getInstance() { + static std::unique_ptr instance; + return instance; +} + +bool Entry::load() { + initPlugin(); + return true; +} + +bool Entry::enable() { + RegisterDamageDefinition(); + ListenEvents(); + return true; +} + +bool Entry::disable() { return true; } + +} // namespace DeathMessages + +LL_REGISTER_PLUGIN(DeathMessages::Entry, DeathMessages::Entry::getInstance()); \ No newline at end of file diff --git a/src/Entry.h b/src/Entry.h new file mode 100644 index 0000000..b0137d0 --- /dev/null +++ b/src/Entry.h @@ -0,0 +1,33 @@ +#pragma once +#include + +namespace DeathMessages { + +class Entry { + +public: + static std::unique_ptr& getInstance(); + + Entry(ll::plugin::NativePlugin& self) : mSelf(self) {} + + [[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; } + + /// @return True if the plugin is loaded successfully. + bool load(); + + /// @return True if the plugin is enabled successfully. + bool enable(); + + /// @return True if the plugin is disabled successfully. + bool disable(); + + // TODO: Implement this method if you need to unload the plugin. + // /// @return True if the plugin is unloaded successfully. + // bool unload(); + +private: + ll::plugin::NativePlugin& mSelf; +}; + +} // namespace DeathMessages + diff --git a/src/MemoryOperators.cpp b/src/MemoryOperators.cpp new file mode 100644 index 0000000..a81be3a --- /dev/null +++ b/src/MemoryOperators.cpp @@ -0,0 +1,6 @@ +// This file will make your plugin use LeviLamina's memory operators by default. +// This improves the memory management of your plugin and is recommended to use. + +#define LL_MEMORY_OPERATORS + +#include "ll/api/memory/MemoryOperators.h" // IWYU pragma: keep diff --git a/src/Plugin.cpp b/src/Plugin.cpp deleted file mode 100644 index be01108..0000000 --- a/src/Plugin.cpp +++ /dev/null @@ -1,38 +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. - initPlugin(); -} - -bool Plugin::enable() { - // Code for enabling the plugin goes here. - auto requireLibVersion = SemVersion(0, 8, 2, "", ""); - if (GMLIB::Version::checkLibVersionMatch(requireLibVersion)) { - RegisterDamageDefinition(); - ListenEvents(); - logger.info("DeathMessages Loaded!"); - logger.info("Author: GroupMountain"); - logger.info("Repository: https://github.com/GroupMountain/DeathMessages"); - } else { - logger.error("GMLIB Version is outdated! Please update your GMLIB!"); - logger.error( - "Current GMLIB Version {}, Required Lowest GMLIB Version {}", - GMLIB::Version::getLibVersionString(), - requireLibVersion.asString() - ); - } - 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 3bc688e..25dafba 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/DeathMessages", - "version": "0.8.0", + "version": "0.9.0", "info": { "name": "DeathMessages", "description": "Better Death Messages on MCBE", @@ -11,9 +11,9 @@ "DeathMessages" ] }, - "asset_url": "https://github.com/GroupMountain/DeathMessages/releases/download/v0.8.0/DeathMessages-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/DeathMessages/releases/download/v0.9.0/DeathMessages-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.8.2" + "github.com/GroupMountain/GMLIB": ">=0.9.8" }, "files": { "place": [