Esempio n. 1
0
        void InitFovChanger()
        {
            settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), (string)gameMode.GetValue("c_settingsDirName"));
            settingsFile = Path.Combine(settingsPath, (string)gameMode.GetValue("c_settingsFileName"));
            gameModeFile = Path.Combine(settingsPath, "gamemode.ini");

            pFoV         = (dword_ptr)gameMode.GetValue("c_pFoV");
            fFoV         = c_FoV;
            doBeep       = c_doBeep;
            updateNotify = c_updateNotify;
            hotKeys      = c_hotKeys;
            catchKeys    = (Keys[])c_catchKeys.Clone();

            this.numFoV.Maximum = Convert.ToDecimal(c_FoV_upperLimit);
            this.numFoV.Minimum = Convert.ToDecimal(c_FoV_lowerLimit);

            if (File.Exists(settingsFile))
            {
                ReadSettings();
            }

            lblVersion.Text    = "v" + c_toolVer;
            lblVersion.Visible = true;

            IsGameInstalled();

            numFoV.Value   = Convert.ToDecimal(fFoV);
            numFoV.Enabled = true;
            ToggleButton(!isRunning(false));
        }
Esempio n. 2
0
        public Memory(string cVar, int pid, dword_ptr baseAddr, byte searchRange, byte pOffset)
        {
            this.cVar = Encoding.ASCII.GetBytes(cVar + '\0');

            this.pid         = pid;
            this.baseAddr    = baseAddr;
            this.searchRange = searchRange;
            this.pOffset     = pOffset;
        }
Esempio n. 3
0
        public void WriteFloat(dword_ptr ptr, float val)
        {
            IntPtr hProc;

            try { hProc = OpenProcess(WRITE, false, pid); }
            catch (Exception e) { throw new Exception(String.Format("Failed to open the process handle during a WriteFloat statement;\n{0}", e.Message)); }

            if (hProc != IntPtr.Zero)
            {
                try { WriteProcessMemory(hProc, ptr, BitConverter.GetBytes(val), sizeof(float), 0); }
                catch (Exception e) { throw new Exception(String.Format("Failed to write to process memory during a WriteFloat statement; Address = {0:X}\nWin32 Error: {1}", ptr, e.Message)); }

                CloseHandle(hProc);
            }
        }
Esempio n. 4
0
        public float ReadFloat(dword_ptr ptr)
        {
            byte[] buffer = new byte[sizeof(float)];
            IntPtr hProc;

            try { hProc = OpenProcess(READ, false, pid); }
            catch (Exception e) { throw new Exception(String.Format("Failed to open the process handle during a ReadFloat statement;\n{0}", e.Message)); }

            if (hProc != IntPtr.Zero)
            {
                try { ReadProcessMemory(hProc, ptr, buffer, sizeof(float), 0); }
                catch (Exception e) { throw new Exception(String.Format("Failed to read process memory during a ReadFloat statement; Address = {0:X}\nWin32 Error: {1}", ptr, e.Message)); }

                CloseHandle(hProc);
            }

            return(BitConverter.ToSingle(buffer, 0));
        }
Esempio n. 5
0
        bool isOffsetWrong(dword_ptr ptr)
        {
            for (int i = 0x20; i < 0x30 /*(byte)gameMode.GetValue("c_checkRange")*/; i += 0x10)
            {
                //MessageBox.Show(ReadFloat(Increment(ptr, i)).ToString());
                try
                {
                    if (mem.ReadFloat(ptr + i) != c_FoV)
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    ErrMessage(ex);
                    Application.Exit();
                }
            }

            return(false);
        }
Esempio n. 6
0
        void ReadSettings()
        {
            currentlyReading = true;
            StreamReader sr       = null;
            string       checkVer = c_toolVer;

            try
            {
                using (sr = new StreamReader(settingsFile))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        try
                        {
                            int equalsign = line.IndexOf('=');
                            if (equalsign > 0)
                            {
                                string varName  = line.Substring(0, equalsign);
                                string varValue = line.Substring(equalsign + 1);

                                if (varName == "ToolVersion" || varName == "GameVersion")
                                {
                                    checkVer = varValue;
                                }
                                else if (varName == "GameMode")
                                {
                                    rbSingleplayer.Checked = (varValue == "sp");
                                }
                                else if (varName == "Beep")
                                {
                                    chkBeep.Checked = bool.Parse(varValue);
                                }
                                else if (varName == "FoV")
                                {
                                    SetFoV(float.Parse(varValue));
                                }
                                else if (varName == "FoVOffset" || varName == "RelativeFoVOffset")
                                {
                                    dword_ptr tmp = dword_ptr.Parse(varValue, NumberStyles.AllowHexSpecifier);
                                    if (tmp > (dword_ptr)gameMode.GetValue("c_baseAddr"))
                                    {
                                        pFoV = (varName == "RelativeFoVOffset" ? (dword_ptr)gameMode.GetValue("c_baseAddr") : 0) + tmp;
                                    }
                                }
                                else if (varName == "UpdateNotify")
                                {
                                    chkUpdate.Checked = bool.Parse(varValue);
                                }
                                else if (varName == "DisableHotkeys")
                                {
                                    chkHotkeys.Checked = bool.Parse(varValue);
                                }
                                else if (varName == "HotkeyIncrease")
                                {
                                    catchKeys[0]       = (Keys)int.Parse(varValue);
                                    btnKeyZoomOut.Text = VirtualKeyName(catchKeys[0]);
                                }
                                else if (varName == "HotkeyDecrease")
                                {
                                    catchKeys[1]      = (Keys)int.Parse(varValue);
                                    btnKeyZoomIn.Text = VirtualKeyName(catchKeys[1]);
                                }
                                else if (varName == "HotkeyReset")
                                {
                                    catchKeys[2]     = (Keys)int.Parse(varValue);
                                    btnKeyReset.Text = VirtualKeyName(catchKeys[2]);
                                }
                            }
                        }
                        catch { }
                    }
                }
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }

            if (checkVer != c_toolVer)
            {
                pFoV = (dword_ptr)gameMode.GetValue("c_pFoV");
            }

            UpdateCheck();

            currentlyReading = false;
        }
Esempio n. 7
0
        private void TimerVerif_Tick(object sender, EventArgs e)
        {
            if (proc != null && mem != null && isRunning(false))
            {
                if (btnStartGame.Enabled)
                {
                    ToggleButton(false);
                }
                proc.Refresh();

                try
                {
                    if (proc.PagedMemorySize64 > 0x2000000)
                    {
                        byte step = 0;

                        try
                        {
                            mem.FindFoVOffset(ref pFoV, ref step);

                            if (!isOffsetWrong(pFoV))
                            {
                                progStart();
                            }
                            else if (proc.PagedMemorySize64 > (dword_ptr)gameMode.GetValue("c_memSearchRange"))
                            {
                                TimerVerif.Stop();
                                TimerCheck.Stop();

                                //bool offsetFound = false;

                                //int ptrSize = IntPtr.Size * 4;

                                /*for (int i = -0x50000; i < 0x50000 && !offsetFound; i += 16)
                                 * {
                                 *  if (mem.ReadFloat(true, pFoV + i) == 65f && !isOffsetWrong(pFoV + i))
                                 *  {
                                 *      pFoV += i;
                                 *      offsetFound = true;
                                 *  }
                                 *
                                 *  if (i % 50000 == 0)
                                 *  {
                                 *      label1.Text = i.ToString();
                                 *      Update();
                                 *  }
                                 * }*/

                                //Console.Beep(5000, 100);

                                //MessageBox.Show("find " + pFoV.ToString("X8"));
                                if (isRunning(false) && !mem.FindFoVOffset(ref pFoV, ref step))
                                {
                                    string memory = BitConverter.ToString(BitConverter.GetBytes(mem.ReadFloat(pFoV)));

                                    MessageBox.Show(this, "The memory research pattern wasn't able to find the FoV offset in your " + gameMode.GetValue("c_supportMessage") + ".\n" +
                                                    "Please look for an updated version of this FoV Changer tool.\n\n" +
                                                    "If you believe this might be a bug, please send me an email at [email protected], and include a screenshot of this:\n" +
                                                    "\n" + c_toolVer +
                                                    "\nWorking Set: 0x" + proc.WorkingSet64.ToString("X8") +
                                                    "\nPaged Memory: 0x" + proc.PagedMemorySize64.ToString("X8") +
                                                    "\nVirtual Memory: 0x" + proc.VirtualMemorySize64.ToString("X8") +
                                                    "\nStep: " + step.ToString() +
                                                    "\nFoV pointer: 0x" + (pFoV - c_pOffset).ToString("X8") + " = " + memory,
                                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                    pFoV = (dword_ptr)gameMode.GetValue("c_pFoV");
                                    Application.Exit();
                                }
                                else
                                {
                                    //Console.Beep(5000, 100);
                                    SaveSettings();
                                    proc = null;
                                    TimerCheck.Start();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrMessage(ex);
                            Application.Exit();
                        }
                    }
                }
                catch (InvalidOperationException) { }
            }
        }
Esempio n. 8
0
        public bool FindFoVOffset(ref dword_ptr pFoV, ref byte step)
        {
            IntPtr hProc;
            bool   isFound = false;

            try { hProc = OpenProcess(READ, false, pid); step = 0; }
            catch (Exception e) { throw new Exception(String.Format("Failed to open the process handle during a FindFoVOffset statement;\n{0}", e.Message)); }

            if (hProc != IntPtr.Zero)
            {
                dword_ptr start = pFoV - searchRegionBefore;

                if (varAddr == 0)
                {
                    step = 2;
                    byte[] buffer = new byte[searchTextRegion];

                    try { ReadProcessMemory(hProc, baseAddr, buffer, searchTextRegion, 0); }
                    catch (Exception e) { step = 3; throw new Exception(String.Format("Failed to read process memory during the first iteration of a FindFoVOffset statement\nWin32 Error: {1}", e.Message)); }

                    unsafe
                    {
                        fixed(byte *pBuffer = buffer)
                        {
                            for (int i = 0; i < searchTextRegion; i += sizeof(Int32))
                            {
                                step = 4;

                                if (strcmp(pBuffer + i, cVar) == 0)
                                {
                                    step    = 5;
                                    varAddr = baseAddr + i;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (varAddr > 0)
                {
                    dword_ptr testCurrentPtr;

                    try { ReadProcessMemory(hProc, pFoV - pOffset, out testCurrentPtr, sizeof(dword_ptr), 0); step = 14; }
                    catch (Exception e) { step = 1; throw new Exception(String.Format("Failed to read process memory during the test FindFoVOffset statement; \nWin32 Error: {0}", e.Message)); }

                    if (testCurrentPtr == varAddr)
                    {
                        step    = 15;
                        isFound = true;
                    }
                    else
                    {
                        step = 6;
                        byte[] buffer = new byte[searchRegion];

                        try { ReadProcessMemory(hProc, start, buffer, searchRegion, 0); step = 7; }
                        catch (Exception e) { step = 8; throw new Exception(String.Format("Failed to read process memory during the second iteration of a FindFoVOffset statement; Address = {0:X}\nWin32 Error: {1}", start, e.Message)); }

                        step = 9;

                        unsafe
                        {
                            fixed(byte *pBuffer = buffer)
                            {
                                for (int i = 0; i < searchRegion; i += sizeof(Int32))
                                {
                                    step = 10;

                                    if (*(dword_ptr *)(pBuffer + i) == varAddr)
                                    {
                                        step    = 11;
                                        pFoV   += i - searchRegionBefore + pOffset;
                                        isFound = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                CloseHandle(hProc);
            }

            return(isFound);
        }
Esempio n. 9
0
 public static extern bool WriteProcessMemory(IntPtr hProc, dword_ptr lpBaseAddress, [In] byte[] buffer, int size, [Out] int lpNumberOfBytesWritten);
Esempio n. 10
0
 public static extern bool ReadProcessMemory(IntPtr hProc, dword_ptr lpBaseAddress, out dword_ptr buffer, int size, [Out] int lpNumberOfBytesRead);