Skip to content

Commit

Permalink
Merge branch 'dreamstalker:master' into sv_maxusrcmdprocessticks_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov authored Sep 29, 2023
2 parents 74ffcb5 + b7f6eb8 commit ecfe8bb
Show file tree
Hide file tree
Showing 40 changed files with 649 additions and 127 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
jobs:
windows:
name: 'Windows'
runs-on: windows-latest
runs-on: windows-2019

env:
solution: 'msvc/ReHLDS.sln'
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
github.event.action == 'published' &&
startsWith(github.ref, 'refs/tags/')
run: |
7z a -tzip rehlds-bin-${{ env.APP_VERSION }}.zip bin/linux32/ hlsdk/
7z a -tzip rehlds-bin-${{ env.APP_VERSION }}.zip bin/ hlsdk/
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -aoa rehlds-dbg-${{ env.APP_VERSION }}.7z debug/
- name: Publish artifacts
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ReHLDS is a result of reverse engineering of original HLDS (build 6152/6153) usi

Along with reverse engineering, a lot of defects and (potential) bugs were found and fixed

You can try play on one of the servers that using rehlds: [Game Tracker](http://www.gametracker.com/search/?search_by=server_variable&search_by2=sv_version)
You can try playing on one of many servers that are using ReHLDS: [Game Tracker](http://www.gametracker.com/search/?search_by=server_variable&search_by2=sv_version)

## Goals of the project
<ul>
Expand Down Expand Up @@ -51,7 +51,8 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
<li>sv_rehlds_stringcmdrate_burst_punish // Time in minutes for which the player will be banned (0 - Permanent, use a negative number for a kick). Default: 5
<li>sv_rehlds_userinfo_transmitted_fields // Userinfo fields only with these keys will be transmitted to clients via network. If not set then all fields will be transmitted (except prefixed with underscore). Each key must be prefixed by backslash, for example "\name\model\*sid\*hltv\bottomcolor\topcolor". See [wiki](https://github.com/dreamstalker/rehlds/wiki/Userinfo-keys) to collect sufficient set of keys for your server. Default: ""
<li>sv_rehlds_attachedentities_playeranimationspeed_fix // Fixes bug with gait animation speed increase when player has some attached entities (aiments). Can cause animation lags when cl_updaterate is low. Default: 0
<li>sv_rehlds_maxclients_from_single_ip // Limit number of connections from the single ip address. Default: 5
<li>sv_rehlds_maxclients_from_single_ip // Limit number of connections at the same time from single IP address, not confuse to already connected players. Default: 5
<li>sv_rehlds_local_gametime <1|0> // A feature of local gametime which decrease "lags" if you run same map for a long time. Default: 0
<li>sv_use_entity_file // Use custom entity file for a map. Path to an entity file will be "maps/[map name].ent". 0 - use original entities. 1 - use .ent files from maps directory. 2 - use .ent files from maps directory and create new .ent file if not exist.
<li>sv_usercmd_custom_random_seed // When enabled server will populate an additional random seed independent of the client. Default: 0
</ul>
Expand Down
2 changes: 1 addition & 1 deletion rehlds/HLTV/Core/src/BSPModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ byte *BSPModel::LeafPVS(mleaf_t *leaf)

byte *BSPModel::DecompressVis(unsigned char *in)
{
static unsigned char decompressed[MODEL_MAX_PVS];
static unsigned char decompressed[MAX_MAP_LEAFS / 8];
if (in == nullptr) {
return m_novis;
}
Expand Down
5 changes: 2 additions & 3 deletions rehlds/HLTV/Core/src/BSPModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "l_studio.h"
#include "edict.h"
#include "bspfile.h"

// values for model_t's needload
#define NL_PRESENT 0
Expand Down Expand Up @@ -87,9 +88,7 @@ class BSPModel: public IBSPModel {

protected:
model_t m_model;

enum { MODEL_MAX_PVS = 1024 };
byte m_novis[MODEL_MAX_PVS];
byte m_novis[MAX_MAP_LEAFS / 8];
byte *m_base;

int m_visframecount;
Expand Down
12 changes: 12 additions & 0 deletions rehlds/common/cvardef.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ struct cvar_listener_t
const char *name;
};

typedef void (*pfnCvar_HookVariable_t) (cvar_t *pCvar);

struct cvarhook_t
{
pfnCvar_HookVariable_t hook;

cvar_t *cvar;
cvarhook_t *next;
};

qboolean Cvar_HookVariable(const char *var_name, cvarhook_t *pHook);

#endif // CVARDEF_H
6 changes: 3 additions & 3 deletions rehlds/engine/cmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
unsigned char *gPAS;
unsigned char *gPVS;
int gPVSRowBytes;
unsigned char mod_novis[MODEL_MAX_PVS];
unsigned char mod_novis[MAX_MAP_LEAFS / 8];

void Mod_Init(void)
{
SW_Mod_Init();
Q_memset(mod_novis, 255, MODEL_MAX_PVS);
Q_memset(mod_novis, 0xFF, MAX_MAP_LEAFS / 8);
}

unsigned char *Mod_DecompressVis(unsigned char *in, model_t *model)
{
static unsigned char decompressed[MODEL_MAX_PVS];
static unsigned char decompressed[MAX_MAP_LEAFS / 8];

if (in == NULL)
{
Expand Down
5 changes: 0 additions & 5 deletions rehlds/engine/cmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@
#pragma once

#include "maintypes.h"
#include "model.h"

// Looks like no more than 8096 visibility leafs per world model
const int MODEL_MAX_PVS = 1024;

extern unsigned char *gPAS;
extern unsigned char *gPVS;
extern int gPVSRowBytes;
extern unsigned char mod_novis[MODEL_MAX_PVS];

void Mod_Init(void);
unsigned char *Mod_DecompressVis(unsigned char *in, model_t *model);
Expand Down
102 changes: 84 additions & 18 deletions rehlds/engine/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,31 +1446,64 @@ char *COM_FileExtension(char *in)
#endif // #ifdef REHLDS_FIXES
}

// Fills "out" with the file name without path and extension.
// Fills "out" with the file name without path and extension
void COM_FileBase(const char *in, char *out)
{
const char *start, *end;
int len;
COM_FileBase_s(in, out, -1);
}

*out = 0;
// Extracts the base name of a file (no path, no extension, assumes '/' as path separator)
const char *COM_FileBase_s(const char *in, char *out, int size)
{
if (!in || !in[0])
{
*out = '\0';
return NULL;
}

len = Q_strlen(in);
int len = Q_strlen(in);
if (len <= 0)
return;
return NULL;

start = in + len - 1;
end = in + len;
while (start >= in && *start != '/' && *start != '\\')
// scan backward for '.'
int end = len - 1;
while (end && in[end] != '.' && !PATHSEPARATOR(in[end]))
end--;

// no '.', copy to end
if (in[end] != '.')
{
if (*start == '.')
end = start;
end = len - 1;
}
else
{
// Found ',', copy to left of '.'
end--;
}

// Scan backward for '/'
int start = len - 1;
while (start >= 0 && !PATHSEPARATOR(in[start]))
start--;

if (start < 0 || !PATHSEPARATOR(in[start]))
{
start = 0;
}
else
{
start++;
}
start++;

len = end - start;
Q_strncpy(out, start, len);
out[len] = 0;
// Length of new sting
int maxcopy = end - start + 1;
if (size >= 0 && maxcopy >= size)
return NULL;

// Copy partial string
Q_strncpy(out, &in[start], maxcopy);
out[maxcopy] = '\0';
return out;
}

void COM_DefaultExtension(char *path, char *extension)
Expand Down Expand Up @@ -1945,6 +1978,34 @@ NOXREF int COM_ExpandFilename(char *filename)
return *filename != 0;
}

// small helper function shared by lots of modules
qboolean COM_IsAbsolutePath(const char *pStr)
{
if (strchr(pStr, ':') || pStr[0] == '/' || pStr[0] == '\\')
return FALSE;

return TRUE;
}

qboolean COM_IsValidPath(const char *pszFilename)
{
if (!pszFilename)
return FALSE;

if (Q_strlen(pszFilename) <= 0 ||
Q_strstr(pszFilename, "\\\\") || // to protect network paths
Q_strstr(pszFilename, ":") || // to protect absolute paths
Q_strstr(pszFilename, "..") || // to protect relative paths
Q_strstr(pszFilename, "~") ||
Q_strstr(pszFilename, "\n") || // CFileSystem_Stdio::FS_fopen doesn't allow this
Q_strstr(pszFilename, "\r")) // CFileSystem_Stdio::FS_fopen doesn't allow this
{
return FALSE;
}

return TRUE;
}

int EXT_FUNC COM_FileSize(const char *filename)
{
FileHandle_t fp;
Expand All @@ -1962,7 +2023,10 @@ int EXT_FUNC COM_FileSize(const char *filename)

unsigned char* EXT_FUNC COM_LoadFile(const char *path, int usehunk, int *pLength)
{
char base[33];
if (!path || !path[0])
return NULL;

char base[MAX_PATH];
unsigned char *buf = NULL;

#ifndef SWDS
Expand All @@ -1982,8 +2046,10 @@ unsigned char* EXT_FUNC COM_LoadFile(const char *path, int usehunk, int *pLength
}

int len = FS_Size(hFile);
COM_FileBase(path, base);
base[32] = 0;
if (!COM_FileBase_s(path, base, sizeof(base)))
Sys_Error("%s: Bad path length: %s", __func__, path);

base[32] = '\0';

switch (usehunk)
{
Expand Down
3 changes: 3 additions & 0 deletions rehlds/engine/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ NOXREF char *COM_SkipPath(char *pathname);
void COM_StripExtension(char *in, char *out);
char *COM_FileExtension(char *in);
void COM_FileBase(const char *in, char *out);
const char *COM_FileBase_s(const char *in, char *out, int size);
void COM_DefaultExtension(char *path, char *extension);
void COM_UngetToken(void);
char *COM_Parse(char *data);
Expand All @@ -186,6 +187,8 @@ void COM_CreatePath(char *path);
NOXREF void COM_CopyFile(char *netpath, char *cachepath);
NOXREF int COM_ExpandFilename(char *filename);
int COM_FileSize(const char *filename);
qboolean COM_IsAbsolutePath(const char *pStr);
qboolean COM_IsValidPath(const char *pszFilename);
unsigned char *COM_LoadFile(const char *path, int usehunk, int *pLength);
void COM_FreeFile(void *buffer);
void COM_CopyFileChunk(FileHandle_t dst, FileHandle_t src, int nSize);
Expand Down
49 changes: 47 additions & 2 deletions rehlds/engine/cvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
All cvar names are case insensitive! Values not.
*/

cvar_t *cvar_vars;
cvar_t *cvar_vars = NULL;
cvarhook_t *cvar_hooks = NULL;
char cvar_null_string[] = "";

void Cvar_Init(void)
Expand Down Expand Up @@ -319,15 +320,26 @@ void Cvar_DirectSet(struct cvar_s *var, const char *value)

void Cvar_Set(const char *var_name, const char *value)
{
cvar_t *var = Cvar_FindVar(var_name);
cvar_t *var;
cvarhook_t *pHook;

var = Cvar_FindVar(var_name);
if (!var)
{
Con_DPrintf("%s: variable \"%s\" not found\n", __func__, var_name);
return;
}

Cvar_DirectSet(var, value);

for (pHook = cvar_hooks; pHook; pHook = pHook->next)
{
if (pHook->cvar == var)
{
pHook->hook(var);
break;
}
}
}

void Cvar_SetValue(const char *var_name, float value)
Expand Down Expand Up @@ -730,3 +742,36 @@ void Cvar_CmdInit(void)
{
Cmd_AddCommand("cvarlist", Cmd_CvarList_f);
}

qboolean Cvar_HookVariable(const char *var_name, cvarhook_t *pHook)
{
cvar_t *cvar;

if (!pHook || !pHook->hook)
return FALSE;

if (pHook->cvar || pHook->next)
return FALSE;

cvar = Cvar_FindVar(var_name);
if (!cvar)
return FALSE;

cvarhook_t *pCur = cvar_hooks;
pHook->cvar = cvar;

if (pCur)
{
while (pCur->next)
pCur = pCur->next;

pCur->next = pHook;
}
else
{
// First in chain is null, assign pHook to it
cvar_hooks = pHook;
}

return TRUE;
}
Loading

0 comments on commit ecfe8bb

Please sign in to comment.