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

Commit

Permalink
added scanner for title screen
Browse files Browse the repository at this point in the history
needed for some disconnect errors
  • Loading branch information
MgAl2O4 committed Jan 10, 2021
1 parent 1b322c0 commit 9b7cbbb
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 1 deletion.
1 change: 1 addition & 0 deletions ImageScan/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public MainForm()
scanners.Add(new ScannerColoPurify());
scanners.Add(new ScannerMessageBox());
scanners.Add(new ScannerCombat());
scanners.Add(new ScannerTitleScreen());

foreach (var scanner in scanners)
{
Expand Down
51 changes: 50 additions & 1 deletion SINoCOLO/GameLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum EState
ColoPurify,
Combat,
MessageBox,
TitleScreen,
}
private EState state;

Expand Down Expand Up @@ -76,6 +77,7 @@ public void OnScan()
handled = handled || OnScan_ColoPurify(screenData as ScannerColoPurify.ScreenData);
handled = handled || OnScan_MessageBox(screenData as ScannerMessageBox.ScreenData);
handled = handled || OnScan_Combat(screenData as ScannerCombat.ScreenData);
handled = handled || OnScan_TitleScreen(screenData as ScannerTitleScreen.ScreenData);

if (!handled)
{
Expand All @@ -91,6 +93,7 @@ public void DrawScanHighlights(Graphics g)
handled = handled || DrawScanHighlights_ColoPurify(g, screenData as ScannerColoPurify.ScreenData);
handled = handled || DrawScanHighlights_MessageBox(g, screenData as ScannerMessageBox.ScreenData);
handled = handled || DrawScanHighlights_Combat(g, screenData as ScannerCombat.ScreenData);
handled = handled || DrawScanHighlights_TitleScreen(g, screenData as ScannerTitleScreen.ScreenData);

if (!handled)
{
Expand Down Expand Up @@ -160,7 +163,7 @@ public void AppendDetails(List<string> lines)
{
if (boostDesc.Length > 0) { boostDesc += ", "; }
boostDesc += elemType.ToString();

if (boostUpkeep[idx] < boostUpkeepTicks)
{
boostDesc += string.Format(" (fading: {0})", boostUpkeep[idx]);
Expand Down Expand Up @@ -795,5 +798,51 @@ private bool DrawScanHighlights_Combat(Graphics g, ScannerCombat.ScreenData scre

return true;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////

private bool OnScan_TitleScreen(ScannerTitleScreen.ScreenData screenData)
{
if (screenData == null) { return false; }

if (state != EState.TitleScreen)
{
state = EState.TitleScreen;
OnStateChanged();

scanSkipCounter = 50; // 5s opening delay
}

cachedDataCombat = null;
cachedDataColoCombat = null;
cachedDataColoPurify = null;
cachedDataMessageBox = null;

scanSkipCounter--;
if (scanSkipCounter > 0)
{
return true;
}

// fixed delay: 10s between action presses (OnScan interval = 100ms)
scanSkipCounter = 100;

specialIdx = 0;
Rectangle actionBox = screenScanner.GetSpecialActionBox(specialIdx);
RequestMouseClick(actionBox, -1, specialIdx);
return true;
}

private bool DrawScanHighlights_TitleScreen(Graphics g, ScannerTitleScreen.ScreenData screenData)
{
if (screenData == null) { return false; }

Rectangle bigButtonBox = screenScanner.GetSpecialActionBox(0);
bool isStartActive = specialIdx == 0;
DrawActionArea(g, bigButtonBox, "START", colorPaletteGreen, isStartActive);

return true;
}
}
}
1 change: 1 addition & 0 deletions SINoCOLO/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public MainForm()
scanners.Add(new ScannerColoPurify());
scanners.Add(new ScannerMessageBox());
scanners.Add(new ScannerCombat());
scanners.Add(new ScannerTitleScreen());

foreach (var scanner in scanners)
{
Expand Down
139 changes: 139 additions & 0 deletions SINoVision/ScannerTitleScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System;
using System.Drawing;

namespace SINoVision
{
public class ScannerTitleScreen : ScannerBase
{
public class ScreenData
{
public override string ToString()
{
return "Title screen";
}
}

private FastPixelMatch matchLogoRed = new FastPixelMatchHueMono(0, 20, 20, 80);
private FastPixelMatch matchLogoBlue = new FastPixelMatchHueMono(200, 220, 50, 100);
private FastPixelMatch matchLogoWhite = new FastPixelMatchMono(253, 255);
private FastPixelMatch matchLogoBlack = new FastPixelMatchMono(0, 3);

private Rectangle rectStartArea = new Rectangle(25, 265, 280, 130);

private Point[] posLogoWhite = new Point[] {
new Point(266, 551), new Point(266, 556), new Point(266, 562),
new Point(290, 551), new Point(290, 556), new Point(290, 562),
new Point(265, 576), new Point(278, 576), new Point(291, 576),
new Point(265, 576), new Point(278, 576)
};
private Point[] posLogoBlue = new Point[] {
new Point(278, 554), new Point(278, 558), new Point(278, 561), new Point(278, 565)
};
private Point[] posLogoBlack = new Point[] {
new Point(303, 550), new Point(312, 550), new Point(321, 550), new Point(329, 550),
new Point(303, 554), new Point(312, 554), new Point(321, 554), new Point(329, 554),
new Point(303, 571), new Point(329, 571),
new Point(303, 575), new Point(312, 575), new Point(321, 575), new Point(329, 575)
};
private Point[] posLogoRed = new Point[] {
new Point(309, 569), new Point(313, 569), new Point(318, 569), new Point(322, 569)
};

private string[] scannerStates = new string[] { "Idle", "NoLogo", "Ok" };

public ScannerTitleScreen()
{
ScannerName = "[TitleScreen]";
DebugLevel = EDebugLevel.None;
}

public override string GetState()
{
return scannerStates[scannerState];
}

public override object Process(FastBitmapHSV bitmap)
{
scannerState = 1;
var hasMsgBox = HasLogoMarkers(bitmap);
if (hasMsgBox)
{
scannerState = 2;
var outputOb = new ScreenData();
return outputOb;
}

return null;
}

public override Rectangle GetSpecialActionBox(int actionType)
{
return rectStartArea;
}

protected bool HasLogoMarkers(FastBitmapHSV bitmap)
{
foreach (var pos in posLogoWhite)
{
var isMatching = matchLogoWhite.IsMatching(bitmap.GetPixel(pos.X, pos.Y));
if (!isMatching)
{
if (DebugLevel >= EDebugLevel.Verbose)
{
Console.WriteLine("{0} HasLogoMarkers: failed WHITE => ({1},{2}) = ({3}) vs ({4})",
ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoWhite);
}

return false;
}
}

foreach (var pos in posLogoBlack)
{
var isMatching = matchLogoBlack.IsMatching(bitmap.GetPixel(pos.X, pos.Y));
if (!isMatching)
{
if (DebugLevel >= EDebugLevel.Verbose)
{
Console.WriteLine("{0} HasLogoMarkers: failed BLACK => ({1},{2}) = ({3}) vs ({4})",
ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoBlack);
}

return false;
}
}

foreach (var pos in posLogoBlue)
{
var isMatching = matchLogoBlue.IsMatching(bitmap.GetPixel(pos.X, pos.Y));
if (!isMatching)
{
if (DebugLevel >= EDebugLevel.Verbose)
{
Console.WriteLine("{0} HasLogoMarkers: failed BLUE => ({1},{2}) = ({3}) vs ({4})",
ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoBlue);
}

return false;
}
}

foreach (var pos in posLogoRed)
{
var isMatching = matchLogoRed.IsMatching(bitmap.GetPixel(pos.X, pos.Y));
if (!isMatching)
{
if (DebugLevel >= EDebugLevel.Verbose)
{
Console.WriteLine("{0} HasLogoMarkers: failed RED => ({1},{2}) = ({3}) vs ({4})",
ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoRed);
}

return false;
}
}

return true;
}
}
}

0 comments on commit 9b7cbbb

Please sign in to comment.