Skip to content

Commit

Permalink
Change controller authentication management for Xbox consoles #542
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Laurendeau committed Mar 25, 2018
1 parent 2841c1f commit ee898ae
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 94 deletions.
66 changes: 20 additions & 46 deletions core/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,36 +650,17 @@ e_gimx_status adapter_detect()
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}

if(ret != -1)
if(ret == E_GIMX_STATUS_SUCCESS)
{
switch(adapter->ctype)
{
case C_TYPE_DS4:
case C_TYPE_T300RS_PS4:
case C_TYPE_G29_PS4:
case C_TYPE_G27_PS3:
if(status == BYTE_STATUS_STARTED)
{
if(adapter_send_reset(i) < 0)
{
gerror(_("failed to reset the GIMX adapter.\n"));
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
else
{
ginfo(_("Reset sent to the GIMX adapter.\n"));
//Leave time for the adapter to reinitialize.
usleep(ADAPTER_RESET_TIME);
}
}
break;
case C_TYPE_XONE_PAD:
case C_TYPE_360_PAD:
if(status == BYTE_STATUS_SPOOFED)
{
adapter->status = 1;
}
else
if(status == BYTE_STATUS_STARTED)
{
if(adapter_send_reset(i) < 0)
{
Expand Down Expand Up @@ -709,28 +690,23 @@ e_gimx_status adapter_detect()
int usb_res = usb_init(i, adapter->ctype);
if(usb_res < 0)
{
if((adapter->ctype != C_TYPE_360_PAD
&& adapter->ctype != C_TYPE_XONE_PAD)
|| status != BYTE_STATUS_SPOOFED)
gerror(_("No game controller was found on USB ports.\n"));
switch(adapter->ctype)
{
gerror(_("No game controller was found on USB ports.\n"));
switch(adapter->ctype)
{
case C_TYPE_360_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_X360;
break;
case C_TYPE_DS4:
case C_TYPE_G29_PS4:
case C_TYPE_T300RS_PS4:
ret = E_GIMX_STATUS_AUTH_MISSING_PS4;
break;
case C_TYPE_XONE_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_XONE;
break;
default:
ret = E_GIMX_STATUS_GENERIC_ERROR;
break;
}
case C_TYPE_360_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_X360;
break;
case C_TYPE_DS4:
case C_TYPE_G29_PS4:
case C_TYPE_T300RS_PS4:
ret = E_GIMX_STATUS_AUTH_MISSING_PS4;
break;
case C_TYPE_XONE_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_XONE;
break;
default:
ret = E_GIMX_STATUS_GENERIC_ERROR;
break;
}
}
}
Expand Down Expand Up @@ -1189,14 +1165,12 @@ e_gimx_status adapter_clean()
}
switch(adapter->ctype)
{
case C_TYPE_360_PAD:
case C_TYPE_XONE_PAD:
usb_close(i);
break;
case C_TYPE_DS4:
case C_TYPE_T300RS_PS4:
case C_TYPE_G29_PS4:
case C_TYPE_G27_PS3:
case C_TYPE_360_PAD:
case C_TYPE_XONE_PAD:
usb_close(i);
adapter_send_reset(i);
break;
Expand Down
73 changes: 37 additions & 36 deletions core/gimx.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,16 @@ int main(int argc, char *argv[])
QUIT: ;

e_gimx_status clean_status = adapter_clean();
if (status == E_GIMX_STATUS_SUCCESS && clean_status != E_GIMX_STATUS_SUCCESS)
if (status == E_GIMX_STATUS_SUCCESS)
{
status = clean_status;
if (clean_status != E_GIMX_STATUS_SUCCESS)
{
status = clean_status;
}
else
{
status = adapter_get(0)->ctype;
}
}

macros_clean();
Expand All @@ -496,47 +503,41 @@ int main(int argc, char *argv[])

xmlCleanupParser();

if (status != E_GIMX_STATUS_SUCCESS)
{
/*
* Write the status in the gimx.status file, in the system temp directory.
*
* In most cases gimx runs in a terminal window (such as xterm) that may not
* provide the return code to the parent process (in most cases gimx-launcher).
*
* The absence of the gimx.status file means the execution was successful,
* or that the program crashed.
*/
/*
* Write the status in the gimx.status file, in the system temp directory.
*
* In most cases gimx runs in a terminal window (such as xterm) that may not
* provide the return code to the parent process (in most cases gimx-launcher).
*/

#ifndef WIN32
char * file = "/tmp/gimx.status";
char * file = "/tmp/gimx.status";
#else
char file[MAX_PATH];
int ret = GetTempPath(sizeof(file), file);
if (ret > 0 && (unsigned int) ret < MAX_PATH - sizeof("/gimx.status"))
{
strcat(file, "/gimx.status");
}
else
{
file[0] = '\0';
}
char file[MAX_PATH];
int ret = GetTempPath(sizeof(file), file);
if (ret > 0 && (unsigned int) ret < MAX_PATH - sizeof("/gimx.status"))
{
strcat(file, "/gimx.status");
}
else
{
file[0] = '\0';
}
#endif
if (file != NULL && file[0] != '\0')
if (file != NULL && file[0] != '\0')
{
FILE * fp = fopen(file, "w");
if (fp != NULL)
{
FILE * fp = fopen(file, "w");
if (fp != NULL)
{
fprintf(fp, "%d\n", status);
fclose(fp);
fprintf(fp, "%d\n", status);
fclose(fp);
#ifndef WIN32
int ret = chown(file, getpwuid(getuid())->pw_uid, getpwuid(getuid())->pw_gid);
if (ret < 0)
{
gerror("failed to set ownership of the gimx status file\n");
}
#endif
int ret = chown(file, getpwuid(getuid())->pw_uid, getpwuid(getuid())->pw_gid);
if (ret < 0)
{
gerror("failed to set ownership of the gimx status file\n");
}
#endif
}
}

Expand Down
2 changes: 0 additions & 2 deletions core/include/connectors/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ typedef struct GIMX_PACKED
#define BYTE_OUT_REPORT 0xee
#define BYTE_IN_REPORT 0xff

#define BYTE_STATUS_NSPOOFED 0x00
#define BYTE_STATUS_SPOOFED 0x01
#define BYTE_STATUS_NSTARTED 0x00
#define BYTE_STATUS_STARTED 0x01

Expand Down
27 changes: 17 additions & 10 deletions launcher/gimx-launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,13 +1709,10 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused
ButtonStart->Enable(true);
StatusBar1->SetStatusText(wxEmptyString);

status = E_GIMX_STATUS_SUCCESS;
status = E_GIMX_STATUS_GENERIC_ERROR;

/*
* Get the execution status from the gimx.status file, in the system temp directory.
*
* The absence of the gimx.status file means the execution was successful,
* or that the program crashed.
*/

wxString statusFile = wxStandardPaths::Get().GetTempDir() + wxT("/") + wxT(STATUS_FILE);
Expand All @@ -1738,12 +1735,6 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused

switch(status)
{
case E_GIMX_STATUS_SUCCESS:
{
wxCommandEvent event;
OnMenuSave(event);
}
break;
case E_GIMX_STATUS_GENERIC_ERROR:
wxMessageBox( _("GIMX failed with a generic error (please report this)."), _("Error"), wxICON_ERROR);
break;
Expand Down Expand Up @@ -1788,6 +1779,22 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused
case E_GIMX_STATUS_AUTH_MISSING_XONE:
wxMessageBox( _("No Xbox One controller (without 3.5mm jack) was found on USB ports."), _("Error"), wxICON_ERROR);
break;
default:
if (status >= E_GIMX_STATUS_SUCCESS)
{
wxCommandEvent event;
OnMenuSave(event);
#ifdef WIN32
switch (status)
{
case C_TYPE_XONE_PAD:
case C_TYPE_360_PAD:
wxMessageBox( _("Unplug and replug the controller before next GIMX start."), _("Info"), wxICON_INFORMATION);
break;
}
#endif
}
break;
}

if(openLog)
Expand Down

0 comments on commit ee898ae

Please sign in to comment.