//----------------------------------------------------------------------------- // Purpose: Starts the effect // Input : *pParticleMgr - // *pArgs - //----------------------------------------------------------------------------- void C_SmokeStack::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs) { pParticleMgr->AddEffect( &m_ParticleEffect, this ); // Figure out the material name. char str[512] = "unset_material"; const model_t *pModel = modelinfo->GetModel( m_iMaterialModel ); if ( pModel ) { Q_strncpy( str, modelinfo->GetModelName( pModel ), sizeof( str ) ); // Get rid of the extension because the material system doesn't want it. char *pExt = Q_stristr( str, ".vmt" ); if ( pExt ) pExt[0] = 0; } m_MaterialHandle[0] = m_ParticleEffect.FindOrAddMaterial( str ); #ifdef HL2_EPISODIC int iCount = 1; char szNames[512]; int iLength = Q_strlen( str ); str[iLength-1] = '\0'; Q_snprintf( szNames, sizeof( szNames ), "%s%d.vmt", str, iCount ); while ( filesystem->FileExists( VarArgs( "materials/%s", szNames ) ) && iCount < SMOKESTACK_MAX_MATERIALS ) { char *pExt = Q_stristr( szNames, ".vmt" ); if ( pExt ) pExt[0] = 0; m_MaterialHandle[iCount] = m_ParticleEffect.FindOrAddMaterial( szNames ); iCount++; } m_iMaxFrames = iCount-1; m_ParticleSpawn.Init( mat_reduceparticles.GetBool() ? m_Rate / 4 : m_Rate ); // Obey mat_reduceparticles in episodic #else m_ParticleSpawn.Init( m_Rate ); #endif m_InvLifetime = m_Speed / m_JetLength; m_pParticleMgr = pParticleMgr; // Figure out how we need to draw. IMaterial *pMaterial = pParticleMgr->PMaterialToIMaterial( m_MaterialHandle[0] ); if( pMaterial ) { m_Renderer.Init( pParticleMgr, pMaterial ); } QueueLightParametersInRenderer(); // For the first N seconds, always simulate so it can build up the smokestack. // Afterwards, we set it to freeze when it's not being rendered. m_ParticleEffect.SetAlwaysSimulate( true ); SetNextClientThink( gpGlobals->curtime + 5 ); }
void CHud :: VidInit( void ) { m_scrinfo.iSize = sizeof( m_scrinfo ); GetScreenInfo( &m_scrinfo ); // ---------- // Load Sprites // --------- m_hHudError = 0; if( ScreenWidth < 640 ) m_iRes = 320; else m_iRes = 640; // Only load this once if( !m_pSpriteList ) { // we need to load the hud.txt, and all sprites within m_pSpriteList = SPR_GetList( "sprites/hud.txt", &m_iSpriteCountAllRes ); if( m_pSpriteList ) { // count the number of sprites of the appropriate res client_sprite_t *p = m_pSpriteList; m_iSpriteCount = 0; for( int j = 0; j < m_iSpriteCountAllRes; j++ ) { if( p->iRes == m_iRes ) m_iSpriteCount++; p++; } // allocated memory for sprite handle arrays m_rghSprites = new HSPRITE[m_iSpriteCount]; m_rgrcRects = new wrect_t[m_iSpriteCount]; m_rgszSpriteNames = new char[m_iSpriteCount * MAX_SPRITE_NAME_LENGTH]; p = m_pSpriteList; int index = 0; for( j = 0; j < m_iSpriteCountAllRes; j++ ) { if( p->iRes == m_iRes ) { char sz[256]; Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); m_rghSprites[index] = SPR_Load( sz ); m_rgrcRects[index] = p->rc; Q_strncpy( &m_rgszSpriteNames[index * MAX_SPRITE_NAME_LENGTH], p->szName, MAX_SPRITE_NAME_LENGTH ); index++; } p++; } } else { ALERT( at_warning, "hud.txt couldn't load\n"); m_pCvarDraw->value = 0; return; } } else { // we have already have loaded the sprite reference from hud.txt, but // we need to make sure all the sprites have been loaded (we've gone through a transition, or loaded a save game) client_sprite_t *p = m_pSpriteList; for( int j = 0, index = 0; j < m_iSpriteCountAllRes; j++ ) { if( p->iRes == m_iRes ) { char sz[256]; Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); m_rghSprites[index] = SPR_Load( sz ); index++; } p++; } } // assumption: number_1, number_2, etc, are all listed and loaded sequentially m_HUD_number_0 = GetSpriteIndex( "number_0" ); m_iFontHeight = m_rgrcRects[m_HUD_number_0].bottom - m_rgrcRects[m_HUD_number_0].top; // loading error sprite m_HUD_error = GetSpriteIndex( "error" ); m_hHudError = GetSprite( m_HUD_error ); m_Ammo.VidInit(); m_Health.VidInit(); m_Geiger.VidInit(); m_Train.VidInit(); m_Battery.VidInit(); m_Flash.VidInit(); m_MOTD.VidInit(); m_Message.VidInit(); m_Scoreboard.VidInit(); m_StatusBar.VidInit(); m_DeathNotice.VidInit(); m_SayText.VidInit(); m_Menu.VidInit(); m_AmmoSecondary.VidInit(); m_TextMessage.VidInit(); m_StatusIcons.VidInit(); }
void WeaponsResource :: LoadWeaponSprites( WEAPON *pWeapon ) { int i, iRes; if( ScreenWidth < 640 ) iRes = 320; else iRes = 640; char sz[128]; if ( !pWeapon ) return; memset( &pWeapon->rcActive, 0, sizeof( wrect_t )); memset( &pWeapon->rcInactive, 0, sizeof( wrect_t )); memset( &pWeapon->rcAmmo, 0, sizeof( wrect_t )); memset( &pWeapon->rcAmmo2, 0, sizeof( wrect_t )); pWeapon->hInactive = 0; pWeapon->hActive = 0; pWeapon->hAmmo = 0; pWeapon->hAmmo2 = 0; Q_snprintf( sz, sizeof( sz ), "sprites/%s.txt", pWeapon->szName ); client_sprite_t *pList = SPR_GetList( sz, &i ); if( !pList ) return; client_sprite_t *p; p = GetSpriteList( pList, "crosshair", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hCrosshair = SPR_Load( sz ); pWeapon->rcCrosshair = p->rc; } else pWeapon->hCrosshair = 0; p = GetSpriteList( pList, "autoaim", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hAutoaim = SPR_Load( sz ); pWeapon->rcAutoaim = p->rc; } else pWeapon->hAutoaim = 0; p = GetSpriteList( pList, "zoom", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hZoomedCrosshair = SPR_Load( sz ); pWeapon->rcZoomedCrosshair = p->rc; } else { pWeapon->hZoomedCrosshair = pWeapon->hCrosshair; // default to non-zoomed crosshair pWeapon->rcZoomedCrosshair = pWeapon->rcCrosshair; } p = GetSpriteList( pList, "zoom_autoaim", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hZoomedAutoaim = SPR_Load( sz ); pWeapon->rcZoomedAutoaim = p->rc; } else { pWeapon->hZoomedAutoaim = pWeapon->hZoomedCrosshair; // default to zoomed crosshair pWeapon->rcZoomedAutoaim = pWeapon->rcZoomedCrosshair; } p = GetSpriteList( pList, "weapon", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hInactive = SPR_Load( sz ); pWeapon->rcInactive = p->rc; gHR.iHistoryGap = max( gHR.iHistoryGap, pWeapon->rcActive.bottom - pWeapon->rcActive.top ); } else { pWeapon->hInactive = gHUD.m_hHudError; pWeapon->rcInactive = gHUD.GetSpriteRect( gHUD.m_HUD_error ); gHR.iHistoryGap = max( gHR.iHistoryGap, pWeapon->rcActive.bottom - pWeapon->rcActive.top ); } p = GetSpriteList( pList, "weapon_s", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hActive = SPR_Load( sz ); pWeapon->rcActive = p->rc; } else { pWeapon->hActive = gHUD.m_hHudError; pWeapon->rcActive = gHUD.GetSpriteRect( gHUD.m_HUD_error ); } p = GetSpriteList( pList, "ammo", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hAmmo = SPR_Load( sz ); pWeapon->rcAmmo = p->rc; gHR.iHistoryGap = max( gHR.iHistoryGap, pWeapon->rcActive.bottom - pWeapon->rcActive.top ); } else pWeapon->hAmmo = 0; p = GetSpriteList( pList, "ammo2", iRes, i ); if( p ) { Q_snprintf( sz, sizeof( sz ), "sprites/%s.spr", p->szSprite ); pWeapon->hAmmo2 = SPR_Load( sz ); pWeapon->rcAmmo2 = p->rc; gHR.iHistoryGap = max( gHR.iHistoryGap, pWeapon->rcActive.bottom - pWeapon->rcActive.top ); } else pWeapon->hAmmo2 = 0; }
void AppendPlayerInformation(ISteamHTTP *pSteamHttp, HTTPRequestHandle httpRequest, CSteamAPIContext *pSteamAPIContext, CBasePlayer *pPlayer, bool bAnonymous) { // Local DS time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); char* local_ds = asctime(timeinfo); char* newLine = strstr(local_ds, "\n"); if (newLine) { *newLine = 0; } pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "localdatetime", local_ds); // Build DS char build_ds[64]; Q_snprintf(build_ds, sizeof(build_ds), "%s,%s", __DATE__, __TIME__); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "builddatetime", build_ds); // DxLevel pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "dxlevel", ConVarRef("mat_dxlevel").GetString()); if (pPlayer) { // Position char player_position[32]; Vector player_pos = pPlayer->GetLocalOrigin(); Q_snprintf(player_position, sizeof(player_position), "%.2f,%.2f,%.2f", player_pos.x, player_pos.y, player_pos.z); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "position", player_position); // Angles char player_angles[32]; QAngle player_ang = pPlayer->GetLocalAngles(); Q_snprintf(player_angles, sizeof(player_angles), "%.2f,%.2f,%.2f", player_ang.x, player_ang.y, player_ang.z); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "angles", player_angles); // Health char player_health[16]; Q_snprintf(player_health, sizeof(player_health), "%i", pPlayer->GetHealth()); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "health", player_health); // Weapon CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if (pWeapon) { pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "weapon", pWeapon->GetClassname()); } } // Cheats char cheats_enabled[8]; Q_snprintf(cheats_enabled, sizeof(cheats_enabled), "%i", (ConVarRef("sv_cheats").GetBool() || ConVarRef("developer").GetBool())); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "cheats", cheats_enabled); // Map #ifdef CLIENT_DLL char mapname[256]; V_FileBase(engine->GetLevelName(), mapname, sizeof(mapname)); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "level", mapname); #else pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "level", gpGlobals->mapname.ToCStr()); #endif if (pSteamAPIContext) { // Language pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "language", pSteamAPIContext->SteamUtils()->GetSteamUILanguage()); } // Platform char * platform = "unknown"; if (IsPC()) platform = "pc"; if (IsOSX()) platform = "osx"; if (IsLinux()) platform = "linux"; if (IsX360()) platform = "360"; if (IsPS3()) platform = "ps3"; pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "platform", platform); // Player ID if (bAnonymous == false) { if (ae_uniqueplayerid.GetInt() == 0) GenerateUniquePlayerId(pSteamAPIContext); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "playerid", ae_uniqueplayerid.GetString()); } }
//----------------------------------------------------------------------------- // Purpose: Static method // Input : *hdr - // sounds - //----------------------------------------------------------------------------- void CModelSoundsCache::BuildAnimationEventSoundList( CStudioHdr *hdr, CUtlVector< unsigned short >& sounds ) { Assert( hdr ); // force animation event resolution!!! VerifySequenceIndex( hdr ); // Find all animation events which fire off sound script entries... for ( int iSeq=0; iSeq < hdr->GetNumSeq(); iSeq++ ) { mstudioseqdesc_t *pSeq = &hdr->pSeqdesc( iSeq ); // Now read out all the sound events with their timing for ( int iEvent=0; iEvent < (int)pSeq->numevents; iEvent++ ) { mstudioevent_t *pEvent = pSeq->pEvent( iEvent ); switch ( pEvent->event ) { default: { if ( pEvent->type & AE_TYPE_NEWEVENTSYSTEM ) { if ( pEvent->event == AE_SV_PLAYSOUND ) { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } } } break; // Old-style client .dll animation event case CL_EVENT_SOUND: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; case CL_EVENT_FOOTSTEP_LEFT: case CL_EVENT_FOOTSTEP_RIGHT: { char soundname[256]; char const *options = pEvent->pszOptions(); if ( !options || !options[0] ) { options = "NPC_CombineS"; } Q_snprintf( soundname, 256, "%s.RunFootstepLeft", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.RunFootstepRight", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.FootstepLeft", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.FootstepRight", options ); FindOrAddScriptSound( sounds, soundname ); } break; case AE_CL_PLAYSOUND: { if ( !( pEvent->type & AE_TYPE_CLIENT ) ) break; if ( pEvent->pszOptions()[0] ) { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } else { Warning( "-- Error --: empty soundname, .qc error on AE_CL_PLAYSOUND in model %s, sequence %s, animevent # %i\n", hdr->pszName(), pSeq->pszLabel(), iEvent+1 ); } } break; case SCRIPT_EVENT_SOUND: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; case SCRIPT_EVENT_SOUND_VOICE: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; } } } }
//// HOST_SAY // String comes in as // say blah blah blah // or as // blah blah blah // void Host_Say( edict_t *pEdict, const CCommand &args, bool teamonly ) { CBasePlayer *client; int j; char *p; char text[256]; char szTemp[256]; const char *cpSay = "say"; const char *cpSayTeam = "say_team"; const char *pcmd = args[0]; bool bSenderDead = false; // We can get a raw string now, without the "say " prepended if ( args.ArgC() == 0 ) return; if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) ) { if ( args.ArgC() >= 2 ) { p = (char *)args.ArgS(); } else { // say with a blank message, nothing to do return; } } else // Raw text, need to prepend argv[0] { if ( args.ArgC() >= 2 ) { Q_snprintf( szTemp,sizeof(szTemp), "%s %s", ( char * )pcmd, (char *)args.ArgS() ); } else { // Just a one word command, use the first word...sigh Q_snprintf( szTemp,sizeof(szTemp), "%s", ( char * )pcmd ); } p = szTemp; } CBasePlayer *pPlayer = NULL; if ( pEdict ) { pPlayer = ((CBasePlayer *)CBaseEntity::Instance( pEdict )); Assert( pPlayer ); // make sure the text has valid content p = CheckChatText( pPlayer, p ); } if ( !p ) return; if ( pEdict ) { if ( !pPlayer->CanSpeak() ) return; // See if the player wants to modify of check the text pPlayer->CheckChatText( p, 127 ); // though the buffer szTemp that p points to is 256, // chat text is capped to 127 in CheckChatText above Assert( strlen( pPlayer->GetPlayerName() ) > 0 ); bSenderDead = ( pPlayer->m_lifeState != LIFE_ALIVE ); } else { bSenderDead = false; } const char *pszFormat = NULL; const char *pszPrefix = NULL; const char *pszLocation = NULL; if ( g_pGameRules ) { pszFormat = g_pGameRules->GetChatFormat( teamonly, pPlayer ); pszPrefix = g_pGameRules->GetChatPrefix( teamonly, pPlayer ); pszLocation = g_pGameRules->GetChatLocation( teamonly, pPlayer ); } const char *pszPlayerName = pPlayer ? pPlayer->GetPlayerName():"Console"; //DHL Chat Macros char *s_pHealthMacro = Q_strstr( p, "%h" ); if ( s_pHealthMacro && pPlayer ) { char sHealthMacro[20]; Q_snprintf( sHealthMacro, sizeof( sHealthMacro ), "HP: %i", pPlayer->GetHealth() >= 0 ? pPlayer->GetHealth() : 0 ); Q_strcpy( s_pHealthMacro, sHealthMacro ); } if ( pszPrefix && strlen( pszPrefix ) > 0 ) { if ( pszLocation && strlen( pszLocation ) ) { Q_snprintf( text, sizeof(text), "%s %s @ %s: ", pszPrefix, pszPlayerName, pszLocation ); } else { Q_snprintf( text, sizeof(text), "%s %s: ", pszPrefix, pszPlayerName ); } } else { Q_snprintf( text, sizeof(text), "%s: ", pszPlayerName ); } j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator if ( (int)strlen(p) > j ) p[j] = 0; Q_strncat( text, p, sizeof( text ), COPY_ALL_CHARACTERS ); Q_strncat( text, "\n", sizeof( text ), COPY_ALL_CHARACTERS ); // loop through all players // Start with the first player. // This may return the world in single player if the client types something between levels or during spawn // so check it, or it will infinite loop client = NULL; for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { client = ToBaseMultiplayerPlayer( UTIL_PlayerByIndex( i ) ); if ( !client || !client->edict() ) continue; if ( client->edict() == pEdict ) continue; if ( !(client->IsNetClient()) ) // Not a client ? (should never be true) continue; if ( teamonly && g_pGameRules->PlayerCanHearChat( client, pPlayer ) != GR_TEAMMATE ) continue; if ( pPlayer && !client->CanHearAndReadChatFrom( pPlayer ) ) continue; if ( pPlayer && GetVoiceGameMgr() && GetVoiceGameMgr()->IsPlayerIgnoringPlayer( pPlayer->entindex(), i ) ) continue; CSingleUserRecipientFilter user( client ); user.MakeReliable(); if ( pszFormat ) { UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation ); } else { UTIL_SayTextFilter( user, text, pPlayer, true ); } } if ( pPlayer ) { // print to the sending client CSingleUserRecipientFilter user( pPlayer ); user.MakeReliable(); if ( pszFormat ) { UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation ); } else { UTIL_SayTextFilter( user, text, pPlayer, true ); } } // echo to server console // Adrian: Only do this if we're running a dedicated server since we already print to console on the client. if ( engine->IsDedicatedServer() ) Msg( "%s", text ); Assert( p ); int userid = 0; const char *networkID = "Console"; const char *playerName = "Console"; const char *playerTeam = "Console"; if ( pPlayer ) { userid = pPlayer->GetUserID(); networkID = pPlayer->GetNetworkIDString(); playerName = pPlayer->GetPlayerName(); CTeam *team = pPlayer->GetTeam(); if ( team ) { playerTeam = team->GetName(); } } if ( teamonly ) UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say_team \"%s\"\n", playerName, userid, networkID, playerTeam, p ); else UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say \"%s\"\n", playerName, userid, networkID, playerTeam, p ); IGameEvent * event = gameeventmanager->CreateEvent( "player_say" ); if ( event ) // will be null if there are no listeners! { event->SetInt("userid", userid ); event->SetString("text", p ); event->SetInt("priority", 1 ); // HLTV event priority, not transmitted gameeventmanager->FireEvent( event ); } }
//================================= // Add the current snapshot to the db //================================= void AddSnapshotToDatabase( void ) { char szSnapshot[1024]; //Only update the prices and close. if ( g_bWeeklyUpdate == true ) { weeklyprice_t prices; CUtlBuffer buf; prices.iVersion = PRICE_BLOB_VERSION; for ( int i = 1; i < WEAPON_MAX; i ++ ) { Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update weapon_info set current_price=%d, purchases_thisweek=0 where WeaponID=%d", g_iNewWeaponPrices[i], i ); int retcode = mysql->Execute( szSnapshot ); if ( retcode != 0 ) { Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode ); } prices.iPreviousPrice[i] = g_Weapons[i].iCurrentPrice; prices.iCurrentPrice[i] = g_iNewWeaponPrices[i]; } buf.Put( &prices, sizeof( weeklyprice_t ) ); if ( g_pFullFileSystem ) { g_pFullFileSystem->WriteFile( PRICE_BLOB_NAME, NULL, buf ); } Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update reset_counter set counter=counter+1" ); int retcode = mysql->Execute( szSnapshot ); if ( retcode != 0 ) { Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode ); } return; } g_iCounter++; for ( int i = 1; i < WEAPON_MAX; i ++ ) { Q_snprintf( szSnapshot, sizeof( szSnapshot ), "Insert into purchases_pricing ( snapshot, dt2, weapon_id, purchases, current_price, projected_price, reset_counter ) values ( \"%d_%d\", NOW(), %d, %d, %d, %d, %d );", g_iCounter, i, i, g_iPurchaseDelta[i], g_Weapons[i].iCurrentPrice, g_iNewWeaponPrices[i], g_iResetCounter ); int retcode = mysql->Execute( szSnapshot ); if ( retcode != 0 ) { Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode ); } } Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update snapshot_counter set counter=%d", g_iCounter ); int retcode = mysql->Execute( szSnapshot ); if ( retcode != 0 ) { Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode ); } for ( int i = 1; i < WEAPON_MAX; i ++ ) { Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update weapon_info set purchases=%d, purchases_thisweek=purchases_thisweek+%d where WeaponID=%d", g_iCurrentWeaponPurchases[i], g_iPurchaseDelta[i], i ); int retcode = mysql->Execute( szSnapshot ); if ( retcode != 0 ) { Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode ); } } Msg( "Added new snapshot to database\n", szSnapshot, retcode ); }
void CASW_Mission_Chooser_Source_Local::AddToSavedCampaignList(const char *szSaveName) { // find out what campaign this save is for char szFullFileName[256]; Q_snprintf(szFullFileName, sizeof(szFullFileName), "save/%s", szSaveName); KeyValues *pSaveKeyValues = new KeyValues( szSaveName ); if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, szFullFileName)) { const char *pCampaignName = pSaveKeyValues->GetString("CampaignName"); // check the campaign exists char tempfile[MAX_PATH]; Q_snprintf( tempfile, sizeof( tempfile ), "resource/campaigns/%s.txt", pCampaignName ); if (g_pFullFileSystem->FileExists(tempfile)) { ASW_Mission_Chooser_Saved_Campaign item; Q_snprintf(item.m_szSaveName, sizeof(item.m_szSaveName), "%s", szSaveName); Q_snprintf(item.m_szCampaignName, sizeof(item.m_szCampaignName), "%s", pCampaignName); Q_snprintf(item.m_szDateTime, sizeof(item.m_szDateTime), "%s", pSaveKeyValues->GetString("DateTime")); //Msg("save %s multiplayer %d\n", szSaveName, pSaveKeyValues->GetInt("Multiplayer")); item.m_bMultiplayer = (pSaveKeyValues->GetInt("Multiplayer") > 0); //Msg("item multiplayer = %d\n", item.m_bMultiplayer); // check subsections for player names and player IDs, concat them into two strings char namebuffer[256]; char idbuffer[512]; namebuffer[0] = '\0'; idbuffer[0] = '\0'; int namepos = 0; int idpos = 0; KeyValues *pkvSubSection = pSaveKeyValues->GetFirstSubKey(); while ( pkvSubSection ) { if ((Q_stricmp(pkvSubSection->GetName(), "PLAYER")==0) && namepos < 253) { const char *pName = pkvSubSection->GetString("PlayerName"); if (pName && pName[0] != '\0') { int namelength = Q_strlen(pName); for (int charcopy=0; charcopy<namelength && namepos<253; charcopy++) { namebuffer[namepos] = pName[charcopy]; namepos++; } namebuffer[namepos] = ' '; namepos++; namebuffer[namepos] = '\0'; } } if ((Q_stricmp(pkvSubSection->GetName(), "DATA")==0) && idpos < 253) { const char *pID = pkvSubSection->GetString("DataBlock"); if (pID && pID[0] != '\0') { int idlength = Q_strlen(pID); for (int charcopy=0; charcopy<idlength && idpos<253; charcopy++) { idbuffer[idpos] = pID[charcopy]; idpos++; } idbuffer[idpos] = ' '; idpos++; idbuffer[idpos] = '\0'; } } pkvSubSection = pkvSubSection->GetNextKey(); } Q_snprintf(item.m_szPlayerNames, sizeof(item.m_szPlayerNames), "%s", namebuffer); Q_snprintf(item.m_szPlayerIDs, sizeof(item.m_szPlayerIDs), "%s", idbuffer); item.m_iMissionsComplete = pSaveKeyValues->GetInt("NumMissionsComplete"); m_SavedCampaignList.Insert( item ); } } pSaveKeyValues->deleteThis(); // check if there's now too many save games int iNumMultiplayer = GetNumSavedCampaigns(true, NULL); if (iNumMultiplayer > asw_max_saves.GetInt()) { // find the oldest one ASW_Mission_Chooser_Saved_Campaign* pChosen = false; int iChosen = -1; for (int i=m_SavedCampaignList.Count()-1; i>=0; i--) { if (m_SavedCampaignList[i].m_bMultiplayer) { pChosen = &m_SavedCampaignList[i]; iChosen = i; break; } } // delete if found if (iChosen != -1 && pChosen) { char buffer[MAX_PATH]; Q_snprintf(buffer, sizeof(buffer), "save/%s", pChosen->m_szSaveName); Msg("Deleting save %s as we have too many\n", buffer); g_pFullFileSystem->RemoveFile( buffer, "GAME" ); m_SavedCampaignList.Remove(iChosen); } } }
bool CASW_Mission_Chooser_Source_Local::ASW_Campaign_CreateNewSaveGame(char *szFileName, int iFileNameMaxLen, const char *szCampaignName, bool bMultiplayerGame, const char *szStartingMission) // szFileName arg is the desired filename or NULL for an autogenerated one. Function sets szFileName with the filename used. { if (!szFileName) return false; char stripped[MAX_PATH]; V_StripExtension( szCampaignName, stripped, MAX_PATH ); char szStartingMissionStripped[64]; if ( szStartingMission ) { V_StripExtension( szStartingMission, szStartingMissionStripped, sizeof( szStartingMissionStripped ) ); } else { szStartingMissionStripped[0] = 0; } // check the campaign file exists char campbuffer[MAX_PATH]; Q_snprintf(campbuffer, sizeof(campbuffer), "resource/campaigns/%s.txt", stripped); if (!g_pFullFileSystem->FileExists(campbuffer)) { Msg("No such campaign: %s\n", campbuffer); return false; } // Get the current time and date as a string char szDateTime[256]; int year, month, dayOfWeek, day, hour, minute, second; ASW_System_GetCurrentTimeAndDate(&year, &month, &dayOfWeek, &day, &hour, &minute, &second); Q_snprintf(szDateTime, sizeof(szDateTime), "%02d/%02d/%02d %02d:%02d", month, day, year, hour, minute); if (szFileName[0] == '\0') { // autogenerate a filename based on the current time and date Q_snprintf(szFileName, iFileNameMaxLen, "%s_save_%02d_%02d_%02d_%02d_%02d_%02d", stripped, year, month, day, hour, minute, second); } // make sure the path and extension are correct Q_SetExtension( szFileName, ".campaignsave", iFileNameMaxLen ); char tempbuffer[256]; Q_snprintf(tempbuffer, sizeof(tempbuffer), "%s", szFileName); const char *pszNoPathName = Q_UnqualifiedFileName(tempbuffer); //Msg("Unqualified = %s\n", pszNoPathName); //softcopy: char szFullFileName[256]; Q_snprintf(szFullFileName, sizeof(szFullFileName), "save/%s", pszNoPathName); //Msg("Creating new save with filename: %s\n", szFullFileName); //softcopy: KeyValues *pSaveKeyValues = new KeyValues( pszNoPathName ); int nMissionsComplete = 0; if ( szStartingMission && szStartingMission[0] ) { KeyValues *pCampaignDetails = GetCampaignDetails( stripped ); if ( pCampaignDetails ) { int nMissionSections = 0; for ( KeyValues *pMission = pCampaignDetails->GetFirstSubKey(); pMission; pMission = pMission->GetNextKey() ) { if ( !Q_stricmp( pMission->GetName(), "MISSION" ) ) { if ( !Q_stricmp( pMission->GetString( "MapName", "" ), szStartingMissionStripped ) ) { nMissionsComplete = nMissionSections - 1; // skip first dummy mission break; } nMissionSections++; } } } } pSaveKeyValues->SetInt("Version", ASW_CURRENT_SAVE_VERSION); pSaveKeyValues->SetString("CampaignName", stripped); pSaveKeyValues->SetInt("CurrentPosition", nMissionsComplete + 1); // position squad on the first uncompleted mission pSaveKeyValues->SetInt("NumMissionsComplete", nMissionsComplete); pSaveKeyValues->SetInt("InitialNumMissionsComplete", nMissionsComplete); pSaveKeyValues->SetInt("Multiplayer", bMultiplayerGame ? 1 : 0); pSaveKeyValues->SetString("DateTime", szDateTime); pSaveKeyValues->SetInt("NumPlayers", 0); // write out each mission's status KeyValues *pSubSection; for (int i=0; i<ASW_MAX_MISSIONS_PER_CAMPAIGN; i++) { pSubSection = new KeyValues("MISSION"); pSubSection->SetInt("MissionID", i); bool bComplete = ( i != 0 ) && ( i <= nMissionsComplete ); pSubSection->SetInt("MissionComplete", bComplete ? 1 : 0 ); pSaveKeyValues->AddSubKey(pSubSection); } const int nInitialSkillPoints = 0; // write out each marine's stats for (int i=0; i<ASW_NUM_MARINE_PROFILES; i++) { pSubSection = new KeyValues("MARINE"); pSubSection->SetInt("MarineID", i); pSubSection->SetInt("SkillSlot0", 0); pSubSection->SetInt("SkillSlot1", 0); pSubSection->SetInt("SkillSlot2", 0); pSubSection->SetInt("SkillSlot3", 0); pSubSection->SetInt("SkillSlot4", 0); pSubSection->SetInt("SkillSlotSpare", nInitialSkillPoints + nMissionsComplete * ASW_SKILL_POINTS_PER_MISSION ); pSubSection->SetInt("UndoSkillSlot0", 0); pSubSection->SetInt("UndoSkillSlot1", 0); pSubSection->SetInt("UndoSkillSlot2", 0); pSubSection->SetInt("UndoSkillSlot3", 0); pSubSection->SetInt("UndoSkillSlot4", 0); pSubSection->SetInt("UndoSkillSlotSpare", nInitialSkillPoints + nMissionsComplete * ASW_SKILL_POINTS_PER_MISSION ); pSubSection->SetString("MissionsCompleted", ""); pSubSection->SetString("Medals", ""); pSubSection->SetInt("Wounded", 0); pSubSection->SetInt("Dead", 0); pSubSection->SetInt("ParasitesKilled", 0); pSaveKeyValues->AddSubKey(pSubSection); } // players section is empty at first // Create the save sub-directory if (!g_pFullFileSystem->IsDirectory( "save", "MOD" )) { g_pFullFileSystem->CreateDirHierarchy( "save", "MOD" ); } // save it if (pSaveKeyValues->SaveToFile(g_pFullFileSystem, szFullFileName)) { // make sure our save summary list adds this to it, if needed //Msg("New save created: %s\n", szFullFileName); Msg("New save game summary created on %s: %s\n", szDateTime, szFullFileName); //softcopy: NotifyNewSave(pszNoPathName); return true; } Msg("Save to file failed. Filename=%s\n", szFullFileName); return false; }
KeyValues* ReadEncryptedKVFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey ) { Assert( strchr( szFilenameWithoutExtension, '.' ) == NULL ); char szFullName[512]; const char *pSearchPath = "GAME"; // Open the weapon data file, and abort if we can't KeyValues *pKV = new KeyValues( "WeaponDatafile" ); pKV->UsesEscapeSequences( true ); Q_snprintf(szFullName,sizeof(szFullName), "%s.txt", szFilenameWithoutExtension); if ( !pKV->LoadFromFile( filesystem, szFullName, pSearchPath ) ) // try to load the normal .txt file first { #ifndef _XBOX if ( pICEKey ) { Q_snprintf(szFullName,sizeof(szFullName), "%s.ctx", szFilenameWithoutExtension); // fall back to the .ctx file FileHandle_t f = filesystem->Open( szFullName, "rb", pSearchPath ); if (!f) { pKV->deleteThis(); return NULL; } // load file into a null-terminated buffer int fileSize = filesystem->Size(f); char *buffer = (char*)MemAllocScratch(fileSize + 1); Assert(buffer); filesystem->Read(buffer, fileSize, f); // read into local buffer buffer[fileSize] = 0; // null terminate file as EOF filesystem->Close( f ); // close file after reading UTIL_DecodeICE( (unsigned char*)buffer, fileSize, pICEKey ); bool retOK = pKV->LoadFromBuffer( szFullName, buffer, filesystem ); MemFreeScratch(); if ( !retOK ) { pKV->deleteThis(); return NULL; } } else { pKV->deleteThis(); return NULL; } #else pKV->deleteThis(); return NULL; #endif } return pKV; }
//----------------------------------------------------------------------------- // Points the maya script to the appropriate place //----------------------------------------------------------------------------- void SetMayaScriptSettings( ) { char pMayaScriptPath[ MAX_PATH ]; Q_snprintf( pMayaScriptPath, sizeof(pMayaScriptPath), "%%VPROJECT%%\\..\\sdktools\\maya\\7.0\\modules\\utilities\\scripts" ); SetVConfigRegistrySetting( "MAYA_SCRIPT_PATH", pMayaScriptPath, false ); }
void CHL2MPRules::ClientSettingsChanged( CBasePlayer *pPlayer ) { #ifndef CLIENT_DLL CHL2MP_Player *pHL2Player = ToHL2MPPlayer( pPlayer ); if ( pHL2Player == NULL ) return; const char *pCurrentModel = modelinfo->GetModelName( pPlayer->GetModel() ); const char *szModelName = engine->GetClientConVarValue( engine->IndexOfEdict( pPlayer->edict() ), "cl_playermodel" ); //If we're different. if ( stricmp( szModelName, pCurrentModel ) ) { //Too soon, set the cvar back to what it was. //Note: this will make this function be called again //but since our models will match it'll just skip this whole dealio. if ( pHL2Player->GetNextModelChangeTime() >= gpGlobals->curtime ) { char szReturnString[512]; Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel %s\n", pCurrentModel ); engine->ClientCommand ( pHL2Player->edict(), szReturnString ); Q_snprintf( szReturnString, sizeof( szReturnString ), "Please wait %d more seconds before trying to switch.\n", (int)(pHL2Player->GetNextModelChangeTime() - gpGlobals->curtime) ); ClientPrint( pHL2Player, HUD_PRINTTALK, szReturnString ); return; } if ( HL2MPRules()->IsTeamplay() == false ) { pHL2Player->SetPlayerModel(); const char *pszCurrentModelName = modelinfo->GetModelName( pHL2Player->GetModel() ); char szReturnString[128]; Q_snprintf( szReturnString, sizeof( szReturnString ), "Your player model is: %s\n", pszCurrentModelName ); ClientPrint( pHL2Player, HUD_PRINTTALK, szReturnString ); } else { if ( Q_stristr( szModelName, "models/human") ) { pHL2Player->ChangeTeam( TEAM_REBELS ); } else { pHL2Player->ChangeTeam( TEAM_COMBINE ); } } } if ( sv_report_client_settings.GetInt() == 1 ) { UTIL_LogPrintf( "\"%s\" cl_cmdrate = \"%s\"\n", pHL2Player->GetPlayerName(), engine->GetClientConVarValue( pHL2Player->entindex(), "cl_cmdrate" )); } BaseClass::ClientSettingsChanged( pPlayer ); #endif }
/* <41063> ../engine/info.c:275 */ void Info_SetValueForStarKey(char *s, const char *key, const char *value, int maxsize) { char newArray[MAX_INFO_STRING]; char *v; int c; if (!key || !value) { Con_Printf("Keys and values can't be null\n"); return; } if (key[0] == 0) { Con_Printf("Keys can't be an empty string\n"); return; } if (Q_strstr(key, "\\") || Q_strstr(value, "\\")) { Con_Printf("Can't use keys or values with a \\\n"); return; } if (Q_strstr(key, "..") || Q_strstr(value, "..")) { // TODO: Why silently return? //Con_Printf("Can't use keys or values with a ..\n"); return; } if (Q_strstr(key, "\"") || Q_strstr(value, "\"")) { Con_Printf("Can't use keys or values with a \"\n"); return; } int keyLen = Q_strlen(key); int valueLan = Q_strlen(value); if (keyLen >= MAX_KV_LEN || valueLan >= MAX_KV_LEN) { Con_Printf("Keys and values must be < %i characters\n", MAX_KV_LEN); return; } if (!Q_UnicodeValidate(key) || !Q_UnicodeValidate(value)) { Con_Printf("Keys and values must be valid utf8 text\n"); return; } // Remove current key/value and return if we doesn't specified to set a value Info_RemoveKey(s, key); if (value[0] == 0) { return; } // Create key/value pair Q_snprintf(newArray, MAX_INFO_STRING - 1, "\\%s\\%s", key, value); newArray[MAX_INFO_STRING - 1] = 0; int neededLength = Q_strlen(newArray); if ((int)Q_strlen(s) + neededLength >= maxsize) { // no more room in the buffer to add key/value if (!Info_IsKeyImportant(key)) { // no room to add setting Con_Printf("Info string length exceeded\n"); return; } // keep removing the largest key/values until we have a room char *largekey; do { largekey = Info_FindLargestKey(s, maxsize); if (largekey[0] == 0) { // no room to add setting Con_Printf("Info string length exceeded\n"); return; } Info_RemoveKey(s, largekey); } while ((int)Q_strlen(s) + neededLength >= maxsize); } // auto lowercase team bool lowerCaseValue = Q_stricmp(key, "team") == 0; s += Q_strlen(s); v = newArray; while (*v) { c = (unsigned char)*v++; if (lowerCaseValue) { c = tolower(c); } *s++ = c; } *s = 0; }
void EntityOutputManager::FireEventDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay) { if (!pCaller) { return; } char sOutput[20]; Q_snprintf(sOutput, sizeof(sOutput), "%p", pOutput); // attempt to directly lookup a hook using the pOutput pointer OutputNameStruct *pOutputName = NULL; bool fastLookup = false; // Fast lookup failed - check the slow way for hooks that haven't fired yet if ((fastLookup = EntityOutputs->Retrieve(sOutput, (void **)&pOutputName)) == false) { const char *classname = GetEntityClassname(pCaller); const char *outputname = FindOutputName(pOutput, pCaller); if (!outputname) { return; } pOutputName = FindOutputPointer(classname, outputname, false); if (!pOutputName) { return; } } if (!pOutputName->hooks.empty()) { if (!fastLookup) { // hook exists on this classname and output - map it into our quick find trie EntityOutputs->Insert(sOutput, pOutputName); } SourceHook::List<omg_hooks *>::iterator _iter; omg_hooks *hook; _iter = pOutputName->hooks.begin(); while (_iter != pOutputName->hooks.end()) { hook = (omg_hooks *)*_iter; hook->in_use = true; cell_t ref = gamehelpers->EntityToReference(pCaller); if (hook->entity_ref != -1 && gamehelpers->ReferenceToIndex(hook->entity_ref) == gamehelpers->ReferenceToIndex(ref) && ref != hook->entity_ref) { // same entity index but different reference. Entity has changed, kill the hook. _iter = pOutputName->hooks.erase(_iter); CleanUpHook(hook); continue; } if (hook->entity_ref == -1 || hook->entity_ref == ref) // Global classname hook { //fire the forward to hook->pf hook->pf->PushString(pOutputName->Name); hook->pf->PushCell(gamehelpers->ReferenceToBCompatRef(ref)); hook->pf->PushCell(gamehelpers->EntityToBCompatRef(pActivator)); //hook->pf->PushCell(handle); hook->pf->PushFloat(fDelay); hook->pf->Execute(NULL); if ((hook->entity_ref != -1) && hook->only_once) { _iter = pOutputName->hooks.erase(_iter); CleanUpHook(hook); continue; } if (hook->delete_me) { _iter = pOutputName->hooks.erase(_iter); CleanUpHook(hook); continue; } } hook->in_use = false; _iter++; } } }
void R_ParseDetailTextures( const char *filename ) { char *afile, *pfile; string token, texname; string detail_texname; string detail_path; float xScale, yScale; texture_t *tex; int i; if( r_detailtextures->integer >= 2 && !FS_FileExists( filename, false )) { // use built-in generator for detail textures R_CreateDetailTexturesList( filename ); } afile = (char *)FS_LoadFile( filename, NULL, false ); if( !afile ) return; pfile = afile; // format: 'texturename' 'detailtexture' 'xScale' 'yScale' while(( pfile = COM_ParseFile( pfile, token )) != NULL ) { texname[0] = '\0'; detail_texname[0] = '\0'; // read texname if( token[0] == '{' ) { // NOTE: COM_ParseFile handled some symbols seperately // this code will be fix it pfile = COM_ParseFile( pfile, token ); Q_strncat( texname, "{", sizeof( texname )); Q_strncat( texname, token, sizeof( texname )); } else Q_strncpy( texname, token, sizeof( texname )); // read detailtexture name pfile = COM_ParseFile( pfile, token ); Q_strncat( detail_texname, token, sizeof( detail_texname )); // trying the scales or '{' pfile = COM_ParseFile( pfile, token ); // read second part of detailtexture name if( token[0] == '{' ) { Q_strncat( detail_texname, token, sizeof( detail_texname )); pfile = COM_ParseFile( pfile, token ); // read scales Q_strncat( detail_texname, token, sizeof( detail_texname )); pfile = COM_ParseFile( pfile, token ); // parse scales } Q_snprintf( detail_path, sizeof( detail_path ), "gfx/%s", detail_texname ); // read scales xScale = Q_atof( token ); pfile = COM_ParseFile( pfile, token ); yScale = Q_atof( token ); if( xScale <= 0.0f || yScale <= 0.0f ) continue; // search for existing texture and uploading detail texture for( i = 0; i < cl.worldmodel->numtextures; i++ ) { tex = cl.worldmodel->textures[i]; if( Q_stricmp( tex->name, texname )) continue; tex->dt_texturenum = GL_LoadTexture( detail_path, NULL, 0, TF_FORCE_COLOR, NULL ); // texture is loaded if( tex->dt_texturenum ) { gltexture_t *glt; GL_SetTextureType( tex->dt_texturenum, TEX_DETAIL ); glt = R_GetTexture( tex->gl_texturenum ); glt->xscale = xScale; glt->yscale = yScale; } break; } } Mem_Free( afile ); }
//----------------------------------------------------------------------------- // Loads VTF files //----------------------------------------------------------------------------- static bool LoadSrcVTFFiles( IVTFTexture *pSrcVTFTextures[6], const char *pSkyboxMaterialBaseName, int *pUnionTextureFlags, bool bHDR ) { const char *facingName[6] = { "rt", "lf", "bk", "ft", "up", "dn" }; int i; for( i = 0; i < 6; i++ ) { char srcMaterialName[1024]; sprintf( srcMaterialName, "%s%s", pSkyboxMaterialBaseName, facingName[i] ); IMaterial *pSkyboxMaterial = g_pMaterialSystem->FindMaterial( srcMaterialName, "skybox" ); //IMaterialVar *pSkyTextureVar = pSkyboxMaterial->FindVar( bHDR ? "$hdrbasetexture" : "$basetexture", NULL ); //, bHDR ? false : true ); IMaterialVar *pSkyTextureVar = pSkyboxMaterial->FindVar( "$basetexture", NULL ); // Since we're setting it to black anyway, just use $basetexture for HDR const char *vtfName = pSkyTextureVar->GetStringValue(); char srcVTFFileName[MAX_PATH]; Q_snprintf( srcVTFFileName, MAX_PATH, "materials/%s.vtf", vtfName ); CUtlBuffer buf; if ( !g_pFullFileSystem->ReadFile( srcVTFFileName, NULL, buf ) ) { // Try looking for a compressed HDR texture if ( bHDR ) { /* // FIXME: We need a way to uncompress this format! bool bHDRCompressed = true; pSkyTextureVar = pSkyboxMaterial->FindVar( "$hdrcompressedTexture", NULL ); vtfName = pSkyTextureVar->GetStringValue(); Q_snprintf( srcVTFFileName, MAX_PATH, "materials/%s.vtf", vtfName ); if ( !g_pFullFileSystem->ReadFile( srcVTFFileName, NULL, buf ) ) */ { return false; } } else { return false; } } pSrcVTFTextures[i] = CreateVTFTexture(); if (!pSrcVTFTextures[i]->Unserialize(buf)) { Warning("*** Error unserializing skybox texture: %s\n", pSkyboxMaterialBaseName ); return false; } *pUnionTextureFlags |= pSrcVTFTextures[i]->Flags(); int flagsNoAlpha = pSrcVTFTextures[i]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); int flagsFirstNoAlpha = pSrcVTFTextures[0]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); // NOTE: texture[0] is a side texture that could be 1/2 height, so allow this and also allow 4x4 faces if ( ( ( pSrcVTFTextures[i]->Width() != pSrcVTFTextures[0]->Width() ) && ( pSrcVTFTextures[i]->Width() != 4 ) ) || ( ( pSrcVTFTextures[i]->Height() != pSrcVTFTextures[0]->Height() ) && ( pSrcVTFTextures[i]->Height() != pSrcVTFTextures[0]->Height()*2 ) && ( pSrcVTFTextures[i]->Height() != 4 ) ) || ( flagsNoAlpha != flagsFirstNoAlpha ) ) { Warning("*** Error: Skybox vtf files for %s weren't compiled with the same size texture and/or same flags!\n", pSkyboxMaterialBaseName ); return false; } if ( bHDR ) { pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGB323232F, false ); pSrcVTFTextures[i]->GenerateMipmaps(); pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGBA16161616F, false ); } } return true; }
//----------------------------------------------------------------------------- // Invokes methods on all installed game systems //----------------------------------------------------------------------------- bool IGameSystem::InitAllSystems() { int i; { // first add any auto systems to the end CAutoGameSystem *pSystem = s_pSystemList; while ( pSystem ) { if ( s_GameSystems.Find( pSystem ) == s_GameSystems.InvalidIndex() ) { Add( pSystem ); } else { DevWarning( 1, "AutoGameSystem already added to game system list!!!\n" ); } pSystem = pSystem->m_pNext; } s_pSystemList = NULL; } { CAutoGameSystemPerFrame *pSystem = s_pPerFrameSystemList; while ( pSystem ) { if ( s_GameSystems.Find( pSystem ) == s_GameSystems.InvalidIndex() ) { Add( pSystem ); } else { DevWarning( 1, "AutoGameSystem already added to game system list!!!\n" ); } pSystem = pSystem->m_pNext; } s_pSystemList = NULL; } // Now remember that we are initted so new CAutoGameSystems will add themselves automatically. s_bSystemsInitted = true; for ( i = 0; i < s_GameSystems.Count(); ++i ) { MDLCACHE_CRITICAL_SECTION(); IGameSystem *sys = s_GameSystems[i]; #if defined( _X360 ) char sz[128]; Q_snprintf( sz, sizeof( sz ), "%s->Init():Start", sys->Name() ); XBX_rTimeStampLog( Plat_FloatTime(), sz ); #endif bool valid = sys->Init(); #if defined( _X360 ) Q_snprintf( sz, sizeof( sz ), "%s->Init():Finish", sys->Name() ); XBX_rTimeStampLog( Plat_FloatTime(), sz ); #endif if ( !valid ) return false; } return true; }
void CreateDefaultCubemaps( bool bHDR ) { memset( g_IsCubemapTexData, 0, sizeof(g_IsCubemapTexData) ); // NOTE: This implementation depends on the fact that all VTF files contain // all mipmap levels const char *pSkyboxBaseName = FindSkyboxMaterialName(); char skyboxMaterialName[MAX_PATH]; Q_snprintf( skyboxMaterialName, MAX_PATH, "skybox/%s", pSkyboxBaseName ); IVTFTexture *pSrcVTFTextures[6]; if( !skyboxMaterialName ) { if( s_DefaultCubemapNames.Count() ) { Warning( "This map uses env_cubemap, and you don't have a skybox, so no default env_cubemaps will be generated.\n" ); } return; } int unionTextureFlags = 0; if( !LoadSrcVTFFiles( pSrcVTFTextures, skyboxMaterialName, &unionTextureFlags, bHDR ) ) { Warning( "Can't load skybox file %s to build the default cubemap!\n", skyboxMaterialName ); return; } Msg( "Creating default %scubemaps for env_cubemap using skybox materials:\n %s*.vmt\n" " ! Run buildcubemaps in the engine to get the correct cube maps.\n", bHDR ? "HDR " : "LDR ", skyboxMaterialName ); // Figure out the mip differences between the two textures int iMipLevelOffset = 0; int tmp = pSrcVTFTextures[0]->Width(); while( tmp > DEFAULT_CUBEMAP_SIZE ) { iMipLevelOffset++; tmp >>= 1; } // Create the destination cubemap IVTFTexture *pDstCubemap = CreateVTFTexture(); pDstCubemap->Init( DEFAULT_CUBEMAP_SIZE, DEFAULT_CUBEMAP_SIZE, 1, pSrcVTFTextures[0]->Format(), unionTextureFlags | TEXTUREFLAGS_ENVMAP, pSrcVTFTextures[0]->FrameCount() ); // First iterate over all frames for (int iFrame = 0; iFrame < pDstCubemap->FrameCount(); ++iFrame) { // Next iterate over all normal cube faces (we know there's 6 cause it's an envmap) for (int iFace = 0; iFace < 6; ++iFace ) { // Finally, iterate over all mip levels in the *destination* for (int iMip = 0; iMip < pDstCubemap->MipCount(); ++iMip ) { // Copy the bits from the source images into the cube faces unsigned char *pSrcBits = pSrcVTFTextures[iFace]->ImageData( iFrame, 0, iMip + iMipLevelOffset ); unsigned char *pDstBits = pDstCubemap->ImageData( iFrame, iFace, iMip ); int iSize = pDstCubemap->ComputeMipSize( iMip ); int iSrcMipSize = pSrcVTFTextures[iFace]->ComputeMipSize( iMip + iMipLevelOffset ); // !!! FIXME: Set this to black until HDR cubemaps are built properly! memset( pDstBits, 0, iSize ); continue; if ( ( pSrcVTFTextures[iFace]->Width() == 4 ) && ( pSrcVTFTextures[iFace]->Height() == 4 ) ) // If texture is 4x4 square { // Force mip level 2 to get the 1x1 face unsigned char *pSrcBits = pSrcVTFTextures[iFace]->ImageData( iFrame, 0, 2 ); int iSrcMipSize = pSrcVTFTextures[iFace]->ComputeMipSize( 2 ); // Replicate 1x1 mip level across entire face //memset( pDstBits, 0, iSize ); for ( int i = 0; i < ( iSize / iSrcMipSize ); i++ ) { memcpy( pDstBits + ( i * iSrcMipSize ), pSrcBits, iSrcMipSize ); } } else if ( pSrcVTFTextures[iFace]->Width() == pSrcVTFTextures[iFace]->Height() ) // If texture is square { if ( iSrcMipSize != iSize ) { Warning( "%s - ERROR! Cannot copy square face for default cubemap! iSrcMipSize(%d) != iSize(%d)\n", skyboxMaterialName, iSrcMipSize, iSize ); memset( pDstBits, 0, iSize ); } else { // Just copy the mip level memcpy( pDstBits, pSrcBits, iSize ); } } else if ( pSrcVTFTextures[iFace]->Width() == pSrcVTFTextures[iFace]->Height()*2 ) // If texture is rectangle 2x wide { int iMipWidth, iMipHeight, iMipDepth; pDstCubemap->ComputeMipLevelDimensions( iMip, &iMipWidth, &iMipHeight, &iMipDepth ); if ( ( iMipHeight > 1 ) && ( iSrcMipSize*2 != iSize ) ) { Warning( "%s - ERROR building default cube map! %d*2 != %d\n", skyboxMaterialName, iSrcMipSize, iSize ); memset( pDstBits, 0, iSize ); } else { // Copy row at a time and repeat last row memcpy( pDstBits, pSrcBits, iSize/2 ); //memcpy( pDstBits + iSize/2, pSrcBits, iSize/2 ); int nSrcRowSize = pSrcVTFTextures[iFace]->RowSizeInBytes( iMip + iMipLevelOffset ); int nDstRowSize = pDstCubemap->RowSizeInBytes( iMip ); if ( nSrcRowSize != nDstRowSize ) { Warning( "%s - ERROR building default cube map! nSrcRowSize(%d) != nDstRowSize(%d)!\n", skyboxMaterialName, nSrcRowSize, nDstRowSize ); memset( pDstBits, 0, iSize ); } else { for ( int i = 0; i < ( iSize/2 / nSrcRowSize ); i++ ) { memcpy( pDstBits + iSize/2 + i*nSrcRowSize, pSrcBits + iSrcMipSize - nSrcRowSize, nSrcRowSize ); } } } } else { // ERROR! This code only supports square and rectangluar 2x wide Warning( "%s - Couldn't create default cubemap because texture res is %dx%d\n", skyboxMaterialName, pSrcVTFTextures[iFace]->Width(), pSrcVTFTextures[iFace]->Height() ); memset( pDstBits, 0, iSize ); return; } } } } ImageFormat originalFormat = pDstCubemap->Format(); if( !bHDR ) { // Convert the cube to format that we can apply tools to it... pDstCubemap->ConvertImageFormat( IMAGE_FORMAT_DEFAULT, false ); } // Fixup the cubemap facing pDstCubemap->FixCubemapFaceOrientation(); // Now that the bits are in place, compute the spheremaps... pDstCubemap->GenerateSpheremap(); if( !bHDR ) { // Convert the cubemap to the final format pDstCubemap->ConvertImageFormat( originalFormat, false ); } // Write the puppy out! char dstVTFFileName[1024]; if( bHDR ) { sprintf( dstVTFFileName, "materials/maps/%s/cubemapdefault.hdr.vtf", mapbase ); } else { sprintf( dstVTFFileName, "materials/maps/%s/cubemapdefault.vtf", mapbase ); } CUtlBuffer outputBuf; if (!pDstCubemap->Serialize( outputBuf )) { Warning( "Error serializing default cubemap %s\n", dstVTFFileName ); return; } IZip *pak = GetPakFile(); // spit out the default one. AddBufferToPak( pak, dstVTFFileName, outputBuf.Base(), outputBuf.TellPut(), false ); // spit out all of the ones that are attached to world geometry. int i; for( i = 0; i < s_DefaultCubemapNames.Count(); i++ ) { char vtfName[MAX_PATH]; VTFNameToHDRVTFName( s_DefaultCubemapNames[i], vtfName, MAX_PATH, bHDR ); if( FileExistsInPak( pak, vtfName ) ) { continue; } AddBufferToPak( pak, vtfName, outputBuf.Base(),outputBuf.TellPut(), false ); } // Clean up the textures for( i = 0; i < 6; i++ ) { DestroyVTFTexture( pSrcVTFTextures[i] ); } DestroyVTFTexture( pDstCubemap ); }
bool GetCurrentPurchaseCount( void ) { if ( mysql->InitMySQL( "gamestats_cstrike", pHostName, pUserName, pPassword ) ) { Msg( "Successfully connected to database %s on host %s, user %s\n", "gamestats_cstrike", pHostName, pUserName ); //Get purchase counts. mysql->Execute( "select * from weapons;" ); bool bFoundNext = mysql->SeekToFirstRow(); int iIndex = WEAPON_P228; while( bFoundNext && iIndex < WEAPON_MAX ) { bFoundNext = mysql->NextRow(); g_iCurrentWeaponPurchases[iIndex] = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "Count" ) ); g_Weapons[iIndex].iPurchaseCount = g_iCurrentWeaponPurchases[iIndex]; iIndex++; } mysql->Execute( "select * from snapshot_counter;" ); mysql->SeekToFirstRow(); mysql->NextRow(); //Get snapshot counter. g_iCounter = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "counter" ) ); mysql->Execute( "select * from reset_counter;" ); mysql->SeekToFirstRow(); mysql->NextRow(); //Get reset snapshot counter. g_iResetCounter = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "counter" ) ); //Get current price and purchase count mysql->Execute( "select * from weapon_info;" ); bFoundNext = mysql->SeekToFirstRow(); iIndex = WEAPON_P228; while( bFoundNext && iIndex < WEAPON_MAX ) { bFoundNext = mysql->NextRow(); int iWeaponID = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "WeaponID" ) ); g_Weapons[iWeaponID].iCurrentPrice = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "current_price" ) ); if ( g_bWeeklyUpdate == true ) { int iPreviousPurchases = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases_thisweek" ) ); g_Weapons[iWeaponID].iPurchaseCount = g_iPurchaseDelta[iWeaponID] = iPreviousPurchases; } else { int iPreviousPurchases = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases" ) ); int iPurchasesThisWeek = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases_thisweek" ) ); g_iPurchaseDelta[iWeaponID] = g_iCurrentWeaponPurchases[iWeaponID] - iPreviousPurchases; g_Weapons[iWeaponID].iPurchaseCount = g_iPurchaseDelta[iWeaponID] + iPurchasesThisWeek; } iIndex++; } if ( g_bWeeklyUpdate == true ) { iIndex = WEAPON_P228; while( iIndex < WEAPON_MAX ) { char szQueryString[512]; Q_snprintf( szQueryString, 512, "select * from purchases_pricing where snapshot=\"%d_%d\"", g_iCounter, iIndex ); //Get current price and purchase count mysql->Execute( szQueryString ); mysql->SeekToFirstRow(); mysql->NextRow(); g_iPurchaseDelta[iIndex] = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases" ) ); iIndex++; } } return true; } Msg( "mysql->InitMySQL( %s, %s, %s, [password]) failed\n", "gamestats_cstrike", pHostName, pUserName ); return false; }
//----------------------------------------------------------------------------- // Create a VMT to override the specified texinfo which references the cubemap entity at the specified origin. // Returns the index of the new (or preexisting) texinfo referencing that VMT. // // Also adds the new cubemap VTF filename to s_DefaultCubemapNames so it can copy the // default (skybox) cubemap into this file so the cubemap doesn't have the pink checkerboard at // runtime before they run buildcubemaps. //----------------------------------------------------------------------------- static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3] ) { // Don't make cubemap tex infos for nodes if ( originalTexInfo == TEXINFO_NODE ) return originalTexInfo; texinfo_t *pTexInfo = &texinfo[originalTexInfo]; dtexdata_t *pTexData = GetTexData( pTexInfo->texdata ); const char *pMaterialName = TexDataStringTable_GetString( pTexData->nameStringTableID ); if ( g_IsCubemapTexData[pTexInfo->texdata] ) { Warning("Multiple references for cubemap on texture %s!!!\n", pMaterialName ); return originalTexInfo; } // Get out of here if the originalTexInfo is already a generated material for this position. char pStringToSearchFor[512]; Q_snprintf( pStringToSearchFor, 512, "_%d_%d_%d", origin[0], origin[1], origin[2] ); if ( Q_stristr( pMaterialName, pStringToSearchFor ) ) return originalTexInfo; // Package up information needed to generate patch names PatchInfo_t info; info.m_pMapName = mapbase; info.m_pOrigin[0] = origin[0]; info.m_pOrigin[1] = origin[1]; info.m_pOrigin[2] = origin[2]; // Generate the name of the patched material char pGeneratedTexDataName[1024]; GeneratePatchedName( pMaterialName, info, true, pGeneratedTexDataName, 1024 ); // Make sure the texdata doesn't already exist. int nTexDataID = FindTexData( pGeneratedTexDataName ); bool bHasTexData = (nTexDataID != -1); if( !bHasTexData ) { // Generate the new "$envmap" texture name. char pTextureName[1024]; GeneratePatchedName( "c", info, false, pTextureName, 1024 ); // Hook the texture into the material and all dependent materials // but if no hooking was necessary, exit out if ( !PatchEnvmapForMaterialAndDependents( pMaterialName, info, pTextureName ) ) return originalTexInfo; // Store off the name of the cubemap that we need to create since we successfully patched char pFileName[1024]; int nLen = Q_snprintf( pFileName, 1024, "materials/%s.vtf", pTextureName ); int id = s_DefaultCubemapNames.AddToTail(); s_DefaultCubemapNames[id] = new char[ nLen + 1 ]; strcpy( s_DefaultCubemapNames[id], pFileName ); // Make a new texdata nTexDataID = AddCloneTexData( pTexData, pGeneratedTexDataName ); g_IsCubemapTexData[nTexDataID] = true; } Assert( nTexDataID != -1 ); texinfo_t newTexInfo; newTexInfo = *pTexInfo; newTexInfo.texdata = nTexDataID; int nTexInfoID = -1; // See if we need to make a new texinfo bool bHasTexInfo = false; if( bHasTexData ) { nTexInfoID = FindTexInfo( newTexInfo ); bHasTexInfo = (nTexInfoID != -1); } // Make a new texinfo if we need to. if( !bHasTexInfo ) { nTexInfoID = texinfo.AddToTail( newTexInfo ); } Assert( nTexInfoID != -1 ); return nTexInfoID; }
void CCollisionProperty::ComputeSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs ) { if (( GetSolid() == SOLID_CUSTOM ) && (m_nSurroundType != USE_GAME_CODE )) { // NOTE: This can only happen in transition periods, say during network // reception on the client. We expect USE_GAME_CODE to be used with SOLID_CUSTOM *pVecWorldMins = GetCollisionOrigin(); *pVecWorldMaxs = *pVecWorldMins; return; } switch( m_nSurroundType ) { case USE_OBB_COLLISION_BOUNDS: Assert( GetSolid() != SOLID_CUSTOM ); ComputeOBBBounds( pVecWorldMins, pVecWorldMaxs ); break; case USE_BEST_COLLISION_BOUNDS: Assert( GetSolid() != SOLID_CUSTOM ); ComputeCollisionSurroundingBox( (GetSolid() == SOLID_VPHYSICS), pVecWorldMins, pVecWorldMaxs ); break; case USE_ROTATION_EXPANDED_SEQUENCE_BOUNDS: ComputeRotationExpandedSequenceBounds( pVecWorldMins, pVecWorldMaxs ); break; case USE_COLLISION_BOUNDS_NEVER_VPHYSICS: Assert( GetSolid() != SOLID_CUSTOM ); ComputeCollisionSurroundingBox( false, pVecWorldMins, pVecWorldMaxs ); break; case USE_HITBOXES: ComputeHitboxSurroundingBox( pVecWorldMins, pVecWorldMaxs ); break; case USE_ROTATION_EXPANDED_BOUNDS: ComputeRotationExpandedBounds( pVecWorldMins, pVecWorldMaxs ); break; case USE_SPECIFIED_BOUNDS: VectorAdd( GetCollisionOrigin(), m_vecSpecifiedSurroundingMins, *pVecWorldMins ); VectorAdd( GetCollisionOrigin(), m_vecSpecifiedSurroundingMaxs, *pVecWorldMaxs ); break; case USE_GAME_CODE: GetOuter()->ComputeWorldSpaceSurroundingBox( pVecWorldMins, pVecWorldMaxs ); Assert( pVecWorldMins->x <= pVecWorldMaxs->x ); Assert( pVecWorldMins->y <= pVecWorldMaxs->y ); Assert( pVecWorldMins->z <= pVecWorldMaxs->z ); return; } //#ifdef DEBUG #ifdef CLIENT_DLL if ( cl_show_bounds_errors.GetBool() && ( m_nSurroundType == USE_ROTATION_EXPANDED_SEQUENCE_BOUNDS ) ) { // For debugging purposes, make sure the bounds actually does surround the thing. // Otherwise the optimization we were using isn't really all that great, is it? Vector vecTestMins, vecTestMaxs; if ( GetOuter()->GetBaseAnimating() ) { GetOuter()->GetBaseAnimating()->InvalidateBoneCache(); } ComputeHitboxSurroundingBox( &vecTestMins, &vecTestMaxs ); Assert( vecTestMins.x >= pVecWorldMins->x && vecTestMins.y >= pVecWorldMins->y && vecTestMins.z >= pVecWorldMins->z ); Assert( vecTestMaxs.x <= pVecWorldMaxs->x && vecTestMaxs.y <= pVecWorldMaxs->y && vecTestMaxs.z <= pVecWorldMaxs->z ); if ( vecTestMins.x < pVecWorldMins->x || vecTestMins.y < pVecWorldMins->y || vecTestMins.z < pVecWorldMins->z || vecTestMaxs.x > pVecWorldMaxs->x || vecTestMaxs.y > pVecWorldMaxs->y || vecTestMaxs.z > pVecWorldMaxs->z ) { const char *pSeqName = "<unknown seq>"; C_BaseAnimating *pAnim = GetOuter()->GetBaseAnimating(); if ( pAnim ) { int nSequence = pAnim->GetSequence(); pSeqName = pAnim->GetSequenceName( nSequence ); } Warning( "*** Bounds problem, index %d Eng %s, Seqeuence %s ", GetOuter()->entindex(), GetOuter()->GetClassname(), pSeqName ); Vector vecDelta = *pVecWorldMins - vecTestMins; Vector vecDelta2 = vecTestMaxs - *pVecWorldMaxs; if ( vecDelta.x > 0.0f || vecDelta2.x > 0.0f || vecDelta.y > 0.0f || vecDelta2.y > 0.0f ) { Msg( "Outside X/Y by %.2f ", MAX( MAX( vecDelta.x, vecDelta2.x ), MAX( vecDelta.y, vecDelta2.y ) ) ); } if ( vecDelta.z > 0.0f || vecDelta2.z > 0.0f ) { Msg( "Outside Z by (below) %.2f, (above) %.2f ", MAX( vecDelta.z, 0.0f ), MAX( vecDelta2.z, 0.0f ) ); } Msg( "\n" ); char pTemp[MAX_PATH]; Q_snprintf( pTemp, sizeof(pTemp), "%s [seq: %s]", GetOuter()->GetClassname(), pSeqName ); debugoverlay->AddBoxOverlay( vec3_origin, vecTestMins, vecTestMaxs, vec3_angle, 255, 0, 0, 0, 2 ); debugoverlay->AddBoxOverlay( vec3_origin, *pVecWorldMins, *pVecWorldMaxs, vec3_angle, 0, 0, 255, 0, 2 ); debugoverlay->AddTextOverlay( ( vecTestMins + vecTestMaxs ) * 0.5f, 2, pTemp ); } } #endif //#endif }
//----------------------------------------------------------------------------- // Sends client commands back to the server: //----------------------------------------------------------------------------- void C_BaseObject::SendClientCommand( const char *pCmd ) { char szbuf[128]; Q_snprintf( szbuf, sizeof( szbuf ), "objcmd %d %s", entindex(), pCmd ); engine->ClientCmd(szbuf); }
int main( int argc, char **argv ) { SpewOutputFunc( VTF2TGAOutputFunc ); CommandLine()->CreateCmdLine( argc, argv ); MathLib_Init( 2.2f, 2.2f, 0.0f, 1.0f, false, false, false, false ); InitDefaultFileSystem(); const char *pVTFFileName = CommandLine()->ParmValue( "-i" ); const char *pTGAFileName = CommandLine()->ParmValue( "-o" ); bool bGenerateMipLevels = CommandLine()->CheckParm( "-mip" ) != NULL; if ( !pVTFFileName ) { Usage(); } if ( !pTGAFileName ) { pTGAFileName = pVTFFileName; } char pCurrentDirectory[MAX_PATH]; if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL ) { fprintf( stderr, "Unable to get the current directory\n" ); return -1; } Q_StripTrailingSlash( pCurrentDirectory ); char pBuf[MAX_PATH]; if ( !Q_IsAbsolutePath( pTGAFileName ) ) { Q_snprintf( pBuf, sizeof(pBuf), "%s\\%s", pCurrentDirectory, pTGAFileName ); } else { Q_strncpy( pBuf, pTGAFileName, sizeof(pBuf) ); } Q_FixSlashes( pBuf ); char pOutFileNameBase[MAX_PATH]; Q_StripExtension( pBuf, pOutFileNameBase, MAX_PATH ); char pActualVTFFileName[MAX_PATH]; Q_strncpy( pActualVTFFileName, pVTFFileName, MAX_PATH ); if ( !Q_strstr( pActualVTFFileName, ".vtf" ) ) { Q_strcat( pActualVTFFileName, ".vtf", MAX_PATH ); } FILE *vtfFp = fopen( pActualVTFFileName, "rb" ); if( !vtfFp ) { Error( "Can't open %s\n", pActualVTFFileName ); exit( -1 ); } fseek( vtfFp, 0, SEEK_END ); int srcVTFLength = ftell( vtfFp ); fseek( vtfFp, 0, SEEK_SET ); CUtlBuffer buf; buf.EnsureCapacity( srcVTFLength ); int nBytesRead = fread( buf.Base(), 1, srcVTFLength, vtfFp ); fclose( vtfFp ); buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); IVTFTexture *pTex = CreateVTFTexture(); if (!pTex->Unserialize( buf )) { Error( "*** Error reading in .VTF file %s\n", pActualVTFFileName ); exit(-1); } Msg( "vtf width: %d\n", pTex->Width() ); Msg( "vtf height: %d\n", pTex->Height() ); Msg( "vtf numFrames: %d\n", pTex->FrameCount() ); Msg( "TEXTUREFLAGS_POINTSAMPLE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_POINTSAMPLE ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_TRILINEAR=%s\n", ( pTex->Flags() & TEXTUREFLAGS_TRILINEAR ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPS ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPT=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPT ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPU=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPU ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ANISOTROPIC=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ANISOTROPIC ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_HINT_DXT5=%s\n", ( pTex->Flags() & TEXTUREFLAGS_HINT_DXT5 ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_SRGB=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SRGB ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NORMAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NORMAL ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NOMIP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOMIP ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NOLOD=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOLOD ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ALL_MIPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ALL_MIPS ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_PROCEDURAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_PROCEDURAL ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ONEBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_EIGHTBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ENVMAP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ENVMAP ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_RENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_RENDERTARGET ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_DEPTHRENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_DEPTHRENDERTARGET ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NODEBUGOVERRIDE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NODEBUGOVERRIDE ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_SINGLECOPY=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SINGLECOPY ) ? "true" : "false" ); Vector vecReflectivity = pTex->Reflectivity(); Msg( "vtf reflectivity: %f %f %f\n", vecReflectivity[0], vecReflectivity[1], vecReflectivity[2] ); Msg( "transparency: " ); if( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA ) { Msg( "eightbitalpha\n" ); } else if( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA ) { Msg( "onebitalpha\n" ); } else { Msg( "noalpha\n" ); } ImageFormat srcFormat = pTex->Format(); Msg( "vtf format: %s\n", ImageLoader::GetName( srcFormat ) ); int iTGANameLen = Q_strlen( pOutFileNameBase ); int iFaceCount = pTex->FaceCount(); int nFrameCount = pTex->FrameCount(); bool bIsCubeMap = pTex->IsCubeMap(); int iLastMipLevel = bGenerateMipLevels ? pTex->MipCount() - 1 : 0; for( int iFrame = 0; iFrame < nFrameCount; ++iFrame ) { for ( int iMipLevel = 0; iMipLevel <= iLastMipLevel; ++iMipLevel ) { int iWidth, iHeight, iDepth; pTex->ComputeMipLevelDimensions( iMipLevel, &iWidth, &iHeight, &iDepth ); for (int iCubeFace = 0; iCubeFace < iFaceCount; ++iCubeFace) { for ( int z = 0; z < iDepth; ++z ) { // Construct output filename char *pTempNameBuf = (char *)stackalloc( iTGANameLen + 13 ); Q_strncpy( pTempNameBuf, pOutFileNameBase, iTGANameLen + 1 ); char *pExt = Q_strrchr( pTempNameBuf, '.' ); if ( pExt ) { pExt = 0; } if ( bIsCubeMap ) { Assert( pTex->Depth() == 1 ); // shouldn't this be 1 instead of 0? static const char *pCubeFaceName[7] = { "rt", "lf", "bk", "ft", "up", "dn", "sph" }; Q_strcat( pTempNameBuf, pCubeFaceName[iCubeFace], iTGANameLen + 13 ); } if ( nFrameCount > 1 ) { char pTemp[4]; Q_snprintf( pTemp, 4, "%03d", iFrame ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if ( iLastMipLevel != 0 ) { char pTemp[8]; Q_snprintf( pTemp, 8, "_mip%d", iMipLevel ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if ( pTex->Depth() > 1 ) { char pTemp[6]; Q_snprintf( pTemp, 6, "_z%03d", z ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if( srcFormat == IMAGE_FORMAT_RGBA16161616F ) { Q_strcat( pTempNameBuf, ".pfm", iTGANameLen + 13 ); } else { Q_strcat( pTempNameBuf, ".tga", iTGANameLen + 13 ); } unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel, 0, 0, z ); ImageFormat dstFormat; if( srcFormat == IMAGE_FORMAT_RGBA16161616F ) { dstFormat = IMAGE_FORMAT_RGB323232F; } else { if( ImageLoader::IsTransparent( srcFormat ) || (srcFormat == IMAGE_FORMAT_ATI1N ) || (srcFormat == IMAGE_FORMAT_ATI2N )) { dstFormat = IMAGE_FORMAT_BGRA8888; } else { dstFormat = IMAGE_FORMAT_BGR888; } } // dstFormat = IMAGE_FORMAT_RGBA8888; // dstFormat = IMAGE_FORMAT_RGB888; // dstFormat = IMAGE_FORMAT_BGRA8888; // dstFormat = IMAGE_FORMAT_BGR888; // dstFormat = IMAGE_FORMAT_BGRA5551; // dstFormat = IMAGE_FORMAT_BGR565; // dstFormat = IMAGE_FORMAT_BGRA4444; // printf( "dstFormat: %s\n", ImageLoader::GetName( dstFormat ) ); unsigned char *pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, dstFormat, false )]; if( !ImageLoader::ConvertImageFormat( pSrcImage, srcFormat, pDstImage, dstFormat, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( srcFormat ), ImageLoader::GetName( dstFormat ) ); exit( -1 ); } if( dstFormat != IMAGE_FORMAT_RGB323232F ) { if( ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGBA8888 ) ) { unsigned char *tmpImage = pDstImage; pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGBA8888, false )]; if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGBA8888, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGBA8888 ) ); } dstFormat = IMAGE_FORMAT_RGBA8888; } else if( !ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGB888 ) ) { unsigned char *tmpImage = pDstImage; pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGB888, false )]; if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGB888, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGB888 ) ); } dstFormat = IMAGE_FORMAT_RGB888; } CUtlBuffer outBuffer; TGAWriter::WriteToBuffer( pDstImage, outBuffer, iWidth, iHeight, dstFormat, dstFormat ); if ( !g_pFullFileSystem->WriteFile( pTempNameBuf, NULL, outBuffer ) ) { fprintf( stderr, "unable to write %s\n", pTempNameBuf ); } } else { PFMWrite( ( float * )pDstImage, pTempNameBuf, iWidth, iHeight ); } } } } } // leak leak leak leak leak, leak leak, leak leak (Blue Danube) return 0; }
//----------------------------------------------------------------------------- // Purpose: Button sound table. // Also used by CBaseDoor to get 'touched' door lock/unlock sounds // Input : sound - index of sound to look up. // Output : Returns a pointer to the corresponding sound file. //----------------------------------------------------------------------------- string_t MakeButtonSound( int sound ) { char tmp[1024]; Q_snprintf( tmp, sizeof(tmp), "Buttons.snd%d", sound ); return AllocPooledString(tmp); }
static int read_server_file(void) { char name[MAX_OSPATH], string[MAX_STRING_CHARS]; mapcmd_t cmd; size_t len; // errors like missing file, bad version, etc are // non-fatal and just return to the command handler if (read_binary_file("save/" SAVE_CURRENT "/server.ssv")) return -1; if (MSG_ReadLong() != SAVE_MAGIC1) return -1; if (MSG_ReadLong() != SAVE_VERSION) return -1; memset(&cmd, 0, sizeof(cmd)); // read the comment field MSG_ReadLong(); MSG_ReadLong(); if (MSG_ReadByte()) cmd.loadgame = 2; // autosave else cmd.loadgame = 1; // regular savegame MSG_ReadString(NULL, 0); // read the mapcmd len = MSG_ReadString(cmd.buffer, sizeof(cmd.buffer)); if (len >= sizeof(cmd.buffer)) return -1; // now try to load the map if (!SV_ParseMapCmd(&cmd)) return -1; // save pending CM to be freed later if ERR_DROP is thrown Com_AbortFunc(abort_func, &cmd.cm); // any error will drop from this point SV_Shutdown("Server restarted\n", ERR_RECONNECT); // the rest can't underflow msg_read.allowunderflow = qfalse; // read all CVAR_LATCH cvars // these will be things like coop, skill, deathmatch, etc while (1) { len = MSG_ReadString(name, MAX_QPATH); if (!len) break; if (len >= MAX_QPATH) Com_Error(ERR_DROP, "Savegame cvar name too long"); len = MSG_ReadString(string, sizeof(string)); if (len >= sizeof(string)) Com_Error(ERR_DROP, "Savegame cvar value too long"); Cvar_UserSet(name, string); } // start a new game fresh with new cvars SV_InitGame(MVD_SPAWN_DISABLED); // error out immediately if game doesn't support safe savegames if (!(g_features->integer & GMF_ENHANCED_SAVEGAMES)) Com_Error(ERR_DROP, "Game does not support enhanced savegames"); // read game state len = Q_snprintf(name, MAX_OSPATH, "%s/save/" SAVE_CURRENT "/game.ssv", fs_gamedir); if (len >= MAX_OSPATH) Com_Error(ERR_DROP, "Savegame path too long"); ge->ReadGame(name); // clear pending CM Com_AbortFunc(NULL, NULL); // go to the map SV_SpawnServer(&cmd); return 0; }
//----------------------------------------------------------------------------- // This is called by the base object when it's time to spawn the control panels //----------------------------------------------------------------------------- void CBaseViewModel::SpawnControlPanels() { #if defined( VGUI_CONTROL_PANELS ) char buf[64]; // Destroy existing panels DestroyControlPanels(); CBaseCombatWeapon *weapon = m_hWeapon.Get(); if ( weapon == NULL ) { return; } MDLCACHE_CRITICAL_SECTION(); // FIXME: Deal with dynamically resizing control panels? // If we're attached to an entity, spawn control panels on it instead of use CBaseAnimating *pEntityToSpawnOn = this; char *pOrgLL = "controlpanel%d_ll"; char *pOrgUR = "controlpanel%d_ur"; char *pAttachmentNameLL = pOrgLL; char *pAttachmentNameUR = pOrgUR; /* if ( IsBuiltOnAttachment() ) { pEntityToSpawnOn = dynamic_cast<CBaseAnimating*>((CBaseEntity*)m_hBuiltOnEntity.Get()); if ( pEntityToSpawnOn ) { char sBuildPointLL[64]; char sBuildPointUR[64]; Q_snprintf( sBuildPointLL, sizeof( sBuildPointLL ), "bp%d_controlpanel%%d_ll", m_iBuiltOnPoint ); Q_snprintf( sBuildPointUR, sizeof( sBuildPointUR ), "bp%d_controlpanel%%d_ur", m_iBuiltOnPoint ); pAttachmentNameLL = sBuildPointLL; pAttachmentNameUR = sBuildPointUR; } else { pEntityToSpawnOn = this; } } */ Assert( pEntityToSpawnOn ); // Lookup the attachment point... int nPanel; for ( nPanel = 0; true; ++nPanel ) { Q_snprintf( buf, sizeof( buf ), pAttachmentNameLL, nPanel ); int nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf); if (nLLAttachmentIndex <= 0) { // Try and use my panels then pEntityToSpawnOn = this; Q_snprintf( buf, sizeof( buf ), pOrgLL, nPanel ); nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf); if (nLLAttachmentIndex <= 0) return; } Q_snprintf( buf, sizeof( buf ), pAttachmentNameUR, nPanel ); int nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf); if (nURAttachmentIndex <= 0) { // Try and use my panels then Q_snprintf( buf, sizeof( buf ), pOrgUR, nPanel ); nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf); if (nURAttachmentIndex <= 0) return; } const char *pScreenName; weapon->GetControlPanelInfo( nPanel, pScreenName ); if (!pScreenName) continue; const char *pScreenClassname; weapon->GetControlPanelClassName( nPanel, pScreenClassname ); if ( !pScreenClassname ) continue; // Compute the screen size from the attachment points... matrix3x4_t panelToWorld; pEntityToSpawnOn->GetAttachment( nLLAttachmentIndex, panelToWorld ); matrix3x4_t worldToPanel; MatrixInvert( panelToWorld, worldToPanel ); // Now get the lower right position + transform into panel space Vector lr, lrlocal; pEntityToSpawnOn->GetAttachment( nURAttachmentIndex, panelToWorld ); MatrixGetColumn( panelToWorld, 3, lr ); VectorTransform( lr, worldToPanel, lrlocal ); float flWidth = lrlocal.x; float flHeight = lrlocal.y; CVGuiScreen *pScreen = CreateVGuiScreen( pScreenClassname, pScreenName, pEntityToSpawnOn, this, nLLAttachmentIndex ); pScreen->ChangeTeam( GetTeamNumber() ); pScreen->SetActualSize( flWidth, flHeight ); pScreen->SetActive( false ); pScreen->MakeVisibleOnlyToTeammates( false ); #ifdef INVASION_DLL pScreen->SetOverlayMaterial( SCREEN_OVERLAY_MATERIAL ); #endif pScreen->SetAttachedToViewModel( true ); int nScreen = m_hScreens.AddToTail( ); m_hScreens[nScreen].Set( pScreen ); } #endif }
int main( int argc, char **argv ) { if( argc != 4 ) { Usage(); } MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); InitDefaultFileSystem(); char pCurrentDirectory[MAX_PATH]; if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL ) { fprintf( stderr, "Unable to get the current directory\n" ); return -1; } Q_FixSlashes( pCurrentDirectory ); Q_StripTrailingSlash( pCurrentDirectory ); char pBuf[3][MAX_PATH]; const char *pFileName[3]; for ( int i = 0; i < 3; ++i ) { if ( !Q_IsAbsolutePath( argv[i+1] ) ) { Q_snprintf( pBuf[i], sizeof(pBuf[i]), "%s\\%s", pCurrentDirectory, argv[i+1] ); pFileName[i] = pBuf[i]; } else { pFileName[i] = argv[i+1]; } } int width1, height1; ImageFormat imageFormat1; float gamma1; CUtlBuffer buf1; if ( !g_pFullFileSystem->ReadFile( pFileName[0], NULL, buf1 ) ) { fprintf( stderr, "%s not found\n", pFileName[0] ); return -1; } if( !TGALoader::GetInfo( buf1, &width1, &height1, &imageFormat1, &gamma1 ) ) { printf( "error loading %s\n", pFileName[0] ); exit( -1 ); } int width2, height2; ImageFormat imageFormat2; float gamma2; CUtlBuffer buf2; if ( !g_pFullFileSystem->ReadFile( pFileName[1], NULL, buf2 ) ) { fprintf( stderr, "%s not found\n", pFileName[1] ); return -1; } if( !TGALoader::GetInfo( buf2, &width2, &height2, &imageFormat2, &gamma2 ) ) { printf( "error loading %s\n", pFileName[1] ); exit( -1 ); } if( width1 != width2 || height1 != height2 ) { printf( "image dimensions different (%dx%d!=%dx%d): can't do diff for %s\n", width1, height1, width2, height2, pFileName[2] ); exit( -1 ); } #if 0 // have to allow for different formats for now due to *.txt file screwup. if( imageFormat1 != imageFormat2 ) { printf( "image format different (%s!=%s). . can't do diff for %s\n", ImageLoader::GetName( imageFormat1 ), ImageLoader::GetName( imageFormat2 ), pFileName[2] ); exit( -1 ); } #endif if( gamma1 != gamma2 ) { printf( "image gamma different (%f!=%f). . can't do diff for %s\n", gamma1, gamma2, pFileName[2] ); exit( -1 ); } unsigned char *pImage1Tmp = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, imageFormat1, false )]; unsigned char *pImage2Tmp = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, imageFormat2, false )]; buf1.SeekGet( CUtlBuffer::SEEK_HEAD, 0 ); if( !TGALoader::Load( pImage1Tmp, buf1, width1, height1, imageFormat1, 2.2f, false ) ) { printf( "error loading %s\n", pFileName[0] ); exit( -1 ); } buf2.SeekGet( CUtlBuffer::SEEK_HEAD, 0 ); if( !TGALoader::Load( pImage2Tmp, buf2, width2, height2, imageFormat2, 2.2f, false ) ) { printf( "error loading %s\n", pFileName[1] ); exit( -1 ); } unsigned char *pImage1 = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, IMAGE_FORMAT_ABGR8888, false )]; unsigned char *pImage2 = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, IMAGE_FORMAT_ABGR8888, false )]; unsigned char *pDiff = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, IMAGE_FORMAT_ABGR8888, false )]; ImageLoader::ConvertImageFormat( pImage1Tmp, imageFormat1, pImage1, IMAGE_FORMAT_ABGR8888, width1, height1, 0, 0 ); ImageLoader::ConvertImageFormat( pImage2Tmp, imageFormat2, pImage2, IMAGE_FORMAT_ABGR8888, width2, height2, 0, 0 ); int sizeInBytes = ImageLoader::SizeInBytes( IMAGE_FORMAT_ABGR8888 ); bool isDifferent = false; for( int i = 0; i < width1 * height1 * sizeInBytes; i++ ) { int d; d = pImage2[i] - pImage1[i]; pDiff[i] = d > 0 ? d : -d; if( d != 0 ) { isDifferent = true; } } if( !isDifferent ) { printf( "Files are the same %s %s : not generating %s\n", pFileName[0], pFileName[1], pFileName[2] ); exit( -1 ); } else { printf( "Generating diff: %s!\n", pFileName[2] ); } ImageFormat dstImageFormat; // get rid of this until we get the formats matching // if( sizeInBytes == 3 ) // { // dstImageFormat = IMAGE_FORMAT_RGB888; // } // else { dstImageFormat = IMAGE_FORMAT_RGBA8888; } CUtlBuffer outBuffer; if ( !TGAWriter::WriteToBuffer( pDiff, outBuffer, width1, height1, dstImageFormat, dstImageFormat ) ) { printf( "error writing %s to buffer\n", pFileName[2] ); exit( -1 ); } if ( !g_pFullFileSystem->WriteFile( pFileName[2], NULL, outBuffer ) ) { fprintf( stderr, "unable to write %s\n", pFileName[2] ); return -1; } return 0; }
/* ================ FS_LoadImage loading and unpack to rgba any known image ================ */ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) { const char *ext = FS_FileExtension( filename ); string path, loadname, sidename; qboolean anyformat = true; int i, filesize = 0; const loadpixformat_t *format; const cubepack_t *cmap; byte *f; Image_Reset(); // clear old image Q_strncpy( loadname, filename, sizeof( loadname )); if( Q_stricmp( ext, "" )) { // we needs to compare file extension with list of supported formats // and be sure what is real extension, not a filename with dot for( format = image.loadformats; format && format->formatstring; format++ ) { if( !Q_stricmp( format->ext, ext )) { FS_StripExtension( loadname ); anyformat = false; break; } } } // HACKHACK: skip any checks, load file from buffer if( filename[0] == '#' && buffer && size ) goto load_internal; // now try all the formats in the selected list for( format = image.loadformats; format && format->formatstring; format++) { if( anyformat || !Q_stricmp( ext, format->ext )) { Q_sprintf( path, format->formatstring, loadname, "", format->ext ); image.hint = format->hint; f = FS_LoadFile( path, &filesize, false ); if( f && filesize > 0 ) { if( format->loadfunc( path, f, filesize )) { Mem_Free( f ); // release buffer return ImagePack(); // loaded } else Mem_Free(f); // release buffer } } } // check all cubemap sides with package suffix for( cmap = load_cubemap; cmap && cmap->type; cmap++ ) { for( i = 0; i < 6; i++ ) { // for support mixed cubemaps e.g. sky_ft.bmp, sky_rt.tga // NOTE: all loaders must keep sides in one format for all for( format = image.loadformats; format && format->formatstring; format++ ) { if( anyformat || !Q_stricmp( ext, format->ext )) { Q_sprintf( path, format->formatstring, loadname, cmap->type[i].suf, format->ext ); image.hint = cmap->type[i].hint; // side hint f = FS_LoadFile( path, &filesize, false ); if( f && filesize > 0 ) { // this name will be used only for tell user about problems if( format->loadfunc( path, f, filesize )) { Q_snprintf( sidename, sizeof( sidename ), "%s%s.%s", loadname, cmap->type[i].suf, format->ext ); if( FS_AddSideToPack( sidename, cmap->type[i].flags )) // process flags to flip some sides { Mem_Free( f ); break; // loaded } } Mem_Free( f ); } } } if( image.num_sides != i + 1 ) // check side { // first side not found, probably it's not cubemap // it contain info about image_type and dimensions, don't generate black cubemaps if( !image.cubemap ) break; MsgDev( D_ERROR, "FS_LoadImage: couldn't load (%s%s), create black image\n", loadname, cmap->type[i].suf ); // Mem_Alloc already filled memblock with 0x00, no need to do it again image.cubemap = Mem_Realloc( host.imagepool, image.cubemap, image.ptr + image.size ); image.ptr += image.size; // move to next image.num_sides++; // merge counter } } // make sure what all sides is loaded if( image.num_sides != 6 ) { // unexpected errors ? if( image.cubemap ) Mem_Free( image.cubemap ); Image_Reset(); } else break; } if( image.cubemap ) return ImagePack(); // all done load_internal: for( format = image.loadformats; format && format->formatstring; format++ ) { if( anyformat || !Q_stricmp( ext, format->ext )) { image.hint = format->hint; if( buffer && size > 0 ) { if( format->loadfunc( loadname, buffer, size )) return ImagePack(); // loaded } } } if( !image.loadformats || image.loadformats->ext == NULL ) MsgDev( D_NOTE, "FS_LoadImage: imagelib offline\n" ); else if( filename[0] != '#' ) MsgDev( D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", loadname ); // clear any force flags image.force_flags = 0; return NULL; }
void CASW_Mission_Chooser_Source_Local::AddToCampaignList(const char *szCampaignName) { MapListName item; Q_snprintf(item.szMapName, sizeof(item.szMapName), "%s", szCampaignName); m_CampaignList.Insert( item ); }
/* ================ SV_SpawnServer Change the server to a new map, taking all connected clients along with it. ================ */ qboolean SV_SpawnServer( const char *mapname, const char *startspot ) { int i, current_skill; qboolean loadgame, paused; qboolean background, changelevel; // save state loadgame = sv.loadgame; background = sv.background; changelevel = sv.changelevel; paused = sv.paused; if( sv.state == ss_dead ) SV_InitGame(); // the game is just starting else if( !sv_maxclients->modified ) Cmd_ExecuteString( "latch\n", src_command ); else MsgDev( D_ERROR, "SV_SpawnServer: while 'maxplayers' was modified.\n" ); if( !svs.initialized ) return false; svgame.globals->changelevel = false; // will be restored later if needed svs.timestart = Sys_DoubleTime(); svs.spawncount++; // any partially connected client will be restarted if( startspot ) { MsgDev( D_INFO, "Spawn Server: %s [%s]\n", mapname, startspot ); } else { MsgDev( D_INFO, "Spawn Server: %s\n", mapname ); } sv.state = ss_dead; Host_SetServerState( sv.state ); Q_memset( &sv, 0, sizeof( sv )); // wipe the entire per-level structure // restore state sv.paused = paused; sv.loadgame = loadgame; sv.background = background; sv.changelevel = changelevel; sv.time = 1.0f; // server spawn time it's always 1.0 second svgame.globals->time = sv.time; // initialize buffers BF_Init( &sv.datagram, "Datagram", sv.datagram_buf, sizeof( sv.datagram_buf )); BF_Init( &sv.reliable_datagram, "Datagram R", sv.reliable_datagram_buf, sizeof( sv.reliable_datagram_buf )); BF_Init( &sv.multicast, "Multicast", sv.multicast_buf, sizeof( sv.multicast_buf )); BF_Init( &sv.signon, "Signon", sv.signon_buf, sizeof( sv.signon_buf )); BF_Init( &sv.spectator_datagram, "Spectator Datagram", sv.spectator_buf, sizeof( sv.spectator_buf )); // leave slots at start for clients only for( i = 0; i < sv_maxclients->integer; i++ ) { // needs to reconnect if( svs.clients[i].state > cs_connected ) svs.clients[i].state = cs_connected; } // make cvars consistant if( Cvar_VariableInteger( "coop" )) Cvar_SetFloat( "deathmatch", 0 ); current_skill = (int)(Cvar_VariableValue( "skill" ) + 0.5f); current_skill = bound( 0, current_skill, 3 ); Cvar_SetFloat( "skill", (float)current_skill ); if( sv.background ) // tell the game parts about background state Cvar_FullSet( "sv_background", "1", CVAR_READ_ONLY ); else Cvar_FullSet( "sv_background", "0", CVAR_READ_ONLY ); // make sure what server name doesn't contain path and extension FS_FileBase( mapname, sv.name ); if( startspot ) Q_strncpy( sv.startspot, startspot, sizeof( sv.startspot )); else sv.startspot[0] = '\0'; Q_snprintf( sv.model_precache[1], sizeof( sv.model_precache[0] ), "maps/%s.bsp", sv.name ); Mod_LoadWorld( sv.model_precache[1], &sv.checksum, false ); sv.worldmodel = Mod_Handle( 1 ); // get world pointer for( i = 1; i < sv.worldmodel->numsubmodels; i++ ) { Q_sprintf( sv.model_precache[i+1], "*%i", i ); Mod_RegisterModel( sv.model_precache[i+1], i+1 ); } // precache and static commands can be issued during map initialization sv.state = ss_loading; Host_SetServerState( sv.state ); // clear physics interaction links SV_ClearWorld(); // tell dlls about new level started svgame.dllFuncs.pfnParmsNewLevel(); return true; }