Skip to content

Commit

Permalink
Convert Lego Star Wars fix into hack method
Browse files Browse the repository at this point in the history
  • Loading branch information
RadWolfie committed Jul 5, 2018
1 parent 75b6f32 commit 5c1abac
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/CxbxKrnl/EmuXapi.cpp
Expand Up @@ -344,6 +344,40 @@ bool TitleIsJSRF()
return result;
}

bool TitleIsLegoSW()
{
static bool detected = false;
static bool result = false;

// Prevent running the check every time this function is called
if (detected) {
return result;
}

// Array of known Lego Star Wars title IDs, must be 0 terminated
DWORD titleIds[] = {
0x4553001D, // NTSC
0
};

DWORD* pTitleId = &titleIds[0];
while (*pTitleId != 0) {
if (g_pCertificate->dwTitleId == *pTitleId) {
result = true;
break;
}

pTitleId++;
}

if (result) {
EmuWarning("Applying Lego Star Wars Hack");
}

detected = true;
return result;
}

// ******************************************************************
// * patch: XGetDevices
// * Note: This could be unpatched however,
Expand Down Expand Up @@ -419,19 +453,17 @@ BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges)
// some titles call XGetDevices first, and the CurrentConnected and ChangeConnected flags are set there.
// note that certain titles such as Otogi need the ChangeConnected to be set to 1 always to enable the input.
int port;
//fix for Lego Star War no input, it requires the XGetDeviceChanges to return changes all the time, but no removal, only insertions.
//if (DeviceType->CurrentConnected == 0) {
if (DeviceType->CurrentConnected == 0) {
for (port = 0; port < 4; port++) {
//if the host controller is connected and the xbox DeviceType matches. set the CurrentConnected flag.
if (g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[port].dwHostType>0) {
DeviceType->CurrentConnected |= 1 << port;
}
}
DeviceType->ChangeConnected = DeviceType->CurrentConnected;
//}
}

// JSRF Hack: Don't set the ChangeConnected flag. Without this, JSRF hard crashes
// TODO: Why is this still needed?
// JSRF Hack: Don't set the ChangeConnected flag. Without this, JSRF hard crashes
if (TitleIsJSRF()) {
DeviceType->ChangeConnected = 0;
}
Expand All @@ -458,9 +490,14 @@ BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges)

xboxkrnl::KfLowerIrql(oldIrql);
}
//fix for Lego Star War no input, it requires the XGetDeviceChanges to return changes all the time, but no removal, only insertions.
*pdwRemovals = 0;
*pdwInsertions = DeviceType->CurrentConnected;

// Lego SW Hack: Require XGetDeviceChanges to return changes all the time, but no removal, only insertions.
// Without this, Lego SW will not response to controller's input.
if (TitleIsLegoSW()) {
*pdwRemovals = 0;
*pdwInsertions = DeviceType->CurrentConnected;
ret = TRUE;
}

RETURN(ret);
}
Expand Down

0 comments on commit 5c1abac

Please sign in to comment.