mirror of
https://github.com/rehlds/rechecker.git
synced 2025-01-28 11:27:57 +03:00
Fixes
This commit is contained in:
parent
9f148eab97
commit
92c1719982
@ -6,7 +6,7 @@ CBufExec::CBufExec(IGameClient *pClient, CResourceBuffer *pResource, uint32 resp
|
|||||||
{
|
{
|
||||||
m_pClient = pClient;
|
m_pClient = pClient;
|
||||||
m_pResource = pResource;
|
m_pResource = pResource;
|
||||||
m_Hash = responseHash;
|
m_ClientHash = responseHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBufExec::~CBufExec()
|
CBufExec::~CBufExec()
|
||||||
@ -92,7 +92,7 @@ void CExecManager::CommandExecute(IGameClient *pClient)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *cmdExec = GetExecCmdPrepare(pClient, pRes, pExec->GetHash());
|
char *cmdExec = GetExecCmdPrepare(pClient, pRes, pExec->GetClientHash());
|
||||||
|
|
||||||
// erase all cmdexec because have flag is break
|
// erase all cmdexec because have flag is break
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
@ -113,7 +113,7 @@ void CExecManager::CommandExecute(IGameClient *pClient)
|
|||||||
else
|
else
|
||||||
iter++;
|
iter++;
|
||||||
|
|
||||||
bBreak = (pRes->GetFlagsFile() & FLAG_TYPE_BREAK) == FLAG_TYPE_BREAK;
|
bBreak = (pRes->GetFileFlags() & FLAG_TYPE_BREAK) == FLAG_TYPE_BREAK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,12 @@ public:
|
|||||||
|
|
||||||
IGameClient *GetGameClient() const { return m_pClient; };
|
IGameClient *GetGameClient() const { return m_pClient; };
|
||||||
CResourceBuffer *GetResource() const { return m_pResource; };
|
CResourceBuffer *GetResource() const { return m_pResource; };
|
||||||
uint32 GetHash() const { return m_Hash; };
|
uint32 GetClientHash() const { return m_ClientHash; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IGameClient *m_pClient;
|
IGameClient *m_pClient;
|
||||||
CResourceBuffer *m_pResource;
|
CResourceBuffer *m_pResource;
|
||||||
uint32 m_Hash;
|
uint32 m_ClientHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CExecManager
|
class CExecManager
|
||||||
@ -24,7 +24,7 @@ public:
|
|||||||
void Clear(IGameClient *pClient = NULL);
|
void Clear(IGameClient *pClient = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<CBufExec *> CBufExecList;
|
typedef std::list<CBufExec *> CBufExecList;
|
||||||
CBufExecList m_execList;
|
CBufExecList m_execList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ bool OnMetaAttach()
|
|||||||
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponce()->registerHook(&SV_CheckConsistencyResponce);
|
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponce()->registerHook(&SV_CheckConsistencyResponce);
|
||||||
g_RehldsApi->GetHookchains()->SV_DropClient()->registerHook(&SV_DropClient);
|
g_RehldsApi->GetHookchains()->SV_DropClient()->registerHook(&SV_DropClient);
|
||||||
|
|
||||||
SV_AddResource = reinterpret_cast<void (*)(resourcetype_t, const char *, int, unsigned char, int)>(g_RehldsApi->GetFuncs()->SV_AddResource);
|
SV_AddResource = g_RehldsApi->GetFuncs()->SV_AddResource;
|
||||||
|
|
||||||
// initialize resource config
|
// initialize resource config
|
||||||
Resource.Init();
|
Resource.Init();
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#undef __FUNCTION__
|
#undef __FUNCTION__
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring> // strrchr
|
#include <cstring> // strrchr
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
CResourceFile Resource;
|
CResourceFile Resource;
|
||||||
|
std::vector<const char *> StringsCache;
|
||||||
|
|
||||||
void CResourceFile::Add()
|
void CResourceFile::Add()
|
||||||
{
|
{
|
||||||
@ -12,10 +13,10 @@ void CResourceFile::Add()
|
|||||||
|
|
||||||
// prevent duplicate of filenames
|
// prevent duplicate of filenames
|
||||||
// check if filename is been marked so do not add the resource again
|
// check if filename is been marked so do not add the resource again
|
||||||
if (pRes->GetMark() != true) {
|
if (!pRes->IsDuplicate()) {
|
||||||
//#ifdef _DEBUG
|
//#ifdef _DEBUG
|
||||||
if (CVAR_GET_FLOAT("developer") == 1.0f) {
|
if (CVAR_GET_FLOAT("developer") == 1.0f) {
|
||||||
UTIL_Printf(__FUNCTION__ " :: (%s)(%s)(%x)\n", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetHashFile());
|
UTIL_Printf(__FUNCTION__ " :: (%s)(%s)(%x)\n", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
||||||
}
|
}
|
||||||
//#endif // _DEBUG
|
//#endif // _DEBUG
|
||||||
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, 4095);
|
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, 4095);
|
||||||
@ -32,6 +33,8 @@ void CResourceFile::Clear()
|
|||||||
|
|
||||||
// clear resources
|
// clear resources
|
||||||
m_resourceList.clear();
|
m_resourceList.clear();
|
||||||
|
|
||||||
|
ClearStringsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CResourceFile::Init()
|
void CResourceFile::Init()
|
||||||
@ -50,7 +53,7 @@ void CResourceFile::Init()
|
|||||||
*(pos + 1) = '\0';
|
*(pos + 1) = '\0';
|
||||||
|
|
||||||
// resources.ini
|
// resources.ini
|
||||||
snprintf(m_PathDir, sizeof(m_PathDir) - 1, "%s" FILE_INI_RESOURCES, path);
|
snprintf(m_PathDir, sizeof(m_PathDir), "%s" FILE_INI_RESOURCES, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint8 hexbyte(uint8 *hex)
|
inline uint8 hexbyte(uint8 *hex)
|
||||||
@ -86,7 +89,7 @@ bool IsValidFilename(char *psrc, char &pchar) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileIsExtension(char *psrc) {
|
bool IsFileHasExtension(char *psrc) {
|
||||||
|
|
||||||
// find the extension filename
|
// find the extension filename
|
||||||
char *pch = strrchr(psrc, '.');
|
char *pch = strrchr(psrc, '.');
|
||||||
@ -120,12 +123,12 @@ void CResourceFile::Load()
|
|||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
{
|
||||||
m_ConfigFailed = false;
|
m_ConfigFailed = true;
|
||||||
UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_RESOURCES "\n");
|
UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_RESOURCES "\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!feof(fp) && fgets(buffer, sizeof(buffer) - 1, fp))
|
while (!feof(fp) && fgets(buffer, sizeof(buffer), fp))
|
||||||
{
|
{
|
||||||
pos = buffer;
|
pos = buffer;
|
||||||
|
|
||||||
@ -222,7 +225,7 @@ void CResourceFile::Load()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!FileIsExtension(filename)) {
|
else if (!IsFileHasExtension(filename)) {
|
||||||
UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; filename has no extension on line %d\n", cline);
|
UTIL_Printf(__FUNCTION__ ": Failed to load \"" FILE_INI_RESOURCES "\"; filename has no extension on line %d\n", cline);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -251,6 +254,7 @@ void CResourceFile::Load()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
m_ConfigFailed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CResourceFile::GetNextToken(char **pbuf)
|
const char *CResourceFile::GetNextToken(char **pbuf)
|
||||||
@ -347,27 +351,26 @@ void TrimSpace(char *pbuf)
|
|||||||
|
|
||||||
void CResourceFile::AddElement(char *filename, char *cmdExec, int flags, uint32 hash)
|
void CResourceFile::AddElement(char *filename, char *cmdExec, int flags, uint32 hash)
|
||||||
{
|
{
|
||||||
m_resourceList.push_back(new CResourceBuffer(filename, cmdExec, flags, hash));
|
auto nRes = new CResourceBuffer(filename, cmdExec, flags, hash);
|
||||||
|
|
||||||
// to mark files which are not required to add to the resource again
|
// to mark files which are not required to add to the resource again
|
||||||
for (auto iter = m_resourceList.cbegin(); iter != m_resourceList.cend(); ++iter)
|
for (auto iter = m_resourceList.cbegin(); iter != m_resourceList.cend(); ++iter)
|
||||||
{
|
{
|
||||||
CResourceBuffer *pRes = (*iter);
|
CResourceBuffer *pRes = (*iter);
|
||||||
|
|
||||||
// do not check the last element
|
|
||||||
if (pRes == m_resourceList.back())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (_stricmp(pRes->GetFileName(), filename) == 0) {
|
if (_stricmp(pRes->GetFileName(), filename) == 0) {
|
||||||
// set be marked
|
// resource name already registered
|
||||||
pRes->SetMark();
|
nRes->SetDuplicate();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_resourceList.push_back(nRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource_t *resource, uint32 hash)
|
bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource_t *resource, uint32 hash)
|
||||||
{
|
{
|
||||||
bool bCheckeFiles = false;
|
bool bHandled = false;
|
||||||
find_type_e typeFind = FIND_TYPE_NONE;
|
find_type_e typeFind = FIND_TYPE_NONE;
|
||||||
std::vector<CResourceBuffer *> tempResourceList;
|
std::vector<CResourceBuffer *> tempResourceList;
|
||||||
|
|
||||||
@ -378,9 +381,9 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
|||||||
if (strcmp(resource->szFileName, pRes->GetFileName()) != 0)
|
if (strcmp(resource->szFileName, pRes->GetFileName()) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bCheckeFiles = true;
|
bHandled = true;
|
||||||
|
|
||||||
int flags = pRes->GetFlagsFile();
|
int flags = pRes->GetFileFlags();
|
||||||
|
|
||||||
if (flags & FLAG_TYPE_IGNORE)
|
if (flags & FLAG_TYPE_IGNORE)
|
||||||
{
|
{
|
||||||
@ -391,7 +394,7 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
|||||||
}
|
}
|
||||||
else if (flags & FLAG_TYPE_EXISTS)
|
else if (flags & FLAG_TYPE_EXISTS)
|
||||||
{
|
{
|
||||||
if (m_PrevHash != hash && pRes->GetHashFile() == hash) {
|
if (m_PrevHash != hash && pRes->GetFileHash() == hash) {
|
||||||
typeFind = FIND_TYPE_ON_HASH;
|
typeFind = FIND_TYPE_ON_HASH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,7 +417,7 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTemp->GetHashFile() == hash) {
|
if (pTemp->GetFileHash() == hash) {
|
||||||
typeFind = FIND_TYPE_NONE;
|
typeFind = FIND_TYPE_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -431,39 +434,42 @@ bool CResourceFile::FileConsistencyResponce(IGameClient *pSenderClient, resource
|
|||||||
|
|
||||||
//#ifdef _DEBUG
|
//#ifdef _DEBUG
|
||||||
if (CVAR_GET_FLOAT("developer") == 1.0f) {
|
if (CVAR_GET_FLOAT("developer") == 1.0f) {
|
||||||
UTIL_Printf(" -> filename: (%s), cmdexec: (%s), hash: (%x)\n", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetHashFile());
|
UTIL_Printf(" -> filename: (%s), cmdexec: (%s), hash: (%x)\n", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
||||||
}
|
}
|
||||||
//#endif // _DEBUG
|
//#endif // _DEBUG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_PrevHash = hash;
|
m_PrevHash = hash;
|
||||||
return !bCheckeFiles;
|
return !bHandled;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* DuplicateString(const char* str)
|
||||||
|
{
|
||||||
|
for (auto it = StringsCache.begin(), end = StringsCache.end(); it != end; ++it)
|
||||||
|
{
|
||||||
|
if (!strcmp(*it, str))
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* s = strcpy(new char[strlen(str) + 1], str);
|
||||||
|
StringsCache.push_back(s);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearStringsCache()
|
||||||
|
{
|
||||||
|
for (auto it = StringsCache.begin(), end = StringsCache.end(); it != end; ++it)
|
||||||
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, int flags, uint32 hash)
|
CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, int flags, uint32 hash)
|
||||||
{
|
{
|
||||||
int lenFile = strlen(filename);
|
m_FileName = DuplicateString(filename);
|
||||||
int lenExec = strlen(cmdExec);
|
m_CmdExec = DuplicateString(cmdExec);
|
||||||
|
|
||||||
m_FileName = new char[lenFile + 1];
|
m_Duplicate = false;
|
||||||
m_CmdExec = new char[lenExec + 1];
|
|
||||||
|
|
||||||
strncpy(m_FileName, filename, lenFile);
|
|
||||||
strncpy(m_CmdExec, cmdExec, lenExec);
|
|
||||||
|
|
||||||
m_FileName[lenFile] = '\0';
|
|
||||||
m_CmdExec[lenExec] = '\0';
|
|
||||||
|
|
||||||
m_Mark = false;
|
|
||||||
|
|
||||||
m_Flags = flags;
|
m_Flags = flags;
|
||||||
m_HashFile = hash;
|
m_FileHash = hash;
|
||||||
}
|
|
||||||
|
|
||||||
CResourceBuffer::~CResourceBuffer()
|
|
||||||
{
|
|
||||||
// free me
|
|
||||||
delete[] m_FileName,
|
|
||||||
m_CmdExec;
|
|
||||||
}
|
}
|
||||||
|
@ -39,28 +39,27 @@ class CResourceBuffer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CResourceBuffer(char *filename, char *cmdExec, int flags, uint32 hash);
|
CResourceBuffer(char *filename, char *cmdExec, int flags, uint32 hash);
|
||||||
~CResourceBuffer();
|
|
||||||
|
|
||||||
uint32 GetHashFile() const { return m_HashFile; };
|
uint32 GetFileHash() const { return m_FileHash; };
|
||||||
int GetFlagsFile() const { return m_Flags; };
|
int GetFileFlags() const { return m_Flags; };
|
||||||
|
|
||||||
char *GetFileName() const { return m_FileName; };
|
const char *GetFileName() const { return m_FileName; };
|
||||||
char *GetCmdExec() const { return m_CmdExec; };
|
const char *GetCmdExec() const { return m_CmdExec; };
|
||||||
|
|
||||||
bool GetBreak() const { return m_Break; };
|
bool GetBreak() const { return m_Break; };
|
||||||
void SetBreak() { m_Break = true; };
|
void SetBreak() { m_Break = true; };
|
||||||
|
|
||||||
bool GetMark() const { return m_Mark; };
|
bool IsDuplicate() const { return m_Duplicate; };
|
||||||
void SetMark() { m_Mark = true; };
|
void SetDuplicate() { m_Duplicate = true; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 m_HashFile;
|
uint32 m_FileHash;
|
||||||
|
|
||||||
int m_Flags;
|
int m_Flags;
|
||||||
|
|
||||||
char *m_FileName;
|
const char *m_FileName;
|
||||||
char *m_CmdExec;
|
const char *m_CmdExec;
|
||||||
bool m_Mark;
|
bool m_Duplicate;
|
||||||
bool m_Break;
|
bool m_Break;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -93,3 +92,4 @@ private:
|
|||||||
|
|
||||||
extern CResourceFile Resource;
|
extern CResourceFile Resource;
|
||||||
|
|
||||||
|
void ClearStringsCache();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user