Changed logging and changed all "int" to "s32"

This commit is contained in:
Maschell 2017-04-10 11:00:55 +02:00
parent 5a3aa0d0aa
commit a6413d4fae
21 changed files with 404 additions and 409 deletions

View File

@ -23,7 +23,7 @@
#include "config/ConfigValues.hpp" #include "config/ConfigValues.hpp"
#include "utils/CPStringTools.hpp" #include "utils/CPStringTools.hpp"
int ConfigReader::numberValidFiles = 0; s32 ConfigReader::numberValidFiles = 0;
ConfigReader *ConfigReader::instance = NULL; ConfigReader *ConfigReader::instance = NULL;
ConfigReader::ConfigReader(){ ConfigReader::ConfigReader(){
@ -34,14 +34,14 @@ ConfigReader::ConfigReader(){
void ConfigReader::ReadAllConfigs(){ void ConfigReader::ReadAllConfigs(){
std::vector<std::string> fileList = ScanFolder(); std::vector<std::string> fileList = ScanFolder();
if(fileList.size() > 0){ if(fileList.size() > 0){
if(HID_DEBUG) log_printf("ConfigReader::ConfigReader(): Found %d config files\n",fileList.size()); if(HID_DEBUG) log_printf("ConfigReader::ConfigReader(line %d): Found %d config files\n",__LINE__,fileList.size());
processFileList(fileList); processFileList(fileList);
} }
} }
ConfigReader::~ConfigReader(){ ConfigReader::~ConfigReader(){
if(HID_DEBUG) log_printf("~ConfigReader\n"); if(HID_DEBUG) log_printf("ConfigReader::~ConfigReader(line %d): ~ConfigReader\n",__LINE__);
freeFSHandles(); freeFSHandles();
} }
@ -58,8 +58,8 @@ void ConfigReader::freeFSHandles(){
} }
// Mounting the sdcard without any external lib to be portable // Mounting the sdcard without any external lib to be portable
int ConfigReader::InitSDCard(){ s32 ConfigReader::InitSDCard(){
if(HID_DEBUG) log_printf("InitSDCard\n"); if(HID_DEBUG) log_printf("ConfigReader::InitSDCard(line %d): InitSDCard\n",__LINE__);
char mountSrc[FS_MOUNT_SOURCE_SIZE]; char mountSrc[FS_MOUNT_SOURCE_SIZE];
char mountPath[FS_MAX_MOUNTPATH_SIZE]; char mountPath[FS_MAX_MOUNTPATH_SIZE];
@ -69,7 +69,7 @@ int ConfigReader::InitSDCard(){
this->pClient = malloc(FS_CLIENT_SIZE); this->pClient = malloc(FS_CLIENT_SIZE);
this->pCmd = malloc(FS_CMD_BLOCK_SIZE); this->pCmd = malloc(FS_CMD_BLOCK_SIZE);
int status = 0; s32 status = 0;
if (this->pClient && this->pCmd) if (this->pClient && this->pCmd)
{ {
@ -88,11 +88,11 @@ int ConfigReader::InitSDCard(){
{ {
return 0; return 0;
}else{ }else{
log_printf("ConfigReader::InitSDCard() error: FSMount failed %d\n",status); log_printf("ConfigReader::InitSDCard(line %d): error: FSMount failed %d\n",__LINE__,status);
return status; return status;
} }
}else{ }else{
log_printf("ConfigReader::InitSDCard() error: FSGetMountSource failed %d\n",status); log_printf("ConfigReader::InitSDCard(line %d): error: FSGetMountSource failed %d\n",__LINE__,status);
return status; return status;
} }
} }
@ -101,11 +101,11 @@ int ConfigReader::InitSDCard(){
std::vector<std::string> ConfigReader::ScanFolder(){ std::vector<std::string> ConfigReader::ScanFolder(){
std::string path = CONTROLLER_PATCHER_PATH; std::string path = CONTROLLER_PATCHER_PATH;
int dirhandle = 0; s32 dirhandle = 0;
if(HID_DEBUG) log_printf("ConfigReader::ScanFolder(): Opening %s\n",path.c_str()); if(HID_DEBUG) log_printf("ConfigReader::ScanFolder(line %d): Opening %s\n",__LINE__,path.c_str());
std::vector<std::string> config_files; std::vector<std::string> config_files;
if (this->pClient && this->pCmd){ if (this->pClient && this->pCmd){
int status = 0; s32 status = 0;
if((status = FSOpenDir(this->pClient,this->pCmd,path.c_str(),&dirhandle,-1)) == FS_STATUS_OK){ if((status = FSOpenDir(this->pClient,this->pCmd,path.c_str(),&dirhandle,-1)) == FS_STATUS_OK){
FSDirEntry dir_entry; FSDirEntry dir_entry;
while (FSReadDir(this->pClient, this->pCmd, dirhandle, &dir_entry, FS_RET_ALL_ERROR) == FS_STATUS_OK){ while (FSReadDir(this->pClient, this->pCmd, dirhandle, &dir_entry, FS_RET_ALL_ERROR) == FS_STATUS_OK){
@ -113,13 +113,13 @@ std::vector<std::string> ConfigReader::ScanFolder(){
if((dir_entry.stat.flag&FS_STAT_FLAG_IS_DIRECTORY) != FS_STAT_FLAG_IS_DIRECTORY){ if((dir_entry.stat.flag&FS_STAT_FLAG_IS_DIRECTORY) != FS_STAT_FLAG_IS_DIRECTORY){
if(CPStringTools::EndsWith(std::string(dir_entry.name),".ini")){ if(CPStringTools::EndsWith(std::string(dir_entry.name),".ini")){
config_files.push_back(full_path); config_files.push_back(full_path);
if(HID_DEBUG) log_printf("%s \n",full_path.c_str()); if(HID_DEBUG) log_printf("ConfigReader::ScanFolder(line %d): %s \n",__LINE__,full_path.c_str());
} }
} }
} }
FSCloseDir(this->pClient,this->pCmd,dirhandle,-1); FSCloseDir(this->pClient,this->pCmd,dirhandle,-1);
}else{ }else{
log_printf("ConfigReader::ScanFolder(): Failed to open %s!\n",path.c_str()); log_printf("ConfigReader::ScanFolder(line %d): Failed to open %s!\n",__LINE__,path.c_str());
} }
} }
return config_files; return config_files;
@ -127,7 +127,7 @@ std::vector<std::string> ConfigReader::ScanFolder(){
void ConfigReader::processFileList(std::vector<std::string> path){ void ConfigReader::processFileList(std::vector<std::string> path){
for(std::vector<std::string>::iterator it = path.begin(); it != path.end(); ++it) { for(std::vector<std::string>::iterator it = path.begin(); it != path.end(); ++it) {
log_printf("Reading %s\n",it->c_str()); log_printf("ConfigReader::processFileList(line %d): Reading %s\n",__LINE__,it->c_str());
std::string result = loadFileToString(*it); std::string result = loadFileToString(*it);
ConfigParser parser(result); ConfigParser parser(result);
@ -136,26 +136,26 @@ void ConfigReader::processFileList(std::vector<std::string> path){
} }
std::string ConfigReader::loadFileToString(std::string path){ std::string ConfigReader::loadFileToString(std::string path){
int handle = 0; s32 handle = 0;
int status = 0; s32 status = 0;
std::string strBuffer; std::string strBuffer;
FSStat stats; FSStat stats;
if((status = FSGetStat(this->pClient,this->pCmd,path.c_str(),&stats,-1)) == FS_STATUS_OK){ if((status = FSGetStat(this->pClient,this->pCmd,path.c_str(),&stats,-1)) == FS_STATUS_OK){
char * file = (char *) malloc((sizeof(char)*stats.size)+1); char * file = (char *) malloc((sizeof(char)*stats.size)+1);
if(!file){ if(!file){
log_print("ConfigReader::loadFileToString error: Failed to allocate space for reading the file\n"); log_printf("ConfigReader::loadFileToString(line %d): error: Failed to allocate space for reading the file\n",__LINE__);
return ""; return "";
} }
file[stats.size] = '\0'; file[stats.size] = '\0';
if((status = FSOpenFile(this->pClient,this->pCmd,path.c_str(),"r",&handle,-1)) == FS_STATUS_OK){ if((status = FSOpenFile(this->pClient,this->pCmd,path.c_str(),"r",&handle,-1)) == FS_STATUS_OK){
int total_read = 0; s32 total_read = 0;
int ret2 = 0; s32 ret2 = 0;
while ((ret2 = FSReadFile(pClient, pCmd, file+total_read, 1, stats.size-total_read, handle, 0, FS_RET_ALL_ERROR)) > 0){ while ((ret2 = FSReadFile(pClient, pCmd, file+total_read, 1, stats.size-total_read, handle, 0, FS_RET_ALL_ERROR)) > 0){
total_read += ret2; total_read += ret2;
} }
}else{ }else{
log_printf("ConfigReader::loadFileToString error: (FSOpenFile) Couldn't open file (%s), error: %d",path.c_str(),status); log_printf("ConfigReader::loadFileToString(line %d): error: (FSOpenFile) Couldn't open file (%s), error: %d",__LINE__,path.c_str(),status);
free(file); free(file);
file=NULL; file=NULL;
return ""; return "";
@ -173,7 +173,7 @@ std::string ConfigReader::loadFileToString(std::string path){
strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t'); strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t');
}else{ }else{
log_printf("ConfigReader::loadFileToString error: (GetStat) Couldn't open file (%s), error: %d",path.c_str(),status); log_printf("ConfigReader::loadFileToString(line %d): error: (GetStat) Couldn't open file (%s), error: %d",__LINE__,path.c_str(),status);
} }
return strBuffer; return strBuffer;

View File

@ -51,7 +51,7 @@ class ConfigReader{
} }
} }
static int getNumberOfLoadedFiles(){ static s32 getNumberOfLoadedFiles(){
return ConfigReader::numberValidFiles; return ConfigReader::numberValidFiles;
} }
@ -59,14 +59,14 @@ class ConfigReader{
ConfigReader::numberValidFiles++; ConfigReader::numberValidFiles++;
} }
void ReadAllConfigs(); void ReadAllConfigs();
static int numberValidFiles; static s32 numberValidFiles;
//!Constructor //!Constructor
ConfigReader(); ConfigReader();
//!Destructor //!Destructor
~ConfigReader(); ~ConfigReader();
int InitSDCard(); s32 InitSDCard();
void freeFSHandles(); void freeFSHandles();
void * pClient = NULL; void * pClient = NULL;

View File

@ -33,9 +33,9 @@ static u32 last_button_hold[4] = {0,0,0,0};
static VPADData myVPADBuffer[4]; static VPADData myVPADBuffer[4];
void ControllerPatcher::InitButtonMapping(){ void ControllerPatcher::InitButtonMapping(){
if(HID_DEBUG) log_printf("init_button_remapping! called! \n"); if(HID_DEBUG) log_printf("ControllerPatcher::InitButtonMapping(line %d): Init called \n",__LINE__);
if(!gButtonRemappingConfigDone){ if(!gButtonRemappingConfigDone){
if(HID_DEBUG) log_printf("init_button_remapping! Remapping is running! \n"); if(HID_DEBUG) log_printf("ControllerPatcher::InitButtonMapping(line %d): Remapping is running! \n",__LINE__);
gButtonRemappingConfigDone = 1; gButtonRemappingConfigDone = 1;
memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything
@ -71,7 +71,7 @@ void ControllerPatcher::InitButtonMapping(){
} }
void ControllerPatcher::ResetConfig(){ void ControllerPatcher::ResetConfig(){
memset(&gControllerMapping,0,sizeof(ControllerMapping)); memset(&gControllerMapping,0,sizeof(gControllerMapping));
disableControllerMapping(); disableControllerMapping();
memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // Init / Invalid everything memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // Init / Invalid everything
memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); // Init / Invalid everything memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); // Init / Invalid everything
@ -93,12 +93,12 @@ void ControllerPatcher::ResetConfig(){
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
gGamePadSlot = slotdata.deviceslot; gGamePadSlot = slotdata.deviceslot;
u32 gGamePadHid = slotdata.hidmask; u32 gGamePadHid = slotdata.hidmask;
if(HID_DEBUG) log_printf("Gamepad HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(gGamePadHid),gGamePadSlot); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gGamePadHid),gGamePadSlot);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
gMouseSlot = slotdata.deviceslot; gMouseSlot = slotdata.deviceslot;
gHID_LIST_MOUSE = slotdata.hidmask; gHID_LIST_MOUSE = slotdata.hidmask;
if(HID_DEBUG) log_printf("Mouse HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
u32 keyboard_slot = slotdata.deviceslot; u32 keyboard_slot = slotdata.deviceslot;
@ -106,30 +106,30 @@ void ControllerPatcher::ResetConfig(){
gHID_LIST_KEYBOARD = keyboard_hid; gHID_LIST_KEYBOARD = keyboard_hid;
gHID_SLOT_KEYBOARD = keyboard_slot; gHID_SLOT_KEYBOARD = keyboard_slot;
if(HID_DEBUG) log_printf("Keyboard HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
u32 gc_slot = slotdata.deviceslot; u32 gc_slot = slotdata.deviceslot;
u32 gc_hid = slotdata.hidmask; u32 gc_hid = slotdata.hidmask;
gHID_LIST_GC = gc_hid; gHID_LIST_GC = gc_hid;
gHID_SLOT_GC = gc_slot; gHID_SLOT_GC = gc_slot;
if(HID_DEBUG) log_printf("GC-Adapter HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
u32 ds3_slot = slotdata.deviceslot; u32 ds3_slot = slotdata.deviceslot;
u32 ds3_hid = slotdata.hidmask; u32 ds3_hid = slotdata.hidmask;
gHID_LIST_DS3 = ds3_hid; gHID_LIST_DS3 = ds3_hid;
if(HID_DEBUG) log_printf("DS3 HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register DS3-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
u32 ds4_slot = slotdata.deviceslot; u32 ds4_slot = slotdata.deviceslot;
u32 ds4_hid = slotdata.hidmask; u32 ds4_hid = slotdata.hidmask;
if(HID_DEBUG) log_printf("DS4 HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(ds4_hid),ds4_slot); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register DS4-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(ds4_hid),ds4_slot);
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
u32 xinput_slot = slotdata.deviceslot; u32 xinput_slot = slotdata.deviceslot;
u32 xinput_hid = slotdata.hidmask; u32 xinput_hid = slotdata.hidmask;
if(HID_DEBUG) log_printf("XInput HID-Mask %s deviceslot: %d\n",CPStringTools::byte_to_binary(xinput_hid),xinput_slot); if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register XInput-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(xinput_hid),xinput_slot);
config_controller_hidmask[gc_slot] = gHID_LIST_GC; config_controller_hidmask[gc_slot] = gHID_LIST_GC;
config_controller_hidmask[ds3_slot] = gHID_LIST_DS3; config_controller_hidmask[ds3_slot] = gHID_LIST_DS3;
@ -408,37 +408,37 @@ bool ControllerPatcher::Init(){
InitVPadFunctionPointers(); InitVPadFunctionPointers();
InitPadScoreFunctionPointers(); InitPadScoreFunctionPointers();
if(HID_DEBUG) log_printf("ControllerPatcher::Init() called! \n"); if(HID_DEBUG) log_printf("ControllerPatcher::Init(line %d): Init called! \n",__LINE__);
if(syshid_handle == 0){ if(syshid_handle == 0){
log_printf("Failed to load the HID API \n"); log_printf("ControllerPatcher::Init(line %d): Failed to load the HID API \n",__LINE__);
return false; return false;
} }
if(gConfig_done == HID_INIT_NOT_DONE){ if(gConfig_done == HID_INIT_NOT_DONE){
if(HID_DEBUG) log_printf("First time calling the Init\n"); if(HID_DEBUG) log_printf("ControllerPatcher::Init(line %d): First time calling the Init\n",__LINE__);
gConfig_done = HID_INIT_DONE; gConfig_done = HID_INIT_DONE;
ControllerPatcher::ResetConfig(); ControllerPatcher::ResetConfig();
}else{ }else{
if(HID_DEBUG) log_print("Config already done!\n"); if(HID_DEBUG) log_printf("ControllerPatcher::Init(line %d): ControllerPatcher::Init(): Config already done!\n",__LINE__);
} }
if(gConfig_done != HID_SDCARD_READ){ if(gConfig_done != HID_SDCARD_READ){
log_print("Reading config files from SD Card\n"); log_printf("ControllerPatcher::Init(line %d): Reading config files from SD Card\n",__LINE__);
ConfigReader* reader = ConfigReader::getInstance(); ConfigReader* reader = ConfigReader::getInstance();
int status = 0; s32 status = 0;
if((status = reader->InitSDCard()) == 0){ if((status = reader->InitSDCard()) == 0){
if(HID_DEBUG) log_printf("ConfigReader::ConfigReader(): SD Card mounted for controller config!\n"); if(HID_DEBUG) log_printf("ControllerPatcher::Init(line %d): SD Card mounted for controller config!\n",__LINE__);
reader->ReadAllConfigs(); reader->ReadAllConfigs();
log_print("Done with reading config files from SD Card\n"); log_printf("ControllerPatcher::Init(line %d): Done with reading config files from SD Card\n",__LINE__);
gConfig_done = HID_SDCARD_READ; gConfig_done = HID_SDCARD_READ;
}else{ }else{
log_printf("ConfigReader::ConfigReader() error: SD mounting failed! %d\n",status); log_printf("ControllerPatcher::Init(line %d): SD mounting failed! %d\n",__LINE__,status);
} }
ConfigReader::destroyInstance(); ConfigReader::destroyInstance();
} }
log_print("Initializing the data for button remapping\n"); log_printf("ControllerPatcher::Init(line %d): Initializing the data for button remapping\n",__LINE__);
InitButtonMapping(); InitButtonMapping();
if(!gHIDAttached){ if(!gHIDAttached){
@ -460,22 +460,21 @@ void ControllerPatcher::stopNetworkServer(){
void ControllerPatcher::DeInit(){ void ControllerPatcher::DeInit(){
if(HID_DEBUG) log_printf("ControllerPatcher::DeInit() called! \n"); if(HID_DEBUG) log_printf("ControllerPatcher::DeInit(line %d) called! \n",__LINE__);
if(gHIDAttached) HIDDelClient(&gHIDClient); if(gHIDAttached) HIDDelClient(&gHIDClient);
//Resetting the state of the last pressed data. //Resetting the state of the last pressed data.
buttonRemapping_lastButtonsHold = 0; buttonRemapping_lastButtonsHold = 0;
memset(last_button_hold,0,sizeof(u32)*4); memset(last_button_hold,0,sizeof(last_button_hold));
memset(myVPADBuffer,0,sizeof(VPADData)*4); memset(myVPADBuffer,0,sizeof(myVPADBuffer));
memset(&gControllerMapping,0,sizeof(gControllerMapping));
memset(&gControllerMapping,0,sizeof(ControllerMapping)); memset(&gHIDClient,0,sizeof(gHIDClient));
memset(&gHIDClient,0,sizeof(HIDClient)); memset(gHID_Devices,0,sizeof(gHID_Devices));
memset(gHID_Devices,0,sizeof(HID_DEVICE_DATA) * gHIDMaxDevices); memset(gGamePadValues,0,sizeof(gGamePadValues));
memset(gGamePadValues,0,sizeof(u32) * CONTRPS_MAX_VALUE); memset(config_controller,0,sizeof(config_controller));
memset(config_controller,0,sizeof(u8) * gHIDMaxDevices * CONTRPS_MAX_VALUE * 2); memset(config_controller_hidmask,0,sizeof(config_controller_hidmask));
memset(config_controller_hidmask,0,sizeof(u16) * gHIDMaxDevices); memset(gNetworkController,0,sizeof(gNetworkController));
memset(gNetworkController,0,sizeof(u16) * gHIDMaxDevices * HID_MAX_PADS_COUNT * 4);
gConfig_done = HID_INIT_NOT_DONE; gConfig_done = HID_INIT_NOT_DONE;
gButtonRemappingConfigDone = 0; gButtonRemappingConfigDone = 0;
@ -512,24 +511,24 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableControllerMapping()
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting(){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting(){
int res; s32 res;
if(IMIsDimEnabled(&res) == 0){ if(IMIsDimEnabled(&res) == 0){
if(res == 1){ if(res == 1){
log_print("Dim was orignally enabled!\n"); if(HID_DEBUG) log_print("ControllerPatcher::disableWiiUEnergySetting(): Dim was orignally enabled!\n");
gOriginalDimState = 1; gOriginalDimState = 1;
} }
} }
if(IMIsAPDEnabled(&res) == 0){ if(IMIsAPDEnabled(&res) == 0){
if(res == 1){ if(res == 1){
log_print("Auto power down was orignally enabled!\n"); if(HID_DEBUG) log_print("ControllerPatcher::disableWiiUEnergySetting(): Auto power down was orignally enabled!\n");
gOriginalAPDState = 1; gOriginalAPDState = 1;
} }
} }
IMDisableDim(); IMDisableDim();
IMDisableAPD(); IMDisableAPD();
log_print("Disable Energy savers\n"); log_print("ControllerPatcher::disableWiiUEnergySetting(): Disable Energy savers\n");
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
@ -537,11 +536,11 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::restoreWiiUEnergySetting()
//Check if we need to enable Auto Power down again on exiting //Check if we need to enable Auto Power down again on exiting
if(gOriginalAPDState == 1){ if(gOriginalAPDState == 1){
log_print("Auto shutdown was on before using HID to VPAD. Setting it to on again.\n"); log_print("ControllerPatcher::restoreWiiUEnergySetting(): Auto shutdown was on before using HID to VPAD. Setting it to on again.\n");
IMEnableAPD(); IMEnableAPD();
} }
if(gOriginalDimState == 1){ if(gOriginalDimState == 1){
log_print("Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n"); log_print("ControllerPatcher::restoreWiiUEnergySetting(): Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n");
IMEnableDim(); IMEnableDim();
} }
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
@ -551,8 +550,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UCo
ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type);
if(cm_map_pad == NULL){return CONTROLLER_PATCHER_ERROR_NULL_POINTER;} if(cm_map_pad == NULL){return CONTROLLER_PATCHER_ERROR_NULL_POINTER;}
memset(cm_map_pad,0,sizeof(*cm_map_pad));
memset(cm_map_pad,0,sizeof(ControllerMappingPAD));
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
@ -560,9 +558,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UCo
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UController_Type type,ControllerMappingPADInfo config){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UController_Type type,ControllerMappingPADInfo config){
ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type);
int result = 0; s32 result = 0;
for(int i=0;i<HID_MAX_DEVICES_PER_SLOT;i++){ for(s32 i=0;i<HID_MAX_DEVICES_PER_SLOT;i++){
ControllerMappingPADInfo * info = &(cm_map_pad->pad_infos[i]); ControllerMappingPADInfo * info = &(cm_map_pad->pad_infos[i]);
if(info != NULL && !info->active){ if(info != NULL && !info->active){
info->active = 1; info->active = 1;
@ -584,13 +582,13 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UCont
} }
int ControllerPatcher::getActiveMappingSlot(UController_Type type){ s32 ControllerPatcher::getActiveMappingSlot(UController_Type type){
ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type);
if(cm_map_pad == NULL){return -1;} if(cm_map_pad == NULL){return -1;}
int connected = -1; s32 connected = -1;
for(int i =0;i<HID_MAX_DEVICES_PER_SLOT;i++){ for(s32 i =0;i<HID_MAX_DEVICES_PER_SLOT;i++){
if(cm_map_pad->pad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController){ if(cm_map_pad->pad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController){
connected = i; connected = i;
break; break;
@ -600,7 +598,7 @@ int ControllerPatcher::getActiveMappingSlot(UController_Type type){
return connected; return connected;
} }
bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,int mapping_slot){ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 mapping_slot){
ControllerMappingPADInfo * padinfo = getControllerMappingInfo(type,mapping_slot); ControllerMappingPADInfo * padinfo = getControllerMappingInfo(type,mapping_slot);
if(!padinfo){ if(!padinfo){
return false; return false;
@ -608,18 +606,18 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,int
if(padinfo->active){ if(padinfo->active){
DeviceInfo device_info; DeviceInfo device_info;
memset(&device_info,0,sizeof(DeviceInfo)); memset(&device_info,0,sizeof(device_info));
device_info.vidpid.vid = padinfo->vidpid.vid; device_info.vidpid.vid = padinfo->vidpid.vid;
device_info.vidpid.pid = padinfo->vidpid.pid; device_info.vidpid.pid = padinfo->vidpid.pid;
int res; s32 res;
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
return false; return false;
} }
int hidmask = device_info.slotdata.hidmask; s32 hidmask = device_info.slotdata.hidmask;
int pad = padinfo->pad; s32 pad = padinfo->pad;
HID_Data * data_cur; HID_Data * data_cur;
@ -632,7 +630,7 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,int
return false; return false;
} }
ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UController_Type type,int mapping_slot){ ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UController_Type type,s32 mapping_slot){
ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type);
if(cm_map_pad == NULL){return NULL;} if(cm_map_pad == NULL){return NULL;}
@ -651,7 +649,7 @@ HID_Mouse_Data * ControllerPatcher::getMouseData(){
HID_Mouse_Data * result = NULL; HID_Mouse_Data * result = NULL;
for(int i;i<HID_MAX_DEVICES_PER_SLOT;i++){ for(s32 i;i<HID_MAX_DEVICES_PER_SLOT;i++){
ControllerMappingPADInfo * padinfo = &(CMPAD->pad_infos[i]); ControllerMappingPADInfo * padinfo = &(CMPAD->pad_infos[i]);
if(!padinfo->active){ if(!padinfo->active){
break; break;
@ -670,18 +668,18 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,int array_size){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){
int hid = gHIDCurrentDevice; s32 hid = gHIDCurrentDevice;
HID_Data * data_cur; HID_Data * data_cur;
VPADData pad_buffer; VPADData pad_buffer;
VPADData * buffer = &pad_buffer; VPADData * buffer = &pad_buffer;
int result = CONTROLLER_PATCHER_ERROR_NONE; s32 result = CONTROLLER_PATCHER_ERROR_NONE;
for(int i = 0;i< gHIDMaxDevices;i++){ for(s32 i = 0;i< gHIDMaxDevices;i++){
if((hid & (1 << i)) != 0){ if((hid & (1 << i)) != 0){
memset(buffer,0,sizeof(VPADData)); memset(buffer,0,sizeof(*buffer));
int newhid = (1 << i); s32 newhid = (1 << i);
int deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid); s32 deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid);
if(deviceslot < 0) continue; if(deviceslot < 0) continue;
DeviceInfo * deviceinfo = &(output[result].device_info); DeviceInfo * deviceinfo = &(output[result].device_info);
InputButtonData * buttondata = output[result].button_data; InputButtonData * buttondata = output[result].button_data;
@ -698,14 +696,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp
deviceinfo->pad_count = HID_MAX_PADS_COUNT; deviceinfo->pad_count = HID_MAX_PADS_COUNT;
} }
int buttons_hold = 0; s32 buttons_hold = 0;
for(int pad = 0;pad<HID_MAX_PADS_COUNT;pad++){ for(s32 pad = 0;pad<HID_MAX_PADS_COUNT;pad++){
buttons_hold = 0; buttons_hold = 0;
buttondata[pad].btn_h = 0; buttondata[pad].btn_h = 0;
buttondata[pad].btn_d = 0; buttondata[pad].btn_d = 0;
buttondata[pad].btn_r = 0; buttondata[pad].btn_r = 0;
int res; s32 res;
if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0){ if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0){
continue; continue;
@ -750,34 +748,34 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp
return result; return result;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHID(void * data,int chan, int mode){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHID(void * data,s32 chan, s32 mode){
if(chan < 0 || chan > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; if(chan < 0 || chan > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN;
//if(gControllerMapping.proController[chan].enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED; //if(gControllerMapping.proController[chan].enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED;
VPADData * vpad_buffer = &myVPADBuffer[chan]; VPADData * vpad_buffer = &myVPADBuffer[chan];
memset(vpad_buffer,0,sizeof(VPADData)); memset(vpad_buffer,0,sizeof(*vpad_buffer));
std::vector<HID_Data *> data_list; std::vector<HID_Data *> data_list;
for(int i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){ for(s32 i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){
ControllerMappingPADInfo cm_map_pad_info = gControllerMapping.proController[chan].pad_infos[i]; ControllerMappingPADInfo cm_map_pad_info = gControllerMapping.proController[chan].pad_infos[i];
if(!cm_map_pad_info.active){ if(!cm_map_pad_info.active){
continue; continue;
} }
DeviceInfo device_info; DeviceInfo device_info;
memset(&device_info,0,sizeof(DeviceInfo)); memset(&device_info,0,sizeof(device_info));
device_info.vidpid.vid = cm_map_pad_info.vidpid.vid; device_info.vidpid.vid = cm_map_pad_info.vidpid.vid;
device_info.vidpid.pid = cm_map_pad_info.vidpid.pid; device_info.vidpid.pid = cm_map_pad_info.vidpid.pid;
int res; s32 res;
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
log_printf("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res); log_printf("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res);
continue; continue;
} }
int hidmask = device_info.slotdata.hidmask; s32 hidmask = device_info.slotdata.hidmask;
int pad = cm_map_pad_info.pad; s32 pad = cm_map_pad_info.pad;
HID_Data * data_cur; HID_Data * data_cur;
@ -791,7 +789,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
if(data_list.empty()){ if(data_list.empty()){
return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA; return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA;
} }
int res = 0; s32 res = 0;
if((res = ControllerPatcherHID::setVPADControllerData(vpad_buffer,data_list)) < 0) return res; if((res = ControllerPatcherHID::setVPADControllerData(vpad_buffer,data_list)) < 0) return res;
//make it configurable? //make it configurable?
//ControllerPatcher::printVPADButtons(vpad_buffer); //Leads to random crashes on transitions. //ControllerPatcher::printVPADButtons(vpad_buffer); //Leads to random crashes on transitions.
@ -815,8 +813,8 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(VPADData * buffer){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(VPADData * buffer){
//if(gControllerMapping.gamepad.enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED; //if(gControllerMapping.gamepad.enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED;
int hidmask = 0; s32 hidmask = 0;
int pad = 0; s32 pad = 0;
ControllerMappingPAD cm_map_pad = gControllerMapping.gamepad; ControllerMappingPAD cm_map_pad = gControllerMapping.gamepad;
std::vector<HID_Data *> data_list; std::vector<HID_Data *> data_list;
@ -824,7 +822,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
if (cm_map_pad.useAll == 1) { if (cm_map_pad.useAll == 1) {
data_list = ControllerPatcherHID::getHIDDataAll(); data_list = ControllerPatcherHID::getHIDDataAll();
}else{ }else{
for(int i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){ for(s32 i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){
ControllerMappingPADInfo cm_map_pad_info = cm_map_pad.pad_infos[i]; ControllerMappingPADInfo cm_map_pad_info = cm_map_pad.pad_infos[i];
if(cm_map_pad_info.active == 1){ if(cm_map_pad_info.active == 1){
DeviceInfo device_info; DeviceInfo device_info;
@ -841,7 +839,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
HID_Data * data; HID_Data * data;
pad = cm_map_pad_info.pad; pad = cm_map_pad_info.pad;
int res = ControllerPatcherHID::getHIDData(hidmask,pad,&data); s32 res = ControllerPatcherHID::getHIDData(hidmask,pad,&data);
if(res < 0){ if(res < 0){
continue; continue;
//return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA; //return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA;
@ -904,10 +902,10 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADData
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADData * buffer,int buffer_count){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADData * buffer,s32 buffer_count){
if(!gButtonRemappingConfigDone) return CONTROLLER_PATCHER_ERROR_CONFIG_NOT_DONE; if(!gButtonRemappingConfigDone) return CONTROLLER_PATCHER_ERROR_CONFIG_NOT_DONE;
if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
for(int i = 0;i < buffer_count;i++){ for(s32 i = 0;i < buffer_count;i++){
VPADData new_data; VPADData new_data;
memset(&new_data,0,sizeof(new_data)); memset(&new_data,0,sizeof(new_data));

View File

@ -39,6 +39,7 @@
#include "network/TCPServer.hpp" #include "network/TCPServer.hpp"
#include "network/UDPServer.hpp" #include "network/UDPServer.hpp"
#include "dynamic_libs/sys_functions.h"
#include "dynamic_libs/syshid_functions.h" #include "dynamic_libs/syshid_functions.h"
#include "dynamic_libs/socket_functions.h" #include "dynamic_libs/socket_functions.h"
#include "dynamic_libs/padscore_functions.h" #include "dynamic_libs/padscore_functions.h"
@ -100,7 +101,7 @@ class ControllerPatcher{
@return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,int chan,int mode = PRO_CONTROLLER_MODE_KPADDATA); static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,s32 chan,s32 mode = PRO_CONTROLLER_MODE_KPADDATA);
/** /**
@ -167,14 +168,14 @@ class ControllerPatcher{
@return The first active mapping slot for the given controller type will be returned. If the controller type is not set active, -1 will be returned. @return The first active mapping slot for the given controller type will be returned. If the controller type is not set active, -1 will be returned.
**/ **/
static int getActiveMappingSlot(UController_Type type); static s32 getActiveMappingSlot(UController_Type type);
/** /**
@param type: The type of the controller. @param type: The type of the controller.
@param mapping_slot: information about the added controller. @param mapping_slot: information about the added controller.
@return When the functions failed result < 0 is returned. Otherwise a pointer to a ControllerMappingPADInfo is returned. @return When the functions failed result < 0 is returned. Otherwise a pointer to a ControllerMappingPADInfo is returned.
**/ **/
static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,int mapping_slot); static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,s32 mapping_slot);
/** /**
Checks if a emulated controller is connected for the given controller type / mapping slot. Checks if a emulated controller is connected for the given controller type / mapping slot.
@ -184,7 +185,7 @@ class ControllerPatcher{
@return @return
**/ **/
static bool isControllerConnectedAndActive(UController_Type type,int mapping_slot = 0); static bool isControllerConnectedAndActive(UController_Type type,s32 mapping_slot = 0);
/** /**
Search for a connected mouse and returns a pointer to it's data. Search for a connected mouse and returns a pointer to it's data.
@ -210,7 +211,7 @@ class ControllerPatcher{
@return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. If the result is > 0 the number of stored sets in the array is returned. @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. If the result is > 0 the number of stored sets in the array is returned.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,int array_size); static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size);
/** /**
Remaps the buttons in the given \p VPADData pointer. InitButtonMapping() needs to be called before calling this. The information about the remapping is stored in the config_controller array. Remaps the buttons in the given \p VPADData pointer. InitButtonMapping() needs to be called before calling this. The information about the remapping is stored in the config_controller array.
@ -220,7 +221,7 @@ class ControllerPatcher{
@return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADData * buffer, int buffer_count); static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADData * buffer, s32 buffer_count);
/** /**
Prints the current pressed down buttons of the given \p VPADData pointer. Uses the utils/logger.c UDP logger.. Prints the current pressed down buttons of the given \p VPADData pointer. Uses the utils/logger.c UDP logger..

View File

@ -74,37 +74,37 @@ void ConfigParser::setSlot(u16 newSlot){
bool ConfigParser::Init(){ bool ConfigParser::Init(){
if(contentLines.size() == 0){ if(contentLines.size() == 0){
log_printf("ConfigParser::Init(): Files seems to be empty. Make sure to have a proper header\n"); log_printf("ConfigParser::Init(line %d): Files seems to be empty. Make sure to have a proper header\n",__LINE__);
return false; return false;
} }
const char * line = contentLines[0].c_str(); const char * line = contentLines[0].c_str();
int len = strlen(line); s32 len = strlen(line);
std::string identify; std::string identify;
if(line[0] == '[' && line[len-1] == ']'){ if(line[0] == '[' && line[len-1] == ']'){
identify = contentLines[0].substr(1,len-2); identify = contentLines[0].substr(1,len-2);
}else{ }else{
log_printf("ConfigParser::Init(): Not a proper config file!\n"); log_printf("ConfigParser::Init((line %d): Not a proper config file!\n",__LINE__);
return false; return false;
} }
if(identify.compare("GAMEPAD") == 0){ if(identify.compare("GAMEPAD") == 0){
if(HID_DEBUG) log_printf("Its a gamepad config file!\n"); log_printf("ConfigParser::Init((line %d): Its a gamepad config file!\n",__LINE__);
setSlot(gGamePadSlot); setSlot(gGamePadSlot);
setType(PARSE_GAMEPAD); setType(PARSE_GAMEPAD);
}else if(identify.compare("MOUSE") == 0){ }else if(identify.compare("MOUSE") == 0){
if(HID_DEBUG) log_printf("Its a mouse config file!\n"); log_printf("ConfigParser::Init((line %d): Its a mouse config file!\n",__LINE__);
setSlot(gMouseSlot); setSlot(gMouseSlot);
setType(PARSE_MOUSE); setType(PARSE_MOUSE);
this->vid = HID_MOUSE_VID; this->vid = HID_MOUSE_VID;
this->pid = HID_MOUSE_PID; this->pid = HID_MOUSE_PID;
}else if(identify.compare("KEYBOARD") == 0){ }else if(identify.compare("KEYBOARD") == 0){
if(HID_DEBUG) log_printf("Its a keyboard config file!\n"); log_printf("ConfigParser::Init((line %d): Its a keyboard config file!\n",__LINE__);
setSlot(gHID_SLOT_KEYBOARD); setSlot(gHID_SLOT_KEYBOARD);
setType(PARSE_KEYBOARD); setType(PARSE_KEYBOARD);
this->vid = HID_KEYBOARD_VID; this->vid = HID_KEYBOARD_VID;
this->pid = HID_KEYBOARD_PID; this->pid = HID_KEYBOARD_PID;
}else{ }else{
if(HID_DEBUG) log_printf("Its a controller config file!\n"); log_printf("ConfigParser::Init((line %d): Its a controller config file!\n",__LINE__);
setSlot(getSlotController(identify)); setSlot(getSlotController(identify));
setType(PARSE_CONTROLLER); setType(PARSE_CONTROLLER);
@ -122,16 +122,16 @@ bool ConfigParser::Init(){
void ConfigParser::parseSingleLine(std::string line){ void ConfigParser::parseSingleLine(std::string line){
std::vector<std::string> cur_values = CPStringTools::StringSplit(line,"="); std::vector<std::string> cur_values = CPStringTools::StringSplit(line,"=");
if(cur_values.size() != 2){ if(cur_values.size() != 2){
if(HID_DEBUG || cur_values.size() > 2) log_printf("Not a valid key=pair line %s\n",line.c_str()); if(HID_DEBUG || cur_values.size() > 2) log_printf("ConfigParser::parseSingleLine(line %d): Not a valid key=pair line %s\n",__LINE__,line.c_str());
return; return;
}else{ }else{
u16 hid_slot = getSlot(); u16 hid_slot = getSlot();
if(HID_DEBUG) log_printf("leftpart = \"%s\" \n",cur_values[0].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): leftpart = \"%s\" \n",__LINE__,cur_values[0].c_str());
if(HID_DEBUG) log_printf("rightpart = \"%s\" \n",cur_values[1].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): rightpart = \"%s\" \n",__LINE__,cur_values[1].c_str());
int keyslot = -1; s32 keyslot = -1;
if(HID_DEBUG) log_printf("Checking single value\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Checking single value\n",__LINE__);
if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD){ if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD){
keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]); keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]);
}else if(getType() == PARSE_MOUSE){ }else if(getType() == PARSE_MOUSE){
@ -140,14 +140,14 @@ void ConfigParser::parseSingleLine(std::string line){
keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]); keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]);
} }
if(keyslot != -1){ if(keyslot != -1){
if(HID_DEBUG) log_printf("Its a single value\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Its a single value\n",__LINE__);
long rightValue = -1; long rightValue = -1;
bool valueSet = false; bool valueSet = false;
if(cur_values[0].compare("DPAD_MODE") == 0){ if(cur_values[0].compare("DPAD_MODE") == 0){
const u8 * values_ = NULL; const u8 * values_ = NULL;
if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL){ if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL){
if(values_[STICK_CONF_MAGIC_VERSION] != STICK_CONF_MAGIC_VALUE) if(values_[STICK_CONF_MAGIC_VERSION] != STICK_CONF_MAGIC_VALUE)
if(HID_DEBUG) log_printf("Settings preset DPAD MODE and Mask\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Settings preset DPAD MODE and Mask\n",__LINE__);
config_controller[hid_slot][CONTRPS_DPAD_MODE][0] = CONTROLLER_PATCHER_VALUE_SET; config_controller[hid_slot][CONTRPS_DPAD_MODE][0] = CONTROLLER_PATCHER_VALUE_SET;
config_controller[hid_slot][CONTRPS_DPAD_MODE][1] = values_[CONTRDPAD_MODE]; config_controller[hid_slot][CONTRPS_DPAD_MODE][1] = values_[CONTRDPAD_MODE];
if(values_[CONTRDPAD_MASK] != 0x00){ if(values_[CONTRDPAD_MASK] != 0x00){
@ -161,9 +161,9 @@ void ConfigParser::parseSingleLine(std::string line){
if(!valueSet){ if(!valueSet){
if(getType() == PARSE_KEYBOARD){ if(getType() == PARSE_KEYBOARD){
if((rightValue = ConfigValues::getPresetValuesKeyboard(cur_values[1]))!= -1){ if((rightValue = ConfigValues::getPresetValuesKeyboard(cur_values[1]))!= -1){
if(HID_DEBUG) log_printf("Used pre-defined Keyboard! \"%s\" is %d\n",cur_values[1].c_str(),rightValue); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Used pre-defined Keyboard! \"%s\" is %d\n",__LINE__,cur_values[1].c_str(),rightValue);
}else{ }else{
if(HID_DEBUG) log_printf("I need to parse %s\n",cur_values[1].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str());
char * ptr; char * ptr;
rightValue = strtol(cur_values[1].c_str(),&ptr,16); rightValue = strtol(cur_values[1].c_str(),&ptr,16);
} }
@ -172,34 +172,34 @@ void ConfigParser::parseSingleLine(std::string line){
if(getType() == PARSE_MOUSE){ //No parsing for the mouse if(getType() == PARSE_MOUSE){ //No parsing for the mouse
if(rightValue == -1){ if(rightValue == -1){
if(HID_DEBUG) log_printf("Invalid mouse value, lets skip it %s\n",cur_values[1].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Invalid mouse value, lets skip it %s\n",__LINE__,cur_values[1].c_str());
return; return;
} }
}else{ }else{
if(rightValue == -1){ if(rightValue == -1){
if(HID_DEBUG) log_printf("I need to parse %s\n",cur_values[1].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str());
char * ptr; char * ptr;
rightValue = strtol(cur_values[1].c_str(),&ptr,16); rightValue = strtol(cur_values[1].c_str(),&ptr,16);
} }
} }
} }
if(HID_DEBUG) log_printf("Setting value to %d\n",rightValue); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Setting value to %d\n",__LINE__,rightValue);
config_controller[hid_slot][keyslot][0] = CONTROLLER_PATCHER_VALUE_SET; config_controller[hid_slot][keyslot][0] = CONTROLLER_PATCHER_VALUE_SET;
config_controller[hid_slot][keyslot][1] = rightValue; config_controller[hid_slot][keyslot][1] = rightValue;
} }
}else{ }else{
if(HID_DEBUG) log_printf("Check pair value\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Check pair value\n",__LINE__);
keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]); keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]);
if(keyslot != -1){ if(keyslot != -1){
if(HID_DEBUG) log_printf("Its a pair value\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Its a pair value\n",__LINE__);
if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){ if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){
if(HID_DEBUG) log_printf("And its no preset\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): And its no preset\n",__LINE__);
std::vector<std::string> rightvalues = CPStringTools::StringSplit(cur_values[1],","); std::vector<std::string> rightvalues = CPStringTools::StringSplit(cur_values[1],",");
if(rightvalues.size() != 2){ if(rightvalues.size() != 2){
log_printf("ConfigParser::parseSingleLine: %d instead of 2 key=values pairs in line\n",rightvalues.size()); log_printf("ConfigParser::parseSingleLine(line %d): %d instead of 2 key=values pairs in line\n",__LINE__,rightvalues.size());
return; return;
} }
@ -209,46 +209,46 @@ void ConfigParser::parseSingleLine(std::string line){
config_controller[hid_slot][keyslot][0] = firstValue; config_controller[hid_slot][keyslot][0] = firstValue;
config_controller[hid_slot][keyslot][1] = secondValue; config_controller[hid_slot][keyslot][1] = secondValue;
if(HID_DEBUG) log_printf("Set %02X,%02X\n",firstValue,secondValue); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Set %02X,%02X\n",__LINE__,firstValue,secondValue);
}else{ }else{
if(HID_DEBUG) log_printf("Found preset value!!\n"); if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Found preset value!!\n",__LINE__);
} }
}else{ }else{
log_printf("ConfigParser::parseSingleLine: The setting \"%s\" is unknown!\n",cur_values[0].c_str()); log_printf("ConfigParser::parseSingleLine(line %d): The setting \"%s\" is unknown!\n",__LINE__,cur_values[0].c_str());
} }
} }
} }
} }
bool ConfigParser::resetConfig(){ bool ConfigParser::resetConfig(){
int slot = getSlot(); s32 slot = getSlot();
if(slot >= gHIDMaxDevices) return false; if(slot >= gHIDMaxDevices) return false;
for(int j = (CONTRPS_PID+1);j< CONTRPS_MAX_VALUE;j++){ for(s32 j = (CONTRPS_PID+1);j< CONTRPS_MAX_VALUE;j++){
config_controller[slot][j][0] = CONTROLLER_PATCHER_INVALIDVALUE; config_controller[slot][j][0] = CONTROLLER_PATCHER_INVALIDVALUE;
config_controller[slot][j][1] = CONTROLLER_PATCHER_INVALIDVALUE; config_controller[slot][j][1] = CONTROLLER_PATCHER_INVALIDVALUE;
} }
return true; return true;
} }
int ConfigParser::getSlotController(std::string identify){ s32 ConfigParser::getSlotController(std::string identify){
if(HID_DEBUG) log_printf("Getting Controller Slot\n"); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Getting Controller Slot\n",__LINE__);
std::vector<std::string> values = CPStringTools::StringSplit(identify,","); std::vector<std::string> values = CPStringTools::StringSplit(identify,",");
if(values.size() != 2){ if(values.size() != 2){
log_printf("ConfigParser::getSlotController: You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",identify.c_str()); log_printf("ConfigParser::getSlotController(line %d): You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",__LINE__,identify.c_str());
return HID_INVALID_SLOT; return HID_INVALID_SLOT;
} }
int vid = getValueFromKeyValue(values[0],"VID","="); s32 vid = getValueFromKeyValue(values[0],"VID","=");
if(vid < 0){ if(vid < 0){
return HID_INVALID_SLOT; return HID_INVALID_SLOT;
} }
int pid = getValueFromKeyValue(values[1],"PID","="); s32 pid = getValueFromKeyValue(values[1],"PID","=");
if(pid < 0){ if(pid < 0){
return HID_INVALID_SLOT; return HID_INVALID_SLOT;
} }
if(HID_DEBUG) log_printf("VID: %04x PID: %04x\n",vid,pid); log_printf("ConfigParser::getSlotController(line %d): VID: %04x PID: %04x\n",__LINE__,vid,pid);
this->vid = vid; this->vid = vid;
this->pid = pid; this->pid = pid;
@ -256,11 +256,11 @@ int ConfigParser::getSlotController(std::string identify){
memset(&deviceinfo,0,sizeof(deviceinfo)); memset(&deviceinfo,0,sizeof(deviceinfo));
deviceinfo.vidpid.vid = vid; deviceinfo.vidpid.vid = vid;
deviceinfo.vidpid.pid = pid; deviceinfo.vidpid.pid = pid;
int result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo); s32 result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo);
int slot = deviceinfo.slotdata.deviceslot; s32 slot = deviceinfo.slotdata.deviceslot;
int hid = 0; s32 hid = 0;
if(result < 0){ if(result < 0){
if(HID_DEBUG) log_printf("Its a new controller, lets save it\n"); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Its a new controller, lets save it\n",__LINE__);
HIDSlotData slotdata; HIDSlotData slotdata;
ControllerPatcherUtils::getNextSlotData(&slotdata); ControllerPatcherUtils::getNextSlotData(&slotdata);
@ -269,10 +269,10 @@ int ConfigParser::getSlotController(std::string identify){
hid = slotdata.hidmask; hid = slotdata.hidmask;
if(slot >= gHIDMaxDevices){ if(slot >= gHIDMaxDevices){
log_printf("ConfigParser::getSlotController: We don't a space for a new controller, please delete .inis\n"); log_printf("ConfigParser::getSlotController(line %d): ConfigParser::getSlotController: We don't a space for a new controller, please delete .inis\n",__LINE__);
return HID_INVALID_SLOT; return HID_INVALID_SLOT;
} }
if(HID_DEBUG) log_printf("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,CPStringTools::byte_to_binary(hid)); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Got new slot! slot: %d hid %s .. Lets registrate it!\n",__LINE__,slot,CPStringTools::byte_to_binary(hid));
config_controller[slot][CONTRPS_VID][0] = (vid & 0xFF00) >> 8; config_controller[slot][CONTRPS_VID][0] = (vid & 0xFF00) >> 8;
config_controller[slot][CONTRPS_VID][1] = (vid & 0x00FF); config_controller[slot][CONTRPS_VID][1] = (vid & 0x00FF);
config_controller[slot][CONTRPS_PID][0] = (pid & 0xFF00) >> 8; config_controller[slot][CONTRPS_PID][0] = (pid & 0xFF00) >> 8;
@ -281,61 +281,61 @@ int ConfigParser::getSlotController(std::string identify){
u16 used_vid = config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1]; u16 used_vid = config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1];
u16 used_pid = config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]; u16 used_pid = config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1];
if(HID_DEBUG) log_printf("Saved vid: %04X pid: %04X\n",used_vid,used_pid); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Saved vid: %04X pid: %04X\n",__LINE__,used_vid,used_pid);
config_controller_hidmask[slot] = hid; config_controller_hidmask[slot] = hid;
if(HID_DEBUG) log_printf("Saved the hid\n"); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Saved the hid\n",__LINE__);
}else{ }else{
if(slot < gHIDMaxDevices){ if(slot < gHIDMaxDevices){
hid = config_controller_hidmask[slot]; hid = config_controller_hidmask[slot];
if(HID_DEBUG) log_printf(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,CPStringTools::byte_to_binary(hid)); if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): >>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",__LINE__,slot,CPStringTools::byte_to_binary(hid));
if(HID_DEBUG) log_printf("We already have data of this controller, lets modify it\n"); log_printf("ConfigParser::getSlotController(line %d): We already have data of this controller, lets modify it\n",__LINE__);
}else{ }else{
log_printf("ConfigParser::getSlotController: Something really odd happend to the slots. %d is bigger then max (%d)\n",slot,gHIDMaxDevices); log_printf("ConfigParser::getSlotController(line %d): Something really odd happend to the slots. %d is bigger then max (%d)\n",__LINE__,slot,gHIDMaxDevices);
return HID_INVALID_SLOT; return HID_INVALID_SLOT;
} }
} }
if(HID_DEBUG) log_printf("using slot: %d hid %s\n",slot,CPStringTools::byte_to_binary(hid)); log_printf("ConfigParser::getSlotController(line %d): using slot: %d hid %08X\n",__LINE__,slot,hid);
return slot; return slot;
} }
bool ConfigParser::parseIni(){ bool ConfigParser::parseIni(){
if(getSlot() == HID_INVALID_SLOT){ if(getSlot() == HID_INVALID_SLOT){
log_printf("ConfigParser::parseIni: Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",getType(),gHIDMaxDevices); log_printf("ConfigParser::parseIni(line %d): Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",__LINE__,getType(),gHIDMaxDevices);
} }
if(HID_DEBUG) log_printf("Parsing content, type %d\n",getType()); if(HID_DEBUG) log_printf("ConfigParser::parseIni(line %d): Parsing content, type %d\n",__LINE__,getType());
int start = 1; s32 start = 1;
if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){ if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){
resetConfig(); resetConfig();
if(HID_DEBUG) log_printf("Overwriting existing settings of this device\n"); log_printf("ConfigParser::parseIni(line %d): Ignoring existing settings of this device\n",__LINE__);
start++; start++;
} }
for(u32 i = start; i < contentLines.size(); i++){ for(u32 i = start; i < contentLines.size(); i++){
if(HID_DEBUG) log_printf("line %d: \"%s\" \n",(i+1),contentLines[i].c_str()); if(HID_DEBUG) log_printf("ConfigParser::parseIni(line %d): line %d: \"%s\" \n",__LINE__,(i+1),contentLines[i].c_str());
parseSingleLine(contentLines[i]); parseSingleLine(contentLines[i]);
} }
if(HID_DEBUG) log_printf("Parsing of the file is done.\n"); if(HID_DEBUG) log_printf("ConfigParser::parseIni(line %d): Parsing of the file is done.\n",__LINE__);
return true; return true;
} }
int ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter){ 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 = CPStringTools::StringSplit(value_pair,delimiter);
if(string_value.size() != 2){ if(string_value.size() != 2){
if(HID_DEBUG || string_value.size() > 2) log_printf("Not a valid key=pair line %s\n",value_pair.c_str()); if(HID_DEBUG || string_value.size() > 2) log_printf("ConfigParser::getValueFromKeyValue(line %d): Not a valid key=pair line %s\n",__LINE__,value_pair.c_str());
return -1; return -1;
} }
if(string_value[0].compare(expectedKey) != 0){ if(string_value[0].compare(expectedKey) != 0){
log_printf("ConfigParser::getValueFromKeyValue: Key part not %s, its %s",expectedKey.c_str(),string_value[0].c_str()); log_printf("ConfigParser::getValueFromKeyValue(line %d): Key part not %s, its %s",__LINE__,expectedKey.c_str(),string_value[0].c_str());
return -1; return -1;
} }
char * ptr; char * ptr;
int value = strtol(string_value[1].c_str(),&ptr,16); s32 value = strtol(string_value[1].c_str(),&ptr,16);
return value; return value;
} }

View File

@ -59,11 +59,11 @@ private:
bool parseConfigString(std::string content); bool parseConfigString(std::string content);
int getSlotController(std::string identify); s32 getSlotController(std::string identify);
int checkExistingController(int vid, int pid); s32 checkExistingController(s32 vid, s32 pid);
int getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter); s32 getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter);
bool resetConfig(); bool resetConfig();

View File

@ -28,7 +28,7 @@ ConfigValues::ConfigValues(){
} }
ConfigValues::~ConfigValues(){ ConfigValues::~ConfigValues(){
if(HID_DEBUG) log_printf("ConfigValues::~ConfigValues(){\n"); if(HID_DEBUG) log_printf("ConfigValues::~ConfigValues(line %d){\n",__LINE__);
} }
const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue){ const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue){
@ -40,7 +40,7 @@ const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> valu
return NULL; return NULL;
} }
bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,int slot,int keyslot){ bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,s32 slot,s32 keyslot){
if(setIfValueIsPreset(presetGCValues,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetGCValues,value,slot,keyslot)) return true;
if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true;
if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true;
@ -49,7 +49,7 @@ bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,int slot,in
} }
//We need this function here so we can use preset sticks. //We need this function here so we can use preset sticks.
bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> values,std::string possibleValue,int slot,int keyslot){ bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> values,std::string possibleValue,s32 slot,s32 keyslot){
if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE){ if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE){
return false; return false;
} }
@ -58,9 +58,9 @@ bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> values,std
keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y || keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y ||
keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X || keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X ||
keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y){ keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y){
if(HID_DEBUG) log_printf("This may be a predefined stick %s\n",possibleValue.c_str()); if(HID_DEBUG) log_printf("ConfigValues::setIfValueIsPreset(line %d): This may be a predefined stick %s\n",__LINE__,possibleValue.c_str());
if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){ if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){
if(HID_DEBUG) log_printf("Found predefined stick!\n"); if(HID_DEBUG) log_printf("ConfigValues::setIfValueIsPreset(line %d): Found predefined stick!\n",__LINE__);
config_controller[slot][keyslot][0] = values_[STICK_CONF_BYTE]; //CONTRPS_VPAD_BUTTON_L_STICK_X config_controller[slot][keyslot][0] = values_[STICK_CONF_BYTE]; //CONTRPS_VPAD_BUTTON_L_STICK_X
config_controller[slot][keyslot][1] = values_[STICK_CONF_DEFAULT]; config_controller[slot][keyslot][1] = values_[STICK_CONF_DEFAULT];
config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT
@ -83,7 +83,7 @@ bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> values,std
} }
int ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string nameOfString){ s32 ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string nameOfString){
std::map<std::string,int>::iterator it; std::map<std::string,int>::iterator it;
it = values.find(nameOfString); it = values.find(nameOfString);
if (it != values.end()){ if (it != values.end()){
@ -94,12 +94,12 @@ int ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string n
return -1; return -1;
} }
int ConfigValues::getPresetValueEx(std::string possibleString){ s32 ConfigValues::getPresetValueEx(std::string possibleString){
int rightValue = -1; s32 rightValue = -1;
if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){ if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){
if(HID_DEBUG) log_printf("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue); if(HID_DEBUG) log_printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined VPAD_VALUE! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue);
}else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){ }else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){
if(HID_DEBUG) log_printf("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue); if(HID_DEBUG) log_printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined value! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue);
} }
return rightValue; return rightValue;
} }

View File

@ -61,7 +61,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getKeySlotGamePad(std::string possibleValue) static s32 getKeySlotGamePad(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -70,7 +70,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getKeySlotMouse(std::string possibleValue) static s32 getKeySlotMouse(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -80,7 +80,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getKeySlotDefaultSingleValue(std::string possibleValue) static s32 getKeySlotDefaultSingleValue(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -90,7 +90,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getKeySlotDefaultPairedValue(std::string possibleValue) static s32 getKeySlotDefaultPairedValue(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -100,7 +100,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getPresetValuesKeyboard(std::string possibleValue) static s32 getPresetValuesKeyboard(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -110,7 +110,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int getPresetValue(std::string possibleValue) static s32 getPresetValue(std::string possibleValue)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -120,7 +120,7 @@ private:
/** /**
Returns -1 if not found Returns -1 if not found
**/ **/
static int setIfValueIsAControllerPreset(std::string value,int slot,int keyslot) static s32 setIfValueIsAControllerPreset(std::string value,s32 slot,s32 keyslot)
{ {
ConfigValues * cur_instance = getInstance(); ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1; if(cur_instance == NULL) return -1;
@ -165,13 +165,14 @@ private:
std::map<std::string,const u8*> presetXInputValues; std::map<std::string,const u8*> presetXInputValues;
std::map<std::string,const u8*> presetSticks; std::map<std::string,const u8*> presetSticks;
int getValueFromMap(std::map<std::string,int> values,std::string nameOfString); s32 getValueFromMap(std::map<std::string,int> values,std::string nameOfString);
bool checkIfValueIsAControllerPreset(std::string value,int slot,int keyslot); bool checkIfValueIsAControllerPreset(std::string value,s32 slot,s32 keyslot);
int getPresetValueEx(std::string possibleString); s32 getPresetValueEx(std::string possibleString);
void InitValues(){ void InitValues(){
log_printf("ConfigValues::InitValues: Init values for the configuration\n");
CONTPRStringToValue["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A; CONTPRStringToValue["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A;
CONTPRStringToValue["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B; CONTPRStringToValue["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B;
CONTPRStringToValue["VPAD_BUTTON_X"] = CONTRPS_VPAD_BUTTON_X; CONTPRStringToValue["VPAD_BUTTON_X"] = CONTRPS_VPAD_BUTTON_X;
@ -519,7 +520,6 @@ private:
gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP; gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP;
gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN; gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN;
log_printf("Value device names \n");
deviceNames[CPStringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING; 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_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_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING;
@ -528,13 +528,12 @@ private:
deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_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_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[CPStringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID, HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING;
log_printf("Value init done\n");
} }
const u8 * getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue); const u8 * getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue);
bool setIfValueIsPreset(std::map<std::string,const u8*> values,std::string possibleValue,int slot,int keyslot); bool setIfValueIsPreset(std::map<std::string,const u8*> values,std::string possibleValue,s32 slot,s32 keyslot);
bool setIfValueIsAControllerPresetEx(std::string value,int slot,int keyslot); bool setIfValueIsAControllerPresetEx(std::string value,s32 slot,s32 keyslot);
void addDeviceNameEx(u16 vid,u16 pid,std::string value); void addDeviceNameEx(u16 vid,u16 pid,std::string value);
std::string getStringByVIDPIDEx(u16 vid,u16 pid); std::string getStringByVIDPIDEx(u16 vid,u16 pid);

View File

@ -2,8 +2,8 @@
#include "dynamic_libs/socket_functions.h" #include "dynamic_libs/socket_functions.h"
#include "ControllerPatcherNet.hpp" #include "ControllerPatcherNet.hpp"
int ControllerPatcherNet::recvwait(int sock, void *buffer, int len) { s32 ControllerPatcherNet::recvwait(s32 sock, void *buffer, s32 len) {
int ret; s32 ret;
while (len > 0) { while (len > 0) {
ret = recv(sock, buffer, len, 0); ret = recv(sock, buffer, len, 0);
if(ret < 0) return ret; if(ret < 0) return ret;
@ -13,18 +13,18 @@ int ControllerPatcherNet::recvwait(int sock, void *buffer, int len) {
return 0; return 0;
} }
int ControllerPatcherNet::recvbyte(int sock) { s32 ControllerPatcherNet::recvbyte(s32 sock) {
unsigned char buffer[1]; unsigned char buffer[1];
int ret; s32 ret;
ret = recvwait(sock, buffer, 1); ret = recvwait(sock, buffer, 1);
if (ret < 0) return ret; if (ret < 0) return ret;
return buffer[0]; return buffer[0];
} }
int ControllerPatcherNet::checkbyte(int sock) { s32 ControllerPatcherNet::checkbyte(s32 sock) {
unsigned char buffer[1]; unsigned char buffer[1];
int ret; s32 ret;
ret = recv(sock, buffer, 1, MSG_DONTWAIT); ret = recv(sock, buffer, 1, MSG_DONTWAIT);
if (ret < 0) return ret; if (ret < 0) return ret;
@ -32,8 +32,8 @@ int ControllerPatcherNet::checkbyte(int sock) {
return buffer[0]; return buffer[0];
} }
int ControllerPatcherNet::sendwait(int sock, const void *buffer, int len) { s32 ControllerPatcherNet::sendwait(s32 sock, const void *buffer, s32 len) {
int ret; s32 ret;
while (len > 0) { while (len > 0) {
ret = send(sock, buffer, len, 0); ret = send(sock, buffer, len, 0);
if(ret < 0) return ret; if(ret < 0) return ret;
@ -43,7 +43,7 @@ int ControllerPatcherNet::sendwait(int sock, const void *buffer, int len) {
return 0; return 0;
} }
int ControllerPatcherNet::sendbyte(int sock, unsigned char byte) { s32 ControllerPatcherNet::sendbyte(s32 sock, unsigned char byte) {
unsigned char buffer[1]; unsigned char buffer[1];
buffer[0] = byte; buffer[0] = byte;
return sendwait(sock, buffer, 1); return sendwait(sock, buffer, 1);

View File

@ -5,11 +5,11 @@ class ControllerPatcherNet{
friend class TCPServer; friend class TCPServer;
friend class UDPServer; friend class UDPServer;
private: private:
static int recvwait(int sock, void *buffer, int len); static s32 recvwait(s32 sock, void *buffer, s32 len);
static int recvbyte(int sock); static s32 recvbyte(s32 sock);
static int checkbyte(int sock); static s32 checkbyte(s32 sock);
static int sendwait(int sock, const void *buffer, int len); static s32 sendwait(s32 sock, const void *buffer, s32 len);
static int sendbyte(int sock, unsigned char byte); static s32 sendbyte(s32 sock, unsigned char byte);
}; };
#endif #endif

View File

@ -44,7 +44,7 @@
ControllerPatcherThread * TCPServer::pThread = NULL; ControllerPatcherThread * TCPServer::pThread = NULL;
TCPServer * TCPServer::instance = NULL; TCPServer * TCPServer::instance = NULL;
TCPServer::TCPServer(int port){ TCPServer::TCPServer(s32 port){
this->sockfd = -1; this->sockfd = -1;
this->clientfd = -1; this->clientfd = -1;
memset(&(this->sock_addr),0,sizeof(this->sock_addr)); memset(&(this->sock_addr),0,sizeof(this->sock_addr));
@ -54,14 +54,14 @@ TCPServer::TCPServer(int port){
TCPServer::~TCPServer(){ TCPServer::~TCPServer(){
CloseSockets(); CloseSockets();
if(HID_DEBUG) log_printf("TCPServer: Thread will be closed\n"); if(HID_DEBUG) log_printf("TCPServer::~TCPServer(line %d): Thread will be closed\n",__LINE__);
TCPServer::AttachDetach(DETACH); TCPServer::AttachDetach(DETACH);
exitThread = 1; exitThread = 1;
if(TCPServer::pThread != NULL){ if(TCPServer::pThread != NULL){
if(HID_DEBUG) log_printf("TCPServer: Deleting it!\n"); if(HID_DEBUG) log_printf("TCPServer::~TCPServer(line %d): Deleting it!\n",__LINE__);
delete TCPServer::pThread; delete TCPServer::pThread;
} }
if(HID_DEBUG) log_printf("TCPServer: Thread done\n"); if(HID_DEBUG) log_printf("TCPServer::~TCPServer(line %d): Thread done\n",__LINE__);
TCPServer::pThread = NULL; TCPServer::pThread = NULL;
} }
@ -81,19 +81,19 @@ void TCPServer::StartTCPThread(TCPServer * server){
TCPServer::pThread->resumeThread(); TCPServer::pThread->resumeThread();
} }
void TCPServer::AttachDetach(int attach){ void TCPServer::AttachDetach(s32 attach){
if(HID_DEBUG){ if(HID_DEBUG){
if(attach){ if(attach){
log_printf("TCPServer: Network Attach\n"); log_printf("TCPServer::AttachDetach(line %d): Network Attach\n",__LINE__);
}else{ }else{
log_printf("TCPServer: Network Detach\n"); log_printf("TCPServer::AttachDetach(line %d): Network Detach\n",__LINE__);
} }
} }
for(int i= 0;i< gHIDMaxDevices;i++){ for(s32 i= 0;i< gHIDMaxDevices;i++){
for(int j= 0;j< HID_MAX_PADS_COUNT;j++){ for(s32 j= 0;j< HID_MAX_PADS_COUNT;j++){
if(gNetworkController[i][j][NETWORK_CONTROLLER_ACTIVE] > 0){ if(gNetworkController[i][j][NETWORK_CONTROLLER_ACTIVE] > 0){
log_printf("Found a registered pad in deviceslot %d and padslot %d! Lets detach it.\n",i,j); log_printf("TCPServer::AttachDetach(line %d): Found a registered pad in deviceslot %d and padslot %d! Lets detach it.\n",__LINE__,i,j);
HIDDevice device; HIDDevice device;
memset(&device,0,sizeof(device)); memset(&device,0,sizeof(device));
@ -110,9 +110,9 @@ void TCPServer::AttachDetach(int attach){
if(HID_DEBUG){ if(HID_DEBUG){
if(attach){ if(attach){
log_printf("TCPServer: Network Attach DONE!\n"); log_printf("TCPServer::AttachDetach(line %d): Network Attach DONE!\n",__LINE__);
}else{ }else{
log_printf("TCPServer: Network Detach DONE!\n"); log_printf("TCPServer::AttachDetach(line %d): Network Detach DONE!\n",__LINE__);
} }
} }
} }
@ -122,8 +122,8 @@ void TCPServer::DetachAndDelete(){
memset(&gNetworkController,0,sizeof(gNetworkController)); memset(&gNetworkController,0,sizeof(gNetworkController));
} }
int TCPServer::RunTCP(){ s32 TCPServer::RunTCP(){
int ret; s32 ret;
while (1) { while (1) {
if(exitThread) break; if(exitThread) break;
ret = ControllerPatcherNet::checkbyte(clientfd); ret = ControllerPatcherNet::checkbyte(clientfd);
@ -135,28 +135,28 @@ int TCPServer::RunTCP(){
//log_printf("got byte from tcp! %01X\n",ret); //log_printf("got byte from tcp! %01X\n",ret);
switch (ret) { switch (ret) {
case WIIU_CP_TCP_ATTACH: { /*attach */ case WIIU_CP_TCP_ATTACH: { /*attach */
int handle; s32 handle;
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4); ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: recvwait handle\n",WIIU_CP_TCP_ATTACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_ATTACH);
return ret; return ret;
} }
if(HID_DEBUG) log_printf("TCPServer: got handle %d\n",handle); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): got handle %d\n",handle);
u16 vid = 0; u16 vid = 0;
u16 pid = 0; u16 pid = 0;
ret = ControllerPatcherNet::recvwait(clientfd, &vid, 2); ret = ControllerPatcherNet::recvwait(clientfd, &vid, 2);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: recvwait vid\n",WIIU_CP_TCP_ATTACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait vid\n",__LINE__,WIIU_CP_TCP_ATTACH);
return ret; return ret;
} }
if(HID_DEBUG) log_printf("TCPServer: got vid %04X\n",vid); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): got vid %04X\n",vid);
ret = ControllerPatcherNet::recvwait(clientfd, &pid, 2); ret = ControllerPatcherNet::recvwait(clientfd, &pid, 2);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: recvwait pid\n",WIIU_CP_TCP_ATTACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait pid\n",__LINE__,WIIU_CP_TCP_ATTACH);
return ret; return ret;
} }
if(HID_DEBUG) log_printf("TCPServer: got pid %04X\n",pid); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): got pid %04X\n",pid);
HIDDevice device; HIDDevice device;
memset(&device,0,sizeof(device)); memset(&device,0,sizeof(device));
device.handle = handle; device.handle = handle;
@ -168,81 +168,81 @@ int TCPServer::RunTCP(){
my_cb_user * user = NULL; my_cb_user * user = NULL;
ControllerPatcherHID::externAttachDetachCallback(&device,1); ControllerPatcherHID::externAttachDetachCallback(&device,1);
if((ret = ControllerPatcherUtils::getDataByHandle(handle,&user)) < 0){ if((ret = ControllerPatcherUtils::getDataByHandle(handle,&user)) < 0){
log_printf("TCPServer::RunTCP() Error in %02X: getDataByHandle(%d,%08X).\n",WIIU_CP_TCP_ATTACH,handle,&user); log_printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_ATTACH,handle,&user);
log_printf("TCPServer::RunTCP() Error in %02X: Config for the controller is missing.\n",WIIU_CP_TCP_ATTACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Config for the controller is missing.\n",__LINE__,WIIU_CP_TCP_ATTACH);
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND) < 0)){ if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND) < 0)){
log_printf("TCPServer::RunTCP() Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret);
} }
return -1; return -1;
} }
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_FOUND) < 0)){ if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_FOUND) < 0)){
log_printf("TCPServer::RunTCP() Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_FOUND byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_FOUND byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret);
return ret; return ret;
} }
if(user != NULL){ if(user != NULL){
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_OKAY) < 0)){ if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_OKAY) < 0)){
log_printf("TCPServer::RunTCP() Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_OKAY byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_OKAY byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret);
return ret; return ret;
} }
ret = ControllerPatcherNet::sendwait(clientfd,&user->slotdata.deviceslot,2); ret = ControllerPatcherNet::sendwait(clientfd,&user->slotdata.deviceslot,2);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: sendwait slotdata: %04X\n",WIIU_CP_TCP_ATTACH,user->slotdata.deviceslot); log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait slotdata: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->slotdata.deviceslot);
return ret; return ret;
} }
ret = ControllerPatcherNet::sendwait(clientfd,&user->pad_slot,1); ret = ControllerPatcherNet::sendwait(clientfd,&user->pad_slot,1);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: sendwait pad_slot: %04X\n",WIIU_CP_TCP_ATTACH,user->pad_slot); log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait pad_slot: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->pad_slot);
return ret; return ret;
} }
}else{ }else{
log_printf("TCPServer::RunTCP() Error in %02X: invalid user data.\n",WIIU_CP_TCP_ATTACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_ATTACH);
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_BAD) < 0)){ if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_BAD) < 0)){
log_printf("TCPServer::RunTCP() Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_BAD byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_BAD byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret);
return ret; return ret;
} }
return -1; return -1;
break; break;
} }
if(HID_DEBUG) log_printf("TCPServer: attachted to device slot: %d , pad slot is: %d\n",user->slotdata.deviceslot,user->pad_slot); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): attachted to device slot: %d , pad slot is: %d\n",__LINE__,user->slotdata.deviceslot,user->pad_slot);
gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_VID] = device.vid; gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_VID] = device.vid;
gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_PID] = device.pid; gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_PID] = device.pid;
gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_ACTIVE] = 1; gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_ACTIVE] = 1;
gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_HANDLE] = handle; gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_HANDLE] = handle;
if(HID_DEBUG) log_printf("TCPServer: handle %d connected! vid: %02X pid: %02X deviceslot %d, padslot %d\n",handle,vid,pid,user->slotdata.deviceslot,user->pad_slot); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): handle %d connected! vid: %02X pid: %02X deviceslot %d, padslot %d\n",__LINE__,handle,vid,pid,user->slotdata.deviceslot,user->pad_slot);
break; break;
} }
case WIIU_CP_TCP_DETACH: { /*detach */ case WIIU_CP_TCP_DETACH: { /*detach */
int handle; s32 handle;
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4); ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
if(ret < 0){ if(ret < 0){
log_printf("TCPServer::RunTCP() Error in %02X: recvwait handle\n",WIIU_CP_TCP_DETACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_DETACH);
return ret; return ret;
break; break;
} }
if(HID_DEBUG) log_printf("TCPServer: got detach for handle: %d\n",handle); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): got detach for handle: %d\n",__LINE__,handle);
my_cb_user * user = NULL; my_cb_user * user = NULL;
if(ControllerPatcherUtils::getDataByHandle(handle,&user) < 0){ if(ControllerPatcherUtils::getDataByHandle(handle,&user) < 0){
log_printf("TCPServer::RunTCP() Error in %02X: getDataByHandle(%d,%08X).\n",WIIU_CP_TCP_DETACH,handle,&user); log_printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_DETACH,handle,&user);
return -1; return -1;
break; break;
} }
if(user == NULL){ if(user == NULL){
log_printf("TCPServer::RunTCP() Error in %02X: invalid user data.\n",WIIU_CP_TCP_DETACH); log_printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_DETACH);
return -1; return -1;
break; break;
} }
int deviceslot = user->slotdata.deviceslot; s32 deviceslot = user->slotdata.deviceslot;
if(HID_DEBUG) log_printf("TCPServer: device slot is: %d , pad slot is: %d\n",deviceslot,user->pad_slot); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): device slot is: %d , pad slot is: %d\n",__LINE__,deviceslot,user->pad_slot);
DeviceVIDPIDInfo vidpid; DeviceVIDPIDInfo vidpid;
int result; s32 result;
if((result = ControllerPatcherUtils::getVIDPIDbyDeviceSlot(deviceslot,&vidpid)) < 0){ if((result = ControllerPatcherUtils::getVIDPIDbyDeviceSlot(deviceslot,&vidpid)) < 0){
log_printf("TCPServer::RunTCP() Error in %02X: Couldn't find a valid VID/PID for device slot %d. Error: %d\n",WIIU_CP_TCP_DETACH,deviceslot,ret); log_printf("TCPServer::RunTCP(line %d): Error in %02X: Couldn't find a valid VID/PID for device slot %d. Error: %d\n",__LINE__,WIIU_CP_TCP_DETACH,deviceslot,ret);
return -1; return -1;
break; break;
} }
@ -257,13 +257,13 @@ int TCPServer::RunTCP(){
ControllerPatcherHID::externAttachDetachCallback(&device,DETACH); ControllerPatcherHID::externAttachDetachCallback(&device,DETACH);
memset(gNetworkController[deviceslot][user->pad_slot],0,sizeof(gNetworkController[deviceslot][user->pad_slot])); memset(gNetworkController[deviceslot][user->pad_slot],0,sizeof(gNetworkController[deviceslot][user->pad_slot]));
if(HID_DEBUG) log_printf("TCPServer: handle %d disconnected!\n",handle); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): handle %d disconnected!\n",__LINE__,handle);
break; break;
} }
case WIIU_CP_TCP_PING: { /*ping*/ case WIIU_CP_TCP_PING: { /*ping*/
if(HID_DEBUG) log_printf("TCPServer: GOT PING\n"); if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): Got Ping, sending now a Pong\n",__LINE__);
int ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_PONG); s32 ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_PONG);
if(ret < 0){ log_printf("TCPServer::RunTCP() Error in %02X: sendbyte PONG\n"); return -1;} if(ret < 0){ log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendbyte PONG\n",__LINE__); return -1;}
break; break;
} }
@ -281,7 +281,7 @@ void TCPServer::ErrorHandling(){
} }
void TCPServer::DoTCPThreadInternal(){ void TCPServer::DoTCPThreadInternal(){
int ret; s32 ret;
s32 len; s32 len;
while (1) { while (1) {
if(exitThread) break; if(exitThread) break;
@ -292,7 +292,7 @@ void TCPServer::DoTCPThreadInternal(){
this->sockfd = ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); this->sockfd = ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(ret == -1){ ErrorHandling(); continue;} if(ret == -1){ ErrorHandling(); continue;}
int enable = 1; s32 enable = 1;
setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
@ -302,20 +302,19 @@ void TCPServer::DoTCPThreadInternal(){
if(ret < 0){ ErrorHandling(); continue;} if(ret < 0){ ErrorHandling(); continue;}
do{ do{
if(HID_DEBUG) log_printf("TCPServer::DoTCPThreadInternal: Waiting for a connection\n"); if(HID_DEBUG) log_printf("TCPServer::DoTCPThreadInternal(line %d): Waiting for a connection\n",__LINE__);
if(exitThread) break; if(exitThread) break;
len = 16; len = 16;
clientfd = ret = accept(sockfd, (sockaddr *)&(sock_addr), &len); clientfd = ret = accept(sockfd, (sockaddr *)&(sock_addr), &len);
if(HID_DEBUG) log_printf("TCPServer::DoTCPThreadInternal: Connection accepted\n");
if(ret == -1){ ErrorHandling(); break;} if(ret == -1){ ErrorHandling(); break;}
int ret; log_printf("TCPServer::DoTCPThreadInternal(line %d): TCP Connection accepted\n",__LINE__);
s32 ret;
ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE); //Hey I'm a WiiU console! ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE); //Hey I'm a WiiU console!
if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal: Error sendbyte: %02X\n",WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;} if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte: %02X\n",__LINE__,WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;}
if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal: Error sendbyte %02X/02X\n",WIIU_CP_TCP_NEW_CLIENT,WIIU_CP_TCP_SAME_CLIENT); ErrorHandling(); break;} if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte %02X/02X\n",__LINE__,WIIU_CP_TCP_NEW_CLIENT,WIIU_CP_TCP_SAME_CLIENT); ErrorHandling(); break;}
TCPServer::DetachAndDelete(); //Clear connected controller TCPServer::DetachAndDelete(); //Clear connected controller
RunTCP(); RunTCP();
@ -324,9 +323,9 @@ void TCPServer::DoTCPThreadInternal(){
} }
clientfd = -1; clientfd = -1;
}while(0); }while(0);
log_printf("TCPServer::DoTCPThreadInternal(line %d): Connection closed\n",__LINE__);
TCPServer::DetachAndDelete(); //Clear connected controller TCPServer::DetachAndDelete(); //Clear connected controller
CloseSockets(); CloseSockets();
if(HID_DEBUG) log_printf("TCPServer: Connection closed\n");
continue; continue;
} }
} }

View File

@ -40,7 +40,7 @@ private:
} }
} }
TCPServer(int port); TCPServer(s32 port);
~TCPServer(); ~TCPServer();
void CloseSockets(); void CloseSockets();
@ -50,18 +50,18 @@ private:
static void DoTCPThread(ControllerPatcherThread *thread, void *arg); static void DoTCPThread(ControllerPatcherThread *thread, void *arg);
void DoTCPThreadInternal(); void DoTCPThreadInternal();
static void DetachConnectedNetworkController(); static void DetachConnectedNetworkController();
static void AttachDetach(int attach); static void AttachDetach(s32 attach);
void DetachAndDelete(); void DetachAndDelete();
static TCPServer *instance; static TCPServer *instance;
int RunTCP(); s32 RunTCP();
struct sockaddr_in sock_addr; struct sockaddr_in sock_addr;
volatile int sockfd = -1; volatile s32 sockfd = -1;
volatile int clientfd = -1; volatile s32 clientfd = -1;
volatile int exitThread = 0; volatile s32 exitThread = 0;
static ControllerPatcherThread *pThread; static ControllerPatcherThread *pThread;
}; };

View File

@ -25,8 +25,8 @@
ControllerPatcherThread * UDPServer::pThread = NULL; ControllerPatcherThread * UDPServer::pThread = NULL;
UDPServer * UDPServer::instance = NULL; UDPServer * UDPServer::instance = NULL;
UDPServer::UDPServer(int port){ UDPServer::UDPServer(s32 port){
int ret; s32 ret;
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
@ -35,7 +35,7 @@ UDPServer::UDPServer(int port){
this->sockfd = ret = socket(AF_INET, SOCK_DGRAM, 0); this->sockfd = ret = socket(AF_INET, SOCK_DGRAM, 0);
if(ret == -1) return; if(ret == -1) return;
int enable = 1; s32 enable = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
ret = bind(sockfd, (sockaddr *)&addr, 16); ret = bind(sockfd, (sockaddr *)&addr, 16);
if(ret < 0) return; if(ret < 0) return;
@ -47,7 +47,6 @@ UDPServer::~UDPServer(){
ControllerPatcherThread * pThreadPointer = UDPServer::pThread; ControllerPatcherThread * pThreadPointer = UDPServer::pThread;
if(pThreadPointer != NULL){ if(pThreadPointer != NULL){
exitThread = 1; exitThread = 1;
log_printf("%08X\n",pThreadPointer);
if(pThreadPointer != NULL){ if(pThreadPointer != NULL){
delete pThreadPointer; delete pThreadPointer;
UDPServer::pThread = NULL; UDPServer::pThread = NULL;
@ -57,7 +56,7 @@ UDPServer::~UDPServer(){
this->sockfd = -1; this->sockfd = -1;
} }
} }
if(HID_DEBUG) log_printf("UDPServer Thread has been closed\n"); if(HID_DEBUG) log_printf("UDPServer::~UDPServer(line %d): Thread has been closed\n",__LINE__);
} }
@ -67,9 +66,9 @@ void UDPServer::StartUDPThread(UDPServer * server){
UDPServer::pThread->resumeThread(); UDPServer::pThread->resumeThread();
} }
bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, int * offset, int typesize, int maximum){ bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum){
if(((int)*offset + typesize) > maximum){ if(((int)*offset + typesize) > maximum){
log_printf("UDPServer::cpyIncrementBufferOffset: Transfer error. Excepted %04X bytes, but only got %04X\n",(*offset + typesize),maximum); log_printf("UDPServer::cpyIncrementBufferOffset(line %d): Transfer error. Excepted %04X bytes, but only got %04X\n",__LINE__,(*offset + typesize),maximum);
return false; return false;
} }
memcpy(target,(void*)((u32)source+(*offset)),typesize); memcpy(target,(void*)((u32)source+(*offset)),typesize);
@ -84,23 +83,23 @@ void UDPServer::DoUDPThread(ControllerPatcherThread *thread, void *arg){
void UDPServer::DoUDPThreadInternal(){ void UDPServer::DoUDPThreadInternal(){
u8 buffer[MAX_UDP_SIZE]; u8 buffer[MAX_UDP_SIZE];
int n; s32 n;
my_cb_user user; my_cb_user user;
while(1){ while(1){
//int usingVar = exitThread; //s32 usingVar = exitThread;
if(exitThread)break; if(exitThread)break;
memset(buffer,0,MAX_UDP_SIZE); memset(buffer,0,MAX_UDP_SIZE);
n = recv(sockfd,buffer,MAX_UDP_SIZE,0); n = recv(sockfd,buffer,MAX_UDP_SIZE,0);
if (n < 0){ if (n < 0){
int errno_ = errno; s32 errno_ = errno;
usleep(2000); usleep(2000);
if(errno_ != 11 && errno_ != 9){ if(errno_ != 11 && errno_ != 9){
break; break;
} }
continue; continue;
} }
int bufferoffset = 0; s32 bufferoffset = 0;
u8 type; u8 type;
memcpy((void *)&type,buffer,sizeof(type)); memcpy((void *)&type,buffer,sizeof(type));
bufferoffset += sizeof(type); bufferoffset += sizeof(type);
@ -109,9 +108,9 @@ void UDPServer::DoUDPThreadInternal(){
u8 count_commands; u8 count_commands;
memcpy((void *)&count_commands,buffer+bufferoffset,sizeof(count_commands)); memcpy((void *)&count_commands,buffer+bufferoffset,sizeof(count_commands));
bufferoffset += sizeof(count_commands); bufferoffset += sizeof(count_commands);
for(int i = 0;i<count_commands;i++){ for(s32 i = 0;i<count_commands;i++){
int handle; s32 handle;
u16 deviceSlot; u16 deviceSlot;
u16 hid; u16 hid;
u8 padslot; u8 padslot;
@ -124,7 +123,7 @@ void UDPServer::DoUDPThreadInternal(){
if(!cpyIncrementBufferOffset((void *)&datasize, (void *)buffer,&bufferoffset,sizeof(datasize), n))continue; if(!cpyIncrementBufferOffset((void *)&datasize, (void *)buffer,&bufferoffset,sizeof(datasize), n))continue;
u8 * databuffer = (u8*) malloc(datasize * sizeof(u8)); u8 * databuffer = (u8*) malloc(datasize * sizeof(u8));
if(!databuffer){ if(!databuffer){
log_printf("UDPServer::DoUDPThreadInternal(): Allocating memory failed\n"); log_printf("UDPServer::DoUDPThreadInternal(line %d): Allocating memory failed\n",__LINE__);
continue; continue;
} }
@ -138,7 +137,7 @@ void UDPServer::DoUDPThreadInternal(){
user.slotdata.hidmask = hid; user.slotdata.hidmask = hid;
if(gNetworkController[deviceSlot][padslot][0] == 0){ if(gNetworkController[deviceSlot][padslot][0] == 0){
log_printf("Ehm. Pad is not connected. STOP SENDING DATA ;) \n"); log_printf("UDPServer::DoUDPThreadInternal(line %d): Ehm. Pad is not connected. STOP SENDING DATA ;) \n",__LINE__);
}else{ }else{
ControllerPatcherHID::externHIDReadCallback(handle,databuffer,datasize,&user); ControllerPatcherHID::externHIDReadCallback(handle,databuffer,datasize,&user);
} }
@ -154,5 +153,5 @@ void UDPServer::DoUDPThreadInternal(){
} }
} }
} }
if(HID_DEBUG) log_printf("UDPServer Thread ended\n"); if(HID_DEBUG) log_printf("UDPServer::DoUDPThreadInternal(line %d): UDPServer Thread ended\n",__LINE__);
} }

View File

@ -40,15 +40,15 @@ private:
} }
} }
UDPServer(int port); UDPServer(s32 port);
~UDPServer(); ~UDPServer();
void StartUDPThread(UDPServer * server); void StartUDPThread(UDPServer * server);
static void DoUDPThread(ControllerPatcherThread *thread, void *arg); static void DoUDPThread(ControllerPatcherThread *thread, void *arg);
void DoUDPThreadInternal(); void DoUDPThreadInternal();
bool cpyIncrementBufferOffset(void * target, void * source, int * offset, int typesize, int maximum); bool cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum);
volatile int sockfd = -1; volatile s32 sockfd = -1;
volatile int exitThread = 0; volatile s32 exitThread = 0;
static UDPServer *instance; static UDPServer *instance;
static ControllerPatcherThread *pThread; static ControllerPatcherThread *pThread;

View File

@ -28,14 +28,13 @@
* public implementation for the network controller * public implementation for the network controller
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, unsigned int attach){ s32 ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, u32 attach){
log_printf("ControllerPatcherHID::externAttachDetachCallback called\n");
HIDClient client; HIDClient client;
memset(&client,0,sizeof(client)); memset(&client,0,sizeof(client));
return AttachDetachCallback(&client,p_device,attach); return AttachDetachCallback(&client,p_device,attach);
} }
void ControllerPatcherHID::externHIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr){ void ControllerPatcherHID::externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){
HIDReadCallback(handle,buf,bytes_transfered,usr); HIDReadCallback(handle,buf,bytes_transfered,usr);
} }
@ -43,11 +42,11 @@ void ControllerPatcherHID::externHIDReadCallback(unsigned int handle, unsigned c
* private implementation for the HID Api. * private implementation for the HID Api.
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int ControllerPatcherHID::myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, unsigned int attach){ s32 ControllerPatcherHID::myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach){
return AttachDetachCallback(p_client,p_device,attach); return AttachDetachCallback(p_client,p_device,attach);
} }
void ControllerPatcherHID::myHIDMouseReadCallback(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user){ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){
if(error == 0){ if(error == 0){
my_cb_user *usr = (my_cb_user*)p_user; my_cb_user *usr = (my_cb_user*)p_user;
@ -95,7 +94,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(unsigned int handle, int error
} }
} }
void ControllerPatcherHID::myHIDReadCallback(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user){ void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){
if(error == 0 && p_user != NULL && gHIDAttached) if(error == 0 && p_user != NULL && gHIDAttached)
{ {
my_cb_user *usr = (my_cb_user*)p_user; my_cb_user *usr = (my_cb_user*)p_user;
@ -114,9 +113,9 @@ void ControllerPatcherHID::myHIDReadCallback(unsigned int handle, int error, uns
* Intern Callback actions * Intern Callback actions
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, unsigned int attach){ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach){
if(attach){ if(attach){
log_printf("vid %04x pid %04x connected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): vid %04x pid %04x connected\n",__LINE__, SWAP16(p_device->vid),SWAP16(p_device->pid));
if(HID_DEBUG) log_printf("interface index %02x\n", p_device->interface_index); if(HID_DEBUG) log_printf("interface index %02x\n", p_device->interface_index);
if(HID_DEBUG) log_printf("sub class %02x\n", p_device->sub_class); if(HID_DEBUG) log_printf("sub class %02x\n", p_device->sub_class);
if(HID_DEBUG) log_printf("protocol %02x\n", p_device->protocol); if(HID_DEBUG) log_printf("protocol %02x\n", p_device->protocol);
@ -124,7 +123,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
if(HID_DEBUG) log_printf("max packet out %02x\n", p_device->max_packet_size_tx); if(HID_DEBUG) log_printf("max packet out %02x\n", p_device->max_packet_size_tx);
} }
if(!attach){ if(!attach){
log_printf("vid %04x pid %04x disconnected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): vid %04x pid %04x disconnected\n",__LINE__, SWAP16(p_device->vid),SWAP16(p_device->pid));
} }
DeviceInfo device_info; DeviceInfo device_info;
memset(&device_info,0,sizeof(DeviceInfo)); memset(&device_info,0,sizeof(DeviceInfo));
@ -143,18 +142,18 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
slotdata->deviceslot = gMouseSlot; slotdata->deviceslot = gMouseSlot;
//log_printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot); //log_printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot);
}else{ }else{
int ret; s32 ret;
if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
log_printf("ControllerPatcherHID::AttachDetachCallback: ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",ret); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",__LINE__,ret);
return HID_DEVICE_DETACH; return HID_DEVICE_DETACH;
}else{ }else{
if(HID_DEBUG) log_printf("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",ret); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",__LINE__,ret);
} }
} }
if(slotdata->hidmask){ if(slotdata->hidmask){
if(attach){ if(attach){
int bufSize = 64; s32 bufSize = 64;
if(slotdata->hidmask != gHID_LIST_MOUSE && config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){ if(slotdata->hidmask != gHID_LIST_MOUSE && config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){
bufSize = config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][1]; bufSize = config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][1];
} }
@ -167,7 +166,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
usr->handle = p_device->handle; usr->handle = p_device->handle;
gHIDAttached |= slotdata->hidmask; gHIDAttached |= slotdata->hidmask;
gHIDCurrentDevice |= slotdata->hidmask; gHIDCurrentDevice |= slotdata->hidmask;
int pads_per_device = 1; s32 pads_per_device = 1;
if(config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if(config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){
pads_per_device = config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][1]; pads_per_device = config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][1];
if(pads_per_device > HID_MAX_PADS_COUNT){//maximum of HID_MAX_PADS_COUNT if(pads_per_device > HID_MAX_PADS_COUNT){//maximum of HID_MAX_PADS_COUNT
@ -175,14 +174,14 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
} }
} }
int pad_count = config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1]; s32 pad_count = config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1];
if(pad_count > 0x0F) pad_count = 0; if(pad_count > 0x0F) pad_count = 0;
int pad_slot = 0; s32 pad_slot = 0;
int failed = 1; s32 failed = 1;
for(int i = 0;i<HID_MAX_PADS_COUNT;i += pads_per_device){ for(s32 i = 0;i<HID_MAX_PADS_COUNT;i += pads_per_device){
if(!(pad_count & (1 << i))){ if(!(pad_count & (1 << i))){
failed = 0; failed = 0;
pad_count |= (1 << i); pad_count |= (1 << i);
@ -192,7 +191,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
} }
if(failed){ if(failed){
log_printf("ControllerPatcherHID::AttachDetachCallback error: I can only handle %d devices of the same type. Sorry \n",HID_MAX_PADS_COUNT); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d) error: I can only handle %d devices of the same type. Sorry \n",__LINE__,HID_MAX_PADS_COUNT);
if(buf){ if(buf){
free(buf); free(buf);
buf = NULL; buf = NULL;
@ -212,11 +211,11 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
usr->pads_per_device = pads_per_device; usr->pads_per_device = pads_per_device;
usr->pad_slot = pad_slot; usr->pad_slot = pad_slot;
for(int i = 0;i<pads_per_device;i++){ for(s32 i = 0;i<pads_per_device;i++){
memset(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],0,sizeof(HID_Data)); memset(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],0,sizeof(HID_Data));
gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].handle = p_device->handle; gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].handle = p_device->handle;
//log_printf("saved handle %d to slot %d and pad %d\n",p_device->handle,slotdata->deviceslot,pad_slot); //log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): saved handle %d to slot %d and pad %d\n",__LINE__,p_device->handle,slotdata->deviceslot,pad_slot);
gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].user_data = usr; gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].user_data = usr;
gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].slotdata = device_info.slotdata; gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].slotdata = device_info.slotdata;
@ -225,7 +224,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data)); DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data));
} }
if(HID_DEBUG) log_print("AttachDetachCallback: Device successfully attached\n"); if(HID_DEBUG) log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully attached\n",__LINE__);
if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD
//The GC Adapter has all ports in one device. Set them all. //The GC Adapter has all ports in one device. Set them all.
@ -260,8 +259,8 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
}else{ }else{
my_cb_user * user_data = NULL; my_cb_user * user_data = NULL;
int founddata = 0; s32 founddata = 0;
for(int i = 0;i<HID_MAX_PADS_COUNT;i++){ for(s32 i = 0;i<HID_MAX_PADS_COUNT;i++){
if(gHID_Devices[slotdata->deviceslot].pad_data[i].handle == p_device->handle){ if(gHID_Devices[slotdata->deviceslot].pad_data[i].handle == p_device->handle){
gHID_Devices[slotdata->deviceslot].pad_data[i].handle = 0; gHID_Devices[slotdata->deviceslot].pad_data[i].handle = 0;
@ -286,7 +285,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
free(user_data); free(user_data);
user_data = NULL; user_data = NULL;
}else{ }else{
if(founddata) log_print("ControllerPatcherHID::AttachDetachCallback: user_data null. You may have a memory leak.\n"); if(founddata) log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): user_data null. You may have a memory leak.\n",__LINE__);
return HID_DEVICE_DETACH; return HID_DEVICE_DETACH;
} }
if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0){ if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0){
@ -302,23 +301,23 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; gHID_Mouse_Mode = HID_MOUSE_MODE_AIM;
} }
}else{ }else{
if(HID_DEBUG)log_printf("ControllerPatcherHID::AttachDetachCallback: We still have pad for deviceslot %d connected.\n",slotdata->deviceslot); if(HID_DEBUG)log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): We still have pad for deviceslot %d connected.\n",__LINE__,slotdata->deviceslot);
} }
if(HID_DEBUG)log_print("AttachDetachCallback: Device successfully detached\n"); if(HID_DEBUG)log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully detached\n",__LINE__);
} }
}else{ }else{
log_print("ControllerPatcherHID::AttachDetachCallback: HID-Device currently not supported! You can add support through config files\n"); log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): HID-Device currently not supported! You can add support through config files\n",__LINE__);
} }
return HID_DEVICE_DETACH; return HID_DEVICE_DETACH;
} }
void ControllerPatcherHID::HIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr){ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){
//log_printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot); //log_printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot);
if(usr->slotdata.hidmask == gHID_LIST_GC){ if(usr->slotdata.hidmask == gHID_LIST_GC){
HID_Data * data_ptr = NULL; HID_Data * data_ptr = NULL;
//Copy the data for all 4 pads //Copy the data for all 4 pads
for(int i = 0;i<4;i++){ for(s32 i = 0;i<4;i++){
data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]); data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]);
memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data. memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data.
memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data. memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data.
@ -326,7 +325,7 @@ void ControllerPatcherHID::HIDReadCallback(unsigned int handle, unsigned char *b
} }
/* /*
int i = 0; s32 i = 0;
log_printf("GC1 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; log_printf("GC1 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++;
log_printf("GC2 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; log_printf("GC2 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++;
log_printf("GC3 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; log_printf("GC3 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++;
@ -334,8 +333,8 @@ void ControllerPatcherHID::HIDReadCallback(unsigned int handle, unsigned char *b
HIDGCRumble(handle,usr); HIDGCRumble(handle,usr);
}else if(usr->slotdata.hidmask != 0){ }else if(usr->slotdata.hidmask != 0){
int dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD; s32 dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD;
int skip = 0; s32 skip = 0;
//Input filter //Input filter
if( config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if( config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){
@ -373,7 +372,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
HID_Data * data_cur; HID_Data * data_cur;
int buttons_hold; s32 buttons_hold;
for(u32 i = 0;i<data.size();i++){ for(u32 i = 0;i<data.size();i++){
data_cur = data[i]; data_cur = data[i];
@ -411,7 +410,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_R); ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_R);
u32 last_emulate_stick = (data_cur->last_buttons) & VPAD_MASK_EMULATED_STICKS; // We should only need the emulated stick data. u32 last_emulate_stick = (data_cur->last_buttons) & VPAD_MASK_EMULATED_STICKS; // We should only need the emulated stick data.
int last_realbuttons = (data_cur->last_buttons) & VPAD_MASK_BUTTONS; s32 last_realbuttons = (data_cur->last_buttons) & VPAD_MASK_BUTTONS;
buffer->btns_h |= buttons_hold; buffer->btns_h |= buttons_hold;
buffer->btns_d |= (buttons_hold & (~last_realbuttons)); buffer->btns_d |= (buttons_hold & (~last_realbuttons));
@ -439,17 +438,17 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
} }
std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){ std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
int hid = gHIDCurrentDevice; s32 hid = gHIDCurrentDevice;
std::vector<HID_Data *> data_list; std::vector<HID_Data *> data_list;
for(int i = 0;i < gHIDMaxDevices;i++){ for(s32 i = 0;i < gHIDMaxDevices;i++){
if((hid & (1 << i)) != 0){ if((hid & (1 << i)) != 0){
int cur_hidmask = config_controller_hidmask[i]; s32 cur_hidmask = config_controller_hidmask[i];
for(int pad = 0; pad < HID_MAX_PADS_COUNT; pad++){ for(s32 pad = 0; pad < HID_MAX_PADS_COUNT; pad++){
int res; s32 res;
HID_Data * new_data = NULL; HID_Data * new_data = NULL;
if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid. if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid.
log_printf("ControllerPatcherHID::getHIDDataAll() error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",CPStringTools::byte_to_binary(cur_hidmask),pad,res); log_printf("ControllerPatcherHID::getHIDDataAll(line %d): error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",__LINE__,CPStringTools::byte_to_binary(cur_hidmask),pad,res);
continue; continue;
} }
if(new_data != NULL) data_list.push_back(new_data); if(new_data != NULL) data_list.push_back(new_data);
@ -462,24 +461,24 @@ std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
/* /*
The slotdata in the HID_Data pointer is empty. We need to provide the hidmask via the parameter The slotdata in the HID_Data pointer is empty. We need to provide the hidmask via the parameter
*/ */
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(int hidmask, int pad, HID_Data ** data){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(s32 hidmask, s32 pad, HID_Data ** data){
if(data == NULL) return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER; if(data == NULL) return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER;
if(!(hidmask & gHIDCurrentDevice)) return CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED; if(!(hidmask & gHIDCurrentDevice)) return CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED;
if(pad < 0 && pad > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; if(pad < 0 && pad > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN;
int device_slot = ControllerPatcherUtils::getDeviceSlot(hidmask); s32 device_slot = ControllerPatcherUtils::getDeviceSlot(hidmask);
if(device_slot < 0){ if(device_slot < 0){
return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND;
} }
int real_pad = pad; s32 real_pad = pad;
if((device_slot != gHID_SLOT_GC) && config_controller[device_slot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if((device_slot != gHID_SLOT_GC) && config_controller[device_slot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){
int pad_count = config_controller[device_slot][CONTRPS_PAD_COUNT][1]; s32 pad_count = config_controller[device_slot][CONTRPS_PAD_COUNT][1];
if(pad_count > HID_MAX_PADS_COUNT) pad_count = HID_MAX_PADS_COUNT; if(pad_count > HID_MAX_PADS_COUNT) pad_count = HID_MAX_PADS_COUNT;
pad = (pad/(pad_count))*pad_count; pad = (pad/(pad_count))*pad_count;
} }
int result = ControllerPatcherUtils::checkActivePad(hidmask,pad); s32 result = ControllerPatcherUtils::checkActivePad(hidmask,pad);
if(result < 0){ //Not pad connected to adapter if(result < 0){ //Not pad connected to adapter
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
@ -491,10 +490,10 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(int hidmask,
} }
void ControllerPatcherHID::HIDGCRumble(unsigned int handle,my_cb_user *usr){ void ControllerPatcherHID::HIDGCRumble(u32 handle,my_cb_user *usr){
int rumblechanged = 0; s32 rumblechanged = 0;
for(int i = 0;i<HID_MAX_PADS_COUNT;i++){ for(s32 i = 0;i<HID_MAX_PADS_COUNT;i++){
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[i]); HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[i]);
if(data_ptr->rumbleActive != usr->rumblestatus[i]){ if(data_ptr->rumbleActive != usr->rumblestatus[i]){
usr->rumblestatus[i] = data_ptr->rumbleActive; usr->rumblestatus[i] = data_ptr->rumbleActive;
@ -508,8 +507,8 @@ void ControllerPatcherHID::HIDGCRumble(unsigned int handle,my_cb_user *usr){
} }
} }
void ControllerPatcherHID::HIDRumble(unsigned int handle,my_cb_user *usr,u32 pad){ void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){
int rumblechanged = 0; s32 rumblechanged = 0;
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[pad]); HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[pad]);
if(data_ptr->rumbleActive != usr->rumblestatus[pad]){ if(data_ptr->rumbleActive != usr->rumblestatus[pad]){
usr->rumblestatus[pad] = data_ptr->rumbleActive; usr->rumblestatus[pad] = data_ptr->rumbleActive;
@ -538,7 +537,7 @@ static u8 ds3_rumble_Report[48] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
void ControllerPatcherHID::HIDDS3Rumble(unsigned int handle,my_cb_user *usr,int rumble){ void ControllerPatcherHID::HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble){
memcpy(usr->buf, ds3_rumble_Report, 48); memcpy(usr->buf, ds3_rumble_Report, 48);
if (rumble) { if (rumble) {

View File

@ -41,34 +41,34 @@ class ControllerPatcherHID{
friend class ControllerPatcher; friend class ControllerPatcher;
friend class ControllerPatcherUtils; friend class ControllerPatcherUtils;
public: public:
static int externAttachDetachCallback(HIDDevice *p_device, unsigned int attach); static s32 externAttachDetachCallback(HIDDevice *p_device, u32 attach);
static void externHIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr); static void externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr);
private: private:
static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADData * buffer,std::vector<HID_Data *>& data); static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADData * buffer,std::vector<HID_Data *>& data);
static std::vector<HID_Data *> getHIDDataAll(); static std::vector<HID_Data *> getHIDDataAll();
static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(int hidmask, int pad, HID_Data ** data); static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(s32 hidmask, s32 pad, HID_Data ** data);
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Rumble * Rumble
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static void HIDRumble(unsigned int handle,my_cb_user *usr,u32 pad); static void HIDRumble(u32 handle,my_cb_user *usr,u32 pad);
static void HIDGCRumble(unsigned int handle,my_cb_user *usr); static void HIDGCRumble(u32 handle,my_cb_user *usr);
static void HIDDS3Rumble(unsigned int handle,my_cb_user *usr,int rumble); static void HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble);
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* HID Callbacks * HID Callbacks
*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static int myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, unsigned int attach); static s32 myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach);
static void myHIDMouseReadCallback(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user); static void myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user);
static void myHIDReadCallback(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user); static void myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user);
static int AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, unsigned int attach); static s32 AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach);
static void HIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr); static void HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr);
}; };
#endif /* _CONTROLLER_PATCHER_HID_H_ */ #endif /* _CONTROLLER_PATCHER_HID_H_ */

View File

@ -21,9 +21,9 @@
#include "utils/logger.h" #include "utils/logger.h"
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(int handle, my_cb_user ** data){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){
for(int i = 0;i< gHIDMaxDevices;i++){ for(s32 i = 0;i< gHIDMaxDevices;i++){
for(int j = 0;j<4;j++){ for(s32 j = 0;j<4;j++){
//log_printf("%d %d %d %d\n",i,j,gHID_Devices[i].pad_data[j].handle,(u32)handle); //log_printf("%d %d %d %d\n",i,j,gHID_Devices[i].pad_data[j].handle,(u32)handle);
if(gHID_Devices[i].pad_data[j].handle == (u32)handle){ if(gHID_Devices[i].pad_data[j].handle == (u32)handle){
*data = gHID_Devices[i].pad_data[j].user_data; *data = gHID_Devices[i].pad_data[j].user_data;
@ -37,12 +37,12 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(int h
* Analyse inputs * Analyse inputs
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_Data * data, int * buttons_hold, int VPADButton){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton){
if(data == NULL || buttons_hold == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(data == NULL || buttons_hold == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int deviceslot = data->slotdata.deviceslot; s32 deviceslot = data->slotdata.deviceslot;
int result = -1; s32 result = -1;
do{ do{
if(data->type == DEVICE_TYPE_MOUSE){ if(data->type == DEVICE_TYPE_MOUSE){
@ -75,7 +75,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int cur_config = 0; s32 cur_config = 0;
if(VPADButton == VPAD_BUTTON_A){ if(VPADButton == VPAD_BUTTON_A){
cur_config = CONTRPS_VPAD_BUTTON_A; cur_config = CONTRPS_VPAD_BUTTON_A;
@ -156,7 +156,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
} }
}else if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values){ }else if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values){
int contrps_value = 0; s32 contrps_value = 0;
if(VPADButton == VPAD_BUTTON_LEFT){ if(VPADButton == VPAD_BUTTON_LEFT){
contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT; contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT;
}else if(VPADButton == VPAD_BUTTON_RIGHT){ }else if(VPADButton == VPAD_BUTTON_RIGHT){
@ -168,7 +168,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
} }
if(contrps_value != 0){ if(contrps_value != 0){
int value_byte = CONTROLLER_PATCHER_INVALIDVALUE; s32 value_byte = CONTROLLER_PATCHER_INVALIDVALUE;
if((value_byte = config_controller[deviceslot][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE){ if((value_byte = config_controller[deviceslot][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE){
if(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]){ if(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]){
result = 1; result = 1;
@ -222,16 +222,16 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,int cur_config){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config){
if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int hidmask = data->slotdata.hidmask; s32 hidmask = data->slotdata.hidmask;
int deviceslot = data->slotdata.deviceslot; s32 deviceslot = data->slotdata.deviceslot;
int result = CONTROLLER_PATCHER_ERROR_NONE; s32 result = CONTROLLER_PATCHER_ERROR_NONE;
if(config_controller[deviceslot][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //Invalid data if(config_controller[deviceslot][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //Invalid data
if(hidmask & gHID_LIST_KEYBOARD){ if(hidmask & gHID_LIST_KEYBOARD){
if(isInKeyboardData(cur_data,config_controller[deviceslot][cur_config][1]) > 0) { if(isInKeyboardData(cur_data,config_controller[deviceslot][cur_config][1]) > 0) {
@ -245,9 +245,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data *
} }
return result; return result;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsigned char * keyboardData,int key){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsigned char * keyboardData,s32 key){
if(keyboardData == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(keyboardData == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
for(int i = 0;i<HID_KEYBOARD_DATA_LENGTH;i++){ for(s32 i = 0;i<HID_KEYBOARD_DATA_LENGTH;i++){
if(keyboardData[i] == 0 && i > 1){ if(keyboardData[i] == 0 && i > 1){
break; break;
}else if (keyboardData[i] == key){ }else if (keyboardData[i] == key){
@ -261,7 +261,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsi
* Utils for setting the Button data * Utils for setting the Button data
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingData(VPADData * old_buffer, VPADData * new_buffer,u32 VPADButton, int CONTRPS_SLOT){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingData(VPADData * old_buffer, VPADData * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT){
if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
u32 new_value = VPADButton; u32 new_value = VPADButton;
@ -292,14 +292,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADDat
* Pad Status functions * Pad Status functions
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(int hidmask,int pad){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(s32 hidmask,s32 pad){
if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){ if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1; if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
}else{ }else{
int deviceslot = getDeviceSlot(hidmask); s32 deviceslot = getDeviceSlot(hidmask);
if(deviceslot < 0 ) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; if(deviceslot < 0 ) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND;
int connected_pads = config_controller[deviceslot][CONTRPS_CONNECTED_PADS][1]; s32 connected_pads = config_controller[deviceslot][CONTRPS_CONNECTED_PADS][1];
if((connected_pads & (1 << pad)) > 0){ if((connected_pads & (1 << pad)) > 0){
return 1; return 1;
@ -309,7 +309,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(int hi
} }
/* /*
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(int hidmask){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(s32 hidmask){
if(hidmask & gHID_LIST_GC){ if(hidmask & gHID_LIST_GC){
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 0; if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 0;
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1; if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
@ -417,7 +417,7 @@ Vec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADData * buffer){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADData * buffer){
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int deviceslot = data->slotdata.deviceslot; s32 deviceslot = data->slotdata.deviceslot;
if (data->type == DEVICE_TYPE_MOUSE){ if (data->type == DEVICE_TYPE_MOUSE){
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values
@ -442,7 +442,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int deadzone = 0; s32 deadzone = 0;
if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){
if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){
@ -537,10 +537,10 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA
u32 emulatedSticks = 0; u32 emulatedSticks = 0;
int l_x_full = (buffer->lstick.x > 0.5f || buffer->lstick.x < -0.5f)? 1:0; s32 l_x_full = (buffer->lstick.x > 0.5f || buffer->lstick.x < -0.5f)? 1:0;
int l_y_full = (buffer->lstick.y > 0.5f || buffer->lstick.y < -0.5f)? 1:0; s32 l_y_full = (buffer->lstick.y > 0.5f || buffer->lstick.y < -0.5f)? 1:0;
int r_x_full = (buffer->rstick.x > 0.5f || buffer->rstick.x < -0.5f)? 1:0; s32 r_x_full = (buffer->rstick.x > 0.5f || buffer->rstick.x < -0.5f)? 1:0;
int r_y_full = (buffer->rstick.y > 0.5f || buffer->rstick.y < -0.5f)? 1:0; s32 r_y_full = (buffer->rstick.y > 0.5f || buffer->rstick.y < -0.5f)? 1:0;
if((buffer->lstick.x > 0.5f) || (buffer->lstick.x > 0.1f && !l_y_full)){ if((buffer->lstick.x > 0.5f) || (buffer->lstick.x > 0.1f && !l_y_full)){
emulatedSticks |= VPAD_STICK_L_EMULATION_RIGHT; emulatedSticks |= VPAD_STICK_L_EMULATION_RIGHT;
@ -585,12 +585,12 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADData * buffer){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADData * buffer){
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
int buttons_hold; s32 buttons_hold;
if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){ if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){
HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data;
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f)); s32 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f));
int y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f)); s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f));
buffer->tpdata.x = x_mouse; buffer->tpdata.x = x_mouse;
buffer->tpdata.y = y_mouse; buffer->tpdata.y = y_mouse;
buffer->tpdata.touched = 1; buffer->tpdata.touched = 1;
@ -609,7 +609,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * d
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){
int hidmask = data->slotdata.hidmask; s32 hidmask = data->slotdata.hidmask;
if(hidmask & gHID_LIST_KEYBOARD){ if(hidmask & gHID_LIST_KEYBOARD){
u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
@ -617,9 +617,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(
if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){ if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){
gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH;
if(HID_DEBUG) log_print("ControllerPatcherUtils::checkAndSetMouseMode: Mouse mode changed! to touch \n"); if(HID_DEBUG) log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to touch \n",__LINE__);
}else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
if(HID_DEBUG) log_print("ControllerPatcherUtils::checkAndSetMouseMode: Mouse mode changed! to aim \n"); if(HID_DEBUG) log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to aim \n",__LINE__);
gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; gHID_Mouse_Mode = HID_MOUSE_MODE_AIM;
} }
} }
@ -634,7 +634,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADData * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesPRO){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADData * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesPRO){
if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesPRO == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesPRO == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int buttons_hold = 0; s32 buttons_hold = 0;
pro_buffer->pro.btns_h = 0; pro_buffer->pro.btns_h = 0;
pro_buffer->pro.btns_d = 0; pro_buffer->pro.btns_d = 0;
@ -696,7 +696,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADDa
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRead(VPADData * vpad_buffer,WPADReadData * pro_buffer){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRead(VPADData * vpad_buffer,WPADReadData * pro_buffer){
if(vpad_buffer == NULL || pro_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(vpad_buffer == NULL || pro_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int buttons_hold = 0; s32 buttons_hold = 0;
pro_buffer->buttons = 0; pro_buffer->buttons = 0;
@ -750,7 +750,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRea
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADData * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesVPAD){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADData * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesVPAD){
if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesVPAD == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesVPAD == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int buttons_hold = 0; s32 buttons_hold = 0;
vpad_buffer->btns_h = 0; vpad_buffer->btns_h = 0;
vpad_buffer->btns_d = 0; vpad_buffer->btns_d = 0;
@ -805,7 +805,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADD
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkValueinConfigController(int deviceslot,int CONTRPS_slot,int expectedValue){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkValueinConfigController(s32 deviceslot,s32 CONTRPS_slot,s32 expectedValue){
if(config_controller[deviceslot][CONTRPS_slot][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if(config_controller[deviceslot][CONTRPS_slot][0] != CONTROLLER_PATCHER_INVALIDVALUE){
if(expectedValue == config_controller[deviceslot][CONTRPS_slot][1]) return 1; if(expectedValue == config_controller[deviceslot][CONTRPS_slot][1]) return 1;
} }
@ -817,8 +817,8 @@ void ControllerPatcherUtils::setConfigValue(u8 * dest, u8 first, u8 second){
dest[1] = second; dest[1] = second;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(int hidmask){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(s32 hidmask){
for(int i = 0;i < gHIDMaxDevices;i++){ for(s32 i = 0;i < gHIDMaxDevices;i++){
if(hidmask & config_controller_hidmask[i]){ if(hidmask & config_controller_hidmask[i]){
return i; return i;
} }
@ -828,7 +828,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(int hid
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidPid(DeviceInfo * info){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidPid(DeviceInfo * info){
if(info != NULL){ if(info != NULL){
for(int i = 0;i< gHIDMaxDevices;i++){ for(s32 i = 0;i< gHIDMaxDevices;i++){
u16 my_vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1]; u16 my_vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1];
u16 my_pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1]; u16 my_pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1];
//log_printf("info->vidpid.vid (%04X) == my_vid (%04X) && info->vidpid.pid (%04X) == my_pid (%04X)\n",info->vidpid.vid,my_vid,info->vidpid.pid,my_pid); //log_printf("info->vidpid.vid (%04X) == my_vid (%04X) && info->vidpid.pid (%04X) == my_pid (%04X)\n",info->vidpid.vid,my_vid,info->vidpid.pid,my_pid);
@ -855,7 +855,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSl
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot(int deviceslot, DeviceVIDPIDInfo * vidpid){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid){
if(vidpid == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(vidpid == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
if(deviceslot >= gHIDMaxDevices) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; if(deviceslot >= gHIDMaxDevices) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND;
vidpid->vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1]; vidpid->vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1];
@ -864,14 +864,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
int ControllerPatcherUtils::getPadSlotInAdapter(int deviceslot, u8 * input_data){ s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data){
int slot_incr = 0; s32 slot_incr = 0;
if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){
int pad_count = config_controller[deviceslot][CONTRPS_PAD_COUNT][1]; s32 pad_count = config_controller[deviceslot][CONTRPS_PAD_COUNT][1];
if(pad_count > HID_MAX_PADS_COUNT){ if(pad_count > HID_MAX_PADS_COUNT){
pad_count = HID_MAX_PADS_COUNT; pad_count = HID_MAX_PADS_COUNT;
} }
for(int i= 0;i<pad_count;i++){ for(s32 i= 0;i<pad_count;i++){
if( config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0] != CONTROLLER_PATCHER_INVALIDVALUE){ if( config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0] != CONTROLLER_PATCHER_INVALIDVALUE){
if(input_data[config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0]] == config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][1]){ if(input_data[config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0]] == config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][1]){
slot_incr = i; slot_incr = i;

View File

@ -48,7 +48,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is the deviceslot of the given HID-Mask \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is the deviceslot of the given HID-Mask
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceSlot(int hidmask); static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceSlot(s32 hidmask);
/** /**
\brief Returns the device slot for a given HID-Mask. \brief Returns the device slot for a given HID-Mask.
@ -58,7 +58,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given my_cb_user **. \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given my_cb_user **.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR getDataByHandle(int handle, my_cb_user ** data); static CONTROLLER_PATCHER_RESULT_OR_ERROR getDataByHandle(s32 handle, my_cb_user ** data);
/** /**
\brief Returns the VID/PID for the given device slot. \brief Returns the VID/PID for the given device slot.
@ -68,7 +68,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given DeviceVIDPIDInfo *. \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given DeviceVIDPIDInfo *.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR getVIDPIDbyDeviceSlot(int deviceslot, DeviceVIDPIDInfo * vidpid); static CONTROLLER_PATCHER_RESULT_OR_ERROR getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid);
/** \brief Set the VPAD data for a given KPAD data. /** \brief Set the VPAD data for a given KPAD data.
* *
@ -92,7 +92,7 @@ class ControllerPatcherUtils{
* \return When the functions failed result < 0 is returned.If the result is >= 0 the function was successful. * \return When the functions failed result < 0 is returned.If the result is >= 0 the function was successful.
* *
*/ */
static CONTROLLER_PATCHER_RESULT_OR_ERROR getButtonPressed(HID_Data * data, int * buttons_hold, int VPADButton); static CONTROLLER_PATCHER_RESULT_OR_ERROR getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton);
/** \brief Checks if a given value is set in the HID_DATA given the data in the slot number provided by cur_config. /** \brief Checks if a given value is set in the HID_DATA given the data in the slot number provided by cur_config.
@ -102,7 +102,7 @@ class ControllerPatcherUtils{
* \return When the functions failed result < 0 is returned. If the value is set, 1 will be returned. Otherwise 0. * \return When the functions failed result < 0 is returned. If the value is set, 1 will be returned. Otherwise 0.
* *
*/ */
static CONTROLLER_PATCHER_RESULT_OR_ERROR isValueSet(HID_Data * data,int cur_config); static CONTROLLER_PATCHER_RESULT_OR_ERROR isValueSet(HID_Data * data,s32 cur_config);
/** \brief Checks if a given key in the keyboard data is pressed. /** \brief Checks if a given key in the keyboard data is pressed.
@ -112,7 +112,7 @@ class ControllerPatcherUtils{
* \return When the functions failed result < 0 is returned. If the key is active pressed, 1 is returned. * \return When the functions failed result < 0 is returned. If the key is active pressed, 1 is returned.
* *
*/ */
static CONTROLLER_PATCHER_RESULT_OR_ERROR isInKeyboardData(unsigned char * keyboardData,int key); static CONTROLLER_PATCHER_RESULT_OR_ERROR isInKeyboardData(unsigned char * keyboardData,s32 key);
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Utils for setting the Button data * Utils for setting the Button data
@ -128,7 +128,7 @@ class ControllerPatcherUtils{
* \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. * \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned.
* *
*/ */
static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonRemappingData(VPADData * old_buffer, VPADData * new_buffer,u32 VPADButton, int CONTRPS_SLOT); static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonRemappingData(VPADData * old_buffer, VPADData * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT);
/** /**
\brief Checks if a given button (oldVPADButton) is set in a given VPADData struct (old_buffer). If its set, it will set an other \brief Checks if a given button (oldVPADButton) is set in a given VPADData struct (old_buffer). If its set, it will set an other
@ -154,7 +154,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR checkActivePad(int hidmask,int pad); static CONTROLLER_PATCHER_RESULT_OR_ERROR checkActivePad(s32 hidmask,s32 pad);
/** /**
\brief Returns the first active pad of devices with the given HID-Mask. Currently only implemented for the GC-Adapter. Every other pad will always return 0. \brief Returns the first active pad of devices with the given HID-Mask. Currently only implemented for the GC-Adapter. Every other pad will always return 0.
@ -163,7 +163,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is fist active pad. \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is fist active pad.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(int hidmask); static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(s32 hidmask);
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Stick functions * Stick functions
@ -266,7 +266,7 @@ class ControllerPatcherUtils{
\return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful.
**/ **/
static CONTROLLER_PATCHER_RESULT_OR_ERROR checkValueinConfigController(int device_slot,int CONTRPS_slot,int expectedValue); static CONTROLLER_PATCHER_RESULT_OR_ERROR checkValueinConfigController(s32 device_slot,s32 CONTRPS_slot,s32 expectedValue);
/** /**
\brief Sets two u8 values to the given pointer. \brief Sets two u8 values to the given pointer.
@ -304,7 +304,7 @@ class ControllerPatcherUtils{
\param current input data \param current input data
\return The relative slot in the device \return The relative slot in the device
**/ **/
static int getPadSlotInAdapter(int deviceslot, u8 * input_data); static s32 getPadSlotInAdapter(s32 deviceslot, u8 * input_data);
/** /**
\brief returns a pointer to the ControllerMapping to the given controller type \brief returns a pointer to the ControllerMapping to the given controller type

View File

@ -17,7 +17,7 @@ std::vector<std::string> CPStringTools::StringSplit(const std::string & inValue,
std::string value = inValue; std::string value = inValue;
std::vector<std::string> result; std::vector<std::string> result;
while (true) { while (true) {
unsigned int index = value.find(splitter); u32 index = value.find(splitter);
if (index == std::string::npos) { if (index == std::string::npos) {
result.push_back(value); result.push_back(value);
break; break;
@ -36,11 +36,11 @@ std::vector<std::string> CPStringTools::StringSplit(const std::string & inValue,
return result; return result;
} }
const char * CPStringTools::byte_to_binary(int x){ const char * CPStringTools::byte_to_binary(s32 x){
static char b[9]; static char b[9];
b[0] = '\0'; b[0] = '\0';
int z; s32 z;
for (z = 128; z > 0; z >>= 1) for (z = 128; z > 0; z >>= 1)
{ {
strcat(b, ((x & z) == z) ? "1" : "0"); strcat(b, ((x & z) == z) ? "1" : "0");

View File

@ -8,7 +8,7 @@ class CPStringTools{
static bool EndsWith(const std::string& a, const std::string& b); 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::vector<std::string> StringSplit(const std::string & inValue, const std::string & splitter);
static std::string removeCharFromString(std::string& input,char toBeRemoved); static std::string removeCharFromString(std::string& input,char toBeRemoved);
static const char *byte_to_binary(int x); static const char *byte_to_binary(s32 x);
static std::string strfmt(const char * format, ...); static std::string strfmt(const char * format, ...);
}; };

View File

@ -29,7 +29,7 @@ public:
typedef void (* Callback)(ControllerPatcherThread *thread, void *arg); typedef void (* Callback)(ControllerPatcherThread *thread, void *arg);
//! constructor //! constructor
ControllerPatcherThread(int iAttr, int iPriority = 16, int iStackSize = 0x8000, ControllerPatcherThread::Callback callback = NULL, void *callbackArg = NULL) ControllerPatcherThread(s32 iAttr, s32 iPriority = 16, s32 iStackSize = 0x8000, ControllerPatcherThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL) : pThread(NULL)
, pThreadStack(NULL) , pThreadStack(NULL)
, pCallback(callback) , pCallback(callback)
@ -49,7 +49,7 @@ public:
//! destructor //! destructor
virtual ~ControllerPatcherThread() {shutdownThread(); } virtual ~ControllerPatcherThread() {shutdownThread(); }
static ControllerPatcherThread *create(ControllerPatcherThread::Callback callback, void *callbackArg, int iAttr = eAttributeNone, int iPriority = 16, int iStackSize = 0x8000) 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) ); return ( new ControllerPatcherThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
} }
@ -67,7 +67,7 @@ public:
//! Resume thread //! Resume thread
virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); } virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); }
//! Set thread priority //! Set thread priority
virtual void setThreadPriority(int prio) { if(pThread) OSSetThreadPriority(pThread, prio); } virtual void setThreadPriority(s32 prio) { if(pThread) OSSetThreadPriority(pThread, prio); }
//! Check if thread is suspended //! Check if thread is suspended
virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; } virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; }
//! Check if thread is terminated //! Check if thread is terminated
@ -105,13 +105,13 @@ public:
eAttributePinnedAff = 0x10 eAttributePinnedAff = 0x10
}; };
private: private:
static int threadCallback(int argc, void *arg) static s32 threadCallback(s32 argc, void *arg)
{ {
//! After call to start() continue with the internal function //! After call to start() continue with the internal function
((ControllerPatcherThread *) arg)->executeThread(); ((ControllerPatcherThread *) arg)->executeThread();
return 0; return 0;
} }
int iAttributes; s32 iAttributes;
void *pThread; void *pThread;
u8 *pThreadStack; u8 *pThreadStack;
Callback pCallback; Callback pCallback;