Skip to content

Commit

Permalink
refactor: WindowSize.Rect struct
Browse files Browse the repository at this point in the history
  • Loading branch information
lulzsun committed Jan 17, 2025
1 parent 76ab413 commit a3141b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Classes/Services/DetectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static bool AutoDetectGame(int processId, string executablePath, nint win
var aspectRatio = GetAspectRatio(windowSize.GetWidth(), windowSize.GetHeight());
bool isValidAspectRatio = IsValidAspectRatio(windowSize.GetWidth(), windowSize.GetHeight());
bool isWhitelistedClass = classWhitelist.Where(c => className.ToLower().Contains(c)).Any() || classWhitelist.Where(c => className.ToLower().Replace(" ", "").Contains(c)).Any();
detailedWindowStr += $"[{windowSize.GetWidth()}x{windowSize.GetHeight()}, {aspectRatio}]";
detailedWindowStr += $"[{windowSize}, {aspectRatio}]";

// if there is no matched game, lets try to make assumptions from the process given the following information:
// 1. window size & aspect ratio
Expand Down
16 changes: 13 additions & 3 deletions Classes/Services/WindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static IntPtr GetWindowHandleByProcessId(int processId, bool lazy = false
}

[StructLayout(LayoutKind.Sequential)]
public struct Rect(int left, int top, int right, int bottom) {
public struct Rect(int left = 0, int top = 0, int right = 0, int bottom = 0) {

Check warning on line 213 in Classes/Services/WindowService.cs

View workflow job for this annotation

GitHub Actions / Build RePlays

'WindowService.Rect' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 213 in Classes/Services/WindowService.cs

View workflow job for this annotation

GitHub Actions / Build RePlays

'WindowService.Rect' defines operator == or operator != but does not override Object.GetHashCode()
public int Left = left, Top = top, Right = right, Bottom = bottom;

public int GetWidth() {
Expand All @@ -221,8 +221,18 @@ public int GetHeight() {
return Bottom - Top;
}

public string GetSizeStr() {
return GetWidth() + "x" + GetHeight();
public override string ToString() {
return $"{GetWidth()}x{GetHeight()}";
}

public static bool operator ==(Rect left, Rect right) => left.Equals(right);
public static bool operator !=(Rect left, Rect right) => !left.Equals(right);

public override bool Equals(object obj) {
if (obj is Rect rect) {
return GetWidth() == rect.GetWidth() && GetHeight() == rect.GetHeight();
}
return false;
}
}

Expand Down

0 comments on commit a3141b5

Please sign in to comment.