diff --git a/Source/MusicMod.sln b/Source/MusicMod.sln
index 584a6e410d..5a9b031847 100644
--- a/Source/MusicMod.sln
+++ b/Source/MusicMod.sln
@@ -101,6 +101,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_Wiimote", "Plugins\Plugin_Wiimote\Plugin_Wiimote.vcproj", "{8D612734-FAA5-4B8A-804F-4DEA2367D495}"
ProjectSection(ProjectDependencies) = postProject
{48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F}
+ {C7E5D50A-2916-464B-86A7-E10B3CC88ADA} = {C7E5D50A-2916-464B-86A7-E10B3CC88ADA}
{0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0}
{71B16F46-0B00-4EDA-B253-D6D9D03A215C} = {71B16F46-0B00-4EDA-B253-D6D9D03A215C}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
diff --git a/Source/Plugins/Plugin_Wiimote/Plugin_Wiimote.vcproj b/Source/Plugins/Plugin_Wiimote/Plugin_Wiimote.vcproj
index 9c5e5b6861..cd2b348ed1 100644
--- a/Source/Plugins/Plugin_Wiimote/Plugin_Wiimote.vcproj
+++ b/Source/Plugins/Plugin_Wiimote/Plugin_Wiimote.vcproj
@@ -67,10 +67,10 @@
/>
0)
+ if(WiiMoteEmu::NumGoodPads > 0)
{
- //for(int x = 0; x < joyinfo.size(); x++)
- // arrayStringFor_Joyname.Add(wxString::FromAscii(joyinfo[x].Name.c_str()));
+ for(int x = 0; x < WiiMoteEmu::joyinfo.size(); x++)
+ StrJoyname.Add(wxString::FromAscii(WiiMoteEmu::joyinfo[x].Name.c_str()));
}
else
{
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
index 9845c397f6..f054eef27a 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
@@ -21,10 +21,10 @@
#ifndef _EMU_DEFINITIONS_
#define _EMU_DEFINITIONS_
-#include "pluginspecs_wiimote.h"
-
#include
#include
+
+#include "pluginspecs_wiimote.h"
#include "Common.h"
#include "wiimote_hid.h"
#include "EmuDefinitions.h"
@@ -60,6 +60,12 @@ std::vector AckDelay; // Ackk delay
wiimote_key g_ExtKey; // The extension encryption key
bool g_Encryption; // Encryption on or off
+// Gamepad input
+int NumPads = 0, NumGoodPads = 0; // Number of goods pads
+std::vector joyinfo;
+InputCommon::CONTROLLER_STATE PadState[4];
+InputCommon::CONTROLLER_MAPPING PadMapping[4];
+
} // namespace
#endif //_EMU_DECLARATIONS_
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
index 7366e89232..b743624ed9 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
@@ -18,14 +18,16 @@
#ifndef _EMU_DECLARATIONS_
#define _EMU_DECLARATIONS_
-#include "pluginspecs_wiimote.h"
-
#include
#include
-#include "Common.h"
+#include "../../../Core/InputCommon/Src/SDL.h" // Core
+#include "../../../Core/InputCommon/Src/XInput.h"
-#include "wiimote_hid.h"
+#include "Common.h"
+#include "pluginspecs_wiimote.h"
+
+#include "wiimote_hid.h" // Local
#include "Encryption.h"
#include "Logging.h" // for startConsoleWin, Console::Print, GetConsoleHwnd
@@ -168,6 +170,11 @@ static const u8 partially_id[] =
0x00, 0x00, 0x00, 0x00, 0xff, 0xff
};
+// Gamepad input
+extern int NumPads, NumGoodPads; // Number of goods pads
+extern std::vector joyinfo;
+extern InputCommon::CONTROLLER_STATE PadState[4];
+extern InputCommon::CONTROLLER_MAPPING PadMapping[4];
} // namespace
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
index 308fb6d790..a41a54c843 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
@@ -24,6 +24,9 @@
#include
#include
+#include "../../../Core/InputCommon/Src/SDL.h" // Core
+#include "../../../Core/InputCommon/Src/XInput.h"
+
#include "Common.h" // Common
#include "StringUtil.h" // for ArrayToString()
#include "IniFile.h"
@@ -298,6 +301,37 @@ void SetDefaultExtensionRegistry()
UpdateEeprom();
}
+
+// ===================================================
+// Fill joyinfo with the current connected devices
+// ----------------
+bool Search_Devices(std::vector &_joyinfo, int &_NumPads, int &_NumGoodPads)
+{
+ bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
+
+ // Warn the user if no gamepads are detected
+ if (_NumGoodPads == 0 && g_EmulatorRunning)
+ {
+ //PanicAlert("nJoy: No Gamepad Detected");
+ //return false;
+ }
+
+ // Load PadMapping[] etc
+ g_Config.Load();
+
+ // Update the PadState[].joy handle
+ for (int i = 0; i < 4; i++)
+ {
+ if (PadMapping[i].enabled && joyinfo.size() > PadMapping[i].ID)
+ if(joyinfo.at(PadMapping[i].ID).Good)
+ PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
+ }
+
+ return Success;
+}
+// ===========================
+
+
// ===================================================
/* Write initial values to Eeprom and registers. */
// ----------------
@@ -332,6 +366,9 @@ void Initialize()
g_RecordingCurrentTime[i] = 0;
}
+ // Load avaliable pads
+ Search_Devices(joyinfo, NumPads, NumGoodPads);
+
/* The Nuncheck extension ID for homebrew applications that use the zero key. This writes 0x0000
in encrypted form (0xfefe) to 0xfe in the extension register. */
//WriteCrypted16(g_RegExt, 0xfe, 0x0000); // Fully inserted Nunchuk
diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp
index 391af1245c..bc7bbed4d8 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp
@@ -866,8 +866,8 @@ void DoInitialize()
MoveWindow(Console::GetHwnd(), 200,0, 130*8,70*14, true); // big wide window*/
// ---------------
- // Load config settings
- g_Config.Load();
+ // Load config settings, will be done after the SDL functions in EmuMain.cpp
+ //g_Config.Load();
// Run this first so that WiiMoteReal::Initialize() overwrites g_Eeprom
WiiMoteEmu::Initialize();
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp
index bffb715001..88827eca93 100644
--- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp
+++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigAdvanced.cpp
@@ -37,7 +37,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
-extern bool emulator_running;
+extern bool g_EmulatorRunning;
////////////////////////
/* If we don't use this hack m_MainSizer->GetMinSize().GetWidth() will not change
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp
index 2590546990..a92dc18710 100644
--- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp
+++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp
@@ -39,7 +39,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
-extern bool emulator_running;
+extern bool g_EmulatorRunning;
// D-Pad type
static const char* DPadType[] =
@@ -161,7 +161,7 @@ void ConfigBox::OnKeyDown(wxKeyEvent& event)
void ConfigBox::OnClose(wxCloseEvent& /*event*/)
{
EndModal(0);
- if(!emulator_running) Shutdown(); // Close pads, unless we are running a game
+ if(!g_EmulatorRunning) Shutdown(); // Close pads, unless we are running a game
}
// Call about dialog
@@ -946,7 +946,7 @@ void ConfigBox::CreateGUIControls()
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
// Don't allow these changes when running
- if(emulator_running)
+ if(g_EmulatorRunning)
{
m_Joyname[i]->Enable(false);
m_Joyattach[i]->Enable(false);
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp
index c42d7b2654..31c5a33ba1 100644
--- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp
+++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp
@@ -39,7 +39,7 @@
#include "../nJoy.h"
#include "Images/controller.xpm"
-extern bool emulator_running;
+extern bool g_EmulatorRunning;
////////////////////////
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp
index 9f6c15e03b..e21942bd54 100644
--- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp
+++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp
@@ -87,7 +87,7 @@ HINSTANCE nJoy_hInst = NULL;
std::vector joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
-bool emulator_running = false;
+bool g_EmulatorRunning = false;
int NumPads = 0, NumGoodPads = 0;
HWND m_hWnd; // Handle to window
SPADInitialize *g_PADInitialize = NULL;
@@ -191,7 +191,7 @@ void DllConfig(HWND _hParent)
#ifdef _WIN32
// Start the pads so we can use them in the configuration and advanced controls
- if(!emulator_running)
+ if(!g_EmulatorRunning)
{
Search_Devices(joyinfo, NumPads, NumGoodPads); // Populate joyinfo for all attached devices
}
@@ -232,7 +232,7 @@ void DllDebugger(HWND _hParent, bool Show) {}
// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
/* Information: This function can not be run twice without a Shutdown in between. If
it's run twice the SDL_Init() will cause a crash. One solution to this is to keep a
- global function that remembers the SDL_Init() and SDL_Quit() (emulator_running does
+ global function that remembers the SDL_Init() and SDL_Quit() (g_EmulatorRunning does
not do that since we can open and close this without any game running). But I would
suggest that avoiding to run this twice from the Core is better. */
void Initialize(void *init)
@@ -241,7 +241,7 @@ void Initialize(void *init)
//Console::Open();
Console::Print("Initialize: %i\n", SDL_WasInit(0));
g_PADInitialize = (SPADInitialize*)init;
- emulator_running = true;
+ g_EmulatorRunning = true;
#ifdef _DEBUG
DEBUG_INIT();
@@ -270,7 +270,7 @@ bool Search_Devices(std::vector &_joyinfo, int &_N
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected
- if (_NumGoodPads == 0 && emulator_running)
+ if (_NumGoodPads == 0 && g_EmulatorRunning)
{
PanicAlert("nJoy: No Gamepad Detected");
return false;
@@ -319,7 +319,7 @@ void Shutdown()
//joyinfo = NULL;
joyinfo.clear();
- emulator_running = false;
+ g_EmulatorRunning = false;
#ifdef _WIN32
#ifdef USE_RUMBLE_DINPUT_HACK