From e0d88d435f780ca74ab8bde26517efd6180dcbab Mon Sep 17 00:00:00 2001 From: "CRINKLE-PC\\sloan" Date: Fri, 31 Aug 2018 19:59:09 -0700 Subject: [PATCH] Swap joypads over Netplay Someone smarter than me can probably figure out a more "proper" way to do this, but I hate RetroArch and wanted an easy way to Swap P1 and P2 without both players having to press the button at the same time. --- controls.cpp | 9 +++++++++ netplay.cpp | 9 ++++++++- netplay.h | 3 +++ server.cpp | 14 ++++++++++++++ win32/snes9xw.vcxproj | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/controls.cpp b/controls.cpp index 975c499a..bddac2e0 100644 --- a/controls.cpp +++ b/controls.cpp @@ -2628,6 +2628,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 56635058..c0e4fa0b 100644 --- a/netplay.cpp +++ b/netplay.cpp @@ -204,6 +204,7 @@ #include #include "snes9x.h" +#include "controls.h" #ifdef __WIN32__ #include @@ -684,7 +685,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 d8e81454..afbcc889 100644 --- a/netplay.h +++ b/netplay.h @@ -241,6 +241,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 { @@ -382,6 +384,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 5fc60e11..1497eb9c 100644 --- a/server.cpp +++ b/server.cpp @@ -869,6 +869,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 b71eb392..802a9d8c 100644 --- a/win32/snes9xw.vcxproj +++ b/win32/snes9xw.vcxproj @@ -92,6 +92,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)