namespace CharacterSwap
{
    using GTA;
    using NativeUI;
    using System;
    using System.Windows.Forms;
    using System.Diagnostics;

    public class Main : Script
    {
        MenuPool menuPool; UIMenu Charactermenu;
        UIMenuItem MButton, FButton, TButton, MMButton, MFButton;



        public Main()
        {
            Charactermenu = new UIMenu("CharacterSwap", "Who should the game think you are?");
            menuPool = new MenuPool();
            menuPool.Add(Charactermenu);
            AddButtons();
            Charactermenu.RefreshIndex();
            base.Tick += new EventHandler(this.OnTick);
            base.KeyDown += new KeyEventHandler(this.OnKeyDown);
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.B)
            {
                Charactermenu.Visible = !Charactermenu.Visible;
            }
        }

        private void OnTick(object sender, EventArgs e)
        {
            menuPool.ProcessMenus();
        }
        public void AddButtons()
        {
            UIMenuItem MButton = new UIMenuItem("Michael", "Makes the game think you are Michael");
            UIMenuItem FButton = new UIMenuItem("Franklin", "Makes the game think you are Franklin");
            UIMenuItem TButton = new UIMenuItem("Trevor", "Makes the game think you are Trevor");
            UIMenuItem MMButton = new UIMenuItem("Freemode Male", "Makes the game think you are the Freemode Male model");
            UIMenuItem MFButton = new UIMenuItem("Freemode Female", "Makes the game think you are the Freemode Female model");
            Charactermenu.AddItem(MButton); Charactermenu.AddItem(FButton); Charactermenu.AddItem(TButton);
            Charactermenu.AddItem(MMButton); Charactermenu.AddItem(MFButton);
            Charactermenu.OnItemSelect += (sender, item, index) =>
            {
                if (item == MButton)
                {
                    Process[] processes = Process.GetProcessesByName("GTA5");
                    if (processes.Length > 0)
                    {

                        using (CheatEngine.Memory memory = new CheatEngine.Memory(processes[0]))
                        {
                            IntPtr address = memory.GetAddress("GTA5.exe", (IntPtr)0x01EDE510, new int[] { 0x0, 0x108, 0x8, 0x20, 0x18 });
                            uint Newhash = 225514697;
                            memory.WriteUInt32(address, Newhash);
                        }
                    }
                }
                if (item == FButton)
                {
                    Process[] processes = Process.GetProcessesByName("GTA5");
                    if (processes.Length > 0)
                    {

                        using (CheatEngine.Memory memory = new CheatEngine.Memory(processes[0]))
                        {
                            IntPtr address = memory.GetAddress("GTA5.exe", (IntPtr)0x01EDE510, new int[] { 0x0, 0x108, 0x8, 0x20, 0x18 });
                            uint Newhash = 2602752943;
                            memory.WriteUInt32(address, Newhash);
                        }
                    }
                }
                if (item == TButton)
                {
                    Process[] processes = Process.GetProcessesByName("GTA5");
                    if (processes.Length > 0)
                    {

                        using (CheatEngine.Memory memory = new CheatEngine.Memory(processes[0]))
                        {
                            IntPtr address = memory.GetAddress("GTA5.exe", (IntPtr)0x01EDE510, new int[] { 0x0, 0x108, 0x8, 0x20, 0x18 });
                            uint Newhash = 2608926626;
                            memory.WriteUInt32(address, Newhash);
                        }
                    }
                }
                if (item == MMButton)
                {
                    Process[] processes = Process.GetProcessesByName("GTA5");
                    if (processes.Length > 0)
                    {

                        using (CheatEngine.Memory memory = new CheatEngine.Memory(processes[0]))
                        {
                            IntPtr address = memory.GetAddress("GTA5.exe", (IntPtr)0x01EDE510, new int[] { 0x0, 0x108, 0x8, 0x20, 0x18 });
                            uint Newhash = 1885233650;
                            memory.WriteUInt32(address, Newhash);
                        }
                    }
                }
                if (item == MFButton)
                {
                    Process[] processes = Process.GetProcessesByName("GTA5");
                    if (processes.Length > 0)
                    {

                        using (CheatEngine.Memory memory = new CheatEngine.Memory(processes[0]))
                        {
                            IntPtr address = memory.GetAddress("GTA5.exe", (IntPtr)0x01EDE510, new int[] { 0x0, 0x108, 0x8, 0x20, 0x18 });
                            uint Newhash = 51650552;
                            memory.WriteUInt32(address, Newhash);
                        }
                    }
                }
            };
        }
    }
}
