Skip to content

Commit

Permalink
Add ProcessPicker to support unknown process names
Browse files Browse the repository at this point in the history
ProcessPicker shows up if LoveBeat is not found. Should allow support
for LoveBeat running under different process names (LoveRitmo, LoveBeat
Korea, notepad...)
  • Loading branch information
Sean committed May 19, 2016
1 parent d64339c commit 4e88049
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 9 deletions.
42 changes: 37 additions & 5 deletions LoveBoot/BotLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,43 @@ public enum Signal

public Overlay GameOverlay { get; private set; }

public BotLogic(string[] processNames)
{
Initialize();

string foundProcess = "";

foreach(string processName in processNames)
{
if (windowFinder.SetProcess(processName)) foundProcess = processName;
}

if(foundProcess.Length > 0)
{
GameOverlay = new Overlay(this, keyCropSettings.X, keyCropSettings.Y, foundProcess);
}
else if (MessageBox.Show("No process found, is LoveBeat running?", Application.ProductName, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (ProcessPicker p = new ProcessPicker())
{
DialogResult dr = p.ShowDialog();
if (dr != DialogResult.OK) return;

string processName = p.PickedProcessName;
windowFinder.SetProcess(processName);
GameOverlay = new Overlay(this, keyCropSettings.X, keyCropSettings.Y, processName);
}
}
}

public BotLogic(string processName)
{
Initialize();
windowFinder.SetProcess(processName);
GameOverlay = new Overlay(this, keyCropSettings.X, keyCropSettings.Y, processName);
}

private void Initialize()
{
const string KEY_CROP_FILENAME = "key.lvb";
const int KEY_CROP_X = 250, KEY_CROP_Y = 473, KEY_CROP_WIDTH = 524, KEY_CROP_HEIGHT = 58;
Expand All @@ -96,14 +132,12 @@ public BotLogic(string processName)
imageFinder = new ImageFinder(0.9);

// load all images based on Signal types. throws error if any of these are not found
foreach (Signal s in Enum.GetValues(typeof (Signal)))
foreach (Signal s in Enum.GetValues(typeof(Signal)))
{
string subImagePath = String.Format("{0}{1}{2}", IMAGE_PATH, s.ToString(), IMAGE_EXT);
imageFinder.SubImages.Add(s, new Image<Bgr, byte>(subImagePath));
}

windowFinder.SetProcess(processName);

// init gamestate
for (int i = 0; i < gameState.Length; i++)
{
Expand All @@ -115,8 +149,6 @@ public BotLogic(string processName)

barCropSettings = CropSettings.Load(BAR_CROP_FILENAME, BAR_CROP_X, BAR_CROP_Y, BAR_CROP_WIDTH, BAR_CROP_HEIGHT);
barCropSettings.SaveIfNotExist(BAR_CROP_FILENAME);

GameOverlay = new Overlay(this, keyCropSettings.X, keyCropSettings.Y, processName);
}

private bool _Enabled = false;
Expand Down
9 changes: 9 additions & 0 deletions LoveBoot/LoveBoot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BotLogic.cs" />
<Compile Include="ProcessPicker.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ProcessPicker.Designer.cs">
<DependentUpon>ProcessPicker.cs</DependentUpon>
</Compile>
<Compile Include="globalKeyboardHook.cs" />
<Compile Include="ImageFinder.cs" />
<Compile Include="Overlay.cs">
Expand All @@ -96,6 +102,9 @@
<EmbeddedResource Include="Overlay.resx">
<DependentUpon>Overlay.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ProcessPicker.resx">
<DependentUpon>ProcessPicker.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
87 changes: 87 additions & 0 deletions LoveBoot/ProcessPicker.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions LoveBoot/ProcessPicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace LoveBoot
{
public partial class ProcessPicker : Form
{
public string PickedProcessName = null;

public ProcessPicker()
{
InitializeComponent();
}

private void ProcessPicker_Load(object sender, EventArgs e)
{
Process[] processes = System.Diagnostics.Process.GetProcesses();
foreach(Process p in processes)
{
cbProcess.Items.Add(p.ProcessName);
}
cbProcess.Sorted = true;
}

private void btnOK_Click(object sender, EventArgs e)
{
object selectedItem = cbProcess.SelectedItem;

/*if(selectedItem.GetType() == typeof(Process))
{
this.PickedProcessName = ((Process)selectedItem).ProcessName.Replace(".exe", "");
}
else
{*/
// user-entered string
this.PickedProcessName = selectedItem.ToString();
//}

this.DialogResult = DialogResult.OK;
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
120 changes: 120 additions & 0 deletions LoveBoot/ProcessPicker.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
7 changes: 3 additions & 4 deletions LoveBoot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LoveBoot
{
static class Program
{
private const string PROCESS_NAME = "LoveBeat";
private static readonly string[] PROCESS_NAMES = { "LoveBeat", "LoveRitmo" };

/// <summary>
/// The main entry point for the application.
Expand All @@ -18,11 +18,10 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());

BotLogic botLogic = new BotLogic(PROCESS_NAME);
BotLogic botLogic = new BotLogic(PROCESS_NAMES);

Application.Run(botLogic.GameOverlay);
if(botLogic.GameOverlay != null) Application.Run(botLogic.GameOverlay);
}
}
}

0 comments on commit 4e88049

Please sign in to comment.