2017-03-30 17:53:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2016,2017 Maschell
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2018-03-07 18:42:36 +01:00
|
|
|
#ifndef _CP_TCPSERVER_WINDOW_H_
|
|
|
|
#define _CP_TCPSERVER_WINDOW_H_
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2017-10-29 09:34:47 +01:00
|
|
|
#include "../ControllerPatcherIncludes.hpp"
|
2017-05-07 14:44:09 +02:00
|
|
|
|
2017-10-29 09:34:47 +01:00
|
|
|
#include <dynamic_libs/socket_functions.h>
|
|
|
|
#include <dynamic_libs/os_functions.h>
|
2018-03-07 18:42:36 +01:00
|
|
|
#include <utils/TCPServer.hpp>
|
|
|
|
#include <utils/net.h>
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2017-04-13 15:30:40 +02:00
|
|
|
#define WIIU_CP_TCP_HANDSHAKE WIIU_CP_TCP_HANDSHAKE_VERSION_3
|
2017-04-10 15:39:58 +02:00
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_MIN WIIU_CP_TCP_HANDSHAKE_VERSION_1
|
2017-04-13 15:30:40 +02:00
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_MAX WIIU_CP_TCP_HANDSHAKE_VERSION_3
|
2017-04-10 15:39:58 +02:00
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_1 0x12
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_2 0x13
|
2017-04-13 15:30:40 +02:00
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_3 0x14
|
2017-04-10 15:39:58 +02:00
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_ABORT 0x30
|
|
|
|
|
|
|
|
#define ATTACH 0x01
|
|
|
|
#define DETACH 0x00
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_ATTACH 0x01
|
|
|
|
#define WIIU_CP_TCP_DETACH 0x02
|
|
|
|
#define WIIU_CP_TCP_PING 0xF0
|
|
|
|
#define WIIU_CP_TCP_PONG 0xF1
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_ATTACH_CONFIG_FOUND 0xE0
|
|
|
|
#define WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND 0xE1
|
|
|
|
#define WIIU_CP_TCP_ATTACH_USER_DATA_OKAY 0xE8
|
|
|
|
#define WIIU_CP_TCP_ATTACH_USER_DATA_BAD 0xE9
|
|
|
|
|
2017-03-30 17:53:36 +02:00
|
|
|
#define DEFAULT_TCP_PORT 8112
|
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
class CPTCPServer: TCPServer{
|
2017-03-30 17:53:36 +02:00
|
|
|
friend class ControllerPatcher;
|
|
|
|
|
|
|
|
private:
|
2018-03-07 18:42:36 +01:00
|
|
|
static CPTCPServer *getInstance() {
|
|
|
|
if(!instance){
|
|
|
|
|
|
|
|
instance = new CPTCPServer(DEFAULT_TCP_PORT);
|
|
|
|
}
|
2017-03-30 17:53:36 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroyInstance() {
|
|
|
|
if(instance){
|
|
|
|
delete instance;
|
|
|
|
instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
static s32 getPriority(){
|
|
|
|
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;
|
|
|
|
DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority);
|
|
|
|
}
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPTCPServer(s32 port);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
virtual ~CPTCPServer();
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
static void DetachConnectedNetworkController();
|
2018-03-07 18:42:36 +01:00
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
static void AttachDetach(s32 attach);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
virtual void DetachAndDelete();
|
|
|
|
|
|
|
|
virtual bool whileLoop();
|
|
|
|
|
|
|
|
virtual bool acceptConnection();
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
virtual void onConnectionClosed();
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2018-03-07 18:42:36 +01:00
|
|
|
static CPTCPServer * instance;
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_TCPSERVER_WINDOW_H_
|