Backport of https://github.com/TrinityCore/TrinityCore/pull/12657, needs functions from Eluna