Fix: compatibility with work mp_consistency 1

Update rehlsdk
This commit is contained in:
s1lentq 2016-01-11 00:13:02 +06:00
parent 458ac40e41
commit cfb3b69378
5 changed files with 69 additions and 37 deletions

View File

@ -161,6 +161,10 @@ typedef IVoidHookChainRegistry<sizebuf_t *> IRehldsHookRegistry_SV_WriteVoiceCod
typedef IHookChain<uint64> IRehldsHook_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 {
public:
virtual ~IRehldsHookchains() { }
@ -196,6 +200,7 @@ public:
virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer() = 0;
virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec() = 0;
virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID() = 0;
virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo() = 0;
};
struct RehldsFuncs_t {
@ -240,6 +245,7 @@ struct RehldsFuncs_t {
void(*MSG_WriteString)(sizebuf_t *sb, const char *s);
void*(*GetPluginApi)(const char *name);
void(*RegisterPluginApi)(const char *name, void *impl);
qboolean(*SV_FileInConsistencyList)(const char *filename, struct consistency_s **ppconsist);
};
class IRehldsApi {

View File

@ -4,6 +4,7 @@ cvar_t cv_mp_consistency = { "mp_consistency", "0", 0, 0.0f, NULL };
cvar_t *pcv_consistency_old = NULL;
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()
{
@ -62,10 +63,11 @@ bool OnMetaAttach()
// register function from ReHLDS API
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_TransferConsistencyInfo()->registerHook(&SV_TransferConsistencyInfo);
SV_AddResource = g_RehldsApi->GetFuncs()->SV_AddResource;
SV_FileInConsistencyList = g_RehldsApi->GetFuncs()->SV_FileInConsistencyList;
// go to attach
return true;
@ -100,8 +102,8 @@ void OnMetaDetach()
Resource.Clear();
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_TransferConsistencyInfo()->unregisterHook(&SV_TransferConsistencyInfo);
}
void ServerDeactivate_Post()
@ -125,14 +127,15 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool
chain->callNext(pClient, crash, string);
}
void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics)
int SV_TransferConsistencyInfo(IRehldsHook_SV_TransferConsistencyInfo *chain)
{
Resource.LoadResources();
chain->callNext(runPhysics);
// 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)

View File

@ -1,7 +1,8 @@
#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);
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 qboolean (*SV_FileInConsistencyList)(const char *filename, consistency_t **ppconsist);

View File

@ -6,10 +6,10 @@ std::vector<const char *> StringsCache;
cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL };
cvar_t *pcv_rch_log = NULL;
void CResourceFile::CreateResourceList()
int CResourceFile::CreateResourceList()
{
int nConsistency = g_RehldsServerData->GetConsistencyNum();
/*m_DecalsNum = g_RehldsServerData->GetDecalNameNum();*/
int nCustomConsistency = 0;
ComputeConsistencyFiles();
for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter)
{
@ -26,51 +26,69 @@ void CResourceFile::CreateResourceList()
break;
}
// check limit consistency
if (nConsistency >= MAX_CONSISTENCY_LIST)
// not allow to add a resource if the index is larger than 1024 or we will get Bad file data.
// 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;
}
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++*/);
nConsistency++;
SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, 4095);
++nCustomConsistency;
}
}
/*m_DecalsNum = g_RehldsServerData->GetDecalNameNum();*/
g_RehldsServerData->SetConsistencyNum(nConsistency);
// sort
std::vector<resource_t *> sortList;
std::vector<resource_t> sortList;
for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i)
{
resource_t *r = g_RehldsServerData->GetResource(i);
sortList.push_back(new resource_t(*r));
sortList.push_back(*g_RehldsServerData->GetResource(i));
}
// Start a first resource list
g_RehldsServerData->SetResourcesNum(0);
class SortFiles
// sort
std::sort(sortList.begin(), sortList.end(), [](const resource_t &a, const resource_t &b)
{
public:
bool operator()(const resource_t *a, const resource_t *b) const
if (!SV_FileInConsistencyList(b.szFileName, NULL))
{
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
std::sort(sortList.begin(), sortList.end(), SortFiles());
if ((a.ucFlags & RES_CHECKFILE) && !(b.ucFlags & RES_CHECKFILE))
return true;
}
return false;
});
for (auto iter = sortList.cbegin(), end = sortList.cend(); iter != end; ++iter)
{
// Add new resource in the own order
resource_t *r = (*iter);
SV_AddResource(r->type, r->szFileName, r->nDownloadSize, r->ucFlags, r->nIndex);
SV_AddResource(iter->type, iter->szFileName, iter->nDownloadSize, iter->ucFlags, iter->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_DecalsNum = 0;*/
m_ConsistencyNum = 0;
// clear resources
m_resourceList.clear();
@ -526,7 +544,7 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource
std::vector<CResourceBuffer *> tempResourceList;
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
{
AddFileResponse(pSenderClient, resource->szFileName, hash);

View File

@ -2,6 +2,7 @@
#define FILE_INI_RESOURCES "resources.ini"
#define MAX_CMD_LENGTH 128
#define MAX_RANGE_CONSISTENCY 1024
enum flag_type_resources
{
@ -58,7 +59,7 @@ public:
void Init();
void Clear(IGameClient *pClient = NULL);
void LoadResources();
void CreateResourceList();
int CreateResourceList();
void Log(const char *fmt, ...);
bool FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash);
@ -87,6 +88,9 @@ private:
const char *FindFilenameOfHash(uint32 hash);
void LogPrepare();
// compute the total number of consistency files.
void ComputeConsistencyFiles();
// parse
const char *GetNextToken(char **pbuf);
@ -97,7 +101,7 @@ private:
ResourceList m_resourceList;
ResponseList m_responseList;
int m_DecalsNum;
int m_ConsistencyNum;
uint32 m_PrevHash;
char m_PathDir[MAX_PATH_LENGTH];