From c46fcaff88a7e617255cd40b21dce565ee2a8555 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 13 Apr 2017 10:14:41 +0200 Subject: [PATCH] Changing the server-thread-priority if a game has problem with it. Added retain variables for the callback workarround --- ControllerPatcher.cpp | 8 ++++++++ network/TCPServer.cpp | 11 ++++++++++- network/UDPServer.cpp | 14 +++++++++++--- utils/CPRetainVars.cpp | 4 ++++ utils/CPRetainVars.hpp | 6 ++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ControllerPatcher.cpp b/ControllerPatcher.cpp index eb4695c..bc580e6 100644 --- a/ControllerPatcher.cpp +++ b/ControllerPatcher.cpp @@ -78,6 +78,10 @@ void ControllerPatcher::ResetConfig(){ memset(gNetworkController,0,sizeof(gNetworkController)); // Init / Invalid everything memset(gHID_Devices,0,sizeof(gHID_Devices)); // Init / Invalid everything + memset(gConnectCallback,0,sizeof(gConnectCallback)); + memset(gExtensionCallback,0,sizeof(gExtensionCallback)); + gCallbackCooldown = 0; + gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; gHID_LIST_GC = 0; gHID_LIST_DS3 = 0; @@ -474,6 +478,10 @@ void ControllerPatcher::DeInit(){ memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); memset(gNetworkController,0,sizeof(gNetworkController)); + memset(gConnectCallback,0,sizeof(gConnectCallback)); + memset(gExtensionCallback,0,sizeof(gExtensionCallback)); + gCallbackCooldown = 0; + gConfig_done = HID_INIT_NOT_DONE; gButtonRemappingConfigDone = 0; gHIDAttached = 0; diff --git a/network/TCPServer.cpp b/network/TCPServer.cpp index 3d40dba..2e4f856 100644 --- a/network/TCPServer.cpp +++ b/network/TCPServer.cpp @@ -61,7 +61,16 @@ void TCPServer::CloseSockets(){ } void TCPServer::StartTCPThread(TCPServer * server){ - TCPServer::pThread = ControllerPatcherThread::create(TCPServer::DoTCPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,28); + s32 priority = 28; + if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN + OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA + OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR + OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR + OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA + priority = 10; + log_printf("TCPServer::StartTCPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority); + } + TCPServer::pThread = ControllerPatcherThread::create(TCPServer::DoTCPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority); TCPServer::pThread->resumeThread(); } diff --git a/network/UDPServer.cpp b/network/UDPServer.cpp index a60c00d..59e5c4b 100644 --- a/network/UDPServer.cpp +++ b/network/UDPServer.cpp @@ -62,7 +62,16 @@ UDPServer::~UDPServer(){ } void UDPServer::StartUDPThread(UDPServer * server){ - UDPServer::pThread = ControllerPatcherThread::create(UDPServer::DoUDPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,17); + s32 priority = 28; + if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN + OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA + OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR + OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR + OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA + priority = 10; + log_printf("UDPServer::StartUDPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority); + } + UDPServer::pThread = ControllerPatcherThread::create(UDPServer::DoUDPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority); UDPServer::pThread->resumeThread(); } @@ -127,9 +136,8 @@ void UDPServer::DoUDPThreadInternal(){ continue; } - //log_printf("UDPServer::DoUDPThreadInternal(): Got handle: %d slot %04X hid %04X pad %02X datasize %02X\n",handle,deviceSlot,hid,padslot,datasize); if(!cpyIncrementBufferOffset((void *)databuffer, (void *)buffer,&bufferoffset,datasize, n))continue; - + //log_printf("UDPServer::DoUDPThreadInternal(): Got handle: %d slot %04X hid %04X pad %02X datasize %02X\n",handle,deviceSlot,hid,padslot,datasize); user.pad_slot = padslot; user.slotdata.deviceslot = deviceSlot; diff --git a/utils/CPRetainVars.cpp b/utils/CPRetainVars.cpp index 992ad6b..b1fa62f 100644 --- a/utils/CPRetainVars.cpp +++ b/utils/CPRetainVars.cpp @@ -56,3 +56,7 @@ u8 gOriginalAPDState __attribute__((section(".data"))) = 0; u16 gNetworkController[gHIDMaxDevices][HID_MAX_PADS_COUNT][4] __attribute__((section(".data"))); s32 gHIDNetworkClientID __attribute__((section(".data"))) = 0; u8 gUsedProtocolVersion __attribute__((section(".data"))) = WIIU_CP_TCP_HANDSHAKE; + +wpad_connect_callback_t gConnectCallback[4] __attribute__((section(".data"))); +wpad_extension_callback_t gExtensionCallback[4] __attribute__((section(".data"))); +u8 gCallbackCooldown __attribute__((section(".data"))) = 0; diff --git a/utils/CPRetainVars.hpp b/utils/CPRetainVars.hpp index d8ee434..f894ac3 100644 --- a/utils/CPRetainVars.hpp +++ b/utils/CPRetainVars.hpp @@ -18,6 +18,7 @@ #define CP_RETAINS_VARS_H_ #include "dynamic_libs/syshid_functions.h" +#include "dynamic_libs/padscore_functions.h" #include "../patcher/ControllerPatcherDefs.h" extern ControllerMapping gControllerMapping; @@ -58,4 +59,9 @@ extern s32 gHIDNetworkClientID; extern u8 gUsedProtocolVersion; +extern wpad_connect_callback_t gConnectCallback[4]; +extern wpad_extension_callback_t gExtensionCallback[4]; +extern u8 gCallbackCooldown; + + #endif // CP_RETAINS_VARS_H_