diff --git a/ControllerSettings.cs b/ControllerSettings.cs
index a297253..336defc 100755
--- a/ControllerSettings.cs
+++ b/ControllerSettings.cs
@@ -288,11 +288,11 @@ public bool UpdateScreenValues()
d3_Rect.Left = Int32.Parse(Between(ref readText, "DisplayModeWinLeft \"", "\"", false));
d3_Rect.Top = Int32.Parse(Between(ref readText, "DisplayModeWinTop \"", "\"", false));
d3_Rect.Right = d3_Rect.Left + d3Width;
- d3_Rect.Bottom = d3_Rect.Top + d3Height;
// Windows bar
d3_Rect.Top += 30;
- d3Height -= 30;
+ d3Height -= 38; // why 8 ?!
+ d3_Rect.Bottom = d3_Rect.Top + d3Height;
}
else
{
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 8181ae2..d7a2ff4 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -1,6 +1,8 @@
-
+ Title="d3gamepad" Height="720" Width="1280" Topmost="True" AllowsTransparency="True" WindowStyle="None" Background="{x:Null}" Left="0" Top="0">
+
\ No newline at end of file
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 5931f71..ee19477 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -26,24 +26,21 @@ public partial class MainWindow : Window
private static GameController _gameController;
private static InputSimulator _inputSimulator;
private static ControllerSettings _settings;
-
- [DllImport("user32.dll")]
- static extern bool GetCursorPos(ref System.Drawing.Point lpPoint);
-
- [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
- public static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
[DllImport("User32.Dll")]
public static extern long SetCursorPos(int x, int y);
+ [DllImport("user32.dll")]
+ static extern IntPtr GetForegroundWindow();
+
+ [DllImport("user32.dll")]
+ static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
+
public static Bitmap CaptureFromScreen(System.Drawing.Point location, int width, int height)
{
Bitmap bmpScreenCapture = new Bitmap(width, height);
-
Graphics p = Graphics.FromImage(bmpScreenCapture);
-
p.CopyFromScreen(location.X,location.Y, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy);
-
p.Dispose();
return bmpScreenCapture;
@@ -52,9 +49,7 @@ public static Bitmap CaptureFromScreen(System.Drawing.Point location, int width,
public static System.Drawing.Color GetColorFromScreen(System.Drawing.Point location)
{
Bitmap map = CaptureFromScreen(location,1,1);
-
System.Drawing.Color c = map.GetPixel(0, 0);
-
map.Dispose();
return c;
@@ -65,7 +60,7 @@ public static System.Drawing.Color GetColorFromScreen(System.Drawing.Point locat
static double default_padding = 11;
static double default_cell = 56;
static double default_bottom = 22;
- static double default_checkui = 120;
+ static double default_checkui = 17;
static double default_check_inventory_w = 17;
static double default_check_inventory_h = 26;
@@ -84,8 +79,8 @@ public static System.Drawing.Color GetColorFromScreen(System.Drawing.Point locat
private static void ComputeScreenValues()
{
- current_h_ratio = (double)_settings.UIHeight;
- current_w_ratio = (double)_settings.UIWidth;
+ current_h_ratio = _settings.UIHeight;
+ current_w_ratio = _settings.UIWidth;
compute_h_ratio = current_h_ratio / default_h_ratio;
compute_w_ratio = current_w_ratio / default_w_ratio;
@@ -104,12 +99,6 @@ private static void ComputeScreenValues()
current_life_check_left = default_life_check_left * compute_h_ratio;
}
- [DllImport("user32.dll")]
- static extern IntPtr GetForegroundWindow();
-
- [DllImport("user32.dll")]
- static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
-
private static string GetActiveWindowTitle()
{
const int nChars = 256;
@@ -130,15 +119,14 @@ private static bool IsInGame()
private static bool IsInMap()
{
- double cursor_x = _settings.d3_Rect.Left + _settings.c_d3Width;
+ double cursor_x = _settings.d3_Rect.Left + _settings.c_d3Width - (34 * compute_h_ratio);
double cursor_y = _settings.d3_Rect.Bottom - current_checkui;
System.Drawing.Point cursor = new System.Drawing.Point((int)cursor_x, (int)cursor_y);
System.Drawing.Color c = GetColorFromScreen(cursor);
- if (c.R >= 130 && c.G >= 130 && c.B >= 130)
- if(c.R <= 220 && c.G <= 220 && c.B <= 220)
- return true;
+ if (c.G > c.R && c.G > c.B && c.R <= 50 && c.G >= 100 && c.B <= 50)
+ return true;
return false;
}
@@ -180,7 +168,6 @@ private static int CheckHealth()
G = c.G > 0 ? c.G : 1;
B = c.B > 0 ? c.B : 1;
- Trace.WriteLine(R + "," + G + "," + B);
if (R / G > 2 && R / B > 2 && R > 50 && R < 140)
break;
else
@@ -240,57 +227,32 @@ public static void ThreadUI()
ComputeScreenValues();
Application.Current.Dispatcher.BeginInvoke((Action)(() =>
{
- myCanvas.Children.Clear();
myForm.Height = _settings.d3Height;
myForm.Width = _settings.d3Width;
myForm.Top = _settings.d3_Rect.Top;
myForm.Left = _settings.d3_Rect.Left;
- draw_pos_x = _settings.c_d3Width - (current_padding / 2);
- draw_pos_y = _settings.d3Height - current_cell - (default_bottom * compute_h_ratio);
+ myGamepad.Width = (int)current_cell;
+ myGamepad.Height = (int)current_cell;
+ Canvas.SetTop(myGamepad, 40 * compute_h_ratio); // temp
+ Canvas.SetLeft(myGamepad, _settings.d3Width - (90 * compute_h_ratio)); // temp
- for (int i = 0; i < 5; i++)
- draw_pos_x -= current_cell;
+ draw_pos_x = _settings.c_d3Width - (current_padding / 2) - current_cell;
+ draw_pos_y = _settings.d3Height - current_cell - current_bottom;
for (int i = 0; i < 4; i++)
- draw_pos_x -= current_padding;
-
- if (_settings.DisplayModeWindowMode == 1)
- draw_pos_y -= 8;
+ draw_pos_x -= (current_cell + current_padding);
- string ico;
- for (int i = -9; i <= 3; i += 2)
+ foreach(UIElement item in myCanvas.Children)
{
- switch (i)
+ if (item is System.Windows.Shapes.Rectangle)
{
- case -9: ico = "B"; break;
- case -7: ico = "Y"; break;
- case -5: ico = "RB"; break;
- case -3: ico = "RT"; break;
- case -1: ico = "X"; break;
- case 1: ico = "A"; break;
- case 3: ico = "LB"; break;
- default: ico = "B"; break;
- }
+ ((System.Windows.Shapes.Rectangle)item).Width = (int)current_cell / 2;
+ ((System.Windows.Shapes.Rectangle)item).Height = (int)current_cell / 2;
+
+ Canvas.SetTop(item, draw_pos_y);
+ Canvas.SetLeft(item, draw_pos_x);
- System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle
- {
- Name = "button_" + ico,
- Fill = new ImageBrush
- {
- ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(".\\Ressources\\XBOne_" + ico + ".png", UriKind.Relative))
- },
- Width = (int)current_cell / 2,
- Height = (int)current_cell / 2,
- Stretch = Stretch.Uniform,
- };
-
- Canvas.SetTop(rect, draw_pos_y);
- Canvas.SetLeft(rect, draw_pos_x);
- myCanvas.Children.Add(rect);
-
- if (i <= 1)
- {
draw_pos_x += current_cell;
draw_pos_x += current_padding;
}
@@ -300,13 +262,32 @@ public static void ThreadUI()
}));
}
- if (IsInGame() && IsInMap())
- {
- if(myCanvas.Visibility == Visibility.Hidden)
- Application.Current.Dispatcher.BeginInvoke((Action)(() => { myCanvas.Visibility = Visibility.Visible; }));
- }
- else if (myCanvas.Visibility == Visibility.Visible)
- Application.Current.Dispatcher.BeginInvoke((Action)(() => { myCanvas.Visibility = Visibility.Hidden; }));
+ Application.Current.Dispatcher.BeginInvoke((Action)(() => {
+ if (IsInGame())
+ {
+ myCanvas.Visibility = Visibility.Visible;
+
+ if (_gameController.IsConnected())
+ myGamepad.Visibility = Visibility.Visible;
+ else
+ myGamepad.Visibility = Visibility.Hidden;
+
+ if (IsInMap())
+ {
+ foreach (UIElement item in myCanvas.Children)
+ if (item is System.Windows.Shapes.Rectangle)
+ item.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ foreach (UIElement item in myCanvas.Children)
+ if (item is System.Windows.Shapes.Rectangle)
+ item.Visibility = Visibility.Hidden;
+ }
+ }
+ else
+ myCanvas.Visibility = Visibility.Hidden;
+ }));
Thread.Sleep(100);
}
@@ -314,6 +295,7 @@ public static void ThreadUI()
static d3gamepad.MainWindow myForm;
static Canvas myCanvas;
+ static System.Windows.Controls.Image myGamepad;
public MainWindow()
{
InitializeComponent();
@@ -329,6 +311,33 @@ public MainWindow()
// STATICS
myForm = Form1;
myCanvas = Canvas1;
+ myGamepad = GamepadIco;
+
+ string ico = "Menu";
+ for (int i = 0; i < 7; i ++)
+ {
+ switch (i)
+ {
+ case 0: ico = "B"; break;
+ case 1: ico = "Y"; break;
+ case 2: ico = "RB"; break;
+ case 3: ico = "RT"; break;
+ case 4: ico = "X"; break;
+ case 5: ico = "A"; break;
+ case 6: ico = "LB"; break;
+ }
+
+ System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle
+ {
+ Fill = new ImageBrush
+ {
+ ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(".\\Ressources\\XBOne_" + ico + ".png", UriKind.Relative))
+ },
+ Stretch = Stretch.Uniform,
+ };
+
+ myCanvas.Children.Add(rect);
+ }
Thread myThread = new Thread(new ThreadStart(ThreadHealth));
myThread.Start();
@@ -340,9 +349,6 @@ public MainWindow()
myThread3.Start();
}
- [DllImport("user32.dll", SetLastError = true)]
- private static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
-
[StructLayout(LayoutKind.Sequential)]
private struct INPUT
{
diff --git a/Ressources/XBOne_Gamepad.png b/Ressources/XBOne_Gamepad.png
new file mode 100644
index 0000000..58e43e2
Binary files /dev/null and b/Ressources/XBOne_Gamepad.png differ
diff --git a/d3gamepad.csproj b/d3gamepad.csproj
index 7b80af1..f671e86 100644
--- a/d3gamepad.csproj
+++ b/d3gamepad.csproj
@@ -227,6 +227,9 @@
Always
+
+ Always
+