Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
added support for Bluestacks 5
Browse files Browse the repository at this point in the history
  • Loading branch information
MgAl2O4 committed Jul 15, 2021
1 parent fe4f0be commit ceb76ff
Showing 1 changed file with 90 additions and 11 deletions.
101 changes: 90 additions & 11 deletions SINoCOLO/ScreenReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ public WINDOWINFO(Boolean? filler) : this() // Allows automatic initialization
private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
#endregion

private void UpdateAvailableGameInfo()
private void UpdateAvailableGames_Bluestack4()
{
const uint WS_VISIBLE = 0x10000000;
const uint WS_EX_APPWINDOW = 0x00040000;

var processes = Process.GetProcessesByName("BlueStacks");
//Console.WriteLine("Scanning processes, check:{0}", processes.Length);
//Console.WriteLine("Scanning processes [Bluestack4], check:{0}", processes.Length);

foreach (var proc in processes)
{
Expand All @@ -237,21 +237,85 @@ private void UpdateAvailableGameInfo()
}, IntPtr.Zero);
}

// remove all handles not on the list
for (int idx = availableGameInfo.Count - 1; idx >= 0; idx--)
// process all known
foreach (IntPtr testHandle in windowHandles)
{
if (!availableGameInfo[idx].IsValid())
StringBuilder sb = new StringBuilder(256);
GetWindowText(testHandle, sb, 256);

//Console.WriteLine(" >> testing window:{0:x} ({1})", testHandle, sb);

IntPtr childHandleInput = FindWindowEx(testHandle, (IntPtr)0, null, null);
//Console.WriteLine(" >> childInput:{0:x}", childHandleInput.ToInt64());
if (childHandleInput != IntPtr.Zero)
{
availableGameInfo.RemoveAt(idx);
IntPtr childHandleClient = FindWindowEx(childHandleInput, (IntPtr)0, null, "_ctl.Window");
//Console.WriteLine(" >> childClient:{0:x}", childHandleClient.ToInt64());
if (childHandleClient != IntPtr.Zero)
{
bool added = false;
foreach (var info in availableGameInfo)
{
if (info.windowMain.Handle == testHandle)
{
if (info.windowClient.Handle != childHandleClient) { info.windowClient = new HandleRef(this, childHandleClient); }
if (info.windowInput.Handle != childHandleInput) { info.windowInput = new HandleRef(this, childHandleInput); }

//Console.WriteLine(" >> already added");
added = true;
break;
}
}

if (!added)
{
var newInfo = new GameInfo
{
process = proc,
windowTitle = sb.ToString(),
windowMain = new HandleRef(this, testHandle),
windowClient = new HandleRef(this, childHandleClient),
windowInput = new HandleRef(this, childHandleInput)
};

//Console.WriteLine(" >> new entry!");
availableGameInfo.Add(newInfo);
}
}
}
else if (availableGameInfo[idx].process == proc)
}
}
}
}

private void UpdateAvailableGames_Bluestack5()
{
const uint WS_VISIBLE = 0x10000000;

var processes = Process.GetProcessesByName("HD-Player");
//Console.WriteLine("Scanning processes [Bluestack5], check:{0}", processes.Length);

foreach (var proc in processes)
{
//Console.WriteLine(">> proc:{0:x}, mainWnd:{1:x} ({2})", proc.Id, proc.MainWindowHandle, proc.MainWindowTitle);
if (proc.MainWindowHandle.ToInt64() != 0)
{
var windowHandles = new List<IntPtr>();
foreach (ProcessThread thread in proc.Threads)
{
EnumThreadWindows(thread.Id, (hWnd, lParam) =>
{
var isKnown = windowHandles.Contains(availableGameInfo[idx].windowMain.Handle);
if (!isKnown)
WINDOWINFO wndInfo = new WINDOWINFO();
GetWindowInfo(hWnd, ref wndInfo);
var isVisible = (wndInfo.dwStyle & WS_VISIBLE) != 0;
if (isVisible)
{
availableGameInfo.RemoveAt(idx);
windowHandles.Add(hWnd);
}
}
return true;
}, IntPtr.Zero);
}

// process all known
Expand Down Expand Up @@ -303,6 +367,21 @@ private void UpdateAvailableGameInfo()
}
}
}
}

private void UpdateAvailableGameInfo()
{
// remove all handles not on the list
for (int idx = availableGameInfo.Count - 1; idx >= 0; idx--)
{
if (!availableGameInfo[idx].IsValid())
{
availableGameInfo.RemoveAt(idx);
}
}

UpdateAvailableGames_Bluestack4();
UpdateAvailableGames_Bluestack5();

foreach (var info in availableGameInfo)
{
Expand Down

0 comments on commit ceb76ff

Please sign in to comment.