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.
This commit is contained in:
CRINKLE-PC\sloan 2018-08-31 19:59:09 -07:00
parent 0a878697ed
commit e0d88d435f
5 changed files with 35 additions and 1 deletions

View File

@ -2629,6 +2629,15 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
break; 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[1] = curcontrollers[0];
newcontrollers[0] = curcontrollers[1]; newcontrollers[0] = curcontrollers[1];

View File

@ -204,6 +204,7 @@
#include <sys/types.h> #include <sys/types.h>
#include "snes9x.h" #include "snes9x.h"
#include "controls.h"
#ifdef __WIN32__ #ifdef __WIN32__
#include <winsock.h> #include <winsock.h>
@ -684,6 +685,12 @@ bool8 S9xNPWaitForHeartBeat ()
else else
S9xNPSetWarning("CLIENT: Server has resumed."); S9xNPSetWarning("CLIENT: Server has resumed.");
break; break;
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: case NP_SERV_LOAD_ROM:
#ifdef NP_DEBUG #ifdef NP_DEBUG
printf ("CLIENT: LOAD_ROM received @%ld\n", S9xGetMilliTime () - START); printf ("CLIENT: LOAD_ROM received @%ld\n", S9xGetMilliTime () - START);

View File

@ -241,6 +241,8 @@
#define NP_SERV_FREEZE_FILE 6 #define NP_SERV_FREEZE_FILE 6
#define NP_SERV_SRAM_DATA 7 #define NP_SERV_SRAM_DATA 7
#define NP_SERV_READY 8 #define NP_SERV_READY 8
// ...
#define NP_SERV_JOYPAD_SWAP 12
struct SNPClient struct SNPClient
{ {
@ -382,6 +384,7 @@ void S9xNPServerAddTask (uint32 task, void *data);
bool8 S9xNPStartServer (int port); bool8 S9xNPStartServer (int port);
void S9xNPStopServer (); void S9xNPStopServer ();
void S9xNPSendJoypadSwap ();
#ifdef __WIN32__ #ifdef __WIN32__
#define S9xGetMilliTime timeGetTime #define S9xGetMilliTime timeGetTime
#else #else

View File

@ -869,6 +869,20 @@ void S9xNPSendServerPause (bool8 paused)
S9xNPSendToAllClients (pause, 7); 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 *) void S9xNPServerLoop (void *)
{ {
#ifdef __WIN32__ #ifdef __WIN32__

View File

@ -92,6 +92,7 @@
<IntDir>$(SolutionDir)_Intermediate\$(ProjectName)\$(Configuration)\$(PlatformTarget)\</IntDir> <IntDir>$(SolutionDir)_Intermediate\$(ProjectName)\$(Configuration)\$(PlatformTarget)\</IntDir>
<TargetName>$(ProjectName)</TargetName> <TargetName>$(ProjectName)</TargetName>
<IncludePath>$(DXSDK_DIR)include;$(CG_INC_PATH);$(IncludePath)</IncludePath> <IncludePath>$(DXSDK_DIR)include;$(CG_INC_PATH);$(IncludePath)</IncludePath>
<IncludePath>$(DXSDK_DIR)include;$(CG_INC_PATH);$(IncludePath);$(DXSDK_DIR)\include</IncludePath>
<LibraryPath>$(DXSDK_DIR)Lib\$(PlatformTarget);$(CG_LIB_PATH);$(LibraryPath)</LibraryPath> <LibraryPath>$(DXSDK_DIR)Lib\$(PlatformTarget);$(CG_LIB_PATH);$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Unicode|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Unicode|x64'">