Fixed crash in message dispatcher after 'meta unload'.

Various cosmetic changes.
This commit is contained in:
jeefo 2019-09-14 23:13:55 +03:00
commit ff6c56aeac
37 changed files with 949 additions and 602 deletions

View file

@ -207,7 +207,7 @@ template <typename ...Args> inline void BotControl::msg (const char *fmt, Args .
return;
}
if (m_isFromConsole || strlen (result) > 48) {
if (m_isFromConsole || strlen (result) > 56) {
game.clientPrint (m_ent, result);
}
else {

View file

@ -13,14 +13,12 @@
#define CR_NAMESPACE_BEGIN namespace cr {
#define CR_NAMESPACE_END }
// undef base max
#if defined (max)
# undef max
#endif
// undef base min
#if defined (min)
# undef min
// disable microsoft deprecation warning
#if defined (_MSC_VER)
# if !defined (_CRT_SECURE_NO_DEPRECATE)
# define _CRT_SECURE_NO_DEPRECATE
# define _WINSOCK_DEPRECATED_NO_WARNINGS
# endif
#endif
#include <stdio.h>
@ -34,13 +32,13 @@ CR_NAMESPACE_BEGIN
// some useful type definitions
//
namespace types {
using int8 = signed char;
using int16 = signed short;
using int32 = signed int;
using uint8 = unsigned char;
using uint16 = unsigned short;
using uint32 = unsigned int;
using uint64 = unsigned long long;
using int8 = signed char;
using int16 = signed short;
using int32 = signed int;
using uint8 = unsigned char;
using uint16 = unsigned short;
using uint32 = unsigned int;
using uint64 = unsigned long long;
}
// make types available for our own use

View file

@ -19,7 +19,7 @@ CR_NAMESPACE_BEGIN
// template for hashing our string
template <typename K> struct StringHash {
uint32 operator () (const K &key) const {
char *str = const_cast <char *> (key.chars ());
auto str = const_cast <char *> (key.chars ());
uint32 hash = 0;
while (*str++) {
@ -68,6 +68,7 @@ namespace detail {
template <class K, class V, class H = StringHash <K>, size_t HashSize = 36> class Dictionary final : public DenyCopying {
private:
using DictBucket = detail::DictionaryBucket <K, V>;
using DictList = detail::DictionaryList;
public:
enum : size_t {
@ -75,7 +76,7 @@ public:
};
private:
Array <detail::DictionaryList *> m_table;
Array <DictList *> m_table;
Array <DictBucket> m_buckets;
H m_hasher;
@ -98,7 +99,7 @@ private:
size_t created = m_buckets.length ();
m_buckets.resize (created + 1);
auto allocated = alloc.allocate <detail::DictionaryList> ();
auto allocated = alloc.allocate <DictList> ();
allocated->index = created;
allocated->next = m_table[pos];
@ -163,7 +164,7 @@ public:
auto pos = hashed % m_table.length ();
auto *bucket = m_table[pos];
detail::DictionaryList *next = nullptr;
DictList *next = nullptr;
while (bucket != nullptr) {
if (m_buckets[bucket->index].hash == hashed) {

View file

@ -35,6 +35,10 @@ public:
public:
bool open (const String &file, const String &mode) {
if (*this) {
close ();
}
if ((m_handle = fopen (file.chars (), mode.chars ())) == nullptr) {
return false;
}

View file

@ -20,15 +20,25 @@ CR_NAMESPACE_BEGIN
class SimpleHook : DenyCopying {
private:
enum : uint32 {
CodeLength = 12
#if defined (CR_ARCH_X64)
CodeLength = 14
#else
CodeLength = 6
#endif
};
#if defined (CR_ARCH_X64)
using uint = uint64;
#else
using uint = uint32;
#endif
private:
bool m_patched;
uint32 m_pageSize;
uint32 m_origFunc;
uint32 m_hookFunc;
uint m_pageSize;
uint m_origFunc;
uint m_hookFunc;
uint8 m_origBytes[CodeLength] {};
uint8 m_hookBytes[CodeLength] {};
@ -43,11 +53,13 @@ private:
#else
m_pageSize = sysconf (_SC_PAGESIZE);
#endif
}
}
inline void *align (void *address) {
#if !defined (CR_WINDOWS)
void *align (void *address) {
return reinterpret_cast <void *> ((reinterpret_cast <long> (address) & ~(m_pageSize - 1)));
}
#endif
bool unprotect () {
auto orig = reinterpret_cast <void *> (m_origFunc);
@ -74,25 +86,36 @@ public:
public:
bool patch (void *address, void *replacement) {
if (plat.isArm) {
const uint16 jmp = 0x25ff;
if (plat.arm) {
return false;
}
uint8 *ptr = reinterpret_cast <uint8 *> (address);
auto ptr = reinterpret_cast <uint8 *> (address);
while (*reinterpret_cast <uint16 *> (ptr) == 0x25ff) {
ptr = **reinterpret_cast <uint8 * **> ((ptr + 2));
while (*reinterpret_cast <uint16 *> (ptr) == jmp) {
ptr = **reinterpret_cast <uint8 * **> (ptr + 2);
}
m_origFunc = reinterpret_cast <uint32> (ptr);
m_origFunc = reinterpret_cast <uint> (address);
if (!m_origFunc) {
return false;
}
m_hookFunc = reinterpret_cast <uint32> (replacement);
m_hookFunc = reinterpret_cast <uint> (replacement);
m_hookBytes[0] = 0x68;
m_hookBytes[5] = 0xc3;
if (plat.x64) {
const uint16 nop = 0x00000000;
*reinterpret_cast <uint32 *> (&m_hookBytes[1]) = m_hookFunc;
memcpy (&m_hookBytes[0], &jmp, sizeof (uint16));
memcpy (&m_hookBytes[2], &nop, sizeof (uint16));
memcpy (&m_hookBytes[6], &replacement, sizeof (uint));
}
else {
m_hookBytes[0] = 0x68;
m_hookBytes[5] = 0xc3;
memcpy (&m_hookBytes[1], &m_hookFunc, sizeof (uint));
}
if (unprotect ()) {
memcpy (m_origBytes, reinterpret_cast <void *> (m_origFunc), CodeLength);
@ -130,6 +153,6 @@ public:
bool enabled () const {
return m_patched;
}
};
};
CR_NAMESPACE_END

View file

@ -374,19 +374,19 @@ public:
if (boundarySlash != String::InvalidIndex) {
boundaryName = localPath.substr (boundarySlash + 1);
}
const String &kBoundary = "---crlib_upload_boundary_1337";
const String &boundaryLine = "---crlib_upload_boundary_1337";
String request, start, end;
start.appendf ("--%s\r\n", kBoundary.chars ());
start.appendf ("--%s\r\n", boundaryLine.chars ());
start.appendf ("Content-Disposition: form-data; name='file'; filename='%s'\r\n", boundaryName.chars ());
start.append ("Content-Type: application/octet-stream\r\n\r\n");
end.appendf ("\r\n--%s--\r\n\r\n", kBoundary.chars ());
end.appendf ("\r\n--%s--\r\n\r\n", boundaryLine.chars ());
request.appendf ("POST /%s HTTP/1.1\r\n", uri.path.chars ());
request.appendf ("Host: %s\r\n", uri.host.chars ());
request.appendf ("User-Agent: %s\r\n", m_userAgent.chars ());
request.appendf ("Content-Type: multipart/form-data; boundary=%s\r\n", kBoundary.chars ());
request.appendf ("Content-Type: multipart/form-data; boundary=%s\r\n", boundaryLine.chars ());
request.appendf ("Content-Length: %d\r\n\r\n", file.length () + start.length () + end.length ());
// send the main request

View file

@ -67,7 +67,7 @@ private:
}
UniquePtr <LambdaFunctorWrapper> clone () const override {
return createUniqueBase <LambdaFunctor <T>, LambdaFunctorWrapper> (m_callable);
return makeUnique <LambdaFunctor <T>> (m_callable);
}
};
@ -93,7 +93,7 @@ private:
}
public:
Lambda () noexcept : Lambda (nullptr)
explicit Lambda () noexcept : Lambda (nullptr)
{ }
Lambda (decltype (nullptr)) noexcept : m_functor (nullptr), m_smallObject (false)
@ -124,7 +124,7 @@ public:
template <typename F> Lambda (F function) {
if (cr::fix (sizeof (function) > LamdaSmallBufferLength)) {
m_smallObject = false;
new (m_small) UniquePtr <LambdaFunctorWrapper> (createUniqueBase <LambdaFunctor <F>, LambdaFunctorWrapper> (cr::move (function)));
new (m_small) UniquePtr <LambdaFunctorWrapper> (makeUnique <LambdaFunctor <F>> (cr::move (function)));
}
else {
m_smallObject = true;

View file

@ -18,12 +18,8 @@
# include <fcntl.h>
# include <sys/stat.h>
# include <unistd.h>
#elif defined (CR_WINDOWS)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
CR_NAMESPACE_BEGIN
// handling dynamic library loading
@ -47,6 +43,10 @@ public:
public:
bool load (const String &file) noexcept {
if (*this) {
unload ();
}
#if defined (CR_WINDOWS)
m_handle = LoadLibraryA (file.chars ());
#else

View file

@ -14,11 +14,6 @@
#include <crlib/cr-files.h>
#include <crlib/cr-lambda.h>
#if defined (CR_WINDOWS)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
CR_NAMESPACE_BEGIN
class SimpleLogger final : public Singleton <SimpleLogger> {

View file

@ -70,6 +70,15 @@ CR_NAMESPACE_END
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <direct.h>
# if defined (max)
# undef max
# endif
# if defined (min)
# undef min
# endif
#else
# include <unistd.h>
# include <strings.h>
@ -77,8 +86,10 @@ CR_NAMESPACE_END
# include <sys/time.h>
#endif
#include <stdio.h>
#include <assert.h>
#include <locale.h>
#include <stdarg.h>
#if defined (CR_ANDROID)
# include <android/log.h>
@ -88,42 +99,42 @@ CR_NAMESPACE_BEGIN
// helper struct for platform detection
struct Platform : public Singleton <Platform> {
bool isWindows = false;
bool isLinux = false;
bool isOSX = false;
bool isAndroid = false;
bool isAndroidHardFP = false;
bool isX64 = false;
bool isArm = false;
bool win32 = false;
bool linux = false;
bool osx = false;
bool android = false;
bool hfp = false;
bool x64 = false;
bool arm = false;
Platform () {
#if defined(CR_WINDOWS)
isWindows = true;
win32 = true;
#endif
#if defined(CR_ANDROID)
isAndroid = true;
android = true;
# if defined (CR_ANDROID_HARD_FP)
isAndroidHardFP = true;
hfp = true;
# endif
#endif
#if defined(CR_LINUX)
isLinux = true;
linux = true;
#endif
#if defined(CR_OSX)
isOSX = true;
osx = true;
#endif
#if defined(CR_ARCH_X64) || defined(CR_ARCH_ARM64)
isX64 = true;
x64 = true;
#endif
#if defined(CR_ARCH_ARM)
isArm = true;
isAndroid = true;
arm = true;
android = true;
#endif
}

View file

@ -20,6 +20,38 @@
CR_NAMESPACE_BEGIN
namespace detail {
template <typename T> uint8 &getMostSignificantByte (T &object) {
return *(reinterpret_cast <uint8 *> (&object) + sizeof (object) - 1);
}
template <size_t N> bool getLeastSignificantBit (uint8 byte) {
return byte & cr::bit (N);
}
template <size_t N> bool getMostSignificantBit (uint8 byte) {
return byte & cr::bit (CHAR_BIT - N - 1);
}
template <size_t N> void setLeastSignificantBit (uint8 &byte, bool bit) {
if (bit) {
byte |= cr::bit (N);
}
else {
byte &= ~cr::bit (N);
}
}
template <size_t N> void setMostSignificantBit (uint8 &byte, bool bit) {
if (bit) {
byte |= cr::bit (CHAR_BIT - N - 1);
}
else {
byte &= ~cr::bit (CHAR_BIT - N - 1);
}
}
}
// small-string optimized string class, sso stuff based on: https://github.com/elliotgoodrich/SSO-23/
class String final {
public:
@ -30,7 +62,6 @@ public:
private:
enum : size_t {
ExcessSpace = 32,
CharBit = CHAR_BIT
};
private:
@ -77,8 +108,7 @@ public:
assign (ch);
}
String (String &&rhs) noexcept {
m_data = rhs.m_data;
String (String &&rhs) noexcept : m_data (rhs.m_data) {
rhs.setMoved ();
}
@ -87,35 +117,6 @@ public:
}
private:
template <typename T> static uint8 &getMostSignificantByte (T &object) {
return *(reinterpret_cast <uint8 *> (&object) + sizeof (object) - 1);
}
template <size_t N> static bool getLeastSignificantBit (uint8 byte) {
return byte & cr::bit (N);
}
template <size_t N> static bool getMostSignificantBit (uint8 byte) {
return byte & cr::bit (CharBit - N - 1);
}
template <size_t N> static void setLeastSignificantBit (uint8 &byte, bool bit) {
if (bit) {
byte |= cr::bit (N);
}
else {
byte &= ~cr::bit (N);
}
}
template <size_t N> static void setMostSignificantBit (uint8 &byte, bool bit) {
if (bit) {
byte |= cr::bit (CharBit - N - 1);
}
else {
byte &= ~cr::bit (CharBit - N - 1);
}
}
void destroy () {
if (!isSmall ()) {
@ -162,7 +163,7 @@ private:
}
bool isSmall () const {
return !getLeastSignificantBit <0> (m_data.small.length) && !getLeastSignificantBit <1> (m_data.small.length);
return !detail::getLeastSignificantBit <0> (m_data.small.length) && !detail::getLeastSignificantBit <1> (m_data.small.length);
}
void setSmallLength (uint8 length) {
@ -174,18 +175,18 @@ private:
}
void setDataNonSmall (size_t length, size_t capacity) {
uint8 &lengthHighByte = getMostSignificantByte (length);
uint8 &capacityHighByte = getMostSignificantByte (capacity);
uint8 &lengthHighByte = detail::getMostSignificantByte (length);
uint8 &capacityHighByte = detail::getMostSignificantByte (capacity);
const bool lengthHasHighBit = getMostSignificantBit <0> (lengthHighByte);
const bool capacityHasHighBit = getMostSignificantBit <0> (capacityHighByte);
const bool capacityHasSecHighBit = getMostSignificantBit <1> (capacityHighByte);
const bool lengthHasHighBit = detail::getMostSignificantBit <0> (lengthHighByte);
const bool capacityHasHighBit = detail::getMostSignificantBit <0> (capacityHighByte);
const bool capacityHasSecHighBit = detail::getMostSignificantBit <1> (capacityHighByte);
setMostSignificantBit <0> (lengthHighByte, capacityHasSecHighBit);
detail::setMostSignificantBit <0> (lengthHighByte, capacityHasSecHighBit);
capacityHighByte <<= 2;
setLeastSignificantBit <0> (capacityHighByte, capacityHasHighBit);
setLeastSignificantBit <1> (capacityHighByte, !lengthHasHighBit);
detail::setLeastSignificantBit <0> (capacityHighByte, capacityHasHighBit);
detail::setLeastSignificantBit <1> (capacityHighByte, !lengthHasHighBit);
m_data.big.length = length;
m_data.big.capacity = capacity;
@ -195,18 +196,18 @@ private:
size_t length = m_data.big.length;
size_t capacity = m_data.big.capacity;
uint8 &lengthHighByte = getMostSignificantByte (length);
uint8 &capacityHighByte = getMostSignificantByte (capacity);
uint8 &lengthHighByte = detail::getMostSignificantByte (length);
uint8 &capacityHighByte = detail::getMostSignificantByte (capacity);
const bool capacityHasHighBit = getLeastSignificantBit <0> (capacityHighByte);
const bool lengthHasHighBit = !getLeastSignificantBit <1> (capacityHighByte);
const bool capacityHasSecHighBit = getMostSignificantBit <0> (lengthHighByte);
const bool capacityHasHighBit = detail::getLeastSignificantBit <0> (capacityHighByte);
const bool lengthHasHighBit = !detail::getLeastSignificantBit <1> (capacityHighByte);
const bool capacityHasSecHighBit = detail::getMostSignificantBit <0> (lengthHighByte);
setMostSignificantBit <0> (lengthHighByte, lengthHasHighBit);
detail::setMostSignificantBit <0> (lengthHighByte, lengthHasHighBit);
capacityHighByte >>= 2;
setMostSignificantBit <0> (capacityHighByte, capacityHasHighBit);
setMostSignificantBit <1> (capacityHighByte, capacityHasSecHighBit);
detail::setMostSignificantBit <0> (capacityHighByte, capacityHasHighBit);
detail::setMostSignificantBit <1> (capacityHighByte, capacityHasSecHighBit);
return { length, capacity };
}

View file

@ -15,7 +15,7 @@
CR_NAMESPACE_BEGIN
// simple pair (twin)
template <typename A, typename B> class Twin {
template <typename A, typename B> class Twin final {
public:
A first;
B second;
@ -55,13 +55,4 @@ public:
}
};
// creating pairs
template <typename A, typename B> constexpr Twin <A, B> makeTwin (A &&a, B &&b) {
return Twin <A, B> (cr::forward <A> (a), cr::forward <B> (b));
}
template <typename A, typename B> constexpr Twin <A, B> makeTwin (const A &a, const B &b) {
return Twin <A, B> (a, b);
}
CR_NAMESPACE_END

View file

@ -41,10 +41,11 @@ private:
SmallArray <int32> m_prevTable;
public:
ULZ () {
explicit ULZ () {
m_hashTable.resize (HashLength);
m_prevTable.resize (WindowSize);
}
~ULZ () = default;
public:

View file

@ -21,12 +21,15 @@ private:
public:
UniquePtr () = default;
explicit UniquePtr (T *ptr) : m_ptr (ptr)
{ }
UniquePtr (UniquePtr &&rhs) noexcept : m_ptr (rhs.m_ptr) {
rhs.m_ptr = nullptr;
}
UniquePtr (UniquePtr &&rhs) noexcept : m_ptr (rhs.release ())
{ }
template <typename U> UniquePtr (UniquePtr <U> &&rhs) noexcept : m_ptr (rhs.release ())
{ }
~UniquePtr () {
destroy ();
@ -60,10 +63,14 @@ private:
public:
UniquePtr &operator = (UniquePtr &&rhs) noexcept {
if (this != &rhs) {
destroy ();
reset (rhs.release ());
}
return *this;
}
m_ptr = rhs.m_ptr;
rhs.m_ptr = nullptr;
template <typename U> UniquePtr &operator = (UniquePtr <U> &&rhs) noexcept {
if (this != &rhs) {
reset (rhs.release ());
}
return *this;
}
@ -87,13 +94,8 @@ public:
};
// create unique
template <typename T, typename... Args> UniquePtr <T> createUnique (Args &&... args) {
template <typename T, typename... Args> UniquePtr <T> makeUnique (Args &&... args) {
return UniquePtr <T> (alloc.create <T> (cr::forward <Args> (args)...));
}
// create unique (base class)
template <typename D, typename B, typename... Args> UniquePtr <B> createUniqueBase (Args &&... args) {
return UniquePtr <B> (alloc.create <D> (cr::forward <Args> (args)...));
}
CR_NAMESPACE_END

View file

@ -65,7 +65,7 @@ CR_DECLARE_SCOPED_ENUM (MapFlags,
CR_DECLARE_SCOPED_ENUM (EntitySearchResult,
Continue,
Break
);
)
// variable reg pair
struct VarPair {
@ -82,6 +82,31 @@ struct VarPair {
// entity prototype
using EntityFunction = void (*) (entvars_t *);
// rehlds has this fixed, but original hlds doesn't allocate string space passed to precache* argument, so game will crash when unloading module using metamod
class EngineWrap final : public DenyCopying {
public:
EngineWrap () = default;
~EngineWrap () = default;
private:
const char *allocStr (const char *str) const {
return STRING (engfuncs.pfnAllocString (str));
}
public:
int32 precacheModel (const char *model) const {
return engfuncs.pfnPrecacheModel (allocStr (model));
}
int32 precacheSound (const char *sound) const {
return engfuncs.pfnPrecacheSound (allocStr (sound));
}
void setModel (edict_t *ent, const char *model) {
engfuncs.pfnSetModel (ent, allocStr (model));
}
};
// provides utility functions to not call original engine (less call-cost)
class Game final : public Singleton <Game> {
public:
@ -101,6 +126,7 @@ private:
Array <edict_t *> m_breakables;
SmallArray <VarPair> m_cvars;
SharedLibrary m_gameLib;
EngineWrap m_engineWrap;
bool m_precached;
int m_gameFlags;
@ -621,7 +647,7 @@ public:
public:
void initialize () {
if (plat.isArm) {
if (plat.arm) {
return;
}
m_dlsym.patch (reinterpret_cast <void *> (&LookupSymbol), reinterpret_cast <void *> (&DynamicEntityLink::replacement));

View file

@ -19,6 +19,24 @@
// This header file included by engine files and DLL files.
// Most came from server.h
#define INTERFACE_VERSION 140
// Dot products for view cone checking
#define VIEW_FIELD_FULL (float)-1.0 // +-180 degrees
#define VIEW_FIELD_WIDE (float)-0.7 // +-135 degrees 0.1 // +-85 degrees, used for full FOV checks
#define VIEW_FIELD_NARROW (float)0.7 // +-45 degrees, more narrow check used to set up ranged attacks
#define VIEW_FIELD_ULTRA_NARROW (float)0.9 // +-25 degrees, more narrow check used to set up ranged attacks
#define FCVAR_ARCHIVE (1 << 0) // set to cause it to be saved to vars.rc
#define FCVAR_USERINFO (1 << 1) // changes the client's info string
#define FCVAR_SERVER (1 << 2) // notifies players when changed
#define FCVAR_EXTDLL (1 << 3) // defined by external DLL
#define FCVAR_CLIENTDLL (1 << 4) // defined by the client dll
#define FCVAR_PROTECTED (1 << 5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value
#define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server.
#define FCVAR_PRINTABLEONLY (1 << 7) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
#define FCVAR_UNLOGGED (1 << 8) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
// edict->flags
#define FL_FLY (1 << 0) // Changes the SV_Movestep() behavior to not need to be on ground
#define FL_SWIM (1 << 1) // Changes the SV_Movestep() behavior to not need to be on ground (but stay in water)
@ -667,6 +685,122 @@
#define TE_BOUNCE_SHELL 1
#define TE_BOUNCE_SHOTSHELL 2
#define MAX_ENT_LEAFS 48
#define MAX_WEAPON_SLOTS 5 // hud item selection slots
#define MAX_ITEM_TYPES 6 // hud item selection slots
#define MAX_ITEMS 5 // hard coded item types
#define HIDEHUD_WEAPONS (1 << 0)
#define HIDEHUD_FLASHLIGHT (1 << 1)
#define HIDEHUD_ALL (1 << 2)
#define HIDEHUD_HEALTH (1 << 3)
#define MAX_AMMO_TYPES 32 // ???
#define MAX_AMMO_SLOTS 32 // not really slots
#define HUD_PRINTNOTIFY 1
#define HUD_PRINTCONSOLE 2
#define HUD_PRINTTALK 3
#define HUD_PRINTCENTER 4
#define WEAPON_SUIT 31
#define VERTEXSIZE 7
#define MAXLIGHTMAPS 4
#define NUM_AMBIENTS 4
#define MAX_MAP_HULLS 4
#define MAX_PHYSINFO_STRING 256
#define MAX_PHYSENTS 600
#define MAX_MOVEENTS 64
#define MAX_LIGHTSTYLES 64
#define MAX_LIGHTSTYLEVALUE 256
#define SURF_DRAWTILED 0x20
#define AMBIENT_SOUND_STATIC 0 // medium radius attenuation
#define AMBIENT_SOUND_EVERYWHERE 1
#define AMBIENT_SOUND_SMALLRADIUS 2
#define AMBIENT_SOUND_MEDIUMRADIUS 4
#define AMBIENT_SOUND_LARGERADIUS 8
#define AMBIENT_SOUND_START_SILENT 16
#define AMBIENT_SOUND_NOT_LOOPING 32
#define SPEAKER_START_SILENT 1 // wait for trigger 'on' to start announcements
#define SND_SPAWNING (1 << 8) // duplicated in protocol.h we're spawing, used in some cases for ambients
#define SND_STOP (1 << 5) // duplicated in protocol.h stop sound
#define SND_CHANGE_VOL (1 << 6) // duplicated in protocol.h change sound vol
#define SND_CHANGE_PITCH (1 << 7) // duplicated in protocol.h change sound pitch
#define LFO_SQUARE 1
#define LFO_TRIANGLE 2
#define LFO_RANDOM 3
// func_rotating
#define SF_BRUSH_ROTATE_Y_AXIS 0
#define SF_BRUSH_ROTATE_INSTANT 1
#define SF_BRUSH_ROTATE_BACKWARDS 2
#define SF_BRUSH_ROTATE_Z_AXIS 4
#define SF_BRUSH_ROTATE_X_AXIS 8
#define SF_PENDULUM_AUTO_RETURN 16
#define SF_PENDULUM_PASSABLE 32
#define SF_BRUSH_ROTATE_SMALLRADIUS 128
#define SF_BRUSH_ROTATE_MEDIUMRADIUS 256
#define SF_BRUSH_ROTATE_LARGERADIUS 512
#define PUSH_BLOCK_ONLY_X 1
#define PUSH_BLOCK_ONLY_Y 2
#define VEC_HULL_MIN Vector(-16, -16, -36)
#define VEC_HULL_MAX Vector(16, 16, 36)
#define VEC_HUMAN_HULL_MIN Vector(-16, -16, 0)
#define VEC_HUMAN_HULL_MAX Vector(16, 16, 72)
#define VEC_HUMAN_HULL_DUCK Vector(16, 16, 36)
#define VEC_VIEW Vector(0, 0, 28)
#define VEC_DUCK_HULL_MIN Vector(-16, -16, -18)
#define VEC_DUCK_HULL_MAX Vector(16, 16, 18)
#define VEC_DUCK_VIEW Vector(0, 0, 12)
#define SVC_TEMPENTITY 23
#define SVC_CENTERPRINT 26
#define SVC_INTERMISSION 30
#define SVC_CDTRACK 32
#define SVC_WEAPONANIM 35
#define SVC_ROOMTYPE 37
#define SVC_DIRECTOR 51
// triggers
#define SF_TRIGGER_ALLOWMONSTERS 1 // monsters allowed to fire this trigger
#define SF_TRIGGER_NOCLIENTS 2 // players not allowed to fire this trigger
#define SF_TRIGGER_PUSHABLES 4 // only pushables can fire this trigger
// func breakable
#define SF_BREAK_TRIGGER_ONLY 1 // may only be broken by trigger
#define SF_BREAK_TOUCH 2 // can be 'crashed through' by running player (plate glass)
#define SF_BREAK_PRESSURE 4 // can be broken by a player standing on it
#define SF_BREAK_CROWBAR 256 // instant break if hit with crowbar
// func_pushable (it's also func_breakable, so don't collide with those flags)
#define SF_PUSH_BREAKABLE 128
#define SF_LIGHT_START_OFF 1
#define SPAWNFLAG_NOMESSAGE 1
#define SPAWNFLAG_NOTOUCH 1
#define SPAWNFLAG_DROIDONLY 4
#define SPAWNFLAG_USEONLY 1 // can't be touched, must be used (buttons)
#define TELE_PLAYER_ONLY 1
#define TELE_SILENT 2
#define SF_TRIG_PUSH_ONCE 1
// Rendering constants
enum {
kRenderNormal, // src
@ -701,29 +835,46 @@ enum {
kRenderFxClampMinScale // Keep this sprite from getting very small (SPRITES only!)
};
typedef int func_t;
typedef int string_t;
typedef enum {
ignore_monsters = 1,
dont_ignore_monsters = 0,
missile = 2
} IGNORE_MONSTERS;
typedef struct link_s {
struct link_s *prev, *next;
} link_t;
typedef enum {
ignore_glass = 1,
dont_ignore_glass = 0
} IGNORE_GLASS;
typedef struct edict_s edict_t;
typedef enum {
point_hull = 0,
human_hull = 1,
large_hull = 2,
head_hull = 3
} HULL;
typedef struct {
vec3_t normal;
float dist;
} plane_t;
typedef enum {
at_notice,
at_console, // same as at_notice, but forces a ConPrintf, not a message box
at_aiconsole, // same as at_console, but only shown if developer level is 2!
at_warning,
at_error,
at_logged // Server print to console ( only in multiplayer games ).
} ALERT_TYPE;
// 4-22-98 JOHN: added for use in pfnClientPrintf
typedef enum {
print_console,
print_center,
print_chat
} PRINT_TYPE;
// For integrity checking of content on clients
typedef enum {
force_exactfile, // File on client must exactly match server's file
force_model_samebounds, // For model files only, the geometry must fit in the same bbox
force_model_specifybounds // For model files only, the geometry must fit in the specified bbox
} FORCE_TYPE;
typedef struct {
int allsolid; // if true, plane is not valid
int startsolid; // if true, the initial point was in a solid area
int inopen, inwater;
float fraction; // time completed, 1.0 = didn't hit anything
vec3_t endpos; // final position
plane_t plane; // surface normal at impact
edict_t *ent; // entity the surface is on
int hitgroup; // 0 == generic, non zero is specific body part
} trace_t;
#endif

View file

@ -12,22 +12,7 @@
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
#ifndef EIFACE_H
#define EIFACE_H
#define INTERFACE_VERSION 140
#include <stdio.h>
#define FCVAR_ARCHIVE (1 << 0) // set to cause it to be saved to vars.rc
#define FCVAR_USERINFO (1 << 1) // changes the client's info string
#define FCVAR_SERVER (1 << 2) // notifies players when changed
#define FCVAR_EXTDLL (1 << 3) // defined by external DLL
#define FCVAR_CLIENTDLL (1 << 4) // defined by the client dll
#define FCVAR_PROTECTED (1 << 5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value
#define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server.
#define FCVAR_PRINTABLEONLY (1 << 7) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
#define FCVAR_UNLOGGED (1 << 8) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
#pragma once
struct cvar_t {
char *name;
@ -37,39 +22,18 @@ struct cvar_t {
cvar_t *next;
};
//
// Defines entity interface between engine and DLLs.
// This header file included by engine files and DLL files.
//
// Before including this header, DLLs must:
// include progdefs.h
// This is conveniently done for them in extdll.h
//
#ifdef _WIN32
#define DLLEXPORT __stdcall
#else
#define DLLEXPORT /* */
#endif
typedef enum {
at_notice,
at_console, // same as at_notice, but forces a ConPrintf, not a message box
at_aiconsole, // same as at_console, but only shown if developer level is 2!
at_warning,
at_error,
at_logged // Server print to console ( only in multiplayer games ).
} ALERT_TYPE;
// 4-22-98 JOHN: added for use in pfnClientPrintf
typedef enum { print_console, print_center, print_chat } PRINT_TYPE;
// For integrity checking of content on clients
typedef enum {
force_exactfile, // File on client must exactly match server's file
force_model_samebounds, // For model files only, the geometry must fit in the same bbox
force_model_specifybounds // For model files only, the geometry must fit in the specified bbox
} FORCE_TYPE;
typedef struct hudtextparms_s {
float x;
float y;
int effect;
uint8 r1, g1, b1, a1;
uint8 r2, g2, b2, a2;
float fadeinTime;
float fadeoutTime;
float holdTime;
float fxTime;
int channel;
} hudtextparms_t;
// Returned by TraceLine
typedef struct {
@ -109,8 +73,8 @@ typedef uint32 CRC32_t;
// Engine hands this to DLLs for functionality callbacks
typedef struct enginefuncs_s {
int (*pfnPrecacheModel) (char *s);
int (*pfnPrecacheSound) (char *s);
int (*pfnPrecacheModel) (const char *s);
int (*pfnPrecacheSound) (const char *s);
void (*pfnSetModel) (edict_t *e, const char *m);
int (*pfnModelIndex) (const char *m);
int (*pfnModelFrames) (int modelIndex);
@ -375,9 +339,6 @@ typedef struct {
int (*pfnAllowLagCompensation) ();
} gamefuncs_t;
// Current version.
#define NEWGAMEDLLFUNCS_VERSION 1
typedef struct {
// Called right before the object's memory is freed.
// Calls its destructor.
@ -388,5 +349,3 @@ typedef struct {
void (*pfnCvarValue) (const edict_t *pEnt, const char *value);
void (*pfnCvarValue2) (const edict_t *pEnt, int requestID, const char *cvarName, const char *value);
} newgamefuncs_t;
#endif /* EIFACE_H */

View file

@ -16,54 +16,58 @@
#ifndef EXTDLL_H
#define EXTDLL_H
#ifdef _MSC_VER
/* disable deprecation warnings concerning unsafe CRT functions */
#if !defined _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#endif
#endif
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOWINRES
#define NOSERVICE
#define NOMCX
#define NOIME
#include "windows.h"
#include "winsock2.h"
#else // _WIN32
#define FALSE 0
#define TRUE (!FALSE)
#define MAX_PATH PATH_MAX
#include <limits.h>
#include <stdarg.h>
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define _vsnprintf(a, b, c, d) vsnprintf (a, b, c, d)
#endif
#endif //_WIN32
#include "stdio.h"
#include "stdlib.h"
typedef int func_t; //
typedef int string_t; // from engine's pr_comp.h;
typedef float vec_t; // needed before including progdefs.h
typedef vec_t vec2_t[2];
typedef vec_t vec4_t[4];
typedef int qboolean;
typedef unsigned char byte;
#include <crlib/cr-vector.h>
// idea from regamedll
class string_t final {
private:
int offset;
public:
explicit string_t () : offset (0) { }
string_t (int offset) : offset (offset) { }
~string_t () = default;
public:
const char *chars () const;
public:
operator int () const {
return offset;
}
string_t &operator = (const string_t &rhs) {
offset = rhs.offset;
return *this;
}
};
typedef cr::Vector vec3_t;
using namespace cr::types;
typedef struct edict_s edict_t;
#include "const.h"
#include "progdefs.h"
#include "model.h"
#define MAX_ENT_LEAFS 48
typedef struct link_s {
struct link_s *prev, *next;
} link_t;
typedef struct {
vec3_t normal;
float dist;
} plane_t;
struct edict_s {
int free;
@ -79,24 +83,29 @@ struct edict_s {
#include "eiface.h"
#define MAX_WEAPON_SLOTS 5 // hud item selection slots
#define MAX_ITEM_TYPES 6 // hud item selection slots
extern globalvars_t *globals;
extern enginefuncs_t engfuncs;
extern gamefuncs_t dllapi;
#define MAX_ITEMS 5 // hard coded item types
// Use this instead of ALLOC_STRING on constant strings
#define STRING(offset) (const char *)(globals->pStringBase + (int)offset)
#define HIDEHUD_WEAPONS (1 << 0)
#define HIDEHUD_FLASHLIGHT (1 << 1)
#define HIDEHUD_ALL (1 << 2)
#define HIDEHUD_HEALTH (1 << 3)
// form fwgs-hlsdk
#if defined (CR_ARCH_X64)
static inline int MAKE_STRING (const char *val) {
long long ptrdiff = val - STRING (0);
#define MAX_AMMO_TYPES 32 // ???
#define MAX_AMMO_SLOTS 32 // not really slots
if (ptrdiff > INT_MAX || ptrdiff < INT_MIN) {
return engfuncs.pfnAllocString (val);
}
return static_cast <int> (ptrdiff);
}
#else
#define MAKE_STRING(str) ((uint64)(str) - (uint64)(STRING(0)))
#endif
#define HUD_PRINTNOTIFY 1
#define HUD_PRINTCONSOLE 2
#define HUD_PRINTTALK 3
#define HUD_PRINTCENTER 4
#define WEAPON_SUIT 31
inline const char *string_t::chars () const {
return STRING (offset);
}
#endif // EXTDLL_H

203
include/engine/metamod.h Normal file
View file

@ -0,0 +1,203 @@
/*
* Copyright (c) 2001-2006 Will Day <willday@hpgx.net>
* See the file "dllapi.h" in this folder for full information
*/
// Simplified version by Wei Mingzhi
#ifndef METAMOD_H
#define METAMOD_H
typedef enum {
PNL_NULL = 0,
PNL_INI_DELETED,
PNL_FILE_NEWER,
PNL_COMMAND,
PNL_CMD_FORCED,
PNL_DELAYED,
PNL_PLUGIN,
PNL_PLG_FORCED,
PNL_RELOAD
} PL_UNLOAD_REASON;
typedef enum {
MRES_UNSET = 0,
MRES_IGNORED,
MRES_HANDLED,
MRES_OVERRIDE,
MRES_SUPERCEDE
} META_RES;
typedef enum {
PT_NEVER = 0,
PT_STARTUP,
PT_CHANGELEVEL,
PT_ANYTIME,
PT_ANYPAUSE
} PLUG_LOADTIME;
// for getgameinfo:
typedef enum {
GINFO_NAME = 0,
GINFO_DESC,
GINFO_GAMEDIR,
GINFO_DLL_FULLPATH,
GINFO_DLL_FILENAME,
GINFO_REALDLL_FULLPATH
} ginfo_t;
typedef int (*GETENTITYAPI_FN) (gamefuncs_t *pFunctionTable, int interfaceVersion);
typedef int (*GETENTITYAPI2_FN) (gamefuncs_t *pFunctionTable, int *interfaceVersion);
typedef int (*GETNEWDLLFUNCTIONS_FN) (newgamefuncs_t *pFunctionTable, int *interfaceVersion);
typedef int (*GET_ENGINE_FUNCTIONS_FN) (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
#define META_INTERFACE_VERSION "5:13"
typedef struct {
char const *ifvers;
char const *name;
char const *version;
char const *date;
char const *author;
char const *url;
char const *logtag;
PLUG_LOADTIME loadable;
PLUG_LOADTIME unloadable;
} plugin_info_t;
extern plugin_info_t Plugin_info;
typedef plugin_info_t *plid_t;
#define PLID &Plugin_info
typedef struct meta_globals_s {
META_RES mres;
META_RES prev_mres;
META_RES status;
void *orig_ret;
void *override_ret;
} meta_globals_t;
extern meta_globals_t *gpMetaGlobals;
#define RETURN_META(result) \
{ \
gpMetaGlobals->mres = result; \
return; \
}
#define RETURN_META_VALUE(result, value) \
{ \
gpMetaGlobals->mres = result; \
return (value); \
}
#define META_RESULT_STATUS gpMetaGlobals->status
#define META_RESULT_PREVIOUS gpMetaGlobals->prev_mres
#define META_RESULT_ORIG_RET(type) *(type *)gpMetaGlobals->orig_ret
#define META_RESULT_OVERRIDE_RET(type) *(type *)gpMetaGlobals->override_ret
typedef struct {
GETENTITYAPI_FN pfnGetEntityAPI;
GETENTITYAPI_FN pfnGetEntityAPI_Post;
GETENTITYAPI2_FN pfnGetEntityAPI2;
GETENTITYAPI2_FN pfnGetEntityAPI2_Post;
GETNEWDLLFUNCTIONS_FN pfnGetNewDLLFunctions;
GETNEWDLLFUNCTIONS_FN pfnGetNewDLLFunctions_Post;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions_Post;
} metamod_funcs_t;
// max buffer size for printed messages
#define MAX_LOGMSG_LEN 1024
// Meta Utility Function table type.
typedef struct meta_util_funcs_s {
void (*pfnLogConsole) (plid_t plid, const char *szFormat, ...);
void (*pfnLogMessage) (plid_t plid, const char *szFormat, ...);
void (*pfnLogError) (plid_t plid, const char *szFormat, ...);
void (*pfnLogDeveloper) (plid_t plid, const char *szFormat, ...);
void (*pfnCenterSay) (plid_t plid, const char *szFormat, ...);
void (*pfnCenterSayParms) (plid_t plid, hudtextparms_t tparms, const char *szFormat, ...);
void (*pfnCenterSayVarargs) (plid_t plid, hudtextparms_t tparms, const char *szFormat, va_list ap);
int (*pfnCallGameEntity) (plid_t plid, const char *entStr, entvars_t *pev);
int (*pfnGetUserMsgID) (plid_t plid, const char *msgname, int *size);
const char *(*pfnGetUserMsgName) (plid_t plid, int msgid, int *size);
const char *(*pfnGetPluginPath) (plid_t plid);
const char *(*pfnGetGameInfo) (plid_t plid, ginfo_t tag);
int (*pfnLoadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, void **plugin_handle);
int (*pfnUnloadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
int (*pfnUnloadPluginByHandle) (plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
const char *(*pfnIsQueryingClienCVar_t) (plid_t plid, const edict_t *player);
int (*pfnMakeRequestID) (plid_t plid);
void (*pfnGetHookTables) (plid_t plid, enginefuncs_t **peng, gamefuncs_t **pdll, newgamefuncs_t **pnewdll);
} mutil_funcs_t;
typedef struct {
gamefuncs_t *dllapi_table;
newgamefuncs_t *newapi_table;
} gamedll_funcs_t;
extern gamedll_funcs_t *gpGamedllFuncs;
extern mutil_funcs_t *gpMetaUtilFuncs;
extern metamod_funcs_t gMetaFunctionTable;
#define MDLL_FUNC gpGamedllFuncs->dllapi_table
#define MDLL_GameDLLInit MDLL_FUNC->pfnGameInit
#define MDLL_Spawn MDLL_FUNC->pfnSpawn
#define MDLL_Think MDLL_FUNC->pfnThink
#define MDLL_Use MDLL_FUNC->pfnUse
#define MDLL_Touch MDLL_FUNC->pfnTouch
#define MDLL_Blocked MDLL_FUNC->pfnBlocked
#define MDLL_KeyValue MDLL_FUNC->pfnKeyValue
#define MDLL_Save MDLL_FUNC->pfnSave
#define MDLL_Restore MDLL_FUNC->pfnRestore
#define MDLL_ObjectCollsionBox MDLL_FUNC->pfnAbsBox
#define MDLL_SaveWriteFields MDLL_FUNC->pfnSaveWriteFields
#define MDLL_SaveReadFields MDLL_FUNC->pfnSaveReadFields
#define MDLL_SaveGlobalState MDLL_FUNC->pfnSaveGlobalState
#define MDLL_RestoreGlobalState MDLL_FUNC->pfnRestoreGlobalState
#define MDLL_ResetGlobalState MDLL_FUNC->pfnResetGlobalState
#define MDLL_ClientConnect MDLL_FUNC->pfnClientConnect
#define MDLL_ClientDisconnect MDLL_FUNC->pfnClientDisconnect
#define MDLL_ClientKill MDLL_FUNC->pfnClientKill
#define MDLL_ClientPutInServer MDLL_FUNC->pfnClientPutInServer
#define MDLL_ClientCommand MDLL_FUNC->pfnClientCommand
#define MDLL_ClientUserInfoChanged MDLL_FUNC->pfnClientUserInfoChanged
#define MDLL_ServerActivate MDLL_FUNC->pfnServerActivate
#define MDLL_ServerDeactivate MDLL_FUNC->pfnServerDeactivate
#define MDLL_PlayerPreThink MDLL_FUNC->pfnPlayerPreThink
#define MDLL_PlayerPostThink MDLL_FUNC->pfnPlayerPostThink
#define MDLL_StartFrame MDLL_FUNC->pfnStartFrame
#define MDLL_ParmsNewLevel MDLL_FUNC->pfnParmsNewLevel
#define MDLL_ParmsChangeLevel MDLL_FUNC->pfnParmsChangeLevel
#define MDLL_GetGameDescription MDLL_FUNC->pfnGetGameDescription
#define MDLL_PlayerCustomization MDLL_FUNC->pfnPlayerCustomization
#define MDLL_SpectatorConnect MDLL_FUNC->pfnSpectatorConnect
#define MDLL_SpectatorDisconnect MDLL_FUNC->pfnSpectatorDisconnect
#define MDLL_SpectatorThink MDLL_FUNC->pfnSpectatorThink
#define MDLL_Sys_Error MDLL_FUNC->pfnSys_Error
#define MDLL_PM_Move MDLL_FUNC->pfnPM_Move
#define MDLL_PM_Init MDLL_FUNC->pfnPM_Init
#define MDLL_PM_FindTextureType MDLL_FUNC->pfnPM_FindTextureType
#define MDLL_SetupVisibility MDLL_FUNC->pfnSetupVisibility
#define MDLL_UpdateClientData MDLL_FUNC->pfnUpdateClientData
#define MDLL_AddToFullPack MDLL_FUNC->pfnAddToFullPack
#define MDLL_CreateBaseline MDLL_FUNC->pfnCreateBaseline
#define MDLL_RegisterEncoders MDLL_FUNC->pfnRegisterEncoders
#define MDLL_GetWeaponData MDLL_FUNC->pfnGetWeaponData
#define MDLL_CmdStart MDLL_FUNC->pfnCmdStart
#define MDLL_CmdEnd MDLL_FUNC->pfnCmdEnd
#define MDLL_ConnectionlessPacket MDLL_FUNC->pfnConnectionlessPacket
#define MDLL_GetHullBounds MDLL_FUNC->pfnGetHullBounds
#define MDLL_CreateInstancedBaselines MDLL_FUNC->pfnCreateInstancedBaselines
#define MDLL_InconsistentFile MDLL_FUNC->pfnInconsistentFile
#define MDLL_AllowLagCompensation MDLL_FUNC->pfnAllowLagCompensation
#define CALL_GAME_ENTITY (*gpMetaUtilFuncs->pfnCallGameEntity)
#define GET_USER_MSG_ID (*gpMetaUtilFuncs->pfnGetUserMsgID)
#endif

View file

@ -18,23 +18,6 @@
#ifndef MODEL_H
#define MODEL_H
typedef vec_t vec2_t[2];
typedef vec_t vec4_t[4];
typedef int qboolean;
typedef unsigned char byte;
#define VERTEXSIZE 7
#define MAXLIGHTMAPS 4
#define NUM_AMBIENTS 4
#define MAX_MAP_HULLS 4
#define MAX_PHYSINFO_STRING 256
#define MAX_PHYSENTS 600
#define MAX_MOVEENTS 64
#define MAX_LIGHTSTYLES 64
#define MAX_LIGHTSTYLEVALUE 256
#define SURF_DRAWTILED 0x20
typedef struct mplane_s {
vec3_t normal;
float dist;

View file

@ -12,11 +12,7 @@
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
#ifndef PROGDEFS_H
#define PROGDEFS_H
#ifdef _WIN32
#pragma once
#endif
typedef struct {
float time;
@ -84,8 +80,8 @@ typedef struct entvars_s {
int modelindex;
string_t model;
int viewmodel; // player's viewmodel
int weaponmodel; // what other players see
string_t viewmodel; // player's viewmodel
string_t weaponmodel; // what other players see
vec3_t absmin; // BB max translated to world coord
vec3_t absmax; // BB max translated to world coord
@ -216,4 +212,3 @@ typedef struct entvars_s {
edict_t *euser4;
} entvars_t;
#endif

View file

@ -122,8 +122,11 @@ public:
public:
int32 add (const String &name, int32 id);
int32 id (NetMsg msg);
void start (edict_t *ent, int32 type);
void stop ();
void ensureMessages ();
public:
template <typename T> void collect (const T &value) {
@ -137,10 +140,6 @@ public:
m_current = NetMsg::None;
}
int32 id (NetMsg msg) const {
return m_maps[msg];
}
private:
void reset () {
m_current = NetMsg::None;

View file

@ -30,6 +30,7 @@ private:
SmallArray <Client> m_clients;
SmallArray <Twin <String, String>> m_tags;
Dictionary <int32, String, IntNoHash <int32>> m_weaponAlias;
Dictionary <String, int32> m_noiseCache;
SimpleHook m_sendToHook;
@ -41,8 +42,8 @@ public:
// need to send welcome message ?
void checkWelcome ();
// gets the weapon alias as hlsting, maybe move to config...
int getWeaponAlias (bool needString, const char *weaponAlias, int weaponIndex = -1);
// converts weapon id to alias name
const String &weaponIdToAlias (const int32 id);
// gets the build number of bot
int buildNumber ();

View file

@ -10,7 +10,7 @@
#pragma once
#include <engine/extdll.h>
#include <engine/meta_api.h>
#include <engine/metamod.h>
#include <crlib/cr-complete.h>
@ -790,7 +790,7 @@ private:
void findShortestPath (int srcIndex, int destIndex);
void findPath (int srcIndex, int destIndex, FindPath pathType = FindPath::Fast);
void clearRoute ();
void sayDebug (const char *format, ...);
void debugMsgInternal (const char *str);
void frame ();
void resetCollision ();
void ignoreCollision ();
@ -1039,13 +1039,23 @@ public:
return pev->pContainingEntity;
};
// bots array index
int index () const {
return m_index;
}
// entity index with worldspawn shift
int entindex () const {
return m_index + 1;
}
// prints debug message
template <typename ...Args> void debugMsg (const char *fmt, Args ...args) {
debugMsgInternal (strings.format (fmt, cr::forward <Args> (args)...));
}
// execute client command helper
template <typename ...Args> void issueCommand (const char *fmt, Args ...args);
};
#include <config.h>
@ -1062,4 +1072,9 @@ extern ConVar yb_ignore_enemies;
extern ConVar yb_chat;
extern ConVar yb_language;
extern ConVar yb_show_latency;
extern ConVar yb_enable_query_hook;
extern ConVar yb_enable_query_hook;
// execute client command helper
template <typename ...Args> void Bot::issueCommand (const char * fmt, Args ...args) {
game.botCommand (ent (), strings.format (fmt, cr::forward <Args> (args)...));
}