diff --git a/dep/cppunitlite/include/cppunitlite/Failure.h b/dep/cppunitlite/include/cppunitlite/Failure.h index 1c3260e..90a8e94 100644 --- a/dep/cppunitlite/include/cppunitlite/Failure.h +++ b/dep/cppunitlite/include/cppunitlite/Failure.h @@ -40,6 +40,8 @@ public: Failure (std::string message, std::string testName) { this->testName = testName; this->message = message; + this->fileName = ""; + this->lineNumber = -1; } std::string testName; diff --git a/dep/cppunitlite/src/Assertions.cpp b/dep/cppunitlite/src/Assertions.cpp index f6c03ef..223a2b7 100644 --- a/dep/cppunitlite/src/Assertions.cpp +++ b/dep/cppunitlite/src/Assertions.cpp @@ -14,7 +14,7 @@ void Assertions::StringEquals(std::string message, std::string expected, std::st } void Assertions::StringEquals(std::string message, const char* expected, const char* actual, const char* fileName, long lineNumber) { - if (expected == NULL) { + if (actual == NULL) { std::stringstream ss; ss << message << " (expected '" << expected << "', got NULL"; throw TestFailException(ss.str(), std::string(fileName), lineNumber); diff --git a/dep/cppunitlite/src/Test.cpp b/dep/cppunitlite/src/Test.cpp index 90d8c50..a39d5d7 100644 --- a/dep/cppunitlite/src/Test.cpp +++ b/dep/cppunitlite/src/Test.cpp @@ -11,7 +11,8 @@ Test::Test (const char* testName, const char* testGroup, int timeout) : name_ (testName), group_ (testGroup), timeout_(timeout) { - TestRegistry::addTest (this); + next_ = NULL; + TestRegistry::addTest(this); } diff --git a/rehlds/engine/cmd.cpp b/rehlds/engine/cmd.cpp index 06743f5..3d417ba 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, cmd_argv[0], src, cl)) + if (!g_RehldsHookchains.m_ValidateCommand.callChain(ValidateCmd_API, false, 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 af62af8..ba22100 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -1307,7 +1307,7 @@ bool NET_GetPacketPreprocessor(uint8* data, unsigned int len, const netadr_t& sr qboolean NET_GetPacket(netsrc_t sock) { qboolean getRes = NET_GetPacket_internal(sock); while (getRes) { - bool pass = g_RehldsHookchains.m_PreprocessPacket.callChain(NET_GetPacketPreprocessor, net_message.data, net_message.cursize, net_from); + bool pass = g_RehldsHookchains.m_PreprocessPacket.callChain(NET_GetPacketPreprocessor, FALSE, 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 86fc3b9..6f13488 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1776,7 +1776,7 @@ qboolean SV_FilterUser(USERID_t *userid) int SV_CheckProtocol(netadr_t *adr, int nProtocol) { - return g_RehldsHookchains.m_SV_CheckProtocol.callChain(SV_CheckProtocol_internal, adr, nProtocol); + return g_RehldsHookchains.m_SV_CheckProtocol.callChain(SV_CheckProtocol_internal, 0, adr, nProtocol); } /* ../engine/sv_main.c:2302 */ @@ -1863,7 +1863,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, adr, nAuthProtocol); + return g_RehldsHookchains.m_SV_CheckIPRestrictions.callChain(SV_CheckIPRestrictions_internal, 0, adr, nAuthProtocol); } /* ../engine/sv_main.c:2393 */ @@ -1904,7 +1904,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, adr, nAuthProtocol, szRawCertificate, userinfo); + return g_RehldsHookchains.m_SV_FinishCertificateCheck.callChain(SV_FinishCertificateCheck_internal, 0, adr, nAuthProtocol, szRawCertificate, userinfo); } /* ../engine/sv_main.c:2461 */ @@ -1945,7 +1945,7 @@ int SV_FinishCertificateCheck_internal(netadr_t *adr, int nAuthProtocol, char *s 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, adr, protinfo, port, pAuthProtocol, pszRaw, cdkey); + return g_RehldsHookchains.m_SV_CheckKeyInfo.callChain(SV_CheckKeyInfo_internal, 0, adr, protinfo, port, pAuthProtocol, pszRaw, cdkey); } /* ../engine/sv_main.c:2527 */ @@ -4766,8 +4766,6 @@ void SV_ExtractFromUserinfo(client_t *cl) { const char *val; int i; - client_t *client; - int dupc; char newname[MAX_NAME]; char rawname[MAX_NAME]; @@ -7085,7 +7083,7 @@ void SV_Shutdown(void) qboolean SV_CompareUserID(USERID_t *id1, USERID_t *id2) { - return g_RehldsHookchains.m_SV_CompareUserID.callChain(SV_CompareUserID_internal, id1, id2); + return g_RehldsHookchains.m_SV_CompareUserID.callChain(SV_CompareUserID_internal, 0, id1, id2); } /* ../engine/sv_main.c:9585 */ @@ -7114,7 +7112,7 @@ qboolean 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, id); + return g_RehldsHookchains.m_SV_GetIDString.callChain(SV_GetIDString_internal, 0, id); } /* ../engine/sv_main.c:9625 */ diff --git a/rehlds/engine/sv_steam3.cpp b/rehlds/engine/sv_steam3.cpp index 74d66b5..5bac6ad 100644 --- a/rehlds/engine/sv_steam3.cpp +++ b/rehlds/engine/sv_steam3.cpp @@ -687,7 +687,7 @@ qboolean Steam_NotifyClientConnect_api(IGameClient *cl, const void *pvSteam2Key, qboolean Steam_NotifyClientConnect(client_t *cl, const void *pvSteam2Key, unsigned int ucbSteam2Key) { return g_RehldsHookchains.m_Steam_NotifyClientConnect - .callChain(Steam_NotifyClientConnect_api, GetRehldsApiClient(cl), pvSteam2Key, ucbSteam2Key); + .callChain(Steam_NotifyClientConnect_api, FALSE, GetRehldsApiClient(cl), pvSteam2Key, ucbSteam2Key); } @@ -708,7 +708,7 @@ qboolean Steam_NotifyBotConnect_api(IGameClient* cl) qboolean Steam_NotifyBotConnect(client_t *cl) { - return g_RehldsHookchains.m_Steam_NotifyBotConnect.callChain(Steam_NotifyBotConnect_api, GetRehldsApiClient(cl)); + return g_RehldsHookchains.m_Steam_NotifyBotConnect.callChain(Steam_NotifyBotConnect_api, FALSE, GetRehldsApiClient(cl)); } /* ../engine/sv_steam3.cpp:924 */ diff --git a/rehlds/hookers/rehlds_debug.cpp b/rehlds/hookers/rehlds_debug.cpp index 1db7dfc..8e9f425 100644 --- a/rehlds/hookers/rehlds_debug.cpp +++ b/rehlds/hookers/rehlds_debug.cpp @@ -192,6 +192,7 @@ uint32 calcEdictChecksum(uint32 crc, const edict_t* ed) { } void PrintFloat(const float* pVal, std::stringstream &ss) { + IosFlagSaver iosfs(ss); uint32 sVal = *reinterpret_cast(pVal); ss << "{ float: " << *pVal << "; raw: " << std::hex << sVal << " }"; } @@ -254,6 +255,7 @@ enum PrintEdictFlags_e { void PrintEdict(edict_t* ent, std::stringstream &ss, int flags) { + IosFlagSaver iosfs(ss); if (ent == NULL) { ss << "NULL"; return; @@ -538,18 +540,21 @@ void __cdecl SV_Physics_Step_hooked(edict_t *ent) void Rehlds_Debug_logAlloc(size_t sz, void* ptr) { + IosFlagSaver iosfs(g_RehldsDebugLog); g_RehldsDebugLog << "malloc(" << sz << ") => " << std::hex << (size_t)ptr << "\n"; g_RehldsDebugLog.flush(); } void Rehlds_Debug_logRealloc(size_t sz, void* oldPtr, void* newPtr) { - g_RehldsDebugLog << "realloc(" << std::hex << (size_t)oldPtr << ", " << sz << ") => " << std::hex << (size_t)newPtr << "\n"; + IosFlagSaver iosfs(g_RehldsDebugLog); + g_RehldsDebugLog << "realloc(" << std::hex << (size_t)oldPtr << ", " << sz << ") => " << (size_t)newPtr << "\n"; g_RehldsDebugLog.flush(); } void Rehlds_Debug_logFree(void* ptr) { + IosFlagSaver iosfs(g_RehldsDebugLog); g_RehldsDebugLog << "free(" << std::hex << (size_t)ptr << ")\n"; g_RehldsDebugLog.flush(); } diff --git a/rehlds/msvc/ReHLDS.vcxproj b/rehlds/msvc/ReHLDS.vcxproj index 1a0d1ae..fe328e0 100644 --- a/rehlds/msvc/ReHLDS.vcxproj +++ b/rehlds/msvc/ReHLDS.vcxproj @@ -470,6 +470,7 @@ + diff --git a/rehlds/msvc/ReHLDS.vcxproj.filters b/rehlds/msvc/ReHLDS.vcxproj.filters index 2f416c4..95f298c 100644 --- a/rehlds/msvc/ReHLDS.vcxproj.filters +++ b/rehlds/msvc/ReHLDS.vcxproj.filters @@ -1050,6 +1050,9 @@ public\rehlds + + public + diff --git a/rehlds/public/iosutil.h b/rehlds/public/iosutil.h new file mode 100644 index 0000000..36c7de7 --- /dev/null +++ b/rehlds/public/iosutil.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +class IosFlagSaver { +public: + explicit IosFlagSaver(std::ostream& _ios) : + ios(_ios), + f(_ios.flags()) { + } + ~IosFlagSaver() { + ios.flags(f); + } + + IosFlagSaver(const IosFlagSaver &rhs) = delete; + IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete; + +private: + std::ostream& ios; + std::ios::fmtflags f; +}; diff --git a/rehlds/public/rehlds/crc32c.cpp b/rehlds/public/rehlds/crc32c.cpp index 6dd7758..ac33355 100644 --- a/rehlds/public/rehlds/crc32c.cpp +++ b/rehlds/public/rehlds/crc32c.cpp @@ -12,7 +12,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ -#include "crc32c.h" +#include "crc32c.h" #include "sys_shared.h" #include "immintrin.h" @@ -120,22 +120,22 @@ uint32 crc32c_t8_sse(uint32 iCRC, uint8 u8) { } uint32 crc32c_t_sse(uint32 iCRC, const uint8 *buf, unsigned int len) { - uint32 crc32cval = iCRC; - unsigned int i = 0; - - for (; i < (len >> 2); i += 4) { - crc32cval = _mm_crc32_u32(crc32cval, *(uint32*)&buf[i]); - } - - for (; i < len; i++) { - crc32cval = _mm_crc32_u8(crc32cval, buf[i]); - } - + uint32 crc32cval = iCRC; + unsigned int i = 0; + + for (; i < (len >> 2); i += 4) { + crc32cval = _mm_crc32_u32(crc32cval, *(uint32*)&buf[i]); + } + + for (; i < len; i++) { + crc32cval = _mm_crc32_u8(crc32cval, buf[i]); + } + return crc32cval; } uint32 crc32c_t(uint32 iCRC, const uint8 *buf, unsigned int len) { - return cpuinfo.sse4_2 ? crc32c_t_nosse(iCRC, buf, len) : crc32c_t_nosse(iCRC, buf, len); + return cpuinfo.sse4_2 ? crc32c_t_sse(iCRC, buf, len) : crc32c_t_nosse(iCRC, buf, len); } uint32 crc32c(const uint8 *buf, int len) { diff --git a/rehlds/rehlds/hookchains_impl.cpp b/rehlds/rehlds/hookchains_impl.cpp index 972cf8d..7ef5c90 100644 --- a/rehlds/rehlds/hookchains_impl.cpp +++ b/rehlds/rehlds/hookchains_impl.cpp @@ -19,6 +19,7 @@ #include "precompiled.h" AbstractHookChain::AbstractHookChain() { + memset(m_Hooks, 0, sizeof(m_Hooks)); m_NumHooks = 0; m_CurHook = 0; m_bOriginalCalled = false; @@ -39,6 +40,7 @@ void AbstractHookChain::init(void* origFunc, void* hooks, int numHooks) { AbstractHookChainRegistry::AbstractHookChainRegistry() { + memset(m_Hooks, 0, sizeof(m_Hooks)); m_NumHooks = 0; } diff --git a/rehlds/rehlds/hookchains_impl.h b/rehlds/rehlds/hookchains_impl.h index 139cdd3..34bf8d2 100644 --- a/rehlds/rehlds/hookchains_impl.h +++ b/rehlds/rehlds/hookchains_impl.h @@ -60,6 +60,11 @@ private: public: virtual ~IHookChainImpl() { } + + IHookChainImpl(t_ret defaultResult) { + m_OriginalReturnResult = defaultResult; + } + virtual t_ret callNext(t_args... args) { void* nextvhook = nextHook(); if (nextvhook) { @@ -130,8 +135,8 @@ public: virtual ~IHookChainRegistryImpl() { } - t_ret callChain(origfunc_t origFunc, t_args... args) { - IHookChainImpl chain; + t_ret callChain(origfunc_t origFunc, t_ret defaultResult, t_args... args) { + IHookChainImpl chain(defaultResult); chain.init((void*)origFunc, m_Hooks, m_NumHooks); return chain.callNext(args...); } diff --git a/rehlds/rehlds/precompiled.h b/rehlds/rehlds/precompiled.h index 0bc1c3b..0639d6a 100644 --- a/rehlds/rehlds/precompiled.h +++ b/rehlds/rehlds/precompiled.h @@ -33,6 +33,8 @@ #include "utlbuffer.h" #include "utlrbtree.h" +#include "iosutil.h" + //testsuite #include "testsuite.h" #include "funccalls.h" diff --git a/rehlds/testsuite/anonymizer.cpp b/rehlds/testsuite/anonymizer.cpp index 5e0b67a..b1d96b3 100644 --- a/rehlds/testsuite/anonymizer.cpp +++ b/rehlds/testsuite/anonymizer.cpp @@ -1,12 +1,5 @@ #include "precompiled.h" -uint64 NET_AdrToLong(const netadr_t &a) { - if (a.type != NA_IP) - return -1; - - return a.ip[0] | (a.ip[1] << 8) | (a.ip[2] << 16) | (a.ip[3] << 24) | (uint64)a.port << 32; -} - CSteamCallbackAnonymizingWrapper::CSteamCallbackAnonymizingWrapper(CAnonymizingEngExtInterceptor* anonymizer, CCallbackBase* cb, int id) { m_Anonymizer = anonymizer;