// Executes the shortcut iShortcut on controller iController // Special case: if iPlayer is -1, run the mouselock shortcut void DoShortcut( int iControl, int iShortcut ) { DebugWriteA("Shortcut: %d %d\n", iControl, iShortcut); TCHAR pszMessage[DEFAULT_BUFFER / 2] = TEXT(""); bool bEjectFirst = false; if (iControl == -1) { EnterCriticalSection( &g_critical ); if( g_sysMouse.didHandle ) { g_sysMouse.didHandle->Unacquire(); if( g_bExclusiveMouse ) { g_sysMouse.didHandle->Unacquire(); g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD ); g_sysMouse.didHandle->Acquire(); LoadString( g_hResourceDLL, IDS_POP_MOUSEUNLOCKED, pszMessage, ARRAYSIZE(pszMessage) ); } else { g_sysMouse.didHandle->Unacquire(); g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); g_sysMouse.didHandle->Acquire(); LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, pszMessage, ARRAYSIZE(pszMessage) ); } g_sysMouse.didHandle->Acquire(); g_bExclusiveMouse = !g_bExclusiveMouse; } LeaveCriticalSection( &g_critical ); } else if( g_pcControllers[iControl].fPlugged ) { if( g_pcControllers[iControl].pPakData ) { SaveControllerPak( iControl ); CloseControllerPak( iControl ); } switch (iShortcut) { case SC_NOPAK: EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_NONE; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_NONE, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); break; case SC_MEMPAK: if (PAK_NONE == g_pcControllers[iControl].PakType) { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_MEM; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_MEMPAK, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); } else { bEjectFirst = true; } break; case SC_RUMBPAK: if (PAK_NONE == g_pcControllers[iControl].PakType) { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_RUMBLE; g_pcControllers[iControl].fPakInitialized = false; if( g_pcControllers[iControl].fRawData ) if (CreateEffectHandle( iControl, g_pcControllers[iControl].bRumbleTyp, g_pcControllers[iControl].bRumbleStrength ) ) { DebugWriteA("CreateEffectHandle for shortcut switch: OK\n"); } else { DebugWriteA("Couldn't CreateEffectHandle for shortcut switch.\n"); } LoadString( g_hResourceDLL, IDS_P_RUMBLEPAK, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); } else { bEjectFirst = true; } break; case SC_TRANSPAK: if (PAK_NONE == g_pcControllers[iControl].PakType) { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_TRANSFER; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_TRANSFERPAK, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); } else { bEjectFirst = true; } break; case SC_VOICEPAK: if (PAK_NONE == g_pcControllers[iControl].PakType) { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_VOICE; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_VOICEPAK, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); } else { bEjectFirst = true; } break; case SC_ADAPTPAK: if (PAK_NONE == g_pcControllers[iControl].PakType) { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_ADAPTOID; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_ADAPTOIDPAK, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); } else { bEjectFirst = true; } break; case SC_SWMEMRUMB: bEjectFirst = true; if( g_pcControllers[iControl].PakType == PAK_MEM ) { iShortcut = PAK_RUMBLE; } else { iShortcut = PAK_MEM; } break; case SC_SWMEMADAPT: bEjectFirst = true; if( g_pcControllers[iControl].PakType == PAK_MEM ) { iShortcut = PAK_ADAPTOID; } else { iShortcut = PAK_MEM; } break; default: DebugWriteA("Invalid iShortcut passed to DoShortcut\n"); EnterCriticalSection( &g_critical ); g_pcControllers[iControl].fPakInitialized = false; LeaveCriticalSection( &g_critical ); return; } // switch (iShortcut) } // else if // let the game code re-init the pak. if (bEjectFirst) // we need to eject the current pack first; then set a DoShortcut to try again in 1 second { EnterCriticalSection( &g_critical ); g_pcControllers[iControl].PakType = PAK_NONE; g_pcControllers[iControl].fPakInitialized = false; LoadString( g_hResourceDLL, IDS_P_SWITCHING, pszMessage, ARRAYSIZE(pszMessage) ); LeaveCriticalSection( &g_critical ); LPMSHORTCUT lpmNextShortcut = (LPMSHORTCUT)P_malloc(sizeof(MSHORTCUT)); if (!lpmNextShortcut) return; lpmNextShortcut->iControl = iControl; lpmNextShortcut->iShortcut = iShortcut; CreateThread(NULL, 0, DelayedShortcut, lpmNextShortcut, 0, NULL); iControl = -2; // this is just a hack to get around the check that appends "Changing Pak X to ..." } if( g_strEmuInfo.fDisplayShortPop && _tcslen(pszMessage) > 0 ) { if( iControl >= 0 ) { TCHAR tszNotify[DEFAULT_BUFFER / 2]; LoadString( g_hResourceDLL, IDS_POP_CHANGEPAK, tszNotify, ARRAYSIZE(tszNotify)); wsprintf( g_pszThreadMessage, tszNotify, iControl+1, pszMessage ); } else lstrcpyn( g_pszThreadMessage, pszMessage, ARRAYSIZE(g_pszThreadMessage) ); CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL); } }
// PrepareInputDevices rewritten --rabid bool PrepareInputDevices() { bool fKeyboard = false; bool fMouse = false; bool fGamePad = false; for( int i = 0; i < ARRAYSIZE( g_pcControllers ); ++i ) { fGamePad = false; if( g_pcControllers[i].fPlugged ) { CountControllerStructDevs( &g_pcControllers[i] ); fKeyboard = g_pcControllers[i].fKeyboard != 0; fMouse = g_pcControllers[i].fMouse != 0; fGamePad = ( g_pcControllers[i].fGamePad != 0); // we'll assume for now that there's a gamepad to go with those buttons } ReleaseEffect( g_apdiEffect[i] ); if( g_pcControllers[i].guidFFDevice != GUID_NULL && GetInputDevice( g_strEmuInfo.hMainWindow, g_apFFDevice[i], g_pcControllers[i].guidFFDevice, DI8DEVTYPE_JOYSTICK, DIB_FF )) // not necessarily a joystick type device, but we don't use the data anyway { DIDEVICEINSTANCE diDev; diDev.dwSize = sizeof( DIDEVICEINSTANCE ); g_apFFDevice[i]->GetDeviceInfo( &diDev ); if( !lstrcmp( diDev.tszProductName, _T( STRING_ADAPTOID ))) { g_pcControllers[i].fIsAdaptoid = true; DebugWriteA("FF device on controller %d is of type Adaptoid\n", i+1); } else { g_pcControllers[i].fIsAdaptoid = false; } if ( CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ) ) { AcquireDevice( g_apFFDevice[i] ); DebugWriteA("Got FF device %d\n", i); } else DebugWriteA("Couldn't get FF device: CreateEffectHandle failed!\n"); } else { g_apFFDevice[i] = NULL; DebugWriteA("Didn't get FF device %d\n", i); } } if( fMouse ) { if( !g_sysMouse.didHandle ) { if( GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, g_bExclusiveMouse ? DIB_MOUSE : DIB_KEYBOARD )) { AcquireDevice( g_sysMouse.didHandle ); } } } else { g_bExclusiveMouse = false; } return true; }