116 lines
3.8 KiB
C#
116 lines
3.8 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ShowGiantsForm
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
|
|
const int PROCESS_WM_READ = 0x0010;
|
|
|
|
IntPtr processHandle;
|
|
Process process;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
this.BackColor = Color.Magenta;
|
|
this.TransparencyKey = Color.Magenta;
|
|
this.TopMost = true;
|
|
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
SpeedLbl.Text = "Waiting for Giants...";
|
|
}
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
{
|
|
e.Graphics.FillRectangle(Brushes.Magenta, e.ClipRectangle);
|
|
}
|
|
|
|
private void lookForProcess(String windowName)
|
|
{
|
|
process = Process.GetProcessesByName(windowName)[0];
|
|
processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
if (processHandle == IntPtr.Zero)
|
|
{
|
|
try
|
|
{
|
|
lookForProcess("Giants");
|
|
} catch (Exception ex)
|
|
{
|
|
// SpeedLbl.Text = ex.Message;
|
|
}
|
|
}
|
|
if (processHandle != IntPtr.Zero) {
|
|
RECT Rect = new RECT();
|
|
GetWindowRect(process.MainWindowHandle, ref Rect);
|
|
int newx = Rect.right - 730;
|
|
int newy = Rect.bottom - 170;
|
|
this.Location = new Point(newx, newy);
|
|
try {
|
|
float speedx = readFloatPointer(0x161D00, 0x134);
|
|
float speedy = readFloatPointer(0x161D00, 0x138);
|
|
float speedz = readFloatPointer(0x161D00, 0x13C);
|
|
|
|
float maxHp = readFloatPointer(0x161D00, 0x1c0);
|
|
float damage = readFloatPointer(0x161D00, 0x278);
|
|
float currentHp = maxHp - damage;
|
|
|
|
double speed = Math.Sqrt(Math.Pow(speedx, 2) + Math.Pow(speedy, 2) + Math.Pow(speedz, 2));
|
|
SpeedLbl.Text = "Speed: " + speed;
|
|
hpLbl.Text = "HP: " + currentHp;
|
|
} catch (Exception ex)
|
|
{
|
|
SpeedLbl.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private float readFloatPointer(int pointer, int offset)
|
|
{
|
|
int bytesRead = 0;
|
|
byte[] buffer = new byte[4];
|
|
|
|
Int32 baseAddress = process.MainModule.BaseAddress.ToInt32() + pointer;
|
|
ReadProcessMemory((int)processHandle, baseAddress, buffer, buffer.Length, ref bytesRead);
|
|
Int32 baseValue = BitConverter.ToInt32(buffer, 0);
|
|
|
|
Int32 firstAddress = baseValue + offset;
|
|
ReadProcessMemory((int)processHandle, firstAddress, buffer, buffer.Length, ref bytesRead);
|
|
float firstValue = BitConverter.ToSingle(buffer, 0);
|
|
|
|
return firstValue;
|
|
|
|
}
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
static extern bool GetWindowRect(IntPtr hWnd, ref RECT Rect);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct RECT
|
|
{
|
|
public int left;
|
|
public int top;
|
|
public int right;
|
|
public int bottom;
|
|
}
|
|
|
|
}
|
|
}
|