From 04afd94aa7f065c02194c203385a12c3547ddc74 Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 18 Jul 2015 16:31:42 +0300 Subject: [PATCH] HookChains refactoring. Added API functions for getting all net message buffers. Added callback for file hash checking. Fixed tests passing if sse 4+ doesn't supported. --- rehlds/engine/cmd.cpp | 2 +- rehlds/engine/net_ws.cpp | 2 +- rehlds/engine/sv_main.cpp | 12 +-- rehlds/engine/sv_steam3.cpp | 4 +- rehlds/engine/sv_user.cpp | 5 +- rehlds/public/rehlds/hookchains.h | 26 +++--- rehlds/public/rehlds/rehlds_api.h | 9 +- rehlds/public/rehlds/rehlds_interfaces.h | 3 + rehlds/rehlds/hookchains_impl.cpp | 21 +---- rehlds/rehlds/hookchains_impl.h | 111 ++++++++++------------- rehlds/rehlds/rehlds_api_impl.cpp | 4 + rehlds/rehlds/rehlds_api_impl.h | 6 ++ rehlds/rehlds/rehlds_interfaces_impl.cpp | 13 +++ rehlds/rehlds/rehlds_interfaces_impl.h | 5 +- rehlds/unittests/crc32c_tests.cpp | 11 ++- rehlds/unittests/mathlib_tests.cpp | 91 +++++++++++++++++-- 16 files changed, 204 insertions(+), 121 deletions(-) diff --git a/rehlds/engine/cmd.cpp b/rehlds/engine/cmd.cpp index 6318c9e..4224795 100644 --- a/rehlds/engine/cmd.cpp +++ b/rehlds/engine/cmd.cpp @@ -998,7 +998,7 @@ void Cmd_ExecuteString(char *text, cmd_source_t src) } IGameClient* cl = (src == src_client) ? GetRehldsApiClient(host_client) : NULL; - if (!g_RehldsHookchains.m_ValidateCommand.callChain(ValidateCmd_API, false, cmd_argv[0], src, cl)) + if (!g_RehldsHookchains.m_ValidateCommand.callChain(ValidateCmd_API, cmd_argv[0], src, cl)) return; g_RehldsHookchains.m_ExecuteServerStringCmd.callChain(Cmd_ExecuteString_internal, cmd_argv[0], src, cl); diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp index 845cc53..e0cd7d8 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -1307,7 +1307,7 @@ bool EXT_FUNC NET_GetPacketPreprocessor(uint8* data, unsigned int len, const net qboolean NET_GetPacket(netsrc_t sock) { qboolean getRes = NET_GetPacket_internal(sock); while (getRes) { - bool pass = g_RehldsHookchains.m_PreprocessPacket.callChain(NET_GetPacketPreprocessor, FALSE, net_message.data, net_message.cursize, net_from); + bool pass = g_RehldsHookchains.m_PreprocessPacket.callChain(NET_GetPacketPreprocessor, net_message.data, net_message.cursize, net_from); if (pass) { return 1; } diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 9e95bec..e290bcf 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1781,7 +1781,7 @@ qboolean EXT_FUNC SV_FilterUser(USERID_t *userid) int SV_CheckProtocol(netadr_t *adr, int nProtocol) { - return g_RehldsHookchains.m_SV_CheckProtocol.callChain(SV_CheckProtocol_internal, 0, adr, nProtocol); + return g_RehldsHookchains.m_SV_CheckProtocol.callChain(SV_CheckProtocol_internal, adr, nProtocol); } /* ../engine/sv_main.c:2302 */ @@ -1868,7 +1868,7 @@ int SV_CheckChallenge(netadr_t *adr, int nChallengeValue) int SV_CheckIPRestrictions(netadr_t *adr, int nAuthProtocol) { - return g_RehldsHookchains.m_SV_CheckIPRestrictions.callChain(SV_CheckIPRestrictions_internal, 0, adr, nAuthProtocol); + return g_RehldsHookchains.m_SV_CheckIPRestrictions.callChain(SV_CheckIPRestrictions_internal, adr, nAuthProtocol); } /* ../engine/sv_main.c:2393 */ @@ -1909,7 +1909,7 @@ int SV_CheckIPConnectionReuse(netadr_t *adr) int SV_FinishCertificateCheck(netadr_t *adr, int nAuthProtocol, char *szRawCertificate, char *userinfo) { - return g_RehldsHookchains.m_SV_FinishCertificateCheck.callChain(SV_FinishCertificateCheck_internal, 0, adr, nAuthProtocol, szRawCertificate, userinfo); + return g_RehldsHookchains.m_SV_FinishCertificateCheck.callChain(SV_FinishCertificateCheck_internal, adr, nAuthProtocol, szRawCertificate, userinfo); } /* ../engine/sv_main.c:2461 */ @@ -1950,7 +1950,7 @@ int EXT_FUNC SV_FinishCertificateCheck_internal(netadr_t *adr, int nAuthProtocol int SV_CheckKeyInfo(netadr_t *adr, char *protinfo, short unsigned int *port, int *pAuthProtocol, char *pszRaw, char *cdkey) { - return g_RehldsHookchains.m_SV_CheckKeyInfo.callChain(SV_CheckKeyInfo_internal, 0, adr, protinfo, port, pAuthProtocol, pszRaw, cdkey); + return g_RehldsHookchains.m_SV_CheckKeyInfo.callChain(SV_CheckKeyInfo_internal, adr, protinfo, port, pAuthProtocol, pszRaw, cdkey); } /* ../engine/sv_main.c:2527 */ @@ -7124,7 +7124,7 @@ void SV_Shutdown(void) qboolean SV_CompareUserID(USERID_t *id1, USERID_t *id2) { - return g_RehldsHookchains.m_SV_CompareUserID.callChain(SV_CompareUserID_internal, 0, id1, id2); + return g_RehldsHookchains.m_SV_CompareUserID.callChain(SV_CompareUserID_internal, id1, id2); } /* ../engine/sv_main.c:9585 */ @@ -7153,7 +7153,7 @@ qboolean EXT_FUNC SV_CompareUserID_internal(USERID_t *id1, USERID_t *id2) char* SV_GetIDString(USERID_t *id) { - return g_RehldsHookchains.m_SV_GetIDString.callChain(SV_GetIDString_internal, 0, id); + return g_RehldsHookchains.m_SV_GetIDString.callChain(SV_GetIDString_internal, id); } /* ../engine/sv_main.c:9625 */ diff --git a/rehlds/engine/sv_steam3.cpp b/rehlds/engine/sv_steam3.cpp index 64d738a..8e9473b 100644 --- a/rehlds/engine/sv_steam3.cpp +++ b/rehlds/engine/sv_steam3.cpp @@ -687,7 +687,7 @@ qboolean EXT_FUNC Steam_NotifyClientConnect_api(IGameClient *cl, const void *pvS qboolean Steam_NotifyClientConnect(client_t *cl, const void *pvSteam2Key, unsigned int ucbSteam2Key) { return g_RehldsHookchains.m_Steam_NotifyClientConnect - .callChain(Steam_NotifyClientConnect_api, FALSE, GetRehldsApiClient(cl), pvSteam2Key, ucbSteam2Key); + .callChain(Steam_NotifyClientConnect_api, GetRehldsApiClient(cl), pvSteam2Key, ucbSteam2Key); } /* ../engine/sv_steam3.cpp:914 */ @@ -707,7 +707,7 @@ qboolean EXT_FUNC Steam_NotifyBotConnect_api(IGameClient* cl) qboolean Steam_NotifyBotConnect(client_t *cl) { - return g_RehldsHookchains.m_Steam_NotifyBotConnect.callChain(Steam_NotifyBotConnect_api, FALSE, GetRehldsApiClient(cl)); + return g_RehldsHookchains.m_Steam_NotifyBotConnect.callChain(Steam_NotifyBotConnect_api, GetRehldsApiClient(cl)); } /* ../engine/sv_steam3.cpp:924 */ diff --git a/rehlds/engine/sv_user.cpp b/rehlds/engine/sv_user.cpp index 2e113b2..450570e 100644 --- a/rehlds/engine/sv_user.cpp +++ b/rehlds/engine/sv_user.cpp @@ -142,7 +142,10 @@ void SV_ParseConsistencyResponse(client_t *pSenderClient) Q_memcpy(resbuffer, r->rguc_reserved, sizeof(resbuffer)); if (!Q_memcmp(resbuffer, nullbuffer, sizeof(resbuffer))) { - if (MSG_ReadBits(32) != *(uint32 *)&r->rgucMD5_hash[0]) + uint32 hash = MSG_ReadBits(32); + g_RehldsHookchains.m_GenericFileConsistencyResponce.callChain(NULL, GetRehldsApiClient(pSenderClient), r, hash); + + if (hash != *(uint32 *)&r->rgucMD5_hash[0]) c = idx + 1; } else diff --git a/rehlds/public/rehlds/hookchains.h b/rehlds/public/rehlds/hookchains.h index 3906fcc..9e16fa8 100644 --- a/rehlds/public/rehlds/hookchains.h +++ b/rehlds/public/rehlds/hookchains.h @@ -30,12 +30,22 @@ template class IHookChain { protected: - virtual ~IHookChain() { } + virtual ~IHookChain() {} public: virtual t_ret callNext(t_args... args) = 0; - virtual t_ret getOriginalReturnResult() = 0; - virtual bool isOriginalCalled() = 0; + virtual t_ret callOriginal(t_args... args) = 0; +}; + +template +class IVoidHookChain +{ +protected: + virtual ~IVoidHookChain() {} + +public: + virtual void callNext(t_args... args) = 0; + virtual void callOriginal(t_args... args) = 0; }; // Hook chain registry(for hooks [un]registration) @@ -48,16 +58,6 @@ public: virtual void unregisterHook(hookfunc_t hook) = 0; }; - - - -template -class IVoidHookChain { -public: - virtual void callNext(t_args... args) = 0; - virtual bool isOriginalCalled() = 0; -}; - // Hook chain registry(for hooks [un]registration) template class IVoidHookChainRegistry { diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index 5f93e1c..ad7823b 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -34,8 +34,8 @@ #include "interface.h" #include "model.h" -#define REHLDS_API_VERSION_MAJOR 1 -#define REHLDS_API_VERSION_MINOR 3 +#define REHLDS_API_VERSION_MAJOR 2 +#define REHLDS_API_VERSION_MINOR 0 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -141,6 +141,10 @@ typedef IVoidHookChainRegistry IRehldsHook_SV_WriteFullClientUpdate; typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_WriteFullClientUpdate; +//SV_GenericFileConsistencyResponce hook +typedef IVoidHookChain IRehldsHook_GenericFileConsistencyResponce; +typedef IVoidHookChainRegistry IRehldsHookRegistry_GenericFileConsistencyResponce; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -171,6 +175,7 @@ public: virtual IRehldsHookRegistry_PF_Remove_I* PF_Remove_I() = 0; virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I() = 0; virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate() = 0; + virtual IRehldsHookRegistry_GenericFileConsistencyResponce* GenericFileConsistencyResponce() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/public/rehlds/rehlds_interfaces.h b/rehlds/public/rehlds/rehlds_interfaces.h index 9fde652..ce46d55 100644 --- a/rehlds/public/rehlds/rehlds_interfaces.h +++ b/rehlds/public/rehlds/rehlds_interfaces.h @@ -77,6 +77,7 @@ public: class INetChan { public: virtual const netadr_t* GetRemoteAdr() = 0; + virtual sizebuf_t* GetMessageBuf() = 0; // this must be the last virtual function in class @@ -108,6 +109,8 @@ public: virtual const char* GetName() = 0; virtual uint32 GetWorldmapCrc() = 0; virtual uint8* GetClientDllMd5() = 0; + virtual sizebuf_t* GetDatagram() = 0; + virtual sizebuf_t* GetReliableDatagram() = 0; virtual void SetModelName(const char* modelname) = 0; }; diff --git a/rehlds/rehlds/hookchains_impl.cpp b/rehlds/rehlds/hookchains_impl.cpp index 1553380..e815822 100644 --- a/rehlds/rehlds/hookchains_impl.cpp +++ b/rehlds/rehlds/hookchains_impl.cpp @@ -17,26 +17,7 @@ */ #include "precompiled.h" - -AbstractHookChain::AbstractHookChain() { - memset(m_Hooks, 0, sizeof(m_Hooks)); - m_NumHooks = 0; - m_CurHook = 0; - m_bOriginalCalled = false; - m_OriginalFunc = NULL; -} - -void* AbstractHookChain::nextHook() { - return (m_CurHook < m_NumHooks) ? m_Hooks[m_CurHook++] : NULL; -} - -void AbstractHookChain::init(void* origFunc, void* hooks, int numHooks) { - m_OriginalFunc = origFunc; - m_NumHooks = numHooks; - m_CurHook = 0; - m_bOriginalCalled = false; - memcpy(m_Hooks, hooks, numHooks * sizeof(size_t)); -} +#include "hookchains_impl.h" AbstractHookChainRegistry::AbstractHookChainRegistry() { diff --git a/rehlds/rehlds/hookchains_impl.h b/rehlds/rehlds/hookchains_impl.h index efee471..db49c41 100644 --- a/rehlds/rehlds/hookchains_impl.h +++ b/rehlds/rehlds/hookchains_impl.h @@ -28,96 +28,82 @@ #pragma once #include "hookchains.h" -#define MAX_HOOKS_IN_CHAIN 64 - -class AbstractHookChain { - -protected: - void* m_Hooks[MAX_HOOKS_IN_CHAIN]; - void* m_OriginalFunc; - int m_CurHook; - int m_NumHooks; - - bool m_bOriginalCalled; - - AbstractHookChain(); - - void* nextHook(); - -public: - void init(void* origFunc, void* hooks, int numHooks); -}; - +#define MAX_HOOKS_IN_CHAIN 63 +// Implementation for chains in modules template -class IHookChainImpl : public IHookChain, public AbstractHookChain { +class IHookChainImpl : public IHookChain { public: typedef t_ret(*hookfunc_t)(IHookChain*, t_args...); typedef t_ret(*origfunc_t)(t_args...); -private: - t_ret m_OriginalReturnResult; - -public: - virtual ~IHookChainImpl() { } - - IHookChainImpl(t_ret defaultResult) { - m_OriginalReturnResult = defaultResult; + IHookChainImpl(void** hooks, origfunc_t orig) : m_Hooks(hooks), m_OriginalFunc(orig) + { + if (orig == NULL) + rehlds_syserror("Non-void HookChain without original function."); } + virtual ~IHookChainImpl() {} + virtual t_ret callNext(t_args... args) { - void* nextvhook = nextHook(); - if (nextvhook) { - hookfunc_t nexthook = (hookfunc_t)nextvhook; - return nexthook(this, args...); + hookfunc_t nexthook = (hookfunc_t)m_Hooks[0]; + + if (nexthook) + { + IHookChainImpl nextChain(m_Hooks + 1, m_OriginalFunc); + return nexthook(&nextChain, args...); } - origfunc_t origfunc = (origfunc_t)m_OriginalFunc; - m_OriginalReturnResult = origfunc(args...); - m_bOriginalCalled = true; - return m_OriginalReturnResult; + return m_OriginalFunc(args...); } - virtual t_ret getOriginalReturnResult() { - return m_OriginalReturnResult; + virtual t_ret callOriginal(t_args... args) { + return m_OriginalFunc(args...); } - virtual bool isOriginalCalled() { - return m_bOriginalCalled; - } +private: + void** m_Hooks; + origfunc_t m_OriginalFunc; }; +// Implementation for void chains in modules template -class IVoidHookChainImpl : public IVoidHookChain, public AbstractHookChain { +class IVoidHookChainImpl : public IVoidHookChain { public: typedef void(*hookfunc_t)(IVoidHookChain*, t_args...); typedef void(*origfunc_t)(t_args...); - virtual ~IVoidHookChainImpl() { } + IVoidHookChainImpl(void** hooks, origfunc_t orig) : m_Hooks(hooks), m_OriginalFunc(orig) {} + virtual ~IVoidHookChainImpl() {} virtual void callNext(t_args... args) { - void* nextvhook = nextHook(); - if (nextvhook) { - hookfunc_t nexthook = (hookfunc_t)nextvhook; - nexthook(this, args...); - return; - } + hookfunc_t nexthook = (hookfunc_t)m_Hooks[0]; + if (nexthook) + { + IVoidHookChainImpl nextChain(m_Hooks + 1, m_OriginalFunc); + nexthook(&nextChain, args...); + } + else + { + if (m_OriginalFunc) + m_OriginalFunc(args...); + } + } + + virtual void callOriginal(t_args... args) { origfunc_t origfunc = (origfunc_t)m_OriginalFunc; - if (origfunc) { - origfunc(args...); - } - m_bOriginalCalled = true; + origfunc(args...); } - virtual bool isOriginalCalled() { - return m_bOriginalCalled; - } +private: + void** m_Hooks; + origfunc_t m_OriginalFunc; }; class AbstractHookChainRegistry { protected: - void* m_Hooks[MAX_HOOKS_IN_CHAIN]; + void* m_Hooks[MAX_HOOKS_IN_CHAIN + 1]; // +1 for null int m_NumHooks; protected: @@ -136,9 +122,8 @@ public: virtual ~IHookChainRegistryImpl() { } - t_ret callChain(origfunc_t origFunc, t_ret defaultResult, t_args... args) { - IHookChainImpl chain(defaultResult); - chain.init((void*)origFunc, m_Hooks, m_NumHooks); + t_ret callChain(origfunc_t origFunc, t_args... args) { + IHookChainImpl chain(m_Hooks, origFunc); return chain.callNext(args...); } @@ -159,14 +144,14 @@ public: virtual ~IVoidHookChainRegistryImpl() { } void callChain(origfunc_t origFunc, t_args... args) { - IVoidHookChainImpl chain; - chain.init((void*)origFunc, m_Hooks, m_NumHooks); + IVoidHookChainImpl chain(m_Hooks, origFunc); chain.callNext(args...); } virtual void registerHook(hookfunc_t hook) { addHook((void*)hook); } + virtual void unregisterHook(hookfunc_t hook) { removeHook((void*)hook); } diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 1d051a0..79ebf27 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -253,6 +253,10 @@ IRehldsHookRegistry_SV_WriteFullClientUpdate* CRehldsHookchains::SV_WriteFullCli return &m_SV_WriteFullClientUpdate; } +IRehldsHookRegistry_GenericFileConsistencyResponce* CRehldsHookchains::GenericFileConsistencyResponce() { + return &m_GenericFileConsistencyResponce; +} + int EXT_FUNC CRehldsApi::GetMajorVersion() { return REHLDS_API_VERSION_MAJOR; diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h index a3b0cac..2c700fb 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -135,6 +135,10 @@ typedef IVoidHookChainRegistryImpl CRehldsHook_SV_WriteFullClientUpdate; typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_WriteFullClientUpdate; +//SV_WriteFullClientUpdate hook +typedef IVoidHookChainImpl CRehldsHook_GenericFileConsistencyResponce; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_GenericFileConsistencyResponce; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -163,6 +167,7 @@ public: CRehldsHookRegistry_PF_Remove_I m_PF_Remove_I; CRehldsHookRegistry_PF_BuildSoundMsg_I m_PF_BuildSoundMsg_I; CRehldsHookRegistry_SV_WriteFullClientUpdate m_SV_WriteFullClientUpdate; + CRehldsHookRegistry_GenericFileConsistencyResponce m_GenericFileConsistencyResponce; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -191,6 +196,7 @@ public: virtual IRehldsHookRegistry_PF_Remove_I* PF_Remove_I(); virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I(); virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate(); + virtual IRehldsHookRegistry_GenericFileConsistencyResponce* GenericFileConsistencyResponce(); }; extern CRehldsHookchains g_RehldsHookchains; diff --git a/rehlds/rehlds/rehlds_interfaces_impl.cpp b/rehlds/rehlds/rehlds_interfaces_impl.cpp index 768091f..2f7c068 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.cpp +++ b/rehlds/rehlds/rehlds_interfaces_impl.cpp @@ -111,6 +111,11 @@ const netadr_t* EXT_FUNC CNetChan::GetRemoteAdr() return &m_pNetChan->remote_address; } +sizebuf_t* EXT_FUNC CNetChan::GetMessageBuf() +{ + return &m_pNetChan->message; +} + netchan_t* EXT_FUNC CNetChan::GetChan() { return m_pNetChan; @@ -178,6 +183,14 @@ uint8* EXT_FUNC CRehldsServerData::GetClientDllMd5() { return g_psv.clientdllmd5; } +sizebuf_t* EXT_FUNC CRehldsServerData::GetDatagram() { + return &g_psv.datagram; +} + +sizebuf_t* EXT_FUNC CRehldsServerData::GetReliableDatagram() { + return &g_psv.reliable_datagram; +} + void Rehlds_Interfaces_FreeClients() { if (g_GameClients == NULL) diff --git a/rehlds/rehlds/rehlds_interfaces_impl.h b/rehlds/rehlds/rehlds_interfaces_impl.h index d311dfa..5224b1f 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.h +++ b/rehlds/rehlds/rehlds_interfaces_impl.h @@ -39,8 +39,7 @@ public: CNetChan(netchan_t* chan); virtual const netadr_t* GetRemoteAdr(); - - + virtual sizebuf_t* GetMessageBuf(); virtual netchan_t* GetChan(); }; @@ -96,6 +95,8 @@ public: virtual const char* GetName(); virtual uint32 GetWorldmapCrc(); virtual uint8* GetClientDllMd5(); + virtual sizebuf_t* GetDatagram(); + virtual sizebuf_t* GetReliableDatagram(); virtual void SetModelName(const char* modelname); }; diff --git a/rehlds/unittests/crc32c_tests.cpp b/rehlds/unittests/crc32c_tests.cpp index 4a4f5f7..7c7c044 100644 --- a/rehlds/unittests/crc32c_tests.cpp +++ b/rehlds/unittests/crc32c_tests.cpp @@ -1,11 +1,20 @@ #include "precompiled.h" #include "rehlds_tests_shared.h" #include "cppunitlite/TestHarness.h" +#include TEST(CRC32C_Hash, CRC32C, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.2 Support", cpuinfo.sse4_2); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_2) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.2 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { const char* src; diff --git a/rehlds/unittests/mathlib_tests.cpp b/rehlds/unittests/mathlib_tests.cpp index 73450ce..203e0f6 100644 --- a/rehlds/unittests/mathlib_tests.cpp +++ b/rehlds/unittests/mathlib_tests.cpp @@ -1,10 +1,19 @@ #include "precompiled.h" #include "rehlds_tests_shared.h" #include "cppunitlite/TestHarness.h" +#include TEST(AngleVectorsTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t angles; @@ -41,7 +50,15 @@ TEST(AngleVectorsTest, MathLib, 1000) { TEST(AngleVectorsTransposeTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t angles; @@ -78,7 +95,15 @@ TEST(AngleVectorsTransposeTest, MathLib, 1000) { TEST(AngleMatrixTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t angles; @@ -120,7 +145,15 @@ TEST(AngleMatrixTest, MathLib, 1000) { TEST(DotProductTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t v1; @@ -146,7 +179,15 @@ TEST(DotProductTest, MathLib, 1000) { TEST(CrossProductTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t v1; @@ -176,7 +217,15 @@ TEST(CrossProductTest, MathLib, 1000) { TEST(LengthTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t v; @@ -201,7 +250,15 @@ TEST(LengthTest, MathLib, 1000) { TEST(Length2DTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t v; @@ -226,7 +283,15 @@ TEST(Length2DTest, MathLib, 1000) { TEST(VectorNormalizeTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t vecIn; @@ -257,7 +322,15 @@ TEST(VectorNormalizeTest, MathLib, 1000) { TEST(VectorAnglesTest, MathLib, 1000) { Sys_CheckCpuInstructionsSupport(); - CHECK("SSE4.1 Support", cpuinfo.sse4_1); + //CHECK("SSE4.1 Support", cpuinfo.sse4_1); + if (!cpuinfo.sse4_1) + { + std::stringstream ss; + ss << "Test '" __FUNCTION__ "' not runned: sse 4.1 doesn't supported"; + std::cout << ss.str() << std::endl; + std::cout.flush(); + return; + } struct testdata_t { vec3_t forward;