//----------------------------------------------------------------------------- // Purpose: // Input : ttype - // pszToken - //----------------------------------------------------------------------------- void TokenReader::Stuff(trtoken_t eType, const char *pszToken) { m_eStuffed = eType; Q_strncpy(m_szStuffed, pszToken, sizeof( m_szStuffed ) ); m_bStuffed = true; }
void C_HLTVCamera::FireGameEvent( IGameEvent * event) { if ( !g_bEngineIsHLTV ) return; // not in HLTV mode const char *type = event->GetName(); if ( Q_strcmp( "game_newmap", type ) == 0 ) { Reset(); // reset all camera settings // show spectator UI if ( !GetViewPortInterface() ) return; if ( engine->IsPlayingDemo() ) { // for demo playback show full menu GetViewPortInterface()->ShowPanel( PANEL_SPECMENU, true ); SetMode( OBS_MODE_ROAMING ); } else { // during live broadcast only show black bars GetViewPortInterface()->ShowPanel( PANEL_SPECGUI, true ); } return; } if ( Q_strcmp( "hltv_message", type ) == 0 ) { wchar_t outputBuf[1024]; const char *pszText = event->GetString( "text", "" ); char *tmpStr = hudtextmessage->LookupString( pszText ); const wchar_t *pBuf = g_pVGuiLocalize->Find( tmpStr ); if ( pBuf ) { // Copy pBuf into szBuf[i]. int nMaxChars = sizeof( outputBuf ) / sizeof( wchar_t ); wcsncpy( outputBuf, pBuf, nMaxChars ); outputBuf[nMaxChars-1] = 0; } else { g_pVGuiLocalize->ConvertANSIToUnicode( tmpStr, outputBuf, sizeof(outputBuf) ); } GetCenterPrint()->Print( ConvertCRtoNL( outputBuf ) ); return ; } if ( Q_strcmp( "hltv_title", type ) == 0 ) { Q_strncpy( m_szTitleText, event->GetString( "text", "" ), sizeof(m_szTitleText) ); return; } if ( Q_strcmp( "hltv_status", type ) == 0 ) { int nNumProxies = event->GetInt( "proxies" ); m_nNumSpectators = event->GetInt( "clients" ) - nNumProxies; return; } // after this only auto-director commands follow // don't execute them is autodirector is off and PVS is unlocked if ( !spec_autodirector.GetBool() && !IsPVSLocked() ) return; if ( Q_strcmp( "hltv_cameraman", type ) == 0 ) { Reset(); m_nCameraMode = OBS_MODE_ROAMING; m_iCameraMan = event->GetInt( "index" ); return; } if ( Q_strcmp( "hltv_fixed", type ) == 0 ) { m_iCameraMan = 0; m_vCamOrigin.x = event->GetInt( "posx" ); m_vCamOrigin.y = event->GetInt( "posy" ); m_vCamOrigin.z = event->GetInt( "posz" ); QAngle angle; angle.x = event->GetInt( "theta" ); angle.y = event->GetInt( "phi" ); angle.z = 0; // no roll yet if ( m_nCameraMode != OBS_MODE_FIXED ) { SetMode( OBS_MODE_FIXED ); SetCameraAngle( angle ); m_flFOV = event->GetFloat( "fov", 90 ); } SetPrimaryTarget( event->GetInt( "target" ) ); if ( m_iTraget1 == 0 ) { SetCameraAngle( angle ); } return; } if ( Q_strcmp( "hltv_chase", type ) == 0 ) { bool bInEye = event->GetBool( "ineye" ); // check if we are already in a player chase mode bool bIsInChaseMode = (m_nCameraMode==OBS_MODE_IN_EYE)|| (m_nCameraMode==OBS_MODE_CHASE); // if we are in auto director or not in a valid chase mode, set new mode now if ( spec_autodirector.GetBool() || !bIsInChaseMode ) { SetMode( bInEye?OBS_MODE_IN_EYE:OBS_MODE_CHASE ); } m_iCameraMan = 0; m_iTraget2 = event->GetInt( "target2" ); m_flDistance = event->GetFloat( "distance", m_flDistance ); m_flOffset = event->GetFloat( "offset", m_flOffset ); m_flTheta = event->GetFloat( "theta", m_flTheta ); m_flPhi = event->GetFloat( "phi", m_flPhi ); m_flFOV = event->GetFloat( "fov", 90 ); m_flInertia = event->GetFloat( "inertia", 30.f ) / 10.f; // if inertia is not set use standard value if ( m_flInertia <= 0 ) m_flInertia = 3.0f; SetPrimaryTarget( event->GetInt( "target1" ) ); return; } }
/* =============== CL_ChangeGame This is experiment. Use with precaution =============== */ qboolean CL_ChangeGame( const char *gamefolder, qboolean bReset ) { if( host.type == HOST_DEDICATED ) return false; if( Q_stricmp( host.gamefolder, gamefolder )) { kbutton_t *mlook, *jlook; qboolean mlook_active = false, jlook_active = false; string mapname, maptitle; int maxEntities; mlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_mlook" ); jlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_jlook" ); if( mlook && ( mlook->state & 1 )) mlook_active = true; if( jlook && ( jlook->state & 1 )) jlook_active = true; // so reload all images (remote connect) Mod_ClearAll( true ); R_ShutdownImages(); FS_LoadGameInfo( (bReset) ? host.gamefolder : gamefolder ); R_InitImages(); // save parms maxEntities = clgame.maxEntities; Q_strncpy( mapname, clgame.mapname, MAX_STRING ); Q_strncpy( maptitle, clgame.maptitle, MAX_STRING ); #ifdef PANDORA if( !CL_LoadProgs( va( "%s/" CLIENTDLL, "." ))) #else if( !CL_LoadProgs( va( "%s/%s", GI->dll_path, GI->client_lib))) #endif Host_Error( "can't initialize client library\n" ); // restore parms clgame.maxEntities = maxEntities; Q_strncpy( clgame.mapname, mapname, MAX_STRING ); Q_strncpy( clgame.maptitle, maptitle, MAX_STRING ); // invalidate fonts so we can reloading them again Q_memset( &cls.creditsFont, 0, sizeof( cls.creditsFont )); SCR_InstallParticlePalette(); SCR_LoadCreditsFont(); Con_InvalidateFonts(); SCR_RegisterTextures (); CL_FreeEdicts (); SCR_VidInit (); if( cls.key_dest == key_game ) // restore mouse state clgame.dllFuncs.IN_ActivateMouse(); // restore mlook state if( mlook_active ) Cmd_ExecuteString( "+mlook\n", src_command ); if( jlook_active ) Cmd_ExecuteString( "+jlook\n", src_command ); return true; } return false; }
void FilePlayerClassInfo_t::Parse( KeyValues *pKeyValuesData, const char *szPlayerClassName ) { // Okay, we tried at least once to look this up... m_bParsedScript = true; // Classname Q_strncpy( m_szPlayerClassName, szPlayerClassName, MAX_PLAYERCLASS_NAME_LENGTH ); // Printable name Q_strncpy( m_szPrintName, pKeyValuesData->GetString( "printname", "!! Missing printname on Player Class" ), MAX_PLAYERCLASS_NAME_LENGTH ); // Player Model Q_strncpy( m_szPlayerModel, pKeyValuesData->GetString( "playermodel", "!! Missing playermodel on Player Class" ), MAX_PLAYERCLASS_NAME_LENGTH ); // Select command Q_strncpy( m_szSelectCmd, pKeyValuesData->GetString( "selectcmd", "!! Missing selectcmd on Player Class" ), 32 ); m_iTeam = TEAM_UNASSIGNED; const char *pTeam = pKeyValuesData->GetString( "team", NULL ); if ( pTeam ) { if ( Q_stricmp( pTeam, "BLUE" ) == 0 ) { m_iTeam = SDK_TEAM_BLUE; } else if ( Q_stricmp( pTeam, "RED" ) == 0 ) { m_iTeam = SDK_TEAM_RED; } else { Assert( false ); } } else { Assert( false ); } const int keyLength = sizeof( "weapon_" ) + MAX_DIGITS; char keyName[ keyLength ]; int ammoKeyLength = sizeof( "weapon__ammo" ) + MAX_DIGITS; char ammoKeyName[ ammoKeyLength ]; for (int i = 1; i <= WEAPON_MAX; i++) { Q_snprintf( keyName, keyLength, "weapon_%d", i ); const char *pszWeapon = pKeyValuesData->GetString( keyName, NULL ); if( !pszWeapon ) { Warning( "weapon_%s: %s requested by class %s not found\n", keyName, pszWeapon, m_szPlayerClassName ); break; } int weaponId = AliasToWeaponID( pszWeapon ); m_WeaponVector.AddToTail( weaponId ); Q_snprintf( ammoKeyName, ammoKeyLength, "weapon_%d_ammo", i ); int ammoCount = pKeyValuesData->GetInt( ammoKeyName, 0 ); m_AmmoVector.AddToTail( ammoCount ); m_iWeaponCount = i; } Q_strncpy( m_szLimitCvar, pKeyValuesData->GetString( "limitcvar", "!! Missing limit cvar on Player Class" ), sizeof(m_szLimitCvar) ); Assert( Q_strlen( m_szLimitCvar ) > 0 && "Every class must specify a limitcvar" ); // HUD player status health images (when the player is hurt) Q_strncpy( m_szClassImage, pKeyValuesData->GetString( "classimage", "white" ), sizeof( m_szClassImage ) ); Q_strncpy( m_szClassImageBG, pKeyValuesData->GetString( "classimagebg", "white" ), sizeof( m_szClassImageBG ) ); m_iHealth = pKeyValuesData->GetFloat( "Health", 100 ); m_flRunSpeed = pKeyValuesData->GetFloat( "RunSpeed", 200 ); m_flSprintSpeed = pKeyValuesData->GetFloat( "SprintSpeed", 340 ); m_flProneSpeed = pKeyValuesData->GetFloat( "ProneSpeed", 160 ); m_flStaminaDrainRate = pKeyValuesData->GetFloat( "StaminaDrainRate", lf_combat_default_drainrate.GetFloat() ); m_flStaminaRestoreRate = pKeyValuesData->GetFloat( "StaminaRestoreRate", lf_combat_default_restorerate.GetFloat() ); m_iArmor = pKeyValuesData->GetInt( "armor", 0 ); }
/* <d3446> ../engine/net_ws.c:410 */ qboolean NET_StringToSockaddr(const char *s, struct sockaddr *sadr) { struct hostent *h; char *colon; int val; char copy[128]; Q_memset(sadr, 0, sizeof(*sadr)); #ifdef _WIN32 if (Q_strlen(s) >= 24 && s[8] == ':' && s[21] == ':') { sadr->sa_family = AF_IPX; copy[2] = 0; copy[0] = s[0]; copy[1] = s[1]; sscanf(copy, "%x", &val); sadr->sa_data[0] = (char)val; copy[0] = s[2]; copy[1] = s[3]; sscanf(copy, "%x", &val); sadr->sa_data[1] = (char)val; copy[0] = s[4]; copy[1] = s[5]; sscanf(copy, "%x", &val); sadr->sa_data[2] = (char)val; copy[0] = s[6]; copy[1] = s[7]; sscanf(copy, "%x", &val); sadr->sa_data[3] = (char)val; copy[0] = s[9]; copy[1] = s[10]; sscanf(copy, "%x", &val); sadr->sa_data[4] = (char)val; copy[0] = s[11]; copy[1] = s[12]; sscanf(copy, "%x", &val); sadr->sa_data[5] = (char)val; copy[0] = s[13]; copy[1] = s[14]; sscanf(copy, "%x", &val); sadr->sa_data[6] = (char)val; copy[0] = s[15]; copy[1] = s[16]; sscanf(copy, "%x", &val); sadr->sa_data[7] = (char)val; copy[0] = s[17]; copy[1] = s[18]; sscanf(copy, "%x", &val); sadr->sa_data[8] = (char)val; copy[0] = s[19]; copy[1] = s[20]; sscanf(copy, "%x", &val); sadr->sa_data[9] = (char)val; sscanf(s + 22, "%u", &val); *(uint16 *)&sadr->sa_data[10] = htons(val); return TRUE; } #endif // _WIN32 ((sockaddr_in *)sadr)->sin_family = AF_INET; ((sockaddr_in *)sadr)->sin_port = 0; Q_strncpy(copy, s, sizeof(copy) - 1); copy[sizeof(copy) - 1] = 0; // Parse port colon = copy; while (*colon != 0) { if (*colon == ':') { *colon = 0; val = atoi(colon + 1); ((sockaddr_in *)sadr)->sin_port = htons(val); } colon++; } // Parse address ((sockaddr_in *)sadr)->sin_addr.s_addr = inet_addr(copy); if (((sockaddr_in *)sadr)->sin_addr.s_addr == INADDR_NONE) { h = CRehldsPlatformHolder::get()->gethostbyname(copy); if (h == NULL || h->h_addr == NULL) { return FALSE; } ((sockaddr_in *)sadr)->sin_addr.s_addr = *(uint32 *)h->h_addr; } return TRUE; }
/* ==================== CL_Record_f record <demoname> Begins recording a demo from the current position ==================== */ void CL_Record_f( void ) { const char *name; string demoname, demopath, demoshot; int n; if( Cmd_Argc() == 1 ) { name = "new"; } else if( Cmd_Argc() == 2 ) { name = Cmd_Argv( 1 ); } else { Msg( "Usage: record <demoname>\n" ); return; } if( cls.demorecording ) { Msg( "Already recording.\n"); return; } if( cls.demoplayback ) { Msg( "Can't record during demo playback.\n"); return; } if( !cls.demoheader || cls.state != ca_active ) { Msg( "You must be in a level to record.\n"); return; } if( !Q_stricmp( name, "new" )) { // scan for a free filename for( n = 0; n < 10000; n++ ) { CL_DemoGetName( n, demoname ); if( !FS_FileExists( va( "demos/%s.dem", demoname ), true )) break; } if( n == 10000 ) { Msg( "^3ERROR: no free slots for demo recording\n" ); return; } } else Q_strncpy( demoname, name, sizeof( demoname )); // open the demo file Q_sprintf( demopath, "demos/%s.dem", demoname ); Q_sprintf( demoshot, "demos/%s.bmp", demoname ); // make sure what old demo is removed if( FS_FileExists( demopath, false )) FS_Delete( demopath ); if( FS_FileExists( demoshot, false )) FS_Delete( demoshot ); // write demoshot for preview Cbuf_AddText( va( "demoshot \"%s\"\n", demoname )); Q_strncpy( cls.demoname, demoname, sizeof( cls.demoname )); Q_strncpy( menu.globals->demoname, demoname, sizeof( menu.globals->demoname )); CL_WriteDemoHeader( demopath ); }
void CHudStatusBar :: ParseStatusString( int line_num ) { // localise string first char szBuffer[MAX_STATUSTEXT_LENGTH]; memset( szBuffer, 0, sizeof szBuffer ); gHUD.m_TextMessage.LocaliseTextString( m_szStatusText[line_num], szBuffer, MAX_STATUSTEXT_LENGTH ); // parse m_szStatusText & m_iStatusValues into m_szStatusBar memset( m_szStatusBar[line_num], 0, MAX_STATUSTEXT_LENGTH ); char *src = szBuffer; char *dst = m_szStatusBar[line_num]; char *src_start = src, *dst_start = dst; while( *src != 0 ) { while( *src == '\n' ) src++; // skip over any newlines if((( src - src_start ) >= MAX_STATUSTEXT_LENGTH ) || (( dst - dst_start ) >= MAX_STATUSTEXT_LENGTH )) break; int index = Q_atoi( src ); // should we draw this line? if(( index >= 0 && index < MAX_STATUSBAR_VALUES ) && ( m_iStatusValues[index] != 0 )) { // parse this line and append result to the status bar while( *src >= '0' && *src <= '9' ) src++; if( *src == '\n' || *src == 0 ) continue; // no more left in this text line // copy the text, char by char, until we hit a % or a \n while( *src != '\n' && *src != 0 ) { if( *src != '%' ) { // just copy the character *dst = *src; dst++, src++; } else { // get the descriptor char valtype = *(++src); // move over % // if it's a %, draw a % sign if( valtype == '%' ) { *dst = valtype; dst++, src++; continue; } // move over descriptor, then get and move over the index index = Q_atoi( ++src ); while( *src >= '0' && *src <= '9' ) src++; if( index >= 0 && index < MAX_STATUSBAR_VALUES ) { int indexval = m_iStatusValues[index]; // get the string to substitute in place of the %XX char szRepString[MAX_PLAYER_NAME_LENGTH]; switch( valtype ) { case 'p': // player name GetPlayerInfo( indexval, &g_PlayerInfoList[indexval] ); if ( g_PlayerInfoList[indexval].name != NULL ) { Q_strncpy( szRepString, g_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH ); m_pflNameColors[line_num] = GetClientColor( indexval ); } else { Q_strcpy( szRepString, "******" ); } break; case 'i': // number Q_snprintf( szRepString, sizeof( szRepString ), "%d", indexval ); break; default: szRepString[0] = 0; break; } for( char *cp = szRepString; *cp != 0 && ((dst - dst_start) < MAX_STATUSTEXT_LENGTH); cp++, dst++ ) *dst = *cp; } } } } else { // skip to next line of text while( *src != 0 && *src != '\n' ) src++; } } }
qboolean HPAK_GetDataPointer( const char *filename, resource_t *pResource, byte **buffer, int *size ) { file_t *f; int i, num_lumps; hpak_dir_t *direntries; byte *tmpbuf; string pakname; hpak_t *queue; hpak_header_t hdr; if( !filename || !filename[0] ) return false; if( buffer ) *buffer = NULL; if( size ) *size = 0; for( queue = hpak_queue; queue != NULL; queue = queue->next ) { if( !Q_stricmp(queue->name, filename ) && !Q_memcmp( queue->HpakResource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) { if( buffer ) { tmpbuf = Z_Malloc( queue->size ); Q_memcpy( tmpbuf, queue->data, queue->size ); *buffer = tmpbuf; } if( size ) *size = queue->size; return true; } } Q_strncpy( pakname, filename, sizeof( pakname )); FS_StripExtension( pakname ); FS_DefaultExtension( pakname, ".hpk" ); f = FS_Open( pakname, "rb", false ); if( !f ) return false; FS_Read( f, &hdr, sizeof( hdr )); if( hdr.ident != IDCUSTOMHEADER ) { MsgDev( D_ERROR, "HPAK_GetDataPointer: %s it's not a HPK file.\n", pakname ); FS_Close( f ); return false; } if( hdr.version != IDCUSTOM_VERSION ) { MsgDev( D_ERROR, "HPAK_GetDataPointer: %s has invalid version (%i should be %i).\n", pakname, hdr.version, IDCUSTOM_VERSION ); FS_Close( f ); return false; } FS_Seek( f, hdr.seek, SEEK_SET ); FS_Read( f, &num_lumps, sizeof( num_lumps )); if( num_lumps < 1 || num_lumps > MAX_FILES_IN_WAD ) { MsgDev( D_ERROR, "HPAK_GetDataPointer: %s has too many lumps %u.\n", filename, num_lumps ); FS_Close( f ); return false; } direntries = Z_Malloc( sizeof( hpak_dir_t ) * num_lumps ); FS_Read( f, direntries, sizeof( hpak_dir_t ) * num_lumps ); for( i = 0; i < num_lumps; i++ ) { if( !Q_memcmp( direntries[i].DirectoryResource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) { FS_Seek( f, direntries[i].seek, SEEK_SET ); if( buffer && direntries[i].size > 0 ) { tmpbuf = Z_Malloc( direntries[i].size ); FS_Read( f, tmpbuf, direntries[i].size ); *buffer = tmpbuf; } Mem_Free( direntries ); FS_Close( f ); return true; } } Mem_Free( direntries ); FS_Close( f ); return false; }
void HPAK_RemoveLump( const char *name, resource_t *resource ) { string read_path; string save_path; file_t *f1, *f2; hpak_container_t hpak_read; hpak_container_t hpak_save; int i, j; if( !name || !name[0] || !resource ) return; HPAK_FlushHostQueue(); Q_strncpy( read_path, name, sizeof( read_path )); FS_StripExtension( read_path ); FS_DefaultExtension( read_path, ".hpk" ); f1 = FS_Open( read_path, "rb", false ); if( !f1 ) { MsgDev( D_ERROR, "HPAK_RemoveLump: %s couldn't open.\n", read_path ); return; } Q_strncpy( save_path, read_path, sizeof( save_path )); FS_StripExtension( save_path ); FS_DefaultExtension( save_path, ".hp2" ); f2 = FS_Open( save_path, "w+b", false ); if( !f2 ) { MsgDev( D_ERROR, "HPAK_RemoveLump: %s couldn't open.\n", save_path ); FS_Close( f1 ); return; } FS_Seek( f1, 0, SEEK_SET ); FS_Seek( f2, 0, SEEK_SET ); // header copy FS_Read( f1, &hash_pack_header, sizeof( hpak_header_t )); FS_Write( f2, &hash_pack_header, sizeof( hpak_header_t )); if( hash_pack_header.ident != IDCUSTOMHEADER || hash_pack_header.version != IDCUSTOM_VERSION ) { MsgDev( D_ERROR, "HPAK_RemoveLump: %s has invalid header.\n", read_path ); FS_Close( f1 ); FS_Close( f2 ); FS_Delete( save_path ); // delete temp file return; } FS_Seek( f1, hash_pack_header.seek, SEEK_SET ); FS_Read( f1, &hpak_read.count, sizeof( hpak_read.count )); if( hpak_read.count < 1 || hpak_read.count > MAX_FILES_IN_WAD ) { MsgDev( D_ERROR, "HPAK_RemoveLump: %s has invalid number of lumps.\n", read_path ); FS_Close( f1 ); FS_Close( f2 ); FS_Delete( save_path ); // delete temp file return; } if( hpak_read.count == 1 ) { MsgDev( D_ERROR, "HPAK_RemoveLump: %s only has one element, so it's not deleted.\n", read_path ); FS_Close( f1 ); FS_Close( f2 ); FS_Delete( read_path ); FS_Delete( save_path ); return; } hpak_save.count = hpak_read.count - 1; hpak_read.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak_read.count ); hpak_save.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak_save.count ); FS_Read( f1, hpak_read.dirs, sizeof( hpak_dir_t ) * hpak_read.count ); if( !HPAK_FindResource( &hpak_read, resource->rgucMD5_hash, NULL )) { MsgDev( D_ERROR, "HPAK_RemoveLump: Couldn't find the lump %s in hpak %s.n", resource->szFileName, read_path ); Mem_Free( hpak_read.dirs ); Mem_Free( hpak_save.dirs ); FS_Close( f1 ); FS_Close( f2 ); FS_Delete( save_path ); return; } MsgDev( D_INFO, "Removing lump %s from %s.\n", resource->szFileName, read_path ); // If there's a collision, we've just corrupted this hpak. for( i = 0, j = 0; i < hpak_read.count; i++ ) { if( !Q_memcmp( hpak_read.dirs[i].DirectoryResource.rgucMD5_hash, resource->rgucMD5_hash, 16 )) continue; hpak_save.dirs[j] = hpak_read.dirs[i]; hpak_save.dirs[j].seek = FS_Tell( f2 ); FS_Seek( f1, hpak_read.dirs[j].seek, SEEK_SET ); HPAK_FileCopy( f2, f1, hpak_save.dirs[j].size ); j++; } hash_pack_header.seek = FS_Tell( f2 ); FS_Write( f2, &hpak_save.count, ( hpak_save.count )); for( i = 0; i < hpak_save.count; i++ ) { FS_Write( f2, &hpak_save.dirs[i], sizeof( hpak_dir_t )); } FS_Seek( f2, 0, SEEK_SET ); FS_Write( f2, &hash_pack_header, sizeof( hpak_header_t )); Mem_Free( hpak_read.dirs ); Mem_Free( hpak_save.dirs ); FS_Close( f1 ); FS_Close( f2 ); FS_Delete( read_path ); FS_Rename( save_path, read_path ); }
static qboolean HPAK_Validate( const char *filename, qboolean quiet ) { file_t *f; hpak_dir_t *dataDir; hpak_header_t hdr; byte *dataPak; int i, num_lumps; MD5Context_t MD5_Hash; string pakname; resource_t *pRes; char md5[16]; if( quiet ) HPAK_FlushHostQueue(); // not an error - just flush queue if( !filename || !*filename ) return true; Q_strncpy( pakname, filename, sizeof( pakname )); FS_StripExtension( pakname ); FS_DefaultExtension( pakname, ".hpk" ); f = FS_Open( pakname, "rb", false ); if( !f ) { MsgDev( D_INFO, "Couldn't find %s.\n", pakname ); return true; } if( !quiet ) MsgDev( D_INFO, "Validating %s\n", pakname ); FS_Read( f, &hdr, sizeof( hdr )); if( hdr.ident != IDCUSTOMHEADER || hdr.version != IDCUSTOM_VERSION ) { MsgDev( D_ERROR, "HPAK_ValidatePak: %s does not have a valid HPAK header.\n", pakname ); FS_Close( f ); return false; } FS_Seek( f, hdr.seek, SEEK_SET ); FS_Read( f, &num_lumps, sizeof( num_lumps )); if( num_lumps < 1 || num_lumps > MAX_FILES_IN_WAD ) { MsgDev( D_ERROR, "HPAK_ValidatePak: %s has too many lumps %u.\n", pakname, num_lumps ); FS_Close( f ); return false; } if( !quiet ) MsgDev( D_INFO, "# of Entries: %i\n", num_lumps ); dataDir = Z_Malloc( sizeof( hpak_dir_t ) * num_lumps ); FS_Read( f, dataDir, sizeof( hpak_dir_t ) * num_lumps ); if( !quiet ) MsgDev( D_INFO, "# Type Size FileName : MD5 Hash\n" ); for( i = 0; i < num_lumps; i++ ) { if( dataDir[i].size < 1 || dataDir[i].size > 131071 ) { // odd max size MsgDev( D_ERROR, "HPAK_ValidatePak: lump %i has invalid size %s\n", i, Q_pretifymem( dataDir[i].size, 2 )); Mem_Free( dataDir ); FS_Close(f); return false; } dataPak = Z_Malloc( dataDir[i].size ); FS_Seek( f, dataDir[i].seek, SEEK_SET ); FS_Read( f, dataPak, dataDir[i].size ); Q_memset( &MD5_Hash, 0, sizeof( MD5Context_t )); MD5Init( &MD5_Hash ); MD5Update( &MD5_Hash, dataPak, dataDir[i].size ); MD5Final( md5, &MD5_Hash ); pRes = &dataDir[i].DirectoryResource; MsgDev( D_INFO, "%i: %s %s %s: ", i, HPAK_TypeFromIndex( pRes->type ), Q_pretifymem( pRes->nDownloadSize, 2 ), pRes->szFileName ); if( Q_memcmp( md5, pRes->rgucMD5_hash, 0x10 )) { if( quiet ) { MsgDev( D_ERROR, "HPAK_ValidatePak: %s has invalid checksum.\n", pakname ); Mem_Free( dataPak ); Mem_Free( dataDir ); FS_Close( f ); return false; } else MsgDev( D_INFO, "failed\n" ); } else { if( !quiet ) MsgDev( D_INFO, "OK\n" ); } // at this point, it's passed our checks. Mem_Free( dataPak ); } Mem_Free( dataDir ); FS_Close( f ); return true; }
qboolean HPAK_ResourceForHash( const char *filename, char *inHash, resource_t *pRes ) { file_t *f; hpak_t *hpak; hpak_container_t hpakcontainer; hpak_header_t hdr; string pakname; int ret; if( !filename || !filename[0] ) return false; for( hpak = hpak_queue; hpak != NULL; hpak = hpak->next ) { if( !Q_stricmp( hpak->name, filename ) && !Q_memcmp( hpak->HpakResource.rgucMD5_hash, inHash, 0x10 )) { if( pRes != NULL ) *pRes = hpak->HpakResource; return true; } } Q_strncpy( pakname, filename, sizeof( pakname )); FS_StripExtension( pakname ); FS_DefaultExtension( pakname, ".hpk" ); f = FS_Open( pakname, "rb", false ); if( !f ) return false; FS_Read( f, &hdr, sizeof( hdr )); if( hdr.ident != IDCUSTOMHEADER ) { MsgDev( D_ERROR, "HPAK_ResourceForHash: %s it's not a HPK file.\n", pakname ); FS_Close( f ); return false; } if( hdr.version != IDCUSTOM_VERSION ) { MsgDev( D_ERROR, "HPAK_ResourceForHash: %s has invalid version (%i should be %i).\n", pakname, hdr.version, IDCUSTOM_VERSION ); FS_Close( f ); return false; } FS_Seek( f, hdr.seek, SEEK_SET ); FS_Read( f, &hpakcontainer.count, sizeof( hpakcontainer.count )); if( hpakcontainer.count < 1 || hpakcontainer.count > MAX_FILES_IN_WAD ) { MsgDev( D_ERROR, "HPAK_ResourceForHash: %s has too many lumps %u.\n", pakname, hpakcontainer.count ); FS_Close( f ); return false; } hpakcontainer.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpakcontainer.count ); FS_Read( f, hpakcontainer.dirs, sizeof( hpak_dir_t ) * hpakcontainer.count ); ret = HPAK_FindResource( &hpakcontainer, inHash, pRes ); Mem_Free( hpakcontainer.dirs ); FS_Close( f ); return(ret); }
void HPAK_AddLump( qboolean add_to_queue, const char *name, resource_t *DirEnt, byte *data, file_t *f ) { int i, position, length; string pakname1, pakname2; char md5[16]; MD5Context_t MD5_Hash; hpak_container_t hpak1, hpak2; file_t *f1, *f2; hpak_dir_t *dirs; byte *temp; if( !name || !name[0] ) { MsgDev( D_ERROR, "HPAK_AddLump: NULL name\n" ); return; } if( !DirEnt ) { MsgDev( D_ERROR, "HPAK_AddLump: invalid lump\n" ); return; } if( data == NULL && f == NULL ) { MsgDev( D_ERROR, "HPAK_AddLump: missing lump data\n" ); return; } if( DirEnt->nDownloadSize < 1024 || DirEnt->nDownloadSize > 131072 ) { MsgDev( D_ERROR, "HPAK_AddLump: invalid size %s\n", Q_pretifymem( DirEnt->nDownloadSize, 2 )); return; } // hash it Q_memset( &MD5_Hash, 0, sizeof( MD5Context_t )); MD5Init( &MD5_Hash ); if( data == NULL ) { // there are better ways position = FS_Tell( f ); temp = Z_Malloc( DirEnt->nDownloadSize ); FS_Read( f, temp, DirEnt->nDownloadSize ); FS_Seek( f, position, SEEK_SET ); MD5Update( &MD5_Hash, temp, DirEnt->nDownloadSize ); Mem_Free( temp ); } else { MD5Update( &MD5_Hash, data, DirEnt->nDownloadSize ); } MD5Final( md5, &MD5_Hash ); if( Q_memcmp( md5, DirEnt->rgucMD5_hash, 0x10 )) { MsgDev( D_ERROR, "HPAK_AddLump: bad checksum for %s. Ignored\n", DirEnt->szFileName ); return; } if( add_to_queue ) { HPAK_AddToQueue( name, DirEnt, data, f ); return; } Q_strncpy( pakname1, name, sizeof( pakname1 )); FS_StripExtension( pakname1 ); FS_DefaultExtension( pakname1, ".hpk" ); f1 = FS_Open( pakname1, "rb", false ); if( !f1 ) { // create new pack HPAK_CreatePak( name, DirEnt, data, f ); return; } Q_strncpy( pakname2, pakname1, sizeof( pakname2 )); FS_StripExtension( pakname2 ); FS_DefaultExtension( pakname2, ".hp2" ); f2 = FS_Open( pakname2, "w+b", false ); if( !f2 ) { MsgDev( D_ERROR, "HPAK_AddLump: couldn't open %s.\n", pakname2 ); FS_Close( f1 ); return; } // load headers FS_Read( f1, &hash_pack_header, sizeof( hpak_header_t )); if( hash_pack_header.version != IDCUSTOM_VERSION ) { // we don't check the HPAK bit for some reason. MsgDev( D_ERROR, "HPAK_AddLump: %s does not have a valid header.\n", pakname2 ); FS_Close( f1 ); FS_Close( f2 ); } length = FS_FileLength( f1 ); HPAK_FileCopy( f2, f1, length ); FS_Seek( f1, hash_pack_header.seek, SEEK_SET ); FS_Read( f1, &hpak1.count, sizeof( hpak1.count )); if( hpak1.count < 1 || hpak1.count > MAX_FILES_IN_WAD ) { MsgDev( D_ERROR, "HPAK_AddLump: %s contain too many lumps.\n", pakname1 ); FS_Close( f1 ); FS_Close( f2 ); return; } // load the data hpak1.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak1.count ); FS_Read( f1, hpak1.dirs, sizeof( hpak_dir_t ) * hpak1.count ); FS_Close( f1 ); if( HPAK_FindResource( &hpak1, DirEnt->rgucMD5_hash, NULL )) { Mem_Free( hpak1.dirs ); FS_Close( f2 ); } // make a new container hpak2.count = hpak1.count; hpak2.dirs = Z_Malloc( sizeof( hpak_dir_t ) * hpak2.count ); Q_memcpy( hpak2.dirs, hpak1.dirs, hpak1.count ); for( i = 0, dirs = NULL; i < hpak1.count; i++ ) { if( Q_memcmp( hpak1.dirs[i].DirectoryResource.rgucMD5_hash, DirEnt->rgucMD5_hash, 16 ) < 0 ) { dirs = &hpak1.dirs[i]; while( i < hpak1.count ) { hpak2.dirs[i+1] = hpak1.dirs[i]; i++; } break; } } if( dirs == NULL ) dirs = &hpak2.dirs[hpak2.count-1]; Q_memset( dirs, 0, sizeof( hpak_dir_t )); FS_Seek( f2, hash_pack_header.seek, SEEK_SET ); dirs->DirectoryResource = *DirEnt; dirs->seek = FS_Tell( f2 ); dirs->size = DirEnt->nDownloadSize; if( !data ) HPAK_FileCopy( f2, f, dirs->size ); else FS_Write( f2, data, dirs->size ); hash_pack_header.seek = FS_Tell( f2 ); FS_Write( f2, &hpak2.count, sizeof( hpak2.count )); for( i = 0; i < hpak2.count; i++ ) { FS_Write( f2, &hpak2.dirs[i], sizeof( hpak_dir_t )); } // finalize Mem_Free( hpak1.dirs ); Mem_Free( hpak2.dirs ); FS_Seek( f2, 0, SEEK_SET ); FS_Write( f2, &hash_pack_header, sizeof( hpak_header_t )); FS_Close( f2 ); FS_Delete( pakname1 ); FS_Rename( pakname2, pakname1 ); }
//========================================================= //========================================================= void CTeamplayRules::RecountTeams( void ) { char *pName; char teamlist[TEAMPLAY_TEAMLISTLENGTH]; // loop through all teams, recounting everything num_teams = 0; // Copy all of the teams from the teamlist // make a copy because strtok is destructive Q_strncpy( teamlist, m_szTeamList, sizeof(teamlist) ); pName = teamlist; pName = strtok( pName, ";" ); while ( pName != NULL && *pName ) { if ( GetTeamIndex( pName ) < 0 ) { Q_strncpy( team_names[num_teams], pName, sizeof(team_names[num_teams])); num_teams++; } pName = strtok( NULL, ";" ); } if ( num_teams < 2 ) { num_teams = 0; m_teamLimit = false; } // Sanity check memset( team_scores, 0, sizeof(team_scores) ); // loop through all clients for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = UTIL_PlayerByIndex( i ); if ( plr ) { const char *pTeamName = plr->TeamID(); // try add to existing team int tm = GetTeamIndex( pTeamName ); if ( tm < 0 ) // no team match found { if ( !m_teamLimit ) { // add to new team tm = num_teams; num_teams++; team_scores[tm] = 0; Q_strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH ); } } if ( tm >= 0 ) { team_scores[tm] += plr->FragCount(); } } } }
void CHL2MPScriptedWeapon::InitScriptedWeapon( void ) { #if defined ( LUA_SDK ) #ifndef CLIENT_DLL // Let the instance reinitialize itself for the client. if ( m_nTableReference != LUA_NOREF ) return; #endif char className[ MAX_WEAPON_STRING ]; #if defined ( CLIENT_DLL ) if ( strlen( GetScriptedClassname() ) > 0 ) Q_strncpy( className, GetScriptedClassname(), sizeof( className ) ); else Q_strncpy( className, GetClassname(), sizeof( className ) ); #else Q_strncpy( m_iScriptedClassname.GetForModify(), GetClassname(), sizeof( className ) ); Q_strncpy( className, GetClassname(), sizeof( className ) ); #endif Q_strlower( className ); // Andrew; This redundancy is pretty annoying. // Classname Q_strncpy( m_pLuaWeaponInfo->szClassName, className, MAX_WEAPON_STRING ); SetClassname( className ); lua_getglobal( L, "weapon" ); if ( lua_istable( L, -1 ) ) { lua_getfield( L, -1, "get" ); if ( lua_isfunction( L, -1 ) ) { lua_remove( L, -2 ); lua_pushstring( L, className ); luasrc_pcall( L, 1, 1, 0 ); } else { lua_pop( L, 2 ); } } else { lua_pop( L, 1 ); } m_nTableReference = luaL_ref( L, LUA_REGISTRYINDEX ); #ifndef CLIENT_DLL m_pLuaWeaponInfo->bParsedScript = true; #endif // Printable name lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "printname" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { Q_strncpy( m_pLuaWeaponInfo->szPrintName, lua_tostring( L, -1 ), MAX_WEAPON_STRING ); } else { Q_strncpy( m_pLuaWeaponInfo->szPrintName, WEAPON_PRINTNAME_MISSING, MAX_WEAPON_STRING ); } lua_pop( L, 1 ); // View model & world model lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "viewmodel" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { Q_strncpy( m_pLuaWeaponInfo->szViewModel, lua_tostring( L, -1 ), MAX_WEAPON_STRING ); } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "playermodel" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { Q_strncpy( m_pLuaWeaponInfo->szWorldModel, lua_tostring( L, -1 ), MAX_WEAPON_STRING ); } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "anim_prefix" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { Q_strncpy( m_pLuaWeaponInfo->szAnimationPrefix, lua_tostring( L, -1 ), MAX_WEAPON_PREFIX ); } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "bucket" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iSlot = lua_tonumber( L, -1 ); } else { m_pLuaWeaponInfo->iSlot = 0; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "bucket_position" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iPosition = lua_tonumber( L, -1 ); } else { m_pLuaWeaponInfo->iPosition = 0; } lua_pop( L, 1 ); // Use the console (X360) buckets if hud_fastswitch is set to 2. #ifdef CLIENT_DLL if ( hud_fastswitch.GetInt() == 2 ) #else if ( IsX360() ) #endif { lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "bucket_360" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iSlot = lua_tonumber( L, -1 ); } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "bucket_position_360" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iPosition = lua_tonumber( L, -1 ); } lua_pop( L, 1 ); } lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "clip_size" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iMaxClip1 = lua_tonumber( L, -1 ); // Max primary clips gun can hold (assume they don't use clips by default) } else { m_pLuaWeaponInfo->iMaxClip1 = WEAPON_NOCLIP; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "clip2_size" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iMaxClip2 = lua_tonumber( L, -1 ); // Max secondary clips gun can hold (assume they don't use clips by default) } else { m_pLuaWeaponInfo->iMaxClip2 = WEAPON_NOCLIP; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "default_clip" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iDefaultClip1 = lua_tonumber( L, -1 ); // amount of primary ammo placed in the primary clip when it's picked up } else { m_pLuaWeaponInfo->iDefaultClip1 = m_pLuaWeaponInfo->iMaxClip1; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "default_clip2" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iDefaultClip2 = lua_tonumber( L, -1 ); // amount of secondary ammo placed in the secondary clip when it's picked up } else { m_pLuaWeaponInfo->iDefaultClip2 = m_pLuaWeaponInfo->iMaxClip2; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "weight" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iWeight = lua_tonumber( L, -1 ); } else { m_pLuaWeaponInfo->iWeight = 0; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "rumble" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->iWeight = lua_tonumber( L, -1 ); } else { m_pLuaWeaponInfo->iWeight = -1; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "showusagehint" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->bShowUsageHint = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->bShowUsageHint = false; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "autoswitchto" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->bAutoSwitchTo = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->bAutoSwitchTo = true; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "autoswitchfrom" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->bAutoSwitchFrom = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->bAutoSwitchFrom = true; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "BuiltRightHanded" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->m_bBuiltRightHanded = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->m_bBuiltRightHanded = true; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "AllowFlipping" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->m_bAllowFlipping = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->m_bAllowFlipping = true; } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "MeleeWeapon" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->m_bMeleeWeapon = (int)lua_tointeger( L, -1 ) != 0 ? true : false; } else { m_pLuaWeaponInfo->m_bMeleeWeapon = false; } lua_pop( L, 1 ); // Primary ammo used lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "primary_ammo" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { const char *pAmmo = lua_tostring( L, -1 ); if ( strcmp("None", pAmmo) == 0 ) Q_strncpy( m_pLuaWeaponInfo->szAmmo1, "", sizeof( m_pLuaWeaponInfo->szAmmo1 ) ); else Q_strncpy( m_pLuaWeaponInfo->szAmmo1, pAmmo, sizeof( m_pLuaWeaponInfo->szAmmo1 ) ); m_pLuaWeaponInfo->iAmmoType = GetAmmoDef()->Index( m_pLuaWeaponInfo->szAmmo1 ); } lua_pop( L, 1 ); // Secondary ammo used lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "secondary_ammo" ); lua_remove( L, -2 ); if ( lua_isstring( L, -1 ) ) { const char *pAmmo = lua_tostring( L, -1 ); if ( strcmp("None", pAmmo) == 0) Q_strncpy( m_pLuaWeaponInfo->szAmmo2, "", sizeof( m_pLuaWeaponInfo->szAmmo2 ) ); else Q_strncpy( m_pLuaWeaponInfo->szAmmo2, pAmmo, sizeof( m_pLuaWeaponInfo->szAmmo2 ) ); m_pLuaWeaponInfo->iAmmo2Type = GetAmmoDef()->Index( m_pLuaWeaponInfo->szAmmo2 ); } lua_pop( L, 1 ); // Now read the weapon sounds memset( m_pLuaWeaponInfo->aShootSounds, 0, sizeof( m_pLuaWeaponInfo->aShootSounds ) ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "SoundData" ); lua_remove( L, -2 ); if ( lua_istable( L, -1 ) ) { for ( int i = EMPTY; i < NUM_SHOOT_SOUND_TYPES; i++ ) { lua_getfield( L, -1, pWeaponSoundCategories[i] ); if ( lua_isstring( L, -1 ) ) { const char *soundname = lua_tostring( L, -1 ); if ( soundname && soundname[0] ) { Q_strncpy( m_pLuaWeaponInfo->aShootSounds[i], soundname, MAX_WEAPON_STRING ); } } lua_pop( L, 1 ); } } lua_pop( L, 1 ); lua_getref( L, m_nTableReference ); lua_getfield( L, -1, "damage" ); lua_remove( L, -2 ); if ( lua_isnumber( L, -1 ) ) { m_pLuaWeaponInfo->m_iPlayerDamage = (int)lua_tointeger( L, -1 ); } lua_pop( L, 1 ); BEGIN_LUA_CALL_WEAPON_METHOD( "Initialize" ); END_LUA_CALL_WEAPON_METHOD( 0, 0 ); #endif }
/* ==================== CL_WriteDemoHeader Write demo header ==================== */ void CL_WriteDemoHeader( const char *name ) { fs_offset_t copysize; fs_offset_t savepos; fs_offset_t curpos; MsgDev( D_INFO, "recording to %s.\n", name ); cls.demofile = FS_Open( name, "wb", false ); cls.demotime = 0.0; if( !cls.demofile ) { MsgDev( D_ERROR, "couldn't open %s.\n", name ); return; } cls.demorecording = true; cls.demowaiting = true; // don't start saving messages until a non-delta compressed message is received Q_memset( &demo.header, 0, sizeof( demo.header )); demo.header.id = IDEMOHEADER; demo.header.dem_protocol = DEMO_PROTOCOL; demo.header.net_protocol = PROTOCOL_VERSION; Q_strncpy( demo.header.mapname, clgame.mapname, sizeof( demo.header.mapname )); Q_strncpy( demo.header.gamedir, FS_Gamedir(), sizeof( demo.header.gamedir )); // write header FS_Write( cls.demofile, &demo.header, sizeof( demo.header )); demo.directory.numentries = 2; demo.directory.entries = Mem_Alloc( cls.mempool, sizeof( demoentry_t ) * demo.directory.numentries ); // DIRECTORY ENTRY # 0 demo.entry = &demo.directory.entries[0]; // only one here. demo.entry->entrytype = DEMO_STARTUP; demo.entry->playback_time = 0.0f; // startup takes 0 time. demo.entry->offset = FS_Tell( cls.demofile ); // position for this chunk. // finish off the startup info. CL_WriteDemoCmdHeader( dem_stop, cls.demoheader ); // now copy the stuff we cached from the server. copysize = savepos = FS_Tell( cls.demoheader ); FS_Seek( cls.demoheader, 0, SEEK_SET ); FS_FileCopy( cls.demofile, cls.demoheader, copysize ); // jump back to end, in case we record another demo for this session. FS_Seek( cls.demoheader, savepos, SEEK_SET ); demo.starttime = CL_GetDemoRecordClock(); // setup the demo starttime demo.realstarttime = demo.starttime; demo.framecount = 0; // now move on to entry # 1, the first data chunk. curpos = FS_Tell( cls.demofile ); demo.entry->length = curpos - demo.entry->offset; // now we are writing the first real lump. demo.entry = &demo.directory.entries[1]; // first real data lump demo.entry->entrytype = DEMO_NORMAL; demo.entry->playback_time = 0.0f; // startup takes 0 time. demo.entry->offset = FS_Tell( cls.demofile ); // demo playback should read this as an incoming message. // write the client's realtime value out so we can synchronize the reads. CL_WriteDemoCmdHeader( dem_jumptime, cls.demofile ); if( clgame.hInstance ) clgame.dllFuncs.pfnReset(); Cbuf_InsertText( "fullupdate\n" ); Cbuf_Execute(); }
void HPAK_CreatePak( const char *filename, resource_t *DirEnt, byte *data, file_t *f ) { int filelocation; string pakname; char md5[16]; char *temp; MD5Context_t MD5_Hash; file_t *fout; if( !filename || !filename[0] ) { MsgDev( D_ERROR, "HPAK_CreatePak: NULL name\n" ); return; } if(( f != NULL && data != NULL ) || ( f == NULL && data == NULL )) { MsgDev( D_ERROR, "HPAK_CreatePak: too many sources, please leave one.\n" ); return; } Q_strncpy( pakname, filename, sizeof( pakname )); FS_StripExtension( pakname ); FS_DefaultExtension( pakname, ".hpk" ); MsgDev( D_INFO, "creating HPAK %s.\n", pakname ); fout = FS_Open( pakname, "wb", false ); if( !fout ) { MsgDev( D_ERROR, "HPAK_CreatePak: can't write %s.\n", pakname ); return; } // let's hash it. Q_memset( &MD5_Hash, 0, sizeof( MD5Context_t )); MD5Init( &MD5_Hash ); if( data == NULL ) { // there are better ways filelocation = FS_Tell( f ); temp = Z_Malloc( DirEnt->nDownloadSize ); FS_Read( f, temp, DirEnt->nDownloadSize ); FS_Seek( f, filelocation, SEEK_SET ); MD5Update( &MD5_Hash, temp, DirEnt->nDownloadSize ); Mem_Free( temp ); } else { MD5Update( &MD5_Hash, data, DirEnt->nDownloadSize ); } MD5Final( md5, &MD5_Hash ); if( Q_memcmp( md5, DirEnt->rgucMD5_hash, 16 )) { MsgDev( D_ERROR, "HPAK_CreatePak: bad checksum for %s. Ignored\n", pakname ); return; } hash_pack_header.ident = IDCUSTOMHEADER; hash_pack_header.version = IDCUSTOM_VERSION; hash_pack_header.seek = 0; FS_Write( fout, &hash_pack_header, sizeof( hash_pack_header )); hash_pack_dir.count = 1; hash_pack_dir.dirs = Z_Malloc( sizeof( hpak_dir_t )); hash_pack_dir.dirs[0].DirectoryResource = *DirEnt; hash_pack_dir.dirs[0].seek = FS_Tell( fout ); hash_pack_dir.dirs[0].size = DirEnt->nDownloadSize; if( data == NULL ) { HPAK_FileCopy( fout, f, hash_pack_dir.dirs[0].size ); } else { FS_Write( fout, data, hash_pack_dir.dirs[0].size ); } filelocation = FS_Tell( fout ); FS_Write( fout, &hash_pack_dir.count, sizeof( hash_pack_dir.count )); FS_Write( fout, &hash_pack_dir.dirs[0], sizeof( hpak_dir_t )); Mem_Free( hash_pack_dir.dirs ); Q_memset( &hash_pack_dir, 0, sizeof( hpak_container_t )); hash_pack_header.seek = filelocation; FS_Seek( fout, 0, SEEK_SET ); FS_Write( fout, &hash_pack_header, sizeof( hpak_header_t )); FS_Close( fout ); }
/* ================== CL_GetComment ================== */ qboolean CL_GetComment( const char *demoname, char *comment ) { file_t *demfile; demoheader_t demohdr; demodirectory_t directory; demoentry_t entry; float playtime = 0.0f; int i; if( !comment ) return false; demfile = FS_Open( demoname, "rb", false ); if( !demfile ) { Q_strncpy( comment, "", MAX_STRING ); return false; } // read in the m_DemoHeader FS_Read( demfile, &demohdr, sizeof( demoheader_t )); if( demohdr.id != IDEMOHEADER ) { FS_Close( demfile ); Q_strncpy( comment, "<corrupted>", MAX_STRING ); return false; } if( demohdr.net_protocol != PROTOCOL_VERSION || demohdr.dem_protocol != DEMO_PROTOCOL ) { FS_Close( demfile ); Q_strncpy( comment, "<invalid protocol>", MAX_STRING ); return false; } // now read in the directory structure. FS_Seek( demfile, demohdr.directory_offset, SEEK_SET ); FS_Read( demfile, &directory.numentries, sizeof( int )); if( directory.numentries < 1 || directory.numentries > 1024 ) { FS_Close( demfile ); Q_strncpy( comment, "<corrupted>", MAX_STRING ); return false; } for( i = 0; i < directory.numentries; i++ ) { FS_Read( demfile, &entry, sizeof( demoentry_t )); playtime += entry.playback_time; } // split comment to sections Q_strncpy( comment, demohdr.mapname, CS_SIZE ); Q_strncpy( comment + CS_SIZE, "<No Title>", CS_SIZE ); // TODO: write titles or somewhat Q_strncpy( comment + CS_SIZE * 2, va( "%g sec", playtime ), CS_TIME ); // all done FS_Close( demfile ); return true; }
qboolean Field_Key( menufield_s *f, int key ) { switch ( key ) { case K_KP_SLASH: key = '/'; break; case K_KP_MINUS: key = '-'; break; case K_KP_PLUS: key = '+'; break; case K_KP_HOME: key = '7'; break; case K_KP_UPARROW: key = '8'; break; case K_KP_PGUP: key = '9'; break; case K_KP_LEFTARROW: key = '4'; break; case K_KP_5: key = '5'; break; case K_KP_RIGHTARROW: key = '6'; break; case K_KP_END: key = '1'; break; case K_KP_DOWNARROW: key = '2'; break; case K_KP_PGDN: key = '3'; break; case K_KP_INS: key = '0'; break; case K_KP_DEL: key = '.'; break; } if ( key > 127 ) { switch ( key ) { case K_DEL: default: return false; } } /* ** support pasting from the clipboard */ if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) || ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) ) { char *cbd; if ( ( cbd = Sys_GetClipboardData() ) != 0 ) { strtok( cbd, "\n\r\b" ); Q_strncpy (f->buffer, cbd, sizeof(f->buffer)-1); f->cursor = (int)strlen( f->buffer ); f->visible_offset = f->cursor - f->visible_length; if ( f->visible_offset < 0 ) f->visible_offset = 0; free( cbd ); } return true; } switch ( key ) { case K_KP_LEFTARROW: case K_LEFTARROW: case K_BACKSPACE: if ( f->cursor > 0 ) { memmove( &f->buffer[f->cursor-1], &f->buffer[f->cursor], strlen( &f->buffer[f->cursor] ) + 1 ); f->cursor--; if ( f->visible_offset ) { f->visible_offset--; } } break; case K_KP_DEL: case K_DEL: memmove( &f->buffer[f->cursor], &f->buffer[f->cursor+1], strlen( &f->buffer[f->cursor+1] ) + 1 ); break; case K_KP_ENTER: case K_ENTER: case K_ESCAPE: case K_TAB: return false; case K_SPACE: default: if (( f->generic.flags & QMF_NUMBERSONLY ) && !isdigit( key ) && key != '.' ) return false; if ( f->cursor < f->length ) { f->buffer[f->cursor++] = key; f->buffer[f->cursor] = 0; if ( f->cursor > f->visible_length ) { f->visible_offset++; } } } return true; }
bool ReadFromBuffer(CNetBuffer &apBuffer) { Q_strncpy(msConVarName, apBuffer->ReadString(), sizeof(msConVarName)); msConVarName[sizeof(msConVarName) - 1] = '\0'; return true; };
static qsocket_t *_Datagram_Connect (char *host) { struct qsockaddr sendaddr; struct qsockaddr readaddr; qsocket_t *sock; int newsock; int ret; int reps; double start_time; int control; char *reason; // see if we can resolve the host name if (dfunc.GetAddrFromName(host, &sendaddr) == -1) return NULL; newsock = dfunc.OpenSocket (0); if (newsock == -1) return NULL; sock = NET_NewQSocket (); if (sock == NULL) goto ErrorReturn2; sock->socket = newsock; sock->landriver = net_landriverlevel; // connect to the host if (dfunc.Connect (newsock, &sendaddr) == -1) goto ErrorReturn; // send the connection request Con_Printf("trying...\n"); SCR_UpdateScreen (); start_time = net_time; for (reps = 0; reps < 3; reps++) { SZ_Clear(&net_message); // save space for the header, filled in later MSG_WriteLong(&net_message, 0); MSG_WriteByte(&net_message, CCREQ_CONNECT); MSG_WriteString(&net_message, "QUAKE"); MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION); *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK)); dfunc.Write (newsock, net_message.data, net_message.cursize, &sendaddr); SZ_Clear(&net_message); do { ret = dfunc.Read (newsock, net_message.data, net_message.maxsize, &readaddr); // if we got something, validate it if (ret > 0) { // is it from the right place? if (sfunc.AddrCompare(&readaddr, &sendaddr) != 0) { #ifdef DEBUG Con_Printf("wrong reply address\n"); Con_Printf("Expected: %s\n", StrAddr (&sendaddr)); Con_Printf("Received: %s\n", StrAddr (&readaddr)); SCR_UpdateScreen (); #endif ret = 0; continue; } if (ret < sizeof(int)) { ret = 0; continue; } net_message.cursize = ret; MSG_BeginReading (); control = BigLong(*((int *)net_message.data)); MSG_ReadLong(); if (control == -1) { ret = 0; continue; } if ((control & (~NETFLAG_LENGTH_MASK)) != NETFLAG_CTL) { ret = 0; continue; } if ((control & NETFLAG_LENGTH_MASK) != ret) { ret = 0; continue; } } } while (ret == 0 && (SetNetTime() - start_time) < 2.5); if (ret) break; Con_Printf("still trying...\n"); SCR_UpdateScreen (); start_time = SetNetTime(); } if (ret == 0) { reason = "No Response"; Con_Printf("%s\n", reason); Q_strcpy(m_return_reason, reason); goto ErrorReturn; } if (ret == -1) { reason = "Network Error"; Con_Printf("%s\n", reason); Q_strcpy(m_return_reason, reason); goto ErrorReturn; } ret = MSG_ReadByte(); if (ret == CCREP_REJECT) { reason = MSG_ReadString(); Con_Printf(reason); Q_strncpy(m_return_reason, reason, 31); goto ErrorReturn; } if (ret == CCREP_ACCEPT) { Q_memcpy(&sock->addr, &sendaddr, sizeof(struct qsockaddr)); dfunc.SetSocketPort (&sock->addr, MSG_ReadLong()); } else { reason = "Bad Response"; Con_Printf("%s\n", reason); Q_strcpy(m_return_reason, reason); goto ErrorReturn; } dfunc.GetNameFromAddr (&sendaddr, sock->address); Con_Printf ("Connection accepted\n"); sock->lastMessageTime = SetNetTime(); // switch the connection to the specified address if (dfunc.Connect (newsock, &sock->addr) == -1) { reason = "Connect to Game failed"; Con_Printf("%s\n", reason); Q_strcpy(m_return_reason, reason); goto ErrorReturn; } m_return_onerror = false; return sock; ErrorReturn: NET_FreeQSocket(sock); ErrorReturn2: dfunc.CloseSocket(newsock); if (m_return_onerror) { key_dest = key_menu; m_state = m_return_state; m_return_onerror = false; } return NULL; }
//----------------------------------------------------------------------------- // Purpose: loads per-map manifest! //----------------------------------------------------------------------------- void ParseParticleEffectsMap( const char *pMapName, bool bLoadSheets, IFileList *pFilesToReload ) { MEM_ALLOC_CREDIT(); CUtlVector<CUtlString> files; char szMapManifestFilename[MAX_PATH]; szMapManifestFilename[0] = NULL; if ( pMapName && *pMapName ) { V_snprintf( szMapManifestFilename, sizeof( szMapManifestFilename ), "maps/%s_particles.txt", pMapName ); } // Open the manifest file, and read the particles specified inside it KeyValues *manifest = new KeyValues( szMapManifestFilename ); if ( manifest->LoadFromFile( filesystem, szMapManifestFilename, "GAME" ) ) { DevMsg( "Successfully loaded particle effects manifest '%s' for map '%s'\n", szMapManifestFilename, pMapName ); for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() ) { if ( !Q_stricmp( sub->GetName(), "file" ) ) { // Ensure the particles are in the particles directory char szPath[ 512 ]; Q_strncpy( szPath, sub->GetString(), sizeof( szPath ) ); Q_StripFilename( szPath ); char *pszPath = (szPath[0] == '!') ? &szPath[1] : &szPath[0]; if ( pszPath && pszPath[0] && !Q_stricmp( pszPath, "particles" ) ) { files.AddToTail( sub->GetString() ); continue; } else { Warning( "CParticleMgr::LevelInit: Manifest '%s' contains a particle file '%s' that's not under the particles directory. Custom particles must be placed in the particles directory.\n", szMapManifestFilename, sub->GetString() ); } } else { Warning( "CParticleMgr::LevelInit: Manifest '%s' with bogus file type '%s', expecting 'file'\n", szMapManifestFilename, sub->GetName() ); } } } else { // Don't print a warning, and don't proceed any further if the file doesn't exist! return; } int nCount = files.Count(); if ( !nCount ) { return; } g_pParticleSystemMgr->ShouldLoadSheets( bLoadSheets ); for ( int i = 0; i < nCount; ++i ) { // If we've been given a list of particles to reload, only reload those. if ( !pFilesToReload || (pFilesToReload && pFilesToReload->IsFileInList( files[i] )) ) { g_pParticleSystemMgr->ReadParticleConfigFile( files[i], true, true ); } } g_pParticleSystemMgr->DecommitTempMemory(); }
void C_SlideshowDisplay::BuildSlideShowImagesList( void ) { FileFindHandle_t matHandle; char szDirectory[_MAX_PATH]; char szMatFileName[_MAX_PATH] = {'\0'}; char szFileBuffer[ SLIDESHOW_LIST_BUFFER_MAX ]; char *pchCurrentLine = NULL; if ( IsX360() ) { Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/slides.txt", m_szSlideshowDirectory ); FileHandle_t fh = g_pFullFileSystem->Open( szDirectory, "rt" ); if ( !fh ) { DevWarning( "Couldn't read slideshow image file %s!", szDirectory ); return; } int iFileSize = MIN( g_pFullFileSystem->Size( fh ), SLIDESHOW_LIST_BUFFER_MAX ); int iBytesRead = g_pFullFileSystem->Read( szFileBuffer, iFileSize, fh ); g_pFullFileSystem->Close( fh ); // Ensure we don't write outside of our buffer if ( iBytesRead > iFileSize ) iBytesRead = iFileSize; szFileBuffer[ iBytesRead ] = '\0'; pchCurrentLine = szFileBuffer; // Seek to end of first line char *pchNextLine = pchCurrentLine; while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' ) ++pchNextLine; if ( *pchNextLine != '\0' ) { // Mark end of string *pchNextLine = '\0'; // Seek to start of next string ++pchNextLine; while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) ) ++pchNextLine; } Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) ); pchCurrentLine = pchNextLine; } else { Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/*.vmt", m_szSlideshowDirectory ); const char *pMatFileName = g_pFullFileSystem->FindFirst( szDirectory, &matHandle ); if ( pMatFileName ) Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) ); } int iSlideIndex = 0; while ( szMatFileName[ 0 ] ) { char szFileName[_MAX_PATH]; Q_snprintf( szFileName, sizeof( szFileName ), "vgui/%s/%s", m_szSlideshowDirectory, szMatFileName ); szFileName[ Q_strlen( szFileName ) - 4 ] = '\0'; int iMatIndex = ::GetMaterialIndex( szFileName ); // Get material keywords char szFullFileName[_MAX_PATH]; Q_snprintf( szFullFileName, sizeof( szFullFileName ), "materials/vgui/%s/%s", m_szSlideshowDirectory, szMatFileName ); KeyValues *pMaterialKeys = new KeyValues( "material" ); bool bLoaded = pMaterialKeys->LoadFromFile( g_pFullFileSystem, szFullFileName, NULL ); if ( bLoaded ) { char szKeywords[ 256 ]; Q_strcpy( szKeywords, pMaterialKeys->GetString( "%keywords", "" ) ); char *pchKeyword = szKeywords; while ( pchKeyword[ 0 ] != '\0' ) { char *pNextKeyword = pchKeyword; // Skip commas and spaces while ( pNextKeyword[ 0 ] != '\0' && pNextKeyword[ 0 ] != ',' ) ++pNextKeyword; if ( pNextKeyword[ 0 ] != '\0' ) { pNextKeyword[ 0 ] = '\0'; ++pNextKeyword; while ( pNextKeyword[ 0 ] != '\0' && ( pNextKeyword[ 0 ] == ',' || pNextKeyword[ 0 ] == ' ' ) ) ++pNextKeyword; } // Find the list with the current keyword int iList; for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList ) { if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword ) == 0 ) break; } if ( iList >= m_SlideMaterialLists.Count() ) { // Couldn't find the list, so create it iList = m_SlideMaterialLists.AddToTail( new SlideMaterialList_t ); Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword ); } // Add material index to this list m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex ); m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex ); pchKeyword = pNextKeyword; } } // Find the generic list int iList; for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList ) { if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" ) == 0 ) break; } if ( iList >= m_SlideMaterialLists.Count() ) { // Couldn't find the generic list, so create it iList = m_SlideMaterialLists.AddToHead( new SlideMaterialList_t ); Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" ); } // Add material index to this list m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex ); m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex ); if ( IsX360() ) { // Seek to end of first line char *pchNextLine = pchCurrentLine; while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' ) ++pchNextLine; if ( *pchNextLine != '\0' ) { // Mark end of string *pchNextLine = '\0'; // Seek to start of next string ++pchNextLine; while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) ) ++pchNextLine; } Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) ); pchCurrentLine = pchNextLine; } else { const char *pMatFileName = g_pFullFileSystem->FindNext( matHandle ); if ( pMatFileName ) Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) ); else szMatFileName[ 0 ] = '\0'; } ++iSlideIndex; } if ( !IsX360() ) { g_pFullFileSystem->FindClose( matHandle ); } }
/* <d4799> ../engine/net_ws.c:2076 */ void NET_GetLocalAddress(void) { char buff[512]; struct sockaddr_in address; int namelen; int net_error; Q_memset(&net_local_adr, 0, sizeof(netadr_t)); #ifdef _WIN32 Q_memset(&net_local_ipx_adr, 0, sizeof(netadr_t)); #endif // _WIN32 if (noip) { Con_Printf("TCP/IP Disabled.\n"); } else { if (Q_strcmp(ipname.string, "localhost")) Q_strncpy(buff, ipname.string, ARRAYSIZE(buff) - 1); else { #ifdef _WIN32 CRehldsPlatformHolder::get()->gethostname(buff, ARRAYSIZE(buff)); #else gethostname(buff, ARRAYSIZE(buff)); #endif // _WIN32 } buff[ARRAYSIZE(buff) - 1] = 0; #ifdef REHLDS_FIXES //check if address is valid if (NET_StringToAdr(buff, &net_local_adr)) { #else NET_StringToAdr(buff, &net_local_adr); #endif namelen = sizeof(address); #ifdef _WIN32 if (CRehldsPlatformHolder::get()->getsockname((SOCKET)ip_sockets[NS_SERVER], (struct sockaddr *)&address, (socklen_t *)&namelen) == SOCKET_ERROR) #else if (getsockname((SOCKET)ip_sockets[NS_SERVER], (struct sockaddr *)&address, (socklen_t *)&namelen) == SOCKET_ERROR) #endif // _WIN32 { noip = TRUE; #ifdef _WIN32 net_error = CRehldsPlatformHolder::get()->WSAGetLastError(); #else net_error = errno; #endif // _WIN32 Con_Printf("Could not get TCP/IP address, TCP/IP disabled\nReason: %s\n", NET_ErrorString(net_error)); } else { net_local_adr.port = address.sin_port; Con_Printf("Server IP address %s\n", NET_AdrToString(net_local_adr)); Cvar_Set("net_address", va(NET_AdrToString(net_local_adr))); } #ifdef REHLDS_FIXES } else { Con_Printf("Could not get TCP/IP address, Invalid hostname '%s'\n", buff); } #endif } #ifdef _WIN32 if (noipx) { Con_Printf("No IPX Support.\n"); } else { namelen = 14; if (CRehldsPlatformHolder::get()->getsockname(ipx_sockets[NS_SERVER], (struct sockaddr *)&address, (socklen_t *)&namelen) == SOCKET_ERROR) { noipx = TRUE; net_error = CRehldsPlatformHolder::get()->WSAGetLastError(); } else { SockadrToNetadr((struct sockaddr *)&address, &net_local_ipx_adr); Con_Printf("Server IPX address %s\n", NET_AdrToString(net_local_ipx_adr)); } } #endif //_WIN32 }
bool SharedDispatch( MessageBuffer *pBuf, int iSource, int iPacketID ) { char *pInPos = &pBuf->data[2]; switch ( pBuf->data[1] ) { case VMPI_SUBPACKETID_DIRECTORIES: { Q_strncpy( gamedir, pInPos, sizeof( gamedir ) ); pInPos += strlen( pInPos ) + 1; Q_strncpy( qdir, pInPos, sizeof( qdir ) ); g_bReceivedDirectoryInfo = true; } return true; case VMPI_SUBPACKETID_DBINFO: { g_DBInfo = *((CDBInfo*)pInPos); pInPos += sizeof( CDBInfo ); g_JobPrimaryID = *((unsigned long*)pInPos); g_bReceivedDBInfo = true; } return true; case VMPI_SUBPACKETID_CRASH: { char const chCrashInfoType = *pInPos; pInPos += 2; switch ( chCrashInfoType ) { case 't': Warning( "\nWorker '%s' dead: %s\n", VMPI_GetMachineName( iSource ), pInPos ); break; case 'f': { int iFileSize = * reinterpret_cast< int const * >( pInPos ); pInPos += sizeof( iFileSize ); // Temp folder char const *szFolder = NULL; if ( !szFolder ) szFolder = getenv( "TEMP" ); if ( !szFolder ) szFolder = getenv( "TMP" ); if ( !szFolder ) szFolder = "c:"; // Base module name char chModuleName[_MAX_PATH], *pModuleName = chModuleName; ::GetModuleFileName( NULL, chModuleName, sizeof( chModuleName ) / sizeof( chModuleName[0] ) ); if ( char *pch = strrchr( chModuleName, '.' ) ) *pch = 0; if ( char *pch = strrchr( chModuleName, '\\' ) ) *pch = 0, pModuleName = pch + 1; // Current time time_t currTime = ::time( NULL ); struct tm * pTime = ::localtime( &currTime ); // Number of minidumps this run static int s_numMiniDumps = 0; ++ s_numMiniDumps; // Prepare the filename char chSaveFileName[ 2 * _MAX_PATH ] = { 0 }; sprintf( chSaveFileName, "%s\\vmpi_%s_on_%s_%d%.2d%2d%.2d%.2d%.2d_%d.mdmp", szFolder, pModuleName, VMPI_GetMachineName( iSource ), pTime->tm_year + 1900, /* Year less 2000 */ pTime->tm_mon + 1, /* month (0 - 11 : 0 = January) */ pTime->tm_mday, /* day of month (1 - 31) */ pTime->tm_hour, /* hour (0 - 23) */ pTime->tm_min, /* minutes (0 - 59) */ pTime->tm_sec, /* seconds (0 - 59) */ s_numMiniDumps ); if ( FILE *fDump = fopen( chSaveFileName, "wb" ) ) { fwrite( pInPos, 1, iFileSize, fDump ); fclose( fDump ); Warning( "\nSaved worker crash minidump '%s', size %d byte(s).\n", chSaveFileName, iFileSize ); } else { Warning( "\nReceived worker crash minidump size %d byte(s), failed to save.\n", iFileSize ); } } break; } } return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: Draw function for the element //----------------------------------------------------------------------------- void CTargetID::Paint() { // No id if still choosing class if ( C_BaseTFPlayer::GetLocalPlayer()->GetClass() == TFCLASS_UNDECIDED ) return; // Get our target's ent index int iEntIndex = C_BaseTFPlayer::GetLocalPlayer()->GetIDTarget(); // Didn't find one? if ( !iEntIndex ) { // Check to see if we should clear our ID if ( m_flLastChangeTime && (gpGlobals->curtime > (m_flLastChangeTime + 0.5)) ) { m_flLastChangeTime = 0; m_sIDString[0] = 0; m_iLastEntIndex = 0; } else { // Keep re-using the old one iEntIndex = m_iLastEntIndex; } } else { m_flLastChangeTime = gpGlobals->curtime; } // Is this an entindex sent by the server? if ( iEntIndex ) { C_BaseTFPlayer *pPlayer = static_cast<C_BaseTFPlayer*>(cl_entitylist->GetEnt( iEntIndex )); C_BaseTFPlayer *pLocalPlayer = C_BaseTFPlayer::GetLocalPlayer(); // Some entities we always want to check, cause the text may change // even while we're looking at it // Is it a player? if ( IsPlayerIndex( iEntIndex ) ) { if ( pPlayer->InSameTeam(pLocalPlayer) ) { // Check distance to other player, and if the player is on the same team float flDistSq = pPlayer->GetRenderOrigin().DistToSqr( pLocalPlayer->GetRenderOrigin() ); if ( flDistSq < PLAYER_HINT_DISTANCE_SQ ) { Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nHealth: %.0f percent\nUse to donate resources", pPlayer->GetPlayerName(), ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) * 100 ); } else { Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nHealth: %.0f percent", pPlayer->GetPlayerName(), ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) * 100 ); } } else if (( pPlayer->GetHealth() == 0) && (pLocalPlayer->GetClass() == TFCLASS_INFILTRATOR) ) { Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nUse to disguise as this player", pPlayer->GetPlayerName() ); } else { m_sIDString[0] = 0; m_iLastEntIndex = 0; } } else { // Objects C_BaseEntity *pEnt = cl_entitylist->GetEnt( iEntIndex ); if ( !pEnt || !pEnt->InSameTeam(pLocalPlayer) ) { // This can happen because the object was destroyed m_sIDString[0] = 0; m_iLastEntIndex = 0; } else { // Don't check validity if it's sent by the server Q_strncpy( m_sIDString, pEnt->GetIDString(), sizeof(m_sIDString) ); m_iLastEntIndex = iEntIndex; } } } // Draw our ID string if ( m_sIDString[0] ) { int width, height; int ypos = YRES(300); // Messagechars can't handle multiple line strings, so parse out the \n's and give it one line at a time char *ch = m_sIDString; while ( *ch ) { // Find the next newline char *next_line; for ( next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ ) { } // Stomp the newline char *top = next_line; if ( *top == '\n' ) { *top = 0; } else { top = NULL; } // Draw the line messagechars->GetStringLength( m_hFont, &width, &height, ch ); messagechars->DrawString( m_hFont, (ScreenWidth() - width) / 2, ypos, 255, 255, 245, 255, ch, IMessageChars::MESSAGESTRINGID_NONE ); ypos += height; // Restore the newline if ( top ) { *top = '\n'; } // Move to the next line ch = next_line; if ( *ch == '\n' ) { ch++; } } } }
void CFlextalkActor::ProcessSceneEvents( void ) { if ( HasSceneEvents() ) { BaseClass::ProcessSceneEvents( ); return; } // only do this if they have more than eyelid movement if (GetNumFlexControllers() > 2) { const char *pszExpression = flex_expression.GetString(); if (pszExpression && pszExpression[0] == '+' && pszExpression[1] != '\0') { int i; int j = atoi( &pszExpression[1] ); for (i = 0; i < GetNumFlexControllers(); i++) { m_flextarget[m_flexnum] = 0; } for (i = 0; i < 35 && predef_flexcontroller_names[i]; i++) { m_flexnum = LookupFlex( predef_flexcontroller_names[i] ); m_flextarget[m_flexnum] = predef_flexcontroller_values[j][i]; // Msg( "%s %.3f\n", predef_flexcontroller_names[i], predef_flexcontroller_values[j][i] ); } } else if (pszExpression && pszExpression[0] != '\0' && strcmp(pszExpression, "+") != 0) { char szExpression[128]; char szTemp[32]; Q_strncpy( szExpression, pszExpression ,sizeof(szExpression)); char *pszExpression = szExpression; while (*pszExpression != '\0') { if (*pszExpression == '+') *pszExpression = ' '; pszExpression++; } pszExpression = szExpression; while (*pszExpression) { if (*pszExpression != ' ') { if (*pszExpression == '-') { for (LocalFlexController_t i = LocalFlexController_t(0); i < GetNumFlexControllers(); i++) { m_flextarget[i] = 0; } } else if (*pszExpression == '?') { for (LocalFlexController_t i = LocalFlexController_t(0); i < GetNumFlexControllers(); i++) { Msg( "\"%s\" ", GetFlexControllerName( i ) ); } Msg( "\n" ); flex_expression.SetValue( "" ); } else { if (sscanf( pszExpression, "%31s", szTemp ) == 1) { m_flexnum = LookupFlex( szTemp ); if (m_flexnum != -1 && m_flextarget[m_flexnum] != 1) { m_flextarget[m_flexnum] = 1.0; // SetFlexTarget( m_flexnum ); } pszExpression += strlen( szTemp ) - 1; } } } pszExpression++; } } else if (m_flextime < gpGlobals->curtime) { m_flextime = gpGlobals->curtime + random->RandomFloat( 0.3, 0.5 ) * (30.0 / GetNumFlexControllers()); m_flexnum = (LocalFlexController_t)random->RandomInt( 0, GetNumFlexControllers() - 1 ); if (m_flextarget[m_flexnum] == 1) { m_flextarget[m_flexnum] = 0; } else if (stricmp( GetFlexControllerType( m_flexnum ), "phoneme" ) != 0) { if (strstr( GetFlexControllerName( m_flexnum ), "upper_raiser" ) == NULL) { Msg( "%s:%s\n", GetFlexControllerType( m_flexnum ), GetFlexControllerName( m_flexnum ) ); SetFlexTarget( m_flexnum, random->RandomFloat( 0.5, 1.0 ) ); } } } // slide it up. for (LocalFlexController_t i = LocalFlexController_t(0); i < GetNumFlexControllers(); i++) { float weight = GetFlexWeight( i ); if (weight != m_flextarget[i]) { weight = weight + (m_flextarget[i] - weight) / random->RandomFloat( 2.0, 4.0 ); } weight = clamp( weight, 0.0f, 1.0f ); SetFlexWeight( i, weight ); } if (flex_talk.GetInt() == -1) { m_istalking = 1; char pszSentence[256]; Q_snprintf( pszSentence,sizeof(pszSentence), "%s%d", STRING(m_iszSentence), m_sentence++ ); int sentenceIndex = engine->SentenceIndexFromName( pszSentence ); if (sentenceIndex >= 0) { Msg( "%d : %s\n", sentenceIndex, pszSentence ); CPASAttenuationFilter filter( this ); CBaseEntity::EmitSentenceByIndex( filter, entindex(), CHAN_VOICE, sentenceIndex, 1, SNDLVL_TALKING, 0, PITCH_NORM ); } else { m_sentence = 0; } flex_talk.SetValue( "0" ); } else if (flex_talk.GetInt() == -2) { m_flNextEyeLookTime = gpGlobals->curtime + 1000.0; } else if (flex_talk.GetInt() == -3) { m_flNextEyeLookTime = gpGlobals->curtime; flex_talk.SetValue( "0" ); } else if (flex_talk.GetInt() == -4) { AddLookTarget( UTIL_PlayerByIndex( 1 ), 0.5, flex_looktime.GetFloat() ); flex_talk.SetValue( "0" ); } else if (flex_talk.GetInt() == -5) { PickLookTarget( true ); flex_talk.SetValue( "0" ); } } }
/* ================= CL_PrepVideo Call before entering a new level, or after changing dlls ================= */ void CL_PrepVideo( void ) { string name, mapname; int i, mdlcount, step; int map_checksum; // dummy if( !cl.model_precache[1][0] ) return; // no map loaded Cvar_SetFloat( "scr_loading", 0.0f ); // reset progress bar MsgDev( D_NOTE, "CL_PrepVideo: %s\n", clgame.mapname ); // let the render dll load the map Q_strncpy( mapname, cl.model_precache[1], MAX_STRING ); Mod_LoadWorld( mapname, &map_checksum, false ); cl.worldmodel = Mod_Handle( 1 ); // get world pointer Cvar_SetFloat( "scr_loading", 25.0f ); SCR_UpdateScreen(); // make sure what map is valid if( !cls.demoplayback && map_checksum != cl.checksum ) Host_Error( "Local map version differs from server: %i != '%i'\n", map_checksum, cl.checksum ); for( i = 0, mdlcount = 0; i < MAX_MODELS && cl.model_precache[i+1][0]; i++ ) mdlcount++; // total num models step = mdlcount/10; for( i = 0; i < MAX_MODELS && cl.model_precache[i+1][0]; i++ ) { Q_strncpy( name, cl.model_precache[i+1], MAX_STRING ); Mod_RegisterModel( name, i+1 ); Cvar_SetFloat( "scr_loading", scr_loading->value + 75.0f / mdlcount ); if( step && !( i % step ) && ( cl_allow_levelshots->integer || cl.background ) ) SCR_UpdateScreen(); } // update right muzzleflash indexes CL_RegisterMuzzleFlashes (); // invalidate all decal indexes Q_memset( cl.decal_index, 0, sizeof( cl.decal_index )); CL_ClearWorld (); R_NewMap(); // tell the render about new map V_SetupOverviewState(); // set overview bounds // must be called after lightmap loading! clgame.dllFuncs.pfnVidInit(); // release unused SpriteTextures for( i = 1; i < MAX_IMAGES; i++ ) { if( !clgame.sprites[i].name[0] ) continue; // free slot if( clgame.sprites[i].needload != clgame.load_sequence ) Mod_UnloadSpriteModel( &clgame.sprites[i] ); } Mod_FreeUnused (); Cvar_SetFloat( "scr_loading", 100.0f ); // all done if( host.decalList ) { // need to reapply all decals after restarting for( i = 0; i < host.numdecals; i++ ) { decallist_t *entry = &host.decalList[i]; cl_entity_t *pEdict = CL_GetEntityByIndex( entry->entityIndex ); int decalIndex = CL_DecalIndex( CL_DecalIndexFromName( entry->name )); int modelIndex = 0; if( pEdict ) modelIndex = pEdict->curstate.modelindex; CL_DecalShoot( decalIndex, entry->entityIndex, modelIndex, entry->position, entry->flags ); } Z_Free( host.decalList ); } host.decalList = NULL; host.numdecals = 0; if( host.soundList ) { // need to reapply all ambient sounds after restarting for( i = 0; i < host.numsounds; i++ ) { soundlist_t *entry = &host.soundList[i]; if( entry->looping && entry->entnum != -1 ) { MsgDev( D_NOTE, "Restarting sound %s...\n", entry->name ); S_AmbientSound( entry->origin, entry->entnum, S_RegisterSound( entry->name ), entry->volume, entry->attenuation, entry->pitch, 0 ); } } } host.soundList = NULL; host.numsounds = 0; if( host.developer <= 2 ) Con_ClearNotify(); // clear any lines of console text SCR_UpdateScreen (); cl.video_prepped = true; cl.force_refdef = true; }
/* ==================== CL_PlayDemo_f playdemo <demoname> ==================== */ void CL_PlayDemo_f( void ) { string filename; string demoname; int i; if( Cmd_Argc() != 2 ) { Msg( "Usage: playdemo <demoname>\n" ); return; } if( cls.demoplayback ) { CL_StopPlayback(); } if( cls.demorecording ) { Msg( "Can't playback during demo record.\n"); return; } Q_strncpy( demoname, Cmd_Argv( 1 ), sizeof( demoname ) - 1 ); Q_snprintf( filename, sizeof( filename ), "demos/%s.dem", demoname ); if( !FS_FileExists( filename, true )) { MsgDev( D_ERROR, "couldn't open %s\n", filename ); cls.demonum = -1; // stop demo loop return; } cls.demofile = FS_Open( filename, "rb", true ); Q_strncpy( cls.demoname, demoname, sizeof( cls.demoname )); Q_strncpy( menu.globals->demoname, demoname, sizeof( menu.globals->demoname )); // read in the m_DemoHeader FS_Read( cls.demofile, &demo.header, sizeof( demoheader_t )); if( demo.header.id != IDEMOHEADER ) { MsgDev( D_ERROR, "%s is not a demo file\n", filename ); FS_Close( cls.demofile ); cls.demofile = NULL; cls.demonum = -1; // stop demo loop return; } if( demo.header.net_protocol != PROTOCOL_VERSION || demo.header.dem_protocol != DEMO_PROTOCOL ) { MsgDev( D_ERROR, "demo protocol outdated\n" "Demo file protocols Network(%i), Demo(%i)\n" "Server protocol is at Network(%i), Demo(%i)\n", demo.header.net_protocol, demo.header.dem_protocol, PROTOCOL_VERSION, DEMO_PROTOCOL ); FS_Close( cls.demofile ); cls.demofile = NULL; cls.demonum = -1; // stop demo loop return; } // now read in the directory structure. FS_Seek( cls.demofile, demo.header.directory_offset, SEEK_SET ); FS_Read( cls.demofile, &demo.directory.numentries, sizeof( int )); if( demo.directory.numentries < 1 || demo.directory.numentries > 1024 ) { MsgDev( D_ERROR, "demo had bogus # of directory entries: %i\n", demo.directory.numentries ); FS_Close( cls.demofile ); cls.demofile = NULL; cls.demonum = -1; // stop demo loop cls.changedemo = false; return; } if( cls.changedemo ) { S_StopAllSounds(); SCR_BeginLoadingPlaque( false ); CL_ClearState (); CL_InitEdicts (); // re-arrange edicts } else { // NOTE: at this point demo is still valid CL_Disconnect(); Host_ShutdownServer(); Con_Close(); UI_SetActiveMenu( false ); } // allocate demo entries demo.directory.entries = Mem_Alloc( cls.mempool, sizeof( demoentry_t ) * demo.directory.numentries ); for( i = 0; i < demo.directory.numentries; i++ ) { FS_Read( cls.demofile, &demo.directory.entries[i], sizeof( demoentry_t )); } demo.entryIndex = 0; demo.entry = &demo.directory.entries[demo.entryIndex]; FS_Seek( cls.demofile, demo.entry->offset, SEEK_SET ); cls.demoplayback = true; cls.state = ca_connected; cl.background = (cls.demonum != -1) ? true : false; demo.starttime = CL_GetDemoPlaybackClock(); // for determining whether to read another message Netchan_Setup( NS_CLIENT, &cls.netchan, net_from, net_qport->integer ); demo.framecount = 0; cls.lastoutgoingcommand = -1; cls.nextcmdtime = host.realtime; // g-cont. is this need? Q_strncpy( cls.servername, demoname, sizeof( cls.servername )); // begin a playback demo }
// Generic Setup void SetInfo( const char *tagLine, const char *website ) { Q_strncpy( m_szHelpTagLine, tagLine ? tagLine : "", 64 ); Q_strncpy( m_szHelpWebsite, website ? website : "", 128 ); }
//----------------------------------------------------------------------------- // Purpose: Returns the next token. // Input : pszStore - Pointer to a string that will receive the token. // Output : Returns the type of token that was read, or TOKENERROR. //----------------------------------------------------------------------------- trtoken_t TokenReader::NextToken(char *pszStore, int nSize) { char *pStart = pszStore; if (!is_open()) { return TOKENEOF; } // // If they stuffed a token, return that token. // if (m_bStuffed) { m_bStuffed = false; Q_strncpy( pszStore, m_szStuffed, nSize ); return m_eStuffed; } SkipWhiteSpace(); if (eof()) { return TOKENEOF; } if (fail()) { return TOKENEOF; } char ch = get(); // // Look for all the valid operators. // switch (ch) { case '@': case ',': case '!': case '+': case '&': case '*': case '$': case '.': case '=': case ':': case '[': case ']': case '(': case ')': case '{': case '}': case '\\': { pszStore[0] = ch; pszStore[1] = 0; return OPERATOR; } } // // Look for the start of a quoted string. // if (ch == '\"') { return GetString(pszStore, nSize); } // // Integers consist of numbers with an optional leading minus sign. // if (isdigit(ch) || (ch == '-')) { do { if ( (pszStore - pStart + 1) < nSize ) { *pszStore = ch; pszStore++; } ch = get(); if (ch == '-') { return TOKENERROR; } } while (isdigit(ch)); // // No identifier characters are allowed contiguous with numbers. // if (isalpha(ch) || (ch == '_')) { return TOKENERROR; } // // Put back the non-numeric character for the next call. // putback(ch); *pszStore = '\0'; return INTEGER; } // // Identifiers consist of a consecutive string of alphanumeric // characters and underscores. // while ( isalpha(ch) || isdigit(ch) || (ch == '_') ) { if ( (pszStore - pStart + 1) < nSize ) { *pszStore = ch; pszStore++; } ch = get(); } // // Put back the non-identifier character for the next call. // putback(ch); *pszStore = '\0'; return IDENT; }