/// <summary>
 /// Writes All the values to SLW's memory
 /// </summary>
 private void ButtonWriteData_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < listView1.Items.Count; ++i)
     {
         var  item    = listView1.Items[i];
         uint address = Address + (0x10 * (uint)i);
         int  width   = int.Parse(item.SubItems[1].Text);
         int  height  = int.Parse(item.SubItems[2].Text);
         ProcessMemory.WriteInt32(ProcessHandle, address, width);
         ProcessMemory.WriteInt32(ProcessHandle, address + 0x4, height);
     }
 }
        public uint GetAddress()
        {
            // LOL, I have no idea how these work
            uint baseAddress = 0;

            if (Process.GetProcesses().Any(t => t.Id == ProcessID))
            {
                baseAddress = ((uint)Process.GetProcessById(ProcessID).MainModule.BaseAddress.ToInt32()) + 0x1000;
            }
            uint pointer1 = ProcessMemory.ReadUInt32(ProcessHandle, baseAddress + 0x402);
            uint pointer2 = ProcessMemory.ReadUInt32(ProcessHandle, pointer1);
            uint pointer3 = ProcessMemory.ReadUInt32(ProcessHandle, pointer2);

            return(pointer3);
        }
        private void ButtonReadData_Click(object sender, EventArgs e)
        {
            if (ProcessHandle == IntPtr.Zero)
            { // No handle
                var processes = Process.GetProcessesByName("slw");
                if (processes.Length > 0)
                {
                    ProcessHandle = ProcessMemory.OpenProcess(
                        ProcessMemory.ProcessAccessFlags.All, false, processes[0].Id);
                    ProcessID = processes[0].Id;
                }
            }

            // Just in case
            if (ProcessHandle == IntPtr.Zero)
            {
                MessageBox.Show("Sonic Lost World is currently not running.",
                                "SLWResolutionEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Find the address
            Address = GetAddress();

            if (Address == 0)
            {
                MessageBox.Show("Something went wrong.", "SLWResolutionEditor",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Reads a block that contains all the resolution values
            var bytes = ProcessMemory.ReadBlock(ProcessHandle, Address, (uint)(numericUpDown1.Value + 1) * 0x10);

            // Clear the old list
            listView1.Items.Clear();

            for (int i = 0; i < numericUpDown1.Value; ++i)
            {
                int width  = BitConverter.ToInt32(bytes, i * 0x10);
                int height = BitConverter.ToInt32(bytes, i * 0x10 + 0x4);

                var item = new ListViewItem(i.ToString("00"));                      // Index
                item.SubItems.Add(width.ToString());                                // Width
                item.SubItems.Add(height.ToString());                               // Height
                item.SubItems.Add(string.Format("0x{0:X8}", i * 0x10 + Address));   // Address
                listView1.Items.Add(item);
            }

            // Theme
            for (int i = 0; i < listView1.Items.Count; ++i)
            {
                if (++i % 2 == 0)
                {
                    listView1.Items[i].BackColor = Color.FromArgb(46, 46, 46);
                }
                else
                {
                    listView1.Items[i].BackColor = Color.FromArgb(54, 54, 54);
                }
            }
        }
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     // Just in case, Its a good idea to close the handle
     ProcessMemory.CloseHandle(ProcessHandle);
 }