コード例 #1
0
ファイル: ZipCrypto.cpp プロジェクト: ismail/7-zip
STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
{
  UInt32 key0 = this->Key0;
  UInt32 key1 = this->Key1;
  UInt32 key2 = this->Key2;
  
  for (UInt32 i = 0; i < size; i++)
  {
    DECRYPT_BYTE_1
    Byte b = (Byte)(data[i] ^ DECRYPT_BYTE_2);
    UPDATE_KEYS(b);
    data[i] = b;
  }
  
  this->Key0 = key0;
  this->Key1 = key1;
  this->Key2 = key2;
  
  return size;
}
コード例 #2
0
		//*************************************************************//
		// UPDATE
		bool InputManager::Update( void )
		{
			// Sanity-check the wrapper's status
			assert( m_eStatus == E_INITIALIZED && "InputManager::Update - wrapper has not been initialized" );
			if( m_eStatus != E_INITIALIZED )
				return false;


			// Store cursor position
			POINT cursor = { };
			RECT clip = { };

			GetCursorPos( &cursor );
			ScreenToClient( m_hWnd, &cursor );

			GetClipCursor( &clip );
			if( clip.left > 0 ) 
				cursor.x -= clip.left;
			if( clip.top > 0 )
				cursor.y -= clip.top;

			m_vCursorMovement = Vector{ (float)cursor.x - m_ptCursor.x, (float)cursor.y - m_ptCursor.y };
			m_ptCursor = Point{ (float)cursor.x, (float)cursor.y };


			// Poll keyboard/mouse key states ONLY if window has focus
			BYTE keyboard[256] = { };
			GetKeyState( 0 );

			if( GetForegroundWindow() == m_hWnd )
				GetKeyboardState( keyboard );

			// Ignore: 0, 7, 10-11, 14-15, 21-26, 28-31, 58-64, 94, 136-143, 146-159, 184-185, 193-218, 224-225, 227-245, 252, 255
#define UPDATE_KEY( key )			m_aKeyboard[ key ] = ((m_aKeyboard[ key ] & Bit_Current) >> 1) | (keyboard[ key ])
#define UPDATE_KEYS( start, stop )	for( int i = start; i <= stop; i++ )	UPDATE_KEY(i);

			UPDATE_KEYS( 1, 6 );
			UPDATE_KEYS( 8, 9 );
			UPDATE_KEYS( 12, 13 );
			UPDATE_KEYS( 16, 20 );
			UPDATE_KEY( 27 );
			UPDATE_KEYS( 32, 57 );
			UPDATE_KEYS( 65, 93 );
			UPDATE_KEYS( 95, 135 );
			UPDATE_KEYS( 144, 145 );
			UPDATE_KEYS( 160, 183 );
			UPDATE_KEYS( 186, 192 );
			UPDATE_KEYS( 219, 223 );
			UPDATE_KEY( 226 );
			UPDATE_KEYS( 246, 251 );
			UPDATE_KEYS( 253, 254 );

#undef UPDATE_KEYS
#undef UPDATE_KEY



			// Update gamepads
			for( unsigned int i = 0; i < m_vGamepads.size(); i++ )
			{
				GamepadInfo& info = m_vGamepads[ i ];

				// Read device state
				DIJOYSTATE state;
				HRESULT hResult = info.pDevice->GetDeviceState( sizeof( DIJOYSTATE ), &state );
				if( FAILED( hResult ) )
				{
					hResult = info.pDevice->Acquire();
					if( FAILED( hResult ) )
					{
						info = GamepadInfo{ info.id, info.pDevice, info.wszName, info.bHasTriggerAxis, false };
						continue;
					}
				}
				
				info.bConnected = true;

				
				// Interpret the dpad / point-of-view hat
				info.ePreviousDPad = info.eDPad;

				DWORD dpad0 = state.rgdwPOV[ 0 ];
				if( dpad0 == 0xFFFFFFFF || dpad0 == 0xFFFF )
					info.eDPad = DPad::Neutral;
				else if( dpad0 < 2250 )
					info.eDPad = DPad::Up;
				else if( dpad0 < 6750 )
					info.eDPad = DPad::UpRight;
				else if( dpad0 < 11250 )
					info.eDPad = DPad::Right;
				else if( dpad0 < 15750 )
					info.eDPad = DPad::DownRight;
				else if( dpad0 < 20250 )
					info.eDPad = DPad::Down;
				else if( dpad0 < 24750 )
					info.eDPad = DPad::DownLeft;
				else if( dpad0 < 29250 )
					info.eDPad = DPad::Left;
				else if( dpad0 < 33750 )
					info.eDPad = DPad::UpLeft;
				else if( dpad0 <= 36000 )
					info.eDPad = DPad::Up;
				else	// invalid?
					info.eDPad = DPad::Neutral;


				// Interpret the buttons
				for( int b = 0; b < 32; b++ )
					info.aButtons[ b ] = ((info.aButtons[ b ] & Bit_Current) >> 1) | state.rgbButtons[ b ];


				// Interpret the joysticks
				info.fLeftX = state.lX * 0.001f;
				info.fLeftY = state.lY * 0.001f;

				if( info.bHasTriggerAxis == true )
				{
					// Right stick *should* be separate
					info.fRightX = state.lRx * 0.001f;
					info.fRightY = state.lRy * 0.001f;
					info.fTrigger = -state.lZ * 0.001f;		// left is negative
				}
				else 
				{
					// Right stick uses left z ... somehow
					info.fRightX = state.lZ  * 0.001f;
					info.fRightY = state.lRz * 0.001f;
					info.fTrigger = 0.0f;
				}
			}

			return true;
		}