diff --git a/controls.cpp b/controls.cpp index b828bd9d..bc5aa1a8 100644 --- a/controls.cpp +++ b/controls.cpp @@ -2442,6 +2442,15 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2) S9xSetInfoString("Cannot swap pads: port 2 is not a joypad"); break; } + + if (Settings.NetPlay && data2 != 1) { //data2 == 1 means it's sent by the netplay code + if (Settings.NetPlayServer) { + S9xNPSendJoypadSwap(); + } else { + S9xSetInfoString("Netplay Client cannot swap pads."); + break; + } + } newcontrollers[1] = curcontrollers[0]; newcontrollers[0] = curcontrollers[1]; diff --git a/netplay.cpp b/netplay.cpp index 7fad5807..1c2078d4 100644 --- a/netplay.cpp +++ b/netplay.cpp @@ -13,6 +13,7 @@ #include #include "snes9x.h" +#include "controls.h" #ifdef __WIN32__ #include @@ -493,7 +494,13 @@ bool8 S9xNPWaitForHeartBeat () else S9xNPSetWarning("CLIENT: Server has resumed."); break; - case NP_SERV_LOAD_ROM: + case NP_SERV_JOYPAD_SWAP: +#ifdef NP_DEBUG + printf("CLIENT: Joypad Swap received @%ld\n", S9xGetMilliTime() - START); +#endif + S9xApplyCommand(S9xGetCommandT("SwapJoypads"), 1, 1); + break; + case NP_SERV_LOAD_ROM: #ifdef NP_DEBUG printf ("CLIENT: LOAD_ROM received @%ld\n", S9xGetMilliTime () - START); #endif diff --git a/netplay.h b/netplay.h index def127d7..ea0b716f 100644 --- a/netplay.h +++ b/netplay.h @@ -57,6 +57,8 @@ #define NP_SERV_FREEZE_FILE 6 #define NP_SERV_SRAM_DATA 7 #define NP_SERV_READY 8 +// ... +#define NP_SERV_JOYPAD_SWAP 12 struct SNPClient { @@ -198,6 +200,7 @@ void S9xNPServerAddTask (uint32 task, void *data); bool8 S9xNPStartServer (int port); void S9xNPStopServer (); +void S9xNPSendJoypadSwap (); #ifdef __WIN32__ #define S9xGetMilliTime timeGetTime #else diff --git a/server.cpp b/server.cpp index dd02087e..aced2227 100644 --- a/server.cpp +++ b/server.cpp @@ -680,6 +680,20 @@ void S9xNPSendServerPause (bool8 paused) S9xNPSendToAllClients (pause, 7); } +void S9xNPSendJoypadSwap() +{ +#ifdef NP_DEBUG + printf("SERVER: Swap Joypads - @%ld\n", S9xGetMilliTime() - START); +#endif + uint8 swap[7]; + uint8 *ptr = swap; + *ptr++ = NP_SERV_MAGIC; + *ptr++ = 0; + *ptr++ = NP_SERV_JOYPAD_SWAP; + WRITE_LONG(ptr, 7); + S9xNPSendToAllClients(swap, 7); +} + void S9xNPServerLoop (void *) { #ifdef __WIN32__ diff --git a/win32/snes9xw.vcxproj b/win32/snes9xw.vcxproj index 4551cce6..a784a655 100644 --- a/win32/snes9xw.vcxproj +++ b/win32/snes9xw.vcxproj @@ -96,6 +96,7 @@ $(SolutionDir)_Intermediate\$(ProjectName)\$(Configuration)\$(PlatformTarget)\ $(ProjectName) $(DXSDK_DIR)include;$(CG_INC_PATH);$(IncludePath) + $(DXSDK_DIR)include;$(CG_INC_PATH);$(IncludePath);$(DXSDK_DIR)\include $(DXSDK_DIR)Lib\$(PlatformTarget);$(CG_LIB_PATH);$(LibraryPath)