代码拉取完成,页面将自动刷新
/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef _ELUNA_UTIL_H
#define _ELUNA_UTIL_H
#include <unordered_map>
#include <unordered_set>
#include <mutex>
#include <memory>
#include "Common.h"
#ifndef CMANGOS
#include "SharedDefines.h"
#include "ObjectGuid.h"
#else
#include "Globals/SharedDefines.h"
#include "Entities/ObjectGuid.h"
#endif
#ifdef TRINITY
#include "QueryResult.h"
#include "Log.h"
#ifdef CATA
#include "Object.h"
#endif
#else
#include "Database/QueryResult.h"
#include "Log.h"
#endif
#if defined(TRINITY) || defined(AZEROTHCORE)
typedef QueryResult ElunaQuery;
#define GET_GUID GetGUID
#define HIGHGUID_PLAYER HighGuid::Player
#define HIGHGUID_UNIT HighGuid::Unit
#define HIGHGUID_ITEM HighGuid::Item
#define HIGHGUID_GAMEOBJECT HighGuid::GameObject
#define HIGHGUID_PET HighGuid::Pet
#define HIGHGUID_TRANSPORT HighGuid::Transport
#define HIGHGUID_VEHICLE HighGuid::Vehicle
#define HIGHGUID_CONTAINER HighGuid::Container
#define HIGHGUID_DYNAMICOBJECT HighGuid::DynamicObject
#define HIGHGUID_CORPSE HighGuid::Corpse
#define HIGHGUID_MO_TRANSPORT HighGuid::Mo_Transport
#define HIGHGUID_INSTANCE HighGuid::Instance
#define HIGHGUID_GROUP HighGuid::Group
#endif
#ifdef TRINITY
#ifdef WOTLK
#include "fmt/printf.h"
#define ELUNA_LOG_TC_FMT(TC_LOG_MACRO, ...) \
try { \
std::string message = fmt::sprintf(__VA_ARGS__); \
TC_LOG_MACRO("eluna", "{}", message); \
} catch (const std::exception& e) { \
TC_LOG_MACRO("eluna", "Failed to format log message: {}", e.what()); \
}
#define ELUNA_LOG_INFO(...) ELUNA_LOG_TC_FMT(TC_LOG_INFO, __VA_ARGS__);
#define ELUNA_LOG_ERROR(...) ELUNA_LOG_TC_FMT(TC_LOG_ERROR, __VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) ELUNA_LOG_TC_FMT(TC_LOG_DEBUG, __VA_ARGS__);
#else
#define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__);
#define ELUNA_LOG_ERROR(...) TC_LOG_ERROR("eluna", __VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) TC_LOG_DEBUG("eluna", __VA_ARGS__);
#endif
#elif defined(AZEROTHCORE)
#define ELUNA_LOG_INFO(...) LOG_INFO("eluna", __VA_ARGS__);
#define ELUNA_LOG_ERROR(...) LOG_ERROR("eluna", __VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) LOG_DEBUG("eluna", __VA_ARGS__);
#elif VMANGOS
typedef QueryNamedResult ElunaQuery;
#define ASSERT MANGOS_ASSERT
#define ELUNA_LOG_INFO(...) sLog.Out(LOG_ELUNA, LOG_LVL_BASIC,__VA_ARGS__);
#define ELUNA_LOG_ERROR(...) sLog.Out(LOG_ELUNA, LOG_LVL_ERROR,__VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) sLog.Out(LOG_ELUNA, LOG_LVL_DEBUG,__VA_ARGS__);
#define GET_GUID GetObjectGuid
#define GetGameObjectTemplate GetGameObjectInfo
#define GetItemTemplate GetItemPrototype
#define GetTemplate GetProto
#else
typedef QueryNamedResult ElunaQuery;
#define ASSERT MANGOS_ASSERT
#define ELUNA_LOG_INFO(...) sLog.outString(__VA_ARGS__);
#define ELUNA_LOG_ERROR(...) sLog.outErrorEluna(__VA_ARGS__);
#define ELUNA_LOG_DEBUG(...) sLog.outDebug(__VA_ARGS__);
#define GET_GUID GetObjectGuid
#define GetGameObjectTemplate GetGameObjectInfo
#define GetItemTemplate GetItemPrototype
#define GetTemplate GetProto
#endif
#if defined(TRINITY) || defined(AZEROTHCORE) || defined(MANGOS) || defined(CMANGOS) || defined(VMANGOS)
#ifndef MAKE_NEW_GUID
#define MAKE_NEW_GUID(l, e, h) ObjectGuid(h, e, l)
#endif
#ifndef GUID_ENPART
#define GUID_ENPART(guid) ObjectGuid(guid).GetEntry()
#endif
#ifndef GUID_LOPART
#define GUID_LOPART(guid) ObjectGuid(guid).GetCounter()
#endif
#ifndef GUID_HIPART
#define GUID_HIPART(guid) ObjectGuid(guid).GetHigh()
#endif
#endif
class Unit;
class WorldObject;
struct FactionTemplateEntry;
namespace ElunaUtil
{
uint32 GetCurrTime();
uint32 GetTimeDiff(uint32 oldMSTime);
class ObjectGUIDCheck
{
public:
ObjectGUIDCheck(ObjectGuid guid);
bool operator()(WorldObject* object);
ObjectGuid _guid;
};
// Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
class ObjectDistanceOrderPred
{
public:
ObjectDistanceOrderPred(WorldObject const* pRefObj, bool ascending = true);
bool operator()(WorldObject const* pLeft, WorldObject const* pRight) const;
WorldObject const* m_refObj;
const bool m_ascending;
};
// Doesn't get self
class WorldObjectInRangeCheck
{
public:
WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
uint16 typeMask = 0, uint32 entry = 0, uint32 hostile = 0, uint32 dead = 0);
WorldObject const& GetFocusObject() const;
bool operator()(WorldObject* u);
WorldObject const* const i_obj;
Unit const* i_obj_unit;
FactionTemplateEntry const* i_obj_fact;
uint32 const i_hostile; // 0 both, 1 hostile, 2 friendly
uint32 const i_entry;
float i_range;
uint16 const i_typeMask;
uint32 const i_dead; // 0 both, 1 alive, 2 dead
bool const i_nearest;
};
/*
* Usage:
* Inherit this class, then when needing lock, use
* Guard guard(GetLock());
*
* The lock is automatically released at end of scope
*/
class Lockable
{
public:
typedef std::mutex LockType;
typedef std::lock_guard<LockType> Guard;
LockType& GetLock() { return _lock; }
private:
LockType _lock;
};
/*
* Encodes `data` in Base-64 and store the result in `output`.
*/
void EncodeData(const unsigned char* data, size_t input_length, std::string& output);
/*
* Decodes `data` from Base-64 and returns a pointer to the result, or `NULL` on error.
*
* The returned result buffer must be `delete[]`ed by the caller.
*/
unsigned char* DecodeData(const char* data, size_t *output_length);
};
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。