mirror of
https://github.com/rehlds/rechecker.git
synced 2025-01-29 03:47:55 +03:00
Fix: compatibility with work mp_consistency 1
Update rehlsdk
This commit is contained in:
parent
458ac40e41
commit
cfb3b69378
@ -161,6 +161,10 @@ typedef IVoidHookChainRegistry<sizebuf_t *> IRehldsHookRegistry_SV_WriteVoiceCod
|
|||||||
typedef IHookChain<uint64> IRehldsHook_Steam_GSGetSteamID;
|
typedef IHookChain<uint64> IRehldsHook_Steam_GSGetSteamID;
|
||||||
typedef IHookChainRegistry<uint64> IRehldsHookRegistry_Steam_GSGetSteamID;
|
typedef IHookChainRegistry<uint64> IRehldsHookRegistry_Steam_GSGetSteamID;
|
||||||
|
|
||||||
|
//SV_TransferConsistencyInfo hook
|
||||||
|
typedef IHookChain<int> IRehldsHook_SV_TransferConsistencyInfo;
|
||||||
|
typedef IHookChainRegistry<int> IRehldsHookRegistry_SV_TransferConsistencyInfo;
|
||||||
|
|
||||||
class IRehldsHookchains {
|
class IRehldsHookchains {
|
||||||
public:
|
public:
|
||||||
virtual ~IRehldsHookchains() { }
|
virtual ~IRehldsHookchains() { }
|
||||||
@ -196,6 +200,7 @@ public:
|
|||||||
virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer() = 0;
|
virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer() = 0;
|
||||||
virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec() = 0;
|
virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec() = 0;
|
||||||
virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID() = 0;
|
virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID() = 0;
|
||||||
|
virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RehldsFuncs_t {
|
struct RehldsFuncs_t {
|
||||||
@ -240,6 +245,7 @@ struct RehldsFuncs_t {
|
|||||||
void(*MSG_WriteString)(sizebuf_t *sb, const char *s);
|
void(*MSG_WriteString)(sizebuf_t *sb, const char *s);
|
||||||
void*(*GetPluginApi)(const char *name);
|
void*(*GetPluginApi)(const char *name);
|
||||||
void(*RegisterPluginApi)(const char *name, void *impl);
|
void(*RegisterPluginApi)(const char *name, void *impl);
|
||||||
|
qboolean(*SV_FileInConsistencyList)(const char *filename, struct consistency_s **ppconsist);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IRehldsApi {
|
class IRehldsApi {
|
||||||
|
15
src/main.cpp
15
src/main.cpp
@ -4,6 +4,7 @@ cvar_t cv_mp_consistency = { "mp_consistency", "0", 0, 0.0f, NULL };
|
|||||||
cvar_t *pcv_consistency_old = NULL;
|
cvar_t *pcv_consistency_old = NULL;
|
||||||
|
|
||||||
void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
||||||
|
qboolean (*SV_FileInConsistencyList)(const char *filename, consistency_t **ppconsist);
|
||||||
|
|
||||||
bool OnMetaAttach()
|
bool OnMetaAttach()
|
||||||
{
|
{
|
||||||
@ -62,10 +63,11 @@ bool OnMetaAttach()
|
|||||||
|
|
||||||
// register function from ReHLDS API
|
// register function from ReHLDS API
|
||||||
g_RehldsApi->GetHookchains()->SV_DropClient()->registerHook(&SV_DropClient);
|
g_RehldsApi->GetHookchains()->SV_DropClient()->registerHook(&SV_DropClient);
|
||||||
g_RehldsApi->GetHookchains()->SV_ActivateServer()->registerHook(&SV_ActivateServer);
|
|
||||||
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponse()->registerHook(&SV_CheckConsistencyResponse);
|
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponse()->registerHook(&SV_CheckConsistencyResponse);
|
||||||
|
g_RehldsApi->GetHookchains()->SV_TransferConsistencyInfo()->registerHook(&SV_TransferConsistencyInfo);
|
||||||
|
|
||||||
SV_AddResource = g_RehldsApi->GetFuncs()->SV_AddResource;
|
SV_AddResource = g_RehldsApi->GetFuncs()->SV_AddResource;
|
||||||
|
SV_FileInConsistencyList = g_RehldsApi->GetFuncs()->SV_FileInConsistencyList;
|
||||||
|
|
||||||
// go to attach
|
// go to attach
|
||||||
return true;
|
return true;
|
||||||
@ -100,8 +102,8 @@ void OnMetaDetach()
|
|||||||
Resource.Clear();
|
Resource.Clear();
|
||||||
|
|
||||||
g_RehldsApi->GetHookchains()->SV_DropClient()->unregisterHook(&SV_DropClient);
|
g_RehldsApi->GetHookchains()->SV_DropClient()->unregisterHook(&SV_DropClient);
|
||||||
g_RehldsApi->GetHookchains()->SV_ActivateServer()->unregisterHook(&SV_ActivateServer);
|
|
||||||
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponse()->unregisterHook(&SV_CheckConsistencyResponse);
|
g_RehldsApi->GetHookchains()->SV_CheckConsistencyResponse()->unregisterHook(&SV_CheckConsistencyResponse);
|
||||||
|
g_RehldsApi->GetHookchains()->SV_TransferConsistencyInfo()->unregisterHook(&SV_TransferConsistencyInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerDeactivate_Post()
|
void ServerDeactivate_Post()
|
||||||
@ -125,14 +127,15 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool
|
|||||||
chain->callNext(pClient, crash, string);
|
chain->callNext(pClient, crash, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics)
|
int SV_TransferConsistencyInfo(IRehldsHook_SV_TransferConsistencyInfo *chain)
|
||||||
{
|
{
|
||||||
Resource.LoadResources();
|
Resource.LoadResources();
|
||||||
|
|
||||||
chain->callNext(runPhysics);
|
|
||||||
|
|
||||||
// add to the resource
|
// add to the resource
|
||||||
Resource.CreateResourceList();
|
int nConsistency = Resource.CreateResourceList();
|
||||||
|
|
||||||
|
// returns the total number of consistency files
|
||||||
|
return chain->callNext() + nConsistency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPutInServer_Post(edict_t *pEntity)
|
void ClientPutInServer_Post(edict_t *pEntity)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics);
|
|
||||||
void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool crash, const char *string);
|
void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool crash, const char *string);
|
||||||
bool SV_CheckConsistencyResponse(IRehldsHook_SV_CheckConsistencyResponse *chain, IGameClient *pSenderClient, resource_t *resource, uint32 hash);
|
bool SV_CheckConsistencyResponse(IRehldsHook_SV_CheckConsistencyResponse *chain, IGameClient *pSenderClient, resource_t *resource, uint32 hash);
|
||||||
|
int SV_TransferConsistencyInfo(IRehldsHook_SV_TransferConsistencyInfo *chain);
|
||||||
|
|
||||||
extern void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
extern void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
||||||
|
extern qboolean (*SV_FileInConsistencyList)(const char *filename, consistency_t **ppconsist);
|
||||||
|
@ -6,10 +6,10 @@ std::vector<const char *> StringsCache;
|
|||||||
cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL };
|
cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL };
|
||||||
cvar_t *pcv_rch_log = NULL;
|
cvar_t *pcv_rch_log = NULL;
|
||||||
|
|
||||||
void CResourceFile::CreateResourceList()
|
int CResourceFile::CreateResourceList()
|
||||||
{
|
{
|
||||||
int nConsistency = g_RehldsServerData->GetConsistencyNum();
|
int nCustomConsistency = 0;
|
||||||
/*m_DecalsNum = g_RehldsServerData->GetDecalNameNum();*/
|
ComputeConsistencyFiles();
|
||||||
|
|
||||||
for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter)
|
for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
@ -26,51 +26,69 @@ void CResourceFile::CreateResourceList()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check limit consistency
|
// not allow to add a resource if the index is larger than 1024 or we will get Bad file data.
|
||||||
if (nConsistency >= MAX_CONSISTENCY_LIST)
|
// https://github.com/dreamstalker/rehlds/blob/master/rehlds/engine/sv_user.cpp#L362
|
||||||
|
if (nCustomConsistency + m_ConsistencyNum >= MAX_RANGE_CONSISTENCY)
|
||||||
{
|
{
|
||||||
UTIL_Printf(__FUNCTION__ ": can't add consistency \"%s\" on line %d; exceeded the limit of consistency max '%d'\n", pRes->GetFileName(), pRes->GetLine(), MAX_CONSISTENCY_LIST);
|
UTIL_Printf(__FUNCTION__ ": can't add consistency \"%s\" on line %d; index out of bounds '%d'\n", pRes->GetFileName(), pRes->GetLine(), MAX_RANGE_CONSISTENCY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(__FUNCTION__ " -> file: (%s), cmdexc: (%s), hash: (%x)", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
Log(__FUNCTION__ " -> file: (%s), cmdexc: (%s), hash: (%x)", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash());
|
||||||
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, 4095/*m_DecalsNum++*/);
|
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, 4095);
|
||||||
nConsistency++;
|
++nCustomConsistency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*m_DecalsNum = g_RehldsServerData->GetDecalNameNum();*/
|
std::vector<resource_t> sortList;
|
||||||
g_RehldsServerData->SetConsistencyNum(nConsistency);
|
|
||||||
|
|
||||||
// sort
|
|
||||||
std::vector<resource_t *> sortList;
|
|
||||||
|
|
||||||
for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i)
|
for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i)
|
||||||
{
|
{
|
||||||
resource_t *r = g_RehldsServerData->GetResource(i);
|
sortList.push_back(*g_RehldsServerData->GetResource(i));
|
||||||
sortList.push_back(new resource_t(*r));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a first resource list
|
// Start a first resource list
|
||||||
g_RehldsServerData->SetResourcesNum(0);
|
g_RehldsServerData->SetResourcesNum(0);
|
||||||
|
|
||||||
class SortFiles
|
// sort
|
||||||
|
std::sort(sortList.begin(), sortList.end(), [](const resource_t &a, const resource_t &b)
|
||||||
{
|
{
|
||||||
public:
|
if (!SV_FileInConsistencyList(b.szFileName, NULL))
|
||||||
bool operator()(const resource_t *a, const resource_t *b) const
|
|
||||||
{
|
{
|
||||||
return (a->ucFlags & RES_CHECKFILE) != 0;
|
// pre-sort the consistency files that which will have the flag RES_CHECKFILE.
|
||||||
}
|
if (SV_FileInConsistencyList(a.szFileName, NULL))
|
||||||
};
|
return true;
|
||||||
|
|
||||||
// sort by flag RES_CHECKFILE
|
if ((a.ucFlags & RES_CHECKFILE) && !(b.ucFlags & RES_CHECKFILE))
|
||||||
std::sort(sortList.begin(), sortList.end(), SortFiles());
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
for (auto iter = sortList.cbegin(), end = sortList.cend(); iter != end; ++iter)
|
for (auto iter = sortList.cbegin(), end = sortList.cend(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
// Add new resource in the own order
|
// Add new resource in the own order
|
||||||
resource_t *r = (*iter);
|
SV_AddResource(iter->type, iter->szFileName, iter->nDownloadSize, iter->ucFlags, iter->nIndex);
|
||||||
SV_AddResource(r->type, r->szFileName, r->nDownloadSize, r->ucFlags, r->nIndex);
|
}
|
||||||
|
|
||||||
|
sortList.clear();
|
||||||
|
return nCustomConsistency;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CResourceFile::ComputeConsistencyFiles()
|
||||||
|
{
|
||||||
|
m_ConsistencyNum = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i)
|
||||||
|
{
|
||||||
|
resource_t *r = g_RehldsServerData->GetResource(i);
|
||||||
|
|
||||||
|
if (r->ucFlags == (RES_CUSTOM | RES_REQUESTED | RES_UNK_6) || (r->ucFlags & RES_CHECKFILE))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (SV_FileInConsistencyList(r->szFileName, NULL))
|
||||||
|
++m_ConsistencyNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +117,7 @@ void CResourceFile::Clear(IGameClient *pClient)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_PrevHash = 0;
|
m_PrevHash = 0;
|
||||||
/*m_DecalsNum = 0;*/
|
m_ConsistencyNum = 0;
|
||||||
|
|
||||||
// clear resources
|
// clear resources
|
||||||
m_resourceList.clear();
|
m_resourceList.clear();
|
||||||
@ -526,8 +544,8 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource
|
|||||||
std::vector<CResourceBuffer *> tempResourceList;
|
std::vector<CResourceBuffer *> tempResourceList;
|
||||||
|
|
||||||
if (resource->type != t_decal
|
if (resource->type != t_decal
|
||||||
|| resource->nIndex != 4095/*< m_DecalsNum*/) // if by some miracle the decals will have the flag RES_CHECKFILE
|
|| resource->nIndex != 4095) // if by some miracle the decals will have the flag RES_CHECKFILE
|
||||||
// to be sure not bypass the decals
|
// to be sure not bypass the decals
|
||||||
{
|
{
|
||||||
AddFileResponse(pSenderClient, resource->szFileName, hash);
|
AddFileResponse(pSenderClient, resource->szFileName, hash);
|
||||||
m_PrevHash = hash;
|
m_PrevHash = hash;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#define FILE_INI_RESOURCES "resources.ini"
|
#define FILE_INI_RESOURCES "resources.ini"
|
||||||
#define MAX_CMD_LENGTH 128
|
#define MAX_CMD_LENGTH 128
|
||||||
|
#define MAX_RANGE_CONSISTENCY 1024
|
||||||
|
|
||||||
enum flag_type_resources
|
enum flag_type_resources
|
||||||
{
|
{
|
||||||
@ -58,7 +59,7 @@ public:
|
|||||||
void Init();
|
void Init();
|
||||||
void Clear(IGameClient *pClient = NULL);
|
void Clear(IGameClient *pClient = NULL);
|
||||||
void LoadResources();
|
void LoadResources();
|
||||||
void CreateResourceList();
|
int CreateResourceList();
|
||||||
void Log(const char *fmt, ...);
|
void Log(const char *fmt, ...);
|
||||||
|
|
||||||
bool FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash);
|
bool FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash);
|
||||||
@ -87,6 +88,9 @@ private:
|
|||||||
const char *FindFilenameOfHash(uint32 hash);
|
const char *FindFilenameOfHash(uint32 hash);
|
||||||
void LogPrepare();
|
void LogPrepare();
|
||||||
|
|
||||||
|
// compute the total number of consistency files.
|
||||||
|
void ComputeConsistencyFiles();
|
||||||
|
|
||||||
// parse
|
// parse
|
||||||
const char *GetNextToken(char **pbuf);
|
const char *GetNextToken(char **pbuf);
|
||||||
|
|
||||||
@ -97,7 +101,7 @@ private:
|
|||||||
ResourceList m_resourceList;
|
ResourceList m_resourceList;
|
||||||
ResponseList m_responseList;
|
ResponseList m_responseList;
|
||||||
|
|
||||||
int m_DecalsNum;
|
int m_ConsistencyNum;
|
||||||
uint32 m_PrevHash;
|
uint32 m_PrevHash;
|
||||||
|
|
||||||
char m_PathDir[MAX_PATH_LENGTH];
|
char m_PathDir[MAX_PATH_LENGTH];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user