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

Commit

Permalink
more fancy button scan
Browse files Browse the repository at this point in the history
  • Loading branch information
MgAl2O4 committed Jan 3, 2021
1 parent bcc726a commit f70a11b
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 270 deletions.
80 changes: 56 additions & 24 deletions ImageScan/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,40 @@ private ScannerColoPurify.ESlotType GetSlotTypeCode(char c)
}
};

private void GatherMLDataWeapon()
private struct ButtonML
{
public string fileName;
public ScannerMessageBox.EButtonType[] ButtonSlots;

public ButtonML(string path, string typeCode)
{
fileName = path;
ButtonSlots = new ScannerMessageBox.EButtonType[6];

string[] tokens = typeCode.Split(new char[] { ':', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int idx = 0; idx < tokens.Length; idx += 2)
{
var buttonPos = ScannerMessageBox.EButtonPos.Unknown;
var buttonType = ScannerMessageBox.EButtonType.Unknown;

if (tokens[idx] == "reportRetry") { buttonPos = ScannerMessageBox.EButtonPos.CombatReportRetry; }
else if (tokens[idx] == "reportOk") { buttonPos = ScannerMessageBox.EButtonPos.CombatReportOk; }
else if (tokens[idx] == "center") { buttonPos = ScannerMessageBox.EButtonPos.Center; }
else if (tokens[idx] == "centerL") { buttonPos = ScannerMessageBox.EButtonPos.CenterTwoLeft; }
else if (tokens[idx] == "centerR") { buttonPos = ScannerMessageBox.EButtonPos.CenterTwoRight; }

if (tokens[idx + 1] == "retry") { buttonType = ScannerMessageBox.EButtonType.Retry; }
else if (tokens[idx + 1] == "ok") { buttonType = ScannerMessageBox.EButtonType.Ok; }
else if (tokens[idx + 1] == "cancel") { buttonType = ScannerMessageBox.EButtonType.Cancel; }
else if (tokens[idx + 1] == "close") { buttonType = ScannerMessageBox.EButtonType.Close; }

ButtonSlots[(int)buttonPos] = buttonType;
}
}
}

private void GatherMLDataWeapon()
{
List<WeapML> fileList = new List<WeapML>();
fileList.Add(new WeapML("real-source10.jpg", "itisi"));
fileList.Add(new WeapML("real-source12.jpg", "itisi"));
Expand Down Expand Up @@ -529,38 +561,38 @@ private void GatherMLDataPurify()

private void GatherMLDataButtons()
{
var fileMap = new Dictionary<string, ScannerMessageBox.ESpecialBox>();
fileMap.Add("real-buttons.jpg", ScannerMessageBox.ESpecialBox.CombatReportOk);
fileMap.Add("real-source4.jpg", ScannerMessageBox.ESpecialBox.CombatReportOk);
fileMap.Add("real-source5.jpg", ScannerMessageBox.ESpecialBox.CombatReportOk);
fileMap.Add("real-source6.jpg", ScannerMessageBox.ESpecialBox.CombatReportOk);
fileMap.Add("real-source7.jpg", ScannerMessageBox.ESpecialBox.CombatReportOk);
fileMap.Add("real-msg1.jpg", ScannerMessageBox.ESpecialBox.MessageBoxOk);
fileMap.Add("real-msg2.jpg", ScannerMessageBox.ESpecialBox.MessageBoxOk);
List<ButtonML> fileList = new List<ButtonML>();
fileList.Add(new ButtonML("real-buttons.jpg", "reportRetry:retry, reportOk:ok"));
fileList.Add(new ButtonML("real-source4.jpg", "reportRetry:retry, reportOk:ok"));
fileList.Add(new ButtonML("real-source5.jpg", "reportRetry:retry, reportOk:ok"));
fileList.Add(new ButtonML("real-source6.jpg", "reportRetry:retry, reportOk:ok"));
fileList.Add(new ButtonML("real-source7.jpg", "reportRetry:retry, reportOk:ok"));
fileList.Add(new ButtonML("real-msg1.jpg", "center:ok"));
fileList.Add(new ButtonML("real-msg2.jpg", "center:ok"));
fileList.Add(new ButtonML("real-msgClose.jpg", "center:close"));
fileList.Add(new ButtonML("real-msgClose2.jpg", "center:close"));
fileList.Add(new ButtonML("real-msgOkCancel.jpg", "centerL:cancel, centerR:ok"));

string jsonDesc = "{\"dataset\":[";
foreach (var kvp in fileMap)
foreach (var fileData in fileList)
{
var srcScreenshot = LoadTestScreenshot("train-smol/" + kvp.Key);
var srcScreenshot = LoadTestScreenshot("train-smol/" + fileData.fileName);
var fastBitmap = ScreenshotUtilities.ConvertToFastBitmap(srcScreenshot);

var buttonsScanner = scanners[2] as ScannerMessageBox;
for (int idx = 1; idx <= 3; idx++)
for (int idx = 0; idx < fileData.ButtonSlots.Length; idx++)
{
var values = buttonsScanner.ExtractButtonData(fastBitmap, idx);
var canUse =
(kvp.Value == ScannerMessageBox.ESpecialBox.MessageBoxOk && idx == (int)ScannerMessageBox.ESpecialBox.MessageBoxOk) ||
(kvp.Value == ScannerMessageBox.ESpecialBox.CombatReportOk && idx == (int)ScannerMessageBox.ESpecialBox.CombatReportOk) ||
(kvp.Value == ScannerMessageBox.ESpecialBox.CombatReportOk && idx == (int)ScannerMessageBox.ESpecialBox.CombatReportRetry);

if (canUse)
if (fileData.ButtonSlots[idx] == ScannerMessageBox.EButtonType.Unknown)
{
jsonDesc += "\n{\"input\":[";
jsonDesc += string.Join(",", values);
jsonDesc += "], \"output\":";
jsonDesc += idx;
jsonDesc += "},";
continue;
}

var values = buttonsScanner.ExtractButtonData(fastBitmap, idx);
jsonDesc += "\n{\"input\":[";
jsonDesc += string.Join(",", values);
jsonDesc += "], \"output\":";
jsonDesc += (int)fileData.ButtonSlots[idx];
jsonDesc += "},";
}
}

Expand Down
2 changes: 1 addition & 1 deletion ML/sinocolo-buttons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nn import NNTraining

training = NNTraining(inputFile='sino-ml-buttons.json', outputFile='sino-ml-buttons.txt')
training.run(numFeatures=16*5, numClasses=4, numSteps=10000)
training.run(numFeatures=16*8, numClasses=5)
73 changes: 54 additions & 19 deletions SINoCOLO/GameLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GameLogic
public ScannerColoCombat.ScreenData cachedDataColoCombat;
public ScannerColoPurify.ScreenData cachedDataColoPurify;
public ScannerCombat.ScreenData cachedDataCombat;
public ScannerMessageBox.ScreenData cachedDataMessageBox;

public int slotIdx = -1;
public int specialIdx = -1;
Expand Down Expand Up @@ -155,6 +156,7 @@ private bool OnScan_ColoCombat(ScannerColoCombat.ScreenData screenData)

cachedDataColoCombat = screenData;
cachedDataCombat = null;
cachedDataMessageBox = null;
scanSkipCounter--;
if (scanSkipCounter > 0)
{
Expand Down Expand Up @@ -350,6 +352,7 @@ private bool OnScan_ColoPurify(ScannerColoPurify.ScreenData screenData)
}

cachedDataColoPurify = screenData;
cachedDataMessageBox = null;

// don't do anything when burst is already active
if (screenData.BurstState == ScannerColoPurify.EBurstState.Active)
Expand Down Expand Up @@ -507,6 +510,8 @@ private bool OnScan_MessageBox(ScannerMessageBox.ScreenData screenData)
OnStateChanged();
}

cachedDataMessageBox = screenData;

scanSkipCounter--;
if (scanSkipCounter > 0)
{
Expand All @@ -515,40 +520,69 @@ private bool OnScan_MessageBox(ScannerMessageBox.ScreenData screenData)

// random delay: 0.5..0.8s between action presses (OnScan interval = 100ms)
scanSkipCounter = randGen.Next(5, 8);
specialIdx = -1;

int specialIdx = (int)screenData.mode;
if (screenData.hasRetry)
switch (screenData.mode)
{
specialIdx = (int)ScannerMessageBox.ESpecialBox.CombatReportRetry;
scanSkipCounter = randGen.Next(25, 30);
case ScannerMessageBox.EMessageType.CombatReport:
scanSkipCounter = randGen.Next(25, 30);
specialIdx = (int)ScannerMessageBox.EButtonPos.CombatReportRetry;
break;

case ScannerMessageBox.EMessageType.Ok:
specialIdx = (int)ScannerMessageBox.EButtonPos.Center;
break;

case ScannerMessageBox.EMessageType.OkCancel:
specialIdx = (int)ScannerMessageBox.EButtonPos.CenterTwoRight;
break;

default: break;
}

if (specialIdx >= 0)
{
RequestMouseClick(screenScanner.GetSpecialActionBox(specialIdx), -1, specialIdx);
}

RequestMouseClick(screenScanner.GetSpecialActionBox(specialIdx), -1, specialIdx);
return true;
}

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

if (screenData.mode == ScannerMessageBox.ESpecialBox.MessageBoxOk)
Rectangle boxA = Rectangle.Empty, boxB = Rectangle.Empty;
switch (screenData.mode)
{
Rectangle okBox = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.ESpecialBox.MessageBoxOk);
DrawActionArea(g, okBox, "Ok", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.ESpecialBox.MessageBoxOk);
}
else if (screenData.mode == ScannerMessageBox.ESpecialBox.CombatReportOk)
{
Rectangle okBox = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.ESpecialBox.CombatReportOk);
DrawActionArea(g, okBox, "Ok", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.ESpecialBox.CombatReportOk);
case ScannerMessageBox.EMessageType.Ok:
boxA = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.Center);
DrawActionArea(g, boxA, "Ok", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.EButtonPos.Center);
break;

if (screenData.hasRetry)
{
Rectangle retryBox = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.ESpecialBox.CombatReportRetry);
DrawActionArea(g, retryBox, "Retry", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.ESpecialBox.CombatReportRetry);
}
case ScannerMessageBox.EMessageType.OkCancel:
boxA = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.CenterTwoLeft);
boxB = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.CenterTwoRight);
DrawActionArea(g, boxA, "Cancel", colorPaletteYellow, specialIdx == (int)ScannerMessageBox.EButtonPos.CenterTwoLeft);
DrawActionArea(g, boxB, "Ok", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.EButtonPos.CenterTwoRight);
break;

case ScannerMessageBox.EMessageType.CombatReport:
boxA = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.CombatReportRetry);
boxB = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.CombatReportOk);
DrawActionArea(g, boxA, "Retry", colorPaletteGreen, specialIdx == (int)ScannerMessageBox.EButtonPos.CombatReportRetry);
DrawActionArea(g, boxB, "Ok", colorPaletteYellow, specialIdx == (int)ScannerMessageBox.EButtonPos.CombatReportOk);
break;

case ScannerMessageBox.EMessageType.Close:
boxA = screenScanner.GetSpecialActionBox((int)ScannerMessageBox.EButtonPos.Center);
DrawActionArea(g, boxA, "Close", colorPaletteYellow, specialIdx == (int)ScannerMessageBox.EButtonPos.Center);
break;

default: break;
}

return false;
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -565,6 +599,7 @@ private bool OnScan_Combat(ScannerCombat.ScreenData screenData)
cachedDataCombat = screenData;
cachedDataColoCombat = null;
cachedDataColoPurify = null;
cachedDataMessageBox = null;

scanSkipCounter--;
if (scanSkipCounter > 0)
Expand Down
8 changes: 8 additions & 0 deletions SINoCOLO/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ private void DetailLog()
lines.AddRange(tokens);
}

if (gameLogic.cachedDataMessageBox != null)
{
lines.Add("");
lines.Add("Cached MessageBox:");
string[] tokens = gameLogic.cachedDataMessageBox.ToString().Split('\n');
lines.AddRange(tokens);
}

textBoxDetails.Lines = lines.ToArray();
}
}
Expand Down
Loading

0 comments on commit f70a11b

Please sign in to comment.