void CBaseGameStats_Driver::PossibleMapChange( void ) { #ifdef GAME_DLL //detect and copy map changes if ( Q_stricmp( m_PrevMapName.String(), STRING( gpGlobals->mapname ) ) ) { MEM_ALLOC_CREDIT(); CUtlString PrevMapBackup = m_PrevMapName; m_PrevMapName = STRING( gpGlobals->mapname ); gamestats->Event_MapChange( PrevMapBackup.String(), STRING( gpGlobals->mapname ) ); if ( gamestats->UseOldFormat() ) { if( gamestats->AutoSave_OnMapChange() ) gamestats->SaveToFileNOW(); if( gamestats->AutoUpload_OnMapChange() ) gamestats->UploadStatsFileNOW(); } } #endif }
bool GameModes::GetLastActiveNameId( char *pOutBuffer, int nOutBufferSize ) { if ( g_CurrentModeIdSave.IsEmpty() ) return false; int nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() ); if ( nActive == -1 ) return false; V_strncpy( pOutBuffer, g_CurrentModeIdSave.String(), nOutBufferSize ); return true; }
static HANDLE CreateTempFile( CUtlString &WritePath, CUtlString &FileName ) { char tempFileName[MAX_PATH]; if ( WritePath.IsEmpty() ) { // use a safe name in the cwd char *pBuffer = tmpnam( NULL ); if ( !pBuffer ) { return INVALID_HANDLE_VALUE; } if ( pBuffer[0] == '\\' ) { pBuffer++; } if ( pBuffer[strlen( pBuffer )-1] == '.' ) { pBuffer[strlen( pBuffer )-1] = '\0'; } V_snprintf( tempFileName, sizeof( tempFileName ), "_%s.tmp", pBuffer ); } else { // generate safe name at the desired prefix char uniqueFilename[MAX_PATH]; SYSTEMTIME sysTime; \ GetLocalTime( &sysTime ); sprintf( uniqueFilename, "%d_%d_%d_%d_%d.tmp", sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds ); \ V_ComposeFileName( WritePath.String(), uniqueFilename, tempFileName, sizeof( tempFileName ) ); } FileName = tempFileName; HANDLE hFile = CreateFile( tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); return hFile; }
static HANDLE CreateTempFile( CUtlString &WritePath, CUtlString &FileName ) { char tempFileName[MAX_PATH]; if ( WritePath.IsEmpty() ) { // use a safe name in the cwd char *pBuffer = tmpnam( NULL ); if ( !pBuffer ) { return INVALID_HANDLE_VALUE; } if ( pBuffer[0] == '\\' ) { pBuffer++; } if ( pBuffer[strlen( pBuffer )-1] == '.' ) { pBuffer[strlen( pBuffer )-1] = '\0'; } V_snprintf( tempFileName, sizeof( tempFileName ), "_%s.tmp", pBuffer ); } else { char uniqueFilename[MAX_PATH]; static int counter = 0; time_t now = time( NULL ); struct tm *tm = localtime( &now ); sprintf( uniqueFilename, "%d_%d_%d_%d_%d.tmp", tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec, ++counter ); \ V_ComposeFileName( WritePath.String(), uniqueFilename, tempFileName, sizeof( tempFileName ) ); } FileName = tempFileName; FILE *hFile = fopen( tempFileName, "rw+" ); return (HANDLE)hFile; }
// add a binding to the list. Calls should be in the form: // AddBinding( "left", "button_press", "start", "+dota_camera_follow", "" ); // // args: // hand_str = "left" or "right" // action_str = 'button_press' 'trigger_press' 'tilt_gesture' 'point_gesture' 'velocity_gesture' or 'joystick_move' // argument_str depends on action_str, see below for details // press_command_str is the concommand executed on start of the action (ie button press) and release_command_str on stop (ie button release) // release_command_str can be the empty string if no stop action is desired // if the press_command_str begins with "+", an equivalent "-" is set to the release_command automatically void SixenseGestureBindings::AddBinding( CUtlString hand_str, CUtlString action_str, CUtlString argument_str, CUtlString press_command_str, CUtlString release_command_str ) { GestureBinding binding; // Convert from strings to enums sixenseUtils::IButtonStates::ActionType action; if( !ActionFromString( action_str, &action ) ) { return; } binding.m_Action = action; int hand; if( !HandFromString( hand_str, &hand ) ) { return; } binding.m_iHand = hand; // handle argument_str per-action type if( action == sixenseUtils::IButtonStates::ACTION_BUTTON_PRESS ) { // button_press takes a button argument unsigned short button_token; if( !ButtonMaskFromString( argument_str, &button_token ) ) { return; } binding.m_iArgument = button_token; } else if( action == sixenseUtils::IButtonStates::ACTION_TRIGGER_PRESS ) { // trigger press has no argument binding.m_iArgument = 0; } else { // all other actions take a direction sixenseUtils::IButtonStates::Direction dir; if( !DirectionFromString( argument_str, &dir ) ) { return; } binding.m_iArgument = dir; } // copy the activate command binding.m_pActivateCommand = strdup( press_command_str.String() ); binding.m_bAutoMirrored = false; // if there is an explicit release_command, use it if ( !release_command_str.IsEmpty() ) { binding.m_pDeactivateCommand = strdup( release_command_str.String() ); } else { // otherwise try to generate a release command // see if it starts with a +, if so, add an off command if( press_command_str[0] == '+' ) { binding.m_pDeactivateCommand = strdup( press_command_str.String() ); binding.m_pDeactivateCommand[0] = '-'; binding.m_bAutoMirrored = true; } else { // Just leave release command null binding.m_pDeactivateCommand = NULL; } } // Try to keep a single binding per 'action' 'hand' 'arg' pair, ie one per button. // We may want to allow multiple if people think it would be useful... FOR_EACH_LL( m_GestureBindingList, it ) { GestureBinding existing_binding = m_GestureBindingList[it]; if( binding.m_Action == existing_binding.m_Action && binding.m_iArgument == existing_binding.m_iArgument && binding.m_iHand == existing_binding.m_iHand ) { // Already the same binding active, delete it FreeStrings( existing_binding ); m_GestureBindingList.Remove( it ); break; } }
/* ============== GetToken ============== */ qboolean GetToken (qboolean crossline) { char *token_p; if (tokenready) // is a token allready waiting? { tokenready = false; return true; } // printf("script_p %x (%x)\n", script->script_p, script->end_p ); fflush( stdout ); if (script->script_p >= script->end_p) { return EndOfScript (crossline); } tokenready = false; // skip space, ctrl chars skipspace: while (*script->script_p <= 32) { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } if (*(script->script_p++) == '\n') { if (!crossline) { Error ("Line %i is incomplete\n",scriptline); } scriptline = ++script->line; } } if (script->script_p >= script->end_p) { return EndOfScript (crossline); } // strip single line comments if (*script->script_p == ';' || *script->script_p == '#' || // semicolon and # is comment field (*script->script_p == '/' && *((script->script_p)+1) == '/')) // also make // a comment field { if (!crossline) Error ("Line %i is incomplete\n",scriptline); while (*script->script_p++ != '\n') { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } } scriptline = ++script->line; goto skipspace; } // strip out matching /* */ comments if (*script->script_p == '/' && *((script->script_p)+1) == '*') { script->script_p += 2; while (*script->script_p != '*' || *((script->script_p)+1) != '/') { if (*script->script_p++ != '\n') { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } scriptline = ++script->line; } } script->script_p += 2; goto skipspace; } // copy token to buffer token_p = token; if (*script->script_p == '"') { // quoted token script->script_p++; while (*script->script_p != '"') { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &token[MAXTOKEN]) Error ("Token too large on line %i\n",scriptline); } script->script_p++; } else if ( g_bCheckSingleCharTokens && !g_sSingleCharTokens.IsEmpty() && strchr( g_sSingleCharTokens.String(), *script->script_p ) != NULL ) { *token_p++ = *script->script_p++; } else // regular token while ( *script->script_p > 32 && *script->script_p != ';') { if ( !ExpandMacroToken( token_p ) ) { if ( !ExpandVariableToken( token_p ) ) { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &token[MAXTOKEN]) Error ("Token too large on line %i\n",scriptline); } } } // add null to end of token *token_p = 0; // check for other commands if ( !stricmp( token, "$include" ) ) { GetToken( false ); bool bFallbackToToken = true; CUtlVector< CUtlString > expandedPathList; if ( CmdLib_ExpandWithBasePaths( expandedPathList, token ) > 0 ) { for ( int i = 0; i < expandedPathList.Count(); ++i ) { CUtlVector< CUtlString > findFileList; FindFileAbsoluteList( findFileList, expandedPathList[i].String() ); if ( findFileList.Count() > 0 ) { bFallbackToToken = false; // Only add the first set of glob matches from the first base path for ( int j = 0; j < findFileList.Count(); ++j ) { AddScriptToStack( const_cast< char * >( findFileList[j].String() ) ); } break; } } } if ( bFallbackToToken ) { AddScriptToStack( token ); } return GetToken( crossline ); } else if (!stricmp (token, "$definemacro")) { GetToken (false); DefineMacro(token); return GetToken (crossline); } else if (!stricmp (token, "$definevariable")) { GetToken (false); DefineVariable(token); return GetToken (crossline); } else if (AddMacroToStack( token )) { return GetToken (crossline); } return true; }
bool CUtlString::MatchesPattern( const CUtlString &Pattern, int nFlags ) { const char *pszSource = String(); const char *pszPattern = Pattern.String(); bool bExact = true; while( 1 ) { if ( ( *pszPattern ) == 0 ) { return ( (*pszSource ) == 0 ); } if ( ( *pszPattern ) == '*' ) { pszPattern++; if ( ( *pszPattern ) == 0 ) { return true; } bExact = false; continue; } int nLength = 0; while( ( *pszPattern ) != '*' && ( *pszPattern ) != 0 ) { nLength++; pszPattern++; } while( 1 ) { const char *pszStartPattern = pszPattern - nLength; const char *pszSearch = pszSource; for( int i = 0; i < nLength; i++, pszSearch++, pszStartPattern++ ) { if ( ( *pszSearch ) == 0 ) { return false; } if ( ( *pszSearch ) != ( *pszStartPattern ) ) { break; } } if ( pszSearch - pszSource == nLength ) { break; } if ( bExact == true ) { return false; } if ( ( nFlags & PATTERN_DIRECTORY ) != 0 ) { if ( ( *pszPattern ) != '/' && ( *pszSource ) == '/' ) { return false; } } pszSource++; } pszSource += nLength; } }
void GameModes::ApplySettings( KeyValues *pInResourceData ) { BaseClass::ApplySettings( pInResourceData ); vgui::HScheme hScheme = vgui::scheme()->GetScheme( "SwarmScheme" ); vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( hScheme ); if ( !pScheme ) return; const char *pImageName = pInResourceData->GetString( "borderimage", "" ); m_nBorderImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nBorderImageId == -1 ) { m_nBorderImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nBorderImageId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "leftarrow", "" ); m_nLeftArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nLeftArrowId == -1 ) { m_nLeftArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nLeftArrowId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "rightarrow", "" ); m_nRightArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nRightArrowId == -1 ) { m_nRightArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nRightArrowId, pImageName, true, false ); } m_nPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picoffsetx", 0 ) ); m_nPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picwidth", 0 ) ); m_nPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picheight", 0 ) ); m_nMenuTitleX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlex", 0 ) ); m_nMenuTitleY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitley", 0 ) ); m_nMenuTitleWide = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlewide", 0 ) ); m_nMenuTitleTall = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitletall", 0 ) ); m_nSubPics = pInResourceData->GetInt( "subpics", 0 ); m_nSubPicGap = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicgap", 0 ) ); m_nSubPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsetx", 0 ) ); m_nSubPicOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsety", 0 ) ); m_nSubPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicwidth", 0 ) ); m_nSubPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicheight", 0 ) ); m_bHideLabels = !!vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "hidelabels", 0 ) ); m_nArrowWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowwidth", 0 ) ); m_nArrowHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowheight", 0 ) ); m_nArrowOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowoffsety", 0 ) ); m_nRightArrowOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "rightarrowoffsetx", 0 ) ); m_hNameFont = pScheme->GetFont( pInResourceData->GetString( "subpicnamefont", "" ), true ); m_nNameFontHeight = vgui::surface()->GetFontTall( m_hNameFont ); const char *pNavUp = pInResourceData->GetString( "navUp", "" ); const char *pNavDown = pInResourceData->GetString( "navDown", "" ); int wideAtOpen = pInResourceData->GetInt( "wideatopen", 0 ); // need to reset due to video mode change, alt+tab, etc m_GameModeInfos.Purge(); // find all modes for ( KeyValues *pModeKey = pInResourceData->GetFirstTrueSubKey(); pModeKey; pModeKey = pModeKey->GetNextTrueSubKey() ) { pImageName = pModeKey->GetString( "image", "" ); int nImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( nImageId == -1 ) { nImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( nImageId, pImageName, true, false ); } int iIndex = m_GameModeInfos.AddToTail(); m_GameModeInfos[iIndex].m_NameId = pModeKey->GetString( "id", "" ); m_GameModeInfos[iIndex].m_NameText = pModeKey->GetString( "name", "" ); m_GameModeInfos[iIndex].m_CommandText = pModeKey->GetString( "command", "" ); m_GameModeInfos[iIndex].m_TitleText = pModeKey->GetString( "menutitle", "" ); m_GameModeInfos[iIndex].m_HintText = pModeKey->GetString( "menuhint", "" ); m_GameModeInfos[iIndex].m_HintTextDisabled = pModeKey->GetString( "menuhintdisabled", "" ); m_GameModeInfos[iIndex].m_nImageId = nImageId; m_GameModeInfos[iIndex].m_bEnabled = pModeKey->GetBool( "enabled", true ); m_GameModeInfos[iIndex].m_pHybridButton = new BaseModHybridButton( this, m_GameModeInfos[iIndex].m_NameId, m_GameModeInfos[iIndex].m_TitleText, this->GetParent(), m_GameModeInfos[iIndex].m_CommandText ); KeyValues *pKV = new KeyValues( "BtnGameMode" ); int buttonX = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleX ); int buttonY = vgui::scheme()->GetProportionalNormalizedValue( m_nPicHeight + m_nMenuTitleY ); int buttonW = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleWide ); int buttonH = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleTall ); pKV->SetInt( "xpos", buttonX ); pKV->SetInt( "ypos", buttonY ); pKV->SetInt( "wide", buttonW ); pKV->SetInt( "tall", buttonH ); pKV->SetInt( "autoResize", 1 ); pKV->SetInt( "pinCorner", 0 ); pKV->SetInt( "visible", 0 ); pKV->SetInt( "enabled", m_GameModeInfos[iIndex].m_bEnabled ); pKV->SetInt( "tabPosition", 0 ); if ( IsX360() ) { pKV->SetString( "navUp", pNavUp ); pKV->SetString( "navDown", pNavDown ); } pKV->SetString( "tooltiptext", m_GameModeInfos[iIndex].m_HintText ); pKV->SetString( "disabled_tooltiptext", m_GameModeInfos[iIndex].m_HintTextDisabled ); pKV->SetString( "style", "GameModeButton" ); pKV->SetInt( "ActivationType", 1 ); pKV->SetString( "EnableCondition", pModeKey->GetString( "EnableCondition", "" ) ); pKV->SetInt( "wideatopen", wideAtOpen ); m_GameModeInfos[iIndex].m_pHybridButton->ApplySettings( pKV ); pKV->deleteThis(); } m_nMenuTitleActualTall = m_nMenuTitleTall; if ( m_GameModeInfos.Count() ) { // get the real size m_nMenuTitleActualTall = m_GameModeInfos[0].m_pHybridButton->GetTall(); // fixup the number of subpics to what we actually have // one active plus any subpics can only show the modes with no repeat m_nSubPics = MIN( m_nSubPics, m_GameModeInfos.Count() - 1 ); } else { m_nSubPics = 0; } // exact size fixup width to get hardware clipping on rhs int panelWidth, panelHeight; GetSize( panelWidth, panelHeight ); panelWidth = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX + ( m_nSubPics + 1 ) * m_nSubPicWidth + m_nSubPics * m_nSubPicGap; panelHeight = m_nPicHeight + m_nMenuTitleY + ( m_nMenuTitleActualTall - m_nMenuTitleTall )/2 + m_nMenuTitleTall; SetSize( panelWidth, panelHeight ); // calc the arrow position for drawing and hit testing m_nSubPicX = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX; m_nSubPicY = ( m_nPicHeight + m_nMenuTitleY + m_nMenuTitleTall - m_nSubPicHeight )/2 + m_nSubPicOffsetY; m_nLeftArrowX = m_nPicOffsetX - m_nSubPicGap - m_nArrowWidth; m_nLeftArrowY = m_nSubPicY + m_nSubPicHeight - m_nArrowHeight + m_nArrowOffsetY; if ( m_nRightArrowOffsetX ) { m_nRightArrowX = m_nPicOffsetX + m_nPicWidth + m_nSubPicGap + m_nRightArrowOffsetX; } else { m_nRightArrowX = m_nSubPicX + m_nSubPics * ( m_nSubPicWidth + m_nSubPicGap ); } m_nRightArrowY = m_nLeftArrowY; // try to put back our last known game mode // this is to solve the navigation to children when the navigation has been lost // or alt+tab, video mode resize m_nActive = 0; if ( !g_CurrentModeIdSave.IsEmpty() ) { m_nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() ); if ( m_nActive == -1 ) { // no longer available g_CurrentModeIdSave = NULL; m_nActive = 0; } } SetActiveGameMode( m_nActive, true ); }