From 08dd8df4b4136857423f9cf201c0e33c386dcecd Mon Sep 17 00:00:00 2001 From: Adidasman Date: Tue, 13 Dec 2016 05:54:47 +0600 Subject: [PATCH] Update ReHLDS API 3.x --- dep/rehlsdk/common/const.h | 3 + dep/rehlsdk/common/kbutton.h | 3 - dep/rehlsdk/common/mathlib.h | 97 ++++++++++++++++++++------ dep/rehlsdk/common/netadr.h | 10 +-- dep/rehlsdk/common/qlimits.h | 6 +- dep/rehlsdk/common/quakedef.h | 5 +- dep/rehlsdk/common/vmodes.h | 2 - dep/rehlsdk/engine/bspfile.h | 45 +++++------- dep/rehlsdk/engine/cmd_rehlds.h | 4 -- dep/rehlsdk/engine/common_rehlds.h | 3 - dep/rehlsdk/engine/crc32c.h | 12 ++-- dep/rehlsdk/engine/d_local.h | 17 ++--- dep/rehlsdk/engine/hookchains.h | 15 +++- dep/rehlsdk/engine/model.h | 58 +++++++-------- dep/rehlsdk/engine/modelgen.h | 16 ----- dep/rehlsdk/engine/osconfig.h | 11 +-- dep/rehlsdk/engine/rehlds_api.h | 63 ++++++++++++++--- dep/rehlsdk/engine/rehlds_interfaces.h | 6 ++ dep/rehlsdk/engine/spritegn.h | 12 +--- dep/rehlsdk/engine/static_map.h | 2 +- dep/rehlsdk/engine/studio.h | 7 +- dep/rehlsdk/engine/sys_shared.cpp | 2 + dep/rehlsdk/engine/sys_shared.h | 2 +- dep/rehlsdk/engine/userid_rehlds.h | 1 - dep/rehlsdk/public/commonmacros.h | 30 ++++++++ revoice/src/SteamP2PCodec.cpp | 35 +++++++--- revoice/src/SteamP2PCodec.h | 3 +- revoice/src/VoiceEncoder_Silk.cpp | 38 ++++++---- revoice/src/VoiceEncoder_Silk.h | 18 ++--- revoice/src/VoiceEncoder_Speex.cpp | 36 +++++----- revoice/src/dllapi.cpp | 8 +-- revoice/src/engine_api.cpp | 3 +- revoice/src/h_export.cpp | 2 +- revoice/src/meta_api.cpp | 18 +++-- revoice/src/precompiled.h | 2 +- revoice/src/revoice_cfg.cpp | 79 ++++++++++++--------- revoice/src/revoice_main.cpp | 92 ++++++++++++++---------- revoice/src/revoice_player.cpp | 31 ++++---- revoice/src/revoice_player.h | 10 +-- revoice/src/revoice_rehlds_api.cpp | 3 +- revoice/src/revoice_reunion_api.cpp | 3 +- revoice/src/revoice_shared.h | 1 - revoice/src/revoice_utils.cpp | 24 +++++-- revoice/src/sdk_util.cpp | 2 + revoice/src/voice_codec_frame.cpp | 3 +- revoice/src/voice_codec_frame.h | 2 +- 46 files changed, 519 insertions(+), 326 deletions(-) create mode 100644 dep/rehlsdk/public/commonmacros.h diff --git a/dep/rehlsdk/common/const.h b/dep/rehlsdk/common/const.h index f539684..721a8da 100644 --- a/dep/rehlsdk/common/const.h +++ b/dep/rehlsdk/common/const.h @@ -71,6 +71,9 @@ #define FL_KILLME (1<<30) // This entity is marked for death -- This allows the engine to kill ents at the appropriate time #define FL_DORMANT (1<<31) // Entity is dormant, no updates to client +// SV_EmitSound2 flags +#define SND_EMIT2_NOPAS (1<<0) // never to do check PAS +#define SND_EMIT2_INVOKER (1<<1) // do not send to the client invoker // Engine edict->spawnflags #define SF_NOTINDEATHMATCH 0x0800 // Do not spawn when deathmatch and loading entities from a file diff --git a/dep/rehlsdk/common/kbutton.h b/dep/rehlsdk/common/kbutton.h index c8177e4..55a75dc 100644 --- a/dep/rehlsdk/common/kbutton.h +++ b/dep/rehlsdk/common/kbutton.h @@ -32,13 +32,10 @@ #pragma once #endif - -/* <31b2a> ../common/kbutton.h:7 */ typedef struct kbutton_s { int down[2]; int state; } kbutton_t; - #endif // KBUTTON_H diff --git a/dep/rehlsdk/common/mathlib.h b/dep/rehlsdk/common/mathlib.h index 142c38c..6d19b3f 100644 --- a/dep/rehlsdk/common/mathlib.h +++ b/dep/rehlsdk/common/mathlib.h @@ -1,37 +1,47 @@ -/*** +/* * -* Copyright (c) 1996-2002, Valve LLC. All rights reserved. -* -* This product contains software technology licensed from Id -* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. -* All Rights Reserved. +* 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. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* 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. +* +*/ +#ifndef MATHLIB_H +#define MATHLIB_H +#ifdef _WIN32 #pragma once +#endif - -/* <42b7f> ../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 -/* <80013> ../common/mathlib.h:8 */ typedef vec_t vec4_t[4]; +typedef int fixed16_t; -/* <42bac> ../common/mathlib.h:18 */ -typedef int fixed16_t; /* size: 4 */ - -/* <42bb7> ../common/mathlib.h:60 */ typedef union DLONG_u { int i[2]; @@ -41,6 +51,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 +104,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/dep/rehlsdk/common/netadr.h b/dep/rehlsdk/common/netadr.h index 5cbf0ea..05f8f27 100644 --- a/dep/rehlsdk/common/netadr.h +++ b/dep/rehlsdk/common/netadr.h @@ -12,7 +12,7 @@ * without written permission from Valve LLC. * ****/ -// netadr.h + #ifndef NETADR_H #define NETADR_H #ifdef _WIN32 @@ -31,10 +31,10 @@ typedef enum typedef struct netadr_s { - netadrtype_t type; - unsigned char ip[4]; - unsigned char ipx[10]; - unsigned short port; + netadrtype_t type; + unsigned char ip[4]; + unsigned char ipx[10]; + unsigned short port; } netadr_t; #endif // NETADR_H diff --git a/dep/rehlsdk/common/qlimits.h b/dep/rehlsdk/common/qlimits.h index 3fad403..c19e670 100644 --- a/dep/rehlsdk/common/qlimits.h +++ b/dep/rehlsdk/common/qlimits.h @@ -25,15 +25,19 @@ #define MAX_LIGHTSTYLE_INDEX_BITS 6 #define MAX_LIGHTSTYLES (1< ../common/quakedef.h:29 */ -typedef int BOOL; /* size: 4 */ +typedef int BOOL; // user message #define MAX_USER_MSG_DATA 192 -/* <627f> ../common/quakedef.h:137 */ //moved to com_model.h //typedef struct cache_user_s //{ // void *data; //} cache_user_t; -/* <4313b> ../common/quakedef.h:162 */ typedef int (*pfnUserMsgHook)(const char *, int, void *); diff --git a/dep/rehlsdk/common/vmodes.h b/dep/rehlsdk/common/vmodes.h index 43334d3..7714765 100644 --- a/dep/rehlsdk/common/vmodes.h +++ b/dep/rehlsdk/common/vmodes.h @@ -27,8 +27,6 @@ */ #pragma once - -/* <430ee> ../common/vmodes.h:40 */ typedef struct rect_s { int left, right, top, bottom; diff --git a/dep/rehlsdk/engine/bspfile.h b/dep/rehlsdk/engine/bspfile.h index 72fe722..3c4dfee 100644 --- a/dep/rehlsdk/engine/bspfile.h +++ b/dep/rehlsdk/engine/bspfile.h @@ -27,46 +27,47 @@ */ #pragma once -#define BSPVERSION 30 +// header +#define Q1BSP_VERSION 29 // quake1 regular version (beta is 28) +#define HLBSP_VERSION 30 // half-life regular version + #define MAX_MAP_HULLS 4 #define CONTENTS_ORIGIN -7 // removed at csg time #define CONTENTS_CLIP -8 // changed to contents_solid -#define CONTENTS_CURRENT_0 -9 -#define CONTENTS_CURRENT_90 -10 +#define CONTENTS_CURRENT_0 -9 +#define CONTENTS_CURRENT_90 -10 #define CONTENTS_CURRENT_180 -11 #define CONTENTS_CURRENT_270 -12 -#define CONTENTS_CURRENT_UP -13 +#define CONTENTS_CURRENT_UP -13 #define CONTENTS_CURRENT_DOWN -14 #define CONTENTS_TRANSLUCENT -15 -#define LUMP_ENTITIES 0 +#define LUMP_ENTITIES 0 #define LUMP_PLANES 1 -#define LUMP_TEXTURES 2 -#define LUMP_VERTEXES 3 -#define LUMP_VISIBILITY 4 +#define LUMP_TEXTURES 2 +#define LUMP_VERTEXES 3 +#define LUMP_VISIBILITY 4 #define LUMP_NODES 5 -#define LUMP_TEXINFO 6 +#define LUMP_TEXINFO 6 #define LUMP_FACES 7 -#define LUMP_LIGHTING 8 -#define LUMP_CLIPNODES 9 +#define LUMP_LIGHTING 8 +#define LUMP_CLIPNODES 9 #define LUMP_LEAFS 10 -#define LUMP_MARKSURFACES 11 +#define LUMP_MARKSURFACES 11 #define LUMP_EDGES 12 -#define LUMP_SURFEDGES 13 +#define LUMP_SURFEDGES 13 #define LUMP_MODELS 14 -#define HEADER_LUMPS 15 +#define HEADER_LUMPS 15 -/* ../engine/bspfile.h:41 */ -typedef struct lump_s +typedef struct lump_s { int fileofs; int filelen; } lump_t; -/* ../engine/bspfile.h:64 */ typedef struct dmodel_s { float mins[3], maxs[3]; @@ -76,21 +77,18 @@ typedef struct dmodel_s int firstface, numfaces; } dmodel_t; -/* ../engine/bspfile.h:73 */ typedef struct dheader_s { int version; lump_t lumps[15]; } dheader_t; -/* <485b2> ../engine/bspfile.h:79 */ typedef struct dmiptexlump_s { int _nummiptex; int dataofs[4]; } dmiptexlump_t; -/* <1ce18> ../engine/bspfile.h:86 */ typedef struct miptex_s { char name[16]; @@ -99,13 +97,11 @@ typedef struct miptex_s unsigned offsets[4]; } miptex_t; -/* <48652> ../engine/bspfile.h:94 */ typedef struct dvertex_s { float point[3]; } dvertex_t; -/* <48674> ../engine/bspfile.h:110 */ typedef struct dplane_s { float normal[3]; @@ -113,7 +109,6 @@ typedef struct dplane_s int type; } dplane_t; -/* <486b2> ../engine/bspfile.h:132 */ typedef struct dnode_s { int planenum; @@ -124,14 +119,12 @@ typedef struct dnode_s unsigned short numfaces; } dnode_t; -/* ../engine/bspfile.h:142 */ typedef struct dclipnode_s { int planenum; short children[2]; // negative numbers are contents } dclipnode_t; -/* <4876a> ../engine/bspfile.h:149 */ typedef struct texinfo_s { float vecs[2][4]; @@ -139,13 +132,11 @@ typedef struct texinfo_s int flags; } texinfo_t; -/* <487c2> ../engine/bspfile.h:159 */ typedef struct dedge_s { unsigned short v[2]; } dedge_t; -/* <487f2> ../engine/bspfile.h:165 */ typedef struct dface_s { short planenum; diff --git a/dep/rehlsdk/engine/cmd_rehlds.h b/dep/rehlsdk/engine/cmd_rehlds.h index 33d167a..0f5de26 100644 --- a/dep/rehlsdk/engine/cmd_rehlds.h +++ b/dep/rehlsdk/engine/cmd_rehlds.h @@ -29,10 +29,7 @@ #include "archtypes.h" -/* <8f1> ../engine/cmd.h:65 */ typedef void(*xcommand_t)(void); - -/* <904> ../engine/cmd.h:71 */ typedef struct cmd_function_s { struct cmd_function_s *next; @@ -41,7 +38,6 @@ typedef struct cmd_function_s int flags; } cmd_function_t; -/* <95a> ../engine/cmd.h:80 */ typedef enum cmd_source_s { src_client = 0, // came in over a net connection as a clc_stringcmd. host_client will be valid during this state. diff --git a/dep/rehlsdk/engine/common_rehlds.h b/dep/rehlsdk/engine/common_rehlds.h index c0004a8..853ee68 100644 --- a/dep/rehlsdk/engine/common_rehlds.h +++ b/dep/rehlsdk/engine/common_rehlds.h @@ -47,7 +47,6 @@ #define COM_COPY_CHUNK_SIZE 1024 #define COM_MAX_CMD_LINE 256 -/* <6ae> ../common/common.h:82 */ typedef struct sizebuf_s { const char *buffername; @@ -57,7 +56,6 @@ typedef struct sizebuf_s int cursize; } sizebuf_t; -/* <270aa> ../common/common.h:297 */ typedef struct downloadtime_s { qboolean bUsed; @@ -65,7 +63,6 @@ typedef struct downloadtime_s int nBytesRemaining; } downloadtime_t; -/* <19fa2> ../common/common.h:303 */ typedef struct incomingtransfer_s { qboolean doneregistering; diff --git a/dep/rehlsdk/engine/crc32c.h b/dep/rehlsdk/engine/crc32c.h index d3a78a3..55bed92 100644 --- a/dep/rehlsdk/engine/crc32c.h +++ b/dep/rehlsdk/engine/crc32c.h @@ -10,12 +10,12 @@ 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 . -*/ -#pragma once -#include "archtypes.h" - -extern uint32 crc32c_t8_nosse(uint32 iCRC, uint8 u8); -extern uint32 crc32c_t8_sse(uint32 iCRC, uint8 u8); +*/ +#pragma once +#include "archtypes.h" + +extern uint32 crc32c_t8_nosse(uint32 iCRC, uint8 u8); +extern uint32 crc32c_t8_sse(uint32 iCRC, uint8 u8); extern uint32 crc32c_t_nosse(uint32 iCRC, const uint8 *buf, int len); extern uint32 crc32c_t_sse(uint32 iCRC, const uint8 *buf, unsigned int len); extern uint32 crc32c_t(uint32 iCRC, const uint8 *buf, unsigned int len); diff --git a/dep/rehlsdk/engine/d_local.h b/dep/rehlsdk/engine/d_local.h index 1313edf..9ba7295 100644 --- a/dep/rehlsdk/engine/d_local.h +++ b/dep/rehlsdk/engine/d_local.h @@ -28,19 +28,16 @@ #pragma once - - -/* <82286> ../engine/d_local.h:20 */ typedef struct surfcache_s { struct surfcache_s *next; struct surfcache_s **owner; - int lightadj[4]; - int dlight; - int size; - unsigned width; - unsigned height; - float mipscale; + int lightadj[4]; + int dlight; + int size; + unsigned width; + unsigned height; + float mipscale; struct texture_s *texture; - unsigned char data[4]; + unsigned char data[4]; } surfcache_t; diff --git a/dep/rehlsdk/engine/hookchains.h b/dep/rehlsdk/engine/hookchains.h index 9e16fa8..a31109d 100644 --- a/dep/rehlsdk/engine/hookchains.h +++ b/dep/rehlsdk/engine/hookchains.h @@ -48,13 +48,24 @@ public: virtual void callOriginal(t_args... args) = 0; }; +// Specifies priorities for hooks call order in the chain. +// For equal priorities first registered hook will be called first. +enum HookChainPriority +{ + HC_PRIORITY_UNINTERRUPTABLE = 255, // Hook will be called before other hooks. + HC_PRIORITY_HIGH = 192, // Hook will be called before hooks with default priority. + HC_PRIORITY_DEFAULT = 128, // Default hook call priority. + HC_PRIORITY_MEDIUM = 64, // Hook will be called after hooks with default priority. + HC_PRIORITY_LOW = 0, // Hook will be called after all other hooks. +}; + // Hook chain registry(for hooks [un]registration) template class IHookChainRegistry { public: typedef t_ret(*hookfunc_t)(IHookChain*, t_args...); - virtual void registerHook(hookfunc_t hook) = 0; + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; virtual void unregisterHook(hookfunc_t hook) = 0; }; @@ -64,6 +75,6 @@ class IVoidHookChainRegistry { public: typedef void(*hookfunc_t)(IVoidHookChain*, t_args...); - virtual void registerHook(hookfunc_t hook) = 0; + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; virtual void unregisterHook(hookfunc_t hook) = 0; }; diff --git a/dep/rehlsdk/engine/model.h b/dep/rehlsdk/engine/model.h index e02ed97..7837482 100644 --- a/dep/rehlsdk/engine/model.h +++ b/dep/rehlsdk/engine/model.h @@ -33,14 +33,21 @@ #include "bspfile.h" #include "crc.h" #include "com_model.h" +#include "commonmacros.h" -#define SURF_PLANEBACK 2 -#define SURF_DRAWSKY 4 +// header +#define ALIAS_MODEL_VERSION 0x006 +#define IDPOLYHEADER MAKEID('I', 'D', 'P', 'O') // little-endian "IDPO" + +#define MAX_LBM_HEIGHT 480 +#define MAX_ALIAS_MODEL_VERTS 2000 + +#define SURF_PLANEBACK 2 +#define SURF_DRAWSKY 4 #define SURF_DRAWSPRITE 8 #define SURF_DRAWTURB 0x10 #define SURF_DRAWTILED 0x20 -#define SURF_DRAWBACKGROUND 0x40 -#define ALIAS_MODEL_VERSION 0x006 +#define SURF_DRAWBACKGROUND 0x40 #define MAX_MODEL_NAME 64 #define MIPLEVELS 4 @@ -48,13 +55,11 @@ #define MAXLIGHTMAPS 4 #define MAX_KNOWN_MODELS 1024 -/* <6816> ../engine/model.h:27 */ typedef struct mvertex_s { vec3_t position; } mvertex_t; -/* <6838> ../engine/model.h:39 */ typedef struct mplane_s { vec3_t normal; // surface normal @@ -64,30 +69,39 @@ typedef struct mplane_s byte pad[2]; } mplane_t; -/* <68a6> ../engine/model.h:48 */ typedef struct texture_s { char name[16]; unsigned width, height; + +#ifndef SWDS + int gl_texturenum; + struct msurface_s * texturechain; +#endif + int anim_total; // total tenths in sequence ( 0 = no) int anim_min, anim_max; // time for this frame min <=time< max struct texture_s *anim_next; // in the animation sequence struct texture_s *alternate_anims; // bmodels in frame 1 use these unsigned offsets[MIPLEVELS]; // four mip maps stored + +#ifdef SWDS unsigned paloffset; +#else + byte *pPal; +#endif + } texture_t; -/* <6950> ../engine/model.h:71 */ typedef struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } medge_t; -/* <697e> ../engine/model.h:78 */ typedef struct mtexinfo_s { - float vecs[2][4]; // [s/t] unit vectors in world space. + float vecs[2][4]; // [s/t] unit vectors in world space. // [i][3] is the s/t offset relative to the origin. // s or t = dot(3Dpoint,vecs[i])+vecs[i][3] float mipadjust; // ?? mipmap limits for very small surfaces @@ -96,13 +110,10 @@ typedef struct mtexinfo_s } mtexinfo_t; #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision -/* <69d0> ../engine/model.h:91 */ typedef struct msurface_s msurface_t; -/* <1db66> ../engine/model.h:92 */ typedef struct decal_s decal_t; // JAY: Compress this as much as possible -/* <1db71> ../engine/model.h:96 */ struct decal_s { decal_t *pnext; // linked list for each surface @@ -116,7 +127,6 @@ struct decal_s short entityIndex; // Entity this is attached to }; -/* <69db> ../engine/model.h:118 */ struct msurface_s { int visframe; // should be drawn when node is crossed @@ -148,7 +158,6 @@ struct msurface_s decal_t *pdecals; }; -/* <6b6c> ../engine/model.h:149 */ typedef struct mnode_s { // common with leaf @@ -167,7 +176,6 @@ typedef struct mnode_s unsigned short numsurfaces; } mnode_t; -/* <1dcd4> ../engine/model.h:169 */ typedef struct mleaf_s { // common with node @@ -188,7 +196,6 @@ typedef struct mleaf_s byte ambient_sound_level[NUM_AMBIENTS]; } mleaf_t; -/* <1ddbe> ../engine/model.h:190 */ typedef struct hull_s { dclipnode_t *clipnodes; @@ -198,7 +205,6 @@ typedef struct hull_s vec3_t clip_mins, clip_maxs; } hull_t; -/* <4b3fe> ../engine/model.h:210 */ typedef struct mspriteframe_t { int width; @@ -208,7 +214,6 @@ typedef struct mspriteframe_t byte pixels[4]; } mspriteframe_s; -/* <4b485> ../engine/model.h:219 */ typedef struct mspritegroup_s { int numframes; @@ -216,14 +221,12 @@ typedef struct mspritegroup_s mspriteframe_t *frames[1]; } mspritegroup_t; -/* <4b4df> ../engine/model.h:226 */ typedef struct mspriteframedesc_s { spriteframetype_t type; mspriteframe_t *frameptr; } mspriteframedesc_t; -/* <4b50f> ../engine/model.h:232 */ typedef struct msprite_s { short int type; @@ -236,7 +239,6 @@ typedef struct msprite_s mspriteframedesc_t frames[1]; } msprite_t; -/* <4b5b5> ../engine/model.h:255 */ typedef struct maliasframedesc_s { aliasframetype_t type; @@ -245,7 +247,6 @@ typedef struct maliasframedesc_s char name[16]; } maliasframedesc_t; -/* <4b615> ../engine/model.h:264 */ typedef struct maliasskindesc_s { aliasskintype_t type; @@ -253,14 +254,12 @@ typedef struct maliasskindesc_s int skin; } maliasskindesc_t; -/* <4b658> ../engine/model.h:271 */ typedef struct maliasgroupframedesc_s { trivertx_t bboxmin, bboxmax; int frame; } maliasgroupframedesc_t; -/* <4b69b> ../engine/model.h:278 */ typedef struct maliasgroup_s { int numframes; @@ -268,7 +267,6 @@ typedef struct maliasgroup_s maliasgroupframedesc_t frames[1]; } maliasgroup_t; -/* <4b6ee> ../engine/model.h:285 */ typedef struct maliasskingroup_s { int numskins; @@ -276,14 +274,12 @@ typedef struct maliasskingroup_s maliasskindesc_t skindescs[1]; } maliasskingroup_t; -/* <4b741> ../engine/model.h:293 */ typedef struct mtriangle_s { int facesfront; int vertindex[3]; } mtriangle_t; -/* <4b779> ../engine/model.h:298 */ typedef struct aliashdr_s { int model; @@ -294,23 +290,21 @@ typedef struct aliashdr_s maliasframedesc_t frames[1]; } aliashdr_t; -/* <1de30> ../engine/model.h:315 */ typedef enum modtype_e { + mod_bad = -1, mod_brush, mod_sprite, mod_alias, mod_studio, } modtype_t; -/* <1de5e> ../engine/model.h:331 */ typedef struct model_s { char name[MAX_MODEL_NAME]; - //TODO: qboolean? seriously? int needload; // bmodels and sprites don't cache normally - + modtype_t type; int numframes; synctype_t synctype; diff --git a/dep/rehlsdk/engine/modelgen.h b/dep/rehlsdk/engine/modelgen.h index c33a202..1fa3b88 100644 --- a/dep/rehlsdk/engine/modelgen.h +++ b/dep/rehlsdk/engine/modelgen.h @@ -32,30 +32,24 @@ #pragma once #endif - -/* <67f6> ../engine/modelgen.h:37 */ typedef enum synctype_e { ST_SYNC = 0, ST_RAND = 1, } synctype_t; -/* <4abae> ../engine/modelgen.h:40 */ typedef enum aliasframetype_s { ALIAS_SINGLE = 0, ALIAS_GROUP = 1, } aliasframetype_t; -/* 203 */ -/* <4abce> ../engine/modelgen.h:42 */ typedef enum aliasskintype_s { ALIAS_SKIN_SINGLE = 0, ALIAS_SKIN_GROUP = 1, } aliasskintype_t; -/* <4abee> ../engine/modelgen.h:44 */ typedef struct mdl_s { int ident; @@ -75,7 +69,6 @@ typedef struct mdl_s float size; } mdl_t; -/* <4acd4> ../engine/modelgen.h:64 */ typedef struct stvert_s { int onseam; @@ -83,59 +76,50 @@ typedef struct stvert_s int t; } stvert_t; -/* <4ad0e> ../engine/modelgen.h:70 */ typedef struct dtriangle_s { int facesfront; int vertindex[3]; } dtriangle_t; -/* <4ad42> ../engine/modelgen.h:80 */ typedef struct trivertx_s { byte v[3]; byte lightnormalindex; } trivertx_t; -/* <4ad80> ../engine/modelgen.h:85 */ typedef struct daliasframe_s { trivertx_t bboxmin, bboxmax; char name[16]; } daliasframe_t; -/* <4adbe> ../engine/modelgen.h:91 */ typedef struct daliasgroup_s { int numframes; trivertx_t bboxmin, bboxmax; } daliasgroup_t; -/* <4adfc> ../engine/modelgen.h:97 */ typedef struct daliasskingroup_s { int numskins; } daliasskingroup_t; -/* <4ae1e> ../engine/modelgen.h:101 */ typedef struct daliasinterval_s { float interval; } daliasinterval_t; -/* <4ae40> ../engine/modelgen.h:105 */ typedef struct daliasskininterval_s { float interval; } daliasskininterval_t; -/* <4ae62> ../engine/modelgen.h:109 */ typedef struct daliasframetype_s { aliasframetype_t type; } daliasframetype_t; -/* <4ae84> ../engine/modelgen.h:113 */ typedef struct daliasskintype_s { aliasskintype_t type; diff --git a/dep/rehlsdk/engine/osconfig.h b/dep/rehlsdk/engine/osconfig.h index 54bb0c8..cf6a551 100644 --- a/dep/rehlsdk/engine/osconfig.h +++ b/dep/rehlsdk/engine/osconfig.h @@ -103,6 +103,7 @@ #define HIDDEN #define NOINLINE __declspec(noinline) #define ALIGN16 __declspec(align(16)) + #define NORETURN __declspec(noreturn) #define FORCE_STACK_ALIGN //inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctlsocket(s, FIONBIO, (u_long*)&m) == 0); } @@ -123,6 +124,11 @@ VirtualFree(ptr, 0, MEM_RELEASE); } #else // _WIN32 + #ifdef __FUNCTION__ + #undef __FUNCTION__ + #endif + #define __FUNCTION__ __func__ + #ifndef PAGESIZE #define PAGESIZE 4096 #endif @@ -143,6 +149,7 @@ #define HIDDEN __attribute__((visibility("hidden"))) #define NOINLINE __attribute__((noinline)) #define ALIGN16 __attribute__((aligned(16))) + #define NORETURN __attribute__((noreturn)) #define FORCE_STACK_ALIGN __attribute__((force_align_arg_pointer)) //inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctl(s, FIONBIO, (int*)&m) == 0); } @@ -166,8 +173,6 @@ #define WSAENOPROTOOPT ENOPROTOOPT - inline unsigned long _byteswap_ulong(unsigned long val) { return _bswap(val); } - #ifndef FALSE #define FALSE 0 #endif @@ -186,6 +191,4 @@ #define EXT_FUNC FORCE_STACK_ALIGN -extern void __declspec(noreturn) rehlds_syserror(const char* fmt, ...); - #endif // _OSCONFIG_H diff --git a/dep/rehlsdk/engine/rehlds_api.h b/dep/rehlsdk/engine/rehlds_api.h index b5b14de..0b0a588 100644 --- a/dep/rehlsdk/engine/rehlds_api.h +++ b/dep/rehlsdk/engine/rehlds_api.h @@ -34,8 +34,8 @@ #include "interface.h" #include "model.h" -#define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 4 +#define REHLDS_API_VERSION_MAJOR 3 +#define REHLDS_API_VERSION_MINOR 0 //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; @@ -122,8 +122,8 @@ typedef IVoidHookChain I typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EmitEvents; //EV_PlayReliableEvent hook -typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; -typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; +typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; +typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; //SV_StartSound hook typedef IVoidHookChain IRehldsHook_SV_StartSound; @@ -157,6 +157,38 @@ typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ActivateServer; typedef IVoidHookChain IRehldsHook_SV_WriteVoiceCodec; typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_WriteVoiceCodec; +//Steam_GSGetSteamID hook +typedef IHookChain IRehldsHook_Steam_GSGetSteamID; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSGetSteamID; + +//SV_TransferConsistencyInfo hook +typedef IHookChain IRehldsHook_SV_TransferConsistencyInfo; +typedef IHookChainRegistry IRehldsHookRegistry_SV_TransferConsistencyInfo; + +//Steam_GSBUpdateUserData hook +typedef IHookChain IRehldsHook_Steam_GSBUpdateUserData; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSBUpdateUserData; + +//Cvar_DirectSet hook +typedef IVoidHookChain IRehldsHook_Cvar_DirectSet; +typedef IVoidHookChainRegistry IRehldsHookRegistry_Cvar_DirectSet; + +//SV_EstablishTimeBase hook +typedef IVoidHookChain IRehldsHook_SV_EstablishTimeBase; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EstablishTimeBase; + +//SV_Spawn_f hook +typedef IVoidHookChain<> IRehldsHook_SV_Spawn_f; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Spawn_f; + +//SV_CreatePacketEntities hook +typedef IHookChain IRehldsHook_SV_CreatePacketEntities; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CreatePacketEntities; + +//SV_EmitSound2 hook +typedef IHookChain IRehldsHook_SV_EmitSound2; +typedef IHookChainRegistry IRehldsHookRegistry_SV_EmitSound2; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -191,6 +223,14 @@ public: virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient() = 0; 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; + virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData() = 0; + virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0; + virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0; + virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0; + virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0; + virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2() = 0; }; struct RehldsFuncs_t { @@ -217,7 +257,7 @@ struct RehldsFuncs_t { cmd_source_t*(*GetCmdSource)(); void(*Log)(const char* prefix, const char* msg); DLL_FUNCTIONS *(*GetEntityInterface)(); - void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, short unsigned int eventindex, float delay, struct event_args_s *pargs); + void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, unsigned short eventindex, float delay, struct event_args_s *pargs); int(*SV_LookupSoundIndex)(const char *sample); void(*MSG_StartBitWriting)(sizebuf_t *buf); void(*MSG_WriteBits)(uint32 data, int numbits); @@ -235,6 +275,13 @@ 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); + qboolean(*Steam_NotifyClientConnect)(IGameClient *cl, const void *pvSteam2Key, unsigned int ucbSteam2Key); + void(*Steam_NotifyClientDisconnect)(IGameClient* cl); + void(*SV_StartSound)(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int flags, int pitch); + bool(*SV_EmitSound2)(edict_t *entity, IGameClient *receiver, int channel, const char *sample, float volume, float attenuation, int flags, int pitch, int emitFlags, const float *pOrigin); + void(*SV_UpdateUserInfo)(IGameClient *pGameClient); + bool(*StripUnprintableAndSpace)(char *pch); }; class IRehldsApi { @@ -250,4 +297,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/dep/rehlsdk/engine/rehlds_interfaces.h b/dep/rehlsdk/engine/rehlds_interfaces.h index d30af0f..7d6a086 100644 --- a/dep/rehlsdk/engine/rehlds_interfaces.h +++ b/dep/rehlsdk/engine/rehlds_interfaces.h @@ -71,6 +71,7 @@ public: virtual void SetLastVoiceTime(double time) = 0; virtual double GetLastVoiceTime() = 0; virtual bool GetLoopback() = 0; + virtual struct usercmd_s *GetLastCmd() = 0; // this must be the last virtual function in class #ifdef REHLDS_SELF @@ -123,4 +124,9 @@ public: virtual int GetDecalNameNum() = 0; virtual double GetTime() = 0; + virtual void SetResourcesNum(int num) = 0; + virtual struct resource_s *GetResource(int index) = 0; + virtual void SetName(const char* name) = 0; + virtual class ISteamGameServer *GetSteamGameServer() = 0; + virtual struct netadr_s *GetNetFrom() = 0; }; diff --git a/dep/rehlsdk/engine/spritegn.h b/dep/rehlsdk/engine/spritegn.h index 59f4f50..959b3d6 100644 --- a/dep/rehlsdk/engine/spritegn.h +++ b/dep/rehlsdk/engine/spritegn.h @@ -33,11 +33,10 @@ #endif #include "modelgen.h" +#include "commonmacros.h" - -#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I') -#define SPRITE_VERSION 2 - +#define SPRITE_VERSION 2 // Half-Life sprites +#define IDSPRITEHEADER MAKEID('I', 'D', 'S', 'P') // little-endian "IDSP" typedef enum spriteframetype_e { @@ -46,7 +45,6 @@ typedef enum spriteframetype_e SPR_ANGLED } spriteframetype_t; -/* <4aea6> ../engine/spritegn.h:50 */ typedef struct dsprite_s { int ident; @@ -61,7 +59,6 @@ typedef struct dsprite_s synctype_t synctype; } dsprite_t; -/* <4af46> ../engine/spritegn.h:74 */ typedef struct dspriteframe_s { int origin[2]; @@ -69,19 +66,16 @@ typedef struct dspriteframe_s int height; } dspriteframe_t; -/* <4af84> ../engine/spritegn.h:80 */ typedef struct dspritegroup_s { int numframes; } dspritegroup_t; -/* <4afa6> ../engine/spritegn.h:84 */ typedef struct dspriteinterval_s { float interval; } dspriteinterval_t; -/* <4afe8> ../engine/spritegn.h:90 */ typedef struct dspriteframetype_s { spriteframetype_t type; diff --git a/dep/rehlsdk/engine/static_map.h b/dep/rehlsdk/engine/static_map.h index 52fc7b2..0a6de4d 100644 --- a/dep/rehlsdk/engine/static_map.h +++ b/dep/rehlsdk/engine/static_map.h @@ -44,7 +44,7 @@ private: // this was a root node unsigned int rootId = GetRoodNodeId(node->key); if (m_RootNodes[rootId] != node) { - util_syserror("%s: invlid root node", __FUNCTION__); + Sys_Error(__FUNCTION__ ": invalid root node"); return; } diff --git a/dep/rehlsdk/engine/studio.h b/dep/rehlsdk/engine/studio.h index 5c0ec15..940f5f9 100644 --- a/dep/rehlsdk/engine/studio.h +++ b/dep/rehlsdk/engine/studio.h @@ -310,10 +310,13 @@ typedef struct } mstudiotrivert_t; #endif +#define STUDIO_DYNAMIC_LIGHT 0x0100 // dynamically get lighting from floor or ceil (flying monsters) +#define STUDIO_TRACE_HITBOX 0x0200 // always use hitbox trace instead of bbox + // lighting options #define STUDIO_NF_FLATSHADE 0x0001 #define STUDIO_NF_CHROME 0x0002 -#define STUDIO_NF_FULLBRIGHT 0x0004 +#define STUDIO_NF_FULLBRIGHT 0x0004 #define STUDIO_NF_NOMIPS 0x0008 #define STUDIO_NF_ALPHA 0x0010 #define STUDIO_NF_ADDITIVE 0x0020 @@ -321,7 +324,7 @@ typedef struct // motion flags #define STUDIO_X 0x0001 -#define STUDIO_Y 0x0002 +#define STUDIO_Y 0x0002 #define STUDIO_Z 0x0004 #define STUDIO_XR 0x0008 #define STUDIO_YR 0x0010 diff --git a/dep/rehlsdk/engine/sys_shared.cpp b/dep/rehlsdk/engine/sys_shared.cpp index e671f46..385b778 100644 --- a/dep/rehlsdk/engine/sys_shared.cpp +++ b/dep/rehlsdk/engine/sys_shared.cpp @@ -35,6 +35,7 @@ #define SSSE3_FLAG (1<<9) #define SSE4_1_FLAG (1<<19) #define SSE4_2_FLAG (1<<20) +#define POPCNT_FLAG (1<<23) #define AVX_FLAG (1<<28) #define AVX2_FLAG (1<<5) @@ -56,6 +57,7 @@ void Sys_CheckCpuInstructionsSupport(void) 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.popcnt = (cpuid_data[2] & POPCNT_FLAG) ? 1 : 0; cpuinfo.avx = (cpuid_data[2] & AVX_FLAG) ? 1 : 0; #if defined ASMLIB_H diff --git a/dep/rehlsdk/engine/sys_shared.h b/dep/rehlsdk/engine/sys_shared.h index cc9ed72..768b51f 100644 --- a/dep/rehlsdk/engine/sys_shared.h +++ b/dep/rehlsdk/engine/sys_shared.h @@ -31,7 +31,7 @@ typedef struct cpuinfo_s { - uint8 sse3, ssse3, sse4_1, sse4_2, avx, avx2; + uint8 sse3, ssse3, sse4_1, sse4_2, avx, avx2, popcnt; } cpuinfo_t; extern cpuinfo_t cpuinfo; diff --git a/dep/rehlsdk/engine/userid_rehlds.h b/dep/rehlsdk/engine/userid_rehlds.h index 0fb8d84..6a22221 100644 --- a/dep/rehlsdk/engine/userid_rehlds.h +++ b/dep/rehlsdk/engine/userid_rehlds.h @@ -38,7 +38,6 @@ enum AUTH_IDTYPE AUTH_IDTYPE_LOCAL = 3 }; -/* <2e915> ../engine/userid.h:22 */ typedef struct USERID_s { int idtype; diff --git a/dep/rehlsdk/public/commonmacros.h b/dep/rehlsdk/public/commonmacros.h new file mode 100644 index 0000000..e82bfd6 --- /dev/null +++ b/dep/rehlsdk/public/commonmacros.h @@ -0,0 +1,30 @@ +#ifndef COMMONMACROS_H +#define COMMONMACROS_H +#pragma once + + +// ------------------------------------------------------- +// +// commonmacros.h +// +// This should contain ONLY general purpose macros that are +// appropriate for use in engine/launcher/all tools +// +// ------------------------------------------------------- + +#include "osconfig.h" +// Makes a 4-byte "packed ID" int out of 4 characters +#define MAKEID(d,c,b,a) ( ((int)(a) << 24) | ((int)(b) << 16) | ((int)(c) << 8) | ((int)(d)) ) + +// Compares a string with a 4-byte packed ID constant +#define STRING_MATCHES_ID( p, id ) ( (*((int *)(p)) == (id) ) ? true : false ) +#define ID_TO_STRING( id, p ) ( (p)[3] = (((id)>>24) & 0xFF), (p)[2] = (((id)>>16) & 0xFF), (p)[1] = (((id)>>8) & 0xFF), (p)[0] = (((id)>>0) & 0xFF) ) + +#define ARRAYSIZE(p) (sizeof(p)/sizeof(p[0])) + +// Keeps clutter down a bit, when using a float as a bit-vector +#define SetBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) | (bits)) +#define ClearBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) & ~(bits)) +#define FBitSet(flBitVector, bit) ((int)(flBitVector) & (bit)) + +#endif // COMMONMACROS_H diff --git a/revoice/src/SteamP2PCodec.cpp b/revoice/src/SteamP2PCodec.cpp index 909d659..d0409a0 100644 --- a/revoice/src/SteamP2PCodec.cpp +++ b/revoice/src/SteamP2PCodec.cpp @@ -1,30 +1,38 @@ #include "precompiled.h" -CSteamP2PCodec::CSteamP2PCodec(VoiceEncoder_Silk* backend) { +CSteamP2PCodec::CSteamP2PCodec(VoiceEncoder_Silk* backend) +{ m_BackendCodec = backend; } -bool CSteamP2PCodec::Init(int quality) { +bool CSteamP2PCodec::Init(int quality) +{ return m_BackendCodec->Init(quality); } -void CSteamP2PCodec::Release() { +void CSteamP2PCodec::Release() +{ m_BackendCodec->Release(); delete this; } -bool CSteamP2PCodec::ResetState() { +bool CSteamP2PCodec::ResetState() +{ return m_BackendCodec->ResetState(); } -int CSteamP2PCodec::StreamDecode(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes) const { +int CSteamP2PCodec::StreamDecode(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes) const +{ const char* maxReadPos = pCompressed + compressedBytes; const char* readPos = pCompressed; - while (readPos < maxReadPos) { + + while (readPos < maxReadPos) + { uint8 opcode = *(uint8*)readPos; readPos++; - switch (opcode) { + switch (opcode) + { case 0xB: //Set sampling rate if (readPos + 2 > maxReadPos) { return 0; @@ -37,6 +45,7 @@ int CSteamP2PCodec::StreamDecode(const char *pCompressed, int compressedBytes, c if (readPos + 2 > maxReadPos) { return 0; } + uint16 len = *(uint16*)readPos; readPos += 2; @@ -56,8 +65,10 @@ int CSteamP2PCodec::StreamDecode(const char *pCompressed, int compressedBytes, c return 0; // no voice payload in the stream } -int CSteamP2PCodec::StreamEncode(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal) const { +int CSteamP2PCodec::StreamEncode(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal) const +{ char* writePos = pCompressed; + if (maxCompressedBytes < 10) { // no room return 0; } @@ -80,13 +91,15 @@ int CSteamP2PCodec::StreamEncode(const char *pUncompressedBytes, int nSamples, c return writePos - pCompressed; } -int CSteamP2PCodec::Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes) { +int CSteamP2PCodec::Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes) +{ if (compressedBytes < 12) { return 0; } uint32 computedChecksum = crc32(pCompressed, compressedBytes - 4); uint32 wireChecksum = *(uint32*)(pCompressed + compressedBytes - 4); + if (computedChecksum != wireChecksum) { return 0; } @@ -94,7 +107,8 @@ int CSteamP2PCodec::Decompress(const char *pCompressed, int compressedBytes, cha return StreamDecode(pCompressed + 8, compressedBytes - 12, pUncompressed, maxUncompressedBytes); } -int CSteamP2PCodec::Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal) { +int CSteamP2PCodec::Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal) +{ if (maxCompressedBytes < 12) { //no room return 0; } @@ -110,6 +124,7 @@ int CSteamP2PCodec::Compress(const char *pUncompressedBytes, int nSamples, char if (encodeRes <= 0) { return 0; } + writePos += encodeRes; uint32 cksum = crc32(pCompressed, writePos - pCompressed); diff --git a/revoice/src/SteamP2PCodec.h b/revoice/src/SteamP2PCodec.h index a21e55a..6176c1e 100644 --- a/revoice/src/SteamP2PCodec.h +++ b/revoice/src/SteamP2PCodec.h @@ -17,6 +17,7 @@ public: private: int StreamDecode(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes) const; int StreamEncode(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal) const; + private: VoiceEncoder_Silk* m_BackendCodec; -}; \ No newline at end of file +}; diff --git a/revoice/src/VoiceEncoder_Silk.cpp b/revoice/src/VoiceEncoder_Silk.cpp index 970d561..1681d16 100644 --- a/revoice/src/VoiceEncoder_Silk.cpp +++ b/revoice/src/VoiceEncoder_Silk.cpp @@ -1,14 +1,15 @@ - #include "precompiled.h" -VoiceEncoder_Silk::VoiceEncoder_Silk() { +VoiceEncoder_Silk::VoiceEncoder_Silk() +{ m_pEncoder = NULL; m_pDecoder = NULL; m_targetRate_bps = 25000; m_packetLoss_perc = 0; } -VoiceEncoder_Silk::~VoiceEncoder_Silk() { +VoiceEncoder_Silk::~VoiceEncoder_Silk() +{ if (m_pEncoder) { free(m_pEncoder); m_pEncoder = NULL; @@ -20,7 +21,8 @@ VoiceEncoder_Silk::~VoiceEncoder_Silk() { } } -bool VoiceEncoder_Silk::Init(int quality) { +bool VoiceEncoder_Silk::Init(int quality) +{ m_targetRate_bps = 25000; m_packetLoss_perc = 0; @@ -37,11 +39,13 @@ bool VoiceEncoder_Silk::Init(int quality) { return true; } -void VoiceEncoder_Silk::Release() { +void VoiceEncoder_Silk::Release() +{ delete this; } -bool VoiceEncoder_Silk::ResetState() { +bool VoiceEncoder_Silk::ResetState() +{ if (m_pEncoder) SKP_Silk_SDK_InitEncoder(m_pEncoder, &this->m_encControl); @@ -49,10 +53,12 @@ bool VoiceEncoder_Silk::ResetState() { SKP_Silk_SDK_InitDecoder(m_pDecoder); m_bufOverflowBytes.Clear(); + return true; } -int VoiceEncoder_Silk::Compress(const char *pUncompressedIn, int nSamplesIn, char *pCompressed, int maxCompressedBytes, bool bFinal) { +int VoiceEncoder_Silk::Compress(const char *pUncompressedIn, int nSamplesIn, char *pCompressed, int maxCompressedBytes, bool bFinal) +{ signed int nSamplesToUse; // edi@4 const __int16 *psRead; // ecx@4 int nSamples; // edi@5 @@ -75,7 +81,7 @@ int VoiceEncoder_Silk::Compress(const char *pUncompressedIn, int nSamplesIn, cha if (m_bufOverflowBytes.TellPut()) { m_bufOverflowBytes.Put(pUncompressedIn, 2 * nSamplesIn); - + psRead = (const __int16 *)m_bufOverflowBytes.Base(); nSamplesToUse = m_bufOverflowBytes.TellPut() / 2; } else { @@ -122,10 +128,11 @@ int VoiceEncoder_Silk::Compress(const char *pUncompressedIn, int nSamplesIn, cha m_bufOverflowBytes.Put(&pUncompressedIn[2 * (nSamplesIn - nSamplesRemaining)], 2 * nSamplesRemaining); } - if (bFinal) { + if (bFinal) + { ResetState(); - if (pWritePosMax > pWritePos + 2) - { + + if (pWritePosMax > pWritePos + 2) { uint16 * pWriteEndFlag = (uint16*)pWritePos; pWritePos += sizeof(uint16); *pWriteEndFlag = 0xFFFF; @@ -147,6 +154,7 @@ int VoiceEncoder_Silk::Decompress(const char *pCompressed, int compressedBytes, m_decControl.API_sampleRate = outSampleRate; int nSamplesPerFrame = outSampleRate / 50; + if (compressedBytes <= 0) { return 0; } @@ -157,7 +165,8 @@ int VoiceEncoder_Silk::Decompress(const char *pCompressed, int compressedBytes, pWritePos = pUncompressed; pWritePosMax = &pUncompressed[maxUncompressedBytes]; - while (pReadPos < pReadPosMax) { + while (pReadPos < pReadPosMax) + { if (pReadPosMax - pReadPos < 2) { break; } @@ -174,11 +183,14 @@ int VoiceEncoder_Silk::Decompress(const char *pCompressed, int compressedBytes, //DTX (discontinued transmission) int numEmptySamples = nSamplesPerFrame; short nSamples = (pWritePosMax - pWritePos) / 2; + if (nSamples < numEmptySamples) { break; } + memset(pWritePos, 0, numEmptySamples * 2); pWritePos += numEmptySamples * 2; + continue; } @@ -189,9 +201,11 @@ int VoiceEncoder_Silk::Decompress(const char *pCompressed, int compressedBytes, do { short nSamples = (pWritePosMax - pWritePos) / 2; int decodeRes = SKP_Silk_SDK_Decode(m_pDecoder, &m_decControl, 0, (const unsigned char*)pReadPos, nPayloadSize, (__int16 *)pWritePos, &nSamples); + if (SKP_SILK_NO_ERROR != decodeRes) { return (pWritePos - pUncompressed) / 2; } + pWritePos += nSamples * sizeof(int16); } while (m_decControl.moreInternalDecoderFrames); pReadPos += nPayloadSize; diff --git a/revoice/src/VoiceEncoder_Silk.h b/revoice/src/VoiceEncoder_Silk.h index b597952..c3c0d35 100644 --- a/revoice/src/VoiceEncoder_Silk.h +++ b/revoice/src/VoiceEncoder_Silk.h @@ -6,15 +6,15 @@ class VoiceEncoder_Silk : public IVoiceCodec { private: - void * m_pEncoder; /* 4 4 */ - //int m_API_fs_Hz; /* 8 4 */ - int m_targetRate_bps; /* 12 4 */ - int m_packetLoss_perc; /* 16 4 */ - SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */ - CUtlBuffer m_bufOverflowBytes; /* 52 24 */ + void * m_pEncoder; /* 4 4 */ + //int m_API_fs_Hz; /* 8 4 */ + int m_targetRate_bps; /* 12 4 */ + int m_packetLoss_perc; /* 16 4 */ + SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */ + CUtlBuffer m_bufOverflowBytes; /* 52 24 */ - void * m_pDecoder; /* 76 4 */ - SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */ + void * m_pDecoder; /* 76 4 */ + SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */ public: VoiceEncoder_Silk(); @@ -28,4 +28,4 @@ public: virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes); int GetNumQueuedEncodingSamples() const { return m_bufOverflowBytes.TellPut() / 2; } -}; /* size: 100 */ \ No newline at end of file +}; /* size: 100 */ diff --git a/revoice/src/VoiceEncoder_Speex.cpp b/revoice/src/VoiceEncoder_Speex.cpp index e7a20f7..f792e77 100644 --- a/revoice/src/VoiceEncoder_Speex.cpp +++ b/revoice/src/VoiceEncoder_Speex.cpp @@ -35,21 +35,21 @@ bool VoiceEncoder_Speex::Init(int quality, int &rawFrameSize, int &encodedFrameS rawFrameSize = 320; switch (quality) { - case 2: - m_Quality = 2; - break; - case 3: - m_Quality = 4; - break; - case 4: - m_Quality = 6; - break; - case 5: - m_Quality = 8; - break; - default: - m_Quality = 0; - break; + case 2: + m_Quality = 2; + break; + case 3: + m_Quality = 4; + break; + case 4: + m_Quality = 6; + break; + case 5: + m_Quality = 8; + break; + default: + m_Quality = 0; + break; } encodedFrameSize = ENCODED_FRAME_SIZE[m_Quality]; @@ -123,14 +123,12 @@ bool VoiceEncoder_Speex::InitStates() /* ../engine/voice_codecs/speex/VoiceEncoder_Speex.cpp:193 */ void VoiceEncoder_Speex::TermStates() { - if (m_EncoderState != NULL) - { + if (m_EncoderState != NULL) { speex_encoder_destroy(m_EncoderState); m_EncoderState = NULL; } - if (m_DecoderState != NULL) - { + if (m_DecoderState != NULL) { speex_encoder_destroy(m_DecoderState); m_DecoderState = NULL; } diff --git a/revoice/src/dllapi.cpp b/revoice/src/dllapi.cpp index ce55546..caf3e44 100644 --- a/revoice/src/dllapi.cpp +++ b/revoice/src/dllapi.cpp @@ -31,8 +31,7 @@ #include "precompiled.h" -static DLL_FUNCTIONS gFunctionTable = -{ +static DLL_FUNCTIONS gFunctionTable = { NULL, // pfnGameInit NULL, // pfnSpawn NULL, // pfnThink @@ -120,7 +119,8 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi return(TRUE); } -C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) { +C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) +{ if (!pNewFunctionTable) { UTIL_LogPrintf("GetNewDLLFunctions called with null pNewFunctionTable"); return(FALSE); @@ -133,4 +133,4 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in } memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS)); return(TRUE); -} \ No newline at end of file +} diff --git a/revoice/src/engine_api.cpp b/revoice/src/engine_api.cpp index 9e81024..e10a6be 100644 --- a/revoice/src/engine_api.cpp +++ b/revoice/src/engine_api.cpp @@ -31,8 +31,7 @@ #include "precompiled.h" -enginefuncs_t meta_engfuncs = -{ +enginefuncs_t meta_engfuncs = { NULL, // pfnPrecacheModel() NULL, // pfnPrecacheSound() NULL, // pfnSetModel() diff --git a/revoice/src/h_export.cpp b/revoice/src/h_export.cpp index 36586b0..7a89316 100644 --- a/revoice/src/h_export.cpp +++ b/revoice/src/h_export.cpp @@ -28,7 +28,7 @@ //! Holds engine functionality callbacks enginefuncs_t g_engfuncs; -globalvars_t *gpGlobals; +globalvars_t *gpGlobals; // Receive engine function table from engine. // This appears to be the _first_ DLL routine called by the engine, so we diff --git a/revoice/src/meta_api.cpp b/revoice/src/meta_api.cpp index 49a9b01..dc5e1f6 100644 --- a/revoice/src/meta_api.cpp +++ b/revoice/src/meta_api.cpp @@ -34,6 +34,7 @@ * version. * */ + #include "precompiled.h" // Must provide at least one of these.. @@ -73,9 +74,11 @@ mutil_funcs_t *gpMetaUtilFuncs; // metamod utility functions C_DLLEXPORT int Meta_Query(char * /*ifvers */, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) { // Give metamod our plugin_info struct - *pPlugInfo=&Plugin_info; + *pPlugInfo = &Plugin_info; + // Get metamod utility function table. - gpMetaUtilFuncs=pMetaUtilFuncs; + gpMetaUtilFuncs = pMetaUtilFuncs; + return(TRUE); } @@ -90,13 +93,16 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME /* now */, META_FUNCTIONS *pFunctionTa LOG_ERROR(PLID, "Meta_Attach called with null pMGlobals"); return(FALSE); } - gpMetaGlobals=pMGlobals; + + gpMetaGlobals = pMGlobals; + if(!pFunctionTable) { LOG_ERROR(PLID, "Meta_Attach called with null pFunctionTable"); return(FALSE); } + memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); - gpGamedllFuncs=pGamedllFuncs; + gpGamedllFuncs = pGamedllFuncs; return Revoice_Load() ? (TRUE) : (FALSE); } @@ -109,7 +115,8 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME /* now */, PL_UNLOAD_REASON /* reason return(TRUE); } -bool Revoice_Load() { +bool Revoice_Load() +{ if (!Revoice_Utils_Init()) return false; @@ -125,6 +132,7 @@ bool Revoice_Load() { return false; Revoice_Init_Players(); + if (!Revoice_Main_Init()) { LCPrintf(true, "Initialization failed\n"); return false; diff --git a/revoice/src/precompiled.h b/revoice/src/precompiled.h index 35098c8..aac479b 100644 --- a/revoice/src/precompiled.h +++ b/revoice/src/precompiled.h @@ -13,7 +13,7 @@ #include #include #include -#include "sdk_util.h" // UTIL_LogPrintf, etc +#include "sdk_util.h" // UTIL_LogPrintf, etc #include "revoice_shared.h" #include "revoice_cfg.h" diff --git a/revoice/src/revoice_cfg.cpp b/revoice/src/revoice_cfg.cpp index a2a4462..67760a3 100644 --- a/revoice/src/revoice_cfg.cpp +++ b/revoice/src/revoice_cfg.cpp @@ -2,16 +2,18 @@ CRevoiceConfig* g_RevoiceConfig; -bool Revoice_Cfg_LoadDefault() { +bool Revoice_Cfg_LoadDefault() +{ CRevoiceConfig* cfg = CRevoiceConfig::load(REVOICE_CFG_FILE); + if (!cfg) return false; - if (g_RevoiceConfig) { + if (g_RevoiceConfig) delete g_RevoiceConfig; - } g_RevoiceConfig = cfg; + return true; } @@ -21,11 +23,16 @@ CRevoiceConfig* CRevoiceConfig::load(const char* fname) char gamedir[MAX_PATH]; sprintf(namebuf, "./%s", fname); + FILE *fl = fopen(namebuf, "r"); - if (fl == NULL) { + + if (fl == NULL) + { g_engfuncs.pfnGetGameDir(gamedir); sprintf(namebuf, "./%s/%s", gamedir, fname); + fl = fopen(namebuf, "r"); + if (fl == NULL) { LCPrintf(true, "Failed to load config: can't find %s in server root or gamedir\n", fname); return NULL; @@ -36,13 +43,17 @@ CRevoiceConfig* CRevoiceConfig::load(const char* fname) int cline = 0; CRevoiceConfig* cfg = createDefault(); - while (fgets(linebuf, sizeof(linebuf), fl)) { + while (fgets(linebuf, sizeof(linebuf), fl)) + { cline++; + char* l = trimbuf(linebuf); + if (l[0] == '\0' || l[0] == '#') continue; char* valSeparator = strchr(l, '='); + if (valSeparator == NULL) { LCPrintf(true, "Config line parsing failed: missed '=' on line %d\n", cline); } @@ -51,6 +62,7 @@ CRevoiceConfig* CRevoiceConfig::load(const char* fname) char* param = trimbuf(l); char* value = trimbuf(valSeparator); + if (!cfg->parseCfgParam(param, value)) { LCPrintf(true, "Config line parsing failed: unknown parameter '%s' at line %d\n", param, cline); } @@ -74,43 +86,44 @@ CRevoiceConfig* CRevoiceConfig::createDefault() bool CRevoiceConfig::parseCfgParam(const char* param, const char* value) { -#define REV_CFG_PARSE_INT(paramName, field, _type, minVal, maxVal) \ - if (!strcasecmp(paramName, param)) { \ - int i = atoi(value); \ - if (i < minVal || i > maxVal) { \ - LCPrintf(true, "Invalid %s value '%s'\n", param, value); \ - return false; \ - } \ - field = (_type) i; \ - return true; \ +#define REV_CFG_PARSE_INT(paramName, field, _type, minVal, maxVal) \ + if (!strcasecmp(paramName, param)) { \ + int i = atoi(value); \ + if (i < minVal || i > maxVal) { \ + LCPrintf(true, "Invalid %s value '%s'\n", param, value); \ + return false; \ + } \ + field = (_type) i; \ + return true; \ } -#define REV_CFG_PARSE_IP(paramName, field) \ - if (!strcasecmp(paramName, param)) { \ - field = inet_addr(value); \ - return true; \ +#define REV_CFG_PARSE_IP(paramName, field) \ + if (!strcasecmp(paramName, param)) { \ + field = inet_addr(value); \ + return true; \ } -#define REV_CFG_PARSE_BOOL(paramName, field) \ - if (!strcasecmp(paramName, param)) { \ - int i = atoi(value); \ - if (i < 0 || i > 1) { \ - LCPrintf(true, "Invalid %s value '%s'\n", param, value); \ - return false; \ - } \ - field = i ? true : false; \ - return true; \ +#define REV_CFG_PARSE_BOOL(paramName, field) \ + if (!strcasecmp(paramName, param)) { \ + int i = atoi(value); \ + if (i < 0 || i > 1) { \ + LCPrintf(true, "Invalid %s value '%s'\n", param, value); \ + return false; \ + } \ + field = i ? true : false; \ + return true; \ } -#define REV_CFG_PARSE_STR(paramName, field) \ - if (!strcasecmp(paramName, param)) { \ - strncpy(field, value, ARRAYSIZE(field) - 1); \ - field[ARRAYSIZE(field) - 1] = 0; \ - return true; \ +#define REV_CFG_PARSE_STR(paramName, field) \ + if (!strcasecmp(paramName, param)) { \ + strncpy(field, value, ARRAYSIZE(field) - 1); \ + field[ARRAYSIZE(field) - 1] = 0; \ + return true; \ } - REV_CFG_PARSE_INT("LoggingMode", m_LogMode, int, rl_none, (rl_console|rl_logfile)); + REV_CFG_PARSE_INT("LoggingMode", m_LogMode, int, rl_none, (rl_console | rl_logfile)); LCPrintf(true, " Config line parsing failed: unknown parameter '%s'\n", param); + return false; } diff --git a/revoice/src/revoice_main.cpp b/revoice/src/revoice_main.cpp index 045569e..5194837 100644 --- a/revoice/src/revoice_main.cpp +++ b/revoice/src/revoice_main.cpp @@ -1,17 +1,18 @@ - #include "precompiled.h" cvar_t* pcv_sv_voiceenable = NULL; -void SV_DropClient_hook(IRehldsHook_SV_DropClient* chain, IGameClient* cl, bool crash, const char* msg) { - +void SV_DropClient_hook(IRehldsHook_SV_DropClient* chain, IGameClient* cl, bool crash, const char* msg) +{ CRevoicePlayer* plr = GetPlayerByClientPtr(cl); + plr->OnDisconnected(); + chain->callNext(cl, crash, msg); } -void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *cvarValue) { - +void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *cvarValue) +{ CRevoicePlayer* plr = GetPlayerByEdict(pEnt); if (plr->GetRequestId() != requestID) { @@ -19,26 +20,31 @@ void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, con } const char* lastSeparator = strrchr(cvarValue, ','); - int buildNumber = 0; - if (lastSeparator) { - buildNumber = atoi(lastSeparator + 1); - } - if (buildNumber > 4554) { - plr->SetCodecType(vct_silk); + if (lastSeparator) + { + int buildNumber = atoi(lastSeparator + 1); + + if (buildNumber > 4554) { + plr->SetCodecType(vct_silk); + } } RETURN_META(MRES_IGNORED); } -int TranscodeVoice(const char* srcBuf, int srcBufLen, IVoiceCodec* srcCodec, IVoiceCodec* dstCodec, char* dstBuf, int dstBufSize) { +int TranscodeVoice(const char* srcBuf, int srcBufLen, IVoiceCodec* srcCodec, IVoiceCodec* dstCodec, char* dstBuf, int dstBufSize) +{ char decodedBuf[32768]; + int numDecodedSamples = srcCodec->Decompress(srcBuf, srcBufLen, decodedBuf, sizeof(decodedBuf)); + if (numDecodedSamples <= 0) { return 0; } int compressedSize = dstCodec->Compress(decodedBuf, numDecodedSamples, dstBuf, dstBufSize, false); + if (compressedSize <= 0) { return 0; } @@ -59,7 +65,8 @@ int TranscodeVoice(const char* srcBuf, int srcBufLen, IVoiceCodec* srcCodec, IVo return compressedSize; } -void SV_ParseVoiceData_emu(IGameClient* cl) { +void SV_ParseVoiceData_emu(IGameClient* cl) +{ char chReceived[4096]; unsigned int nDataLength = g_RehldsFuncs->MSG_ReadShort(); @@ -82,7 +89,8 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { char* speexData; int speexDataLen; char* silkData; int silkDataLen; - switch (srcPlayer->GetCodecType()) { + switch (srcPlayer->GetCodecType()) + { case vct_silk: { if (nDataLength > MAX_SILK_DATA_LEN || srcPlayer->GetVoiceRate() > MAX_SILK_VOICE_RATE) @@ -109,7 +117,8 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { int maxclients = g_RehldsSvs->GetMaxClients(); - for (int i = 0; i < maxclients; i++) { + for (int i = 0; i < maxclients; i++) + { CRevoicePlayer* dstPlayer = &g_Players[i]; IGameClient* dstClient = dstPlayer->GetClient(); @@ -121,7 +130,8 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { char* sendBuf; int nSendLen; - switch (dstPlayer->GetCodecType()) { + switch (dstPlayer->GetCodecType()) + { case vct_silk: sendBuf = silkData; nSendLen = silkDataLen; break; @@ -151,7 +161,8 @@ void SV_ParseVoiceData_emu(IGameClient* cl) { } } -void Rehlds_HandleNetCommand(IRehldsHook_HandleNetCommand* chain, IGameClient* cl, int8 opcode) { +void Rehlds_HandleNetCommand(IRehldsHook_HandleNetCommand* chain, IGameClient* cl, int8 opcode) +{ if (opcode == 8) { //clc_voicedata SV_ParseVoiceData_emu(cl); return; @@ -163,39 +174,44 @@ void Rehlds_HandleNetCommand(IRehldsHook_HandleNetCommand* chain, IGameClient* c qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) { CRevoicePlayer* plr = GetPlayerByEdict(pEntity); + plr->OnConnected(); + RETURN_META_VALUE(MRES_IGNORED, TRUE); } -void SV_WriteVoiceCodec_hooked(IRehldsHook_SV_WriteVoiceCodec* chain, sizebuf_t* sb) { - +void SV_WriteVoiceCodec_hooked(IRehldsHook_SV_WriteVoiceCodec* chain, sizebuf_t* sb) +{ IGameClient* cl = g_RehldsFuncs->GetHostClient(); CRevoicePlayer* plr = GetPlayerByClientPtr(cl); - switch (plr->GetCodecType()) { - case vct_silk: - g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit - g_RehldsFuncs->MSG_WriteString(sb, ""); //codec id - g_RehldsFuncs->MSG_WriteByte(sb, 0); //quality - break; + switch (plr->GetCodecType()) + { + case vct_silk: + g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit + g_RehldsFuncs->MSG_WriteString(sb, ""); //codec id + g_RehldsFuncs->MSG_WriteByte(sb, 0); //quality + break; - case vct_speex: - g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit - g_RehldsFuncs->MSG_WriteString(sb, "voice_speex"); //codec id - g_RehldsFuncs->MSG_WriteByte(sb, 5); //quality - break; + case vct_speex: + g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit + g_RehldsFuncs->MSG_WriteString(sb, "voice_speex"); //codec id + g_RehldsFuncs->MSG_WriteByte(sb, 5); //quality + break; - default: - LCPrintf(true, "SV_WriteVoiceCodec() called on client(%d) with unknown voice codec\n", cl->GetId()); - break; + default: + LCPrintf(true, "SV_WriteVoiceCodec() called on client(%d) with unknown voice codec\n", cl->GetId()); + break; } } -bool Revoice_Main_Init() { - g_RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_hook); - g_RehldsHookchains->HandleNetCommand()->registerHook(Rehlds_HandleNetCommand); - g_RehldsHookchains->SV_WriteVoiceCodec()->registerHook(SV_WriteVoiceCodec_hooked); +bool Revoice_Main_Init() +{ + g_RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_hook, HC_PRIORITY_DEFAULT + 1); + g_RehldsHookchains->HandleNetCommand()->registerHook(Rehlds_HandleNetCommand, HC_PRIORITY_DEFAULT + 1); + g_RehldsHookchains->SV_WriteVoiceCodec()->registerHook(SV_WriteVoiceCodec_hooked, HC_PRIORITY_DEFAULT + 1); + pcv_sv_voiceenable = g_engfuncs.pfnCVarGetPointer("sv_voiceenable"); return true; -} \ No newline at end of file +} diff --git a/revoice/src/revoice_player.cpp b/revoice/src/revoice_player.cpp index a91ac47..3a6b6ac 100644 --- a/revoice/src/revoice_player.cpp +++ b/revoice/src/revoice_player.cpp @@ -2,7 +2,8 @@ CRevoicePlayer g_Players[MAX_PLAYERS]; -CRevoicePlayer::CRevoicePlayer() { +CRevoicePlayer::CRevoicePlayer() +{ m_CodecType = vct_none; m_SpeexCodec = new VoiceCodec_Frame(new VoiceEncoder_Speex()); m_SilkCodec = new CSteamP2PCodec(new VoiceEncoder_Silk()); @@ -15,7 +16,8 @@ CRevoicePlayer::CRevoicePlayer() { m_Connected = false; } -void CRevoicePlayer::Initialize(IGameClient* cl) { +void CRevoicePlayer::Initialize(IGameClient* cl) +{ m_RehldsClient = cl; } @@ -67,18 +69,20 @@ void Revoice_Init_Players() } } -CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl) { - return &g_Players[cl->GetId()]; +CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl) +{ + return &g_Players[ cl->GetId() ]; } CRevoicePlayer* GetPlayerByEdict(const edict_t* ed) { int clientId = g_engfuncs.pfnIndexOfEdict(ed) - 1; + if (clientId < 0 || clientId >= g_RehldsSvs->GetMaxClients()) { util_syserror("Invalid player edict id=%d\n", clientId); } - return &g_Players[clientId]; + return &g_Players[ clientId ]; } void CRevoicePlayer::SetLastVoiceTime(double time) @@ -93,15 +97,16 @@ void CRevoicePlayer::UpdateVoiceRate(double delta) { switch (m_CodecType) { - case vct_silk: - m_VoiceRate -= int(delta * MAX_SILK_VOICE_RATE) + MAX_SILK_DATA_LEN; - break; + case vct_silk: + m_VoiceRate -= int(delta * MAX_SILK_VOICE_RATE) + MAX_SILK_DATA_LEN; + break; - case vct_speex: - m_VoiceRate -= int(delta * MAX_SPEEX_VOICE_RATE) + MAX_SPEEX_DATA_LEN; - break; - default: - break; + case vct_speex: + m_VoiceRate -= int(delta * MAX_SPEEX_VOICE_RATE) + MAX_SPEEX_DATA_LEN; + break; + + default: + break; } if (m_VoiceRate < 0) diff --git a/revoice/src/revoice_player.h b/revoice/src/revoice_player.h index 2790618..3459e86 100644 --- a/revoice/src/revoice_player.h +++ b/revoice/src/revoice_player.h @@ -31,11 +31,11 @@ public: int GetRequestId() const { return m_RequestId; } bool IsConnected() const { return m_Connected; } - void SetCodecType(revoice_codec_type codecType) { m_CodecType = codecType; }; - revoice_codec_type GetCodecType() const { return m_CodecType; } - CSteamP2PCodec* GetSilkCodec() const { return m_SilkCodec; } - VoiceCodec_Frame* GetSpeexCodec() const { return m_SpeexCodec; } - IGameClient* GetClient() const { return m_RehldsClient; } + void SetCodecType(revoice_codec_type codecType) { m_CodecType = codecType; }; + revoice_codec_type GetCodecType() const { return m_CodecType; } + CSteamP2PCodec* GetSilkCodec() const { return m_SilkCodec; } + VoiceCodec_Frame* GetSpeexCodec() const { return m_SpeexCodec; } + IGameClient* GetClient() const { return m_RehldsClient; } }; extern CRevoicePlayer g_Players[MAX_PLAYERS]; diff --git a/revoice/src/revoice_rehlds_api.cpp b/revoice/src/revoice_rehlds_api.cpp index ba736fc..0e1b2e2 100644 --- a/revoice/src/revoice_rehlds_api.cpp +++ b/revoice/src/revoice_rehlds_api.cpp @@ -14,6 +14,7 @@ bool Revoice_RehldsApi_TryInit(CSysModule* engineModule, char* failureReason) } CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule); + if (!ifaceFactory) { sprintf(failureReason, "Failed to locate interface factory in engine module\n"); return false; @@ -21,6 +22,7 @@ bool Revoice_RehldsApi_TryInit(CSysModule* engineModule, char* failureReason) int retCode = 0; g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode); + if (!g_RehldsApi) { sprintf(failureReason, "Failed to locate retrieve rehlds api interface from engine module, return code is %d\n", retCode); return false; @@ -47,7 +49,6 @@ bool Revoice_RehldsApi_TryInit(CSysModule* engineModule, char* failureReason) return true; } - bool Revoice_RehldsApi_Init() { char failReason[2048]; diff --git a/revoice/src/revoice_reunion_api.cpp b/revoice/src/revoice_reunion_api.cpp index b126b23..8086f05 100644 --- a/revoice/src/revoice_reunion_api.cpp +++ b/revoice/src/revoice_reunion_api.cpp @@ -2,7 +2,8 @@ IReunionApi* g_ReunionApi; -bool Revoice_ReunionApi_Init() { +bool Revoice_ReunionApi_Init() +{ g_ReunionApi = (IReunionApi *)g_RehldsFuncs->GetPluginApi("reunion"); if (g_ReunionApi == NULL) { diff --git a/revoice/src/revoice_shared.h b/revoice/src/revoice_shared.h index b80267e..bf993b9 100644 --- a/revoice/src/revoice_shared.h +++ b/revoice/src/revoice_shared.h @@ -53,4 +53,3 @@ extern uint32 crc32(const void* buf, unsigned int bufLen); extern bool Revoice_Load(); extern bool Revoice_Utils_Init(); extern void util_syserror(const char* fmt, ...); - diff --git a/revoice/src/revoice_utils.cpp b/revoice/src/revoice_utils.cpp index 8fb482b..503f123 100644 --- a/revoice/src/revoice_utils.cpp +++ b/revoice/src/revoice_utils.cpp @@ -6,9 +6,10 @@ cvar_t* pcv_revoice_version; cvar_t* pcv_mp_logecho; char logstring[2048]; -void LCPrintf(bool critical, const char *fmt, ...) { - va_list argptr; - const int prefixlen = 11; //sizeof(LOG_PREFIX) - 1; +void LCPrintf(bool critical, const char *fmt, ...) +{ + va_list argptr; + const int prefixlen = 11; //sizeof(LOG_PREFIX) - 1; va_start(argptr, fmt); vsnprintf(logstring + prefixlen, sizeof(logstring) - prefixlen, fmt, argptr); @@ -30,38 +31,47 @@ void LCPrintf(bool critical, const char *fmt, ...) { ALERT(at_logged, logstring); } -bool Revoice_Utils_Init() { +bool Revoice_Utils_Init() +{ g_engfuncs.pfnCvar_RegisterVariable(&cv_revoice_version); pcv_revoice_version = g_engfuncs.pfnCVarGetPointer(cv_revoice_version.name); pcv_mp_logecho = g_engfuncs.pfnCVarGetPointer("mp_logecho"); strcpy(logstring, LOG_PREFIX); + return true; } -char* trimbuf(char *str) { +char* trimbuf(char *str) +{ char *ibuf = str; int i = 0; if (str == NULL) return NULL; + for (ibuf = str; *ibuf && (byte)(*ibuf) < (byte)0x80 && isspace(*ibuf); ++ibuf) ; i = strlen(ibuf); + if (str != ibuf) memmove(str, ibuf, i); str[i] = 0; + while (--i >= 0) { if (!isspace(ibuf[i])) break; } + ibuf[++i] = 0; + return str; } -uint32 crc32(const void* buf, unsigned int bufLen) { +uint32 crc32(const void* buf, unsigned int bufLen) +{ CRC32_t hCrc; g_engfuncs.pfnCRC32_Init(&hCrc); g_engfuncs.pfnCRC32_ProcessBuffer(&hCrc, (void*)buf, bufLen); @@ -73,11 +83,13 @@ void util_syserror(const char* fmt, ...) { va_list argptr; char buf[4096]; + va_start(argptr, fmt); vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr); buf[ARRAYSIZE(buf) - 1] = 0; va_end(argptr); LCPrintf(true, "ERROR: %s", buf); + *(int *)0 = 0; } diff --git a/revoice/src/sdk_util.cpp b/revoice/src/sdk_util.cpp index 2bf2aa0..115951f 100644 --- a/revoice/src/sdk_util.cpp +++ b/revoice/src/sdk_util.cpp @@ -16,6 +16,7 @@ * without written permission from Valve LLC. * ****/ + /* ===== util.cpp ======================================================== @@ -23,6 +24,7 @@ Utility code. Really not optional after all. */ + #include "precompiled.h" //========================================================= diff --git a/revoice/src/voice_codec_frame.cpp b/revoice/src/voice_codec_frame.cpp index 4fc318e..b2c1b8c 100644 --- a/revoice/src/voice_codec_frame.cpp +++ b/revoice/src/voice_codec_frame.cpp @@ -71,8 +71,7 @@ int VoiceCodec_Frame::Compress(const char *pUncompressedBytes, int nSamples, cha } // If it must get the last data, just pad with zeros.. - if (bFinal && m_nEncodeBufferSamples && (maxCompressedBytes - nCompressedBytes) >= m_nEncodedBytes) - { + if (bFinal && m_nEncodeBufferSamples && (maxCompressedBytes - nCompressedBytes) >= m_nEncodedBytes) { memset(&m_EncodeBuffer[m_nEncodeBufferSamples], 0, (m_nRawSamples - m_nEncodeBufferSamples) * BYTES_PER_SAMPLE); m_pFrameEncoder->EncodeFrame((const char*)m_EncodeBuffer, &pCompressed[nCompressedBytes]); nCompressedBytes += m_nEncodedBytes; diff --git a/revoice/src/voice_codec_frame.h b/revoice/src/voice_codec_frame.h index e4ccdc4..c489bb8 100644 --- a/revoice/src/voice_codec_frame.h +++ b/revoice/src/voice_codec_frame.h @@ -26,4 +26,4 @@ protected: int m_nRawSamples; int m_nEncodedBytes; -};/* size: 2072, cachelines: 33, members: 7 */ +}; /* size: 2072, cachelines: 33, members: 7 */