#ifndef QUAKE2_QCOMMON_QCOMMON_H__
#define QUAKE2_QCOMMON_QCOMMON_H__
#include "../game/q_shared.h"
void *global_uv_loop(void);
#define VERSION 3.19
#define BASEDIRNAME "baseq2"
#ifdef WIN32
#ifdef NDEBUG
#define BUILDSTRING "Win32 RELEASE"
#else
#define BUILDSTRING "Win32 DEBUG"
#endif
#ifdef _M_IX86
#define CPUSTRING "x86"
#elif defined _M_ALPHA
#define CPUSTRING "AXP"
#endif
#elif defined __linux__
#define BUILDSTRING "Linux"
#ifdef __i386__
#define CPUSTRING "i386"
#elif defined __alpha__
#define CPUSTRING "axp"
#else
#define CPUSTRING "unknown"
#endif
#elif defined __sun__
#define BUILDSTRING "Solaris"
#ifdef __i386__
#define CPUSTRING "i386"
#else
#define CPUSTRING "sparc"
#endif
#else
#define BUILDSTRING "NON-WIN32"
#define CPUSTRING "NON-WIN32"
#endif
typedef struct sizebuf_s {
bool allowoverflow; bool overflowed; byte *data;
int maxsize;
int cursize;
int readcount;
} sizebuf_t;
void SZ_Init(sizebuf_t *buf, byte *data, int length);
void SZ_Clear(sizebuf_t *buf);
void *SZ_GetSpace(sizebuf_t *buf, int length);
void SZ_Write(sizebuf_t *buf, const void *data, int length);
void SZ_Print(sizebuf_t *buf, const char *data);
struct usercmd_s;
struct entity_state_s;
void MSG_WriteChar(sizebuf_t *sb, int c);
void MSG_WriteByte(sizebuf_t *sb, int c);
void MSG_WriteShort(sizebuf_t *sb, int c);
void MSG_WriteLong(sizebuf_t *sb, int c);
void MSG_WriteFloat(sizebuf_t *sb, float f);
void MSG_WriteString(sizebuf_t *sb, char *s);
void MSG_WriteCoord(sizebuf_t *sb, float f);
void MSG_WritePos(sizebuf_t *sb, vec3_t pos);
void MSG_WriteAngle(sizebuf_t *sb, float f);
void MSG_WriteAngle16(sizebuf_t *sb, float f);
void MSG_WriteDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
void MSG_WriteDeltaEntity(struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, bool force,
bool newentity);
void MSG_WriteDir(sizebuf_t *sb, vec3_t vector);
void MSG_BeginReading(sizebuf_t *sb);
int MSG_ReadChar(sizebuf_t *sb);
int MSG_ReadByte(sizebuf_t *sb);
int MSG_ReadShort(sizebuf_t *sb);
int MSG_ReadLong(sizebuf_t *sb);
float MSG_ReadFloat(sizebuf_t *sb);
char *MSG_ReadString(sizebuf_t *sb);
char *MSG_ReadStringLine(sizebuf_t *sb);
float MSG_ReadCoord(sizebuf_t *sb);
void MSG_ReadPos(sizebuf_t *sb, vec3_t pos);
float MSG_ReadAngle(sizebuf_t *sb);
float MSG_ReadAngle16(sizebuf_t *sb);
void MSG_ReadDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
void MSG_ReadDir(sizebuf_t *sb, vec3_t vector);
void MSG_ReadData(sizebuf_t *sb, void *buffer, int size);
#if 0#endif
int COM_Argc(void);
char *COM_Argv(int arg); void COM_ClearArgv(int arg);
int COM_CheckParm(char *parm);
void COM_AddParm(char *parm);
void COM_Init(void);
void COM_InitArgv(int argc, char **argv);
char *CopyString(const char *in);
void Info_Print(char *s);
void CRC_Init(unsigned short *crcvalue);
void CRC_ProcessByte(unsigned short *crcvalue, byte data);
unsigned short CRC_Value(unsigned short crcvalue);
unsigned short CRC_Block(byte *start, int count);
#define PROTOCOL_VERSION 34
#define PORT_MASTER 27900
#define PORT_CLIENT 27901
#define PORT_SERVER 27910
#define UPDATE_BACKUP 16
#define UPDATE_MASK (UPDATE_BACKUP - 1)
enum svc_ops_e {
svc_bad,
svc_muzzleflash,
svc_muzzleflash2,
svc_temp_entity,
svc_layout,
svc_inventory,
svc_nop,
svc_disconnect,
svc_reconnect,
svc_sound, svc_print, svc_stufftext, svc_serverdata, svc_configstring, svc_spawnbaseline,
svc_centerprint, svc_download, svc_playerinfo, svc_packetentities, svc_deltapacketentities, svc_frame
};
enum clc_ops_e {
clc_bad,
clc_nop,
clc_move, clc_userinfo, clc_stringcmd };
#define PS_M_TYPE (1 << 0)
#define PS_M_ORIGIN (1 << 1)
#define PS_M_VELOCITY (1 << 2)
#define PS_M_TIME (1 << 3)
#define PS_M_FLAGS (1 << 4)
#define PS_M_GRAVITY (1 << 5)
#define PS_M_DELTA_ANGLES (1 << 6)
#define PS_VIEWOFFSET (1 << 7)
#define PS_VIEWANGLES (1 << 8)
#define PS_KICKANGLES (1 << 9)
#define PS_BLEND (1 << 10)
#define PS_FOV (1 << 11)
#define PS_WEAPONINDEX (1 << 12)
#define PS_WEAPONFRAME (1 << 13)
#define PS_RDFLAGS (1 << 14)
#define PS_CMODEL_INDEX (1 << 15)
#define CM_ANGLE1 (1 << 0)
#define CM_ANGLE2 (1 << 1)
#define CM_ANGLE3 (1 << 2)
#define CM_FORWARD (1 << 3)
#define CM_SIDE (1 << 4)
#define CM_UP (1 << 5)
#define CM_BUTTONS (1 << 6)
#define CM_IMPULSE (1 << 7)
#define SND_VOLUME (1 << 0)
#define SND_ATTENUATION (1 << 1)
#define SND_POS (1 << 2)
#define SND_ENT (1 << 3)
#define SND_OFFSET (1 << 4)
#define DEFAULT_SOUND_PACKET_VOLUME 1.0
#define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
#define U_ORIGIN1 (1 << 0)
#define U_ORIGIN2 (1 << 1)
#define U_ANGLE2 (1 << 2)
#define U_ANGLE3 (1 << 3)
#define U_FRAME8 (1 << 4)
#define U_EVENT (1 << 5)
#define U_REMOVE (1 << 6)
#define U_MOREBITS1 (1 << 7)
#define U_NUMBER16 (1 << 8)
#define U_ORIGIN3 (1 << 9)
#define U_ANGLE1 (1 << 10)
#define U_MODEL (1 << 11)
#define U_RENDERFX8 (1 << 12)
#define U_EFFECTS8 (1 << 14)
#define U_MOREBITS2 (1 << 15)
#define U_SKIN8 (1 << 16)
#define U_FRAME16 (1 << 17)
#define U_RENDERFX16 (1 << 18)
#define U_EFFECTS16 (1 << 19)
#define U_MODEL2 (1 << 20)
#define U_MODEL3 (1 << 21)
#define U_MODEL4 (1 << 22)
#define U_MOREBITS3 (1 << 23)
#define U_OLDORIGIN (1 << 24)
#define U_SKIN16 (1 << 25)
#define U_SOUND (1 << 26)
#define U_SOLID (1 << 27)
#define U_CMODEL_INDEX (1 << 26)
#define EXEC_NOW 0
#define EXEC_INSERT 1
#define EXEC_APPEND 2
void Cbuf_Init(void);
void Cbuf_AddText(const char *text);
void Cbuf_InsertText(const char *text);
void Cbuf_ExecuteText(int exec_when, const char *text);
void Cbuf_AddEarlyCommands(bool clear);
bool Cbuf_AddLateCommands(void);
void Cbuf_Execute(void);
void Cbuf_CopyToDefer(void);
void Cbuf_InsertFromDefer(void);
typedef void (*xcommand_t)(void);
void Cmd_Init(void);
void Cmd_AddCommand(const char *cmd_name, xcommand_t function);
void Cmd_RemoveCommand(const char *cmd_name);
bool Cmd_Exists(const char *cmd_name);
const char *Cmd_CompleteCommand(const char *partial);
int Cmd_Argc(void);
char *Cmd_Argv(int arg);
char *Cmd_Args(void);
void Cmd_TokenizeString(const char *text, bool macroExpand);
void Cmd_ExecuteString(const char *text);
void Cmd_ForwardToServer(void);
extern cvar_t *cvar_vars;
cvar_t *Cvar_Get(const char *var_name, const char *value, int flags);
cvar_t *Cvar_Set(const char *var_name, const char *value);
cvar_t *Cvar_ForceSet(const char *var_name, const char *value);
cvar_t *Cvar_FullSet(const char *var_name, const char *value, int flags);
void Cvar_SetValue(const char *var_name, float value);
float Cvar_VariableValue(const char *var_name);
char *Cvar_VariableString(const char *var_name);
char *Cvar_CompleteVariable(const char *partial);
void Cvar_GetLatchedVars(void);
bool Cvar_Command(void);
void Cvar_WriteVariables(const char *path);
void Cvar_Init(void);
char *Cvar_Userinfo(void);
char *Cvar_Serverinfo(void);
extern bool userinfo_modified;
#define PORT_ANY -1
#define MAX_MSGLEN 1400
#define PACKET_HEADER 10
typedef enum { NA_LOOPBACK, NA_BROADCAST, NA_IP } netadrtype_t;
typedef enum { NS_CLIENT, NS_SERVER, NETSRC_LAST = NS_SERVER, NETSRC_COUNT = NETSRC_LAST + 1 } netsrc_t;
typedef struct {
netadrtype_t type;
byte ip[4];
unsigned short port;
} netadr_t;
void NET_Init(void);
void NET_Shutdown(void);
void NET_Config(bool multiplayer);
bool NET_GetPacket(netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message);
void NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to);
bool NET_CompareAdr(netadr_t a, netadr_t b);
bool NET_CompareBaseAdr(netadr_t a, netadr_t b);
bool NET_IsLocalAddress(netadr_t adr);
char *NET_AdrToString(netadr_t a);
bool NET_StringToAdr(char *s, netadr_t *a);
void NET_Sleep(int msec);
#define OLD_AVG 0.99
#define MAX_LATENT 32
typedef struct {
bool fatal_error;
netsrc_t sock;
int dropped;
int last_received; int last_sent;
netadr_t remote_address;
int qport;
int incoming_sequence;
int incoming_acknowledged;
int incoming_reliable_acknowledged;
int incoming_reliable_sequence;
int outgoing_sequence;
int reliable_sequence; int last_reliable_sequence;
sizebuf_t message; byte message_buf[MAX_MSGLEN - 16];
int reliable_length;
byte reliable_buf[MAX_MSGLEN - 16]; } netchan_t;
extern netadr_t net_from;
extern sizebuf_t net_message;
extern byte net_message_buffer[MAX_MSGLEN];
void Netchan_Init(void);
void Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport);
bool Netchan_NeedReliable(netchan_t *chan);
void Netchan_Transmit(netchan_t *chan, int length, byte *data);
void Netchan_OutOfBand(int net_socket, netadr_t adr, int length, byte *data);
void Netchan_OutOfBandPrint(int net_socket, netadr_t adr, char *format, ...);
bool Netchan_Process(netchan_t *chan, sizebuf_t *msg);
bool Netchan_CanReliable(netchan_t *chan);
#include "../qcommon/qfiles.h"
cmodel_t *CM_LoadMap(int cmodel_index, char *name, bool clientload, unsigned *checksum);
cmodel_t *CM_InlineModel(int cmodel_index, char *name);
int CM_NumClusters(int cmodel_index);
int CM_NumInlineModels(int cmodel_index);
char *CM_EntityString(int cmodel_index);
int CM_HeadnodeForBox(int cmodel_index, vec3_t mins, vec3_t maxs);
int CM_PointContents(int cmodel_index, vec3_t p, int headnode);
int CM_TransformedPointContents(int cmodel_index, vec3_t p, int headnode, vec3_t origin, vec3_t angles);
trace_t CM_BoxTrace(int cmodel_index, vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headnode, int brushmask);
trace_t CM_TransformedBoxTrace(int cmodel_index, vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, int headnode,
int brushmask, vec3_t origin, vec3_t angles);
byte *CM_ClusterPVS(int cmodel_index, int cluster);
byte *CM_ClusterPHS(int cmodel_index, int cluster);
int CM_PointLeafnum(int cmodel_index, vec3_t p);
int CM_BoxLeafnums(int cmodel_index, vec3_t mins, vec3_t maxs, int *list, int listsize, int *topnode);
int CM_LeafContents(int cmodel_index, int leafnum);
int CM_LeafCluster(int cmodel_index, int leafnum);
int CM_LeafArea(int cmodel_index, int leafnum);
void CM_SetAreaPortalState(int cmodel_index, int portalnum, bool open);
bool CM_AreasConnected(int cmodel_index, int area1, int area2);
int CM_WriteAreaBits(int cmodel_index, byte *buffer, int area);
bool CM_HeadnodeVisible(int cmodel_index, int headnode, byte *visbits);
void CM_WritePortalState(int cmodel_index, FILE *f);
void CM_ReadPortalState(int cmodel_index, FILE *f);
int CM_NumTextures(int cmodel_index);
const char *CM_GetTexturePrecacheName(int cmodel_index, int texture);
bool CM_IsActive(int cmodel_index);
extern float pm_airaccelerate;
void Pmove(pmove_t *pmove);
void FS_InitFilesystem(void);
void FS_SetGamedir(const char *dir);
const char *FS_Gamedir(void);
const char *FS_NextPath(const char *prevpath);
void FS_ExecAutoexec(void);
int FS_FOpenFile(const char *filename, FILE **file);
void FS_FCloseFile(FILE *f);
int FS_LoadFile(const char *path, void **buffer);
void FS_Read(void *buffer, int len, FILE *f);
void FS_FreeFile(void *buffer);
void FS_CreatePath(const char *path);
void FS_LoadAsync(const char *path, void (*error)(void *ud), void (*done)(const void *, int, void *ud), void *ud);
#define ERR_FATAL 0
#define ERR_DROP 1
#define ERR_QUIT 2
#define EXEC_NOW 0
#define EXEC_INSERT 1
#define EXEC_APPEND 2
#define PRINT_ALL 0
#define PRINT_DEVELOPER 1
void Com_BeginRedirect(int target, char *buffer, int buffersize, void(*flush));
void Com_EndRedirect(void);
void Com_Printf(char *fmt, ...);
void Com_DPrintf(char *fmt, ...);
void Com_Error(int code, char *fmt, ...);
void Com_Quit(void);
int Com_ServerState(void); void Com_SetServerState(int state);
unsigned Com_BlockChecksum(void *buffer, int length);
byte COM_BlockSequenceCRCByte(byte *base, int length, int sequence);
float frand(void); float crand(void);
extern cvar_t *developer;
extern cvar_t *dedicated;
extern cvar_t *host_speeds;
extern cvar_t *log_stats;
extern FILE *log_stats_file;
extern int time_before_game;
extern int time_after_game;
extern int time_before_ref;
extern int time_after_ref;
void Z_Free(void *ptr);
void *Z_Malloc(int size); void *Z_TagMalloc(int size, int tag);
void Z_FreeTags(int tag);
void Qcommon_Init(int argc, char **argv);
void Qcommon_Frame(int msec);
int Qcommon_RunFrames(void);
void Qcommon_Shutdown(void);
#define NUMVERTEXNORMALS 162
extern vec3_t bytedirs[NUMVERTEXNORMALS];
void SCR_DebugGraph(float value, int color);
void Sys_Init(void);
void Sys_AppActivate(void);
void Sys_UnloadGame(void);
void *Sys_GetGameAPI(void *parms);
char *Sys_ConsoleInput(void);
void Sys_ConsoleOutput(char *string);
void Sys_SendKeyEvents(void);
void Sys_Error(char *error, ...);
void Sys_Quit(void);
char *Sys_GetClipboardData(void);
void Sys_CopyProtect(void);
void CL_Init(void);
void CL_Drop(void);
void CL_Shutdown(void);
void CL_Frame(int msec);
void Con_Print(char *text);
void SCR_BeginLoadingPlaque(void);
void SV_Init(void);
void SV_Shutdown(char *finalmsg, bool reconnect);
void SV_Frame(int msec);
#endif