diff --git a/.gitignore b/.gitignore index cd2946a..ba5f6af 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc829b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,134 @@ +DO_LOGGING := 0 + +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) +endif +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=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 +#--------------------------------------------------------------------------------------- + diff --git a/README.md b/README.md index 12c8159..df87026 100644 --- a/README.md +++ b/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.
-To be able to use in other projects, you will need some external data though.
-- 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 diff --git a/ConfigReader.cpp b/source/ConfigReader.cpp similarity index 86% rename from ConfigReader.cpp rename to source/ConfigReader.cpp index 5e4a4fa..80e9bbd 100644 --- a/ConfigReader.cpp +++ b/source/ConfigReader.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . ****************************************************************************/ #include "./ConfigReader.hpp" -#include "./utils/CPFSUtils.hpp" +#include #include #include @@ -29,8 +29,8 @@ #include -#include "dynamic_libs/fs_functions.h" -#include "utils/logger.h" +#include +#include s32 ConfigReader::numberValidFiles = 0; ConfigReader *ConfigReader::instance = NULL; @@ -74,7 +74,7 @@ std::vector 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 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; } diff --git a/ConfigReader.hpp b/source/ConfigReader.hpp similarity index 97% rename from ConfigReader.hpp rename to source/ConfigReader.hpp index 4a97088..0e6fbd8 100644 --- a/ConfigReader.hpp +++ b/source/ConfigReader.hpp @@ -17,11 +17,10 @@ #ifndef _ConfigReader_H_ #define _ConfigReader_H_ -#include #include #include -#include "./ControllerPatcher.hpp" +#include "ControllerPatcherIncludes.hpp" class ConfigReader{ friend class ControllerPatcher; diff --git a/ControllerPatcher.cpp b/source/ControllerPatcher.cpp similarity index 94% rename from ControllerPatcher.cpp rename to source/ControllerPatcher.cpp index 439c478..31cea9d 100644 --- a/ControllerPatcher.cpp +++ b/source/ControllerPatcher.cpp @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include "ControllerPatcher.hpp" +#include "ControllerPatcherIncludes.hpp" #include #include @@ -22,12 +22,12 @@ #include #include -#include "utils/logger.h" +#include -#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 +#include +#include +#include // 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; +} + diff --git a/ControllerPatcher.hpp b/source/ControllerPatcher.hpp similarity index 92% rename from ControllerPatcher.hpp rename to source/ControllerPatcher.hpp index d975adc..d3b2f11 100644 --- a/ControllerPatcher.hpp +++ b/source/ControllerPatcher.hpp @@ -27,32 +27,11 @@ #ifndef _CONTROLLER_PATCHER_H_ #define _CONTROLLER_PATCHER_H_ -#include #include - -#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 +#include +#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_ */ diff --git a/patcher/ControllerPatcherDefs.h b/source/ControllerPatcherDefs.h similarity index 99% rename from patcher/ControllerPatcherDefs.h rename to source/ControllerPatcherDefs.h index 121e8a9..f558624 100644 --- a/patcher/ControllerPatcherDefs.h +++ b/source/ControllerPatcherDefs.h @@ -27,7 +27,8 @@ #ifndef _CONTROLLER_PATCHER_DEFS_H_ #define _CONTROLLER_PATCHER_DEFS_H_ -#include +#include + #define FIRST_INSTRUCTION_IN_SAMPLING_CALLBACK 0x9421FFB8 diff --git a/source/ControllerPatcherIncludes.hpp b/source/ControllerPatcherIncludes.hpp new file mode 100644 index 0000000..f60e1c8 --- /dev/null +++ b/source/ControllerPatcherIncludes.hpp @@ -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 . + ****************************************************************************/ + +#ifndef _CONTROLLER_PATCHER_INCLUDES_H_ +#define _CONTROLLER_PATCHER_INCLUDES_H_ + +#define HID_DEBUG 0 + +#include + +#include "./ConfigReader.hpp" +#include "./ControllerPatcher.hpp" + +#include +#include "./utils/CPRetainVars.hpp" +#include "./utils/PadConst.hpp" +#include + +#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_ */ diff --git a/config/ConfigParser.cpp b/source/config/ConfigParser.cpp similarity index 94% rename from config/ConfigParser.cpp rename to source/config/ConfigParser.cpp index 5ae8b68..14be571 100644 --- a/config/ConfigParser.cpp +++ b/source/config/ConfigParser.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . ****************************************************************************/ #include "./ConfigParser.hpp" +#include #include #include #include @@ -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 comments = CPStringTools::StringSplit(contentLines[i], "//"); + std::vector 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 cur_values = CPStringTools::StringSplit(line,"="); + std::vector 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 rightvalues = CPStringTools::StringSplit(cur_values[1],","); + std::vector 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 values = CPStringTools::StringSplit(identify,","); + std::vector 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 string_value = CPStringTools::StringSplit(value_pair,delimiter); + std::vector 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; diff --git a/config/ConfigValues.cpp b/source/config/ConfigValues.cpp similarity index 95% rename from config/ConfigValues.cpp rename to source/config/ConfigValues.cpp index 7c577c5..22eec65 100644 --- a/config/ConfigValues.cpp +++ b/source/config/ConfigValues.cpp @@ -19,7 +19,7 @@ #include #include -#include "utils/logger.h" +#include 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::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; } diff --git a/config/ConfigParser.hpp b/source/config/configparser.hpp similarity index 95% rename from config/ConfigParser.hpp rename to source/config/configparser.hpp index 93207b7..421e42c 100644 --- a/config/ConfigParser.hpp +++ b/source/config/configparser.hpp @@ -22,11 +22,10 @@ #include #include -#include -#include "../ControllerPatcher.hpp" +#include "../ControllerPatcherIncludes.hpp" -#include "utils/logger.h" +#include enum PARSE_TYPE{ PARSE_CONTROLLER, diff --git a/config/ConfigValues.hpp b/source/config/configvalues.hpp similarity index 97% rename from config/ConfigValues.hpp rename to source/config/configvalues.hpp index 50dfb14..ac650ef 100644 --- a/config/ConfigValues.hpp +++ b/source/config/configvalues.hpp @@ -20,11 +20,10 @@ #include #include #include -#include -#include "../ControllerPatcher.hpp" +#include "../ControllerPatcherIncludes.hpp" -#include "utils/logger.h" +#include 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 values,std::string possibleValue); diff --git a/network/ControllerPatcherNet.cpp b/source/network/ControllerPatcherNet.cpp similarity index 92% rename from network/ControllerPatcherNet.cpp rename to source/network/ControllerPatcherNet.cpp index 7c5f9ed..429d670 100644 --- a/network/ControllerPatcherNet.cpp +++ b/source/network/ControllerPatcherNet.cpp @@ -1,6 +1,6 @@ #include "ControllerPatcherNet.hpp" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" +#include +#include s32 ControllerPatcherNet::recvwait(s32 sock, void *buffer, s32 len) { s32 ret; diff --git a/network/ControllerPatcherNet.hpp b/source/network/ControllerPatcherNet.hpp similarity index 92% rename from network/ControllerPatcherNet.hpp rename to source/network/ControllerPatcherNet.hpp index dcebd13..cab98b0 100644 --- a/network/ControllerPatcherNet.hpp +++ b/source/network/ControllerPatcherNet.hpp @@ -1,7 +1,7 @@ #ifndef _CONTROLLERPATCHERNET_H_ #define _CONTROLLERPATCHERNET_H_ -#include +#include class ControllerPatcherNet{ friend class TCPServer; diff --git a/network/TCPServer.cpp b/source/network/TCPServer.cpp similarity index 98% rename from network/TCPServer.cpp rename to source/network/TCPServer.cpp index afb88c3..4daea50 100644 --- a/network/TCPServer.cpp +++ b/source/network/TCPServer.cpp @@ -19,11 +19,11 @@ #include #include -#include "utils/logger.h" +#include #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(); } diff --git a/network/UDPClient.cpp b/source/network/UDPClient.cpp similarity index 98% rename from network/UDPClient.cpp rename to source/network/UDPClient.cpp index 6b0c583..a7ef74f 100644 --- a/network/UDPClient.cpp +++ b/source/network/UDPClient.cpp @@ -18,7 +18,7 @@ #include #include -#include "utils/logger.h" +#include #define MAX_UDP_SIZE 0x578 diff --git a/network/UDPClient.hpp b/source/network/UDPClient.hpp similarity index 94% rename from network/UDPClient.hpp rename to source/network/UDPClient.hpp index d863d36..460096f 100644 --- a/network/UDPClient.hpp +++ b/source/network/UDPClient.hpp @@ -17,11 +17,9 @@ #ifndef _UDPCLIENT_WINDOW_H_ #define _UDPCLIENT_WINDOW_H_ -#include +#include "../ControllerPatcherIncludes.hpp" -#include "../ControllerPatcher.hpp" - -#include "dynamic_libs/socket_functions.h" +#include #define DEFAULT_UDP_CLIENT_PORT 8114 diff --git a/network/UDPServer.cpp b/source/network/UDPServer.cpp similarity index 93% rename from network/UDPServer.cpp rename to source/network/UDPServer.cpp index 8180d21..ee4b07c 100644 --- a/network/UDPServer.cpp +++ b/source/network/UDPServer.cpp @@ -19,13 +19,13 @@ #include #include -#include "dynamic_libs/socket_functions.h" -#include "utils/logger.h" +#include +#include #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(); } diff --git a/network/UDPServer.hpp b/source/network/UDPServer.hpp similarity index 91% rename from network/UDPServer.hpp rename to source/network/UDPServer.hpp index 27d7135..2f15dac 100644 --- a/network/UDPServer.hpp +++ b/source/network/UDPServer.hpp @@ -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_ diff --git a/network/TCPServer.hpp b/source/network/tcpserver.hpp similarity index 91% rename from network/TCPServer.hpp rename to source/network/tcpserver.hpp index dec30ef..38531e6 100644 --- a/network/TCPServer.hpp +++ b/source/network/tcpserver.hpp @@ -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 +#include #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_ diff --git a/patcher/ControllerPatcherHID.cpp b/source/patcher/ControllerPatcherHID.cpp similarity index 99% rename from patcher/ControllerPatcherHID.cpp rename to source/patcher/ControllerPatcherHID.cpp index e1d888d..0dd0802 100644 --- a/patcher/ControllerPatcherHID.cpp +++ b/source/patcher/ControllerPatcherHID.cpp @@ -19,11 +19,11 @@ #include #include #include -#include -#include "dynamic_libs/os_functions.h" -#include "utils/logger.h" +#include + +#include /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * public implementation for the network controller @@ -562,7 +562,7 @@ std::vector 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); diff --git a/patcher/ControllerPatcherHID.hpp b/source/patcher/ControllerPatcherHID.hpp similarity index 96% rename from patcher/ControllerPatcherHID.hpp rename to source/patcher/ControllerPatcherHID.hpp index e5878a1..5555f53 100644 --- a/patcher/ControllerPatcherHID.hpp +++ b/source/patcher/ControllerPatcherHID.hpp @@ -29,10 +29,10 @@ #include -#include "dynamic_libs/syshid_functions.h" -#include "dynamic_libs/vpad_functions.h" +#include +#include -#include "../ControllerPatcher.hpp" +#include "../ControllerPatcherIncludes.hpp" #define SWAP16(x) ((x>>8) | ((x&0xFF)<<8)) #define SWAP8(x) ((x>>4) | ((x&0xF)<<4)) diff --git a/patcher/ControllerPatcherUtils.cpp b/source/patcher/ControllerPatcherUtils.cpp similarity index 99% rename from patcher/ControllerPatcherUtils.cpp rename to source/patcher/ControllerPatcherUtils.cpp index 22a316d..ed9f570 100644 --- a/patcher/ControllerPatcherUtils.cpp +++ b/source/patcher/ControllerPatcherUtils.cpp @@ -18,7 +18,7 @@ #include #include -#include "utils/logger.h" +#include CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){ for(s32 i = 0;i< gHIDMaxDevices;i++){ diff --git a/patcher/ControllerPatcherUtils.hpp b/source/patcher/ControllerPatcherUtils.hpp similarity index 99% rename from patcher/ControllerPatcherUtils.hpp rename to source/patcher/ControllerPatcherUtils.hpp index bb36271..eac3e26 100644 --- a/patcher/ControllerPatcherUtils.hpp +++ b/source/patcher/ControllerPatcherUtils.hpp @@ -27,12 +27,10 @@ #ifndef _CONTROLLER_PATCHER_UTIL_H_ #define _CONTROLLER_PATCHER_UTIL_H_ -#include +#include +#include -#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. diff --git a/utils/CPRetainVars.cpp b/source/utils/CPRetainVars.cpp similarity index 97% rename from utils/CPRetainVars.cpp rename to source/utils/CPRetainVars.cpp index 4917d75..8d34115 100644 --- a/utils/CPRetainVars.cpp +++ b/source/utils/CPRetainVars.cpp @@ -14,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include -#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; diff --git a/utils/CPRetainVars.hpp b/source/utils/CPRetainVars.hpp similarity index 93% rename from utils/CPRetainVars.hpp rename to source/utils/CPRetainVars.hpp index 6de7c33..7f804bc 100644 --- a/utils/CPRetainVars.hpp +++ b/source/utils/CPRetainVars.hpp @@ -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 +#include +#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; diff --git a/utils/PadConst.cpp b/source/utils/PadConst.cpp similarity index 100% rename from utils/PadConst.cpp rename to source/utils/PadConst.cpp diff --git a/utils/PadConst.hpp b/source/utils/PadConst.hpp similarity index 99% rename from utils/PadConst.hpp rename to source/utils/PadConst.hpp index 02426b3..7fd54c1 100644 --- a/utils/PadConst.hpp +++ b/source/utils/PadConst.hpp @@ -18,9 +18,9 @@ #ifndef _PAD_CONST_H_ #define _PAD_CONST_H_ -#include + #include -#include "../patcher/ControllerPatcherDefs.h" +#include "../ControllerPatcherDefs.h" extern const u8 DEF_R_STICK; extern const u8 DEF_L_STICK; diff --git a/utils/CPFSUtils.cpp b/utils/CPFSUtils.cpp deleted file mode 100644 index aed5628..0000000 --- a/utils/CPFSUtils.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "CPFSUtils.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//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 diff --git a/utils/CPFSUtils.hpp b/utils/CPFSUtils.hpp deleted file mode 100644 index c690b60..0000000 --- a/utils/CPFSUtils.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _CPFS_UTILS_H_ -#define _CPFS_UTILS_H_ -#include -#include -#include - -class CPFSUtils{ - public: - static s32 LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size); -}; - -#endif /* _CPFS_UTILS_H_ */ diff --git a/utils/CPStringTools.cpp b/utils/CPStringTools.cpp deleted file mode 100644 index 905cb58..0000000 --- a/utils/CPStringTools.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "CPStringTools.hpp" -#include -#include -#include -#include - -#include -#include - -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 CPStringTools::StringSplit(const std::string & inValue, const std::string & splitter){ - std::string value = inValue; - std::vector 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 diff --git a/utils/CPStringTools.hpp b/utils/CPStringTools.hpp deleted file mode 100644 index 6335672..0000000 --- a/utils/CPStringTools.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _CPSTRING_TOOLS_H_ -#define _CPSTRING_TOOLS_H_ -#include -#include -#include - -class CPStringTools{ - public: - static bool EndsWith(const std::string& a, const std::string& b); - static std::vector 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_ */ diff --git a/utils/ControllerPatcherThread.hpp b/utils/ControllerPatcherThread.hpp deleted file mode 100644 index 5926ddf..0000000 --- a/utils/ControllerPatcherThread.hpp +++ /dev/null @@ -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 . - ****************************************************************************/ -#ifndef CONTROLLERPATCHERTHREAD_H_ -#define CONTROLLERPATCHERTHREAD_H_ - -#include -#include -#include -#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