Skip to content

Commit

Permalink
Swap joypads over Netplay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CaptainDapper committed Sep 1, 2018
1 parent 0a87869 commit e0d88d4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 8 additions & 1 deletion netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
#include <sys/types.h>

#include "snes9x.h"
#include "controls.h"

#ifdef __WIN32__
#include <winsock.h>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -382,6 +384,7 @@ void S9xNPServerAddTask (uint32 task, void *data);

bool8 S9xNPStartServer (int port);
void S9xNPStopServer ();
void S9xNPSendJoypadSwap ();
#ifdef __WIN32__
#define S9xGetMilliTime timeGetTime
#else
Expand Down
14 changes: 14 additions & 0 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
1 change: 1 addition & 0 deletions win32/snes9xw.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<IntDir>$(SolutionDir)_Intermediate\$(ProjectName)\$(Configuration)\$(PlatformTarget)\</IntDir>
<TargetName>$(ProjectName)</TargetName>
<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>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Unicode|x64'">
Expand Down

0 comments on commit e0d88d4

Please sign in to comment.