Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace URWSSSelector
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- ReadWriteMem RWMain;
- Rectangle Map = new Rectangle();
- Process URW;
- public bool Active = false;
- public bool MoveLocation = false;
- public RECT WindowRect;
- Rectangle GameRect = new Rectangle();
- private bool BoxCanDraw;
- private int BoxStartX, BoxStartY;
- private Rectangle BoxRect;
- private Rectangle BoxRectFill;
- const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
- [DllImport("dwmapi.dll")]
- static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT pvAttribute, int cbAttribute);
- [DllImport("user32.dll", SetLastError = true)]
- static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll", SetLastError = true)]
- static extern int GetWindowLong(IntPtr hWnd, int nIndex);
- [DllImport("user32.dll")]
- static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
- static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, int wParam, IntPtr lParam);
- [DllImport("user32.dll")]
- static extern bool SetForegroundWindow(IntPtr hWnd);
- [StructLayout(LayoutKind.Sequential)]
- public struct RECT
- {
- public int Left; // x position of upper-left corner
- public int Top; // y position of upper-left corner
- public int Right; // x position of lower-right corner
- public int Bottom; // y position of lower-right corner
- }
- Point StartLocation
- {
- get
- {
- return new Point(RWMain.Read<int>((int)Address.XStart), RWMain.Read<int>((int)Address.YStart));
- }
- set
- {
- RWMain.Write((int)Address.XStart, value.X);
- RWMain.Write((int)Address.YStart, value.Y);
- }
- }
- byte[] MapIDArray
- {
- get
- {
- return RWMain.Read<byte[]>((int)Address.MapTileIDArray, 6293502);
- }
- set
- {
- RWMain.Write((int)Address.MapTileIDArray, value);
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- URW = Process.GetProcessesByName("urw")[0];
- RWMain = new ReadWriteMem(URW);
- new Thread(WindowThread) { IsBackground = true }.Start();
- if (MapIDArray[0] == 0)
- {
- MessageBox.Show("Map has not been generated. Exiting.");
- Environment.Exit(0);
- }
- SetForegroundWindow(URW.MainWindowHandle);
- }
- catch
- {
- MessageBox.Show("Unreal world not found running. Closing URWSSSelector.");
- Environment.Exit(0);
- }
- }
- private Point GetMouseXYMap(MouseEventArgs e)
- {
- int X = 0, Y = 0;
- if (BoxRectFill.Width > 0 && BoxRectFill.Contains(e.X, e.Y))
- {
- X = (int)((e.X - BoxRectFill.X) * (3072m / BoxRectFill.Width));
- Y = (int)((e.Y - BoxRectFill.Y) * (2048m / BoxRectFill.Height));
- if (MoveLocation)
- {
- StartLocation = new Point(X, Y);
- SendMessage(URW.MainWindowHandle, 0x0102, '-', IntPtr.Zero);
- }
- }
- return new Point(X, Y);
- }
- private void WindowThread()
- {
- IntPtr ThisHandle = IntPtr.Zero;
- this.Invoke(new Action(() => ThisHandle = this.Handle));
- while (Thread.CurrentThread.IsAlive)
- {
- if (DwmGetWindowAttribute(RWMain.TargetProcess.MainWindowHandle, DWMWA_EXTENDED_FRAME_BOUNDS, out WindowRect, Marshal.SizeOf(typeof(RECT))) != 0)
- {
- GetWindowRect(RWMain.TargetProcess.MainWindowHandle, out WindowRect);
- }
- GameRect = new Rectangle(new Point(WindowRect.Left, WindowRect.Top), new Size(WindowRect.Right - WindowRect.Left, WindowRect.Bottom - WindowRect.Top));
- this.Invoke(new Action(() => this.Location = GameRect.Location));
- this.Invoke(new Action(() => this.Size = GameRect.Size));
- if (GetForegroundWindow() != RWMain.TargetProcess.MainWindowHandle && GetForegroundWindow() != ThisHandle)
- {
- this.Invoke(new Action(() => this.Visible = false));
- }
- else if (GetForegroundWindow() == RWMain.TargetProcess.MainWindowHandle)
- {
- this.Invoke(new Action(() => this.Visible = true));
- }
- Thread.Sleep(10);
- }
- }
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- Point MouseLocation = GetMouseXYMap(e);
- lblMapMouse.Text = string.Format("X: {0}, Y: {1}", MouseLocation.X, MouseLocation.Y);
- lblMapMouse.Location = new Point (this.Width / 2 - 50, lblMapMouse.Location.Y);
- if (BoxCanDraw)
- {
- int Box_X = Math.Min(BoxStartX, e.X);
- int Box_Y = Math.Min(BoxStartY, e.Y);
- int Box_Width = Math.Max(BoxStartX, e.X) - Math.Min(BoxStartX, e.X);
- int Box_Height = Math.Max(BoxStartY, e.Y) - Math.Min(BoxStartY, e.Y);
- BoxRect = new Rectangle(Box_X, Box_Y, Box_Width, Box_Height);
- BoxRectFill = new Rectangle(Box_X - 1, Box_Y - 1, Box_Width + 2, Box_Height + 2);
- Refresh();
- }
- }
- private void Form1_MouseDown(object sender, MouseEventArgs e)
- {
- MoveLocation = false;
- if (e.Button == MouseButtons.Left)
- {
- BoxCanDraw = true;
- BoxStartX = e.X;
- BoxStartY = e.Y;
- }
- else if (e.Button == MouseButtons.Right)
- {
- Environment.Exit(0);
- }
- }
- private void Form1_MouseUp(object sender, MouseEventArgs e)
- {
- MoveLocation = true;
- if (e.Button == MouseButtons.Left)
- {
- BoxCanDraw = false;
- BoxRect = new Rectangle(0, 0, 0, 0);
- Refresh();
- }
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- //Create a new 'pen' to draw our rectangle with, give it the color red and a width of 2
- using (Pen BoxPen = new Pen(Color.Red, 2))
- {
- using (SolidBrush BoxFill = new SolidBrush(Color.FromArgb((int)(255 * .45m), Color.Red)))
- {
- e.Graphics.FillRectangle(BoxFill, BoxRectFill);
- }
- e.Graphics.DrawRectangle(BoxPen, BoxRect);
- }
- }
- }
- public static class Extensions
- {
- public static string ReplaceModifiedString(this string s)
- {
- return s.Replace('Σ', 'ä').Replace('Ø', '¥').Replace('─', 'Ä').Replace('÷', 'ö');
- }
- }
- public class ReadWriteMem
- {
- [DllImport("Kernel32.dll")]
- private static extern bool ReadProcessMemory(IntPtr hProcess, int BaseAddress, byte[] Buffer, int Size, ref int NumberOfBytesRead);
- [DllImport("Kernel32.dll")]
- private static extern bool WriteProcessMemory(IntPtr hProcess, int BaseAddress, byte[] Buffer, int Size, ref int NumberOfBytesWritten);
- private Process Proc;
- public Process TargetProcess
- {
- get { return Proc; }
- set { Proc = value; }
- }
- public IntPtr WindowHandle = IntPtr.Zero;
- public int ProcBaseAddress = 0;
- public const int VersionOffset = 0x0000;
- public ReadWriteMem(Process T)
- {
- TargetProcess = T;
- ProcBaseAddress = T.MainModule.BaseAddress.ToInt32();
- WindowHandle = T.Handle;
- }
- public bool Write(int BaseAddress, dynamic obj, byte pb = 1)
- {
- byte[] Buffer = BitConverter.GetBytes(obj);
- int BytesWritten = 0;
- if (Buffer.Length == 2 && Buffer[1] == 0) { WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, new byte[] { (byte)obj }, 1, ref BytesWritten); }
- else { WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten); }
- switch (BytesWritten)
- {
- case 0: return false;
- default: return true;
- }
- }
- public bool Write(int BaseAddress, byte[] Buffer, byte pb = 1)
- {
- int BytesWritten = 0;
- WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten);
- switch (BytesWritten)
- {
- case 0: return false;
- default: return true;
- }
- }
- public bool Write(int BaseAddress, string Text, byte pb = 1)
- {
- byte[] Buffer = Encoding.GetEncoding("IBM865").GetBytes(Text.ReplaceModifiedString());
- int BytesWritten = 0;
- WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten);
- switch (BytesWritten)
- {
- case 0: return false;
- default: return true;
- }
- }
- public T Read<T>(int BaseAddress, byte pb = 1)
- {
- byte[] Buffer;
- int BytesRead = 0;
- switch (Type.GetTypeCode(typeof(T)))
- {
- case TypeCode.Byte:
- Buffer = new byte[1];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 1, ref BytesRead);
- return (T)Convert.ChangeType(Buffer[0], typeof(T));
- case TypeCode.Int16:
- Buffer = new byte[2];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 2, ref BytesRead);
- return (T)Convert.ChangeType(BitConverter.ToUInt16(Buffer, 0), typeof(T));
- case TypeCode.Int32:
- Buffer = new byte[4];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
- return (T)Convert.ChangeType(BitConverter.ToUInt32(Buffer, 0), typeof(T));
- case TypeCode.UInt32:
- Buffer = new byte[4];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
- return (T)Convert.ChangeType(BitConverter.ToUInt32(Buffer, 0), typeof(T));
- case TypeCode.Single:
- Buffer = new byte[4];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
- return (T)Convert.ChangeType(BitConverter.ToSingle(Buffer, 0), typeof(T));
- default:
- return (T)Convert.ChangeType(false, typeof(T));
- }
- }
- public T Read<T>(int BaseAddress, int Length, byte pb = 1)
- {
- byte[] Buffer;
- int BytesRead = 0;
- switch (Type.GetTypeCode(typeof(T)))
- {
- case TypeCode.Object:
- Buffer = new byte[Length];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Length, ref BytesRead);
- return (T)Convert.ChangeType(Buffer, typeof(T));
- case TypeCode.String:
- Buffer = new byte[Length];
- ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Length, ref BytesRead);
- return (T)Convert.ChangeType(Encoding.GetEncoding("IBM865").GetString(Buffer, 0, Buffer.Length).Split(new char[] { '\0' })[0].ReplaceModifiedString(), typeof(T));
- default:
- return (T)Convert.ChangeType(false, typeof(T));
- }
- }
- }
- public enum Address
- {
- MapTileIDArray = 0x8C6928,
- MouseXCoord = 0x5D1C4E4,
- MouseYCoord = 0x5F20434,
- TimeDay = 0xA2F1534,
- TimeHour = 0xA2F150C,
- TimeMinute = 0xA2F150D,
- TimeMonth = 0xA2F1540,
- TimeYear = 0xA2F1541,
- XLocation = 0xA297824,
- XStart = 0x1B4BA0,
- YLocation = 0xA2F20C8,
- YStart = 0x1B4BA4
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement