diff --git a/Program.cs b/Program.cs index 09b1de1..54c68e4 100644 --- a/Program.cs +++ b/Program.cs @@ -35,7 +35,7 @@ static partial class Program private static int _resolution; private static readonly IntPtr _windowHandle; - private static ReadonlyImage _lastCapture = null; + private static ReadonlyImage _lastSS = null; private static int _windowWidth = -1; private static int _windowHeight = -1; private static int _targetLeft = -1; @@ -108,6 +108,8 @@ static Program() private static void Main() { + // ActivateDirectXWorkaround(); + Console.WriteLine(_jpMode ? "BOTTO wo kidou simasita." : "Bot started."); Console.WriteLine(_jpMode ? "CTRL + C wo osite teisi." : "Press ctrl + C to stop."); if (_hardwareAccelerated) { } @@ -129,9 +131,6 @@ private static void Main() Stopwatch waitSw = Stopwatch.StartNew(); while (true) { - // Invalidate capture - _lastCapture = null; - if (!playing) { perfSw.Stop(); @@ -145,6 +144,8 @@ private static void Main() continue; } + InvalidateLastSS(); + if (_targetLeft >= 0 && _targetTop >= 0) { PlayFishingGame(ref playing, in timeoutSw); @@ -179,10 +180,7 @@ private static void Main() ? "20byou inai ni NO-TU ga mitukarimasen desita. kore ga tudukeru baai ha, HoloCure no kaizoudo wo tiisaku site kudasai. MINIGE-MU wo saikidou simasu." : "No notes detected in 20 seconds. If this continues, try setting HoloCure to a smaller resolution. Restarting minigame." ); - if (!_hardwareAccelerated) - { - ActivateDirectXWorkaround(); - } + ActivateDirectXWorkaround(); playing = false; timeoutSw.Restart(); @@ -344,6 +342,11 @@ private static void FindTargetArea() private static void ActivateDirectXWorkaround() { + if (_hardwareAccelerated) + { + return; + } + _hardwareAccelerated = true; _notes = new Note[] @@ -384,13 +387,13 @@ private static void ActivateDirectXWorkaround() Console.WriteLine( _jpMode ? "3. ika no settei wo dekiru kagiri OFU ni site kudasai:" - + "\n\ta. UXINDOU GE-MU no saitekika" - + "\n\tb. kahen RIFURESSYU RE-TO" - + "\n\tc. zidou HDR" + + "\n a. UXINDOU GE-MU no saitekika" + + "\n b. kahen RIFURESSYU RE-TO" + + "\n c. zidou HDR" : "3. Disable the following (if the setting(s) can be found):" - + "\n\ta. Optimizations for windowed games" - + "\n\tb. Variable refresh rate" - + "\n\tc. Auto HDR" + + "\n a. Optimizations for windowed games" + + "\n b. Variable refresh rate" + + "\n c. Auto HDR" ); Console.WriteLine( _jpMode diff --git a/WindowCapture.cs b/WindowCapture.cs index ff20ae1..902c3cf 100644 --- a/WindowCapture.cs +++ b/WindowCapture.cs @@ -3,7 +3,7 @@ using System.Drawing.Imaging; using System.Runtime.InteropServices; -internal static partial class Program +static partial class Program { [StructLayout(LayoutKind.Sequential)] private struct Rect @@ -84,10 +84,9 @@ private static int GetHolocureResolution(Rect rect) : $"HoloCure window was resized to {width} x {height}" ); - // Invalidate target position and capture + // Invalidate target position _targetLeft = -1; _targetTop = -1; - _lastCapture = null; } width -= GRACE; @@ -117,7 +116,7 @@ private static int GetHolocureResolution(Rect rect) } // Always behaves as if the window is 640 x 360 - public static ReadonlyImage CaptureHolocureWindow( + private static ReadonlyImage CaptureHolocureWindow( int left = 0, int top = 0, int width = -1, @@ -141,20 +140,17 @@ public static ReadonlyImage CaptureHolocureWindow( height = _windowHeight; } - if (_hardwareAccelerated && _lastCapture != null) - { - return _lastCapture.Crop(left, top, width, height); - } - if (_hardwareAccelerated) { - Bitmap bmp = new Bitmap(_windowWidth, _windowHeight, PixelFormat.Format32bppArgb); - Graphics graphics = Graphics.FromImage(bmp); - graphics.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size); - ReadonlyImage capture = new ReadonlyImage(bmp).ShrinkBy(_resolution); - _lastCapture = capture; - - return capture.Crop(left, top, width, height); + if (_lastSS == null) + { + Bitmap bmp = new Bitmap(_windowWidth, _windowHeight, PixelFormat.Format32bppArgb); + Graphics graphics = Graphics.FromImage(bmp); + graphics.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size); + _lastSS = new ReadonlyImage(bmp); + } + + return _lastSS.Crop(left, top, width, height).ShrinkBy(_resolution); } else { @@ -169,4 +165,9 @@ public static ReadonlyImage CaptureHolocureWindow( return new ReadonlyImage(bmp).ShrinkBy(_resolution); } } + + private static void InvalidateLastSS() + { + _lastSS = null; + } }