Advertisement
Nighticus

URW_SSSelector1.0.2Source

Dec 14th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14.  
  15. namespace URWSSSelector
  16. {
  17.     public partial class Form1 : Form
  18.     {
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         ReadWriteMem RWMain;
  25.         Process URW;
  26.         public bool Active = false;
  27.         public bool MoveLocation = false;
  28.         public RECT WindowRect;
  29.         Rectangle GameRect = new Rectangle();
  30.         byte[] LoadedMap;
  31.         private Rectangle GameMap;
  32.         Point ClosestLand = new Point(0, 0);
  33.         private int[] TileIDFilter = new[] { 180, 181, 182, 183, 177, 244, 247, 178 };
  34.         public TileSearchSettings TSS = new TileSearchSettings();
  35.         private Dictionary<int, string> TileNames = new Dictionary<int, string>();
  36.         private Dictionary<int, List<Point>> TileLocations = new Dictionary<int, List<Point>>();
  37.         string GameTitle = "";
  38.         Point MouseLocation;
  39.  
  40.         int[] HighCountTiles = new int[] { 3, 15, 180, 181, 233, 235, 236, 238, 247 };
  41.         int[] LowCountTiles = new int[] { 16, 20, 30, 31, 46, 47, 60, 86, 91, 93, 94, 176, 210, 211, 228, 237, 239, 250, 251 };
  42.  
  43.         const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
  44.  
  45.         [DllImport("dwmapi.dll")]
  46.         static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT pvAttribute, int cbAttribute);
  47.  
  48.         [DllImport("user32.dll", SetLastError = true)]
  49.         static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
  50.  
  51.         [DllImport("user32.dll")]
  52.         public static extern IntPtr GetForegroundWindow();
  53.  
  54.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  55.         static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, int wParam, IntPtr lParam);
  56.  
  57.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  58.         static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, int wParam, string lParam);
  59.  
  60.         [DllImport("user32.dll")]
  61.         static extern bool SetForegroundWindow(IntPtr hWnd);
  62.  
  63.         [StructLayout(LayoutKind.Sequential)]
  64.         public struct RECT
  65.         {
  66.             public int Left;        // x position of upper-left corner
  67.             public int Top;         // y position of upper-left corner
  68.             public int Right;       // x position of lower-right corner
  69.             public int Bottom;      // y position of lower-right corner
  70.         }
  71.  
  72.         Point StartLocation
  73.         {
  74.             get
  75.             {
  76.                 return new Point(RWMain.Read<int>((int)Address.XStart), RWMain.Read<int>((int)Address.YStart));
  77.             }
  78.             set
  79.             {
  80.                 RWMain.Write((int)Address.XStart, value.X);
  81.                 RWMain.Write((int)Address.YStart, value.Y);
  82.             }
  83.         }
  84.  
  85.         byte[] MapIDArray
  86.         {
  87.             get
  88.             {
  89.                 return RWMain.Read<byte[]>((int)Address.MapTileIDArray, 6293502);
  90.             }
  91.             set
  92.             {
  93.                 RWMain.Write((int)Address.MapTileIDArray, value);
  94.             }
  95.         }
  96.  
  97.         private void LoadTileNames()
  98.         {
  99.             TileNames.Add(3, "Lichenous pine forest");
  100.             TileNames.Add(15, "Coniferous forest");
  101.             TileNames.Add(16, "Grove");
  102.             TileNames.Add(20, "High cliff");
  103.             TileNames.Add(30, "Camp");
  104.             TileNames.Add(31, "Shelter");
  105.             TileNames.Add(46, "Road");
  106.             TileNames.Add(47, "Pasture");
  107.             TileNames.Add(60, "Cave");
  108.             TileNames.Add(86, "Settlement");
  109.             TileNames.Add(91, "Hill");
  110.             TileNames.Add(93, "Cliff");
  111.             TileNames.Add(94, "Mountain");
  112.             TileNames.Add(176, "Ford");
  113.             TileNames.Add(177, "Rapids");
  114.             TileNames.Add(178, "River");
  115.             TileNames.Add(180, "Sea");
  116.             TileNames.Add(181, "Shallow Sea");
  117.             TileNames.Add(182, "Deep Water");
  118.             TileNames.Add(183, "Shallow Water");
  119.             TileNames.Add(210, "Fortified village");
  120.             TileNames.Add(211, "Settlement");
  121.             TileNames.Add(228, "Thicket");
  122.             TileNames.Add(233, "Open mire");
  123.             TileNames.Add(235, "Spruce mire");
  124.             TileNames.Add(236, "Pine mire");
  125.             TileNames.Add(237, "Bushes");
  126.             TileNames.Add(238, "Heathland");
  127.             TileNames.Add(239, "Village");
  128.             TileNames.Add(244, "Water");
  129.             TileNames.Add(247, "Water");
  130.             TileNames.Add(250, "Ground");
  131.             TileNames.Add(251, "Field");
  132.         }
  133.  
  134.         private void Form1_Load(object sender, EventArgs e)
  135.         {
  136.             try
  137.             {
  138.                 URW = Process.GetProcessesByName("urw")[0];
  139.                 RWMain = new ReadWriteMem(URW);
  140.                 TSS.URW = URW;
  141.  
  142.                 string VersionInfo = VersionCheck();
  143.                 if (VersionInfo.Length > 0) { MessageBox.Show(VersionInfo); Environment.Exit(0); }
  144.  
  145.                 new Thread(WindowThread) { IsBackground = true }.Start();
  146.  
  147.                 LoadedMap = MapIDArray;
  148.  
  149.                 LoadTileNames();
  150.                 if (LoadedMap[0] == 0)
  151.                 {
  152.                     MessageBox.Show("Map has not been generated. Exiting.");
  153.                     Environment.Exit(0);
  154.                 }
  155.  
  156.                 SetForegroundWindow(URW.MainWindowHandle);
  157.                 this.MouseWheel += Form1_MouseWheel;
  158.             }
  159.             catch
  160.             {
  161.                 MessageBox.Show("Unreal world not found running. Closing URWSSSelector.");
  162.                 Environment.Exit(0);
  163.             }
  164.  
  165.             foreach (int i in LowCountTiles)
  166.             {
  167.                 TileLocations.Add(i, new List<Point>());
  168.             }
  169.  
  170.             for (int i = 0; i < LoadedMap.Length; i++)
  171.             {
  172.                 if (LowCountTiles.Contains(LoadedMap[i]))
  173.                 {
  174.                     TileLocations[LoadedMap[i]].Add(new Point((i % 3073), (i / 3073)));
  175.                 }
  176.             }
  177.             //MessageBox.Show(TileLocations.Keys.Count().ToString());
  178.  
  179.             TSS.CalculateMode();
  180.         }
  181.  
  182.         private string VersionCheck()
  183.         {
  184.             FileVersionInfo Info = URW.MainModule.FileVersionInfo;
  185.             string Folder = Info.FileName.Substring(0, Info.FileName.Length - 8);
  186.             List<string> Lines = new List<string>();
  187.             Lines.AddRange(File.ReadAllLines(Folder + "\\news.txt"));
  188.             for (int i = 0; i < Lines.Count; i++)
  189.             {
  190.                 if (Lines[i].ToLower().Contains("3.63") && i < 10)
  191.                 {
  192.                     return "";
  193.                 }
  194.             }
  195.             return "Game version mismatch, please check thread on official forum for updates.";
  196.         }
  197.  
  198.         private Rectangle GetMap()
  199.         {
  200.             Bitmap bmpScreen = new Bitmap(GameRect.Width, GameRect.Height);
  201.             Point TopLeft = new Point(0, 0);
  202.             Point BottomRight = new Point(0, 0);
  203.             using (Graphics g = Graphics.FromImage(bmpScreen))
  204.             {
  205.                 g.CopyFromScreen(GameRect.Location, new Point(0,0), GameRect.Size, CopyPixelOperation.SourceCopy);
  206.             }
  207.             for (int x = 0; x < bmpScreen.Width; x++)
  208.             {
  209.                 for (int y = 0; y < bmpScreen.Height; y++)
  210.                 {
  211.                     Color Pixel = bmpScreen.GetPixel(x, y);
  212.                     if (Pixel.B > 190 && Pixel.R < 20 && Pixel.G < 30)
  213.                     {
  214.                         if (TopLeft.X == 0) { TopLeft = new Point(x, y); }
  215.                         else { BottomRight = new Point(x, y); }
  216.                     }
  217.                 }
  218.             }
  219.             MoveLocation = true;
  220.             return new Rectangle(TopLeft, new Size(BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y));
  221.         }
  222.  
  223.         private Point GetMouseXYMap(MouseEventArgs e)
  224.         {
  225.             int X = 0, Y = 0;
  226.             if (GameMap.Width > 0)
  227.             {
  228.                 X = (int)((e.X - GameMap.X) * (3073m / GameMap.Width));
  229.                 Y = (int)((e.Y - GameMap.Y) * (2049m / GameMap.Height));
  230.                 if (MoveLocation)
  231.                 {
  232.                     if (X < 48) { X = 48; }
  233.                     if (X > 3024) { X = 3024; }
  234.                     if (Y < 48) { Y = 48; }
  235.                     if (Y > 2000) { Y = 2000; }
  236.                     int LocationIndex = (Y * 3073) + X;
  237.                     if (!TileIDFilter.Contains((int)LoadedMap[LocationIndex]) && TSS.Mode == 0)
  238.                     {
  239.                         StartLocation = new Point(X, Y);
  240.                         GameTitle = string.Format("UnReal World - Closest Land, X: {0} - Y: {1}, {2}", X, Y, TileNames[(int)LoadedMap[LocationIndex]]);
  241.                     }
  242.                     else // find nearest landmass
  243.                     {
  244.                         //ClosestLand = StartLocation;
  245.                         Point OldCursorDistance = new Point(9999,9999);
  246.                         Point NewCursorDistance = new Point(9999,9999);
  247.  
  248.                         int SearchCount = 0;
  249.                         if (TSS.TileIDs.Count > 0)
  250.                         {
  251.                             foreach (int i in TSS.TileIDs)
  252.                             {
  253.                                 if (TileLocations.ContainsKey(i))
  254.                                 {
  255.                                     if (SearchCount < 100000)
  256.                                     {
  257.                                         SearchCount += TileLocations[i].Count();
  258.                                     }
  259.                                     else break;
  260.                                 }
  261.                             }
  262.                         }
  263.  
  264.                         if (SearchCount > 0 && SearchCount < 100000 && TSS.TileIDs.Count > 0) // Search sorted tiles
  265.                         {
  266.                             foreach (int ID in TSS.TileIDs) // Search each tile ID
  267.                             {
  268.                                 if (!TileIDFilter.Contains(ID)) // Filter unwanted tile arrays
  269.                                 {
  270.                                     foreach (Point P in TileLocations[ID]) // Compare each tiles X/Y
  271.                                     {
  272.                                         if (P.X > 48 && P.X < 3024 && P.Y > 48 && P.Y < 2000) // Tile within map bounds
  273.                                         {
  274.                                             NewCursorDistance.X = Math.Abs(P.X - X); NewCursorDistance.Y = Math.Abs(P.Y - Y);
  275.                                             //OldCursorDistance.X = Math.Abs(ClosestLand.X - X); OldCursorDistance.Y = Math.Abs(ClosestLand.Y - Y);
  276.  
  277.                                             if (OldCursorDistance.X + OldCursorDistance.Y > NewCursorDistance.X + NewCursorDistance.Y)
  278.                                             {
  279.                                                 OldCursorDistance = NewCursorDistance;
  280.                                                 ClosestLand.X = P.X; ClosestLand.Y = P.Y;//new Point(XSearch, YSearch);
  281.                                                 StartLocation = ClosestLand;
  282.                                                 GameTitle = string.Format("UnReal World - {3}, X: {0} - Y: {1}, {2}", ClosestLand.X, ClosestLand.Y, TileNames[ID], TSS.ModeText);
  283.                                             }
  284.                                         }
  285.                                     }
  286.                                 }
  287.                             }
  288.                         }
  289.  
  290.                         else // Search by radius
  291.                         {
  292.                             for (int XSearch = X - TSS.SearchRadius; XSearch < X + TSS.SearchRadius; XSearch++)
  293.                             {
  294.                                 for (int YSearch = Y - TSS.SearchRadius; YSearch < Y + TSS.SearchRadius; YSearch++)
  295.                                 {
  296.                                     int SearchIndex = (YSearch * 3073) + XSearch;
  297.                                     if (SearchIndex > 0 && SearchIndex < LoadedMap.Length)
  298.                                     {
  299.                                         if (!TileIDFilter.Contains((int)LoadedMap[SearchIndex]))
  300.                                         {
  301.                                             if (XSearch > 48 && XSearch < 3024 && YSearch > 48 && YSearch < 2000)
  302.                                             {
  303.                                                 if (TSS.Mode == 0)// Default mode
  304.                                                 {
  305.                                                     //OldCursorDistance.X = Math.Abs(ClosestLand.X - X); OldCursorDistance.Y = Math.Abs(ClosestLand.Y - Y);
  306.                                                     NewCursorDistance.X = Math.Abs(XSearch - X); NewCursorDistance.Y = Math.Abs(YSearch - Y);
  307.  
  308.                                                     if (OldCursorDistance.X + OldCursorDistance.Y > NewCursorDistance.X + NewCursorDistance.Y)
  309.                                                     {
  310.                                                         OldCursorDistance = NewCursorDistance;
  311.                                                         ClosestLand.X = XSearch; ClosestLand.Y = YSearch;// = new Point(XSearch, YSearch);
  312.                                                         StartLocation = ClosestLand;
  313.                                                         GameTitle = string.Format("UnReal World - Closest Land, X: {0} - Y: {1}, {2}", ClosestLand.X, ClosestLand.Y, TileNames[(int)LoadedMap[SearchIndex]]);
  314.                                                     }
  315.                                                 }
  316.  
  317.                                                 else if (TSS.Mode != 0 && TSS.TileIDs.Count > 0) // Additional modes
  318.                                                 {
  319.                                                     if (TSS.TileIDs.Contains((int)LoadedMap[SearchIndex]))
  320.                                                     {
  321.                                                         //OldCursorDistance.X = Math.Abs(ClosestLand.X - X); OldCursorDistance.Y = Math.Abs(ClosestLand.Y - Y);
  322.                                                         NewCursorDistance.X = Math.Abs(XSearch - X); NewCursorDistance.Y = Math.Abs(YSearch - Y);
  323.  
  324.                                                         if (OldCursorDistance.X + OldCursorDistance.Y > NewCursorDistance.X + NewCursorDistance.Y)
  325.                                                         {
  326.                                                             OldCursorDistance = NewCursorDistance;
  327.                                                             ClosestLand.X = XSearch; ClosestLand.Y = YSearch;//new Point(XSearch, YSearch);
  328.                                                             StartLocation = ClosestLand;
  329.                                                             GameTitle = string.Format("UnReal World - {3}, X: {0} - Y: {1}, {2}", ClosestLand.X, ClosestLand.Y, TileNames[(int)LoadedMap[SearchIndex]], TSS.ModeText);
  330.                                                         }
  331.                                                     }
  332.                                                 }
  333.                                             }
  334.                                         }
  335.                                     }
  336.                                 }
  337.                             }
  338.                         }
  339.                         //if (ClosestLand.X + ClosestLand.Y > 0) { StartLocation = ClosestLand; }
  340.                     }
  341.                     SendMessage(URW.MainWindowHandle, 0x000C, 0, GameTitle);
  342.                     SendMessage(URW.MainWindowHandle, 0x0102, '-', IntPtr.Zero);
  343.                 }
  344.             }
  345.             return new Point(X, Y);
  346.         }
  347.  
  348.         private void WindowThread()
  349.         {
  350.             IntPtr ThisHandle = IntPtr.Zero;
  351.             this.Invoke(new Action(() => ThisHandle = this.Handle));
  352.             while (Thread.CurrentThread.IsAlive)
  353.             {
  354.                 if (DwmGetWindowAttribute(RWMain.TargetProcess.MainWindowHandle, DWMWA_EXTENDED_FRAME_BOUNDS, out WindowRect, Marshal.SizeOf(typeof(RECT))) != 0)
  355.                 {
  356.                     GetWindowRect(RWMain.TargetProcess.MainWindowHandle, out WindowRect);
  357.                 }
  358.  
  359.                 GameRect = new Rectangle(new Point(WindowRect.Left, WindowRect.Top), new Size(WindowRect.Right - WindowRect.Left, WindowRect.Bottom - WindowRect.Top));
  360.                 this.Invoke(new Action(() => this.Location = GameRect.Location));
  361.                 this.Invoke(new Action(() => this.Size = GameRect.Size));
  362.  
  363.                 if (GetForegroundWindow() != RWMain.TargetProcess.MainWindowHandle && GetForegroundWindow() != ThisHandle)
  364.                 {
  365.                     this.Invoke(new Action(() => this.Visible = false));
  366.                 }
  367.                 else if (GetForegroundWindow() == RWMain.TargetProcess.MainWindowHandle)
  368.                 {
  369.                     this.Invoke(new Action(() => this.Visible = true));
  370.                 }
  371.  
  372.                 if (GameMap.Width <= 0)
  373.                 {
  374.                     GameMap = GetMap();
  375.                 }
  376.  
  377.                 Thread.Sleep(10);
  378.             }
  379.         }
  380.  
  381.         private int CountTile(int ID)
  382.         {
  383.             int i = 0;
  384.             int TileCount = 0;
  385.             while (i < LoadedMap.Length)
  386.             {
  387.                 if (LoadedMap[i] == ID)
  388.                 {
  389.                     TileCount++;
  390.                 }
  391.                 i++;
  392.             }
  393.             return TileCount;
  394.         }
  395.  
  396.         private void Form1_MouseMove(object sender, MouseEventArgs e)
  397.         {
  398.             if (MouseLocation != e.Location)
  399.             {
  400.                 MouseLocation = e.Location;
  401.                 GetMouseXYMap(e);
  402.             }
  403.         }
  404.  
  405.         private void Form1_MouseDown(object sender, MouseEventArgs e)
  406.         {
  407.             if (e.Button == MouseButtons.Right)
  408.             {
  409.                 SendMessage(URW.MainWindowHandle, 0x000C, 0, "UnReal World");
  410.                 Environment.Exit(0);
  411.             }
  412.             else if (e.Button == MouseButtons.Middle && TSS.Mode == 3)
  413.             {
  414.                 TSS.OpenList();
  415.             }
  416.             else if(e.Button == MouseButtons.Left)
  417.             {
  418.  
  419.             }
  420.         }
  421.  
  422.         private void Form1_MouseWheel(object sender, MouseEventArgs e)
  423.         {
  424.             if (e.Delta < 0)
  425.             {
  426.                 if (TSS.Mode == 0) { TSS.Mode = 5; }
  427.                 else { TSS.Mode -= 1; }
  428.             }
  429.             else
  430.             {
  431.                 if (TSS.Mode == 5) { TSS.Mode = 0; }
  432.                 else { TSS.Mode += 1; }
  433.             }
  434.             ClosestLand = new Point(-1000, -1000);
  435.             TSS.CalculateMode();
  436.             GetMouseXYMap(e);
  437.         }
  438.  
  439.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  440.         {
  441.             SendMessage(URW.MainWindowHandle, 0x000C, 0, "UnReal World");
  442.         }
  443.     }
  444.  
  445.     public class TileSearchSettings
  446.     {
  447.         public int Mode = 0;
  448.         public int SearchRadius = 200;
  449.         public List<int> TileIDs = new List<int>();
  450.         private TileChecklist TCL;
  451.         public Process URW;
  452.         public string ModeText = "";
  453.  
  454.         public TileSearchSettings()
  455.         {
  456.             TCL = new TileChecklist(this)
  457.             {
  458.                 Opacity = 1,
  459.                 Enabled = true
  460.             };
  461.         }
  462.  
  463.         public void CalculateMode()
  464.         {
  465.             TileIDs.Clear();
  466.             if (TCL.Visible) { TCL.Hide(); }
  467.             switch (Mode)
  468.             {
  469.                 case 0: // Default, closest land
  470.                     SearchRadius = 200;
  471.                     break;
  472.                 case 1: // Closest village or settlement
  473.                     ModeText = "Closest Village/Settlement";
  474.                     SearchRadius = 200;
  475.                     TileIDs.AddRange(new int[] { 239, 211, 86 });
  476.                     break;
  477.                 case 2: // Closest cave
  478.                     ModeText = "Closest cave";
  479.                     SearchRadius = 200;
  480.                     TileIDs.Add(60);
  481.                     break;
  482.                 case 3: // Custom
  483.                     ModeText = "Custom";
  484.                     SearchRadius = 200;
  485.                     TileIDs = TCL.GetCheckedIDs();
  486.                     if (TileIDs.Count == 0) { OpenList(); }
  487.                     break;
  488.                 case 4: // High ground
  489.                     ModeText = "High ground";
  490.                     SearchRadius = 200;
  491.                     TileIDs.AddRange(new int[] { 94, 93, 91, 60, 20 });
  492.                     break;
  493.                 case 5: // Dense Forests
  494.                     ModeText = "Dense Forests";
  495.                     SearchRadius = 200;
  496.                     TileIDs.AddRange(new int[] { 3, 15 });
  497.                     break;
  498.                 case 6:
  499.                     break;
  500.                 case 7:
  501.                     break;
  502.                 default:
  503.                     break;
  504.             }
  505.         }
  506.  
  507.         public void OpenList()
  508.         {
  509.             TCL.ShowDialog();
  510.         }
  511.     }
  512.  
  513.     public static class Extensions
  514.     {
  515.         public static string ReplaceModifiedString(this string s)
  516.         {
  517.             return s.Replace('Σ', 'ä').Replace('Ø', '¥').Replace('─', 'Ä').Replace('÷', 'ö');
  518.         }
  519.     }
  520.  
  521.     public class ReadWriteMem
  522.     {
  523.         [DllImport("Kernel32.dll")]
  524.         private static extern bool ReadProcessMemory(IntPtr hProcess, int BaseAddress, byte[] Buffer, int Size, ref int NumberOfBytesRead);
  525.  
  526.         [DllImport("Kernel32.dll")]
  527.         private static extern bool WriteProcessMemory(IntPtr hProcess, int BaseAddress, byte[] Buffer, int Size, ref int NumberOfBytesWritten);
  528.  
  529.         private Process Proc;
  530.         public Process TargetProcess
  531.         {
  532.             get { return Proc; }
  533.             set { Proc = value; }
  534.         }
  535.         public IntPtr WindowHandle = IntPtr.Zero;
  536.  
  537.         public int ProcBaseAddress = 0;
  538.         public const int VersionOffset = 0x0000;
  539.  
  540.         public ReadWriteMem(Process T)
  541.         {
  542.             TargetProcess = T;
  543.             ProcBaseAddress = T.MainModule.BaseAddress.ToInt32();
  544.             WindowHandle = T.Handle;
  545.         }
  546.  
  547.         public bool Write(int BaseAddress, dynamic obj, byte pb = 1)
  548.         {
  549.             byte[] Buffer = BitConverter.GetBytes(obj);
  550.             int BytesWritten = 0;
  551.             if (Buffer.Length == 2 && Buffer[1] == 0) { WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, new byte[] { (byte)obj }, 1, ref BytesWritten); }
  552.             else { WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten); }
  553.             switch (BytesWritten)
  554.             {
  555.                 case 0: return false;
  556.                 default: return true;
  557.             }
  558.         }
  559.  
  560.         public bool Write(int BaseAddress, byte[] Buffer, byte pb = 1)
  561.         {
  562.             int BytesWritten = 0;
  563.             WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten);
  564.             switch (BytesWritten)
  565.             {
  566.                 case 0: return false;
  567.                 default: return true;
  568.             }
  569.         }
  570.  
  571.         public bool Write(int BaseAddress, string Text, byte pb = 1)
  572.         {
  573.             byte[] Buffer = Encoding.GetEncoding("IBM865").GetBytes(Text.ReplaceModifiedString());
  574.             int BytesWritten = 0;
  575.             WriteProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Buffer.Length, ref BytesWritten);
  576.             switch (BytesWritten)
  577.             {
  578.                 case 0: return false;
  579.                 default: return true;
  580.             }
  581.         }
  582.  
  583.         public T Read<T>(int BaseAddress, byte pb = 1)
  584.         {
  585.             byte[] Buffer;
  586.             int BytesRead = 0;
  587.  
  588.             switch (Type.GetTypeCode(typeof(T)))
  589.             {
  590.                 case TypeCode.Byte:
  591.                     Buffer = new byte[1];
  592.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 1, ref BytesRead);
  593.                     return (T)Convert.ChangeType(Buffer[0], typeof(T));
  594.                 case TypeCode.Int16:
  595.                     Buffer = new byte[2];
  596.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 2, ref BytesRead);
  597.                     return (T)Convert.ChangeType(BitConverter.ToUInt16(Buffer, 0), typeof(T));
  598.                 case TypeCode.Int32:
  599.                     Buffer = new byte[4];
  600.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
  601.                     return (T)Convert.ChangeType(BitConverter.ToUInt32(Buffer, 0), typeof(T));
  602.                 case TypeCode.UInt32:
  603.                     Buffer = new byte[4];
  604.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
  605.                     return (T)Convert.ChangeType(BitConverter.ToUInt32(Buffer, 0), typeof(T));
  606.                 case TypeCode.Single:
  607.                     Buffer = new byte[4];
  608.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, 4, ref BytesRead);
  609.                     return (T)Convert.ChangeType(BitConverter.ToSingle(Buffer, 0), typeof(T));
  610.                 default:
  611.                     return (T)Convert.ChangeType(false, typeof(T));
  612.             }
  613.         }
  614.  
  615.         public T Read<T>(int BaseAddress, int Length, byte pb = 1)
  616.         {
  617.             byte[] Buffer;
  618.             int BytesRead = 0;
  619.  
  620.             switch (Type.GetTypeCode(typeof(T)))
  621.             {
  622.                 case TypeCode.Object:
  623.                     Buffer = new byte[Length];
  624.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Length, ref BytesRead);
  625.                     return (T)Convert.ChangeType(Buffer, typeof(T));
  626.                 case TypeCode.String:
  627.                     Buffer = new byte[Length];
  628.                     ReadProcessMemory(Proc.Handle, (pb * ProcBaseAddress) + BaseAddress + VersionOffset, Buffer, Length, ref BytesRead);
  629.                     return (T)Convert.ChangeType(Encoding.GetEncoding("IBM865").GetString(Buffer, 0, Buffer.Length).Split(new char[] { '\0' })[0].ReplaceModifiedString(), typeof(T));
  630.                 default:
  631.                     return (T)Convert.ChangeType(false, typeof(T));
  632.             }
  633.         }
  634.  
  635.     }
  636.  
  637.     public enum Address
  638.     {
  639.         MapTileIDArray = 0x8C6928,
  640.         XStart = 0x1B4BA0,
  641.         YStart = 0x1B4BA4
  642.     }
  643.  
  644. }
  645.  
  646.  
  647. namespace URWSSSelector
  648. {
  649.     public partial class TileChecklist : Form
  650.     {
  651.         public TileChecklist(TileSearchSettings TSS)
  652.         {
  653.             InitializeComponent();
  654.             SearchSettings = TSS;
  655.         }
  656.  
  657.         TileSearchSettings SearchSettings;
  658.         private void TileChecklist_Load(object sender, EventArgs e)
  659.         {
  660.  
  661.         }
  662.  
  663.         public List<int> GetCheckedIDs()
  664.         {
  665.             List<int> Return = new List<int>();
  666.             for (int i = 0; i < cbList.CheckedItems.Count; i++)
  667.             {
  668.                 int TileID = int.Parse(cbList.CheckedItems[i].ToString().Split(' ')[0]);
  669.                 Return.Add(TileID);
  670.             }
  671.             return Return;
  672.         }
  673.  
  674.         private void cbList_ItemCheck(object sender, ItemCheckEventArgs e)
  675.         {
  676.             if (e.NewValue == CheckState.Checked)
  677.             {
  678.                 SearchSettings.TileIDs.Add(int.Parse(cbList.Items[e.Index].ToString().Split(' ')[0]));
  679.             }
  680.             else if (e.NewValue == CheckState.Unchecked)
  681.             {
  682.                 SearchSettings.TileIDs.Remove(int.Parse(cbList.Items[e.Index].ToString().Split(' ')[0]));
  683.             }
  684.         }
  685.  
  686.         private void TileChecklist_FormClosing(object sender, FormClosingEventArgs e)
  687.         {
  688.             if (SearchSettings.TileIDs.Count == 0)
  689.             {
  690.                 SearchSettings.TileIDs = GetCheckedIDs();
  691.             }
  692.         }
  693.     }
  694. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement