diff --git a/src-server/ll/api/event/player/PlayerChatEvent.cpp b/src-server/ll/api/event/player/PlayerChatEvent.cpp index 893d84e357..829fc926c4 100644 --- a/src-server/ll/api/event/player/PlayerChatEvent.cpp +++ b/src-server/ll/api/event/player/PlayerChatEvent.cpp @@ -30,8 +30,7 @@ LL_TYPE_INSTANCE_HOOK( NetworkIdentifier const& identifier, TextPacket const& packet ) { - auto handle = static_cast(reinterpret_cast(this)); - if (auto player = handle->_getServerPlayer(identifier, packet.mClientSubId); player) { + if (auto player = thisFor()->_getServerPlayer(identifier, packet.mClientSubId); player) { auto event = PlayerChatEvent{*player, const_cast(packet).mMessage}; EventBus::getInstance().publish(event); if (event.isCancelled()) { diff --git a/src-server/ll/api/event/player/PlayerJoinEvent.cpp b/src-server/ll/api/event/player/PlayerJoinEvent.cpp index f2611ca2cd..92d998b6e7 100644 --- a/src-server/ll/api/event/player/PlayerJoinEvent.cpp +++ b/src-server/ll/api/event/player/PlayerJoinEvent.cpp @@ -17,8 +17,7 @@ LL_TYPE_INSTANCE_HOOK( NetworkIdentifier const& identifier, SetLocalPlayerAsInitializedPacket const& packet ) { - auto handle = static_cast(reinterpret_cast(this)); - if (auto player = handle->_getServerPlayer(identifier, packet.mClientSubId); player) { + if (auto player = thisFor()->_getServerPlayer(identifier, packet.mClientSubId); player) { auto event = PlayerJoinEvent{*player}; EventBus::getInstance().publish(event); if (event.isCancelled()) { diff --git a/src-server/ll/api/event/player/PlayerSneakAndSprintEvent.cpp b/src-server/ll/api/event/player/PlayerSneakAndSprintEvent.cpp index 16640cade3..34d73c2a04 100644 --- a/src-server/ll/api/event/player/PlayerSneakAndSprintEvent.cpp +++ b/src-server/ll/api/event/player/PlayerSneakAndSprintEvent.cpp @@ -17,7 +17,7 @@ LL_TYPE_INSTANCE_HOOK( NetworkIdentifier const& id, PlayerActionPacket const& packet ) { - auto handle = static_cast(reinterpret_cast(this)); + auto handle = thisFor(); switch (packet.mAction) { case PlayerActionType::StartSprinting: if (auto player = handle->_getServerPlayer(id, packet.mClientSubId); player) { diff --git a/src-server/ll/api/event/player/PlayerSwingEvent.cpp b/src-server/ll/api/event/player/PlayerSwingEvent.cpp index 35774c303b..f23221ce19 100644 --- a/src-server/ll/api/event/player/PlayerSwingEvent.cpp +++ b/src-server/ll/api/event/player/PlayerSwingEvent.cpp @@ -17,9 +17,8 @@ LL_TYPE_INSTANCE_HOOK( NetworkIdentifier const& id, AnimatePacket const& packet ) { - auto handle = static_cast(reinterpret_cast(this)); if (packet.mAction == AnimatePacket::Action::Swing) { - if (auto player = handle->_getServerPlayer(id, packet.mClientSubId); player) { + if (auto player = thisFor()->_getServerPlayer(id, packet.mClientSubId); player) { EventBus::getInstance().publish(PlayerSwingEvent(*player)); } } diff --git a/src/ll/api/event/player/PlayerJumpEvent.cpp b/src/ll/api/event/player/PlayerJumpEvent.cpp index 9679f863ff..d385d5cac3 100644 --- a/src/ll/api/event/player/PlayerJumpEvent.cpp +++ b/src/ll/api/event/player/PlayerJumpEvent.cpp @@ -35,8 +35,7 @@ LL_TYPE_INSTANCE_HOOK( auto mode = settings->getPlayerMovementSettings().mUnk3c7e19.as(); if (mode == ServerAuthMovementMode::LegacyClientAuthoritativeV1) { if (packet.mAction == PlayerActionType::StartJump) { - auto handle = static_cast(reinterpret_cast(this)); - if (auto player = handle->_getServerPlayer(source, packet.mClientSubId); player) { + if (auto player = thisFor()->_getServerPlayer(source, packet.mClientSubId); player) { EventBus::getInstance().publish(PlayerJumpEvent(*player)); } } diff --git a/src/ll/api/memory/Hook.h b/src/ll/api/memory/Hook.h index 05a7f9fb47..0530f1aac2 100644 --- a/src/ll/api/memory/Hook.h +++ b/src/ll/api/memory/Hook.h @@ -160,7 +160,7 @@ struct LL_EBO Hook {}; inline static _OriginFuncType _OriginalFunc{}; \ \ template \ - static consteval void detector() { \ + static consteval void _Detector() { \ if constexpr (requires { ::ll::memory::virtualDetector(); }) { \ if constexpr (::ll::memory::virtualDetector()) { \ static_assert( \ @@ -172,6 +172,11 @@ struct LL_EBO Hook {}; } \ \ public: \ + template \ + requires(::std::is_polymorphic_v && ::std::is_base_of_v) \ + [[nodiscard]] TYPE* thisFor() { \ + return static_cast(reinterpret_cast(this)); \ + } \ template \ STATIC RET_TYPE origin(Args&&... params) { \ return CALL(std::forward(params)...); \ @@ -180,7 +185,7 @@ struct LL_EBO Hook {}; STATIC RET_TYPE detour(__VA_ARGS__); \ \ static int hook(bool suspendThreads = true) { \ - detector<_OriginFuncType>(); \ + _Detector<_OriginFuncType>(); \ if (!_HookTarget) _HookTarget = ::ll::memory::resolveIdentifier<_OriginFuncType>(IDENTIFIER); \ return ::ll::memory::hook( \ _HookTarget, \