Skip to content

Commit

Permalink
fix: 修复可能无法自动检测窗口大小的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Coooookies committed Dec 13, 2023
1 parent b9c4c0f commit 351d32a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
31 changes: 20 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ static LeagueClientAPI GetLCU()
return (LeagueClientWindowHWnd, LeagueClientWindowCefHWnd);
}

static async Task<int> FixLeagueClientWindow(bool forced = false)
static bool needResize(RECT Rect)
{
return (Rect.Bottom - Rect.Top) /
(double)(Rect.Right - Rect.Left) != 0.5625;
}

var LeagueClientWindowRect = new RECT();
static async Task<int> FixLeagueClientWindow(bool forced = false)
{
var LeagueClientWindow = GetLeagueClientWindowHandle();
var LeagueClientAPIClient = GetLCU();
var LeagueClientWindowRect = new RECT();
var LeagueClientWindowCefRect = new RECT();

if (
LeagueClientWindow.LeagueClientWindowHWnd == IntPtr.Zero ||
Expand All @@ -49,26 +54,30 @@ static async Task<int> FixLeagueClientWindow(bool forced = false)
return -1; // Failed to get leagueclient window handle
}

if (LeagueClientAPIClient == null)
if (IsMinimalized(LeagueClientWindow.LeagueClientWindowHWnd))
{
return -2; // Failed to get leagueclient api instance
return 0;
}

GetWindowRect(LeagueClientWindow.LeagueClientWindowHWnd, ref LeagueClientWindowRect);
GetWindowRect(LeagueClientWindow.LeagueClientWindowCefHWnd, ref LeagueClientWindowCefRect);

var LeagueClientWindowWidth = LeagueClientWindowRect.Right - LeagueClientWindowRect.Left;
var LeagueClientWindowHeight = LeagueClientWindowRect.Bottom - LeagueClientWindowRect.Top;
var LeagueClientMinimized = IsMinimalized(LeagueClientWindow.LeagueClientWindowHWnd);

if ((LeagueClientMinimized || LeagueClientWindowHeight / (double)LeagueClientWindowWidth == 0.5625) && !forced)
if (!needResize(LeagueClientWindowRect) && !needResize(LeagueClientWindowCefRect) && !forced)
{
return 0;
}

var LeagueClientAPIClient = GetLCU();

if (LeagueClientAPIClient == null)
{
return -2; // Failed to get leagueclient api instance
}

var LeagueClientZoom = await LeagueClientAPIClient.GetClientZoom();
var PrimaryScreenWidth = Screen.PrimaryScreen.Bounds.Width;
var PrimaryScreenHeight = Screen.PrimaryScreen.Bounds.Height;
// var PrimaryScreenDpi = GetDpiForWindow(LeagueClientWindow.LeagueClientWindowHWnd) / 96.0;
var PrimaryScreenDpi = GetDpiForWindow(LeagueClientWindow.LeagueClientWindowHWnd) / 96.0;

if (LeagueClientZoom == -1)
{
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]

0 comments on commit 351d32a

Please sign in to comment.