Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CheckpointTeleporter.Properties;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Windows.Forms;
- using System.Globalization;
- namespace CheckpointTeleporter
- {
- public class Main : Form
- {
- public static int NONE = 0,
- MOD_ALT = 1,
- MOD_CONTROL = 2,
- MOD_SHIFT = 4,
- MOD_WIN = 8,
- WM_HOTKEY = 786;
- private List<Main.coords> list = new List<Main.coords>();
- private IContainer components = (IContainer)null;
- private const uint MOUSEEVENTF_LEFTDOWN = 2U;
- private const uint MOUSEEVENTF_LEFTUP = 4U;
- // Tools
- private NumericUpDown vehicleYNumeric;
- private TextBox keyText;
- private StatusStrip bottomBar;
- private ToolStripStatusLabel copyrightLabel;
- private Label vehicleLabel;
- private Label keyText;
- private Label cordsLabel;
- private TextBox customKeyText;
- private TextBox zText;
- private TextBox yText;
- private TextBox zText;
- private Label savedCoordsText;
- private Button addButton;
- private ListView cordsView;
- private ColumnHeader cordsViewKey;
- private ColumnHeader cordsViewName;
- private ColumnHeader cordsViewX;
- private ColumnHeader cordsViewY;
- private ColumnHeader cordsViewZ;
- private TextBox nameText;
- private Label infoLabel;
- private Label vehicleInfoText;
- public Main()
- {
- this.InitializeComponent();
- }
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr GetModuleHandle(string lpModuleName);
- [DllImport("user32.dll")]
- private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
- [DllImport("user32.dll")]
- private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
- [DllImport("user32.dll")]
- private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, IntPtr dwExtraInfo);
- [DllImport("kernel32.dll")]
- private static extern IntPtr OpenProcess(Main.ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
- [DllImport("kernel32.dll")]
- public static extern int CloseHandle(IntPtr hProcess);
- public IntPtr getHandleByName()
- {
- Process[] processesByName = Process.GetProcessesByName("gta_sa");
- if(processesByName.Length == 0) {
- return IntPtr.Zero;
- }
- Process[] processArray = processesByName;
- int index = 0;
- if(index < processArray.Length) {
- return processArray[index].MainWindowHandle;
- }
- return IntPtr.Zero;
- }
- private void WriteInt(int address, int value)
- {
- int bytesWritten;
- Main.WriteMemory(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), address, (long)value, out bytesWritten);
- }
- private void WriteFloat(int address, float value)
- {
- int bytesWritten;
- Main.WriteMemory2(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), address, value, out bytesWritten);
- }
- public static bool WriteMemory(Process process, int address, long value, out int bytesWritten)
- {
- IntPtr hProcess = Main.OpenProcess(Main.ProcessAccessFlags.All, false, process.Id);
- byte[] bytes = BitConverter.GetBytes(value);
- bool flag = Main.WriteProcessMemory(hProcess, new IntPtr(address), bytes, (uint)bytes.LongLength, out bytesWritten);
- Main.CloseHandle(hProcess);
- return flag;
- }
- public static bool WriteMemory2(Process process, int address, float value, out int bytesWritten)
- {
- IntPtr hProcess = Main.OpenProcess(Main.ProcessAccessFlags.All, false, process.Id);
- byte[] bytes = BitConverter.GetBytes(value);
- bool flag = Main.WriteProcessMemory(hProcess, new IntPtr(address), bytes, (uint)bytes.LongLength, out bytesWritten);
- Main.CloseHandle(hProcess);
- return flag;
- }
- public static byte[] ReadMemory(Process process, int address, int numOfBytes)
- {
- IntPtr hProcess = Main.OpenProcess(Main.ProcessAccessFlags.All, false, process.Id);
- byte[] lpBuffer = new byte[numOfBytes];
- int lpNumberOfBytesRead = 0;
- Main.ReadProcessMemory(hProcess, new IntPtr(address), lpBuffer, numOfBytes, out lpNumberOfBytesRead);
- return lpBuffer;
- }
- private int ReadInt(int Adresa)
- {
- return BitConverter.ToInt32(Main.ReadMemory(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), Adresa, 4), 0);
- }
- private float ReadFloat(int Adresa)
- {
- return BitConverter.ToSingle(Main.ReadMemory(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), Adresa, 8), 0);
- }
- private double ReadDouble(int Adresa)
- {
- return (double)BitConverter.ToSingle(Main.ReadMemory(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), Adresa, 8), 0);
- }
- private string ReadText(int Adresa)
- {
- return Encoding.Default.GetString(Main.ReadMemory(Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa")), Adresa, 8));
- }
- private void WUT()
- {
- try
- {
- Process process = Enumerable.FirstOrDefault<Process>((IEnumerable<Process>)Process.GetProcessesByName("gta_sa"));
- float markerX = this.ReadFloat(process.MainModule.BaseAddress.ToInt32() + 8904392);
- float markerY = this.ReadFloat(process.MainModule.BaseAddress.ToInt32() + 8904400);
- float markerZ = this.ReadFloat(process.MainModule.BaseAddress.ToInt32() + 8904396);
- int num1 = this.ReadInt(11990512);
- int num2 = this.ReadInt(num1 + 20);
- int num3 = this.ReadInt(this.ReadInt(num1 + 1420) + 20);
- this.WriteFloat(num3 + 48, markerX);
- this.WriteFloat(num3 + 52, markerZ);
- this.WriteFloat(num3 + 56, markerY + (float)(int)this.vehicleYNumeric.Value);
- this.WriteFloat(num2 + 48, markerX);
- this.WriteFloat(num2 + 52, markerZ);
- this.WriteFloat(num2 + 56, markerY);
- }
- catch (Exception ex)
- {
- }
- }
- private void WUT_XYZ()
- {
- try
- {
- float X = (float)float.Parse(zText.Text, CultureInfo.InvariantCulture.NumberFormat);
- float Y = (float)float.Parse(yText.Text, CultureInfo.InvariantCulture.NumberFormat) - 190;
- float Z = (float)float.Parse(zText.Text, CultureInfo.InvariantCulture.NumberFormat);
- int num1 = this.ReadInt(11990512);
- int num2 = this.ReadInt(num1 + 20);
- int num3 = this.ReadInt(this.ReadInt(num1 + 1420) + 20);
- this.WriteFloat(num3 + 48, X);
- this.WriteFloat(num3 + 52, Z);
- this.WriteFloat(num3 + 56, Y + (float)(int)this.vehicleYNumeric.Value);
- this.WriteFloat(num2 + 48, X);
- this.WriteFloat(num2 + 52, Z);
- this.WriteFloat(num2 + 56, Y);
- }
- catch (Exception ex)
- {
- }
- }
- protected override void WndProc(ref Message m)
- {
- if(m.Msg == Main.WM_HOTKEY && m.WParam.ToInt32() == 3) {
- this.WUT();
- }
- if(m.Msg == Main.WM_HOTKEY && m.WParam.ToInt32() == 5) {
- this.WUT_XYZ();
- }
- base.WndProc(ref m);
- }
- protected override void Dispose(bool disposing)
- {
- if(disposing && this.components != null) {
- this.components.Dispose();
- }
- base.Dispose(disposing);
- }
- private void InitializeComponent()
- {
- this.vehicleYNumeric = new System.Windows.Forms.NumericUpDown();
- this.keyText = new System.Windows.Forms.TextBox();
- this.bottomBar = new System.Windows.Forms.StatusStrip();
- this.copyrightLabel = new System.Windows.Forms.ToolStripStatusLabel();
- this.vehicleLabel = new System.Windows.Forms.Label();
- this.keyText = new System.Windows.Forms.Label();
- this.cordsLabel = new System.Windows.Forms.Label();
- this.customKeyText = new System.Windows.Forms.TextBox();
- this.zText = new System.Windows.Forms.TextBox();
- this.yText = new System.Windows.Forms.TextBox();
- this.zText = new System.Windows.Forms.TextBox();
- this.savedCoordsText = new System.Windows.Forms.Label();
- this.addButton = new System.Windows.Forms.Button();
- this.cordsView = new System.Windows.Forms.ListView();
- this.cordsViewKey = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.cordsViewName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.cordsViewX = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.cordsViewY = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.cordsViewZ = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.nameText = new System.Windows.Forms.TextBox();
- this.infoLabel = new System.Windows.Forms.Label();
- this.vehicleInfoText = new System.Windows.Forms.Label();
- ((System.ComponentModel.ISupportInitialize)(this.vehicleYNumeric)).BeginInit();
- this.bottomBar.SuspendLayout();
- this.SuspendLayout();
- //
- // vehicleYNumeric
- //
- this.vehicleYNumeric.Location = new System.Drawing.Point(19, 80);
- this.vehicleYNumeric.Name = "vehicleYNumeric";
- this.vehicleYNumeric.Size = new System.Drawing.Size(120, 20);
- this.vehicleYNumeric.TabIndex = 0;
- //
- // keyText
- //
- this.keyText.Location = new System.Drawing.Point(19, 41);
- this.keyText.Name = "keyText";
- this.keyText.ReadOnly = true;
- this.keyText.Size = new System.Drawing.Size(100, 20);
- this.keyText.TabIndex = 1;
- this.keyText.Text = "F11";
- this.keyText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.keyText_KeyDown);
- //
- // bottomBar
- //
- this.bottomBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.copyrightLabel});
- this.bottomBar.Location = new System.Drawing.Point(0, 228);
- this.bottomBar.Name = "bottomBar";
- this.bottomBar.Size = new System.Drawing.Size(511, 22);
- this.bottomBar.SizingGrip = false;
- this.bottomBar.TabIndex = 2;
- this.bottomBar.Text = "bottomBar";
- //
- // copyrightLabel
- //
- this.copyrightLabel.Name = "copyrightLabel";
- this.copyrightLabel.Size = new System.Drawing.Size(124, 17);
- this.copyrightLabel.Text = "Entwickelt von Caglar.";
- //
- // vehicleLabel
- //
- this.vehicleLabel.AutoSize = true;
- this.vehicleLabel.Location = new System.Drawing.Point(16, 64);
- this.vehicleLabel.Name = "vehicleLabel";
- this.vehicleLabel.Size = new System.Drawing.Size(115, 13);
- this.vehicleLabel.TabIndex = 4;
- this.vehicleLabel.Text = "Fahrzeug Y Koordinate";
- //
- // keyText
- //
- this.keyText.AutoSize = true;
- this.keyText.Location = new System.Drawing.Point(16, 25);
- this.keyText.Name = "keyText";
- this.keyText.Size = new System.Drawing.Size(97, 13);
- this.keyText.TabIndex = 5;
- this.keyText.Text = "Teleportationstaste";
- //
- // cordsLabel
- //
- this.cordsLabel.AutoSize = true;
- this.cordsLabel.Location = new System.Drawing.Point(225, 25);
- this.cordsLabel.Name = "cordsLabel";
- this.cordsLabel.Size = new System.Drawing.Size(115, 13);
- this.cordsLabel.TabIndex = 6;
- this.cordsLabel.Text = "Benutzerdefinierte Orte";
- //
- // customKeyText
- //
- this.customKeyText.Location = new System.Drawing.Point(228, 41);
- this.customKeyText.Name = "customKeyText";
- this.customKeyText.ReadOnly = true;
- this.customKeyText.Size = new System.Drawing.Size(100, 20);
- this.customKeyText.TabIndex = 7;
- this.customKeyText.Text = "F10";
- this.customKeyText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.customKeyText_KeyDown);
- //
- // zText
- //
- this.zText.Location = new System.Drawing.Point(228, 67);
- this.zText.Name = "zText";
- this.zText.Size = new System.Drawing.Size(77, 20);
- this.zText.TabIndex = 8;
- this.zText.Text = "-2704.1953";
- //
- // yText
- //
- this.yText.Location = new System.Drawing.Point(311, 67);
- this.yText.Name = "yText";
- this.yText.Size = new System.Drawing.Size(77, 20);
- this.yText.TabIndex = 9;
- this.yText.Text = "195.3329";
- //
- // zText
- //
- this.zText.Location = new System.Drawing.Point(394, 67);
- this.zText.Name = "zText";
- this.zText.Size = new System.Drawing.Size(77, 20);
- this.zText.TabIndex = 10;
- this.zText.Text = "3.8849";
- //
- // savedCoordsText
- //
- this.savedCoordsText.AutoSize = true;
- this.savedCoordsText.Location = new System.Drawing.Point(225, 106);
- this.savedCoordsText.Name = "savedCoordsText";
- this.savedCoordsText.Size = new System.Drawing.Size(130, 13);
- this.savedCoordsText.TabIndex = 15;
- this.savedCoordsText.Text = "Gespeicherte Koordinaten";
- //
- // addButton
- //
- this.addButton.Enabled = false;
- this.addButton.Location = new System.Drawing.Point(477, 67);
- this.addButton.Name = "addButton";
- this.addButton.Size = new System.Drawing.Size(19, 20);
- this.addButton.TabIndex = 16;
- this.addButton.Text = "+";
- this.addButton.UseVisualStyleBackColor = true;
- this.addButton.Click += new System.EventHandler(this.addButton_Click);
- //
- // cordsView
- //
- this.cordsView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.cordsViewKey,
- this.cordsViewName,
- this.cordsViewX,
- this.cordsViewY,
- this.cordsViewZ});
- this.cordsView.Location = new System.Drawing.Point(228, 122);
- this.cordsView.Name = "cordsView";
- this.cordsView.Size = new System.Drawing.Size(268, 92);
- this.cordsView.TabIndex = 17;
- this.cordsView.UseCompatibleStateImageBehavior = false;
- this.cordsView.View = System.Windows.Forms.View.Details;
- //
- // cordsViewKey
- //
- this.cordsViewKey.Text = "#";
- this.cordsViewKey.Width = 33;
- //
- // cordsViewName
- //
- this.cordsViewName.Text = "Name";
- this.cordsViewName.Width = 80;
- //
- // cordsViewX
- //
- this.cordsViewX.Text = "X";
- this.cordsViewX.Width = 52;
- //
- // cordsViewY
- //
- this.cordsViewY.Text = "Y";
- this.cordsViewY.Width = 48;
- //
- // cordsViewZ
- //
- this.cordsViewZ.Text = "Z";
- this.cordsViewZ.Width = 51;
- //
- // nameText
- //
- this.nameText.Location = new System.Drawing.Point(334, 41);
- this.nameText.Name = "nameText";
- this.nameText.Size = new System.Drawing.Size(137, 20);
- this.nameText.TabIndex = 18;
- this.nameText.Text = "Name";
- this.nameText.Click += new System.EventHandler(this.nameText_Click);
- //
- // infoLabel
- //
- this.infoLabel.AutoSize = true;
- this.infoLabel.Location = new System.Drawing.Point(16, 149);
- this.infoLabel.Name = "infoLabel";
- this.infoLabel.Size = new System.Drawing.Size(199, 65);
- this.infoLabel.TabIndex = 19;
- this.infoLabel.Text = "Moment an kann man keine Koordinaten\r\nspeichern. Es ist nur möglich die\r\nX, Y, Z " +
- "Koordinaten anzugeben und die\r\nTaste für das selbst definierte Ort eine\r\nTaste a" +
- "uszusuchen.";
- //
- // vehicleInfoText
- //
- this.vehicleInfoText.AutoSize = true;
- this.vehicleInfoText.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
- this.vehicleInfoText.Location = new System.Drawing.Point(16, 103);
- this.vehicleInfoText.Name = "vehicleInfoText";
- this.vehicleInfoText.Size = new System.Drawing.Size(158, 39);
- this.vehicleInfoText.TabIndex = 20;
- this.vehicleInfoText.Text = "Damit das Fahrzeug nicht zu tief\r\nteleportiert wird, kann man\r\ndie Y Koordinate e" +
- "rhöhen.";
- //
- // Main
- //
- this.ClientSize = new System.Drawing.Size(511, 250);
- this.Controls.Add(this.vehicleInfoText);
- this.Controls.Add(this.infoLabel);
- this.Controls.Add(this.nameText);
- this.Controls.Add(this.cordsView);
- this.Controls.Add(this.addButton);
- this.Controls.Add(this.savedCoordsText);
- this.Controls.Add(this.zText);
- this.Controls.Add(this.yText);
- this.Controls.Add(this.zText);
- this.Controls.Add(this.customKeyText);
- this.Controls.Add(this.cordsLabel);
- this.Controls.Add(this.keyText);
- this.Controls.Add(this.vehicleLabel);
- this.Controls.Add(this.bottomBar);
- this.Controls.Add(this.keyText);
- this.Controls.Add(this.vehicleYNumeric);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
- this.MaximizeBox = false;
- this.Name = "Main";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "SA:MP Checkpoint-Teleporter";
- this.Load += new System.EventHandler(this.Main_Load);
- ((System.ComponentModel.ISupportInitialize)(this.vehicleYNumeric)).EndInit();
- this.bottomBar.ResumeLayout(false);
- this.bottomBar.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- [Flags]
- public enum ProcessAccessFlags : uint
- {
- All = 2035711U,
- Terminate = 1U,
- CreateThread = 2U,
- VMOperation = 8U,
- VMRead = 16U,
- VMWrite = 32U,
- DupHandle = 64U,
- SetInformation = 512U,
- QueryInformation = 1024U,
- Synchronize = 1048576U,
- }
- private class coords
- {
- public float x;
- public float y;
- public float z;
- public coords(double xx, double yy, double zz)
- {
- this.x = (float)xx;
- this.y = (float)yy;
- this.z = (float)zz;
- }
- }
- private void keyText_KeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- Main.UnregisterHotKey(this.Handle, 3);
- this.keyText.Text = e.KeyCode.ToString();
- Main.RegisterHotKey(this.Handle, 3, Main.NONE, (int)e.KeyCode);
- }
- catch (Exception ex)
- {
- }
- }
- private void Main_Load(object sender, EventArgs e)
- {
- try
- {
- int currentPos = this.ReadInt(this.ReadInt(11990512) + 20);
- double currentX = (double)this.ReadFloat(currentPos + 48);
- double currentY = (double)this.ReadFloat(currentPos + 52);
- double currentZ = (double)this.ReadFloat(currentPos + 56);
- Main.RegisterHotKey(this.Handle, 3, Main.NONE, 122);
- Main.RegisterHotKey(this.Handle, 5, Main.NONE, (int) Keys.F10);
- if(Settings.Default.loaded) {
- return;
- }
- Settings.Default.loaded = true;
- Settings.Default.Save();
- }
- catch (Exception ex)
- {
- }
- }
- private void customKeyText_KeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- Main.UnregisterHotKey(this.Handle, 5);
- this.customKeyText.Text = e.KeyCode.ToString();
- Main.RegisterHotKey(this.Handle, 5, Main.NONE, (int)e.KeyCode);
- }
- catch (Exception ex)
- {
- }
- }
- private void addButton_Click(object sender, EventArgs e)
- {
- string[] item = { nameText.Text, zText.Text, yText.Text, zText.Text };
- cordsView.Items.Add(customKeyText.Text).SubItems.AddRange(item);
- }
- private void nameText_Click(object sender, EventArgs e)
- {
- if(nameText.Text == "Name")
- {
- nameText.Text = "";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement