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 "utils/CPStringTools.hpp"
int ConfigReader::numberValidFiles = 0;
s32 ConfigReader::numberValidFiles = 0;
ConfigReader *ConfigReader::instance = NULL;
ConfigReader::ConfigReader(){
@ -34,14 +34,14 @@ ConfigReader::ConfigReader(){
void ConfigReader::ReadAllConfigs(){
std::vector<std::string> fileList = ScanFolder();
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);
}
}
ConfigReader::~ConfigReader(){
if(HID_DEBUG) log_printf("~ConfigReader\n");
if(HID_DEBUG) log_printf("ConfigReader::~ConfigReader(line %d): ~ConfigReader\n",__LINE__);
freeFSHandles();
}
@ -58,8 +58,8 @@ void ConfigReader::freeFSHandles(){
}
// Mounting the sdcard without any external lib to be portable
int ConfigReader::InitSDCard(){
if(HID_DEBUG) log_printf("InitSDCard\n");
s32 ConfigReader::InitSDCard(){
if(HID_DEBUG) log_printf("ConfigReader::InitSDCard(line %d): InitSDCard\n",__LINE__);
char mountSrc[FS_MOUNT_SOURCE_SIZE];
char mountPath[FS_MAX_MOUNTPATH_SIZE];
@ -69,7 +69,7 @@ int ConfigReader::InitSDCard(){
this->pClient = malloc(FS_CLIENT_SIZE);
this->pCmd = malloc(FS_CMD_BLOCK_SIZE);
int status = 0;
s32 status = 0;
if (this->pClient && this->pCmd)
{
@ -88,11 +88,11 @@ int ConfigReader::InitSDCard(){
{
return 0;
}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;
}
}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;
}
}
@ -101,11 +101,11 @@ int ConfigReader::InitSDCard(){
std::vector<std::string> ConfigReader::ScanFolder(){
std::string path = CONTROLLER_PATCHER_PATH;
int dirhandle = 0;
if(HID_DEBUG) log_printf("ConfigReader::ScanFolder(): Opening %s\n",path.c_str());
s32 dirhandle = 0;
if(HID_DEBUG) log_printf("ConfigReader::ScanFolder(line %d): Opening %s\n",__LINE__,path.c_str());
std::vector<std::string> config_files;
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){
FSDirEntry dir_entry;
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(CPStringTools::EndsWith(std::string(dir_entry.name),".ini")){
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);
}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;
@ -127,7 +127,7 @@ std::vector<std::string> ConfigReader::ScanFolder(){
void ConfigReader::processFileList(std::vector<std::string> path){
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);
ConfigParser parser(result);
@ -136,26 +136,26 @@ void ConfigReader::processFileList(std::vector<std::string> path){
}
std::string ConfigReader::loadFileToString(std::string path){
int handle = 0;
int status = 0;
s32 handle = 0;
s32 status = 0;
std::string strBuffer;
FSStat stats;
if((status = FSGetStat(this->pClient,this->pCmd,path.c_str(),&stats,-1)) == FS_STATUS_OK){
char * file = (char *) malloc((sizeof(char)*stats.size)+1);
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 "";
}
file[stats.size] = '\0';
if((status = FSOpenFile(this->pClient,this->pCmd,path.c_str(),"r",&handle,-1)) == FS_STATUS_OK){
int total_read = 0;
int ret2 = 0;
s32 total_read = 0;
s32 ret2 = 0;
while ((ret2 = FSReadFile(pClient, pCmd, file+total_read, 1, stats.size-total_read, handle, 0, FS_RET_ALL_ERROR)) > 0){
total_read += ret2;
}
}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);
file=NULL;
return "";
@ -173,7 +173,7 @@ std::string ConfigReader::loadFileToString(std::string path){
strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t');
}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;

View File

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

View File

@ -33,9 +33,9 @@ static u32 last_button_hold[4] = {0,0,0,0};
static VPADData myVPADBuffer[4];
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(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;
memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything
@ -71,7 +71,7 @@ void ControllerPatcher::InitButtonMapping(){
}
void ControllerPatcher::ResetConfig(){
memset(&gControllerMapping,0,sizeof(ControllerMapping));
memset(&gControllerMapping,0,sizeof(gControllerMapping));
disableControllerMapping();
memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // 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);
gGamePadSlot = slotdata.deviceslot;
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);
gMouseSlot = slotdata.deviceslot;
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);
u32 keyboard_slot = slotdata.deviceslot;
@ -106,30 +106,30 @@ void ControllerPatcher::ResetConfig(){
gHID_LIST_KEYBOARD = keyboard_hid;
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);
u32 gc_slot = slotdata.deviceslot;
u32 gc_hid = slotdata.hidmask;
gHID_LIST_GC = gc_hid;
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);
u32 ds3_slot = slotdata.deviceslot;
u32 ds3_hid = slotdata.hidmask;
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);
u32 ds4_slot = slotdata.deviceslot;
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);
u32 xinput_slot = slotdata.deviceslot;
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[ds3_slot] = gHID_LIST_DS3;
@ -408,37 +408,37 @@ bool ControllerPatcher::Init(){
InitVPadFunctionPointers();
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){
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;
}
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;
ControllerPatcher::ResetConfig();
}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){
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();
int status = 0;
s32 status = 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();
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;
}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();
}
log_print("Initializing the data for button remapping\n");
log_printf("ControllerPatcher::Init(line %d): Initializing the data for button remapping\n",__LINE__);
InitButtonMapping();
if(!gHIDAttached){
@ -460,22 +460,21 @@ void ControllerPatcher::stopNetworkServer(){
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);
//Resetting the state of the last pressed data.
buttonRemapping_lastButtonsHold = 0;
memset(last_button_hold,0,sizeof(u32)*4);
memset(myVPADBuffer,0,sizeof(VPADData)*4);
memset(&gControllerMapping,0,sizeof(ControllerMapping));
memset(&gHIDClient,0,sizeof(HIDClient));
memset(gHID_Devices,0,sizeof(HID_DEVICE_DATA) * gHIDMaxDevices);
memset(gGamePadValues,0,sizeof(u32) * CONTRPS_MAX_VALUE);
memset(config_controller,0,sizeof(u8) * gHIDMaxDevices * CONTRPS_MAX_VALUE * 2);
memset(config_controller_hidmask,0,sizeof(u16) * gHIDMaxDevices);
memset(gNetworkController,0,sizeof(u16) * gHIDMaxDevices * HID_MAX_PADS_COUNT * 4);
memset(last_button_hold,0,sizeof(last_button_hold));
memset(myVPADBuffer,0,sizeof(myVPADBuffer));
memset(&gControllerMapping,0,sizeof(gControllerMapping));
memset(&gHIDClient,0,sizeof(gHIDClient));
memset(gHID_Devices,0,sizeof(gHID_Devices));
memset(gGamePadValues,0,sizeof(gGamePadValues));
memset(config_controller,0,sizeof(config_controller));
memset(config_controller_hidmask,0,sizeof(config_controller_hidmask));
memset(gNetworkController,0,sizeof(gNetworkController));
gConfig_done = HID_INIT_NOT_DONE;
gButtonRemappingConfigDone = 0;
@ -512,24 +511,24 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableControllerMapping()
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting(){
int res;
s32 res;
if(IMIsDimEnabled(&res) == 0){
if(res == 1){
log_print("Dim was orignally enabled!\n");
if(HID_DEBUG) log_print("ControllerPatcher::disableWiiUEnergySetting(): Dim was orignally enabled!\n");
gOriginalDimState = 1;
}
}
if(IMIsAPDEnabled(&res) == 0){
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;
}
}
IMDisableDim();
IMDisableAPD();
log_print("Disable Energy savers\n");
log_print("ControllerPatcher::disableWiiUEnergySetting(): Disable Energy savers\n");
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
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();
}
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();
}
return CONTROLLER_PATCHER_ERROR_NONE;
@ -551,8 +550,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UCo
ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type);
if(cm_map_pad == NULL){return CONTROLLER_PATCHER_ERROR_NULL_POINTER;}
memset(cm_map_pad,0,sizeof(ControllerMappingPAD));
memset(cm_map_pad,0,sizeof(*cm_map_pad));
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){
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]);
if(info != NULL && !info->active){
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);
if(cm_map_pad == NULL){return -1;}
int connected = -1;
for(int i =0;i<HID_MAX_DEVICES_PER_SLOT;i++){
s32 connected = -1;
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){
connected = i;
break;
@ -600,7 +598,7 @@ int ControllerPatcher::getActiveMappingSlot(UController_Type type){
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);
if(!padinfo){
return false;
@ -608,18 +606,18 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,int
if(padinfo->active){
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.pid = padinfo->vidpid.pid;
int res;
s32 res;
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
return false;
}
int hidmask = device_info.slotdata.hidmask;
int pad = padinfo->pad;
s32 hidmask = device_info.slotdata.hidmask;
s32 pad = padinfo->pad;
HID_Data * data_cur;
@ -632,7 +630,7 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,int
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);
if(cm_map_pad == NULL){return NULL;}
@ -651,7 +649,7 @@ HID_Mouse_Data * ControllerPatcher::getMouseData(){
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]);
if(!padinfo->active){
break;
@ -670,18 +668,18 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type
return CONTROLLER_PATCHER_ERROR_NONE;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,int array_size){
int hid = gHIDCurrentDevice;
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){
s32 hid = gHIDCurrentDevice;
HID_Data * data_cur;
VPADData pad_buffer;
VPADData * buffer = &pad_buffer;
int result = CONTROLLER_PATCHER_ERROR_NONE;
for(int i = 0;i< gHIDMaxDevices;i++){
s32 result = CONTROLLER_PATCHER_ERROR_NONE;
for(s32 i = 0;i< gHIDMaxDevices;i++){
if((hid & (1 << i)) != 0){
memset(buffer,0,sizeof(VPADData));
memset(buffer,0,sizeof(*buffer));
int newhid = (1 << i);
int deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid);
s32 newhid = (1 << i);
s32 deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid);
if(deviceslot < 0) continue;
DeviceInfo * deviceinfo = &(output[result].device_info);
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;
}
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;
buttondata[pad].btn_h = 0;
buttondata[pad].btn_d = 0;
buttondata[pad].btn_r = 0;
int res;
s32 res;
if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0){
continue;
@ -750,34 +748,34 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp
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(gControllerMapping.proController[chan].enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED;
VPADData * vpad_buffer = &myVPADBuffer[chan];
memset(vpad_buffer,0,sizeof(VPADData));
memset(vpad_buffer,0,sizeof(*vpad_buffer));
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];
if(!cm_map_pad_info.active){
continue;
}
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.pid = cm_map_pad_info.vidpid.pid;
int res;
s32 res;
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
log_printf("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res);
continue;
}
int hidmask = device_info.slotdata.hidmask;
int pad = cm_map_pad_info.pad;
s32 hidmask = device_info.slotdata.hidmask;
s32 pad = cm_map_pad_info.pad;
HID_Data * data_cur;
@ -791,7 +789,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
if(data_list.empty()){
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;
//make it configurable?
//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){
//if(gControllerMapping.gamepad.enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED;
int hidmask = 0;
int pad = 0;
s32 hidmask = 0;
s32 pad = 0;
ControllerMappingPAD cm_map_pad = gControllerMapping.gamepad;
std::vector<HID_Data *> data_list;
@ -824,7 +822,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
if (cm_map_pad.useAll == 1) {
data_list = ControllerPatcherHID::getHIDDataAll();
}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];
if(cm_map_pad_info.active == 1){
DeviceInfo device_info;
@ -841,7 +839,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
HID_Data * data;
pad = cm_map_pad_info.pad;
int res = ControllerPatcherHID::getHIDData(hidmask,pad,&data);
s32 res = ControllerPatcherHID::getHIDData(hidmask,pad,&data);
if(res < 0){
continue;
//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;
}
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(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;
memset(&new_data,0,sizeof(new_data));

View File

@ -39,6 +39,7 @@
#include "network/TCPServer.hpp"
#include "network/UDPServer.hpp"
#include "dynamic_libs/sys_functions.h"
#include "dynamic_libs/syshid_functions.h"
#include "dynamic_libs/socket_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.
**/
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.
**/
static int getActiveMappingSlot(UController_Type type);
static s32 getActiveMappingSlot(UController_Type type);
/**
@param type: The type of the 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.
**/
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.
@ -184,7 +185,7 @@ class ControllerPatcher{
@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.
@ -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.
**/
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.
@ -220,7 +221,7 @@ class ControllerPatcher{
@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..

View File

@ -74,37 +74,37 @@ void ConfigParser::setSlot(u16 newSlot){
bool ConfigParser::Init(){
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;
}
const char * line = contentLines[0].c_str();
int len = strlen(line);
s32 len = strlen(line);
std::string identify;
if(line[0] == '[' && line[len-1] == ']'){
identify = contentLines[0].substr(1,len-2);
}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;
}
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);
setType(PARSE_GAMEPAD);
}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);
setType(PARSE_MOUSE);
this->vid = HID_MOUSE_VID;
this->pid = HID_MOUSE_PID;
}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);
setType(PARSE_KEYBOARD);
this->vid = HID_KEYBOARD_VID;
this->pid = HID_KEYBOARD_PID;
}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));
setType(PARSE_CONTROLLER);
@ -122,16 +122,16 @@ bool ConfigParser::Init(){
void ConfigParser::parseSingleLine(std::string line){
std::vector<std::string> cur_values = CPStringTools::StringSplit(line,"=");
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;
}else{
u16 hid_slot = getSlot();
if(HID_DEBUG) log_printf("leftpart = \"%s\" \n",cur_values[0].c_str());
if(HID_DEBUG) log_printf("rightpart = \"%s\" \n",cur_values[1].c_str());
int keyslot = -1;
if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): leftpart = \"%s\" \n",__LINE__,cur_values[0].c_str());
if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): rightpart = \"%s\" \n",__LINE__,cur_values[1].c_str());
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){
keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]);
}else if(getType() == PARSE_MOUSE){
@ -140,14 +140,14 @@ void ConfigParser::parseSingleLine(std::string line){
keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]);
}
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;
bool valueSet = false;
if(cur_values[0].compare("DPAD_MODE") == 0){
const u8 * values_ = NULL;
if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL){
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][1] = values_[CONTRDPAD_MODE];
if(values_[CONTRDPAD_MASK] != 0x00){
@ -161,9 +161,9 @@ void ConfigParser::parseSingleLine(std::string line){
if(!valueSet){
if(getType() == PARSE_KEYBOARD){
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{
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;
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(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;
}
}else{
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;
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][1] = rightValue;
}
}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]);
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(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],",");
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;
}
@ -209,46 +209,46 @@ void ConfigParser::parseSingleLine(std::string line){
config_controller[hid_slot][keyslot][0] = firstValue;
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{
if(HID_DEBUG) log_printf("Found preset value!!\n");
if(HID_DEBUG) log_printf("ConfigParser::parseSingleLine(line %d): Found preset value!!\n",__LINE__);
}
}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(){
int slot = getSlot();
s32 slot = getSlot();
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][1] = CONTROLLER_PATCHER_INVALIDVALUE;
}
return true;
}
int ConfigParser::getSlotController(std::string identify){
if(HID_DEBUG) log_printf("Getting Controller Slot\n");
s32 ConfigParser::getSlotController(std::string identify){
if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Getting Controller Slot\n",__LINE__);
std::vector<std::string> values = CPStringTools::StringSplit(identify,",");
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;
}
int vid = getValueFromKeyValue(values[0],"VID","=");
s32 vid = getValueFromKeyValue(values[0],"VID","=");
if(vid < 0){
return HID_INVALID_SLOT;
}
int pid = getValueFromKeyValue(values[1],"PID","=");
s32 pid = getValueFromKeyValue(values[1],"PID","=");
if(pid < 0){
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->pid = pid;
@ -256,11 +256,11 @@ int ConfigParser::getSlotController(std::string identify){
memset(&deviceinfo,0,sizeof(deviceinfo));
deviceinfo.vidpid.vid = vid;
deviceinfo.vidpid.pid = pid;
int result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo);
int slot = deviceinfo.slotdata.deviceslot;
int hid = 0;
s32 result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo);
s32 slot = deviceinfo.slotdata.deviceslot;
s32 hid = 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;
ControllerPatcherUtils::getNextSlotData(&slotdata);
@ -269,10 +269,10 @@ int ConfigParser::getSlotController(std::string identify){
hid = slotdata.hidmask;
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;
}
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][1] = (vid & 0x00FF);
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_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;
if(HID_DEBUG) log_printf("Saved the hid\n");
if(HID_DEBUG) log_printf("ConfigParser::getSlotController(line %d): Saved the hid\n",__LINE__);
}else{
if(slot < gHIDMaxDevices){
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("We already have data of this controller, lets modify it\n");
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));
log_printf("ConfigParser::getSlotController(line %d): We already have data of this controller, lets modify it\n",__LINE__);
}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;
}
}
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;
}
bool ConfigParser::parseIni(){
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){
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++;
}
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]);
}
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;
}
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);
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;
}
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;
}
char * ptr;
int value = strtol(string_value[1].c_str(),&ptr,16);
s32 value = strtol(string_value[1].c_str(),&ptr,16);
return value;
}

View File

@ -59,11 +59,11 @@ private:
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();

View File

@ -28,7 +28,7 @@ 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){
@ -40,7 +40,7 @@ const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> valu
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(presetDS3Values,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.
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){
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_R_STICK_X ||
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(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][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
@ -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;
it = values.find(nameOfString);
if (it != values.end()){
@ -94,12 +94,12 @@ int ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string n
return -1;
}
int ConfigValues::getPresetValueEx(std::string possibleString){
int rightValue = -1;
s32 ConfigValues::getPresetValueEx(std::string possibleString){
s32 rightValue = -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){
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;
}

View File

@ -61,7 +61,7 @@ private:
/**
Returns -1 if not found
**/
static int getKeySlotGamePad(std::string possibleValue)
static s32 getKeySlotGamePad(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -70,7 +70,7 @@ private:
/**
Returns -1 if not found
**/
static int getKeySlotMouse(std::string possibleValue)
static s32 getKeySlotMouse(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -80,7 +80,7 @@ private:
/**
Returns -1 if not found
**/
static int getKeySlotDefaultSingleValue(std::string possibleValue)
static s32 getKeySlotDefaultSingleValue(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -90,7 +90,7 @@ private:
/**
Returns -1 if not found
**/
static int getKeySlotDefaultPairedValue(std::string possibleValue)
static s32 getKeySlotDefaultPairedValue(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -100,7 +100,7 @@ private:
/**
Returns -1 if not found
**/
static int getPresetValuesKeyboard(std::string possibleValue)
static s32 getPresetValuesKeyboard(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -110,7 +110,7 @@ private:
/**
Returns -1 if not found
**/
static int getPresetValue(std::string possibleValue)
static s32 getPresetValue(std::string possibleValue)
{
ConfigValues * cur_instance = getInstance();
if(cur_instance == NULL) return -1;
@ -120,7 +120,7 @@ private:
/**
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();
if(cur_instance == NULL) return -1;
@ -165,13 +165,14 @@ private:
std::map<std::string,const u8*> presetXInputValues;
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(){
log_printf("ConfigValues::InitValues: Init values for the configuration\n");
CONTPRStringToValue["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A;
CONTPRStringToValue["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B;
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_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_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;
@ -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_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;
log_printf("Value init done\n");
}
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 setIfValueIsAControllerPresetEx(std::string value,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,s32 slot,s32 keyslot);
void addDeviceNameEx(u16 vid,u16 pid,std::string value);
std::string getStringByVIDPIDEx(u16 vid,u16 pid);

View File

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

View File

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

View File

@ -44,7 +44,7 @@
ControllerPatcherThread * TCPServer::pThread = NULL;
TCPServer * TCPServer::instance = NULL;
TCPServer::TCPServer(int port){
TCPServer::TCPServer(s32 port){
this->sockfd = -1;
this->clientfd = -1;
memset(&(this->sock_addr),0,sizeof(this->sock_addr));
@ -54,14 +54,14 @@ TCPServer::TCPServer(int port){
TCPServer::~TCPServer(){
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);
exitThread = 1;
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;
}
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;
}
@ -81,19 +81,19 @@ void TCPServer::StartTCPThread(TCPServer * server){
TCPServer::pThread->resumeThread();
}
void TCPServer::AttachDetach(int attach){
void TCPServer::AttachDetach(s32 attach){
if(HID_DEBUG){
if(attach){
log_printf("TCPServer: Network Attach\n");
log_printf("TCPServer::AttachDetach(line %d): Network Attach\n",__LINE__);
}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(int j= 0;j< HID_MAX_PADS_COUNT;j++){
for(s32 i= 0;i< gHIDMaxDevices;i++){
for(s32 j= 0;j< HID_MAX_PADS_COUNT;j++){
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;
memset(&device,0,sizeof(device));
@ -110,9 +110,9 @@ void TCPServer::AttachDetach(int attach){
if(HID_DEBUG){
if(attach){
log_printf("TCPServer: Network Attach DONE!\n");
log_printf("TCPServer::AttachDetach(line %d): Network Attach DONE!\n",__LINE__);
}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));
}
int TCPServer::RunTCP(){
int ret;
s32 TCPServer::RunTCP(){
s32 ret;
while (1) {
if(exitThread) break;
ret = ControllerPatcherNet::checkbyte(clientfd);
@ -135,28 +135,28 @@ int TCPServer::RunTCP(){
//log_printf("got byte from tcp! %01X\n",ret);
switch (ret) {
case WIIU_CP_TCP_ATTACH: { /*attach */
int handle;
s32 handle;
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
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;
}
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 pid = 0;
ret = ControllerPatcherNet::recvwait(clientfd, &vid, 2);
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;
}
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);
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;
}
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;
memset(&device,0,sizeof(device));
device.handle = handle;
@ -168,81 +168,81 @@ int TCPServer::RunTCP(){
my_cb_user * user = NULL;
ControllerPatcherHID::externAttachDetachCallback(&device,1);
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() Error in %02X: Config for the controller is missing.\n",WIIU_CP_TCP_ATTACH);
log_printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_ATTACH,handle,&user);
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)){
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;
}
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;
}
if(user != NULL){
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;
}
ret = ControllerPatcherNet::sendwait(clientfd,&user->slotdata.deviceslot,2);
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;
}
ret = ControllerPatcherNet::sendwait(clientfd,&user->pad_slot,1);
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;
}
}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)){
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 -1;
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_PID] = device.pid;
gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_ACTIVE] = 1;
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;
}
case WIIU_CP_TCP_DETACH: { /*detach */
int handle;
s32 handle;
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
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;
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;
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;
break;
}
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;
break;
}
int deviceslot = user->slotdata.deviceslot;
if(HID_DEBUG) log_printf("TCPServer: device slot is: %d , pad slot is: %d\n",deviceslot,user->pad_slot);
s32 deviceslot = user->slotdata.deviceslot;
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;
int result;
s32 result;
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;
break;
}
@ -257,13 +257,13 @@ int TCPServer::RunTCP(){
ControllerPatcherHID::externAttachDetachCallback(&device,DETACH);
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;
}
case WIIU_CP_TCP_PING: { /*ping*/
if(HID_DEBUG) log_printf("TCPServer: GOT PING\n");
int ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_PONG);
if(ret < 0){ log_printf("TCPServer::RunTCP() Error in %02X: sendbyte PONG\n"); return -1;}
if(HID_DEBUG) log_printf("TCPServer::RunTCP(line %d): Got Ping, sending now a Pong\n",__LINE__);
s32 ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_PONG);
if(ret < 0){ log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendbyte PONG\n",__LINE__); return -1;}
break;
}
@ -281,7 +281,7 @@ void TCPServer::ErrorHandling(){
}
void TCPServer::DoTCPThreadInternal(){
int ret;
s32 ret;
s32 len;
while (1) {
if(exitThread) break;
@ -292,7 +292,7 @@ void TCPServer::DoTCPThreadInternal(){
this->sockfd = ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(ret == -1){ ErrorHandling(); continue;}
int enable = 1;
s32 enable = 1;
setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
@ -302,20 +302,19 @@ void TCPServer::DoTCPThreadInternal(){
if(ret < 0){ ErrorHandling(); continue;}
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;
len = 16;
clientfd = ret = accept(sockfd, (sockaddr *)&(sock_addr), &len);
if(HID_DEBUG) log_printf("TCPServer::DoTCPThreadInternal: Connection accepted\n");
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!
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
RunTCP();
@ -324,9 +323,9 @@ void TCPServer::DoTCPThreadInternal(){
}
clientfd = -1;
}while(0);
log_printf("TCPServer::DoTCPThreadInternal(line %d): Connection closed\n",__LINE__);
TCPServer::DetachAndDelete(); //Clear connected controller
CloseSockets();
if(HID_DEBUG) log_printf("TCPServer: Connection closed\n");
continue;
}
}

View File

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

View File

@ -25,8 +25,8 @@
ControllerPatcherThread * UDPServer::pThread = NULL;
UDPServer * UDPServer::instance = NULL;
UDPServer::UDPServer(int port){
int ret;
UDPServer::UDPServer(s32 port){
s32 ret;
struct sockaddr_in addr;
addr.sin_family = AF_INET;
@ -35,7 +35,7 @@ UDPServer::UDPServer(int port){
this->sockfd = ret = socket(AF_INET, SOCK_DGRAM, 0);
if(ret == -1) return;
int enable = 1;
s32 enable = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
ret = bind(sockfd, (sockaddr *)&addr, 16);
if(ret < 0) return;
@ -47,7 +47,6 @@ UDPServer::~UDPServer(){
ControllerPatcherThread * pThreadPointer = UDPServer::pThread;
if(pThreadPointer != NULL){
exitThread = 1;
log_printf("%08X\n",pThreadPointer);
if(pThreadPointer != NULL){
delete pThreadPointer;
UDPServer::pThread = NULL;
@ -57,7 +56,7 @@ UDPServer::~UDPServer(){
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();
}
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){
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;
}
memcpy(target,(void*)((u32)source+(*offset)),typesize);
@ -84,23 +83,23 @@ void UDPServer::DoUDPThread(ControllerPatcherThread *thread, void *arg){
void UDPServer::DoUDPThreadInternal(){
u8 buffer[MAX_UDP_SIZE];
int n;
s32 n;
my_cb_user user;
while(1){
//int usingVar = exitThread;
//s32 usingVar = exitThread;
if(exitThread)break;
memset(buffer,0,MAX_UDP_SIZE);
n = recv(sockfd,buffer,MAX_UDP_SIZE,0);
if (n < 0){
int errno_ = errno;
s32 errno_ = errno;
usleep(2000);
if(errno_ != 11 && errno_ != 9){
break;
}
continue;
}
int bufferoffset = 0;
s32 bufferoffset = 0;
u8 type;
memcpy((void *)&type,buffer,sizeof(type));
bufferoffset += sizeof(type);
@ -109,9 +108,9 @@ void UDPServer::DoUDPThreadInternal(){
u8 count_commands;
memcpy((void *)&count_commands,buffer+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 hid;
u8 padslot;
@ -124,7 +123,7 @@ void UDPServer::DoUDPThreadInternal(){
if(!cpyIncrementBufferOffset((void *)&datasize, (void *)buffer,&bufferoffset,sizeof(datasize), n))continue;
u8 * databuffer = (u8*) malloc(datasize * sizeof(u8));
if(!databuffer){
log_printf("UDPServer::DoUDPThreadInternal(): Allocating memory failed\n");
log_printf("UDPServer::DoUDPThreadInternal(line %d): Allocating memory failed\n",__LINE__);
continue;
}
@ -138,7 +137,7 @@ void UDPServer::DoUDPThreadInternal(){
user.slotdata.hidmask = hid;
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{
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();
void StartUDPThread(UDPServer * server);
static void DoUDPThread(ControllerPatcherThread *thread, void *arg);
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 int exitThread = 0;
volatile s32 sockfd = -1;
volatile s32 exitThread = 0;
static UDPServer *instance;
static ControllerPatcherThread *pThread;

View File

@ -28,14 +28,13 @@
* public implementation for the network controller
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, unsigned int attach){
log_printf("ControllerPatcherHID::externAttachDetachCallback called\n");
s32 ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, u32 attach){
HIDClient client;
memset(&client,0,sizeof(client));
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);
}
@ -43,11 +42,11 @@ void ControllerPatcherHID::externHIDReadCallback(unsigned int handle, unsigned c
* 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);
}
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){
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)
{
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
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
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){
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("sub class %02x\n", p_device->sub_class);
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(!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;
memset(&device_info,0,sizeof(DeviceInfo));
@ -143,18 +142,18 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
slotdata->deviceslot = gMouseSlot;
//log_printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot);
}else{
int ret;
s32 ret;
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;
}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(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){
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;
gHIDAttached |= 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){
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
@ -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;
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))){
failed = 0;
pad_count |= (1 << i);
@ -192,7 +191,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
}
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){
free(buf);
buf = NULL;
@ -212,11 +211,11 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
usr->pads_per_device = pads_per_device;
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));
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].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));
}
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
//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{
my_cb_user * user_data = NULL;
int founddata = 0;
for(int i = 0;i<HID_MAX_PADS_COUNT;i++){
s32 founddata = 0;
for(s32 i = 0;i<HID_MAX_PADS_COUNT;i++){
if(gHID_Devices[slotdata->deviceslot].pad_data[i].handle == p_device->handle){
gHID_Devices[slotdata->deviceslot].pad_data[i].handle = 0;
@ -286,7 +285,7 @@ int ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
free(user_data);
user_data = NULL;
}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;
}
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;
}
}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{
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;
}
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);
if(usr->slotdata.hidmask == gHID_LIST_GC){
HID_Data * data_ptr = NULL;
//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]);
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.
@ -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("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++;
@ -334,8 +333,8 @@ void ControllerPatcherHID::HIDReadCallback(unsigned int handle, unsigned char *b
HIDGCRumble(handle,usr);
}else if(usr->slotdata.hidmask != 0){
int dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD;
int skip = 0;
s32 dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD;
s32 skip = 0;
//Input filter
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;
HID_Data * data_cur;
int buttons_hold;
s32 buttons_hold;
for(u32 i = 0;i<data.size();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);
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_d |= (buttons_hold & (~last_realbuttons));
@ -439,17 +438,17 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
}
std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
int hid = gHIDCurrentDevice;
s32 hid = gHIDCurrentDevice;
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){
int cur_hidmask = config_controller_hidmask[i];
for(int pad = 0; pad < HID_MAX_PADS_COUNT; pad++){
int res;
s32 cur_hidmask = config_controller_hidmask[i];
for(s32 pad = 0; pad < HID_MAX_PADS_COUNT; pad++){
s32 res;
HID_Data * new_data = NULL;
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;
}
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
*/
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(!(hidmask & gHIDCurrentDevice)) return CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED;
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){
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){
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;
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
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){
int rumblechanged = 0;
void ControllerPatcherHID::HIDGCRumble(u32 handle,my_cb_user *usr){
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]);
if(data_ptr->rumbleActive != usr->rumblestatus[i]){
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){
int rumblechanged = 0;
void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){
s32 rumblechanged = 0;
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[pad]);
if(data_ptr->rumbleActive != usr->rumblestatus[pad]){
usr->rumblestatus[pad] = data_ptr->rumbleActive;
@ -538,7 +537,7 @@ static u8 ds3_rumble_Report[48] =
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);
if (rumble) {

View File

@ -41,34 +41,34 @@ class ControllerPatcherHID{
friend class ControllerPatcher;
friend class ControllerPatcherUtils;
public:
static int externAttachDetachCallback(HIDDevice *p_device, unsigned int attach);
static void externHIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr);
static s32 externAttachDetachCallback(HIDDevice *p_device, u32 attach);
static void externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr);
private:
static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADData * buffer,std::vector<HID_Data *>& data);
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
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
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
*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
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 myHIDReadCallback(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(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 void HIDReadCallback(unsigned int handle, unsigned char *buf, unsigned int bytes_transfered, my_cb_user * usr);
static s32 AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach);
static void HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr);
};
#endif /* _CONTROLLER_PATCHER_HID_H_ */

View File

@ -21,9 +21,9 @@
#include "utils/logger.h"
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(int handle, my_cb_user ** data){
for(int i = 0;i< gHIDMaxDevices;i++){
for(int j = 0;j<4;j++){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){
for(s32 i = 0;i< gHIDMaxDevices;i++){
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);
if(gHID_Devices[i].pad_data[j].handle == (u32)handle){
*data = gHID_Devices[i].pad_data[j].user_data;
@ -37,12 +37,12 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(int h
* 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;
int deviceslot = data->slotdata.deviceslot;
s32 deviceslot = data->slotdata.deviceslot;
int result = -1;
s32 result = -1;
do{
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];
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int cur_config = 0;
s32 cur_config = 0;
if(VPADButton == 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){
int contrps_value = 0;
s32 contrps_value = 0;
if(VPADButton == VPAD_BUTTON_LEFT){
contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT;
}else if(VPADButton == VPAD_BUTTON_RIGHT){
@ -168,7 +168,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
}
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(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]){
result = 1;
@ -222,16 +222,16 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
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;
u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int hidmask = data->slotdata.hidmask;
int deviceslot = data->slotdata.deviceslot;
s32 hidmask = data->slotdata.hidmask;
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(hidmask & gHID_LIST_KEYBOARD){
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;
}
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;
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){
break;
}else if (keyboardData[i] == key){
@ -261,7 +261,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsi
* 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;
u32 new_value = VPADButton;
@ -292,14 +292,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADDat
* 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 (!(((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;
}else{
int deviceslot = getDeviceSlot(hidmask);
s32 deviceslot = getDeviceSlot(hidmask);
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){
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 (!(((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;
@ -417,7 +417,7 @@ Vec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADData * buffer){
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(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];
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_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){
@ -537,10 +537,10 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA
u32 emulatedSticks = 0;
int 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;
int 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 l_x_full = (buffer->lstick.x > 0.5f || buffer->lstick.x < -0.5f)? 1:0;
s32 l_y_full = (buffer->lstick.y > 0.5f || buffer->lstick.y < -0.5f)? 1:0;
s32 r_x_full = (buffer->rstick.x > 0.5f || buffer->rstick.x < -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)){
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){
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
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)){
HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data;
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
int 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 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f));
s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f));
buffer->tpdata.x = x_mouse;
buffer->tpdata.y = y_mouse;
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){
int hidmask = data->slotdata.hidmask;
s32 hidmask = data->slotdata.hidmask;
if(hidmask & gHID_LIST_KEYBOARD){
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(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){
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){
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;
}
}
@ -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){
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_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){
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;
@ -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){
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_d = 0;
@ -805,7 +805,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADD
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(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;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(int hidmask){
for(int i = 0;i < gHIDMaxDevices;i++){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(s32 hidmask){
for(s32 i = 0;i < gHIDMaxDevices;i++){
if(hidmask & config_controller_hidmask[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){
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_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);
@ -855,7 +855,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSl
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(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];
@ -864,14 +864,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot
return CONTROLLER_PATCHER_ERROR_NONE;
}
int ControllerPatcherUtils::getPadSlotInAdapter(int deviceslot, u8 * input_data){
int slot_incr = 0;
s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data){
s32 slot_incr = 0;
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){
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(input_data[config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0]] == config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][1]){
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
**/
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.
@ -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 **.
**/
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.
@ -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 *.
**/
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.
*
@ -92,7 +92,7 @@ class ControllerPatcherUtils{
* \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.
@ -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.
*
*/
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.
@ -112,7 +112,7 @@ class ControllerPatcherUtils{
* \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
@ -128,7 +128,7 @@ class ControllerPatcherUtils{
* \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
@ -154,7 +154,7 @@ class ControllerPatcherUtils{
\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.
@ -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.
**/
static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(int hidmask);
static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(s32 hidmask);
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* 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.
**/
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.
@ -304,7 +304,7 @@ class ControllerPatcherUtils{
\param current input data
\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

View File

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

View File

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