Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for irregular screen resolution (such as 1366x768, etc.) #523

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions InventoryKamera/game/Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace InventoryKamera
{
public static class Navigation
public static class Navigation
{
private static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

Expand All @@ -21,7 +21,7 @@ public static class Navigation
private static Size AspectRatio;
public static bool IsNormal { get; private set; }

private static double delay = 1;
private static double delay = 1;

public static VirtualKeyCode escapeKey = VirtualKeyCode.ESCAPE;
public static VirtualKeyCode characterKey = VirtualKeyCode.VK_C;
Expand Down Expand Up @@ -281,10 +281,26 @@ public static Size GetAspectRatio()

if (WindowSize.Width == 0) throw new DivideByZeroException("Genshin's window width cannot be 0");
if (WindowSize.Height == 0) throw new DivideByZeroException("Genshin's window height cannot be 0");
int x = WindowSize.Width/GCD(WindowSize.Width, WindowSize.Height);
int y = WindowSize.Height/GCD(WindowSize.Width, WindowSize.Height);
var size = new Size(x, y);


(int x, int y)[] IRREGULAR_RES_169 = new[] {
(854, 480),
(1366, 768),
};

int gcd = GCD(WindowSize.Width, WindowSize.Height);
int w = WindowSize.Width / gcd;
int h = WindowSize.Height / gcd;
Size size = new Size(w, h);

foreach (var (x, y) in IRREGULAR_RES_169)
{
if (WindowSize.Width == x && WindowSize.Height == y)
{
size = new Size(16, 9);
break;
}
}

IsNormal = size == new Size(16, 9);

return size;
Expand Down Expand Up @@ -386,7 +402,7 @@ public static bool InitializeProcess(string processName, out IntPtr handle)
public static extern bool SetCursorPos(int X, int Y);

public static bool SetCursor(int X, int Y)
{
{
return SetCursorPos(GetPosition().Left + X, GetPosition().Top + Y);
}

Expand Down Expand Up @@ -415,45 +431,45 @@ public static void Click(Point point)
}

public static void Scroll(Direction direction, int scrolls, int delay = 1)
{
{
Action Scroll;
switch (direction)
{
case Direction.UP:
switch (direction)
{
case Direction.UP:
Scroll = () => sim.Mouse.VerticalScroll(1);
break;
case Direction.DOWN:
case Direction.DOWN:
Scroll = () => sim.Mouse.VerticalScroll(-1);
break;
case Direction.LEFT:
break;
case Direction.LEFT:
Scroll = () => sim.Mouse.HorizontalScroll(-1);
break;
case Direction.RIGHT:
break;
case Direction.RIGHT:
Scroll = () => sim.Mouse.HorizontalScroll(1);
break;
default:
return;
}
for (int i = 0; i < scrolls; i++)
{
break;
default:
return;
}
for (int i = 0; i < scrolls; i++)
{
Scroll();
Wait(delay);
}
}
}
}

public enum Direction
{
{
UP = 0,
DOWN = 1,
LEFT = 2,
RIGHT = 3,
}
}

#endregion Mouse
#endregion Mouse

#region Delays
#region Delays

public static void SystemWait(Speed speed = Speed.Normal)
public static void SystemWait(Speed speed = Speed.Normal)
{
double value;
switch (speed)
Expand Down Expand Up @@ -520,9 +536,9 @@ public static void SystemWait(Speed speed = Speed.Normal)
}

public static void SystemWait(float ms)
{
{
Wait((int)(ms * delay));
}
}

public static void Wait(int ms = 1000)
{
Expand All @@ -539,9 +555,9 @@ public static double GetDelay()
return delay;
}

internal static void ClearArtifactFilters()
{
var x = (IsNormal ? 0.0875 : 0.0868) * GetWidth();
internal static void ClearArtifactFilters()
{
var x = (IsNormal ? 0.0875 : 0.0868) * GetWidth();
var y = (IsNormal ? 0.9389 : 0.9444) * GetHeight();

for (var i = 0; i < 2; ++i)
Expand All @@ -551,9 +567,9 @@ internal static void ClearArtifactFilters()
}
sim.Keyboard.KeyPress(escapeKey);
SystemWait(Speed.Fast);
}
}

public enum Speed
public enum Speed
{
Slowest,
Slower,
Expand Down