mirror of
https://github.com/Maschell/controller_patcher.git
synced 2024-11-21 19:49:16 +01:00
Improved the logging, added more checks while parsing the ini
This commit is contained in:
parent
3bf07857be
commit
c9284c0238
@ -35,14 +35,14 @@ ConfigReader::ConfigReader(){
|
||||
void ConfigReader::ReadAllConfigs(){
|
||||
std::vector<std::string> fileList = ScanFolder();
|
||||
if(fileList.size() > 0){
|
||||
if(HID_DEBUG){ log_printf("ConfigReader::ConfigReader(line %d): Found %d config files\n",__LINE__,fileList.size()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found %d config files\n",fileList.size()); }
|
||||
processFileList(fileList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ConfigReader::~ConfigReader(){
|
||||
if(HID_DEBUG){ log_printf("ConfigReader::~ConfigReader(line %d): ~ConfigReader\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("~ConfigReader\n"); }
|
||||
freeFSHandles();
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ void ConfigReader::freeFSHandles(){
|
||||
|
||||
// Mounting the sdcard without any external lib to be portable
|
||||
s32 ConfigReader::InitSDCard(){
|
||||
if(HID_DEBUG){ log_printf("ConfigReader::InitSDCard(line %d): InitSDCard\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("InitSDCard\n"); }
|
||||
|
||||
char mountSrc[FS_MOUNT_SOURCE_SIZE];
|
||||
char mountPath[FS_MAX_MOUNTPATH_SIZE];
|
||||
@ -89,11 +89,11 @@ s32 ConfigReader::InitSDCard(){
|
||||
{
|
||||
return 0;
|
||||
}else{
|
||||
log_printf("ConfigReader::InitSDCard(line %d): error: FSMount failed %d\n",__LINE__,status);
|
||||
DEBUG_FUNCTION_LINE("error: FSMount failed %d\n",status);
|
||||
return status;
|
||||
}
|
||||
}else{
|
||||
log_printf("ConfigReader::InitSDCard(line %d): error: FSGetMountSource failed %d\n",__LINE__,status);
|
||||
DEBUG_FUNCTION_LINE("error: FSGetMountSource failed %d\n",status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ s32 ConfigReader::InitSDCard(){
|
||||
std::vector<std::string> ConfigReader::ScanFolder(){
|
||||
std::string path = CONTROLLER_PATCHER_PATH;
|
||||
s32 dirhandle = 0;
|
||||
if(HID_DEBUG){ log_printf("ConfigReader::ScanFolder(line %d): Opening %s\n",__LINE__,path.c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Opening %s\n",path.c_str()); }
|
||||
std::vector<std::string> config_files;
|
||||
if (this->pClient && this->pCmd){
|
||||
s32 status = 0;
|
||||
@ -114,13 +114,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("ConfigReader::ScanFolder(line %d): %s \n",__LINE__,full_path.c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found ini: %s \n",full_path.c_str()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
FSCloseDir(this->pClient,this->pCmd,dirhandle,-1);
|
||||
}else{
|
||||
log_printf("ConfigReader::ScanFolder(line %d): Failed to open %s!\n",__LINE__,path.c_str());
|
||||
DEBUG_FUNCTION_LINE("Failed to open folder %s!\n",path.c_str());
|
||||
}
|
||||
}
|
||||
return config_files;
|
||||
@ -128,7 +128,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("ConfigReader::processFileList(line %d): Reading %s\n",__LINE__,it->c_str());
|
||||
DEBUG_FUNCTION_LINE("Reading %s\n",it->c_str());
|
||||
std::string result = loadFileToString(*it);
|
||||
|
||||
ConfigParser parser(result);
|
||||
@ -139,12 +139,12 @@ void ConfigReader::processFileList(std::vector<std::string> path){
|
||||
std::string ConfigReader::loadFileToString(std::string path){
|
||||
s32 handle = 0;
|
||||
s32 status = 0;
|
||||
std::string strBuffer;
|
||||
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_printf("ConfigReader::loadFileToString(line %d): error: Failed to allocate space for reading the file\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("error: Failed to allocate space for reading the file\n");
|
||||
return "";
|
||||
}
|
||||
file[stats.size] = '\0';
|
||||
@ -156,7 +156,7 @@ std::string ConfigReader::loadFileToString(std::string path){
|
||||
}
|
||||
|
||||
}else{
|
||||
log_printf("ConfigReader::loadFileToString(line %d): error: (FSOpenFile) Couldn't open file (%s), error: %d",__LINE__,path.c_str(),status);
|
||||
DEBUG_FUNCTION_LINE("error: (FSOpenFile) Couldn't open file (%s), error: %d",path.c_str(),status);
|
||||
free(file);
|
||||
file=NULL;
|
||||
return "";
|
||||
@ -174,7 +174,7 @@ std::string ConfigReader::loadFileToString(std::string path){
|
||||
strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t');
|
||||
|
||||
}else{
|
||||
log_printf("ConfigReader::loadFileToString(line %d): error: (GetStat) Couldn't open file (%s), error: %d",__LINE__,path.c_str(),status);
|
||||
DEBUG_FUNCTION_LINE("error: (GetStat) Couldn't open file (%s), error: %d",path.c_str(),status);
|
||||
}
|
||||
|
||||
return strBuffer;
|
||||
|
@ -40,9 +40,9 @@ static u32 last_button_hold[4] = {0,0,0,0};
|
||||
static VPADData myVPADBuffer[4];
|
||||
|
||||
void ControllerPatcher::InitButtonMapping(){
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::InitButtonMapping(line %d): Init called \n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Init called \n"); }
|
||||
if(!gButtonRemappingConfigDone){
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::InitButtonMapping(line %d): Remapping is running! \n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Remapping is running! \n"); }
|
||||
gButtonRemappingConfigDone = 1;
|
||||
memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything
|
||||
|
||||
@ -105,12 +105,12 @@ void ControllerPatcher::ResetConfig(){
|
||||
gHIDRegisteredDevices = 0;
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
gGamePadSlot = slotdata.deviceslot;
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::ResetConfig(line %d): Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
gMouseSlot = slotdata.deviceslot;
|
||||
gHID_LIST_MOUSE = slotdata.hidmask;
|
||||
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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 keyboard_slot = slotdata.deviceslot;
|
||||
@ -118,36 +118,36 @@ void ControllerPatcher::ResetConfig(){
|
||||
gHID_LIST_KEYBOARD = keyboard_hid;
|
||||
gHID_SLOT_KEYBOARD = keyboard_slot;
|
||||
|
||||
if(HID_DEBUG){ 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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); }
|
||||
|
||||
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("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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 ds3_slot = slotdata.deviceslot;
|
||||
u32 ds3_hid = slotdata.hidmask;
|
||||
gHID_LIST_DS3 = ds3_hid;
|
||||
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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS3-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 ds4_slot = slotdata.deviceslot;
|
||||
u32 ds4_hid = slotdata.hidmask;
|
||||
gHID_LIST_DS4 = ds4_hid;
|
||||
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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS4-Config. HID-Mask %s Device-Slot: %d\n",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("ControllerPatcher::ResetConfig(line %d): Register XInput-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(xinput_hid),xinput_slot); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register XInput-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(xinput_hid),xinput_slot); }
|
||||
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
u32 switch_pro_slot = slotdata.deviceslot;
|
||||
gHID_LIST_SWITCH_PRO = slotdata.hidmask;
|
||||
log_printf("ControllerPatcher::ResetConfig(line %d): Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot);
|
||||
DEBUG_FUNCTION_LINE("Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",CPStringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot);
|
||||
|
||||
|
||||
config_controller_hidmask[gc_slot] = gHID_LIST_GC;
|
||||
@ -486,39 +486,39 @@ bool ControllerPatcher::Init(){
|
||||
gSamplingCallback = NULL;
|
||||
}
|
||||
}
|
||||
log_printf("ControllerPatcher::Init(line %d): Found the gSamplingCallback at %08X \n",__LINE__,gSamplingCallback);
|
||||
DEBUG_FUNCTION_LINE("Found the gSamplingCallback at %08X \n",gSamplingCallback);
|
||||
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::Init(line %d): Init called! \n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Init called! \n"); }
|
||||
|
||||
if(syshid_handle == 0){
|
||||
log_printf("ControllerPatcher::Init(line %d): Failed to load the HID API \n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Failed to load the HID API \n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(gConfig_done == HID_INIT_NOT_DONE){
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::Init(line %d): First time calling the Init\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("First time calling the Init\n"); }
|
||||
gConfig_done = HID_INIT_DONE;
|
||||
ControllerPatcher::ResetConfig();
|
||||
}else{
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::Init(line %d): ControllerPatcher::Init(): Config already done!\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Config already done!\n"); }
|
||||
}
|
||||
|
||||
if(gConfig_done != HID_SDCARD_READ){
|
||||
log_printf("ControllerPatcher::Init(line %d): Reading config files from SD Card\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Reading config files from SD Card\n");
|
||||
ConfigReader* reader = ConfigReader::getInstance();
|
||||
s32 status = 0;
|
||||
if((status = reader->InitSDCard()) == 0){
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::Init(line %d): SD Card mounted for controller config!\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE(" SD Card mounted for controller config!\n"); }
|
||||
reader->ReadAllConfigs();
|
||||
log_printf("ControllerPatcher::Init(line %d): Done with reading config files from SD Card\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Done with reading config files from SD Card\n");
|
||||
gConfig_done = HID_SDCARD_READ;
|
||||
}else{
|
||||
log_printf("ControllerPatcher::Init(line %d): SD mounting failed! %d\n",__LINE__,status);
|
||||
DEBUG_FUNCTION_LINE("SD mounting failed! %d\n",status);
|
||||
}
|
||||
ConfigReader::destroyInstance();
|
||||
}
|
||||
|
||||
log_printf("ControllerPatcher::Init(line %d): Initializing the data for button remapping\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Initializing the data for button remapping\n");
|
||||
InitButtonMapping();
|
||||
|
||||
if(!gHIDAttached){
|
||||
@ -530,20 +530,20 @@ bool ControllerPatcher::Init(){
|
||||
|
||||
void ControllerPatcher::startNetworkServer(){
|
||||
if(!gNetworkControllerActivated) return;
|
||||
log_printf("ControllerPatcher::startNetworkServer(line %d) statedNetworkServer! \n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("statedNetworkServer! \n");
|
||||
UDPServer::getInstance();
|
||||
TCPServer::getInstance();
|
||||
}
|
||||
|
||||
void ControllerPatcher::stopNetworkServer(){
|
||||
log_printf("ControllerPatcher::stopNetworkServer(line %d) called! \n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("called! \n");
|
||||
UDPServer::destroyInstance();
|
||||
UDPClient::destroyInstance();
|
||||
TCPServer::destroyInstance();
|
||||
}
|
||||
|
||||
void ControllerPatcher::DeInit(){
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcher::DeInit(line %d) called! \n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("called! \n"); }
|
||||
|
||||
if(gHIDAttached) HIDDelClient(&gHIDClient);
|
||||
|
||||
@ -604,21 +604,21 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting()
|
||||
s32 res;
|
||||
if(IMIsDimEnabled(&res) == 0){
|
||||
if(res == 1){
|
||||
if(HID_DEBUG){ log_print("ControllerPatcher::disableWiiUEnergySetting(): Dim was orignally enabled!\n"); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Dim was orignally enabled!\n"); }
|
||||
gOriginalDimState = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(IMIsAPDEnabled(&res) == 0){
|
||||
if(res == 1){
|
||||
if(HID_DEBUG){ log_print("ControllerPatcher::disableWiiUEnergySetting(): Auto power down was orignally enabled!\n"); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Auto power down was orignally enabled!\n"); }
|
||||
gOriginalAPDState = 1;
|
||||
}
|
||||
}
|
||||
|
||||
IMDisableDim();
|
||||
IMDisableAPD();
|
||||
log_print("ControllerPatcher::disableWiiUEnergySetting(): Disable Energy savers\n");
|
||||
DEBUG_FUNCTION_LINE("Disable Energy savers\n");
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -626,11 +626,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("ControllerPatcher::restoreWiiUEnergySetting(): Auto shutdown was on before using HID to VPAD. Setting it to on again.\n");
|
||||
DEBUG_FUNCTION_LINE("Auto shutdown was on before using HID to VPAD. Setting it to on again.\n");
|
||||
IMEnableAPD();
|
||||
}
|
||||
if(gOriginalDimState == 1){
|
||||
log_print("ControllerPatcher::restoreWiiUEnergySetting(): Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n");
|
||||
DEBUG_FUNCTION_LINE("Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n");
|
||||
IMEnableDim();
|
||||
}
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
@ -859,7 +859,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
|
||||
|
||||
s32 res;
|
||||
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
|
||||
log_printf("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res);
|
||||
DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -869,7 +869,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
|
||||
HID_Data * data_cur;
|
||||
|
||||
if((res = ControllerPatcherHID::getHIDData(hidmask,pad,&data_cur)) < 0) {
|
||||
//log_printf("ControllerPatcherHID::getHIDData(hidmask,pad,&data_cur)) = %d\n",res);
|
||||
//DEBUG_FUNCTION_LINE("ControllerPatcherHID::getHIDData(hidmask,pad,&data_cur)) = %d\n",res);
|
||||
continue;
|
||||
}
|
||||
data_list.push_back(data_cur);
|
||||
@ -987,7 +987,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADData
|
||||
if((buffer->btns_d & VPAD_STICK_L_EMULATION_UP) == VPAD_STICK_L_EMULATION_UP) strcat(output,"LE_Up ");
|
||||
if((buffer->btns_d & VPAD_STICK_L_EMULATION_DOWN) == VPAD_STICK_L_EMULATION_DOWN) strcat(output,"LE_Down ");
|
||||
|
||||
log_printf("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->lstick.x,buffer->lstick.y,buffer->rstick.x,buffer->rstick.y);
|
||||
DEBUG_FUNCTION_LINE("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->lstick.x,buffer->lstick.y,buffer->rstick.x,buffer->rstick.y);
|
||||
}
|
||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||
}
|
||||
|
@ -24,8 +24,9 @@ ConfigParser::ConfigParser(std::string configData){
|
||||
this->content = configData;
|
||||
this->contentLines = CPStringTools::StringSplit(content, "\n");
|
||||
|
||||
if(contentLines.empty())
|
||||
if(contentLines.empty()){
|
||||
return;
|
||||
}
|
||||
|
||||
//remove the comments and make everything uppercase
|
||||
for(u32 i = 0; i < contentLines.size(); i++){
|
||||
@ -70,38 +71,42 @@ void ConfigParser::setSlot(u16 newSlot){
|
||||
|
||||
bool ConfigParser::Init(){
|
||||
if(contentLines.size() == 0){
|
||||
log_printf("ConfigParser::Init(line %d): Files seems to be empty. Make sure to have a proper header\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("File seems to be empty. Make sure to have a proper header\n");
|
||||
return false;
|
||||
}
|
||||
const char * line = contentLines[0].c_str();
|
||||
s32 len = strlen(line);
|
||||
if(len <= 4){
|
||||
DEBUG_FUNCTION_LINE("Header is too short.\n");
|
||||
return false;
|
||||
}
|
||||
std::string identify;
|
||||
|
||||
if(line[0] == '[' && line[len-1] == ']'){
|
||||
identify = contentLines[0].substr(1,len-2);
|
||||
}else{
|
||||
log_printf("ConfigParser::Init((line %d): Not a proper config file!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Not a proper config file!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(identify.compare("GAMEPAD") == 0){
|
||||
log_printf("ConfigParser::Init((line %d): Its a gamepad config file!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Its a gamepad config file!\n");
|
||||
setSlot(gGamePadSlot);
|
||||
setType(PARSE_GAMEPAD);
|
||||
}else if(identify.compare("MOUSE") == 0){
|
||||
log_printf("ConfigParser::Init((line %d): Its a mouse config file!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Its a mouse config file!\n");
|
||||
setSlot(gMouseSlot);
|
||||
setType(PARSE_MOUSE);
|
||||
this->vid = HID_MOUSE_VID;
|
||||
this->pid = HID_MOUSE_PID;
|
||||
}else if(identify.compare("KEYBOARD") == 0){
|
||||
log_printf("ConfigParser::Init((line %d): Its a keyboard config file!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Its a keyboard config file!\n");
|
||||
setSlot(gHID_SLOT_KEYBOARD);
|
||||
setType(PARSE_KEYBOARD);
|
||||
this->vid = HID_KEYBOARD_VID;
|
||||
this->pid = HID_KEYBOARD_PID;
|
||||
}else{
|
||||
log_printf("ConfigParser::Init((line %d): Its a controller config file!\n",__LINE__);
|
||||
|
||||
DEBUG_FUNCTION_LINE("Its a controller config file!\n");
|
||||
setSlot(getSlotController(identify));
|
||||
setType(PARSE_CONTROLLER);
|
||||
}
|
||||
@ -116,18 +121,19 @@ bool ConfigParser::Init(){
|
||||
}
|
||||
|
||||
void ConfigParser::parseSingleLine(std::string line){
|
||||
if(line.empty()){DEBUG_FUNCTION_LINE("Can't parse line. it's empty\n"); return;}
|
||||
std::vector<std::string> cur_values = CPStringTools::StringSplit(line,"=");
|
||||
if(cur_values.size() != 2){
|
||||
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()); }
|
||||
if(HID_DEBUG || cur_values.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",line.c_str()); }
|
||||
return;
|
||||
}else{
|
||||
u16 hid_slot = getSlot();
|
||||
|
||||
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()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("leftpart = \"%s\" \n",cur_values[0].c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("rightpart = \"%s\" \n",cur_values[1].c_str()); }
|
||||
s32 keyslot = -1;
|
||||
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Checking single value\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Checking single value\n"); }
|
||||
if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD){
|
||||
keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]);
|
||||
}else if(getType() == PARSE_MOUSE){
|
||||
@ -136,14 +142,14 @@ void ConfigParser::parseSingleLine(std::string line){
|
||||
keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]);
|
||||
}
|
||||
if(keyslot != -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Its a single value\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a single value\n"); }
|
||||
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("ConfigParser::parseSingleLine(line %d): Settings preset DPAD MODE and Mask\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Settings preset DPAD MODE and Mask\n"); }
|
||||
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){
|
||||
@ -157,9 +163,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("ConfigParser::parseSingleLine(line %d): Used pre-defined Keyboard! \"%s\" is %d\n",__LINE__,cur_values[1].c_str(),rightValue);}
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined Keyboard! \"%s\" is %d\n",cur_values[1].c_str(),rightValue);}
|
||||
}else{
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); }
|
||||
char * ptr;
|
||||
rightValue = strtol(cur_values[1].c_str(),&ptr,16);
|
||||
}
|
||||
@ -168,34 +174,34 @@ void ConfigParser::parseSingleLine(std::string line){
|
||||
|
||||
if(getType() == PARSE_MOUSE){ //No parsing for the mouse
|
||||
if(rightValue == -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Invalid mouse value, lets skip it %s\n",__LINE__,cur_values[1].c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Invalid mouse value, lets skip it %s\n",cur_values[1].c_str()); }
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
if(rightValue == -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); }
|
||||
char * ptr;
|
||||
rightValue = strtol(cur_values[1].c_str(),&ptr,16);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Setting value to %d\n",__LINE__,rightValue); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Setting value to %d\n",rightValue); }
|
||||
|
||||
config_controller[hid_slot][keyslot][0] = CONTROLLER_PATCHER_VALUE_SET;
|
||||
config_controller[hid_slot][keyslot][1] = rightValue;
|
||||
}
|
||||
}else{
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Check pair value\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Check pair value\n"); }
|
||||
keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]);
|
||||
if(keyslot != -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Its a pair value\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a pair value\n"); }
|
||||
|
||||
if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): And its no preset\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("And its no preset\n"); }
|
||||
std::vector<std::string> rightvalues = CPStringTools::StringSplit(cur_values[1],",");
|
||||
|
||||
if(rightvalues.size() != 2){
|
||||
log_printf("ConfigParser::parseSingleLine(line %d): %d instead of 2 key=values pairs in line\n",__LINE__,rightvalues.size());
|
||||
DEBUG_FUNCTION_LINE("%d instead of 2 key=values pairs in line\n",rightvalues.size());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -205,12 +211,12 @@ 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("ConfigParser::parseSingleLine(line %d): Set %02X,%02X\n",__LINE__,firstValue,secondValue); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Set %02X,%02X\n",firstValue,secondValue); }
|
||||
}else{
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseSingleLine(line %d): Found preset value!!\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found preset value!!\n"); }
|
||||
}
|
||||
}else{
|
||||
log_printf("ConfigParser::parseSingleLine(line %d): The setting \"%s\" is unknown!\n",__LINE__,cur_values[0].c_str());
|
||||
DEBUG_FUNCTION_LINE("The setting \"%s\" is unknown!\n",cur_values[0].c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,7 +224,7 @@ void ConfigParser::parseSingleLine(std::string line){
|
||||
|
||||
bool ConfigParser::resetConfig(){
|
||||
s32 slot = getSlot();
|
||||
if(slot >= gHIDMaxDevices) return false;
|
||||
if((slot == HID_INVALID_SLOT) || (slot >= gHIDMaxDevices)) return false;
|
||||
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;
|
||||
@ -227,12 +233,12 @@ bool ConfigParser::resetConfig(){
|
||||
}
|
||||
|
||||
s32 ConfigParser::getSlotController(std::string identify){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::getSlotController(line %d): Getting Controller Slot\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Getting Controller Slot\n"); }
|
||||
|
||||
std::vector<std::string> values = CPStringTools::StringSplit(identify,",");
|
||||
|
||||
if(values.size() != 2){
|
||||
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());
|
||||
DEBUG_FUNCTION_LINE("You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",identify.c_str());
|
||||
return HID_INVALID_SLOT;
|
||||
}
|
||||
|
||||
@ -244,7 +250,7 @@ s32 ConfigParser::getSlotController(std::string identify){
|
||||
if(pid < 0){
|
||||
return HID_INVALID_SLOT;
|
||||
}
|
||||
log_printf("ConfigParser::getSlotController(line %d): VID: %04x PID: %04x\n",__LINE__,vid,pid);
|
||||
DEBUG_FUNCTION_LINE("VID: %04x PID: %04x\n",vid,pid);
|
||||
|
||||
this->vid = vid;
|
||||
this->pid = pid;
|
||||
@ -256,7 +262,7 @@ s32 ConfigParser::getSlotController(std::string identify){
|
||||
s32 slot = deviceinfo.slotdata.deviceslot;
|
||||
s32 hid = 0;
|
||||
if(result < 0){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::getSlotController(line %d): Its a new controller, lets save it\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a new controller, lets save it\n"); }
|
||||
|
||||
HIDSlotData slotdata;
|
||||
ControllerPatcherUtils::getNextSlotData(&slotdata);
|
||||
@ -265,69 +271,75 @@ s32 ConfigParser::getSlotController(std::string identify){
|
||||
hid = slotdata.hidmask;
|
||||
|
||||
if(slot >= gHIDMaxDevices){
|
||||
log_printf("ConfigParser::getSlotController(line %d): ConfigParser::getSlotController: We don't a space for a new controller, please delete .inis\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("We don't a space for a new controller, please delete .inis\n");
|
||||
return HID_INVALID_SLOT;
|
||||
}
|
||||
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)); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Got new slot! slot: %d hid %s .. Lets registrate it!\n",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;
|
||||
config_controller[slot][CONTRPS_PID][1] = (pid & 0x00FF);
|
||||
|
||||
if(HID_DEBUG){
|
||||
log_printf("ConfigParser::getSlotController(line %d): Saved vid: %04X pid: %04X\n",__LINE__,
|
||||
DEBUG_FUNCTION_LINE("Saved vid: %04X pid: %04X\n",
|
||||
config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1],
|
||||
config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]); }
|
||||
|
||||
config_controller_hidmask[slot] = hid;
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::getSlotController(line %d): Saved the hid\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Saved the hid\n"); }
|
||||
|
||||
}else{
|
||||
if(slot < gHIDMaxDevices){
|
||||
hid = config_controller_hidmask[slot];
|
||||
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__);
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,CPStringTools::byte_to_binary(hid)); }
|
||||
DEBUG_FUNCTION_LINE("We already have data of this controller, lets modify it\n");
|
||||
}else{
|
||||
log_printf("ConfigParser::getSlotController(line %d): Something really odd happend to the slots. %d is bigger then max (%d)\n",__LINE__,slot,gHIDMaxDevices);
|
||||
DEBUG_FUNCTION_LINE("Something really odd happend to the slots. %d is bigger then max (%d)\n",slot,gHIDMaxDevices);
|
||||
return HID_INVALID_SLOT;
|
||||
}
|
||||
}
|
||||
|
||||
log_printf("ConfigParser::getSlotController(line %d): using slot: %d hid %08X\n",__LINE__,slot,hid);
|
||||
DEBUG_FUNCTION_LINE("using slot: %d hid %08X\n",slot,hid);
|
||||
return slot;
|
||||
}
|
||||
|
||||
bool ConfigParser::parseIni(){
|
||||
if(getSlot() == HID_INVALID_SLOT){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",getType(),gHIDMaxDevices);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseIni(line %d): Parsing content, type %d\n",__LINE__,getType()); }
|
||||
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Parsing content, type %d\n",getType()); }
|
||||
|
||||
s32 start = 1;
|
||||
if(contentLines.size() <= 1){
|
||||
DEBUG_FUNCTION_LINE("File only contains a header.\n");
|
||||
return false;
|
||||
}
|
||||
if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){
|
||||
resetConfig();
|
||||
log_printf("ConfigParser::parseIni(line %d): Ignoring existing settings of this device\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Ignoring existing settings of this device\n");
|
||||
start++;
|
||||
}
|
||||
|
||||
for(u32 i = start; i < contentLines.size(); i++){
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseIni(line %d): line %d: \"%s\" \n",__LINE__,(i+1),contentLines[i].c_str()); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("line %d: \"%s\" \n",(i+1),contentLines[i].c_str()); }
|
||||
parseSingleLine(contentLines[i]);
|
||||
}
|
||||
|
||||
if(HID_DEBUG){ log_printf("ConfigParser::parseIni(line %d): Parsing of the file is done.\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Parsing of the file is done.\n"); }
|
||||
return true;
|
||||
}
|
||||
|
||||
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("ConfigParser::getValueFromKeyValue(line %d): Not a valid key=pair line %s\n",__LINE__,value_pair.c_str()); }
|
||||
if(HID_DEBUG || string_value.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",value_pair.c_str()); }
|
||||
return -1;
|
||||
}
|
||||
if(string_value[0].compare(expectedKey) != 0){
|
||||
log_printf("ConfigParser::getValueFromKeyValue(line %d): Key part not %s, its %s",__LINE__,expectedKey.c_str(),string_value[0].c_str());
|
||||
DEBUG_FUNCTION_LINE("Key part not %s, its %s",expectedKey.c_str(),string_value[0].c_str());
|
||||
return -1;
|
||||
}
|
||||
char * ptr;
|
||||
|
@ -28,7 +28,7 @@ ConfigValues::ConfigValues(){
|
||||
}
|
||||
|
||||
ConfigValues::~ConfigValues(){
|
||||
if(HID_DEBUG){ log_printf("ConfigValues::~ConfigValues(line %d){\n",__LINE__);}
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("\n");}
|
||||
}
|
||||
|
||||
const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue){
|
||||
@ -59,9 +59,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("ConfigValues::setIfValueIsPreset(line %d): This may be a predefined stick %s\n",__LINE__,possibleValue.c_str());}
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("This may be a predefined stick %s\n",possibleValue.c_str());}
|
||||
if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){
|
||||
if(HID_DEBUG){ log_printf("ConfigValues::setIfValueIsPreset(line %d): Found predefined stick!\n",__LINE__);}
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found predefined stick!\n");}
|
||||
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
|
||||
@ -98,9 +98,9 @@ s32 ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string n
|
||||
s32 ConfigValues::getPresetValueEx(std::string possibleString){
|
||||
s32 rightValue = -1;
|
||||
if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined VPAD_VALUE! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue); }
|
||||
}else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){
|
||||
if(HID_DEBUG){ log_printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined value! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue); }
|
||||
}
|
||||
return rightValue;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ friend class ControllerPatcher;
|
||||
private:
|
||||
static ConfigValues *getInstance() {
|
||||
if(instance == NULL){
|
||||
log_printf("ConfigValues: We need a new instance!!!\n");
|
||||
DEBUG_FUNCTION_LINE("We need a new instance!!!\n");
|
||||
instance = new ConfigValues();
|
||||
}
|
||||
return instance;
|
||||
@ -171,7 +171,7 @@ private:
|
||||
s32 getPresetValueEx(std::string possibleString);
|
||||
|
||||
void InitValues(){
|
||||
log_printf("ConfigValues::InitValues: Init values for the configuration\n");
|
||||
DEBUG_FUNCTION_LINE("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;
|
||||
|
@ -36,14 +36,14 @@ TCPServer::TCPServer(s32 port){
|
||||
|
||||
TCPServer::~TCPServer(){
|
||||
CloseSockets();
|
||||
if(HID_DEBUG){ log_printf("TCPServer::~TCPServer(line %d): Thread will be closed\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Thread will be closed\n"); }
|
||||
TCPServer::AttachDetach(DETACH);
|
||||
exitThread = 1;
|
||||
if(TCPServer::pThread != NULL){
|
||||
if(HID_DEBUG){ log_printf("TCPServer::~TCPServer(line %d): Deleting it!\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Deleting it!\n"); }
|
||||
delete TCPServer::pThread;
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("TCPServer::~TCPServer(line %d): Thread done\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Thread done\n"); }
|
||||
TCPServer::pThread = NULL;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ void TCPServer::StartTCPThread(TCPServer * server){
|
||||
OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR
|
||||
OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA
|
||||
priority = 10;
|
||||
log_printf("TCPServer::StartTCPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority);
|
||||
DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority);
|
||||
}
|
||||
TCPServer::pThread = ControllerPatcherThread::create(TCPServer::DoTCPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority);
|
||||
TCPServer::pThread->resumeThread();
|
||||
@ -75,16 +75,16 @@ void TCPServer::StartTCPThread(TCPServer * server){
|
||||
void TCPServer::AttachDetach(s32 attach){
|
||||
if(HID_DEBUG){
|
||||
if(attach){
|
||||
log_printf("TCPServer::AttachDetach(line %d): Network Attach\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Network Attach\n");
|
||||
}else{
|
||||
log_printf("TCPServer::AttachDetach(line %d): Network Detach\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Network Detach\n");
|
||||
}
|
||||
}
|
||||
|
||||
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("TCPServer::AttachDetach(line %d): Found a registered pad in deviceslot %d and padslot %d! Lets detach it.\n",__LINE__,i,j);
|
||||
DEBUG_FUNCTION_LINE("Found a registered pad in deviceslot %d and padslot %d! Lets detach it.\n",i,j);
|
||||
HIDDevice device;
|
||||
memset(&device,0,sizeof(device));
|
||||
|
||||
@ -101,9 +101,9 @@ void TCPServer::AttachDetach(s32 attach){
|
||||
|
||||
if(HID_DEBUG){
|
||||
if(attach){
|
||||
log_printf("TCPServer::AttachDetach(line %d): Network Attach DONE!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Network Attach DONE!\n");
|
||||
}else{
|
||||
log_printf("TCPServer::AttachDetach(line %d): Network Detach DONE!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Network Detach DONE!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,32 +123,32 @@ s32 TCPServer::RunTCP(){
|
||||
os_usleep(1000);
|
||||
continue;
|
||||
}
|
||||
//log_printf("got byte from tcp! %01X\n",ret);
|
||||
//DEBUG_FUNCTION_LINE("got byte from tcp! %01X\n",ret);
|
||||
switch (ret) {
|
||||
case WIIU_CP_TCP_ATTACH: { /*attach */
|
||||
if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){
|
||||
s32 handle;
|
||||
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_ATTACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: recvwait handle\n",WIIU_CP_TCP_ATTACH);
|
||||
return ret;
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("TCPServer::RunTCP(line %d): got handle %d\n",handle); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("got handle %d\n",handle); }
|
||||
u16 vid = 0;
|
||||
u16 pid = 0;
|
||||
ret = ControllerPatcherNet::recvwait(clientfd, &vid, 2);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait vid\n",__LINE__,WIIU_CP_TCP_ATTACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: recvwait vid\n",WIIU_CP_TCP_ATTACH);
|
||||
return ret;
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("TCPServer::RunTCP(line %d): got vid %04X\n",vid); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("got vid %04X\n",vid); }
|
||||
|
||||
ret = ControllerPatcherNet::recvwait(clientfd, &pid, 2);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait pid\n",__LINE__,WIIU_CP_TCP_ATTACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: recvwait pid\n",WIIU_CP_TCP_ATTACH);
|
||||
return ret;
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("TCPServer::RunTCP(line %d): got pid %04X\n",pid); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("got pid %04X\n",pid); }
|
||||
HIDDevice device;
|
||||
memset(&device,0,sizeof(device));
|
||||
device.handle = handle;
|
||||
@ -160,51 +160,51 @@ s32 TCPServer::RunTCP(){
|
||||
my_cb_user * user = NULL;
|
||||
ControllerPatcherHID::externAttachDetachCallback(&device,1);
|
||||
if((ret = ControllerPatcherUtils::getDataByHandle(handle,&user)) < 0){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: getDataByHandle(%d,%08X).\n",WIIU_CP_TCP_ATTACH,handle,&user);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Config for the controller is missing.\n",WIIU_CP_TCP_ATTACH);
|
||||
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND) < 0)){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_FOUND) < 0)){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_FOUND byte failed. Error: %d.\n",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(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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_OKAY byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ControllerPatcherNet::sendwait(clientfd,&user->slotdata.deviceslot,2);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait slotdata: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->slotdata.deviceslot);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: sendwait slotdata: %04X\n",WIIU_CP_TCP_ATTACH,user->slotdata.deviceslot);
|
||||
return ret;
|
||||
}
|
||||
ret = ControllerPatcherNet::sendwait(clientfd,&user->pad_slot,1);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait pad_slot: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->pad_slot);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: sendwait pad_slot: %04X\n",WIIU_CP_TCP_ATTACH,user->pad_slot);
|
||||
return ret;
|
||||
}
|
||||
}else{
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_ATTACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: invalid user data.\n",WIIU_CP_TCP_ATTACH);
|
||||
if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_BAD) < 0)){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_BAD byte failed. Error: %d.\n",WIIU_CP_TCP_ATTACH,ret);
|
||||
return ret;
|
||||
}
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("attachted to device slot: %d , pad slot is: %d\n",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::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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("handle %d connected! vid: %02X pid: %02X deviceslot %d, padslot %d\n",handle,vid,pid,user->slotdata.deviceslot,user->pad_slot); }
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -214,30 +214,30 @@ s32 TCPServer::RunTCP(){
|
||||
s32 handle;
|
||||
ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4);
|
||||
if(ret < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_DETACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: recvwait handle\n",WIIU_CP_TCP_DETACH);
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
|
||||
if(HID_DEBUG){ log_printf("TCPServer::RunTCP(line %d): got detach for handle: %d\n",__LINE__,handle); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("got detach for handle: %d\n",handle); }
|
||||
my_cb_user * user = NULL;
|
||||
if(ControllerPatcherUtils::getDataByHandle(handle,&user) < 0){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_DETACH,handle,&user);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: getDataByHandle(%d,%08X).\n",WIIU_CP_TCP_DETACH,handle,&user);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
if(user == NULL){
|
||||
log_printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_DETACH);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: invalid user data.\n",WIIU_CP_TCP_DETACH);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
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); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("device slot is: %d , pad slot is: %d\n",deviceslot,user->pad_slot); }
|
||||
|
||||
DeviceVIDPIDInfo vidpid;
|
||||
s32 result;
|
||||
if((result = ControllerPatcherUtils::getVIDPIDbyDeviceSlot(deviceslot,&vidpid)) < 0){
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("Error in %02X: Couldn't find a valid VID/PID for device slot %d. Error: %d\n",WIIU_CP_TCP_DETACH,deviceslot,ret);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
@ -252,16 +252,16 @@ s32 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::RunTCP(line %d): handle %d disconnected!\n",__LINE__,handle); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("handle %d disconnected!\n",handle); }
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WIIU_CP_TCP_PING: { /*ping*/
|
||||
if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){
|
||||
if(HID_DEBUG){ log_printf("TCPServer::RunTCP(line %d): Got Ping, sending now a Pong\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Got Ping, sending now a Pong\n"); }
|
||||
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;}
|
||||
if(ret < 0){ DEBUG_FUNCTION_LINE("Error in %02X: sendbyte PONG\n"); return -1;}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -302,7 +302,7 @@ void TCPServer::DoTCPThreadInternal(){
|
||||
if(ret < 0){ ErrorHandling(); continue;}
|
||||
|
||||
do{
|
||||
if(HID_DEBUG){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Waiting for a connection\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Waiting for a connection\n"); }
|
||||
if(exitThread) break;
|
||||
len = 16;
|
||||
|
||||
@ -317,37 +317,37 @@ void TCPServer::DoTCPThreadInternal(){
|
||||
clientfd = ret = accept(sockfd, (sockaddr *)&(sock_addr), &len);
|
||||
|
||||
if(ret == -1){ ErrorHandling(); break;}
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): TCP Connection accepted! Sending my protocol version: %d (0x%02X)\n",__LINE__, (WIIU_CP_TCP_HANDSHAKE - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,WIIU_CP_TCP_HANDSHAKE);
|
||||
DEBUG_FUNCTION_LINE("TCP Connection accepted! Sending my protocol version: %d (0x%02X)\n", (WIIU_CP_TCP_HANDSHAKE - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,WIIU_CP_TCP_HANDSHAKE);
|
||||
|
||||
gUDPClientip = sock_addr.sin_addr.s_addr;
|
||||
UDPClient::createInstance();
|
||||
|
||||
s32 ret;
|
||||
ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE); //Hey I'm a WiiU console!
|
||||
if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte: %02X\n",__LINE__,WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;}
|
||||
if(ret < 0){ DEBUG_FUNCTION_LINE("Error sendbyte: %02X\n",WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;}
|
||||
|
||||
u8 clientProtocolVersion = ControllerPatcherNet::recvbyte(clientfd);
|
||||
if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Error recvbyte: %02X\n",__LINE__,WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;}
|
||||
if(ret < 0){ DEBUG_FUNCTION_LINE("Error recvbyte: %02X\n",WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;}
|
||||
|
||||
if(clientProtocolVersion == WIIU_CP_TCP_HANDSHAKE_ABORT){
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): The network client wants to abort.\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("The network client wants to abort.\n");
|
||||
ErrorHandling(); break;
|
||||
}
|
||||
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): received protocol version: %d (0x%02X)\n",__LINE__,(clientProtocolVersion - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,clientProtocolVersion);
|
||||
DEBUG_FUNCTION_LINE("received protocol version: %d (0x%02X)\n",(clientProtocolVersion - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,clientProtocolVersion);
|
||||
|
||||
if(clientProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_MIN && clientProtocolVersion <= WIIU_CP_TCP_HANDSHAKE_VERSION_MAX){
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): We support this protocol version. Let's confirm it to the network client.\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("We support this protocol version. Let's confirm it to the network client.\n");
|
||||
gUsedProtocolVersion = clientProtocolVersion;
|
||||
ret = ControllerPatcherNet::sendbyte(clientfd, clientProtocolVersion);
|
||||
if(ret < 0){ log_printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte: %02X\n",__LINE__,clientProtocolVersion); ErrorHandling(); break;}
|
||||
if(ret < 0){ DEBUG_FUNCTION_LINE("Error sendbyte: %02X\n",clientProtocolVersion); ErrorHandling(); break;}
|
||||
}else{
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): We don't support this protocol version. We need to abort =(.\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("We don't support this protocol version. We need to abort =(.\n");
|
||||
ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE_ABORT);
|
||||
ErrorHandling(); break;
|
||||
}
|
||||
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): Handshake done! Success!\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Handshake done! Success!\n");
|
||||
|
||||
TCPServer::DetachAndDelete(); //Clear connected controller
|
||||
RunTCP();
|
||||
@ -357,7 +357,7 @@ void TCPServer::DoTCPThreadInternal(){
|
||||
}
|
||||
clientfd = -1;
|
||||
}while(0);
|
||||
log_printf("TCPServer::DoTCPThreadInternal(line %d): Connection closed\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Connection closed\n");
|
||||
gUDPClientip = 0;
|
||||
UDPClient::destroyInstance();
|
||||
TCPServer::DetachAndDelete(); //Clear connected controller
|
||||
|
@ -59,7 +59,7 @@ UDPServer::~UDPServer(){
|
||||
this->sockfd = -1;
|
||||
}
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("UDPServer::~UDPServer(line %d): Thread has been closed\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Thread has been closed\n"); }
|
||||
|
||||
|
||||
}
|
||||
@ -72,7 +72,7 @@ void UDPServer::StartUDPThread(UDPServer * server){
|
||||
OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR
|
||||
OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA
|
||||
priority = 10;
|
||||
log_printf("UDPServer::StartUDPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority);
|
||||
DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority);
|
||||
}
|
||||
UDPServer::pThread = ControllerPatcherThread::create(UDPServer::DoUDPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority);
|
||||
UDPServer::pThread->resumeThread();
|
||||
@ -80,7 +80,7 @@ void UDPServer::StartUDPThread(UDPServer * server){
|
||||
|
||||
bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum){
|
||||
if(((int)*offset + typesize) > maximum){
|
||||
log_printf("UDPServer::cpyIncrementBufferOffset(line %d): Transfer error. Excepted %04X bytes, but only got %04X\n",__LINE__,(*offset + typesize),maximum);
|
||||
DEBUG_FUNCTION_LINE("Transfer error. Excepted %04X bytes, but only got %04X\n",(*offset + typesize),maximum);
|
||||
return false;
|
||||
}
|
||||
memcpy(target,(void*)((u32)source+(*offset)),typesize);
|
||||
@ -135,19 +135,19 @@ 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(line %d): Allocating memory failed\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Allocating memory failed\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!cpyIncrementBufferOffset((void *)databuffer, (void *)buffer,&bufferoffset,datasize, n))continue;
|
||||
//log_printf("UDPServer::DoUDPThreadInternal(): Got handle: %d slot %04X hid %04X pad %02X datasize %02X\n",handle,deviceSlot,hid,padslot,datasize);
|
||||
//DEBUG_FUNCTION_LINE("UDPServer::DoUDPThreadInternal(): Got handle: %d slot %04X hid %04X pad %02X datasize %02X\n",handle,deviceSlot,hid,padslot,datasize);
|
||||
|
||||
user.pad_slot = padslot;
|
||||
user.slotdata.deviceslot = deviceSlot;
|
||||
user.slotdata.hidmask = hid;
|
||||
|
||||
if(gNetworkController[deviceSlot][padslot][0] == 0){
|
||||
log_printf("UDPServer::DoUDPThreadInternal(line %d): Ehm. Pad is not connected. STOP SENDING DATA ;) \n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Ehm. Pad is not connected. STOP SENDING DATA ;) \n");
|
||||
}else{
|
||||
ControllerPatcherHID::externHIDReadCallback(handle,databuffer,datasize,&user);
|
||||
}
|
||||
@ -165,5 +165,5 @@ void UDPServer::DoUDPThreadInternal(){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(HID_DEBUG){ log_printf("UDPServer::DoUDPThreadInternal(line %d): UDPServer Thread ended\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("UDPServer Thread ended\n"); }
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne
|
||||
HID_Mouse_Data * cur_mouse_data = &data_ptr->data_union.mouse.cur_mouse_data;
|
||||
|
||||
data_ptr->type = DEVICE_TYPE_MOUSE;
|
||||
//log_printf("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered);
|
||||
//DEBUG_FUNCTION_LINE("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered);
|
||||
|
||||
if(buf[0] == 2 && bytes_transfered > 3){ // using the other mouse mode
|
||||
buf +=1;
|
||||
@ -89,7 +89,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne
|
||||
|
||||
cur_mouse_data->valuedChanged = 1;
|
||||
|
||||
//log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value);
|
||||
//DEBUG_FUNCTION_LINE("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value);
|
||||
|
||||
HIDRead(handle, usr->buf, bytes_transfered, myHIDMouseReadCallback, usr);
|
||||
}
|
||||
@ -114,15 +114,15 @@ void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned cha
|
||||
|
||||
s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach){
|
||||
if(attach){
|
||||
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);
|
||||
log_printf("sub class %02x\n", p_device->sub_class);
|
||||
log_printf("protocol %02x\n", p_device->protocol);
|
||||
log_printf("max packet in %02x\n", p_device->max_packet_size_rx);
|
||||
log_printf("max packet out %02x\n", p_device->max_packet_size_tx); }
|
||||
DEBUG_FUNCTION_LINE("vid %04x pid %04x connected\n", SWAP16(p_device->vid),SWAP16(p_device->pid));
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("interface index %02x\n", p_device->interface_index);
|
||||
DEBUG_FUNCTION_LINE("sub class %02x\n", p_device->sub_class);
|
||||
DEBUG_FUNCTION_LINE("protocol %02x\n", p_device->protocol);
|
||||
DEBUG_FUNCTION_LINE("max packet in %02x\n", p_device->max_packet_size_rx);
|
||||
DEBUG_FUNCTION_LINE("max packet out %02x\n", p_device->max_packet_size_tx); }
|
||||
}
|
||||
if(!attach){
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): vid %04x pid %04x disconnected\n",__LINE__, SWAP16(p_device->vid),SWAP16(p_device->pid));
|
||||
DEBUG_FUNCTION_LINE("vid %04x pid %04x disconnected\n", SWAP16(p_device->vid),SWAP16(p_device->pid));
|
||||
}
|
||||
DeviceInfo device_info;
|
||||
memset(&device_info,0,sizeof(DeviceInfo));
|
||||
@ -135,18 +135,18 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
if ((p_device->sub_class == 1) && (p_device->protocol == 1)) { //Keyboard
|
||||
slotdata->hidmask = gHID_LIST_KEYBOARD;
|
||||
slotdata->deviceslot = gHID_SLOT_KEYBOARD;
|
||||
//log_printf("Found Keyboard: device: %s slot: %d\n",byte_to_binary(device_info.slotdata.hidmask),device_info.slotdata.deviceslot);
|
||||
//DEBUG_FUNCTION_LINE("Found Keyboard: device: %s slot: %d\n",byte_to_binary(device_info.slotdata.hidmask),device_info.slotdata.deviceslot);
|
||||
}else if ((p_device->sub_class == 1) && (p_device->protocol == 2)){ // MOUSE
|
||||
slotdata->hidmask = gHID_LIST_MOUSE;
|
||||
slotdata->deviceslot = gMouseSlot;
|
||||
//log_printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot);
|
||||
//DEBUG_FUNCTION_LINE("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot);
|
||||
}else{
|
||||
s32 ret;
|
||||
if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",__LINE__,ret);
|
||||
DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",ret);
|
||||
return HID_DEVICE_DETACH;
|
||||
}else{
|
||||
//log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",__LINE__,ret);
|
||||
//DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",ret);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
}
|
||||
|
||||
if(failed){
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d) error: I can only handle %d devices of the same type. Sorry \n",__LINE__,HID_MAX_PADS_COUNT);
|
||||
DEBUG_FUNCTION_LINE("error: I can only handle %d devices of the same type. Sorry \n",HID_MAX_PADS_COUNT);
|
||||
if(buf){
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
@ -214,7 +214,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
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("ControllerPatcherHID::AttachDetachCallback(line %d): saved handle %d to slot %d and pad %d\n",__LINE__,p_device->handle,slotdata->deviceslot,pad_slot);
|
||||
//DEBUG_FUNCTION_LINE("saved handle %d to slot %d and pad %d\n",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;
|
||||
@ -223,7 +223,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data));
|
||||
}
|
||||
|
||||
if(HID_DEBUG){ log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully attached\n",__LINE__); }
|
||||
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Device successfully attached\n"); }
|
||||
|
||||
if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD
|
||||
//The GC Adapter has all ports in one device. Set them all.
|
||||
@ -245,7 +245,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
s32 read_result = HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL);
|
||||
if(read_result == 64){
|
||||
if(usr->buf[01] == 0x01){ //We need to do the handshake
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake needed\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Switch Pro Controller handshake needed\n");
|
||||
/**
|
||||
Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering)
|
||||
**/
|
||||
@ -265,7 +265,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL);
|
||||
HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL);
|
||||
}else{
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake already done\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("Switch Pro Controller handshake already done\n");
|
||||
}
|
||||
HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr);
|
||||
}
|
||||
@ -312,7 +312,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
free(user_data);
|
||||
user_data = NULL;
|
||||
}else{
|
||||
if(founddata){ log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): user_data null. You may have a memory leak.\n",__LINE__); }
|
||||
if(founddata){ DEBUG_FUNCTION_LINE("user_data null. You may have a memory leak.\n"); }
|
||||
return HID_DEVICE_DETACH;
|
||||
}
|
||||
if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0){
|
||||
@ -328,12 +328,12 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
gHID_Mouse_Mode = HID_MOUSE_MODE_AIM;
|
||||
}
|
||||
}else{
|
||||
if(HID_DEBUG){log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): We still have pad for deviceslot %d connected.\n",__LINE__,slotdata->deviceslot); }
|
||||
if(HID_DEBUG){DEBUG_FUNCTION_LINE("We still have pad for deviceslot %d connected.\n",slotdata->deviceslot); }
|
||||
}
|
||||
if(HID_DEBUG){log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully detached\n",__LINE__); }
|
||||
if(HID_DEBUG){DEBUG_FUNCTION_LINE("Device successfully detached\n"); }
|
||||
}
|
||||
}else{
|
||||
log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): HID-Device currently not supported! You can add support through config files\n",__LINE__);
|
||||
DEBUG_FUNCTION_LINE("HID-Device currently not supported! You can add support through config files\n");
|
||||
}
|
||||
return HID_DEVICE_DETACH;
|
||||
}
|
||||
@ -341,7 +341,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
|
||||
void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){
|
||||
ControllerPatcherUtils::doSampling(usr->slotdata.deviceslot,usr->pad_slot,false);
|
||||
|
||||
//log_printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot);
|
||||
//DEBUG_FUNCTION_LINE("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;
|
||||
@ -355,10 +355,10 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b
|
||||
|
||||
/*
|
||||
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++;
|
||||
log_printf("GC4 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n", 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]);*/
|
||||
DEBUG_FUNCTION_LINE("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++;
|
||||
DEBUG_FUNCTION_LINE("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++;
|
||||
DEBUG_FUNCTION_LINE("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++;
|
||||
DEBUG_FUNCTION_LINE("GC4 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n", 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]);*/
|
||||
HIDGCRumble(handle,usr);
|
||||
}else if(usr->slotdata.hidmask != 0){
|
||||
//Depending on how the switch pro controller is connected, it has a different data format. At first we had the Bluetooth version, so we need to convert
|
||||
@ -562,7 +562,7 @@ std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
|
||||
s32 res;
|
||||
HID_Data * new_data = NULL;
|
||||
if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid.
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",CPStringTools::byte_to_binary(cur_hidmask),pad,res);
|
||||
continue;
|
||||
}
|
||||
if(new_data != NULL) data_list.push_back(new_data);
|
||||
@ -638,7 +638,7 @@ void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){
|
||||
}
|
||||
usr->forceRumbleInTicks[pad]--;
|
||||
if(rumblechanged || usr->forceRumbleInTicks[pad] <= 0){
|
||||
//log_printf("Rumble: %d %d\n",usr->rumblestatus[pad],usr->rumbleForce[pad]);
|
||||
//DEBUG_FUNCTION_LINE("Rumble: %d %d\n",usr->rumblestatus[pad],usr->rumbleForce[pad]);
|
||||
//Seding to the network client!
|
||||
char bytes[6];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user