WIP - arrows and angles

This commit is contained in:
Conor 2021-01-19 21:32:11 +00:00
parent c5bb1d7fad
commit ccf796cdf6
10 changed files with 332 additions and 13 deletions

Binary file not shown.

View File

@ -28,9 +28,27 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.lblGameStatus = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblPlayerIncline = new System.Windows.Forms.Label();
this.lblPlayerAzimuth = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.lblPlayerZ = new System.Windows.Forms.Label();
this.lblPlayerY = new System.Windows.Forms.Label();
this.lblPlayerX = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.PlayerStatsTimer = new System.Windows.Forms.Timer(this.components);
this.label7 = new System.Windows.Forms.Label();
this.lblNumberOfPlayers = new System.Windows.Forms.Label();
this.pbMap = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbMap)).BeginInit();
this.SuspendLayout();
//
// label1
@ -53,7 +71,7 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(173, 124);
this.button1.Location = new System.Drawing.Point(176, 241);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
@ -61,16 +79,164 @@
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblPlayerIncline);
this.groupBox1.Controls.Add(this.lblPlayerAzimuth);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.lblPlayerZ);
this.groupBox1.Controls.Add(this.lblPlayerY);
this.groupBox1.Controls.Add(this.lblPlayerX);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(13, 43);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(152, 184);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Your Stats";
//
// lblPlayerIncline
//
this.lblPlayerIncline.AutoSize = true;
this.lblPlayerIncline.Location = new System.Drawing.Point(68, 68);
this.lblPlayerIncline.Name = "lblPlayerIncline";
this.lblPlayerIncline.Size = new System.Drawing.Size(22, 15);
this.lblPlayerIncline.TabIndex = 1;
this.lblPlayerIncline.Text = "0.0";
//
// lblPlayerAzimuth
//
this.lblPlayerAzimuth.AutoSize = true;
this.lblPlayerAzimuth.Location = new System.Drawing.Point(68, 83);
this.lblPlayerAzimuth.Name = "lblPlayerAzimuth";
this.lblPlayerAzimuth.Size = new System.Drawing.Size(22, 15);
this.lblPlayerAzimuth.TabIndex = 1;
this.lblPlayerAzimuth.Text = "0.0";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 83);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(55, 15);
this.label6.TabIndex = 0;
this.label6.Text = "Azimuth:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(7, 68);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(45, 15);
this.label5.TabIndex = 0;
this.label5.Text = "Incline:";
//
// lblPlayerZ
//
this.lblPlayerZ.AutoSize = true;
this.lblPlayerZ.Location = new System.Drawing.Point(68, 53);
this.lblPlayerZ.Name = "lblPlayerZ";
this.lblPlayerZ.Size = new System.Drawing.Size(22, 15);
this.lblPlayerZ.TabIndex = 1;
this.lblPlayerZ.Text = "0.0";
//
// lblPlayerY
//
this.lblPlayerY.AutoSize = true;
this.lblPlayerY.Location = new System.Drawing.Point(68, 38);
this.lblPlayerY.Name = "lblPlayerY";
this.lblPlayerY.Size = new System.Drawing.Size(22, 15);
this.lblPlayerY.TabIndex = 1;
this.lblPlayerY.Text = "0.0";
//
// lblPlayerX
//
this.lblPlayerX.AutoSize = true;
this.lblPlayerX.Location = new System.Drawing.Point(68, 23);
this.lblPlayerX.Name = "lblPlayerX";
this.lblPlayerX.Size = new System.Drawing.Size(22, 15);
this.lblPlayerX.TabIndex = 1;
this.lblPlayerX.Text = "0.0";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(7, 53);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(17, 15);
this.label4.TabIndex = 0;
this.label4.Text = "Z:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 38);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(17, 15);
this.label3.TabIndex = 0;
this.label3.Text = "Y:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(7, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(17, 15);
this.label2.TabIndex = 0;
this.label2.Text = "X:";
//
// PlayerStatsTimer
//
this.PlayerStatsTimer.Tick += new System.EventHandler(this.PlayerStatsTimer_Tick);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(13, 241);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(108, 15);
this.label7.TabIndex = 0;
this.label7.Text = "Number of Players:";
//
// lblNumberOfPlayers
//
this.lblNumberOfPlayers.AutoSize = true;
this.lblNumberOfPlayers.Location = new System.Drawing.Point(127, 241);
this.lblNumberOfPlayers.Name = "lblNumberOfPlayers";
this.lblNumberOfPlayers.Size = new System.Drawing.Size(13, 15);
this.lblNumberOfPlayers.TabIndex = 0;
this.lblNumberOfPlayers.Text = "0";
//
// pbMap
//
this.pbMap.BackColor = System.Drawing.Color.White;
this.pbMap.Location = new System.Drawing.Point(306, 31);
this.pbMap.Name = "pbMap";
this.pbMap.Size = new System.Drawing.Size(431, 363);
this.pbMap.TabIndex = 4;
this.pbMap.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pbMap);
this.Controls.Add(this.lblNumberOfPlayers);
this.Controls.Add(this.label7);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.lblGameStatus);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pbMap)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -81,6 +247,21 @@
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblGameStatus;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblPlayerZ;
private System.Windows.Forms.Label lblPlayerY;
private System.Windows.Forms.Label lblPlayerX;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Timer PlayerStatsTimer;
private System.Windows.Forms.Label lblPlayerIncline;
private System.Windows.Forms.Label lblPlayerAzimuth;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label lblNumberOfPlayers;
private System.Windows.Forms.PictureBox pbMap;
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
@ -12,25 +13,130 @@ namespace MW2_Ultimate_Hacks
{
public partial class Form1 : Form
{
ProcessManager ProcessManager;
Bitmap Map;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Attempts to hook the game's process.
/// </summary>
/// <returns>True if sucessful, False otherwise.</returns>
public bool ConnectToGame()
{
ProcessManager pm = new ProcessManager("iw4x");
MessageBox.Show(pm.ReadFloat((IntPtr)0x007F4310).ToString());
return false;
}
private void button1_Click(object sender, EventArgs e)
{
ConnectToGame();
Graphics g;
g = Graphics.FromImage(Map);
Pen mypen = new Pen(Color.Black);
g.DrawLine(mypen, 0, 0, 200, 150);
pbMap.Image = Map;
g.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
// Setup the map
Map = new Bitmap(pbMap.Size.Width, pbMap.Size.Height);
pbMap.Image = Map;
// Connect to the game's process
ProcessManager = new ProcessManager("iw4x");
// Start updating the local player's stats
PlayerStatsTimer.Enabled = true;
}
/// <summary>
/// Updates the local player's stats
/// </summary>
private void UpdatePlayerStats()
{
lblPlayerX.Text = ProcessManager.ReadFloatRelative((IntPtr)0x3F418C).ToString();
lblPlayerY.Text = ProcessManager.ReadFloatRelative((IntPtr)0x3F4188).ToString();
lblPlayerZ.Text = ProcessManager.ReadFloatRelative((IntPtr)0x3F4190).ToString();
lblPlayerIncline.Text = ProcessManager.ReadFloatRelative((IntPtr)0x3F41AC).ToString();
lblPlayerAzimuth.Text = ProcessManager.ReadFloatRelative((IntPtr)0x3F41B0).ToString();
// this could be moved else where
lblNumberOfPlayers.Text = ProcessManager.ReadIntRelative((IntPtr)0x3F741C).ToString();
// Draw the map
Graphics g;
Bitmap old = new Bitmap(Map);
g = Graphics.FromImage(Map);
Pen player = new Pen(Color.Black);
int x = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F418C);
x = x / 10;
int y = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F4188);
y += 2000;
y = y / 10;
//g.DrawEllipse(player, new Rectangle(x, y, 5, 5));
//g.FillEllipse(Brushes.Black, new Rectangle(x, y, 5, 5));
// calculate polygone points
int h = 20;
int triangleAngle = 30;
double azimuth = (int)ProcessManager.ReadFloatRelative((IntPtr)0x3F41B0) +180;
double angle = azimuth - (triangleAngle / 2);
angle = (angle / 360) * (2 * Math.PI);
int dx = (int)(Math.Cos(angle) * h);
int dy = (int)(Math.Sin(angle) * h);
int x1, x2, y1, y2;
if(angle < 90)
{
x1 = x + dx;
y1 = y - dy;
x2 = x - dy;
y2 = y - dx;
Debug.WriteLine("Case 1: (" + x + "," + y + ")(" + x1 +"," + y1 + ")(" + x2 + "," + y2 + ")");
}
else if(angle < 180)
{
x1 = x + dx;
y1 = y + dy;
x2 = x + dy;
y2 = y + dx;
Debug.WriteLine("Case 2: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
}
else if(angle < 270)
{
x1 = x - dx;
y1 = y + dy;
x2 = x - dy;
y2 = y + dx;
Debug.WriteLine("Case 3: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
}
else
{
x1 = x - dx;
y1 = y - dy;
x2 = x - dy;
y2 = y - dx;
Debug.WriteLine("Case 4: (" + x + "," + y + ")(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
}
Point[] triangle =
{
new Point(x,y),
new Point(x1, y1),
new Point(x2,y2)
};
g.DrawPolygon(player, triangle);
pbMap.Image = Map;
Map = old;
g.Dispose();
}
private void PlayerStatsTimer_Tick(object sender, EventArgs e)
{
UpdatePlayerStats();
}
}
}

View File

@ -69,6 +69,7 @@ namespace MW2_Ultimate_Hacks
private IntPtr processHandle;
private IntPtr baseAddress;
/// <summary>
///
@ -78,6 +79,7 @@ namespace MW2_Ultimate_Hacks
{
Process process = Process.GetProcessesByName(processName)[0];
processHandle = OpenProcess(ProcessAccessFlags.All, false, process.Id);
baseAddress = process.MainModule.BaseAddress;
}
public float ReadFloat(IntPtr address)
@ -99,5 +101,35 @@ namespace MW2_Ultimate_Hacks
}
}
public float ReadFloatRelative(IntPtr offset)
{
IntPtr address = new IntPtr(offset.ToInt32() + baseAddress.ToInt32());
return ReadFloat(address);
}
public int ReadInt(IntPtr address)
{
// if the process handle is not open it will be null
if (processHandle != null)
{
IntPtr bytesRead = (IntPtr)0;
byte[] buffer = new byte[4];
ReadProcessMemory(processHandle, address, buffer, buffer.Length, out bytesRead);
return System.BitConverter.ToInt32(buffer, 0);
}
else
{
// Probally do some error stuff here
return 0;
}
}
public int ReadIntRelative(IntPtr offset)
{
IntPtr address = new IntPtr(offset.ToInt32() + baseAddress.ToInt32());
return ReadInt(address);
}
}
}