添加进入人物和退出人物hook

This commit is contained in:
小疯
2022-09-12 18:11:08 +08:00
parent 2ccdac8561
commit cdca473ec3
10 changed files with 590 additions and 78 deletions

View File

@@ -2,14 +2,214 @@
#define utils_h__
#include <string>
#include <stdarg.h>
#include <iconv.h>
#include <stdio.h>
#define BUFFCOUNT (3196)
#define SET_TEXTW(X) L#X
#define SET_TEXTA(X) #X
namespace Utils
{
class NLock
{
public:
typedef pthread_mutex_t OSLockType;
NLock()
{
pthread_mutex_init(&os_lock_, NULL);
}
~NLock()
{
pthread_mutex_destroy(&os_lock_);
}
// If the lock is not held, take it and return true. If the lock is already
// held by something else, immediately return false.
bool Try()
{
int rv = pthread_mutex_trylock(&os_lock_);
return rv == 0;
}
// Take the lock, blocking until it is available if necessary.
void Lock()
{
pthread_mutex_lock(&os_lock_);
}
// Release the lock. This must only be called by the lock's holder: after
// a successful call to Try, or a call to Lock.
void Unlock()
{
pthread_mutex_unlock(&os_lock_);
}
// Return the native underlying lock. Not supported for Windows builds.
OSLockType* os_lock() { return &os_lock_; }
private:
OSLockType os_lock_;
};
class NAutoLock
{
public:
NAutoLock(NLock* lock)
{
lock_ = lock;
lock_->Lock();
}
~NAutoLock()
{
if (lock_)
lock_->Unlock();
}
private:
NLock* lock_;
};
class NAutoUnlock
{
public:
NAutoUnlock(NLock* lock)
{
lock_ = lock;
lock_->Unlock();
}
~NAutoUnlock()
{
if (lock_)
lock_->Lock();
}
private:
NLock* lock_;
};
template <class V1, class V2, class V3 = std::less<V1>>
class TMap
{
public:
/**
* @brief 保存
* @param key
* @param data
* @return
*/
bool Push(V1 key, V2 data)
{
NAutoLock auto_lock(&Lock);
auto itrM = Map.find(key);
if (itrM != Map.end())
{
return false;
}
Map.insert(std::make_pair(key, data));
return true;
}
/**
* @brief 删除
* @param key
* @return
*/
bool Erase(V1 key)
{
NAutoLock auto_lock(&Lock);
auto itrM = Map.find(key);
if (itrM != Map.end())
{
Map.erase(key);
return true;
}
return false;
}
/**
* @brief 清空
*/
void Clear()
{
NAutoLock auto_lock(&Lock);
Map.clear();
}
/**
* @brief 大小
* @return
*/
size_t Size()
{
return Map.size();
}
/**
* @brief 迭代器头
* @return
*/
typename std::map<V1, V2>::iterator Begin()
{
return Map.begin();
}
/**
* @brief 迭代器尾
* @return
*/
typename std::map<V1, V2>::iterator End()
{
return Map.end();
}
/**
* @brief 查找数据
* @param key
* @param data
* @return
*/
bool Find(V1 key, V2* data = NULL)
{
NAutoLock auto_lock(&Lock);
auto itr = Map.find(key);
if (itr != Map.end())
{
if (data)
{
*data = itr->second;
}
return true;
}
return false;
}
/**
* @brief 更改数据
* @param key
* @param data
* @return
*/
bool Change(V1 key, V2 data)
{
NAutoLock auto_lock(&Lock);
auto itr = Map.find(key);
if (itr != Map.end())
{
itr->second = data;
return true;
}
return false;
}
std::map<V1, V2, V3>Map;
NLock Lock;
};
/**
* @brief 到16进制Hex文本
* @param buf
@@ -49,7 +249,6 @@ namespace Utils
}
#define LOG(format,...) Utils::_Log(format,##__VA_ARGS__)