mirror of
https://github.com/Maschell/controller_patcher.git
synced 2024-11-23 20:49:16 +01:00
Transforming it into a static lib
This commit is contained in:
parent
409871f29d
commit
765b9dcb1c
50
.gitignore
vendored
50
.gitignore
vendored
@ -1,47 +1,3 @@
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# =========================
|
||||
# Operating System Files
|
||||
# =========================
|
||||
|
||||
# OSX
|
||||
# =========================
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
release/*
|
||||
libcontrollerpatcher.cbp
|
||||
libcontrollerpatcher.depend
|
134
Makefile
Normal file
134
Makefile
Normal file
@ -0,0 +1,134 @@
|
||||
DO_LOGGING := 0
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC)
|
||||
endif
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
|
||||
endif
|
||||
|
||||
include $(DEVKITPPC)/wii_rules
|
||||
|
||||
export PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
# DATA is a list of directories containing binary files
|
||||
# LIBDIR is where the built library will be placed
|
||||
# all directories are relative to this makefile
|
||||
#---------------------------------------------------------------------------------
|
||||
BUILD ?= release
|
||||
SOURCES := source \
|
||||
source/utils \
|
||||
source/network \
|
||||
source/patcher \
|
||||
source/config \
|
||||
INCLUDES := include
|
||||
DATA :=
|
||||
LIB := lib
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
CFLAGS = -g -Os -Wall -D__wiiu__ $(MACHDEP) $(INCLUDE)
|
||||
CXXFLAGS = $(CFLAGS) -D_GNU_SOURCE
|
||||
|
||||
ifeq ($(DO_LOGGING), 1)
|
||||
CFLAGS += -D__LOGGING__
|
||||
CXXFLAGS += -D__LOGGING__
|
||||
endif
|
||||
|
||||
ASFLAGS := -g
|
||||
|
||||
export WIIUBIN := $(LIB)/libcontrollerpatcher.a
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -ldynamiclibs -lutils
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export TOPDIR ?= $(CURDIR)/..
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD) -I$(PORTLIBS)/include -I$(PORTLIBS)/include/libutils
|
||||
|
||||
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(PORTLIBS)/lib
|
||||
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr debug release bin obj $(LIB) include
|
||||
|
||||
all: $(WIIUBIN)
|
||||
|
||||
install:
|
||||
@cp $(BUILD)/lib/libcontrollerpatcher.a $(PORTLIBS)/lib
|
||||
@mkdir -p $(PORTLIBS)/include/controller_patcher
|
||||
@cp source/ControllerPatcher.hpp $(PORTLIBS)/include/controller_patcher
|
||||
@cp source/ControllerPatcherDefs.h $(PORTLIBS)/include/controller_patcher
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(WIIUBIN) : $(OFILES) $(LIB)
|
||||
@rm -f "$(WIIUBIN)"
|
||||
@$(AR) rcs "$(WIIUBIN)" $(OFILES)
|
||||
@echo built ... $(notdir $@)
|
||||
|
||||
$(LIB):
|
||||
mkdir $(LIB)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
33
README.md
33
README.md
@ -7,16 +7,39 @@ Detailed information about creating config files and adding support for more con
|
||||
# Where can I find config files
|
||||
Configfiles for all controllers are collection in [this repository](https://github.com/Maschell/controller_patch_configs)
|
||||
|
||||
# Dependencies for including it in other applications
|
||||
This controller_patcher is build to be used in serveral projects. It don't uses some ultra fancy external libraries. </br>
|
||||
To be able to use in other projects, you will need some external data though.</br>
|
||||
- At first, you need a copy of the [dynamic_libs](https://github.com/Maschell/dynamic_libs) in your src/dynamic_libs folder.
|
||||
- To able to log something, you need the right [logger functions](https://github.com/Maschell/hid_to_vpad/tree/master/src/utils).
|
||||
## Logging usage
|
||||
To able to use the logging change the "DO_LOGGING" parameter in the Makefile.
|
||||
|
||||
# Compiling
|
||||
You need to install all dependencies first!
|
||||
|
||||
Install this static library into your portlibs folder via:
|
||||
|
||||
```
|
||||
make && make install
|
||||
```
|
||||
|
||||
# Dependencies
|
||||
- Application needs to be loaded from the [homebrew_launcher](https://github.com/dimok789/homebrew_launcher)
|
||||
- [libutils](https://github.com/Maschell/libutils) for common function.
|
||||
- [dynamic_libs](https://github.com/Maschell/dynamic_libs/tree/lib) for access to the functions.
|
||||
|
||||
# Example implementation
|
||||
|
||||
### How to "install" it
|
||||
TODO!
|
||||
|
||||
```
|
||||
ControllerPatcher::Init(NULL); //No custom configuration
|
||||
ControllerPatcher::disableControllerMapping();
|
||||
ControllerPatcher::startNetworkServer();
|
||||
```
|
||||
|
||||
```
|
||||
ControllerPatcher::DeInit();
|
||||
ControllerPatcher::stopNetworkServer();
|
||||
```
|
||||
|
||||
# Credits:
|
||||
- Maschell
|
||||
- FIX94 - huge thanks to him and his initally created gc-to-vpad. Was a motivation and base to start all this
|
||||
|
@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "./ConfigReader.hpp"
|
||||
#include "./utils/CPFSUtils.hpp"
|
||||
#include <fs/FSUtils.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -29,8 +29,8 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#include "dynamic_libs/fs_functions.h"
|
||||
#include "utils/logger.h"
|
||||
#include <dynamic_libs/fs_functions.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
s32 ConfigReader::numberValidFiles = 0;
|
||||
ConfigReader *ConfigReader::instance = NULL;
|
||||
@ -74,7 +74,7 @@ std::vector<std::string> ConfigReader::ScanFolder(std::string path){
|
||||
|
||||
std::string newPath = path + "/" + std::string(filename);
|
||||
|
||||
if(!isDir && CPStringTools::EndsWith(std::string(filename),".ini")){
|
||||
if(!isDir && StringTools::EndsWith(std::string(filename),".ini")){
|
||||
config_files.push_back(newPath);
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found ini: %s \n",newPath.c_str()); }
|
||||
}
|
||||
@ -96,11 +96,11 @@ void ConfigReader::processFileList(std::vector<std::string> path){
|
||||
std::string ConfigReader::loadFileToString(std::string path){
|
||||
std::string strBuffer = "";
|
||||
u8 * buffer = NULL;
|
||||
if(CPFSUtils::LoadFileToMem(path.c_str(),&buffer,NULL) > 0){
|
||||
if(FSUtils::LoadFileToMem(path.c_str(),&buffer,NULL) > 0){
|
||||
strBuffer = std::string((char *)buffer);
|
||||
strBuffer = CPStringTools::removeCharFromString(strBuffer,'\r');
|
||||
strBuffer = CPStringTools::removeCharFromString(strBuffer,' ');
|
||||
strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t');
|
||||
strBuffer = StringTools::removeCharFromString(strBuffer,'\r');
|
||||
strBuffer = StringTools::removeCharFromString(strBuffer,' ');
|
||||
strBuffer = StringTools::removeCharFromString(strBuffer,'\t');
|
||||
}
|
||||
return strBuffer;
|
||||
}
|
@ -17,11 +17,10 @@
|
||||
#ifndef _ConfigReader_H_
|
||||
#define _ConfigReader_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "./ControllerPatcher.hpp"
|
||||
#include "ControllerPatcherIncludes.hpp"
|
||||
|
||||
class ConfigReader{
|
||||
friend class ControllerPatcher;
|
@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "ControllerPatcher.hpp"
|
||||
#include "ControllerPatcherIncludes.hpp"
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
#include "dynamic_libs/sys_functions.h"
|
||||
#include "dynamic_libs/syshid_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "dynamic_libs/padscore_functions.h"
|
||||
#include <dynamic_libs/sys_functions.h>
|
||||
#include <dynamic_libs/syshid_functions.h>
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
#include <dynamic_libs/padscore_functions.h>
|
||||
|
||||
// This stores the holded buttons for the gamepad after the button remapping.
|
||||
static u32 buttonRemapping_lastButtonsHold = 0;
|
||||
@ -105,12 +105,12 @@ void ControllerPatcher::ResetConfig(){
|
||||
gHIDRegisteredDevices = 0;
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
gGamePadSlot = slotdata.deviceslot;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
gMouseSlot = slotdata.deviceslot;
|
||||
gHID_LIST_MOUSE = slotdata.hidmask;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 keyboard_slot = slotdata.deviceslot;
|
||||
@ -118,36 +118,36 @@ void ControllerPatcher::ResetConfig(){
|
||||
gHID_LIST_KEYBOARD = keyboard_hid;
|
||||
gHID_SLOT_KEYBOARD = keyboard_slot;
|
||||
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 gc_slot = slotdata.deviceslot;
|
||||
u32 gc_hid = slotdata.hidmask;
|
||||
gHID_LIST_GC = gc_hid;
|
||||
gHID_SLOT_GC = gc_slot;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 ds3_slot = slotdata.deviceslot;
|
||||
u32 ds3_hid = slotdata.hidmask;
|
||||
gHID_LIST_DS3 = ds3_hid;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS3-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS3-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 ds4_slot = slotdata.deviceslot;
|
||||
u32 ds4_hid = slotdata.hidmask;
|
||||
gHID_LIST_DS4 = ds4_hid;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS4-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(ds4_hid),ds4_slot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS4-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(ds4_hid),ds4_slot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 xinput_slot = slotdata.deviceslot;
|
||||
u32 xinput_hid = slotdata.hidmask;
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register XInput-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(xinput_hid),xinput_slot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register XInput-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(xinput_hid),xinput_slot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 switch_pro_slot = slotdata.deviceslot;
|
||||
gHID_LIST_SWITCH_PRO = slotdata.hidmask;
|
||||
DEBUG_FUNCTION_LINE("Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot);
|
||||
DEBUG_FUNCTION_LINE("Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot);
|
||||
|
||||
|
||||
config_controller_hidmask[gc_slot] = gHID_LIST_GC;
|
||||
@ -725,6 +725,7 @@ ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UControll
|
||||
}
|
||||
|
||||
HID_Mouse_Data * ControllerPatcher::getMouseData(){
|
||||
if(gHID_Mouse_Mode != HID_MOUSE_MODE_TOUCH) return NULL;
|
||||
ControllerMappingPAD * CMPAD = ControllerPatcherUtils::getControllerMappingByType(UController_Type_Gamepad);
|
||||
|
||||
if(CMPAD == NULL){
|
||||
@ -1070,3 +1071,89 @@ bool ControllerPatcher::isRumbleActivated(){
|
||||
return gGlobalRumbleActivated;
|
||||
}
|
||||
|
||||
|
||||
bool ControllerPatcher::isButtonRemappingDone(){
|
||||
return gButtonRemappingConfigDone;
|
||||
}
|
||||
|
||||
bool ControllerPatcher::isKeyboardConnected(){
|
||||
return (gHIDCurrentDevice & gHID_LIST_KEYBOARD) == gHID_LIST_KEYBOARD;
|
||||
}
|
||||
|
||||
bool ControllerPatcher::areControllersConnected(){
|
||||
return gHIDAttached > 0;
|
||||
}
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::sampleKeyboardData(){
|
||||
if(ControllerPatcher::isKeyboardConnected()){
|
||||
ControllerPatcher::doSamplingForDeviceSlot(gHID_SLOT_KEYBOARD);
|
||||
}
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetCallbackData(){
|
||||
memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback));
|
||||
memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback));
|
||||
memset(gExtensionCallback,0,sizeof(gExtensionCallback));
|
||||
gSamplingCallback = 0;
|
||||
gCallbackCooldown = 0;
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADConnectedCallback(s32 chan, wpad_connect_callback_t callback){
|
||||
if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; }
|
||||
gKPADConnectCallback[chan] = callback;
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADExtensionCallback(s32 chan, wpad_connect_callback_t callback){
|
||||
if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; }
|
||||
gExtensionCallback[chan] = callback;
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setWPADConnectCallback(s32 chan, wpad_connect_callback_t callback){
|
||||
if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; }
|
||||
gWPADConnectCallback[chan] = callback;
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::handleCallbackData(bool button_pressed){
|
||||
if(button_pressed && gCallbackCooldown == 0){
|
||||
gCallbackCooldown = 0xFF;
|
||||
|
||||
/*if(HID_DEBUG){ log_printf("my_VPADRead(line %d): Pressed the TV button. Maybe we can call the callbacks.!\n",__LINE__); }
|
||||
if(HID_DEBUG){ log_printf("my_VPADRead(line %d): gExtensionCallback = %08X %08X %08X %08X\n",__LINE__,gExtensionCallback[0],gExtensionCallback[1],gExtensionCallback[2],gExtensionCallback[3]); }
|
||||
if(HID_DEBUG){ log_printf("my_VPADRead(line %d): gWPADConnectCallback = %08X %08X %08X %08X\n",__LINE__,gWPADConnectCallback[0],gWPADConnectCallback[1],gWPADConnectCallback[2],gWPADConnectCallback[3]); }
|
||||
if(HID_DEBUG){ log_printf("my_VPADRead(line %d): gKPADConnectCallback = %08X %08X %08X %08X\n",__LINE__,gKPADConnectCallback[0],gKPADConnectCallback[1],gKPADConnectCallback[2],gKPADConnectCallback[3]); }*/
|
||||
|
||||
for(s32 i = 0;i<4;i++){
|
||||
bool doCall = false;
|
||||
if(i == 0){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1); }
|
||||
if(i == 1){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2); }
|
||||
if(i == 2){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3); }
|
||||
if(i == 3){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4); }
|
||||
if(doCall){
|
||||
if(gWPADConnectCallback[i] != NULL){
|
||||
log_printf("my_VPADRead(line %d): Called WPAD connect callback for pro controller in slot %d!\n",__LINE__,(i+1));
|
||||
gWPADConnectCallback[i](i,0);
|
||||
}
|
||||
if(gKPADConnectCallback[i] != NULL){
|
||||
log_printf("my_VPADRead(line %d): Called KPAD connect callback for pro controller in slot %d!\n",__LINE__,(i+1));
|
||||
gKPADConnectCallback[i](i,0);
|
||||
}
|
||||
if(gExtensionCallback[i] != NULL){
|
||||
log_printf("my_VPADRead(line %d): Called extension callback for pro controller in slot %d!\n",__LINE__,(i+1));
|
||||
gExtensionCallback[i](i,WPAD_EXT_PRO_CONTROLLER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(gCallbackCooldown > 0){
|
||||
gCallbackCooldown--;
|
||||
}
|
||||
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
@ -27,32 +27,11 @@
|
||||
#ifndef _CONTROLLER_PATCHER_H_
|
||||
#define _CONTROLLER_PATCHER_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include "./patcher/ControllerPatcherDefs.h"
|
||||
#include "./utils/ControllerPatcherThread.hpp"
|
||||
#include "./utils/CPRetainVars.hpp"
|
||||
#include "./utils/PadConst.hpp"
|
||||
#include "./utils/CPStringTools.hpp"
|
||||
|
||||
#include "./patcher/ControllerPatcherHID.hpp"
|
||||
#include "./patcher/ControllerPatcherUtils.hpp"
|
||||
|
||||
#include "./config/ConfigValues.hpp"
|
||||
#include "./config/ConfigParser.hpp"
|
||||
|
||||
#include "./network/ControllerPatcherNet.hpp"
|
||||
#include "./network/TCPServer.hpp"
|
||||
#include "./network/UDPServer.hpp"
|
||||
#include "./network/UDPClient.hpp"
|
||||
#include "./ConfigReader.hpp"
|
||||
|
||||
#include "dynamic_libs/vpad_functions.h"
|
||||
|
||||
|
||||
#define HID_DEBUG 0
|
||||
#include <dynamic_libs/vpad_functions.h>
|
||||
#include <dynamic_libs/padscore_functions.h>
|
||||
#include "ControllerPatcherDefs.h"
|
||||
|
||||
class ControllerPatcher{
|
||||
public:
|
||||
@ -247,6 +226,24 @@ class ControllerPatcher{
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR setNetworkControllerActivated(bool value);
|
||||
|
||||
static bool isRumbleActivated();
|
||||
|
||||
static bool isButtonRemappingDone();
|
||||
|
||||
static bool isKeyboardConnected();
|
||||
|
||||
static bool areControllersConnected();
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR sampleKeyboardData();
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR resetCallbackData();
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADConnectedCallback(s32 chan, wpad_connect_callback_t callback);
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADExtensionCallback(s32 chan, wpad_connect_callback_t callback);
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR setWPADConnectCallback(s32 chan, wpad_connect_callback_t callback);
|
||||
|
||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR handleCallbackData(bool button_pressed);
|
||||
};
|
||||
|
||||
#endif /* _CONTROLLER_PATCHER_H_ */
|
@ -27,7 +27,8 @@
|
||||
#ifndef _CONTROLLER_PATCHER_DEFS_H_
|
||||
#define _CONTROLLER_PATCHER_DEFS_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <dynamic_libs/os_types.h>
|
||||
|
||||
|
||||
#define FIRST_INSTRUCTION_IN_SAMPLING_CALLBACK 0x9421FFB8
|
||||
|
45
source/ControllerPatcherIncludes.hpp
Normal file
45
source/ControllerPatcherIncludes.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
* 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/>.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CONTROLLER_PATCHER_INCLUDES_H_
|
||||
#define _CONTROLLER_PATCHER_INCLUDES_H_
|
||||
|
||||
#define HID_DEBUG 0
|
||||
|
||||
#include <dynamic_libs/os_types.h>
|
||||
|
||||
#include "./ConfigReader.hpp"
|
||||
#include "./ControllerPatcher.hpp"
|
||||
|
||||
#include <system/CThread.h>
|
||||
#include "./utils/CPRetainVars.hpp"
|
||||
#include "./utils/PadConst.hpp"
|
||||
#include <utils/StringTools.h>
|
||||
|
||||
#include "./patcher/ControllerPatcherHID.hpp"
|
||||
#include "./patcher/ControllerPatcherUtils.hpp"
|
||||
|
||||
#include "./config/ConfigValues.hpp"
|
||||
#include "./config/ConfigParser.hpp"
|
||||
|
||||
#include "./network/ControllerPatcherNet.hpp"
|
||||
#include "./network/TCPServer.hpp"
|
||||
#include "./network/UDPServer.hpp"
|
||||
#include "./network/UDPClient.hpp"
|
||||
|
||||
|
||||
#endif /* _CONTROLLER_PATCHER_INCLUDES_H_ */
|
@ -15,6 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "./ConfigParser.hpp"
|
||||
#include <utils/StringTools.h>
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -22,7 +23,7 @@
|
||||
|
||||
ConfigParser::ConfigParser(std::string configData){
|
||||
this->content = configData;
|
||||
this->contentLines = CPStringTools::StringSplit(content, "\n");
|
||||
this->contentLines = StringTools::stringSplit(content, "\n");
|
||||
|
||||
if(contentLines.empty()){
|
||||
return;
|
||||
@ -30,7 +31,7 @@ ConfigParser::ConfigParser(std::string configData){
|
||||
|
||||
//remove the comments and make everything uppercase
|
||||
for(u32 i = 0; i < contentLines.size(); i++){
|
||||
std::vector<std::string> comments = CPStringTools::StringSplit(contentLines[i], "//");
|
||||
std::vector<std::string> comments = StringTools::stringSplit(contentLines[i], "//");
|
||||
if(!comments.empty()){
|
||||
contentLines[i] = comments[0];
|
||||
}
|
||||
@ -122,7 +123,7 @@ bool ConfigParser::Init(){
|
||||
|
||||
void ConfigParser::parseSingleLine(std::string line){
|
||||
if(line.empty()){DEBUG_FUNCTION_LINE("Can't parse line. it's empty\n"); return;}
|
||||
std::vector<std::string> cur_values = CPStringTools::StringSplit(line,"=");
|
||||
std::vector<std::string> cur_values = StringTools::stringSplit(line,"=");
|
||||
if(cur_values.size() != 2){
|
||||
if(HID_DEBUG || cur_values.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",line.c_str()); }
|
||||
return;
|
||||
@ -198,7 +199,7 @@ void ConfigParser::parseSingleLine(std::string line){
|
||||
|
||||
if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("And its no preset\n"); }
|
||||
std::vector<std::string> rightvalues = CPStringTools::StringSplit(cur_values[1],",");
|
||||
std::vector<std::string> rightvalues = StringTools::stringSplit(cur_values[1],",");
|
||||
|
||||
if(rightvalues.size() != 2){
|
||||
DEBUG_FUNCTION_LINE("%d instead of 2 key=values pairs in line\n",rightvalues.size());
|
||||
@ -235,7 +236,7 @@ bool ConfigParser::resetConfig(){
|
||||
s32 ConfigParser::getSlotController(std::string identify){
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Getting Controller Slot\n"); }
|
||||
|
||||
std::vector<std::string> values = CPStringTools::StringSplit(identify,",");
|
||||
std::vector<std::string> values = StringTools::stringSplit(identify,",");
|
||||
|
||||
if(values.size() != 2){
|
||||
DEBUG_FUNCTION_LINE("You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",identify.c_str());
|
||||
@ -274,7 +275,7 @@ s32 ConfigParser::getSlotController(std::string identify){
|
||||
DEBUG_FUNCTION_LINE("We don't a space for a new controller, please delete .inis\n");
|
||||
return HID_INVALID_SLOT;
|
||||
}
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,CPStringTools::byte_to_binary(hid)); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,StringTools::byte_to_binary(hid)); }
|
||||
config_controller[slot][CONTRPS_VID][0] = (vid & 0xFF00) >> 8;
|
||||
config_controller[slot][CONTRPS_VID][1] = (vid & 0x00FF);
|
||||
config_controller[slot][CONTRPS_PID][0] = (pid & 0xFF00) >> 8;
|
||||
@ -291,7 +292,7 @@ s32 ConfigParser::getSlotController(std::string identify){
|
||||
}else{
|
||||
if(slot < gHIDMaxDevices){
|
||||
hid = config_controller_hidmask[slot];
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,CPStringTools::byte_to_binary(hid)); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,StringTools::byte_to_binary(hid)); }
|
||||
DEBUG_FUNCTION_LINE("We already have data of this controller, lets modify it\n");
|
||||
}else{
|
||||
DEBUG_FUNCTION_LINE("Something really odd happend to the slots. %d is bigger then max (%d)\n",slot,gHIDMaxDevices);
|
||||
@ -333,7 +334,7 @@ bool ConfigParser::parseIni(){
|
||||
}
|
||||
|
||||
s32 ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter){
|
||||
std::vector<std::string> string_value = CPStringTools::StringSplit(value_pair,delimiter);
|
||||
std::vector<std::string> string_value = StringTools::stringSplit(value_pair,delimiter);
|
||||
if(string_value.size() != 2){
|
||||
if(HID_DEBUG || string_value.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",value_pair.c_str()); }
|
||||
return -1;
|
@ -19,7 +19,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
ConfigValues *ConfigValues::instance = NULL;
|
||||
|
||||
@ -106,18 +106,18 @@ s32 ConfigValues::getPresetValueEx(std::string possibleString){
|
||||
}
|
||||
|
||||
void ConfigValues::addDeviceNameEx(u16 vid,u16 pid,std::string value){
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",vid,pid).c_str()] = value;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",vid,pid).c_str()] = value;
|
||||
}
|
||||
|
||||
std::string ConfigValues::getStringByVIDPIDEx(u16 vid,u16 pid){
|
||||
std::string result = "";
|
||||
std::map<std::string,std::string>::iterator it;
|
||||
|
||||
it = deviceNames.find(CPStringTools::strfmt("%04X%04X",vid,pid));
|
||||
it = deviceNames.find(StringTools::strfmt("%04X%04X",vid,pid));
|
||||
if (it != deviceNames.end()){
|
||||
result = it->second;
|
||||
}else{
|
||||
result = CPStringTools::strfmt("VID: 0x%04X\nPID: 0x%04X",vid,pid);
|
||||
result = StringTools::strfmt("VID: 0x%04X\nPID: 0x%04X",vid,pid);
|
||||
}
|
||||
return result;
|
||||
}
|
@ -22,11 +22,10 @@
|
||||
#include <map>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gctypes.h>
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
enum PARSE_TYPE{
|
||||
PARSE_CONTROLLER,
|
@ -20,11 +20,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <gctypes.h>
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
class ConfigValues
|
||||
{
|
||||
@ -551,14 +550,14 @@ private:
|
||||
gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP;
|
||||
gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN;
|
||||
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_KEYBOARD_VID, HID_KEYBOARD_PID).c_str()] = HID_KEYBOARD_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS3_VID, HID_DS3_PID).c_str()] = HID_DS3_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_NEW_DS4_VID, HID_NEW_DS4_PID).c_str()] = HID_NEW_DS4_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_DS4_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_XINPUT_VID, HID_XINPUT_PID).c_str()] = HID_XINPUT_STRING;
|
||||
deviceNames[CPStringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID,HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_KEYBOARD_VID, HID_KEYBOARD_PID).c_str()] = HID_KEYBOARD_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_DS3_VID, HID_DS3_PID).c_str()] = HID_DS3_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_NEW_DS4_VID, HID_NEW_DS4_PID).c_str()] = HID_NEW_DS4_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_DS4_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_XINPUT_VID, HID_XINPUT_PID).c_str()] = HID_XINPUT_STRING;
|
||||
deviceNames[StringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID,HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING;
|
||||
}
|
||||
|
||||
const u8 * getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue);
|
@ -1,6 +1,6 @@
|
||||
#include "ControllerPatcherNet.hpp"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include <dynamic_libs/os_functions.h>
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
|
||||
s32 ControllerPatcherNet::recvwait(s32 sock, void *buffer, s32 len) {
|
||||
s32 ret;
|
@ -1,7 +1,7 @@
|
||||
#ifndef _CONTROLLERPATCHERNET_H_
|
||||
#define _CONTROLLERPATCHERNET_H_
|
||||
|
||||
#include<gctypes.h>
|
||||
#include <dynamic_libs/os_types.h>
|
||||
|
||||
class ControllerPatcherNet{
|
||||
friend class TCPServer;
|
@ -19,11 +19,11 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
#define wiiu_errno (*__gh_errno_ptr())
|
||||
|
||||
ControllerPatcherThread * TCPServer::pThread = NULL;
|
||||
CThread * TCPServer::pThread = NULL;
|
||||
TCPServer * TCPServer::instance = NULL;
|
||||
|
||||
TCPServer::TCPServer(s32 port){
|
||||
@ -68,7 +68,7 @@ void TCPServer::StartTCPThread(TCPServer * server){
|
||||
priority = 10;
|
||||
DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority);
|
||||
}
|
||||
TCPServer::pThread = ControllerPatcherThread::create(TCPServer::DoTCPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority);
|
||||
TCPServer::pThread = CThread::create(TCPServer::DoTCPThread, (void*)server, CThread::eAttributeAffCore2,priority);
|
||||
TCPServer::pThread->resumeThread();
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ void TCPServer::DoTCPThreadInternal(){
|
||||
|
||||
}
|
||||
|
||||
void TCPServer::DoTCPThread(ControllerPatcherThread *thread, void *arg){
|
||||
void TCPServer::DoTCPThread(CThread *thread, void *arg){
|
||||
TCPServer * args = (TCPServer * )arg;
|
||||
return args->DoTCPThreadInternal();
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
#define MAX_UDP_SIZE 0x578
|
||||
|
@ -17,11 +17,9 @@
|
||||
#ifndef _UDPCLIENT_WINDOW_H_
|
||||
#define _UDPCLIENT_WINDOW_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
|
||||
#define DEFAULT_UDP_CLIENT_PORT 8114
|
||||
|
@ -19,13 +19,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "utils/logger.h"
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
#define MAX_UDP_SIZE 0x578
|
||||
#define wiiu_errno (*__gh_errno_ptr())
|
||||
|
||||
ControllerPatcherThread * UDPServer::pThread = NULL;
|
||||
CThread * UDPServer::pThread = NULL;
|
||||
UDPServer * UDPServer::instance = NULL;
|
||||
|
||||
UDPServer::UDPServer(s32 port){
|
||||
@ -47,7 +47,7 @@ UDPServer::UDPServer(s32 port){
|
||||
}
|
||||
|
||||
UDPServer::~UDPServer(){
|
||||
ControllerPatcherThread * pThreadPointer = UDPServer::pThread;
|
||||
CThread * pThreadPointer = UDPServer::pThread;
|
||||
if(pThreadPointer != NULL){
|
||||
exitThread = 1;
|
||||
if(pThreadPointer != NULL){
|
||||
@ -74,7 +74,7 @@ void UDPServer::StartUDPThread(UDPServer * server){
|
||||
priority = 10;
|
||||
DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority);
|
||||
}
|
||||
UDPServer::pThread = ControllerPatcherThread::create(UDPServer::DoUDPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority);
|
||||
UDPServer::pThread = CThread::create(UDPServer::DoUDPThread, (void*)server, CThread::eAttributeAffCore2,priority);
|
||||
UDPServer::pThread->resumeThread();
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * off
|
||||
return true;
|
||||
}
|
||||
|
||||
void UDPServer::DoUDPThread(ControllerPatcherThread *thread, void *arg){
|
||||
void UDPServer::DoUDPThread(CThread *thread, void *arg){
|
||||
UDPServer * args = (UDPServer * )arg;
|
||||
args->DoUDPThreadInternal();
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
#ifndef _UDPSERVER_WINDOW_H_
|
||||
#define _UDPSERVER_WINDOW_H_
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#define DEFAULT_UDP_PORT 8113
|
||||
|
||||
@ -43,7 +43,7 @@ private:
|
||||
UDPServer(s32 port);
|
||||
~UDPServer();
|
||||
void StartUDPThread(UDPServer * server);
|
||||
static void DoUDPThread(ControllerPatcherThread *thread, void *arg);
|
||||
static void DoUDPThread(CThread *thread, void *arg);
|
||||
void DoUDPThreadInternal();
|
||||
bool cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum);
|
||||
|
||||
@ -51,7 +51,7 @@ private:
|
||||
volatile s32 exitThread = 0;
|
||||
|
||||
static UDPServer *instance;
|
||||
static ControllerPatcherThread *pThread;
|
||||
static CThread *pThread;
|
||||
};
|
||||
|
||||
#endif //_UDPSERVER_WINDOW_H_
|
@ -17,10 +17,10 @@
|
||||
#ifndef _TCPSERVER_WINDOW_H_
|
||||
#define _TCPSERVER_WINDOW_H_
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include <dynamic_libs/socket_functions.h>
|
||||
#include <dynamic_libs/os_functions.h>
|
||||
|
||||
#define WIIU_CP_TCP_HANDSHAKE WIIU_CP_TCP_HANDSHAKE_VERSION_3
|
||||
|
||||
@ -72,7 +72,7 @@ private:
|
||||
void ErrorHandling();
|
||||
|
||||
void StartTCPThread(TCPServer * server);
|
||||
static void DoTCPThread(ControllerPatcherThread *thread, void *arg);
|
||||
static void DoTCPThread(CThread *thread, void *arg);
|
||||
void DoTCPThreadInternal();
|
||||
static void DetachConnectedNetworkController();
|
||||
static void AttachDetach(s32 attach);
|
||||
@ -87,7 +87,7 @@ private:
|
||||
|
||||
|
||||
volatile s32 exitThread = 0;
|
||||
static ControllerPatcherThread *pThread;
|
||||
static CThread *pThread;
|
||||
};
|
||||
|
||||
#endif //_TCPSERVER_WINDOW_H_
|
@ -19,11 +19,11 @@
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gctypes.h>
|
||||
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <dynamic_libs/os_functions.h>
|
||||
|
||||
#include <utils/logger.h>
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
* public implementation for the network controller
|
||||
@ -562,7 +562,7 @@ std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
|
||||
s32 res;
|
||||
HID_Data * new_data = NULL;
|
||||
if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid.
|
||||
DEBUG_FUNCTION_LINE("error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",CPStringTools::byte_to_binary(cur_hidmask),pad,res);
|
||||
DEBUG_FUNCTION_LINE("error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",StringTools::byte_to_binary(cur_hidmask),pad,res);
|
||||
continue;
|
||||
}
|
||||
if(new_data != NULL) data_list.push_back(new_data);
|
@ -29,10 +29,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "dynamic_libs/syshid_functions.h"
|
||||
#include "dynamic_libs/vpad_functions.h"
|
||||
#include <dynamic_libs/syshid_functions.h>
|
||||
#include <dynamic_libs/vpad_functions.h>
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
#define SWAP16(x) ((x>>8) | ((x&0xFF)<<8))
|
||||
#define SWAP8(x) ((x>>4) | ((x&0xF)<<4))
|
@ -18,7 +18,7 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include <utils/logger.h>
|
||||
|
||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){
|
||||
for(s32 i = 0;i< gHIDMaxDevices;i++){
|
@ -27,12 +27,10 @@
|
||||
#ifndef _CONTROLLER_PATCHER_UTIL_H_
|
||||
#define _CONTROLLER_PATCHER_UTIL_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <dynamic_libs/vpad_functions.h>
|
||||
#include <dynamic_libs/padscore_functions.h>
|
||||
|
||||
#include "dynamic_libs/vpad_functions.h"
|
||||
#include "dynamic_libs/padscore_functions.h"
|
||||
|
||||
#include "../ControllerPatcher.hpp"
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
class ControllerPatcherUtils{
|
||||
//give the other classes access to the private functions.
|
@ -14,8 +14,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include <gctypes.h>
|
||||
#include "../ControllerPatcher.hpp"
|
||||
|
||||
#include "../ControllerPatcherIncludes.hpp"
|
||||
|
||||
ControllerMapping gControllerMapping __attribute__((section(".data")));
|
||||
|
||||
@ -62,7 +62,6 @@ wpad_connect_callback_t gKPADConnectCallback[4] __attribute__((section(".data"))
|
||||
wpad_extension_callback_t gExtensionCallback[4] __attribute__((section(".data")));
|
||||
wpad_sampling_callback_t gSamplingCallback __attribute__((section(".data"))) = 0;
|
||||
u8 gCallbackCooldown __attribute__((section(".data"))) = 0;
|
||||
u8 gAppStatus __attribute__((section(".data"))) = 0;
|
||||
u8 gNetworkControllerActivated __attribute__((section(".data"))) = 1;
|
||||
|
||||
u8 gGlobalRumbleActivated __attribute__((section(".data"))) = 0;
|
@ -17,9 +17,9 @@
|
||||
#ifndef CP_RETAINS_VARS_H_
|
||||
#define CP_RETAINS_VARS_H_
|
||||
|
||||
#include "dynamic_libs/syshid_functions.h"
|
||||
#include "dynamic_libs/padscore_functions.h"
|
||||
#include "../patcher/ControllerPatcherDefs.h"
|
||||
#include <dynamic_libs/syshid_functions.h>
|
||||
#include <dynamic_libs/padscore_functions.h>
|
||||
#include "../ControllerPatcherDefs.h"
|
||||
|
||||
extern ControllerMapping gControllerMapping;
|
||||
|
||||
@ -67,7 +67,6 @@ extern wpad_extension_callback_t gExtensionCallback[4];
|
||||
extern wpad_sampling_callback_t gSamplingCallback;
|
||||
extern u8 gCallbackCooldown;
|
||||
extern u8 gGlobalRumbleActivated;
|
||||
extern u8 gAppStatus;
|
||||
extern u8 gNetworkControllerActivated;
|
||||
|
||||
extern u32 gUDPClientip;
|
@ -18,9 +18,9 @@
|
||||
#ifndef _PAD_CONST_H_
|
||||
#define _PAD_CONST_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#include <string>
|
||||
#include "../patcher/ControllerPatcherDefs.h"
|
||||
#include "../ControllerPatcherDefs.h"
|
||||
|
||||
extern const u8 DEF_R_STICK;
|
||||
extern const u8 DEF_L_STICK;
|
@ -1,69 +0,0 @@
|
||||
#include "CPFSUtils.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//Copy pasted from dimoks sources. Thanks!!!
|
||||
s32 CPFSUtils::LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size){
|
||||
//! always initialze input
|
||||
*inbuffer = NULL;
|
||||
if(size){
|
||||
*size = 0;
|
||||
}
|
||||
|
||||
s32 iFd = open(filepath, O_RDONLY);
|
||||
if (iFd < 0)
|
||||
return -1;
|
||||
|
||||
u32 filesize = lseek(iFd, 0, SEEK_END);
|
||||
lseek(iFd, 0, SEEK_SET);
|
||||
|
||||
u8 *buffer = (u8 *) malloc(filesize);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
close(iFd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
u32 blocksize = 0x4000;
|
||||
u32 done = 0;
|
||||
s32 readBytes = 0;
|
||||
|
||||
while(done < filesize)
|
||||
{
|
||||
if(done + blocksize > filesize) {
|
||||
blocksize = filesize - done;
|
||||
}
|
||||
readBytes = read(iFd, buffer + done, blocksize);
|
||||
if(readBytes <= 0)
|
||||
break;
|
||||
done += readBytes;
|
||||
}
|
||||
|
||||
close(iFd);
|
||||
|
||||
if (done != filesize)
|
||||
{
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
return -3;
|
||||
}
|
||||
|
||||
*inbuffer = buffer;
|
||||
|
||||
//! size is optional input
|
||||
if(size){
|
||||
*size = filesize;
|
||||
}
|
||||
|
||||
return filesize;
|
||||
}
|
||||
|
||||
//CPFSUtils
|
@ -1,12 +0,0 @@
|
||||
#ifndef _CPFS_UTILS_H_
|
||||
#define _CPFS_UTILS_H_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gctypes.h>
|
||||
|
||||
class CPFSUtils{
|
||||
public:
|
||||
static s32 LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size);
|
||||
};
|
||||
|
||||
#endif /* _CPFS_UTILS_H_ */
|
@ -1,82 +0,0 @@
|
||||
#include "CPStringTools.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool CPStringTools::EndsWith(const std::string& a, const std::string& b) {
|
||||
if (b.size() > a.size()) return false;
|
||||
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
|
||||
}
|
||||
|
||||
std::vector<std::string> CPStringTools::StringSplit(const std::string & inValue, const std::string & splitter){
|
||||
std::string value = inValue;
|
||||
std::vector<std::string> result;
|
||||
while (true) {
|
||||
u32 index = value.find(splitter);
|
||||
if (index == std::string::npos) {
|
||||
result.push_back(value);
|
||||
break;
|
||||
}
|
||||
std::string first = value.substr(0, index);
|
||||
result.push_back(first);
|
||||
if (index + splitter.size() == value.length()) {
|
||||
result.push_back("");
|
||||
break;
|
||||
}
|
||||
if(index + splitter.size() > value.length()) {
|
||||
break;
|
||||
}
|
||||
value = value.substr(index + splitter.size(), value.length());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const char * CPStringTools::byte_to_binary(s32 x){
|
||||
static char b[9];
|
||||
b[0] = '\0';
|
||||
|
||||
s32 z;
|
||||
for (z = 128; z > 0; z >>= 1)
|
||||
{
|
||||
strcat(b, ((x & z) == z) ? "1" : "0");
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
std::string CPStringTools::removeCharFromString(std::string& input,char toBeRemoved){
|
||||
std::string output = input;
|
||||
size_t position;
|
||||
while(1){
|
||||
position = output.find(toBeRemoved);
|
||||
if(position == std::string::npos)
|
||||
break;
|
||||
output.erase(position, 1);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string CPStringTools::strfmt(const char * format, ...){
|
||||
std::string str;
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
str = tmp;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp){
|
||||
free(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
//CPStringTools
|
@ -1,16 +0,0 @@
|
||||
#ifndef _CPSTRING_TOOLS_H_
|
||||
#define _CPSTRING_TOOLS_H_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gctypes.h>
|
||||
|
||||
class CPStringTools{
|
||||
public:
|
||||
static bool EndsWith(const std::string& a, const std::string& b);
|
||||
static std::vector<std::string> StringSplit(const std::string & inValue, const std::string & splitter);
|
||||
static std::string removeCharFromString(std::string& input,char toBeRemoved);
|
||||
static const char *byte_to_binary(s32 x);
|
||||
static std::string strfmt(const char * format, ...);
|
||||
};
|
||||
|
||||
#endif /* _CPSTRING_TOOLS_H_ */
|
@ -1,121 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* 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/>.
|
||||
****************************************************************************/
|
||||
#ifndef CONTROLLERPATCHERTHREAD_H_
|
||||
#define CONTROLLERPATCHERTHREAD_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
class ControllerPatcherThread
|
||||
{
|
||||
public:
|
||||
typedef void (* Callback)(ControllerPatcherThread *thread, void *arg);
|
||||
|
||||
//! constructor
|
||||
ControllerPatcherThread(s32 iAttr, s32 iPriority = 16, s32 iStackSize = 0x8000, ControllerPatcherThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||
: pThread(NULL)
|
||||
, pThreadStack(NULL)
|
||||
, pCallback(callback)
|
||||
, pCallbackArg(callbackArg)
|
||||
{
|
||||
//! save attribute assignment
|
||||
iAttributes = iAttr;
|
||||
//! allocate the thread
|
||||
pThread = (OSThread*) memalign(8, 0x1000);
|
||||
//! allocate the stack
|
||||
pThreadStack = (u8 *) memalign(0x20, iStackSize);
|
||||
//! create the thread
|
||||
if(pThread && pThreadStack)
|
||||
OSCreateThread(pThread, &ControllerPatcherThread::threadCallback, 1, this, (u32)pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
|
||||
}
|
||||
|
||||
//! destructor
|
||||
virtual ~ControllerPatcherThread() {shutdownThread(); }
|
||||
|
||||
static ControllerPatcherThread *create(ControllerPatcherThread::Callback callback, void *callbackArg, s32 iAttr = eAttributeNone, s32 iPriority = 16, s32 iStackSize = 0x8000)
|
||||
{
|
||||
return ( new ControllerPatcherThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
||||
}
|
||||
|
||||
//! Get thread ID
|
||||
virtual void* getThread() const { return pThread; }
|
||||
//! Thread entry function
|
||||
virtual void executeThread(void)
|
||||
{
|
||||
if(pCallback)
|
||||
pCallback(this, pCallbackArg);
|
||||
}
|
||||
//! Suspend thread
|
||||
virtual void suspendThread(void) { if(isThreadSuspended()) return; if(pThread) OSSuspendThread(pThread); }
|
||||
//! Resume thread
|
||||
virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); }
|
||||
//! Set thread priority
|
||||
virtual void setThreadPriority(s32 prio) { if(pThread) OSSetThreadPriority(pThread, prio); }
|
||||
//! Check if thread is suspended
|
||||
virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; }
|
||||
//! Check if thread is terminated
|
||||
virtual bool isThreadTerminated(void) const { if(pThread) return OSIsThreadTerminated(pThread); return false; }
|
||||
//! Check if thread is running
|
||||
virtual bool isThreadRunning(void) const { return !isThreadSuspended() && !isThreadRunning(); }
|
||||
//! Shutdown thread
|
||||
virtual void shutdownThread(void)
|
||||
{
|
||||
//! wait for thread to finish
|
||||
if(pThread && !(iAttributes & eAttributeDetach))
|
||||
{
|
||||
while(isThreadSuspended()){
|
||||
resumeThread();
|
||||
}
|
||||
OSJoinThread(pThread, NULL);
|
||||
}
|
||||
//! free the thread stack buffer
|
||||
if(pThreadStack){
|
||||
free(pThreadStack);
|
||||
}
|
||||
if(pThread)
|
||||
free(pThread);
|
||||
pThread = NULL;
|
||||
pThreadStack = NULL;
|
||||
}
|
||||
//! Thread attributes
|
||||
enum eCThreadAttributes
|
||||
{
|
||||
eAttributeNone = 0x07,
|
||||
eAttributeAffCore0 = 0x01,
|
||||
eAttributeAffCore1 = 0x02,
|
||||
eAttributeAffCore2 = 0x04,
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributePinnedAff = 0x10
|
||||
};
|
||||
private:
|
||||
static s32 threadCallback(s32 argc, void *arg)
|
||||
{
|
||||
//! After call to start() continue with the internal function
|
||||
((ControllerPatcherThread *) arg)->executeThread();
|
||||
return 0;
|
||||
}
|
||||
s32 iAttributes;
|
||||
OSThread* pThread;
|
||||
u8 *pThreadStack;
|
||||
Callback pCallback;
|
||||
void *pCallbackArg;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user