#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; #if TO_BE_IMPLEMENTED *((_QWORD *)this + 1024) = malloc(SCE_REMOTEPLAY_HEAP_SIZE); int remotePlayInit = sceRemoteplayInitialize(*((_QWORD *)this + 1024), SCE_REMOTEPLAY_HEAP_SIZE); if (remotePlayInit != SCE_OK) InternalInputManager.DebugPrintf("sceRemoteplayInitialize failed with error code: %X\n", remotePlayInit); #endif } void CInput::Tick() { UpdateJoypads(); m_Keyboard.Tick(); #if TO_BE_IMPLEMENTED UpdateRemotePlay(); #endif } 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) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_X; } if ((pGamePad->buttons & SCE_PAD_BUTTON_CIRCLE) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_O; } if ((pGamePad->buttons & SCE_PAD_BUTTON_SQUARE) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_SQUARE; } if ((pGamePad->buttons & SCE_PAD_BUTTON_TRIANGLE) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_TRIANGLE; } if ((pGamePad->buttons & SCE_PAD_BUTTON_R2) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R2; } if ((pGamePad->buttons & SCE_PAD_BUTTON_L2) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L2; } if ((pGamePad->buttons & SCE_PAD_BUTTON_R1) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R1; } if ((pGamePad->buttons & SCE_PAD_BUTTON_L1) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L1; } if ((pGamePad->buttons & SCE_PAD_BUTTON_OPTIONS) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_OPTIONS; } if ((pGamePad->buttons & SCE_PAD_BUTTON_TOUCH_PAD) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_TOUCHPAD; } if ((pGamePad->buttons & SCE_PAD_BUTTON_R3) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_R3; } if ((pGamePad->buttons & SCE_PAD_BUTTON_L3) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_L3; } if ((pGamePad->buttons & SCE_PAD_BUTTON_UP) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_UP; } if ((pGamePad->buttons & SCE_PAD_BUTTON_DOWN) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_DOWN; } if ((pGamePad->buttons & SCE_PAD_BUTTON_LEFT) != 0) { pThisPad->m_uiButtons |= _PS4_JOY_BUTTON_DPAD_LEFT; } if ((pGamePad->buttons & SCE_PAD_BUTTON_RIGHT) != 0) { 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); m_Joypads[i].m_iScePadHandle = scePadOpen(UserID, SCE_PAD_PORT_TYPE_STANDARD, 0, NULL); if (m_Joypads[i].m_iScePadHandle >= 0) { if (!m_Joypads[i].m_bIsDisabled) { JOYPAD *pThisPad = &m_Joypads[i]; bool bOldIsConnected = pThisPad->m_bIsConnected; pThisPad->m_ucInputStateIndex++; if (pThisPad->m_ucInputStateIndex == m_ucInputStateC) { pThisPad->m_ucInputStateIndex = 0; } ScePadData *pState = &pThisPad->m_pInputStates[pThisPad->m_ucInputStateIndex]; scePadRead(pThisPad->m_iScePadHandle, pState, 1); pThisPad->m_bIsConnected = pState->connected; if (!pThisPad->m_bIsConnected) memset(pState, 0, sizeof(ScePadData)); bool bWasConnected = bOldIsConnected && !pThisPad->m_bIsConnected; pThisPad->m_bWasConnected = bWasConnected; bool bHasConnected = !bOldIsConnected && pThisPad->m_bIsConnected; pThisPad->m_bHasConnected = bHasConnected; if (pThisPad->m_bIsConnected) { SetJoypadValues(pThisPad); /*if (pThisPad[128] && pThisPad[104]) { /*v9 = *((unsigned __int16 *)pThisPad + 56) - *((unsigned __int16 *)pThisPad + 68); x = *((unsigned __int16 *)pThisPad + 57) - *((unsigned __int16 *)pThisPad + 69); v4 = abs(x); if (v4 <= abs(v9)) { if (v9 <= 50) { if (v9 < -50) *((_DWORD *)pThisPad + 1) |= 0x8000u; } else { *((_DWORD *)pThisPad + 1) |= 0x4000u; } } else if (x <= 50) { if (x < -50) *((_DWORD *)pThisPad + 1) |= 0x200000u; } else { *((_DWORD *)pThisPad + 1) |= 0x100000u; } }*/ pThisPad->m_uiButtonsPressed = ~pThisPad->m_uiOldButtons & pThisPad->m_uiButtons; pThisPad->m_uiButtonsReleased = ~pThisPad->m_uiButtons & pThisPad->m_uiOldButtons; for (int bit = 0; bit < 24; ++bit) { if ((pThisPad->m_uiButtonsPressed & (1 << bit)) != 0) { GetStartTime(i, bit); } else if ((pThisPad->m_uiButtons & (1 << bit)) != 0) { UpdateTime(i, bit); } } } else if (pThisPad->m_bWasConnected) { ClearJoypadValues(pThisPad); } } } } else if (m_Joypads[i].m_iScePadHandle >= 0) { scePadClose(m_Joypads[i].m_iScePadHandle); m_Joypads[i].m_iScePadHandle = -1; m_Joypads[i].m_ucInputStateIndex = 0; } } return true; } bool CInput::UpdateRemotePlay() { #if TO_BE_IMPLEMENTED unsigned int v1; int v2; int v4; int RemotePlayer; char v6; int tickCount = GetTickCount(); v1 = TickCount - *((_DWORD *)this + 2043); if (v1 > 0x3E8) { *((_DWORD *)this + 2043) = TickCount; LOBYTE(v1) = CInput::UsingRemotePlay(this) & 1; v6 = v1; if ((v1 & 1) == 0 || (LOBYTE(v1) = (_BYTE)this, (*((_BYTE *)this + 8168) & 1) != 0)) { if ((v6 & 1) == 0) { LOBYTE(v1) = (_BYTE)this; if ((*((_BYTE *)this + 8168) & 1) != 0) LOBYTE(v1) = CInput::OnRemotePlayEnd(this); } } else { RemotePlayer = CInput::GetRemotePlayer(this); if ((CInput::IsRemotePlayAllowed(this, RemotePlayer) & 1) != 0) { v4 = sceRemoteplayApprove(); if (v4) CInput::DebugPrintf(this, "CInput:: Remote play approve failed with error code: %X\n", v4); v2 = CInput::GetRemotePlayer(this); LOBYTE(v1) = CInput::OnRemotePlayStart(this, v2); } else { CInput::DebugPrintf(this, "CInput:: Remote play starting but not currently allowed, calling to prohibit\n"); v1 = sceRemoteplayProhibit(); if (v1) LOBYTE(v1) = CInput::DebugPrintf(this, "CInput:: Remote play prohibit failed with error code: %X\n", v1); } } } return v1; #endif } 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) { ; }