diff --git a/Makefile b/Makefile index 6c6579e..ca7ae1c 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ COMPILER = /opt/intel/bin/icpc OBJECTS = src/main.cpp src/meta_api.cpp src/dllapi.cpp\ src/cmdexec.cpp src/engine_rehlds.cpp src/h_export.cpp\ - src/resource.cpp src/sdk_util.cpp public/interface.cpp\ - src/task.cpp + src/resource.cpp src/sdk_util.cpp public/interface.cpp LINK = -lm -ldl -static-intel -static-libgcc -no-intel-extensions diff --git a/common/const.h b/common/const.h index 921afb6..e8e3743 100644 --- a/common/const.h +++ b/common/const.h @@ -19,6 +19,18 @@ #pragma once #endif +// Max # of clients allowed in a server. +#define MAX_CLIENTS 32 + +// How many bits to use to encode an edict. +#define MAX_EDICT_BITS 11 // # of bits needed to represent max edicts +// Max # of edicts in a level (2048) +#define MAX_EDICTS (1< ../common/mathlib.h:3 */ typedef float vec_t; /* <42b91> ../common/mathlib.h:6 */ -#ifndef DID_VEC3_T_DEFINE +#if !defined DID_VEC3_T_DEFINE && !defined vec3_t #define DID_VEC3_T_DEFINE typedef vec_t vec3_t[3]; #endif @@ -41,6 +41,50 @@ typedef union DLONG_u #define M_PI 3.14159265358979323846 +#ifdef __cplusplus +#ifdef min +#undef min +#endif + +#ifdef max +#undef max +#endif + +#ifdef clamp +#undef clamp +#endif + +template +inline T min(T a, T b) { + return (a < b) ? a : b; +} + +template +inline T max(T a, T b) { + return (a < b) ? b : a; +} + +template +inline T clamp(T a, T min, T max) { + return (a > max) ? max : (a < min) ? min : a; +} + +template +inline T bswap(T s) { + switch (sizeof(T)) { +#ifdef _WIN32 + case 2: {auto res = _byteswap_ushort(*(uint16 *)&s); return *(T *)&res;} + case 4: {auto res = _byteswap_ulong(*(uint32 *)(&s)); return *(T *)&res;} + case 8: {auto res = _byteswap_uint64(*(uint64 *)&s); return *(T *)&res;} +#else + case 2: {auto res = _bswap16(*(uint16 *)&s); return *(T *)&res;} + case 4: {auto res = _bswap(*(uint32 *)&s); return *(T *)&res;} + case 8: {auto res = _bswap64(*(uint64 *)&s); return *(T *)&res;} +#endif + default: return s; + } +} +#else // __cplusplus #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif @@ -50,3 +94,6 @@ typedef union DLONG_u #endif #define clamp(val, min, max) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val))) +#endif // __cplusplus + +#endif // MATHLIB_H diff --git a/common/qlimits.h b/common/qlimits.h new file mode 100644 index 0000000..3fad403 --- /dev/null +++ b/common/qlimits.h @@ -0,0 +1,39 @@ +//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ========== +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef QLIMITS_H +#define QLIMITS_H + +#if defined( _WIN32 ) +#pragma once +#endif + +// DATA STRUCTURE INFO + +#define MAX_NUM_ARGVS 50 + +// SYSTEM INFO +#define MAX_QPATH 64 // max length of a game pathname +#define MAX_OSPATH 260 // max length of a filesystem pathname + +#define ON_EPSILON 0.1 // point on plane side epsilon + +#define MAX_LIGHTSTYLE_INDEX_BITS 6 +#define MAX_LIGHTSTYLES (1< ../common/quakedef.h:29 */ typedef int BOOL; /* size: 4 */ +// user message +#define MAX_USER_MSG_DATA 192 + /* <627f> ../common/quakedef.h:137 */ //moved to com_model.h //typedef struct cache_user_s diff --git a/dist/config.ini b/dist/config.ini deleted file mode 100644 index e9a1bdd..0000000 --- a/dist/config.ini +++ /dev/null @@ -1,5 +0,0 @@ -# -# delay_exec 0|60 Delay before executing the all cmdexec -# - -delay_exec = 3.5 diff --git a/dist/resources.ini b/dist/resources.ini index 3654b44..534fdd1 100644 --- a/dist/resources.ini +++ b/dist/resources.ini @@ -11,8 +11,8 @@ # [file_md5hash] - md5hash the file of responce client # # -> Format -# path to file hash (exec cmd) -# "../opengl32.dll" 3cc7f256fab2fd6bbb3eb65a118b0ef0 "kick [userid]" +# path to file hash (exec cmd) +# "../opengl32.dll" 3cc7f256 "kick [userid]" # # NOTE: Hash enough 4 bytes (or 8 characters) # -> Example @@ -30,10 +30,10 @@ # ; DemoPlayer.dll base of bad files -"../demoplayer.dll" ad6d0e43 "amx_kick [userid] 'WallHack Detected'" BREAK -"../demoplayer.dll" cca8c33f "amx_kick [userid] 'WallHack Detected'" BREAK -"../demoplayer.dll" 36ad16fd "amx_kick [userid] 'NoRecoil Detected'" BREAK -"../demoplayer.dll" c599a6de "amx_kick [userid] 'HLR Leis 10 Detected'" BREAK +"../demoplayer.dll" ad6d0e43 "kick [userid] 'WallHack Detected'" BREAK +"../demoplayer.dll" cca8c33f "kick [userid] 'WallHack Detected'" BREAK +"../demoplayer.dll" 36ad16fd "kick [userid] 'NoRecoil Detected'" BREAK +"../demoplayer.dll" c599a6de "kick [userid] 'HLR Leis 10 Detected'" BREAK ; DemoPlayer.dll to ignore the original files "../demoplayer.dll" 7ef5b581 IGNORE @@ -43,28 +43,28 @@ "../demoplayer.dll" UNKNOWN "echo ' -> file: ([file_name]), md5hex: ([file_md5hash]) for ([name])'" ; OpenGL.dll -"../opengl32.dll" UNKNOWN "amx_kick [userid] 'OpenGL32 Detected'" BREAK +"../opengl32.dll" UNKNOWN "kick [userid] 'OpenGL32 Detected'" BREAK ; Leis -"../bin/TrackerUI.dll" UNKNOWN "amx_kick [userid] 'Leis [#1] Detected'" BREAK -"../bin/standard.ini" UNKNOWN "amx_kick [userid] 'Leis [#2] Detected'" BREAK -"../standard.ini" UNKNOWN "amx_kick [userid] 'Leis [#3] Detected'" BREAK +"../bin/TrackerUI.dll" UNKNOWN "kick [userid] 'Leis [#1] Detected'" BREAK +"../bin/standard.ini" UNKNOWN "kick [userid] 'Leis [#2] Detected'" BREAK +"../standard.ini" UNKNOWN "kick [userid] 'Leis [#3] Detected'" BREAK ; Intelligent AimBot -"../log.txt" UNKNOWN "amx_kick [userid] 'Intelligent Detected'" BREAK +"../log.txt" UNKNOWN "kick [userid] 'Intelligent Detected'" BREAK ; WallHack -"../[1.6]wh2k13.dll" UNKNOWN "amx_kick [userid] 'Simple Wallhack Detected'" BREAK -"../inFaMous GL.dll" UNKNOWN "amx_kick [userid] 'nFaMous GL Detected'" BREAK -"../skillwall.dll" UNKNOWN "amx_kick [userid] 'WallHack Detected'" BREAK -"../jtx.dll" UNKNOWN "amx_kick [userid] 'WallHack Detected'" BREAK -"../jtx.asi" UNKNOWN "amx_kick [userid] 'WallHack Detected'" BREAK -"../FPTHook.dll" UNKNOWN "amx_kick [userid] 'WallHack Detected'" BREAK +"../[1.6]wh2k13.dll" UNKNOWN "kick [userid] 'Simple Wallhack Detected'" BREAK +"../inFaMous GL.dll" UNKNOWN "kick [userid] 'nFaMous GL Detected'" BREAK +"../skillwall.dll" UNKNOWN "kick [userid] 'WallHack Detected'" BREAK +"../jtx.dll" UNKNOWN "kick [userid] 'WallHack Detected'" BREAK +"../jtx.asi" UNKNOWN "kick [userid] 'WallHack Detected'" BREAK +"../FPTHook.dll" UNKNOWN "kick [userid] 'WallHack Detected'" BREAK ; SSW -"../SSWv6.4.dll" UNKNOWN "amx_kick [userid] '[SSW]WallHack Detected'" BREAK -"../sswv7.0.dll" UNKNOWN "amx_kick [userid] '[SSW]WallHack Detected'" BREAK -"../sswv7.3_[www.unknowncheats.me]_.dll" UNKNOWN "amx_kick [userid] '[SSW]WallHack Detected'" BREAK +"../SSWv6.4.dll" UNKNOWN "kick [userid] '[SSW]WallHack Detected'" BREAK +"../sswv7.0.dll" UNKNOWN "kick [userid] '[SSW]WallHack Detected'" BREAK +"../sswv7.3_[www.unknowncheats.me]_.dll" UNKNOWN "kick [userid] '[SSW]WallHack Detected'" BREAK ; ESP -"../esp.dll" UNKNOWN "amx_kick [userid] 'ESP Detected'" BREAK +"../esp.dll" UNKNOWN "kick [userid] 'ESP Detected'" BREAK diff --git a/engine/common_rehlds.h b/engine/common_rehlds.h index d397b59..c7c4ed7 100644 --- a/engine/common_rehlds.h +++ b/engine/common_rehlds.h @@ -28,8 +28,13 @@ #pragma once #include "const.h" +#include "qlimits.h" +#ifdef REHLDS_FIXES +#define COM_TOKEN_LEN 2048 +#else #define COM_TOKEN_LEN 1024 +#endif // Don't allow overflow #define SIZEBUF_CHECK_OVERFLOW 0 diff --git a/engine/crc32c.cpp b/engine/crc32c.cpp new file mode 100644 index 0000000..1220c50 --- /dev/null +++ b/engine/crc32c.cpp @@ -0,0 +1,143 @@ +/* +Copyright (C) 2010 by Ronnie Sahlberg +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, see . +*/ + +#include "crc32c.h" +#include "sys_shared.h" +#include "immintrin.h" + +/*****************************************************************/ +/* */ +/* CRC LOOKUP TABLE */ +/* ================ */ +/* The following CRC lookup table was generated automagically */ +/* by the Rocksoft^tm Model CRC Algorithm Table Generation */ +/* Program V1.0 using the following model parameters: */ +/* */ +/* Width : 4 bytes. */ +/* Poly : 0x1EDC6F41L */ +/* Reverse : TRUE. */ +/* */ +/* For more information on the Rocksoft^tm Model CRC Algorithm, */ +/* see the document titled "A Painless Guide to CRC Error */ +/* Detection Algorithms" by Ross Williams */ +/* (ross@guest.adelaide.edu.au.). This document is likely to be */ +/* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */ +/* */ +/*****************************************************************/ + +static uint32 crctable[256] = { + 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, + 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, + 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, + 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, + 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, + 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, + 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, + 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL, + 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, + 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L, + 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, + 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, + 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, + 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL, + 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, + 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L, + 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, + 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L, + 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, + 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L, + 0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, + 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, + 0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, + 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L, + 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, + 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, + 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, + 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L, + 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, + 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L, + 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, + 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L, + 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, + 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L, + 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, + 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, + 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, + 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL, + 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, + 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L, + 0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, + 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, + 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, + 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L, + 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, + 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, + 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, + 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL, + 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, + 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL, + 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, + 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L, + 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, + 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L, + 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, + 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, + 0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, + 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L, + 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L, + 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL, + 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, + 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, + 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, + 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L +}; + +uint32 crc32c_t8_nosse(uint32 iCRC, uint8 u8) { + return (iCRC >> 8) ^ crctable[(iCRC ^ u8) & 0xFF]; +} + +uint32 crc32c_t_nosse(uint32 iCRC, const uint8 *buf, int len) { + uint32 crc = iCRC; + while (len-- > 0) { + crc = (crc >> 8) ^ crctable[(crc ^ (*buf++)) & 0xFF]; + } + return crc; +} + +uint32 crc32c_t8_sse(uint32 iCRC, uint8 u8) { + return _mm_crc32_u8(iCRC, 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]); + } + + return crc32cval; +} + +uint32 crc32c_t(uint32 iCRC, const uint8 *buf, unsigned int len) { + return cpuinfo.sse4_2 ? crc32c_t_sse(iCRC, buf, len) : crc32c_t_nosse(iCRC, buf, len); +} + +uint32 crc32c(const uint8 *buf, int len) { + return crc32c_t(0xffffffff, buf, len); +} diff --git a/engine/eiface.h b/engine/eiface.h index b952e13..e377975 100644 --- a/engine/eiface.h +++ b/engine/eiface.h @@ -493,7 +493,7 @@ typedef struct // Return 1 if the packet is valid. Set response_buffer_size if you want to send a response packet. Incoming, it holds the max // size of the response_buffer, so you must zero it out if you choose not to respond. - int (*pfnConnectionlessPacket ) ( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ); + int (*pfnConnectionlessPacket ) ( const struct netadr_s *net_from_, const char *args, char *response_buffer, int *response_buffer_size ); // Enumerates player hulls. Returns 0 if the hull number doesn't exist, 1 otherwise int (*pfnGetHullBounds) ( int hullnumber, float *mins, float *maxs ); diff --git a/engine/osconfig.h b/engine/osconfig.h index 1f3f08f..bb45a62 100644 --- a/engine/osconfig.h +++ b/engine/osconfig.h @@ -123,6 +123,11 @@ VirtualFree(ptr, 0, MEM_RELEASE); } #else // _WIN32 + #ifdef __FUNCTION__ + #undef __FUNCTION__ + #endif + #define __FUNCTION__ __func__ + #ifndef PAGESIZE #define PAGESIZE 4096 #endif @@ -166,8 +171,6 @@ #define WSAENOPROTOOPT ENOPROTOOPT - inline unsigned long _byteswap_ulong(unsigned long val) { return _bswap(val); } - #ifndef FALSE #define FALSE 0 #endif diff --git a/engine/rehlds_api.h b/engine/rehlds_api.h index 13098be..fc6fe89 100644 --- a/engine/rehlds_api.h +++ b/engine/rehlds_api.h @@ -35,7 +35,7 @@ #include "model.h" #define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 5 +#define REHLDS_API_VERSION_MINOR 7 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -78,8 +78,8 @@ typedef IHookChain IRehldsHook_Steam_NotifyBotConnect; typedef IHookChainRegistry IRehldsHookRegistry_Steam_NotifyBotConnect; //SerializeSteamId -typedef IVoidHookChain IRehldsHook_SerializeSteamId; -typedef IVoidHookChainRegistry IRehldsHookRegistry_SerializeSteamId; +typedef IVoidHookChain IRehldsHook_SerializeSteamId; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SerializeSteamId; //SV_CompareUserID hook typedef IHookChain IRehldsHook_SV_CompareUserID; @@ -165,6 +165,10 @@ typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSGetSteamID; typedef IHookChain IRehldsHook_SV_TransferConsistencyInfo; typedef IHookChainRegistry IRehldsHookRegistry_SV_TransferConsistencyInfo; +//Steam_GSBUpdateUserData hook +typedef IHookChain IRehldsHook_Steam_GSBUpdateUserData; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSBUpdateUserData; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -201,6 +205,7 @@ public: virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec() = 0; virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID() = 0; virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo() = 0; + virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData() = 0; }; struct RehldsFuncs_t { @@ -261,4 +266,4 @@ public: virtual IRehldsFlightRecorder* GetFlightRecorder() = 0; }; -#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" +#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" \ No newline at end of file diff --git a/engine/sys_shared.cpp b/engine/sys_shared.cpp new file mode 100644 index 0000000..b5d4409 --- /dev/null +++ b/engine/sys_shared.cpp @@ -0,0 +1,70 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#include "sys_shared.h" + +#if defined(__GNUC__) +#include +#endif + +#define SSE3_FLAG (1<<0) +#define SSSE3_FLAG (1<<9) +#define SSE4_1_FLAG (1<<19) +#define SSE4_2_FLAG (1<<20) +#define AVX_FLAG (1<<28) +#define AVX2_FLAG (1<<5) + +cpuinfo_t cpuinfo; + +void Sys_CheckCpuInstructionsSupport(void) +{ + unsigned int cpuid_data[4]; + +#if defined ASMLIB_H + cpuid_ex((int *)cpuid_data, 1, 0); +#elif defined(__GNUC__) + __get_cpuid(0x1, &cpuid_data[0], &cpuid_data[1], &cpuid_data[2], &cpuid_data[3]); +#else + __cpuidex((int *)cpuid_data, 1, 0); +#endif + + cpuinfo.sse3 = (cpuid_data[2] & SSE3_FLAG) ? 1 : 0; // ecx + cpuinfo.ssse3 = (cpuid_data[2] & SSSE3_FLAG) ? 1 : 0; + cpuinfo.sse4_1 = (cpuid_data[2] & SSE4_1_FLAG) ? 1 : 0; + cpuinfo.sse4_2 = (cpuid_data[2] & SSE4_2_FLAG) ? 1 : 0; + cpuinfo.avx = (cpuid_data[2] & AVX_FLAG) ? 1 : 0; + +#if defined ASMLIB_H + cpuid_ex((int *)cpuid_data, 7, 0); +#elif defined(__GNUC__) + __get_cpuid(0x7, &cpuid_data[0], &cpuid_data[1], &cpuid_data[2], &cpuid_data[3]); +#else + __cpuidex((int *)cpuid_data, 7, 0); +#endif + + cpuinfo.avx2 = (cpuid_data[1] & AVX2_FLAG) ? 1 : 0; // ebx +} \ No newline at end of file diff --git a/msvc/rechecker.vcxproj b/msvc/rechecker.vcxproj index 5655ba9..5c51048 100644 --- a/msvc/rechecker.vcxproj +++ b/msvc/rechecker.vcxproj @@ -168,7 +168,6 @@ - @@ -192,7 +191,6 @@ Create - diff --git a/msvc/rechecker.vcxproj.filters b/msvc/rechecker.vcxproj.filters index 4ca9a3c..216e9fe 100644 --- a/msvc/rechecker.vcxproj.filters +++ b/msvc/rechecker.vcxproj.filters @@ -462,7 +462,6 @@ - @@ -481,7 +480,6 @@ - diff --git a/src/cmdexec.cpp b/src/cmdexec.cpp index b21c27d..92a09a3 100644 --- a/src/cmdexec.cpp +++ b/src/cmdexec.cpp @@ -7,6 +7,7 @@ CExecMngr::CBufExec::CBufExec(IGameClient *pClient, CResourceBuffer *pResource, m_pClient = pClient; m_pResource = pResource; m_ClientHash = responseHash; + m_UserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); } CExecMngr::CBufExec::~CBufExec() @@ -40,6 +41,7 @@ void StringReplace(char *src, const char *strold, const char *strnew) char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash) { int len; + int nUserID; const netadr_t *net; static char string[256]; @@ -51,6 +53,7 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 string[sizeof(string) - 1] = '\0'; net = pClient->GetNetChan()->GetRemoteAdr(); + nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); // replace key values StringReplace(string, "[file_name]", pResource->GetFileName()); @@ -58,14 +61,14 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 StringReplace(string, "[file_md5hash]", UTIL_VarArgs("%x", _byteswap_ulong(responseHash))); // replace of templates for identification - StringReplace(string, "[userid]", UTIL_VarArgs("#%u", g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()))); + StringReplace(string, "[userid]", UTIL_VarArgs("#%u", nUserID)); StringReplace(string, "[steamid]", UTIL_VarArgs("%s", g_engfuncs.pfnGetPlayerAuthId(pClient->GetEdict()))); StringReplace(string, "[ip]", UTIL_VarArgs("%i.%i.%i.%i", net->ip[0], net->ip[1], net->ip[2], net->ip[3])); StringReplace(string, "[name]", pClient->GetName()); if (string[0] != '\0') { - Resource.Log(" -> ExecuteCMD: (%s), for (%s)", string, pClient->GetName()); + Resource.Log(LOG_NORMAL, " -> ExecuteCMD: (%s), for (#%u)(%s)", string, nUserID, pClient->GetName()); } len = strlen(string); @@ -82,12 +85,13 @@ void CExecMngr::CommandExecute(IGameClient *pClient) { bool bBreak = false; auto iter = m_execList.begin(); - + int nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); + while (iter != m_execList.end()) { CBufExec *pExec = (*iter); - if (pExec->GetGameClient() != pClient) + if (pExec->GetUserID() != nUserID) { iter++; continue; @@ -130,13 +134,14 @@ void CExecMngr::Clear(IGameClient *pClient) return; } + int nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); auto iter = m_execList.begin(); while (iter != m_execList.end()) { CBufExec *pExec = (*iter); // erase cmdexec - if (pExec->GetGameClient() == pClient) + if (pExec->GetUserID() == nUserID) { delete pExec; iter = m_execList.erase(iter); diff --git a/src/cmdexec.h b/src/cmdexec.h index b0b47e2..bd98663 100644 --- a/src/cmdexec.h +++ b/src/cmdexec.h @@ -14,11 +14,13 @@ private: CBufExec(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash); ~CBufExec(); + int GetUserID() const { return m_UserID; }; IGameClient *GetGameClient() const { return m_pClient; }; CResourceBuffer *GetResource() const { return m_pResource; }; uint32 GetClientHash() const { return m_ClientHash; }; private: + int m_UserID; IGameClient *m_pClient; CResourceBuffer *m_pResource; uint32 m_ClientHash; diff --git a/src/main.cpp b/src/main.cpp index 8cee2b7..706d0f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,7 +99,6 @@ void OnMetaDetach() // clear Exec.Clear(); - Task.Clear(); Resource.Clear(); g_RehldsApi->GetHookchains()->SV_DropClient()->unregisterHook(&SV_DropClient); @@ -111,7 +110,6 @@ void ServerDeactivate_Post() { // clear Exec.Clear(); - Task.Clear(); Resource.Clear(); SET_META_RESULT(MRES_IGNORED); @@ -122,9 +120,6 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *pClient, bool // clear buffer cmdexec the client when was disconnected up to perform cmdexec Exec.Clear(pClient); - // to clear the current tasks - Task.Clear(pClient); - // clear temporary files of response Resource.Clear(pClient); @@ -143,18 +138,6 @@ int SV_TransferConsistencyInfo(IRehldsHook_SV_TransferConsistencyInfo *chain) return chain->callNext() + nConsistency; } -void TaskCommandExecute_Handler(IGameClient *pClient) -{ - if (!pClient->IsConnected()) - return; - - // client is connected to putinserver, go execute cmd out buffer - Exec.CommandExecute(pClient); - - // clear temporary files of response - Resource.Clear(pClient); -} - void ClientPutInServer_Post(edict_t *pEntity) { int nIndex = ENTINDEX(pEntity) - 1; @@ -164,19 +147,11 @@ void ClientPutInServer_Post(edict_t *pEntity) IGameClient *pClient = g_RehldsApi->GetServerStatic()->GetClient(nIndex); - if (pcv_rch_delay->value == 0.0f) - { - // client is connected to putinserver, go execute cmd out buffer - Exec.CommandExecute(pClient); + // client is connected to putinserver, go execute cmd out buffer + Exec.CommandExecute(pClient); - // clear temporary files of response - Resource.Clear(pClient); - } - else - { - // hold to execute cmd - Task.AddTask(pClient, pcv_rch_delay->value, (xtask_t)TaskCommandExecute_Handler); - } + // clear temporary files of response + Resource.Clear(pClient); SET_META_RESULT(MRES_IGNORED); } @@ -189,9 +164,3 @@ bool SV_CheckConsistencyResponse(IRehldsHook_SV_CheckConsistencyResponse *chain, // call next hook and take return of values from original func return chain->callNext(pSenderClient, resource, hash); } - -void StartFrame() -{ - Task.StartFrame(); - SET_META_RESULT(MRES_IGNORED); -} diff --git a/src/meta_api.cpp b/src/meta_api.cpp index c6cab09..87fd300 100644 --- a/src/meta_api.cpp +++ b/src/meta_api.cpp @@ -4,7 +4,7 @@ plugin_info_t Plugin_info = { META_INTERFACE_VERSION, "Rechecker", - "1.6", + "2.0", __DATE__, "s1lent", "http://www.dedicated-server.ru/", diff --git a/src/resource.cpp b/src/resource.cpp index 4f74272..6f699c1 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -4,23 +4,24 @@ CResourceFile Resource; std::vector StringsCache; cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL }; -cvar_t cv_rch_delay = { "rch_delay", "0", 0, 0.0f, NULL }; - cvar_t *pcv_rch_log = NULL; -cvar_t *pcv_rch_delay = NULL; + +const char *szTypeNames[] = { "none", "exists", "missing", "ignore", "hash_any" }; int CResourceFile::CreateResourceList() { + int startIndex = 4095; int nCustomConsistency = 0; + ComputeConsistencyFiles(); - for (auto iter = m_resourceList.cbegin(), end = m_resourceList.cend(); iter != end; ++iter) + for (auto iter = m_resourceList.begin(), end = m_resourceList.end(); iter != end; ++iter) { CResourceBuffer *pRes = (*iter); // prevent duplicate of filenames // check if filename is been marked so do not add the resource again - if (!pRes->IsDuplicate() && !SV_FileInConsistencyList(pRes->GetFileName(), NULL)) + if (!pRes->IsDuplicate()) { // check limit resource if (g_RehldsServerData->GetResourcesNum() >= MAX_RESOURCE_LIST) @@ -30,21 +31,20 @@ int CResourceFile::CreateResourceList() } // 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 + // https://github.com/dreamstalker/rehlds/blob/beaeb6513893760b231b01a981cecd48f50baa81/rehlds/engine/sv_user.cpp#L374 if (nCustomConsistency + m_ConsistencyNum >= MAX_RANGE_CONSISTENCY) { 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); + Log(LOG_DETAILED, __FUNCTION__ " -> file: (%s), cmdexec: (%s), hash: (%x), typeFind: (%s)", pRes->GetFileName(), pRes->GetCmdExec(), pRes->GetFileHash(), szTypeNames[ pRes->GetFileFlag() ]); + SV_AddResource(t_decal, pRes->GetFileName(), 0, RES_CHECKFILE, startIndex++); ++nCustomConsistency; } } std::vector sortList; - for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i) { sortList.push_back(*g_RehldsServerData->GetResource(i)); @@ -56,17 +56,16 @@ int CResourceFile::CreateResourceList() // sort std::sort(sortList.begin(), sortList.end(), [](const resource_t &a, const resource_t &b) { - if (!SV_FileInConsistencyList(b.szFileName, NULL)) - { - // pre-sort the consistency files that which will have the flag RES_CHECKFILE. - if (SV_FileInConsistencyList(a.szFileName, NULL)) - return true; + bool a_cons = (a.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(a.szFileName, NULL); + bool b_cons = (b.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(b.szFileName, NULL); - if ((a.ucFlags & RES_CHECKFILE) && !(b.ucFlags & RES_CHECKFILE)) - return true; - } + if (a_cons && !b_cons) + return true; - return false; + if (b_cons && !a_cons) + return false; + + return a.nIndex < b.nIndex; }); for (auto iter = sortList.cbegin(), end = sortList.cend(); iter != end; ++iter) @@ -100,11 +99,13 @@ void CResourceFile::Clear(IGameClient *pClient) if (pClient != NULL) { auto iter = m_responseList.begin(); + int nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); + while (iter != m_responseList.end()) { CResponseBuffer *pFiles = (*iter); - if (pFiles->GetGameClient() != pClient) + if (pFiles->GetUserID() != nUserID) { iter++; continue; @@ -129,7 +130,7 @@ void CResourceFile::Clear(IGameClient *pClient) ClearStringsCache(); } -void CResourceFile::Log(const char *fmt, ...) +void CResourceFile::Log(flag_type_log type, const char *fmt, ...) { static char string[2048]; @@ -139,8 +140,8 @@ void CResourceFile::Log(const char *fmt, ...) char *file; char dateLog[64]; bool bFirst = false; - - if (pcv_rch_log->string[0] != '1') + + if ((int)pcv_rch_log->value < type) return; fp = fopen(m_LogFilePath, "r"); @@ -216,10 +217,7 @@ void CResourceFile::Init() snprintf(m_PathDir, sizeof(m_PathDir), "%s" FILE_INI_RESOURCES, path); g_engfuncs.pfnCvar_RegisterVariable(&cv_rch_log); - g_engfuncs.pfnCvar_RegisterVariable(&cv_rch_delay); - pcv_rch_log = g_engfuncs.pfnCVarGetPointer(cv_rch_log.name); - pcv_rch_delay = g_engfuncs.pfnCVarGetPointer(cv_rch_delay.name); } inline uint8 hexbyte(uint8 *hex) @@ -404,10 +402,9 @@ void CResourceFile::LoadResources() break; } - argc++; pToken = GetNextToken(&pos); - if (pToken == NULL && argc == ARG_TYPE_FLAG) + if (++argc == ARG_TYPE_FLAG && pToken == NULL) { // go to next argument argc++; @@ -461,7 +458,7 @@ const char *CResourceFile::GetNextToken(char **pbuf) return NULL; // skip spaces at the beginning - while (*rpos != 0 && isspace(*rpos)) + while (*rpos != '\0' && isspace(*rpos)) rpos++; if (*rpos == '\0') @@ -506,7 +503,8 @@ const char *CResourceFile::GetNextToken(char **pbuf) if (rpos != wpos) *wpos = cc; - rpos++; wpos++; + rpos++; + wpos++; } } @@ -550,7 +548,7 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource std::vector tempResourceList; if (resource->type != t_decal - || resource->nIndex != 4095) // 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); @@ -619,10 +617,10 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource // push exec cmd Exec.AddElement(pSenderClient, pRes, hash); - static const char *szTypeNames[] = { "none", "exists", "missing", "ignore", "hash_any" }; - Log(" -> file: (%s), exphash: (%x), got: (%x), typeFind: (%s), prevhash: (%x), (%s), prevfile: (%s), findathash: (%s), md5hex: (%x)", - pRes->GetFileName(), pRes->GetFileHash(), hash, szTypeNames[typeFind], m_PrevHash, pSenderClient->GetName(), - FindFilenameOfHash(m_PrevHash), FindFilenameOfHash(hash), _byteswap_ulong(hash)); + flag_type_log type = (typeFind == FLAG_TYPE_IGNORE) ? LOG_DETAILED : LOG_NORMAL; + Log(type, " -> file: (%s), exphash: (%x), got: (%x), typeFind: (%s), prevhash: (%x), (#%u)(%s), prevfile: (%s), findathash: (%s), md5hex: (%x)", + pRes->GetFileName(), pRes->GetFileHash(), hash, szTypeNames[ typeFind ], m_PrevHash, g_engfuncs.pfnGetPlayerUserId(pSenderClient->GetEdict()), + pSenderClient->GetName(), FindFilenameOfHash(m_PrevHash), FindFilenameOfHash(hash), _byteswap_ulong(hash)); } bHandled = true; @@ -672,6 +670,7 @@ CResourceFile::CResponseBuffer::CResponseBuffer(IGameClient *pSenderClient, char m_pClient = pSenderClient; m_FileName = DuplicateString(filename); m_ClientHash = hash; + m_UserID = g_engfuncs.pfnGetPlayerUserId(pSenderClient->GetEdict()); } const char *CResourceFile::FindFilenameOfHash(uint32 hash) diff --git a/src/resource.h b/src/resource.h index d105318..fd6829e 100644 --- a/src/resource.h +++ b/src/resource.h @@ -4,6 +4,13 @@ #define MAX_CMD_LENGTH 128 #define MAX_RANGE_CONSISTENCY 1024 +enum flag_type_log +{ + LOG_NONE = 0, + LOG_NORMAL, + LOG_DETAILED +}; + enum flag_type_resources { FLAG_TYPE_NONE = 0, @@ -60,7 +67,7 @@ public: void Clear(IGameClient *pClient = NULL); void LoadResources(); int CreateResourceList(); - void Log(const char *fmt, ...); + void Log(flag_type_log type, const char *fmt, ...); bool FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash); @@ -71,11 +78,13 @@ private: public: CResponseBuffer(IGameClient *pSenderClient, char *filename, uint32 hash); + int GetUserID() const { return m_UserID; }; IGameClient *GetGameClient() const { return m_pClient; }; const char *GetFileName() const { return m_FileName; }; uint32 GetClientHash() const { return m_ClientHash; }; private: + int m_UserID; IGameClient *m_pClient; const char *m_FileName; uint32 m_ClientHash; @@ -109,8 +118,6 @@ private: }; extern CResourceFile Resource; - extern cvar_t *pcv_rch_log; -extern cvar_t *pcv_rch_delay; void ClearStringsCache();