#include "INP_Main.h" CInput InternalInputManager; CInput::CInput() { m_Keyboard = CKeyboard(); m_uiSigninJoypadMask = 0; for (int i = 0; i < 4; ++i) m_bIsMenuDisplayed[i] = 0; InitTime(); m_fRepeatDelaySecs = 0.5f; m_fRepeatRateSecs = 0.8f; m_sDebugSequenceName = 0; m_uiDebugSequenceIndex = 0; m_pDebugSequenceFn = 0; #if TO_BE_IMPLEMENTED *((_BYTE *)&loc_650 + this + 1) = 0; #endif } CInput::~CInput() { //~CKeyboard } void CInput::DebugPrintf(const char *szFormat, ...) { va_list ap; va_start(ap, szFormat); char buf[1024]; vsnprintf(buf, sizeof(buf), szFormat, ap); va_end(ap); printf(buf); } void CInput::Initialise(int iInputStateC, unsigned char ucMapC, unsigned char ucActionC, unsigned char ucMenuActionC) { assert(iInputStateC > 0); assert(ucMapC > 0); assert(ucActionC > 0); sceUserServiceInitialize(NULL); scePadInit(); memset(m_Joypads, 0, sizeof(m_Joypads)); m_ucInputStateC = iInputStateC; m_iDeadzone = 0x2; m_iMovementRangeMax = 0x7F; m_iEffectiveRange = m_iMovementRangeMax - m_iDeadzone; m_fEffectiveRange = (float)m_iEffectiveRange; m_iHalfRange = static_cast(m_iEffectiveRange * 0.75); for (int i = 0; i < MAX_JOYPADS; i++) { m_Joypads[i].m_pInputStates = new ScePadData[m_ucInputStateC]; m_Joypads[i].m_ucInputStateIndex = -1; m_Joypads[i].m_pfLeftThumbXAxisMap = &m_Joypads[i].m_fNormalizedLeftThumbX; m_Joypads[i].m_pfLeftThumbYAxisMap = &m_Joypads[i].m_fNormalizedLeftThumbY; m_Joypads[i].m_pfRightThumbXAxisMap = &m_Joypads[i].m_fNormalizedRightThumbX; m_Joypads[i].m_pfRightThumbYAxisMap = &m_Joypads[i].m_fNormalizedRightThumbY; m_Joypads[i].m_pucLeftTriggerAxisMap = &m_Joypads[i].m_ucLeftTriggerState; m_Joypads[i].m_pucRightTriggerAxisMap = &m_Joypads[i].m_ucRightTriggerState; m_Joypads[i].m_fSensitivity = 1.0f; } m_JoypadMap = (unsigned int **)operator new[](ucMapC * sizeof(int *)); for (int i = 0; i < ucMapC; i++) { m_JoypadMap[i] = (unsigned int *)operator new[](ucActionC * sizeof(int)); } m_ucJoypadMapC = ucMapC; m_ucJoypadMapActionC = ucActionC; m_ucMenuActionC = ucMenuActionC; m_bJoypadMapArrayIsSetup = false; } void CInput::Tick() { UpdateJoypads(); m_Keyboard.Tick(); } void CInput::SetJoypadValues(JOYPAD *pThisPad) { ScePadData *pGamePad = &pThisPad->m_pInputStates[pThisPad->m_ucInputStateIndex]; pThisPad->m_uiButtons = pThisPad->m_uiOldButtons; //str1k3r - decomp uses pThisPad->m_uiButtons not pGamePad->buttons if (pGamePad->buttons == SCE_PAD_BUTTON_CROSS) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_X; } if (pGamePad->buttons == SCE_PAD_BUTTON_CIRCLE) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_O; } if (pGamePad->buttons == SCE_PAD_BUTTON_SQUARE) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_SQUARE; } if (pGamePad->buttons == SCE_PAD_BUTTON_TRIANGLE) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_TRIANGLE; } if (pGamePad->buttons == SCE_PAD_BUTTON_R2) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R2; } if (pGamePad->buttons == SCE_PAD_BUTTON_L2) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L2; } if (pGamePad->buttons == SCE_PAD_BUTTON_R1) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R1; } if (pGamePad->buttons == SCE_PAD_BUTTON_L1) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L1; } if (pGamePad->buttons == SCE_PAD_BUTTON_OPTIONS) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_OPTIONS; } if (pGamePad->buttons == SCE_PAD_BUTTON_TOUCH_PAD) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_TOUCHPAD; } if (pGamePad->buttons == SCE_PAD_BUTTON_R3) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R3; } if (pGamePad->buttons == SCE_PAD_BUTTON_L3) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L3; } if (pGamePad->buttons == SCE_PAD_BUTTON_UP) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_UP; } if (pGamePad->buttons == SCE_PAD_BUTTON_DOWN) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_DOWN; } if (pGamePad->buttons == SCE_PAD_BUTTON_LEFT) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_LEFT; } if (pGamePad->buttons == SCE_PAD_BUTTON_RIGHT) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_RIGHT; } pThisPad->m_iNormalizedLeftThumbX = pThisPad->m_iLeftThumbX / m_iEffectiveRange; pThisPad->m_iNormalizedLeftThumbY = pThisPad->m_iLeftThumbY / m_iEffectiveRange; pThisPad->m_iNormalizedRightThumbX = pThisPad->m_iRightThumbX / m_iEffectiveRange; pThisPad->m_iNormalizedRightThumbY = pThisPad->m_iRightThumbY / m_iEffectiveRange; pThisPad->m_fNormalizedLeftThumbX = pThisPad->m_iLeftThumbX / m_fEffectiveRange; pThisPad->m_fNormalizedLeftThumbY = pThisPad->m_iLeftThumbY / m_fEffectiveRange; pThisPad->m_fNormalizedRightThumbX = pThisPad->m_iRightThumbX / m_fEffectiveRange; pThisPad->m_fNormalizedRightThumbY = pThisPad->m_iRightThumbY / m_fEffectiveRange; } void CInput::SetDeadzoneAndMovementRange(unsigned int uiDeadzone, unsigned int uiDeadzoneDigital, unsigned int uiMovementRangeMax) { m_iDeadzone = uiDeadzone; m_iDeadzoneDigital = uiDeadzoneDigital; m_iMovementRangeMax = uiMovementRangeMax; m_iEffectiveRange = uiMovementRangeMax - uiDeadzone; } void CInput::SetJoypadSensitivity(int iPad, float fSensitivity) { m_Joypads[iPad].m_fSensitivity = fSensitivity; } void CInput::SetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction, unsigned int uiActionVal) { assert(ucMap < m_ucJoypadMapC); assert(ucAction < m_ucJoypadMapActionC); m_JoypadMap[ucMap][ucAction] = uiActionVal; } unsigned int CInput::GetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction) { assert(ucMap < m_ucJoypadMapC); assert(ucAction < m_ucJoypadMapActionC); return m_JoypadMap[ucMap][ucAction]; } void CInput::SetJoypadMapVal(int iPad, unsigned char ucMap) { m_bJoypadMapArrayIsSetup = true; m_Joypads[iPad].m_ucMappingValue = ucMap; } unsigned char CInput::GetJoypadMapVal(int iPad) { return m_Joypads[iPad].m_ucMappingValue; } void CInput::SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo) { float *pfTo = NULL; switch (uiTo) { case AXIS_MAP_LX: pfTo = &m_Joypads[iPad].m_fNormalizedLeftThumbX; break; case AXIS_MAP_LY: pfTo = &m_Joypads[iPad].m_fNormalizedLeftThumbY; break; case AXIS_MAP_RX: pfTo = &m_Joypads[iPad].m_fNormalizedRightThumbX; break; case AXIS_MAP_RY: pfTo = &m_Joypads[iPad].m_fNormalizedRightThumbY; break; } switch (uiFrom) { case AXIS_MAP_LX: m_Joypads[iPad].m_pfLeftThumbXAxisMap = pfTo; break; case AXIS_MAP_LY: m_Joypads[iPad].m_pfLeftThumbYAxisMap = pfTo; break; case AXIS_MAP_RX: m_Joypads[iPad].m_pfRightThumbXAxisMap = pfTo; break; case AXIS_MAP_RY: m_Joypads[iPad].m_pfRightThumbYAxisMap = pfTo; break; } } void CInput::SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom, unsigned int uiTo) { unsigned char *pucTo = NULL; switch (uiTo) { case TRIGGER_MAP_0: pucTo = &m_Joypads[iPad].m_ucRightTriggerState; break; case TRIGGER_MAP_1: pucTo = &m_Joypads[iPad].m_ucLeftTriggerState; break; } switch (uiFrom) { case TRIGGER_MAP_0: m_Joypads[iPad].m_pucRightTriggerAxisMap = pucTo; break; case TRIGGER_MAP_1: m_Joypads[iPad].m_pucLeftTriggerAxisMap = pucTo; break; } } bool CInput::IsPadConnected(int iPad) { return m_Joypads[iPad].m_bIsConnected; } void CInput::SetSigninJoypadMask(unsigned int mask) { m_uiSigninJoypadMask = mask; } unsigned int CInput::GetValue(int iPad, unsigned char ucAction, bool bRepeat) { if (m_bIsMenuDisplayed[iPad] && ucAction > this->m_ucMenuActionC) { return 0; } unsigned char ucMap = this->m_Joypads[iPad].m_ucMappingValue; unsigned int uiVal = this->m_JoypadMap[ucMap][ucAction] & this->m_Joypads[iPad].m_uiButtons; if (!uiVal || !bRepeat) { return uiVal; } int iKeyVal = 0; for (int iKey = this->m_JoypadMap[ucMap][ucAction]; (iKey & 1) == 0; iKey >>= 1) { iKeyVal++; } if (m_fRepeatDelaySecs <= m_Timers[iPad][iKeyVal].m_fTotalHoldTime || m_Timers[iPad][iKeyVal].m_bInitialPressHandled) { if (m_Timers[iPad][iKeyVal].m_fTotalHoldTime < m_fRepeatDelaySecs) { return 0; } else if (m_Timers[iPad][iKeyVal].m_fLastRepeatTime == 0.0f) { m_Timers[iPad][iKeyVal].m_fLastRepeatTime = m_fRepeatDelaySecs; return uiVal; } else if ((m_Timers[iPad][iKeyVal].m_fTotalHoldTime - m_Timers[iPad][iKeyVal].m_fLastRepeatTime) <= m_fRepeatRateSecs) { return 0; } else { m_Timers[iPad][iKeyVal].m_fLastRepeatTime = m_Timers[iPad][iKeyVal].m_fLastRepeatTime + m_fRepeatRateSecs; return uiVal; } } else { m_Timers[iPad][iKeyVal].m_bInitialPressHandled = true; return uiVal; } } bool CInput::IsSet(int iPad, unsigned char ucAction) { return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) && (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtons) != 0; } bool CInput::ButtonPressed(int iPad, unsigned char ucAction) { if (ucAction == 255) { return m_Joypads[iPad].m_uiButtonsPressed != 0; } if (m_bIsMenuDisplayed[iPad] && ucAction > m_ucMenuActionC) { return 0; } return (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtonsPressed) != 0; } bool CInput::ButtonReleased(int iPad, unsigned char ucAction) { return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) && (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtonsReleased) != 0; } bool CInput::ButtonDown(int iPad, unsigned char ucAction) { if (ucAction == 255) { return m_Joypads[iPad].m_uiButtons != 0; } if (m_bIsMenuDisplayed[iPad] && ucAction > m_ucMenuActionC) { return 0; } return (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtons) != 0; } float CInput::GetJoypadStick_Menu_LX(unsigned char ucPad) { return m_Joypads[ucPad].m_iNormalizedLeftThumbX; } float CInput::GetJoypadStick_Menu_LY(unsigned char ucPad) { return m_Joypads[ucPad].m_iNormalizedLeftThumbY; } float CInput::GetJoypadStick_Menu_RX(unsigned char ucPad) { return m_Joypads[ucPad].m_iNormalizedRightThumbX; } float CInput::GetJoypadStick_Menu_RY(unsigned char ucPad) { return m_Joypads[ucPad].m_iNormalizedRightThumbY; } unsigned char CInput::GetJoypadLTrigger_Menu(unsigned char ucPad) { return m_Joypads[ucPad].m_ucLeftTriggerState; } unsigned char CInput::GetJoypadRTrigger_Menu(unsigned char ucPad) { return m_Joypads[ucPad].m_ucRightTriggerState; } float CInput::GetJoypadStick_LX(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0.0f; } return *m_Joypads[iPad].m_pfLeftThumbXAxisMap * m_Joypads[iPad].m_fSensitivity; } float CInput::GetJoypadStick_LY(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0.0f; } return *m_Joypads[iPad].m_pfLeftThumbYAxisMap * m_Joypads[iPad].m_fSensitivity; } float CInput::GetJoypadStick_RX(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0.0f; } return *m_Joypads[iPad].m_pfRightThumbXAxisMap * m_Joypads[iPad].m_fSensitivity; } float CInput::GetJoypadStick_RY(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0.0f; } return *m_Joypads[iPad].m_pfRightThumbYAxisMap * m_Joypads[iPad].m_fSensitivity; } unsigned char CInput::GetJoypadLTrigger(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0; } return *m_Joypads[iPad].m_pucLeftTriggerAxisMap; } unsigned char CInput::GetJoypadRTrigger(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0; } return *m_Joypads[iPad].m_pucRightTriggerAxisMap; } ScePadTouchData* CInput::GetTouchPadData(int iPad, bool bCheckMenuDisplay) { if (bCheckMenuDisplay && m_bIsMenuDisplayed[iPad]) { return 0; } return &m_Joypads[iPad].m_pInputStates->touchData; } void CInput::SetMenuDisplayed(int iPad, bool bVal) { m_bIsMenuDisplayed[iPad] = bVal; } void CInput::SetKeyRepeatRate(float fRepeatDelaySecs, float fRepeatRateSecs) { m_fRepeatDelaySecs = fRepeatDelaySecs; m_fRepeatRateSecs = fRepeatRateSecs; } void CInput::SetDebugSequence(const char *chSequenceA, int (*Func)(LPVOID), LPVOID lpParam) { int iLen = strlen(chSequenceA); m_sDebugSequenceName = (char *)operator new[](iLen); strcpy(m_sDebugSequenceName, chSequenceA); m_pDebugSequenceFn = Func; m_pDebugSequenceParam = lpParam; } FLOAT CInput::GetIdleSeconds(int iPad) { ; } bool CInput::UpdateJoypads() { assert(m_bJoypadMapArrayIsSetup); for (int i = 0; i < MAX_JOYPADS; i++) { JOYPAD *pThisPad = &m_Joypads[i]; pThisPad->m_uiOldButtons = pThisPad->m_uiButtons; pThisPad->m_uiButtons = 0; pThisPad->m_ucLeftTriggerState = 0; pThisPad->m_ucRightTriggerState = 0; } for (int i = 0; i < MAX_JOYPADS; i++) { if (ProfileManager.IsSignedIn(i)) { SceUserServiceUserId UserID = ProfileManager.getUserID(i); } } return true; } void CInput::ClearJoypadValues(JOYPAD *pThisPad) { pThisPad->m_uiButtonsPressed = 0; pThisPad->m_uiButtonsReleased = 0; pThisPad->m_uiButtons = 0; pThisPad->m_ucLeftTriggerState = 0; pThisPad->m_ucRightTriggerState = 0; pThisPad->m_iRightThumbX = 0; pThisPad->m_iRightThumbY = 0; pThisPad->m_iLeftThumbX = 0; pThisPad->m_iLeftThumbY = 0; pThisPad->m_iNormalizedLeftThumbX = 0; pThisPad->m_iNormalizedLeftThumbY = 0; pThisPad->m_iNormalizedRightThumbX = 0; pThisPad->m_iNormalizedRightThumbY = 0; pThisPad->m_fNormalizedLeftThumbX = 0.0f; pThisPad->m_fNormalizedLeftThumbY = 0.0f; pThisPad->m_fNormalizedRightThumbX = 0.0f; pThisPad->m_fNormalizedRightThumbY = 0.0f; } void CInput::InitTime(void) { ; } void CInput::GetStartTime(int iPad, int iKey) { ; } void CInput::UpdateTime(int iPad, int iKey) { ; }