458 lines
17 KiB
C
458 lines
17 KiB
C
//=======================================================================
|
|
// Copyright XashXT Group 2007 ©
|
|
// launch.h - launch.dll main header
|
|
//=======================================================================
|
|
#ifndef LAUNCHER_H
|
|
#define LAUNCHER_H
|
|
|
|
#include <limits.h>
|
|
#include <fcntl.h>
|
|
#include <direct.h>
|
|
#include <sys/stat.h>
|
|
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <io.h>
|
|
#include <time.h>
|
|
#include <winreg.h>
|
|
|
|
#define LAUNCH_DLL // skip alias names
|
|
#include "basetypes.h"
|
|
#include "ref_dllapi.h"
|
|
|
|
#define XASH_VERSION 0.51f // current version will be shared across gameinfo struct
|
|
|
|
#define MAX_NUM_ARGVS 128
|
|
#define MAX_STRING_TOKENS 80
|
|
#define LOG_QUEUE_SIZE MAX_MSGLEN * 4 // 128 kb intermediate buffer
|
|
|
|
// just for last chanse to view message (debug only)
|
|
#define MSGBOX(x) MessageBox(NULL, x, "Xash Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP );
|
|
|
|
enum state_e
|
|
{
|
|
SYS_SHUTDOWN = 0,
|
|
SYS_RESTART,
|
|
SYS_ABORT,
|
|
SYS_ERROR,
|
|
SYS_FRAME,
|
|
};
|
|
|
|
typedef struct system_s
|
|
{
|
|
char progname[64]; // instance keyword
|
|
char fmessage[64]; // shutdown final message
|
|
int app_name;
|
|
int app_state;
|
|
|
|
bool debug;
|
|
int developer;
|
|
int printlevel;
|
|
|
|
// log stuff
|
|
bool log_active;
|
|
char log_path[MAX_SYSPATH];
|
|
FILE *logfile;
|
|
|
|
bool hooked_out;
|
|
bool stuffcmdsrun;
|
|
byte packet_received[MAX_MSGLEN]; // network data
|
|
uint msg_time; // GetMessage time
|
|
char ModuleName[4096]; // exe.filename
|
|
|
|
HINSTANCE hInstance;
|
|
dll_info_t *linked_dll;
|
|
|
|
char caption[64];
|
|
bool con_readonly;
|
|
bool con_showalways;
|
|
bool con_showcredits;
|
|
bool con_silentmode;
|
|
byte *basepool;
|
|
byte *zonepool;
|
|
byte *imagepool;
|
|
byte *stringpool;
|
|
bool shutdown_issued;
|
|
bool error;
|
|
|
|
// simply profiling
|
|
double start, end;
|
|
|
|
void (*Con_Print)( const char *msg );
|
|
void ( *Init ) ( int argc, char **argv );
|
|
void ( *Main ) ( void ); // host frame
|
|
void ( *Free ) ( void ); // close host
|
|
void (*CPrint)( const char *msg ); // console print
|
|
void (*MSG_Init)( sizebuf_t *buf, byte *data, size_t length );
|
|
} system_t;
|
|
|
|
typedef struct timer_s
|
|
{
|
|
bool initialized; // any timer can be setup it
|
|
double oldtime;
|
|
double curtime;
|
|
dword timebase;
|
|
} timer_t;
|
|
|
|
typedef struct cvar_s
|
|
{
|
|
char *name;
|
|
char *string; // normal string
|
|
float value; // atof( string )
|
|
int integer; // atoi( string )
|
|
bool modified; // set each time the cvar is changed
|
|
|
|
char *reset_string; // cvar_restart will reset to this value
|
|
char *latched_string; // for CVAR_LATCH vars
|
|
char *description; // variable descrition info
|
|
uint flags; // state flags
|
|
uint modificationCount; // incremented each time the cvar is changed
|
|
|
|
struct cvar_s *next;
|
|
struct cvar_s *hash;
|
|
};
|
|
|
|
extern system_t Sys;
|
|
extern timer_t Msec;
|
|
extern gameinfo_t GI;
|
|
extern stdlib_api_t com;
|
|
|
|
//
|
|
// console.c
|
|
//
|
|
void Con_ShowConsole( bool show );
|
|
void Con_PrintA(const char *pMsg);
|
|
void Con_PrintW(const char *pMsg);
|
|
void Con_CreateConsole( void );
|
|
void Con_DestroyConsole( void );
|
|
char *Sys_Input( void );
|
|
void Con_RegisterHotkeys( void );
|
|
|
|
//
|
|
// system.c
|
|
//
|
|
void Sys_InitCPU( void );
|
|
gameinfo_t Sys_GameInfo( void );
|
|
void Sys_ParseCommandLine (LPSTR lpCmdLine);
|
|
void Sys_LookupInstance( void );
|
|
void Sys_NewInstance( const char *name, const char *fmsg );
|
|
double Sys_DoubleTime( void );
|
|
dword Sys_Milliseconds( void );
|
|
char *Sys_GetClipboardData( void );
|
|
char *Sys_GetCurrentUser( void );
|
|
bool Sys_GetModuleName( char *buffer, size_t length );
|
|
void Sys_Sleep( int msec );
|
|
void Sys_Init( void );
|
|
void Sys_Exit( void );
|
|
void Sys_Abort( void );
|
|
bool Sys_LoadLibrary ( dll_info_t *dll );
|
|
void* Sys_GetProcAddress ( dll_info_t *dll, const char* name );
|
|
byte *Sys_LoadRes( const char *filename, size_t *size );
|
|
bool Sys_FreeLibrary ( dll_info_t *dll );
|
|
void Sys_WaitForQuit( void );
|
|
void Sys_InitLog( void );
|
|
void Sys_CloseLog( void );
|
|
void Sys_Error(const char *error, ...);
|
|
void Sys_Break(const char *error, ...);
|
|
void Sys_PrintLog( const char *pMsg );
|
|
void Sys_Print(const char *pMsg);
|
|
void Sys_Msg( const char *pMsg, ... );
|
|
void Sys_MsgDev( int level, const char *pMsg, ... );
|
|
sys_event_t Sys_GetEvent( void );
|
|
void Sys_QueEvent( dword time, ev_type_t type, int value, int value2, int length, void *ptr );
|
|
int Sys_GetThreadWork( void );
|
|
void Sys_ThreadWorkerFunction (int threadnum);
|
|
void Sys_ThreadSetDefault (void);
|
|
void Sys_ThreadLock( void );
|
|
void Sys_ThreadUnlock( void );
|
|
int Sys_GetNumThreads( void );
|
|
void Sys_RunThreadsOnIndividual(int workcnt, bool showpacifier, void(*func)(int));
|
|
void Sys_RunThreadsOn (int workcnt, bool showpacifier, void(*func)(int));
|
|
|
|
#define Msg Sys_Msg
|
|
#define MsgDev Sys_MsgDev
|
|
|
|
// registry common tools
|
|
bool REG_GetValue( HKEY hKey, const char *SubKey, const char *Value, char *pBuffer);
|
|
bool REG_SetValue( HKEY hKey, const char *SubKey, const char *Value, char *pBuffer);
|
|
|
|
//
|
|
// network.c
|
|
//
|
|
void NET_Init( void );
|
|
void NET_Shutdown( void );
|
|
void NET_ShowIP( void ); // just for debug
|
|
void NET_Config( bool net_enable );
|
|
char *NET_AdrToString( netadr_t a );
|
|
bool NET_IsLANAddress( netadr_t adr );
|
|
bool NET_StringToAdr( const char *s, netadr_t *a );
|
|
bool NET_GetPacket( netadr_t *net_from, sizebuf_t *net_message );
|
|
void NET_SendPacket( int length, const void *data, netadr_t to );
|
|
|
|
//
|
|
// stdlib.c
|
|
//
|
|
void com_strnupr(const char *in, char *out, size_t size_out);
|
|
void com_strupr(const char *in, char *out);
|
|
void com_strnlwr(const char *in, char *out, size_t size_out);
|
|
void com_strlwr(const char *in, char *out);
|
|
int com_strlen( const char *string );
|
|
int com_cstrlen( const char *string );
|
|
char com_toupper(const char in );
|
|
char com_tolower(const char in );
|
|
size_t com_strncat(char *dst, const char *src, size_t siz);
|
|
size_t com_strcat(char *dst, const char *src );
|
|
size_t com_strncpy(char *dst, const char *src, size_t siz);
|
|
size_t com_strcpy(char *dst, const char *src );
|
|
char *com_stralloc(byte *mempool, const char *s, const char *filename, int fileline);
|
|
int com_atoi(const char *str);
|
|
float com_atof(const char *str);
|
|
void com_atov( float *vec, const char *str, size_t siz );
|
|
char *com_strchr(const char *s, char c);
|
|
char *com_strrchr(const char *s, char c);
|
|
int com_strnicmp(const char *s1, const char *s2, int n);
|
|
int com_stricmp(const char *s1, const char *s2);
|
|
int com_strncmp (const char *s1, const char *s2, int n);
|
|
int com_strcmp (const char *s1, const char *s2);
|
|
const char* com_timestamp( int format );
|
|
char *com_stristr( const char *string, const char *string2 );
|
|
char *com_strstr( const char *string, const char *string2 );
|
|
size_t com_strpack( byte *buffer, size_t pos, char *string, int n );
|
|
size_t com_strunpack( byte *buffer, size_t pos, char *string );
|
|
int com_vsnprintf(char *buffer, size_t buffersize, const char *format, va_list args);
|
|
int com_vsprintf(char *buffer, const char *format, va_list args);
|
|
int com_snprintf(char *buffer, size_t buffersize, const char *format, ...);
|
|
int com_sprintf(char *buffer, const char *format, ...);
|
|
char *com_pretifymem( float value, int digitsafterdecimal );
|
|
char *va(const char *format, ...);
|
|
#define copystring( str ) com_stralloc( NULL, str, __FILE__, __LINE__)
|
|
|
|
//
|
|
// random.c
|
|
//
|
|
long Com_RandomLong( long lMin, long lMax );
|
|
float Com_RandomFloat( float fMin, float fMax );
|
|
|
|
//
|
|
// memlib.c
|
|
//
|
|
void Memory_Init( void );
|
|
void Memory_Shutdown( void );
|
|
void Memory_Init_Commands( void );
|
|
void _mem_move(byte *poolptr, void **dest, void *src, size_t size, const char *filename, int fileline);
|
|
void *_mem_realloc(byte *poolptr, void *memptr, size_t size, const char *filename, int fileline);
|
|
void _mem_copy(void *dest, const void *src, size_t size, const char *filename, int fileline);
|
|
void _mem_set(void *dest, int set, size_t size, const char *filename, int fileline);
|
|
void *_mem_alloc(byte *poolptr, size_t size, const char *filename, int fileline);
|
|
byte *_mem_allocpool(const char *name, const char *filename, int fileline);
|
|
void _mem_freepool(byte **poolptr, const char *filename, int fileline);
|
|
void _mem_emptypool(byte *poolptr, const char *filename, int fileline);
|
|
void _mem_free(void *data, const char *filename, int fileline);
|
|
byte *_mem_alloc_array( byte *poolptr, size_t recordsize, int count, const char *filename, int fileline );
|
|
void _mem_free_array( byte *arrayptr, const char *filename, int fileline );
|
|
void *_mem_alloc_array_element( byte *arrayptr, const char *filename, int fileline );
|
|
void _mem_free_array_element( byte *arrayptr, void *element, const char *filename, int fileline );
|
|
void *_mem_get_array_element( byte *arrayptr, size_t index );
|
|
size_t _mem_array_size( byte *arrayptr );
|
|
void _mem_check(const char *filename, int fileline);
|
|
bool _is_allocated( byte *poolptr, void *data );
|
|
|
|
#define Mem_Alloc(pool, size) _mem_alloc(pool, size, __FILE__, __LINE__)
|
|
#define Mem_Realloc(pool, ptr, size) _mem_realloc(pool, ptr, size, __FILE__, __LINE__)
|
|
#define Mem_Free(mem) _mem_free(mem, __FILE__, __LINE__)
|
|
#define Mem_AllocPool(name) _mem_allocpool(name, __FILE__, __LINE__)
|
|
#define Mem_FreePool(pool) _mem_freepool(pool, __FILE__, __LINE__)
|
|
#define Mem_EmptyPool(pool) _mem_emptypool(pool, __FILE__, __LINE__)
|
|
#define Mem_Move(pool, dest, src, size ) _mem_move(pool, dest, src, size, __FILE__, __LINE__)
|
|
#define Mem_Copy(dest, src, size ) _mem_copy(dest, src, size, __FILE__, __LINE__)
|
|
#define Mem_Set(dest, val, size ) _mem_set(dest, val, size, __FILE__, __LINE__)
|
|
#define Mem_CreateArray( p, s, n ) _mem_alloc_array( p, s, n, __FILE__, __LINE__)
|
|
#define Mem_RemoveArray( array ) _mem_free_array( array, __FILE__, __LINE__)
|
|
#define Mem_AllocElement( array ) _mem_alloc_array_element( array, __FILE__, __LINE__)
|
|
#define Mem_FreeElement( array, el ) _mem_free_array_element( array, el, __FILE__, __LINE__ )
|
|
#define Mem_GetElement( array, idx ) _mem_get_array_element( array, idx )
|
|
#define Mem_ArraySize( array ) _mem_array_size( array )
|
|
#define Mem_IsAllocated( mem ) _is_allocated( NULL, mem )
|
|
#define Mem_Check() _mem_check(__FILE__, __LINE__)
|
|
#define Mem_Pretify( x ) com_pretifymem(x, 3)
|
|
#define Malloc( size ) Mem_Alloc( Sys.basepool, size )
|
|
|
|
//
|
|
// filesystem.c
|
|
//
|
|
void FS_Init( void );
|
|
void FS_Path( void );
|
|
void FS_Shutdown( void );
|
|
void FS_InitEditor( void );
|
|
void FS_InitRootDir( char *path );
|
|
void FS_ClearSearchPath (void);
|
|
void FS_AddGameHierarchy (const char *dir);
|
|
int FS_CheckParm (const char *parm);
|
|
void FS_LoadGameInfo( const char *filename );
|
|
void FS_FileBase( const char *in, char *out);
|
|
const char *FS_FileExtension (const char *in);
|
|
void FS_DefaultExtension (char *path, const char *extension );
|
|
bool FS_GetParmFromCmdLine( char *parm, char *out );
|
|
void FS_ExtractFilePath(const char* const path, char* dest);
|
|
void FS_UpdateEnvironmentVariables( void );
|
|
const char *FS_FileWithoutPath( const char *in );
|
|
extern char sys_rootdir[];
|
|
extern char *fs_argv[];
|
|
extern int fs_argc;
|
|
|
|
// wadsystem.c
|
|
wfile_t *W_Open( const char *filename, const char *mode );
|
|
byte *W_LoadLump( wfile_t *wad, const char *lumpname, size_t *lumpsizeptr, const char type );
|
|
fs_offset_t W_SaveLump( wfile_t *wad, const char *lump, const void* data, size_t datasize, char type, char cmp );
|
|
int W_Check( const char *filename );
|
|
void W_Close( wfile_t *wad );
|
|
|
|
// simply files managment interface
|
|
byte *FS_LoadFile (const char *path, fs_offset_t *filesizeptr );
|
|
bool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
|
|
|
|
rgbdata_t *FS_LoadImage( const char *name, const byte *buffer, size_t size );
|
|
void FS_SaveImage( const char *name, int format, rgbdata_t *image );
|
|
void Image_Process( rgbdata_t **pix, int w, int h, uint flags );
|
|
bpc_desc_t *Image_GetPixelFormat( pixformat_t type );
|
|
void FS_FreeImage( rgbdata_t *pack );
|
|
|
|
search_t *FS_Search(const char *pattern, int caseinsensitive );
|
|
search_t *FS_SearchDirs(const char *pattern, int caseinsensitive );
|
|
|
|
// files managment (like fopen, fread etc)
|
|
file_t *FS_Open( const char* filepath, const char* mode );
|
|
file_t* _FS_Open( const char* filepath, const char* mode, bool quiet );
|
|
fs_offset_t FS_Write (file_t* file, const void* data, size_t datasize);
|
|
fs_offset_t FS_Read (file_t* file, void* buffer, size_t buffersize);
|
|
int FS_VPrintf(file_t* file, const char* format, va_list ap);
|
|
int FS_Seek (file_t* file, fs_offset_t offset, int whence);
|
|
int FS_Gets (file_t* file, byte *string, size_t bufsize );
|
|
int FS_Printf(file_t* file, const char* format, ...);
|
|
fs_offset_t FS_FileSize (const char *filename);
|
|
fs_offset_t FS_FileTime (const char *filename);
|
|
int FS_Print(file_t* file, const char *msg);
|
|
bool FS_FileExists (const char *filename);
|
|
bool FS_Remove( const char *path );
|
|
int FS_UnGetc (file_t* file, byte c);
|
|
void FS_StripExtension (char *path);
|
|
fs_offset_t FS_Tell (file_t* file);
|
|
void FS_Purge (file_t* file);
|
|
int FS_Close (file_t* file);
|
|
int FS_Getc (file_t* file);
|
|
bool FS_Eof( file_t* file);
|
|
|
|
//
|
|
// cvar.c
|
|
//
|
|
cvar_t *Cvar_FindVar (const char *var_name);
|
|
cvar_t *Cvar_Get (const char *var_name, const char *value, int flags, const char *description);
|
|
void Cvar_Set( const char *var_name, const char *value);
|
|
cvar_t *Cvar_Set2( const char *var_name, const char *value, bool force );
|
|
void Cvar_LookupVars( int checkbit, void *buffer, void *ptr, setpair_t callback );
|
|
void Cvar_FullSet (char *var_name, char *value, int flags);
|
|
void Cvar_SetLatched( const char *var_name, const char *value);
|
|
void Cvar_SetValue( const char *var_name, float value);
|
|
float Cvar_VariableValue (const char *var_name);
|
|
char *Cvar_VariableString (const char *var_name);
|
|
bool Cvar_Command (void);
|
|
void Cvar_WriteVariables( file_t *f );
|
|
void Cvar_Init (void);
|
|
char *Cvar_Userinfo (void);
|
|
char *Cvar_Serverinfo (void);
|
|
extern bool userinfo_modified;
|
|
char *Info_ValueForKey( char *s, char *key );
|
|
void Info_RemoveKey( char *s, char *key );
|
|
void Info_SetValueForKey( char *s, char *key, char *value );
|
|
bool Info_Validate( char *s );
|
|
void Info_Print( char *s );
|
|
extern cvar_t *cvar_vars;
|
|
|
|
//
|
|
// cmd.c
|
|
//
|
|
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_Execute (void);
|
|
uint Cmd_Argc( void );
|
|
char *Cmd_Args( void );
|
|
char *Cmd_Argv( uint arg );
|
|
void Cmd_Init( void );
|
|
void Cmd_AddCommand(const char *cmd_name, xcommand_t function, const char *cmd_desc);
|
|
void Cmd_RemoveCommand(const char *cmd_name);
|
|
bool Cmd_Exists (const char *cmd_name);
|
|
void Cmd_LookupCmds( char *buffer, void *ptr, setpair_t callback );
|
|
bool Cmd_GetMapList( const char *s, char *completedname, int length );
|
|
bool Cmd_GetDemoList( const char *s, char *completedname, int length );
|
|
bool Cmd_GetMovieList (const char *s, char *completedname, int length );
|
|
void Cmd_TokenizeString (const char *text);
|
|
void Cmd_ExecuteString (const char *text);
|
|
void Cmd_ForwardToServer (void);
|
|
|
|
// virtual files managment
|
|
vfile_t *VFS_Create( const byte *buffer, size_t buffsize );
|
|
vfile_t *VFS_Open(file_t *handle, const char* mode);
|
|
fs_offset_t VFS_Write( vfile_t *file, const void *buf, size_t size );
|
|
fs_offset_t VFS_Read( vfile_t* file, void* buffer, size_t buffersize);
|
|
int VFS_Print(vfile_t* file, const char *msg);
|
|
int VFS_Printf(vfile_t* file, const char* format, ...);
|
|
int VFS_Seek( vfile_t *file, fs_offset_t offset, int whence );
|
|
int VFS_Gets(vfile_t* file, byte *string, size_t bufsize );
|
|
bool VFS_Unpack( void* compbuf, size_t compsize, void **buf, size_t size );
|
|
byte *VFS_GetBuffer( vfile_t *file );
|
|
fs_offset_t VFS_Tell (vfile_t* file);
|
|
file_t *VFS_Close( vfile_t *file );
|
|
bool VFS_Eof( vfile_t* file);
|
|
|
|
//
|
|
// crclib.c
|
|
//
|
|
void CRC_Init(word *crcvalue);
|
|
word CRC_Block (byte *start, int count);
|
|
void CRC_ProcessByte(word *crcvalue, byte data);
|
|
byte CRC_BlockSequence(byte *base, int length, int sequence);
|
|
uint Com_BlockChecksum (void *buffer, int length);
|
|
uint Com_BlockChecksumKey(void *buffer, int length, int key);
|
|
|
|
//
|
|
// parselib.c
|
|
//
|
|
bool SC_LoadScript( const char *filename, char *buf, int size );
|
|
bool SC_AddScript( const char *filename, char *buf, int size );
|
|
bool SC_FilterToken(char *filter, char *name, int casecmp);
|
|
uint SC_HashKey( const char *string, uint hashSize );
|
|
bool SC_ParseToken_Simple(const char **data_p);
|
|
char *SC_ParseToken( const char **data_p, bool newline );
|
|
char *SC_ParseWord( const char **data_p, bool newline );
|
|
void SC_SkipBracedSection( char **data_p, int depth );
|
|
void SC_PushScript( const char **data_p );
|
|
void SC_PopScript( const char **data_p );
|
|
bool SC_MatchToken( const char *match );
|
|
void SC_ResetScript( void );
|
|
void SC_SkipToken( void );
|
|
void SC_FreeToken( void );
|
|
bool SC_TryToken( void );
|
|
char *SC_GetToken( bool newline );
|
|
char *SC_GetTokenSimple( bool newline );
|
|
char *SC_Token( void );
|
|
extern char token[];
|
|
|
|
//
|
|
// imglib.c
|
|
//
|
|
void Image_Init( void );
|
|
void Image_Setup( const char *formats, const uint flags );
|
|
void Image_Shutdown( void );
|
|
|
|
//
|
|
// stringtable.c
|
|
//
|
|
int StringTable_CreateNewSystem( const char *name, size_t max_strings );
|
|
string_t StringTable_SetString( int handle, const char *string );
|
|
const char *StringTable_GetString( int handle, string_t index );
|
|
int StringTable_LoadSystem( wfile_t *wad, const char *name );
|
|
bool StringTable_SaveSystem( int h, wfile_t *wad );
|
|
void StringTable_DeleteSystem( int handle );
|
|
|
|
#endif//LAUNCHER_H
|